html { color-scheme: light; padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); -webkit-text-size-adjust: 100%; }
body { margin: 0; }
[hidden] { display: none !important; }
img { max-width: 100%; }

/* Layout: a student's own marked-up wordbook. Plain paper, ink rules, highlighter for what you got right, red pencil for misses. */
:root {
  --paper: #f3f4f0;
  --surface: #fbfbf8;
  --ink: #171716;
  --muted: #6a6b64;
  --rule: #d9dad2;
  --hover: #ecede6;
  --blue: #2340d9;
  --marker: #e8ee55;
  --on-marker: #171716;
  --red: #c8392c;
  --ui: "BIZ UDPGothic", "Hiragino Sans", "Yu Gothic", sans-serif;
  --serif: "Newsreader", "Iowan Old Style", Georgia, serif;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
  --paper: #141413; --surface: #1b1b19; --ink: #ebebe3; --muted: #9b9b92; --rule: #34342f; --hover: #23231f;
  --blue: #9caeff; --marker: #d6dc4a; --on-marker: #141413; --red: #ff7d6f; color-scheme: dark;
} }
:root[data-theme="dark"] {
  --paper: #141413; --surface: #1b1b19; --ink: #ebebe3; --muted: #9b9b92; --rule: #34342f; --hover: #23231f;
  --blue: #9caeff; --marker: #d6dc4a; --on-marker: #141413; --red: #ff7d6f; color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { background: var(--paper); color: var(--ink); font: 400 15px/1.7 var(--ui); letter-spacing: .01em; -webkit-font-smoothing: antialiased; }
button, input { font: inherit; color: inherit; letter-spacing: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
::selection { background: var(--marker); color: var(--on-marker); }
.app {
  max-width: 600px; margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 22px 120px;
  display: flex; flex-direction: column; gap: 20px;
}
.app.wide { max-width: 1240px; }

/* headings */
header { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; padding-bottom: 12px; border-bottom: 2px solid var(--ink); }
h1 { font: 700 21px/1.3 var(--ui); margin: 0; letter-spacing: .03em; }
h2 { font: 700 15px/1.4 var(--ui); margin: 0; letter-spacing: .04em; }
.masthead { align-items: flex-end; }
.brand { margin: 0; font: 700 12px/1 var(--ui); letter-spacing: .16em; color: var(--muted); }
.tally { margin: 10px 0 0; display: flex; align-items: baseline; gap: 8px; }
.tally b { font: 400 60px/.85 var(--serif); letter-spacing: -.02em; font-variant-numeric: lining-nums tabular-nums; }
.tally span { font: italic 400 19px/1 var(--serif); color: var(--muted); }
.count { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.headright { display: flex; align-items: center; gap: 14px; }

/* controls */
.btn { border: 1.5px solid var(--ink); background: transparent; border-radius: 6px; padding: 11px 16px; font-weight: 700; min-height: 48px; color: var(--ink); }
.btn.primary { background: var(--ink); color: var(--paper); }
.btn.quiet { border-color: transparent; text-decoration: underline; text-underline-offset: 5px; text-decoration-thickness: 1px; }
.btn.danger { border-color: var(--red); color: var(--red); }
.btn:not(:disabled):active { transform: translateY(1px); }
.btn:disabled { opacity: .38; cursor: default; }
.iconlink { border: 0; background: none; padding: 6px 0; font-weight: 700; font-size: 14px; text-decoration: underline; text-underline-offset: 5px; text-decoration-thickness: 1px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > .btn { flex: 1 1 130px; }
.note { color: var(--muted); font-size: 13.5px; margin: 0; }
.err { color: var(--red); font-size: 14px; margin: 0; font-weight: 700; }
.ok { margin: 0; font-size: 14px; font-weight: 700; }
.ok::before { content: ""; display: inline-block; width: .9em; height: .45em; margin-right: .45em; background: var(--marker); vertical-align: .15em; }
.section { display: flex; flex-direction: column; gap: 12px; }
.empty { padding: 40px 20px; border: 1.5px dashed var(--rule); border-radius: 6px; display: flex; flex-direction: column; gap: 12px; align-items: flex-start; }
.empty p { margin: 0; color: var(--muted); max-width: 30em; }
.vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* text fields share one look: an underline you write on */
.search { display: flex; align-items: center; gap: 14px; }
.search input, .manual input, .field input {
  width: 100%; min-width: 0; border: 0; border-bottom: 1.5px solid var(--ink); border-radius: 0;
  background: transparent; padding: 11px 2px; font-size: 16px; outline: none;
}
.search input { flex: 1; font-size: 17px; }
.search input::-webkit-search-cancel-button { -webkit-appearance: none; display: none; }
.search input:focus, .manual input:focus, .field input:focus { border-bottom-color: var(--blue); box-shadow: 0 1.5px 0 var(--blue); }
::placeholder { color: var(--muted); opacity: 1; }
.search .count { white-space: nowrap; }
.manual { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 4px 16px; }
.manual .btn { grid-column: 1 / -1; margin-top: 8px; }
.field { display: flex; flex-direction: column; gap: 2px; }
.field label { font-weight: 700; font-size: 13px; letter-spacing: .04em; }

/* word sheet: a ledger with a frozen header row and headword column */
.sheet { overflow: auto; max-height: max(300px, calc(100dvh - 300px)); border-top: 2px solid var(--ink); border-bottom: 1px solid var(--rule); background: var(--surface); }
.sheet table { border-collapse: separate; border-spacing: 0; table-layout: fixed; width: 1242px; min-width: 100%; font-size: 13.5px; line-height: 1.55; }
.sheet th, .sheet td { border-bottom: 1px solid var(--rule); border-right: 1px solid var(--rule); padding: 9px 10px; vertical-align: top; text-align: left; overflow-wrap: anywhere; background: var(--surface); }
.sheet thead th { position: sticky; top: 0; z-index: 3; border-bottom: 1px solid var(--ink); color: var(--muted); font: 700 11px/1.4 var(--ui); letter-spacing: .1em; white-space: nowrap; padding-block: 10px; }
.sheet td { position: relative; }  /* keeps visually hidden labels inside the sheet instead of widening the page */
.sheet tbody tr:hover td { background: var(--hover); }
.sheet .c-no { width: 46px; position: sticky; left: 0; z-index: 2; color: var(--muted); text-align: right; font: italic 400 13px/1.7 var(--serif); font-variant-numeric: tabular-nums; }
.sheet .c-en { width: 158px; position: sticky; left: 46px; z-index: 2; font: 600 17px/1.35 var(--serif); box-shadow: 1px 0 0 var(--ink); }
.sheet thead .c-no, .sheet thead .c-en { z-index: 4; font: 700 11px/1.4 var(--ui); font-style: normal; }
.sheet .c-ja { width: 160px; }
.sheet .c-pa { width: 200px; font: 400 14px/1.5 var(--serif); }
.sheet .c-ex { width: 320px; font: 400 14.5px/1.55 var(--serif); }
.sheet .c-xj { width: 240px; color: var(--muted); font-size: 12.5px; }
.sheet .c-sc { width: 86px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.sheet .c-del { width: 36px; padding: 4px 0; text-align: center; border-right: 0; }
.sheet thead .c-pa, .sheet thead .c-ex { font: 700 11px/1.4 var(--ui); }
.sheet tr.weak .c-sc { color: var(--red); font-weight: 700; }
.sheet td.nohit { color: var(--muted); padding: 22px 12px; position: sticky; left: 0; }
.hw { display: flex; align-items: flex-start; justify-content: space-between; gap: 6px; }
.speak { flex: none; width: 28px; height: 28px; margin-top: -1px; border-radius: 50%; border: 1px solid var(--rule); background: transparent; color: var(--muted); display: grid; place-items: center; padding: 0; }
.speak:hover { color: var(--ink); border-color: var(--ink); }
.speak svg { width: 15px; height: 15px; }
mark { background: var(--marker); color: var(--on-marker); font-weight: 600; padding: 0 2px; }
.iconbtn { border: 0; background: none; color: var(--muted); width: 32px; height: 32px; font-size: 17px; line-height: 1; border-radius: 4px; }
.iconbtn:hover { color: var(--red); }

/* paraphrases and examples */
.extras { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.paras { display: flex; flex-wrap: wrap; gap: 2px 14px; font: 400 15px/1.5 var(--serif); color: var(--muted); overflow-wrap: anywhere; }
.paras span::before { content: "≒ "; color: var(--ink); }
.ex { font: italic 400 16px/1.55 var(--serif); overflow-wrap: anywhere; }
.ex mark { font-style: italic; }
.exja { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.detail { padding: 4px 0 16px; border-bottom: 1px solid var(--rule); }

/* review before saving */
.bigphoto { width: 100%; max-height: 46vh; object-fit: contain; border-radius: 4px; background: var(--hover); display: block; }
.wordrow { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--rule); }
.wordrow .en { font: 600 18px/1.35 var(--serif); overflow-wrap: anywhere; }
.wordrow .ja { font-size: 14px; overflow-wrap: anywhere; }
.review .wordrow { grid-template-columns: 24px minmax(0, 1fr) minmax(0, 1fr); padding: 10px 0; }
.review input[type="text"] { width: 100%; min-width: 0; border: 0; border-bottom: 1px solid var(--rule); border-radius: 0; background: transparent; padding: 7px 2px; font-size: 16px; outline: none; }
.review input[type="text"]:focus { border-bottom-color: var(--blue); }
.review input[data-en] { font-family: var(--serif); font-weight: 600; }
.review input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--ink); }
.busy { display: flex; flex-direction: column; align-items: flex-start; gap: 14px; padding: 8px 0; }
.busy img { max-height: 200px; width: auto; border-radius: 4px; }

/* quiz */
.bar { height: 2px; background: var(--rule); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--ink); transition: width .3s; }
.ringcard { display: flex; flex-direction: column; align-items: flex-start; gap: 12px; padding: 26px 0 30px; border-bottom: 1px solid var(--rule); }
.progress { font: italic 400 16px/1 var(--serif); color: var(--muted); font-variant-numeric: tabular-nums; }
.prompt { font: 700 clamp(28px, 8.4vw, 42px)/1.35 var(--ui); letter-spacing: .02em; text-wrap: balance; overflow-wrap: anywhere; }
.choices { display: flex; flex-direction: column; }
.choice {
  display: flex; align-items: center; gap: 16px; min-height: 70px; width: 100%; text-align: left;
  background: none; border: 0; border-bottom: 1px solid var(--rule); border-radius: 0; padding: 12px 2px;
  font: 400 25px/1.25 var(--serif); color: var(--ink); overflow-wrap: anywhere;
}
.choice .key { flex: none; width: 26px; height: 26px; border: 1px solid var(--rule); border-radius: 50%; display: grid; place-items: center; font: 700 12px/1 var(--ui); color: var(--muted); }
.choice:not(:disabled):hover .key { border-color: var(--ink); color: var(--ink); }
.choice:not(:disabled):hover { background: var(--hover); }
.choice:disabled { cursor: default; }
.choice .word { padding: 0 3px; min-width: 0; }
.choice.right .word { color: var(--on-marker); background: linear-gradient(var(--marker), var(--marker)) no-repeat 0 50% / 100% 100%; animation: sweep .45s cubic-bezier(.3, .7, .2, 1) both; }
.choice.right .key { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.choice.wrong { color: var(--red); }
.choice.wrong .word { text-decoration: line-through; text-decoration-thickness: 2px; text-decoration-color: var(--red); }
.choice.wrong .key { border-color: var(--red); color: var(--red); }
.choice.dim { color: var(--muted); }
@keyframes sweep { from { background-size: 0% 100%; } }
@media (prefers-reduced-motion: reduce) { .choice.right .word { animation: none; } .bar i { transition: none; } }
#next-btn { scroll-margin-bottom: 100px; }
.score { font: 400 96px/.85 var(--serif); font-variant-numeric: lining-nums tabular-nums; letter-spacing: -.02em; }
.score small { font: italic 400 30px/1 var(--serif); color: var(--muted); }
.misses { display: flex; flex-direction: column; border-top: 1px solid var(--ink); }

/* bottom bar */
nav.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; background: var(--paper); border-top: 1px solid var(--ink);
  padding: 8px max(16px, env(safe-area-inset-right, 0px)) calc(8px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
}
nav.tabs > div { max-width: 568px; margin: 0 auto; display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; align-items: center; }
.tab { position: relative; isolation: isolate; border: 0; background: none; min-height: 48px; font-weight: 700; color: var(--muted); }
.tab[aria-current="page"] { color: var(--on-marker); }
.tab[aria-current="page"]::after { content: ""; position: absolute; z-index: -1; left: 50%; bottom: 10px; width: 4.2em; height: 28px; transform: translateX(-50%); background: var(--marker); }
.shoot { border: 0; background: var(--ink); color: var(--paper); min-height: 46px; border-radius: 6px; font-weight: 700; letter-spacing: .04em; }

/* learning state */
.dots { display: flex; gap: 3px; margin-top: 5px; }
.dots i { width: 8px; height: 8px; border-radius: 50%; border: 1px solid var(--muted); }
.dots i.on { background: var(--ink); border-color: var(--ink); }
.due { display: block; margin-top: 4px; font-size: 11.5px; color: var(--muted); }
.due.now { color: var(--ink); font-weight: 700; }
.queue { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border-top: 1px solid var(--ink); border-bottom: 1px solid var(--rule); margin-bottom: 4px; }
.queue div { padding: 12px 4px 10px; display: flex; flex-direction: column; gap: 2px; }
.queue div + div { border-left: 1px solid var(--rule); padding-left: 14px; }
.queue b { font: 400 40px/1 var(--serif); font-variant-numeric: lining-nums tabular-nums; }
.queue span { font-size: 12px; color: var(--muted); font-weight: 700; letter-spacing: .04em; }
.banner { margin: 0; display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 14px; padding: 10px 12px; background: var(--marker); color: var(--on-marker); font-size: 13.5px; font-weight: 700; border-radius: 4px; }
.banner .iconlink { color: inherit; font-size: 13.5px; padding: 0; }
.about a.iconlink { align-self: flex-start; color: var(--blue); }
.ringcard.intro { border-bottom: 0; padding-bottom: 4px; }
.sheet thead th.c-xj, .sheet thead th.c-sc, .sheet thead th.c-ja { font: 700 11px/1.4 var(--ui); color: var(--muted); }
.review input[data-para], .review input[data-ex] { font-family: var(--serif); }
