:root {
  color-scheme: light;
  --canvas: #f6f4ef;
  --paper: #fffefa;
  --subtle: #f2efe9;
  --ink: #242624;
  --muted: #635f58;
  --line: #e4dfd6;
  --line-strong: #cfc8bc;
  --accent: #c8102e;
  --accent-hover: #a90e27;
  --red: #b51532;
  --red-wash: #fbedef;
  --red-line: #eab6bf;
  --green: #21634f;
  --green-wash: #e7f3ed;
  --green-line: #b7d9ca;
  --amber: #85491b;
  --amber-wash: #fbefdb;
  --amber-line: #e8c698;
  --banner: #282d31;
  --banner-ink: #fff9ef;
  --banner-muted: #c5c0b9;
  --banner-line: #4b4f51;
  --shadow: 0 7px 24px rgb(48 38 27 / 5%);
  --radius: 14px;
  --gutter: clamp(16px, 4vw, 46px);
  --shell: 1240px;
  --sticky-header: 66px;
  --sticky-navigation: 0px;
  --digits: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", system-ui, sans-serif;
  font-synthesis: none;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --canvas: #181d21;
  --paper: #23292d;
  --subtle: #2c3337;
  --ink: #f4eee3;
  --muted: #c1bab0;
  --line: #3b4448;
  --line-strong: #59646a;
  --accent-hover: #dc2241;
  --red: #ff9cad;
  --red-wash: #432831;
  --red-line: #82505a;
  --green: #a1dcc1;
  --green-wash: #243d35;
  --green-line: #486d5f;
  --amber: #f4c78e;
  --amber-wash: #40352b;
  --amber-line: #765b3f;
  --banner: #292e33;
  --banner-ink: #fff4e2;
  --banner-muted: #c2bcb3;
  --banner-line: #4e5559;
  --shadow: 0 7px 24px rgb(0 0 0 / 10%);
}

*, *::before, *::after { box-sizing: border-box; }

body {
  min-width: 0;
  margin: 0;
  color: var(--ink);
  background: var(--canvas);
  font-size: 15px;
  line-height: 1.55;
}

h1, h2, h3, p { margin: 0; }
svg { display: block; flex: none; }
button, input, select, textarea { color: inherit; font: inherit; }

button {
  border: 0;
  background: transparent;
  cursor: pointer;
  touch-action: manipulation;
}

button:disabled {
  opacity: .44;
  cursor: default;
}

:focus-visible {
  outline: 2px solid var(--red);
  outline-offset: 3px;
}

[hidden] { display: none !important; }
.muted { color: var(--muted); }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.skip-link {
  position: fixed;
  z-index: 11;
  inset: 8px auto auto 10px;
  transform: translateY(-150%);
  padding: 8px 12px;
  border-radius: 7px;
  background: var(--paper);
  color: var(--red);
}

.skip-link:focus { transform: translateY(0); }

.container {
  width: min(100% - var(--gutter) * 2, var(--shell));
  margin-inline: auto;
}

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: var(--shadow);
}

.button, .icon-button {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 7px 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  font-weight: 600;
  text-decoration: none;
  transition: color 140ms, background-color 140ms, border-color 140ms;
}

.icon-button { min-width: 40px; padding-inline: 8px; }
.button:hover:not(:disabled), .icon-button:hover:not(:disabled) {
  border-color: var(--line-strong);
  background: var(--subtle);
}
.button.primary, .button.danger {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}
.button.primary:hover:not(:disabled), .button.danger:hover:not(:disabled) {
  border-color: var(--accent-hover);
  background: var(--accent-hover);
}

kbd {
  display: inline-grid;
  min-width: 22px;
  min-height: 22px;
  place-items: center;
  padding-inline: 4px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--paper);
  color: var(--muted);
  font: 12px/1 var(--digits);
}

select, textarea {
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--paper);
}

input[type="checkbox"] { accent-color: var(--accent); }
::selection { color: var(--red); background: var(--red-wash); }

.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}

.header-inner, .brand, .header-actions {
  display: flex;
  align-items: center;
}

.header-inner {
  min-height: 65px;
  justify-content: space-between;
  gap: 14px;
  padding-block: 9px;
}

.brand {
  flex: 0 1 auto;
  gap: 11px;
  color: var(--ink);
  text-decoration: none;
}

.brand-mark {
  display: grid;
  flex: none;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: .01em;
}

.brand-text { display: grid; line-height: 1.25; gap: 4px; }
.brand-text strong { font-size: 15px; font-weight: 760; }
.brand-text span { font-size: 11px; color: var(--muted); }
.header-actions { flex: none; gap: 7px; }
.header-actions .button { min-height: 36px; font-size: 13px; }
.header-actions .sync-button {
  --sync-color: var(--muted);
  --sync-wash: var(--subtle);
  --sync-border: var(--line);
  gap: 6px;
  padding-inline: 11px;
  border-color: var(--sync-border);
  border-radius: 999px;
  background: var(--sync-wash);
  color: var(--sync-color);
  white-space: nowrap;
}
.sync-button[data-status="synced"] { --sync-color: var(--green); --sync-wash: var(--green-wash); --sync-border: var(--green-line); }
.sync-button[data-status="syncing"] { --sync-color: var(--amber); --sync-wash: var(--amber-wash); --sync-border: var(--amber-line); }
.sync-dot { flex: none; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.button-quiet {
  border-color: transparent;
  background: transparent;
}

.sprint-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 20px;
  margin-top: 17px;
  padding: clamp(15px, 1.5vw, 21px) clamp(20px, 3.6vw, 42px);
  border: 1px solid var(--banner-line);
  border-radius: var(--radius);
  background: var(--banner);
  color: var(--banner-ink);
}

.hero-main { min-width: 0; }

.hero-kicker {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--banner-muted);
  font-size: 12px;
  font-weight: 650;
  letter-spacing: .1em;
}

.hero-kicker::before {
  width: 3px;
  height: 13px;
  background: #f35d71;
  content: "";
}

.sprint-hero h1 {
  margin-block: 4px 5px;
  font-size: clamp(29px, 3.15vw, 44px);
  font-weight: 770;
  line-height: 1.18;
  letter-spacing: -.035em;
}

.hero-subtitle { color: var(--banner-muted); font-size: 13px; }

.hero-clock {
  display: grid;
  min-width: 236px;
  gap: 5px;
  padding-inline-start: clamp(20px, 4vw, 55px);
  border-inline-start: 1px solid var(--banner-line);
}

.clock-label { color: var(--banner-muted); font-size: 12px; }

.clock-value {
  color: #fff8ee;
  font-size: clamp(19px, 2.2vw, 29px);
  font-variant-numeric: tabular-nums;
  font-weight: 730;
  line-height: 1.28;
}

.clock-date {
  color: var(--banner-muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.stats-strip {
  margin-block: 10px 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
}

.stats {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  margin: 0;
}

.stat {
  display: grid;
  align-content: center;
  gap: 2px;
  min-width: 0;
  padding: 8px clamp(10px, 2.3vw, 24px);
}

.stat + .stat { border-inline-start: 1px solid var(--line); }
.stat dt { color: var(--muted); font-size: 12px; }
.stat dd { margin: 0; font-size: clamp(19px, 2.1vw, 26px); line-height: 1.2; font-weight: 730; font-variant-numeric: tabular-nums; }
.stat-mastered dd { color: var(--green); }
.stat-review dd { color: var(--amber); }

.mode-tabs {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 4px;
  margin-bottom: 13px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--subtle);
}

.mode-tab {
  display: flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 5px 8px;
  border: 1px solid transparent;
  border-radius: 7px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 680;
  line-height: 1.25;
  transition: color 140ms, background-color 140ms;
}

.mode-tab:hover { background: var(--paper); color: var(--ink); }
.mode-tab[aria-pressed="true"] {
  border-color: var(--red-line);
  background: var(--paper);
  color: var(--red);
  box-shadow: 0 2px 4px rgb(27 22 20 / 4%);
}

.mode-icon { flex: none; font-size: 17px; line-height: 1; }
.mode-count {
  min-width: 17px;
  padding-inline: 3px;
  border-radius: 4px;
  background: var(--amber-wash);
  color: var(--amber);
  font: 700 11px/1.55 var(--digits);
}

.workspace {
  display: grid;
  grid-template-columns: clamp(207px, 22vw, 252px) minmax(0, 1fr);
  align-items: start;
  gap: 16px;
}

.workspace.no-nav { grid-template-columns: minmax(0, 1fr); }

.main-panel {
  display: grid;
  min-width: 0;
  gap: 10px;
}

.main-panel > :empty { display: none; }

.nav-panel, .filter-panel, .question-card, .empty-card, .mock-lobby, .result-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
}

.nav-panel { position: sticky; top: calc(var(--sticky-header) + 8px); }

#main-panel, .question-card, .empty-card, .mock-lobby, .result-card, .feedback {
  scroll-margin-block-start: calc(var(--sticky-header) + var(--sticky-navigation) + 9px);
}

.exam-toolbar + .question-card { scroll-margin-block-start: calc(var(--sticky-header) + var(--sticky-navigation) + 63px); }

.nav-heading {
  display: flex;
  min-height: 49px;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 15px;
  font-size: 14px;
  font-weight: 700;
}

.nav-heading :is(h2, h3) { font-size: inherit; }
.nav-content { display: grid; gap: 11px; padding: 0 14px 14px; }

.progress-caption {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

progress {
  width: 100%;
  height: 5px;
  overflow: hidden;
  border: 0;
  border-radius: 10px;
  background: var(--subtle);
  color: var(--red);
  vertical-align: middle;
}

progress::-webkit-progress-bar { background: var(--subtle); }
progress::-webkit-progress-value { background: var(--red); border-radius: 10px; }
progress::-moz-progress-bar { background: var(--red); border-radius: 10px; }

.nav-grid {
  display: grid;
  max-height: min(236px, 42dvh);
  grid-template-columns: repeat(5, minmax(0, 1fr));
  align-content: start;
  gap: 6px;
  overflow: auto;
  padding: 4px;
  margin: 0 -4px;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}

.nav-number {
  display: grid;
  min-height: 33px;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--subtle);
  color: var(--muted);
  font: 12px/1 var(--digits);
}

.nav-number:hover { border-color: var(--red); color: var(--red); }
.nav-number.is-seen { border-color: var(--line-strong); background: var(--paper); color: var(--ink); }
.nav-number.is-mastered { border-color: var(--green-line); background: var(--green-wash); color: var(--green); }
.nav-number.is-review { border-color: var(--amber-line); background: var(--amber-wash); color: var(--amber); }
.nav-number.is-current { border-color: var(--accent); background: var(--accent); color: #fff; font-weight: 750; }
.nav-empty { grid-column: 1 / -1; font-size: 12px; }

.nav-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 9px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
}

.nav-legend span { display: inline-flex; align-items: center; gap: 4px; }
.nav-legend :is(i, b) {
  display: inline-block;
  width: 8px;
  height: 8px;
  flex: none;
  border: 1px solid var(--line-strong);
  border-radius: 2px;
  background: var(--subtle);
}

.nav-legend .is-mastered { border-color: var(--green-line); background: var(--green-wash); }
.nav-legend .is-review { border-color: var(--amber-line); background: var(--amber-wash); }
.nav-legend .is-current { border-color: var(--accent); background: var(--accent); }

.filter-panel {
  display: grid;
  gap: 6px;
  padding: 11px clamp(13px, 2vw, 20px);
}

.filter-line {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 10px;
}

.filter-label {
  flex: none;
  min-width: 3em;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.filter-head { justify-content: space-between; }
.filter-all {
  min-height: 24px;
  padding: 1px 6px;
  color: var(--red);
  font-size: 12px;
}
.filter-line > .muted, .filter-line > div > .muted { font-size: 13px; }
.filter-line > div + button { margin-inline-start: auto; }
.filter-options { gap: 5px 12px; }
.sort-control, .auto-control {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}
.auto-control { cursor: pointer; }

.chip-list {
  display: flex;
  flex: 1 0 min-content;
  flex-wrap: wrap;
  gap: 5px;
}

.chip {
  min-height: 30px;
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.chip:hover { border-color: var(--line-strong); background: var(--subtle); color: var(--ink); }
.chip[aria-pressed="true"], .chip[aria-selected="true"] {
  border-color: var(--red-line);
  background: var(--red-wash);
  color: var(--red);
  font-weight: 700;
}
.filter-panel:not(:has(.chip[data-filter][aria-pressed="false"])) .chip[data-filter][aria-pressed="true"] {
  border-color: var(--line-strong);
  background: var(--subtle);
  color: var(--ink);
}
.chip[data-filter] span { margin-inline-start: 2px; color: var(--muted); font: 11px/1 var(--digits); }

.filter-line select, .setting-row select {
  min-height: 31px;
  max-width: 100%;
  padding-inline: 7px;
  font-size: 12px;
}

label.toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding-block: 3px;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}

:is(input.toggle, .toggle input) {
  appearance: none;
  position: relative;
  width: 31px;
  height: 18px;
  flex: none;
  margin: 0;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--subtle);
  cursor: pointer;
}

:is(input.toggle, .toggle input):checked { border-color: var(--accent); background: var(--accent); }
:is(input.toggle, .toggle input)::before {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--muted);
  content: "";
  transition: transform 140ms;
}

:is(input.toggle, .toggle input):checked::before { transform: translateX(13px); background: #fff; }

.question-card, .mock-lobby, .result-card, .empty-card {
  padding: clamp(15px, 1.65vw, 24px);
  box-shadow: var(--shadow);
}

.question-top, .question-meta, .question-actions, .question-footer, .pager {
  display: flex;
  align-items: center;
}

.question-top, .question-footer { justify-content: space-between; gap: 10px; }
.question-meta { flex-wrap: wrap; gap: 6px; }
.question-actions, .pager { flex: none; gap: 6px; }
.question-actions .icon-button { min-width: 34px; min-height: 34px; padding: 4px 8px; font-size: 13px; }
.question-actions .favorite-button { font-size: 20px; line-height: 1; }
.question-actions .weak-button { min-height: 34px; padding: 4px 7px; color: var(--muted); font-size: 12px; }
.question-actions [aria-pressed="true"] { border-color: var(--amber-line); background: var(--amber-wash); color: var(--amber); }
.question-actions .weak-button:disabled { opacity: 1; }

.badge, .tag {
  display: inline-flex;
  width: fit-content;
  max-width: 100%;
  align-items: center;
  padding: 2px 7px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--subtle);
  color: var(--muted);
  font-size: 11px;
  line-height: 1.65;
}

.badge { font-weight: 700; }
.badge-red { border-color: var(--red-line); background: var(--red-wash); color: var(--red); }
.badge-review { border-color: var(--amber-line); background: var(--amber-wash); color: var(--amber); }
.badge-mastered { border-color: var(--green-line); background: var(--green-wash); color: var(--green); }
.tag { border-color: transparent; background: transparent; padding-inline: 0; }
.tag::before { margin-inline-end: 3px; content: "#"; }
.question-tags { display: flex; flex-wrap: wrap; gap: 0 10px; margin-bottom: 4px; }
.question-tags:empty { display: none; }

.question-title {
  margin-block: 10px 9px;
  font-size: clamp(18px, 1.7vw, 24px);
  font-weight: 710;
  line-height: 1.55;
  white-space: pre-line;
  overflow-wrap: anywhere;
}

.options { display: grid; gap: 7px; }
.option {
  display: grid;
  width: 100%;
  min-height: 48px;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 11px;
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  text-align: left;
  transition: border-color 140ms, background-color 140ms;
}

.option:hover:not(:disabled) { border-color: var(--red-line); background: var(--subtle); }
.option:disabled { opacity: 1; }
.option-text { overflow-wrap: anywhere; }
.option-key {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--subtle);
  color: var(--muted);
  font: 700 13px/1 var(--digits);
}

.option.is-selected, .option.is-selected .option-key { border-color: var(--red-line); background: var(--red-wash); color: var(--red); }
.option.is-correct, .option.is-correct .option-key { border-color: var(--green-line); background: var(--green-wash); color: var(--green); }
.option.is-wrong, .option.is-wrong .option-key { border-color: var(--red-line); background: var(--red-wash); color: var(--red); }
.option-mark { font-weight: 730; }

.feedback {
  margin-top: 12px;
  padding: 13px 16px;
  border: 1px solid var(--line);
  border-inline-start: 3px solid var(--red);
  border-radius: 8px;
  background: var(--subtle);
  font-size: 14px;
}

.feedback-correct, .feedback.is-correct { border-color: var(--green-line); border-inline-start-color: var(--green); background: var(--green-wash); }
.feedback-wrong, .feedback.is-wrong { border-color: var(--red-line); border-inline-start-color: var(--red); background: var(--red-wash); }
.feedback-wait { border-color: var(--amber-line); border-inline-start-color: var(--amber); background: var(--amber-wash); }
.feedback-title { margin-bottom: 4px; font-weight: 750; }
.feedback p { white-space: pre-line; overflow-wrap: anywhere; }
.feedback cite { display: block; margin-top: 6px; color: var(--muted); font-size: 12px; font-style: normal; }

.note-box {
  margin: 12px 0;
  padding: 0 0 0 1px;
  color: var(--muted);
  font-size: 13px;
}

.note-box summary { width: fit-content; cursor: pointer; }
.note-box textarea {
  display: block;
  width: 100%;
  min-height: 66px;
  margin-top: 8px;
  padding: 8px 11px;
  color: var(--ink);
  resize: vertical;
}

.question-footer { margin-top: 13px; padding-top: 12px; border-top: 1px solid var(--line); }
.question-position { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.pager .button { min-height: 36px; font-size: 13px; white-space: nowrap; }
.flash-actions, .empty-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; }
.flash-actions { margin-top: 12px; }
.flash-actions .success { border-color: var(--green-line); background: var(--green-wash); color: var(--green); }
.flash-actions .success:hover:not(:disabled) { border-color: var(--green); background: var(--green-wash); }
.flash-actions small { font-size: 11px; }

.shortcuts, .site-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 13px;
  padding: 12px 1px;
  color: var(--muted);
  font-size: 12px;
}

.shortcuts span { display: inline-flex; align-items: center; gap: 4px; }
.site-footer {
  justify-content: space-between;
  margin-top: 4px;
  padding-block: 12px 20px;
  border-top: 1px solid var(--line);
}

.empty-card, .mock-lobby, .result-card { display: grid; gap: 14px; }
.empty-card { justify-items: start; min-height: 184px; align-content: center; gap: 9px; }
.empty-card h2, .mock-lobby h2, .result-card h2 { font-size: clamp(20px, 2.2vw, 28px); line-height: 1.25; }
.empty-card p, .mock-lobby p { color: var(--muted); }

.preset-grid, .result-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 11px;
}

.preset-card, .result-metric {
  display: grid;
  align-content: start;
  justify-items: start;
  gap: 6px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--subtle);
}

.preset-card { text-align: left; }
button.preset-card:hover { border-color: var(--red-line); background: var(--red-wash); }
.preset-card h3, .preset-card strong { font-size: 17px; }
.preset-card .button { margin-top: 3px; }
.preset-card .preset-figures { color: var(--ink); font-size: 28px; line-height: 1.2; font-variant-numeric: tabular-nums; font-weight: 730; }
.preset-figures small { color: var(--muted); font-size: 14px; font-weight: 600; }
.preset-cta { margin-top: 5px; color: var(--red); font-weight: 700; }
.result-grid { grid-template-columns: repeat(auto-fit, minmax(min(115px, 100%), 1fr)); }
.result-metric strong { color: var(--red); font-size: 26px; line-height: 1.2; font-variant-numeric: tabular-nums; }

.exam-toolbar {
  position: sticky;
  top: calc(var(--sticky-header) + var(--sticky-navigation) + 5px);
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px 12px;
  padding: 9px 12px;
  border: 1px solid var(--red-line);
  border-radius: 9px;
  background: var(--red-wash);
  color: var(--red);
}

.exam-timer { font: 760 20px/1.2 var(--digits); font-variant-numeric: tabular-nums; }
.diagnosis { min-width: 0; }
.diagnosis, .review-list { display: grid; gap: 9px; }
.diagnosis table, .memory-table { width: 100%; border-collapse: collapse; text-align: left; }
.diagnosis :is(th, td), .memory-table :is(th, td) { padding: 7px 8px; border-bottom: 1px solid var(--line); }
.diagnosis :is(th, td):not(:first-child) { text-align: right; font-variant-numeric: tabular-nums; }
.diagnosis th, .memory-table th { background: var(--subtle); color: var(--ink); }
.review-question { padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--subtle); }
.review-question summary { cursor: pointer; }
.review-question p { margin-top: 6px; overflow-wrap: anywhere; white-space: pre-line; }

dialog { border: 1px solid var(--line); background: var(--paper); color: var(--ink); }
dialog::backdrop { background: rgb(14 20 24 / 54%); }
body:has(dialog[open]) { overflow: hidden; }

.drawer, .settings-dialog {
  padding: 0;
  box-shadow: 0 15px 52px rgb(0 0 0 / 19%);
}

.drawer {
  inset: 0 0 0 auto;
  width: min(530px, 100%);
  max-width: none;
  height: 100%;
  max-height: 100%;
  margin: 0;
  border-block: 0;
  border-inline-end: 0;
}

.drawer[open] {
  display: flex;
  flex-direction: column;
  animation: slide-in 170ms ease-out;
}

@keyframes slide-in {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

.settings-dialog { width: min(460px, 100% - 28px); border-radius: 13px; }
.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 15px 18px;
  border-bottom: 1px solid var(--line);
}

.dialog-header h2 { font-size: 21px; line-height: 1.3; }
.drawer-tabs { display: flex; flex-wrap: wrap; gap: 5px; padding: 10px 18px; border-bottom: 1px solid var(--line); }
.drawer-tabs .chip { flex: 1 0 auto; min-height: 34px; }
.drawer-body { flex: 1; min-height: 0; overflow: auto; padding: 14px 18px 24px; }
.drawer-body h3 { margin: 13px 0 7px; font-size: 16px; }
.drawer-body h3:first-child { margin-top: 1px; }
.drawer-body ul { margin-block: 6px 12px; padding-inline-start: 22px; }
.drawer-body li + li { margin-top: 6px; }
.drawer-body p + p { margin-top: 8px; }
.drawer-body a { color: var(--red); }
.memory-table { font-size: 14px; }
.memory-table :is(td, th) { vertical-align: top; }
.memory-table { margin-top: 10px; }
.memory-table tbody th { width: 45%; background: none; font-weight: 650; }
.memory-table td strong { color: var(--red); }

.memory-list { margin: 11px 0; }
.memory-list dt {
  margin-top: 9px;
  padding-top: 9px;
  border-top: 1px solid var(--line);
  font-weight: 720;
}
.memory-list dd, .fraction-grid dd { margin-inline-start: 0; }
.memory-list dd { margin-top: 2px; }
.fraction-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(89px, 1fr)); gap: 6px; }
.fraction-grid > * { display: flex; justify-content: space-between; gap: 6px; padding: 5px 8px; border-radius: 5px; background: var(--subtle); font: 12px/1.5 var(--digits); }
.fraction-grid dd { color: var(--red); font-weight: 700; }

.settings-body { display: grid; gap: 12px; padding: 16px 18px 21px; }
.setting-row { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; }
.setting-row small { display: block; color: var(--muted); }
.settings-body h3 { margin-top: 3px; padding-top: 11px; border-top: 1px solid var(--line); font-size: 16px; }
.settings-body .muted { font-size: 13px; }
.settings-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.sync-form { display: grid; gap: 7px; }
.sync-form label { font-weight: 650; }
.sync-key-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 7px; }
.sync-key-row input, #sync-link {
  width: 100%;
  min-width: 0;
  min-height: 40px;
  padding: 6px 9px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--paper);
  font: 16px var(--digits);
}
.sync-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 24px;
  margin: 0;
  padding: 9px 11px;
  border-radius: 8px;
  background: var(--subtle);
}
.sync-meta dt { color: var(--muted); font-size: 13px; }
.sync-meta dd { margin: 1px 0 0; font-variant-numeric: tabular-nums; }
#sync-message:empty { display: none; }
.mock-history { margin-top: 14px; }
.storage-alert {
  margin-block: 9px;
  padding: 8px 11px;
  border: 1px solid var(--amber-line);
  border-radius: 8px;
  background: var(--amber-wash);
  color: var(--amber);
}

.toast {
  position: fixed;
  z-index: 5;
  inset: auto auto max(18px, env(safe-area-inset-bottom)) 50%;
  width: max-content;
  max-width: calc(100% - 30px);
  transform: translateX(-50%);
  padding: 9px 13px;
  border: 1px solid var(--banner-line);
  border-radius: 8px;
  background: var(--banner);
  color: var(--banner-ink);
  box-shadow: var(--shadow);
  font-size: 13px;
}

.nav-toggle { display: none; }

@media (max-width: 760px) {
  .workspace { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .workspace:not(.no-nav) { --sticky-navigation: 51px; }
  .workspace:has(.nav-panel.is-open:not([hidden])) { --sticky-navigation: calc(144px + min(144px, 24dvh)); }
  .nav-panel { top: calc(var(--sticky-header) + 4px); z-index: 3; }
  .nav-heading { min-height: 43px; padding-block: 5px; }
  .nav-grid { max-height: min(144px, 24dvh); grid-template-columns: repeat(8, minmax(0, 1fr)); }
  .nav-toggle { display: inline-flex; min-height: 33px; padding-block: 3px; font-size: 13px; }
  .nav-panel:has([aria-expanded="false"]) .nav-content { display: none; }
  .mode-tab { gap: 5px; padding-inline: 4px; font-size: 12px; }
  .mode-icon { font-size: 14px; }
}

@media (max-width: 520px) {
  :root { --sticky-header: 58px; }
  .header-inner { min-height: 57px; gap: 7px; }
  .brand { gap: 7px; }
  .brand-mark { width: 35px; height: 35px; font-size: 11px; }
  .brand-text strong { font-size: 13px; }
  .brand-text span { font-size: 10px; }
  .header-actions { gap: 4px; }
  .header-actions .button { min-width: 35px; min-height: 35px; padding: 4px 7px; }
  .header-actions .sync-button { gap: 4px; font-size: 11px; }
  .brand { min-width: 0; }
  .brand-text { min-width: 0; }
  .brand-text > * { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .header-actions .action-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
  .sprint-hero { grid-template-columns: minmax(0, 1fr); gap: 11px; margin-top: 13px; padding: 15px 16px; }
  .hero-clock {
    min-width: 0;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 2px 9px;
    padding: 9px 0 0;
    border-block-start: 1px solid var(--banner-line);
    border-inline-start: 0;
  }
  .clock-value { font-size: 17px; }
  .clock-date { grid-column: 1 / -1; }
  .stats-strip { margin-block: 9px 11px; }
  .stat { padding-inline: 6px; }
  .stat dt { font-size: 10px; line-height: 1.3; overflow-wrap: anywhere; }
  .mode-tabs { margin-bottom: 10px; }
  .mode-tab { position: relative; min-height: 38px; padding-inline: 2px; }
  .mode-icon { display: none; }
  .mode-count { position: absolute; inset-block-start: -4px; inset-inline-end: 2px; }
  .question-top { flex-wrap: wrap; }
  .question-title { margin-block: 10px 7px; }
  .option-mark { font-size: 11px; }
  .question-footer { flex-wrap: wrap; }
  .pager { margin-inline-start: auto; }
  .preset-grid { grid-template-columns: minmax(0, 1fr); }
  .result-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
  .result-metric { padding: 8px; font-size: 12px; }
  .result-metric strong { font-size: clamp(18px, 5.3vw, 23px); }
}

@media (380px <= width <= 520px) {
  .header-actions .primary .action-label {
    position: static;
    width: auto;
    height: auto;
    clip-path: none;
  }
}

@media (max-width: 359px) {
  .mode-tabs { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .mode-tab { grid-column: span 2; min-height: 34px; }
  .mode-tab:nth-child(n + 4) { grid-column: span 3; }
}

@media (min-width: 1040px) {
  .filter-panel:has(.filter-head) {
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: start;
    gap: 7px 9px;
  }
  .filter-head { display: contents; }
  .filter-head .filter-label, .filter-all { min-height: 30px; align-content: center; }
  .filter-all { grid-area: 1 / 3; }
  .filter-panel > .chip-list { grid-area: 1 / 2; }
  .filter-options { grid-column: 1 / -1; }
  .chip[data-filter] { padding-inline: 6px; }
}

@media (min-width: 761px) and (max-height: 850px) {
  :root { --sticky-header: 61px; }
  .header-inner { min-height: 58px; }
  .sprint-hero { margin-top: 15px; padding-block: 15px; }
  .sprint-hero h1 { font-size: clamp(30px, 3.1vw, 42px); }
  .stats-strip { margin-block: 9px 13px; }
  .stat { padding-block: 8px; }
  .mode-tabs { margin-bottom: 12px; }
  .question-card { padding-block: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
