:root {
  --bg: #f3efe6;
  --paper: #fffdf8;
  --ink: #1f1a17;
  --muted: #6d645c;
  --line: #e4dcd0;
  --sidebar: #243126;
  --sidebar-text: #f6f3ec;
  --sidebar-muted: #c9d4c4;
  --accent: #c4552a;
  --good: #1b6b45;
  --good-bg: #e5f6ec;
  --bad: #a3262d;
  --bad-bg: #fdecee;
  --meter: #1f7a4d;
  --shadow: 0 1px 0 rgba(80, 50, 20, 0.04), 0 16px 40px rgba(80, 50, 20, 0.06);
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Noto Sans JP", "Hiragino Sans", "Yu Gothic", "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

button, input { font: inherit; color: inherit; }

a { color: inherit; }

.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 16% 1fr;
}

html.sidebar-collapsed .app {
  grid-template-columns: 4.5rem 1fr;
}

.sidebar {
  background: var(--sidebar);
  color: var(--sidebar-text);
  padding: 16px 12px 18px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
}

.side-head {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

html.sidebar-collapsed .side-head {
  flex-direction: column;
}

.collapse-button {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 12px;
  background: transparent;
  color: var(--sidebar-text);
  display: grid;
  place-items: center;
  cursor: pointer;
}

.collapse-button:hover { background: rgba(255, 255, 255, 0.08); }

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  min-width: 0;
  font-family: "Source Serif 4", Georgia, serif;
  font-weight: 650;
  font-size: 1.25rem;
}

.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.1);
  font-size: 1rem;
}

html.sidebar-collapsed .brand-name,
html.sidebar-collapsed .nav-title,
html.sidebar-collapsed .menu-label,
html.sidebar-collapsed .learner-name {
  display: none;
}

html.sidebar-collapsed .nav-link,
html.sidebar-collapsed .brand {
  justify-content: center;
}

.menu { display: flex; flex-direction: column; gap: 6px; }

.menu-label {
  margin: 8px 8px 2px;
  color: var(--sidebar-muted);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 8px 10px;
  border-radius: 12px;
  text-decoration: none;
  color: var(--sidebar-text);
}

.nav-link:hover { background: rgba(255, 255, 255, 0.08); }

.nav-link.is-active { background: rgba(255, 255, 255, 0.14); }

.nav-emoji { font-size: 1.25rem; width: 1.5rem; text-align: center; }

.nav-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.learner-name {
  margin-top: auto;
  padding: 0 8px;
  color: var(--sidebar-muted);
  font-size: 0.85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.main {
  min-width: 0;
  max-width: none;
  padding: 20px 28px 40px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.exercise-window,
.progress-window {
  width: min(1080px, 100%);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 2;
  padding-bottom: 8px;
  background: rgba(243, 239, 230, 0.92);
  backdrop-filter: blur(8px);
}

.title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.title-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.help-link {
  flex: 0 0 auto;
  margin: 0;
  padding: 6px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  text-decoration: none;
  font-weight: 700;
  font-size: 0.92rem;
  cursor: pointer;
}

button.help-link[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--accent);
}

.help-link:hover { border-color: var(--accent); color: var(--accent); }

.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

h1 {
  margin: 4px 0 8px;
  font-family: "Source Serif 4", Georgia, serif;
  font-size: 2.4rem;
  font-weight: 650;
  letter-spacing: -0.03em;
  line-height: 1.15;
}

.hint, .queue-note, .sort-note {
  margin: 0 0 8px;
  color: var(--muted);
}

.suffix-track {
  display: flex;
  flex-wrap: nowrap;
  justify-content: center;
  gap: 8px;
  margin: 0 0 8px;
  padding: 0;
}

.suffix-track.is-split {
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.track-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
}

.track-cell {
  position: relative;
  box-sizing: border-box;
  flex: 0 0 2.85rem;
  width: 2.85rem;
  height: 2.85rem;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid #e4dcd0;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
}

.track-cell.is-locked {
  color: #a39890;
}

.track-cell.is-locked::before {
  content: "";
  position: absolute;
  top: 50%;
  left: -20%;
  width: 140%;
  height: 2px;
  background: #8a8178;
  transform: rotate(-42deg);
}

.score-line {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin: 0 0 8px;
}

.score-overall,
.score-worst {
  margin: 0;
  font-variant-numeric: tabular-nums;
}

.score-overall .meter-value {
  font-size: 1.35rem;
  font-weight: 700;
}

.score-worst {
  font-weight: 700;
  font-size: 1.15rem;
}

.score-cluster {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
}

.score-kicker {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.score-overall {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px;
}

.score-overall .score-kicker {
  margin-right: 2px;
}

.page-score {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
  margin: 0 0 4px;
  padding: 7px 2px 8px;
  border-bottom: 1px solid var(--line);
}

.page-score:has(#previous-score[hidden]) {
  display: none;
}

.page-previous {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.score-previous {
  color: var(--muted);
  font-weight: 700;
}

.perfect-label:not([hidden]) {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 12px 3px;
  border-radius: 999px;
  background: #1a5fd0;
  color: #fffdf8;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  box-shadow: 0 0 0 4px rgba(26, 95, 208, 0.16);
  animation: perfect-in 420ms ease;
}

@keyframes perfect-in {
  0% { transform: scale(0.82); opacity: 0; }
  60% { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1); }
}

.help-page {
  align-items: flex-start;
  height: auto;
  min-height: 100vh;
  overflow: auto;
}

.help-window {
  width: min(860px, 100%);
  padding-bottom: 64px;
}

.rule-card {
  margin: 0 0 16px;
  padding: 16px 16px 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.rule-kanji {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 2px;
}

.kanji-toggle {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 2px;
  min-width: 4.6rem;
  margin: 0;
  padding: 6px 10px 8px;
  border: 0;
  border-radius: 14px;
  background: transparent;
  cursor: pointer;
}

.kanji-toggle:hover,
.kanji-toggle:focus-visible {
  background: #f6efe4;
}

.kanji-toggle[aria-expanded="true"] {
  background: #fff7ee;
  box-shadow: inset 0 0 0 2px var(--accent);
}

.kanji-toggle .furi {
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 500;
  line-height: 1;
}

.kanji-toggle .kanji {
  color: var(--ink);
  font-size: clamp(2.6rem, 5vw, 3.5rem);
  font-weight: 700;
  line-height: 1.05;
}

.rule-note {
  margin: 8px 0 0;
  text-align: center;
}

.rule-examples {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  list-style: none;
  margin: 14px 0 0;
  padding: 0;
}

.rule-examples li {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 6.5rem;
  padding: 8px 12px 9px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #faf6ef;
}

.ex-prompt {
  font-weight: 700;
  font-size: 1.2rem;
  line-height: 1.2;
}

.ex-reading {
  color: var(--ink);
  font-size: 0.95rem;
}

.reading-table {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}

.reading-table table {
  width: 100%;
  border-collapse: collapse;
}

.reading-table caption {
  padding: 8px 12px 0;
  font-size: 1.15rem;
  font-weight: 700;
  text-align: left;
}

.reading-table th,
.reading-table td {
  padding: 7px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

.reading-table th {
  width: 42%;
  font-size: 1.12rem;
  font-weight: 700;
}

.reading-table td {
  color: var(--ink);
  font-size: 1.05rem;
}

.reading-table tr:nth-child(odd) {
  background: #faf6ef;
}

.rule-group.is-later {
  margin-top: 28px;
}

.later-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 14px 16px;
  border: 1px dashed #b7aea4;
  border-radius: 14px;
  background: #e4ddd3;
  color: #6a625b;
  font-weight: 700;
  cursor: pointer;
}

.later-toggle[aria-expanded="true"] {
  border-style: solid;
  border-color: var(--line);
  background: var(--paper);
  color: var(--ink);
}

.later-count {
  min-width: 1.6rem;
  padding: 1px 8px;
  border-radius: 999px;
  background: rgba(80, 60, 40, 0.08);
  text-align: center;
  font-size: 0.85rem;
}

.later-panel {
  margin-top: 14px;
}

.later-panel .rule-card {
  color: var(--ink);
}

.rule-toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 30;
  width: min(280px, calc(100vw - 40px));
  padding: 14px 16px 12px;
  border-radius: 16px;
  background: #243126;
  color: #f6f3ec;
  box-shadow: 0 16px 40px rgba(20, 30, 20, 0.28);
}

.rule-toast-kicker {
  margin: 0 0 4px;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #c9d4c4;
}

.rule-toast p { margin: 0 0 10px; }

.rule-toast-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.rule-toast a { color: #f3d7a1; font-weight: 700; }

.rule-toast button {
  border: 0;
  background: transparent;
  color: #f6f3ec;
  cursor: pointer;
  font-weight: 700;
}

.meter-wrap { margin: 8px 0 18px; }

.meter-label {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
  font-size: 0.92rem;
}

.meter-value { font-variant-numeric: tabular-nums; font-weight: 700; }

.meter {
  height: 16px;
  background: #e7e0d6;
  border-radius: 999px;
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #3d8f62, var(--meter));
  border-radius: inherit;
  transition: width 240ms ease;
}

.meter-sub { margin: 6px 0 0; color: var(--muted); font-size: 0.9rem; }

.sheet {
  background: var(--paper);
  border-radius: 18px;
  padding: 6px 22px 8px;
  box-shadow: var(--shadow);
}

.band-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 8px;
}

.band-button {
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  font-weight: 700;
  cursor: pointer;
}

.band-button[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--accent);
}

.band-button:disabled {
  opacity: 0.4;
  cursor: default;
}

.number-goal {
  margin: 0 0 10px;
  color: var(--muted);
  font-weight: 700;
}

.native-score {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  margin: 0 0 8px;
}

.native-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.questions.is-native {
  display: block;
}

.questions.is-native .q {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  margin: 0 auto;
  padding: 28px 12px 18px;
  border: 0;
}

.questions.is-native .q-prompt-wrap {
  width: auto;
  text-align: center;
}

.questions.is-native .q-prompt {
  font-size: 4.5rem;
  line-height: 1;
}

.questions.is-native .q-gloss {
  text-align: center;
}

.questions.is-native .q-field {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: min(18rem, 100%);
}

.questions.is-native .answer {
  width: 100%;
  height: 3.1rem;
  text-align: center;
  font-size: 1.45rem;
}

.questions.is-native .correction {
  min-height: 1.4em;
  text-align: center;
}

.questions {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: repeat(5, auto);
  grid-auto-flow: column;
  column-gap: 32px;
}

.q {
  display: grid;
  grid-template-columns: 1.4rem 9.4rem 11.5rem minmax(0, 1fr);
  gap: 4px 12px;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
}

.q-index {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.q-prompt-wrap { width: 9.4rem; }

.q-prompt {
  margin: 0;
  font-size: 1.55rem;
  line-height: 1.15;
  font-weight: 700;
}

.q-prompt ruby {
  ruby-position: over;
  ruby-align: center;
}

.q-prompt rt {
  color: var(--muted);
  font-size: 0.46em;
  font-weight: 500;
  line-height: 1;
  visibility: hidden;
}

html.furigana-on .q-prompt rt {
  visibility: visible;
}

.q-gloss {
  display: block;
  visibility: hidden;
  height: 1.15em;
  margin: 2px 0 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.15;
}

html.hints-on .q-gloss:not([hidden]) {
  visibility: visible;
}

html.hints-on .exercise-window[data-exercise="te"] .q-gloss {
  visibility: hidden;
}

html.translation-on .exercise-window[data-exercise="te"] .q-gloss:not([hidden]) {
  visibility: visible;
}

.hint-text,
.suffix-meaning {
  display: none;
}

html.hints-on .hint-text:not([hidden]),
html.hints-on .suffix-meaning {
  display: block;
}

.q-field { display: contents; }

.answer {
  width: 11.5rem;
  height: 2.6rem;
  font-size: 1.15rem;
  padding: 0 10px;
  border: 2px solid #ddd4c8;
  border-radius: 12px;
  background: #fff;
}

.q.is-correct .answer {
  background: var(--good-bg);
  border-color: var(--good);
  color: var(--good);
}

.q.is-wrong .answer {
  background: var(--bad-bg);
  border-color: var(--bad);
  color: var(--bad);
}

.correction {
  color: var(--bad);
  font-weight: 700;
  font-size: 1rem;
  min-width: 0;
}

.continue {
  align-self: center;
  margin-top: 10px;
  background: var(--accent);
  color: white;
  border: 0;
  border-radius: 999px;
  padding: 8px 20px;
  font-weight: 700;
  cursor: pointer;
}

.continue:hover { filter: brightness(1.05); }

.status:empty { display: none; }

.status { margin: 0; color: var(--bad); }

html:has(.exercise-page),
html:has(.exercise-page) body {
  height: 100%;
  overflow: hidden;
}

.exercise-page {
  height: 100vh;
  overflow: hidden;
  align-items: center;
  justify-content: center;
  padding: 12px 28px;
}

.exercise-window {
  max-height: 100%;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.exercise-page .topbar {
  position: static;
  background: transparent;
  backdrop-filter: none;
  padding-bottom: 0;
}

.exercise-page h1 {
  font-size: 1.7rem;
  margin: 0;
}

.exercise-page .meter-wrap {
  margin-bottom: 6px;
}

.exercise-page .meter-wrap { margin-top: 0; }

.exercise-page .sheet {
  min-height: 0;
  padding: 2px 18px 4px;
}

.chart-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: end;
  margin-top: 8px;
}

.text-button {
  border: 0;
  background: transparent;
  color: var(--accent);
  font-weight: 700;
  cursor: pointer;
  padding: 6px 0;
}

.suffix-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 12px 0 22px;
}

.suffix-row {
  display: grid;
  grid-template-columns: minmax(10rem, 1.1fr) minmax(8rem, 1.4fr) 7.5rem;
  gap: 12px;
  align-items: center;
  width: 100%;
  text-align: left;
  background: var(--paper);
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 8px 12px;
  cursor: pointer;
  box-shadow: 0 1px 0 rgba(80, 50, 20, 0.03);
}

.suffix-row.is-selected { border-color: var(--accent); }

.suffix-name { display: flex; gap: 10px; align-items: center; min-width: 0; }

.suffix-emoji { font-size: 1.2rem; }

.suffix-key { display: block; font-weight: 700; }

.suffix-meaning {
  color: var(--muted);
  font-size: 0.85rem;
}

.suffix-bar {
  display: block;
  height: 10px;
  background: #e7e0d6;
  border-radius: 999px;
  overflow: hidden;
}

.suffix-bar-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--meter);
}

.tone-low .suffix-bar-fill { background: var(--bad); }
.tone-mid .suffix-bar-fill { background: #c47b2b; }
.tone-high .suffix-bar-fill { background: var(--meter); }

.suffix-stat {
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.day-chart {
  width: 100%;
  height: auto;
  background: var(--paper);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.grid-line { stroke: #eadfce; stroke-width: 1; }
.accuracy-line { fill: none; stroke: var(--meter); stroke-width: 2.5; }
.accuracy-dot { fill: var(--meter); }
.axis-label { fill: #6d645c; font-size: 12px; font-family: "Noto Sans JP", sans-serif; }

.chart-empty { color: var(--muted); }

.day-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 16px;
  background: var(--paper);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.day-table th, .day-table td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--line);
}

.day-table th { color: var(--muted); font-weight: 600; font-size: 0.85rem; }

:focus-visible {
  outline: 3px solid #e0a15a;
  outline-offset: 2px;
}

@media (max-width: 800px) {
  .main { padding: 16px; }
  .suffix-row { grid-template-columns: 1fr; }
}
