@font-face {
  font-family: Newsreader;
  src: url(/fonts/newsreader.woff2) format("woff2");
  font-weight: 200 800;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Plex Sans";
  src: url(/fonts/plex-sans.woff2) format("woff2");
  font-weight: 100 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Plex Mono";
  src: url(/fonts/plex-mono-400.woff2) format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Plex Mono";
  src: url(/fonts/plex-mono-500.woff2) format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light;
  --paper: #f4f5f2;
  --sheet: #fcfdfb;
  --bar: #e3ece1;
  --ink: #17191a;
  --ink-2: #585d59;
  --rule: #d4d9d3;
  --rule-strong: #b6bcb5;
  --accent: #17503f;
  --flag: #8a3324;
  --serif: Newsreader, "Iowan Old Style", Georgia, serif;
  --sans: "Plex Sans", ui-sans-serif, system-ui, sans-serif;
  --mono: "Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --out: cubic-bezier(0.23, 1, 0.32, 1);
  --gutter: clamp(1.15rem, 5vw, 3.25rem);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 1rem/1.6 var(--sans);
  padding: env(safe-area-inset-top, 0) 0 env(safe-area-inset-bottom, 0);
}

::selection { background: color-mix(in oklab, var(--accent) 22%, transparent); }

a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}
a:hover { color: var(--ink); }

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

.skip {
  position: absolute;
  left: -200vw;
  top: 0.5rem;
  background: var(--sheet);
  border: 1px solid var(--accent);
  padding: 0.5rem 0.9rem;
  z-index: 5;
}
.skip:focus { left: 0.5rem; }

.mono {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 0.92em;
}

.label {
  font: 500 0.69rem/1.3 var(--mono);
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--ink-2);
  margin: 0;
}

/* --- masthead ------------------------------------------------------- */

.masthead {
  max-width: 72rem;
  margin: 0 auto;
  padding: clamp(1.4rem, 4vw, 2.5rem) var(--gutter) clamp(1.5rem, 3.5vw, 2.25rem);
}

.wordmark {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin: 0 0 clamp(1.9rem, 6vw, 3.4rem);
  font: 500 0.95rem/1 var(--mono);
  letter-spacing: 0.05em;
}
.wordmark svg { color: var(--accent); flex: none; }

h1 {
  font: 420 clamp(2rem, 5.6vw, 3.25rem)/1.08 var(--serif);
  font-optical-sizing: auto;
  letter-spacing: -0.018em;
  text-wrap: balance;
  margin: 0 0 1.1rem;
  max-width: 24ch;
}

.lede {
  margin: 0 0 1.5rem;
  max-width: 58ch;
  font-size: clamp(1rem, 2.4vw, 1.1rem);
  color: var(--ink-2);
}

.stamp {
  font: 400 0.78rem/1.5 var(--mono);
  font-variant-numeric: tabular-nums;
  color: var(--ink-2);
  margin: 0;
}

/* --- bands ---------------------------------------------------------- */

main { max-width: 72rem; margin: 0 auto; }

.band {
  display: grid;
  gap: 0.9rem 2rem;
  border-top: 1px solid var(--rule);
  padding: clamp(1.5rem, 3.5vw, 2.25rem) var(--gutter) clamp(1.75rem, 4vw, 2.75rem);
}
.band > * { min-width: 0; }
.band > .label { grid-column: 1 / -1; }

@media (min-width: 62rem) {
  .band { grid-template-columns: 8.5rem minmax(0, 1fr); }
  .band > .label { grid-column: 1; grid-row: 1; padding-top: 0.45rem; }
  .band > :not(.label) { grid-column: 2; }
}

.aside {
  margin: 0;
  font-size: 0.86rem;
  line-height: 1.6;
  color: var(--ink-2);
  max-width: 70ch;
}

.caption {
  margin: 0.7rem 0 0;
  font: 400 0.78rem/1.5 var(--mono);
  color: var(--ink-2);
}

/* --- source picker -------------------------------------------------- */

.sources { display: flex; flex-wrap: wrap; gap: 0.5rem; }

button, .file span {
  font: 400 0.875rem/1.2 var(--sans);
  color: var(--ink);
  background: var(--sheet);
  border: 1px solid var(--rule-strong);
  padding: 0.55rem 0.85rem;
  min-height: 2.5rem;
  cursor: pointer;
  transition: transform 140ms var(--out), border-color 140ms ease, background-color 140ms ease;
}
button:active, .file:active span { transform: scale(0.975); }
@media (hover: hover) and (pointer: fine) {
  button:hover, .file:hover span { border-color: var(--accent); color: var(--accent); }
}

.sources button[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--sheet);
}
@media (hover: hover) and (pointer: fine) {
  .sources button[aria-pressed="true"]:hover { color: var(--sheet); }
}

.file { display: inline-block; position: relative; }
.file input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}
.file span { display: inline-block; border-style: dashed; }

/* --- table card ----------------------------------------------------- */

.card {
  background: var(--sheet);
  border: 1px solid var(--rule);
  padding: clamp(0.9rem, 2.5vw, 1.35rem);
  box-shadow: 0 1px 2px rgb(23 25 26 / 5%), 0 10px 24px -14px rgb(23 25 26 / 16%);
}

.shape {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.2rem 1.15rem;
  margin: 0 0 0.25rem;
}
.shape strong { font: 500 1.05rem/1.3 var(--sans); }
.shape .mono { color: var(--ink-2); white-space: nowrap; }

.note { margin: 0 0 1rem; font-size: 0.86rem; color: var(--ink-2); max-width: 62ch; }

.warnings {
  margin: 0.9rem 0 0;
  padding-left: 1.1rem;
  font-size: 0.82rem;
  color: var(--flag);
}

.scroll {
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-color: var(--rule-strong) transparent;
}
@media (min-width: 48rem) {
  .scroll.tall { max-height: 26rem; overflow-y: auto; }
}
.scroll::-webkit-scrollbar { height: 9px; width: 9px; }
.scroll::-webkit-scrollbar-thumb { background: var(--rule-strong); }
.scroll::-webkit-scrollbar-track { background: transparent; }

table.grid {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.82rem;
}
.grid th, .grid td {
  text-align: left;
  padding: 0.42rem 0.75rem 0.42rem 0;
  border-bottom: 1px solid var(--rule);
  white-space: nowrap;
  max-width: 22rem;
  overflow: hidden;
  text-overflow: ellipsis;
}
.grid thead th {
  border-bottom: 1px solid var(--rule-strong);
  font: 500 0.69rem/1.3 var(--mono);
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--ink-2);
  position: sticky;
  top: 0;
  background: var(--sheet);
}
.grid tbody tr:nth-child(even) td { background: var(--bar); }
.grid tbody tr:last-child td { border-bottom: 0; }
.grid .num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.grid thead .num { text-align: right; }
.grid .idx {
  font: 400 0.76rem/1.3 var(--mono);
  color: var(--ink-2);
  padding-right: 1rem;
  width: 1%;
}
.grid .blank { color: var(--rule-strong); }

.file-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.3rem 0.75rem;
  margin: 0;
}
.file-row .aside { flex: 1 1 18rem; }

.columns {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 0.45rem;
  margin: 0 0 0.2rem;
  padding: 0;
  list-style: none;
}
.columns li {
  font: 400 0.8rem/1.4 var(--sans);
  color: var(--ink-2);
  border: 1px solid var(--rule);
  padding: 0.22rem 0.55rem;
}
.columns li.num {
  font-family: var(--mono);
  color: var(--accent);
  border-color: color-mix(in oklab, var(--accent) 35%, transparent);
}
.columns .blank { color: var(--flag); font-size: 0.92em; }

/* --- question ------------------------------------------------------- */

#ask-form { display: flex; flex-wrap: wrap; gap: 0.5rem; }

#question {
  flex: 1 1 18rem;
  min-width: 0;
  font: 400 1rem/1.2 var(--sans);
  color: var(--ink);
  caret-color: var(--accent);
  background: var(--sheet);
  border: 1px solid var(--rule-strong);
  padding: 0.6rem 0.8rem;
  min-height: 2.5rem;
}
#question::placeholder { color: var(--ink-2); }
#question:focus-visible { outline-offset: -1px; border-color: var(--accent); }

#submit {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--sheet);
  font-weight: 500;
  padding-inline: 1.1rem;
}
@media (hover: hover) and (pointer: fine) {
  #submit:hover { background: var(--ink); border-color: var(--ink); color: var(--sheet); }
}
#submit[disabled] {
  background: var(--rule);
  border-color: var(--rule-strong);
  color: var(--ink-2);
  cursor: default;
  transform: none;
}

.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.chips button {
  background: transparent;
  border-color: var(--rule);
  font-size: 0.8rem;
  padding: 0.4rem 0.65rem;
  min-height: 2.1rem;
}

.failure {
  margin: 0;
  padding-left: 0.8rem;
  border-left: 1px solid var(--flag);
  color: var(--flag);
  font-size: 0.9rem;
}

/* --- answer --------------------------------------------------------- */

.restated {
  font: 420 clamp(1.35rem, 3.4vw, 1.9rem)/1.25 var(--serif);
  font-optical-sizing: auto;
  letter-spacing: -0.012em;
  margin: 0;
  max-width: 34ch;
  text-wrap: balance;
}

.total {
  font-size: clamp(2.5rem, 9vw, 4.25rem);
  font-weight: 500;
  line-height: 1;
  letter-spacing: -0.035em;
  margin: 0.35rem 0 0;
  overflow-wrap: anywhere;
}

.groups { display: grid; gap: 1px; margin-top: 0.4rem; }

.group {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: "name amount" "bar bar";
  align-items: center;
  gap: 0.45rem 0.9rem;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--rule);
  padding: 0.6rem 0.4rem 0.6rem 0;
  min-height: 3rem;
}
.group:last-child { border-bottom: 0; }
.group .name {
  grid-area: name;
  font-size: 0.92rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.group .bar {
  grid-area: bar;
  height: 0.55rem;
  background: color-mix(in oklab, var(--accent) 20%, transparent);
  border-right: 1px solid var(--accent);
  min-width: 1px;
  transition: width 320ms var(--out);
}
.group .amount {
  grid-area: amount;
  font: 500 clamp(0.95rem, 2.2vw, 1.15rem)/1.2 var(--mono);
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.group .rows { grid-area: rows; display: none; }
.group[aria-pressed="true"] { background: var(--sheet); }
.group[aria-pressed="true"] .amount { color: var(--accent); }
@media (hover: hover) and (pointer: fine) {
  .group:hover { background: var(--sheet); color: var(--ink); }
}
@media (min-width: 40rem) {
  .group {
    grid-template-columns: minmax(6rem, 13rem) minmax(3rem, 1fr) auto 5.5rem;
    grid-template-areas: "name bar amount rows";
    row-gap: 0;
  }
  .group .bar { height: 0.7rem; }
  .group .rows {
    display: block;
    text-align: right;
    font: 400 0.74rem/1.2 var(--mono);
    color: var(--ink-2);
  }
}

#timing { margin-top: 0.9rem; }

.receipt { margin-top: 0.4rem; min-width: 0; }
.strip { border-top: 1px solid var(--rule); padding: 1.1rem 0 0.1rem; min-width: 0; }
.strip > .label { margin-bottom: 0.6rem; }
.strip p, .strip pre { margin: 0 0 0.75rem; }
.strip p:last-child { margin-bottom: 0; }

.strip pre {
  font-family: var(--mono);
  font-size: 0.78rem;
  line-height: 1.75;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--ink);
}

#download { font-size: 0.8rem; padding: 0.45rem 0.7rem; min-height: 2.2rem; }

#method p { font-size: 0.89rem; color: var(--ink-2); max-width: 68ch; }

.working {
  font-size: 0.82rem;
  line-height: 1.8;
  overflow-wrap: anywhere;
  padding: 0.7rem 0.85rem;
  background: var(--sheet);
  border: 1px solid var(--rule);
}

/* --- footer --------------------------------------------------------- */

footer {
  max-width: 72rem;
  margin: 0 auto;
  border-top: 1px solid var(--rule);
  padding: 1.6rem var(--gutter) 3rem;
  font-size: 0.82rem;
  color: var(--ink-2);
}
footer p { margin: 0 0 0.45rem; max-width: 76ch; }
.credits { font-size: 0.8rem; }

/* --- the one authored moment ---------------------------------------- */

.answer[data-fresh] .restated,
.answer[data-fresh] .total,
.answer[data-fresh] .groups,
.answer[data-fresh] #timing {
  animation: ink 420ms var(--out) both;
}
.answer[data-fresh] .groups { animation-delay: 60ms; }
.answer[data-fresh] #timing { animation-delay: 140ms; }
.answer[data-fresh] .strip { animation: rise 340ms var(--out) both; }
.answer[data-fresh] .strip:nth-child(2) { animation-delay: 50ms; }
.answer[data-fresh] .strip:nth-child(3) { animation-delay: 100ms; }

@keyframes ink {
  from { clip-path: inset(0 100% 0 0); opacity: 0.55; }
  to { clip-path: inset(0 -2% 0 0); opacity: 1; }
}
@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

@keyframes fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Reduced motion keeps the fades that mark a new answer and drops the movement. */
@media (prefers-reduced-motion: reduce) {
  .group .bar { transition: none; }
  button, .file span { transition: border-color 140ms ease, background-color 140ms ease; }
  button:active, .file:active span { transform: none; }
  .answer[data-fresh] .restated,
  .answer[data-fresh] .total,
  .answer[data-fresh] .groups,
  .answer[data-fresh] #timing,
  .answer[data-fresh] .strip {
    animation: fade 180ms ease both;
    animation-delay: 0ms;
  }
}
