:root {
  color-scheme: light dark;
  --paper: #f7f9f8;
  --surface: #ffffff;
  --ink: #1b2833;
  --muted: #5a6b76;
  --line: #d5dedb;
  --accent: #0e7c74;
  --accent-ink: #ffffff;
  --too-hard: #e34948;
  --wrong: #eda100;
  --right: #1baf7a;
  --too-easy: #2a78d6;
  --error-bg: #fdecec;
  --error-ink: #8a1f1f;
  --new-word: #cdeee9;
  /* Progress pie: new, learned, mature. Checked for colour-blind separation on both surfaces. */
  --stat-new: #2a78d6;
  --stat-learned: #eda100;
  --stat-mature: #1baf7a;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #111a20;
    --surface: #182430;
    --ink: #e4eaed;
    --muted: #8ca0ab;
    --line: #2c3b46;
    --accent: #4db6ab;
    --accent-ink: #0b1f1d;
    --too-hard: #d64545;
    --wrong: #c98500;
    --right: #199e70;
    --too-easy: #3987e5;
    --error-bg: #3a1a1a;
    --error-ink: #f3b5b5;
    --new-word: #1f5a54;
    --stat-new: #3987e5;
    --stat-learned: #c98500;
    --stat-mature: #199e70;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

[hidden] { display: none !important; }

.bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1.5rem;
  padding: 0.9rem 1.25rem;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.bar h1 { margin: 0; font-size: 1.15rem; letter-spacing: 0.01em; }
.who { margin-left: auto; display: flex; align-items: center; gap: 0.75rem; color: var(--muted); font-size: 0.9rem; }

.modes { display: flex; gap: 0.25rem; }
.mode {
  font: inherit;
  padding: 0.35rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}
.mode[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
/* Immersion sits apart from the two modes: it changes the words on the page, not the exercise. */
.mode.immersion { border-style: dashed; font-size: 0.85rem; padding: 0.25rem 0.75rem; }
.mode.immersion[aria-pressed="true"] { border-style: solid; }

main { max-width: 58rem; margin: 0 auto; padding: 1.5rem 1.25rem 3rem; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1.5rem;
}

.signin { max-width: 26rem; margin: 0 auto; }
.signin h2 { margin: 0 0 0.25rem; font-size: 1.2rem; }
.signin p { margin: 0 0 1rem; color: var(--muted); }
.signin form { display: grid; gap: 0.7rem; }
.field { display: flex; flex-direction: column; gap: 0.3rem; }
.field label { font-weight: 600; font-size: 0.9rem; }
.signin .actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.6rem 1rem; margin-top: 0.3rem; }
.signin .actions p { margin: 0; font-size: 0.9rem; }
.signin .alternatives { display: flex; flex-direction: column; gap: 0.25rem; }
.field input, .field select {
  width: 100%;
  min-width: 0;
  font: inherit;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
}

.tracks { max-width: 44rem; margin: 0 auto; }
.tracks h2 { margin: 0 0 1rem; font-size: 1.2rem; }
.track-options { display: grid; grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr)); gap: 0.75rem; margin-bottom: 0.9rem; }
.track {
  display: flex; flex-direction: column; gap: 0.4rem;
  text-align: left;
  padding: 1rem 1.1rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
}
.track:hover { border-color: var(--accent); }
.track strong { font-size: 1.05rem; }
.track span { color: var(--muted); font-size: 0.92rem; }

.card { text-align: center; min-height: 18rem; display: flex; flex-direction: column; justify-content: center; }
.front, .back { display: flex; flex-direction: column; align-items: center; gap: 1.1rem; }

/* One line whenever possible: app.js shrinks the type to fit, and adds .wrap
   only when the sentence still overflows at the smallest size. */
/* The lang attribute picks the script: Japanese and Chinese share code points
   but not glyph shapes, so each needs its own font stack. */
:lang(ja) { font-family: "Hiragino Sans", "Yu Gothic", "Noto Sans JP", "Noto Sans CJK JP", sans-serif; }
:lang(zh) { font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", "Noto Sans CJK SC", sans-serif; }

.sentence {
  margin: 0;
  width: 100%;
  font-size: 2.2rem;
  line-height: 1.5;
  white-space: nowrap;
  overflow: hidden;
}
.sentence.wrap { white-space: normal; overflow: visible; overflow-wrap: anywhere; }
#back-text { line-height: 2.1; }  /* room for the furigana above the line */
.sentence rt { font-size: 0.48em; color: var(--muted); user-select: none; }
/* No padding or gap: a word split across a kanji and its kana (行 + こう) reads as one highlight. */
.sentence mark { background: var(--new-word); color: inherit; border-radius: 0.12em; padding: 0; }
.new-words { margin: 0; font-size: 0.95rem; }
.new-words b { font-weight: 600; }
.reading { margin: 0; font-size: 1.05rem; color: var(--muted); }
.track:disabled { opacity: 0.5; cursor: default; }
.track:disabled:hover { border-color: var(--line); }
.mode:disabled { opacity: 0.45; cursor: default; }
.translation { margin: 0; font-size: 1.1rem; color: var(--muted); }
.meta { margin: 0; font-size: 0.82rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.hint { margin: 0; font-size: 0.88rem; color: var(--muted); }

.listen { display: flex; flex-direction: column; align-items: center; gap: 0.8rem; }

button { font: inherit; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.primary {
  padding: 0.6rem 1.2rem;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  cursor: pointer;
}
.primary.wide { min-width: 12rem; }

.play {
  width: 5rem;
  height: 5rem;
  border-radius: 50%;
  border: 2px solid var(--accent);
  background: transparent;
  color: var(--accent);
  font-size: 1.8rem;
  cursor: pointer;
}
.play.small {
  width: auto;
  height: auto;
  border-radius: 999px;
  border-width: 1px;
  padding: 0.3rem 0.9rem;
  font-size: 0.9rem;
}

.link { border: 0; background: none; color: var(--accent); cursor: pointer; padding: 0; text-decoration: underline; }

/* Debug: each word with the probability the learner knows it written above; colour says where it came from. */
.word-probabilities { margin: 0; font-size: 1.15rem; line-height: 2.2; display: flex; flex-wrap: wrap; justify-content: center; gap: 0.2rem 0.7rem; }
.word-probabilities ruby { ruby-align: center; }
.word-probabilities rt { font-size: 0.6em; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); }
.word-probabilities .seen rt { color: var(--right); }
.word-probabilities .model rt { color: var(--too-easy); }
.word-probabilities .scratch rt { color: var(--too-hard); }
.word-probabilities .uncountable { color: var(--muted); }
.answers {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
  width: 100%;
  max-width: 28rem;
  margin-top: 0.4rem;
}

.answer {
  padding: 0.7rem 0.4rem;
  border: 1px solid var(--line);
  border-top: 4px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  font-weight: 600;
  cursor: pointer;
}
.answer kbd { display: block; width: max-content; margin: 0.35rem auto 0; }
.answer:disabled, .primary:disabled { opacity: 0.55; cursor: progress; }
.answer.wrong { border-top-color: var(--wrong); }
.answer.right { border-top-color: var(--right); }


kbd {
  display: inline-block;
  margin-left: 0.35rem;
  padding: 0 0.35rem;
  border: 1px solid currentColor;
  border-radius: 4px;
  font: 0.72rem ui-monospace, SFMono-Regular, Menlo, monospace;
  opacity: 0.7;
}

/* Today's counters, as a flashcard app shows them: reviews due, learning cards due, new sentences left. */
.today { margin: 1rem 0 0; display: flex; justify-content: center; gap: 1.4rem; font-size: 0.9rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.today b { font-size: 1.05rem; }
.today .review b { color: var(--right); }
.today .learning b { color: var(--wrong); }
.today .new b { color: var(--too-easy); }
.status { margin: 1.2rem 0 0.2rem; text-align: center; }
.counts { margin: 0; text-align: center; font-size: 0.85rem; color: var(--muted); font-variant-numeric: tabular-nums; }

.error {
  margin: 0 0 1rem;
  padding: 0.7rem 0.9rem;
  border-radius: 8px;
  background: var(--error-bg);
  color: var(--error-ink);
}

/* The interface-language pick sits above the sign-in form, small and out of the way. */
.signin .ui-language { align-items: flex-end; margin-bottom: 0.9rem; }
.signin .ui-language label { font-size: 0.8rem; color: var(--muted); }
.signin .ui-language select { width: auto; font-size: 0.9rem; padding: 0.3rem 0.5rem; }

.profile { max-width: 30rem; margin: 0 auto; }
.profile h2 { margin: 0 0 0.25rem; font-size: 1.2rem; }
.profile > .hint { margin-bottom: 0.6rem; }
.profile form { display: grid; gap: 0.9rem; margin-top: 0.6rem; }
.profile fieldset { margin: 0; padding: 0; border: 0; }
.profile legend { font-weight: 600; font-size: 0.9rem; padding: 0; margin-bottom: 0.4rem; }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr)); gap: 0.4rem 1rem; }
.checks label, .switch { display: flex; align-items: center; gap: 0.5rem; cursor: pointer; }
.checks label.unready { color: var(--muted); }
.checks input, .switch input { width: 1.1rem; height: 1.1rem; accent-color: var(--accent); margin: 0; }
.switch { font-weight: 600; }
.date { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.date label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.8rem; color: var(--muted); }
.date select { font: inherit; padding: 0.5rem 0.6rem; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); color: var(--ink); }
.date select.year { min-width: 6rem; }
.profile .actions { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-top: 0.3rem; }
.saved { color: var(--accent); }

/* Debug: the raw numbers behind the card, in monospace, three columns that stack on narrow screens. */
.debug { margin-top: 1rem; font-size: 0.82rem; }
.debug h2 { margin: 0 0 0.6rem; font-size: 0.95rem; }
.debug h3 { margin: 0 0 0.3rem; font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.debug-columns { display: grid; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); gap: 0.8rem 1.5rem; }
.debug dl { margin: 0; display: grid; grid-template-columns: max-content 1fr; gap: 0.15rem 0.8rem; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.debug dt { color: var(--muted); }
.debug dd { margin: 0; overflow-wrap: anywhere; }
.debug .empty { grid-column: 1 / -1; color: var(--muted); font-family: inherit; }
#toggle-debug[aria-pressed="true"] { font-weight: 600; text-decoration-style: double; }

/* Progress: one card per language, a donut with a 2px surface gap between segments, and the counts beside it. */
.progress-page { max-width: 48rem; margin: 0 auto; }
.progress-page h2 { margin: 0 0 0.25rem; font-size: 1.2rem; }
.progress-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr)); gap: 0.9rem; margin: 1rem 0; }
.language-stats { display: grid; grid-template-columns: auto 1fr; gap: 0.4rem 1rem; align-items: center; padding: 1rem; border: 1px solid var(--line); border-radius: 10px; background: var(--paper); }
.language-stats h3 { grid-column: 1 / -1; margin: 0; font-size: 1.05rem; }
.pie { width: 7rem; height: 7rem; }
.pie circle { fill: none; stroke-width: 22; }
.pie .track { stroke: var(--line); }
.pie .new { stroke: var(--stat-new); }
.pie .learned { stroke: var(--stat-learned); }
.pie .mature { stroke: var(--stat-mature); }
.legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.3rem; font-size: 0.92rem; font-variant-numeric: tabular-nums; }
.legend li { display: flex; align-items: center; gap: 0.5rem; }
.legend .swatch { width: 0.75rem; height: 0.75rem; border-radius: 3px; flex: none; }
.legend .swatch.new { background: var(--stat-new); }
.legend .swatch.learned { background: var(--stat-learned); }
.legend .swatch.mature { background: var(--stat-mature); }
.legend .count { margin-left: auto; font-weight: 600; }
.language-stats .meta { grid-column: 1 / -1; }

/* Password strength: four segments fill left to right, coloured from the answer palette. */
/* The eye sits inside the field; the input keeps room for it on the right. */
.password-wrap { position: relative; }
.password-wrap input { padding-right: 2.6rem; }
.reveal {
  position: absolute; top: 50%; right: 0.35rem; transform: translateY(-50%);
  width: 2rem; height: 2rem; padding: 0; border: 0; border-radius: 6px;
  background: transparent; color: var(--muted); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.reveal:hover { color: var(--ink); }
.reveal svg { width: 1.25rem; height: 1.25rem; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.reveal[aria-pressed="false"] .eye-off, .reveal[aria-pressed="true"] .eye { display: none; }

.strength { display: grid; gap: 0.3rem; margin-top: 0.4rem; }
#setup-block { display: grid; gap: 0.9rem; padding-bottom: 0.9rem; border-bottom: 1px solid var(--line); }
#sent p { margin: 0 0 0.6rem; }
.strength-bar { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.25rem; }
.strength-bar span { height: 0.35rem; border-radius: 999px; background: var(--line); transition: background 150ms; }
.strength[data-score="0"] span:nth-child(-n+1) { background: var(--too-hard); }
.strength[data-score="1"] span:nth-child(-n+1) { background: var(--too-hard); }
.strength[data-score="2"] span:nth-child(-n+2) { background: var(--wrong); }
.strength[data-score="3"] span:nth-child(-n+3) { background: var(--right); }
.strength[data-score="4"] span:nth-child(-n+4) { background: var(--right); }
.strength .hint { font-size: 0.82rem; }
