:root {
  --bg: #f6f4ef;
  --paper: #ffffff;
  --ink: #1d1d1f;
  --muted: #6b6b73;
  --line: #e3dfd6;
  --accent: #c8102e;
  --accent-ink: #ffffff;
  --ok: #1f7a4d;
  --ok-bg: #e5f4ec;
  --warn: #8a5a00;
  --warn-bg: #fff3d6;
  --bad: #b3261e;
  --bad-bg: #fde8e6;
  --info-bg: #eef3fb;
  --code-bg: #faf8f3;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.05);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121214;
    --paper: #1b1b1f;
    --ink: #ececf0;
    --muted: #9a9aa6;
    --line: #2c2c33;
    --accent: #ff4d5e;
    --accent-ink: #1b1b1f;
    --ok: #5ed39a;
    --ok-bg: #16271f;
    --warn: #f3c56b;
    --warn-bg: #2a2314;
    --bad: #ff8a80;
    --bad-bg: #2d1717;
    --info-bg: #1a2130;
    --code-bg: #151518;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: 260px; /* room for Gord */
}
a { color: var(--accent); }
h1, h2 { margin: 0; line-height: 1.2; }
small { color: var(--muted); font-weight: normal; }
.mono, code, pre { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; flex-wrap: wrap; gap: 16px; align-items: center; justify-content: space-between;
  padding: 16px 24px; background: var(--paper); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; gap: 12px; align-items: center; }
.brand h1 { font-size: 20px; }
.brand .sub { margin: 0; color: var(--muted); font-size: 13px; }
.leaf { width: 34px; height: 34px; fill: var(--accent); }
.keybox { display: grid; gap: 2px; min-width: min(420px, 100%); flex: 1 1 320px; max-width: 480px; }
.keybox label { font-size: 12px; color: var(--muted); font-weight: 600; letter-spacing: .02em; }
/* Until a demo key is accepted, only the header bar shows. */
body.locked .notice, body.locked .layout, body.locked .foot, body.locked .guides { display: none; }
.keyrow { display: flex; gap: 6px; }
.keyrow input { flex: 1; }
.keystatus { font-size: 12px; color: var(--muted); }
.keystatus.ok { color: var(--ok); }
.keystatus.bad { color: var(--bad); }
.toplinks { display: flex; gap: 12px; align-items: center; font-size: 14px; }
.pill { font-size: 12px; padding: 3px 10px; border-radius: 999px; background: var(--line); color: var(--muted); white-space: nowrap; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }

.notice {
  margin: 16px 24px 0; padding: 10px 14px; border-radius: 10px;
  background: var(--warn-bg); color: var(--ink); font-size: 14px; border: 1px solid var(--line);
}

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 210px 1fr; gap: 24px; padding: 20px 24px; max-width: 1280px; margin: 0 auto; }
.sidenav { position: sticky; top: 110px; align-self: start; display: grid; gap: 2px; }
.sidenav a { color: var(--ink); text-decoration: none; padding: 8px 10px; border-radius: 8px; font-size: 14px; }
.sidenav a:hover { background: var(--paper); }
.cards { display: grid; gap: 20px; min-width: 0; }
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; padding: 16px; }
  .sidenav { position: static; display: flex; flex-wrap: wrap; gap: 4px; }
  .sidenav a { background: var(--paper); border: 1px solid var(--line); padding: 4px 10px; font-size: 13px; }
  .topbar { padding: 12px 16px; position: static; }
  .notice { margin: 12px 16px 0; }
}

.card {
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow); scroll-margin-top: 110px; min-width: 0;
}
.card-h { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.card-h h2 { font-size: 19px; }
.lead { color: var(--muted); margin: 6px 0 14px; }

/* ---------- forms ---------- */
form.op { display: grid; gap: 12px; }
fieldset { border: 1px dashed var(--line); border-radius: 10px; padding: 10px 12px 12px; margin: 0; display: grid; gap: 10px; min-width: 0; }
legend { font-weight: 600; font-size: 13px; padding: 0 4px; }
label { display: grid; gap: 4px; font-size: 12px; font-weight: 600; color: var(--muted); min-width: 0; }
label.check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--ink); font-weight: 500; width: fit-content; }
label.check input { width: 18px; height: 18px; flex: none; padding: 0; margin: 0; accent-color: var(--accent, #c8102e); }
label.preset { max-width: 320px; }
input, select {
  font: inherit; font-size: 14px; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; width: 100%; min-width: 0;
}
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.inline { display: flex; gap: 6px; }
.grid { display: grid; gap: 10px; }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g-address { grid-template-columns: 2fr 1.2fr .8fr .9fr .7fr; }
.g-address .span2 { grid-column: span 1; }
@media (max-width: 1000px) {
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g-address { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g-address .span2 { grid-column: span 2; }
}
@media (max-width: 560px) {
  .g3, .g4, .g-address { grid-template-columns: 1fr; }
  .g-address .span2 { grid-column: span 1; }
}

.lines { display: grid; gap: 6px; }
.line-row { display: grid; grid-template-columns: 120px 1fr 1.6fr 120px 34px; gap: 6px; }
@media (max-width: 700px) { .line-row { grid-template-columns: 1fr 1fr; } .line-row .remove-line { width: auto; } }

button {
  font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; border-radius: 9px; padding: 8px 14px;
  border: 1px solid transparent; transition: transform .05s ease, background .15s ease;
}
button:active { transform: translateY(1px); }
button:disabled { opacity: .45; cursor: not-allowed; }
.send { background: var(--accent); color: var(--accent-ink); justify-self: start; padding: 9px 18px; }
.send.loading { opacity: .7; }
.secondary { background: var(--bg); color: var(--ink); border-color: var(--line); }
.secondary.danger { color: var(--bad); }
.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.tiny { padding: 4px 8px; font-size: 12px; }
.ask {
  background: var(--bg); border: 1px solid var(--line); color: var(--ink); font-size: 13px; padding: 6px 12px;
}
.ask::before { content: "🍁 "; }
.btnrow { display: flex; flex-wrap: wrap; gap: 8px; }

.tabs { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 12px; border-bottom: 1px solid var(--line); }
.tab { background: none; border: none; border-bottom: 2px solid transparent; border-radius: 0; color: var(--muted); padding: 8px 12px; }
.tab.active { color: var(--ink); border-bottom-color: var(--accent); }

.endpoint { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.endpoint.small { font-family: inherit; }
.verb { display: inline-block; font-weight: 700; font-size: 11px; padding: 2px 7px; border-radius: 5px; margin-right: 8px; color: #fff; }
.verb.get { background: #2257b8; } .verb.post { background: #17703f; } .verb.put { background: #8a4f00; }
.followups { margin-top: 16px; padding-top: 14px; border-top: 1px dashed var(--line); display: grid; gap: 8px; }

/* ---------- results ---------- */
.result:empty { display: none; }
.result { margin-top: 16px; display: grid; gap: 12px; min-width: 0; }
.res-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 13px; }
.status { font-weight: 700; padding: 2px 9px; border-radius: 6px; }
.status.ok { background: var(--ok-bg); color: var(--ok); }
.status.warn { background: var(--warn-bg); color: var(--warn); }
.status.bad { background: var(--bad-bg); color: var(--bad); }
.res-head .spacer { flex: 1; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.stat { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.stat .k { font-size: 12px; color: var(--muted); font-weight: 600; }
.stat .v { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat.hero .v { font-size: 26px; color: var(--accent); }

.big-rate { text-align: center; padding: 18px; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; }
.big-rate .eq { font-size: 30px; font-weight: 800; font-variant-numeric: tabular-nums; }
.big-rate .meta { color: var(--muted); font-size: 13px; margin-top: 4px; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: var(--bg); font-size: 12px; color: var(--muted); position: sticky; top: 0; }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--info-bg); white-space: nowrap; }
.chip b { font-weight: 700; }
.tag { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 5px; background: var(--line); }
.tag.ok { background: var(--ok-bg); color: var(--ok); }
.tag.warn { background: var(--warn-bg); color: var(--warn); }
.tag.bad { background: var(--bad-bg); color: var(--bad); }

.problem { background: var(--bad-bg); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.problem h3 { margin: 0 0 4px; font-size: 15px; color: var(--bad); }
.problem ul { margin: 6px 0 0; padding-left: 18px; }

details.raw { border: 1px solid var(--line); border-radius: 10px; background: var(--code-bg); }
details.raw summary { cursor: pointer; padding: 8px 12px; font-size: 13px; font-weight: 600; color: var(--muted); }
pre.json { margin: 0; padding: 12px; overflow: auto; max-height: 420px; font-size: 12.5px; line-height: 1.45; }
.j-key { color: #8250df; } .j-str { color: #0a7f45; } .j-num { color: #b35900; } .j-bool { color: #2f6fd6; } .j-null { color: var(--muted); }
@media (prefers-color-scheme: dark) {
  .j-key { color: #c9a6ff; } .j-str { color: #7ee2a8; } .j-num { color: #ffb86b; } .j-bool { color: #8fb8ff; }
}

.foot { text-align: center; color: var(--muted); font-size: 13px; padding: 12px 0 24px; }

/* ---------- The explainers ---------- */
.guides { position: fixed; right: 14px; bottom: 10px; z-index: 50; display: flex; align-items: flex-end; gap: 0; max-width: calc(100vw - 20px); }
.guides .bubble {
  position: absolute; right: 12px; bottom: 175px; background: #fffdf5; color: #1b1b1b; border: 3px solid #1b1b1b;
  border-radius: 18px; padding: 10px 14px 8px; width: min(360px, calc(100vw - 40px));
  box-shadow: 4px 4px 0 #1b1b1b; font-size: 14px; font-family: "Comic Sans MS", "Chalkboard SE", system-ui, sans-serif;
}
.guides .bubble::after {
  content: ""; position: absolute; bottom: -20px; border: 10px solid transparent; border-top: 14px solid #1b1b1b;
  right: var(--tail, 180px); transition: right .2s ease;
}
.guides .who { font-weight: 800; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: #c8102e; }
.guides .bubble p { margin: 2px 0 6px; min-height: 1.4em; white-space: pre-line; }
.guides .bubble-actions { display: flex; justify-content: flex-end; }
.guides .bubble .ghost { color: #1b1b1b; border-color: #cfc8b8; background: #fff; }
.guides.quiet .bubble { display: none; }
.guide-btn { background: none; border: none; padding: 0; cursor: pointer; width: 120px; }
@media (max-width: 560px) {
  .guide-btn { width: 82px; }
  .guides .bubble { bottom: 120px; font-size: 13px; }
  body { padding-bottom: 240px; }
}
