/* ─────────────────────────────────────────────────────────────────────────────
   playground.shen.id — design system

   The site commits to a single dark treatment on purpose. Everything here is an
   instrument reading off a live machine, and instruments read better on black;
   a light variant would be a second design, not a translation of this one.
   `color-scheme: dark` is declared so form controls and scrollbars follow.

   Colour roles are split deliberately:
     --accent      chrome only (headings, links, focus). Never encodes data.
     --series-1..3 the only colours allowed to carry a data series. These are
                   validated for the dark band, chroma, all-pairs CVD separation
                   and 3:1 contrast against --bg.
   Text always wears an ink token, never a series colour.
   ──────────────────────────────────────────────────────────────────────────── */

:root {
  color-scheme: dark;

  --bg: #0b0c0e;
  --surface: #12141a;
  --surface-2: #171a21;
  --hairline: rgba(255, 255, 255, 0.08);
  --hairline-strong: rgba(255, 255, 255, 0.16);

  --ink: #f2f0ed;
  --ink-2: #b9bcc4;
  --ink-3: #7c828d;

  --accent: #ffb454;
  --accent-wash: rgba(255, 180, 84, 0.12);
  --link: #7cc4f8;

  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;

  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;

  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --r: 10px;
  --r-sm: 6px;
  --gutter: clamp(1.15rem, 4vw, 2.5rem);
  --measure: 68ch;
}

*,
*::before,
*::after { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink-2);
  font: 400 16px/1.65 var(--sans);
  font-synthesis-weight: none;
  /* A hairline grid, barely there — the graph-paper the instruments sit on. */
  background-image:
    linear-gradient(to right, rgba(255, 255, 255, 0.018) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255, 255, 255, 0.018) 1px, transparent 1px);
  background-size: 48px 48px;
  background-position: center top;
}

/* ── typography ─────────────────────────────────────────────────────────── */

h1, h2, h3 {
  color: var(--ink);
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.015em;
  margin: 0;
  text-wrap: balance;
}

h1 { font-size: clamp(1.75rem, 4.5vw, 2.6rem); }
h2 { font-size: clamp(1.15rem, 2.4vw, 1.4rem); }
h3 { font-size: 1rem; }

p { margin: 0 0 1em; max-width: var(--measure); }
p:last-child { margin-bottom: 0; }

a {
  color: var(--link);
  text-decoration-color: color-mix(in srgb, var(--link) 40%, transparent);
  text-underline-offset: 3px;
}
a:hover { text-decoration-color: currentColor; }

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

strong { color: var(--ink); font-weight: 600; }

code, kbd, samp, .mono { font-family: var(--mono); font-size: 0.92em; }

code {
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  border-radius: var(--r-sm);
  padding: 0.1em 0.4em;
  color: var(--ink);
}

pre {
  margin: 0;
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--r);
  padding: 1rem 1.15rem;
  font-family: var(--mono);
  font-size: 0.85rem;
  line-height: 1.6;
  color: var(--ink-2);
}
pre code { background: none; border: 0; padding: 0; }

/* The site's small-caps label. Used for every field name and axis title. */
.label {
  font-family: var(--mono);
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.num {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.muted { color: var(--ink-3); }

/* ── skip link ──────────────────────────────────────────────────────────── */

.skip {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 100;
  background: var(--surface-2);
  color: var(--ink);
  padding: 0.6rem 1rem;
  border: 1px solid var(--hairline-strong);
  border-radius: var(--r-sm);
}
.skip:focus { left: 1rem; top: 1rem; }

/* ── shell ──────────────────────────────────────────────────────────────── */

.wrap {
  width: 100%;
  max-width: 1080px;
  margin-inline: auto;
  padding-inline: var(--gutter);
}
.wrap--wide { max-width: 1280px; }

.site {
  border-bottom: 1px solid var(--hairline);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.site__inner {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  min-height: 56px;
  flex-wrap: wrap;
}

.wordmark {
  font-family: var(--mono);
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
}
.wordmark .dim { color: var(--ink-3); font-weight: 400; }
.wordmark:hover .dim { color: var(--ink-2); }

.site nav {
  display: flex;
  gap: 0.25rem;
  margin-left: auto;
  flex-wrap: wrap;
}

.site nav a {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--ink-3);
  text-decoration: none;
  padding: 0.3rem 0.6rem;
  border-radius: var(--r-sm);
  white-space: nowrap;
}
.site nav a:hover { color: var(--ink); background: var(--surface-2); }
.site nav a[aria-current="page"] {
  color: var(--accent);
  background: var(--accent-wash);
}

main { display: block; padding-block: clamp(2rem, 6vw, 3.75rem) 4rem; }

.hero { margin-bottom: clamp(2rem, 5vw, 3rem); }
.hero .label { display: block; margin-bottom: 0.9rem; }
.hero p {
  font-size: clamp(1rem, 1.6vw, 1.1rem);
  color: var(--ink-2);
  margin-top: 1rem;
}

.stack > * + * { margin-top: 1.5rem; }
.stack-lg > * + * { margin-top: clamp(2rem, 5vw, 3rem); }

footer.site-foot {
  border-top: 1px solid var(--hairline);
  padding-block: 1.75rem 2.5rem;
  color: var(--ink-3);
  font-family: var(--mono);
  font-size: 0.78rem;
  line-height: 1.8;
}
footer.site-foot a { color: var(--ink-3); }
footer.site-foot a:hover { color: var(--ink-2); }

/* ── cards ──────────────────────────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--r);
  padding: 1.15rem 1.25rem;
}
.card--flush { padding: 0; overflow: hidden; }

.card__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.9rem;
}

.grid {
  display: grid;
  gap: 0.85rem;
  grid-template-columns: repeat(auto-fit, minmax(min(210px, 100%), 1fr));
}
.grid--2 { grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr)); }

/* ── stat tile ──────────────────────────────────────────────────────────── */

.stat { display: flex; flex-direction: column; gap: 0.3rem; }
.stat__value {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: clamp(1.4rem, 3vw, 1.85rem);
  font-weight: 500;
  line-height: 1.1;
  color: var(--ink);
  letter-spacing: -0.02em;
}
.stat__unit { font-size: 0.62em; color: var(--ink-3); margin-left: 0.15em; }
.stat__note { font-size: 0.8rem; color: var(--ink-3); line-height: 1.45; }

/* A single number carrying the page. */
.hero-figure {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: clamp(2.6rem, 9vw, 4.5rem);
  font-weight: 500;
  letter-spacing: -0.035em;
  line-height: 1;
  color: var(--ink);
}

/* ── meters ─────────────────────────────────────────────────────────────────
   Horizontal magnitude. The fill is anchored to the baseline (left) and only
   its leading end is rounded, so length stays honest at small values.
   Stacked segments are separated by a 2px surface gap, never a border. */

.meter {
  --meter-h: 8px;
  display: flex;
  height: var(--meter-h);
  border-radius: calc(var(--meter-h) / 2);
  background: var(--surface-2);
  overflow: hidden;
  gap: 2px;
}

.meter__fill {
  height: 100%;
  min-width: 0;
  background: var(--series-1);
  border-radius: 0 4px 4px 0;
  transition: width 240ms cubic-bezier(0.4, 0, 0.2, 1);
}
.meter__fill:first-child { border-start-start-radius: calc(var(--meter-h) / 2); border-end-start-radius: calc(var(--meter-h) / 2); }
.meter__fill:last-child { border-radius: 0 calc(var(--meter-h) / 2) calc(var(--meter-h) / 2) 0; }
.meter__fill--s2 { background: var(--series-2); }
.meter__fill--s3 { background: var(--series-3); }
.meter__fill--quiet { background: color-mix(in srgb, var(--series-1) 38%, var(--surface-2)); }

.meter-row {
  display: grid;
  grid-template-columns: minmax(64px, auto) 1fr minmax(78px, auto);
  align-items: center;
  gap: 0.9rem;
}
.meter-row + .meter-row { margin-top: 0.7rem; }
.meter-row__value {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 0.82rem;
  color: var(--ink-2);
  text-align: right;
}

/* ── legend & swatches ──────────────────────────────────────────────────── */

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 1.1rem;
  list-style: none;
  margin: 0;
  padding: 0;
  font-family: var(--mono);
  font-size: 0.76rem;
  color: var(--ink-2);
}
.legend li { display: flex; align-items: center; gap: 0.45rem; }

.swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex: none;
  background: var(--series-1);
  /* A 2px surface ring keeps abutting swatches from bleeding together. */
  box-shadow: 0 0 0 2px var(--surface);
}
.swatch--s2 { background: var(--series-2); }
.swatch--s3 { background: var(--series-3); }

/* ── charts ─────────────────────────────────────────────────────────────── */

.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid-line { stroke: #2c2c2a; stroke-width: 1; }
.chart .axis { stroke: #383835; stroke-width: 1; }
.chart .tick {
  font-family: var(--mono);
  font-size: 10px;
  fill: #898781;
  font-variant-numeric: tabular-nums;
}
.chart .series { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .series--1 { stroke: var(--series-1); }
.chart .series--2 { stroke: var(--series-2); }
.chart .series--3 { stroke: var(--series-3); }
.chart .area--1 { fill: color-mix(in srgb, var(--series-1) 16%, transparent); }
.chart .area--2 { fill: color-mix(in srgb, var(--series-2) 16%, transparent); }

.tooltip {
  position: absolute;
  z-index: 5;
  pointer-events: none;
  background: var(--surface-2);
  border: 1px solid var(--hairline-strong);
  border-radius: var(--r-sm);
  padding: 0.5rem 0.65rem;
  font-family: var(--mono);
  font-size: 0.74rem;
  line-height: 1.5;
  color: var(--ink);
  white-space: nowrap;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  opacity: 0;
  transition: opacity 120ms;
}
.tooltip[data-show="true"] { opacity: 1; }
.tooltip .tt-label { color: var(--ink-3); }

/* ── tables ─────────────────────────────────────────────────────────────── */

table.data {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--mono);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}
table.data th,
table.data td {
  text-align: left;
  padding: 0.45rem 0.7rem;
  border-bottom: 1px solid var(--hairline);
  white-space: nowrap;
}
table.data th {
  color: var(--ink-3);
  font-weight: 500;
  font-size: 0.7rem;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}
table.data td { color: var(--ink-2); }
table.data td.n { text-align: right; }
table.data tr:last-child td { border-bottom: 0; }
.table-scroll { overflow-x: auto; }

/* ── feed (log-style rows) ──────────────────────────────────────────────── */

.feed {
  font-family: var(--mono);
  font-size: 0.76rem;
  line-height: 1.5;
  margin: 0;
  padding: 0;
  list-style: none;
  max-height: 26rem;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.feed li {
  display: grid;
  grid-template-columns: 4.6rem 9.5rem 2.4rem 1fr;
  gap: 0.75rem;
  padding: 0.4rem 1.25rem;
  border-bottom: 1px solid var(--hairline);
  align-items: baseline;
}
.feed li > * { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.feed .f-time { color: var(--ink-3); }
.feed .f-net { color: var(--ink-2); }
.feed .f-path { color: var(--ink); }
.feed .f-agent { color: var(--ink-3); font-size: 0.95em; }
.feed li[data-fresh="true"] { animation: arrive 1.4s ease-out; }

@keyframes arrive {
  from { background: var(--accent-wash); }
  to { background: transparent; }
}

.status-4xx { color: var(--warning); }
.status-2xx { color: var(--good); }
.status-5xx { color: var(--critical); }

/* ── buttons & controls ─────────────────────────────────────────────────── */

.btn {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--ink-2);
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  border-radius: var(--r-sm);
  padding: 0.4rem 0.75rem;
  cursor: pointer;
  transition: background 120ms, color 120ms, border-color 120ms;
}
.btn:hover { color: var(--ink); border-color: var(--hairline-strong); }
.btn[aria-pressed="true"] {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
  background: var(--accent-wash);
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

/* ── connection state pill ──────────────────────────────────────────────── */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--ink-3);
  border: 1px solid var(--hairline);
  border-radius: 999px;
  padding: 0.2rem 0.6rem 0.2rem 0.5rem;
}
.pill::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ink-3);
  flex: none;
}
.pill[data-state="live"] { color: var(--ink-2); }
.pill[data-state="live"]::before { background: var(--good); animation: pulse 2.4s ease-in-out infinite; }
.pill[data-state="down"] { color: var(--critical); }
.pill[data-state="down"]::before { background: var(--critical); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* ── index cards ────────────────────────────────────────────────────────── */

.exhibits { display: grid; gap: 0.85rem; }

.exhibit {
  display: block;
  position: relative;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--r);
  padding: 1.25rem 1.35rem;
  text-decoration: none;
  color: inherit;
  transition: border-color 140ms, background 140ms, transform 140ms;
}
.exhibit:hover {
  border-color: var(--hairline-strong);
  background: var(--surface-2);
  transform: translateY(-1px);
}
.exhibit__name {
  font-family: var(--mono);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 0.4rem;
}
.exhibit__desc { color: var(--ink-2); font-size: 0.95rem; margin: 0 0 0.75rem; max-width: 56ch; }
.exhibit__live {
  font-family: var(--mono);
  font-size: 0.76rem;
  font-variant-numeric: tabular-nums;
  color: var(--ink-3);
  margin: 0;
}
.exhibit__live b { color: var(--ink); font-weight: 500; }

/* Wide enough to stop the prose measure leaving half the card empty: the live
   figures move into their own right-hand column instead of trailing the text. */
@media (min-width: 880px) {
  .exhibit {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(190px, 22ch);
    column-gap: clamp(1.5rem, 4vw, 3.5rem);
    align-items: start;
  }
  .exhibit__desc { margin-bottom: 0; }
  .exhibit__live {
    grid-column: 2;
    grid-row: 1 / span 2;
    text-align: right;
    line-height: 1.85;
    border-left: 1px solid var(--hairline);
    padding-left: clamp(1rem, 2vw, 1.75rem);
  }
}
.exhibit__live b { color: var(--ink); font-weight: 500; }

/* ── life canvas ────────────────────────────────────────────────────────── */

.stage {
  position: relative;
  border: 1px solid var(--hairline);
  border-radius: var(--r);
  overflow: hidden;
  background: #000;
  line-height: 0;
}
.stage canvas {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: pixelated;
  touch-action: none;
  cursor: crosshair;
}

.you {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--ink-2);
}
.you__chip {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  box-shadow: 0 0 0 2px var(--surface), 0 0 12px currentColor;
  flex: none;
}

/* ── misc ───────────────────────────────────────────────────────────────── */

.notice {
  border: 1px solid var(--hairline);
  border-left: 2px solid var(--accent);
  border-radius: var(--r-sm);
  background: var(--surface);
  padding: 0.85rem 1.1rem;
  font-size: 0.9rem;
  color: var(--ink-2);
}

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

hr.rule { border: 0; border-top: 1px solid var(--hairline); margin: 2rem 0; }

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

@media (max-width: 640px) {
  .feed li { grid-template-columns: 4.2rem 1fr; row-gap: 0.15rem; }
  .feed .f-status { display: none; }
  .feed .f-agent { grid-column: 2; }
  .meter-row { grid-template-columns: minmax(54px, auto) 1fr; row-gap: 0.3rem; }
  .meter-row__value { grid-column: 2; text-align: left; }
}
