/* Layout: a lottery ticket for the puzzle plus a large live readout in the main column;
   power controls docked on the right. One column on phones, with the start button fixed at the bottom. */
:root {
  --bg: #edf0f4;
  --surface: #ffffff;
  --surface-2: #f4f6f9;
  --ink: #111827;
  --muted: #5b6578;
  --line: #d7dde6;
  --accent: #c94a10;
  --accent-ink: #ffffff;
  --accent-soft: #fbe6da;
  --run: #0a8a78;
  --run-soft: #d2f0ea;
  --run-ink: #066b5b;
  --accent-text: #a83c0b;
  --warn: #a15c00;
  --danger: #c0302b;
  --chart: #2f5bc4;
  --chart-fill: rgba(47, 91, 196, 0.12);
  --tick: rgba(17, 24, 39, 0.28);
  --shadow: 0 1px 2px rgba(17, 24, 39, 0.06), 0 8px 24px -12px rgba(17, 24, 39, 0.18);

  --font-display: "Bricolage Grotesque", "Avenir Next", "Segoe UI", system-ui, sans-serif;
  --font-body: "Instrument Sans", "Helvetica Neue", "Segoe UI", system-ui, sans-serif;
  --font-mono: "Martian Mono", "SF Mono", ui-monospace, Menlo, Consolas, monospace;

  --step--1: 0.8125rem;
  --step-0: 0.9375rem;
  --step-1: 1.125rem;
  --step-2: 1.5rem;
  --step-3: clamp(2rem, 1.4rem + 2.6vw, 3rem);
  --step-4: clamp(2.4rem, 1.6rem + 4vw, 4.25rem);
  --radius: 14px;
  --radius-sm: 9px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1017;
    --surface: #121a25;
    --surface-2: #19222f;
    --ink: #e7ecf3;
    --muted: #96a2b6;
    --line: #253144;
    --accent: #ff8c47;
    --accent-ink: #1d0d03;
    --accent-soft: #3b2214;
    --run: #3fd0b8;
    --run-soft: #12332e;
    --run-ink: #3fd0b8;
    --accent-text: #ff8c47;
    --warn: #f0b155;
    --danger: #ff6d66;
    --chart: #82a6ff;
    --chart-fill: rgba(130, 166, 255, 0.16);
    --tick: rgba(231, 236, 243, 0.3);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 30px -14px rgba(0, 0, 0, 0.7);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1017;
  --surface: #121a25;
  --surface-2: #19222f;
  --ink: #e7ecf3;
  --muted: #96a2b6;
  --line: #253144;
  --accent: #ff8c47;
  --accent-ink: #1d0d03;
  --accent-soft: #3b2214;
  --run: #3fd0b8;
  --run-soft: #12332e;
  --run-ink: #3fd0b8;
  --accent-text: #ff8c47;
  --warn: #f0b155;
  --danger: #ff6d66;
  --chart: #82a6ff;
  --chart-fill: rgba(130, 166, 255, 0.16);
  --tick: rgba(231, 236, 243, 0.3);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 30px -14px rgba(0, 0, 0, 0.7);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

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

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

h1, h2 { font-family: var(--font-display); text-wrap: balance; margin: 0; line-height: 1.15; }
h2 { font-size: var(--step-1); font-weight: 700; letter-spacing: -0.01em; }
p { margin: 0; }
sup { font-size: 0.65em; line-height: 0; }
a { color: inherit; text-underline-offset: 2px; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--chart); outline-offset: 2px; }

.mono { font-family: var(--font-mono); font-stretch: 87.5%; }
.label, .eyebrow, dt {
  font-size: var(--step--1);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
.hint { font-size: var(--step--1); color: var(--muted); }

.page {
  max-width: 1240px;
  margin: 0 auto;
  padding-block: 20px 40px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Top bar */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; flex: none; }
.brand-mark { width: 28px; height: 28px; }
.brand-dots circle { fill: var(--line); }
.brand-hit { fill: var(--accent); }
.brand-name { font-family: var(--font-display); font-weight: 800; font-size: var(--step-1); letter-spacing: -0.02em; }
.brand-slash { color: var(--accent); margin-inline: 1px; }

.status {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 12px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line);
  font-size: var(--step--1); font-weight: 600;
  min-width: 0;
}
#statusText { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status-dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status[data-state="running"] { border-color: var(--run); color: var(--run-ink); background: var(--run-soft); }
.status[data-state="running"] .status-dot { background: var(--run); }
.status[data-state="paused"] { color: var(--warn); border-color: var(--warn); }
.status[data-state="paused"] .status-dot { background: var(--warn); }
.status[data-state="found"] { color: var(--accent-text); border-color: var(--accent); background: var(--accent-soft); }
.status[data-state="found"] .status-dot { background: var(--accent); }
.status[data-state="error"] { color: var(--danger); border-color: var(--danger); }
.status[data-state="error"] .status-dot { background: var(--danger); }

.solved-banner {
  padding: 12px 16px; border-radius: var(--radius-sm);
  background: var(--run-soft); border: 1px solid var(--run); color: var(--run-ink); font-weight: 600;
}
.saved-find {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 12px 16px; border-radius: var(--radius-sm);
  background: var(--accent-soft); border: 1px solid var(--accent);
}

/* Grid. Phones: one column, everything below the live readout folded away. */
.layout {
  display: grid;
  gap: 20px;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "ticket" "readout" "controls" "odds" "safety" "local";
}
@media (min-width: 1040px) {
  .layout {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 360px;
    grid-template-areas:
      "ticket ticket controls"
      "readout readout controls"
      "odds safety controls"
      "local local controls";
    align-items: start;
  }
  .controls {
    position: sticky; top: calc(env(safe-area-inset-top, 0px) + 20px); align-self: start;
    max-height: calc(100dvh - 40px); overflow-y: auto; overscroll-behavior: contain;
  }
}
.ticket { grid-area: ticket; }
.readout { grid-area: readout; }
.controls { grid-area: controls; }
.odds { grid-area: odds; }
.safety { grid-area: safety; }
.local-fold { grid-area: local; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

/* Folded sections: the summary is the heading, a chevron shows the state. */
details > summary { list-style: none; cursor: pointer; }
details > summary::-webkit-details-marker { display: none; }
.fold { gap: 0; padding-block: 0; }
.fold > summary {
  display: flex; align-items: center; gap: 8px 12px; flex-wrap: wrap;
  padding-block: 18px; padding-right: 28px; position: relative;
}
.fold > summary::after, .more > summary::after {
  content: ""; position: absolute; right: 2px; top: 50%; width: 8px; height: 8px;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: translateY(-70%) rotate(45deg); transition: transform 0.15s ease;
}
.fold[open] > summary::after, .more[open] > summary::after { transform: translateY(-30%) rotate(-135deg); }
.fold-peek { font-size: var(--step--1); color: var(--muted); font-weight: 600; }
.fold[open] .fold-peek { display: none; }
.fold-body { display: flex; flex-direction: column; gap: 14px; padding-bottom: 20px; }

.more > summary {
  position: relative; padding: 10px 28px 10px 0;
  font-size: var(--step--1); font-weight: 600; color: var(--muted);
}
.more > summary:hover { color: var(--ink); }
.more-body { display: flex; flex-direction: column; gap: 16px; padding-top: 8px; }
.controls .more { border-top: 1px solid var(--line); }

/* Ticket */
.ticket {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  position: relative;
  min-width: 0;
}
.ticket-stub { padding: 20px; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.ticket-body { padding: 4px 20px; min-width: 0; }
.ticket-body[open] { padding-bottom: 18px; }
.ticket-stub { border-bottom: 2px dashed var(--line); position: relative; }
.ticket-stub::before, .ticket-stub::after {
  content: ""; position: absolute; bottom: -11px; width: 20px; height: 20px; border-radius: 50%;
  background: var(--bg); border: 1px solid var(--line);
}
.ticket-stub::before { left: -11px; clip-path: inset(0 0 0 50%); }
.ticket-stub::after { right: -11px; clip-path: inset(0 50% 0 0); }
.title-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 8px 16px; flex-wrap: wrap; }
.puzzle-title {
  font-size: var(--step-4);
  font-weight: 800;
  line-height: 0.95;
  letter-spacing: -0.03em;
  font-variation-settings: "opsz" 96;
}
.puzzle-title span { color: var(--accent); }

.mode-switch { display: inline-flex; padding: 3px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); align-self: flex-start; }
.mode-switch button {
  border: 0; background: transparent; padding: 6px 14px; border-radius: 999px; cursor: pointer;
  font-size: var(--step--1); font-weight: 600; color: var(--muted);
}
.mode-switch button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }
.mode-switch button:disabled { cursor: not-allowed; opacity: 0.6; }

.puzzle-pick { display: flex; flex-direction: column; gap: 6px; font-size: var(--step--1); color: var(--muted); font-weight: 600; }
.puzzle-pick select {
  appearance: none;
  padding: 9px 36px 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5 6 6.5 11 1.5' fill='none' stroke='%238a94a6' stroke-width='1.6'/%3E%3C/svg%3E") no-repeat right 12px center;
  color: var(--ink);
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  text-overflow: ellipsis;
}
@media (pointer: coarse) { .puzzle-pick select { font-size: 16px; } }
.puzzle-pick select:disabled { cursor: not-allowed; opacity: 0.6; }

.prize { display: flex; flex-direction: column; align-items: flex-end; gap: 0; }
.prize strong {
  font-family: var(--font-display);
  font-size: var(--step-3);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1;
  color: var(--ink);
}
.prize strong.solved { color: var(--muted); font-size: var(--step-2); }

.facts { display: grid; gap: 12px; margin: 0; }
@media (min-width: 720px) { .facts { grid-template-columns: minmax(0, 1.3fr) minmax(0, 1.3fr) minmax(0, 0.8fr); gap: 12px 20px; } }
.facts div { display: grid; align-content: start; gap: 2px; min-width: 0; }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.address { font-size: var(--step--1); }
.range { font-size: var(--step--1); line-height: 1.7; }
.range-sep { font-family: var(--font-body); color: var(--muted); margin-inline: 4px; }

/* Readout */
.rate { display: flex; flex-direction: column; gap: 4px; }
.rate-value { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.rate-value .rate-num {
  font-family: var(--font-mono);
  font-size: var(--step-4);
  font-weight: 500;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.unit { font-weight: 600; color: var(--muted); }
.spark { width: 100%; height: 72px; display: block; }
.readout-top { display: grid; gap: 12px; }
@media (min-width: 720px) { .readout-top { grid-template-columns: minmax(0, auto) minmax(0, 1fr); align-items: end; gap: 24px; } }

/* Progress: the share of the puzzle searched so far, with ten decimals it moves visibly. */
.progress { display: flex; flex-direction: column; gap: 6px; padding-top: 16px; border-top: 1px solid var(--line); }
.progress-rows { display: grid; gap: 12px; }
@media (min-width: 720px) { .progress-rows:has(#progressPool:not([hidden])) { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; } }
.progress-row { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.progress-who { font-size: var(--step--1); font-weight: 600; color: var(--ink); overflow-wrap: anywhere; }
.progress-keys { font-size: var(--step--1); color: var(--muted); font-variant-numeric: tabular-nums; }
.progress-value { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.progress-num {
  font-family: var(--font-mono);
  font-stretch: 87.5%;
  font-size: clamp(1.6rem, 1.2rem + 1.6vw, 2.4rem);
  font-weight: 500;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  line-height: 1.05;
  color: var(--accent-text);
  overflow-wrap: anywhere;
}
.progress .hint sup { line-height: 0; }

.sync-line { display: flex; align-items: center; gap: 4px 8px; flex-wrap: wrap; font-size: var(--step--1); color: var(--muted); }
.sync-dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.sync-line[data-state="on"] .sync-dot { background: var(--run); }
.sync-line[data-state="offline"] .sync-dot { background: var(--warn); }
.sync-line[data-state="checking"] .sync-dot, .sync-line[data-state="connecting"] .sync-dot { background: var(--muted); }
.text-btn {
  border: 0; background: none; padding: 4px 2px; margin-left: auto; cursor: pointer;
  font-weight: 600; color: var(--accent-text); text-decoration: underline; text-underline-offset: 3px;
}
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px 20px; margin: 0; }
.stats div { display: grid; grid-template-rows: 1fr auto; gap: 2px; min-width: 0; }
.stats dd { margin: 0; font-family: var(--font-mono); font-size: var(--step-1); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stats dd .unit { font-family: var(--font-body); font-size: var(--step--1); white-space: nowrap; }

/* Controls */
.controls h2 { margin-top: 4px; }
.engine { display: flex; flex-direction: column; gap: 6px; }
.engine-switch { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-self: stretch; }
.engine-switch button { padding-inline: 8px; }
.run { display: flex; flex-direction: column; gap: 6px; }
.run-row { display: flex; gap: 8px; }
.run-row .run-btn { flex: 1 1 auto; min-width: 0; }
.pause-btn { flex: none; border-radius: 12px; padding-inline: 16px; }
.run-btn {
  width: 100%;
  border: 0;
  border-radius: 12px;
  padding: 16px 20px;
  font-family: var(--font-display);
  font-size: var(--step-1);
  font-weight: 700;
  letter-spacing: -0.01em;
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.12s ease;
}
.run-btn:hover { filter: brightness(1.06); }
.run-btn:active { transform: translateY(1px); }
.run-btn.is-running { background: var(--ink); color: var(--surface); }
.run-btn:disabled { background: var(--surface-2); color: var(--muted); box-shadow: inset 0 0 0 1px var(--line); cursor: not-allowed; filter: none; transform: none; }
.run-note { text-align: center; font-size: var(--step--1); color: var(--muted); }

.presets { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.preset {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  padding: 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--surface-2);
  cursor: pointer; text-align: left; min-width: 0;
}
.preset strong { font-size: var(--step--1); }
.preset span { font-size: 0.75rem; line-height: 1.3; color: var(--muted); white-space: pre-line; }
.preset[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }

.field { display: flex; flex-direction: column; gap: 8px; }
.field-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.field-head label { font-weight: 600; }
.field-head output { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-weight: 500; }

input[type="range"] {
  appearance: none;
  width: 100%;
  height: 28px;
  background: transparent;
  cursor: pointer;
  --fill: 50%;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 6px; border-radius: 999px;
  background: linear-gradient(to right, var(--accent) var(--fill), var(--line) var(--fill));
}
input[type="range"]::-moz-range-track { height: 6px; border-radius: 999px; background: var(--line); }
input[type="range"]::-moz-range-progress { height: 6px; border-radius: 999px; background: var(--accent); }
input[type="range"]::-webkit-slider-thumb {
  appearance: none; width: 22px; height: 22px; margin-top: -8px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--accent); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}
input[type="range"]::-moz-range-thumb {
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--accent);
}
input[type="range"]:disabled { cursor: not-allowed; opacity: 0.55; }
@media (pointer: coarse) {
  input[type="range"] { height: 36px; }
  input[type="range"]::-webkit-slider-thumb { width: 28px; height: 28px; margin-top: -11px; }
  input[type="range"]::-moz-range-thumb { width: 24px; height: 24px; }
}

.load { display: flex; flex-direction: column; gap: 8px; padding: 12px; border-radius: var(--radius-sm); background: var(--surface-2); }
.load-head { display: flex; justify-content: space-between; gap: 12px; font-size: var(--step--1); color: var(--muted); }
.load-head strong { color: var(--ink); font-weight: 600; text-align: right; }
#loadScale { font-size: 0.75rem; }
.load-bar { height: 8px; border-radius: 999px; background: var(--line); overflow: hidden; }
.load-bar span { display: block; height: 100%; width: 10%; border-radius: inherit; background: var(--run); transition: width 0.25s ease; }
.load-bar span.high { background: var(--warn); }

.toggles { display: flex; flex-direction: column; gap: 10px; }
.browser-only { display: contents; }
.toggle { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.toggle-ui {
  flex: none; width: 36px; height: 20px; border-radius: 999px; position: relative;
  background: var(--surface-2); box-shadow: inset 0 0 0 1.5px var(--muted);
  transition: background 0.15s ease;
}
.toggle-ui::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%;
  background: var(--muted); transition: transform 0.15s ease;
}
.toggle input:checked + .toggle-ui { background: var(--run); box-shadow: none; }
.toggle input:checked + .toggle-ui::after { transform: translateX(16px); background: #ffffff; }
.toggle:has(input:disabled) { cursor: not-allowed; color: var(--muted); }
.toggle input:disabled + .toggle-ui { opacity: 0.5; }
.toggle input:focus-visible + .toggle-ui { outline: 2px solid var(--chart); outline-offset: 2px; }

.thread-list { display: flex; flex-direction: column; gap: 6px; padding-top: 4px; border-top: 1px solid var(--line); }
.thread-row {
  display: grid; grid-template-columns: 2.2em minmax(0, 1fr) auto; align-items: center; gap: 10px;
  font-size: var(--step--1); font-variant-numeric: tabular-nums;
}
.thread-row .mono { color: var(--muted); }
.thread-meter { height: 6px; border-radius: 999px; background: var(--line); overflow: hidden; }
.thread-meter span { display: block; height: 100%; width: 0; background: var(--run); transition: width 0.3s ease; }
.thread-row.is-paused .thread-meter span { background: var(--warn); }

/* Keyspace strip under the progress */
.keyspace-canvas { width: 100%; height: 56px; display: block; margin-top: 4px; }
.keyspace-scale { display: flex; justify-content: space-between; gap: 12px; font-size: 0.75rem; color: var(--muted); margin-top: -6px; }

/* Odds and safety */
.odds-grid { display: grid; gap: 14px; margin: 0; }
.odds-grid div { display: grid; gap: 2px; }
.odds-grid dd { margin: 0; font-family: var(--font-display); font-size: var(--step-2); font-weight: 700; letter-spacing: -0.01em; }
.odds-note { color: var(--muted); }
.steps { margin: 0; padding-left: 1.3em; display: flex; flex-direction: column; gap: 10px; }
.steps li::marker { font-family: var(--font-mono); color: var(--accent); }

/* Local engine: folded away until a program is connected (the program's own page opens it). */
.local { display: flex; flex-direction: row; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px 20px; padding-bottom: 20px; }
.local-text { min-width: 0; flex: 1 1 260px; }
.local-badge {
  font-size: 0.75rem; font-weight: 600; padding: 2px 10px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--muted); white-space: nowrap;
}
.local-fold[data-state="connected"] .local-badge { border-color: var(--run); color: var(--run-ink); background: var(--run-soft); }
.local-fold[data-state="pair"] .local-badge { border-color: var(--warn); color: var(--warn); }
.local-fold[data-state="error"] .local-badge { border-color: var(--danger); color: var(--danger); }
.local-form { display: flex; align-items: flex-end; gap: 8px; flex-wrap: wrap; min-width: 0; }
.local-field { display: flex; flex-direction: column; gap: 4px; font-size: var(--step--1); font-weight: 600; color: var(--muted); min-width: 0; }
.local-field input {
  padding: 8px 10px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--surface-2);
  color: var(--ink); font-family: var(--font-mono); font-stretch: 87.5%; font-weight: 500; min-width: 0;
}
.local-port input { width: 9ch; }
.local-code input { width: 15ch; text-transform: uppercase; letter-spacing: 0.06em; }
.local-code input::placeholder { color: var(--muted); opacity: 0.6; letter-spacing: 0.06em; }
@media (pointer: coarse) { .local-field input { font-size: 16px; } }
.local-form button { padding-block: 8px; }
.local-form button:disabled { cursor: progress; color: var(--muted); }
.local-info { flex: 1 1 100%; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 20px; margin: 0; }
@media (min-width: 720px) { .local-info { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.local-info div { display: grid; align-content: start; gap: 2px; min-width: 0; }
.local-info dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.local-msg { flex: 1 1 100%; font-size: var(--step--1); padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface-2); overflow-wrap: anywhere; }
.local-msg[data-state="error"] { color: var(--danger); background: transparent; border: 1px solid var(--danger); }
.local-msg a { font-family: var(--font-mono); font-stretch: 87.5%; font-weight: 600; }

.ghost-btn, .primary-btn, .copy-btn, .link-btn {
  border-radius: var(--radius-sm); padding: 9px 14px; font-weight: 600; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface-2);
}
.ghost-btn:disabled { cursor: not-allowed; color: var(--muted); }
.primary-btn { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.primary-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.link-btn { background: transparent; border-color: var(--accent); }

.footer { color: var(--muted); font-size: var(--step--1); text-align: center; padding-top: 8px; }

/* Found dialog, and the sync dialog in the same shape */
.found, .sheet {
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 0;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 30px 80px -20px rgba(0, 0, 0, 0.5);
}
.found::backdrop, .sheet::backdrop { background: rgba(8, 12, 20, 0.6); backdrop-filter: blur(3px); }
.found-inner, .sheet-inner { padding: 24px; display: flex; flex-direction: column; gap: 14px; }
.sheet { border-color: var(--line); }
.sheet h2 { font-size: var(--step-2); font-weight: 800; letter-spacing: -0.02em; }
.sheet-inner > p { overflow-wrap: anywhere; }
.sync-msg { font-size: var(--step--1); font-weight: 600; color: var(--run-ink); }
.sync-msg[data-state="pending"] { color: var(--muted); }
.pool-note { padding: 12px; border-radius: var(--radius-sm); background: var(--accent-soft); font-size: var(--step--1); }
#addressInput { width: 100%; font-size: var(--step--1); }
@media (pointer: coarse) { #addressInput { font-size: 16px; } }
.sheet.solved { border-color: var(--run); }
.sync-msg[data-state="error"] { color: var(--danger); }
.found h2 { font-size: clamp(1.6rem, 1.2rem + 2vw, 2.4rem); font-weight: 800; letter-spacing: -0.02em; line-height: 1.1; }
.found-inner p, .found-inner li { overflow-wrap: anywhere; }
.found-inner code.mono { font-size: 0.9em; }
.found-save { font-size: var(--step--1); font-weight: 600; }
.found-save[data-state="ok"] { color: var(--run-ink); }
.found-save[data-state="error"] { color: var(--danger); }
.found-save[data-state="pending"] { color: var(--muted); }
.found-file { font-weight: 500; }
.found-file code { font-weight: 600; }
.found-backup { display: flex; flex-direction: column; gap: 6px; padding: 12px; border-radius: var(--radius-sm); border: 1px solid var(--line); font-size: var(--step--1); }
.found-backup ul { margin: 0; padding-left: 1.2em; }
.secret { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 10px; align-items: center; }
.secret .label { grid-column: 1 / -1; }
.secret code {
  font-family: var(--font-mono); font-stretch: 87.5%; font-size: var(--step--1);
  padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--line);
  overflow-wrap: anywhere; user-select: all; min-width: 0;
}
.found-share { display: flex; flex-wrap: wrap; gap: 10px; }
.found-share > button { flex: 1 1 200px; padding-block: 12px; }
.found-share-msg { flex: 1 1 100%; font-size: var(--step--1); font-weight: 600; color: var(--run-ink); }
.found-share-msg[data-state="error"] { color: var(--danger); }
.found-lock { font-size: var(--step--1); color: var(--muted); }
.found-warn { padding: 12px; border-radius: var(--radius-sm); background: var(--accent-soft); font-size: var(--step--1); }
.found.is-test { border-color: var(--run); }
.found.is-test .found-warn { background: var(--run-soft); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }
.link-btn.danger { border-color: var(--danger); color: var(--danger); margin-right: auto; }
.link-btn.danger[data-armed="true"] { background: var(--danger); color: var(--surface); }
@media (max-width: 479px) {
  .status-detail { display: none; }
  .secret { grid-template-columns: minmax(0, 1fr); }
  .secret .copy-btn { justify-self: start; }
  .dialog-actions > * { flex: 1 1 auto; }
}

/* Phones: tighter spacing, start button fixed at the bottom */
@media (max-width: 719px) {
  html { scroll-padding-bottom: calc(130px + env(safe-area-inset-bottom, 0px)); }
  .page { gap: 14px; padding-top: 14px; padding-bottom: calc(120px + env(safe-area-inset-bottom, 0px)); }
  .layout { gap: 14px; }
  .panel { padding: 16px; gap: 14px; }
  .fold { padding-block: 0; }
  .fold > summary { padding-block: 15px; }
  .fold-body { padding-bottom: 16px; }
  .ticket-stub { padding: 16px; gap: 10px; }
  .ticket-body { padding-inline: 16px; }
  .ticket-body[open] { padding-bottom: 14px; }
  .spark { height: 56px; }
  .stats { gap: 10px 16px; }
  .stats dd { font-size: var(--step-0); }
  .run {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
    padding: 12px max(16px, env(safe-area-inset-right, 0px)) calc(12px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
    background: var(--surface);
    border-top: 1px solid var(--line);
    box-shadow: 0 -8px 24px -16px rgba(0, 0, 0, 0.35);
  }
}

/* Screen saver: true black (OLED pixels off) in every theme, above everything but dialogs */
.saver {
  position: fixed; inset: 0; z-index: 100;
  display: block; width: 100%; height: 100%; margin: 0; padding: 0; border: 0; border-radius: 0;
  background: #000; color: #a3a8b0; cursor: default; text-align: left;
  font: inherit; touch-action: none; -webkit-tap-highlight-color: transparent;
  animation: saver-in 1.2s ease-out;
}
.saver:focus-visible { outline: none; }
.saver-box {
  position: absolute; left: 0; top: 0;
  display: flex; flex-direction: column; gap: 6px;
  padding: 12px; transition: opacity 0.8s ease;
}
.saver-box.is-moving { opacity: 0; }
.saver-rate { color: #e8eaee; font-family: var(--font-mono); font-stretch: 87.5%; font-size: var(--step-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.saver-unit { font-size: var(--step--1); }
.saver-note, .saver-hint { font-size: var(--step--1); white-space: nowrap; }
.saver-note { color: #a3a8b0; }
.saver-hint { color: #5d626b; }
@keyframes saver-in { from { opacity: 0; } }

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