:root {
    --bg: #0f1113;
    --bg-2: #181b1e;
    --bg-3: #23272b;
    --text: #e8e8e8;
    --muted: #9aa0a6;
    --accent: #ff4655;
    --accent-2: #ffb347;
    --radius: 10px;
    --shadow: 0 6px 24px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 15px;
}

a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

/* ---------- cabecera ---------- */
.topbar {
    position: sticky; top: 0; z-index: 10;
    display: flex; align-items: center; justify-content: space-between;
    padding: .8em 1.5em;
    background: var(--bg-2);
    border-bottom: 1px solid #2a2e33;
}
.brand { font-weight: 800; font-size: 1.2em; letter-spacing: .02em; }
.brand span { color: var(--accent); }
.count { color: var(--muted); font-size: .9em; }

main { max-width: 1400px; margin: 0 auto; padding: 1.2em 1.5em 4em; }

/* ---------- filtros ---------- */
.filters {
    background: var(--bg-2);
    border-radius: var(--radius);
    padding: 1em 1.2em;
    display: grid; gap: 1em;
}
.filter-label { color: var(--muted); font-size: .8em; text-transform: uppercase; letter-spacing: .08em; margin-bottom: .4em; }
.filter-row-inline { display: flex; flex-wrap: wrap; gap: 1.5em; align-items: end; }

.agents { display: flex; flex-wrap: wrap; gap: .4em; align-items: center; }
.agent {
    width: 46px; height: 46px; padding: 0;
    border: 2px solid transparent; border-radius: 8px;
    background: var(--bg-3); overflow: hidden;
    opacity: .75; transition: opacity .15s, border-color .15s, transform .15s;
}
.agent img { width: 100%; height: 100%; display: block; }
.agent:hover { opacity: 1; transform: translateY(-2px); }
.agent.selected { opacity: 1; border-color: var(--accent); }
.agent.empty { opacity: .25; }

.abilities { display: flex; flex-wrap: wrap; gap: .4em; }
.ability {
    display: flex; align-items: center; gap: .5em;
    padding: .3em .7em .3em .3em;
    border: 2px solid transparent; border-radius: 8px; background: var(--bg-3);
}
.ability img { width: 28px; height: 28px; filter: invert(1); }
.ability.selected { border-color: var(--accent); }

.chips { display: flex; flex-wrap: wrap; gap: .4em; align-items: center; }
.chip {
    padding: .35em .9em; border-radius: 999px; line-height: 1.3;
    border: 1px solid #353a40; background: transparent;
}
.chip:hover { background: var(--bg-3); }
.chip.selected { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.chip.empty { opacity: .35; }

.toggles { display: inline-flex; background: var(--bg-3); border-radius: 8px; padding: 3px; }
.toggles button { border: 0; background: transparent; padding: .35em .9em; border-radius: 6px; color: var(--muted); }
.toggles button.selected { background: var(--bg); color: var(--text); }

select {
    font: inherit; color: var(--text); background: var(--bg-3);
    border: 1px solid #353a40; border-radius: 8px; padding: .4em .7em; min-width: 12em;
}
.link-btn { background: none; border: 0; color: var(--muted); text-decoration: underline; padding: .4em 0; }
.link-btn:hover { color: var(--text); }

/* minimapa con callouts */
.minimap-panel { display: flex; justify-content: center; }
.minimap { position: relative; width: min(100%, 420px); aspect-ratio: 1; }
.minimap img { width: 100%; height: 100%; display: block; border-radius: 8px; }
.callouts { position: absolute; inset: 0; }
.callout {
    position: absolute; transform: translate(-50%, -50%);
    font-size: .62em; font-weight: 600; color: #fff;
    text-shadow: 0 0 3px #000, 0 0 3px #000;
    pointer-events: none; white-space: nowrap;
}

/* ---------- grid ---------- */
.grid-title { margin: 1.4em 0 .8em; font-size: 1.1em; color: var(--muted); font-weight: 600; }
.grid {
    display: grid; gap: 1em;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}
.card {
    display: block; background: var(--bg-2); border-radius: var(--radius); overflow: hidden;
    transition: transform .15s, box-shadow .15s;
}
.card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.card-img { position: relative; aspect-ratio: 16 / 9; background: var(--bg-3); }
.card-img .thumb { width: 100%; height: 100%; object-fit: cover; display: block; }
.card-img::after {
    content: ""; position: absolute; inset: 0;
    background: linear-gradient(to top, rgba(0,0,0,.55), transparent 50%);
}
.card-agent {
    position: absolute; left: .5em; bottom: .5em; z-index: 1;
    width: 40px; height: 40px; border-radius: 8px; border: 2px solid var(--bg-2);
}
.card-ability {
    position: absolute; right: .5em; top: .5em; z-index: 1;
    width: 30px; height: 30px; padding: 4px; border-radius: 6px;
    background: rgba(0,0,0,.6); filter: invert(1) brightness(1.3);
}
.card-side {
    position: absolute; right: .5em; bottom: .5em; z-index: 1;
    font-size: .7em; padding: .15em .5em; border-radius: 4px; font-weight: 700;
}
.card-side.attack { background: var(--accent); }
.card-side.defense { background: #2f9e6e; }
.card-imported {
    position: absolute; left: .5em; top: .5em; z-index: 1;
    font-size: .65em; padding: .15em .45em; border-radius: 4px; font-weight: 700;
    background: rgba(0,0,0,.6); color: var(--muted); letter-spacing: .05em;
}
.viewer-source { font-size: .85em; color: var(--muted); }
.viewer-source a { color: var(--accent-2); text-decoration: underline; }
.card-text { padding: .7em .9em .9em; }
.card-title { font-weight: 600; line-height: 1.3; }
.card-pos { color: var(--muted); font-size: .85em; margin-top: .3em; }
.card-pos b { color: var(--text); font-weight: 500; }
.empty-msg { color: var(--muted); text-align: center; padding: 3em 0; }

/* ---------- visor ---------- */
.viewer {
    position: fixed; inset: 0; z-index: 100;
    background: rgba(0, 0, 0, .8);
    display: flex; align-items: center; justify-content: center;
    padding: 1em;
}
.viewer-box {
    width: min(100%, 1500px); max-height: 100%;
    background: var(--bg-2); border-radius: var(--radius);
    display: flex; flex-direction: column; overflow: hidden; box-shadow: var(--shadow);
}
.viewer-head { display: flex; align-items: center; gap: .6em; padding: .5em .8em; border-bottom: 1px solid #2a2e33; }
.viewer-title { flex: 1; font-weight: 600; }
.icon-btn { background: var(--bg-3); border: 0; border-radius: 8px; width: 2.2em; height: 2.2em; font-size: 1em; }
.icon-btn:hover { background: #2e3338; }

.viewer-body { display: grid; grid-template-columns: 1fr 340px; min-height: 0; }
.viewer-stage { position: relative; background: #000; display: flex; align-items: center; justify-content: center; }
.viewer-stage img { max-width: 100%; max-height: 80vh; display: block; }
.nav {
    position: absolute; top: 50%; transform: translateY(-50%);
    width: 2.4em; height: 2.4em; border-radius: 50%; border: 0;
    background: rgba(0,0,0,.55); color: #fff; font-size: 1.6em; line-height: 1;
}
.nav:hover { background: rgba(0,0,0,.8); }
.nav.prev { left: .5em; }
.nav.next { right: .5em; }
.nav[disabled] { opacity: .2; cursor: default; }
.viewer-caption {
    position: absolute; left: 50%; bottom: .6em; transform: translateX(-50%);
    background: rgba(0,0,0,.6); padding: .25em .8em; border-radius: 999px; font-size: .85em;
}

.viewer-side { padding: 1em; overflow: auto; display: flex; flex-direction: column; gap: .8em; }
.viewer-side h3 { margin: .4em 0 0; font-size: .85em; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.viewer-meta { display: flex; flex-wrap: wrap; gap: .4em; align-items: center; }
.viewer-meta img { width: 32px; height: 32px; border-radius: 6px; }
.viewer-meta img.ab { filter: invert(1); background: var(--bg-3); padding: 4px; }
.viewer-meta .tag { background: var(--bg-3); padding: .25em .7em; border-radius: 999px; font-size: .85em; }
.viewer-steps { margin: 0; padding-left: 1.2em; line-height: 1.5; }
.viewer-steps .none { color: var(--muted); list-style: none; margin-left: -1.2em; font-style: italic; }
.viewer-thumbs { display: grid; grid-template-columns: repeat(3, 1fr); gap: .4em; margin-top: auto; }
.viewer-thumbs img {
    width: 100%; aspect-ratio: 16/9; object-fit: cover; border-radius: 6px;
    border: 2px solid transparent; cursor: pointer; opacity: .6;
}
.viewer-thumbs img.current { border-color: var(--accent); opacity: 1; }

.toast {
    position: fixed; left: 50%; bottom: 1.5em; transform: translateX(-50%);
    background: var(--bg-3); padding: .6em 1.2em; border-radius: 999px; box-shadow: var(--shadow); z-index: 200;
}

@media (max-width: 900px) {
    main { padding: 1em; }
    .viewer { padding: 0; }
    .viewer-box { height: 100%; border-radius: 0; }
    .viewer-body { grid-template-columns: 1fr; overflow: auto; }
    .viewer-stage img { max-height: 55vh; }
    .filter-row-inline { gap: 1em; }
    select { min-width: 9em; }
}
