/* ============================================================
   SLAVA — styles
   Deep night-blue base, sunflower-yellow energy accents,
   vyshyvanka-inspired geometric pattern on progress elements.
   Mobile-first; scales up at 700px+.
   ============================================================ */

/* ---------- Theme tokens ---------- */
:root {
  --font-display: "Unbounded", "Avenir Next", "Segoe UI", system-ui, sans-serif;
  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, system-ui, sans-serif;

  --radius: 16px;
  --radius-sm: 10px;
  --nav-h: 64px;
  --tap: 48px;               /* minimum touch target */

  /* Vyshyvanka diamond pattern (currentColor-ish via explicit fills) */
  --vysh-size: 18px;
}

html[data-theme="dark"] {
  --bg: #0d1530;             /* deep night blue */
  --bg-soft: #131e42;
  --card: #1a2650;
  --card-2: #21305f;
  --border: #2c3b6e;
  --text: #eef1fb;
  --text-dim: #9aa6cf;
  --text-faint: #6b77a6;

  --sun: #ffd23f;            /* sunflower yellow — the energy color */
  --sun-deep: #8a5a00;
  --sun-soft: rgba(255, 210, 63, 0.14);

  --good: #4ade80;
  --good-soft: rgba(74, 222, 128, 0.14);
  --bad: #fb7185;
  --bad-soft: rgba(251, 113, 133, 0.14);
  --info: #7dd3fc;

  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  --overlay: rgba(5, 9, 24, 0.72);
}

html[data-theme="light"] {
  --bg: #f4f2ea;
  --bg-soft: #ece9dd;
  --card: #ffffff;
  --card-2: #f6f4ec;
  --border: #ddd8c8;
  --text: #1d2440;
  --text-dim: #5b6285;
  --text-faint: #9096b3;

  --sun: #e8a800;
  --sun-deep: #6b4a00;
  --sun-soft: rgba(232, 168, 0, 0.14);

  --good: #16a34a;
  --good-soft: rgba(22, 163, 74, 0.12);
  --bad: #dc2626;
  --bad-soft: rgba(220, 38, 38, 0.10);
  --info: #0369a1;

  --shadow: 0 6px 20px rgba(29, 36, 64, 0.12);
  --overlay: rgba(29, 36, 64, 0.45);
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100dvh;
  overscroll-behavior-y: none;
  -webkit-tap-highlight-color: transparent;
}
button {
  font-family: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
}
button:focus-visible, a:focus-visible, input:focus-visible {
  outline: 2px solid var(--sun);
  outline-offset: 2px;
}
h1, h2, h3 { font-family: var(--font-display); font-weight: 700; line-height: 1.2; margin: 0; }
a { color: var(--info); }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; min-height: var(--tap); }
.brand-mark { width: 30px; height: 30px; }
.brand-name {
  font-family: var(--font-display); font-weight: 700; font-size: 1.25rem;
  letter-spacing: 0.02em;
}
.topbar-right { display: flex; align-items: center; gap: 8px; }
.iconbtn {
  min-width: var(--tap); min-height: var(--tap);
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%; color: var(--text-dim);
}
.iconbtn:hover { color: var(--text); background: var(--card); }
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  min-height: 40px; padding: 4px 12px;
  border-radius: 999px; background: var(--card); border: 1px solid var(--border);
  font-weight: 700; font-size: 0.95rem;
}
.chip-streak { color: var(--sun); }
.chip-streak .freeze { font-size: 0.8rem; }

/* ---------- Main / layout ---------- */
#app {
  max-width: 720px; margin: 0 auto;
  padding: 16px 16px calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + 24px);
  outline: none;
}
@media (min-width: 700px) {
  #app { padding-top: 28px; }
}

/* ---------- Bottom nav ---------- */
.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: flex; justify-content: space-around;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: color-mix(in srgb, var(--bg-soft) 94%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
}
.navbtn {
  position: relative;
  flex: 1; max-width: 160px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--text-faint); font-size: 0.72rem; font-weight: 600;
  min-height: var(--tap);
}
.navbtn svg { width: 24px; height: 24px; }
.navbtn.active { color: var(--sun); }
.navbadge {
  position: absolute; top: 6px; right: calc(50% - 26px);
  min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 999px; background: var(--sun); color: #1d2440;
  font-size: 0.68rem; font-weight: 800; line-height: 18px; text-align: center;
}

/* ---------- Vyshyvanka pattern (signature element) ----------
   A row of geometric diamonds, like the hem of an embroidered shirt.
   Used as a top border on progress cards and the lesson-complete card. */
.vysh {
  height: 8px;
  background-image:
    linear-gradient(45deg, var(--sun) 25%, transparent 25%),
    linear-gradient(-45deg, var(--sun) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--sun) 75%),
    linear-gradient(-45deg, transparent 75%, var(--sun) 75%);
  background-size: var(--vysh-size) var(--vysh-size);
  background-position: 0 4px, 0 4px, 0 0, 0 0;
  opacity: 0.85;
  border-radius: 2px;
}
.vysh.dim { opacity: 0.35; }

/* ---------- Cards & common ---------- */
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
  box-shadow: var(--shadow);
}
.muted { color: var(--text-dim); }
.small { font-size: 0.85rem; }
.center { text-align: center; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 10px 20px;
  border-radius: var(--radius-sm);
  background: var(--card-2); border: 1px solid var(--border);
  font-weight: 700; font-size: 1rem;
  transition: transform 0.08s ease, background 0.15s ease;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--sun); border-color: var(--sun); color: #1d2440; }
.btn-primary:hover { filter: brightness(1.06); }
.btn-ghost { background: transparent; }
.btn-wide { width: 100%; }
.btn-good { background: var(--good); border-color: var(--good); color: #08240f; }
.btn[disabled] { opacity: 0.45; cursor: default; }

.kbd-hint { display: none; color: var(--text-faint); font-size: 0.75rem; }
@media (min-width: 900px) and (hover: hover) { .kbd-hint { display: block; } }

/* ---------- Audio buttons ---------- */
.audio-row { display: inline-flex; align-items: center; gap: 8px; }
.speak-btn, .gt-btn {
  min-width: var(--tap); min-height: var(--tap);
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: var(--sun-soft); color: var(--sun);
  border: 1px solid transparent;
  transition: transform 0.08s ease;
}
.speak-btn:active, .gt-btn:active { transform: scale(0.92); }
.speak-btn.speaking { background: var(--sun); color: #1d2440; }
.speak-btn svg, .gt-btn svg { width: 22px; height: 22px; }
.gt-btn { background: var(--card-2); color: var(--text-dim); border-color: var(--border); text-decoration: none; }
.gt-btn:hover { color: var(--text); }
.audio-row.compact .speak-btn, .audio-row.compact .gt-btn { min-width: 44px; min-height: 44px; }

/* Register badge (formal/informal) */
.badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px;
  font-size: 0.68rem; font-weight: 800; letter-spacing: 0.04em; text-transform: uppercase;
  vertical-align: middle;
}
.badge-formal { background: rgba(125, 211, 252, 0.16); color: var(--info); }
.badge-informal { background: rgba(216, 180, 254, 0.16); color: #c084fc; }
html[data-theme="light"] .badge-informal { color: #7c3aed; background: rgba(124, 58, 237, 0.1); }

/* ---------- Home screen ---------- */
.home-hero { margin-bottom: 18px; }
.home-hero h1 { font-size: 1.5rem; margin-bottom: 2px; }
.home-hero .sub { color: var(--text-dim); font-size: 0.95rem; }

.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 18px; }
.stat {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 8px; text-align: center;
}
.stat .num { font-family: var(--font-display); font-size: 1.3rem; font-weight: 700; color: var(--sun); }
.stat .lbl { font-size: 0.72rem; color: var(--text-dim); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }

.level-card { margin-bottom: 20px; padding: 0; overflow: hidden; }
.level-card .inner { padding: 14px 16px 16px; }
.level-title { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.level-title .uk-title { font-family: var(--font-display); font-size: 1.15rem; color: var(--sun); }
.level-title .en-title { color: var(--text-dim); font-size: 0.85rem; }
.xpbar { height: 10px; background: var(--bg-soft); border-radius: 999px; margin-top: 10px; overflow: hidden; }
.xpbar > div { height: 100%; background: var(--sun); border-radius: 999px; transition: width 0.6s cubic-bezier(0.22, 1, 0.36, 1); }
.xp-nums { display: flex; justify-content: space-between; font-size: 0.78rem; color: var(--text-faint); margin-top: 6px; }

.review-cta {
  display: flex; align-items: center; gap: 12px; width: 100%;
  text-align: left; margin-bottom: 22px;
}
.review-cta .grow { flex: 1; }
.review-cta .due-num { font-family: var(--font-display); font-size: 1.4rem; color: var(--sun); }

/* Journey map */
.journey { position: relative; padding-left: 8px; }
.journey h2 { font-size: 1.05rem; margin-bottom: 14px; }
.stop {
  display: flex; align-items: center; gap: 14px;
  width: 100%; text-align: left;
  padding: 10px 8px; border-radius: var(--radius);
  position: relative;
}
.stop:hover { background: var(--card); }
.stop + .stop::before {
  content: ""; position: absolute; left: 35px; top: -18px;
  width: 2px; height: 26px; background: var(--border);
}
.stop .ring { flex: none; position: relative; width: 56px; height: 56px; }
.stop .ring svg { transform: rotate(-90deg); }
.stop .ring .icon {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem;
}
.stop .meta { flex: 1; min-width: 0; }
.stop .meta .name { font-weight: 700; }
.stop .meta .sub { font-size: 0.8rem; color: var(--text-dim); }
.stop.locked { opacity: 0.5; }
.stop.locked .icon { filter: grayscale(1); }
.stop .lock { color: var(--text-faint); }
.stop.done .name::after { content: " ✓"; color: var(--good); }

/* ---------- Learn: category / lesson lists ---------- */
.screen-title { font-size: 1.3rem; margin-bottom: 4px; }
.screen-sub { color: var(--text-dim); margin: 0 0 18px; font-size: 0.95rem; }
.lesson-list { display: flex; flex-direction: column; gap: 10px; }
.lesson-row {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; min-height: 64px;
}
.lesson-row:not([disabled]):hover { background: var(--card-2); }
.lesson-row .num {
  flex: none; width: 40px; height: 40px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--sun-soft); color: var(--sun); font-weight: 800; font-family: var(--font-display);
}
.lesson-row.done .num { background: var(--good-soft); color: var(--good); }
.lesson-row .grow { flex: 1; min-width: 0; }
.lesson-row .preview { font-size: 0.8rem; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.back-row { margin-bottom: 14px; }
.back-btn { display: inline-flex; align-items: center; gap: 6px; color: var(--text-dim); font-weight: 600; min-height: var(--tap); }
.back-btn:hover { color: var(--text); }

/* ---------- Lesson: progress bar ---------- */
.lesson-progress { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.lesson-progress .bar { flex: 1; height: 8px; background: var(--bg-soft); border-radius: 999px; overflow: hidden; }
.lesson-progress .bar > div { height: 100%; background: var(--sun); border-radius: 999px; transition: width 0.4s ease; }
.lesson-progress .count { font-size: 0.8rem; color: var(--text-dim); font-weight: 700; min-width: 44px; text-align: right; }
.quit-btn { color: var(--text-faint); min-width: var(--tap); min-height: var(--tap); display: inline-flex; align-items: center; justify-content: center; }
.quit-btn:hover { color: var(--bad); }

/* ---------- Flashcards ---------- */
.flash-wrap { perspective: 1200px; margin-bottom: 16px; }
.flash {
  position: relative; width: 100%; min-height: 280px;
  transform-style: preserve-3d;
  transition: transform 0.5s cubic-bezier(0.4, 0.2, 0.2, 1);
  cursor: pointer;
}
.flash.flipped { transform: rotateY(180deg); }
.flash .face {
  position: absolute; inset: 0;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 24px 18px; text-align: center;
  box-shadow: var(--shadow);
}
.flash .face.back { transform: rotateY(180deg); }
.flash .uk-text { font-size: 1.7rem; font-weight: 700; line-height: 1.25; }
.flash .translit { color: var(--sun); font-size: 1rem; letter-spacing: 0.02em; }
.flash .en-text { font-size: 1.5rem; font-weight: 700; }
.flash .literal { color: var(--text-dim); font-size: 0.9rem; font-style: italic; }
.flash .note { color: var(--text-dim); font-size: 0.85rem; max-width: 40ch; }
.flash .hint { position: absolute; bottom: 10px; left: 0; right: 0; color: var(--text-faint); font-size: 0.72rem; }
.flash-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---------- Quiz / games ---------- */
.task-prompt { text-align: center; margin: 10px 0 20px; }
.task-kind { font-size: 0.72rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-faint); margin-bottom: 10px; }
.task-prompt .big { font-size: 1.55rem; font-weight: 700; line-height: 1.3; }
.task-prompt .translit { color: var(--sun); margin-top: 4px; }
.task-prompt .audio-row { margin-top: 12px; }
.listen-big {
  width: 88px; height: 88px; border-radius: 50%;
  background: var(--sun); color: #1d2440;
  display: inline-flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow);
}
.listen-big svg { width: 40px; height: 40px; }
.listen-big:active { transform: scale(0.94); }

.options { display: flex; flex-direction: column; gap: 10px; }
.option {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: var(--card); border: 1.5px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; min-height: 56px; font-size: 1.05rem; font-weight: 600;
  transition: transform 0.08s ease, border-color 0.15s ease, background 0.15s ease;
}
.option .key {
  flex: none; width: 26px; height: 26px; border-radius: 7px;
  background: var(--bg-soft); color: var(--text-faint);
  font-size: 0.8rem; font-weight: 800;
  display: none; align-items: center; justify-content: center;
}
@media (min-width: 900px) and (hover: hover) { .option .key { display: inline-flex; } }
.option:not([disabled]):hover { border-color: var(--text-faint); }
.option:not([disabled]):active { transform: scale(0.98); }
.option.correct { border-color: var(--good); background: var(--good-soft); }
.option.wrong { border-color: var(--bad); background: var(--bad-soft); animation: shake 0.35s ease; }
.option.reveal { border-color: var(--good); }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

/* Feedback banner + continue */
.feedback {
  display: flex; align-items: center; gap: 10px;
  border-radius: var(--radius); padding: 12px 16px; margin-top: 16px;
  font-weight: 700;
}
.feedback.good { background: var(--good-soft); color: var(--good); }
.feedback.bad { background: var(--bad-soft); color: var(--bad); }
.feedback .detail { font-weight: 500; color: var(--text); font-size: 0.9rem; }
.continue-wrap { margin-top: 14px; }

/* Combo indicator */
.combo-pill {
  position: fixed; top: calc(env(safe-area-inset-top, 0px) + 70px); right: 16px; z-index: 25;
  background: var(--sun); color: #1d2440; font-weight: 800; font-size: 0.85rem;
  padding: 6px 12px; border-radius: 999px; box-shadow: var(--shadow);
  animation: pop 0.3s ease;
}
@keyframes pop { 0% { transform: scale(0.6); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }

/* ---------- Word builder ---------- */
.builder-answer {
  min-height: 62px; display: flex; flex-wrap: wrap; gap: 8px; align-content: flex-start;
  background: var(--bg-soft); border: 1.5px dashed var(--border); border-radius: var(--radius);
  padding: 10px; margin-bottom: 14px;
}
.builder-pool { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.tile {
  min-height: var(--tap); padding: 10px 16px;
  background: var(--card); border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  font-size: 1.1rem; font-weight: 700;
  transition: transform 0.1s ease;
}
.tile:active { transform: scale(0.95); }
.builder-answer .tile { background: var(--sun-soft); border-color: var(--sun); color: var(--sun); }
html[data-theme="light"] .builder-answer .tile { color: var(--sun-deep); }
.tile.ghost { opacity: 0.25; pointer-events: none; }

/* ---------- Matching ---------- */
.match-timer { text-align: center; font-family: var(--font-display); font-size: 1.1rem; color: var(--sun); margin-bottom: 12px; }
.match-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.match-btn {
  min-height: 60px; padding: 8px 10px;
  background: var(--card); border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  font-size: 0.95rem; font-weight: 600; line-height: 1.25;
  transition: transform 0.08s ease, opacity 0.3s ease, border-color 0.15s ease;
}
.match-btn.sel { border-color: var(--sun); background: var(--sun-soft); }
.match-btn.matched { opacity: 0.18; pointer-events: none; border-color: var(--good); }
.match-btn.miss { border-color: var(--bad); animation: shake 0.35s ease; }

/* ---------- Lesson summary ---------- */
.summary-card { padding: 0; overflow: hidden; text-align: center; }
.summary-card .inner { padding: 26px 18px 22px; }
.summary-card .emoji { font-size: 3rem; }
.summary-card h2 { font-size: 1.4rem; margin: 8px 0 4px; }
.summary-stats { display: flex; justify-content: center; gap: 26px; margin: 18px 0; }
.summary-stats .s .num { font-family: var(--font-display); font-size: 1.5rem; color: var(--sun); }
.summary-stats .s .lbl { font-size: 0.75rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em; }

/* ---------- Phrasebook ---------- */
.searchbar {
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 4px 14px; margin-bottom: 12px;
}
.searchbar svg { width: 20px; height: 20px; color: var(--text-faint); flex: none; }
.searchbar input {
  flex: 1; min-height: var(--tap);
  background: none; border: none; color: var(--text); font-size: 1rem; outline: none;
}
.searchbar input::placeholder { color: var(--text-faint); }
.cat-chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 8px; margin-bottom: 10px; scrollbar-width: none; }
.cat-chips::-webkit-scrollbar { display: none; }
.cat-chip {
  flex: none; min-height: 40px; padding: 6px 14px;
  border-radius: 999px; background: var(--card); border: 1px solid var(--border);
  font-size: 0.85rem; font-weight: 600; color: var(--text-dim); white-space: nowrap;
}
.cat-chip.active { background: var(--sun); border-color: var(--sun); color: #1d2440; }

.phrase-list { display: flex; flex-direction: column; gap: 8px; }
.phrase-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px;
}
.phrase-row .grow { flex: 1; min-width: 0; }
.phrase-row .uk { font-weight: 700; font-size: 1.05rem; }
.phrase-row .tr { color: var(--sun); font-size: 0.82rem; }
.phrase-row .en { color: var(--text-dim); font-size: 0.9rem; }
.phrase-row .note { color: var(--text-faint); font-size: 0.78rem; margin-top: 3px; }
.phrase-row .learned-dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--good); }

/* ---------- Modals ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: var(--overlay);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fadeIn 0.2s ease;
}
@media (min-width: 700px) { .modal-backdrop { align-items: center; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  width: 100%; max-width: 480px; max-height: 88dvh; overflow-y: auto;
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 22px 20px calc(20px + env(safe-area-inset-bottom, 0px));
  animation: slideUp 0.25s cubic-bezier(0.22, 1, 0.36, 1);
}
@media (min-width: 700px) { .modal { border-radius: var(--radius); } }
@keyframes slideUp { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal h2 { font-size: 1.2rem; margin-bottom: 14px; }
.setting-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 52px; padding: 6px 0;
  border-bottom: 1px solid var(--border);
}
.setting-row:last-of-type { border-bottom: none; }
.setting-row .lbl { font-weight: 600; }
.setting-row .sub { font-size: 0.78rem; color: var(--text-dim); }
.toggle {
  flex: none; width: 52px; height: 32px; border-radius: 999px;
  background: var(--bg-soft); border: 1px solid var(--border);
  position: relative; transition: background 0.2s ease;
}
.toggle::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--text-dim); transition: transform 0.2s ease, background 0.2s ease;
}
.toggle.on { background: var(--sun); border-color: var(--sun); }
.toggle.on::after { transform: translateX(20px); background: #1d2440; }

/* Onboarding */
.onb { text-align: center; }
.onb .art { font-size: 3rem; margin: 6px 0 10px; }
.onb h2 { font-size: 1.3rem; }
.onb p { color: var(--text-dim); max-width: 38ch; margin: 10px auto 0; }
.onb .demo-row { display: flex; justify-content: center; gap: 10px; margin: 16px 0; }
.onb-dots { display: flex; justify-content: center; gap: 6px; margin: 18px 0 14px; }
.onb-dots span { width: 8px; height: 8px; border-radius: 50%; background: var(--border); }
.onb-dots span.on { background: var(--sun); }

/* ---------- Toast ---------- */
#toastLayer { position: fixed; bottom: calc(var(--nav-h) + 20px); left: 0; right: 0; z-index: 60; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast {
  background: var(--card-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 999px; padding: 10px 18px; font-weight: 600; font-size: 0.9rem;
  box-shadow: var(--shadow);
  animation: toastIn 0.25s ease;
}
.toast.sun { border-color: var(--sun); color: var(--sun); }
@keyframes toastIn { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Confetti ---------- */
#fxLayer { position: fixed; inset: 0; z-index: 70; pointer-events: none; overflow: hidden; }
.confetto {
  position: absolute; top: -12px;
  width: 9px; height: 14px; border-radius: 2px;
  animation: fall linear forwards;
}
@keyframes fall {
  to { transform: translateY(105vh) rotate(720deg); opacity: 0.6; }
}

/* ---------- Desktop niceties ---------- */
@media (min-width: 900px) {
  .flash { min-height: 320px; }
  .options { max-width: 560px; margin: 0 auto; }
  .match-grid { max-width: 640px; margin: 0 auto; }
}

/* ============================================================
   Alphabet module (Абетка) + speaking exercises
   Everything below reuses the existing tokens — no new palette.
   ============================================================ */

/* ---------- Letter cards ---------- */
.letter-hero { display: flex; align-items: baseline; justify-content: center; gap: 18px; margin: 6px 0 2px; }
.letter-hero .glyph { font-size: 4.2rem; font-weight: 700; line-height: 1; }
.letter-hero .glyph.lower { font-size: 3.4rem; color: var(--text-dim); }
.letter-name { text-align: center; margin-bottom: 4px; }
.letter-name .nm { font-family: var(--font-display); font-size: 1.1rem; color: var(--sun); }
.letter-name .ipa { color: var(--text-faint); font-size: 0.85rem; margin-left: 8px; }
.sound-hint { text-align: center; color: var(--text-dim); font-size: 0.95rem; margin-bottom: 10px; }

.tricky-card {
  display: flex; gap: 10px; align-items: flex-start;
  background: var(--bad-soft); border: 1px solid var(--bad);
  border-radius: var(--radius); padding: 10px 14px; margin: 10px 0;
  font-size: 0.9rem;
}
.tricky-card .tag { font-weight: 800; color: var(--bad); white-space: nowrap; }

.example-row {
  display: flex; align-items: center; gap: 10px; justify-content: center;
  background: var(--card-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 14px; margin: 10px auto; max-width: 420px;
}
.example-row .uk { font-weight: 700; font-size: 1.1rem; }
.example-row .tr { color: var(--sun); font-size: 0.82rem; }
.example-row .en { color: var(--text-dim); font-size: 0.88rem; }

/* ---------- Tracing canvas ---------- */
.trace-wrap {
  position: relative; width: min(78vw, 330px); aspect-ratio: 1;
  margin: 0 auto; background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
  touch-action: none; /* the page must not scroll while writing */
}
.trace-svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.trace-canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }

.t-base line { stroke: var(--border); stroke-width: 1; stroke-dasharray: 4 6; }
.t-base .t-baseline { stroke-dasharray: none; opacity: 0.9; }
.t-ghost path { fill: none; stroke: var(--text-faint); stroke-width: 11; stroke-linecap: round; stroke-linejoin: round; opacity: 0.3; }
.t-done path { fill: none; stroke: var(--good); stroke-width: 10; stroke-linecap: round; stroke-linejoin: round; }
.t-cur { fill: none; stroke: var(--sun); stroke-width: 5; stroke-linecap: round; stroke-linejoin: round; opacity: 0.9; }
.t-startdot { fill: var(--sun); animation: startPulse 1.2s ease-in-out infinite; }
.t-startdot.t-nudge { animation: startNudge 0.4s ease; }
.t-arrow { fill: var(--sun); }
.t-dot { fill: var(--sun); stroke: var(--bg); stroke-width: 2; }
.t-num circle { fill: var(--sun-soft); stroke: var(--sun); stroke-width: 1.5; }
.t-num text { fill: var(--sun); font-size: 11px; font-weight: 800; font-family: var(--font-body); }

@keyframes startPulse { 0%, 100% { r: 9; opacity: 1; } 50% { r: 12; opacity: 0.55; } }
@keyframes startNudge { 0%, 100% { r: 9; } 40% { r: 16; } }
.shake-anim { animation: shake 0.35s ease; }

.stroke-dots { display: flex; justify-content: center; gap: 7px; margin: 12px 0 4px; }
.stroke-dots span { width: 10px; height: 10px; border-radius: 50%; background: var(--border); }
.stroke-dots span.on { background: var(--good); }
.stroke-dots span.cur { background: var(--sun); }

.stars { font-size: 1.7rem; letter-spacing: 6px; text-align: center; margin: 8px 0 2px; }
.stars .dim { opacity: 0.25; }

/* ---------- Alphabet lists / rings ---------- */
.alpha-banner { display: flex; align-items: center; gap: 14px; width: 100%; text-align: left; margin-bottom: 18px; }
.alpha-banner .big-a { font-family: var(--font-display); font-size: 1.9rem; color: var(--sun); }
.letter-chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.letter-chip {
  min-width: 34px; height: 34px; padding: 0 6px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 9px; background: var(--bg-soft); border: 1px solid var(--border);
  font-weight: 700; font-size: 1rem;
}
.letter-chip.known { border-color: var(--good); color: var(--good); }

/* ---------- Letter hunt tiles ---------- */
.hunt-word { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; margin: 6px 0; }
.hunt-word .tile { font-size: 1.5rem; min-width: var(--tap); }
.hunt-word .tile.correct { border-color: var(--good); background: var(--good-soft); color: var(--good); }
.hunt-word .tile.wrong { border-color: var(--bad); background: var(--bad-soft); animation: shake 0.35s ease; }

/* ---------- Speaking (Say it) ---------- */
.mic-zone { text-align: center; margin: 18px 0 8px; }
.mic-btn {
  width: 92px; height: 92px; border-radius: 50%;
  background: var(--sun); color: #1d2440;
  display: inline-flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow);
  transition: transform 0.1s ease;
  touch-action: none;
}
.mic-btn svg { width: 40px; height: 40px; }
.mic-btn:active { transform: scale(0.95); }
.mic-btn.listening { animation: micPulse 1.1s ease-in-out infinite; background: var(--bad); color: #fff; }
.mic-btn[disabled] { opacity: 0.4; }
@keyframes micPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(251, 113, 133, 0.45); }
  50% { box-shadow: 0 0 0 22px rgba(251, 113, 133, 0); }
}
.mic-status { color: var(--text-dim); font-size: 0.85rem; margin-top: 10px; min-height: 1.2em; }
.say-transcript {
  min-height: 30px; text-align: center; margin-top: 10px;
  font-size: 1.05rem; color: var(--text);
}
.say-transcript .heard-label { color: var(--text-faint); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; display: block; }
.diff-row { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 10px; }
.diff-chip {
  padding: 3px 10px; border-radius: 999px; font-weight: 600; font-size: 0.95rem;
  background: var(--bad-soft); color: var(--bad); border: 1px solid transparent;
}
.diff-chip.hit { background: var(--good-soft); color: var(--good); }
.echo-players { display: flex; gap: 10px; justify-content: center; margin: 14px 0; flex-wrap: wrap; }
.self-grade { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.countdown { font-family: var(--font-display); font-size: 2.6rem; color: var(--sun); text-align: center; min-height: 1.2em; }

/* ---------- Lesson mode: everything fits the viewport ----------
   In lessons/review the app chrome hides and #app becomes a 100dvh
   flex column: progress header on top, exercise in a flexible middle
   (scales up on tall screens, inner-scrolls in extreme cases), and
   the validate/continue action bar ALWAYS pinned at the bottom above
   the home indicator. No scroll-to-validate, ever. */
body.lesson-mode .topbar,
body.lesson-mode .bottomnav { display: none; }
body.lesson-mode #app {
  height: 100dvh;
  display: flex; flex-direction: column;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 0;
  overflow: hidden;
}
body.lesson-mode .lesson-progress { flex: none; margin-bottom: 8px; }
.lesson-body {
  flex: 1 1 auto; min-height: 0;
  overflow-y: auto;
  display: flex;
  -webkit-overflow-scrolling: touch;
}
.lesson-inner { margin: auto; width: 100%; padding: 4px 0; } /* centers; still scrolls when tall */
.action-bar {
  flex: none;
  padding: 10px 0 calc(env(safe-area-inset-bottom, 0px) + 12px);
}
.action-bar .feedback { margin-top: 0; margin-bottom: 10px; }
.action-bar .continue-wrap { margin-top: 0; }

/* Content scales up into tall viewports instead of leaving a void */
body.lesson-mode .flash { min-height: min(48dvh, 380px); }
body.lesson-mode .trace-wrap { width: min(84vw, 44dvh, 360px); }
body.lesson-mode .task-prompt { margin: 4px 0 2dvh; }
body.lesson-mode .task-prompt .big { font-size: clamp(1.3rem, 3.4dvh, 1.9rem); }
body.lesson-mode .options { gap: clamp(8px, 1.4dvh, 14px); }
body.lesson-mode .option { min-height: clamp(52px, 7dvh, 70px); }
body.lesson-mode .flash .uk-text { font-size: clamp(1.5rem, 3.6dvh, 2.1rem); }
body.lesson-mode .tile { font-size: clamp(1rem, 2.4dvh, 1.3rem); }
body.lesson-mode .match-btn { min-height: clamp(54px, 8dvh, 76px); }

/* Non-lesson screens keep the normal document flow (nav + padding). */

/* ---------- Tap-to-hear Ukrainian text ---------- */
/* Any Ukrainian text without transliteration is tappable to play its
   audio. Affordance: faint dotted underline in the accent color. */
.uk-tap {
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;                 /* no iOS text-selection on tap */
  -webkit-touch-callout: none;
  touch-action: manipulation;        /* no double-tap zoom delay */
  text-decoration: underline dotted;
  text-decoration-color: color-mix(in srgb, var(--sun) 55%, transparent);
  text-decoration-thickness: 1.5px;
  text-underline-offset: 3px;
  border-radius: 4px;
  transition: color 0.15s ease;
}
.uk-tap:active, .uk-tap.speaking { color: var(--sun); }

/* Small speaker zone inside quiz options: tapping it plays the option's
   audio; tapping anywhere else on the card answers. */
.opt-say {
  flex: none; margin-left: auto;
  min-width: 40px; min-height: 40px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%; color: var(--text-faint);
}
.opt-say:hover, .opt-say.speaking { color: var(--sun); background: var(--sun-soft); }
.opt-say svg { width: 18px; height: 18px; }

/* ---------- Support screen (donations) ---------- */
.qr-wrap {
  width: min(64vw, 248px); margin: 0 auto 12px;
  background: #fff; border-radius: var(--radius-sm); padding: 10px;
}
.qr-wrap canvas { display: block; width: 100%; height: auto; image-rendering: pixelated; }
.addr-row { display: flex; align-items: center; gap: 8px; }
.mono-addr {
  flex: 1; min-width: 0; overflow-wrap: anywhere;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.82rem; color: var(--text-dim);
  background: var(--bg-soft); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 8px 10px;
}
.chip-support {
  margin: 0 auto 22px; display: flex; color: var(--sun);
}

/* ---------- Gentle nudge cards (account / support) ---------- */
.nudge-card {
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 12px; margin-top: 12px;
  animation: toastIn 0.3s ease;
}
.nudge-card .nudge-text { flex: 1; font-size: 0.9rem; }
.nudge-card .btn { min-height: 40px; padding: 6px 14px; font-size: 0.9rem; }
.nudge-x {
  flex: none; min-width: 40px; min-height: 40px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-faint); border-radius: 50%;
}
.nudge-x:hover { color: var(--text); }

/* Reading mode (phrasebook, unlocked by finishing the alphabet) */
.phrase-list.no-translit .tr { display: none; }
.reading-chip { border-color: var(--good); color: var(--good); }
.reading-chip.active { background: var(--good); border-color: var(--good); color: #08240f; }

/* ============================================================
   Landing page (crawler-visible static content at /)
   Shown to first-time visitors and no-JS crawlers; hidden the
   moment the app takes over (html.app-mode, set pre-paint).
   ============================================================ */
#landing { display: none; }
html:not(.app-mode) #landing { display: block; }
html:not(.app-mode) .topbar,
html:not(.app-mode) #app,
html:not(.app-mode) .bottomnav { display: none; }

#landing { max-width: 860px; margin: 0 auto; padding: 0 20px 40px; }
.l-nav {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 0;
}
.l-brand { font-family: var(--font-display); font-weight: 700; font-size: 1.3rem; }
.l-hero { text-align: center; padding: 7vh 0 40px; }
.l-hero h1 {
  font-size: clamp(1.7rem, 5.5vw, 2.8rem);
  max-width: 22ch; margin: 0 auto 18px;
}
.l-sub { color: var(--text-dim); max-width: 58ch; margin: 0 auto 26px; font-size: 1.05rem; }
.l-cta { font-size: 1.1rem; padding: 14px 30px; }
.l-flavor { color: var(--sun); margin-top: 26px; font-size: 1.05rem; }
.l-features { padding: 30px 0; }
.l-features h2, .l-faq h2 { font-size: 1.35rem; margin-bottom: 20px; text-align: center; }
.l-grid { display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 700px) { .l-grid { grid-template-columns: 1fr 1fr; } }
.l-grid h3 { font-size: 1.02rem; margin-bottom: 8px; }
.l-grid p { color: var(--text-dim); font-size: 0.93rem; margin: 0; }
.l-faq { padding: 26px 0; max-width: 640px; margin: 0 auto; }
.l-faq details {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px; margin-bottom: 10px;
}
.l-faq summary { font-weight: 700; cursor: pointer; min-height: 24px; }
.l-faq details p { color: var(--text-dim); margin: 10px 0 0; font-size: 0.93rem; }
.l-footer { text-align: center; color: var(--text-dim); font-size: 0.9rem; padding-top: 26px; }
.l-footer .vysh { margin-bottom: 22px; }
.l-footer p { margin: 8px 0; }
.l-link {
  color: var(--info); text-decoration: underline; font-size: inherit;
  min-height: var(--tap); padding: 0 4px;
}

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