/*
 * Flop agent app: one calm system (DESIGN-ui.md). The brand carries action and identity: primary
 * buttons, links, the focus ring, the selected step and the spending meter are Flop's cyan family,
 * and the mark is navy, cyan and ice. The neutral layer is brand-tinted too — page, rules, borders,
 * the neutral "info" tone and the dark panel are navy-grey, not the green-grey the first redesign
 * used, so the whole page reads as the mark rather than only the buttons. (A LIGHT panel stays
 * #ffffff: it is the one surface the brand does not tint.) Colour itself still means state,
 * never decoration: green done, amber needs attention, red failed or deletes.
 * Contrast of every pairing is measured in DESIGN-ui.md; e2e/gallery.mjs re-checks it on every screen.
 */

/* Atkinson Hyperlegible Next (Braille Institute; SIL Open Font License 1.1, fonts/OFL.txt): one
   variable file per subset serves both weights used, unchanged from Google Fonts' build (24 Nov 2026). */
@font-face {
  font-family: "Atkinson Hyperlegible Next";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("fonts/atkinson-hyperlegible-next-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Atkinson Hyperlegible Next";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("fonts/atkinson-hyperlegible-next-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  color-scheme: light dark;
  --page: #e8eef8;
  --panel: #ffffff;
  --ink: #0d1526;
  --ink-2: #4a5568;
  --line: #d3dae6;
  --control: #64748b;
  /* The brand, as the action colour. Flop's cyan #00b4d8 is only 2.11:1 on the page, so light mode takes
     one deeper step of the same hue (194°) and paints the brand's ice on it; navy is the identity
     colour of the mark. Dark mode carries the cyan itself and puts the navy on the fill. Measured in
     DESIGN-ui.md. */
  --action: #0e6e8c;
  --on-action: #f5f7fa;
  --ok: #1b6440;
  --ok-tint: #e6f2ea;
  --warn: #7a4b00;
  --warn-tint: #fbf0d9;
  --bad: #a1281f;
  --bad-tint: #fbeae7;
  --info: #334155;
  --info-tint: #eef3fa;

  --font: "Atkinson Hyperlegible Next", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --fs-sm: 0.875rem;
  --fs-md: 1rem;
  --fs-lg: 1.125rem;
  --fs-xl: clamp(1.375rem, 1.15rem + 1.1vw, 1.75rem);
  --fs-2xl: clamp(1.75rem, 1.4rem + 1.8vw, 2.25rem);
  --s1: 0.25rem;
  --s2: 0.5rem;
  --s3: 0.75rem;
  --s4: 1rem;
  --s5: 1.5rem;
  --s6: 2rem;
  --s7: 3rem;
  --r-control: 8px;
  --r-panel: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --page: #0b1120;
    --panel: #161f30;
    --ink: #e8ecf5;
    --ink-2: #a7b2c6;
    --line: #26303f;
    --control: #7b8798;
    --action: #00b4d8;
    --on-action: #0a1128;
    --ok: #7fcf9f;
    --ok-tint: #16291e;
    --warn: #e9bd66;
    --warn-tint: #2c2414;
    --bad: #ff9b90;
    --bad-tint: #331a17;
    --info: #c7d0de;
    --info-tint: #1b2433;
  }
}

/* ── Base ─────────────────────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--fs-md);
  line-height: 1.5;
}
#app { max-width: 40rem; margin: 0 auto; padding: 0 var(--s4) var(--s7); }
@media (min-width: 768px) { #app { padding-inline: var(--s5); } }
main { padding-top: var(--s2); }
h1, h2, h3, h4, p, li, dt, dd, label, figcaption, summary { overflow-wrap: anywhere; }
/* Table cells break only a string too long for any line, never an ordinary word ("Join/ed"); the table scrolls instead. */
td, th { overflow-wrap: break-word; }
h1 { font-size: var(--fs-xl); line-height: 1.25; margin: var(--s5) 0 var(--s3); }
h1.display { font-size: var(--fs-2xl); margin-top: var(--s6); }
h1[tabindex="-1"]:focus { outline: none; }
@media (min-width: 768px) { h1 { margin-top: var(--s7); } h1.display { margin-top: var(--s7); } }
h2 { font-size: var(--fs-lg); line-height: 1.3; margin: var(--s5) 0 var(--s2); }
h3 { font-size: var(--fs-md); line-height: 1.35; margin: var(--s4) 0 var(--s2); }
h4 { font-size: var(--fs-md); line-height: 1.35; margin: 0 0 var(--s1); }
p { margin: var(--s2) 0; }
.lead { font-size: var(--fs-lg); }
ol, ul { padding-left: 1.4rem; margin: var(--s2) 0; }
li { margin: var(--s1) 0; }
small, .muted { color: var(--ink-2); font-size: var(--fs-sm); }
.meta { color: var(--ink-2); font-size: var(--fs-sm); }
strong { font-weight: 700; }
code, .mono { font-family: var(--mono); font-size: 0.875em; word-break: break-all; }
code { background: var(--info-tint); color: var(--ink); padding: 0.1rem 0.35rem; border-radius: 6px; }
a { color: var(--action); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid var(--action); outline-offset: 2px; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0;
}

/* ── App bar and footer ───────────────────────────────────────────────────────────────────── */
header { display: flex; align-items: center; flex-wrap: wrap; gap: var(--s2) var(--s3); padding: var(--s2) 0; border-bottom: 1px solid var(--line); }
.brand { display: inline-flex; align-items: center; gap: var(--s2); min-height: 44px; font-weight: 700; color: var(--ink); text-decoration: none; }
/* The mark, in the app's header and on the stats page (both take this sheet). */
.brand img { display: block; width: 22px; height: 22px; }
.badge, .net-chip { display: inline-flex; align-items: center; font-size: var(--fs-sm); padding: 0.1rem 0.6rem; border: 1px solid var(--control); border-radius: 999px; color: var(--ink-2); }
.who { margin-left: auto; display: inline-flex; align-items: baseline; gap: var(--s2); color: var(--ink-2); font-size: var(--fs-sm); }
.who strong { color: var(--ink); }
header .notice { flex-basis: 100%; margin: 0 0 var(--s2); }
footer {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0 var(--s4);
  margin-top: var(--s6); padding: var(--s3) 0 var(--s6); border-top: 1px solid var(--line);
  color: var(--ink-2); font-size: var(--fs-sm);
}
footer a { display: inline-flex; align-items: center; min-height: 44px; }
.confirm { flex-basis: 100%; }

/* ── Buttons: every one at least 44 x 44 px ───────────────────────────────────────────────── */
button, .button {
  font: inherit; font-weight: 700; line-height: 1.25;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: 44px; min-width: 44px; padding: 0.55rem 1.1rem;
  border: 1px solid var(--control); border-radius: var(--r-control);
  background: var(--panel); color: var(--ink);
  cursor: pointer; text-align: center; text-decoration: none;
}
button:hover, .button:hover { border-color: var(--action); }
button.primary, .button.primary { background: var(--action); border-color: var(--action); color: var(--on-action); }
button.big, .button.big { width: 100%; font-size: var(--fs-lg); min-height: 52px; }
button.small { font-size: var(--fs-sm); padding: 0.4rem 0.8rem; }
/* A text button is a link that happens to dispatch, so it takes the action colour too. */
button.text, button.link, .button.text {
  background: none; border-color: transparent; padding: 0.4rem 0.25rem; color: var(--action);
  font-weight: 400; text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px;
}
button.text:hover, button.link:hover { border-color: transparent; text-decoration-thickness: 2px; }
button.danger { border-color: var(--bad); color: var(--bad); }
button.danger.solid { background: var(--bad); color: var(--panel); }
button:disabled, button:disabled:hover {
  cursor: not-allowed; background: var(--info-tint); border-color: var(--line); color: var(--ink-2);
}
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s3); margin: var(--s5) 0; }
@media (max-width: 479px) { .actions > .primary { width: 100%; } }
.segmented, .tabs { display: flex; flex-wrap: wrap; gap: var(--s2); margin: var(--s3) 0; }
.segmented button, .tab { font-weight: 400; }
.segmented button[aria-pressed="true"], .tab.on { background: var(--info-tint); border: 2px solid var(--action); font-weight: 700; }

/* ── Fields ───────────────────────────────────────────────────────────────────────────────── */
.field { display: block; margin: var(--s4) 0; }
.field > span, .field > .label { display: block; font-weight: 700; margin-bottom: var(--s1); }
.hint, .field > small { display: block; color: var(--ink-2); font-size: var(--fs-sm); margin-top: var(--s1); }
input, textarea, select {
  font: inherit; width: 100%; min-height: 48px; padding: 0.6rem 0.75rem;
  border: 1px solid var(--control); border-radius: var(--r-control);
  background: var(--panel); color: var(--ink);
}
textarea { resize: vertical; line-height: 1.45; }
input[type="file"] { padding: 0.3rem; }
input[type="file"]::file-selector-button {
  font: inherit; font-weight: 700; min-height: 36px; margin-right: var(--s3); padding: 0.3rem 0.9rem;
  border: 1px solid var(--control); border-radius: 6px; background: var(--info-tint); color: var(--ink); cursor: pointer;
}
.check { display: flex; align-items: flex-start; gap: var(--s3); min-height: 44px; padding: var(--s2) 0; color: var(--ink-2); font-size: var(--fs-sm); cursor: pointer; }
.check input { flex: none; width: 1.375rem; height: 1.375rem; min-height: 0; margin: 0; accent-color: var(--action); }

/* ── Panels, status and notices ───────────────────────────────────────────────────────────── */
.card, .panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-panel); padding: var(--s4); margin: var(--s4) 0; }
.card > :first-child, .panel > :first-child, .status > :first-child { margin-top: 0; }
.card > :last-child, .panel > :last-child, .status > :last-child { margin-bottom: 0; }
[data-tone="neutral"], [data-tone="working"] { --tone: var(--info); --tone-tint: var(--info-tint); }
[data-tone="success"] { --tone: var(--ok); --tone-tint: var(--ok-tint); }
[data-tone="warning"] { --tone: var(--warn); --tone-tint: var(--warn-tint); }
[data-tone="danger"] { --tone: var(--bad); --tone-tint: var(--bad-tint); }
.status {
  margin: var(--s4) 0; padding: var(--s4);
  background: var(--tone-tint, var(--panel)); border: 1px solid var(--line); border-left: 4px solid var(--tone, var(--info));
  border-radius: var(--r-panel);
}
.status .title { font-weight: 700; color: var(--tone, var(--ink)); }
.chip {
  display: inline-flex; align-items: center; gap: var(--s1); font-size: var(--fs-sm); font-weight: 700; line-height: 1.3;
  padding: 0.1rem 0.6rem; border-radius: 999px; border: 1px solid var(--tone, var(--control));
  color: var(--tone, var(--ink-2)); background: var(--tone-tint, var(--panel));
}
.notice { background: var(--info-tint); color: var(--ink); padding: var(--s3) var(--s4); border-radius: var(--r-panel); }
.notice[data-tone] { background: var(--tone-tint); color: var(--tone); }
.honest { background: var(--info-tint); border-left: 4px solid var(--info); padding: var(--s3) var(--s4); border-radius: 0 var(--r-panel) var(--r-panel) 0; }
.error { background: var(--bad-tint); color: var(--bad); padding: var(--s3) var(--s4); border-radius: var(--r-panel); }
.error.fatal { margin-top: var(--s4); font-weight: 700; }
.warn { color: var(--warn); font-weight: 700; }
.warnline { color: var(--warn); font-size: var(--fs-sm); margin: var(--s2) 0 0; }
.ok { color: var(--ok); font-weight: 700; }
.spinner::before {
  content: ""; display: inline-block; width: 1em; height: 1em; margin-right: var(--s2); vertical-align: -0.15em;
  border: 2px solid var(--line); border-top-color: var(--ink); border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
/* Saving failed, so nothing runs: the screen stays visible but frozen under the red banner. */
main.stopped { opacity: 0.45; }
main.stopped .spinner::before { animation: none; }
/* main.js's bare messages (second tab, insecure page, failed start) as one centred panel. */
#app > p.notice:only-child, #app > p.error.fatal:only-child { max-width: 30rem; margin: var(--s7) auto; padding: var(--s5); font-size: var(--fs-lg); }

/* ── Setup steps (a real sequence, so numbered) ───────────────────────────────────────────── */
.track { display: flex; flex-wrap: wrap; gap: var(--s2) var(--s4); list-style: none; padding: 0; margin: var(--s4) 0 0; counter-reset: step; font-size: var(--fs-sm); color: var(--ink-2); }
.track li { counter-increment: step; display: inline-flex; align-items: center; gap: var(--s2); margin: 0; }
.track li::before { content: counter(step); display: inline-grid; place-items: center; flex: none; width: 1.5rem; height: 1.5rem; border: 1px solid var(--control); border-radius: 50%; font-weight: 700; }
.track li.current { color: var(--ink); font-weight: 700; }
.track li.current::before { background: var(--action); border-color: var(--action); color: var(--on-action); }
.track li.done { color: var(--ok); }
.track li.done::before { content: "\2713"; border-color: var(--ok); }

/* ── Setup screens ───────────────────────────────────────────────────────────────────────── */
.how li, .facts li { margin: var(--s2) 0; }
.stepped > li { margin: var(--s3) 0; }
.stepped > li > p { margin: 0 0 var(--s2); }
.address-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); }
.address-row code { flex: 1 1 14rem; padding: var(--s2) var(--s3); font-size: var(--fs-sm); }
h2 .chip { vertical-align: 0.1em; }
.actions + .hint { margin-top: calc(-1 * var(--s3)); }

/* ── Backup words, checklists, steps ──────────────────────────────────────────────────────── */
.words { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s2); padding: 0; list-style: none; counter-reset: w; }
.words li { counter-increment: w; margin: 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-control); padding: var(--s2) var(--s3); font-weight: 700; }
.words li::before { content: counter(w) ". "; color: var(--ink-2); font-weight: 400; }
@media (max-width: 420px) { .words { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.checkwords { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s3); }
@media (max-width: 480px) { .checkwords { grid-template-columns: 1fr; } }
.steps { list-style: none; padding: 0; margin: var(--s3) 0; }
.steps li { display: flex; align-items: flex-start; gap: var(--s2); margin: var(--s2) 0; }
.steps li::before { content: ""; flex: none; width: 0.875rem; height: 0.875rem; margin-top: 0.3rem; border-radius: 50%; border: 2px solid var(--control); }
.steps li.done { color: var(--ok); }
.steps li.done::before { background: var(--ok); border-color: var(--ok); }
.steps li.doing::before { border-color: var(--line); border-top-color: var(--ink); animation: spin 0.8s linear infinite; }
.steps li.failed { color: var(--bad); }
.steps li.failed::before { background: var(--bad); border-color: var(--bad); }

/* ── Tasks and answers ────────────────────────────────────────────────────────────────────── */
.answer { border-top: 1px solid var(--line); padding: var(--s4) 0; }
.answer .text { white-space: pre-wrap; }
.answer h3 { margin: 0 0 var(--s1); }
.answer.unknown h3, .answer.failed h3 { color: var(--warn); }
meter {
  display: block; width: 100%; height: 0.75rem; margin: var(--s2) 0;
  appearance: none; -webkit-appearance: none; background: var(--info-tint); border: 1px solid var(--control); border-radius: 999px;
}
meter::-webkit-meter-bar { background: var(--info-tint); border: 0; border-radius: 999px; height: 100%; }
meter::-webkit-meter-optimum-value, meter::-webkit-meter-suboptimum-value, meter::-webkit-meter-even-less-good-value { background: var(--action); border-radius: 999px; }
meter::-moz-meter-bar { background: var(--action); border-radius: 999px; }

/* ── Spending ───────────────────────────────────────────────────────────────────────────── */
.facts-list { display: grid; grid-template-columns: minmax(7rem, max-content) 1fr; gap: var(--s2) var(--s4); margin: var(--s3) 0; }
.facts-list dt { font-weight: 700; }
.facts-list dd { margin: 0; }
@media (max-width: 479px) { .facts-list { grid-template-columns: 1fr; gap: 0; } .facts-list dd { margin-bottom: var(--s3); } }
.limit meter { margin: var(--s3) 0 var(--s2); }
.answer-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--s2) var(--s3); margin-bottom: var(--s1); }
.answer-head h3 { margin: 0; flex: 1 1 12rem; }
.chip.spinner::before { width: 0.75em; height: 0.75em; margin-right: 0; }
.meta a { display: inline-flex; align-items: center; min-height: 44px; }

/* ── Public stats ─────────────────────────────────────────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); gap: var(--s3); }
.stats-grid .card { margin: 0; }
.stat { font-size: var(--fs-2xl); font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; max-width: 100%; }
table { border-collapse: collapse; width: 100%; font-size: var(--fs-sm); }
caption { text-align: left; font-weight: 700; padding: var(--s3) 0 var(--s2); }
th, td { text-align: left; padding: var(--s1) var(--s2); border-bottom: 1px solid var(--line); vertical-align: middle; }
td a { display: inline-flex; align-items: center; min-height: 44px; }

/* ── Motion: only the progress spinner moves, and not at all when asked ─────────────────── */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .spinner::before, .steps li.doing::before { animation: none; border-color: var(--ink-2); }
}
