/* ==========================================================================
   Design tokens
   Breakpoints (literales — las custom properties NO funcionan en @media):
   sm 640 · md 900 · lg 1200 · xl 1600
   ========================================================================== */
:root {
    /* superficie */
    --bg: #eef0f2;
    --surface: #fff;
    --surface-2: #f8f8f8;
    --surface-3: #e8e8e8;
    --surface-4: #fafafa;
    --border: #ddd;
    --border-strong: #ccc;
    --border-soft: #e0e0e0;

    /* texto */
    --text: #333;
    --text-soft: #555;
    --text-muted: #666;

    /* marca */
    --accent: #4CAF50;
    --accent-hover: #45a049;
    --accent-soft: #e8f5e8;
    --alt: #49c1e6;
    --alt-hover: #34acd1;
    --warn: #e66849;
    --warn-hover: #cf4e2e;
    --neutral: #6b7280;
    --danger: #d32f2f;
    --code: #d63384;

    /* Frames: un color por cada uno. La franja aparece a la izquierda de cada
       fila del mazo. Para cambiar su grosor, tocá --frame-bar-w. */
    --frame-bar-w: 10px;
    --frame-rule: #86c53e;
    --frame-monster: #ddba47;
    --frame-alter: #c42230;
    --frame-fusion: #8548c7;
    --frame-ritual: #3479d4;
    --frame-integration: #8f601a;
    --frame-token: #98a0a8;
    --frame-spell: #1dad7d;
    --frame-trap: #c436a5;
    --frame-combination: #9ca865;
    --frame-terrain: #5ba85e;

    /* espaciado y forma */
    --sp-1: 4px;
    --sp-2: 8px;
    --sp-3: 12px;
    --sp-4: 16px;
    --sp-5: 24px;
    --sp-6: 32px;
    --radius: 6px;
    --radius-lg: 10px;
    --shadow-1: 0 1px 2px rgba(0, 0, 0, .06);
    --shadow-2: 0 4px 12px rgba(0, 0, 0, .12);

    /* tipografía */
    --fs-xs: 11px;
    --fs-sm: 12px;
    --fs-md: 14px;
    --fs-lg: 16px;
    --fs-xl: 20px;
    --font: system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
    --mono: ui-monospace, "Cascadia Code", "Courier New", monospace;

    /* layout */
    --topbar-h: 56px;
    --sidebar-w: 320px;
    --card-min: 215px;
    --grid-gap: 12px;

    /* capas */
    --z-sidebar: 40;
    --z-topbar: 50;
    --z-modal: 1000;
    --z-popup: 1100;
    --z-combo: 1200;

    /* transiciones */
    --t-fast: 120ms;
    --t-med: 220ms;
}

@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        transition-duration: 1ms !important;
        animation-duration: 1ms !important;
    }
}

/* ==========================================================================
   Base — la página no scrollea; scrollean los paneles
   ========================================================================== */
* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
}

body {
    margin: 0;
    font-family: var(--font);
    font-size: var(--fs-md);
    color: var(--text);
    background-color: var(--bg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

/* ==========================================================================
   Topbar
   ========================================================================== */
.topbar {
    flex: 0 0 auto;
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: 0 var(--sp-4);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-1);
    z-index: var(--z-topbar);
}

.brand {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    text-decoration: none;
    color: inherit;
    flex: 0 0 auto;
}

.brand-logo {
    height: 32px;
    width: auto;
    /* contain + width auto: respeta el aspecto original del logo */
    object-fit: contain;
}

.brand-name {
    font-size: var(--fs-lg);
    white-space: nowrap;
}

.brand-name strong {
    color: var(--accent);
}

.brand:hover .brand-logo {
    opacity: .8;
}

.search-wrap {
    flex: 1 1 auto;
    max-width: 640px;
    margin: 0 auto;
    position: relative;
    display: flex;
    align-items: center;
}

.search-icon {
    position: absolute;
    left: 10px;
    font-size: var(--fs-md);
    pointer-events: none;
    opacity: .6;
}

#advancedSearch {
    width: 100%;
    padding: 9px 32px 9px 34px;
    border: 2px solid var(--border-strong);
    border-radius: var(--radius);
    font-size: var(--fs-md);
    font-family: inherit;
    outline: none;
    transition: border-color var(--t-fast);
}

#advancedSearch:focus {
    border-color: var(--accent);
}

.search-clear {
    position: absolute;
    right: 6px;
    border: none;
    background: transparent;
    font-size: var(--fs-xl);
    line-height: 1;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 50%;
}

.search-clear:hover {
    background: var(--surface-3);
}

.topbar-btn,
.drawer-toggle {
    flex: 0 0 auto;
    width: 32px;
    height: 32px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    border-radius: 50%;
    cursor: pointer;
    font-size: var(--fs-md);
    color: var(--text-soft);
    transition: background-color var(--t-fast);
}

.topbar-btn:hover,
.drawer-toggle:hover {
    background: var(--surface-3);
}

.drawer-toggle {
    display: none;
    border-radius: var(--radius);
}

/* ==========================================================================
   Layout
   ========================================================================== */
.layout {
    flex: 1 1 auto;
    display: flex;
    min-height: 0;
}

/* ==========================================================================
   Sidebar
   ========================================================================== */
.sidebar {
    flex: 0 0 var(--sidebar-w);
    width: var(--sidebar-w);
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    z-index: var(--z-sidebar);
}

.sidebar-tabs {
    flex: 0 0 auto;
    display: flex;
    border-bottom: 1px solid var(--border);
}

.sidebar-tab {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--sp-1);
    padding: var(--sp-3) var(--sp-2);
    border: none;
    border-bottom: 3px solid transparent;
    background: var(--surface-2);
    font-family: inherit;
    font-size: var(--fs-md);
    color: var(--text-muted);
    cursor: pointer;
    transition: background-color var(--t-fast), color var(--t-fast);
}

.sidebar-tab:hover {
    background: var(--surface-3);
}

.sidebar-tab.active {
    background: var(--surface);
    color: var(--text);
    border-bottom-color: var(--accent);
    font-weight: 600;
}

.tab-badge {
    display: inline-block;
    min-width: 20px;
    padding: 1px 6px;
    border-radius: 10px;
    background: var(--neutral);
    color: #fff;
    font-size: var(--fs-xs);
    font-weight: 700;
}

.sidebar-tab.active .tab-badge {
    background: var(--accent);
}

@keyframes badge-pulse {
    0% {
        transform: scale(1);
    }

    40% {
        transform: scale(1.35);
    }

    100% {
        transform: scale(1);
    }
}

.tab-badge.pulse {
    animation: badge-pulse var(--t-med) ease-out;
}

/* ---- franja de estado persistente (visible en ambas pestañas) ---- */
.deck-status {
    flex: 0 0 auto;
    display: flex;
    gap: var(--sp-3);
    padding: var(--sp-2) var(--sp-3);
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    font-size: var(--fs-xs);
}

.status-seg {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
}

.status-label {
    color: var(--text-muted);
}

.status-bar {
    display: block;
    height: 4px;
    border-radius: 2px;
    background: var(--border);
    overflow: hidden;
}

.status-bar i {
    display: block;
    height: 100%;
    width: 0;
    background: var(--accent);
    transition: width var(--t-med);
}

.status-bar i.full {
    background: var(--warn);
}

.status-count {
    font-variant-numeric: tabular-nums;
    color: var(--text);
}

/* ---- paneles ---- */
.tab-panel {
    flex: 1 1 auto;
    min-height: 0;
    /* obligatorio: sin esto el hijo con overflow no se encoge */
    display: flex;
    flex-direction: column;
}

#panel-filters {
    overflow-y: auto;
    padding: var(--sp-3);
}

#panel-filters[hidden],
#panel-deck[hidden] {
    display: none;
}

/* ==========================================================================
   Filtros
   ========================================================================== */
.filter-section {
    border-bottom: 1px solid var(--border-soft);
}

.section-toggle {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    width: 100%;
    padding: var(--sp-3) var(--sp-1);
    border: none;
    background: transparent;
    font-family: inherit;
    font-size: var(--fs-xs);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-muted);
    cursor: pointer;
}

.section-toggle:hover {
    color: var(--text);
}

.section-chevron {
    display: inline-block;
    transition: transform var(--t-fast);
}

.section-toggle[aria-expanded="false"] .section-chevron {
    transform: rotate(-90deg);
}

.section-body {
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
    padding-bottom: var(--sp-3);
}

.section-body[hidden] {
    display: none;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.field-label {
    font-size: var(--fs-xs);
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-muted);
}

.field-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--sp-2);
}

.field-check {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    font-size: var(--fs-sm);
    color: var(--text);
    cursor: pointer;
    padding: var(--sp-1) 0;
}

.field-check input {
    width: 15px;
    height: 15px;
    accent-color: var(--accent);
    cursor: pointer;
    flex: 0 0 auto;
}

.field input,
.field select {
    width: 100%;
    padding: 7px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-family: inherit;
    font-size: var(--fs-md);
    background: var(--surface);
    color: var(--text);
}

.field input:focus,
.field select:focus {
    outline: 2px solid var(--accent);
    outline-offset: -1px;
    border-color: var(--accent);
}

/* ---- combo con búsqueda ---- */
.combo {
    position: relative;
}

.combo-trigger {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    width: 100%;
    padding: 7px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    font-family: inherit;
    font-size: var(--fs-md);
    color: var(--text);
    cursor: pointer;
    text-align: left;
    transition: border-color var(--t-fast);
}

.combo-trigger:hover {
    border-color: var(--border-strong);
}

.combo.open .combo-trigger,
.combo-trigger:focus-visible {
    border-color: var(--accent);
    outline: none;
}

.combo.has-value .combo-trigger {
    border-color: var(--accent);
    background: var(--accent-soft);
}

.combo-icon {
    flex: 0 0 auto;
    width: 15px;
    height: 15px;
    color: var(--text-muted);
}

.combo-value {
    flex: 1 1 auto;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.combo-value.is-placeholder {
    color: var(--text-muted);
}

.combo-caret {
    flex: 0 0 auto;
    color: var(--text-muted);
    font-size: var(--fs-sm);
}

/* fixed + montado en <body>: el sidebar tiene overflow y recortaría un absolute */
.combo-panel {
    position: fixed;
    z-index: var(--z-combo);
    display: flex;
    flex-direction: column;
    max-height: 320px;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    box-shadow: var(--shadow-2);
    overflow: hidden;
}

.combo-panel[hidden] {
    display: none;
}

.combo-search {
    flex: 0 0 auto;
    margin: var(--sp-2);
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-family: inherit;
    font-size: var(--fs-sm);
    outline: none;
}

.combo-search:focus {
    border-color: var(--accent);
}

.combo-list {
    flex: 1 1 auto;
    overflow-y: auto;
    margin: 0;
    padding: 0 0 var(--sp-1);
    list-style: none;
}

.combo-option {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    padding: 6px var(--sp-3);
    font-size: var(--fs-sm);
    cursor: pointer;
}

.combo-option.active {
    background: var(--surface-3);
}

.combo-option.selected {
    color: var(--accent-hover);
    font-weight: 600;
}

.combo-check {
    flex: 0 0 auto;
    width: 14px;
    color: var(--accent);
}

.combo-option-label {
    flex: 1 1 auto;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.combo-count {
    flex: 0 0 auto;
    color: var(--text-muted);
    font-size: var(--fs-xs);
    font-variant-numeric: tabular-nums;
}

.combo-empty {
    padding: var(--sp-3);
    color: var(--text-muted);
    font-size: var(--fs-sm);
    font-style: italic;
}

/* ---- filtros numéricos con operador ---- */
.numfilter {
    display: grid;
    grid-template-columns: 16px 1fr 52px 1fr;
    align-items: center;
    gap: var(--sp-2);
}

/* variante sin icono ni label propios: el campo ya los tiene arriba */
.numfilter.compact {
    grid-template-columns: 52px 1fr;
}

.numfilter[hidden] {
    display: none;
}

.field-hint {
    margin: 0;
    font-size: var(--fs-xs);
    font-style: italic;
    color: var(--text-muted);
}

.field-hint[hidden] {
    display: none;
}

.field-hint.is-error {
    color: var(--danger);
    font-style: normal;
}

/* mensaje que ocupa el grid entero: cargando / error / sin resultados */
.grid-message {
    grid-column: 1 / -1;
    margin: var(--sp-6) 0;
    text-align: center;
    color: var(--text-muted);
    font-style: italic;
}

.numfilter-icon {
    width: 15px;
    height: 15px;
    color: var(--text-muted);
}

.numfilter-label {
    font-size: var(--fs-xs);
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-muted);
}

.numfilter-op {
    appearance: none;
    -webkit-appearance: none;
    padding: 6px 4px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-2);
    font-family: var(--mono);
    font-size: var(--fs-md);
    text-align: center;
    text-align-last: center;
    color: var(--text);
    cursor: pointer;
}

.numfilter-op:focus {
    border-color: var(--accent);
    outline: none;
}

.numfilter input {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-family: inherit;
    font-size: var(--fs-md);
    background: var(--surface);
    color: var(--text);
}

.numfilter input:focus {
    border-color: var(--accent);
    outline: none;
}

.filter-buttons {
    display: flex;
    gap: var(--sp-2);
    padding: var(--sp-3) 0;
}

.clear-filters-btn {
    flex: 1;
    padding: 9px 12px;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-family: inherit;
    font-size: var(--fs-md);
    color: #fff;
    transition: background-color var(--t-fast);
    background-color: var(--neutral);
}

.clear-filters-btn:hover {
    background-color: var(--text-soft);
}

/* ---- type tags ---- */
.type-tags {
    display: flex;
    flex-wrap: wrap;
    gap: var(--sp-1);
}

.type-tag {
    display: inline-flex;
    align-items: center;
    background-color: var(--bg);
    border-radius: 12px;
    padding: 2px 6px;
    font-size: var(--fs-xs);
    border: 1px solid var(--border);
}

.type-tag.positive {
    background-color: var(--accent-soft);
    border-color: var(--accent);
}

.type-tag.negative {
    background-color: #ffeaea;
    border-color: var(--warn);
}

.type-prefix,
.type-remove {
    border: none;
    background: transparent;
    font-family: inherit;
    font-weight: bold;
    font-size: var(--fs-xs);
    line-height: 1;
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 50%;
    color: inherit;
}

.type-prefix:hover {
    background-color: rgba(0, 0, 0, .12);
}

.type-value {
    margin: 0 3px;
}

.type-remove {
    color: var(--text-muted);
}

.type-remove:hover {
    background-color: var(--warn);
    color: #fff;
}

/* ==========================================================================
   Panel del mazo
   ========================================================================== */
.deck-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: var(--sp-3);
}

.deck-section {
    margin-bottom: var(--sp-4);
}

.deck-section h4 {
    position: sticky;
    top: calc(var(--sp-3) * -1);
    margin: 0 0 var(--sp-1);
    padding: var(--sp-1) 0;
    background: var(--surface);
    color: var(--text-muted);
    font-size: var(--fs-xs);
    text-transform: uppercase;
    letter-spacing: .06em;
    z-index: 1;
}

.deck-card {
    display: grid;
    grid-template-columns: 22px 1fr auto;
    align-items: center;
    gap: var(--sp-2);
    height: 26px;
    padding: 0 var(--sp-1) 0 var(--sp-2);
    border-left: var(--frame-bar-w) solid var(--row-frame, var(--border-strong));
    border-bottom: 1px solid var(--border-soft);
}

.deck-card:hover {
    background: var(--surface-2);
}

.deck-card-count {
    font-size: var(--fs-xs);
    font-weight: 700;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    text-align: right;
}

.deck-card-name {
    font-size: var(--fs-sm);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* distingue filas de la misma carta con distinto arte */
.deck-card-art {
    margin-left: var(--sp-1);
    padding: 0 4px;
    border-radius: 8px;
    background: var(--surface-3);
    color: var(--text-muted);
    font-size: var(--fs-xs);
    font-weight: 700;
}

.deck-card-actions {
    display: flex;
    gap: 2px;
    opacity: 0;
    transition: opacity var(--t-fast);
}

.deck-card:hover .deck-card-actions,
.deck-card:focus-within .deck-card-actions {
    opacity: 1;
}

.deck-btn {
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-muted);
    font-family: inherit;
    font-size: var(--fs-sm);
    line-height: 1;
    cursor: pointer;
    border-radius: 3px;
}

.deck-btn:hover {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.deck-footer {
    flex: 0 0 auto;
    padding: var(--sp-2) var(--sp-3);
    border-top: 1px solid var(--border);
    background: var(--surface-2);
}

.button-group {
    display: flex;
    gap: var(--sp-1);
    flex-wrap: wrap;
    align-items: center;
}

.button-group+.button-group {
    margin-top: var(--sp-1);
}

/* ==========================================================================
   Botones
   ========================================================================== */
.button,
.button-alt,
.button-warning {
    padding: 7px 12px;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    color: #fff;
    font-family: inherit;
    font-size: var(--fs-sm);
    transition: background-color var(--t-fast);
}

.button {
    background-color: var(--accent);
}

.button:hover {
    background-color: var(--accent-hover);
}

.button-alt {
    background-color: var(--alt);
}

.button-alt:hover {
    background-color: var(--alt-hover);
}

.button-warning {
    background-color: var(--warn);
}

.button-warning:hover {
    background-color: var(--warn-hover);
}

/* ==========================================================================
   Contenido / toolbar
   ========================================================================== */
.content {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    overflow-y: auto;
    padding: 0 var(--sp-4) var(--sp-5);
}

.toolbar {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--bg);
    padding: var(--sp-3) 0;
}

.toolbar-row {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    flex-wrap: wrap;
}

.toolbar-spacer {
    flex: 1 1 auto;
}

.result-count {
    font-size: var(--fs-sm);
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.active-chips {
    display: flex;
    flex-wrap: wrap;
    gap: var(--sp-1);
}

.active-chips:not(:empty) {
    margin-bottom: var(--sp-2);
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-1);
    padding: 3px 4px 3px 10px;
    border: 1px solid var(--accent);
    background: var(--accent-soft);
    border-radius: 14px;
    font-size: var(--fs-sm);
    color: var(--text);
}

.chip-remove {
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: var(--fs-md);
    line-height: 1;
    cursor: pointer;
    padding: 1px 5px;
    border-radius: 50%;
}

.chip-remove:hover {
    background: var(--warn);
    color: #fff;
}

.size-toggle {
    display: inline-flex;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--surface);
}

.size-toggle button {
    border: none;
    background: transparent;
    padding: 5px 10px;
    cursor: pointer;
    font-family: inherit;
    font-size: var(--fs-sm);
    color: var(--text-muted);
    transition: background-color var(--t-fast);
}

.size-toggle button+button {
    border-left: 1px solid var(--border);
}

.size-toggle button:hover {
    background: var(--surface-3);
}

.size-toggle button[aria-pressed="true"] {
    background: var(--accent);
    color: #fff;
}

.sort-wrap select {
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    font-family: inherit;
    font-size: var(--fs-sm);
    color: var(--text);
    cursor: pointer;
}

/* ==========================================================================
   Grid de cartas
   ========================================================================== */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(var(--card-min), 1fr));
    gap: var(--grid-gap);
    align-content: start;
}

.card {
    position: relative;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--sp-2);
    background: var(--surface);
    text-align: center;
    cursor: pointer;
    transition: transform var(--t-fast), box-shadow var(--t-fast), border-color var(--t-fast);
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-2);
}

.card.in-deck {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-soft);
}

/* ancla de los badges: se posicionan sobre la imagen, no sobre la carta */
.card-media {
    position: relative;
    display: block;
}

.card img {
    width: 100%;
    height: auto;
    aspect-ratio: 59 / 86;
    /* evita el layout shift al cargar imágenes diferidas */
    object-fit: cover;
    border-radius: var(--radius);
    background: var(--surface-3);
    display: block;
}

.card-count {
    position: absolute;
    top: var(--sp-2);
    right: var(--sp-2);
    background: var(--accent);
    color: #fff;
    font-size: var(--fs-xs);
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 10px;
    box-shadow: var(--shadow-1);
}

.card-info {
    margin-top: var(--sp-1);
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
}

.card-info .card-title {
    font-size: var(--fs-sm);
    line-height: 1.25;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.card-info .card-details {
    font-style: italic;
    font-size: var(--fs-xs);
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ==========================================================================
   Paginación
   ========================================================================== */
.pagination-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: var(--sp-1);
}

.pagination-controls:empty {
    display: none;
}

.pagination-bottom {
    margin-top: var(--sp-5);
}

.pagination-controls button {
    background-color: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 5px 10px;
    border-radius: var(--radius);
    cursor: pointer;
    font-family: inherit;
    font-size: var(--fs-sm);
}

.pagination-controls button:hover:not(:disabled) {
    background-color: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.pagination-controls button:disabled {
    opacity: .4;
    cursor: not-allowed;
}

.pagination-controls span {
    font-size: var(--fs-sm);
    color: var(--text-muted);
    white-space: nowrap;
    padding: 0 var(--sp-2);
}

/* ==========================================================================
   Mensajes
   ========================================================================== */
#importError {
    color: var(--danger);
    font-size: var(--fs-sm);
    margin: 0 0 var(--sp-2);
    display: none;
}

/* import parcial: no es un error, es un aviso de qué quedó afuera */
#importError.is-warning {
    color: var(--warn-hover);
}

#fileInput {
    display: none;
}

/* ==========================================================================
   Tooltip
   ========================================================================== */
.tooltip-container {
    position: relative;
    display: inline-block;
}

.tooltip {
    visibility: hidden;
    position: absolute;
    bottom: calc(100% + 10px);
    /* se despliega hacia la derecha: el icono quedó en el borde izquierdo
       del footer al pasar los botones a dos filas */
    left: 0;
    background-color: var(--text);
    color: #fff;
    padding: 8px 12px;
    border-radius: var(--radius);
    font-size: var(--fs-sm);
    width: 250px;
    word-wrap: break-word;
    text-align: left;
    line-height: 1.4;
    z-index: 9999;
    opacity: 0;
    transition: opacity var(--t-med);
    pointer-events: none;
}

.tooltip-container:hover .tooltip {
    visibility: visible;
    opacity: 1;
}

/* ==========================================================================
   Modales
   ========================================================================== */
.preview-container {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .8);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: var(--z-modal);
}

.preview-content {
    background: var(--surface);
    padding: var(--sp-4);
    border-radius: var(--radius-lg);
    max-width: 80%;
    max-height: 90%;
    overflow: auto;
}

.preview-grid {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    gap: var(--sp-1);
}

/* 10 columnas dejarían las cartas ilegibles en pantallas chicas */
@media (max-width: 899px) {
    .preview-grid {
        grid-template-columns: repeat(5, 1fr);
    }
}

.preview-card img {
    width: 100%;
    height: auto;
    aspect-ratio: 59 / 86;
    object-fit: cover;
    border-radius: 3px;
}

.close-preview {
    position: absolute;
    top: var(--sp-4);
    right: var(--sp-5);
    color: #fff;
    font-size: 32px;
    line-height: 1;
    cursor: pointer;
}

/* ==========================================================================
   Mazos guardados
   ========================================================================== */
.decks-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .55);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--sp-4);
    z-index: var(--z-modal);
}

.decks-modal[hidden] {
    display: none;
}

.decks-panel {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-2);
    width: min(920px, 100%);
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    padding: var(--sp-4);
}

.decks-header {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--sp-3);
}

.decks-header h2 {
    margin: 0;
    font-size: var(--fs-xl);
}

.decks-close {
    border: none;
    background: transparent;
    font-size: 28px;
    line-height: 1;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0 var(--sp-2);
    border-radius: var(--radius);
}

.decks-close:hover {
    background: var(--surface-3);
    color: var(--text);
}

.decks-status {
    margin: 0 0 var(--sp-3);
    color: var(--text-muted);
    font-style: italic;
    font-size: var(--fs-sm);
}

.decks-status[hidden] {
    display: none;
}

.decks-status.is-error {
    color: var(--danger);
    font-style: normal;
}

.decks-grid {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: var(--sp-3);
    align-content: start;
}

.deck-tile {
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
    padding: var(--sp-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface);
    font-family: inherit;
    text-align: left;
    cursor: pointer;
    transition: transform var(--t-fast), box-shadow var(--t-fast), border-color var(--t-fast);
}

.deck-tile:hover {
    transform: translateY(-2px);
    border-color: var(--accent);
    box-shadow: var(--shadow-2);
}

.deck-tile-art {
    aspect-ratio: 59 / 86;
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--surface-3);
}

.deck-tile-art img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.deck-tile-body {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
}

.deck-tile-name {
    font-size: var(--fs-md);
    font-weight: 600;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.deck-tile-author,
.deck-tile-meta {
    font-size: var(--fs-xs);
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.topbar-icon {
    width: 16px;
    height: 16px;
    display: block;
    margin: 0 auto;
}

.card-popup {
    position: fixed;
    display: none;
    gap: var(--sp-3);
    max-width: min(94vw, 620px);
    padding: var(--sp-3);
    background: rgba(20, 20, 22, .96);
    color: #fff;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-2);
    z-index: var(--z-popup);
    pointer-events: none;
}

.card-popup img {
    display: block;
    flex: 0 0 auto;
    max-height: 70vh;
    max-width: min(50vw, 260px);
    width: auto;
    height: auto;
    border-radius: var(--radius);
}

/* sólo imagen (click derecho en el grid): sin datos y más grande */
.card-popup.image-only .popup-side {
    display: none;
}

.card-popup.image-only img {
    max-height: 80vh;
    max-width: min(90vw, 420px);
}

/* el popup deja pasar el puntero salvo cuando persiste y tiene controles */
.card-popup.interactive {
    pointer-events: auto;
}

.popup-art {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
    align-items: center;
}

.artwork-nav {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
}

.artwork-nav[hidden] {
    display: none;
}

.artwork-btn {
    width: 26px;
    height: 26px;
    border: 1px solid rgba(255, 255, 255, .25);
    background: rgba(255, 255, 255, .08);
    color: #fff;
    font-size: var(--fs-lg);
    line-height: 1;
    border-radius: var(--radius);
    cursor: pointer;
}

.artwork-btn:hover {
    background: rgba(255, 255, 255, .2);
}

.artwork-count {
    font-size: var(--fs-sm);
    color: #a9adb4;
    font-variant-numeric: tabular-nums;
    min-width: 46px;
    text-align: center;
}

/* badge de artes alternativos: sólo aparece en las cartas que los tienen.
   Abajo a la izquierda, donde no compite con el contador de copias. */
.card-artworks {
    position: absolute;
    bottom: var(--sp-2);
    left: var(--sp-2);
    background: rgba(20, 20, 22, .82);
    color: #fff;
    font-size: var(--fs-xs);
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 10px;
    letter-spacing: .02em;
}

.popup-side {
    flex: 1 1 auto;
    min-width: 0;
    max-height: 70vh;
    overflow-y: auto;
}

.popup-title {
    margin: 0 0 var(--sp-2);
    font-size: var(--fs-lg);
    font-weight: 700;
    line-height: 1.2;
}

.popup-data {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 3px var(--sp-3);
    margin: 0;
    font-size: var(--fs-sm);
}

.popup-data dt {
    color: #a9adb4;
    white-space: nowrap;
}

.popup-data dd {
    margin: 0;
    overflow-wrap: anywhere;
}

/* ==========================================================================
   Panel de sintaxis
   ========================================================================== */
.syntax-content {
    position: absolute;
    top: var(--topbar-h);
    right: var(--sp-4);
    width: min(520px, calc(100vw - var(--sp-6)));
    max-height: 70vh;
    overflow-y: auto;
    padding: var(--sp-4);
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-2);
    font-size: var(--fs-sm);
    line-height: 1.5;
    z-index: var(--z-combo);
}

.syntax-content[hidden] {
    display: none;
}

.syntax-section {
    margin-bottom: var(--sp-3);
}

.syntax-section:last-child {
    margin-bottom: 0;
}

.syntax-section strong {
    display: block;
    margin-bottom: var(--sp-1);
    color: var(--text);
    font-size: 13px;
}

.syntax-item {
    margin-bottom: 2px;
    color: var(--text-soft);
}

.syntax-item code {
    background-color: var(--surface-3);
    padding: 1px 4px;
    border-radius: 3px;
    font-family: var(--mono);
    font-size: var(--fs-xs);
    color: var(--code);
}

/* ==========================================================================
   Drawer backdrop (solo < 1200px)
   ========================================================================== */
.drawer-backdrop {
    display: none;
}

/* ==========================================================================
   Responsive
   ========================================================================== */

/* lg — el mazo y los filtros aprietan un poco */
@media (max-width: 1599px) {
    :root {
        --sidebar-w: 280px;
    }
}

/* md — sidebar como drawer superpuesto */
@media (max-width: 1199px) {
    .drawer-toggle {
        display: block;
    }

    .sidebar {
        position: fixed;
        top: var(--topbar-h);
        bottom: 0;
        left: 0;
        transform: translateX(-100%);
        transition: transform var(--t-med);
        box-shadow: var(--shadow-2);
    }

    body.drawer-open .sidebar {
        transform: translateX(0);
    }

    .drawer-backdrop {
        display: block;
        position: fixed;
        inset: var(--topbar-h) 0 0 0;
        background: rgba(0, 0, 0, .4);
        z-index: 39;
    }

    .drawer-backdrop[hidden] {
        display: none;
    }

    .brand-name {
        display: none;
    }
}

/* sm — una columna, cartas más chicas */
@media (max-width: 899px) {
    :root {
        --sidebar-w: min(340px, 88vw);
        --card-min: 150px;
        --grid-gap: 10px;
    }

    .content {
        padding: 0 var(--sp-3) var(--sp-4);
    }

    .toolbar-row {
        gap: var(--sp-2);
    }
}

@media (max-width: 639px) {
    :root {
        --card-min: 130px;
    }

    .topbar {
        gap: var(--sp-2);
        padding: 0 var(--sp-2);
    }

    .brand {
        display: none;
    }
}
