:root {
  color-scheme: light;
  --paper: #f6f1ea;
  --surface: #fffdf9;
  --hover: #efe7dc;
  --ink: #1a1814;
  --muted: #5c564c;
  --accent: #8c2f2a;
  --radius: 8px;
  --inset: #f7f3ed;
  --border: #d9d0c6;
  --rule: 1px solid var(--border);
  --serif: "Source Serif 4", Georgia, serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  font: 1rem/1.5 "IBM Plex Sans", "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--paper);
  scroll-padding-top: 4.75rem;
}

* { box-sizing: border-box; }
body, h1, h2, h3, p, dl, dd { margin: 0; }
body {
  min-height: 100vh;
  background-image: linear-gradient(to bottom, #d9d0c666 1px, transparent 1px);
  background-size: 100% 5.75rem;
}
body::before {
  content: "";
  position: fixed;
  inset: 0 auto 0 0;
  width: 3px;
  z-index: 5;
  background: var(--accent);
  pointer-events: none;
}
::selection { background: #f0e2dc; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.wrap { width: min(calc(100% - 3rem), 72rem); margin-inline: auto; }
button, a { color: inherit; }
button { padding: 0; border: 0; font: inherit; background: transparent; cursor: pointer; }
.skip { position: fixed; top: -5rem; left: 1rem; z-index: 6; background: var(--surface); padding: .6rem; }
.skip:focus { top: .4rem; }
header { position: sticky; top: 0; z-index: 4; background: var(--paper); border-bottom: var(--rule); }
.bar, .brand, nav, .panel-heading, .actions, .notice, footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.bar { min-height: 3.75rem; }
.brand { justify-content: start; gap: .8rem; font: 600 1.22rem/1.1 var(--serif); text-decoration: none; }
.mark { font: .74rem var(--mono); color: var(--muted); letter-spacing: .14em; padding-right: .8rem; border-right: var(--rule); }
nav { align-self: stretch; gap: 1.6rem; }
nav a, nav button, .calculate, .eyebrow, #count {
  font: 400 .71rem/1.4 var(--mono);
  letter-spacing: .07em;
  text-transform: uppercase;
}
nav a, nav button { display: grid; align-items: center; min-height: 44px; color: var(--muted); text-decoration: none; }
nav [aria-current], nav button:hover { color: var(--accent); }
header :focus-visible { outline-offset: -2px; }
nav [aria-current] { align-self: stretch; border-bottom: 2px solid; padding-top: 2px; }
.hero { padding: clamp(1.35rem, 3.7vh, 2.7rem) 0 1.55rem; animation: enter .25s ease-out; }
.eyebrow { display: flex; align-items: center; gap: .7rem; color: var(--accent); letter-spacing: .14em; }
.eyebrow::before { content: ""; background: currentColor; width: 2rem; height: 1px; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.12; letter-spacing: -.025em; }
h1 { font-size: clamp(2.15rem, 4.4vw, 3.85rem); margin: .48rem 0 .4rem; }
.lede { color: var(--muted); font-size: 1.03rem; }
.workspace { display: grid; grid-template-columns: 1.1fr 1fr; gap: 1.25rem; }
.panel {
  --gutter: clamp(1rem, 2vw, 1.65rem);
  border-radius: var(--radius);
  overflow: clip;
  display: flex;
  flex-direction: column;
  min-width: 0;
  border: var(--rule);
  background: var(--surface);
}
.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: .65rem 1rem;
  padding: 1.2rem var(--gutter);
  border-bottom: var(--rule);
}
.actions { background: #faf6f0; }
.completion { display: grid; gap: .4rem; min-width: 6rem; }
.completion progress {
  appearance: none;
  width: 100%;
  height: 4px;
  border: 0;
  background: var(--border);
  color: var(--accent);
}
progress::-webkit-progress-bar { background: var(--border); }
progress::-webkit-progress-value { background: var(--accent); transition: width .18s ease; }
progress::-moz-progress-bar { background: var(--accent); }
h2 { font-size: clamp(1.65rem, 2.5vw, 2.15rem); }
#count { color: var(--muted); font-size: .65rem; letter-spacing: .035em; }
.hint { margin-top: .38rem; color: var(--muted); font-size: .91rem; }
.fields { margin: auto var(--gutter); }
fieldset { display: flow-root; min-width: 0; margin: 0; padding: .65rem 0; border: 0; border-bottom: var(--rule); }
fieldset:last-child { border-bottom: 0; }
legend { float: left; padding: 0; line-height: 52px; font-weight: 500; }
.segments {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 2px;
  width: min(58%, 16.5rem);
  margin-left: auto;
  padding: 3px;
  border: var(--rule);
  border-radius: 8px;
  background: var(--inset);
}
.segments label { position: relative; }
.segments input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.segments span {
  display: grid; place-items: center; min-width: 0; height: 44px;
  border-radius: 5px; border: 1px solid transparent; background: transparent; font: .84rem var(--mono);
  transition: background-color 160ms, border-color 160ms, color 160ms;
}
.segments input:hover + span { background: var(--hover); }
.segments input:active + span { transform: scale(.97); }
.segments input:checked + span { color: var(--surface); background: var(--accent); border-color: var(--accent); }
.segments input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.actions { padding: .75rem var(--gutter); border-top: var(--rule); }
.calculate { border-radius: 4px; display: inline-flex; align-items: center; gap: 1rem; padding: .7rem 1rem; min-height: 44px; color: var(--surface); background: var(--accent); transition: background-color 160ms; }
.calculate span { font: 1.15rem/1 var(--serif); transition: transform 160ms ease; }
.calculate:hover:enabled span { transform: translateX(2px); }
.calculate:hover:enabled { background: var(--ink); }
.calculate:disabled { background: var(--hover); color: var(--muted); cursor: default; }
.text-button, dialog a { color: var(--accent); font-size: .9rem; text-decoration: underline; text-underline-offset: .24em; }
.text-button { min-width: 44px; min-height: 44px; }
.text-button:hover, dialog a:hover { color: var(--ink); }
.scores {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  margin: 1rem var(--gutter);
  overflow: hidden;
  border: var(--rule);
  border-radius: 6px;
  background: var(--border);
}
.scores div {
  display: flex;
  flex-direction: column;
  align-items: start;
  justify-content: space-between;
  gap: .5rem;
  padding: .85rem 1rem;
  background: var(--surface);
}
.scores dt { font-weight: 600; line-height: 1.35; }
.scores small { display: block; margin-top: .15rem; color: var(--muted); font-size: .76rem; font-weight: 400; }
.scores dd { font: 600 2.3rem/1 var(--serif); color: var(--muted); font-variant-numeric: lining-nums tabular-nums; }
.scores.ready dd { color: var(--ink); animation: enter .28s ease-out; }
.result-status {
  display: flex; align-items: center; gap: .6rem;
  min-height: 3rem; padding: .7rem var(--gutter); border-top: var(--rule);
  font-size: .84rem; color: var(--muted);
}
.result-status:focus-visible { outline-offset: -4px; }
.result-status::before {
  content: ""; flex: none; width: 7px; height: 7px;
  border: 1px solid currentColor; border-radius: 50%;
}
.scores.ready + .result-status::before { background: var(--accent); border-color: var(--accent); }
@keyframes enter { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.notice { padding: .65rem 0; justify-content: start; font-size: .89rem; color: var(--muted); }
.notice strong { color: var(--ink); font-weight: 600; }
footer { border-top: var(--rule); margin-top: 1rem; padding: 1rem 0; font-size: .76rem; color: var(--muted); }
dialog { width: min(38rem, calc(100% - 2rem)); max-height: 85vh; padding: clamp(1.2rem, 4vw, 2rem); border: var(--rule); background: var(--surface); color: var(--ink); }
dialog::backdrop { background: rgb(26 24 20 / 42%); }
dialog h3 { margin: 1.2rem 0 .35rem; font-size: 1.25rem; }
dialog p + p { margin-top: .6rem; }
dialog a { display: inline-block; margin-top: 1rem; }

@media (max-width: 960px) {
  legend { float: none; line-height: 1.4; }
  fieldset { padding: .42rem 0 .65rem; margin-top: .55rem; }
  .fields { margin-block: .25rem; }
  .segments { width: 100%; }
}
@media (max-width: 720px) {
  .wrap { width: min(calc(100% - 2rem), 36rem); }
  body { background-size: 100% 6.25rem; }
  body::before { width: 2px; }
  .bar { min-height: 3.45rem; gap: .5rem; }
  .brand { gap: .5rem; font-size: 1.04rem; }
  .mark { padding-right: .5rem; }
  nav a { display: none; }
  nav button { font-size: .64rem; }
  .hero { padding: 1.35rem 0; }
  .workspace { grid-template-columns: 1fr; gap: .85rem; }
  .scores div { padding: .8rem; }
  .card-head { padding-block: 1rem; }
  .scores dd { font-size: 2rem; }
  .notice { display: block; padding-top: 1rem; }
  .notice button { display: block; width: 100%; text-align: left; }
  footer { flex-wrap: wrap; gap: .2rem 1rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
