:root {
  color-scheme: light;
  --ink: #24211f;
  --muted: #6b625d;
  --paper: #f7f5ef;
  --surface: #fffdf8;
  --line: #d9d0c7;
  --accent: #b42b30;
  --accent-dark: #8f1f24;
  --accent-soft: #f8e7e6;
  --gold: #c78a26;
  --gold-soft: #f3e3c4;
  --blue: #2d64b3;
  --green: #2f7d4a;
  --green-soft: #e3f1e7;
  --shadow: 0 16px 42px rgba(50, 38, 31, 0.09);
  --ja: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", "YuGothic", "Meiryo", "Noto Sans JP", "Noto Sans CJK JP", sans-serif;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at top right, rgba(180, 43, 48, 0.08), transparent 30rem),
    var(--paper);
  line-height: 1.55;
}

button, input { font: inherit; }
button { min-height: 44px; }
[lang="ja"] { font-family: var(--ja); }

button:focus-visible,
input:focus-visible,
a:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid #285da8;
  outline-offset: 3px;
}

[hidden] { display: none !important; }

.site-header {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 24px 0;
}

.back-link {
  color: var(--accent-dark);
  font-weight: 700;
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}

.page-shell {
  width: min(760px, calc(100% - 32px));
  margin: 0 auto;
  padding: 38px 0 72px;
}

.intro { margin-bottom: 28px; }
.intro h1 { margin: 0; font-size: clamp(2.25rem, 7vw, 4rem); line-height: 1; letter-spacing: -0.045em; }
.intro > p:last-child { margin: 18px 0 0; color: var(--muted); font-size: 1.08rem; }
.eyebrow { margin: 0 0 8px; color: var(--accent); font-size: 0.78rem; font-weight: 800; letter-spacing: 0.13em; text-transform: uppercase; }

.panel {
  padding: clamp(20px, 5vw, 36px);
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.notice { padding: 12px 14px; border: 1px solid #dda7aa; border-radius: 10px; color: #6e161b; background: #fff0f0; }

/* ---------- Buttons ---------- */

.button {
  min-height: 44px;
  padding: 10px 18px;
  border: 2px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 800;
  line-height: 1.2;
}
.button:disabled { cursor: not-allowed; opacity: 0.4; }
.button-primary { color: #fff; border-color: var(--accent); background: var(--accent); }
.button-primary:hover:not(:disabled) { border-color: var(--accent-dark); background: var(--accent-dark); }
.button-secondary { color: var(--accent-dark); border-color: var(--accent); background: #fff; }
.button-secondary:hover:not(:disabled) { background: var(--accent-soft); }
.button-quiet { color: var(--ink); border-color: #cfc5bb; background: transparent; }
.button-quiet:hover:not(:disabled) { background: #eee9e2; }
.button-small { min-height: 38px; padding: 6px 12px; font-size: 0.92rem; }
.button-large { min-width: 170px; min-height: 52px; font-size: 1.05rem; }
.button-hero { width: 100%; min-height: 60px; border-radius: 14px; font-size: 1.15rem; }

/* ---------- Setup ---------- */

.group { margin: 0 0 26px; padding: 0; border: 0; }
.group > legend { float: left; margin-bottom: 10px; font-size: 1.15rem; font-weight: 800; }
.row-actions { display: flex; justify-content: flex-end; gap: 8px; margin-bottom: 10px; }

.set-options {
  clear: both;
  margin: 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  list-style: none;
  overflow: hidden;
}
.set-option { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; }
.set-option + .set-option { border-top: 1px solid var(--line); }
.set-option:has(input:checked) { background: var(--accent-soft); }
.set-label { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 12px; min-height: 48px; padding: 8px 4px 8px 14px; cursor: pointer; }
.set-label input, .choice input, .check input { width: 20px; height: 20px; margin: 3px 0 0; flex: none; accent-color: var(--accent); }
.set-label input { margin: 0; }
.set-name { font-weight: 750; white-space: nowrap; }
.set-kanji { letter-spacing: 0.06em; }
.set-count { margin-left: auto; color: var(--muted); font-size: 0.88rem; white-space: nowrap; }
.set-toggle {
  width: 44px;
  min-height: 44px;
  margin-right: 4px;
  border: 0;
  border-radius: 8px;
  color: var(--accent-dark);
  background: transparent;
  cursor: pointer;
  font-size: 1rem;
  transition: transform 0.15s;
}
.set-toggle:hover { background: rgba(0, 0, 0, 0.05); }
.set-toggle[aria-expanded="true"] { transform: rotate(180deg); }

.word-preview {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 4px 16px;
  margin: 0;
  padding: 2px 14px 12px 46px;
  list-style: none;
}
.word-preview li { font-weight: 700; line-height: 2.1; }
.word-preview rt { font-size: 0.62em; }

.choice-row { clear: both; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.choice {
  display: flex;
  align-items: start;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  cursor: pointer;
}
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.choice span { display: grid; }
.choice small { color: var(--muted); }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; }
.check input { margin: 0; }

.start-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
}
.deck-count { margin: 0; color: var(--muted); font-weight: 700; }

/* ---------- Study ---------- */

.study { display: grid; gap: 14px; }
.study-topbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
.study-topbar .button { white-space: nowrap; }
.counts { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 14px; margin: 0; font-size: 0.92rem; font-weight: 700; }
.count span { font-variant-numeric: tabular-nums; }
.count-fresh { color: var(--blue); }
.count-learning { color: var(--accent); }
.count-done { color: var(--green); }

.progress { height: 6px; overflow: hidden; border-radius: 99px; background: #e8e1d8; }
.progress-bar { width: 0; height: 100%; background: var(--green); transition: width 0.2s; }

.card {
  display: grid;
  justify-items: center;
  min-height: 340px;
  align-content: center;
  text-align: center;
  container-type: inline-size;
}
.card-mode { margin-bottom: 14px; }

ruby { ruby-position: over; ruby-align: center; }
rt { color: var(--accent-dark); font-weight: 600; }
.test-kanji { color: var(--accent); }

/* The word is sized to fit its longest form on one line, since ruby can't wrap. */
.word {
  margin: 0;
  font-size: clamp(1.6rem, calc(88cqi / var(--chars, 2)), 5.5rem);
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
}
.word rt { padding-bottom: 0.12em; font-size: 0.36em; letter-spacing: 0.04em; }
.card:not(.is-revealed) .word rt { visibility: hidden; }

.sentence { max-width: 34em; margin: 22px 0 0; color: var(--muted); font-size: 1.1rem; line-height: 2.4; }
.sentence mark { padding: 0 3px; white-space: nowrap; border-radius: 4px; color: var(--ink); background: var(--gold-soft); font-weight: 700; }
.sentence rt { font-size: 0.5em; }
.card:not(.is-revealed) .sentence.is-answer-only { visibility: hidden; }

.grade-bar { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.grade { display: grid; align-content: center; gap: 2px; min-height: 60px; padding: 8px 6px; border-radius: 14px; color: #fff; }
.grade small { font-size: 0.78rem; font-weight: 600; opacity: 0.9; }
.grade-again { background: var(--accent); }
.grade-good { background: var(--green); }
.grade:hover { filter: brightness(0.9); }

.keys { margin: 4px 0 0; color: var(--muted); font-size: 0.85rem; text-align: center; }
kbd { padding: 1px 6px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; background: #fff; font: inherit; font-size: 0.8rem; }

/* ---------- Done ---------- */

.done h2 { margin: 0; font-size: clamp(1.6rem, 5vw, 2.2rem); }
.done h3 { margin: 22px 0 10px; }
.done-summary { margin: 10px 0 0; outline: none; color: var(--muted); font-size: 1.05rem; }
.missed-list { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; }
.missed-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 14px;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--accent-soft);
}
.missed-word { font-size: 1.4rem; font-weight: 800; line-height: 2; }
.missed-word rt { font-size: 0.55em; }
.missed-meta { margin-left: auto; color: var(--muted); font-size: 0.85rem; }
.done-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 26px; }

@media (max-width: 640px) {
  .site-header { padding-inline: 16px; }
  .page-shell { width: calc(100% - 32px); padding-top: 26px; }
  .panel { border-radius: 16px; }
  .choice-row { grid-template-columns: 1fr; }
  .set-kanji { order: 3; flex-basis: 100%; padding-left: 32px; }
  .word-preview { padding-left: 14px; }
  .start-bar .button, .done-actions .button { width: 100%; }
  .card { min-height: 300px; }
  .counts { order: 3; flex-basis: 100%; }
  .keys { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .progress-bar, .set-toggle { transition: none; }
}
