: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 {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
  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; }
.choice-screen { display: grid; gap: 18px; }
.choice-screen .intro { margin-bottom: 0; }
.choice-title { margin: 0; font-size: clamp(1.8rem, 6vw, 2.6rem); line-height: 1.1; }
.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; }

/* ます or ています, in the header on every screen: two joined pill buttons. */
.form-switch { display: inline-flex; margin: 0; padding: 3px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); }
.form-switch label { position: relative; }
.form-switch input { position: absolute; opacity: 0; pointer-events: none; }
.form-switch span { display: inline-flex; align-items: center; min-height: 38px; padding: 4px 16px; border-radius: 999px; cursor: pointer; font-weight: 800; white-space: nowrap; }
.form-switch label:hover span { background: #eee9e2; }
.form-switch input:checked + span { color: #fff; background: var(--accent); }
.form-switch input:focus-visible + span { outline: 3px solid #285da8; outline-offset: 2px; }

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

.key-act { color: var(--accent); }
.key-self { color: var(--gold); }

/* Each quiz is one button: tap to start. */
.modes { display: grid; gap: 12px; }
.mode {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 2px 16px;
  align-items: center;
  width: 100%;
  padding: 18px 22px;
  color: inherit;
  cursor: pointer;
  font: inherit;
  text-align: left;
  transition: border-color 0.15s, transform 0.15s;
}
.mode:hover { border-color: rgba(180, 43, 48, 0.45); transform: translateY(-1px); }
.mode-name { font-size: 1.3rem; font-weight: 800; }
.mode-text { grid-row: 2; color: var(--muted); }
.mode-count { grid-row: 1 / 3; grid-column: 2; color: var(--muted); font-size: 0.88rem; font-weight: 700; white-space: nowrap; }

/* ---------- All pairs ---------- */

.list { display: grid; gap: 14px; }
.list-title { margin: 0; font-size: 1.15rem; }
/* Two pairs to a line where there's room, one on a phone. */
.pair-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 330px), 1fr)); gap: 10px; margin: 0; padding: 0; list-style: none; }
.pair-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.pair-row { padding: 8px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); }
/* One column as wide as the cell, so a long label wraps instead of widening its picture. */
.pair-cell { display: grid; grid-template-columns: minmax(0, 1fr); align-content: start; justify-items: center; gap: 4px; min-width: 0; text-align: center; }
.pair-cell img { display: block; width: 100%; height: auto; border: 1px solid var(--line); border-radius: 10px; }
.pair-cell.is-empty { border: 2px dashed var(--line); border-radius: 10px; background: #f1ece5; }
.pair-cell .pair-verb { margin: 0; font-size: 1rem; font-weight: 700; line-height: 2.1; }
.pair-part { white-space: nowrap; }
.pair-cell rt { color: var(--accent-dark); font-size: 0.5em; font-weight: 600; }
.pair-cell-transitive .pair-label { color: var(--accent); }
.pair-cell-intransitive .pair-label { color: var(--gold); }

/* Without pictures, each row is one compact line of text. */
.pair-list.no-pictures { grid-template-columns: minmax(0, 1fr); gap: 6px; }
.pair-list.no-pictures .pair-row { padding: 4px 8px; }
.pair-list.no-pictures img { display: none; }
.pair-list.no-pictures .pair-cell.is-empty { border: 0; background: transparent; }

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

.study { display: grid; gap: 14px; scroll-margin-top: 16px; }
.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; gap: 18px; text-align: center; }
.card rt { color: var(--accent-dark); font-size: 0.5em; font-weight: 600; }
.card img { display: block; width: 100%; height: auto; border-radius: 12px; }

.card-picture { width: min(100%, 340px); margin: 0; }
.card-picture img { border: 1px solid var(--line); }

.cloze { margin: 0; font-size: clamp(1.6rem, 7vw, 2.3rem); font-weight: 700; line-height: 2; }

/* A blank is as wide as its answer, which stays invisible until revealed. */
.blank {
  display: inline-block;
  min-width: 1.6em;
  min-height: 0;
  margin: 0 2px;
  padding: 0 6px;
  border: 0;
  border-bottom: 3px solid var(--ink);
  border-radius: 6px 6px 0 0;
  color: inherit;
  background: var(--gold-soft);
  cursor: pointer;
  font: inherit;
  line-height: 1.6;
}
.blank:hover { background: #ecd6ab; }
.blank-answer { visibility: hidden; }
.blank.is-revealed { background: transparent; cursor: default; }
.card.is-revealed .blank.verb-form { cursor: pointer; }
.blank.is-revealed .blank-answer { visibility: visible; color: var(--accent-dark); }

/* The pair's pictures, always 他 on the left and 自 on the right. */
.choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; width: 100%; }
.choice {
  position: relative;
  display: grid;
  gap: 4px;
  padding: 6px 6px 4px;
  border: 3px solid var(--line);
  border-radius: 16px;
  color: var(--muted);
  background: #fff;
  cursor: pointer;
  font: inherit;
  font-weight: 800;
}
.choice:hover:not(:disabled) { border-color: var(--gold); }
.choice:disabled { cursor: default; }
.choice-label { font-size: 1.05rem; }
.choice.is-correct { border-color: var(--green); color: var(--green); background: var(--green-soft); }
.choice.is-wrong { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.card.is-revealed .choice:not(.is-correct):not(.is-wrong) { opacity: 0.45; }

/* Read by screen readers only. */
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* A tick over the right picture and a cross over a wrong pick. */
.choice-mark {
  position: absolute;
  top: 10px;
  right: 10px;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 3px solid #fff;
  border-radius: 50%;
  color: #fff;
  font-size: 1.6rem;
  font-weight: 900;
  line-height: 1;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}
.choice-mark:empty { display: none; }
.choice.is-correct .choice-mark { background: var(--green); }
.choice.is-wrong .choice-mark { background: var(--accent); }

/* Shown with the answer: both verbs of the pair, the asked one in red. */
.pair-block { display: grid; gap: 2px; justify-items: center; margin-top: -4px; }
.pair-line { display: flex; flex-wrap: wrap; justify-content: center; gap: 2px 22px; margin: 0; color: var(--muted); font-size: 1.2rem; line-height: 2.1; }
/* Answered, a verb is tapped to see it in the other form. */
.verb-form:not(.blank) { min-height: 0; padding: 0; border: 0; color: inherit; background: none; font: inherit; line-height: inherit; }
.card.is-revealed .verb-form { cursor: pointer; text-decoration: underline dotted 2px; text-decoration-color: var(--line); text-underline-offset: 0.3em; }
.card.is-revealed .verb-form:hover { text-decoration-color: currentColor; }
/* The answer's verb becomes a tinted chip with a swap mark. */
.card.is-revealed .cloze .verb-form { border-radius: 10px; background: var(--gold-soft); text-decoration: none; }
.card.is-revealed .cloze .verb-form:not(.blank) { padding: 0 8px; }
.card.is-revealed .cloze .verb-form:hover { background: #ecd6ab; }
.card.is-revealed .cloze .verb-form::after { content: "⇄" / ""; display: inline-grid; place-items: center; width: 1.5em; height: 1.5em; margin-left: 0.35em; border-radius: 50%; color: #fff; background: var(--gold); font-size: 0.5em; font-weight: 900; line-height: 1; vertical-align: 0.45em; }
.cloze-verb:disabled { cursor: default; }
.pair-verb.is-asked { color: var(--accent-dark); font-weight: 800; }
.pair-label { margin-right: 6px; padding: 1px 6px; border: 1px solid currentColor; border-radius: 6px; font-size: 0.75em; font-weight: 700; vertical-align: 0.15em; }

.action-dock {
  position: sticky;
  bottom: 0;
  z-index: 2;
  margin: 0 -8px;
  padding: 12px 8px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to bottom, rgba(247, 245, 239, 0), var(--paper) 22px);
}

.grade-bar { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.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.25rem; font-weight: 800; line-height: 2; }
.missed-word rt { color: var(--accent-dark); 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; }
  .card { gap: 14px; padding: 16px 14px; }
  .mode { padding: 16px 18px; }
  .choices { gap: 8px; }
  .choice-mark { top: 8px; right: 8px; width: 34px; height: 34px; font-size: 1.2rem; }
  .pair-line { font-size: 1.05rem; }
  .pair-row { gap: 6px; padding: 6px; }
  .done-actions .button { width: 100%; }
  .counts { order: 3; flex-basis: 100%; }
  .keys { display: none; }
}

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