:root {
    --purple: #7C5CBF;
    --purple-light: #EDE8FF;
    --green: #2ECC71;
    --green-light: #E8FAF0;
    --red: #E74C3C;
    --red-light: #FDE8E6;
    --yellow: #F1C40F;
    --yellow-light: #FFFBE6;
    --orange: #FF8C42;
    --bg: #F5F3FF;
    --card: #FFFFFF;
    --text: #2D2D2D;
    --muted: #888;
    --radius: 20px;
    --shadow: 0 4px 20px rgba(124,92,191,0.12);
  }
  * { box-sizing: border-box; margin: 0; padding: 0; }
  body {
    font-family: 'Nunito', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    padding-bottom: calc(96px + env(safe-area-inset-bottom));
  }
  header {
    background: var(--purple);
    color: white;
    text-align: center;
    padding: 12px 16px 10px;
    position: sticky; top: 0; z-index: 100;
    box-shadow: 0 2px 12px rgba(124,92,191,0.3);
  }
  header h1 { font-size: 22px; font-weight: 900; letter-spacing: -0.5px; }
  header p { font-size: 12px; opacity: 0.85; margin-top: 2px; }

  .tab-bar {
    display: flex; background: white; border-bottom: 2px solid var(--purple-light);
    position: sticky; top: 58px; z-index: 99; overflow-x: auto;
  }
  .tab-btn {
    flex: 1; padding: 14px 4px; text-align: center; font-family: 'Nunito', sans-serif;
    font-size: 14px; font-weight: 700; border: none; background: none;
    color: var(--muted); cursor: pointer; transition: all 0.2s; border-bottom: 3px solid transparent;
    margin-bottom: -2px;
  }
  .tab-btn.active { color: var(--purple); border-bottom-color: var(--purple); }
  .tab-btn span { display: block; font-size: 20px; margin-bottom: 2px; }

  .cat-scroll {
    display: flex; gap: 8px; overflow-x: auto; padding: 10px 16px;
    scrollbar-width: none; background: white; border-bottom: 1px solid #EEE;
    position: sticky; top: 110px; z-index: 98;
  }
  .cat-scroll::-webkit-scrollbar { display: none; }
  .cat-btn {
    flex-shrink: 0; padding: 6px 14px; border-radius: 20px; font-family: 'Nunito', sans-serif;
    font-size: 13px; font-weight: 700; border: 2px solid #DDD; background: white;
    color: var(--muted); cursor: pointer; transition: all 0.18s; white-space: nowrap;
  }
  .cat-btn.active { background: var(--purple); color: white; border-color: var(--purple); }

  .content { padding: 16px; max-width: 600px; margin: 0 auto; }

  /* FLASHCARD */
  .fc-wrap { display: flex; flex-direction: column; align-items: center; gap: 20px; }
  .flashcard {
    width: 100%; background: white; border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 30px 24px; text-align: center;
    cursor: pointer; transition: transform 0.15s; min-height: 220px;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
    border: 3px solid var(--purple-light); position: relative;
  }
  .flashcard:active { transform: scale(0.97); }
  .card-emoji { font-size: 72px; line-height: 1; }
  .card-english { font-size: 26px; font-weight: 800; color: var(--text); }
  .card-romanian { font-size: 30px; font-weight: 900; color: var(--purple); margin-top: 8px; }
  .card-hint { font-size: 12px; color: var(--muted); position: absolute; bottom: 14px; font-weight: 600; }
  .fc-nav { display: flex; gap: 12px; align-items: center; width: 100%; }
  .nav-btn {
    flex: 1; padding: 14px; border-radius: 14px; border: none; font-family: 'Nunito', sans-serif;
    font-size: 15px; font-weight: 800; cursor: pointer; transition: all 0.15s;
    background: var(--purple); color: white;
  }
  .nav-btn:active { transform: scale(0.97); }
  .fc-counter { font-size: 14px; font-weight: 700; color: var(--muted); min-width: 60px; text-align: center; }

  /* QUIZ */
  .quiz-wrap { display: flex; flex-direction: column; gap: 16px; }
  .quiz-score-row { display: flex; gap: 10px; }
  .score-pill {
    flex: 1; padding: 10px; border-radius: 14px; text-align: center; font-weight: 800;
  }
  .score-pill.correct { background: var(--green-light); color: #1a8a4a; }
  .score-pill.wrong { background: var(--red-light); color: #b02020; }
  .score-pill.left { background: var(--purple-light); color: var(--purple); }
  .score-pill .val { font-size: 22px; display: block; }
  .score-pill .lbl { font-size: 11px; }
  .quiz-card {
    background: white; border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 28px 20px; text-align: center; border: 3px solid var(--purple-light);
  }
  .quiz-emoji { font-size: 60px; margin-bottom: 8px; }
  .quiz-prompt { font-size: 13px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; }
  .quiz-word { font-size: 28px; font-weight: 900; margin-top: 4px; color: var(--text); }
  .quiz-opts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 20px; }
  .quiz-opt {
    padding: 14px 8px; border-radius: 14px; border: 2.5px solid #DDD; background: white;
    font-family: 'Nunito', sans-serif; font-size: 16px; font-weight: 700; cursor: pointer;
    transition: all 0.15s; color: var(--text);
  }
  .quiz-opt:active:not(.disabled) { transform: scale(0.97); }
  .quiz-opt.correct { background: var(--green-light); border-color: var(--green); color: #1a8a4a; }
  .quiz-opt.wrong { background: var(--red-light); border-color: var(--red); color: #b02020; }
  .quiz-opt.disabled { cursor: default; }
  .quiz-feedback { margin-top: 14px; font-size: 16px; font-weight: 800; min-height: 26px; }
  .next-btn {
    width: 100%; padding: 15px; border-radius: 14px; border: none; background: var(--purple);
    color: white; font-family: 'Nunito', sans-serif; font-size: 16px; font-weight: 800;
    cursor: pointer; margin-top: 12px; display: none; transition: all 0.15s;
  }
  .next-btn.show { display: block; }
  .next-btn:active { transform: scale(0.98); }
  .done-card {
    background: white; border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 40px 24px; text-align: center; border: 3px solid var(--purple-light);
  }
  .done-card h2 { font-size: 22px; font-weight: 900; margin: 12px 0 8px; }
  .done-card p { color: var(--muted); font-weight: 700; font-size: 15px; margin-bottom: 20px; }

  /* MATCH */
  .match-wrap {}
  .match-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
  .match-header span { font-size: 15px; font-weight: 800; color: var(--purple); }
  .new-game-btn {
    padding: 8px 16px; border-radius: 12px; border: 2px solid var(--purple); background: white;
    color: var(--purple); font-family: 'Nunito', sans-serif; font-size: 13px; font-weight: 800; cursor: pointer;
  }
  .match-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  .match-col { display: flex; flex-direction: column; gap: 8px; }
  .match-item {
    padding: 12px 8px; border-radius: 14px; border: 2.5px solid #DDD; background: white;
    font-family: 'Nunito', sans-serif; font-size: 14px; font-weight: 700; cursor: pointer;
    transition: all 0.15s; text-align: center; color: var(--text); min-height: 52px;
    display: flex; align-items: center; justify-content: center; gap: 4px;
  }
  .match-item.selected { border-color: var(--purple); background: var(--purple-light); color: var(--purple); }
  .match-item.matched { background: var(--green-light); border-color: var(--green); color: #1a8a4a; cursor: default; }
  .match-item.wrong { background: var(--red-light); border-color: var(--red); }
  .match-done {
    margin-top: 16px; background: var(--green-light); border-radius: var(--radius);
    padding: 24px; text-align: center; display: none;
  }
  .match-done h3 { font-size: 20px; font-weight: 900; color: #1a8a4a; }

  .hidden { display: none !important; }

  /* SPEAK BUTTON */
  .speak-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 10px 20px; border-radius: 30px; border: 2.5px solid var(--purple);
    background: white; color: var(--purple); font-family: 'Nunito', sans-serif;
    font-size: 15px; font-weight: 800; cursor: pointer; transition: all 0.15s;
    margin-top: 4px;
  }
  .speak-btn:active { transform: scale(0.96); background: var(--purple-light); }
  .speak-btn.speaking { background: var(--purple); color: white; }
  .speak-btn svg { width: 18px; height: 18px; flex-shrink: 0; }

  .quiz-speak { margin-top: 10px; }

  .no-tts-banner {
    background: var(--yellow-light); border: 2px solid var(--yellow); border-radius: 14px;
    padding: 10px 14px; font-size: 13px; font-weight: 700; color: #7a6000;
    margin-bottom: 12px; text-align: center; display: none;
  }


  /* ENGAGEMENT ADD-ONS */
  .tab-bar { overflow-x: auto; scrollbar-width: none; }
  .tab-bar::-webkit-scrollbar { display:none; }
  .tab-btn { min-width: 92px; }
  .dashboard { max-width: 600px; margin: 12px auto 0; padding: 0 16px; }
  .dash-card { background: white; border-radius: var(--radius); box-shadow: var(--shadow); border: 2px solid var(--purple-light); padding: 14px; }
  .player-row { display:flex; align-items:center; gap:10px; justify-content:space-between; flex-wrap:wrap; }
  .mascot { font-size: 42px; background: var(--purple-light); border-radius: 18px; padding: 8px 10px; transition: transform .2s; }
  .mascot.happy { transform: rotate(-6deg) scale(1.08); }
  .player-name { font-weight:900; color: var(--purple); font-size: 15px; }
  .small-input, .small-select { border:2px solid #DDD; border-radius: 12px; padding: 8px 10px; font-family:'Nunito', sans-serif; font-weight:800; background:white; }
  .stat-row { display:grid; grid-template-columns: repeat(4, 1fr); gap:8px; margin-top:12px; }
  .mini-stat { background: var(--purple-light); color: var(--purple); border-radius: 14px; padding: 8px 4px; text-align:center; font-weight:900; font-size:13px; }
  .mini-stat span { display:block; font-size:18px; }
  .progress-wrap { margin-top:12px; }
  .progress-label { display:flex; justify-content:space-between; font-size:12px; font-weight:900; color:var(--muted); margin-bottom:5px; }
  .progress-track { height: 12px; background:#eee; border-radius: 999px; overflow:hidden; }
  .progress-fill { height:100%; background: linear-gradient(90deg, var(--green), var(--yellow)); width:0%; transition: width .35s; }
  .badge-row { display:flex; flex-wrap:wrap; gap:6px; margin-top:10px; }
  .badge { background: var(--yellow-light); border: 2px solid var(--yellow); color:#7a6000; padding:5px 8px; border-radius:999px; font-size:11px; font-weight:900; }
  .message-bubble { margin-top:10px; background: var(--green-light); color:#1a8a4a; border-radius:14px; padding:8px 10px; font-size:13px; font-weight:900; text-align:center; }
  .confetti-piece { position: fixed; top: -10px; width: 10px; height: 10px; pointer-events:none; z-index:9999; animation: fall 900ms ease-out forwards; }
  @keyframes fall { to { transform: translateY(105vh) rotate(540deg); opacity:0; } }
  .typing-card, .report-card, .diary-card { background:white; border-radius:var(--radius); box-shadow:var(--shadow); border:3px solid var(--purple-light); padding:22px; text-align:center; }
  .answer-input { width:100%; max-width:360px; border:3px solid var(--purple-light); border-radius:16px; padding:14px; font-family:'Nunito', sans-serif; font-size:22px; font-weight:900; text-align:center; margin:14px auto 8px; display:block; color:var(--text); }
  .mode-actions { display:flex; gap:10px; justify-content:center; flex-wrap:wrap; margin-top:12px; }
  .chip-grid { display:flex; gap:8px; justify-content:center; flex-wrap:wrap; margin:16px 0; }
  .word-chip { border:2.5px solid var(--purple); background:white; color:var(--purple); border-radius:14px; padding:10px 14px; font-family:'Nunito', sans-serif; font-weight:900; cursor:pointer; }
  .word-chip.used { opacity:.35; pointer-events:none; }
  .leader-table { width:100%; border-collapse:separate; border-spacing:0 8px; text-align:left; }
  .leader-table td, .leader-table th { padding:8px; font-size:14px; }
  .leader-table tr { background:var(--purple-light); border-radius:12px; }
  .diary-grid { display:grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap:8px; text-align:left; margin-top:12px; max-height:360px; overflow:auto; }
  .diary-word { background:var(--green-light); border-radius:12px; padding:8px; font-weight:800; font-size:13px; display: flex; flex-direction: column; align-items: flex-start; display: flex; align-items: center; justify-content: center; gap: 6px; flex-wrap: wrap; text-align: center;}
  .diary-word strong { color: #111827; font-weight: 900; }
  .diary-word small { color: #5f5874; font-weight: 800; font-size: 13px; }
  .diary-separator { color: #7c5bd6; font-weight: 900; margin: 0 2px; }
  
  .timer-big { font-size:44px; font-weight:900; color:var(--orange); }


  .dashboard { max-width: 600px; margin: 8px auto 0; padding: 0 16px; }
  .dash-shell { display:flex; flex-direction:column; gap:12px; }
  .dash-summary { display:flex; align-items:center; justify-content:space-between; gap:10px; flex-wrap:wrap; }
  .summary-stats { display:flex; gap:6px; flex-wrap:wrap; justify-content:flex-end; }
  .summary-pill {
    background: var(--purple-light); color: var(--purple); border-radius: 999px;
    padding: 7px 10px; font-size:12px; font-weight:900;
  }
  .dash-toggle {
    border:2px solid var(--purple-light); background:white; color:var(--purple); border-radius:12px;
    padding:8px 12px; font-family:'Nunito', sans-serif; font-weight:900; cursor:pointer;
  }
  .dash-main { display:flex; flex-direction:column; gap:10px; }
  .dash-main.hidden { display:none; }
  .compact-progress { font-size:12px; font-weight:800; color:#888; }

  .fc-wrap, .quiz-wrap, .match-wrap, .typing-card, .done-card { padding-bottom: 92px; }
  .fc-nav, .mode-actions {
    position: sticky;
    bottom: calc(10px + env(safe-area-inset-bottom));
    z-index: 30;
    background: rgba(245,243,255,0.96);
    backdrop-filter: blur(8px);
    border: 1px solid #e5ddff;
    border-radius: 18px;
    box-shadow: 0 8px 24px rgba(124,92,191,0.14);
    padding: 10px;
  }
  .fc-nav { margin-top: 6px; }
  .next-btn.show {
    position: sticky;
    bottom: calc(10px + env(safe-area-inset-bottom));
    z-index: 30;
    box-shadow: 0 8px 24px rgba(124,92,191,0.18);
  }
  @media (max-width: 640px) {
    .dashboard { padding: 0 12px; }
    .content { padding: 12px; }
    .player-row { flex-direction: column; align-items: stretch; }
    .stat-row { grid-template-columns: repeat(2, 1fr); }
    .tab-btn { min-width: 88px; }
    .summary-stats { width: 100%; justify-content: flex-start; }
    .dash-toggle { width: 100%; }
  }

/* =========================================================
   Responsive refinements
   ========================================================= */

/* Desktop/tablet: give the game room without becoming too wide */
@media (min-width: 900px) {
  .content,
  .dashboard {
    max-width: 760px;
  }

  .flashcard {
    min-height: 280px;
  }

  .quiz-card,
  .done-card,
  .typing-card {
    padding: 36px 28px;
  }

  .match-grid {
    gap: 16px;
  }
}

/* Tablet */
@media (max-width: 899px) {
  header h1 {
    font-size: 22px;
  }

  .content,
  .dashboard {
    max-width: 680px;
  }

  .tab-btn {
    min-width: 96px;
  }

  .quiz-opts {
    grid-template-columns: 1fr 1fr;
  }
}

/* Phone */
@media (max-width: 600px) {
  body {
    padding-bottom: calc(110px + env(safe-area-inset-bottom));
  }

  header {
    padding: 10px 12px 8px;
  }

  header h1 {
    font-size: 20px;
  }

  header p {
    font-size: 11px;
  }

  .tab-bar {
    overflow-x: auto;
    scrollbar-width: none;
  }

  .tab-bar::-webkit-scrollbar {
    display: none;
  }

  .tab-btn {
    flex: 0 0 auto;
    min-width: 88px;
    padding: 10px 8px;
    font-size: 12px;
  }

  .tab-btn span {
    font-size: 18px;
  }

  .cat-scroll {
    padding: 8px 12px;
  }

  .cat-btn {
    padding: 6px 12px;
    font-size: 12px;
  }

  .dashboard {
    padding: 0 12px;
  }

  .content {
    padding: 12px;
  }

  .dash-summary {
    align-items: stretch;
  }

  .summary-stats {
    width: 100%;
    justify-content: flex-start;
  }

  .summary-pill {
    font-size: 11px;
    padding: 6px 9px;
  }

  .dash-toggle {
    width: 100%;
  }

  .player-row {
    flex-direction: column;
    align-items: stretch;
  }

  .stat-row {
    grid-template-columns: repeat(2, 1fr);
  }

  .flashcard {
    min-height: 230px;
    padding: 28px 18px;
  }

  .card-emoji {
    font-size: 62px;
  }

  .card-english {
    font-size: 24px;
  }

  .card-romanian {
    font-size: 28px;
  }

  .fc-nav {
    gap: 8px;
  }

  .nav-btn {
    padding: 13px 10px;
    font-size: 14px;
  }

  .fc-counter {
    min-width: 52px;
    font-size: 13px;
  }

  .quiz-score-row {
    flex-direction: column;
  }

  .quiz-opts {
    grid-template-columns: 1fr;
  }

  .quiz-word {
    font-size: 25px;
  }

  .match-grid {
    gap: 8px;
  }

  .match-item {
    font-size: 13px;
    min-height: 48px;
  }

  .mode-actions {
    flex-direction: column;
  }

  .mode-actions .nav-btn {
    width: 100%;
  }

  .answer-input {
    font-size: 18px;
  }

  .diary-grid {
    grid-template-columns: 1fr;
  }
}

/* Very small phones */
@media (max-width: 380px) {
  .card-emoji {
    font-size: 54px;
  }

  .card-english {
    font-size: 21px;
  }

  .card-romanian {
    font-size: 24px;
  }

  .nav-btn {
    font-size: 13px;
    padding: 12px 8px;
  }

  .fc-counter {
    font-size: 12px;
    min-width: 46px;
  }

  .quiz-word {
    font-size: 22px;
  }
}

/* =========================================================
   Fire tablet / small desktop refinements
   ========================================================= */

@media (max-width: 760px) {
  body {
    padding-bottom: calc(104px + env(safe-area-inset-bottom));
  }

  header {
    padding: 8px 12px 7px;
  }

  header h1 {
    font-size: 20px;
    line-height: 1.1;
  }

  header p {
    font-size: 11px;
  }

  .tab-bar {
    top: 48px;
  }

  .tab-btn {
    min-width: 82px;
    padding: 8px 6px;
    font-size: 12px;
  }

  .tab-btn span {
    font-size: 17px;
    margin-bottom: 1px;
  }

  .cat-scroll {
    top: 96px;
    padding: 7px 10px;
  }

  .cat-btn {
    font-size: 12px;
    padding: 5px 11px;
  }

  .dashboard {
    margin-top: 6px;
    padding: 0 12px;
  }

  .dash-card {
    padding: 9px 10px;
    border-radius: 16px;
  }

  .dash-summary {
    gap: 7px;
  }

  .mascot {
    font-size: 30px;
    border-radius: 13px;
    padding: 5px 7px;
  }

  .summary-stats {
    display: none;
  }

  .compact-progress {
    font-size: 11px;
  }

  .dash-toggle {
    padding: 7px 10px;
    font-size: 12px;
  }

  .content {
    padding: 10px 12px;
  }

  .fc-wrap {
    gap: 12px;
  }

  .compact-tts {
    margin-bottom: 0;
    padding: 7px 10px;
    font-size: 12px;
  }

  .flashcard {
    min-height: 210px;
    padding: 22px 18px;
    border-radius: 18px;
  }

  .card-emoji {
    font-size: 58px;
  }

  .card-english {
    font-size: 24px;
  }

  .card-romanian {
    font-size: 27px;
  }

  .card-hint {
    bottom: 10px;
  }

  .fc-nav {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom));
    max-width: 736px;
    margin: 0 auto;
  }

  .nav-btn {
    padding: 12px 10px;
  }
}

@media (min-width: 1100px) {
  .content,
  .dashboard {
    max-width: 820px;
  }

  .flashcard {
    min-height: 300px;
  }
}

/* =========================================================
   v3: Small-device playable-area focus
   ========================================================= */

@media (max-width: 760px) {
  body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
  }

  .content {
    flex: 1;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding-top: 8px;
    padding-bottom: 118px;
  }

  #content > * {
    width: 100%;
  }

  .fc-wrap,
  .quiz-wrap,
  .match-wrap,
  .typing-card,
  .done-card {
    width: 100%;
    max-width: 620px;
    margin-left: auto;
    margin-right: auto;
  }

  .flashcard {
    width: 100%;
    margin-left: auto;
    margin-right: auto;
  }

  .quiz-card,
  .typing-card,
  .done-card {
    margin-left: auto;
    margin-right: auto;
  }

  .match-grid {
    align-items: stretch;
  }

  .match-col {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .match-item {
    width: 100%;
    min-height: 54px;
    padding: 12px 8px;
    font-size: 14px;
    line-height: 1.15;
    border-radius: 16px;
  }
}

@media (max-width: 600px) {
  .content {
    min-height: calc(100vh - 245px);
  }

  .flashcard {
    min-height: 245px;
  }

  .match-item {
    min-height: 52px;
    font-size: 13.5px;
  }
}

@media (max-width: 420px) {
  .content {
    align-items: flex-start;
  }

  .match-grid {
    grid-template-columns: 1fr 1fr;
    gap: 7px;
  }

  .match-item {
    min-height: 50px;
    font-size: 12.8px;
    padding: 10px 6px;
  }
}

/* =========================================================
   v4: Mobile quiz/speed/daily layout improvements
   ========================================================= */

@media (max-width: 760px) {
  .quiz-wrap {
    max-width: 620px;
  }

  .quiz-score-row {
    display: flex;
    flex-direction: row;
    gap: 8px;
    width: 100%;
  }

  .score-pill {
    flex: 1 1 0;
    min-width: 0;
    padding: 8px 5px;
  }

  .score-pill .val {
    font-size: 20px;
    line-height: 1.05;
  }

  .score-pill .lbl {
    font-size: 10px;
    white-space: nowrap;
  }

  .quiz-card {
    width: 100%;
  }

  .quiz-opts {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .quiz-opt {
    min-height: 58px;
    padding: 12px 8px;
    font-size: 15px;
    line-height: 1.15;
  }
}

@media (max-width: 420px) {
  .quiz-score-row {
    gap: 6px;
  }

  .score-pill {
    padding: 7px 4px;
  }

  .score-pill .val {
    font-size: 18px;
  }

  .score-pill .lbl {
    font-size: 9px;
  }

  .quiz-opts {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .quiz-opt {
    min-height: 56px;
    padding: 10px 6px;
    font-size: 13.5px;
  }
}

/* =========================================================
   v5: Learning direction switch
   ========================================================= */

.direction-select {
  min-width: 190px;
}

.direction-pill {
  display: inline-flex;
  align-self: center;
  align-items: center;
  justify-content: center;
  background: var(--purple-light);
  color: var(--purple);
  border: 2px solid #d8ccff;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 900;
}

@media (max-width: 760px) {
  .direction-select {
    width: 100%;
    min-width: 0;
  }

  .direction-pill {
    font-size: 11px;
    padding: 5px 10px;
  }
}

/* =========================================================
   v6: Top language switch and full reverse learning mode
   ========================================================= */

.language-switch-bar {
  background: white;
  border-bottom: 1px solid #eee;
  padding: 8px 16px;
  position: sticky;
  top: 58px;
  z-index: 100;
}

.language-switch {
  max-width: 820px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.lang-choice {
  border: 2px solid #ded6f7;
  background: white;
  color: var(--muted);
  border-radius: 16px;
  padding: 10px 12px;
  font-family: 'Nunito', sans-serif;
  font-size: 14px;
  font-weight: 900;
  cursor: pointer;
  transition: all .15s ease;
}

.lang-choice.active {
  background: var(--purple);
  color: white;
  border-color: var(--purple);
  box-shadow: 0 4px 12px rgba(124,92,191,.18);
}

.lang-choice:active {
  transform: scale(.98);
}

/* Because the language switch is now sticky under the header, push the tab/category sticky positions down. */
.tab-bar {
  top: 112px;
}

.cat-scroll {
  top: 164px;
}

@media (max-width: 760px) {
  .language-switch-bar {
    top: 48px;
    padding: 7px 10px;
  }

  .language-switch {
    gap: 6px;
  }

  .lang-choice {
    padding: 8px 7px;
    font-size: 12px;
    border-radius: 13px;
  }

  .tab-bar {
    top: 100px;
  }

  .cat-scroll {
    top: 146px;
  }
}

@media (max-width: 420px) {
  .lang-choice {
    font-size: 11px;
    padding: 7px 5px;
  }
}

/* =========================================================
   v7: Language switch inside purple header banner
   ========================================================= */

header {
  padding: 12px 16px;
}

.header-row {
  max-width: 980px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.header-title {
  text-align: left;
  min-width: 0;
}

.header-title h1 {
  margin: 0;
}

.header-title p {
  margin: 2px 0 0;
}

.language-switch-bar {
  position: static;
  top: auto;
  z-index: auto;
  padding: 0;
  background: transparent;
  border-bottom: none;
  flex: 0 0 auto;
}

.language-switch {
  max-width: none;
  margin: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  min-width: 330px;
}

.lang-choice {
  border: 2px solid rgba(255,255,255,.55);
  background: rgba(255,255,255,.14);
  color: white;
  border-radius: 999px;
  padding: 8px 10px;
  font-family: 'Nunito', sans-serif;
  font-size: 12px;
  font-weight: 900;
  cursor: pointer;
  transition: all .15s ease;
  white-space: nowrap;
}

.lang-choice strong {
  font-weight: 900;
}

.lang-choice.active {
  background: white;
  color: var(--purple);
  border-color: white;
  box-shadow: 0 4px 12px rgba(0,0,0,.12);
}

.lang-choice:active {
  transform: scale(.98);
}

/* The language switch is now inside the header, so tabs/categories move back up. */
.tab-bar {
  top: 68px;
}

.cat-scroll {
  top: 120px;
}

@media (max-width: 760px) {
  header {
    padding: 8px 10px;
  }

  .header-row {
    gap: 8px;
    align-items: center;
  }

  .header-title h1 {
    font-size: 18px;
    line-height: 1.1;
  }

  .header-title p {
    display: none;
  }

  .language-switch {
    min-width: 220px;
    gap: 4px;
  }

  .lang-choice {
    padding: 7px 7px;
    font-size: 10px;
  }

  .tab-bar {
    top: 52px;
  }

  .cat-scroll {
    top: 98px;
  }
}

@media (max-width: 480px) {
  .header-row {
    flex-wrap: wrap;
  }

  .header-title {
    width: 100%;
    text-align: center;
  }

  .language-switch-bar {
    width: 100%;
  }

  .language-switch {
    width: 100%;
    min-width: 0;
  }

  .lang-choice {
    font-size: 11px;
    padding: 7px 6px;
  }

  .tab-bar {
    top: 92px;
  }

  .cat-scroll {
    top: 138px;
  }
}

/* =========================================================
   v10: localized interface + cache-busting marker
   ========================================================= */

.version-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(255,255,255,.22);
  color: white;
  font-size: 10px;
  font-weight: 900;
  vertical-align: middle;
}

header .language-switch-bar {
  position: static !important;
  top: auto !important;
  z-index: auto !important;
  background: transparent !important;
  border: 0 !important;
  padding: 0 !important;
  margin: 0 !important;
}

header .language-switch {
  margin: 0 !important;
}

header .lang-choice {
  color: white;
}

header .lang-choice.active {
  background: white;
  color: var(--purple);
}

body > .language-switch-bar {
  display: none !important;
}

@media (min-width: 761px) {
  header {
    min-height: 68px;
  }
}

/* =========================================================
   v10: clearer localized interface indicators
   ========================================================= */

.direction-pill {
  margin-bottom: 8px;
}

.lang-choice {
  min-height: 38px;
}

@media (max-width: 760px) {
  .lang-choice strong {
    display: inline;
  }
}

/* =========================================================
   v10: localized interface helpers
   ========================================================= */

.lang-choice {
  line-height: 1.15;
}

.header-title h1 .version-badge {
  position: relative;
  top: -1px;
}

/* =========================================================
   v14: stable category icons
   ========================================================= */
.cat-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.cat-icon {
  line-height: 1;
}

/* v22 mode marker */
.version-badge { font-weight: 900; }

/* =========================================================
   v26: progression unlock panel
   ========================================================= */

.unlock-panel {
  background: #f7f4ff;
  border: 2px solid #ded6f7;
  border-radius: 16px;
  padding: 10px 12px;
  margin: 10px 0;
  color: var(--purple);
  font-size: 13px;
  font-weight: 800;
}

.unlock-line {
  margin-top: 4px;
  color: #6f6590;
  font-size: 12px;
}

@media (max-width: 760px) {
  .unlock-panel {
    font-size: 12px;
    padding: 8px 10px;
  }

  .unlock-line {
    font-size: 11px;
  }
}

/* =========================================================
   v27: export/import progress controls
   ========================================================= */

.backup-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-top: 18px;
}

.import-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.danger-btn {
  background: #ff6b6b !important;
}

.danger-btn:hover {
  background: #ff4f4f !important;
}

/* =========================================================
   v30: bilingual game guide modal
   ========================================================= */

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
}

.guide-btn {
  border: 2px solid rgba(255,255,255,.65);
  background: rgba(255,255,255,.18);
  color: white;
  border-radius: 999px;
  padding: 8px 12px;
  font-family: 'Nunito', sans-serif;
  font-size: 12px;
  font-weight: 900;
  cursor: pointer;
  white-space: nowrap;
  transition: all .15s ease;
}

.guide-btn:hover {
  background: rgba(255,255,255,.28);
}

.guide-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(33, 24, 56, .58);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

.guide-modal {
  width: min(920px, 96vw);
  max-height: 90vh;
  overflow-y: auto;
  background: white;
  border-radius: 26px;
  box-shadow: 0 24px 80px rgba(0,0,0,.28);
  padding: 22px;
  position: relative;
  color: var(--text);
}

.guide-close {
  position: sticky;
  top: 0;
  float: right;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 999px;
  background: var(--purple);
  color: white;
  font-size: 26px;
  font-weight: 900;
  cursor: pointer;
  z-index: 2;
}

.guide-hero {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 16px;
  align-items: center;
  background: linear-gradient(135deg, #f7f4ff, #fff);
  border: 2px solid #ded6f7;
  border-radius: 22px;
  padding: 16px;
  margin-bottom: 16px;
}

.guide-mascot {
  font-size: 64px;
  text-align: center;
}

.guide-hero h2 {
  color: var(--purple);
  margin: 0 0 6px;
  font-size: 28px;
}

.guide-hero p,
.guide-section p {
  margin: 6px 0;
  color: #5f5874;
  font-weight: 750;
}

.guide-section {
  border: 2px solid #f0ecfb;
  border-radius: 22px;
  padding: 16px;
  margin: 14px 0;
  background: #fff;
}

.guide-section h3 {
  color: var(--purple);
  margin: 0 0 12px;
}

.guide-illustration,
.guide-rewards,
.guide-levels,
.guide-mode-grid,
.guide-card-demo {
  display: grid;
  gap: 10px;
  margin: 12px 0;
}

.guide-illustration {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.mini-toggle {
  border: 2px solid #ded6f7;
  border-radius: 16px;
  padding: 12px;
  text-align: center;
  font-weight: 900;
  color: var(--purple);
  background: #f7f4ff;
}

.mini-toggle.active {
  background: var(--purple);
  color: white;
}

.guide-card-demo {
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
}

.demo-card {
  min-height: 150px;
  border-radius: 22px;
  background: linear-gradient(145deg, #ffffff, #f7f4ff);
  border: 3px solid #ded6f7;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px;
  text-align: center;
}

.demo-card.revealed {
  border-color: var(--green);
}

.demo-emoji {
  font-size: 44px;
}

.demo-word {
  font-size: 28px;
  font-weight: 900;
  color: var(--purple);
}

.demo-hint,
.demo-sound {
  font-size: 13px;
  font-weight: 900;
  color: #81779d;
}

.demo-arrow {
  font-size: 30px;
  font-weight: 900;
  color: var(--purple);
}

.guide-mode-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.guide-mode-grid > div,
.guide-rewards span,
.level-pill {
  background: #f7f4ff;
  border: 2px solid #ded6f7;
  border-radius: 18px;
  padding: 12px;
  font-weight: 900;
  color: var(--purple);
}

.guide-mode-grid span {
  color: #6f6590;
  font-size: 12px;
}

.guide-levels {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.level-pill {
  text-align: center;
}

.level-pill small {
  color: #6f6590;
}

.guide-rewards {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.guide-footer {
  display: flex;
  justify-content: center;
  margin-top: 18px;
}

body.guide-open {
  overflow: hidden;
}

@media (max-width: 760px) {
  .header-actions {
    width: 100%;
    flex-direction: column;
    gap: 6px;
  }

  .guide-btn {
    width: 100%;
    padding: 7px 8px;
  }

  .guide-modal {
    padding: 14px;
    border-radius: 20px;
  }

  .guide-hero {
    grid-template-columns: 1fr;
    text-align: center;
  }

  .guide-hero h2 {
    font-size: 22px;
  }

  .guide-card-demo,
  .guide-illustration,
  .guide-mode-grid,
  .guide-levels,
  .guide-rewards {
    grid-template-columns: 1fr;
  }

  .demo-arrow {
    transform: rotate(90deg);
    text-align: center;
  }
}

/* =========================================================
   v30: guide details, import/export, feedback contact
   ========================================================= */

.guide-unlock-box,
.guide-tip {
  background: #fff9e8;
  border: 2px solid #ffe1a6;
  border-radius: 18px;
  padding: 12px;
  margin-top: 12px;
  color: #6e5516;
  font-weight: 800;
}

.guide-unlock-box h4 {
  margin: 0 0 8px;
  color: #7a4f00;
}

.guide-export-demo {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 10px;
  align-items: center;
  margin: 12px 0;
}

.export-card {
  background: #f7f4ff;
  border: 2px solid #ded6f7;
  border-radius: 18px;
  padding: 14px;
  color: var(--purple);
  font-weight: 900;
  text-align: center;
}

.export-card small {
  color: #6f6590;
}

.contact-card {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #f7f4ff;
  border: 2px solid #ded6f7;
  border-radius: 999px;
  padding: 12px 16px;
  margin-top: 8px;
  font-size: 18px;
  font-weight: 900;
}

.contact-card a {
  color: var(--purple);
  text-decoration: none;
}

.contact-card a:hover {
  text-decoration: underline;
}

.game-instruction {
  font-weight: 900;
  color: #5f5874;
  font-size: 22px;
  line-height: 1.35;
  text-align: center;
}

.target-word-highlight {
  display: inline-block;
  color: #4b3296;
  background: #f3edff;
  border: 2px solid #d9ccff;
  border-radius: 14px;
  padding: 4px 12px;
  margin-left: 6px;
  font-size: 30px;
  font-weight: 1000;
}

.top-header {
  width: 100%;
  min-height: 108px;
  background: var(--purple);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px 24px;
  box-sizing: border-box;
}

.brand-home-link {
  position: absolute;
  left: 28px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 2;
}

.brand-logo-left {
  width: 250px;
  max-height: 78px;
  object-fit: contain;
  display: block;
}

.header-center {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 28px;
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
  z-index: 3;
}

.header-title {
  text-align: center;
  color: white;
  flex: 0 0 auto;
}

.header-title h1 {
  margin: 0;
  line-height: 1.1;
  white-space: nowrap;
}

.header-title p {
  margin: 6px 0 0;
  line-height: 1.25;
  white-space: nowrap;
}

.language-switch-bar {
  flex: 0 0 auto;
}

@media (max-width: 1350px) {
  .brand-logo-left {
    width: 180px;
  }

  .header-center {
    max-width: 760px;
  }
}

@media (max-width: 900px) {
  .top-header {
    min-height: 160px;
    padding: 12px 16px;
    flex-direction: column;
  }

  .brand-home-link {
    position: static;
    transform: none;
    margin-bottom: 8px;
  }

  .brand-logo-left {
    width: 170px;
    max-height: 60px;
  }

  .header-center {
    flex-direction: column;
    gap: 10px;
    max-width: 100%;
  }

  .header-title h1,
  .header-title p {
    white-space: normal;
  }
}

@media (max-width: 760px) {
  .guide-export-demo {
    grid-template-columns: 1fr;
  }
  
}
/* =========================================================
   FINAL HEADER FIX FOR CURRENT INDEX.HTML
   Logo far left, title/buttons centered
   ========================================================= */

header.top-header {
  width: 100% !important;
  max-width: none !important;
  min-height: 100px !important;
  background: var(--purple) !important;
  color: white !important;
  position: sticky !important;
  top: 0 !important;
  z-index: 1000 !important;
  padding: 0 !important;
  box-shadow: 0 2px 12px rgba(124,92,191,0.3) !important;

  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  box-sizing: border-box !important;
}

/* Logo far left */
header.top-header .brand-home-link {
  position: absolute !important;
  left: 24px !important;
  top: 50% !important;
  transform: translateY(-50%) !important;
  z-index: 20 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  text-decoration: none !important;
}

/* Adjust logo size here */
header.top-header .brand-logo-left {
  width: 230px !important;
  max-width: 230px !important;
  max-height: 74px !important;
  height: auto !important;
  object-fit: contain !important;
  display: block !important;
}

/* Center group */
header.top-header .header-center {
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 24px !important;
  width: auto !important;
  max-width: 900px !important;
  margin: 0 auto !important;
  padding: 14px 24px !important;
  z-index: 10 !important;
  box-sizing: border-box !important;
}

/* Title */
header.top-header .header-title {
  text-align: center !important;
  color: white !important;
  flex: 0 0 auto !important;
  min-width: 0 !important;
  padding: 0 !important;
  margin: 0 !important;
}

header.top-header .header-title h1 {
  margin: 0 !important;
  font-size: 22px !important;
  line-height: 1.1 !important;
  white-space: nowrap !important;
  color: white !important;
  font-weight: 900 !important;
}

header.top-header .header-title p {
  margin: 6px 0 0 !important;
  font-size: 12px !important;
  line-height: 1.25 !important;
  white-space: nowrap !important;
  color: white !important;
  opacity: 0.9 !important;
}

/* Language switch and guide button stay inside centered group */
header.top-header .language-switch-bar {
  position: static !important;
  top: auto !important;
  z-index: auto !important;
  background: transparent !important;
  border: 0 !important;
  padding: 0 !important;
  margin: 0 !important;
  flex: 0 0 auto !important;
}

header.top-header .header-actions {
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 8px !important;
  flex-wrap: nowrap !important;
}

header.top-header .language-switch {
  width: auto !important;
  max-width: none !important;
  min-width: 330px !important;
  margin: 0 !important;
  display: grid !important;
  grid-template-columns: 1fr 1fr !important;
  gap: 6px !important;
}

header.top-header .lang-choice {
  min-height: 38px !important;
  border: 2px solid rgba(255,255,255,.55) !important;
  background: rgba(255,255,255,.14) !important;
  color: white !important;
  border-radius: 999px !important;
  padding: 8px 10px !important;
  font-size: 12px !important;
  line-height: 1.1 !important;
  white-space: nowrap !important;
}

header.top-header .lang-choice.active {
  background: white !important;
  color: var(--purple) !important;
  border-color: white !important;
}

header.top-header .guide-btn {
  width: auto !important;
  min-height: 38px !important;
  white-space: nowrap !important;
  flex: 0 0 auto !important;
}

/* Sticky bars below header */
.tab-bar {
  top: 100px !important;
}

.cat-scroll {
  top: 152px !important;
}

/* Medium screens */
@media (max-width: 1180px) {
  header.top-header {
    min-height: 112px !important;
  }

  header.top-header .brand-logo-left {
    width: 160px !important;
    max-width: 160px !important;
    max-height: 58px !important;
  }

  header.top-header .header-title h1 {
    font-size: 20px !important;
  }

  header.top-header .language-switch {
    min-width: 300px !important;
  }

  .tab-bar {
    top: 112px !important;
  }

  .cat-scroll {
    top: 164px !important;
  }
}

/* Tablets and phones */
@media (max-width: 900px) {
  header.top-header {
    min-height: 158px !important;
    flex-direction: column !important;
    padding: 12px !important;
  }

  header.top-header .brand-home-link {
    left: 12px !important;
    top: 12px !important;
    transform: none !important;
  }

  header.top-header .brand-logo-left {
    width: 130px !important;
    max-width: 130px !important;
    max-height: 48px !important;
  }

  header.top-header .header-center {
    flex-direction: column !important;
    gap: 8px !important;
    max-width: 100% !important;
    width: 100% !important;
    padding: 42px 0 0 !important;
  }

  header.top-header .header-title h1 {
    font-size: 20px !important;
    white-space: normal !important;
  }

  header.top-header .header-title p {
    font-size: 11px !important;
    white-space: normal !important;
  }

  header.top-header .header-actions {
    flex-direction: column !important;
    width: min(420px, 100%) !important;
  }

  header.top-header .language-switch {
    width: 100% !important;
    min-width: 0 !important;
  }

  header.top-header .guide-btn {
    width: 100% !important;
  }

  .tab-bar {
    top: 158px !important;
  }

  .cat-scroll {
    top: 204px !important;
  }
}

@media (max-width: 480px) {
  header.top-header {
    min-height: 176px !important;
  }

  header.top-header .brand-logo-left {
    width: 110px !important;
    max-width: 110px !important;
  }

  header.top-header .header-title h1 {
    font-size: 18px !important;
  }

  header.top-header .header-title p {
    display: block !important;
    font-size: 10px !important;
  }

  header.top-header .lang-choice {
    font-size: 10px !important;
    padding: 7px 5px !important;
  }

  .tab-bar {
    top: 176px !important;
  }

  .cat-scroll {
    top: 222px !important;
  }
}
