@font-face {
  font-family: "Nunito";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("../fonts/nunito-600.woff2") format("woff2");
}
@font-face {
  font-family: "Nunito";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("../fonts/nunito-700.woff2") format("woff2");
}
@font-face {
  font-family: "Nunito";
  font-style: normal;
  font-weight: 800;
  font-display: swap;
  src: url("../fonts/nunito-800.woff2") format("woff2");
}

:root {
  --bg: #f6f1e7;
  --ink: #241c16;
  --muted: #6d6258;
  --line: #e4d9c8;
  --lapis: #1a4f86;
  --lapis-dark: #12365e;
  --lapis-soft: #e7eef7;
  --gold: #c8963e;
  --gold-soft: #fbf3df;
  --good: #1d7a45;
  --good-soft: #e5f6ec;
  --bad: #b42318;
  --bad-soft: #fdecea;
  --card: #fffdf8;
  --shadow: 0 10px 30px rgba(36, 28, 22, 0.06);
  --tab: calc(64px + env(safe-area-inset-bottom));
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  min-height: 100dvh;
  font-family: "Nunito", "Segoe UI", sans-serif;
  font-weight: 600;
  color: var(--ink);
  background:
    radial-gradient(900px 420px at 50% -10%, #d5e3f4, transparent 55%),
    #e7e2d8;
}
button, input { font: inherit; color: inherit; }
button { touch-action: manipulation; }
:focus-visible { outline: 3px solid var(--lapis); outline-offset: 2px; }
.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}
.latin {
  font-family: Palatino, "Palatino Linotype", "Iowan Old Style", Georgia, serif;
  font-weight: 700;
}

.app {
  width: min(480px, 100%);
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--bg);
  position: relative;
}
@media (min-width: 560px) {
  body { padding: 24px 0; }
  .app {
    min-height: calc(100dvh - 48px);
    border-radius: 28px;
    overflow: hidden;
    box-shadow: 0 24px 70px rgba(18, 54, 94, 0.16);
  }
}

#view { padding-bottom: var(--tab); }
.tabs:empty { display: none; }
body:has(.tabs:empty) #view { padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
body.lesson-mode { overflow: hidden; height: 100dvh; background: var(--bg); }
body.lesson-mode .app { height: 100dvh; min-height: 0; border-radius: 0; box-shadow: none; }
body.lesson-mode #view { height: 100%; padding-bottom: 0; overflow: auto; }

.tabs {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: min(480px, 100%);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: #fffdf9;
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 5;
}
.tabs a {
  text-decoration: none;
  text-align: center;
  padding: 10px 0 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.02em;
}
.tabs a.on { color: var(--lapis); }

.screen { padding: 18px 18px 28px; }
.topbar { padding-top: calc(12px + env(safe-area-inset-top)); }
.brand { display: flex; align-items: center; gap: 10px; }
.brand img { width: 36px; height: 36px; border-radius: 10px; }
.brand h1 { font-size: 22px; line-height: 1; margin: 0; font-weight: 800; }
.brand p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.welcome { text-align: center; }
.welcome h1 { font-size: 34px; margin: 8px 0; }
.welcome p { color: var(--muted); line-height: 1.45; }
.hero-mark { width: 88px; height: 88px; border-radius: 22px; margin-top: 18px; }

.stats-row { display: flex; justify-content: space-between; gap: 12px; margin: 16px 0 8px; }
.pill, .goal {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
}
.flame { width: 16px; height: 16px; color: var(--gold); display: inline-flex; }
.flame svg { width: 16px; height: 16px; }
.goal b { display: block; font-size: 14px; line-height: 1.1; }
.goal span { color: var(--muted); font-size: 11px; }
.ring { width: 36px; height: 36px; display: inline-flex; }
.ring svg { width: 36px; height: 36px; transform: rotate(-90deg); }
.ring-track { fill: none; stroke: var(--line); stroke-width: 4; }
.ring-value { fill: none; stroke: var(--lapis); stroke-width: 4; stroke-linecap: round; }

.seg-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 14px 0 4px; }
.seg, .choice-row .seg {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 12px;
  padding: 8px 6px;
  font-size: 13px;
  font-weight: 800;
}
.seg.on { background: var(--lapis); color: white; border-color: var(--lapis); }
.choice-row { display: flex; gap: 8px; }
.choice-row .seg { flex: 1; }

.continue, .btn {
  display: block;
  width: 100%;
  border: 0;
  border-radius: 16px;
  padding: 14px 16px;
  background: var(--lapis);
  color: white;
  font-weight: 800;
  text-align: center;
  text-decoration: none;
}
.continue { text-align: left; margin-top: 12px; }
.continue small, .continue em { display: block; font-style: normal; font-weight: 700; opacity: 0.85; font-size: 12px; }
.continue strong { display: block; font-size: 18px; margin: 2px 0; }
.btn.ghost { background: transparent; color: var(--lapis); border: 2px solid var(--lapis); }
.btn.bad { background: var(--bad); }
.btn:disabled { opacity: 0.45; }
.stack { display: grid; gap: 8px; }
.text-btn {
  border: 0;
  background: transparent;
  color: var(--lapis);
  font-weight: 800;
  padding: 8px 0;
}
.section-label {
  margin: 18px 0 8px;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.path { display: grid; gap: 8px; }
.unit {
  display: flex;
  gap: 12px;
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 16px;
  padding: 12px;
}
.unit h2 { margin: 0; font-size: 16px; }
.unit p { margin: 3px 0 0; color: var(--muted); font-size: 13px; line-height: 1.35; }
.unit.current { border-color: var(--lapis); box-shadow: 0 0 0 3px var(--lapis-soft); }
.unit.locked { opacity: 0.72; }
.marker {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--lapis-soft);
  color: var(--lapis);
  font-weight: 800;
  flex: none;
}
.unit.done .marker { background: var(--good); color: white; }
.bar { height: 6px; background: var(--line); border-radius: 99px; margin-top: 8px; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--lapis); }
.fine, .hint { color: var(--muted); font-size: 13px; line-height: 1.45; }
.banner {
  background: var(--gold-soft);
  border-radius: 12px;
  padding: 10px 12px;
  margin-top: 10px;
  font-size: 14px;
}
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px 14px;
  margin-top: 10px;
}
.back { color: var(--lapis); font-weight: 800; text-decoration: none; font-size: 14px; }
.eyebrow { margin: 10px 0 0; color: var(--gold); font-size: 12px; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; }
.prompt { font-size: 26px; line-height: 1.25; margin: 6px 0; }
.prompt.compact { font-size: 20px; }
.hero-word {
  font-family: Palatino, "Palatino Linotype", "Iowan Old Style", Georgia, serif;
  font-size: clamp(32px, 9vw, 48px);
  line-height: 1.15;
  margin: 6px 0;
}
.hero-word.long { font-size: clamp(22px, 5.6vw, 32px); }
.gloss { font-size: 20px; margin: 0 0 6px; }

.chart { display: grid; gap: 0; margin-top: 12px; border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
.chart div {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 12px;
  align-items: center;
  padding: 10px 14px;
  background: var(--card);
  border-top: 1px solid var(--line);
}
.chart div:first-child { border-top: 0; }
.chart b { font-size: 20px; }
.chart small { color: var(--muted); text-align: right; }

.lesson { min-height: 100%; display: flex; flex-direction: column; }
.lesson-top {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: calc(10px + env(safe-area-inset-top)) 14px 8px;
}
.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 0;
  background: transparent;
  font-size: 28px;
  line-height: 1;
}
.track { height: 10px; background: var(--line); border-radius: 99px; overflow: hidden; }
.track span { display: block; height: 100%; background: var(--lapis); }
.hearts { display: flex; gap: 2px; }
.heart { width: 18px; height: 18px; color: #e7d3d0; display: inline-flex; }
.heart svg { width: 18px; height: 18px; }
.heart.on { color: var(--bad); }
.combo { text-align: center; color: var(--gold); font-weight: 800; margin: 0; }
.lesson-body { flex: 1; padding: 8px 18px 16px; }
.choices { display: grid; gap: 8px; }
.choice {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border-radius: 14px;
  border: 2px solid var(--line);
  background: var(--card);
}
.choice .key {
  width: 22px;
  flex: none;
  color: var(--muted);
  font-weight: 800;
}
.choice.selected { border-color: var(--lapis); background: var(--lapis-soft); }
.choice.good { border-color: var(--good); background: var(--good-soft); }
.choice.bad { border-color: var(--bad); background: var(--bad-soft); }
.answer-input {
  width: 100%;
  border: 2px solid var(--line);
  background: white;
  border-radius: 14px;
  padding: 14px;
  font-size: 20px;
}
.macron-row { display: flex; gap: 6px; margin-top: 8px; }
.macron-row button {
  flex: 1;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 10px;
  padding: 8px 0;
  font-family: Palatino, Georgia, serif;
  font-size: 18px;
}
.letter-hint { min-height: 1.2em; }
.match { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.match button {
  width: 100%;
  min-height: 48px;
  text-align: left;
  border: 2px solid var(--line);
  background: var(--card);
  border-radius: 12px;
  padding: 8px 10px;
}
.match button.sel { border-color: var(--lapis); background: var(--lapis-soft); }
.match button.done { opacity: 0.45; }
.match button.flash { border-color: var(--bad); background: var(--bad-soft); }
.dock {
  padding: 12px 18px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--card);
}
.dock.good { background: var(--good-soft); }
.dock.bad { background: var(--bad-soft); }
.dock-note { margin: 0; color: var(--muted); text-align: center; }
.feedback-copy strong { font-size: 18px; }
.feedback-copy p { margin: 4px 0; white-space: pre-wrap; }
.xp-pop { margin-left: 8px; color: var(--lapis); }
.sheet {
  position: fixed;
  inset: 0;
  background: rgba(36, 28, 22, 0.45);
  display: grid;
  align-items: end;
  z-index: 6;
}
.sheet .card { margin: 0 auto 24px; width: min(440px, calc(100% - 24px)); }

.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }
.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px;
  text-align: center;
}
.stat b { display: block; font-size: 20px; }
.stat span { color: var(--muted); font-size: 12px; }
.skill-row .who, .who { display: flex; justify-content: space-between; gap: 8px; }
.meters { display: grid; gap: 4px; margin-top: 8px; }
.meter { display: grid; grid-template-columns: 72px 1fr 32px; gap: 8px; align-items: center; font-size: 12px; color: var(--muted); }
.meter-track { height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; }
.meter-fill { display: block; height: 100%; background: var(--lapis); }
.search, .file-btn { width: 100%; }
.search {
  border: 2px solid var(--line);
  background: white;
  border-radius: 14px;
  padding: 12px 14px;
  margin: 8px 0;
}
.lex details { border-top: 1px solid var(--line); padding: 8px 0; }
.lex summary { font-weight: 800; cursor: pointer; }
.lex a, .weak a {
  display: block;
  text-decoration: none;
  color: inherit;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}
.lex a small, .weak a small { display: block; color: var(--muted); }
.result-score { font-size: 64px; margin: 0; font-weight: 800; }
.result-score small { font-size: 24px; }
.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.confetti i {
  position: absolute;
  left: var(--x);
  top: -10px;
  width: 8px;
  height: 14px;
  background: var(--c);
  animation: fall 0.9s ease-in forwards;
}
@keyframes fall { to { transform: translateY(100dvh) rotate(180deg); opacity: 0.2; } }
@media (prefers-reduced-motion: reduce) {
  .confetti i { animation: none; }
}
