  @import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@400;600;700&family=IM+Fell+English:ital@0;1&family=Share+Tech+Mono&display=swap');

  :root {
    --ink: #0a0806;
    --parchment: #f0e8d8;
    --parchment-dim: #d9ccb4;
    --ember: #c94a1a;
    --ember-glow: #e8622a;
    --gold: #b8922a;
    --gold-light: #d4a83a;
    --ash: #6b5c4e;
    --fog: #3a2f26;
    --blood: #7a1a1a;
    --surface: #12100e;
    --surface-raised: #1c1814;
    --surface-border: #2a2018;
    --health-green: #4a7c4e;
    --health-red: #8b2222;
    --text-primary: #f0e6d0;
    --text-muted: #b8a890;
    --text-dim: #8a7a68;
    --accent-crown: #8a6fd1;
    --accent-zero: #5fa8a0;
    --accent-train: #c9a85c;
    --accent-serpent: #4f7fb8;
    --accent-dust: #8c9c42;
    --font-display: 'Cinzel', serif;
    --font-body: 'IM Fell English', serif;
    --font-mono: 'Share Tech Mono', monospace;
  }

  * { box-sizing: border-box; margin: 0; padding: 0; }

  body {
    background: var(--ink);
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 17px;
    line-height: 1.7;
    min-height: 100vh;
    overflow-x: hidden;
  }

  /* VIGNETTE BACKGROUND */
  body::before {
    content: '';
    position: fixed;
    inset: 0;
    background:
      radial-gradient(ellipse at 50% 0%, rgba(184,146,42,0.04) 0%, transparent 60%),
      radial-gradient(ellipse at 50% 100%, rgba(201,74,26,0.06) 0%, transparent 60%);
    pointer-events: none;
    z-index: 0;
  }

  /* ─── AUTH SCREEN ─── */
  .auth-screen {
    position: fixed;
    inset: 0;
    z-index: 900;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: var(--ink);
    overflow-y: auto;
  }

  .auth-card {
    width: 100%;
    max-width: 400px;
    padding: 20px 0;
  }

  .auth-field { margin-bottom: 18px; }

  .auth-label {
    display: block;
    font-family: var(--font-mono);
    font-size: 10px;
    letter-spacing: 0.2em;
    color: var(--text-dim);
    text-transform: uppercase;
    margin-bottom: 8px;
  }

  .auth-input {
    width: 100%;
    background: var(--surface-raised);
    border: 1px solid var(--surface-border);
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 1rem;
    padding: 13px 14px;
    outline: none;
    border-radius: 1px;
    transition: border-color 0.15s;
  }

  .auth-input:focus { border-color: var(--gold); }
  .auth-input::placeholder { color: var(--text-dim); }

  .auth-error {
    color: #e85a4a;
    font-size: 0.82rem;
    font-style: italic;
    margin-bottom: 12px;
    min-height: 1em;
  }

  .btn-auth-primary {
    width: 100%;
    background: var(--ember);
    color: var(--parchment);
    font-family: var(--font-display);
    font-size: 0.9rem;
    letter-spacing: 0.08em;
    border: none;
    padding: 15px;
    cursor: pointer;
    transition: background 0.15s;
    border-radius: 1px;
    touch-action: manipulation;
    margin-bottom: 18px;
  }

  .btn-auth-primary:hover { background: var(--ember-glow); }
  .btn-auth-primary:disabled { opacity: 0.5; cursor: not-allowed; }

  .auth-checkbox-field {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 18px;
  }

  .auth-checkbox-field input[type="checkbox"] {
    margin-top: 3px;
    accent-color: var(--gold);
    cursor: pointer;
  }

  .auth-checkbox-field label {
    font-size: 0.82rem;
    color: var(--text-muted);
    cursor: pointer;
  }

  .auth-switch {
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 18px;
  }

  .auth-switch a {
    color: var(--gold);
    text-decoration: none;
  }

  .auth-switch a:hover { text-decoration: underline; }

  .auth-forgot-link {
    text-align: right;
    margin-top: 8px;
  }

  .auth-forgot-link a {
    font-size: 0.78rem;
    color: var(--text-dim);
    text-decoration: none;
    transition: color 0.15s;
  }

  .auth-forgot-link a:hover { color: var(--gold); }

  .auth-divider {
    display: flex;
    align-items: center;
    text-align: center;
    margin-bottom: 18px;
    color: var(--text-dim);
    font-family: var(--font-mono);
    font-size: 0.7rem;
    letter-spacing: 0.1em;
  }

  .auth-divider::before, .auth-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--surface-border);
  }

  .auth-divider span { padding: 0 12px; }

  .btn-auth-guest {
    width: 100%;
    background: none;
    color: var(--text-muted);
    font-family: var(--font-display);
    font-size: 0.85rem;
    letter-spacing: 0.08em;
    border: 1px solid var(--surface-border);
    padding: 14px;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
    border-radius: 1px;
    touch-action: manipulation;
  }

  .btn-auth-guest:hover { color: var(--parchment); border-color: var(--ash); }

  .auth-note {
    text-align: center;
    font-size: 0.72rem;
    color: var(--text-dim);
    font-style: italic;
    line-height: 1.5;
    margin-top: 24px;
  }

  /* ─── CHARACTER CREATION SCREEN ─── */
  .char-create-title {
    text-align: center;
    font-family: var(--font-display);
    font-size: 1.3rem;
    letter-spacing: 0.1em;
    color: var(--gold-light);
    text-transform: uppercase;
    margin-bottom: 28px;
  }

  .stat-row {
    margin-bottom: 18px;
    padding: 14px 16px;
    background: var(--surface-raised);
    border: 1px solid var(--surface-border);
    border-radius: 1px;
  }

  .stat-row-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .stat-name {
    font-family: var(--font-display);
    font-size: 0.95rem;
    letter-spacing: 0.08em;
    color: var(--parchment);
  }

  .stat-desc {
    font-size: 0.78rem;
    font-style: italic;
    color: var(--text-dim);
    margin-top: 6px;
  }

  .stat-stepper {
    display: flex;
    align-items: center;
    gap: 10px;
  }

  .stat-btn {
    width: 28px;
    height: 28px;
    background: none;
    border: 1px solid var(--surface-border);
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    border-radius: 1px;
    transition: color 0.15s, border-color 0.15s;
    touch-action: manipulation;
  }

  .stat-btn:hover:not(:disabled) { color: var(--gold); border-color: var(--gold); }
  .stat-btn:disabled { opacity: 0.3; cursor: not-allowed; }

  .stat-value {
    font-family: var(--font-mono);
    font-size: 1rem;
    color: var(--gold);
    min-width: 1.5em;
    text-align: center;
  }

  .points-remaining {
    text-align: center;
    font-family: var(--font-mono);
    font-size: 0.78rem;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: 22px;
  }

  .points-remaining.is-complete { color: var(--gold); }

  /* ─── LEVEL-UP SCREEN ─── */
  .levelup-points-label {
    font-family: var(--font-mono);
    font-size: 10px;
    letter-spacing: 0.2em;
    color: var(--text-dim);
    text-transform: uppercase;
    margin: 24px 0 14px;
  }

  .levelup-ability-label {
    text-align: center;
    font-family: var(--font-display);
    font-size: 0.85rem;
    letter-spacing: 0.08em;
    color: var(--gold-light);
    text-transform: uppercase;
    margin: 28px 0 14px;
  }

  .ability-option {
    text-align: left;
    background: var(--surface-raised);
    border: 1px solid var(--surface-border);
    border-radius: 1px;
    padding: 12px 14px;
    margin-bottom: 10px;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
  }

  .ability-option:hover { border-color: var(--ash); }
  .ability-option.selected { border-color: var(--gold); background: #221c14; }

  .ability-option-name {
    font-family: var(--font-display);
    font-size: 0.9rem;
    color: var(--parchment);
  }

  .ability-option.selected .ability-option-name { color: var(--gold-light); }

  .ability-option-desc {
    font-size: 0.8rem;
    font-style: italic;
    color: var(--text-dim);
    margin-top: 4px;
  }

  .account-bar {
    position: absolute;
    top: 20px;
    right: 24px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-family: var(--font-mono);
    font-size: 0.72rem;
    color: var(--text-dim);
    z-index: 10;
    flex-wrap: wrap;
    justify-content: flex-end;
    max-width: calc(100% - 48px);
  }

  @media (max-width: 600px) {
    .account-bar {
      position: static;
      width: 100%;
      justify-content: center;
      margin-bottom: 24px;
      padding: 0 16px;
    }
    .account-bar-email { display: none; } /* save space on phones */
  }

  .account-bar-email { color: var(--text-muted); }

  .account-bar-tokens {
    color: var(--gold);
    font-weight: bold;
  }

  .btn-buy-tokens-small {
    background: var(--gold);
    color: var(--ink);
    font-family: var(--font-mono);
    font-size: 0.68rem;
    letter-spacing: 0.08em;
    border: none;
    padding: 6px 12px;
    cursor: pointer;
    border-radius: 1px;
    transition: background 0.15s;
    touch-action: manipulation;
  }

  .btn-buy-tokens-small:hover { background: var(--gold-light); }

  .btn-logout, .btn-login-prompt {
    background: none;
    border: 1px solid var(--surface-border);
    color: var(--text-dim);
    font-family: var(--font-mono);
    font-size: 0.68rem;
    letter-spacing: 0.08em;
    padding: 6px 12px;
    cursor: pointer;
    border-radius: 1px;
    transition: color 0.15s, border-color 0.15s;
    touch-action: manipulation;
  }

  .btn-logout:hover, .btn-login-prompt:hover { color: var(--gold); border-color: var(--gold); }

  /* ─── WORLD SELECT SCREEN ─── */
  #world-select {
    position: relative;
    z-index: 10;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 60px 20px 40px;
  }

  .masthead {
    text-align: center;
    margin-bottom: 56px;
  }

  /* ─── PLAYER PROFILE SCREEN ─── */
  #player-profile-screen {
    position: relative;
    z-index: 10;
    min-height: 100vh;
    flex-direction: column;
    align-items: center;
    padding: 40px 20px 60px;
  }

  .profile-header {
    width: 100%;
    max-width: 640px;
    margin-bottom: 28px;
  }

  .profile-content {
    width: 100%;
    max-width: 640px;
    display: flex;
    flex-direction: column;
    gap: 28px;
  }

  .profile-section {
    background: var(--surface-raised);
    border: 1px solid var(--surface-border);
    border-radius: 2px;
    padding: 24px;
  }

  .profile-section-label {
    font-family: var(--font-mono);
    font-size: 10px;
    letter-spacing: 0.35em;
    color: var(--gold);
    text-transform: uppercase;
    margin-bottom: 18px;
    text-align: center;
  }

  .profile-history-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 1px solid var(--surface-border);
    font-size: 0.85rem;
  }

  .profile-history-row:last-child { border-bottom: none; }
  .profile-history-world { color: var(--text-primary); }
  .profile-history-status { color: var(--text-muted); font-family: var(--font-mono); font-size: 0.78rem; text-align: right; }

  .profile-history-stats {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--surface-border);
    font-size: 0.8rem;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    gap: 4px;
  }

  .profile-ability-row { font-size: 0.85rem; color: var(--text-primary); padding: 4px 0; }
  .profile-ability-row.locked { color: var(--text-dim); font-style: italic; }

  .profile-row { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 8px; }

  .profile-actions-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
  .profile-actions-row button { margin-bottom: 0; width: auto; }

  .profile-guest-message {
    text-align: center;
    font-style: italic;
    color: var(--text-muted);
    padding: 40px 20px;
  }

  .masthead-eyebrow {
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.3em;
    color: var(--gold);
    text-transform: uppercase;
    margin-bottom: 16px;
  }

  .masthead h1 {
    font-family: var(--font-display);
    font-size: clamp(2.4rem, 6vw, 4rem);
    font-weight: 700;
    color: var(--parchment);
    letter-spacing: 0.05em;
    text-shadow: 0 0 40px rgba(184,146,42,0.3), 0 2px 4px rgba(0,0,0,0.8);
    line-height: 1.1;
  }

  .masthead h1 span { color: var(--gold); }

  .masthead-sub {
    margin-top: 14px;
    font-style: italic;
    color: var(--text-muted);
    font-size: 1rem;
  }

  .divider {
    width: 200px;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--gold), transparent);
    margin: 24px auto;
    opacity: 0.5;
  }

  .character-summary {
    text-align: center;
    font-family: var(--font-display);
    font-size: 0.9rem;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 36px;
  }

  .character-summary .character-summary-name { color: var(--gold-light); }
  .character-summary a { color: var(--gold); text-decoration: none; }
  .character-summary a:hover { text-decoration: underline; }

  .worlds-label {
    font-family: var(--font-mono);
    font-size: 10px;
    letter-spacing: 0.4em;
    color: var(--text-dim);
    text-transform: uppercase;
    text-align: center;
    margin-bottom: 28px;
  }

  .worlds-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    align-items: start;
    column-gap: 16px;
    row-gap: 30px;
    width: 100%;
    max-width: 960px;
  }

  /* Holds every card in a world's chain (the main adventure plus any sequels), stacked
     vertically in document order so a sequel always sits directly beneath its parent,
     in the same grid column — works for any chain depth, not just 1 main + 1 sequel. */
  .world-card-chain-group {
    display: flex;
    flex-direction: column;
    gap: 14px;
  }

  /* Gentle separator between rows of chain-groups once the grid wraps. auto-fill's column
     count is responsive (varies by viewport), so which items start a new row can't be
     known from CSS alone — this class is applied via JS in renderWorldSelect() after
     layout, to whichever grid item (chain-group or standalone card) sits in row 2+. */
  .worlds-grid-row-start {
    border-top: 1px solid var(--surface-border);
    padding-top: 26px;
  }

  .world-card {
    background: var(--surface-raised);
    border: 1px solid var(--surface-border);
    border-radius: 2px;
    padding: 28px 24px;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 302px;
  }

  .world-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: var(--ember);
    opacity: 0;
    transition: opacity 0.2s;
  }

  .world-card:hover {
    border-color: var(--ash);
    background: #201a14;
  }

  .world-card:hover::before { opacity: 1; }

  .world-card-icon {
    font-size: 2rem;
    margin-bottom: 12px;
    display: block;
  }

  .world-card-genre {
    font-family: var(--font-mono);
    font-size: 9px;
    letter-spacing: 0.35em;
    color: var(--ember);
    text-transform: uppercase;
    margin-bottom: 8px;
  }

  .world-card h3 {
    font-family: var(--font-display);
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--parchment);
    margin-bottom: 10px;
  }

  /* Series code + episode number prefix, e.g. "SC1 · The Shattered Crown" — a distinct
     catalog-style font/color from the serif title it precedes. Color is overridden inline
     per-card to that world's own accentColor (see buildSeriesTitle in game.js) — this
     var(--text-dim) is just the fallback for a hypothetical world with no chain. */
  .world-card-series-code {
    font-family: var(--font-mono);
    font-size: 1em;
    font-weight: 700;
    letter-spacing: 0.05em;
    color: var(--text-dim);
  }

  .world-card p {
    font-size: 0.88rem;
    color: var(--text-muted);
    font-style: italic;
    line-height: 1.5;
  }

  .world-card-footer {
    margin-top: auto;
    padding-top: 14px;
    border-top: 1px solid var(--surface-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .world-card-difficulty {
    font-family: var(--font-mono);
    font-size: 9px;
    letter-spacing: 0.2em;
    color: var(--text-dim);
    text-transform: uppercase;
  }

  .world-card-cta {
    font-family: var(--font-display);
    font-size: 0.75rem;
    color: var(--gold);
    letter-spacing: 0.1em;
  }

  /* Epilogue cards render smaller/secondary compared to the 5 main adventure cards,
     reinforcing "bonus content" independent of locked/unlocked state. Border color itself
     is set inline per-card from the parent world's accentColor (see buildWorldCard /
     buildLockedWorldCard in game.js) — these rules only control size/density. */
  .epilogue-card {
    padding: 18px 16px;
    min-height: 218px;
  }

  .epilogue-card .world-card-icon {
    font-size: 1.4rem;
    margin-bottom: 8px;
  }

  .epilogue-card .world-card-genre {
    font-size: 8px;
    margin-bottom: 6px;
  }

  .epilogue-card h3 {
    font-size: 0.95rem;
    margin-bottom: 6px;
  }

  .epilogue-card p {
    font-size: 0.8rem;
  }

  .epilogue-card .world-card-footer {
    padding-top: 10px;
  }

  .epilogue-card .world-card-unlock-hint {
    font-size: 8px;
    padding: 3px 8px;
  }

  /* Desaturated/dimmed treatment mirroring the landing page's "coming soon" preview cards */
  .world-card--locked {
    cursor: default;
    filter: saturate(0.5) brightness(0.65);
  }

  .world-card--locked:hover {
    border-color: var(--surface-border);
    background: var(--surface-raised);
  }

  .world-card--locked:hover::before {
    opacity: 0;
  }

  .world-card-unlock-hint {
    margin-top: auto;
    display: inline-block;
    font-family: var(--font-mono);
    font-size: 9px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-dim);
    border: 1px solid var(--surface-border);
    padding: 4px 10px;
    border-radius: 2px;
  }

  /* One-time glow when a chained world flips from locked to unlocked */
  @keyframes world-card-reveal {
    0% { box-shadow: 0 0 0 rgba(184,146,42,0); filter: brightness(1); }
    35% { box-shadow: 0 0 28px rgba(184,146,42,0.55); filter: brightness(1.2); }
    100% { box-shadow: 0 0 0 rgba(184,146,42,0); filter: brightness(1); }
  }

  .world-card--reveal {
    animation: world-card-reveal 1.8s ease-out;
  }

  /* ─── GAME SCREEN ─── */
  #game-screen {
    display: none;
    position: relative;
    z-index: 10;
    min-height: 100vh;
    flex-direction: column;
  }

  /* TOP BAR */
  .game-topbar {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(10,8,6,0.95);
    border-bottom: 1px solid var(--surface-border);
    backdrop-filter: blur(8px);
    padding: 12px 24px;
    display: flex;
    align-items: center;
    gap: 20px;
  }

  .topbar-world {
    font-family: var(--font-display);
    font-size: 0.75rem;
    color: var(--gold);
    letter-spacing: 0.1em;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
  }

  .topbar-studio {
    color: var(--text-dim);
    margin-right: 8px;
  }

  .topbar-studio::after {
    content: ' ·';
    margin-right: 8px;
  }

  .stat-bar {
    display: flex;
    align-items: center;
    gap: 16px;
  }

  .stat {
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: var(--font-mono);
    font-size: 0.8rem;
  }

  .stat-label {
    color: var(--text-muted);
    font-size: 0.68rem;
    letter-spacing: 0.15em;
    text-transform: uppercase;
  }

  .stat-value {
    color: var(--parchment);
    font-weight: bold;
  }

  .health-pips {
    display: flex;
    gap: 3px;
  }

  .pip {
    width: 8px;
    height: 8px;
    border-radius: 1px;
    background: var(--health-green);
    transition: background 0.3s;
  }

  .pip.empty { background: var(--surface-border); }

  .pip.damage-flash { animation: damageFlash 0.5s ease forwards; }

  @keyframes damageFlash {
    0% { background: #ff4444; transform: scale(1.4); }
    100% { background: var(--surface-border); transform: scale(1); }
  }

  .btn-exit {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    letter-spacing: 0.15em;
    color: var(--text-dim);
    background: none;
    border: 1px solid var(--surface-border);
    padding: 5px 12px;
    cursor: pointer;
    transition: color 0.2s, border-color 0.2s;
    border-radius: 1px;
  }

  .btn-exit:hover { color: var(--ember); border-color: var(--ember); }

  .level-badge {
    font-family: var(--font-mono);
    font-weight: bold;
    color: var(--gold);
  }

  .xp-bar-track {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--surface-border);
  }

  .xp-bar-fill {
    height: 100%;
    background: var(--gold);
    width: 0%;
    transition: width 0.3s ease;
  }

  /* MAIN GAME LAYOUT */
  .game-body {
    display: flex;
    flex: 1;
    min-height: calc(100vh - 57px);
  }

  /* SCENE PANEL */
  .scene-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    max-width: 720px;
    margin: 0 auto;
    padding: 32px 28px 120px;
    width: 100%;
  }

  /* SCENE IMAGE */
  .scene-image-wrapper {
    width: 100%;
    aspect-ratio: 16/7;
    background: var(--surface-raised);
    border: 1px solid var(--surface-border);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 28px;
    margin-top: 28px;
    position: relative;
  }

  .scene-image-wrapper canvas {
    width: 100%;
    height: 100%;
    display: block;
  }

  .scene-image-label { display: none; }

  /* NARRATIVE */
  .narrative-block {
    margin-bottom: 24px;
  }

  .narrative-turn-label {
    font-family: var(--font-mono);
    font-size: 9px;
    letter-spacing: 0.3em;
    color: var(--text-dim);
    text-transform: uppercase;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 10px;
  }

  .narrative-turn-label::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--surface-border);
  }

  .narrative-text {
    font-size: 1.05rem;
    line-height: 1.85;
    color: var(--text-primary);
  }

  .narrative-text p + p { margin-top: 1em; }

  .narrative-text em { color: var(--parchment); font-style: italic; }

  /* PLAYER ACTION ECHO */
  .player-action {
    margin-bottom: 20px;
    padding: 10px 16px;
    background: rgba(184,146,42,0.06);
    border-left: 2px solid var(--gold);
    font-style: italic;
    color: var(--text-muted);
    font-size: 0.9rem;
  }

  /* CHOICES */
  .choices-section {
    margin-top: 28px;
  }

  .choices-label {
    font-family: var(--font-mono);
    font-size: 9px;
    letter-spacing: 0.35em;
    color: var(--text-dim);
    text-transform: uppercase;
    margin-bottom: 14px;
  }

  .choices-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .choice-btn {
    background: var(--surface-raised);
    border: 1px solid var(--surface-border);
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 0.95rem;
    font-style: italic;
    padding: 14px 18px;
    text-align: left;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
    border-radius: 1px;
    line-height: 1.4;
    position: relative;
    padding-left: 36px;
  }

  .choice-btn::before {
    content: attr(data-index);
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--ember);
    font-style: normal;
  }

  .choice-btn:hover {
    background: #201a14;
    border-color: var(--ash);
    color: var(--parchment);
  }

  .choice-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
  }

  /* CUSTOM INPUT */
  .custom-input-row {
    margin-top: 12px;
    display: flex;
    gap: 8px;
  }

  .custom-input {
    flex: 1;
    background: var(--surface-raised);
    border: 1px solid var(--surface-border);
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 0.9rem;
    font-style: italic;
    padding: 11px 14px;
    outline: none;
    border-radius: 1px;
    transition: border-color 0.15s;
  }

  .custom-input::placeholder { color: var(--text-dim); }
  .custom-input:focus { border-color: var(--ash); }

  .btn-do {
    font-family: var(--font-display);
    font-size: 0.75rem;
    letter-spacing: 0.1em;
    color: var(--ink);
    background: var(--gold);
    border: none;
    padding: 11px 20px;
    cursor: pointer;
    transition: background 0.15s;
    border-radius: 1px;
  }

  .btn-do:hover { background: var(--gold-light); }
  .btn-do:disabled { opacity: 0.4; cursor: not-allowed; }

  /* LOADING STATE */
  .narrative-loading {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text-dim);
    font-family: var(--font-mono);
    font-size: 0.8rem;
    letter-spacing: 0.1em;
    padding: 20px 0;
  }

  .loading-rune {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 1px solid var(--ember);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
  }

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

  /* SCROLL ANCHOR */
  #scroll-anchor { height: 1px; }

  /* HISTORY SIDEBAR (optional collapse on mobile) */
  .history-sidebar {
    width: 260px;
    border-left: 1px solid var(--surface-border);
    padding: 28px 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow-y: auto;
    max-height: calc(100vh - 57px);
    position: sticky;
    top: 57px;
    align-self: flex-start;
  }

  @media (max-width: 900px) { .history-sidebar { display: none; } }

  /* ─── MOBILE DRAWER ─── */
  .mobile-tab-bar {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 200;
    background: rgba(10,8,6,0.97);
    border-top: 1px solid var(--surface-border);
    backdrop-filter: blur(10px);
    padding: 8px 0 env(safe-area-inset-bottom, 8px);
    flex-direction: row;
    justify-content: space-around;
    align-items: center;
  }

  .tab-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    padding: 6px 20px;
    transition: color 0.15s;
    flex: 1;
  }

  .tab-btn.active { color: var(--gold); }
  .tab-btn:hover { color: var(--text-muted); }

  .tab-btn-icon {
    font-size: 1.1rem;
    line-height: 1;
  }

  .tab-btn-label {
    font-family: var(--font-mono);
    font-size: 0.55rem;
    letter-spacing: 0.2em;
    text-transform: uppercase;
  }

  /* MOBILE DRAWER SHEET */
  .mobile-drawer {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 300;
    background: var(--surface-raised);
    border-top: 2px solid var(--gold);
    border-radius: 12px 12px 0 0;
    padding: 0 0 env(safe-area-inset-bottom, 0);
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    max-height: 70vh;
    overflow: hidden;
    flex-direction: column;
    pointer-events: none;
  }

  .mobile-drawer.open {
    display: flex;
    transform: translateY(0);
    pointer-events: auto;
  }

  .drawer-handle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px 12px;
    border-bottom: 1px solid var(--surface-border);
    flex-shrink: 0;
  }

  .drawer-title {
    font-family: var(--font-display);
    font-size: 0.85rem;
    color: var(--parchment);
    letter-spacing: 0.08em;
  }

  .drawer-close {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 2px 6px;
    line-height: 1;
    transition: color 0.15s;
  }

  .drawer-close:hover { color: var(--ember); }

  .drawer-content {
    overflow-y: auto;
    padding: 20px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 24px;
    padding-bottom: 72px;
  }

  /* DRAWER OVERLAY */
  .drawer-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 250;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
  }

  .drawer-overlay.show {
    display: block;
    opacity: 1;
    pointer-events: auto;
  }

  /* Extra bottom padding on mobile so content isn't hidden behind tab bar */
  @media (max-width: 900px) {
    .scene-panel { padding-bottom: 100px; padding-left: 16px; padding-right: 16px; }
    .game-topbar { padding: 10px 14px; gap: 10px; }
    .topbar-studio { display: none; }
    .stat-label { display: none; }
    .stat { gap: 4px; }
    .pip { width: 6px; height: 6px; }
    .health-pips { gap: 2px; }
    .btn-exit { padding: 5px 8px; font-size: 0.65rem; }

    /* Bigger fonts on mobile */
    body { font-size: 19px; }
    .narrative-text { font-size: 1.1rem; line-height: 1.9; }
    .choice-btn { font-size: 1.05rem; padding: 16px 18px 16px 40px; }
    .custom-input { font-size: 1rem; padding: 14px; }
    .btn-do { font-size: 0.85rem; padding: 14px 16px; }
    .world-card h3 { font-size: 1.2rem; }
    .world-card p { font-size: 0.95rem; }
    .epilogue-card h3 { font-size: 1rem; }
    .epilogue-card p { font-size: 0.85rem; }
    .masthead h1 { font-size: 2.8rem; }
    .resume-banner-title { font-size: 1.1rem; }
    .resume-banner-meta { font-size: 0.9rem; }
    .intro-banner h2 { font-size: 1.4rem; }
    .intro-banner p { font-size: 1rem; }
    .tab-btn-label { font-size: 0.6rem; }
    .tab-btn-icon { font-size: 1.3rem; }
  }

  .sidebar-section-label {
    font-family: var(--font-mono);
    font-size: 9px;
    letter-spacing: 0.35em;
    color: var(--gold);
    text-transform: uppercase;
    margin-bottom: 10px;
  }

  .char-sidebar-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 12px;
  }

  .char-sidebar-name {
    font-family: var(--font-display);
    font-size: 1rem;
    color: var(--parchment);
  }

  .char-sidebar-level {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--gold);
  }

  .char-stat-mini-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    font-family: var(--font-mono);
    font-size: 0.72rem;
  }

  .char-stat-mini-label {
    width: 36px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.1em;
  }

  .char-stat-mini-track {
    flex: 1;
    height: 5px;
    background: var(--surface-border);
  }

  .char-stat-mini-fill {
    height: 100%;
    background: var(--gold);
  }

  .char-stat-mini-value { color: var(--text-muted); width: 1.5em; text-align: right; }

  .char-sidebar-xp-label {
    font-size: 0.72rem;
    color: var(--text-dim);
    margin: 12px 0 4px;
  }

  .char-sidebar-abilities {
    margin-top: 12px;
  }

  .char-sidebar-ability {
    font-size: 0.82rem;
    font-style: italic;
    color: var(--text-muted);
    padding: 4px 0;
  }

  .inventory-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
  }

  .inventory-item {
    font-size: 0.85rem;
    color: var(--text-primary);
    padding: 6px 0;
    border-bottom: 1px solid var(--surface-border);
    font-style: italic;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
  }

  .inventory-item-name { flex: 1; }

  .ability-item .inventory-item-name { color: var(--gold-light); font-style: normal; }

  .btn-use-item {
    font-family: var(--font-mono);
    font-size: 0.6rem;
    letter-spacing: 0.1em;
    color: var(--ember);
    background: none;
    border: 1px solid var(--ember);
    padding: 3px 7px;
    cursor: pointer;
    border-radius: 1px;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
    touch-action: manipulation;
    flex-shrink: 0;
  }

  .btn-use-item:hover { background: var(--ember); color: var(--ink); }
  .btn-use-item:disabled { opacity: 0.3; cursor: not-allowed; }

  .flag-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
  }

  .flag-item {
    font-family: var(--font-mono);
    font-size: 0.72rem;
    color: var(--text-muted);
    padding: 4px 0;
  }

  .flag-item.true { color: #6abf6e; }

  .summary-text {
    font-size: 0.82rem;
    font-style: italic;
    color: var(--text-muted);
    line-height: 1.6;
  }



  /* INTRO SCENE */
  .intro-banner {
    background: var(--surface-raised);
    border: 1px solid var(--surface-border);
    border-top: 2px solid var(--ember);
    padding: 24px;
    margin-bottom: 28px;
  }

  .intro-banner h2 {
    font-family: var(--font-display);
    font-size: 1.3rem;
    color: var(--parchment);
    margin-bottom: 8px;
  }

  .intro-banner p {
    font-style: italic;
    color: var(--text-muted);
    font-size: 0.9rem;
    line-height: 1.6;
  }

  /* STREAMING CURSOR */
  .streaming-cursor {
    display: inline-block;
    width: 2px;
    height: 1em;
    background: var(--ember);
    margin-left: 2px;
    vertical-align: text-bottom;
    animation: blink 0.7s step-end infinite;
  }

  @keyframes blink { 50% { opacity: 0; } }

  /* RESUME BANNER */
  .resume-banner {
    width: 100%;
    max-width: 960px;
    background: var(--surface-raised);
    border: 1px solid var(--gold);
    border-top: 3px solid var(--gold);
    padding: 20px 24px;
    margin-bottom: 32px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    border-radius: 2px;
  }

  .resume-banner-info { flex: 1; }

  .resume-banner-eyebrow {
    font-family: var(--font-mono);
    font-size: 9px;
    letter-spacing: 0.3em;
    color: var(--gold);
    text-transform: uppercase;
    margin-bottom: 8px;
  }

  .resume-banner-title {
    font-family: var(--font-display);
    font-size: 1.1rem;
    color: var(--parchment);
    margin-bottom: 8px;
    line-height: 1.3;
  }

  .resume-banner-meta {
    font-size: 0.85rem;
    font-style: italic;
    color: var(--text-muted);
    line-height: 1.5;
    margin-bottom: 4px;
  }

  .resume-banner-actions {
    display: flex;
    gap: 10px;
    width: 100%;
  }

  .btn-resume {
    font-family: var(--font-display);
    font-size: 0.85rem;
    letter-spacing: 0.1em;
    color: var(--ink);
    background: var(--gold);
    border: none;
    padding: 14px 20px;
    cursor: pointer;
    transition: background 0.15s;
    border-radius: 1px;
    flex: 1;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }

  .resume-banners-label {
    font-family: var(--font-mono);
    font-size: 10px;
    letter-spacing: 0.35em;
    color: var(--gold);
    text-transform: uppercase;
    margin-bottom: 12px;
    text-align: center;
  }

  .btn-resume:hover { background: var(--gold-light); }

  .btn-discard {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    letter-spacing: 0.1em;
    color: var(--text-dim);
    background: none;
    border: 1px solid var(--surface-border);
    padding: 14px 20px;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
    border-radius: 1px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }

  .btn-discard:hover { color: var(--ember); border-color: var(--ember); }

  /* ─── GAME OVER SCREENS ─── */
  .game-over-screen {
    position: fixed;
    inset: 0;
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(0,0,0,0.92);
    backdrop-filter: blur(8px);
    animation: fadeIn 0.5s ease;
    overflow-y: auto;
  }

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

  .game-over-card {
    background: var(--surface-raised);
    border-radius: 2px;
    max-width: 520px;
    width: 100%;
    text-align: center;
    padding: 48px 36px;
    overflow: hidden;
  }

  .game-over-card.death { border-top: 3px solid #7a1a1a; }
  .game-over-card.win { border-top: 3px solid var(--gold); }
  .game-over-card.neutral { border-top: 3px solid var(--ash); }
  .game-over-card.lose { border-top: 3px solid var(--ember); }

  .game-over-icon { font-size: 3rem; margin-bottom: 16px; display: block; }

  .game-over-label {
    font-family: var(--font-mono);
    font-size: 9px;
    letter-spacing: 0.4em;
    text-transform: uppercase;
    margin-bottom: 12px;
  }

  .game-over-card.death .game-over-label { color: #7a1a1a; }
  .game-over-card.win .game-over-label { color: var(--gold); }
  .game-over-card.neutral .game-over-label { color: var(--ash); }
  .game-over-card.lose .game-over-label { color: var(--ember); }

  .game-over-title {
    font-family: var(--font-display);
    font-size: 1.8rem;
    color: var(--parchment);
    margin-bottom: 20px;
    line-height: 1.2;
  }

  .game-over-narrative {
    font-style: italic;
    color: var(--text-muted);
    font-size: 0.95rem;
    line-height: 1.7;
    margin-bottom: 32px;
  }

  .game-over-chronicle {
    background: var(--surface);
    border: 1px solid var(--surface-border);
    padding: 16px;
    margin-bottom: 32px;
    text-align: left;
  }

  .game-over-chronicle-label {
    font-family: var(--font-mono);
    font-size: 8px;
    letter-spacing: 0.3em;
    color: var(--text-dim);
    text-transform: uppercase;
    margin-bottom: 8px;
  }

  .game-over-chronicle-text {
    font-size: 0.78rem;
    font-style: italic;
    color: var(--text-dim);
    line-height: 1.5;
  }

  .game-over-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
  }

  .btn-restart {
    font-family: var(--font-display);
    font-size: 0.8rem;
    letter-spacing: 0.1em;
    color: var(--ink);
    background: var(--ember);
    border: none;
    padding: 14px 24px;
    cursor: pointer;
    transition: background 0.15s;
    border-radius: 1px;
    touch-action: manipulation;
  }

  .btn-restart:hover { background: var(--ember-glow); }

  .btn-world-select {
    font-family: var(--font-display);
    font-size: 0.8rem;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    background: none;
    border: 1px solid var(--surface-border);
    padding: 14px 24px;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
    border-radius: 1px;
    touch-action: manipulation;
  }

  .btn-world-select:hover { color: var(--parchment); border-color: var(--ash); }

  /* SAVE INDICATOR */
  .save-indicator {
    font-family: var(--font-mono);
    font-size: 0.65rem;
    letter-spacing: 0.15em;
    color: var(--text-dim);
    display: flex;
    align-items: center;
    gap: 5px;
    opacity: 0;
    transition: opacity 0.5s;
  }

  .save-indicator.show { opacity: 1; }
  .save-indicator::before { content: '✦'; color: var(--gold); font-size: 0.5rem; }

  .stat-tokens .stat-value { color: var(--gold); }
  .stat-tokens .stat-value.tokens-low { color: var(--ember); animation: pulse 1.5s ease infinite; }
  @keyframes pulse { 50% { opacity: 0.5; } }

  .token-pack-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 8px;
    text-align: center;
  }

  @media (max-width: 480px) {
    .token-pack-grid { grid-template-columns: 1fr; }
  }

  .token-pack {
    background: var(--surface);
    border: 1px solid var(--surface-border);
    border-radius: 2px;
    padding: 20px 12px;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
    position: relative;
    touch-action: manipulation;
  }

  .token-pack:hover { border-color: var(--gold); background: #201a14; }
  .token-pack.popular { border-color: var(--gold); }

  .token-pack-badge {
    position: absolute;
    top: -10px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--gold);
    color: var(--ink);
    font-family: var(--font-mono);
    font-size: 0.6rem;
    letter-spacing: 0.1em;
    padding: 3px 10px;
    border-radius: 8px;
    white-space: nowrap;
  }

  .token-pack-amount {
    font-family: var(--font-display);
    font-size: 1.8rem;
    color: var(--parchment);
    font-weight: 700;
  }

  .token-pack-label {
    font-family: var(--font-mono);
    font-size: 0.65rem;
    letter-spacing: 0.15em;
    color: var(--text-dim);
    text-transform: uppercase;
    margin-bottom: 10px;
  }

  .token-pack-price {
    font-family: var(--font-display);
    font-size: 1.3rem;
    color: var(--gold);
    margin-bottom: 4px;
  }

  .token-pack-rate {
    font-family: var(--font-mono);
    font-size: 0.62rem;
    color: var(--text-dim);
  }

  /* TOAST */
  .toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--surface-raised);
    border: 1px solid var(--ember);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 0.78rem;
    letter-spacing: 0.08em;
    padding: 10px 20px;
    z-index: 2000;
    opacity: 0;
    transition: opacity 0.3s;
    border-radius: 1px;
    pointer-events: none;
  }

  .toast.show { opacity: 1; }

  .site-footer {
    margin-top: 60px;
    text-align: center;
    padding-bottom: 32px;
    width: 100%;
    max-width: 960px;
  }

  .footer-brand {
    font-family: var(--font-display);
    font-size: 0.85rem;
    letter-spacing: 0.2em;
    color: var(--text-dim);
  }

  .footer-sub {
    font-family: var(--font-mono);
    font-size: 0.65rem;
    letter-spacing: 0.2em;
    color: var(--text-dim);
    margin-top: 6px;
    opacity: 0.6;
  }

  .footer-links {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-top: 10px;
  }

  .footer-link {
    font-family: var(--font-mono);
    font-size: 0.68rem;
    color: var(--text-dim);
    text-decoration: none;
    letter-spacing: 0.1em;
    transition: color 0.15s;
  }

  .footer-link:hover { color: var(--gold); }

  .footer-dot {
    color: var(--text-dim);
    font-size: 0.68rem;
    opacity: 0.5;
  }

  .footer-copy {
    font-family: var(--font-mono);
    font-size: 0.62rem;
    color: var(--text-dim);
    margin-top: 8px;
    opacity: 0.5;
    letter-spacing: 0.08em;
  }

  /* Procgen canvas art styles */
  .scene-canvas { image-rendering: pixelated; }
