:root {
  color-scheme: light;
  --bg: #f3eee6;
  --ink: #1c1612;
  --muted: #5c5148;
  --card: #fffaf4;
  --field: #fff;
  --line: #e4d5c4;
  --ember: #b4330c;
  --on-ember: #fff7ef;
  --ember-soft: #fde7d8;
  --pine: #1d6b45;
  --danger: #9d1c1c;
  --shadow: 0 16px 40px rgba(70, 36, 14, 0.06);
  --serif: "Iowan Old Style", Palatino, "Palatino Linotype", Georgia, serif;
  --sans: "Avenir Next", "Segoe UI", sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #12151a;
    --ink: #f4efe8;
    --muted: #c4b6a8;
    --card: #1c212a;
    --field: #14181f;
    --line: #343b48;
    --ember: #ff7a45;
    --on-ember: #1a100c;
    --ember-soft: #3a241c;
    --pine: #8ddeaf;
    --danger: #ff8d86;
    --shadow: 0 16px 40px rgba(0, 0, 0, 0.28);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(900px 420px at 0% -10%, rgba(180, 51, 12, 0.16), transparent 55%),
    radial-gradient(700px 380px at 100% 0%, rgba(244, 176, 92, 0.18), transparent 50%),
    var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.45;
}

body.gating { overflow: hidden; }

.skip {
  position: absolute;
  left: 12px;
  top: -40px;
  background: var(--card);
  color: var(--ink);
  padding: 8px 12px;
  border-radius: 8px;
  z-index: 5;
}

.skip:focus { top: 12px; }

.top, main, footer { width: min(1040px, calc(100% - 32px)); margin-inline: auto; }

.top {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px 28px;
  align-items: end;
  padding: 20px 0 4px;
}

.brand { display: flex; gap: 12px; align-items: center; }

.brand img { border-radius: 8px; display: block; }

.eyebrow {
  margin: 0;
  font-size: 0.75rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ember);
  font-weight: 700;
}

h1, h2, .detail-name, .empty-title { font-family: var(--serif); font-weight: 600; }

h1 { margin: 0; font-size: clamp(1.9rem, 4vw, 2.45rem); letter-spacing: -0.03em; line-height: 1; }

.detail h2 { margin: 0 0 2px; font-size: 1.65rem; letter-spacing: -0.03em; line-height: 1.1; }

.lede { margin: 0; color: var(--muted); max-width: 42rem; }

.tally { margin: 0; font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; }

.stage {
  display: grid;
  gap: 16px;
  margin-top: 18px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 14px 16px;
  min-width: 0;
}

.field { display: grid; gap: 6px; margin-bottom: 12px; }

label, .field > label { font-size: 0.875rem; font-weight: 650; }

.opt { color: var(--muted); font-weight: 500; }

input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  background: var(--field);
  color: var(--ink);
  border-radius: 12px;
  padding: 10px 12px;
  font: inherit;
}

input.mono, #url, #spark-url { font-family: var(--mono); font-size: 0.92rem; }

.actions, .toolbar-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.btn {
  min-height: 44px;
  padding: 0 16px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-weight: 650;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn.primary { background: var(--ember); border-color: transparent; color: var(--on-ember); }

.btn.ghost { background: transparent; }

.btn.danger { background: transparent; color: var(--danger); padding-inline: 12px; }

.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.error { color: var(--danger); margin: 0 0 12px; }

.status, .fine, .quiet, figcaption, .lens { color: var(--muted); }

.status { min-height: 1.4em; margin: 12px 0 0; }

.detail-host { margin: 2px 0 8px; color: var(--muted); }

.delta { margin: 0; font-weight: 700; }

.delta[data-kind="shorter"] { color: var(--pine); }

.lens { margin: 4px 0 8px; font-variant-numeric: tabular-nums; }

.meter {
  height: 8px;
  border-radius: 999px;
  background: var(--ember-soft);
  overflow: hidden;
  margin-bottom: 14px;
}

#meter {
  display: block;
  height: 100%;
  background: var(--pine);
  border-radius: inherit;
}

#meter[data-kind="longer"], #meter[data-kind="same"] { background: var(--ember); }

.spark-foot {
  display: grid;
  grid-template-columns: 132px minmax(0, 1fr);
  gap: 12px;
  align-items: end;
  margin-top: 8px;
}

.qr-wrap { margin: 0; }

#qr svg { width: 100%; height: auto; display: block; border-radius: 10px; }

figcaption { margin-top: 6px; font-size: 0.75rem; line-height: 1.3; }

.history { margin-top: 8px; }

.open-count { margin: 0 0 8px; font-variant-numeric: tabular-nums; }

.bars {
  height: 44px;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  align-items: end;
}

.bars span {
  display: block;
  height: max(4px, var(--h));
  background: var(--ember);
  border-radius: 5px 5px 2px 2px;
  opacity: 0.9;
}

.bars span[data-zero="true"] { opacity: 0.35; }

.bar-labels {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.75rem;
  text-align: center;
}

.board { margin: 22px 0 8px; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
}

.toolbar h2 { margin: 0; font-size: 1.4rem; }

.toolbar input { flex: 1 1 180px; min-width: 0; }

.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }

.item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 6px 6px 6px 8px;
}

.item.is-selected { border-color: var(--ember); box-shadow: inset 3px 0 0 var(--ember); }

.item-main {
  min-height: 44px;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 12px;
  text-align: left;
  background: transparent;
  border: 0;
  color: inherit;
  font: inherit;
  padding: 6px 8px;
  border-radius: 10px;
  cursor: pointer;
  min-width: 0;
}

.item-name { font-weight: 700; flex: 1 1 10rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.item-host, .item-meta { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.item-meta { margin-left: auto; }

.item-meta { font-variant-numeric: tabular-nums; }

.chip {
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 8px;
  color: var(--muted);
}

.none, .empty { color: var(--muted); }

.empty-title { margin: 0 0 4px; color: var(--ink); font-size: 1.4rem; }

.gate {
  position: fixed;
  inset: 0;
  background: rgba(18, 16, 14, 0.46);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 4;
}

.gate[hidden], [hidden] { display: none !important; }

.gate-card {
  width: min(560px, 100%);
  max-height: calc(100dvh - 32px);
  overflow: auto;
  background: var(--card);
  color: var(--ink);
  border-radius: 20px;
  padding: 22px 20px;
  box-shadow: var(--shadow);
}

.gate-card h2 { margin: 6px 0 12px; font-size: clamp(1.55rem, 4vw, 2rem); letter-spacing: -0.03em; line-height: 1.15; }

.gate-url {
  margin: 0 0 14px;
  max-height: 7.5rem;
  overflow: auto;
  font-family: var(--mono);
  font-size: 0.92rem;
  overflow-wrap: anywhere;
  background: var(--field);
  border-radius: 12px;
  padding: 12px;
  border: 1px solid var(--line);
}

.gate .actions { position: sticky; bottom: 0; background: var(--card); padding-top: 4px; }

.fine { font-size: 0.875rem; margin: 14px 0 0; }

footer { padding: 8px 0 32px; color: var(--muted); font-size: 0.9rem; }

:focus { outline: none; }

:focus-visible {
  outline: 2px solid var(--ember);
  outline-offset: 3px;
}

@media (min-width: 880px) {
  .stage { grid-template-columns: minmax(0, 1.15fr) minmax(280px, 0.85fr); align-items: start; }
  .detail { position: sticky; top: 16px; }
}

@media (max-width: 800px) {
  .top { grid-template-columns: 1fr; align-items: start; padding-top: 20px; }
  .tally { white-space: normal; }
  .item-meta { margin-left: 0; }
}

@media (max-width: 420px) {
  .top, main, footer { width: min(1040px, calc(100% - 24px)); }
  .actions .btn, .gate .btn { flex: 1 1 100%; }
  .spark-foot { grid-template-columns: 112px minmax(0, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; }
}
