html,
body {
    height: 100%;
    overflow: hidden;
}

.web-shell {
    width: min(1440px, 100vw);
    height: 100vh;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-left: 1px solid var(--border-color);
    border-right: 1px solid var(--border-color);
    background: var(--bg-primary);
}

.tui-header,
.tui-footer {
    background: var(--bg-secondary);
    border-color: var(--border-color);
    color: var(--text-secondary);
}

.tui-header {
    position: relative;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    min-height: 52px;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
    color: var(--accent-purple);
    background: var(--bg-secondary);
}

.tui-header-subtitle {
    color: var(--text-secondary);
    margin-left: 0.75rem;
}

.tui-brand {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    min-width: 0;
}

/* The Learning Curve wordmark. assets/img/tlc-logo-white.png is white art on a
   real alpha channel, cut from resolute's assets/images/tlc.png; sizing off the
   height and leaving width:auto keeps its intrinsic 1024x218 ratio. */
.tui-brand-logo {
    display: block;
    flex: 0 0 auto;
    height: 26px;
    width: auto;
}

.tui-brand-divider {
    flex: 0 0 auto;
    width: 1px;
    height: 1.15rem;
    background: var(--border-color);
}

.tui-brand-name {
    color: var(--accent-purple);
    white-space: nowrap;
    letter-spacing: 0.03em;
}

/* The wordmark is white for the dark header. On the light theme flatten it to a
   solid dark mark; brightness(0) maps every opaque pixel to black but, unlike
   invert(), leaves the alpha channel (and therefore the shape) untouched. */
[data-theme="light"] .tui-brand-logo,
[data-theme="light"] .landing-logo {
    filter: brightness(0);
}

.tui-header-actions {
    display: flex;
    gap: 0.5rem;
}

.tui-button {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    color: var(--text-primary);
    cursor: pointer;
    padding: 0.35rem 0.7rem;
}

.tui-button:hover,
.tui-button:focus {
    border-color: var(--accent-purple);
    outline: none;
}

a.tui-header-link {
    text-decoration: none;
    color: inherit;
    display: inline-flex;
    align-items: center;
    box-sizing: border-box;
}

a.tui-header-link:hover,
a.tui-header-link:focus {
    border-color: var(--accent-purple);
    outline: none;
}

.tui-footer-link {
    color: var(--accent-blue);
    text-decoration: none;
    word-break: break-all;
}

.tui-footer-link:hover,
.tui-footer-link:focus {
    text-decoration: underline;
    outline: none;
}

.tui-main {
    position: relative;
    z-index: 0;
    flex: 1 1 auto;
    display: grid;
    grid-template-columns: 320px minmax(0, 1fr);
    min-height: 0;
    overflow: hidden;
}

.tui-sidebar {
    min-height: 0;
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    background: #0a0a20;
    border-right: 1px solid var(--border-color);
    overflow: auto;
}

[data-theme="light"] .tui-sidebar {
    background: var(--bg-secondary);
}

.tui-panel {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    padding: 0.75rem;
    transition: border-color 320ms ease, box-shadow 360ms cubic-bezier(0.22, 1, 0.36, 1), opacity 220ms ease;
}
.tui-panel.is-refreshing {
    opacity: 0.88;
    border-color: var(--fx-accent, var(--accent-purple));
}

.tui-panel h2 {
    margin: 0 0 0.5rem;
    color: var(--text-heading);
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    cursor: pointer;
    user-select: none;
}

.tui-panel h2::before {
    content: "▾ ";
    opacity: 0.7;
}

.tui-panel.is-collapsed h2 {
    margin: 0;
}

.tui-panel.is-collapsed h2::before {
    content: "▸ ";
}

.tui-panel.is-collapsed > :not(h2) {
    display: none;
}

.tui-panel.is-hud-hidden {
    display: none;
}

.tui-main.hud-dock-right {
    grid-template-columns: minmax(0, 1fr) 320px;
}

.tui-main.hud-dock-right .tui-sidebar {
    order: 2;
    border-right: 0;
    border-left: 1px solid var(--border-color);
}

.hud-menu {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.hud-menu[hidden] {
    display: none;
}

.hud-menu label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.85rem;
}

.hud-menu-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin: 0;
}

.tui-room-panel {
    /* Size to content; let the whole .tui-sidebar scroll (it is overflow:auto)
       rather than collapsing this panel to its title when several panels share
       a short viewport. */
    flex: 0 0 auto;
}

.tui-content {
    position: relative;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}

.tui-log {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    min-height: 0;
    margin: 0;
    padding: 1rem;
    border: 0;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.45;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-word;
}

.tui-input-row {
    position: relative;
    z-index: 1;
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 48px;
    margin: 0;
    padding: 0.6rem 0.75rem;
    border-top: 1px solid var(--border-color);
    background: #0a0a20;
}

[data-theme="light"] .tui-input-row {
    background: var(--bg-secondary);
}

.tui-prompt {
    color: var(--accent-blue);
    font-family: var(--font-mono);
    font-weight: 700;
    white-space: nowrap;
    min-width: 0;
    flex: 0 1 auto;
    max-width: min(50vw, 22rem);
    overflow: hidden;
    text-overflow: ellipsis;
}

@media (max-width: 600px) {
    .tui-prompt {
        white-space: normal;
        word-break: break-all;
        max-width: 45%;
    }
}

.tui-input {
    flex: 1;
    min-width: 0;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-input);
    color: var(--text-primary);
    font-family: var(--font-mono);
    padding: 0.45rem 0.65rem;
}

.tui-input:focus {
    border-color: var(--accent-purple);
    outline: none;
}

.tui-footer {
    position: relative;
    z-index: 1;
    flex: 0 0 auto;
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    padding: 0.55rem 0.75rem;
    border-top: 1px solid var(--border-color);
    font-size: 0.85rem;
}

.kind-error { color: var(--accent-red); }
.kind-success { color: var(--accent-green); }
.kind-info { color: var(--accent-blue); }
.kind-magic { color: var(--accent-yellow); }
/* The Learning Curve rank ladder — one class per tier, coloured by --rank-*.
   Emitted from ARENA_RANKS[].kind in runtime.js via hud.js's hero model. */
.kind-rank-curious { color: var(--rank-curious); }
.kind-rank-explorer { color: var(--rank-explorer); }
.kind-rank-tinkerer { color: var(--rank-tinkerer); }
.kind-rank-builder { color: var(--rank-builder); }
.kind-rank-engineer { color: var(--rank-engineer); }
.kind-rank-innovator { color: var(--rank-innovator); }
.kind-dim { color: var(--text-secondary); }
.kind-output { color: var(--text-primary); }
.kind-art {
    color: var(--accent-purple);
    white-space: pre;
    word-break: normal;
    font-family: var(--font-mono);
    text-shadow: 0 0 6px rgba(167, 139, 250, 0.25);
}
.kind-banner {
    color: var(--accent-yellow);
    white-space: pre;
    word-break: normal;
    font-family: var(--font-mono);
    text-shadow: 0 0 8px rgba(251, 191, 36, 0.45);
}

.tui-log span.kind-banner,
.tui-log span.kind-art {
    display: block;
    white-space: pre;
    word-break: normal;
    overflow-wrap: normal;
    overflow-x: auto;
    max-width: 100%;
}

@keyframes bc-sparkle {
    0%, 100% { box-shadow: 0 0 0 0 rgba(167, 139, 250, 0.0); transform: translateY(0); }
    25%      { box-shadow: 0 0 18px 4px rgba(251, 191, 36, 0.55); transform: translateY(-1px); }
    60%      { box-shadow: 0 0 12px 3px rgba(167, 139, 250, 0.55); transform: translateY(0); }
}
.fx-sparkle {
    animation: bc-sparkle 900ms ease-out;
    border-color: var(--accent-yellow) !important;
}

@keyframes bc-shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-6px); }
    40% { transform: translateX(5px); }
    60% { transform: translateX(-3px); }
    80% { transform: translateX(2px); }
}
.fx-shake { animation: bc-shake 320ms ease-in-out; }

@keyframes bc-pop {
    0% { transform: scale(1); color: var(--accent-yellow); }
    50% { transform: scale(1.18); color: var(--accent-green); }
    100% { transform: scale(1); }
}
.fx-pop {
    display: inline-block;
    animation: bc-pop 600ms ease-out;
}

@keyframes bc-fadein {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}
.tui-log span { animation: bc-fadein 280ms cubic-bezier(0.22, 1, 0.36, 1) both; }

/* Encounter Creature Gallery: scan-in reveal for freshly-mounted ASCII art.
   renderLog() rebuilds the <pre> on every render, so each art span re-mounts
   and re-runs this animation. Color/glow stay on .kind-art (theme-aware via
   CSS vars). Gated on reduced-motion with a static fallback. */
@media (prefers-reduced-motion: no-preference) {
    @keyframes bc-art-reveal {
        from { opacity: 0; transform: translateY(3px); clip-path: inset(0 100% 0 0); filter: brightness(1.6); }
        60%  { opacity: 1; transform: translateY(0);   clip-path: inset(0 0 0 0);   filter: brightness(1.25); }
        to   { opacity: 1; transform: translateY(0);   clip-path: inset(0 0 0 0);   filter: brightness(1); }
    }
    .tui-log span.kind-art {
        display: block;
        animation: bc-art-reveal 420ms ease-out both;
    }
    .tui-log span.kind-art + span.kind-art { animation-delay: 40ms; }
    .tui-log span.kind-art + span.kind-art + span.kind-art { animation-delay: 80ms; }
    .tui-log span.kind-art + span.kind-art + span.kind-art + span.kind-art { animation-delay: 120ms; }
    .tui-log span.kind-art + span.kind-art + span.kind-art + span.kind-art + span.kind-art { animation-delay: 160ms; }
    .tui-log span.kind-art + span.kind-art + span.kind-art + span.kind-art + span.kind-art + span.kind-art { animation-delay: 200ms; }
    .tui-log span.kind-art + span.kind-art + span.kind-art + span.kind-art + span.kind-art + span.kind-art + span.kind-art { animation-delay: 240ms; }
    .tui-log span.kind-art + span.kind-art + span.kind-art + span.kind-art + span.kind-art + span.kind-art + span.kind-art + span.kind-art { animation-delay: 280ms; }
    .tui-log span.kind-art + span.kind-art + span.kind-art + span.kind-art + span.kind-art + span.kind-art + span.kind-art + span.kind-art + span.kind-art { animation-delay: 320ms; }
}
/* Static fallback: under reduced-motion the art appears instantly, fully lit. */
@media (prefers-reduced-motion: reduce) {
    .tui-log span.kind-art {
        animation: none;
        opacity: 1;
        transform: none;
        clip-path: none;
        filter: none;
    }
}

.tui-log .kind-magic, .tui-log .kind-success {
    text-shadow: 0 0 4px currentColor;
}

/* Rank tiers glow in the terminal log like the other accent lines. */
.tui-log .kind-rank-curious,
.tui-log .kind-rank-explorer,
.tui-log .kind-rank-tinkerer,
.tui-log .kind-rank-builder,
.tui-log .kind-rank-engineer,
.tui-log .kind-rank-innovator {
    text-shadow: 0 0 4px currentColor;
}

.docs-drawer {
    position: fixed;
    inset: 0 0 0 auto;
    width: min(480px, 100vw);
    transform: translateX(100%);
    transition: transform 160ms ease;
    visibility: hidden;
    pointer-events: none;
    background: var(--bg-card);
    border-left: 1px solid var(--border-color);
    z-index: 10;
    display: flex;
    flex-direction: column;
}

.docs-drawer.open {
    transform: translateX(0);
    visibility: visible;
    pointer-events: auto;
}

.docs-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.docs-header h2 {
    margin: 0;
}

.docs-search {
    margin: 1rem;
    padding: 0.55rem 0.7rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-input);
    color: var(--text-primary);
}

.docs-content {
    overflow: auto;
    padding: 0 1rem 1rem;
}

.docs-card {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 0.75rem;
    margin-bottom: 0.75rem;
    background: var(--bg-primary);
}

.docs-card h3 {
    margin: 0 0 0.45rem;
}

.docs-cmd-block {
    margin-top: 0.75rem;
}

.docs-cmd-block:first-child {
    margin-top: 0;
}

.docs-cmd-cat {
    margin: 0 0 0.4rem;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-heading);
}

.docs-cmd-list {
    margin: 0;
    padding-left: 1.1rem;
    list-style: disc;
}

.docs-cmd-list li {
    margin: 0.2rem 0;
}

.docs-cmd-desc {
    color: var(--text-primary);
}

.docs-command {
    display: inline-flex;
    margin: 0.15rem 0.25rem 0.15rem 0;
    padding: 0.2rem 0.4rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-input);
    color: var(--accent-blue);
    cursor: pointer;
}

@media (max-width: 900px) {
    .tui-main {
        grid-template-columns: 1fr;
        grid-template-rows: auto minmax(0, 1fr);
    }

    .tui-sidebar {
        max-height: 34vh;
        border-right: 0;
        border-bottom: 1px solid var(--border-color);
    }
}

/* ============================================================
 * Pixel Hero Companion
 * CSS-drawn sprite — no emoji, no glyphs. Theme-aware via vars.
 * All motion gated behind prefers-reduced-motion: no-preference.
 * ============================================================ */
.hero-panel {
    flex: 0 0 auto;
    text-align: center;
}

.hero-stage {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
    padding: 0.35rem 0 0.1rem;
}

/* Sprite frame. --hpx is the pixel unit; the whole sprite lives in this box. */
.hero-sprite {
    --hpx: 7px;
    position: relative;
    width: calc(var(--hpx) * 9);
    height: calc(var(--hpx) * 9);
    image-rendering: pixelated;
    transform: translateZ(0);
}

/* Each body part is an absolutely-placed crisp pixel block. */
.hero-px {
    position: absolute;
    display: block;
    border-radius: 1px;
}

/* Helm (metal/heading tone) */
.hero-helm {
    top: 0;
    left: calc(var(--hpx) * 2);
    width: calc(var(--hpx) * 5);
    height: calc(var(--hpx) * 2);
    background: var(--text-secondary);
    box-shadow: inset 0 calc(var(--hpx) * -0.4) 0 0 rgba(0, 0, 0, 0.18);
}

/* Face (skin = warm accent) */
.hero-face {
    top: calc(var(--hpx) * 2);
    left: calc(var(--hpx) * 2.5);
    width: calc(var(--hpx) * 4);
    height: calc(var(--hpx) * 2);
    background: var(--accent-yellow);
    box-shadow:
        inset calc(var(--hpx) * 0.8) calc(var(--hpx) * 0.6) 0 0 var(--bg-primary),
        inset calc(var(--hpx) * -1.4) calc(var(--hpx) * 0.6) 0 0 var(--bg-primary);
}

/* Torso (tunic = green adventurer) */
.hero-torso {
    top: calc(var(--hpx) * 4);
    left: calc(var(--hpx) * 2);
    width: calc(var(--hpx) * 5);
    height: calc(var(--hpx) * 3);
    background: var(--accent-green);
    box-shadow: inset 0 calc(var(--hpx) * -0.6) 0 0 rgba(0, 0, 0, 0.2);
}

/* Arms */
.hero-arm {
    top: calc(var(--hpx) * 4);
    width: var(--hpx);
    height: calc(var(--hpx) * 2.4);
    background: var(--accent-yellow);
}
.hero-arm-l { left: calc(var(--hpx) * 1); }
.hero-arm-r { left: calc(var(--hpx) * 7); }

/* Legs (boots = muted) */
.hero-legs {
    top: calc(var(--hpx) * 7);
    left: calc(var(--hpx) * 2.5);
    width: calc(var(--hpx) * 4);
    height: calc(var(--hpx) * 2);
    background: var(--text-muted);
    box-shadow: inset calc(var(--hpx) * 1) 0 0 0 var(--bg-card);
}

/* Blade held in right hand (steel = blue accent). Pure CSS bar, not a glyph. */
.hero-blade {
    top: calc(var(--hpx) * 1);
    left: calc(var(--hpx) * 7.6);
    width: calc(var(--hpx) * 0.7);
    height: calc(var(--hpx) * 5);
    background: var(--accent-blue);
    box-shadow:
        0 calc(var(--hpx) * 0) 0 0 var(--accent-blue),
        0 calc(var(--hpx) * 4.6) 0 0 var(--accent-yellow); /* pommel */
    transform-origin: bottom center;
}

/* Ground shadow (sits under the sprite) */
.hero-shadow {
    position: absolute;
    left: 50%;
    bottom: calc(var(--hpx) * -0.6);
    width: calc(var(--hpx) * 6);
    height: calc(var(--hpx) * 1);
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.28);
    border-radius: 50%;
    filter: blur(1px);
}
[data-theme="light"] .hero-shadow { background: rgba(0, 0, 0, 0.16); }

/* Sparkle particles (hidden until 'item' mood). CSS dots, not emoji. */
.hero-fx {
    position: absolute;
    inset: 0;
    pointer-events: none;
}
.hero-spark {
    position: absolute;
    width: calc(var(--hpx) * 0.8);
    height: calc(var(--hpx) * 0.8);
    border-radius: 50%;
    background: var(--accent-yellow);
    box-shadow: 0 0 6px 1px rgba(251, 191, 36, 0.7);
    opacity: 0;
}
.hero-spark-1 { top: 10%; left: 12%; }
.hero-spark-2 { top: 4%;  left: 70%; }
.hero-spark-3 { top: 38%; left: 86%; }

.hero-mood-label {
    margin: 0;
    font-size: 0.78rem;
    min-height: 1.05em;
}

/* ---- Static mood tints (apply in ALL motion preferences) ---- */
.hero-stage[data-mood="hurt"] .hero-torso { background: var(--accent-red); }
.hero-stage[data-mood="hurt"] .hero-face  { background: var(--accent-red); }
.hero-stage[data-mood="xp"]   .hero-sprite { filter: drop-shadow(0 0 5px rgba(96, 165, 250, 0.65)); }
.hero-stage[data-mood="quest"] .hero-blade { background: var(--accent-yellow); box-shadow: 0 calc(var(--hpx) * 4.6) 0 0 var(--accent-yellow); }
.hero-stage[data-mood="cast"] .hero-blade { background: var(--accent-purple); box-shadow: 0 calc(var(--hpx) * 4.6) 0 0 var(--accent-purple); }
.hero-stage[data-mood="cast"] .hero-sprite { filter: drop-shadow(0 0 8px rgba(167, 139, 250, 0.75)); }

/* ---- Motion — only when reduced motion is NOT requested ---- */
@media (prefers-reduced-motion: no-preference) {
    .hero-stage[data-mood="idle"] .hero-sprite {
        animation: hero-bob 2600ms ease-in-out infinite;
    }
    @keyframes hero-bob {
        0%, 100% { transform: translateY(0) translateZ(0); }
        50%      { transform: translateY(calc(var(--hpx) * -0.5)) translateZ(0); }
    }

    .hero-stage[data-mood="hurt"] .hero-sprite {
        animation: hero-hurt 480ms ease-in-out 1;
    }
    @keyframes hero-hurt {
        0%   { transform: translateX(0) rotate(0); }
        20%  { transform: translateX(calc(var(--hpx) * -0.8)) rotate(-5deg); }
        45%  { transform: translateX(calc(var(--hpx) * 0.6)) rotate(4deg); }
        70%  { transform: translateX(calc(var(--hpx) * -0.4)) rotate(-2deg); }
        100% { transform: translateX(0) rotate(0); }
    }

    .hero-stage[data-mood="quest"] .hero-sprite {
        animation: hero-cheer 720ms cubic-bezier(0.34, 1.56, 0.64, 1) 2;
    }
    .hero-stage[data-mood="quest"] .hero-arm-r,
    .hero-stage[data-mood="quest"] .hero-blade {
        animation: hero-thrust 720ms ease-out 2;
        transform-origin: bottom center;
    }
    @keyframes hero-cheer {
        0%, 100% { transform: translateY(0); }
        40%      { transform: translateY(calc(var(--hpx) * -1.6)); }
    }
    @keyframes hero-thrust {
        0%, 100% { transform: translateY(0) rotate(0); }
        40%      { transform: translateY(calc(var(--hpx) * -0.8)) rotate(-12deg); }
    }

    .hero-stage[data-mood="item"] .hero-sprite {
        animation: hero-hop 520ms ease-out 1;
    }
    .hero-stage[data-mood="item"] .hero-spark {
        animation: hero-twinkle 620ms ease-out 1;
    }
    .hero-stage[data-mood="item"] .hero-spark-2 { animation-delay: 90ms; }
    .hero-stage[data-mood="item"] .hero-spark-3 { animation-delay: 180ms; }
    @keyframes hero-hop {
        0%, 100% { transform: translateY(0); }
        45%      { transform: translateY(calc(var(--hpx) * -0.9)); }
    }
    @keyframes hero-twinkle {
        0%   { opacity: 0; transform: scale(0.4); }
        40%  { opacity: 1; transform: scale(1.2); }
        100% { opacity: 0; transform: scale(0.6); }
    }

    .hero-stage[data-mood="xp"] .hero-sprite {
        animation: hero-glow 760ms ease-in-out 1;
    }
    @keyframes hero-glow {
        0%, 100% { filter: drop-shadow(0 0 0 rgba(96, 165, 250, 0)); transform: scale(1); }
        50%      { filter: drop-shadow(0 0 8px rgba(96, 165, 250, 0.8)); transform: scale(1.06); }
    }
}

@media (prefers-reduced-motion: reduce) {
    .hero-sprite,
    .hero-arm-r,
    .hero-blade,
    .hero-spark { animation: none !important; }
}

/* ============================================================
   Terminal Juice Pack — feel-good micro-animations.
   All motion gated on reduced-motion; theme tokens only.
   (Piece 4 "typewriter" was intentionally dropped: it mangles
   wrapped lines and would fight the encounter-art reveal.)
   ============================================================ */

/* (1) Blinking block cursor on the prompt label. Static solid block
   under reduced-motion. */
#prompt-label::after {
    content: "";
    display: inline-block;
    width: 0.6ch;
    height: 1em;
    margin-left: 0.15ch;
    vertical-align: -0.12em;
    background: var(--accent-green);
    border-radius: 1px;
    opacity: 1;
}
@media (prefers-reduced-motion: no-preference) {
    @keyframes bc-caret-blink {
        0%, 49% { opacity: 1; }
        50%, 100% { opacity: 0; }
    }
    #prompt-label::after {
        animation: bc-caret-blink 1.05s steps(1, end) infinite;
    }
}

/* (2) Floating "+N XP" number near #quest-panel (created/removed by JS). */
.bc-xp-float {
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
    pointer-events: none;
    z-index: 5;
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--accent-green);
    text-shadow: 0 0 6px rgba(74, 222, 128, 0.55);
    will-change: transform, opacity;
}
@media (prefers-reduced-motion: no-preference) {
    @keyframes bc-xp-rise {
        0%   { transform: translateY(0) scale(0.9); opacity: 0; }
        15%  { transform: translateY(-2px) scale(1.05); opacity: 1; }
        70%  { transform: translateY(-22px) scale(1); opacity: 1; }
        100% { transform: translateY(-34px) scale(0.95); opacity: 0; }
    }
    .bc-xp-float { animation: bc-xp-rise 1100ms ease-out both; }
}
@media (prefers-reduced-motion: reduce) {
    .bc-xp-float { opacity: 1; }
}

/* (3) Animated HP fill bar (the text bar in renderInventory stays as fallback).
   Width driven by --hp (0..100); color shifts green->amber->red via a class. */
.bc-hpbar {
    position: relative;
    height: 8px;
    margin: 0.4rem 0 0.1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-input);
    overflow: hidden;
}
.bc-hpbar-fill {
    height: 100%;
    width: calc(var(--hp, 100) * 1%);
    border-radius: inherit;
    background: var(--accent-green);
}
.bc-hpbar-fill.is-mid { background: var(--accent-yellow); }
.bc-hpbar-fill.is-low { background: var(--accent-red); }
@media (prefers-reduced-motion: no-preference) {
    .bc-hpbar-fill {
        transition: width 420ms cubic-bezier(0.22, 1, 0.36, 1),
                    background-color 420ms ease;
    }
}

/* ============================================================
   CRT Retro Mode — optional overlay, toggled in the header.
   Activated by body[data-crt="on"] (set by game.js). Pure-CSS:
   scanlines + vignette via a ::after layer on .web-shell, plus a
   phosphor glow on the log text. Flicker is motion-only; the
   scanlines/vignette/glow stay static under reduced motion.
   ============================================================ */
body[data-crt="on"] .web-shell {
    position: relative;
}

body[data-crt="on"] .web-shell::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 30;
    pointer-events: none;
    border-radius: inherit;
    background:
        radial-gradient(
            ellipse at center,
            rgba(0, 0, 0, 0) 55%,
            rgba(0, 0, 0, 0.28) 100%
        ),
        repeating-linear-gradient(
            to bottom,
            rgba(0, 0, 0, 0.16) 0,
            rgba(0, 0, 0, 0.16) 1px,
            rgba(0, 0, 0, 0) 1px,
            rgba(0, 0, 0, 0) 3px
        );
    mix-blend-mode: multiply;
}

/* Light theme: soften scanlines/vignette so multiply doesn't muddy it. */
[data-theme="light"] body[data-crt="on"] .web-shell::after {
    background:
        radial-gradient(
            ellipse at center,
            rgba(0, 0, 0, 0) 60%,
            rgba(45, 36, 25, 0.14) 100%
        ),
        repeating-linear-gradient(
            to bottom,
            rgba(45, 36, 25, 0.07) 0,
            rgba(45, 36, 25, 0.07) 1px,
            rgba(0, 0, 0, 0) 1px,
            rgba(0, 0, 0, 0) 3px
        );
}

/* Soft phosphor glow on the terminal text; readability preserved. */
body[data-crt="on"] .tui-log {
    text-shadow:
        0 0 1px rgba(74, 222, 128, 0.35),
        0 0 6px rgba(74, 222, 128, 0.12);
}
[data-theme="light"] body[data-crt="on"] .tui-log {
    text-shadow:
        0 0 1px rgba(96, 165, 250, 0.30),
        0 0 5px rgba(96, 165, 250, 0.10);
}

/* Barely-there flicker — MOTION ONLY. */
@media (prefers-reduced-motion: no-preference) {
    @keyframes bc-crt-flicker {
        0%, 100% { opacity: 1; }
        48%      { opacity: 0.97; }
        50%      { opacity: 0.93; }
        52%      { opacity: 0.985; }
        70%      { opacity: 0.96; }
    }
    body[data-crt="on"] .web-shell::after {
        animation: bc-crt-flicker 4.5s steps(1, end) infinite;
        will-change: opacity;
    }
}

/* ============================================================
   Living Banner & Room Vignettes
   All motion gated behind prefers-reduced-motion; static first.
   ============================================================ */

/* (1) LIVING BANNER — base is a plain solid accent (identical to the
   prior look in every theme); the gradient shimmer applies ONLY when
   motion is welcome and background-clip:text is supported. */
.tui-log .kind-banner {
    color: var(--accent-yellow);
}
@media (prefers-reduced-motion: no-preference) {
    @supports ((-webkit-background-clip: text) or (background-clip: text)) {
        .tui-log .kind-banner {
            background-image: linear-gradient(
                100deg,
                var(--accent-yellow) 0%,
                var(--accent-yellow) 35%,
                var(--accent-green) 50%,
                var(--accent-yellow) 65%,
                var(--accent-yellow) 100%
            );
            background-size: 220% 100%;
            background-repeat: no-repeat;
            -webkit-background-clip: text;
            background-clip: text;
            -webkit-text-fill-color: transparent;
            color: transparent;
            text-shadow: none; /* glyphs are transparent; drop inherited glow */
            animation: bc-banner-sweep 6s linear infinite;
        }
    }
}
/* Sweep stays within [0%, 100%]: with background-size:220% and no-repeat,
   any position outside this range leaves part of the text uncovered by the
   gradient, which (because text-fill is transparent) makes those glyphs
   vanish mid-animation. Both endpoints render all-yellow (the green shine
   sits just off-screen), so the loop repeats seamlessly with no jump. */
@keyframes bc-banner-sweep {
    from { background-position: 100% 0; }
    to   { background-position: 0% 0; }
}

/* (2) ROOM VIGNETTE — small ASCII mascot below the Location panel. */
.room-vignette {
    margin: 0.5rem 0;
    padding: 0;
    border: 0;
    background: transparent;
    font-family: var(--font-mono);
    font-size: 0.78rem;
    line-height: 1.15;
    white-space: pre;
    word-break: normal;
    overflow: hidden;
    color: var(--accent-purple);
    opacity: 0.92;
    text-shadow: 0 0 6px rgba(167, 139, 250, 0.22);
}
.room-vignette[data-room-art="entrance"],
.room-vignette[data-room-art="cellar"] {
    color: var(--accent-yellow);
    text-shadow: 0 0 7px rgba(251, 191, 36, 0.35);
}
.room-vignette[data-room-art="vault"] {
    color: var(--accent-blue);
    text-shadow: 0 0 7px rgba(96, 165, 250, 0.35);
}
.room-vignette[data-room-art="graveyard"] {
    color: var(--text-secondary);
    text-shadow: none;
}
.room-vignette[data-room-art="rift"] {
    color: var(--accent-purple);
    text-shadow: 0 0 8px rgba(167, 139, 250, 0.4);
}
@media (prefers-reduced-motion: no-preference) {
    .room-vignette[data-room-art="entrance"],
    .room-vignette[data-room-art="cellar"] {
        animation: bc-vignette-flicker 2.4s ease-in-out infinite;
    }
    .room-vignette[data-room-art="vault"] {
        animation: bc-vignette-shimmer 3.6s ease-in-out infinite;
    }
    .room-vignette[data-room-art="graveyard"] {
        animation: bc-vignette-drift 5s ease-in-out infinite;
    }
    .room-vignette[data-room-art="rift"] {
        animation: bc-vignette-swirl 4s ease-in-out infinite;
    }
}
@keyframes bc-vignette-flicker {
    0%, 100% { opacity: 0.9;  filter: brightness(1); }
    18%      { opacity: 1;    filter: brightness(1.18); }
    32%      { opacity: 0.82; filter: brightness(0.92); }
    54%      { opacity: 0.97; filter: brightness(1.1); }
    71%      { opacity: 0.86; filter: brightness(0.96); }
}
@keyframes bc-vignette-shimmer {
    0%, 100% { opacity: 0.85; text-shadow: 0 0 5px rgba(96, 165, 250, 0.25); }
    50%      { opacity: 1;    text-shadow: 0 0 11px rgba(96, 165, 250, 0.6); }
}
@keyframes bc-vignette-drift {
    0%, 100% { opacity: 0.78; }
    50%      { opacity: 0.95; }
}
@keyframes bc-vignette-swirl {
    0%, 100% { opacity: 0.85; filter: brightness(0.95); text-shadow: 0 0 6px rgba(167, 139, 250, 0.3); }
    50%      { opacity: 1;    filter: brightness(1.15); text-shadow: 0 0 13px rgba(167, 139, 250, 0.6); }
}

/* ============================================================
   Level-Up flash — a brief golden bloom over the whole shell
   when the player's rank advances. Motion-gated; under reduced
   motion the class is inert (the ::before only exists in the
   no-preference block) so nothing flashes.
   ============================================================ */
.web-shell.fx-levelup { position: relative; }
@media (prefers-reduced-motion: no-preference) {
    @keyframes bc-levelup-flash {
        0%   { opacity: 0; }
        20%  { opacity: 1; }
        100% { opacity: 0; }
    }
    .web-shell.fx-levelup::before {
        content: "";
        position: absolute;
        inset: 0;
        z-index: 40;
        pointer-events: none;
        background: radial-gradient(
            ellipse at center,
            rgba(251, 191, 36, 0.38) 0%,
            rgba(251, 191, 36, 0.10) 45%,
            rgba(251, 191, 36, 0) 75%
        );
        animation: bc-levelup-flash 900ms ease-out;
    }
}

/* ============================================================
   Damage flash — a brief red edge-pulse over the viewport when
   the player takes a hit (HP drops). A transient full-screen
   overlay element appended/removed by game.js. Motion-gated:
   under reduced motion the element has no styling and is inert.
   ============================================================ */
.bc-screenflash {
    position: fixed;
    inset: 0;
    z-index: 50;
    pointer-events: none;
}
@media (prefers-reduced-motion: no-preference) {
    @keyframes bc-damage-flash {
        0%   { opacity: 0; }
        12%  { opacity: 1; }
        100% { opacity: 0; }
    }
    .bc-screenflash-damage {
        background: radial-gradient(
            ellipse at center,
            rgba(248, 113, 113, 0) 40%,
            rgba(248, 113, 113, 0.5) 100%
        );
        animation: bc-damage-flash 600ms ease-out;
    }
    @keyframes bc-heal-flash {
        0%   { opacity: 0; }
        18%  { opacity: 1; }
        100% { opacity: 0; }
    }
    .bc-screenflash-heal {
        background: radial-gradient(
            ellipse at center,
            rgba(74, 222, 128, 0.35) 0%,
            rgba(74, 222, 128, 0) 70%
        );
        animation: bc-heal-flash 700ms ease-out;
    }
    @keyframes bc-unlock-flash {
        0%   { opacity: 0; }
        15%  { opacity: 1; }
        100% { opacity: 0; }
    }
    .bc-screenflash-unlock {
        background: radial-gradient(
            ellipse at 20% 80%,
            rgba(251, 191, 36, 0.45) 0%,
            rgba(251, 191, 36, 0) 55%
        );
        animation: bc-unlock-flash 800ms ease-out;
    }
    @keyframes bc-magic-flash {
        0%   { opacity: 0; }
        20%  { opacity: 1; }
        100% { opacity: 0; }
    }
    .bc-screenflash-magic {
        background: radial-gradient(
            ellipse at center,
            rgba(167, 139, 250, 0.32) 0%,
            rgba(96, 165, 250, 0.12) 40%,
            rgba(167, 139, 250, 0) 72%
        );
        animation: bc-magic-flash 720ms ease-out;
    }
    @keyframes bc-poweron {
        0%   { opacity: 1; transform: scaleY(0.004); filter: brightness(2.4); }
        18%  { opacity: 1; transform: scaleY(0.03); }
        42%  { opacity: 0.85; transform: scaleY(1); filter: brightness(1.6); }
        100% { opacity: 0; transform: scaleY(1); filter: brightness(1); }
    }
    .bc-screenflash-poweron {
        background: linear-gradient(
            to bottom,
            rgba(74, 222, 128, 0.15),
            rgba(226, 255, 230, 0.55) 48%,
            rgba(74, 222, 128, 0.2)
        );
        transform-origin: center;
        animation: bc-poweron 920ms cubic-bezier(0.22, 1, 0.36, 1);
    }
}

/* ============================================================
   Gameplay terminal FX — room warp, casts, glitch, prompt pulse.
   Motion-gated; reduced-motion leaves the classes inert.
   ============================================================ */
.tui-content.fx-warp,
.tui-content.fx-cast-log {
    position: relative;
}
@media (prefers-reduced-motion: no-preference) {
    @keyframes bc-warp {
        from { transform: translateY(-110%); opacity: 1; }
        to   { transform: translateY(110%); opacity: 0; }
    }
    .tui-content.fx-warp::after {
        content: "";
        position: absolute;
        left: 0;
        right: 0;
        top: 0;
        height: 28%;
        z-index: 6;
        pointer-events: none;
        background: linear-gradient(
            to bottom,
            transparent,
            rgba(96, 165, 250, 0.18) 40%,
            rgba(255, 255, 255, 0.55) 50%,
            rgba(96, 165, 250, 0.18) 60%,
            transparent
        );
        animation: bc-warp 480ms ease-out;
    }
    .tui-content.fx-cast-log {
        box-shadow: inset 0 0 28px rgba(167, 139, 250, 0.35);
    }
    @keyframes bc-glitch {
        0%, 100% { transform: none; text-shadow: none; }
        25% { transform: translate(-2px, 1px); text-shadow: -2px 0 var(--accent-red), 2px 0 var(--accent-blue); }
        50% { transform: translate(2px, -1px); text-shadow: 2px 0 var(--accent-red), -2px 0 var(--accent-cyan, #2dd4bf); }
        75% { transform: translate(-1px, 0); }
    }
    .tui-log.fx-glitch {
        animation: bc-glitch 280ms steps(2, end);
    }
    @keyframes bc-phosphor {
        from { filter: brightness(1.55); text-shadow: 0 0 10px rgba(74, 222, 128, 0.55); }
        to   { filter: none; }
    }
    .tui-log.fx-fresh span:last-of-type {
        animation: bc-phosphor 400ms ease-out;
    }
    #prompt-label.fx-cast {
        color: var(--accent-purple);
        text-shadow: 0 0 10px rgba(167, 139, 250, 0.85);
    }
    .tui-input-row.fx-submit .tui-input {
        border-color: var(--accent-green);
        box-shadow: 0 0 12px rgba(74, 222, 128, 0.4);
    }
    @keyframes bc-arrive {
        0%   { color: var(--accent-yellow); text-shadow: 0 0 8px rgba(251, 191, 36, 0.7); }
        100% { color: inherit; text-shadow: none; }
    }
    .map-panel.fx-arrive .map-here {
        animation: bc-arrive 700ms ease-out;
    }
    .hero-stage[data-mood="cast"] .hero-spark {
        animation: hero-twinkle 620ms ease-out 1;
    }
}

/* === Sidebar overhaul: inventory items, collapsible quest log, generative map === */

/* Keep the map panel sized to its content; the whole .tui-sidebar scrolls. */
.map-panel {
    flex: 0 0 auto;
}

/* --- Inventory: vitals bar, then a clear carried-items list --- */
.inv-hp {
    margin: 0 0 0.4rem;
}
.inv-heading {
    margin: 0.2rem 0 0.3rem;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.inv-items {
    margin: 0;
    padding: 0;
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}
.inv-items li {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    color: var(--accent-yellow);
}
.inv-empty {
    margin: 0;
    font-style: italic;
}

/* Label that marks the room's contents (distinct from carried inventory). */
.room-contents-label {
    margin: 0.35rem 0 0.15rem;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* --- Collapsible quest log --- */
.quest-log {
    margin-top: 0.5rem;
    border-top: 1px solid var(--border-color);
    padding-top: 0.4rem;
}
.quest-log > summary {
    cursor: pointer;
    list-style: none;
    font-size: 0.78rem;
    color: var(--accent-blue);
    user-select: none;
}
.quest-log > summary::-webkit-details-marker {
    display: none;
}
.quest-log > summary::before {
    content: "▸ ";
    color: var(--text-secondary);
}
.quest-log[open] > summary::before {
    content: "▾ ";
}
.quest-log > summary:hover {
    color: var(--accent-purple);
}
.ql-group {
    margin: 0.5rem 0 0.2rem;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.ql-list {
    margin: 0;
    padding: 0;
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.12rem;
}
.ql-list li {
    font-size: 0.82rem;
    line-height: 1.3;
}
.ql-done {
    color: var(--accent-green);
}
.ql-active {
    color: var(--accent-yellow);
    font-weight: 700;
}
.ql-locked,
.ql-side {
    color: var(--text-secondary);
}

/* --- Generative dungeon map (fog-of-war tree) --- */
.map-tree {
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
    font-family: var(--font-mono);
    font-size: 0.78rem;
    line-height: 1.35;
    white-space: pre;
    overflow-x: auto;
    color: var(--text-secondary);
}
.map-tree .map-seen {
    color: var(--accent-blue);
}
.map-tree .map-here {
    color: var(--accent-yellow);
    font-weight: 700;
}
.map-tree .map-fog {
    color: var(--text-secondary);
    opacity: 0.55;
}
.map-legend {
    margin: 0.4rem 0 0;
    font-size: 0.7rem;
}

@media (prefers-reduced-motion: no-preference) {
    .map-tree .map-here {
        text-shadow: 0 0 6px rgba(251, 191, 36, 0.45);
    }
}

/* ============================================================
 * Mode shell: nav tabs · landing · Practice Arcade · Reference
 * (flagship additions — Story · Arcade · Reference router)
 * ============================================================ */

/* ── Mode nav tabs (header) ── */
.mode-nav {
    display: flex;
    gap: 0.35rem;
    flex-wrap: wrap;
    justify-content: center;
}

.mode-tab {
    padding: 0.35rem 0.9rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--text-secondary);
    font-family: var(--font-mono);
    font-size: 0.85rem;
    cursor: pointer;
    transition: color 120ms ease, border-color 120ms ease, background 120ms ease;
}

.mode-tab:hover,
.mode-tab:focus-visible {
    color: var(--text-heading);
    border-color: var(--accent-blue);
    outline: none;
}

.mode-tab-on {
    color: var(--accent-blue);
    border-color: var(--accent-blue);
    background: var(--bg-input);
    box-shadow: 0 0 10px color-mix(in srgb, var(--accent-blue) 25%, transparent);
}

.footer-mode-hint {
    color: var(--accent-purple);
}

/* ── Inline syntax hint (under the prompt) ── */
.inline-hint {
    margin: 0;
    padding: 0.15rem 1rem 0.35rem 1rem;
    font-family: var(--font-mono);
    font-size: 0.78rem;
    color: var(--text-muted);
    background: var(--bg-secondary);
    border-top: 1px dashed var(--border-color);
}

.inline-hint code {
    color: var(--accent-yellow);
}

/* ── Chips (shared: spotlight, arcade cards, decks, reference) ── */
.chip {
    display: inline-block;
    margin: 0.1rem 0.2rem 0.1rem 0;
    padding: 0.08rem 0.45rem;
    border: 1px solid var(--border-color);
    border-radius: 999px;
    background: var(--bg-input);
    color: var(--accent-purple);
    font-family: var(--font-mono);
    font-size: 0.72rem;
}

.cheat-line {
    margin: 0.25rem 0;
    font-size: 0.8rem;
    line-height: 1.35;
}

.cheat-line code {
    color: var(--accent-yellow);
    font-family: var(--font-mono);
    font-size: 0.78rem;
}

/* ── Practice Arcade home (cards grid) ── */
.arcade-home {
    overflow-y: auto;
    padding: 1.25rem 1.5rem 2rem;
}

.arcade-intro h2 {
    margin: 0 0 0.2rem;
    color: var(--text-heading);
    font-family: var(--font-mono);
    letter-spacing: 0.04em;
}

.arcade-intro p {
    margin: 0 0 1rem;
}

.arcade-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 0.9rem;
}

.arcade-card {
    padding: 0.9rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    background: var(--bg-card);
    cursor: pointer;
    transition: transform 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
}

.arcade-card:hover,
.arcade-card:focus-visible {
    transform: translateY(-2px);
    border-color: var(--accent-purple);
    box-shadow: 0 4px 18px color-mix(in srgb, var(--accent-purple) 22%, transparent);
    outline: none;
}

.arcade-card h3 {
    margin: 0.3rem 0 0.25rem;
    color: var(--text-heading);
    font-family: var(--font-mono);
    font-size: 1rem;
}

.arcade-card p {
    margin: 0.2rem 0;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.arcade-card-icon {
    font-size: 1.6rem;
    line-height: 1;
}

.arcade-card-stats {
    font-size: 0.75rem;
}

.arcade-decks {
    margin-top: 1.25rem;
}

.arcade-decks p {
    margin: 0 0 0.4rem;
    font-size: 0.85rem;
}

.chip-action {
    cursor: pointer;
    transition: color 120ms ease, border-color 120ms ease;
}

.chip-action:hover,
.chip-action:focus-visible {
    color: var(--accent-blue);
    border-color: var(--accent-blue);
    outline: none;
}

.chip-on {
    color: var(--accent-blue);
    border-color: var(--accent-blue);
    background: var(--bg-input);
}

.arcade-best-list {
    margin: 0;
    padding-left: 1rem;
    font-size: 0.82rem;
    line-height: 1.6;
}

/* ── Reference mode ── */
.ref-main {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
}

.ref-controls {
    padding: 0.8rem 1.5rem 0.4rem;
}

.ref-search {
    width: 100%;
    max-width: 480px;
}

.ref-content {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 0.4rem 1.5rem 2rem;
}

.ref-chips {
    margin: 0.4rem 0 0.9rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.ref-chips .chip {
    font-size: 0.78rem;
    padding: 0.18rem 0.6rem;
}

.ref-card {
    margin: 0 0 1rem;
    padding: 0.9rem 1.1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    background: var(--bg-card);
}

.ref-card h3 {
    margin: 0 0 0.5rem;
    font-family: var(--font-mono);
    font-size: 0.95rem;
    color: var(--accent-blue);
    letter-spacing: 0.03em;
}

.ref-card h4 {
    margin: 0.8rem 0 0.3rem;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--text-muted);
    letter-spacing: 0.08em;
}

.ref-table-wrap {
    overflow-x: auto;
}

.ref-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.ref-table td {
    padding: 0.3rem 0.75rem 0.3rem 0;
    border-bottom: 1px solid color-mix(in srgb, var(--border-color) 55%, transparent);
    vertical-align: top;
}

.ref-table tr:last-child td {
    border-bottom: 0;
}

.ref-cmd {
    display: inline-block;
    padding: 0.1rem 0.45rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-input);
    color: var(--accent-yellow);
    font-family: var(--font-mono);
    white-space: nowrap;
    cursor: copy;
    transition: border-color 120ms ease, color 120ms ease;
}

.ref-cmd:hover {
    border-color: var(--accent-yellow);
}

.ref-copied {
    color: var(--accent-green);
    border-color: var(--accent-green);
}

.ref-empty {
    padding: 1rem 0;
}

/* ── Landing overlay (first visit) ── */
.landing-overlay {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.25rem;
    background: color-mix(in srgb, var(--bg-primary) 88%, black);
    backdrop-filter: blur(3px);
}

.landing-card {
    max-width: 720px;
    width: 100%;
    max-height: 92vh;
    overflow-y: auto;
    padding: 1.6rem 1.8rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    background: var(--bg-card);
    text-align: center;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.45);
}

.landing-logo {
    display: block;
    height: 42px;
    width: auto;
    margin: 0 auto 0.55rem;
}

.landing-card .landing-title {
    margin: 0 auto 0.8rem;
    text-align: center;
    color: var(--accent-purple);
    font-family: var(--font-mono);
    font-size: 1rem;
    letter-spacing: 0.16em;
    text-transform: uppercase;
}

.landing-card h1 {
    margin: 0 0 0.25rem;
    font-size: 1.35rem;
    color: var(--text-heading);
}

.landing-card > p {
    margin: 0 0 1.1rem;
}

.landing-doors {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0.8rem;
    margin-bottom: 1rem;
}

.landing-door {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    padding: 0.95rem 0.9rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    background: var(--bg-input);
    color: var(--text-secondary);
    text-align: left;
    cursor: pointer;
    transition: transform 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
}

.landing-door:hover,
.landing-door:focus-visible {
    transform: translateY(-2px);
    border-color: var(--accent-green);
    box-shadow: 0 4px 18px color-mix(in srgb, var(--accent-green) 20%, transparent);
    outline: none;
}

.landing-door strong {
    color: var(--text-heading);
    font-family: var(--font-mono);
}

.landing-door span:last-child {
    font-size: 0.8rem;
    line-height: 1.4;
}

.landing-door-icon {
    font-size: 1.4rem;
}

.landing-tip {
    margin: 0;
    font-size: 0.8rem;
}

.landing-tip code {
    color: var(--accent-yellow);
    font-family: var(--font-mono);
}

/* ── Toast (transient status, bottom-right) ── */
#bc-toast {
    position: fixed;
    right: 1rem;
    bottom: 3.2rem;
    z-index: 70;
    padding: 0.5rem 0.9rem;
    border: 1px solid var(--accent-green);
    border-radius: var(--radius-md);
    background: var(--bg-card);
    color: var(--accent-green);
    font-family: var(--font-mono);
    font-size: 0.82rem;
    opacity: 0;
    transform: translateY(8px);
    pointer-events: none;
    transition: opacity 180ms ease, transform 180ms ease;
}

#bc-toast.bc-toast-show {
    opacity: 1;
    transform: translateY(0);
}

/* ── Responsive: small screens ── */
@media (max-width: 900px) {
    .tui-header {
        flex-wrap: wrap;
        gap: 0.4rem;
    }

    .mode-nav {
        order: 3;
        width: 100%;
    }

    .arcade-home {
        padding: 0.9rem 0.9rem 1.5rem;
    }

    .ref-controls,
    .ref-content {
        padding-left: 0.9rem;
        padding-right: 0.9rem;
    }
}

@media (max-width: 600px) {
    .landing-doors {
        grid-template-columns: 1fr;
    }

    .tui-footer span:nth-child(n+4):not(#footer-mode-hint) {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .mode-tab,
    .arcade-card,
    .landing-door,
    #bc-toast,
    .tui-panel,
    .tui-prompt,
    .tui-input,
    .tui-log span {
        transition: none;
        animation: none !important;
    }
    .tui-content.fx-play::after,
    .tui-content.fx-play::before {
        animation: none !important;
        opacity: 0;
    }
}

/* ============================================================
   Per-command + per-flag terminal FX.
   .tui-content.fx-play[data-fx-motion] drives the overlay;
   flags tint via --fx-hue / attribute selectors. Smooth easings.
   ============================================================ */
.tui-content {
    --fx-accent: var(--accent-blue);
    --fx-hue: 0;
    transition: box-shadow 420ms cubic-bezier(0.22, 1, 0.36, 1);
}
.tui-content.fx-play {
    box-shadow: inset 0 0 28px color-mix(in srgb, var(--fx-accent) 28%, transparent);
}
.tui-content.fx-play::after,
.tui-content.fx-play::before {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 6;
}
.tui-content.fx-play::before {
    z-index: 5;
    mix-blend-mode: screen;
    opacity: 0;
}

@media (prefers-reduced-motion: no-preference) {
    #prompt-label,
    .tui-input,
    .tui-button,
    .mode-tab {
        transition: color 280ms ease, background-color 280ms ease, border-color 280ms ease, box-shadow 320ms cubic-bezier(0.22, 1, 0.36, 1);
    }

    @keyframes fx-scan {
        from { transform: translateX(-120%); opacity: 0.9; }
        to   { transform: translateX(120%); opacity: 0; }
    }
    @keyframes fx-radar {
        from { transform: rotate(0deg) scale(0.4); opacity: 0.7; }
        to   { transform: rotate(220deg) scale(1.4); opacity: 0; }
    }
    @keyframes fx-sweep-y {
        from { transform: translateY(-120%); opacity: 0.85; }
        to   { transform: translateY(120%); opacity: 0; }
    }
    @keyframes fx-sweep-y-rev {
        from { transform: translateY(120%); opacity: 0.85; }
        to   { transform: translateY(-120%); opacity: 0; }
    }
    @keyframes fx-sweep-x-rev {
        from { transform: translateX(120%); opacity: 0.85; }
        to   { transform: translateX(-120%); opacity: 0; }
    }
    @keyframes fx-bloom {
        0%   { opacity: 0; transform: scale(0.6); }
        35%  { opacity: 0.7; transform: scale(1); }
        100% { opacity: 0; transform: scale(1.25); }
    }
    @keyframes fx-wipe-down {
        from { clip-path: inset(0 0 100% 0); opacity: 0.8; }
        to   { clip-path: inset(0 0 0 0); opacity: 0; }
    }
    @keyframes fx-wipe-up {
        from { clip-path: inset(100% 0 0 0); opacity: 0.8; }
        to   { clip-path: inset(0 0 0 0); opacity: 0; }
    }
    @keyframes fx-ripple {
        0%   { transform: scale(0.2); opacity: 0.65; }
        100% { transform: scale(1.8); opacity: 0; }
    }
    @keyframes fx-spark {
        0%   { opacity: 0; filter: brightness(1); }
        30%  { opacity: 0.8; filter: brightness(1.5); }
        100% { opacity: 0; filter: brightness(1); }
    }
    @keyframes fx-skew {
        0%   { transform: translateX(0) skewX(0); opacity: 0.7; }
        40%  { transform: translateX(18px) skewX(-8deg); opacity: 0.5; }
        100% { transform: translateX(48px) skewX(0); opacity: 0; }
    }
    @keyframes fx-mirror {
        0%   { transform: scaleX(1); opacity: 0.55; }
        50%  { transform: scaleX(-1); opacity: 0.4; }
        100% { transform: scaleX(1); opacity: 0; }
    }
    @keyframes fx-shake-soft {
        0%, 100% { transform: translateX(0); opacity: 0.5; }
        25% { transform: translateX(-4px); }
        75% { transform: translateX(4px); opacity: 0; }
    }
    @keyframes fx-room-enter {
        from { opacity: 0; transform: translateY(8px); }
        to   { opacity: 1; transform: translateY(0); }
    }

    .tui-content.fx-play::after {
        filter: hue-rotate(calc(var(--fx-hue) * 1deg));
        background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--fx-accent) 45%, white 10%), transparent);
        animation: fx-scan 520ms cubic-bezier(0.22, 1, 0.36, 1);
    }
    .tui-content.fx-play[data-fx-motion="radar"]::after {
        inset: 20%;
        border-radius: 50%;
        background: conic-gradient(from 0deg, transparent 0 70%, color-mix(in srgb, var(--fx-accent) 55%, transparent) 100%);
        animation: fx-radar 640ms cubic-bezier(0.22, 1, 0.36, 1);
    }
    .tui-content.fx-play[data-fx-motion="warp"]::after,
    .tui-content.fx-play[data-fx-motion="steam"]::after {
        background: linear-gradient(to bottom, transparent, color-mix(in srgb, var(--fx-accent) 40%, white 20%) 50%, transparent);
        animation: fx-sweep-y 480ms cubic-bezier(0.22, 1, 0.36, 1);
    }
    .tui-content.fx-play[data-fx-motion="climb"]::after {
        background: linear-gradient(to bottom, transparent, color-mix(in srgb, var(--fx-accent) 40%, white 20%) 50%, transparent);
        animation: fx-sweep-y-rev 480ms cubic-bezier(0.22, 1, 0.36, 1);
    }
    .tui-content.fx-play[data-fx-motion="rewind"]::after {
        animation: fx-sweep-x-rev 480ms cubic-bezier(0.22, 1, 0.36, 1);
    }
    .tui-content.fx-play[data-fx-motion="home"]::after,
    .tui-content.fx-play[data-fx-motion="cast"]::after,
    .tui-content.fx-play[data-fx-motion="spark"]::after,
    .tui-content.fx-play[data-fx-motion="bloom"]::after,
    .tui-content.fx-play[data-fx-motion="seal"]::after,
    .tui-content.fx-play[data-fx-motion="pulse"]::after {
        background: radial-gradient(ellipse at center, color-mix(in srgb, var(--fx-accent) 50%, transparent), transparent 70%);
        animation: fx-bloom 640ms cubic-bezier(0.22, 1, 0.36, 1);
    }
    .tui-content.fx-play[data-fx-motion="cat"]::after {
        background: none;
        animation: none;
    }
    .tui-content.fx-play[data-fx-motion="unroll"]::after,
    .tui-content.fx-play[data-fx-motion="peek-top"]::after,
    .tui-content.fx-play[data-fx-motion="lore"]::after,
    .tui-content.fx-play[data-fx-motion="branch"]::after {
        background: linear-gradient(to bottom, color-mix(in srgb, var(--fx-accent) 35%, transparent), transparent);
        animation: fx-wipe-down 560ms cubic-bezier(0.22, 1, 0.36, 1);
    }
    .tui-content.fx-play[data-fx-motion="peek-bottom"]::after,
    .tui-content.fx-play[data-fx-motion="follow"]::after {
        background: linear-gradient(to top, color-mix(in srgb, var(--fx-accent) 35%, transparent), transparent);
        animation: fx-wipe-up 560ms cubic-bezier(0.22, 1, 0.36, 1);
    }
    .tui-content.fx-play[data-fx-motion="hunt"]::after,
    .tui-content.fx-play[data-fx-motion="identify"]::after,
    .tui-content.fx-play[data-fx-motion="compass"]::after {
        inset: 15%;
        border-radius: 50%;
        background: radial-gradient(circle, color-mix(in srgb, var(--fx-accent) 55%, transparent), transparent 65%);
        animation: fx-ripple 620ms cubic-bezier(0.22, 1, 0.36, 1);
    }
    .tui-content.fx-play[data-fx-motion="ripple"]::after,
    .tui-content.fx-play[data-fx-motion="echo"]::after,
    .tui-content.fx-play[data-fx-motion="absorb"]::after {
        border-radius: 50%;
        border: 2px solid var(--fx-accent);
        background: transparent;
        animation: fx-ripple 640ms cubic-bezier(0.22, 1, 0.36, 1);
    }
    .tui-content.fx-play[data-fx-motion="forge"]::after,
    .tui-content.fx-play[data-fx-motion="grant"]::after,
    .tui-content.fx-play[data-fx-motion="beast"]::after,
    .tui-content.fx-play[data-fx-motion="streak"]::after {
        background: radial-gradient(ellipse at 50% 80%, color-mix(in srgb, var(--fx-accent) 55%, transparent), transparent 60%);
        animation: fx-spark 560ms cubic-bezier(0.22, 1, 0.36, 1);
    }
    .tui-content.fx-play[data-fx-motion="copy"]::after,
    .tui-content.fx-play[data-fx-motion="shift"]::after,
    .tui-content.fx-play[data-fx-motion="slice"]::after {
        animation: fx-skew 500ms cubic-bezier(0.22, 1, 0.36, 1);
    }
    .tui-content.fx-play[data-fx-motion="mirror"]::after,
    .tui-content.fx-play[data-fx-motion="invert"]::after,
    .tui-content.fx-play[data-fx-motion="morph"]::after,
    .tui-content.fx-play[data-fx-motion="rewrite"]::after {
        background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--fx-accent) 40%, transparent), transparent);
        animation: fx-mirror 560ms ease-in-out;
    }
    .tui-content.fx-play[data-fx-motion="burn"]::after,
    .tui-content.fx-play[data-fx-motion="revoke"]::after,
    .tui-content.fx-play[data-fx-motion="error"]::after {
        background: radial-gradient(ellipse at center, color-mix(in srgb, var(--fx-accent) 40%, transparent), transparent 70%);
        animation: fx-shake-soft 380ms ease-in-out;
    }
    .tui-content.fx-play[data-fx-motion="clear"]::after {
        background: var(--bg-primary);
        animation: fx-bloom 500ms ease-out;
    }
    .tui-content.fx-play[data-fx-motion="shuffle"]::after,
    .tui-content.fx-play[data-fx-motion="merge"]::after,
    .tui-content.fx-play[data-fx-motion="tally"]::after,
    .tui-content.fx-play[data-fx-motion="numbers"]::after,
    .tui-content.fx-play[data-fx-motion="tick"]::after,
    .tui-content.fx-play[data-fx-motion="grid"]::after,
    .tui-content.fx-play[data-fx-motion="bind"]::after,
    .tui-content.fx-play[data-fx-motion="scale"]::after,
    .tui-content.fx-play[data-fx-motion="mark"]::after,
    .tui-content.fx-play[data-fx-motion="unveil"]::after,
    .tui-content.fx-play[data-fx-motion="ledger"]::after,
    .tui-content.fx-play[data-fx-motion="blink"]::after,
    .tui-content.fx-play[data-fx-motion="soften"]::after {
        background: linear-gradient(115deg, transparent 30%, color-mix(in srgb, var(--fx-accent) 40%, transparent) 50%, transparent 70%);
        animation: fx-scan 540ms cubic-bezier(0.22, 1, 0.36, 1);
    }

    .tui-content.fx-play[data-fx-flags*="a"]::before {
        background: radial-gradient(ellipse at 20% 30%, rgba(251, 191, 36, 0.35), transparent 55%);
        animation: fx-bloom 560ms cubic-bezier(0.22, 1, 0.36, 1);
        opacity: 1;
    }
    .tui-content.fx-play[data-fx-flags*="F"]::before {
        background: repeating-linear-gradient(90deg, transparent 0 12px, color-mix(in srgb, var(--fx-accent) 22%, transparent) 12px 13px);
        animation: fx-wipe-down 500ms cubic-bezier(0.22, 1, 0.36, 1);
        opacity: 1;
    }
    .tui-content.fx-play[data-fx-flags*="l"]::before {
        background: repeating-linear-gradient(to bottom, transparent 0 1.35em, color-mix(in srgb, var(--fx-accent) 18%, transparent) 1.35em 1.4em);
        animation: fx-wipe-down 520ms cubic-bezier(0.22, 1, 0.36, 1);
        opacity: 1;
    }
    .tui-content.fx-play[data-fx-flags*="r"]::before,
    .tui-content.fx-play[data-fx-flags*="R"]::before {
        border-radius: 50%;
        border: 2px solid color-mix(in srgb, var(--fx-accent) 50%, white);
        background: transparent;
        animation: fx-ripple 620ms cubic-bezier(0.22, 1, 0.36, 1);
        opacity: 1;
    }
    .tui-content.fx-play[data-fx-pipe="1"] {
        box-shadow: inset 8px 0 18px color-mix(in srgb, var(--fx-accent) 25%, transparent),
                    inset -8px 0 18px color-mix(in srgb, var(--accent-green) 20%, transparent);
    }
    .tui-content.fx-play[data-fx-redirect="write"] .tui-log,
    .tui-content.fx-play[data-fx-redirect="append"] .tui-log {
        text-shadow: 0 0 10px var(--fx-accent);
    }

    .tui-room-panel.fx-room-enter .room-vignette,
    .tui-room-panel.fx-room-enter #room-panel {
        animation: fx-room-enter 420ms cubic-bezier(0.22, 1, 0.36, 1);
    }
    .map-panel.fx-arrive .map-tree {
        animation: fx-room-enter 420ms cubic-bezier(0.22, 1, 0.36, 1);
    }
}

/* Pixel cat — walks in on `cat`/`less` and coughs file text in, pixelated. */
.px-cat {
    --cat-px: 5px;
    position: absolute;
    left: 1.1rem;
    bottom: 1.1rem;
    z-index: 8;
    width: calc(var(--cat-px) * 14);
    height: calc(var(--cat-px) * 12);
    pointer-events: none;
    opacity: 0;
}
.px-cat-sprite {
    position: relative;
    width: 100%;
    height: 100%;
}
.px-cat-sprite > span {
    position: absolute;
    image-rendering: pixelated;
}
.px-cat-ear {
    width: calc(var(--cat-px) * 2);
    height: calc(var(--cat-px) * 2);
    background: #c4843c;
    clip-path: polygon(50% 0, 100% 100%, 0 100%);
}
.px-cat-ear-l { left: calc(var(--cat-px) * 3); top: 0; }
.px-cat-ear-r { left: calc(var(--cat-px) * 8); top: 0; }
.px-cat-head {
    left: calc(var(--cat-px) * 3);
    top: calc(var(--cat-px) * 2);
    width: calc(var(--cat-px) * 7);
    height: calc(var(--cat-px) * 5);
    background: #e8b86d;
}
.px-cat-eye {
    width: var(--cat-px);
    height: var(--cat-px);
    background: #1a1423;
}
.px-cat-eye-l { left: calc(var(--cat-px) * 4.5); top: calc(var(--cat-px) * 3.5); }
.px-cat-eye-r { left: calc(var(--cat-px) * 7.5); top: calc(var(--cat-px) * 3.5); }
.px-cat-nose {
    left: calc(var(--cat-px) * 6);
    top: calc(var(--cat-px) * 5);
    width: var(--cat-px);
    height: var(--cat-px);
    background: #f87171;
}
.px-cat-body {
    left: calc(var(--cat-px) * 2);
    top: calc(var(--cat-px) * 6);
    width: calc(var(--cat-px) * 8);
    height: calc(var(--cat-px) * 4);
    background: #d4a056;
}
.px-cat-paw {
    width: calc(var(--cat-px) * 2);
    height: calc(var(--cat-px) * 2);
    background: #c4843c;
    top: calc(var(--cat-px) * 10);
}
.px-cat-paw-f { left: calc(var(--cat-px) * 3); }
.px-cat-paw-b { left: calc(var(--cat-px) * 7); }
.px-cat-tail {
    left: calc(var(--cat-px) * 10);
    top: calc(var(--cat-px) * 6);
    width: calc(var(--cat-px) * 4);
    height: var(--cat-px);
    background: #c4843c;
    transform-origin: left center;
}
.px-cat-bit {
    width: var(--cat-px);
    height: var(--cat-px);
    background: var(--accent-yellow);
    opacity: 0;
    box-shadow: 0 0 0 1px rgba(251, 191, 36, 0.4);
}
[data-theme="light"] .px-cat-head { background: #c9954a; }
[data-theme="light"] .px-cat-body { background: #b07d38; }

@media (prefers-reduced-motion: no-preference) {
    @keyframes px-cat-walk {
        0%   { transform: translateX(-96px) translateY(4px); opacity: 0; }
        10%  { opacity: 1; }
        42%  { transform: translateX(6px) translateY(0); opacity: 1; }
        55%  { transform: translateX(16px) translateY(3px); }
        78%  { transform: translateX(22px) translateY(0); opacity: 1; }
        100% { transform: translateX(52px) translateY(-8px); opacity: 0; }
    }
    @keyframes px-cat-paw {
        0%, 100% { transform: translateY(0); }
        50%      { transform: translateY(calc(var(--cat-px) * -0.8)); }
    }
    @keyframes px-cat-tail {
        0%, 100% { transform: rotate(-18deg); }
        50%      { transform: rotate(26deg); }
    }
    @keyframes px-cat-hack {
        0%   { opacity: 0; transform: translate(0, 0) scale(1); }
        18%  { opacity: 1; }
        100% { opacity: 0; transform: translate(calc(var(--cat-px) * 7), calc(var(--cat-px) * 5)) scale(0.5); }
    }
    @keyframes fx-cat-load {
        0%   { opacity: 0; filter: contrast(8) brightness(1.7) saturate(0); clip-path: inset(0 100% 0 0); }
        38%  { opacity: 1; filter: contrast(3) brightness(1.25); clip-path: inset(0 52% 0 0); }
        72%  { filter: contrast(1.3); clip-path: inset(0 10% 0 0); }
        100% { opacity: 1; filter: none; clip-path: inset(0 0 0 0); }
    }
    .px-cat.px-cat-run {
        animation: px-cat-walk 1.55s cubic-bezier(0.22, 1, 0.36, 1) both;
    }
    .px-cat-run .px-cat-paw-f { animation: px-cat-paw 160ms ease-in-out 7; }
    .px-cat-run .px-cat-paw-b { animation: px-cat-paw 160ms ease-in-out 7; animation-delay: 80ms; }
    .px-cat-run .px-cat-tail { animation: px-cat-tail 360ms ease-in-out 4; }
    .px-cat-run .px-cat-bit-1 {
        left: calc(var(--cat-px) * 9);
        top: calc(var(--cat-px) * 5);
        animation: px-cat-hack 640ms ease-out 520ms both;
    }
    .px-cat-run .px-cat-bit-2 {
        left: calc(var(--cat-px) * 8);
        top: calc(var(--cat-px) * 4);
        animation: px-cat-hack 640ms ease-out 620ms both;
    }
    .px-cat-run .px-cat-bit-3 {
        left: calc(var(--cat-px) * 10);
        top: calc(var(--cat-px) * 6);
        animation: px-cat-hack 640ms ease-out 720ms both;
    }
    .tui-content.fx-cat-play .tui-log {
        background-image:
            repeating-linear-gradient(0deg, transparent 0 3px, rgba(251, 191, 36, 0.07) 3px 4px),
            repeating-linear-gradient(90deg, transparent 0 3px, rgba(251, 191, 36, 0.04) 3px 4px);
    }
    .tui-log span.fx-cat-text {
        animation: fx-cat-load 640ms cubic-bezier(0.22, 1, 0.36, 1) both;
        animation-delay: var(--cat-delay, 0ms);
    }
}

/* The `hidden` attribute must always win, even over display rules above
 * (mode sections and the landing overlay set display:flex/grid). */
[hidden] {
    display: none !important;
}
