/* ═══════════════════════════════════════════════════════════════
   Aibo Adventures — Stories Browser & Visual Novel Player
   ═══════════════════════════════════════════════════════════════ */

/* ── Design tokens ─────────────────────────────────────────────── */
:root {
    --story-purple: #b48aff;
    --story-purple-dim: rgba(180, 138, 255, 0.15);
    --story-pink: #ff8ab4;
    --story-gold: #ffd76e;
    --story-surface: rgba(20, 20, 28, 0.92);
    --story-border: rgba(255, 255, 255, 0.08);
    --story-text: #f0f0f2;
    --story-muted: #9898a6;
}

/* ── Stories Browser ─────────────────────────────────────────── */

.stories-browser {
    min-height: 100vh;
    background: #0e0e14;
    color: var(--story-text);
    padding-bottom: 4rem;
    margin-top: -1.1rem; /* cancel the global .content padding-top so the hero sits flush against the top edge */
}

/* ── Filters ─────────────────────────────────────────────────── */

.stories-filters {
    display: flex;
    gap: 0.5rem;
    padding: 1.25rem 2rem;
    flex-wrap: wrap;
}

/* ── Section headings ────────────────────────────────────────── */

.stories-section {
    padding: 0 2rem;
    margin-bottom: 2rem;
}

/* ── Grid ────────────────────────────────────────────────────── */

.stories-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.25rem;
}

/* ── Story Card ──────────────────────────────────────────────── */

.story-card {
    position: relative;
    border-radius: 1.25rem;
    overflow: hidden;
    background: #16161f;
    border: 1px solid var(--story-border);
    transition: transform 0.2s, box-shadow 0.2s;
    cursor: pointer;
}

.story-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 40px rgba(0,0,0,0.5);
}

.story-card__level {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    padding: 0.15rem 0.55rem;
    border-radius: 99px;
}

.story-card__level--n5 {
    background: rgba(100, 200, 120, 0.15);
    color: #64c878;
    border: 1px solid rgba(100, 200, 120, 0.3);
}

.story-card__level--n4 {
    background: rgba(100, 160, 255, 0.15);
    color: #64a0ff;
    border: 1px solid rgba(100, 160, 255, 0.3);
}

.story-card__level--n3 {
    background: rgba(116, 179, 247, 0.15);
    color: #74b3f7;
    border: 1px solid rgba(116, 179, 247, 0.3);
}

.story-card__level--n2 {
    background: rgba(244, 162, 97, 0.15);
    color: #f4a261;
    border: 1px solid rgba(244, 162, 97, 0.3);
}

.story-card__level--n1 {
    background: rgba(248, 81, 73, 0.15);
    color: #f85149;
    border: 1px solid rgba(248, 81, 73, 0.3);
}

/* ══════════════════════════════════════════════════════════════
   Visual Novel Player
   ══════════════════════════════════════════════════════════════ */

.player {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    background: #08080e;
    outline: none;
    z-index: 200;
    cursor: pointer;
    /* Rapid clicking (advancing dialogue fast) can otherwise trigger the browser's
       native text/image drag-selection highlight across sprites and dialogue text. */
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

/* ── Top bar ─────────────────────────────────────────────────── */

.player-topbar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 1.25rem;
    background: rgba(10,10,16,0.9);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--story-border);
    z-index: 10;
    flex-shrink: 0;
}

.player-topbar__back {
    color: var(--story-muted);
    font-size: 1.1rem;
    text-decoration: none;
    line-height: 1;
    padding: 0.25rem;
    flex-shrink: 0;
    cursor: pointer;
}

.player-topbar__back:hover { color: var(--story-text); }

.player-topbar__title {
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--story-text);
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.player-topbar__progress {
    font-size: 0.75rem;
    color: var(--story-muted);
    flex-shrink: 0;
}

.player-topbar__mood {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.75rem;
    color: var(--story-muted);
    flex-shrink: 0;
}

.player-topbar__mood-name { font-weight: 600; }

.player-topbar__toggles {
    display: flex;
    gap: 0.35rem;
    flex-shrink: 0;
}

.player-toggle {
    background: transparent;
    border: 1px solid var(--story-border);
    color: var(--story-muted);
    font-size: 0.7rem;
    font-weight: 700;
    padding: 0.15rem 0.45rem;
    border-radius: 0.4rem;
    cursor: pointer;
    transition: all 0.15s;
}

.player-toggle.active {
    background: var(--story-purple-dim);
    border-color: rgba(180,138,255,0.4);
    color: var(--story-purple);
}

/* ── Scene background ────────────────────────────────────────── */

.player-scene {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: linear-gradient(135deg, #0f1520 0%, #1a0f2e 100%);
    background-color: #0a0a10;
    /* Scene images are preloaded before this element mounts (see StoryPlayer's
       preload pass), so this fade is a deliberate transition, not a loading wait —
       it replaces the old hard cut/flash between backgrounds. Only fires on scene
       change: this element is @key'd to the scene id, so it remounts on scene
       boundaries but stays put across dialogue-line advances within a scene. */
    animation: scene-fade-in 0.35s ease;
}

@keyframes scene-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* Scene-specific backgrounds */
.player-scene--tokyo_apartment_morning {
    background-image: url('/img/backgrounds/tokyo_apartment_morning.png');
    background-size: cover;
    background-position: center;
}
.player-scene--tokyo_street_morning {
    background-image: url('/img/backgrounds/tokyo_street_morning.png');
    background-size: cover;
    background-position: center;
}
.player-scene--tokyo_cafe_interior {
    background-image: url('/img/backgrounds/tokyo_cafe_interior.png');
    background-size: cover;
    background-position: center;
}
.player-scene--shibuya_street_daytime {
    background-image: url('/img/backgrounds/shibuya_street_daytime.png');
    background-size: cover;
    background-position: center;
}
.player-scene--hokkori_cafe_interior {
    background-image: url('/img/backgrounds/hokkori_cafe_interior.png');
    background-size: cover;
    background-position: center;
}

/* Dark vignette so dialogue box area is readable */
.player-scene::before {
    content: '';
    position: absolute;
    inset: 0;
    background:
        linear-gradient(to bottom, rgba(0,0,0,0.15) 0%, rgba(0,0,0,0.0) 40%, rgba(0,0,0,0.55) 100%);
    pointer-events: none;
    z-index: 1;
}

/* ── Scene actor (NPC sprite) ─────────────────────────────────── */

.player-actor {
    position: fixed;
    bottom: -3.5rem;
    z-index: 3;
    display: flex;
    align-items: flex-end;
    pointer-events: none;
}

/* Positioning variants */
.player-actor--left {
    left: 3rem;
    right: auto;
    transform: scaleX(-1); /* mirror so character faces right */
}

.player-actor--center {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
}

.player-actor--right {
    right: 3rem;
    left: auto;
}

.player-actor__img {
    height: 90vh;
    max-height: 680px;
    width: auto;
    object-fit: contain;
    object-position: bottom;
    filter: drop-shadow(0 4px 24px rgba(0,0,0,0.5));
    transition: opacity 0.25s ease;
    -webkit-user-drag: none;
    user-drag: none;
    pointer-events: none;
}

/* ── Narration overlay ───────────────────────────────────────── */

.player-narration {
    position: absolute;
    top: 1.5rem;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(10,10,16,0.75);
    backdrop-filter: blur(8px);
    border: 1px solid var(--story-border);
    border-radius: 0.75rem;
    padding: 0.6rem 1.25rem;
    font-size: 0.8rem;
    color: var(--story-muted);
    font-style: italic;
    max-width: 70%;
    text-align: center;
    z-index: 3;
}

/* ── Player bottom ───────────────────────────────────────────── */

.player-bottom {
    flex-shrink: 0;
    z-index: 10;
}

/* ── Dialogue box ────────────────────────────────────────────── */

.dialogue-box {
    background: rgba(12,12,20,0.72);
    backdrop-filter: blur(16px);
    border-top: 1px solid var(--story-border);
    padding: 1.25rem 1.5rem 1rem;
    min-height: 160px;
    position: relative;
}

.dialogue-box--narrator,
.dialogue-box--npc {
    border-top-color: rgba(255,255,255,0.06);
}

.dialogue-box--yuki { border-top-color: rgba(255,138,180,0.3); }
.dialogue-box--ren  { border-top-color: rgba(100,160,255,0.3); }

.dialogue-box__narration {
    font-size: 0.78rem;
    color: var(--story-muted);
    font-style: italic;
    margin-bottom: 0.6rem;
}

.dialogue-box__speaker {
    display: block;
    width: fit-content;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--story-purple);
    background: var(--story-purple-dim);
    border: 1px solid rgba(180,138,255,0.2);
    padding: 0.15rem 0.65rem;
    border-radius: 99px;
    margin-bottom: 0.65rem;
}

/* Sit on the same side as whoever's actually speaking, so the badge never sits
   under the player's own Aibo sprite (left) while someone else is talking. */
.dialogue-box__speaker--right {
    margin-left: auto;
}

.dialogue-box__speaker--center {
    margin-left: auto;
    margin-right: auto;
}

.dialogue-box--yuki .dialogue-box__speaker { color: var(--story-pink); background: rgba(255,138,180,0.1); border-color: rgba(255,138,180,0.25); }
.dialogue-box--ren  .dialogue-box__speaker { color: #64a0ff;            background: rgba(100,160,255,0.1); border-color: rgba(100,160,255,0.25); }

.dialogue-box__japanese {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--story-text);
    line-height: 1.5;
    margin-bottom: 0.3rem;
    font-family: 'Noto Sans JP', 'Hiragino Sans', sans-serif;
}

.dialogue-box__romaji {
    font-size: 0.82rem;
    color: #b8b8c8;
    margin-bottom: 0.25rem;
    font-style: italic;
}

.dialogue-box__english {
    font-size: 0.82rem;
    color: var(--story-muted);
    margin-bottom: 0.5rem;
}

.dialogue-box__flavor {
    background: rgba(255,215,110,0.08);
    border: 1px solid rgba(255,215,110,0.2);
    border-radius: 0.6rem;
    padding: 0.5rem 0.75rem;
    font-size: 0.8rem;
    color: var(--story-gold);
    margin-top: 0.5rem;
}

.dialogue-box__hint {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.25rem;
    margin-top: 0.75rem;
}

.dialogue-box__hint-text {
    font-size: 0.7rem;
    color: rgba(152,152,166,0.5);
}

.dialogue-box__hint-arrow {
    font-size: 0.65rem;
    color: rgba(180,138,255,0.5);
    animation: blink 1.4s ease-in-out infinite;
}

@keyframes blink {
    0%, 100% { opacity: 0.4; }
    50%       { opacity: 1; }
}

/* ── Choice panel ────────────────────────────────────────────── */

.choice-panel {
    background: rgba(12,12,20,0.78);
    backdrop-filter: blur(16px);
    border-top: 1px solid var(--story-border);
    padding: 1.25rem 1.5rem;
}

.choice-panel__label {
    font-size: 0.75rem;
    color: var(--story-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 0.75rem;
}

.choice-panel__buttons {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.choice-btn {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    width: 100%;
    padding: 0.75rem 1rem;
    background: rgba(180,138,255,0.06);
    border: 1px solid rgba(180,138,255,0.2);
    border-radius: 0.875rem;
    cursor: pointer;
    text-align: left;
    transition: all 0.15s;
}

.choice-btn:hover {
    background: rgba(180,138,255,0.14);
    border-color: rgba(180,138,255,0.45);
    transform: translateX(3px);
}

.choice-btn:focus-visible {
    outline: 2px solid var(--story-purple);
    outline-offset: 2px;
}

.choice-btn__jp {
    font-size: 1rem;
    font-weight: 700;
    color: var(--story-text);
    font-family: 'Noto Sans JP', 'Hiragino Sans', sans-serif;
}

.choice-btn__romaji {
    font-size: 0.78rem;
    color: #b8b8c8;
    font-style: italic;
}

.choice-btn__en {
    font-size: 0.78rem;
    color: var(--story-muted);
}

/* ── Flavor text overlay ─────────────────────────────────────── */

.player-flavor {
    background: rgba(12,12,20,0.78);
    backdrop-filter: blur(16px);
    border-top: 1px solid rgba(255,215,110,0.2);
    padding: 1.25rem 1.5rem;
    text-align: center;
}

.player-flavor p {
    font-size: 1rem;
    color: var(--story-gold);
    margin: 0 0 0.5rem;
}

/* Whole panel is clickable (via .player's onclick) — this is just a hint, not a button. */
.player-flavor__hint {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
}

.player-flavor__hint-text {
    font-size: 0.7rem;
    color: rgba(255,215,110,0.5);
}

.player-flavor__hint-arrow {
    font-size: 0.65rem;
    color: rgba(255,215,110,0.5);
    animation: blink 1.4s ease-in-out infinite;
}

/* ── Aibo sprite component ───────────────────────────────────── */

.aibo-sprite {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
    transition: filter 0.4s;
}

.aibo-sprite__img {
    width: 120px;
    height: auto;
    filter: drop-shadow(0 8px 24px rgba(0,0,0,0.6));
    transition: filter 0.4s, transform 0.3s;
}

.aibo-sprite--happy     .aibo-sprite__img { filter: drop-shadow(0 8px 24px rgba(0,0,0,0.6)) brightness(1.05); }
.aibo-sprite--excited   .aibo-sprite__img { filter: drop-shadow(0 12px 28px rgba(180,138,255,0.4)) brightness(1.1); }
.aibo-sprite--energetic .aibo-sprite__img { filter: drop-shadow(0 12px 28px rgba(100,200,255,0.3)) brightness(1.08); }
.aibo-sprite--thoughtful .aibo-sprite__img { filter: drop-shadow(0 8px 20px rgba(0,0,0,0.7)) brightness(0.95); }
.aibo-sprite--gentle    .aibo-sprite__img { filter: drop-shadow(0 8px 24px rgba(255,138,180,0.3)) brightness(1.02); }
.aibo-sprite--curious   .aibo-sprite__img { filter: drop-shadow(0 8px 20px rgba(255,215,110,0.2)) brightness(1.0); }

.aibo-sprite__mood-badge {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    background: rgba(10,10,16,0.8);
    backdrop-filter: blur(6px);
    border: 1px solid var(--story-border);
    border-radius: 99px;
    padding: 0.2rem 0.6rem;
    font-size: 0.7rem;
    color: var(--story-muted);
    font-weight: 600;
}

.aibo-sprite__mood-icon { font-size: 0.75rem; }

/* ── Loading & Error ─────────────────────────────────────────── */

.player-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    gap: 1rem;
    color: var(--story-muted);
}

.player-loading__spinner {
    width: 36px;
    height: 36px;
    border: 3px solid rgba(180,138,255,0.2);
    border-top-color: var(--story-purple);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.player-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    gap: 1rem;
    color: var(--story-muted);
}

.player-error a {
    color: var(--story-purple);
    text-decoration: none;
    font-weight: 600;
}

/* ── Completion screen ───────────────────────────────────────── */

.player-complete {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: radial-gradient(ellipse 80% 80% at 50% 50%, rgba(180,138,255,0.1) 0%, #08080e 60%);
    padding: 2rem;
    outline: none;
}

.player-complete__card {
    background: rgba(16,16,24,0.95);
    border: 1px solid rgba(180,138,255,0.2);
    border-radius: 1.5rem;
    padding: 2.5rem 2rem;
    max-width: 480px;
    width: 100%;
    text-align: center;
    box-shadow: 0 24px 80px rgba(0,0,0,0.6), 0 0 0 1px rgba(180,138,255,0.05);
}

.player-complete__aibo {
    display: flex;
    justify-content: center;
    margin-bottom: 1.5rem;
}

.player-complete__title {
    font-size: 1.6rem;
    font-weight: 800;
    background: linear-gradient(135deg, #fff 30%, var(--story-purple));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin: 0 0 0.25rem;
}

.player-complete__story-name {
    color: var(--story-muted);
    font-size: 0.9rem;
    margin: 0 0 1.5rem;
}

.player-complete__xp {
    background: rgba(180,138,255,0.06);
    border: 1px solid rgba(180,138,255,0.15);
    border-radius: 1rem;
    padding: 1rem 1.25rem;
    margin-bottom: 1.25rem;
    text-align: left;
}

.player-complete__xp-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.875rem;
    color: var(--story-muted);
    padding: 0.25rem 0;
}

.player-complete__xp-row--bonus { color: var(--story-gold); }

.player-complete__xp-total {
    display: flex;
    justify-content: space-between;
    font-size: 1rem;
    font-weight: 700;
    color: var(--story-text);
    border-top: 1px solid var(--story-border);
    margin-top: 0.5rem;
    padding-top: 0.5rem;
}

.player-complete__levelup {
    background: linear-gradient(135deg, rgba(180,138,255,0.15), rgba(255,215,110,0.1));
    border: 1px solid rgba(180,138,255,0.3);
    border-radius: 0.75rem;
    padding: 0.6rem 1rem;
    font-size: 0.875rem;
    font-weight: 700;
    color: var(--story-purple);
    margin-bottom: 1.25rem;
}

.player-complete__actions {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
}

.player-complete__btn {
    padding: 0.7rem 1.5rem;
    border-radius: 0.875rem;
    font-size: 0.875rem;
    font-weight: 700;
    text-decoration: none;
    transition: all 0.15s;
}

.player-complete__btn--secondary {
    background: transparent;
    border: 1px solid var(--story-border);
    color: var(--story-muted);
}

.player-complete__btn--secondary:hover {
    background: rgba(255,255,255,0.05);
    color: var(--story-text);
}

.player-complete__btn--primary {
    background: linear-gradient(135deg, rgba(180,138,255,0.25), rgba(255,138,180,0.15));
    border: 1px solid rgba(180,138,255,0.4);
    color: var(--story-purple);
}

.player-complete__btn--primary:hover {
    background: linear-gradient(135deg, rgba(180,138,255,0.35), rgba(255,138,180,0.25));
}

/* ── Vocab words in Japanese text ───────────────────────────── */

.japanese-text { display: inline; }

.vocab-word-wrap {
    position: relative;
    display: inline-block;
}

.vocab-word {
    cursor: pointer;
    border-bottom: 2px solid rgba(180, 138, 255, 0.5);
    color: #e0d0ff;
    transition: color 0.1s, border-color 0.1s, background 0.1s;
    border-radius: 2px;
    padding: 0 1px;
    outline: none;
}

.vocab-word:hover,
.vocab-word:focus-visible {
    color: #fff;
    border-bottom-color: var(--story-purple);
    background: rgba(180, 138, 255, 0.12);
}

.vocab-word--story {
    color: #ffe4a8;
    border-bottom-color: rgba(255, 190, 92, 0.72);
}

.vocab-word--story:hover,
.vocab-word--story:focus-visible {
    border-bottom-color: #ffbe5c;
    background: rgba(255, 190, 92, 0.12);
}

/* ── Word popover (hover card, anchored to the word) ──────────── */

.word-popover {
    position: absolute;
    bottom: calc(100% + 0.6rem);
    /* Horizontal position (centered + edge-clamp shift) lives in `left`, not
       `transform`, on purpose: `left` isn't in the transition list below, so
       the edge-clamp correction applied by storyPlayer.js snaps in instantly.
       If it were animated along with the reveal transition, the card would
       visibly drift through the wrong (off-screen) position for ~120ms on
       every hover before settling. */
    left: calc(50% + var(--popover-shift, 0px));
    transform: translateX(-50%) translateY(4px);
    z-index: 250;
    width: 260px;
    max-width: min(260px, 88vw);
    background: rgba(16, 14, 26, 0.98);
    border: 1px solid rgba(180, 138, 255, 0.3);
    border-radius: 1rem;
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(180, 138, 255, 0.08);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.12s ease, transform 0.12s ease, visibility 0.12s;
    cursor: default;
    white-space: normal;
}

/* Scroll/height-cap live on this inner wrapper, not .word-popover itself:
   `overflow-y: auto` clips anything positioned outside its own box — which
   is exactly how the ::after "bridge" below works (it sits below/above the
   box on purpose, to keep the pointer inside the hover chain while crossing
   the gap to the card). Putting overflow on .word-popover clipped that
   bridge away, breaking hover the moment the cursor left the word — the
   card would vanish before you could reach it. */
.word-popover__inner {
    max-height: min(80vh, 420px);
    overflow-y: auto;
    overflow-wrap: break-word;
    padding: 1.1rem 1.1rem 1rem;
}

/* Flipped variant: not enough room above the word, so the card opens
   downward instead — set by JS (storyPlayer.js) once it measures overflow. */
.word-popover--flip {
    bottom: auto;
    top: calc(100% + 0.6rem);
    transform: translateX(-50%) translateY(-4px);
}

/* Invisible bridge filling the gap between the word and the popover,
   so the pointer stays over the hover chain while crossing it. */
.word-popover::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: -0.6rem;
    height: 0.6rem;
}

.word-popover--flip::after {
    bottom: auto;
    top: -0.6rem;
}

.vocab-word-wrap:hover .word-popover,
.vocab-word-wrap:focus-within .word-popover {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateX(-50%) translateY(0);
}

/* ── Vocab chips below the line ──────────────────────────────── */

.dialogue-box__vocab {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-top: 0.65rem;
    padding-top: 0.6rem;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.vocab-chip {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    background: rgba(180, 138, 255, 0.07);
    border: 1px solid rgba(180, 138, 255, 0.18);
    border-radius: 0.5rem;
    padding: 0.25rem 0.6rem;
    cursor: pointer;
    font-size: 0.78rem;
    transition: all 0.13s;
    color: var(--story-text);
}

.vocab-chip:hover {
    background: rgba(180, 138, 255, 0.16);
    border-color: rgba(180, 138, 255, 0.4);
}

.vocab-chip--known {
    border-color: rgba(100, 200, 120, 0.3);
    background: rgba(100, 200, 120, 0.06);
}

.vocab-chip--known:hover {
    background: rgba(100, 200, 120, 0.14);
}

.vocab-chip__jp {
    font-family: 'Noto Sans JP', 'Hiragino Sans', sans-serif;
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--story-purple);
}

.vocab-chip--known .vocab-chip__jp { color: #64c878; }

.vocab-chip--story {
    border-color: rgba(255, 190, 92, 0.32);
    background: rgba(255, 190, 92, 0.07);
}

.vocab-chip--story:hover {
    border-color: rgba(255, 190, 92, 0.55);
    background: rgba(255, 190, 92, 0.14);
}

.vocab-chip--story .vocab-chip__jp { color: #ffcf7d; }

.vocab-chip__en {
    color: var(--story-muted);
    font-size: 0.72rem;
}

/* ── Word card overlay ───────────────────────────────────────── */

.word-card-overlay {
    position: fixed;
    inset: 0;
    z-index: 300;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 1rem;
    animation: fadeIn 0.15s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.word-card {
    background: rgba(16, 14, 26, 0.98);
    border: 1px solid rgba(180, 138, 255, 0.25);
    border-radius: 1.25rem 1.25rem 1rem 1rem;
    padding: 1.75rem 1.5rem 1.5rem;
    width: 100%;
    max-width: 480px;
    /* Cap the whole card to the viewport; the close button stays put and
       only .word-card__scroll below scrolls, so it's never carried out of
       view by long content. */
    max-height: 90vh;
    position: relative;
    animation: slideUp 0.18s ease;
    box-shadow: 0 -8px 48px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(180, 138, 255, 0.08);
}

.word-card__scroll {
    /* Content can grow (long translations, more meanings, future fields) —
       scroll internally instead of spilling past the card or getting
       clipped by the overlay. */
    max-height: calc(90vh - 1.75rem - 1.5rem);
    overflow-y: auto;
    overflow-wrap: break-word;
}

@keyframes slideUp {
    from { transform: translateY(24px); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
}

.word-card__close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--story-border);
    border-radius: 50%;
    width: 28px;
    height: 28px;
    color: var(--story-muted);
    font-size: 0.75rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.13s;
}

.word-card__close:hover {
    background: rgba(255, 255, 255, 0.12);
    color: var(--story-text);
}

.word-card__header {
    margin-bottom: 0.5rem;
}

.word-card__kanji {
    font-family: 'Noto Sans JP', 'Hiragino Sans', sans-serif;
    font-size: 2rem;
    font-weight: 800;
    color: var(--story-text);
    line-height: 1.2;
}

.word-card__kana {
    font-size: 0.9rem;
    color: var(--story-muted);
    margin-top: 0.15rem;
    font-family: 'Noto Sans JP', 'Hiragino Sans', sans-serif;
}

.word-card__meta {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.word-card__level {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    padding: 0.15rem 0.55rem;
    border-radius: 99px;
}

.word-card__id {
    font-size: 0.72rem;
    color: rgba(152, 152, 166, 0.5);
}

.word-card__kind {
    color: #ffcf7d;
    background: rgba(255, 190, 92, 0.1);
    border: 1px solid rgba(255, 190, 92, 0.28);
    border-radius: 99px;
    padding: 0.15rem 0.55rem;
    font-size: 0.7rem;
    font-weight: 700;
}

.word-card__translation {
    font-size: 1.05rem;
    color: var(--story-text);
    margin-bottom: 1rem;
    line-height: 1.5;
}

.word-card__curated-note {
    color: var(--story-muted);
    font-size: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid rgba(255, 190, 92, 0.14);
}

/* ── Memorization ring ──────────────────────────────────────── */

.word-card__progress {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    margin-bottom: 1.1rem;
}

.word-card__progress-label {
    font-size: 0.8rem;
    color: var(--story-muted);
    font-weight: 600;
}

.word-ring {
    flex-shrink: 0;
}

.word-ring__bg {
    fill: none;
    stroke: rgba(255, 255, 255, 0.08);
    stroke-width: 3.5;
}

.word-ring__fill {
    fill: none;
    stroke: #64c878;
    stroke-width: 3.5;
    stroke-linecap: round;
    transition: stroke-dasharray 0.5s ease;
}

.word-ring__label {
    font-size: 10px;
    font-weight: 800;
    fill: var(--story-text);
    font-family: inherit;
}

/* ── Actions ─────────────────────────────────────────────────── */

.word-card__actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.word-card__btn {
    width: 100%;
    padding: 0.75rem 1rem;
    border-radius: 0.875rem;
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s;
    border: 1px solid transparent;
}

.word-card__btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.word-card__btn--primary {
    background: linear-gradient(135deg, rgba(180, 138, 255, 0.2), rgba(255, 138, 180, 0.12));
    border-color: rgba(180, 138, 255, 0.45);
    color: var(--story-purple);
}

.word-card__btn--primary:hover:not(:disabled) {
    background: linear-gradient(135deg, rgba(180, 138, 255, 0.3), rgba(255, 138, 180, 0.2));
    border-color: rgba(180, 138, 255, 0.7);
}

.word-card__btn--secondary {
    background: rgba(255, 255, 255, 0.04);
    border-color: var(--story-border);
    color: var(--story-muted);
    font-size: 0.8rem;
    padding: 0.5rem 1rem;
}

.word-card__btn--secondary:hover:not(:disabled) {
    background: rgba(255, 100, 100, 0.08);
    border-color: rgba(255, 100, 100, 0.25);
    color: #ff8080;
}

.word-card__btn.word-card__btn--added {
    background: rgba(100, 200, 120, 0.1);
    border-color: rgba(100, 200, 120, 0.35);
    color: #64c878;
    opacity: 1;
    cursor: default;
}

/* ── Responsive ──────────────────────────────────────────────── */

@media (max-width: 600px) {
    .stories-section { padding: 0 1rem; }
    .stories-filters { padding: 1rem; }
    .stories-grid { grid-template-columns: 1fr; }
    .dialogue-box__japanese { font-size: 1rem; }
    .player-topbar__title { display: none; }
}

/* ══════════════════════════════════════════════════════════════
   Admin Stories Manager
   ══════════════════════════════════════════════════════════════ */

.admin-stories {
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 2rem 2.5rem 4rem;
    color: var(--story-text);
    box-sizing: border-box;
}

.admin-stories__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.admin-stories__title {
    font-size: 1.5rem;
    font-weight: 800;
    margin: 0 0 0.25rem;
}

.admin-stories__subtitle {
    font-size: 0.85rem;
    color: var(--story-muted);
    margin: 0;
}

.admin-stories__subtitle code {
    background: rgba(255,255,255,0.06);
    border: 1px solid var(--story-border);
    padding: 0.1rem 0.4rem;
    border-radius: 0.3rem;
    font-size: 0.8rem;
}

.admin-stories__loading,
.admin-stories__empty {
    padding: 3rem;
    text-align: center;
    color: var(--story-muted);
}

.admin-stories__empty code {
    background: rgba(255,255,255,0.06);
    padding: 0.1rem 0.4rem;
    border-radius: 0.3rem;
    font-size: 0.85rem;
}

/* ── Sync log ──────────────────────────────────────────────── */

.admin-sync-log {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
    padding: 0.75rem 1rem;
    background: rgba(255,255,255,0.03);
    border: 1px solid var(--story-border);
    border-radius: 0.75rem;
}

.admin-sync-badge {
    font-size: 0.78rem;
    font-weight: 600;
    padding: 0.2rem 0.6rem;
    border-radius: 99px;
}

.admin-sync-badge--created  { background: rgba(100,200,120,0.15); color: #64c878; }
.admin-sync-badge--updated  { background: rgba(100,160,255,0.15); color: #64a0ff; }
.admin-sync-badge--skipped  { background: rgba(255,255,255,0.06); color: var(--story-muted); }
.admin-sync-badge--error    { background: rgba(255,100,100,0.15); color: #ff6464; }

/* ── Table ─────────────────────────────────────────────────── */

.admin-table-wrap {
    overflow-x: auto;
    border: 1px solid var(--story-border);
    border-radius: 1rem;
    margin-bottom: 1.25rem;
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.admin-table thead th {
    text-align: left;
    padding: 0.75rem 1rem;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--story-muted);
    background: rgba(255,255,255,0.03);
    border-bottom: 1px solid var(--story-border);
    white-space: nowrap;
}

.admin-table tbody td {
    padding: 0.85rem 1rem;
    border-bottom: 1px solid rgba(255,255,255,0.04);
    vertical-align: middle;
}

.admin-table tbody tr:last-child td { border-bottom: none; }

.admin-table tbody tr:hover td { background: rgba(255,255,255,0.02); }

.admin-table__row--dirty td { background: rgba(255,215,110,0.03); }

.admin-story-name { font-weight: 600; color: var(--story-text); }
.admin-story-slug { font-size: 0.75rem; color: var(--story-muted); margin-top: 0.15rem; }

.admin-hash { font-family: monospace; font-size: 0.78rem; color: var(--story-muted); }

/* ── Status badges ─────────────────────────────────────────── */

.admin-status {
    font-size: 0.75rem;
    font-weight: 700;
    padding: 0.2rem 0.6rem;
    border-radius: 99px;
}

.admin-status--ok    { background: rgba(100,200,120,0.12); color: #64c878; }
.admin-status--new   { background: rgba(180,138,255,0.12); color: var(--story-purple); }
.admin-status--dirty { background: rgba(255,215,110,0.12); color: var(--story-gold); }

/* ── Buttons ────────────────────────────────────────────────── */

.admin-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    padding: 0.55rem 1.1rem;
    border-radius: 0.75rem;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    border: 1px solid var(--story-border);
    background: rgba(255,255,255,0.05);
    color: var(--story-text);
    transition: all 0.15s;
}

.admin-btn:hover:not(:disabled) {
    background: rgba(255,255,255,0.1);
    border-color: rgba(255,255,255,0.15);
}

.admin-btn:disabled { opacity: 0.45; cursor: not-allowed; }

.admin-btn--primary {
    background: var(--story-purple-dim);
    border-color: rgba(180,138,255,0.35);
    color: var(--story-purple);
}

.admin-btn--primary:hover:not(:disabled) {
    background: rgba(180,138,255,0.22);
}

.admin-btn--accent {
    background: rgba(100,200,120,0.08);
    border-color: rgba(100,200,120,0.25);
    color: #64c878;
}

.admin-btn--accent:hover:not(:disabled) {
    background: rgba(100,200,120,0.16);
}

.admin-btn--sm {
    padding: 0.3rem 0.75rem;
    font-size: 0.78rem;
    border-radius: 0.5rem;
}

.admin-btn.loading { opacity: 0.6; }

.admin-row-actions { display: flex; gap: 0.4rem; }

/* ── Hint ───────────────────────────────────────────────────── */

.admin-stories__hint {
    font-size: 0.82rem;
    color: var(--story-muted);
    padding: 0.75rem 1rem;
    background: rgba(255,255,255,0.03);
    border: 1px solid var(--story-border);
    border-radius: 0.75rem;
    line-height: 1.6;
}

.admin-stories__hint code {
    background: rgba(255,255,255,0.06);
    padding: 0.1rem 0.35rem;
    border-radius: 0.3rem;
    font-size: 0.8rem;
}

/* ── Header actions ─────────────────────────────────────────── */

.admin-stories__header-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}

/* ── Alert ──────────────────────────────────────────────────── */

.admin-alert {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.75rem 1rem;
    border-radius: 0.75rem;
    margin-bottom: 1rem;
    font-size: 0.875rem;
}

.admin-alert--error {
    background: rgba(255,100,100,0.1);
    border: 1px solid rgba(255,100,100,0.25);
    color: #ff8080;
}

.admin-alert button {
    background: none;
    border: none;
    cursor: pointer;
    color: inherit;
    opacity: 0.7;
    font-size: 1rem;
    padding: 0;
    line-height: 1;
}

/* ── Panel (create form, import panel) ──────────────────────── */

.admin-panel {
    background: rgba(255,255,255,0.03);
    border: 1px solid var(--story-border);
    border-radius: 1rem;
    padding: 1.25rem;
    margin-bottom: 1.25rem;
}

.admin-panel__title {
    font-size: 0.95rem;
    font-weight: 700;
    margin: 0 0 0.5rem;
    color: var(--story-text);
}

.admin-panel__desc {
    font-size: 0.82rem;
    color: var(--story-muted);
    margin: 0 0 1rem;
}

.admin-panel__actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    justify-content: flex-end;
    margin-top: 1rem;
    flex-wrap: wrap;
}

/* ── Form grid ──────────────────────────────────────────────── */

.admin-form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 0.75rem;
}

.admin-form-label {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--story-muted);
    letter-spacing: 0.04em;
}

.admin-form-label--full {
    grid-column: 1 / -1;
}

.admin-form-label--checkbox {
    flex-direction: row;
    align-items: center;
    color: var(--story-text);
    font-size: 0.875rem;
    cursor: pointer;
}

.admin-form-hint {
    font-weight: 400;
    font-style: italic;
}

.admin-input {
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--story-border);
    border-radius: 0.5rem;
    padding: 0.5rem 0.75rem;
    color: var(--story-text);
    font-size: 0.875rem;
    width: 100%;
    box-sizing: border-box;
    outline: none;
    transition: border-color 0.15s;
}

.admin-input:focus {
    border-color: rgba(180,138,255,0.5);
}

.admin-input--textarea {
    resize: vertical;
    font-family: inherit;
}

.admin-input--sm { max-width: 100px; }

/* ── Table rows (expanded) ──────────────────────────────────── */

.admin-table__row--inactive td { opacity: 0.6; }

.admin-table__expanded-row td {
    padding: 0;
    background: rgba(255,255,255,0.015);
    border-bottom: 2px solid var(--story-border);
}

/* ── Story editor ───────────────────────────────────────────── */

.admin-story-editor {
    padding: 1.25rem 1.5rem;
}

.admin-editor-section {
    margin-bottom: 1.5rem;
}

.admin-editor-section__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}

.admin-editor-section__title {
    font-size: 0.875rem;
    font-weight: 700;
    margin: 0 0 0.75rem;
    color: var(--story-text);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-size: 0.72rem;
}

/* ── Scene cards ────────────────────────────────────────────── */

.admin-scene-card {
    border: 1px solid var(--story-border);
    border-radius: 0.75rem;
    margin-bottom: 0.5rem;
    overflow: hidden;
}

.admin-scene-card__header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 1rem;
    cursor: pointer;
    transition: background 0.15s;
    font-size: 0.875rem;
}

.admin-scene-card__header:hover { background: rgba(255,255,255,0.04); }

.admin-scene-card--open .admin-scene-card__header { background: rgba(180,138,255,0.06); }

.admin-scene-card__order {
    font-weight: 700;
    color: var(--story-purple);
    font-size: 0.78rem;
    min-width: 24px;
}

.admin-scene-card__bg {
    font-family: monospace;
    font-size: 0.78rem;
    background: rgba(255,255,255,0.06);
    padding: 0.15rem 0.5rem;
    border-radius: 0.4rem;
    color: var(--story-muted);
}

.admin-scene-card__sound {
    font-family: monospace;
    font-size: 0.72rem;
    background: rgba(167, 139, 250, 0.16);
    border: 1px solid rgba(167, 139, 250, 0.35);
    padding: 0.12rem 0.45rem;
    border-radius: 0.4rem;
    color: var(--story-text);
    white-space: nowrap;
}

.admin-scene-card__narration {
    font-size: 0.8rem;
    color: var(--story-muted);
    font-style: italic;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.admin-scene-card__counts {
    font-size: 0.75rem;
    color: var(--story-muted);
    margin-left: auto;
    white-space: nowrap;
}

.admin-scene-card__chevron {
    font-size: 0.65rem;
    color: var(--story-muted);
}

.admin-scene-card__body {
    padding: 0.75rem 1rem 1rem;
    border-top: 1px solid var(--story-border);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/* ── Sublist (lines / choices) ──────────────────────────────── */

.admin-sublist {
    background: rgba(0,0,0,0.15);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: 0.6rem;
    overflow: hidden;
}

.admin-sublist__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.75rem;
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--story-muted);
    border-bottom: 1px solid rgba(255,255,255,0.05);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ── Line / Choice rows ─────────────────────────────────────── */

.admin-line-row,
.admin-choice-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.45rem 0.75rem;
    font-size: 0.8rem;
    cursor: pointer;
    transition: background 0.12s;
    border-bottom: 1px solid rgba(255,255,255,0.04);
}

.admin-line-row:last-child,
.admin-choice-row:last-child { border-bottom: none; }

.admin-line-row:hover,
.admin-choice-row:hover { background: rgba(255,255,255,0.04); }

.admin-line-row__order,
.admin-choice-row__order {
    font-weight: 700;
    color: var(--story-muted);
    min-width: 20px;
    font-size: 0.72rem;
}

.admin-line-row__speaker,
.admin-choice-row__mood {
    font-size: 0.72rem;
    font-weight: 600;
    padding: 0.1rem 0.45rem;
    border-radius: 99px;
    background: rgba(180,138,255,0.12);
    color: var(--story-purple);
    white-space: nowrap;
}

.admin-line-row__jp,
.admin-choice-row__jp {
    font-size: 0.82rem;
    color: var(--story-text);
}

.admin-line-row__en,
.admin-choice-row__en {
    font-size: 0.78rem;
    color: var(--story-muted);
    flex: 1;
}

.admin-line-row__mood {
    font-size: 0.7rem;
    padding: 0.1rem 0.4rem;
    border-radius: 99px;
    background: rgba(100,200,120,0.1);
    color: #64c878;
    white-space: nowrap;
}

/* ── Inline forms ───────────────────────────────────────────── */

.admin-inline-form {
    padding: 0.75rem;
    background: rgba(255,255,255,0.03);
    border: 1px solid var(--story-border);
    border-radius: 0.6rem;
    margin: 0.25rem 0;
}

.admin-inline-form--compact {
    margin: 0;
    border-radius: 0;
    border-left: none;
    border-right: none;
}

/* ── Extra button variants ──────────────────────────────────── */

.admin-btn--danger {
    background: rgba(255,80,80,0.08);
    border-color: rgba(255,80,80,0.25);
    color: #ff6464;
}

.admin-btn--danger:hover:not(:disabled) {
    background: rgba(255,80,80,0.16);
}

.admin-btn--secondary {
    background: rgba(255,255,255,0.04);
    border-color: var(--story-border);
    color: var(--story-muted);
}

.admin-btn--xs {
    padding: 0.2rem 0.55rem;
    font-size: 0.72rem;
    border-radius: 0.4rem;
}

/* ═══════════════════════════════════════════════════════════════
   Background Picker
   ═══════════════════════════════════════════════════════════════ */

.bg-picker {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    margin-top: 0.25rem;
}

/* ── Preview strip ─────────────────────────────────────────────── */

.bg-picker__preview {
    width: 100%;
    height: 100px;
    border-radius: 0.65rem;
    border: 1px solid var(--story-border);
    background-size: cover;
    background-position: center;
    display: flex;
    align-items: flex-end;
    overflow: hidden;
    position: relative;
}

.bg-picker__preview--empty {
    background: rgba(255,255,255,0.04);
    align-items: center;
    justify-content: center;
}

.bg-picker__preview-placeholder {
    font-size: 0.8rem;
    color: var(--story-muted);
}

.bg-picker__preview-label {
    width: 100%;
    padding: 0.35rem 0.6rem;
    font-size: 0.72rem;
    font-weight: 600;
    font-family: monospace;
    color: #fff;
    background: linear-gradient(to top, rgba(0,0,0,0.75) 0%, transparent 100%);
    letter-spacing: 0.02em;
}

/* ── Search ─────────────────────────────────────────────────────── */

.bg-picker__search-wrap {
    position: relative;
}

.bg-picker__search {
    width: 100%;
    box-sizing: border-box;
}

/* ── Thumbnail grid ──────────────────────────────────────────────── */

.bg-picker__grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.5rem;
    max-height: 260px;
    overflow-y: auto;
    padding-right: 0.25rem;
}

.bg-picker__grid::-webkit-scrollbar {
    width: 4px;
}
.bg-picker__grid::-webkit-scrollbar-track { background: transparent; }
.bg-picker__grid::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.12);
    border-radius: 2px;
}

.bg-picker__thumb {
    position: relative;
    height: 80px;
    border-radius: 0.55rem;
    border: 2px solid transparent;
    background-size: cover;
    background-position: center;
    cursor: pointer;
    overflow: hidden;
    transition: border-color 0.15s, transform 0.1s;
    padding: 0;
}

.bg-picker__thumb:hover {
    border-color: rgba(255,255,255,0.3);
    transform: scale(1.03);
}

.bg-picker__thumb--selected {
    border-color: var(--story-purple) !important;
    box-shadow: 0 0 0 1px var(--story-purple);
}

.bg-picker__thumb-label {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 0.25rem 0.4rem;
    font-size: 0.65rem;
    font-family: monospace;
    color: #fff;
    background: linear-gradient(to top, rgba(0,0,0,0.8) 0%, transparent 100%);
    text-align: left;
    line-height: 1.2;
    word-break: break-all;
}

.bg-picker__thumb-check {
    position: absolute;
    top: 0.3rem;
    right: 0.3rem;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--story-purple);
    color: #fff;
    font-size: 0.65rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
}

.bg-picker__empty {
    grid-column: 1 / -1;
    padding: 1rem;
    text-align: center;
    font-size: 0.82rem;
    color: var(--story-muted);
}

/* ═══════════════════════════════════════════════════════════════
   Sound Picker
   ═══════════════════════════════════════════════════════════════ */

.sound-picker {
    margin-top: 0.25rem;
}

.sound-picker__list {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    max-height: 220px;
    overflow-y: auto;
    padding-right: 0.25rem;
}

.sound-picker__list::-webkit-scrollbar { width: 4px; }
.sound-picker__list::-webkit-scrollbar-track { background: transparent; }
.sound-picker__list::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.12);
    border-radius: 2px;
}

.sound-picker__row {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.sound-picker__item {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.6rem;
    border-radius: 0.5rem;
    border: 2px solid transparent;
    background: rgba(255,255,255,0.05);
    color: var(--story-text);
    cursor: pointer;
    text-align: left;
    transition: border-color 0.15s, background 0.15s;
}

.sound-picker__item:hover {
    border-color: rgba(255,255,255,0.25);
    background: rgba(255,255,255,0.08);
}

.sound-picker__item--selected {
    border-color: var(--story-purple) !important;
    background: rgba(167, 139, 250, 0.14);
}

.sound-picker__icon { font-size: 0.9rem; }

.sound-picker__name {
    font-family: monospace;
    font-size: 0.78rem;
    word-break: break-all;
}

.sound-picker__empty {
    padding: 0.75rem;
    text-align: center;
    font-size: 0.8rem;
    color: var(--story-muted);
    background: rgba(255,255,255,0.04);
    border-radius: 0.5rem;
}

/* ═══════════════════════════════════════════════════════════════
   Actor Picker
   ═══════════════════════════════════════════════════════════════ */

.actor-picker {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-top: 0.25rem;
    min-width: 0;
    min-height: 0;
}

/* ── Preview ────────────────────────────────────────────────────── */

.actor-picker__preview {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.85rem 1rem;
    border: 1px solid var(--story-border);
    border-radius: 0.75rem;
    background: rgba(255,255,255,0.03);
    min-height: 88px;
}

.actor-picker__preview--empty {
    justify-content: center;
}

.actor-picker__preview-placeholder {
    font-size: 0.8rem;
    color: var(--story-muted);
    font-style: italic;
}

.actor-picker__preview-img {
    height: 76px;
    width: auto;
    object-fit: contain;
    object-position: bottom;
    border-radius: 0.4rem;
}

.actor-picker__preview-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 1;
}

.actor-picker__preview-name {
    font-family: monospace;
    font-size: 0.9rem;
    color: var(--story-text);
    font-weight: 600;
}

.actor-picker__preview-hint {
    font-size: 0.78rem;
    color: var(--story-muted);
    font-style: italic;
}

.actor-picker__clear {
    margin-left: auto;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--story-muted);
    font-size: 1rem;
    padding: 0.3rem 0.5rem;
    border-radius: 0.4rem;
    transition: color 0.15s;
}

.actor-picker__clear:hover { color: #ff6464; }

/* ── Search ─────────────────────────────────────────────────────── */

.actor-picker__search { width: 100%; box-sizing: border-box; }

/* ── Grid ──────────────────────────────────────────────────────── */

.actor-picker__grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    grid-auto-rows: min-content;
    align-items: start;
    gap: 0.85rem;
    max-height: 640px;
    overflow-y: auto;
    padding-right: 0.35rem;
    min-width: 0;
}

.actor-picker__grid::-webkit-scrollbar { width: 4px; }
.actor-picker__grid::-webkit-scrollbar-track { background: transparent; }
.actor-picker__grid::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.12);
    border-radius: 2px;
}

.actor-picker__thumb {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    gap: 0.4rem;
    padding: 0.75rem 0.5rem 0.6rem;
    aspect-ratio: 2 / 3;
    border: 2px solid transparent;
    border-radius: 0.75rem;
    background: rgba(255,255,255,0.04);
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s, transform 0.1s;
    overflow: hidden;
}

.actor-picker__thumb:hover {
    border-color: rgba(255,255,255,0.2);
    background: rgba(255,255,255,0.08);
    transform: scale(1.03);
}

.actor-picker__thumb--selected {
    border-color: var(--story-purple) !important;
    background: var(--story-purple-dim);
}

.actor-picker__thumb-img {
    flex: 1;
    min-height: 0;
    width: auto;
    max-width: 100%;
    object-fit: contain;
    object-position: bottom;
}

.actor-picker__thumb-label {
    flex-shrink: 0;
    font-size: 0.72rem;
    font-family: monospace;
    color: var(--story-muted);
    text-align: center;
    line-height: 1.25;
    word-break: break-all;
    max-width: 100%;
}

.actor-picker__thumb-badge {
    flex-shrink: 0;
    font-size: 0.65rem;
    color: var(--story-purple);
    background: var(--story-purple-dim);
    border-radius: 0.4rem;
    padding: 0.1rem 0.4rem;
}

.actor-picker__thumb-check {
    position: absolute;
    top: 0.4rem;
    right: 0.4rem;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--story-purple);
    color: #fff;
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
}

.actor-picker__empty,
.actor-picker__empty-dir {
    grid-column: 1 / -1;
    padding: 1rem;
    text-align: center;
    font-size: 0.82rem;
    color: var(--story-muted);
}

.actor-picker__empty-dir code {
    background: rgba(255,255,255,0.06);
    padding: 0.1rem 0.4rem;
    border-radius: 0.3rem;
}

/* ── Admin actors editor ─────────────────────────────────────── */

.admin-actors-editor {
    margin-top: 0.75rem;
    margin-bottom: 0.25rem;
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 0.6rem;
    overflow: hidden;
}

.admin-actors-editor__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.4rem 0.75rem;
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--story-muted);
    background: rgba(0,0,0,0.2);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.admin-actor-block {
    padding: 0.75rem;
    border-top: 1px solid rgba(255,255,255,0.05);
}

.admin-actor-block__header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.admin-actor-block__label {
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--story-muted);
    margin-right: auto;
}

.admin-actor-block__header .admin-input--sm {
    max-width: 140px;
}

/* ── Episode cards (player-facing episode list) ─────────────── */

.episodes-back {
    display: inline-block;
    color: var(--story-muted);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    transition: color 0.15s;
}

.episodes-back:hover { color: var(--story-purple); }

.episode-list {
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
}

.episode-card {
    display: flex;
    align-items: stretch;
    gap: 1rem;
    background: #16161f;
    border: 1px solid var(--story-border);
    border-radius: 1rem;
    padding: 1rem 1.25rem;
    transition: border-color 0.15s;
}

/* ── Episode cards (admin) ──────────────────────────────────── */

.admin-episode-card {
    border: 1px solid rgba(255, 215, 110, 0.25);
    border-radius: 0.75rem;
    margin-bottom: 0.75rem;
    overflow: hidden;
}

.admin-episode-card__header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.7rem 1rem;
    cursor: pointer;
    transition: background 0.15s;
    font-size: 0.875rem;
}

.admin-episode-card__header:hover { background: rgba(255,255,255,0.04); }

.admin-episode-card--open .admin-episode-card__header { background: rgba(255,215,110,0.08); }

.admin-episode-card__order {
    font-weight: 700;
    color: var(--story-gold);
    font-size: 0.78rem;
    min-width: 24px;
}

.admin-episode-card__title {
    font-weight: 700;
    color: var(--story-text);
}

.admin-episode-card__counts {
    font-size: 0.75rem;
    color: var(--story-muted);
    margin-left: auto;
    white-space: nowrap;
}

.admin-episode-card__chevron {
    font-size: 0.65rem;
    color: var(--story-muted);
}

.admin-episode-card__body {
    padding: 0.85rem 1rem 1rem;
    border-top: 1px solid rgba(255, 215, 110, 0.2);
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.admin-episode-card__desc {
    margin: 0;
    font-size: 0.82rem;
    line-height: 1.5;
    color: var(--story-text);
}

.admin-episode-card__desc--empty {
    color: var(--story-muted);
    font-style: italic;
}
