:root {
  --bg: #f3ead8;
  --surface: #faf6ec;
  --ink: #1c1914;
  --muted: #6e6558;
  --primary: #b93a2f;
  --primary-fg: #faf6ec;
  --gold: #b08948;
  --moss: #2f6b4f;
  --moss-fg: #f4efe4;
  --shadow:
    0 0 0 1px rgba(28, 25, 20, 0.06),
    0 1px 2px -1px rgba(28, 25, 20, 0.06),
    0 2px 8px 0 rgba(28, 25, 20, 0.04);
  --shadow-hover:
    0 0 0 1px rgba(28, 25, 20, 0.1),
    0 2px 6px -1px rgba(28, 25, 20, 0.08),
    0 6px 16px 0 rgba(28, 25, 20, 0.06);
  --sans: "Source Sans 3", ui-sans-serif, system-ui, sans-serif;
  --serif: "Noto Serif JP", ui-serif, serif;
}

html.dark {
  --bg: #14110e;
  --surface: #1e1a16;
  --ink: #f3ead8;
  --muted: #a89b88;
  --primary: #e05548;
  --primary-fg: #faf3e8;
  --gold: #d4b06a;
  --moss: #5dae7d;
  --moss-fg: #101612;
  --shadow: 0 0 0 1px rgba(243, 234, 216, 0.08);
  --shadow-hover: 0 0 0 1px rgba(243, 234, 216, 0.15);
}

* { box-sizing: border-box; }
html { -webkit-font-smoothing: antialiased; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  background-image:
    radial-gradient(ellipse 90% 50% at 8% -8%, rgba(185, 58, 47, 0.07), transparent 55%),
    radial-gradient(ellipse 70% 40% at 100% 0%, rgba(176, 137, 72, 0.08), transparent 50%);
}
html.dark body {
  background-image:
    radial-gradient(ellipse 90% 50% at 8% -8%, rgba(224, 85, 72, 0.14), transparent 55%),
    radial-gradient(ellipse 70% 40% at 100% 0%, rgba(212, 176, 106, 0.07), transparent 50%);
}
button:not(:disabled), [role="button"]:not(:disabled) { cursor: pointer; }
button { font: inherit; color: inherit; }
h1, h2, h3 { font-family: var(--serif); letter-spacing: -0.02em; text-wrap: balance; margin: 0; }
p { text-wrap: pretty; }
a { color: inherit; text-decoration: none; }

.wrap { max-width: 64rem; margin: 0 auto; padding: 0 1rem; }
@media (min-width: 640px) { .wrap { padding: 0 1.5rem; } }

.header {
  position: sticky; top: 0; z-index: 20;
  border-bottom: 1px solid color-mix(in oklab, var(--ink) 8%, transparent);
  background: color-mix(in oklab, var(--bg) 80%, transparent);
  backdrop-filter: blur(12px);
}
.header-inner { display: flex; align-items: center; justify-content: space-between; height: 3.5rem; }
.brand { display: flex; align-items: baseline; gap: .5rem; font-family: var(--serif); font-size: 1.25rem; }
.brand small { color: var(--primary); font-size: .875rem; }
.nav { display: flex; align-items: center; gap: .25rem; }
.nav a, .icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  height: 2.25rem; padding: 0 .65rem; border-radius: 999px;
  color: var(--muted); font-size: .875rem; border: 0; background: transparent;
}
.nav a:hover, .nav a.active, .icon-btn:hover { color: var(--ink); }
.icon-btn { width: 2.25rem; padding: 0; }

main { padding: 2rem 0 4rem; }
.hero { max-width: 36rem; margin-bottom: 2.5rem; }
.kicker { font-size: .8rem; font-weight: 600; letter-spacing: .18em; text-transform: uppercase; color: var(--primary); }
.hero h1 { font-size: clamp(2rem, 5vw, 3rem); line-height: 1.15; margin: .6rem 0; }
.muted { color: var(--muted); }
.section { margin-top: 2.5rem; }
.section h2 { font-size: 1.15rem; margin-bottom: .75rem; }

.grid-3 { display: grid; gap: .75rem; }
@media (min-width: 640px) { .grid-3 { grid-template-columns: repeat(3, 1fr); } }
.card {
  background: var(--surface); box-shadow: var(--shadow); border-radius: 1rem;
  padding: 1rem; text-align: left; border: 0; width: 100%;
  transition: box-shadow 150ms ease;
}
.card:hover { box-shadow: var(--shadow-hover); }
.card.active { box-shadow: var(--shadow); outline: 2px solid color-mix(in oklab, var(--primary) 70%, transparent); outline-offset: 2px; }
.card .ja { font-family: var(--serif); font-size: 1.6rem; }
.card .en { font-weight: 600; margin-top: .4rem; }

.row-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .75rem; align-items: end; margin-bottom: .75rem; }
.chips { display: flex; flex-wrap: wrap; gap: .5rem; }
.chip, .pill {
  height: 2.25rem; min-width: 3.5rem; padding: 0 .8rem; border-radius: 999px;
  border: 0; background: var(--surface); box-shadow: var(--shadow); font-size: .875rem;
}
.chip.active, .pill.active { background: var(--ink); color: var(--bg); }
.chip.accent { background: var(--primary); color: var(--primary-fg); }
.linkish { background: none; border: 0; color: var(--muted); font-size: .8rem; text-decoration: underline; text-underline-offset: 3px; }

.rows { display: grid; grid-template-columns: repeat(2, 1fr); gap: .5rem; }
@media (min-width: 640px) { .rows { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 768px) { .rows { grid-template-columns: repeat(5, 1fr); } }
.row-btn {
  position: relative; min-height: 5rem; border: 0; border-radius: .75rem;
  background: var(--surface); box-shadow: var(--shadow); padding: .65rem .75rem; text-align: left;
}
.row-btn.active { outline: 2px solid color-mix(in oklab, var(--ink) 70%, transparent); outline-offset: 2px; }
.row-btn .lbl { font-size: .7rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.row-btn .kana { font-family: var(--serif); font-size: 1.1rem; line-height: 1.2; }
.check { position: absolute; top: .4rem; right: .4rem; color: var(--primary); font-size: .75rem; }

.split { display: grid; gap: 2rem; }
@media (min-width: 640px) { .split { grid-template-columns: 1fr 1fr; } }

.actions { display: flex; flex-wrap: wrap; gap: .75rem; justify-content: flex-end; margin-top: 2.5rem; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  height: 3rem; padding: 0 1.25rem; border-radius: .75rem; border: 0; font-weight: 600;
  background: var(--primary); color: var(--primary-fg); box-shadow: var(--shadow);
}
.btn:disabled { opacity: .45; }
.btn.ink { background: var(--ink); color: var(--bg); }
.btn.ghost { background: transparent; color: var(--ink); box-shadow: none; }
.btn.moss { background: var(--moss); color: var(--moss-fg); }
.btn.xl { height: 3.5rem; padding: 0 1.5rem; }
.btn.block { width: 100%; }

.quiz { max-width: 36rem; margin: 0 auto; }
.quiz-top { display: flex; justify-content: space-between; color: var(--muted); font-size: .875rem; margin-bottom: .75rem; }
.bar { height: 4px; background: color-mix(in oklab, var(--ink) 10%, transparent); border-radius: 999px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--primary); }
.timer { display: flex; align-items: center; gap: .75rem; margin-top: .5rem; }
.timer .bar { flex: 1; height: 6px; }
.timer .bar > span { background: var(--gold); }
.timer.urgent .bar > span { background: var(--primary); }
.timer .sec { width: 2.5rem; text-align: right; font-family: var(--serif); font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.prompt {
  margin-top: 1.5rem; background: var(--surface); border-radius: 1rem; box-shadow: var(--shadow);
  padding: 2.5rem 1.25rem; text-align: center;
}
.prompt.ok { outline: 2px solid color-mix(in oklab, var(--moss) 50%, transparent); }
.prompt.bad { outline: 2px solid color-mix(in oklab, var(--primary) 50%, transparent); }
.glyph { font-family: var(--serif); font-size: clamp(3.5rem, 12vw, 5.5rem); line-height: 1; margin: 1rem 0; }
.hear {
  display: inline-flex; align-items: center; gap: .4rem; height: 2.75rem; padding: 0 .9rem;
  border-radius: 999px; border: 0; background: var(--bg); box-shadow: var(--shadow);
}
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; margin-top: 1rem; }
.choice {
  min-height: 5rem; border: 0; border-radius: 1rem; background: var(--surface);
  box-shadow: var(--shadow); font-family: var(--serif); font-size: 2.2rem;
}
input[type="text"], input[type="number"] {
  width: 100%; height: 3rem; border: 0; border-radius: .75rem; background: var(--surface);
  box-shadow: var(--shadow); padding: 0 1rem; color: var(--ink); font: inherit;
}
input:focus { outline: 2px solid color-mix(in oklab, var(--primary) 35%, transparent); }
.custom-row { display: flex; align-items: center; gap: .5rem; margin-top: .5rem; }
.custom-row input { width: 6rem; }

.results { max-width: 36rem; margin: 0 auto; text-align: center; }
.score { font-family: var(--serif); font-size: 4rem; margin: .4rem 0; }
.miss { text-align: left; background: var(--surface); border-radius: 1rem; box-shadow: var(--shadow); overflow: hidden; }
.miss li { display: flex; gap: 1rem; align-items: center; padding: .75rem 1rem; border-top: 1px solid color-mix(in oklab, var(--ink) 8%, transparent); list-style: none; }
.miss ul { margin: 0; padding: 0; }
.tile {
  width: 3.5rem; height: 3.5rem; display: grid; place-items: center;
  background: var(--bg); border-radius: .6rem; font-family: var(--serif); font-size: 1.7rem; border: 0;
}
.grid-ans { display: grid; grid-template-columns: repeat(5, 1fr); gap: .5rem; }
@media (min-width: 640px) { .grid-ans { grid-template-columns: repeat(8, 1fr); } }
.ans { aspect-ratio: 1; display: grid; place-items: center; border-radius: .6rem; font-family: var(--serif); font-size: 1.2rem; border: 0; box-shadow: var(--shadow); }
.ans.ok { background: color-mix(in oklab, var(--moss) 16%, var(--surface)); }
.ans.no { background: color-mix(in oklab, var(--primary) 16%, var(--surface)); }

.chart-row { display: grid; grid-template-columns: 4.5rem 1fr; gap: .5rem; margin-bottom: .5rem; }
.chart-lab { display: flex; align-items: center; padding: 0 .5rem; background: color-mix(in oklab, var(--ink) 5%, transparent); border-radius: .6rem; font-size: .7rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.chart-cells { display: grid; grid-template-columns: repeat(5, 1fr); gap: .5rem; }
.cell {
  min-height: 4rem; border: 0; border-radius: .75rem; background: var(--surface);
  box-shadow: var(--shadow); display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.cell b { font-family: var(--serif); font-size: 1.5rem; font-weight: 500; }
.cell span { font-size: .7rem; color: var(--muted); }

.hidden { display: none !important; }
.ok { color: var(--moss); }
.bad { color: var(--primary); }
.center { text-align: center; }
.mt { margin-top: 1rem; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
@media (min-width: 640px) { .stat-grid { grid-template-columns: repeat(4, 1fr); } }
.stat { display: flex; gap: .75rem; align-items: center; background: var(--surface); box-shadow: var(--shadow); border-radius: 1rem; padding: .75rem; border: 0; width: 100%; text-align: left; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
