/* Kernewek: "Gorse and Heather". Mobile first, one thumb. */

:root {
  --plum: #2B1B3D;
  --cream: #FFF9EC;
  --heather: #5B2A86;
  --heather-dark: #47206A;
  --gorse: #F2C230;
  --sea: #1E6B5C;
  --sea-dark: #17564A;
  --pale: #E9DDF5;
  --muted: #5E5368;
  --error: #B4233A;
  --white: #FFFFFF;
  --line: #D9CBE8;
  --radius: 18px;
  --radius-sm: 12px;
  --pad: 16px;
  --font-head: Georgia, "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Palatino, serif;
  --font-body: "Nunito", ui-rounded, "SF Pro Rounded", "Hiragino Maru Gothic ProN", "Varela Round", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --nav-h: 64px;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--cream);
  color: var(--plum);
  font-family: var(--font-body);
  font-size: 1.0625rem;
  line-height: 1.5;
  overflow-wrap: break-word;
}

h1, h2, h3 { font-family: var(--font-head); line-height: 1.2; margin: 0; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; margin: 28px 0 12px; }
h3 { font-size: 1.1rem; margin: 20px 0 8px; }
p { margin: 0 0 12px; }
ul { margin: 0; padding: 0; list-style: none; }
a { color: var(--heather); }
[hidden] { display: none !important; }
[lang="kw"] { font-family: var(--font-head); }

.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip {
  position: absolute; left: 8px; top: -80px; z-index: 20;
  background: var(--plum); color: var(--white); padding: 12px 16px; border-radius: var(--radius-sm);
}
.skip:focus { top: 8px; }

/* Visible focus everywhere */
:focus-visible { outline: 3px solid var(--plum); outline-offset: 3px; border-radius: 6px; }
h1:focus, h2:focus, main:focus { outline: none; }
.btn-primary:focus-visible, .nav-link:focus-visible, .answer:focus-visible { box-shadow: 0 0 0 3px var(--cream), 0 0 0 6px var(--plum); outline: none; }

/* ---------- layout ---------- */

#app { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
#main { flex: 1; display: flex; flex-direction: column; width: 100%; }

.page {
  width: 100%;
  padding: var(--pad) var(--pad) calc(var(--nav-h) + 32px + env(safe-area-inset-bottom, 0px));
}

.round {
  flex: 1; display: flex; flex-direction: column; width: 100%;
  min-height: 100vh; min-height: 100dvh;
  padding: 8px var(--pad) calc(16px + env(safe-area-inset-bottom, 0px));
}

.icon { display: inline-flex; flex: none; }
.icon svg { display: block; }

/* ---------- bottom navigation ---------- */

#nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; background: var(--white); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.in-round #nav { display: none; }
.nav-link {
  flex: 1; min-height: var(--nav-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: 0.8rem; font-weight: 700;
  border-top: 4px solid transparent;
}
.nav-link[aria-current="page"] { color: var(--heather); border-top-color: var(--heather); }

/* ---------- headers ---------- */

.brand { display: flex; align-items: center; gap: 14px; margin: 4px 0 16px; }
.mark svg { display: block; width: 100%; height: 100%; }
.brand-mark { width: 56px; height: 56px; flex: none; }
.brand-name { font-size: 2rem; letter-spacing: 0.01em; }
.strap { margin: 0; color: var(--muted); }

.page-head { display: flex; align-items: center; gap: 8px; margin: 0 0 16px; min-height: 48px; }

.icon-btn {
  flex: none; width: 48px; height: 48px; display: inline-flex; align-items: center; justify-content: center;
  border: 0; border-radius: 50%; background: var(--pale); color: var(--plum); cursor: pointer; text-decoration: none; padding: 0;
}
.audio-btn { background: var(--sea); color: var(--white); }

/* ---------- cards and text ---------- */

.card {
  display: block; background: var(--pale); border-radius: var(--radius); padding: 18px;
  color: var(--plum); text-decoration: none; margin: 0 0 16px;
}
.eyebrow { font-size: 0.8rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: var(--heather); margin: 0 0 6px; }
.kw-big { font-size: 2rem; font-weight: 700; margin: 0 0 4px; line-height: 1.15; }
.kw-huge { font-size: 2.6rem; font-weight: 700; margin: 0 0 4px; line-height: 1.1; }
.kw-mid { font-size: 1.25rem; font-weight: 700; }
.say { margin: 0 0 8px; color: var(--plum); }
.say-label { color: var(--muted); font-size: 0.95rem; }
.say-text { font-weight: 700; letter-spacing: 0.02em; }
.meaning { margin: 0; font-size: 1.1rem; }
.meaning-big { font-size: 1.35rem; font-weight: 700; margin: 8px 0; }
.late { margin: 0; color: var(--muted); font-size: 1rem; }
.note { margin: 10px 0 0; padding: 10px 12px; background: var(--cream); border-radius: var(--radius-sm); font-size: 1rem; }
.hint { color: var(--muted); margin: 6px 0; font-size: 1rem; }
.lead { font-size: 1.25rem; font-family: var(--font-head); }
.notice { background: var(--gorse); color: var(--plum); border-radius: var(--radius-sm); padding: 10px 14px; font-weight: 700; font-size: 0.95rem; }
.check-label { color: var(--muted); font-size: 0.95rem; border-left: 4px solid var(--gorse); padding-left: 10px; }
.label { color: var(--muted); }
.link { display: inline-block; padding: 12px 0; font-weight: 700; }
.footer-line { color: var(--muted); text-align: center; margin: 32px 0 0; font-size: 0.95rem; }
.word-top { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 14px; }
.word-top .audio-btn { align-self: center; }

.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 12px 0 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-weight: 700; }
.more { margin-top: 8px; }
.ipa { font-family: "Charis SIL", "Doulos SIL", "Gentium Plus", "Noto Sans", "Segoe UI", system-ui, sans-serif; font-size: 1.1rem; }

/* ---------- buttons ---------- */

.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; min-height: 52px;
  padding: 12px 18px; border: 2px solid transparent; border-radius: 999px;
  font: inherit; font-weight: 800; text-align: center; text-decoration: none; cursor: pointer;
  background: var(--pale); color: var(--plum);
}
.btn-big { min-height: 60px; font-size: 1.2rem; }
.btn-primary { background: var(--heather); color: var(--white); }
.btn-primary:active { background: var(--heather-dark); }
.btn-secondary { background: var(--sea); color: var(--white); }
.btn-secondary:active { background: var(--sea-dark); }
.btn-quiet { background: transparent; color: var(--heather); border-color: var(--line); }
.btn-danger { background: var(--error); color: var(--white); }
.btn-outline-danger { background: transparent; color: var(--error); border-color: var(--error); }
.actions { display: flex; flex-direction: column; gap: 10px; margin: 16px 0; }
.actions-end { margin: auto 0 0; padding-top: 16px; }
.card .btn { margin-top: 10px; }

/* ---------- home ---------- */

.today { border: 2px solid transparent; }
.today:active { border-color: var(--heather); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 6px; text-align: center; display: flex; flex-direction: column; justify-content: center; min-height: 76px; }
.stat strong { font-family: var(--font-head); font-size: 1.5rem; line-height: 1.15; }
.stat .stat-level { font-size: 1.05rem; }
.stat span { color: var(--muted); font-size: 0.82rem; }
.progress .hint { margin: 8px 0 0; }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile {
  display: flex; flex-direction: column; gap: 4px; min-height: 104px; padding: 14px;
  background: var(--white); border: 2px solid var(--line); border-radius: var(--radius); color: var(--plum); text-decoration: none;
}
.tile:active { border-color: var(--heather); }
.tile-icon { color: var(--heather); width: 40px; height: 40px; border-radius: 12px; background: var(--pale); align-items: center; justify-content: center; }
.tile-title { font-weight: 800; }
.tile-sub { color: var(--muted); font-size: 0.9rem; }
.tile:last-child:nth-child(odd) { grid-column: 1 / -1; }

.badges { display: flex; flex-direction: column; gap: 8px; }
.badge { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-radius: var(--radius-sm); border: 2px dashed var(--line); color: var(--muted); }
.badge > span:last-child { display: flex; flex-direction: column; }
.badge.is-earned { background: var(--gorse); border: 2px solid var(--plum); color: var(--plum); }
.badge-how { font-size: 0.9rem; }

/* ---------- lists ---------- */

.list { display: flex; flex-direction: column; gap: 8px; }
.row {
  display: flex; align-items: center; gap: 12px; min-height: 60px; padding: 10px 14px;
  background: var(--white); border: 1px solid var(--line); border-radius: var(--radius-sm); color: var(--plum); text-decoration: none;
}
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row-title { font-weight: 800; font-size: 1.15rem; }
.row-sub { color: var(--muted); font-size: 0.95rem; }
.row .bar { margin-top: 6px; }

.status { flex: none; font-size: 0.85rem; font-weight: 800; padding: 4px 10px; border-radius: 999px; border: 2px solid var(--line); color: var(--muted); background: var(--white); }
.status-learning { border-color: var(--heather); color: var(--heather); }
.status-learned { background: var(--sea); border-color: var(--sea); color: var(--white); }
p.status { display: inline-block; margin: 14px 0 0; }

.bar { height: 10px; background: var(--line); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: var(--sea); border-radius: 999px; transition: width 0.3s ease; }

/* ---------- rounds ---------- */

.round-top { display: flex; align-items: center; gap: 10px; min-height: 56px; }
.round-meter { flex: 1; min-width: 0; }
.round-title { font-size: 1rem; margin-bottom: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.round-progress { margin: 0; color: var(--muted); font-weight: 700; font-size: 0.95rem; min-width: 3.5em; text-align: right; }
.round-body { flex: 1; display: flex; flex-direction: column; }
.question { flex: 1; display: flex; flex-direction: column; }
.prompt { flex: 1; display: flex; flex-direction: column; justify-content: center; padding: 16px 0; min-height: 120px; }
.prompt-en { font-size: 1.8rem; font-weight: 800; margin: 0; }
.learn-card { margin-top: 16px; padding: 22px 18px; }

.answers { display: flex; flex-direction: column; gap: 10px; }
.answer {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%; min-height: 60px;
  padding: 12px 16px; border: 2px solid var(--heather); border-radius: var(--radius); background: var(--white); color: var(--plum);
  font: inherit; font-size: 1.15rem; font-weight: 700; text-align: left; cursor: pointer;
}
.answer[lang="kw"], .answer [lang="kw"] { font-size: 1.25rem; }
.answer:active { background: var(--pale); }
.answer[aria-disabled="true"] { cursor: default; }
.answer.is-right { background: var(--sea); border-color: var(--sea); color: var(--white); }
.answer.is-wrong { background: var(--white); border-color: var(--error); border-style: dashed; border-width: 3px; color: var(--error); }
.answer.is-dim { border-color: var(--line); color: var(--muted); }
.answer-mark { display: inline-flex; align-items: center; gap: 6px; flex: none; }
.answer-tag { font-size: 0.8rem; font-weight: 800; }

.feedback { margin-top: 14px; }
.feedback:empty { display: none; }
.verdict { display: flex; align-items: center; gap: 8px; margin: 0 0 6px; font-size: 1.2rem; font-family: var(--font-head); }
.verdict.is-right { color: var(--sea); }
.verdict.is-wrong { color: var(--error); }
.reveal { margin: 0 0 12px; }
.reveal-line { margin: 0 0 2px; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; }
.reveal-en { font-weight: 700; }
.reveal .say { margin: 0; }

/* flashcards */
.flash-wrap { flex: 1; display: flex; flex-direction: column; gap: 12px; padding-top: 16px; }
.flashcard {
  width: 100%; min-height: 240px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  border: 3px solid var(--heather); font: inherit; text-align: center; cursor: pointer; margin: 0;
}
.flashcard.is-flipped { border-color: var(--line); cursor: default; min-height: 160px; }
.flash-back { text-align: center; background: var(--white); border: 2px solid var(--line); border-radius: var(--radius); padding: 16px; }
.flash-hint { margin-top: 12px; }

/* match pairs */
.match-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding-top: 12px; }
.match-col { display: flex; flex-direction: column; gap: 10px; }
.tile-pair {
  position: relative; width: 100%; min-height: 64px; padding: 8px 10px; display: flex; align-items: center; justify-content: center; gap: 6px;
  border: 2px solid var(--heather); border-radius: var(--radius-sm); background: var(--white); color: var(--plum);
  font: inherit; font-weight: 700; font-size: 1.05rem; text-align: center; cursor: pointer;
}
.tile-en { border-color: var(--sea); }
.tile-pair[aria-pressed="true"] { background: var(--gorse); border-color: var(--plum); border-width: 3px; }
.tile-pair.is-matched { background: var(--pale); border-color: var(--line); color: var(--muted); cursor: default; }
.tile-pair.is-miss { border-color: var(--error); border-style: dashed; border-width: 3px; }
.match-msg { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 16px 0 0; min-height: 48px; font-size: 1.05rem; }
.match-msg.is-right { color: var(--sea); }
.match-msg.is-wrong { color: var(--error); }

/* decoder */
.place-en { font-size: 1.5rem; font-weight: 800; margin: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.chip { display: flex; flex-direction: column; padding: 8px 14px; border-radius: var(--radius-sm); background: var(--pale); border: 2px solid transparent; min-width: 72px; }
.chip.is-current { border-color: var(--heather); background: var(--white); }
.chip.is-done { background: var(--gorse); }
.chip-kw { font-weight: 700; font-size: 1.15rem; }
.chip-en { font-size: 0.95rem; }
.part-ask { font-size: 1.1rem; margin: 0 0 10px; }
.decode-area { display: flex; flex-direction: column; }
.decode-reveal { margin-bottom: 12px; }

/* result */
.result { flex: 1; display: flex; flex-direction: column; text-align: center; padding-top: 12px; }
.result .badges, .result .a2hs { text-align: left; margin-top: 12px; }
.medal { margin: 8px auto 16px; width: 168px; height: 168px; border-radius: 50%; background: var(--gorse); border: 4px solid var(--plum); display: flex; flex-direction: column; align-items: center; justify-content: center; }
.medal-mark { width: 64px; height: 64px; }
.medal-level { margin: 6px 0 0; font-weight: 800; font-size: 0.95rem; }
.medal-day { margin: 0; font-family: var(--font-head); font-size: 1.2rem; font-weight: 700; }
.result-title { font-size: 1.8rem; margin: 0 0 8px; }
.result-score { font-size: 1.15rem; margin: 0; }
.a2hs h3 { margin-top: 0; }
.a2hs p { margin: 0; }

/* settings */
.code {
  width: 100%; margin: 10px 0 0; padding: 12px; border: 2px solid var(--heather); border-radius: var(--radius-sm);
  background: var(--white); color: var(--plum); font-family: ui-monospace, "Cascadia Mono", Menlo, Consolas, monospace; font-size: 0.95rem;
  word-break: break-all; resize: vertical;
}
.msg { margin: 10px 0 0; font-weight: 700; min-height: 1.5em; }
.msg:empty { min-height: 0; margin: 0; }
.confirm { background: var(--white); border: 2px solid var(--error); border-radius: var(--radius-sm); padding: 14px; margin-top: 10px; }
.card h2 { margin-top: 0; }
.sources { list-style: disc; padding-left: 20px; }
.sources li { margin-bottom: 6px; }
.boot { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 12px; padding-top: 20vh; }

/* ---------- desktop: centred column ---------- */

@media (min-width: 700px) {
  #main > .page, #main > .round { max-width: 640px; margin-left: auto; margin-right: auto; }
  #nav { left: 50%; right: auto; width: 640px; transform: translateX(-50%); border: 1px solid var(--line); border-bottom: 0; border-radius: var(--radius) var(--radius) 0 0; }
  .btn:hover, .answer:hover:not([aria-disabled="true"]), .tile:hover, .row:hover { filter: brightness(0.96); }
  .round { min-height: 0; padding-top: 24px; }
  .prompt { flex: none; }
  .actions-end { margin-top: 24px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
