/* FALSE FLAG - the playable page, which is now the whole site: docs/ is the
   game and nothing else.

   ONE THEME, DARK. No light variant, no prefers-color-scheme switch. The
   page ground is the terminal pane's ground, to the byte: GROUND in
   docs/ansi.js is [11, 16, 23] = #0b1017, so the live pane no longer
   sits in a hole cut out of a differently-coloured page — the page IS the
   terminal, and the pane is the part of it the engine is writing to.

   The tokens are cli/theme.py's `defcon` palette, the theme the game itself
   prints in, split where a colour cannot legally carry small text on this
   ground. Ratios are measured against --ground:

     --navy  #004e89 and --steel #1a659e are STRUCTURE ONLY (2.23 and 3.09
     against the ground). Their text-carrying siblings are --steel-t #6eabd6
     (7.69), which is literally what the pane paints "bright blue", and
     --dim #92a8ba (7.75), the game's muted blue lifted far enough to hold a
     label. --red #ff0000 draws rules, borders and the live ● (4.77, and
     never a word); --red-t #ff8375 (7.95) says the words. --accent #ff6b35
     (6.73) fills buttons and sets headings; --accent-t #ff8b5e (8.27) is
     the same orange at link size. Everything that carries text clears 7:1. */

:root {
  --ground: #0b1017;
  --panel: #0f1621;
  --panel-2: #111a26;
  --line: #1d2836;
  --line-2: #263447;
  --navy: #004e89;
  --steel: #1a659e;
  --steel-t: #6eabd6;
  --ink: #f1faee;
  --ink-2: #c9d6e0;
  --dim: #92a8ba;
  --accent: #ff6b35;
  --accent-t: #ff8b5e;
  --amber: #ffb627;
  --teal: #00d9a3;
  --red: #ff0000;
  --red-t: #ff8375;
  --mono: ui-monospace, "SFMono-Regular", "Cascadia Mono", "JetBrains Mono",
          Menlo, Consolas, "Liberation Mono", "DejaVu Sans Mono", monospace;
  --term-fs: 12.4px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { background: var(--ground); -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 15px;
  line-height: 1.62;
  /* The page must never scroll sideways; wide things scroll inside
     their own pane instead. */
  overflow-x: hidden;
  max-width: 100%;
}

/* ---------------------------------------------------------------- chrome */

.strip {
  display: flex;
  align-items: baseline;
  padding: 6px 16px;
  font-size: 11.5px;
  letter-spacing: 0.14em;
  color: var(--red);
  white-space: nowrap;
  overflow: hidden;
  border-bottom: 1px solid var(--navy);
  background: var(--ground);
}
.strip.bottom { border-bottom: 0; border-top: 1px solid var(--navy); }
.strip b { color: var(--amber); font-weight: 600; }
.strip .fill {
  flex: 1 1 auto;
  min-width: 12px;
  overflow: hidden;
  color: var(--navy);
  margin: 0 8px;
}
.strip .fill::before {
  content: "────────────────────────────────────────────────────────────"
           "────────────────────────────────────────────────────────────"
           "────────────────────────────────────────────────────────────";
}
.strip .code { color: var(--dim); }

.bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 18px;
  padding: 9px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--navy);
  font-size: 12.5px;
  letter-spacing: 0.1em;
}
.bar .home {
  color: var(--accent);
  font-weight: 700;
  text-decoration: none;
  letter-spacing: 0.18em;
}
/* The right-hand end yields first: on a phone the wordmark must survive. */
.bar .links {
  display: flex; gap: 16px; margin-left: auto;
  min-width: 0; overflow: hidden;
}
.bar .ref {
  color: var(--dim); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.bar a { color: var(--dim); text-decoration: none; }
.bar a:hover, .bar a:focus-visible { color: var(--ink); }

main { max-width: 1080px; margin: 0 auto; padding: 0 16px 56px; }

h1, h2, h3 { font-weight: 700; letter-spacing: 0.08em; }

.rule {
  display: flex;
  align-items: baseline;
  margin: 26px 0 18px;
  font-size: 14px;
  letter-spacing: 0.16em;
  color: var(--accent);
  white-space: nowrap;
  overflow: hidden;
}
h1.rule { font-size: 19px; letter-spacing: 0.18em; }
.rule .num { color: var(--amber); font-weight: 400; margin-right: 10px; }
.rule .fill {
  flex: 1 1 auto; overflow: hidden; color: var(--steel);
  margin-left: 10px; font-weight: 400;
}
.rule .fill::before {
  content: "─────────────────────────────────────────────────────────────"
           "─────────────────────────────────────────────────────────────"
           "──────────────────────────────────────────────────────·─· ·  ·";
}

p, li { color: var(--ink-2); }
p { margin: 0 0 14px; max-width: 74ch; }
strong { color: var(--ink); font-weight: 700; }
em { color: var(--amber); font-style: normal; }
a { color: var(--accent-t); text-underline-offset: 3px; text-decoration-color: var(--steel); }
a:hover, a:focus-visible { color: var(--amber); }
code {
  font-family: var(--mono); font-size: 0.92em; color: var(--teal);
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 2px; padding: 0 4px;
}

.note {
  font-size: 12.5px; color: var(--dim);
  border-left: 2px solid var(--steel);
  padding: 4px 0 4px 14px; margin: 16px 0; max-width: 80ch;
}
.note b { color: var(--amber); font-weight: 600; }
.note.warn { border-left-color: var(--red); }
.note.warn b { color: var(--red-t); font-weight: 600; }

.offscreen {
  position: absolute; width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  clip-path: inset(50%); overflow: hidden; white-space: nowrap;
}

.skip {
  position: absolute; left: -9999px;
  background: var(--accent); color: var(--ground);
  padding: 8px 14px; z-index: 99;
}
.skip:focus { left: 8px; top: 8px; }

/* --------------------------------------------------------------- panels */

.panel {
  background: var(--panel);
  border: 1px solid var(--navy);
  border-radius: 2px;
  padding: 16px 18px;
  margin: 0 0 18px;
}
.panel > :last-child { margin-bottom: 0; }
/* The alternative way in, once there is a primary one above it. Quieter
   edge, quieter ground; still a panel, not a footnote. */
.panel.secondary { border-color: var(--line-2); background: var(--panel-2); }
.panel .cap {
  display: block; font-size: 11.5px; letter-spacing: 0.16em;
  color: var(--dim); margin-bottom: 10px;
}
.panel .cap b { color: var(--amber); font-weight: 600; }

/* --------------------------------------------------------------- controls */

button, .btn {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--ink-2);
  background: var(--panel-2);
  border: 1px solid var(--steel);
  border-radius: 2px;
  padding: 8px 14px;
  cursor: pointer;
  min-height: 38px;
}
button:hover:not(:disabled), .btn:hover { color: var(--ink); border-color: var(--steel-t); }
button:focus-visible, .btn:focus-visible,
select:focus-visible, textarea:focus-visible, input:focus-visible {
  outline: 2px solid var(--amber); outline-offset: 1px;
}
button:disabled { opacity: 0.42; cursor: not-allowed; }
button.primary {
  color: var(--ground); background: var(--accent);
  border-color: var(--accent); font-weight: 700;
}
button.primary:hover:not(:disabled) { background: var(--amber); border-color: var(--amber); }
button.ghost { background: transparent; }

select, input[type="text"], input[type="password"], input[type="number"], textarea {
  font-family: var(--mono);
  font-size: 14px;
  color: var(--ink);
  background: var(--ground);
  border: 1px solid var(--steel);
  border-radius: 2px;
  padding: 9px 10px;
  width: 100%;
  max-width: 100%;
}
textarea { line-height: 1.55; resize: vertical; min-height: 96px; }
label { display: block; font-size: 11.5px; letter-spacing: 0.14em; color: var(--dim); margin-bottom: 5px; }

.fields { display: grid; gap: 14px; margin-bottom: 14px; }
/* Two columns, not four: the gate is 780px of reading measure, and four
   across truncated every <select> mid-word ("Classic — metrics visi"). The
   labels are the point of the control. */
@media (min-width: 620px) {
  .fields.row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.actions .spacer { flex: 1 1 auto; }

/* ------------------------------------------------------------ the screen */

.term {
  background: var(--ground);
  border: 1px solid var(--navy);
  border-radius: 2px;
  margin: 0 0 16px;
  /* Nothing inside may widen the page. */
  max-width: 100%;
  overflow: hidden;
}
.term > .label {
  display: flex;
  gap: 10px;
  align-items: baseline;
  padding: 7px 12px;
  border-bottom: 1px solid var(--navy);
  font-size: 11px;
  letter-spacing: 0.15em;
  color: var(--dim);
  white-space: nowrap;
  overflow: hidden;
}
.term > .label b {
  color: var(--amber); font-weight: 600;
  /* The title yields first; the WIDTH control must never be clipped off the
     right-hand edge on a phone. */
  overflow: hidden; text-overflow: ellipsis; min-width: 0;
}
.term > .label .r { color: var(--red); flex: 0 0 auto; }
.term > .label #termRef { flex: 0 0 auto; }
.term > .label .spacer { flex: 1 1 auto; min-width: 4px; }
.term > .label .widthtoggle {
  flex: 0 0 auto;
  min-height: 0; padding: 2px 8px; font-size: 10px;
  background: transparent; border-color: var(--navy); color: var(--dim);
  letter-spacing: 0.12em;
}

pre.screen {
  margin: 0;
  padding: 12px 14px 16px;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  /* FIT sizes the text so all 78 design columns fit, and lets the handful of
     over-length prose lines the engine prints soft-wrap rather than forcing a
     sideways scroll. Box-drawing rows are exactly 78 columns and so never
     wrap. */
  white-space: pre-wrap;
  font-family: var(--mono);
  font-size: var(--term-fs);
  line-height: 1.42;
  color: var(--ink-2);
  background: var(--ground);
  height: 58vh;
  min-height: 300px;
  max-height: 72vh;
  overscroll-behavior: contain;
}
pre.screen:focus-visible { outline: 1px solid var(--amber); outline-offset: -1px; }
/* FIT mode: the whole 78-column layout is squeezed into the pane so no box
   drawing is ever cut in half. READ mode keeps a legible size and scrolls
   the pane sideways instead. */
pre.screen.read { font-size: 12.4px; white-space: pre; }

.metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 18px;
  padding: 8px 14px;
  border-top: 1px solid var(--navy);
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--dim);
  background: var(--ground);
}
.metrics .m { display: flex; gap: 7px; align-items: baseline; white-space: nowrap; }
.metrics .m .k { color: var(--dim); }
.metrics .m .bar { color: var(--accent); letter-spacing: 0; }
.metrics .m .v { color: var(--ink); }
.metrics .sealed { color: var(--red-t); }

/* ------------------------------------------------------------- awaiting */

.awaiting {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 14px;
  border: 1px solid var(--navy);
  border-left: 3px solid var(--amber);
  border-radius: 2px;
  background: var(--panel);
  margin: 0 0 14px;
  font-size: 12.5px;
  letter-spacing: 0.08em;
}
.awaiting .tag {
  color: var(--amber); font-weight: 700; letter-spacing: 0.16em; white-space: nowrap;
}
.awaiting .what { color: var(--ink-2); }
.awaiting.busy { border-left-color: var(--steel); }
.awaiting.busy .tag { color: var(--steel-t); }
.awaiting.busy .tag::after {
  content: " ▚"; animation: pulse 900ms steps(2, end) infinite;
}
.awaiting.over { border-left-color: var(--red); }
.awaiting.over .tag { color: var(--red-t); }
/* A paced beat is waiting on the reader. The whole bar is the tap target,
   because touch devices have no space bar. */
.awaiting.paused { cursor: pointer; }
.awaiting.paused .tag::after {
  content: " ▸"; animation: pulse 1400ms steps(2, end) infinite;
}
@keyframes pulse { 50% { opacity: 0.25; } }

/* ----------------------------------------------------------------- tabs */

.tabs { display: flex; gap: 0; margin-bottom: -1px; flex-wrap: wrap; }
.tabs button {
  border-radius: 2px 2px 0 0;
  border-bottom-color: transparent;
  background: transparent;
  color: var(--dim);
}
.tabs button[aria-selected="true"] {
  background: var(--panel);
  color: var(--amber);
  border-color: var(--navy);
  border-bottom-color: var(--panel);
}
.tabpanel {
  border: 1px solid var(--navy);
  border-radius: 0 2px 2px 2px;
  background: var(--panel);
  padding: 14px;
}
.hint { font-size: 11.5px; color: var(--dim); margin: 8px 0 0; }
.hint kbd {
  font-family: var(--mono); font-size: 0.95em; color: var(--ink-2);
  border: 1px solid var(--steel); border-radius: 2px; padding: 0 4px;
}

/* ---------------------------------------------------------------- gate */

.gate { max-width: 780px; }
.gate .keyrow { display: grid; gap: 10px; }
@media (min-width: 640px) { .gate .keyrow { grid-template-columns: 1fr auto; align-items: end; } }
/* Teal is "a key is in place"; before that it is just status, so the
   idle/locked wording must not read as a success. */
.gate .keystate {
  font-size: 12px; letter-spacing: 0.1em; color: var(--teal);
  margin: 10px 0 0;
}
.gate .keystate.idle { color: var(--dim); }
.gate .keystate b { color: var(--ink); font-weight: 600; }
.checkrow { display: flex; gap: 9px; align-items: flex-start; margin: 12px 0 0; }
.checkrow input { width: auto; min-width: 18px; min-height: 18px; margin-top: 3px; }
.checkrow label { margin: 0; font-size: 12.5px; letter-spacing: 0; color: var(--ink-2); text-transform: none; }

/* --------------------------------------------------------------- ending */

.ending {
  border: 1px solid var(--red);
  border-radius: 2px;
  background: var(--panel);
  padding: 16px 18px;
  margin: 0 0 18px;
}
.ending .verdict {
  font-size: 12px; letter-spacing: 0.2em; color: var(--red-t); margin-bottom: 6px;
}
.ending h2 { font-size: 17px; letter-spacing: 0.16em; color: var(--amber); margin: 0 0 10px; }
.ending p { white-space: pre-wrap; }

/* ---------------------------------------------------------------- alerts */

.alert {
  border: 1px solid var(--red);
  border-left-width: 3px;
  border-radius: 2px;
  background: var(--panel);
  padding: 10px 14px;
  margin: 0 0 14px;
  font-size: 12.5px;
  color: var(--ink-2);
}
.alert b { color: var(--red-t); letter-spacing: 0.14em; }
.alert .again { color: var(--amber); letter-spacing: 0.1em; }

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

footer { margin-top: 40px; }
footer .inner {
  max-width: 1080px; margin: 0 auto; padding: 18px 16px 36px;
  font-size: 12.5px; color: var(--dim);
}
footer .inner p { color: var(--dim); font-size: 12.5px; max-width: 80ch; }
footer .inner a { color: var(--dim); }
footer .inner a:hover { color: var(--accent); }

/* --------------------------------------------------------------- mobile */

@media (max-width: 640px) {
  body { font-size: 14.5px; }
  main { padding: 0 10px 40px; }
  .strip .code { display: none; }
  .strip .fill { margin-right: 0; }
  h1.rule { font-size: 16px; }
  pre.screen { height: 52vh; min-height: 240px; padding: 10px 8px 14px; }
  .actions button { flex: 1 1 auto; }
  .term > .label { font-size: 10px; letter-spacing: 0.1em; gap: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
