:root {
  --bg: #0b1214;
  --surface: #121a19;
  --text: #e8fbf6;
  --muted: #9ab3ad;
  --accent: #2ee6c7;
  --warn: #e6b84d;
  --border: rgba(46,230,199,.22);
  --serif: "Instrument Serif", Georgia, serif;
  --sans: "Inter", ui-sans-serif, system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  padding: 0 1.25rem 3rem;
  max-width: 1120px;
  margin-inline: auto;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  position: sticky;
  top: 0;
  z-index: 50;
  margin: 0 -1.25rem 1rem;
  padding: 10px 16px;
  background: rgba(11,18,20,.88);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: inherit; }
.smark {
  width: 32px; height: 32px; border-radius: 10px;
  display: grid; place-items: center;
  font: 700 15px var(--sans); color: #04110a;
  background: linear-gradient(135deg,#7ee8d4,#8a7cff);
}
.sword {
  font-weight: 600; font-size: 13px; letter-spacing: .2em;
  background: linear-gradient(135deg,#d8fff4 0%,#6fe0c4 44%,#9b7dff 100%);
  -webkit-background-clip: text; background-clip: text;
  color: transparent; -webkit-text-fill-color: transparent;
}
.header-right { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.theme-wrap { position: relative; }
.theme-btn {
  display: flex; align-items: center; gap: 6px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 999px;
  padding: 6px 10px; font: 600 11px var(--sans); cursor: pointer;
}
.theme-dot { width: 10px; height: 10px; border-radius: 50%; background: #2ee6c7; }
.theme-panel {
  display: none; position: absolute; right: 0; top: calc(100% + 8px);
  min-width: 200px; background: #16181d; border: 1px solid rgba(255,255,255,.08);
  border-radius: 16px; padding: 10px; z-index: 80;
}
.theme-wrap.open .theme-panel { display: block; }
.theme-panel p { font-size: 10px; letter-spacing: .14em; text-transform: uppercase; color: #8b93a0; margin: 0 8px 8px; }
.theme-item {
  display: flex; align-items: center; gap: 10px; width: 100%; border: 0;
  background: transparent; color: #e8eef2; padding: 10px; border-radius: 12px;
  font: 600 14px var(--sans); cursor: pointer; text-align: left;
}
.theme-item.on { background: #14302c; color: #2ee6c7; }
.theme-item i { width: 14px; height: 14px; border-radius: 50%; display: block; }
.theme-item .ck { margin-left: auto; opacity: 0; }
.theme-item.on .ck { opacity: 1; }

header h1 {
  margin: 1rem 0 0.25rem;
  font-family: var(--serif);
  font-size: clamp(2rem, 5vw, 2.6rem);
  font-weight: 400;
  letter-spacing: -.02em;
}

.tagline { color: var(--muted); margin: 0 0 0.5rem; }
.ai-note { font-size: 0.85rem; color: var(--muted); font-style: italic; margin: 0 0 1rem; }

.controls { display: flex; align-items: center; gap: 1rem; margin-bottom: 0.5rem; }

button {
  background: var(--accent);
  color: #04110a;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 999px;
  font-weight: 600;
  font-family: var(--sans);
  cursor: pointer;
}

button:disabled { opacity: 0.5; cursor: wait; }

.status, .meta { color: var(--muted); font-size: 0.9rem; }

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  margin: 1rem 0;
}

table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
}

th, td {
  padding: 0.55rem 0.7rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  line-height: 1.25;
}

th .sub { display: block; text-transform: none; letter-spacing: 0; font-weight: 500; }

.num { font-variant-numeric: tabular-nums; }
.sub { color: var(--muted); font-size: 0.75rem; }

.pill {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
}

.pill.open { background: #0d3d2a; color: var(--accent); }
.pill.closed { background: #1a2423; color: var(--muted); }

.flag.ok { color: var(--accent); }
.flag.warn { color: var(--warn); font-weight: 600; }
.flag.muted { color: var(--muted); }

td.warn { color: var(--warn); font-weight: 600; }

footer {
  margin-top: 2rem;
  font-size: 0.85rem;
  color: var(--muted);
}

footer a, .tagline a, .sub a, td a { color: var(--accent); }

.thresholds { margin-top: 0.75rem; }

.tabs { display: flex; gap: 0.5rem; margin: 0 0 1rem; border-bottom: 1px solid var(--border); }
.tab { background: transparent; color: var(--muted); border-radius: 6px 6px 0 0; border: 1px solid transparent; border-bottom: none; }
.tab.active { background: var(--surface); color: var(--text); border-color: var(--border); }
.err { color: var(--warn); }
.rich { color: var(--warn); font-weight: 600; }
.cheap { color: #6cb6ff; font-weight: 600; }
.match { color: var(--accent); font-weight: 600; }
.diff { color: var(--warn); font-weight: 600; }
.unknown { color: var(--warn); font-weight: 600; }
code { font-size: 0.85em; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.75rem; white-space: nowrap; }
.subhead { margin: 1.5rem 0 0.25rem; font-size: 1.15rem; font-family: var(--serif); font-weight: 400; }

/* ---- depth, sparklines, chart dialog ---- */
.depth div { white-space: nowrap; line-height: 1.35; }
.depth b { color: var(--muted); font-weight: 600; font-size: 0.78rem; }
button.spark { background: transparent; border: 1px solid var(--border); padding: 4px 6px; border-radius: 6px; display: inline-flex; flex-direction: column; align-items: flex-start; gap: 2px; color: var(--text); cursor: pointer; min-height: 44px; }
button.spark:hover { border-color: var(--accent); }
svg .zero { stroke: var(--border); stroke-dasharray: 3 3; }
svg path { fill: none; stroke-width: 1.5; }
svg .l-p { stroke: var(--accent); } svg .d-p { fill: var(--accent); }
svg .l-b { stroke: var(--warn); } svg .d-b { fill: var(--warn); }
svg .l-s { stroke: #6cb6ff; } svg .d-s { fill: #6cb6ff; }
svg .axis { fill: var(--muted); font-size: 10px; }
.legend .k-p { color: var(--accent); } .legend .k-b { color: var(--warn); } .legend .k-s { color: #6cb6ff; }
dialog#chart-dialog { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 10px; padding: 0; max-width: calc(100vw - 16px); }
dialog#chart-dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
.dlg { padding: 1rem 1.25rem; position: relative; }
.dlg h3 { margin: 0 2rem 0.25rem 0; }
.dlg .close { position: absolute; top: 0.5rem; right: 0.5rem; background: transparent; color: var(--text); font-size: 1.5rem; padding: 0.25rem 0.75rem; min-height: 44px; }

/* ---- desktop: keep the token column visible while scrolling horizontally ---- */
.table-wrap th:first-child, .table-wrap td:first-child { position: sticky; left: 0; background: var(--surface); z-index: 1; }
.table-wrap td:first-child { min-width: 9rem; max-width: 13rem; }
.mono { display: inline-block; max-width: 100%; }

/* ---- phones: card layout, one card per token ---- */
@media (max-width: 760px) {
  body { padding: 0 0.75rem 2rem; font-size: 16px; }
  .topbar { margin: 0 -0.75rem 0.75rem; }
  header h1 { font-size: 1.5rem; }
  .tabs { position: sticky; top: 56px; z-index: 40; background: var(--bg); padding-top: 0.25rem; }
  .tab { flex: 1; min-height: 44px; font-size: 1rem; }
  .controls button { min-height: 44px; }
  .table-wrap { overflow-x: visible; border: none; background: transparent; }
  .table-wrap table, .table-wrap tbody, .table-wrap tr, .table-wrap td { display: block; width: 100%; }
  .table-wrap thead { display: none; }
  .table-wrap tr { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; margin: 0 0 0.9rem; padding: 0.35rem 0.75rem; }
  .table-wrap table { width: 100%; min-width: 0; }
  .table-wrap td { display: grid; grid-template-columns: 38% 62%; gap: 0.5rem; padding: 0.5rem 0; border-bottom: 1px solid var(--border); font-size: 0.95rem; overflow-wrap: anywhere; white-space: normal; }
  .table-wrap td:last-child { border-bottom: none; }
  .table-wrap td::before { content: attr(data-label); color: var(--muted); font-size: 0.78rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.02em; }
  .table-wrap td:first-child { position: static; display: block; max-width: none; font-size: 1.05rem; padding-top: 0.6rem; }
  .table-wrap td:first-child::before { content: none; }
  .table-wrap td[colspan] { display: block; }
  .table-wrap td[colspan]::before { content: none; }
  .depth div { white-space: normal; }
  .sub { font-size: 0.8rem; }
  .mono { font-size: 0.72rem; white-space: normal; word-break: break-all; }
}
@media (min-width: 1100px) { body { max-width: 1500px; } }
.ca-strip { list-style: none; padding: 0; margin: 0.5rem 0 1rem; display: grid; gap: 0.5rem; }
.ca-strip li { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 0.6rem 0.8rem; font-size: 0.9rem; }
