
  :root {
    --bg-0: #0b0f1a;
    --bg-1: #131829;
    --bg-2: #1c2238;
    --bg-3: #262e4a;
    --bg-4: #313a5e;
    --text-0: #f4f6fb;
    --text-1: #b9c1d6;
    --text-2: #7a849f;
    --azure: #2b9eff;
    --azure-deep: #006bd6;
    --gold: #ffc940;
    --gold-deep: #f0a000;
    --flame: #ff6b35;
    --flame-deep: #d44a17;
    --green: #22c55e;
    --green-deep: #15803d;
    --red: #ef4444;
    --red-deep: #b91c1c;
    --violet: #a855f7;
    --violet-deep: #7e22ce;
    --pink: #ec4899;
    --cyan: #22d3ee;
    --radius: 16px;
    --radius-sm: 10px;
    --radius-lg: 24px;
    --shadow-lift: 0 12px 36px -8px rgba(0,0,0,0.6);
    --shadow-glow-blue: 0 0 36px -6px rgba(43,158,255,0.45);
    --shadow-glow-gold: 0 0 32px -4px rgba(255,201,64,0.5);
    --shadow-glow-green: 0 0 32px -4px rgba(34,197,94,0.5);
    --shadow-glow-red: 0 0 32px -4px rgba(239,68,68,0.5);
    --shadow-glow-violet: 0 0 32px -4px rgba(168,85,247,0.5);
    --transition: 0.22s cubic-bezier(.4,0,.2,1);
    --transition-slow: 0.4s cubic-bezier(.4,0,.2,1);
  }

  *, *::before, *::after { box-sizing: border-box; }

  html, body {
    margin: 0; padding: 0;
    /* Desactiva el "font boosting"/text-autosizing de Blink, que en móvil fija
       el tamaño de fuente de bloques de texto largos (p.ej. botones de opción)
       ignorando el CSS — rompía el escalado responsive del quiz. */
    -webkit-text-size-adjust: 100%;
    -moz-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }

  body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background:
      radial-gradient(ellipse 80% 50% at 50% -10%, rgba(43,158,255,0.18), transparent 50%),
      radial-gradient(ellipse 60% 50% at 90% 110%, rgba(168,85,247,0.18), transparent 50%),
      radial-gradient(ellipse 60% 50% at 10% 90%, rgba(255,201,64,0.10), transparent 60%),
      var(--bg-0);
    color: var(--text-0);
    min-height: 100vh;
    overflow-x: hidden;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
  }

  .num-font { font-family: 'Space Grotesk', 'Inter', sans-serif; letter-spacing: -0.02em; }

  /* ── CONFETTI CANVAS ───────────────────────────────── */
  #confetti-canvas {
    position: fixed; inset: 0; pointer-events: none; z-index: 9000;
    width: 100vw; height: 100vh;
  }

  /* ── HUD ──────────────────────────────────────────── */
  .hud {
    position: sticky; top: 0; z-index: 100;
    backdrop-filter: blur(14px);
    background: rgba(11,15,26,0.78);
    border-bottom: 1px solid rgba(255,255,255,0.06);
    padding: 10px 16px;
  }
  .hud-inner {
    max-width: 940px; margin: 0 auto;
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 14px;
  }
  .hud-brand {
    display: flex; align-items: center; gap: 10px;
    font-weight: 800; font-size: 1.05rem;
    cursor: pointer;
    transition: opacity var(--transition);
  }
  .hud-brand:hover { opacity: 0.85; }
  .hud-brand .brand-logo {
    width: 36px; height: 36px;
    background: linear-gradient(135deg, var(--azure), var(--violet));
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.2rem;
    box-shadow: var(--shadow-glow-blue);
  }
  .hud-brand .brand-text { display: flex; flex-direction: column; line-height: 1.05; }
  .hud-brand .brand-text small { font-size: 0.7rem; font-weight: 500; color: var(--text-2); }

  .hud-level {
    display: flex; align-items: center; gap: 10px;
    min-width: 0;
  }
  .hud-level-badge {
    background: linear-gradient(135deg, var(--azure), var(--azure-deep));
    color: #fff;
    font-weight: 800; font-size: 0.78rem;
    padding: 4px 9px; border-radius: 99px;
    text-shadow: 0 1px 0 rgba(0,0,0,0.2);
    box-shadow: 0 4px 12px -2px rgba(43,158,255,0.5);
    white-space: nowrap;
  }
  .hud-xp-wrap { flex: 1; min-width: 80px; display: flex; flex-direction: column; gap: 3px; }
  .hud-xp-text {
    display: flex; justify-content: space-between; align-items: center;
    font-size: 0.7rem; color: var(--text-2); font-weight: 500;
  }
  .hud-xp-bar { height: 6px; background: var(--bg-2); border-radius: 99px; overflow: hidden; position: relative; }
  .hud-xp-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--azure), var(--violet));
    border-radius: 99px;
    transition: width 0.7s cubic-bezier(.4,0,.2,1);
    position: relative;
    box-shadow: 0 0 12px -2px rgba(43,158,255,0.6);
  }
  .hud-xp-bar-fill::after {
    content: '';
    position: absolute; inset: 0;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.4), transparent);
    animation: shimmer 2.5s infinite;
  }
  @keyframes shimmer { 0% { transform: translateX(-100%);} 100% { transform: translateX(100%);} }

  .hud-meta { display: flex; gap: 10px; align-items: center; }
  .hud-meta-chip {
    display: inline-flex; align-items: center; gap: 4px;
    font-size: 0.85rem; font-weight: 700;
    padding: 4px 9px;
    border-radius: 99px;
    background: var(--bg-2);
    border: 1px solid rgba(255,255,255,0.06);
  }
  .hud-meta-chip.flame {
    background: linear-gradient(135deg, rgba(255,107,53,0.2), rgba(212,74,23,0.15));
    border-color: rgba(255,107,53,0.4);
    color: var(--flame);
  }
  .hud-meta-chip.flame.active { animation: pulse 1.5s infinite; }
  .hud-meta-chip.comfort {
    background: linear-gradient(135deg, rgba(34,197,94,0.2), rgba(21,128,61,0.15));
    border-color: rgba(34,197,94,0.4);
    color: var(--green);
    animation: pulse-green 2s infinite;
  }
  @keyframes pulse-green {
    0%, 100% { box-shadow: 0 0 0 0 rgba(34,197,94,0.4); }
    50% { box-shadow: 0 0 0 7px rgba(34,197,94,0); }
  }
  @keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(255,107,53,0.4); }
    50% { box-shadow: 0 0 0 8px rgba(255,107,53,0); }
  }
  .hud-sound-btn {
    background: var(--bg-2);
    border: 1px solid rgba(255,255,255,0.06);
    color: var(--text-1);
    width: 36px; height: 36px;
    border-radius: 99px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    transition: all var(--transition);
    font-size: 1rem;
  }
  .hud-sound-btn:hover { background: var(--bg-3); color: var(--text-0); }

  /* ── SCREENS ──────────────────────────────────────── */
  .screen { display: none; animation: fadeIn 0.3s ease; }
  .screen.active { display: block; }
  @keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

  .container {
    width: 100%;
    max-width: 760px;
    margin: 0 auto;
    padding: 20px 16px 60px;
  }

  /* ── HOME ─────────────────────────────────────────── */
  .home-hero { text-align: center; margin: 12px 0 24px; }
  .home-hero h1 {
    font-family: 'Space Grotesk', sans-serif;
    font-size: clamp(1.7rem, 5vw, 2.3rem);
    font-weight: 800;
    margin: 0 0 4px;
    background: linear-gradient(135deg, var(--azure) 0%, var(--violet) 50%, var(--pink) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    letter-spacing: -0.02em;
  }
  .home-hero p { color: var(--text-1); margin: 0; font-size: 0.95rem; }

  .level-card {
    background: linear-gradient(135deg, var(--bg-1) 0%, var(--bg-2) 100%);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: var(--shadow-lift);
    position: relative;
    overflow: hidden;
  }
  .level-card::before {
    content: '';
    position: absolute; top: -40%; right: -10%;
    width: 240px; height: 240px;
    background: radial-gradient(circle, rgba(43,158,255,0.18) 0%, transparent 60%);
    pointer-events: none;
  }
  .level-card-top {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 14px;
  }
  .level-card-num { display: flex; align-items: baseline; gap: 6px; }
  .level-card-num .nlabel { font-size: 0.75rem; color: var(--text-2); text-transform: uppercase; letter-spacing: 1px; font-weight: 600; }
  .level-card-num .nval { font-family: 'Space Grotesk'; font-size: 2.5rem; font-weight: 800; color: var(--text-0); line-height: 1; }
  .level-card-title {
    font-size: 0.95rem; font-weight: 800; color: var(--gold);
    text-transform: uppercase; letter-spacing: 1px;
    text-shadow: 0 0 18px rgba(255,201,64,0.5);
  }

  .level-card-bar {
    height: 14px; background: var(--bg-3);
    border-radius: 99px; overflow: hidden;
    margin-bottom: 6px;
    position: relative;
  }
  .level-card-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--azure), var(--violet), var(--pink));
    background-size: 200% 100%;
    animation: gradShift 4s linear infinite;
    border-radius: 99px;
    transition: width 0.9s cubic-bezier(.4,0,.2,1);
    box-shadow: 0 0 14px -2px rgba(43,158,255,0.5);
  }
  @keyframes gradShift {
    0% { background-position: 0% 50%; }
    100% { background-position: 200% 50%; }
  }
  .level-card-bar-text {
    font-size: 0.78rem; color: var(--text-2);
    display: flex; justify-content: space-between;
  }

  .home-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 16px;
  }
  .stat-tile {
    background: var(--bg-1);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: var(--radius-sm);
    padding: 10px 6px;
    text-align: center;
  }
  .stat-tile .val {
    font-family: 'Space Grotesk'; font-size: 1.2rem; font-weight: 800;
    color: var(--text-0); display: block; line-height: 1.1;
  }
  .stat-tile .lbl {
    font-size: 0.62rem; color: var(--text-2);
    text-transform: uppercase; letter-spacing: 0.5px;
    font-weight: 600; margin-top: 2px; display: block;
  }

  /* Daily banner */
  .daily-banner {
    background: linear-gradient(135deg, rgba(255,201,64,0.18), rgba(255,107,53,0.18));
    border: 1px solid rgba(255,201,64,0.35);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    margin-bottom: 16px;
    display: flex; align-items: center; gap: 12px;
    cursor: pointer;
    transition: transform var(--transition);
  }
  .daily-banner:hover { transform: translateY(-2px); }
  .daily-banner.claimed { opacity: 0.55; filter: grayscale(0.3); cursor: default; }
  .daily-banner.claimed:hover { transform: none; }
  .daily-banner .dchip { font-size: 1.6rem; flex-shrink: 0; }
  .daily-banner .dtxt { flex: 1; }
  .daily-banner .dtxt strong { display: block; color: var(--gold); font-size: 0.92rem; }
  .daily-banner .dtxt span { font-size: 0.8rem; color: var(--text-1); }

  /* Play mega */
  .play-mega {
    width: 100%;
    padding: 22px 24px;
    background: linear-gradient(135deg, var(--azure) 0%, var(--violet) 100%);
    border: none;
    border-radius: var(--radius);
    color: #fff;
    font-size: 1.35rem;
    font-weight: 800;
    cursor: pointer;
    margin-bottom: 12px;
    box-shadow: 0 12px 32px -6px rgba(43,158,255,0.6);
    transition: transform var(--transition), box-shadow var(--transition);
    display: flex; align-items: center; justify-content: center;
    gap: 12px;
    text-shadow: 0 2px 6px rgba(0,0,0,0.18);
    position: relative;
    overflow: hidden;
    font-family: inherit;
  }
  .play-mega::after {
    content: '';
    position: absolute; top: 0; left: -100%;
    width: 100%; height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
    animation: sweep 3.5s infinite;
  }
  @keyframes sweep { 0% { left: -100%; } 100% { left: 100%; } }
  .play-mega:hover { transform: translateY(-3px) scale(1.01); box-shadow: 0 18px 40px -6px rgba(43,158,255,0.7); }
  .play-mega:active { transform: translateY(0) scale(0.99); }
  .play-mega .play-text { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.1; }
  .play-mega .play-text small { font-size: 0.72rem; font-weight: 500; opacity: 0.88; margin-top: 2px; }
  .play-mega .play-icon { font-size: 1.8rem; }

  .mode-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 24px;
  }
  .mode-btn {
    background: var(--bg-1);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: var(--radius-sm);
    padding: 12px 8px;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition);
    color: var(--text-1);
    font-family: inherit;
  }
  .mode-btn:hover { background: var(--bg-2); border-color: rgba(255,255,255,0.15); transform: translateY(-2px); }
  .mode-btn .micon { font-size: 1.4rem; line-height: 1; margin-bottom: 4px; }
  .mode-btn .mlbl { font-size: 0.78rem; font-weight: 700; color: var(--text-0); }
  .mode-btn .mqty { font-size: 0.68rem; color: var(--text-2); display: block; }

  .section-title {
    display: flex; align-items: center; justify-content: space-between;
    margin: 0 0 12px;
    font-size: 0.85rem; font-weight: 700;
    color: var(--text-1); letter-spacing: 0.5px; text-transform: uppercase;
  }
  .section-title .count { color: var(--text-2); font-weight: 500; }

  /* Powerups inventory */
  .pup-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 16px;
  }
  .pup-tile {
    background: var(--bg-1);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: var(--radius-sm);
    padding: 12px 8px;
    display: flex; flex-direction: column; align-items: center; gap: 3px;
    position: relative;
  }
  .pup-tile .pico { font-size: 1.6rem; line-height: 1; }
  .pup-tile .plbl { font-size: 0.72rem; font-weight: 700; color: var(--text-1); }
  .pup-tile .pdesc { font-size: 0.62rem; color: var(--text-2); text-align: center; margin-top: 2px; }
  .pup-tile .pcount {
    position: absolute; top: -6px; right: -6px;
    min-width: 22px; height: 22px;
    background: linear-gradient(135deg, var(--gold), var(--flame));
    border-radius: 99px;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.7rem; font-weight: 800;
    color: #1a0d00; padding: 0 6px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
  }

  /* Next goal */
  .next-goal {
    background: var(--bg-1);
    border: 1px dashed rgba(255,255,255,0.15);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    margin-bottom: 14px;
    display: flex; align-items: center; gap: 12px;
  }
  .next-goal .ngicon { font-size: 1.6rem; }
  .next-goal .ngtxt { flex: 1; font-size: 0.85rem; }
  .next-goal .ngtxt strong { color: var(--gold); }
  .next-goal-bar { height: 5px; background: var(--bg-3); border-radius: 99px; margin-top: 6px; overflow: hidden; }
  .next-goal-bar-fill { height: 100%; background: linear-gradient(90deg, var(--gold), var(--flame)); border-radius: 99px; transition: width var(--transition-slow); }

  .ach-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(74px, 1fr));
    gap: 8px;
    margin-bottom: 20px;
  }
  .ach-tile {
    background: var(--bg-1);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: var(--radius-sm);
    padding: 8px 6px;
    text-align: center;
    cursor: help;
    transition: all var(--transition);
    position: relative;
  }
  .ach-tile.locked { opacity: 0.4; filter: grayscale(0.7); }
  .ach-tile.unlocked {
    border-color: rgba(255,201,64,0.35);
    background: linear-gradient(135deg, var(--bg-1), rgba(255,201,64,0.06));
  }
  .ach-tile:hover { transform: translateY(-2px); border-color: rgba(255,255,255,0.2); }
  .ach-tile .aicon { font-size: 1.4rem; line-height: 1; }
  .ach-tile .albl { font-size: 0.62rem; font-weight: 600; color: var(--text-1); margin-top: 4px; line-height: 1.15; }
  .ach-tooltip {
    position: absolute; bottom: calc(100% + 6px); left: 50%;
    transform: translateX(-50%);
    background: var(--bg-3); color: var(--text-0);
    padding: 6px 10px; border-radius: 6px;
    font-size: 0.72rem; font-weight: 500;
    white-space: nowrap;
    opacity: 0; pointer-events: none;
    transition: opacity var(--transition);
    z-index: 5;
    border: 1px solid rgba(255,255,255,0.1);
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  }
  .ach-tile:hover .ach-tooltip { opacity: 1; }

  /* ── QUIZ ─────────────────────────────────────────── */
  .quiz-top {
    display: flex; align-items: center; gap: 10px;
    margin-bottom: 12px;
  }
  .quiz-exit {
    background: var(--bg-2);
    border: 1px solid rgba(255,255,255,0.06);
    color: var(--text-1);
    width: 38px; height: 38px;
    border-radius: 99px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    transition: all var(--transition);
    flex-shrink: 0;
    font-size: 1rem;
  }
  .quiz-exit:hover { background: var(--bg-3); color: var(--text-0); }

  .quiz-prog { flex: 1; display: flex; flex-direction: column; gap: 4px; }
  .quiz-prog-label {
    display: flex; justify-content: space-between; font-size: 0.78rem;
    color: var(--text-2); font-weight: 600;
  }
  .quiz-prog-bar { height: 6px; background: var(--bg-2); border-radius: 99px; overflow: hidden; }
  .quiz-prog-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--azure), var(--violet));
    border-radius: 99px;
    transition: width 0.5s ease;
  }

  /* Combo display */
  .combo-display {
    position: fixed; top: 80px; right: 16px; z-index: 50;
    display: none;
    pointer-events: none;
  }
  .combo-display.show {
    display: block;
    animation: comboIn 0.35s cubic-bezier(.5,1.8,.5,1);
  }
  .combo-display.shake { animation: comboShake 0.4s; }
  @keyframes comboIn {
    from { transform: scale(0) rotate(-15deg); opacity: 0; }
    to { transform: scale(1) rotate(0); opacity: 1; }
  }
  @keyframes comboShake {
    0%, 100% { transform: scale(1) rotate(0); }
    25% { transform: scale(1.15) rotate(-3deg); }
    75% { transform: scale(1.15) rotate(3deg); }
  }
  .combo-bubble {
    background: linear-gradient(135deg, var(--flame) 0%, var(--gold) 100%);
    color: #1a0d00;
    padding: 8px 14px;
    border-radius: var(--radius);
    font-weight: 900;
    box-shadow: var(--shadow-glow-gold), 0 8px 24px rgba(0,0,0,0.4);
    text-align: center;
    border: 2px solid rgba(255,255,255,0.18);
    min-width: 70px;
  }
  .combo-bubble .ckanji { font-family: 'Space Grotesk'; font-size: 2rem; line-height: 0.9; text-shadow: 0 2px 0 rgba(0,0,0,0.15); }
  .combo-bubble .clbl { font-size: 0.62rem; letter-spacing: 1.5px; opacity: 0.85; font-weight: 700; }
  .combo-bubble.mega {
    background: linear-gradient(135deg, var(--violet), var(--pink));
    color: #fff;
    box-shadow: var(--shadow-glow-violet), 0 8px 24px rgba(0,0,0,0.4);
  }
  .combo-bubble.god {
    background: linear-gradient(135deg, var(--pink), var(--cyan));
    color: #fff;
    box-shadow: 0 0 32px -2px rgba(34,211,238,0.7), 0 8px 24px rgba(0,0,0,0.4);
  }

  /* Question card */
  .qcard {
    background: linear-gradient(180deg, var(--bg-1) 0%, var(--bg-2) 100%);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: var(--radius);
    padding: 22px 22px 20px;
    margin-bottom: 14px;
    box-shadow: var(--shadow-lift);
  }
  .qcard.shake { animation: shake 0.4s; }
  @keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-9px); }
    40% { transform: translateX(8px); }
    60% { transform: translateX(-6px); }
    80% { transform: translateX(4px); }
  }
  .qcard.glow-correct { box-shadow: var(--shadow-glow-green), var(--shadow-lift); border-color: var(--green); }
  .qcard.glow-incorrect { box-shadow: var(--shadow-glow-red), var(--shadow-lift); border-color: var(--red); }
  .qcard-badges { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; align-items: center; }
  .qbadge {
    font-size: 0.7rem; font-weight: 700;
    padding: 3px 9px;
    border-radius: 99px;
    letter-spacing: 0.3px;
  }
  .qbadge.b-mcq { background: rgba(43,158,255,0.18); color: var(--azure); }
  .qbadge.b-tf  { background: rgba(255,201,64,0.18); color: var(--gold); }
  .qbadge.b-mt  { background: rgba(168,85,247,0.18); color: var(--violet); }
  .qbadge.b-num { background: var(--bg-3); color: var(--text-2); font-family: 'Space Grotesk'; }
  .qbadge.b-speed { background: rgba(34,211,238,0.18); color: var(--cyan); animation: pulse-cy 1s infinite; }
  @keyframes pulse-cy {
    0%, 100% { box-shadow: 0 0 0 0 rgba(34,211,238,0.3); }
    50% { box-shadow: 0 0 0 4px rgba(34,211,238,0); }
  }

  .qcard-text {
    font-size: 1.04rem;
    line-height: 1.6;
    color: var(--text-0);
    white-space: pre-wrap;
    word-break: break-word;
  }
  /* Code rendering (questions, options, review) */
  .code-block {
    background: #070b14;
    border: 1px solid rgba(255,255,255,0.09);
    border-radius: 10px;
    padding: 12px 14px;
    margin: 10px 0;
    overflow-x: auto;
    font-family: 'JetBrains Mono','Fira Code','Cascadia Code','Consolas','SF Mono',ui-monospace,monospace;
    font-size: 0.84rem;
    line-height: 1.55;
    color: #d6e0f5;
    white-space: pre;
    tab-size: 4;
    -moz-tab-size: 4;
    box-shadow: inset 0 0 0 1px rgba(0,0,0,0.3);
  }
  .code-block code {
    font-family: inherit;
    color: inherit;
    background: none;
    white-space: pre;
    padding: 0;
    border: 0;
  }
  .code-inline {
    font-family: 'JetBrains Mono','Cascadia Code','Consolas','SF Mono',ui-monospace,monospace;
    font-size: 0.88em;
    background: rgba(255,255,255,0.07);
    border: 1px solid rgba(255,255,255,0.09);
    border-radius: 5px;
    padding: 1px 5px;
    color: #ffd9a0;
    white-space: pre-wrap;
    word-break: break-word;
  }
  .opt .code-block { margin: 6px 0; font-size: 0.8rem; }
  .opt-text { min-width: 0; }
  .review-q .code-block { font-size: 0.78rem; }
  /* Options */
  .opts {
    display: flex; flex-direction: column;
    gap: 10px; margin-bottom: 12px;
  }
  .opt {
    display: flex; align-items: center; gap: 12px;
    padding: 14px 16px;
    border-radius: var(--radius-sm);
    border: 2px solid rgba(255,255,255,0.08);
    background: var(--bg-1);
    cursor: pointer;
    text-align: left;
    font-size: 0.97rem;
    line-height: 1.45;
    color: var(--text-0);
    transition: all var(--transition);
    position: relative;
    word-break: break-word;
    width: 100%;
    font-family: inherit;
  }
  .opt:hover:not(:disabled) { border-color: var(--azure); background: rgba(43,158,255,0.08); transform: translateX(2px); }
  .opt.selected { border-color: var(--azure); background: rgba(43,158,255,0.14); }
  .opt.correct {
    border-color: var(--green);
    background: rgba(34,197,94,0.16);
    color: #c6f6d5;
    box-shadow: 0 0 22px -4px rgba(34,197,94,0.5);
    animation: correctPulse 0.5s;
  }
  @keyframes correctPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.02); }
    100% { transform: scale(1); }
  }
  .opt.incorrect {
    border-color: var(--red);
    background: rgba(239,68,68,0.14);
    color: #fecaca;
  }
  .opt.dimmed { opacity: 0.35; }
  .opt.eliminated { opacity: 0.15; pointer-events: none; text-decoration: line-through; }
  .opt:disabled { cursor: default; }

  .opt-letter {
    width: 32px; height: 32px;
    border-radius: 50%;
    background: var(--bg-3);
    border: 2px solid rgba(255,255,255,0.1);
    display: flex; align-items: center; justify-content: center;
    font-weight: 800; font-size: 0.82rem;
    flex-shrink: 0;
    transition: all var(--transition);
    font-family: 'Space Grotesk';
  }
  .opt.selected .opt-letter  { background: var(--azure); border-color: var(--azure); color: #fff; }
  .opt.correct .opt-letter   { background: var(--green); border-color: var(--green); color: #fff; }
  .opt.incorrect .opt-letter { background: var(--red); border-color: var(--red); color: #fff; }
  .opt-text { flex: 1; }
  .opt-icon { font-size: 1.2rem; flex-shrink: 0; }

  /* Power-ups in quiz */
  .pup-bar {
    display: flex; gap: 8px;
    margin-bottom: 12px;
  }
  .pup-bar .pup-btn {
    flex: 1;
    background: var(--bg-1);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: var(--radius-sm);
    padding: 8px 6px;
    cursor: pointer;
    color: var(--text-1);
    transition: all var(--transition);
    position: relative;
    font-size: 0.82rem;
    display: flex; align-items: center; justify-content: center; gap: 6px;
    font-weight: 700;
    font-family: inherit;
  }
  .pup-bar .pup-btn:hover:not(:disabled) { background: var(--bg-2); color: var(--text-0); transform: translateY(-1px); }
  .pup-bar .pup-btn:disabled { opacity: 0.3; cursor: not-allowed; }
  .pup-bar .pup-btn .picn { font-size: 1.1rem; }
  .pup-bar .pup-btn .pcnt {
    background: var(--bg-3);
    border-radius: 99px;
    padding: 1px 7px;
    font-size: 0.7rem;
    color: var(--gold);
    font-family: 'Space Grotesk';
    font-weight: 700;
  }
  .pup-bar .pup-btn.used {
    background: rgba(168,85,247,0.18);
    border-color: var(--violet);
    color: var(--violet);
    pointer-events: none;
  }

  /* Action buttons */
  .qactions { display: flex; gap: 10px; margin-top: 6px; }
  .btn-check, .btn-next {
    flex: 1; padding: 14px 18px;
    border-radius: var(--radius-sm);
    border: none;
    font-size: 1rem;
    font-weight: 800;
    cursor: pointer;
    transition: all var(--transition);
    font-family: inherit;
    color: #fff;
    position: relative;
    overflow: hidden;
  }
  .btn-check {
    background: linear-gradient(135deg, var(--azure), var(--azure-deep));
    box-shadow: 0 8px 20px -4px rgba(43,158,255,0.5);
  }
  .btn-check:disabled { background: var(--bg-3); color: var(--text-2); cursor: not-allowed; box-shadow: none; }
  .btn-check:not(:disabled):hover { transform: translateY(-2px); }
  .btn-next {
    background: linear-gradient(135deg, var(--green), var(--green-deep));
    box-shadow: 0 8px 20px -4px rgba(34,197,94,0.5);
    display: none;
  }
  .btn-next.show { display: block; }
  .btn-next:hover { transform: translateY(-2px); }
  .btn-next .ncountdown {
    position: absolute; bottom: 0; left: 0; height: 3px;
    background: rgba(255,255,255,0.55);
    width: 0%;
    transition: width 0.08s linear;
  }

  /* Feedback */
  .feedback {
    display: none;
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    margin-bottom: 10px;
    font-size: 0.92rem;
    line-height: 1.55;
    animation: fbIn 0.3s;
  }
  @keyframes fbIn {
    from { opacity: 0; transform: translateY(-6px); }
    to { opacity: 1; transform: translateY(0); }
  }
  .feedback.show { display: block; }
  .feedback.correct {
    background: rgba(34,197,94,0.14);
    border-left: 4px solid var(--green);
    color: #c6f6d5;
  }
  .feedback.incorrect {
    background: rgba(239,68,68,0.14);
    border-left: 4px solid var(--red);
    color: #fecaca;
  }
  .feedback .fbtitle { font-weight: 800; font-size: 1rem; margin-bottom: 6px; display: flex; align-items: center; gap: 8px; }
  .feedback .fbexpl { color: var(--text-1); font-size: 0.85rem; margin-top: 6px; line-height: 1.6; }

  /* Matching */
  .match-wrap { display: flex; flex-direction: column; gap: 8px; }
  .match-row {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    border: 2px solid rgba(255,255,255,0.08);
    background: var(--bg-1);
  }
  .match-row.correct { border-color: var(--green); background: rgba(34,197,94,0.12); }
  .match-row.incorrect { border-color: var(--red); background: rgba(239,68,68,0.12); }
  .match-row .mlbl { font-weight: 700; font-size: 0.85rem; color: var(--text-1); min-width: 92px; }
  .match-row select {
    flex: 1;
    background: var(--bg-2); color: var(--text-0);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: var(--radius-sm);
    padding: 8px 10px; font-size: 0.92rem;
    cursor: pointer;
    font-family: inherit;
  }
  .match-row select:disabled { opacity: 0.7; }
  .match-icon { font-size: 1.2rem; flex-shrink: 0; min-width: 22px; text-align: center; }

  /* Floating XP popup */
  .xp-popup {
    position: fixed;
    z-index: 8500;
    font-family: 'Space Grotesk';
    font-weight: 800;
    font-size: 1.4rem;
    pointer-events: none;
    text-shadow: 0 2px 8px rgba(0,0,0,0.7);
    transform: translate(-50%, 0);
    animation: xpFly 1.5s cubic-bezier(.2,.8,.4,1) forwards;
  }
  .xp-popup.gold { color: var(--gold); }
  .xp-popup.crit { color: var(--pink); font-size: 1.9rem; }
  .xp-popup.lucky { color: var(--cyan); }
  .xp-popup.combo { color: var(--flame); }
  .xp-popup.mega { color: var(--violet); font-size: 2.1rem; }
  @keyframes xpFly {
    0% { opacity: 0; transform: translate(-50%, 0) scale(0.4); }
    18% { opacity: 1; transform: translate(-50%, -10px) scale(1.18); }
    100% { opacity: 0; transform: translate(-50%, -100px) scale(0.85); }
  }

  /* Toasts */
  .toast-stack {
    position: fixed; top: 80px; left: 50%;
    transform: translateX(-50%);
    z-index: 7000;
    display: flex; flex-direction: column; gap: 8px;
    pointer-events: none;
    width: min(92vw, 380px);
  }
  .toast {
    background: linear-gradient(135deg, var(--gold), var(--flame));
    color: #1a0d00;
    border-radius: var(--radius);
    padding: 12px 16px;
    box-shadow: var(--shadow-glow-gold), 0 8px 24px rgba(0,0,0,0.4);
    display: flex; align-items: center; gap: 12px;
    animation: toastIn 0.45s cubic-bezier(.5,1.6,.5,1), toastOut 0.4s 3.6s forwards;
    border: 2px solid rgba(255,255,255,0.25);
  }
  @keyframes toastIn {
    from { opacity: 0; transform: translateY(-20px) scale(0.85); }
    to { opacity: 1; transform: translateY(0) scale(1); }
  }
  @keyframes toastOut {
    to { opacity: 0; transform: translateY(-20px) scale(0.9); }
  }
  .toast.lvlup {
    background: linear-gradient(135deg, var(--violet), var(--pink));
    color: #fff;
    border-color: rgba(255,255,255,0.35);
  }
  .toast.streak {
    background: linear-gradient(135deg, var(--flame), var(--red));
    color: #fff;
    border-color: rgba(255,255,255,0.35);
  }
  .toast-icon { font-size: 2rem; line-height: 1; flex-shrink: 0; }
  .toast-body { flex: 1; min-width: 0; }
  .toast-title { font-weight: 800; font-size: 0.98rem; line-height: 1.1; }
  .toast-desc { font-size: 0.78rem; opacity: 0.85; margin-top: 2px; word-break: break-word; }

  /* ── RESULTS ─────────────────────────────────────── */
  .res-card {
    background: linear-gradient(180deg, var(--bg-1), var(--bg-2));
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: var(--radius);
    padding: 28px 24px 24px;
    box-shadow: var(--shadow-lift);
    margin-bottom: 16px;
    text-align: center;
    position: relative;
    overflow: hidden;
  }
  .res-rank {
    display: inline-block;
    font-family: 'Space Grotesk'; font-size: 2.2rem; font-weight: 800;
    text-transform: uppercase; letter-spacing: 2px;
    margin-bottom: 12px;
    padding: 6px 22px;
    border-radius: var(--radius);
    text-shadow: 0 2px 8px rgba(0,0,0,0.3);
    animation: rankIn 0.6s cubic-bezier(.5,1.6,.5,1);
  }
  @keyframes rankIn {
    0% { transform: scale(0) rotate(-20deg); opacity: 0; }
    60% { transform: scale(1.15) rotate(5deg); opacity: 1; }
    100% { transform: scale(1) rotate(0); }
  }
  .res-rank.r-S { background: linear-gradient(135deg, var(--gold), var(--flame)); color: #1a0d00; box-shadow: var(--shadow-glow-gold); }
  .res-rank.r-A { background: linear-gradient(135deg, var(--violet), var(--pink)); color: #fff; }
  .res-rank.r-B { background: linear-gradient(135deg, var(--azure), var(--cyan)); color: #fff; }
  .res-rank.r-C { background: linear-gradient(135deg, var(--green), var(--green-deep)); color: #fff; }
  .res-rank.r-D { background: var(--bg-3); color: var(--text-1); }
  .res-rank.r-F { background: linear-gradient(135deg, var(--red), var(--red-deep)); color: #fff; }

  .res-circle {
    width: 150px; height: 150px;
    border-radius: 50%;
    border: 8px solid var(--azure);
    margin: 0 auto 16px;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    background: var(--bg-2);
    box-shadow: var(--shadow-glow-blue);
  }
  .res-circle .res-num { font-family: 'Space Grotesk'; font-size: 2.6rem; font-weight: 800; }
  .res-circle .res-denom { font-size: 0.85rem; color: var(--text-2); }
  .res-circle.green  { border-color: var(--green); box-shadow: var(--shadow-glow-green); }
  .res-circle.gold   { border-color: var(--gold); box-shadow: var(--shadow-glow-gold); }
  .res-circle.red    { border-color: var(--red); box-shadow: var(--shadow-glow-red); }

  .res-xp-big {
    font-family: 'Space Grotesk'; font-size: 2.4rem; font-weight: 800;
    color: var(--gold);
    margin-bottom: 4px;
    text-shadow: 0 0 24px rgba(255,201,64,0.5);
  }
  .res-xp-lbl { font-size: 0.78rem; color: var(--text-2); text-transform: uppercase; letter-spacing: 1px; }

  .res-stats {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
    margin-top: 20px;
    margin-bottom: 4px;
  }
  .res-stat-mini {
    background: var(--bg-0); padding: 12px 6px; border-radius: var(--radius-sm);
    border: 1px solid rgba(255,255,255,0.06);
  }
  .res-stat-mini .rs-val { font-family: 'Space Grotesk'; font-size: 1.4rem; font-weight: 800; display: block; }
  .res-stat-mini .rs-lbl { font-size: 0.65rem; color: var(--text-2); text-transform: uppercase; letter-spacing: 0.5px; }
  .res-stat-mini.ok .rs-val { color: var(--green); }
  .res-stat-mini.ko .rs-val { color: var(--red); }
  .res-stat-mini.combo .rs-val { color: var(--flame); }

  .res-actions { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
  .btn-play-again {
    flex: 2 1 220px;
    padding: 16px 18px;
    background: linear-gradient(135deg, var(--azure), var(--violet));
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 1.08rem; font-weight: 800;
    cursor: pointer;
    box-shadow: 0 8px 22px -4px rgba(43,158,255,0.5);
    transition: transform var(--transition);
    font-family: inherit;
    position: relative;
    overflow: hidden;
  }
  .btn-play-again::after {
    content: '';
    position: absolute; top: 0; left: -100%;
    width: 100%; height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.25), transparent);
    animation: sweep 3s infinite;
  }
  .btn-play-again:hover { transform: translateY(-2px); }
  .btn-home, .btn-review {
    flex: 1 1 90px;
    padding: 14px 14px;
    background: var(--bg-2);
    color: var(--text-1);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: var(--radius-sm);
    font-size: 0.95rem; font-weight: 700;
    cursor: pointer;
    transition: all var(--transition);
    font-family: inherit;
  }
  .btn-home:hover, .btn-review:hover { background: var(--bg-3); color: var(--text-0); }

  /* Review */
  .review-sec {
    background: var(--bg-1);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: var(--radius);
    overflow: hidden;
    display: none;
  }
  .review-sec.show { display: block; }
  .review-head {
    padding: 14px 18px;
    background: var(--bg-2);
    border-bottom: 1px solid rgba(255,255,255,0.06);
    font-weight: 700;
    display: flex; justify-content: space-between; align-items: center;
    cursor: pointer; user-select: none;
  }
  .review-body { padding: 8px 0; max-height: 480px; overflow-y: auto; }
  .review-item {
    padding: 12px 18px;
    border-bottom: 1px solid rgba(255,255,255,0.04);
    display: flex; gap: 12px; align-items: flex-start;
  }
  .review-item:last-child { border: none; }
  .review-icon { font-size: 1.3rem; flex-shrink: 0; margin-top: 1px; }
  .review-icon.ok { color: var(--green); }
  .review-icon.ko { color: var(--red); }
  .review-content { flex: 1; min-width: 0; }
  .review-q { font-size: 0.88rem; margin-bottom: 4px; white-space: pre-wrap; word-break: break-word; }
  .review-ans { font-size: 0.8rem; }
  .review-given { color: var(--red); }
  .review-given.ok { color: var(--green); }
  .review-correct { color: var(--green); font-style: italic; }

  /* Loading */
  .loading-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(11,15,26,0.85);
    backdrop-filter: blur(6px);
    z-index: 500;
    align-items: center; justify-content: center;
    flex-direction: column; gap: 14px;
    color: var(--azure);
    font-weight: 700;
  }
  .loading-overlay.active { display: flex; }
  .spinner {
    width: 48px; height: 48px;
    border: 5px solid rgba(43,158,255,0.18);
    border-top-color: var(--azure);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
  }
  @keyframes spin { to { transform: rotate(360deg); } }

  /* Mobile */
  @media (max-width: 540px) {
    .hud-brand .brand-text { display: none; }
    .hud-inner { gap: 8px; }
    .home-stats { gap: 6px; }
    .stat-tile { padding: 8px 4px; }
    .stat-tile .val { font-size: 1.05rem; }
    .stat-tile .lbl { font-size: 0.58rem; }
    .qcard { padding: 18px 16px 16px; }
    .qcard-text { font-size: 0.98rem; }
    .opt { padding: 12px 14px; font-size: 0.92rem; }
    .opts { gap: 8px; }
    .ach-grid { grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); }
    .ach-tile .albl { font-size: 0.58rem; }
    .combo-display { top: 70px; right: 10px; }
    .combo-bubble .ckanji { font-size: 1.6rem; }
    .res-actions { flex-direction: column; }
    .play-mega { font-size: 1.18rem; padding: 18px 18px; }
  }

  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
      animation-duration: 0.01ms !important;
      animation-iteration-count: 1 !important;
      transition-duration: 0.01ms !important;
    }
  }

/* ── Subjects & Mode screens ──────────────────────── */
.screen-top {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 6px;
}
.back-btn {
  background: var(--bg-1); border: 1px solid rgba(255,255,255,0.08);
  color: var(--text-0); width: 40px; height: 40px;
  border-radius: 12px; display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem; cursor: pointer; transition: background var(--transition);
}
.back-btn:hover { background: var(--bg-2); }
.screen-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.5rem; font-weight: 800; margin: 0; flex: 1;
}
.screen-sub {
  color: var(--text-2); font-size: 0.85rem; margin: 0 0 18px;
}

.subjects-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}
.subject-card {
  background: var(--bg-1); border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius); padding: 16px;
  display: flex; flex-direction: column; gap: 8px;
  cursor: pointer; transition: all var(--transition);
  text-align: left; color: inherit; font: inherit;
}
.subject-card:hover { transform: translateY(-3px); border-color: rgba(43,158,255,0.4); }
.subject-card[disabled] {
  opacity: 0.45; cursor: not-allowed; transform: none;
}
.subject-card[disabled]:hover { transform: none; border-color: rgba(255,255,255,0.08); }
.subject-card .sc-icon { font-size: 1.6rem; }
.subject-card .sc-name { font-weight: 700; font-size: 1.05rem; }
.subject-card .sc-count { font-size: 0.8rem; color: var(--text-2); }
.subject-card .sc-progress { height: 4px; background: var(--bg-2); border-radius: 99px; overflow: hidden; }
.subject-card .sc-progress-fill { height: 100%; background: linear-gradient(90deg, var(--azure), var(--violet)); }
.subject-card .sc-reason { font-size: 0.7rem; color: var(--flame); margin-top: 4px; }

.mode-list { display: flex; flex-direction: column; gap: 12px; }
.mode-card {
  background: var(--bg-1); border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius); padding: 18px;
  display: flex; flex-direction: column; gap: 4px;
  cursor: pointer; transition: all var(--transition);
  text-align: left; color: inherit; font: inherit;
}
.mode-card:hover { transform: translateY(-2px); border-color: rgba(43,158,255,0.5); box-shadow: var(--shadow-lift); }
.mode-card-icon { font-size: 1.8rem; }
.mode-card-title { font-size: 1.15rem; font-weight: 800; }
.mode-card-sub { font-size: 0.82rem; color: var(--text-2); }
.mode-endless { border-color: rgba(255,201,64,0.35); }
.mode-40 { border-color: rgba(168,85,247,0.35); }

.subject-stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px;
  margin-bottom: 20px;
}
.subject-stat-mini {
  background: var(--bg-1); border: 1px solid rgba(255,255,255,0.06);
  border-radius: var(--radius-sm); padding: 10px 12px;
  display: flex; flex-direction: column; gap: 2px;
}
.subject-stat-mini .ssm-name { font-weight: 700; font-size: 0.85rem; }
.subject-stat-mini .ssm-meta { font-size: 0.72rem; color: var(--text-2); }

/* ── Exam mode: hide power-ups and combo display ───────── */
body.exam-mode .pup-bar,
body.exam-mode .combo-display {
  display: none !important;
}

/* ── Home: mini subject teaser (readiness) ─────────────── */
.subject-stat-mini .ssm-top {
  display: flex; align-items: baseline; justify-content: space-between; gap: 6px;
}
.subject-stat-mini .ssm-score {
  font-family: 'Space Grotesk', sans-serif; font-weight: 800; font-size: 1.05rem;
}
.subject-stat-mini .ssm-bar {
  height: 5px; background: var(--bg-3); border-radius: 99px; overflow: hidden; margin: 2px 0;
}
.subject-stat-mini .ssm-bar-fill { height: 100%; border-radius: 99px; transition: width var(--transition-slow); }

.btn-see-progress {
  width: 100%;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--bg-1); border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius-sm); padding: 13px 16px; margin-bottom: 24px;
  color: var(--text-0); font: inherit; font-weight: 700; font-size: 0.9rem;
  cursor: pointer; transition: all var(--transition);
}
.btn-see-progress:hover { background: var(--bg-2); border-color: rgba(43,158,255,0.4); transform: translateY(-2px); }

/* ── Progress screen ───────────────────────────────────── */
.progress-hero {
  display: none; align-items: center; gap: 14px;
  padding: 16px 18px; margin-bottom: 20px;
  border-radius: var(--radius); border: 1px solid rgba(255,255,255,0.08);
  border-left-width: 4px; background: var(--bg-1);
}
.progress-hero.tone-good, .progress-hero.tone-warn,
.progress-hero.tone-bad,  .progress-hero.tone-none { display: flex; }
.progress-hero.tone-good { border-left-color: var(--green); background: linear-gradient(90deg, rgba(34,197,94,0.12), transparent 60%); }
.progress-hero.tone-warn { border-left-color: var(--gold);  background: linear-gradient(90deg, rgba(255,201,64,0.12), transparent 60%); }
.progress-hero.tone-bad  { border-left-color: var(--red);   background: linear-gradient(90deg, rgba(239,68,68,0.13), transparent 60%); }
.progress-hero.tone-none { border-left-color: var(--text-2); }
.progress-hero .ph-icon { font-size: 1.8rem; line-height: 1; }
.progress-hero .ph-txt { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.progress-hero .ph-txt strong { font-size: 1.02rem; }
.progress-hero .ph-txt span { font-size: 0.82rem; color: var(--text-1); }
.progress-hero .ph-btn {
  background: var(--bg-2); border: 1px solid rgba(255,255,255,0.12); color: var(--text-0);
  border-radius: var(--radius-sm); padding: 9px 14px; font: inherit; font-weight: 700;
  cursor: pointer; white-space: nowrap; transition: all var(--transition);
}
.progress-hero .ph-btn:hover { background: var(--bg-3); transform: translateY(-1px); }

.progress-list { display: flex; flex-direction: column; gap: 12px; padding-bottom: 20px; }

.psub-card {
  background: var(--bg-1); border: 1px solid rgba(255,255,255,0.08);
  border-left: 4px solid transparent;
  border-radius: var(--radius); padding: 16px;
  display: flex; align-items: flex-start; gap: 16px;
}
.psub-card.tone-good { border-left-color: var(--green); }
.psub-card.tone-warn { border-left-color: var(--gold); }
.psub-card.tone-bad  { border-left-color: var(--red); }
.psub-card.tone-none { border-left-color: var(--text-2); }
.psub-card.muted { flex-direction: column; gap: 4px; opacity: 0.55; }
.psub-card.muted .pc-locked-row { display: flex; justify-content: space-between; width: 100%; gap: 8px; }
.psub-card.muted .pc-locked { font-size: 0.78rem; color: var(--text-2); }
.psub-card.muted .pc-locked-sub { font-size: 0.72rem; color: var(--text-2); }

.pring {
  flex-shrink: 0; width: 66px; height: 66px; border-radius: 50%;
  display: grid; place-items: center; position: relative;
}
.pring::before {
  content: ''; position: absolute; inset: 6px; border-radius: 50%; background: var(--bg-1);
}
.pring span {
  position: relative; z-index: 1;
  font-family: 'Space Grotesk', sans-serif; font-weight: 800; font-size: 1.25rem;
}

.pc-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.pc-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.pc-name { font-weight: 800; font-size: 1.08rem; }
.pc-verdict { font-weight: 700; font-size: 0.82rem; white-space: nowrap; }

.pbar { display: flex; height: 9px; border-radius: 99px; overflow: hidden; background: var(--bg-3); }
.pbar .pseg { height: 100%; transition: width var(--transition-slow); }
.pbar .pseg.mastered { background: var(--green); }
.pbar .pseg.learning { background: var(--azure); }
.pbar .pseg.weak     { background: var(--red); }
.pbar .pseg.unseen   { background: var(--bg-3); }

.pc-metrics { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 0.74rem; color: var(--text-1); }
.pc-metrics .pm { white-space: nowrap; }

.pc-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  flex-wrap: wrap; margin-top: 2px;
}
.pc-cov { font-size: 0.76rem; color: var(--text-2); }
.btn-review-weak {
  background: rgba(239,68,68,0.14); border: 1px solid rgba(239,68,68,0.4); color: #ffd9d9;
  border-radius: var(--radius-sm); padding: 8px 13px; font: inherit; font-weight: 700; font-size: 0.8rem;
  cursor: pointer; white-space: nowrap; transition: all var(--transition);
}
.btn-review-weak:hover { background: rgba(239,68,68,0.24); transform: translateY(-1px); }

@media (max-width: 540px) {
  .psub-card { flex-direction: column; gap: 12px; }
  .pring { width: 56px; height: 56px; }
  .pring span { font-size: 1.05rem; }
}

/* ════════════════════════════════════════════════════════════════
   RESPONSIVE FIT — el quiz cabe SIEMPRE en una pantalla, sin scroll,
   de un iPhone 17 Pro Max a un Android de 4".
   La pantalla de quiz es una columna de altura = viewport. La pregunta,
   las opciones y el feedback viven en .quiz-body, y un factor --qscale
   (que calcula UI.fitQuiz en JS) encoge proporcionalmente tipografías,
   paddings y gaps hasta que todo entra. Si ni al mínimo cabe (caso
   patológico: muchísimo código en pantalla diminuta), .quiz-body hace
   scroll interno como último recurso — nunca scrollea la página entera.
   ════════════════════════════════════════════════════════════════ */

/* Durante el quiz: sin scroll de página y sin HUD (modo foco). */
body.quiz-active { overflow: hidden; overscroll-behavior: none; }
body.quiz-active .hud { display: none; }
body.quiz-active .combo-display { top: 12px; }

#screen-quiz { --qscale: 1; }

#screen-quiz.active {
  display: flex;
  flex-direction: column;
  height: 100vh;          /* fallback navegadores viejos */
  height: 100svh;         /* altura útil con las barras del navegador visibles */
  overflow: hidden;
  animation: none;        /* sin fade: evita medir durante el reflow */
}
#screen-quiz.active .container {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: calc(8px * var(--qscale, 1));
  padding: calc(10px * var(--qscale, 1))
           clamp(10px, 3.5vw, 16px)
           calc(10px + env(safe-area-inset-bottom, 0px));
  max-width: 760px;
}

#screen-quiz .quiz-top { flex: 0 0 auto; margin: 0; }

/* Zona elástica: pregunta + opciones + feedback. */
#screen-quiz .quiz-body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;      /* arriba: scrollHeight fiable y nunca recorta el inicio */
  gap: calc(10px * var(--qscale, 1));
  overflow-y: auto;                 /* solo entra en juego en el caso patológico */
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
#screen-quiz .quiz-body > * { margin: 0; flex: 0 0 auto; }

/* La tarjeta de la pregunta toma el alto sobrante y, si el enunciado (texto +
   código) no entra ni encogido, scrollea DENTRO de la tarjeta. Las 3 opciones
   y los botones, al ser flex:0 0 auto, quedan SIEMPRE anclados y visibles. */
#screen-quiz .quiz-body > .qcard {
  flex: 0 1 auto;          /* se ajusta al contenido; encoge (no crece) si falta sitio */
  min-height: clamp(44px, 14svh, 160px);  /* el enunciado nunca desaparece del todo */
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#screen-quiz .quiz-body > .qcard > .qcard-badges { flex: 0 0 auto; }
#screen-quiz .quiz-body > .qcard > .qcard-text {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;        /* el enunciado scrollea aquí solo si es gigantesco */
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
/* Las opciones comparten el alto; si son muy largas se acotan y scrollean,
   pero nunca llegan a tapar por completo el enunciado (que tiene su mínimo). */
#screen-quiz .quiz-body > .opts {
  flex: 0 1 auto;          /* mismo reparto que la tarjeta: encoge proporcionalmente */
  min-height: clamp(40px, 12svh, 120px);  /* las opciones nunca desaparecen del todo */
  max-height: 62svh;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

#screen-quiz .pup-bar,
#screen-quiz .qactions { flex: 0 0 auto; margin: 0; }

/* ── Medidas escalables (base = look de escritorio; ×--qscale al encoger) ── */
#screen-quiz .quiz-prog-label { font-size: calc(0.78rem * var(--qscale, 1)); }

#screen-quiz .qcard {
  padding: calc(20px * var(--qscale, 1)) calc(22px * var(--qscale, 1));
}
#screen-quiz .qcard-badges {
  gap: calc(6px * var(--qscale, 1));
  margin-bottom: calc(10px * var(--qscale, 1));
}
#screen-quiz .qbadge {
  font-size: calc(0.7rem * var(--qscale, 1));
  padding: calc(3px * var(--qscale, 1)) calc(9px * var(--qscale, 1));
}
#screen-quiz .qcard-text { font-size: calc(1.04rem * var(--qscale, 1)); line-height: 1.5; }

#screen-quiz .qcard-text .code-block,
#screen-quiz .opt .code-block {
  font-size: calc(0.84rem * var(--qscale, 1));
  padding: calc(10px * var(--qscale, 1)) calc(12px * var(--qscale, 1));
  margin: calc(8px * var(--qscale, 1)) 0;
  line-height: 1.45;
}
/* Un bloque de código dentro de una OPCIÓN se acota para no inflar la opción;
   el enunciado no se acota porque su tarjeta ya scrollea como conjunto. */
#screen-quiz .opt .code-block { max-height: clamp(80px, 20svh, 200px); overflow: auto; }

#screen-quiz .opts { gap: calc(10px * var(--qscale, 1)); }
#screen-quiz .opt {
  gap: calc(10px * var(--qscale, 1));
  padding: calc(13px * var(--qscale, 1)) calc(15px * var(--qscale, 1));
  font-size: calc(0.97rem * var(--qscale, 1));
  line-height: 1.4;
}
/* El texto va en este span hijo: escalarlo aquí garantiza que encoge aunque el
   navegador "fije" el font-size del <button> contenedor (text-autosizing). */
#screen-quiz .opt .opt-text {
  font-size: calc(0.97rem * var(--qscale, 1));
  line-height: 1.4;
}
#screen-quiz .opt-letter {
  width: calc(31px * var(--qscale, 1));
  height: calc(31px * var(--qscale, 1));
  font-size: calc(0.82rem * var(--qscale, 1));
}
#screen-quiz .opt-icon { font-size: calc(1.2rem * var(--qscale, 1)); }

#screen-quiz .feedback {
  padding: calc(11px * var(--qscale, 1)) calc(14px * var(--qscale, 1));
  font-size: calc(0.9rem * var(--qscale, 1));
}
#screen-quiz .feedback .fbtitle {
  font-size: calc(0.98rem * var(--qscale, 1));
  margin-bottom: calc(4px * var(--qscale, 1));
}
#screen-quiz .feedback .fbexpl { font-size: calc(0.84rem * var(--qscale, 1)); }

#screen-quiz .pup-bar { gap: calc(8px * var(--qscale, 1)); }
#screen-quiz .pup-bar .pup-btn {
  padding: calc(8px * var(--qscale, 1)) calc(6px * var(--qscale, 1));
  font-size: calc(0.82rem * var(--qscale, 1));
}
#screen-quiz .pup-bar .pup-btn .picn { font-size: calc(1.1rem * var(--qscale, 1)); }

#screen-quiz .qactions { gap: calc(10px * var(--qscale, 1)); }
#screen-quiz .btn-check,
#screen-quiz .btn-next {
  padding: calc(13px * var(--qscale, 1)) calc(16px * var(--qscale, 1));
  font-size: calc(1rem * var(--qscale, 1));
}

/* En orientación apaisada del móvil el alto es mínimo: damos prioridad
   absoluta a que entre, el JS hará el resto. */
@media (orientation: landscape) and (max-height: 480px) {
  body.quiz-active .combo-display { display: none; }
}
