/* ---------------------------------------------------------------------------
   Tokens. Light values live on bare :root; dark values are redefined twice —
   once for the OS setting, once for an explicit toggle — so neither can strand
   a color that was only ever defined inside a media query.
   Palette: validated categorical slots 1–4 + chart chrome.
--------------------------------------------------------------------------- */
:root {
  color-scheme: light;

  --plane:          #f9f9f7;
  --surface:        #fcfcfb;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;
  --gridline:       #e1e0d9;
  --baseline:       #c3c2b7;
  --border:         rgba(11, 11, 11, 0.10);

  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;

  --accent:      #2a78d6;
  --accent-ink:  #ffffff;
  --good:        #0ca30c;
  --critical:    #d03b3b;
  --warning-bg:  #fdf6e3;
  --warning-bd:  #eda100;

  --seq-400: #3987e5;
  --seq-250: #86b6ef;

  --radius: 10px;
  --maxw: 62rem;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --plane:          #0d0d0d;
    --surface:        #1a1a19;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #898781;
    --gridline:       #2c2c2a;
    --baseline:       #383835;
    --border:         rgba(255, 255, 255, 0.10);

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

    --accent:     #3987e5;
    --accent-ink: #ffffff;
    --warning-bg: #2a2416;
    --warning-bd: #c98500;

    --seq-400: #3987e5;
    --seq-250: #184f95;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --plane:          #0d0d0d;
  --surface:        #1a1a19;
  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #898781;
  --gridline:       #2c2c2a;
  --baseline:       #383835;
  --border:         rgba(255, 255, 255, 0.10);

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

  --accent:     #3987e5;
  --accent-ink: #ffffff;
  --warning-bg: #2a2416;
  --warning-bd: #c98500;

  --seq-400: #3987e5;
  --seq-250: #184f95;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--plane);
  color: var(--text-primary);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
}

.wrap { max-width: var(--maxw); margin: 0 auto; padding: 1.5rem 1.15rem 4rem; }

/* --- header --------------------------------------------------------------- */

header.site {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
header.site .wrap { padding-block: 1.1rem; display: flex; flex-wrap: wrap; gap: .75rem 1.25rem; align-items: baseline; }
header.site h1 { font-size: 1.05rem; margin: 0; letter-spacing: -0.01em; }
header.site p { margin: 0; color: var(--text-secondary); font-size: .85rem; }

nav.site { margin-left: auto; display: flex; gap: 1rem; }
nav.site a { color: var(--text-secondary); text-decoration: none; font-size: .88rem; border-bottom: 1px solid transparent; padding-bottom: 1px; }
nav.site a:hover, nav.site a[aria-current="page"] { color: var(--text-primary); border-bottom-color: var(--accent); }

/* --- generic blocks ------------------------------------------------------- */

h2 { font-size: 1.25rem; margin: 2.25rem 0 .4rem; letter-spacing: -0.01em; }
h3 { font-size: .95rem; margin: 0 0 .1rem; }
.lede { color: var(--text-secondary); margin: .25rem 0 1.5rem; max-width: 46rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem 1.25rem;
  margin-bottom: 1rem;
}

.notice {
  background: var(--warning-bg);
  border: 1px solid var(--border);
  border-left: 3px solid var(--warning-bd);
  border-radius: var(--radius);
  padding: .85rem 1rem;
  font-size: .88rem;
  color: var(--text-secondary);
  margin-bottom: 1.25rem;
}
.notice strong { color: var(--text-primary); }
.notice ul { margin: .5rem 0 0; padding-left: 1.1rem; }
.notice li { margin: .2rem 0; }

.muted { color: var(--text-muted); font-size: .82rem; }
.subnote { color: var(--text-secondary); font-size: .84rem; margin: 0 0 .55rem; max-width: 44rem; }

/* Key explaining the hatched "withheld" mark, shown once above the charts. */
.hatch-key {
  display: flex; align-items: center; gap: .55rem;
  font-size: .84rem; color: var(--text-secondary);
  margin-bottom: 1.25rem;
}
.hatch-key .sample {
  width: 2.5rem; height: 1rem; flex: none; border-radius: 4px;
  background: repeating-linear-gradient(135deg, var(--baseline) 0 4px, transparent 4px 8px);
  border: 1px dashed var(--baseline);
}

/* --- form ----------------------------------------------------------------- */

fieldset { border: 0; margin: 0 0 1.6rem; padding: 0; }
legend { font-weight: 600; font-size: .95rem; padding: 0; margin-bottom: .55rem; }

.opts { display: grid; gap: .4rem; }

.opt {
  display: flex; align-items: flex-start; gap: .6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .6rem .75rem;
  cursor: pointer;
  background: var(--surface);
  transition: border-color .12s, background .12s;
}
.opt:hover { border-color: var(--accent); }
.opt input { margin: .18rem 0 0; accent-color: var(--accent); flex: none; }
.opt:has(input:checked) { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.opt:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }

label.field { display: block; font-weight: 600; font-size: .95rem; margin-bottom: .35rem; }

input[type="number"], input[type="text"], textarea {
  width: 100%;
  font: inherit;
  color: var(--text-primary);
  background: var(--surface);
  border: 1px solid var(--baseline);
  border-radius: 8px;
  padding: .55rem .7rem;
}
input:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
textarea { resize: vertical; min-height: 4.5rem; }

/* Honeypot — hidden from people, visible to bots that ignore CSS. */
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

button {
  font: inherit; font-weight: 600;
  border-radius: 8px;
  padding: .6rem 1.15rem;
  border: 1px solid transparent;
  cursor: pointer;
  background: var(--accent);
  color: var(--accent-ink);
}
button:hover { filter: brightness(1.07); }
button:focus-visible { outline: 2px solid var(--text-primary); outline-offset: 2px; }
button[disabled] { opacity: .55; cursor: progress; }
button.secondary { background: transparent; color: var(--text-secondary); border-color: var(--baseline); }
button.danger { background: transparent; color: var(--critical); border-color: var(--critical); }

.actions { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }

.msg { margin-top: 1rem; font-size: .9rem; }
.msg.err { color: var(--critical); }
.msg.ok  { color: var(--good); }

/* --- token reveal --------------------------------------------------------- */

.token-box {
  display: flex; gap: .5rem; align-items: stretch; margin: .75rem 0;
}
.token-box input {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .82rem;
}

/* --- stat tiles ----------------------------------------------------------- */

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); gap: .75rem; margin-bottom: 1.5rem; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .95rem 1.05rem; }
.tile .k { font-size: .78rem; color: var(--text-secondary); margin-bottom: .3rem; }
.tile .v { font-size: 1.85rem; font-weight: 650; letter-spacing: -0.02em; line-height: 1.1; }
.tile .v.na { font-size: 1rem; font-weight: 500; color: var(--text-muted); }
.tile .sub { font-size: .74rem; color: var(--text-muted); margin-top: .3rem; line-height: 1.35; }

/* --- save-your-link block ------------------------------------------------- */

.card.save-link { border-left: 3px solid var(--accent); }
.card.save-link .token-box input { font-size: .8rem; }
.card.save-link .confirm { margin-top: .9rem; }
.card.save-link .confirm .opt { background: transparent; }
#after { margin-top: .85rem; padding-top: .85rem; border-top: 1px solid var(--border); }

/* --- bar charts ----------------------------------------------------------- */

.chart { margin-bottom: .35rem; }

.bar-row { display: grid; grid-template-columns: minmax(7.5rem, 13rem) 1fr; gap: .75rem; align-items: center; padding: .28rem 0; }
.bar-row .lbl { font-size: .85rem; color: var(--text-secondary); text-align: right; }
.bar-track { position: relative; display: flex; align-items: center; gap: .5rem; min-height: 1.15rem; }

.bar {
  height: 1.05rem;
  border-radius: 0 4px 4px 0;   /* rounded data-end, square against the baseline */
  background: var(--seq-400);
  min-width: 2px;
  flex: none;
  transition: filter .12s;
}
.bar-row:hover .bar { filter: brightness(1.12); }
.bar-val { font-size: .82rem; color: var(--text-secondary); font-variant-numeric: tabular-nums; white-space: nowrap; }
.bar-val .pct { color: var(--text-muted); }

.bar.withheld {
  background: repeating-linear-gradient(135deg, var(--baseline) 0 4px, transparent 4px 8px);
  border: 1px dashed var(--baseline);
  width: 3rem;
}

/* stacked cross-tab bars: 2px surface gap between adjacent fills */
.stack { display: flex; width: 100%; height: 1.35rem; gap: 2px; }
.seg { min-width: 2px; position: relative; }
.seg:first-child { border-radius: 4px 0 0 4px; }
.seg:last-child  { border-radius: 0 4px 4px 0; }
.seg-1 { background: var(--series-1); }
.seg-2 { background: var(--series-2); }
.seg-3 { background: var(--series-3); }
.seg-4 { background: var(--series-4); }
/* "Pending" is the absence of an outcome — neutral, never a categorical hue. */
.seg-pending { background: var(--baseline); }
.seg-w { background: repeating-linear-gradient(135deg, var(--baseline) 0 4px, transparent 4px 8px); border: 1px dashed var(--baseline); }

.sw-1 { background: var(--series-1); }
.sw-2 { background: var(--series-2); }
.sw-3 { background: var(--series-3); }
.sw-4 { background: var(--series-4); }
.sw-pending { background: var(--baseline); }

.seg-label {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  font-size: .72rem; font-weight: 600;
  color: #fff;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

.legend { display: flex; flex-wrap: wrap; gap: .35rem 1rem; margin: .1rem 0 .8rem; }
.legend .item { display: flex; align-items: center; gap: .38rem; font-size: .82rem; color: var(--text-secondary); }
.legend .swatch { width: .7rem; height: .7rem; border-radius: 3px; flex: none; }

/* --- table view ----------------------------------------------------------- */

.viewtoggle { display: flex; gap: .4rem; margin-bottom: 1rem; }
.viewtoggle button { font-size: .82rem; padding: .35rem .8rem; font-weight: 500; }
.viewtoggle button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.viewtoggle button[aria-pressed="false"] { background: transparent; color: var(--text-secondary); border-color: var(--baseline); }

.tablewrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .86rem; }
th, td { text-align: left; padding: .42rem .6rem; border-bottom: 1px solid var(--gridline); }
th { color: var(--text-secondary); font-weight: 600; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* --- tooltip -------------------------------------------------------------- */

#tip {
  position: fixed; z-index: 50; pointer-events: none;
  background: var(--surface); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: 8px;
  padding: .45rem .6rem; font-size: .8rem; line-height: 1.4;
  box-shadow: 0 4px 14px rgba(0,0,0,.14);
  max-width: 16rem;
}
#tip[hidden] { display: none !important; }
#tip .t-k { color: var(--text-secondary); }
#tip .t-v { font-weight: 650; font-variant-numeric: tabular-nums; }

footer.site { border-top: 1px solid var(--border); margin-top: 2.5rem; padding-top: 1.1rem; color: var(--text-muted); font-size: .8rem; }
footer.site a { color: var(--text-secondary); }

@media (max-width: 34rem) {
  .bar-row { grid-template-columns: 1fr; gap: .15rem; }
  .bar-row .lbl { text-align: left; }
}
