/* oito.cafe — one-screen phone app. Header chip row, 2x4 word grid filling
   the height, actions in the thumb zone. Cards pop to center; the quiz
   collapses the grid into a deck. Dark by default; light via data-theme. */

@font-face {
  font-family: "Nunito";
  font-style: normal;
  font-weight: 600 900;
  font-display: swap;
  src: url(fonts/nunito-latin.woff2) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Nunito";
  font-style: normal;
  font-weight: 600 900;
  font-display: swap;
  src: url(fonts/nunito-latin-ext.woff2) format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  color-scheme: dark;
  --bg: #141a33;
  --surface: #1f2547;
  --raised: #2a3160;
  --fg: #f4f1e6;
  --muted: #a9aecb;
  --line: #343c70;
  --scrim: rgba(10, 13, 30, .62);
  --primary: #f9c301;        /* flag yellow: the one main action */
  --on-accent: #141a33;
  --c-verb: #34c26b;         /* flag green */
  --c-noun: #75c3b7;         /* teal */
  --c-adj: #e3b341;          /* gold */
  --c-other: #8fb0ff;        /* flag blue, lifted for dark ground */
  --correct: #34c26b;
  --wrong: #e08a5f;          /* terracotta */
  --blob-a: rgba(6, 163, 57, .16);
  --blob-b: rgba(249, 195, 1, .10);
  --blob-c: rgba(18, 58, 104, .55);
  --shadow: 0 18px 50px rgba(0, 0, 0, .45);
  --font-word: "Nunito", ui-rounded, "SF Pro Rounded", system-ui, sans-serif;
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --r-tile: 18px;
  --r-card: 26px;
  --ease-pop: cubic-bezier(.2, .9, .25, 1.12);
  --ease-out: cubic-bezier(.2, .8, .2, 1);
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f3f5ee;
  --surface: #ffffff;
  --raised: #e9ede2;
  --fg: #1c2140;
  --muted: #5b6183;
  --line: #d6dccd;
  --scrim: rgba(28, 33, 64, .38);
  --primary: #f9c301;
  --on-accent: #1c2140;
  --c-verb: #1e8a4c;
  --c-noun: #1f8577;
  --c-adj: #a8750c;
  --c-other: #3b5bdb;
  --correct: #1e8a4c;
  --wrong: #c4623a;
  --blob-a: rgba(6, 163, 57, .10);
  --blob-b: rgba(249, 195, 1, .16);
  --blob-c: rgba(59, 91, 219, .08);
  --shadow: 0 18px 50px rgba(28, 33, 64, .18);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.4 var(--font-ui);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
body::before {
  content: "";
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(60vmax 40vmax at -10% -5%, var(--blob-a), transparent 60%),
    radial-gradient(50vmax 35vmax at 110% 20%, var(--blob-b), transparent 60%),
    radial-gradient(70vmax 50vmax at 50% 115%, var(--blob-c), transparent 60%);
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
button:focus-visible, input:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }

/* The app is pinned to the *visible* viewport (--vvh / --vvt are set from
   visualViewport), so an on-screen keyboard shrinks it instead of scrolling
   the page and pushing the quiz card out of view. */
.app {
  position: fixed; left: 0; right: 0; top: 0;
  height: var(--vvh, 100%);
  transform: translateY(var(--vvt, 0px));
  padding-inline: max(16px, calc((100% - 560px) / 2));
  padding-top: calc(10px + env(safe-area-inset-top, 0px));
  padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  display: flex; flex-direction: column; gap: 12px;
  box-sizing: border-box;
}
body.kb .app { padding-bottom: 8px; }
.view { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 12px; }

/* ---------- header ---------- */
.topbar { display: flex; align-items: center; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 36px; padding: 0 12px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line);
  font-weight: 600; font-size: 14px; white-space: nowrap;
}
.seed-chip { min-width: 0; flex: 0 1 auto; }
.seed-chip span { overflow: hidden; text-overflow: ellipsis; font-family: var(--font-word); font-weight: 800; }
.seed-chip svg { flex: none; opacity: .7; }
.spacer { flex: 1; }
.level-chip { color: var(--muted); }
.level-chip b { color: var(--fg); }
.icon-btn {
  width: 36px; height: 36px; border-radius: 999px; display: grid; place-items: center;
  background: var(--surface); border: 1px solid var(--line); flex: none;
}

/* ---------- grid ---------- */
.grid {
  flex: 1; min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: repeat(4, minmax(0, 1fr));
  gap: 10px;
  max-height: 720px;
}
.tile {
  --pos: var(--c-other);
  position: relative;
  display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 4px;
  border-radius: var(--r-tile);
  background: linear-gradient(160deg,
    color-mix(in oklab, var(--pos) 24%, var(--surface)),
    color-mix(in oklab, var(--pos) 7%, var(--surface)));
  border: 1px solid color-mix(in oklab, var(--pos) 38%, transparent);
  min-height: 0; padding: 8px;
  transition: transform .12s var(--ease-out);
  will-change: transform;
}
.tile:active { transform: scale(.96); }
.tile .word {
  font-family: var(--font-word); font-weight: 900;
  font-size: clamp(19px, 5.6vw, 28px); line-height: 1.1; letter-spacing: -.01em;
  text-align: center; overflow-wrap: anywhere;
}
.tile .art { font-weight: 700; color: var(--muted); font-size: .72em; margin-right: .18em; }
.tile .pos {
  font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--pos);
}
.tile .seen {
  position: absolute; top: 8px; right: 8px; width: 20px; height: 20px; border-radius: 999px;
  display: grid; place-items: center; background: var(--pos); color: var(--on-accent);
}
.tile .seen.pop-in { animation: badge .45s var(--ease-pop); }
@keyframes badge { 0% { transform: scale(0) } 60% { transform: scale(1.25) } 100% { transform: scale(1) } }
.tile.lifted { visibility: hidden; }
/* Cognate badge: same word in English. Outlined so it never competes with
   the part-of-speech color. */
.cog {
  display: inline-flex; align-items: center; height: 18px; padding: 0 7px; border-radius: 999px;
  font-size: 10px; font-weight: 800; letter-spacing: .07em; text-transform: uppercase;
  color: var(--fg); border: 1px solid color-mix(in oklab, var(--fg) 40%, transparent);
  background: color-mix(in oklab, var(--bg) 30%, transparent);
}
.tile .cog { position: absolute; top: 8px; left: 8px; }
.card-meta .cog, .qcard .cog { height: 24px; font-size: 11px; }
.qcard .badges { display: flex; justify-content: center; gap: 6px; }
.pos-verb { --pos: var(--c-verb); }
.pos-noun { --pos: var(--c-noun); }
.pos-adj { --pos: var(--c-adj); }
.pos-other { --pos: var(--c-other); }

.legend { display: flex; justify-content: center; gap: 14px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i { width: 8px; height: 8px; border-radius: 999px; background: var(--pos); }

/* ---------- action bar ---------- */
.actions { display: grid; grid-template-columns: 1fr 1.4fr; gap: 10px; }
.btn {
  height: 56px; border-radius: 16px; font-weight: 800; font-size: 17px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-family: var(--font-word); letter-spacing: .01em;
  transition: transform .12s var(--ease-out), filter .12s;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--primary); color: var(--on-accent); box-shadow: 0 8px 24px color-mix(in oklab, var(--primary) 30%, transparent); }
.btn-secondary { background: var(--surface); border: 1px solid var(--line); }
.btn[disabled] { opacity: .45; }

/* ---------- word card (pop open) ---------- */
/* The card sits above everything in its own fixed layer; the scrim is a
   separate element so it can fade without fading the card. */
.overlay {
  position: fixed; inset: 0; z-index: 20;
  display: grid; place-items: center;
  padding: 16px;
}
.scrim {
  position: absolute; inset: 0;
  background: var(--scrim);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
@keyframes fade { from { opacity: 0 } }
.card {
  position: relative;
  transform-origin: center;
  will-change: transform, opacity;
  --pos: var(--c-other);
  width: min(100%, 440px);
  max-height: min(82dvh, 720px);
  display: flex; flex-direction: column;
  background: var(--surface);
  border-radius: var(--r-card);
  border: 1px solid color-mix(in oklab, var(--pos) 40%, transparent);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card-head {
  padding: 18px 20px 16px;
  background: linear-gradient(170deg, color-mix(in oklab, var(--pos) 30%, var(--surface)), color-mix(in oklab, var(--pos) 6%, var(--surface)));
  touch-action: none;
  position: relative;
}
.grabber { width: 40px; height: 4px; border-radius: 99px; background: color-mix(in oklab, var(--fg) 25%, transparent); margin: -6px auto 12px; }
.card-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 13px; color: var(--muted); }
.pill {
  display: inline-flex; align-items: center; height: 24px; padding: 0 10px; border-radius: 999px;
  font-size: 11px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase;
  background: var(--pos); color: var(--on-accent);
}
.card-word {
  font-family: var(--font-word); font-weight: 900; font-size: 44px; line-height: 1.05;
  margin: 10px 0 6px; letter-spacing: -.015em; overflow-wrap: anywhere;
}
.card-word .art { color: var(--muted); font-size: .6em; font-weight: 800; margin-right: .15em; }
.say { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 15px; }
.say button {
  width: 36px; height: 36px; border-radius: 999px; display: grid; place-items: center;
  background: color-mix(in oklab, var(--pos) 25%, transparent); color: var(--fg);
}
.card-close {
  position: absolute; top: 12px; right: 12px; width: 40px; height: 40px; border-radius: 999px;
  display: grid; place-items: center; background: color-mix(in oklab, var(--bg) 35%, transparent);
}
.card-body { padding: 16px 20px 8px; overflow-y: auto; display: flex; flex-direction: column; gap: 18px; overscroll-behavior: contain; }
.sense-group { display: flex; flex-direction: column; gap: 8px; }
.sense-group + .sense-group { border-top: 1px solid var(--line); padding-top: 16px; }
.gloss { font-family: var(--font-word); font-weight: 800; font-size: 24px; line-height: 1.2; text-wrap: balance; }
.group-pos { font-size: 11px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--pos); }
.senses { margin: 0; padding-left: 18px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.br {
  display: inline-block; font-size: 10px; font-weight: 800; letter-spacing: .06em;
  padding: 1px 6px; border-radius: 6px; margin-left: 6px; vertical-align: 1px;
  background: color-mix(in oklab, var(--c-verb) 25%, transparent); color: var(--fg);
}
.example { border-left: 3px solid var(--pos); padding: 2px 0 2px 12px; }
.example .pt { font-family: var(--font-word); font-weight: 700; font-size: 17px; }
.example .en { color: var(--muted); font-size: 14px; }
.label { font-size: 11px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.seg { display: inline-grid; grid-auto-flow: column; background: var(--raised); border-radius: 12px; padding: 3px; gap: 2px; }
.seg button { height: 34px; padding: 0 14px; border-radius: 9px; font-weight: 700; font-size: 14px; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--fg); box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.conj { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin-top: 10px; font-size: 16px; }
.conj dt { color: var(--muted); }
.conj dd { margin: 0; font-family: var(--font-word); font-weight: 800; }
.card-foot { padding: 12px 20px 18px; background: var(--surface); }
.card-foot .btn { width: 100%; background: var(--pos); color: var(--on-accent); }

::view-transition-group(deck) { animation-duration: .34s; animation-timing-function: var(--ease-pop); z-index: 10; }
::view-transition-group(root) { animation-duration: .22s; }

/* ---------- seed sheet ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 25; background: var(--scrim); display: flex; align-items: flex-end; justify-content: center; }
.sheet-wrap.fade-in { animation: fade .2s ease-out; }
.sheet {
  width: min(100%, 560px); box-sizing: border-box;
  background: var(--surface); border-radius: 26px 26px 0 0; border: 1px solid var(--line); border-bottom: 0;
  padding: 10px 20px calc(20px + env(safe-area-inset-bottom, 0px));
  display: flex; flex-direction: column; gap: 16px;
  animation: rise .3s var(--ease-out);
}
@keyframes rise { from { transform: translateY(100%) } }
.sheet h2 { margin: 0; font-family: var(--font-word); font-weight: 900; font-size: 22px; }
.seed-big { font-family: var(--font-word); font-weight: 900; font-size: 28px; color: var(--primary); overflow-wrap: anywhere; }
.row { display: flex; gap: 8px; }
.field {
  flex: 1; min-width: 0; height: 48px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--bg); color: var(--fg); padding: 0 14px; font: 700 17px var(--font-word);
}
.levels { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.levels button { height: 48px; border-radius: 14px; background: var(--raised); font-weight: 800; font-family: var(--font-word); font-size: 18px; }
.levels button small { display: block; font: 600 11px var(--font-ui); color: var(--muted); }
.levels button[aria-pressed="true"] { background: var(--primary); color: var(--on-accent); }
.levels button[aria-pressed="true"] small { color: var(--on-accent); }
.hint { font-size: 13px; color: var(--muted); margin: -8px 0 0; }

/* ---------- quiz ---------- */
.quiz-top { display: flex; align-items: center; gap: 12px; }
.pips { flex: 1; display: grid; grid-template-columns: repeat(8, 1fr); gap: 5px; }
.pips i { height: 6px; border-radius: 99px; background: var(--raised); transition: background .3s; }
.pips i.on { background: var(--correct); }
.quiz-count { font-weight: 800; font-family: var(--font-word); font-variant-numeric: tabular-nums; min-width: 3.2em; text-align: right; }
.deck-area { flex: 1; min-height: 0; display: grid; place-items: center; position: relative; }
.deck { position: relative; width: min(100%, 340px); height: min(100%, 300px); }
.deck .back, .deck .qcard {
  position: absolute; inset: 0; border-radius: var(--r-card);
  border: 1px solid color-mix(in oklab, var(--pos) 38%, transparent);
  background: linear-gradient(165deg, color-mix(in oklab, var(--pos) 24%, var(--surface)), color-mix(in oklab, var(--pos) 6%, var(--surface)));
  box-shadow: var(--shadow);
}
.deck .back { transform: translate(var(--dx), var(--dy)) rotate(var(--rot)); }
.qcard {
  --pos: var(--c-other);
  display: flex; flex-direction: column; justify-content: center; gap: 10px;
  padding: 22px; text-align: center; transition: background .25s, border-color .25s;
}
.qcard .cue { font-family: var(--font-word); font-weight: 900; font-size: clamp(26px, 7.5vw, 34px); line-height: 1.15; text-wrap: balance; }
.qcard .qhint { color: var(--muted); font-size: 14px; }
.qcard .pill { align-self: center; }
.qcard .verdict { font-family: var(--font-word); font-weight: 800; font-size: 18px; min-height: 1.4em; }
.qcard .verdict b { font-weight: 900; font-size: 26px; display: block; }
.qcard .verdict s { color: var(--muted); font-weight: 700; }
.qcard.is-correct { --pos: var(--correct); }
.qcard.is-wrong { --pos: var(--wrong); }
.answer { display: flex; flex-direction: column; gap: 8px; }
.answer-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.answer .field { height: 56px; font-size: 22px; text-align: center; }
.answer .btn { padding: 0 22px; min-width: 96px; }
.qcount {
  position: absolute; top: 14px; right: 16px;
  font: 800 13px var(--font-word); color: var(--muted); font-variant-numeric: tabular-nums;
}

/* Keyboard open: drop the progress bar (the card shows the count), shrink
   the card and its type so card + input + accents fit above the keyboard. */
body.kb .quiz-top { display: none; }
body.kb .view { gap: 8px; }
body.kb .deck { height: 100%; max-height: 260px; }
body.kb .qcard { padding: 14px 16px; gap: 6px; }
body.kb .qcard .badges { display: none; }
body.kb .qcard .cue { font-size: clamp(22px, 6.4vw, 28px); }
body.kb .qcard .verdict b { font-size: 22px; }
body.kb .deck .back { transform: translate(calc(var(--dx) / 2), calc(var(--dy) / 3)) rotate(calc(var(--rot) / 2)); }
body.kb .answer .field, body.kb .answer .btn { height: 50px; }
body.kb .accents button { height: 36px; }
.accents { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.accents::-webkit-scrollbar { display: none; }
.accents button {
  flex: none; width: 40px; height: 40px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line);
  font: 800 18px var(--font-word);
}
.done { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; text-align: center; }
.done .score { font-family: var(--font-word); font-weight: 900; font-size: 72px; line-height: 1; color: var(--primary); font-variant-numeric: tabular-nums; }
.done h2 { margin: 0; font-family: var(--font-word); font-weight: 900; font-size: 26px; }
.done p { margin: 0; color: var(--muted); max-width: 30ch; }
.missed { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.missed .chip { font-family: var(--font-word); font-weight: 800; }
.done-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%; margin-top: 14px; }

.toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom, 0px)); z-index: 40;
  transform: translateX(-50%); background: var(--fg); color: var(--bg);
  padding: 10px 16px; border-radius: 999px; font-weight: 700; font-size: 14px;
  animation: fade .2s ease-out;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after, ::view-transition-group(*) { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---------- production additions ---------- */
.label.spaced { display: block; margin-bottom: 8px; }
.btn-small { height: 48px; padding: 0 18px; }

/* Loading: placeholder tiles shimmer until the word list arrives. */
.tile.skeleton { --pos: var(--raised); pointer-events: none; overflow: hidden; }
.tile.skeleton::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(100deg, transparent 30%, color-mix(in oklab, var(--fg) 7%, transparent) 50%, transparent 70%);
  background-size: 250% 100%;
  animation: shimmer 1.3s linear infinite;
}
.tile.skeleton .bar { width: 55%; height: 18px; border-radius: 8px; background: color-mix(in oklab, var(--fg) 10%, transparent); }
@keyframes shimmer { from { background-position: 150% 0 } to { background-position: -100% 0 } }

.load-error {
  grid-column: 1 / -1; grid-row: 1 / -1; align-self: center; justify-self: center;
  text-align: center; display: flex; flex-direction: column; gap: 12px; align-items: center; max-width: 32ch;
}
.load-error p { margin: 0; color: var(--muted); }

.credits { font-size: 12px; color: var(--muted); }
.credits summary { cursor: pointer; font-weight: 700; }
.credits ul { margin: 8px 0 0; padding-left: 18px; display: flex; flex-direction: column; gap: 4px; }
.credits a { color: inherit; }

#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 50; }
