/* =====================================================================
   DECK EDITOR — three-pane card editor
   Bob and Mariel Ward School of Filipino Languages
   =====================================================================
   Replaces the 11-column table and the separate Lesson Organizer tab.

   Layout: a fixed-height grid of rail | list | inspector. Fixed height is
   what lets the list virtualise — it needs a scroll container with a
   known viewport, which a page that grows to fit 894 rows cannot give it.

   Widths come from container queries on the editor itself, not the
   window: the list narrows when the inspector opens, when the rail opens,
   and when the browser chrome changes, and only one of those is a window
   resize.
   ===================================================================== */

.deck-editor {
    container-type: inline-size;
    container-name: deckeditor;
    display: flex;
    flex-direction: column;
    /* Tall enough to be worth virtualising, short enough to leave the page
       header visible. Falls back to a fixed height where dvh is unknown. */
    height: 720px;
    height: clamp(520px, calc(100dvh - 210px), 1100px);
    border: 1px solid var(--border-color, #E5E7EB);
    border-radius: 10px;
    overflow: hidden;
    background: var(--card-bg, #FFFFFF);
}

/* ---------------------------------------------------------------- top bar */

.de-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-color, #E5E7EB);
    background: var(--surface-2, #FAFAFB);
    flex: none;
    flex-wrap: wrap;
}

.de-topbar-left,
.de-topbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.de-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary, #111827);
    white-space: nowrap;
}

.de-crumb-sep {
    color: var(--text-secondary, #6B7280);
}

.de-lang-select {
    font: inherit;
    font-size: 14px;
    padding: 5px 8px;
    border: 1px solid var(--border-color, #E5E7EB);
    border-radius: 6px;
    background: var(--card-bg, #FFF);
    color: var(--text-primary, #111827);
    max-width: 180px;
}

/* --- save state --- */
.de-savestate {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-size: 12.5px;
    color: var(--text-secondary, #6B7280);
    white-space: nowrap;
}

.de-savedot {
    font-size: 8px;
    color: #10B981;
}

.de-savestate[data-state="saving"] .de-savedot { color: #F59E0B; }
.de-savestate[data-state="error"] .de-savedot { color: #EF4444; }
.de-savestate[data-state="error"] { color: #B91C1C; font-weight: 600; }

/* --- mode tabs --- */
.de-modes {
    display: inline-flex;
    border: 1px solid var(--border-color, #E5E7EB);
    border-radius: 8px;
    overflow: hidden;
    background: var(--card-bg, #FFF);
}

.de-mode-tab {
    font: inherit;
    font-size: 13px;
    padding: 6px 14px;
    border: 0;
    background: transparent;
    color: var(--text-secondary, #6B7280);
    cursor: pointer;
    white-space: nowrap;
}

.de-mode-tab + .de-mode-tab { border-left: 1px solid var(--border-color, #E5E7EB); }
.de-mode-tab:hover { background: var(--surface-2, #F3F4F6); }

.de-mode-tab.de-mode-active {
    background: var(--primary-color, #4F46E5);
    color: #FFF;
    font-weight: 600;
}

/* --- density --- */
.de-density-wrap { position: relative; }

.de-density-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    z-index: 40;
    min-width: 220px;
    padding: 6px;
    border: 1px solid var(--border-color, #E5E7EB);
    border-radius: 8px;
    background: var(--card-bg, #FFF);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.14);
}

.de-density-menu[hidden] { display: none; }

.de-density-opt {
    display: flex;
    align-items: baseline;
    gap: 8px;
    width: 100%;
    font: inherit;
    font-size: 13px;
    text-align: left;
    padding: 7px 9px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--text-primary, #111827);
    cursor: pointer;
}

.de-menu-group {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-secondary, #9CA3AF);
    padding: 8px 9px 4px;
}

.de-menu-group:first-child { padding-top: 4px; }

.de-density-opt:hover { background: var(--surface-2, #F3F4F6); }
.de-col-opt small { margin-left: auto; font-size: 10.5px; opacity: 0.75; }
.de-density-opt small { color: var(--text-secondary, #6B7280); }
.de-density-opt .fa-check { visibility: hidden; font-size: 11px; }
.de-density-opt.de-density-on .fa-check { visibility: visible; color: var(--primary-color, #4F46E5); }

/* ---------------------------------------------------------------- body */

.de-body {
    display: grid;
    /* The inspector grows into the width the content-sized word columns give
       back, but only so far. A bounded track is maximized before the 1fr list
       is fed, so an over-generous ceiling here silently narrows the list until
       it drops down a tier and loses the English and Status columns. 420px
       buys the third pane real room without costing the list a column. */
    grid-template-columns: 232px minmax(0, 1fr) minmax(340px, 420px);
    flex: 1;
    min-height: 0;
    position: relative;
}

.deck-editor.de-rail-closed .de-body { grid-template-columns: 0 minmax(0, 1fr) minmax(340px, 420px); }
.deck-editor.de-rail-closed .de-rail { display: none; }

/* ---------------------------------------------------------------- rail */

.de-rail {
    display: flex;
    flex-direction: column;
    min-height: 0;
    border-right: 1px solid var(--border-color, #E5E7EB);
    background: var(--surface-2, #FAFAFB);
}

.de-rail-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    padding: 10px 12px 6px;
    flex: none;
}

.de-rail-title {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-secondary, #6B7280);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.de-rail-list {
    list-style: none;
    margin: 0;
    padding: 0 6px 8px;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

.de-rail-empty {
    padding: 12px;
    font-size: 13px;
    color: var(--text-secondary, #6B7280);
}

.de-lesson {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 8px;
    border-radius: 7px;
    cursor: pointer;
    border-left: 3px solid transparent;
}

.de-lesson:hover { background: rgba(79, 70, 229, 0.07); }

.de-lesson.de-lesson-on {
    background: rgba(79, 70, 229, 0.12);
    border-left-color: var(--primary-color, #4F46E5);
}

.de-lesson.de-lesson-droptarget {
    background: rgba(16, 185, 129, 0.18);
    border-left-color: #10B981;
}

.de-lesson-main { flex: 1; min-width: 0; }

.de-lesson-line {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
}

.de-lesson-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary, #111827);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.de-lesson-count {
    font-size: 11.5px;
    color: var(--text-secondary, #6B7280);
    white-space: nowrap;
    flex: none;
}

.de-lesson-count em {
    font-style: normal;
    color: #B45309;
    margin-left: 3px;
}

.de-lesson-review { color: #7C3AED; }

.de-lesson-bar {
    margin-top: 5px;
    height: 3px;
    border-radius: 2px;
    background: var(--border-color, #E5E7EB);
    overflow: hidden;
}

.de-lesson-bar > span {
    display: block;
    height: 100%;
    background: #10B981;
}

.de-lesson-is-review .de-lesson-bar > span { background: #7C3AED; }

.de-lesson-grip {
    color: var(--text-secondary, #9CA3AF);
    cursor: grab;
    font-size: 11px;
}

.de-lesson-ghost { opacity: 0.4; }

.de-lesson-rename {
    opacity: 0;
    font-size: 11px;
    flex: none;
}

.de-lesson:hover .de-lesson-rename,
.de-lesson-rename:focus-visible { opacity: 1; }

.de-lesson-name-input {
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    width: 100%;
    padding: 2px 5px;
    border: 1px solid var(--primary-color, #4F46E5);
    border-radius: 5px;
    background: var(--card-bg, #FFF);
    color: var(--text-primary, #111827);
}

.de-rail-nodrag {
    margin: 0 8px 6px;
    padding: 7px 9px;
    font-size: 11.5px;
    border-radius: 6px;
    background: #FEF3C7;
    color: #92400E;
}

.de-rail-foot {
    flex: none;
    padding: 8px;
    border-top: 1px solid var(--border-color, #E5E7EB);
}

.de-rail-foot .btn { width: 100%; }

.de-rail-toggle {
    position: absolute;
    left: 0;
    top: 8px;
    z-index: 5;
    width: 18px;
    height: 30px;
    padding: 0;
    font-size: 10px;
    border: 1px solid var(--border-color, #E5E7EB);
    border-left: 0;
    border-radius: 0 6px 6px 0;
    background: var(--card-bg, #FFF);
    color: var(--text-secondary, #6B7280);
    cursor: pointer;
}

.deck-editor:not(.de-rail-closed) .de-rail-toggle { left: 232px; }

/* ---------------------------------------------------------------- list */

.de-list-pane {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    border-right: 1px solid var(--border-color, #E5E7EB);
}

.de-filterbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 12px;
    border-bottom: 1px solid var(--border-color, #E5E7EB);
    flex: none;
    flex-wrap: wrap;
}

.de-searchwrap {
    position: relative;
    flex: 1 1 200px;
    min-width: 130px;
}

.de-searchicon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 12px;
    color: var(--text-secondary, #9CA3AF);
    pointer-events: none;
}

.de-search {
    font: inherit;
    font-size: 13.5px;
    width: 100%;
    padding: 7px 10px 7px 30px;
    border: 1px solid var(--border-color, #E5E7EB);
    border-radius: 999px;
    background: var(--card-bg, #FFF);
    color: var(--text-primary, #111827);
}

.de-chips { display: flex; gap: 6px; flex-wrap: wrap; }

.de-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    padding: 4px 6px 4px 10px;
    border: 1px solid var(--primary-color, #4F46E5);
    border-radius: 999px;
    color: var(--primary-color, #4F46E5);
    background: rgba(79, 70, 229, 0.07);
    white-space: nowrap;
}

.de-chip-x {
    border: 0;
    background: transparent;
    color: inherit;
    cursor: pointer;
    font-size: 10px;
    padding: 0 2px;
    line-height: 1;
}

.de-filter-add-wrap { position: relative; }

.de-filter-add {
    font: inherit;
    font-size: 12px;
    padding: 5px 11px;
    border: 1px dashed var(--border-color, #D1D5DB);
    border-radius: 999px;
    background: transparent;
    color: var(--text-secondary, #6B7280);
    cursor: pointer;
    white-space: nowrap;
}

.de-filter-add:hover { border-color: var(--primary-color, #4F46E5); color: var(--primary-color, #4F46E5); }

.de-filter-menu {
    position: absolute;
    left: 0;
    top: calc(100% + 6px);
    z-index: 40;
    min-width: 190px;
    padding: 6px;
    border: 1px solid var(--border-color, #E5E7EB);
    border-radius: 8px;
    background: var(--card-bg, #FFF);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.14);
}

.de-filter-menu[hidden] { display: none; }

.de-filter-menu button {
    display: block;
    width: 100%;
    font: inherit;
    font-size: 13px;
    text-align: left;
    padding: 7px 9px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--text-primary, #111827);
    cursor: pointer;
}

.de-filter-menu button:hover { background: var(--surface-2, #F3F4F6); }

.de-count {
    font-size: 12.5px;
    color: var(--text-secondary, #6B7280);
    white-space: nowrap;
    margin-left: auto;
}

.de-send-rec {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    flex: none;
    font-size: 12px;
    border: 1px solid var(--border-color, #E5E7EB);
    border-radius: 6px;
    background: var(--card-bg, #FFF);
    color: var(--text-secondary, #6B7280);
    cursor: pointer;
}

.de-send-rec:hover { border-color: var(--primary-color, #4F46E5); color: var(--primary-color, #4F46E5); }

/* --- bulk bar --- */
.de-bulkbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-color, #E5E7EB);
    background: rgba(79, 70, 229, 0.07);
    flex: none;
    flex-wrap: wrap;
}

.de-bulkbar[hidden] { display: none; }

.de-bulk-count {
    font-size: 13px;
    font-weight: 600;
    color: var(--primary-color, #4F46E5);
    white-space: nowrap;
}

.de-bulk-clear {
    font: inherit;
    font-size: 12.5px;
    border: 0;
    background: transparent;
    color: var(--text-secondary, #6B7280);
    text-decoration: underline;
    cursor: pointer;
}

/* --- columns ---------------------------------------------------------
   The track list is computed in JS (deComputeColumns) from three inputs,
   in order of strictness: what the role allows, what the user has switched
   off in the View menu, and what the current width has room for. It
   arrives as --de-cols.

   Hand-written per-tier templates lived here until v0.7.83.0. They could
   not express a user turning a column off, and they drifted from the row's
   cell list — which is how the status chip ended up truncated at a width
   that had room for it. Cells are now built from the same list that builds
   the template, so the two cannot disagree.
   ------------------------------------------------------------------ */
.de-colhead,
.de-row {
    display: grid;
    grid-template-columns: var(--de-cols, 30px 34px 40px minmax(90px, 1.3fr) minmax(90px, 1.2fr) minmax(0, 1fr) 96px 158px 22px);
    align-items: center;
    gap: 8px;
    padding: 0 12px;
}

.deck-editor[data-tier="l"] .de-colhead,
.deck-editor[data-tier="l"] .de-row { gap: 7px; }

.deck-editor[data-tier="m"] .de-colhead,
.deck-editor[data-tier="m"] .de-row { gap: 7px; }

.deck-editor[data-tier="s"] .de-colhead,
.deck-editor[data-tier="s"] .de-row { gap: 6px; padding: 0 9px; }

.deck-editor[data-tier="xs"] .de-colhead,
.deck-editor[data-tier="xs"] .de-row { gap: 5px; padding: 0 7px; font-size: 13px; }

.deck-editor[data-tier="xs"] .de-thumb,
.deck-editor[data-tier="s"] .de-thumb { width: 26px; height: 26px; }

.de-colhead {
    /* Matches the row's severity rail so the header's tracks start at the
       same x as the row's. Without it every fixed column before the
       flexible one sat 3 px to the left of its data. */
    border-left: 3px solid transparent;
    height: 32px;
    flex: none;
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-secondary, #6B7280);
    border-bottom: 1px solid var(--border-color, #E5E7EB);
    background: var(--surface-2, #FAFAFB);
}

.de-col {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.de-col-seq { text-align: right; color: var(--text-secondary, #9CA3AF); font-variant-numeric: tabular-nums; }
.de-col-open { text-align: center; color: var(--text-secondary, #D1D5DB); font-size: 11px; }
.de-col-check { overflow: visible; }

/* --- scroller --- */
.de-scroll {
    position: relative;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
}

.de-scroll[hidden] { display: none; }
.de-scroll:focus-visible { outline: 2px solid var(--primary-color, #4F46E5); outline-offset: -2px; }

.de-spacer { width: 1px; }

/* Holds the slack the content-sized word columns give back, so the open
   chevron stays on the right edge. Deliberately empty and non-interactive. */
.de-col-filler {
    min-width: 0;
    pointer-events: none;
}
.de-rows { position: absolute; inset: 0; }

.de-group-head,
.de-row { position: absolute; left: 0; right: 0; }

.de-group-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 0 14px;
    font-size: 12px;
    background: var(--surface-2, #F3F4F6);
    border-top: 1px solid var(--border-color, #E5E7EB);
    border-bottom: 1px solid var(--border-color, #E5E7EB);
}

.de-group-title { font-weight: 700; color: var(--text-primary, #111827); }
.de-group-meta { color: var(--text-secondary, #6B7280); }

.de-row {
    border-bottom: 1px solid var(--border-color, #F3F4F6);
    border-left: 3px solid transparent;
    cursor: pointer;
    font-size: 13.5px;
    color: var(--text-primary, #111827);
    background: var(--card-bg, #FFF);
}

.de-row:hover { background: rgba(79, 70, 229, 0.05); }
.de-row-selected { background: rgba(79, 70, 229, 0.09); }

.de-row-active {
    background: rgba(79, 70, 229, 0.14);
    box-shadow: inset 0 0 0 1px var(--primary-color, #4F46E5);
}

/* The severity rail. It survives every tier, including the ones where
   the Status column itself is hidden. */
.de-row[data-status="complete-animated"],
.de-row[data-status="complete-static"] { border-left-color: #10B981; }
.de-row[data-status="partial"] { border-left-color: #F59E0B; }
.de-row[data-status="missing"] { border-left-color: #EF4444; }

.de-row-broken { background: rgba(239, 68, 68, 0.07); }
.de-broken-icon { color: #DC2626; margin-left: 6px; font-size: 11px; }

/* The specific asset whose file is not on disk, inside an already-marked
   row. Deeper than the row so it reads as "this one", and never the only
   signal — the row also carries a named icon. */
.de-row-broken .de-broken-part {
    background: rgba(239, 68, 68, 0.16);
    border-radius: 4px;
    outline: 1px solid rgba(220, 38, 38, 0.35);
}
.de-row-ghost { opacity: 0.4; }
/* Sits over the row's leading edge rather than in a track — the grid
   template is computed from the column list, and an extra child would
   push every cell one column to the right. */
.de-row-grip {
    position: absolute;
    left: 2px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary, #9CA3AF);
    cursor: grab;
    font-size: 11px;
}

.deck-editor[data-mode="order"] .de-row { padding-left: 18px; }
.deck-editor[data-mode="order"] .de-colhead { padding-left: 18px; }

.de-thumb {
    width: 34px;
    height: 34px;
    border-radius: 5px;
    object-fit: cover;
    background: var(--surface-2, #F3F4F6);
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.08);
}

.de-thumb-none {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary, #D1D5DB);
    font-size: 13px;
}

.de-col-word { font-weight: 600; }
.de-anim-dot { margin-left: 6px; font-size: 10px; color: #7C3AED; }
.de-col-eng { color: var(--text-secondary, #4B5563); font-weight: 400; }

.de-col-audio { display: flex; align-items: center; gap: 7px; }

.de-play {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    flex: none;
    font-size: 9px;
    border: 1px solid var(--border-color, #E5E7EB);
    border-radius: 50%;
    background: var(--card-bg, #FFF);
    color: var(--primary-color, #4F46E5);
    cursor: pointer;
}

.de-play:hover { background: var(--primary-color, #4F46E5); color: #FFF; }

.de-dur {
    font-size: 11.5px;
    color: var(--text-secondary, #9CA3AF);
    font-variant-numeric: tabular-nums;
}

.de-noaudio { color: #D97706; font-size: 12px; }

.de-status {
    display: inline-block;
    max-width: 100%;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.de-status-complete-animated,
.de-status-complete-static { background: #D1FAE5; color: #065F46; }
.de-status-partial { background: #FEF3C7; color: #92400E; }
.de-status-missing { background: #FEE2E2; color: #991B1B; }

/* --- empty state --- */
.de-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: var(--text-secondary, #6B7280);
}

.de-empty[hidden] { display: none; }
.de-empty i { font-size: 30px; opacity: 0.35; }
.de-empty p { margin: 0; font-size: 14px; }

/* ---------------------------------------------------------------- inspector */

.de-inspector {
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-height: 0;
    padding: 14px;
    overflow-y: auto;
    background: var(--surface-2, #FAFAFB);
}

.de-insp-empty {
    margin: auto;
    text-align: center;
    color: var(--text-secondary, #6B7280);
    padding: 20px;
}

.de-insp-empty i { font-size: 26px; opacity: 0.3; }
.de-insp-empty p { margin: 10px 0 0; font-size: 13.5px; }
.de-insp-hint { font-size: 12px !important; opacity: 0.8; }

.de-insp-head { display: flex; gap: 12px; align-items: flex-start; }

/* Only meaningful once the inspector overlays the list; the three-pane
   layout has nothing to close it back to. */
.de-insp-close {
    display: none;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    flex: none;
    font-size: 12px;
    border: 1px solid var(--border-color, #E5E7EB);
    border-radius: 6px;
    background: var(--card-bg, #FFF);
    color: var(--text-secondary, #6B7280);
    cursor: pointer;
}

/* The header thumbnail was removed: the PICTURE slot directly beneath it shows
   the same image larger, so the header only repeated it and cost the title a
   chunk of a narrow pane. */

.de-insp-titles { min-width: 0; flex: 1; }

.de-insp-word {
    margin: 0 0 5px;
    font-size: 17px;
    line-height: 1.25;
    color: var(--text-primary, #111827);
    word-break: break-word;
}

.de-insp-dash { color: var(--text-secondary, #9CA3AF); font-weight: 400; }
.de-insp-eng { font-weight: 400; color: var(--text-secondary, #4B5563); }

.de-insp-sub { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.de-insp-num { font-size: 12px; color: var(--text-secondary, #6B7280); }

/* --- media trio --- */
.de-insp-media {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.de-slot {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 9px;
    border: 1px solid var(--border-color, #E5E7EB);
    border-radius: 8px;
    background: var(--card-bg, #FFF);
}

.de-slot-audio { grid-column: 1 / -1; }

.de-slot-label {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--text-secondary, #6B7280);
}

.de-slot-body {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 96px;
    border-radius: 6px;
    background: var(--surface-2, #F9FAFB);
    overflow: hidden;
}

.de-slot-body img { max-width: 100%; max-height: 100%; object-fit: contain; }
.de-slot-none { font-size: 24px; color: var(--text-secondary, #D1D5DB); }

.de-slot-file {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    padding: 6px;
    font-size: 20px;
    color: #7C3AED;
    text-align: center;
}

.de-slot-file small { font-size: 10px; color: var(--text-secondary, #6B7280); word-break: break-all; }

.de-slot-btn {
    font: inherit;
    font-size: 12px;
    padding: 5px 10px;
    border: 1px solid var(--border-color, #E5E7EB);
    border-radius: 6px;
    background: var(--card-bg, #FFF);
    color: var(--text-primary, #111827);
    cursor: pointer;
}

.de-slot-btn:hover { border-color: var(--primary-color, #4F46E5); color: var(--primary-color, #4F46E5); }

.de-audio-rows { display: flex; flex-direction: column; gap: 6px; }

.de-audio-row { display: flex; align-items: center; gap: 8px; }

.de-audio-variant {
    flex: 1;
    min-width: 0;
    font-size: 13px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.de-audio-btn { flex: none; }

/* --- fields --- */
.de-insp-fields {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.de-fieldwrap { display: flex; flex-direction: column; gap: 4px; min-width: 0; }

.de-fieldlabel {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--text-secondary, #6B7280);
}

.de-field {
    font: inherit;
    font-size: 13.5px;
    width: 100%;
    padding: 7px 9px;
    border: 1px solid var(--border-color, #E5E7EB);
    border-radius: 6px;
    background: var(--card-bg, #FFF);
    color: var(--text-primary, #111827);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.de-field:focus {
    outline: none;
    border-color: var(--primary-color, #4F46E5);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

.de-field:disabled { background: var(--surface-2, #F3F4F6); color: var(--text-secondary, #6B7280); }

.de-field-saving { border-color: #F59E0B; }
.de-field-saved { border-color: #10B981; box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.18); }
.de-field-failed { border-color: #EF4444; box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.18); }

.de-fieldstatic {
    font-size: 13.5px;
    padding: 7px 9px;
    color: var(--text-secondary, #6B7280);
}

.de-note { resize: vertical; min-height: 46px; }

.de-insp-block { display: flex; flex-direction: column; gap: 6px; }

.de-cats { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

.de-cat {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    padding: 3px 5px 3px 10px;
    border-radius: 999px;
    background: rgba(79, 70, 229, 0.09);
    color: var(--primary-color, #4F46E5);
}

/* Shown only when a second field holds the same value, so an identical
   pair of chips explains itself instead of looking like a duplicate. */
.de-cat-field {
    font-style: normal;
    font-size: 9.5px;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    opacity: 0.7;
    margin-right: 4px;
}

.de-cat-x {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    padding: 0;
    font-size: 9px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: inherit;
    opacity: 0.6;
    cursor: pointer;
}

.de-cat-x:hover { opacity: 1; background: rgba(79, 70, 229, 0.2); }

.de-cat-none { font-size: 12.5px; color: var(--text-secondary, #9CA3AF); }

.de-cat-add {
    font: inherit;
    font-size: 12px;
    padding: 3px 10px;
    border: 1px dashed var(--border-color, #D1D5DB);
    border-radius: 999px;
    background: transparent;
    color: var(--text-secondary, #6B7280);
    cursor: pointer;
}

.de-cat-all {
    font: inherit;
    font-size: 11.5px;
    padding: 3px 4px;
    border: 0;
    background: transparent;
    color: var(--text-secondary, #6B7280);
    text-decoration: underline;
    cursor: pointer;
}

.de-insp-foot {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: auto;
    padding-top: 10px;
    border-top: 1px solid var(--border-color, #E5E7EB);
}

.de-navbtn {
    font: inherit;
    font-size: 12.5px;
    padding: 6px 10px;
    border: 1px solid var(--border-color, #E5E7EB);
    border-radius: 6px;
    background: var(--card-bg, #FFF);
    color: var(--text-primary, #111827);
    cursor: pointer;
}

.de-navbtn:hover { border-color: var(--primary-color, #4F46E5); }
.de-delete { margin-left: auto; }

/* =====================================================================
   The density ladder

   Columns are dropped only when they carry nothing unique. English is the
   last thing to go because it is the only field that identifies a card to
   an English speaker; Status goes early because the severity rail on the
   row's leading edge already says the same thing in colour.
   ===================================================================== */

/* L — the rail and the inspector give the list back some width. */
@container deckeditor (max-width: 1180px) {
    .de-body { grid-template-columns: 208px minmax(0, 1fr) minmax(310px, 370px); }
    .deck-editor:not(.de-rail-closed) .de-rail-toggle { left: 208px; }
}

/* M — three fixed panes stop fitting. Rather than squeeze the list to a
   few hundred pixels, the inspector lifts off and floats over it, and is
   shown only while a card is open. The list keeps the width. */
@container deckeditor (max-width: 980px) {
    .de-body { grid-template-columns: 190px minmax(0, 1fr); }
    .deck-editor.de-rail-closed .de-body { grid-template-columns: minmax(0, 1fr); }
    .deck-editor:not(.de-rail-closed) .de-rail-toggle { left: 190px; }
    .de-insp-media, .de-insp-fields { grid-template-columns: 1fr; }
    .de-list-pane { border-right: 0; }

    .de-inspector {
        position: absolute;
        z-index: 25;
        top: 0;
        bottom: 0;
        right: 0;
        width: min(340px, 92%);
        border-left: 1px solid var(--border-color, #E5E7EB);
        box-shadow: -6px 0 22px rgba(0, 0, 0, 0.16);
    }
    /* Nothing open — do not cover the list with an empty panel. */
    .deck-editor:not([data-insp="open"]) .de-inspector { display: none; }
    .de-insp-close { display: inline-flex; }
}

/* S — the rail floats too. */
@container deckeditor (max-width: 760px) {
    .de-body { grid-template-columns: minmax(0, 1fr); }
    .de-rail {
        position: absolute;
        z-index: 20;
        top: 0;
        bottom: 0;
        left: 0;
        width: 210px;
        box-shadow: 4px 0 18px rgba(0, 0, 0, 0.14);
    }
    .deck-editor:not(.de-rail-closed) .de-rail-toggle { left: 210px; }
}

/* XS — the top bar has to wrap before the list gives up any more. */
@container deckeditor (max-width: 560px) {
    .de-topbar { gap: 8px; }
    .de-title { font-size: 14px; }
    .de-savestate { order: 10; }
}

/* =====================================================================
   Dark theme
   ===================================================================== */

[data-theme="dark"] .deck-editor {
    border-color: #374151;
    background: #111827;
}

[data-theme="dark"] .de-topbar,
[data-theme="dark"] .de-colhead,
[data-theme="dark"] .de-rail,
[data-theme="dark"] .de-inspector { background: #0F172A; border-color: #374151; }

[data-theme="dark"] .de-group-head { background: #1F2937; border-color: #374151; }
[data-theme="dark"] .de-row { background: #111827; border-bottom-color: #1F2937; color: #E5E7EB; }
[data-theme="dark"] .de-row:hover { background: #1E293B; }
[data-theme="dark"] .de-row-selected { background: rgba(99, 102, 241, 0.2); }
[data-theme="dark"] .de-row-active { background: rgba(99, 102, 241, 0.3); }
[data-theme="dark"] .de-row-broken { background: rgba(239, 68, 68, 0.16); }
[data-theme="dark"] .de-row-broken .de-broken-part { background: rgba(239, 68, 68, 0.32); }

[data-theme="dark"] .de-search,
[data-theme="dark"] .de-field,
[data-theme="dark"] .de-lang-select,
[data-theme="dark"] .de-slot,
[data-theme="dark"] .de-play,
[data-theme="dark"] .de-slot-btn,
[data-theme="dark"] .de-navbtn,
[data-theme="dark"] .de-density-menu,
[data-theme="dark"] .de-filter-menu,
[data-theme="dark"] .de-rail-toggle {
    background: #1F2937;
    border-color: #374151;
    color: #E5E7EB;
}

[data-theme="dark"] .de-slot-body { background: #111827; }
[data-theme="dark"] .de-modes { background: #1F2937; border-color: #374151; }
[data-theme="dark"] .de-mode-tab { color: #9CA3AF; }
[data-theme="dark"] .de-mode-tab:hover { background: #374151; }
[data-theme="dark"] .de-mode-tab.de-mode-active { background: #6366F1; color: #FFF; }
[data-theme="dark"] .de-density-opt { color: #E5E7EB; }
[data-theme="dark"] .de-density-opt:hover { background: #374151; }
[data-theme="dark"] .de-lesson-label,
[data-theme="dark"] .de-group-title,
[data-theme="dark"] .de-insp-word { color: #F3F4F6; }
[data-theme="dark"] .de-lesson-bar { background: #374151; }
[data-theme="dark"] .de-thumb { background: #1F2937; }
[data-theme="dark"] .de-status-complete-animated,
[data-theme="dark"] .de-status-complete-static { background: rgba(16, 185, 129, 0.24); color: #6EE7B7; }
[data-theme="dark"] .de-status-partial { background: rgba(245, 158, 11, 0.24); color: #FCD34D; }
[data-theme="dark"] .de-status-missing { background: rgba(239, 68, 68, 0.24); color: #FCA5A5; }
[data-theme="dark"] .de-rail-nodrag { background: rgba(245, 158, 11, 0.2); color: #FCD34D; }
[data-theme="dark"] .de-savestate[data-state="error"] { color: #FCA5A5; }

/* =====================================================================
   Screen-reader-only helper (scoped here so the editor never depends on
   a utility class defined in another sheet)
   ===================================================================== */
.deck-editor .sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* =====================================================================
   Pickers

   Mounted on <body> with position: fixed. They cannot live inside the
   editor — .deck-editor is overflow:hidden so the list can virtualise,
   and a popover anchored within it would be clipped.
   ===================================================================== */

.de-pop {
    position: fixed;
    z-index: 1200;
    width: 300px;
    max-width: calc(100vw - 16px);
    padding: 8px;
    border: 1px solid var(--border-color, #E5E7EB);
    border-radius: 10px;
    background: var(--card-bg, #FFF);
    box-shadow: 0 14px 40px rgba(0, 0, 0, 0.18);
    font-size: 13px;
    color: var(--text-primary, #111827);
}

.de-pop-head {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--text-secondary, #6B7280);
    padding: 2px 4px 8px;
}

.de-pop-search { padding: 0 2px 6px; }

.de-pop-input {
    font: inherit;
    font-size: 13px;
    width: 100%;
    padding: 6px 9px;
    border: 1px solid var(--border-color, #E5E7EB);
    border-radius: 6px;
    background: var(--card-bg, #FFF);
    color: var(--text-primary, #111827);
}

.de-pop-input:focus {
    outline: none;
    border-color: var(--primary-color, #4F46E5);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

.de-pop-list {
    list-style: none;
    margin: 0;
    padding: 0;
    max-height: 260px;
    overflow-y: auto;
}

.de-pop-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    width: 100%;
    font: inherit;
    font-size: 13px;
    text-align: left;
    padding: 7px 9px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--text-primary, #111827);
    cursor: pointer;
}

.de-pop-row:hover,
.de-pop-row:focus-visible { background: rgba(79, 70, 229, 0.1); outline: none; }

.de-pop-main { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.de-pop-meta { flex: none; font-size: 11.5px; color: var(--text-secondary, #9CA3AF); }

.de-pop-empty,
.de-pop-note {
    padding: 8px 9px;
    margin: 0;
    font-size: 12px;
    color: var(--text-secondary, #6B7280);
}

.de-pop-note { border-top: 1px solid var(--border-color, #E5E7EB); margin-top: 6px; }

.de-pop-fieldrow { display: flex; align-items: center; gap: 8px; padding: 0 2px 8px; }

.de-pop-label {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-secondary, #6B7280);
    flex: none;
}

.de-pop-select {
    font: inherit;
    font-size: 13px;
    flex: 1;
    padding: 5px 8px;
    border: 1px solid var(--border-color, #E5E7EB);
    border-radius: 6px;
    background: var(--card-bg, #FFF);
    color: var(--text-primary, #111827);
}

.de-pop-new { padding: 8px 2px 2px; margin-top: 6px; border-top: 1px solid var(--border-color, #E5E7EB); }
.de-pop-newrow { display: flex; gap: 6px; margin-top: 4px; }
.de-pop-newrow .de-pop-input { flex: 1; min-width: 0; }
.de-pop-apply { flex: none; font-size: 12px; padding: 5px 12px; }

.de-pop-warn {
    margin: 6px 0 0;
    padding: 6px 8px;
    font-size: 11.5px;
    border-radius: 6px;
    background: #FEF3C7;
    color: #92400E;
}

.de-pop-warn[hidden] { display: none; }

.de-pop-foot { padding-top: 6px; margin-top: 6px; border-top: 1px solid var(--border-color, #E5E7EB); }

.de-pop-scope {
    margin: 0 2px 8px;
    padding: 8px 9px;
    font-size: 12.5px;
    line-height: 1.45;
    border-radius: 6px;
    background: var(--surface-2, #F9FAFB);
    color: var(--text-secondary, #4B5563);
}

.de-pop-scope strong { color: var(--text-primary, #111827); font-size: 13.5px; }
.de-pop-url { font-size: 11.5px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.de-pop-actions { display: flex; gap: 6px; margin-top: 8px; }
.de-pop-actions .btn { flex: 1; font-size: 12.5px; padding: 6px 10px; }

.de-pop-clear {
    font: inherit;
    font-size: 12.5px;
    display: flex;
    align-items: center;
    gap: 7px;
    width: 100%;
    padding: 6px 9px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: #B91C1C;
    cursor: pointer;
}

.de-pop-clear:hover { background: rgba(239, 68, 68, 0.1); }

.de-pop .sr-only {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

[data-theme="dark"] .de-pop {
    background: #1F2937;
    border-color: #374151;
    color: #E5E7EB;
}

[data-theme="dark"] .de-pop-row { color: #E5E7EB; }
[data-theme="dark"] .de-pop-row:hover { background: rgba(99, 102, 241, 0.24); }
[data-theme="dark"] .de-pop-input,
[data-theme="dark"] .de-pop-select { background: #111827; border-color: #374151; color: #E5E7EB; }
[data-theme="dark"] .de-pop-warn { background: rgba(245, 158, 11, 0.2); color: #FCD34D; }
[data-theme="dark"] .de-pop-scope { background: #111827; color: #9CA3AF; }
[data-theme="dark"] .de-pop-scope strong { color: #F3F4F6; }
[data-theme="dark"] .de-send-rec { background: #1F2937; border-color: #374151; color: #9CA3AF; }
[data-theme="dark"] .de-cat-x:hover { background: rgba(99, 102, 241, 0.3); }

/* Motion */
@media (prefers-reduced-motion: reduce) {
    .de-field { transition: none; }
}
