:root {
  color-scheme: light;
  --bg: #e9e5d9;
  --surface: #f6f3ea;
  --surface-2: #e0d9c6;
  --ink: #1b1813;
  --muted: #5b5445;
  --line: #c6bca4;
  --accent: #8a3d00;
  --accent-ink: #ffffff;
  --focus: #1a4fd6;
  --rubber: #16130d;
  --rubber-2: #221d13;
  --stencil: #ffd23f;
  --stencil-dim: #b99a3e;
  --fresh: #1e6b2e;
  --normal: #2f5d62;
  --inspect: #8a5a00;
  --replace: #a31616;
  --chip-bg: #efe8d3;
  --radius: 12px;
  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "DejaVu Sans Mono", monospace;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #12110d;
  --surface: #1d1b15;
  --surface-2: #2a2619;
  --ink: #f0e8d5;
  --muted: #bcae8c;
  --line: #48402c;
  --accent: #ffc53d;
  --accent-ink: #241a04;
  --focus: #9db9ff;
  --rubber: #0c0b08;
  --rubber-2: #191610;
  --stencil: #ffd23f;
  --stencil-dim: #9d8142;
  --fresh: #7ed08a;
  --normal: #7fc4cc;
  --inspect: #ffbe3c;
  --replace: #ff9d9d;
  --chip-bg: #242014;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  line-height: 1.6;
  font-size: 1.0625rem;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  height: 3rem;
  padding: 0 1rem;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  white-space: nowrap;
}

.topbar .home { font-weight: 800; color: var(--ink); text-decoration: none; flex: none; letter-spacing: -0.01em; }
.topnav { display: flex; gap: 0.25rem; overflow-x: auto; scrollbar-width: none; }
.topnav::-webkit-scrollbar { display: none; }
.topnav a { flex: none; padding: 0.5rem 0.6rem; color: var(--muted); text-decoration: none; border-radius: 6px; }
.topnav a[aria-current="true"] { color: var(--ink); font-weight: 700; }
.topbar .spacer { flex: 1; }
.topbar .chip { flex: none; color: var(--accent); font-weight: 600; }
.icon-btn {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}
.icon-btn svg { display: block; }
.icon-btn svg[hidden] { display: none; }

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

main {
  max-width: 60rem;
  margin: 0 auto;
  padding: 0 1.25rem 4rem;
}

section { scroll-margin-top: 3.75rem; }

.hero { padding: 2.75rem 0 0.5rem; max-width: 46rem; }
.hero h1 {
  font-size: clamp(2.1rem, 5.4vw, 3.4rem);
  line-height: 1.05;
  letter-spacing: -0.02em;
  margin: 0 0 1rem;
  text-wrap: balance;
}
.deck { font-size: 1.2rem; color: var(--muted); margin: 0 0 1rem; max-width: 40rem; }
.deck strong { color: var(--ink); }
.answer-line {
  font-family: var(--font-mono);
  font-size: 1.02rem;
  background: var(--rubber);
  color: var(--stencil);
  border-radius: var(--radius);
  padding: 0.9rem 1.1rem;
  margin: 1.25rem 0 0;
  max-width: 40rem;
  letter-spacing: 0.01em;
}
.answer-line strong { font-weight: 700; }

/* ---------- decoder ---------- */

.decoder { padding-top: 1.5rem; }
.dot-form { display: grid; gap: 1rem; }
.input-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 1rem 1.5rem;
}
.field { display: grid; gap: 0.35rem; }
.field label { font-weight: 700; font-size: 1.05rem; }
#dot-in {
  font-family: var(--font-mono);
  font-size: clamp(2.4rem, 7vw, 3.4rem);
  font-weight: 700;
  letter-spacing: 0.22em;
  text-indent: 0.22em;
  text-align: center;
  text-transform: uppercase;
  width: 4.6em;
  max-width: 78vw;
  padding: 0.12em 0.1em;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
}
.presets { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.presets span { color: var(--muted); font-size: 0.95rem; }
.presets button {
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  min-height: 44px;
  min-width: 44px;
  padding: 0.45rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--chip-bg);
  color: var(--ink);
  cursor: pointer;
}
.presets button:hover { border-color: var(--ink); }
.hint { color: var(--muted); font-size: 0.95rem; margin: 0; max-width: 34rem; }

/* ---------- result card ---------- */

.card {
  margin-top: 1.25rem;
  background: var(--rubber);
  color: #f2ead2;
  border-radius: 16px;
  padding: clamp(1.25rem, 3.5vw, 2rem);
  box-shadow: 0 1.25rem 2.5rem rgba(0, 0, 0, 0.22);
}
[data-theme="dark"] .card { border: 1px solid var(--line); box-shadow: none; }
.card-top {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.25rem 1rem;
  border-bottom: 1px dashed #4d4530;
  padding-bottom: 0.9rem;
  margin-bottom: 1rem;
}
.code-echo {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: clamp(1.8rem, 5vw, 2.6rem);
  letter-spacing: 0.12em;
  color: var(--stencil);
  margin: 0;
}
.week-line { margin: 0; font-size: 1.1rem; color: #d8cba4; }
.card-grid { display: grid; gap: 1.1rem; }
.card-label {
  font-size: 0.82rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--stencil-dim);
  margin: 0 0 0.2rem;
}
.interval-line {
  margin: 0;
  font-size: clamp(1.35rem, 3.6vw, 1.9rem);
  font-weight: 800;
  letter-spacing: -0.01em;
  color: #fff8e2;
}
.strip { display: grid; grid-template-columns: repeat(7, 1fr); gap: 0.35rem; margin-top: 0.6rem; }
.day {
  background: var(--rubber-2);
  border: 1px solid #3d3520;
  border-radius: 8px;
  padding: 0.35rem 0;
  text-align: center;
}
.day.edge { border-color: var(--stencil-dim); }
.day-name { display: block; font-size: 0.72rem; letter-spacing: 0.08em; color: #b7a67c; }
.day-num { display: block; font-family: var(--font-mono); font-size: 1.05rem; color: #fff8e2; }
.age-line { margin: 0; font-size: 1.15rem; color: #fff8e2; }
.verdict-row { display: flex; flex-wrap: wrap; gap: 0.6rem 1rem; align-items: center; }
.verdict {
  display: inline-block;
  margin: 0;
  font-weight: 800;
  font-size: 1.02rem;
  padding: 0.45rem 0.95rem;
  border-radius: 999px;
  background: var(--stencil);
  color: #241a04;
}
.verdict[data-band="fresh"] { background: #8fd694; color: #0d2f13; }
.verdict[data-band="normal"] { background: #a9d6db; color: #0e2a2e; }
.verdict[data-band="inspect"] { background: var(--stencil); color: #241a04; }
.verdict[data-band="replace"] { background: #ff8f8f; color: #3d0a0a; }
.verdict-note { margin: 0; color: #d8cba4; font-size: 0.98rem; max-width: 34rem; }
.timeline-wrap { margin-top: 0.25rem; }
#timeline { width: 100%; height: auto; display: block; }
.tl-track { stroke: #4d4530; stroke-width: 4; stroke-linecap: round; }
.tl-fill { stroke: var(--stencil); stroke-width: 4; stroke-linecap: round; }
.tl-tick { stroke: #8a7c58; stroke-width: 3; }
.tl-tick.is-done { stroke: var(--stencil); }
.tl-label { fill: #b7a67c; font-size: 15px; font-family: var(--font-mono); }
.tl-dot { fill: var(--stencil); }
.tl-now { fill: #fff8e2; }
.timeline-note { color: #b7a67c; font-size: 0.9rem; margin: 0.35rem 0 0; }
.btn-row { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: center; margin-top: 1.1rem; }
.btn {
  font-size: 1rem;
  font-weight: 700;
  min-height: 44px;
  padding: 0.6rem 1.2rem;
  border-radius: 10px;
  border: 1px solid var(--stencil-dim);
  background: transparent;
  color: var(--stencil);
  cursor: pointer;
}
.btn:hover:not(:disabled) { border-color: var(--stencil); }
.btn:disabled { opacity: 0.45; cursor: default; }
.copy-status { color: #b7a67c; margin: 0; min-height: 1.5em; }
.error {
  margin: 1rem 0 0;
  padding: 0.7rem 1rem;
  border-radius: 10px;
  background: #3d1414;
  border: 1px solid #7c2b2b;
  color: #ffd7d7;
  font-weight: 600;
}
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- prose ---------- */

.prose { max-width: 44rem; padding-top: 2.5rem; }
.prose h2 {
  font-size: clamp(1.4rem, 3vw, 1.8rem);
  letter-spacing: -0.015em;
  line-height: 1.2;
  margin: 0 0 0.75rem;
}
.prose p { margin: 0 0 1rem; }
.prose a { color: var(--accent); }
.prose code, .tin code, td code {
  font-family: var(--font-mono);
  font-size: 0.92em;
  background: var(--surface-2);
  padding: 0.1em 0.35em;
  border-radius: 5px;
}
.tin {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: stretch;
  margin: 1.25rem 0;
  font-family: var(--font-mono);
}
.tin .g {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.55rem 0.8rem;
  text-align: center;
}
.tin .g b { display: block; font-size: 1.25rem; letter-spacing: 0.06em; }
.tin .g span { display: block; font-family: var(--font-body); font-size: 0.8rem; color: var(--muted); }
.tin .g.date { background: var(--rubber); border-color: var(--rubber); color: var(--stencil); }
.tin .g.date span { color: var(--stencil-dim); }
.table-wrap { overflow-x: auto; margin: 1rem 0; }
table.codes { border-collapse: collapse; width: 100%; font-size: 0.98rem; }
table.codes caption { text-align: left; color: var(--muted); padding-bottom: 0.5rem; }
table.codes th, table.codes td {
  border: 1px solid var(--line);
  padding: 0.55rem 0.7rem;
  text-align: left;
  vertical-align: top;
}
table.codes thead th { background: var(--surface-2); }
table.codes tbody th { font-family: var(--font-mono); white-space: nowrap; }
table.codes td.bad { color: var(--replace); font-weight: 600; }
table.codes td.ok { color: var(--fresh); font-weight: 600; }
.formula {
  font-family: var(--font-mono);
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 6px solid var(--stencil-dim);
  border-radius: 8px;
  padding: 0.8rem 1rem;
}
.faq { border: 1px solid var(--line); border-radius: 10px; margin-bottom: 0.6rem; background: var(--surface); }
.faq summary {
  cursor: pointer;
  font-weight: 700;
  padding: 0.8rem 1rem;
  min-height: 44px;
}
.faq p { padding: 0 1rem 0.9rem; margin: 0; }
.sources ul { padding-left: 1.2rem; }
.sources li { margin-bottom: 0.6rem; }

footer.site {
  max-width: 60rem;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 2.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.25rem;
  align-items: center;
  border-top: 1px solid var(--line);
  color: var(--muted);
}
footer.site a { color: var(--accent); }
footer.site .spacer { flex: 1; }

@media (max-width: 480px) {
  main { padding: 0 1rem 3rem; }
  .strip { gap: 0.22rem; }
  .day-num { font-size: 0.92rem; }
  .day-name { font-size: 0.64rem; }
}
