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

  :root {
    --bg: #0f1220;
    --surface: #1a1f33;
    --surface-2: #232a45;
    --border: #2e3760;
    --text: #e8ecff;
    --muted: #9aa3c7;
    --accent: #6c7bff;
    --accent-2: #45e3a0;
    --amber: #ffb84d;
    --danger: #ff6b8a;
  }

  body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, "Noto Sans Kannada", "Nirmala UI", sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: clamp(16px, 3vw, 40px);
  }

  header { text-align: center; margin-bottom: 22px; }
  header h1 { font-size: clamp(22px, 3.5vw, 34px); letter-spacing: 0.5px; }
  header h1 .hi { color: var(--accent-2); }
  header p { color: var(--muted); margin-top: 8px; font-size: clamp(13px, 1.5vw, 16px); }

  .tabs { display: flex; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; justify-content: center; }
  .tab {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--muted);
    padding: 10px 20px;
    border-radius: 10px;
    font-size: 15px;
    cursor: pointer;
    transition: all .15s ease;
  }
  .tab:hover { border-color: var(--accent); color: var(--text); }
  .tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }

  .lesson-select-wrap { margin-bottom: 24px; display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }
  .lesson-select-wrap select {
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 10px 16px;
    border-radius: 10px;
    font-size: 15px;
    outline: none;
    cursor: pointer;
    text-align: center;
  }
  .lesson-select-wrap select:focus { border-color: var(--accent); }
  #langSelect { min-width: 150px; }
  #lessonSelect { min-width: 260px; }

  .card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: clamp(20px, 3vw, 36px);
    width: min(94vw, 980px);
    box-shadow: 0 10px 30px rgba(0,0,0,.35);
  }

  .view { display: none; }
  .view.active { display: block; }

  /* ---- Flashcard ---- */
  .lesson-label { text-align: center; color: var(--accent); font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 1px; margin-bottom: 16px; }
  .flashcard {
    perspective: 1000px;
    margin: 0 auto 24px;
    width: 100%;
  }
  .flashcard-inner {
    position: relative;
    width: 100%;
    height: clamp(220px, 38vh, 380px);
    transform-style: preserve-3d;
    transition: transform .5s ease;
  }
  .flashcard-inner.flipped { transform: rotateY(180deg); }
  .flashcard-face {
    position: absolute;
    inset: 0;
    backface-visibility: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 24px;
    text-align: center;
  }
  .flashcard-face.back { transform: rotateY(180deg); }
  .flashcard-word { font-size: clamp(28px, 4.5vw, 44px); font-weight: 700; }
  .flashcard-hint { color: var(--muted); font-size: 14px; margin-top: 10px; }
  .flashcard-extra { color: var(--accent-2); font-size: 16px; margin-top: 6px; }

  .speak {
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--muted);
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    flex-shrink: 0;
    transition: all .15s ease;
  }
  .speak:hover { color: var(--accent-2); border-color: var(--accent-2); filter: none; }
  .flashcard-face .speak { position: absolute; top: 12px; right: 12px; }
  .glossary-item .speak { margin-left: 8px; }

  .card-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
  .card-actions button { margin: 0; }
  .counter { text-align: center; color: var(--muted); font-size: 14px; margin-top: 16px; }

  /* ---- Quiz ---- */
  .quiz-question { font-size: clamp(20px, 3vw, 30px); text-align: center; margin-bottom: 6px; font-weight: 600; }
  .quiz-sub { text-align: center; color: var(--muted); font-size: 14px; margin-bottom: 22px; }
  .options { display: grid; gap: 10px; grid-template-columns: 1fr; }
  @media (min-width: 640px) {
    .options { grid-template-columns: 1fr 1fr; }
  }
  .option {
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 14px;
    border-radius: 10px;
    font-size: 17px;
    cursor: pointer;
    text-align: left;
    transition: all .12s ease;
  }
  .option:hover { border-color: var(--accent); }
  .option.correct { background: var(--accent-2); border-color: var(--accent-2); color: #063; }
  .option.wrong { background: var(--danger); border-color: var(--danger); color: #fff; }
  .option:disabled { cursor: default; opacity: 1; }

  .score-bar { height: 8px; background: var(--surface-2); border-radius: 8px; overflow: hidden; margin: 20px 0 8px; }
  .score-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .3s ease; }

  /* ---- Glossary ---- */
  .search-wrap { margin-bottom: 18px; }
  .search-wrap input {
    width: 100%;
    padding: 12px 14px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    font-size: 15px;
    outline: none;
  }
  .search-wrap input:focus { border-color: var(--accent); }
  .glossary { display: grid; grid-template-columns: 1fr; gap: 8px; }
  @media (min-width: 640px) {
    .glossary { grid-template-columns: 1fr 1fr; }
  }
  @media (min-width: 900px) {
    .glossary { grid-template-columns: 1fr 1fr 1fr; }
  }
  .glossary-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--surface-2);
    border: 1px solid var(--border);
    padding: 12px 16px;
    border-radius: 10px;
  }
  .glossary-en { font-weight: 600; font-size: 16px; }
  .glossary-hi { color: var(--accent-2); font-size: 16px; }
  .glossary-trans { color: var(--muted); font-size: 13px; margin-top: 2px; }

  /* ---- Dashboard ---- */
  .stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 24px; }
  @media (min-width: 640px) {
    .stats-grid { grid-template-columns: repeat(4, 1fr); }
  }
  .stat-card { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 16px 12px; text-align: center; }
  .stat-value { font-size: 28px; font-weight: 800; color: var(--accent-2); }
  .stat-label { color: var(--muted); font-size: 12px; margin-top: 4px; text-transform: uppercase; letter-spacing: 0.5px; }
  .dash-section { margin-bottom: 24px; }
  .dash-section h3 { font-size: 15px; color: var(--muted); margin-bottom: 14px; text-transform: uppercase; letter-spacing: 1px; }

  .chart { display: flex; align-items: flex-end; gap: 6px; height: clamp(120px, 24vh, 220px); padding: 0 4px; }
  .chart-bar {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    height: 100%;
    gap: 4px;
    min-width: 0;
  }
  .bar-fill {
    width: 100%;
    max-width: 34px;
    border-radius: 6px 6px 0 0;
    background: linear-gradient(180deg, var(--accent-2), var(--accent));
    min-height: 4px;
  }
  .bar-fill.empty { background: var(--surface-2); }
  .bar-label { font-size: 10px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  .chart-empty { color: var(--muted); font-size: 14px; padding: 30px 0; text-align: center; }

  .mastery-grid { display: grid; grid-template-columns: 1fr; gap: 8px; }
  @media (min-width: 640px) {
    .mastery-grid { grid-template-columns: 1fr 1fr; }
  }
  @media (min-width: 900px) {
    .mastery-grid { grid-template-columns: 1fr 1fr 1fr; }
  }
  .mastery-item { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
  .mastery-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
  .mastery-en { font-weight: 600; font-size: 14px; }
  .mastery-pct { font-size: 12px; font-weight: 700; }
  .mastery-pct.high { color: var(--accent-2); }
  .mastery-pct.mid { color: var(--amber); }
  .mastery-pct.low { color: var(--danger); }
  .mastery-bar { height: 5px; background: var(--border); border-radius: 4px; overflow: hidden; }
  .mastery-fill { height: 100%; border-radius: 4px; background: var(--accent-2); }

  .empty-state { color: var(--muted); font-size: 15px; text-align: center; padding: 24px 0; line-height: 1.6; }

  button {
    background: var(--accent);
    border: none;
    color: #fff;
    padding: 12px 22px;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: filter .15s ease;
  }
  button:hover { filter: brightness(1.1); }
  button.secondary { background: var(--surface-2); border: 1px solid var(--border); color: var(--text); }
  button.ghost { background: transparent; border: 1px solid var(--border); color: var(--muted); }
  button.danger { background: transparent; border: 1px solid var(--danger); color: var(--danger); }

  .result { text-align: center; }
  .result h2 { font-size: 26px; margin-bottom: 8px; }
  .result .score-num { font-size: 48px; font-weight: 800; color: var(--accent-2); margin: 16px 0; }
  .result p { color: var(--muted); margin-bottom: 20px; }

  @media (max-width: 480px) {
    .flashcard-word { font-size: 26px; }
  }

  /* ---- Title screen ---- */
  .overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    background: radial-gradient(1200px 600px at 50% -10%, #2a3466 0%, var(--bg) 60%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 24px;
  }
  .overlay.hidden { display: none; }
  .title-logo { font-size: clamp(30px, 5vw, 52px); font-weight: 800; letter-spacing: 0.5px; margin-bottom: 6px; }
  .title-logo .hi { color: var(--accent-2); }
  .title-tagline { color: var(--muted); font-size: clamp(14px, 1.8vw, 17px); margin-bottom: 34px; }
  .title-form { display: flex; flex-direction: column; gap: 14px; width: min(92vw, 380px); }
  .title-form label { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: 1px; }
  .name-input {
    width: 100%;
    padding: 14px 16px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    font-size: 17px;
    text-align: center;
    outline: none;
  }
  .name-input:focus { border-color: var(--accent); }
  .title-lang-row { display: flex; justify-content: center; }
  .title-lang-row select {
    width: 100%;
    padding: 12px 16px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    font-size: 16px;
    text-align: center;
    outline: none;
    cursor: pointer;
  }
  .title-lang-row select:focus { border-color: var(--accent); }
  .title-actions { display: flex; flex-direction: column; gap: 10px; }
  .title-actions button { width: 100%; }

  .modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(5, 7, 16, 0.75);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
  }
  .modal-backdrop.show { display: flex; }
  .modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 28px;
    width: min(92vw, 480px);
    box-shadow: 0 20px 60px rgba(0,0,0,.5);
  }
  .modal h2 { font-size: 22px; margin-bottom: 4px; }
  .modal .version { color: var(--accent-2); font-size: 14px; margin-bottom: 16px; font-weight: 700; }
  .modal ul { list-style: none; margin-bottom: 20px; }
  .modal li { color: var(--text); padding: 7px 0; font-size: 15px; border-bottom: 1px solid var(--border); }
  .modal li:last-child { border-bottom: none; }
  .modal li .mark { color: var(--accent-2); font-weight: 700; margin-right: 8px; }
  .modal .close-row { display: flex; justify-content: center; }