  /* ===== RESET & BASE ===== */
  *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
  :root {
    --primary: #5b4ced;
    --primary-dark: #3730a3;
    --primary-light: #a78bfa;
    --secondary: #06b6d4;
    --accent: #f59e0b;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --bg: #0d0f1a;
    --bg2: #13162a;
    --card: #1a1f38;
    --card2: #222845;
    --text: #e8eaf6;
    --text-muted: #8892b0;
    --border: #2e3560;
    --radius: 16px;
    --shadow: 0 8px 32px rgba(0,0,0,0.5);
    --glow: 0 0 20px rgba(91,76,237,0.35);
  }
  html, body { height: 100%; font-family: 'Segoe UI', system-ui, -apple-system, sans-serif; background: var(--bg); color: var(--text); font-size: 16px; }
  body { display: flex; flex-direction: column; min-height: 100vh; background: radial-gradient(ellipse at top, #1a1f3c 0%, #0d0f1a 70%); }

  /* ===== SITE HEADER BAR ===== */
  /* 10. Enhanced topbar gradient */
  .site-topbar {
    width: 100%;
    background: linear-gradient(135deg, #1a1040 0%, #1e1b4b 40%, #0d1a2a 100%);
    border-bottom: 1px solid var(--border);
    padding: 10px 20px;
    display: flex; align-items: center; justify-content: space-between;
    flex-shrink: 0;
    box-shadow: 0 2px 16px rgba(0,0,0,0.4);
    position: sticky; top: 0; z-index: 100; /* stays visible when keyboard pushes page up */
  }
  .site-topbar .brand { display: flex; align-items: center; gap: 12px; }
  .site-topbar .brand-logo {
    width: 42px; height: 42px; border-radius: 10px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    display: flex; align-items: center; justify-content: center;
    font-size: 0.68rem; font-weight: 900; color: #fff; letter-spacing: -0.02em;
    flex-shrink: 0; box-shadow: var(--glow);
  }
  .site-topbar .brand-name { font-size: 1rem; font-weight: 700; color: var(--primary-light); letter-spacing: 0.04em; }
  .site-topbar .brand-title { font-size: 0.95rem; color: var(--text); font-weight: 700; letter-spacing: 0.02em; }

  /* ===== FOOTER ===== */
  .site-footer { width: 100%; text-align: center; padding: 14px 16px; font-size: 0.78rem; color: var(--text-muted); border-top: 1px solid var(--border); background: var(--bg); flex-shrink: 0; margin-top: auto; }

  /* ===== SCREENS ===== */
  /* 6. Screen fade — hide inactive screens without position:absolute to avoid clipping */
  .screen {
    display: none; flex-direction: column; align-items: center; justify-content: flex-start;
    flex: 1; padding: 28px 16px 36px;
  }
  .screen.active {
    display: flex;
    animation: screenFadeIn 0.28s ease both;
  }
  @keyframes screenFadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
  }

  /* ===== PAGE HEADER (title screen) ===== */
  .site-header { text-align: center; margin-bottom: 32px; }
  .site-header h1 {
    font-size: clamp(2rem, 6vw, 3rem); font-weight: 900;
    background: linear-gradient(135deg, #a78bfa, #06b6d4);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
    margin-top: 6px; text-shadow: none; letter-spacing: -0.01em;
  }
  .site-header p { color: var(--text-muted); margin-top: 8px; font-size: 1rem; }

  /* ===== GAME-STYLE SETTING CARDS ===== */
  .setting-section {
    width: 100%; max-width: 660px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 22px 24px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
    position: relative;
    overflow: hidden; /* clips ::before gradient bar to rounded corners */
  }
  .setting-section::before {
    content: '';
    position: absolute; top: 0; left: 0; right: 0; height: 3px;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    border-radius: var(--radius) var(--radius) 0 0;
  }
  .setting-label {
    display: flex; align-items: center; gap: 10px;
    font-size: 0.78rem; font-weight: 800; text-transform: uppercase;
    letter-spacing: 0.12em; color: var(--primary-light);
    margin-bottom: 16px;
  }
  .setting-label .step-badge {
    width: 22px; height: 22px; border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    display: flex; align-items: center; justify-content: center;
    font-size: 0.7rem; font-weight: 900; color: #fff; flex-shrink: 0;
  }

  /* ===== OPTION GROUPS ===== */
  .option-group { display: flex; gap: 10px; flex-wrap: wrap; }
  .opt-btn {
    flex: 1; min-width: 80px; padding: 11px 10px;
    border-radius: 12px;
    border: 2px solid var(--border);
    background: var(--card2);
    color: var(--text-muted);
    font-size: 0.92rem; font-weight: 600; cursor: pointer;
    transition: all 0.2s; text-align: center; letter-spacing: 0.01em;
    -webkit-appearance: none;
    appearance: none;
    font-family: inherit;
    -webkit-tap-highlight-color: transparent; /* remove Android Chrome tap highlight ring */
  }
  /* 2. Button press micro-interaction */
  .opt-btn:active:not(:disabled) { transform: scale(0.96); }
  /* Hover and focus-border only on real pointer devices — prevents sticky hover outline on mobile touch */
  @media (hover: hover) {
    .opt-btn:hover:not(:disabled):not(.selected) { border-color: var(--primary-light); color: var(--text); background: rgba(91,76,237,0.12); }
    .opt-btn:focus:not(.selected) { border-color: var(--primary-light); }
  }
  .opt-btn:focus { outline: none; }
  /* Suppress focus-visible ring on touch devices — prevents bright border after tap on mobile */
  .opt-btn:focus-visible:not(.selected) { outline: none; border-color: var(--border); }
  .opt-btn.selected {
    border-color: var(--primary) !important;
    background: linear-gradient(135deg, var(--primary), #7c3aed) !important;
    color: #fff !important;
    box-shadow: 0 0 14px rgba(91,76,237,0.45);
  }
  .opt-btn:disabled { opacity: 0.3; cursor: not-allowed; }

  /* ===== START BUTTON ===== */
  .btn-start {
    width: 100%; max-width: 660px; margin-top: 8px; padding: 18px;
    border-radius: var(--radius); border: none;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: #fff; font-size: 1.15rem; font-weight: 800; cursor: pointer;
    transition: opacity 0.2s, transform 0.15s, box-shadow 0.2s;
    letter-spacing: 0.04em; box-shadow: 0 4px 24px rgba(91,76,237,0.4);
    text-transform: uppercase;
  }
  .btn-start:hover:not(:disabled) { opacity: 0.92; transform: translateY(-2px); box-shadow: 0 8px 32px rgba(91,76,237,0.55); }
  .btn-start:disabled { opacity: 0.3; cursor: not-allowed; box-shadow: none; }

  /* ===== HUD ===== */
  .hud {
    display: flex; align-items: center; justify-content: space-between;
    width: 100%; max-width: 720px; margin-bottom: 12px; gap: 8px; flex-wrap: wrap;
  }
  .hud-item {
    background: var(--card); border: 1px solid var(--border); border-radius: 12px;
    padding: 10px 16px; font-size: 0.88rem; font-weight: 700;
    display: flex; align-items: center; gap: 6px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  }
  .hud-item .label { color: var(--text-muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em; }
  .hud-item .value { color: var(--text); font-size: 1rem; }
  .hud-item.score .value { color: var(--success); }
  .hud-item.timer .value { color: var(--secondary); font-variant-numeric: tabular-nums; font-family: 'Courier New', monospace; }
  .btn-quit {
    background: transparent; border: 1px solid var(--border); color: var(--text-muted);
    border-radius: 10px; padding: 9px 16px; font-size: 0.84rem; cursor: pointer;
    transition: all 0.18s; font-weight: 600;
  }
  .btn-quit:hover { border-color: var(--danger); color: var(--danger); background: rgba(239,68,68,0.08); }

  /* ===== PROGRESS BAR ===== */
  /* 4. Smooth progress bar transition */
  .progress-bar-wrap { width: 100%; max-width: 720px; height: 6px; background: var(--border); border-radius: 99px; margin-bottom: 18px; overflow: hidden; }
  .progress-bar-fill { height: 100%; background: linear-gradient(90deg, var(--primary), var(--secondary)); border-radius: 99px; transition: width 0.55s cubic-bezier(0.4,0,0.2,1); }

  /* ===== QUESTION CARD ===== */
  .q-card {
    background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 20px 24px 26px;
    width: 100%; max-width: 720px; box-shadow: var(--shadow);
    position: relative; overflow: visible; text-align: center;
  }
  /* Header row: type badge on left, unit badge on right — never overlaps */
  .q-card-header {
    display: flex; align-items: center; justify-content: center;
    gap: 8px; flex-wrap: nowrap; margin-bottom: 14px;
  }
  .q-card-header .q-type-badge { margin-bottom: 0; flex-shrink: 1; min-width: 0; }
  .q-card-header .q-unit-badge { flex-shrink: 0; }
  .q-card::before {
    content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    border-radius: var(--radius) var(--radius) 0 0; /* clip gradient bar to card corners without overflow:hidden */
  }
  .q-type-badge {
    display: inline-block; font-size: 0.72rem; font-weight: 800; text-transform: uppercase;
    letter-spacing: 0.08em; padding: 4px 12px; border-radius: 99px; margin-bottom: 14px;
  }
  .q-card .match-col-label { text-align: center; }
  .q-card .match-grid { text-align: left; }
  .match-item { text-align: center; justify-content: center; }
  .match-label { display: block; width: 100%; text-align: center; }
  .match-label em { font-style: italic; }
  .badge-mcq { background: rgba(91,76,237,0.2); color: var(--primary-light); border: 1px solid rgba(91,76,237,0.3); }
  .badge-fill { background: rgba(6,182,212,0.2); color: var(--secondary); border: 1px solid rgba(6,182,212,0.3); }
  .badge-match { background: rgba(16,185,129,0.2); color: var(--success); border: 1px solid rgba(16,185,129,0.3); }
  /* Unit origin badge — inline in the card header row */
  .q-unit-badge {
    display: inline-block;
    font-size: 0.62rem; font-weight: 900; text-transform: uppercase; letter-spacing: 0.1em;
    padding: 3px 9px; border-radius: 99px;
    opacity: 0.92; pointer-events: none; white-space: nowrap;
  }
  /* Tick mark inside selected unit button */
  .unit-tick {
    display: inline-block; font-size: 0.85em; font-weight: 900;
    margin-right: 3px; color: #fff;
  }
  .q-unit-badge.unit-5  { background: rgba(167,139,250,0.18); color: #c4b5fd; border: 1px solid rgba(167,139,250,0.35); }
  .q-unit-badge.unit-6  { background: rgba(6,182,212,0.15);  color: #67e8f9;  border: 1px solid rgba(6,182,212,0.3);   }
  .q-unit-badge.unit-8  { background: rgba(245,158,11,0.15);  color: #fcd34d;  border: 1px solid rgba(245,158,11,0.3);  }
  .q-unit-badge.unit-mix{ background: rgba(255,255,255,0.08); color: #94a3b8;  border: 1px solid rgba(255,255,255,0.12);}
  /* Unit label pill on results vocab list */
  .vi-unit-label {
    display: inline-block; flex-shrink: 0;
    font-size: 0.65rem; font-weight: 900; letter-spacing: 0.06em;
    padding: 2px 6px; border-radius: 99px; margin-top: 2px;
    text-transform: uppercase; white-space: nowrap;
  }
  .vi-unit-label.unit-5 { background: rgba(167,139,250,0.18); color: #c4b5fd; border: 1px solid rgba(167,139,250,0.35); }
  .vi-unit-label.unit-6 { background: rgba(6,182,212,0.15);  color: #67e8f9;  border: 1px solid rgba(6,182,212,0.3);   }
  .vi-unit-label.unit-8 { background: rgba(245,158,11,0.15);  color: #fcd34d;  border: 1px solid rgba(245,158,11,0.3);  }
  /* 7. Improved question text typography */
  .q-text { font-size: clamp(1.18rem, 3.5vw, 1.45rem); font-weight: 700; line-height: 1.8; margin-bottom: 20px; color: #ffffff; letter-spacing: 0.01em; }
  .def-reveal { margin-top: 14px; padding: 12px 16px; background: rgba(16,185,129,0.1); border-left: 3px solid var(--success); border-radius: 8px; font-size: 0.9rem; color: #a7f3d0; display: none; }
  .def-reveal.show { display: block; }

  /* ===== MCQ OPTIONS ===== */
  .mcq-options { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
  @media(max-width:480px){ .mcq-options { grid-template-columns: 1fr; } }
  .mcq-opt {
    padding: 14px 18px; border-radius: 12px; border: 2px solid var(--border);
    background: var(--card2); color: var(--text); font-size: 0.95rem; cursor: pointer;
    transition: all 0.18s; text-align: center; line-height: 1.45; font-weight: 500;
  }
  /* 2. MCQ button press micro-interaction */
  .mcq-opt:active:not(:disabled):not(.correct):not(.wrong) { transform: scale(0.97); }
  .mcq-opt:hover:not(:disabled):not(.correct):not(.wrong) { border-color: var(--primary-light); background: rgba(91,76,237,0.12); }
  .mcq-opt.correct { border-color: var(--success); background: rgba(16,185,129,0.18); color: #a7f3d0; }
  .mcq-opt.wrong { border-color: var(--danger); background: rgba(239,68,68,0.15); color: #fca5a5; }
  .mcq-opt:disabled { cursor: default; }

  /* ===== FILL IN THE BLANK ===== */
  .fill-wrap { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: center; }
  .fill-input {
    flex: 1; min-width: 180px; padding: 13px 16px; border-radius: 12px;
    border: 2px solid var(--border); background: var(--card2); color: var(--text);
    font-size: 1rem; outline: none; transition: border-color 0.18s; font-family: inherit;
  }
  .fill-input:focus { border-color: var(--primary-light); }
  .fill-input.correct { border-color: var(--success); background: rgba(16,185,129,0.12); }
  .fill-input.wrong { border-color: var(--danger); background: rgba(239,68,68,0.1); }
  .btn-submit {
    padding: 13px 24px; border-radius: 12px; border: none;
    background: linear-gradient(135deg, var(--primary), #7c3aed);
    color: #fff; font-size: 0.95rem; font-weight: 700; cursor: pointer;
    transition: opacity 0.18s, transform 0.15s; box-shadow: 0 2px 10px rgba(91,76,237,0.4);
  }
  .btn-submit:hover:not(:disabled) { opacity: 0.88; transform: translateY(-1px); }
  .btn-submit:disabled { opacity: 0.4; cursor: default; box-shadow: none; }
  .fill-feedback { margin-top: 10px; font-size: 0.9rem; font-weight: 600; display: none; }
  .fill-feedback.show { display: block; }
  .fill-feedback.ok { color: var(--success); }
  .fill-feedback.err { color: var(--danger); }

  /* ===== FILL2 (SPLIT BLANK) ===== */
  .fill2-num {
    font-size: 0.6em; color: var(--text-muted);
    vertical-align: super; margin-right: 3px;
  }
  .fill2-inputs { display: flex; flex-direction: column; gap: 12px; margin-top: 16px; }
  .fill2-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
  .fill2-row-label {
    min-width: 60px; font-size: 0.78rem; font-weight: 800; text-transform: uppercase;
    letter-spacing: 0.08em; color: var(--text-muted); flex-shrink: 0;
  }
  .fill2-inputs .fill-input { flex: 1; min-width: 160px; }
  .fill2-inputs .btn-submit { margin-top: 6px; align-self: center; }

  /* ===== MATCHING ===== */
  .match-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
  @media(max-width:500px){ .match-grid { gap: 8px; } .match-item { padding: 9px 10px; font-size: 0.8rem; min-height: 44px; } }
  .match-col { display: flex; flex-direction: column; gap: 12px; }
  .match-col-label { font-size: 0.75rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted); margin-bottom: 4px; }
  .match-item {
    padding: 12px 16px; border-radius: 12px; border: 2px solid var(--border);
    background: var(--card2); color: var(--text); font-size: 0.88rem; cursor: pointer;
    transition: all 0.18s; line-height: 1.45; min-height: 54px; display: flex; align-items: center;
    margin-bottom: 4px;
  }
  .match-item:hover:not(.matched):not(.wrong-flash) { border-color: var(--primary-light); background: rgba(91,76,237,0.1); }
  .match-item.selected { border-color: var(--primary); background: rgba(91,76,237,0.22); box-shadow: 0 0 10px rgba(91,76,237,0.3); }
  .match-item.matched { border-color: var(--success); background: rgba(16,185,129,0.15); color: #a7f3d0; cursor: default; }
  .match-item.wrong-flash { border-color: var(--danger); background: rgba(239,68,68,0.15); animation: shake 0.35s; }
  @keyframes shake { 0%,100%{transform:translateX(0)} 25%{transform:translateX(-4px)} 75%{transform:translateX(4px)} }
  .match-score-note { margin-top: 14px; font-size: 0.88rem; font-weight: 600; }
  .match-score-note.ok { color: var(--success); }
  .match-score-note.err { color: var(--danger); }

  /* ===== NEXT BUTTON ===== */
  .btn-next {
    margin-top: 20px; width: 100%; max-width: 720px; padding: 15px;
    border-radius: var(--radius); border: none;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: #fff; font-size: 1rem; font-weight: 700; cursor: pointer;
    display: none; transition: opacity 0.2s, transform 0.15s;
    box-shadow: 0 4px 20px rgba(91,76,237,0.4); text-transform: uppercase; letter-spacing: 0.04em;
  }
  .btn-next.show { display: block; }
  .btn-next:hover { opacity: 0.88; transform: translateY(-1px); }

  /* ===== RESULTS SCREEN ===== */
  .results-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 30px 26px; width: 100%; max-width: 720px; box-shadow: var(--shadow); }
  .results-score-big { font-size: clamp(2.8rem, 9vw, 4.5rem); font-weight: 900; text-align: center; background: linear-gradient(135deg, #a78bfa, #06b6d4); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; }
  .results-label { text-align: center; color: var(--text-muted); font-size: 0.9rem; margin-bottom: 6px; }
  .results-remark { text-align: center; font-size: 1.1rem; font-weight: 700; margin: 14px 0 22px; color: var(--warning); }
  .results-meta { display: flex; justify-content: center; gap: 28px; margin-bottom: 22px; flex-wrap: wrap; }
  .results-meta-item { text-align: center; }
  .results-meta-item .val { font-size: 1.4rem; font-weight: 800; color: var(--text); font-variant-numeric: tabular-nums; }
  .results-meta-item .lbl { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; margin-top: 2px; }
  .vocab-review { margin-top: 20px; }
  .vocab-review h3 { font-size: 0.85rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.08em; color: var(--primary-light); margin-bottom: 12px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
  .vocab-count { font-size: 0.8rem; font-weight: 700; color: var(--text-muted); margin-left: 6px; }
  .vocab-list { display: flex; flex-direction: column; gap: 8px; max-height: 320px; overflow-y: auto; padding-right: 4px; }
  .vocab-list::-webkit-scrollbar { width: 5px; }
  .vocab-list::-webkit-scrollbar-track { background: var(--card2); border-radius: 99px; }
  .vocab-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }
  .vocab-item { display: flex; gap: 10px; align-items: flex-start; padding: 10px 14px; background: var(--card2); border-radius: 10px; border: 1px solid var(--border); }
  .vocab-item .vi-word { font-weight: 700; color: var(--text); min-width: 140px; font-size: 0.9rem; }
  .vocab-item .vi-pos { font-size: 0.7rem; font-weight: 700; font-style: italic; flex-shrink: 0; color: #67e8f9; background: rgba(6,182,212,0.12); border: 1px solid rgba(6,182,212,0.3); border-radius: 6px; padding: 1px 6px; align-self: center; letter-spacing: 0.02em; }
  .vocab-item .vi-def { color: var(--text-muted); font-size: 0.88rem; line-height: 1.4; }
  .btn-play-again { width: 100%; margin-top: 22px; padding: 15px; border-radius: var(--radius); border: none; background: linear-gradient(135deg, var(--primary), var(--secondary)); color: #fff; font-size: 1rem; font-weight: 700; cursor: pointer; transition: opacity 0.2s, transform 0.15s; text-transform: uppercase; letter-spacing: 0.04em; box-shadow: 0 4px 20px rgba(91,76,237,0.4); }
  .btn-play-again:hover { opacity: 0.88; transform: translateY(-1px); }

  /* ===== DIVIDER ===== */
  .divider { height: 1px; background: var(--border); margin: 20px 0; }

  /* ===== ANIMATIONS ===== */

  /* 1. Question card entrance */
  @keyframes cardEnter {
    from { opacity: 0; transform: translateY(18px) scale(0.98); }
    to   { opacity: 1; transform: translateY(0)   scale(1);    }
  }
  .q-card { animation: cardEnter 0.32s cubic-bezier(0.22,1,0.36,1) both; }

  /* 3. Correct / wrong answer flash on MCQ buttons */
  @keyframes correctFlash {
    0%   { box-shadow: 0 0 0 0 rgba(16,185,129,0.7); }
    50%  { box-shadow: 0 0 0 10px rgba(16,185,129,0); }
    100% { box-shadow: none; }
  }
  @keyframes wrongFlash {
    0%   { box-shadow: 0 0 0 0 rgba(239,68,68,0.7); }
    50%  { box-shadow: 0 0 0 10px rgba(239,68,68,0); }
    100% { box-shadow: none; }
  }
  .mcq-opt.correct { animation: correctFlash 0.45s ease-out forwards; }
  .mcq-opt.wrong   { animation: wrongFlash  0.45s ease-out forwards; }

  /* 5. Score counter pop */
  @keyframes scorePop {
    0%   { transform: scale(1); }
    40%  { transform: scale(1.45); color: #fbbf24; }
    100% { transform: scale(1); }
  }
  .hud-item.score .value.pop { animation: scorePop 0.38s cubic-bezier(0.34,1.56,0.64,1) both; }

  /* 6. Screen fade transition — handled by screenFadeIn keyframe above */

  /* 9. Confetti (100% score) */
  @keyframes confettiFall {
    0%   { transform: translateY(-20px) rotate(0deg);   opacity: 1; }
    100% { transform: translateY(110vh) rotate(720deg); opacity: 0; }
  }
  .confetti-piece {
    position: fixed; top: -10px; width: 10px; height: 10px;
    border-radius: 2px; pointer-events: none; z-index: 9999;
    animation: confettiFall linear forwards;
  }

  /* ===== RESPONSIVE ===== */
  @media(max-width:640px){
    .setting-section, .q-card, .results-card { padding: 18px 14px; }
    .hud { gap: 6px; }
    .hud-item { padding: 7px 10px; font-size: 0.78rem; }
    /* 7. Larger mobile question text */
    .q-text { font-size: 1.22rem; line-height: 1.85; }
  }

  /* ===== DESKTOP (≥1024px): wider container + larger text ===== */
  @media(min-width:1024px){
    /* Widen all constrained elements from 720px to 900px */
    .hud, .progress-bar-wrap, .q-card, .btn-next, .results-card { max-width: 900px; }
    /* Widen title page setting sections and action buttons to match */
    .setting-section, .btn-start, .btn-action-row { max-width: 900px; }
    /* Taller question card to reduce empty space below on desktop */
    .q-card { min-height: 420px; display: flex; flex-direction: column; justify-content: center; }
    /* Larger question text */
    .q-text { font-size: 1.55rem; line-height: 1.85; }
    /* Larger MCQ option buttons */
    .mcq-opt { font-size: 1.05rem; padding: 16px 22px; }
    /* Larger fill-in input and submit */
    .fill-input { font-size: 1.1rem; padding: 15px 18px; }
    .btn-submit { font-size: 1.05rem; padding: 15px 28px; }
    /* Larger matching items */
    .match-item { font-size: 1rem; padding: 14px 18px; }
    /* Larger next/play-again buttons */
    .btn-next, .btn-play-again { font-size: 1.1rem; padding: 17px; }
    /* Larger results vocab list */
    .vocab-item .vi-word { font-size: 1rem; }
    .vocab-item .vi-def  { font-size: 0.97rem; }
    .vocab-list { max-height: 420px; }
  }


/* ===== FLASHCARD SCREEN ===== */

/* Two-button action row on title screen */
.btn-action-row {
  display: flex;
  gap: 12px;
  width: 100%; max-width: 660px;
  margin-top: 8px;
  padding: 0 0 8px;
}
.btn-revision {
  flex: 1;
  padding: 18px 12px;
  border-radius: 16px;
  border: 2px solid var(--primary);
  background: transparent;
  color: var(--primary-light);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.03em;
  transition: background 0.18s, color 0.18s;
  -webkit-tap-highlight-color: transparent;
  font-family: inherit;
}
.btn-revision:not(:disabled):active { background: rgba(124,58,237,0.15); }
.btn-revision:disabled { opacity: 0.35; cursor: default; }
.btn-action-row .btn-start { flex: 1.4; width: auto; max-width: none; margin-top: 0; }

/* Flashcard screen layout */
#screen-flashcard { padding: 0 0 36px; }

/* Flashcard topbar */
.fc-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px 10px;
  width: 100%;
  background: var(--bg);
  border-bottom: 1px solid rgba(255,255,255,0.06);
  position: sticky;
  top: 0;
  z-index: 10;
}
.fc-btn-back, .fc-btn-shuffle {
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.12);
  color: var(--text-muted);
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, color 0.15s;
  font-family: inherit;
}
.fc-btn-back:active, .fc-btn-shuffle:active {
  background: rgba(255,255,255,0.14);
  color: #fff;
}
@media (hover: hover) {
  .fc-btn-back:hover, .fc-btn-shuffle:hover { background: rgba(255,255,255,0.12); color: #fff; }
  .fc-nav-btn:hover:not(:disabled) { background: rgba(255,255,255,0.12); color: #fff; }
  .btn-revision:hover:not(:disabled) { background: rgba(91,76,237,0.15); color: #fff; }
}
.fc-counter {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.04em;
}

/* Flashcard area */
.fc-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 28px 20px 20px;
  width: 100%;
}

/* 3D flip card container */
.fc-card {
  width: 100%;
  max-width: 480px;
  min-height: 280px;          /* prevents collapse when faces are position:absolute */
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  margin-bottom: 24px;
  perspective: 1000px;
  user-select: none;          /* prevent text selection on swipe */
  -webkit-user-select: none;
}
.fc-card-inner {
  width: 100%;
  min-height: 280px;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.45s cubic-bezier(0.4, 0.2, 0.2, 1);
}
.fc-card.flipped .fc-card-inner {
  transform: rotateY(180deg);
}
.fc-face {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  min-height: 280px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: 20px;
  padding: 28px 24px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
}
.fc-front {
  background: linear-gradient(145deg, #1e2140 0%, #252847 100%);
  border: 1px solid rgba(124,58,237,0.35);
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}
.fc-back {
  background: linear-gradient(145deg, #162030 0%, #1a2a3a 100%);
  border: 1px solid rgba(6,182,212,0.35);
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  transform: rotateY(180deg);
}

/* Card content */
.fc-unit-badge {
  position: absolute;
  top: 14px;
  right: 16px;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  padding: 3px 9px;
  border-radius: 20px;
  text-transform: uppercase;
}
.fc-unit-badge.unit-5 { background: rgba(196,181,253,0.18); color: #c4b5fd; border: 1px solid rgba(196,181,253,0.4); }
.fc-unit-badge.unit-6 { background: rgba(103,232,249,0.15); color: #67e8f9; border: 1px solid rgba(103,232,249,0.4); }
.fc-unit-badge.unit-8 { background: rgba(252,211,77,0.15);  color: #fcd34d; border: 1px solid rgba(252,211,77,0.4);  }

.fc-pos {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-style: italic;
  margin-bottom: 10px;
  letter-spacing: 0.04em;
  align-self: flex-start;
  margin-top: 8px;
}
.fc-item {
  font-size: clamp(1.5rem, 6vw, 2.2rem);
  font-weight: 800;
  color: #fff;
  text-align: center;
  line-height: 1.3;
  margin-bottom: 18px;
  word-break: break-word;
  hyphens: auto;
}
.fc-tap-hint {
  font-size: 0.78rem;
  color: rgba(255,255,255,0.28);
  letter-spacing: 0.04em;
  margin-top: 16px;
}
.fc-item-reminder {
  font-size: 0.95rem;
  font-weight: 700;
  color: rgba(255,255,255,0.45);
  text-align: center;
  margin-bottom: 14px;
  font-style: italic;
}
.fc-def {
  font-size: clamp(1.25rem, 5vw, 1.65rem);
  color: #e2e8f0;
  text-align: center;
  line-height: 1.55;
  font-weight: 500;
  word-break: break-word;
}
.fc-sentence {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid rgba(255,255,255,0.1);
  font-size: clamp(0.82rem, 3vw, 0.95rem);
  color: rgba(255,255,255,0.55);
  text-align: center;
  line-height: 1.6;
  font-style: italic;
  word-break: break-word;
}
.fc-sentence strong {
  font-style: normal;
  font-weight: 700;
  color: #fcd34d;
}

/* Nav buttons below card */
.fc-nav {
  display: flex;
  gap: 16px;
  width: 100%;
  max-width: 480px;
}
.fc-nav-btn {
  flex: 1;
  padding: 15px;
  border-radius: 14px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  color: var(--text-muted);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, color 0.15s;
  font-family: inherit;
}
.fc-nav-btn:not(:disabled):active {
  background: rgba(255,255,255,0.13);
  color: #fff;
}
.fc-nav-btn:disabled { opacity: 0.25; cursor: default; }

/* ===== RESPONSIVE: TABLET & DESKTOP ===== */
@media (min-width: 640px) {
  /* Wider card on tablet/desktop */
  .fc-area { padding: 36px 32px 28px; }
  .fc-card,
  .fc-nav { max-width: 700px; }
  .fc-card { min-height: 360px; }
  .fc-card-inner { min-height: 360px; }
  .fc-face { min-height: 360px; padding: 36px 40px 32px; }
  .fc-item { font-size: clamp(2rem, 4vw, 2.8rem); }
  .fc-def  { font-size: clamp(1.5rem, 3.5vw, 2rem); }
  .fc-sentence { font-size: clamp(0.95rem, 2vw, 1.1rem); }
  .fc-item-reminder { font-size: 1.1rem; }
  .fc-topbar { padding: 14px 32px 12px; }
  .fc-btn-back, .fc-btn-shuffle { font-size: 0.95rem; padding: 10px 20px; }
  .fc-counter { font-size: 1rem; }
  .fc-nav-btn { padding: 18px; font-size: 1.1rem; }
}

@media (min-width: 1024px) {
  /* Even wider on desktop — cap at a comfortable reading width */
  .fc-card,
  .fc-nav { max-width: 860px; }
  .fc-card { min-height: 420px; }
  .fc-card-inner { min-height: 420px; }
  .fc-face { min-height: 420px; padding: 44px 56px 40px; }
  .fc-area { padding: 44px 48px 36px; }
}

/* Slide transition for card swipe */
@keyframes fcSlideInRight {
  from { opacity: 0; transform: translateX(60px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes fcSlideInLeft {
  from { opacity: 0; transform: translateX(-60px); }
  to   { opacity: 1; transform: translateX(0); }
}
.fc-slide-right .fc-card-inner { animation: fcSlideInRight 0.28s ease; }
.fc-slide-left  .fc-card-inner { animation: fcSlideInLeft  0.28s ease; }

/* ===== ANAGRAM QUESTION ===== */

/* Badge colour — amber/orange to distinguish from other types */
.badge-anagram {
  background: rgba(245,158,11,0.18);
  color: #fbbf24;
  border: 1px solid rgba(245,158,11,0.35);
}

/* Prompt (definition) — slightly larger, centred */
.anagram-prompt {
  text-align: center;
  font-size: 1.25rem;
  line-height: 1.7;
  margin-bottom: 18px;
}

/* ── Answer field ── */
.anagram-answer {
  display: flex;
  flex-wrap: nowrap;
  justify-content: center;
  align-items: center;
  gap: clamp(3px, 1.2vw, 6px);
  min-height: 64px;
  padding: 10px 12px;
  border-radius: 14px;
  border: 2px dashed var(--border);
  background: rgba(255,255,255,0.03);
  margin-bottom: 14px;
  transition: border-color 0.18s;
}
.anagram-answer:not(:empty) {
  border-style: solid;
  border-color: var(--primary-light);
}

/* ── Rack ── */
/* Rack wraps onto a second row when tiles don't fit — keeps tiles large enough to tap */
.anagram-rack {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: clamp(4px, 1.5vw, 8px);
  padding: 10px 8px;
  min-height: 60px;
  margin-bottom: 18px;
}

/* ── Scrabble-style tile ── */
.anagram-tile {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  border-radius: 8px;
  background: linear-gradient(160deg, #f5e6c8 0%, #e8d5a3 100%);
  color: #2d1a00;
  font-weight: 900;
  letter-spacing: 0.02em;
  border: 2px solid #c8a96e;
  box-shadow: 0 3px 0 #9a7a40, 0 4px 8px rgba(0,0,0,0.35);
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.12s, box-shadow 0.12s, background 0.15s;
  position: relative;
}
.anagram-tile:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #9a7a40, 0 2px 4px rgba(0,0,0,0.3);
}

/* Font size tiers — controlled by JS class */
/* md: ≤8 letters — clamp so tiles don't overflow on narrow mobile screens */
.anagram-tile-font-md { font-size: clamp(1rem, 4vw, 1.5rem); width: clamp(36px, 11vw, 46px); height: clamp(40px, 12.5vw, 52px); }
/* sm: 9–11 letters — comfortable tap size; rack wraps to 2 rows if needed */
.anagram-tile-font-sm { font-size: clamp(0.9rem, 3.5vw, 1.3rem); width: clamp(36px, 10vw, 44px); height: clamp(40px, 11vw, 50px); }
/* xs: 12–13 letters — larger tiles; rack wraps to 2 rows */
.anagram-tile-font-xs { font-size: clamp(1rem, 4vw, 1.4rem);     width: clamp(36px, 11vw, 46px);  height: clamp(40px, 12vw, 52px);  border-radius: 7px; }
/* xxs: ≥14 letters — rack uses same size as xs (wraps to 2 rows); answer field gets its own smaller override */
.anagram-tile-font-xxs { font-size: clamp(1rem, 4vw, 1.4rem);    width: clamp(36px, 11vw, 46px);  height: clamp(40px, 12vw, 52px);  border-radius: 7px; }

/* ── Answer-field tile overrides (placed tiles don't need to be tapped — shrink aggressively) ── */
/* The answer field stays flex-wrap:nowrap so the word always reads on one line.                  */
.anagram-answer .anagram-tile.placed.anagram-tile-font-sm {
  width: clamp(22px, 6.5vw, 32px); height: clamp(26px, 7.5vw, 38px);
  font-size: clamp(0.6rem, 2.2vw, 0.95rem); padding: 0;
}
.anagram-answer .anagram-tile.placed.anagram-tile-font-xs {
  width: clamp(18px, 5.5vw, 28px); height: clamp(22px, 6.5vw, 34px);
  font-size: clamp(0.5rem, 1.8vw, 0.85rem); padding: 0; border-radius: 4px;
}
/* xxs: ≥14 letters — answer field only; rack still wraps at xs size */
.anagram-answer .anagram-tile.placed.anagram-tile-font-xxs {
  width: clamp(14px, 4.2vw, 22px); height: clamp(18px, 5.5vw, 28px);
  font-size: clamp(0.4rem, 1.4vw, 0.7rem); padding: 0; border-radius: 3px;
  border-width: 1px; box-shadow: 0 2px 0 #2563eb, 0 2px 4px rgba(37,99,235,0.2);
}
/* Reduce answer container padding for xxs words so tiles have maximum width */
.anagram-answer:has(.anagram-tile-font-xxs) {
  padding: 6px 6px;
  gap: clamp(2px, 0.8vw, 4px);
}

/* Tile in the answer field */
.anagram-tile.placed {
  background: linear-gradient(160deg, #dbeafe 0%, #bfdbfe 100%);
  border-color: #60a5fa;
  box-shadow: 0 3px 0 #2563eb, 0 4px 8px rgba(37,99,235,0.25);
  color: #1e3a5f;
}

/* Correct answer feedback */
.anagram-tile.tile-correct {
  background: linear-gradient(160deg, #d1fae5 0%, #a7f3d0 100%);
  border-color: var(--success);
  box-shadow: 0 3px 0 #059669, 0 4px 8px rgba(16,185,129,0.3);
  color: #064e3b;
}

/* Wrong answer feedback */
.anagram-tile.tile-wrong {
  background: linear-gradient(160deg, #fee2e2 0%, #fecaca 100%);
  border-color: var(--danger);
  box-shadow: 0 3px 0 #b91c1c, 0 4px 8px rgba(239,68,68,0.3);
  color: #7f1d1d;
}

/* Give-up tiles (spelled out automatically) */
.anagram-tile.tile-giveup {
  background: linear-gradient(160deg, #fef3c7 0%, #fde68a 100%);
  border-color: var(--accent);
  box-shadow: 0 3px 0 #b45309, 0 4px 8px rgba(245,158,11,0.3);
  color: #451a03;
  animation: tileDropIn 0.22s ease both;
}
@keyframes tileDropIn {
  from { opacity: 0; transform: translateY(-18px) scale(0.8); }
  to   { opacity: 1; transform: translateY(0)    scale(1);   }
}

/* ── Button row ── */
.anagram-btns {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-bottom: 6px;
  flex-wrap: wrap;
}

/* Give Up button — secondary style */
.btn-giveup {
  padding: 13px 24px;
  border-radius: 12px;
  border: 2px solid rgba(239,68,68,0.4);
  background: rgba(239,68,68,0.1);
  color: #fca5a5;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.18s, transform 0.15s;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
}
.btn-giveup:hover:not(:disabled) { opacity: 0.85; transform: translateY(-1px); }
.btn-giveup:disabled { opacity: 0.35; cursor: default; }

/* ── Desktop enhancements ── */
@media (min-width: 1024px) {
  .anagram-prompt { font-size: 1.55rem; }
  .anagram-tile-font-md { font-size: 1.6rem; width: 54px; height: 60px; }
  .anagram-tile-font-sm { font-size: 1.3rem; width: 48px; height: 54px; }
  .anagram-tile-font-xs { font-size: 1.1rem; width: 42px; height: 48px; }
  .anagram-answer { min-height: 76px; gap: 8px; }
  .anagram-rack   { gap: 9px; flex-wrap: nowrap; } /* desktop has enough width — no wrapping needed */
  .btn-giveup { font-size: 1.05rem; padding: 15px 28px; }
  /* On desktop, placed tiles in answer field can be larger since viewport is wide */
  .anagram-answer .anagram-tile.placed.anagram-tile-font-sm { width: 38px; height: 44px; font-size: 1.1rem; padding: 0; }
  .anagram-answer .anagram-tile.placed.anagram-tile-font-xs { width: 32px; height: 38px; font-size: 0.95rem; padding: 0; }
  .anagram-answer .anagram-tile.placed.anagram-tile-font-xxs { width: 28px; height: 34px; font-size: 0.85rem; padding: 0; }
}

/* Correct-answer reveal row (shown below wrong tiles on wrong submission) */
.anagram-correct-row {
  display: flex;
  flex-wrap: nowrap;          /* never wrap onto a second line */
  justify-content: center;
  align-items: center;
  gap: 4px;
  margin-top: 10px;
  width: 100%;
  overflow: visible;          /* allow tile shadows/borders to show fully */
  padding-bottom: 4px;         /* prevent bottom border/shadow clipping */
}
/* Reveal tiles shrink to fit available width automatically */
.anagram-correct-row .anagram-tile {
  flex-shrink: 1;             /* allow tiles to shrink */
  min-width: 0;               /* allow shrinking below intrinsic width */
  width: clamp(24px, calc((100% - 4px * 14) / 15), 46px);
  height: clamp(28px, 8vw, 52px);
  font-size: clamp(0.7rem, 2.8vw, 1.5rem);
  padding: 0;
  border-radius: 6px;
}
/* Prevent pointer events on reveal tiles — they are display-only */
.tile-answer-reveal {
  cursor: default;
  pointer-events: none;
  animation: tileDropIn 0.22s ease both;
}
@media (min-width: 1024px) {
  .anagram-correct-row { gap: 6px; margin-top: 12px; }
  .anagram-correct-row .anagram-tile {
    width: clamp(28px, calc((100% - 6px * 14) / 15), 54px);
    height: clamp(32px, 5vw, 60px);
    font-size: clamp(0.8rem, 1.8vw, 1.6rem);
  }
}
