:root {
  --bg: #ffffff;
  --text: rgb(55, 53, 47);
  --text-2: rgba(55, 53, 47, 0.68);
  --text-3: rgba(55, 53, 47, 0.48);
  --line: rgba(55, 53, 47, 0.12);
  --line-strong: rgba(55, 53, 47, 0.2);
  --hover: rgba(55, 53, 47, 0.06);
  --active: rgba(55, 53, 47, 0.09);
  --surface: #ffffff;
  --callout: #f1f1ef;
  --code-bg: #f7f6f3;
  --accent: #2383e2;
  --accent-hover: #0f74d8;
  --accent-soft: rgba(35, 131, 226, 0.1);
  --good: #448361;
  --good-bg: #edf3ec;
  --bad: #d44c47;
  --bad-bg: #fdebec;
  --series: #2a78d6;
  --series-strong: #104281;
  --inline-code: #eb5757;
  --tok-comment: #708090;
  --tok-keyword: #0077aa;
  --tok-string: #669900;
  --tok-number: #990055;
  --tok-function: #dd4a68;
  --tok-constant: #b45309;
  --mono: "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #191919;
    --text: rgba(255, 255, 255, 0.86);
    --text-2: rgba(255, 255, 255, 0.58);
    --text-3: rgba(255, 255, 255, 0.4);
    --line: rgba(255, 255, 255, 0.11);
    --line-strong: rgba(255, 255, 255, 0.2);
    --hover: rgba(255, 255, 255, 0.055);
    --active: rgba(255, 255, 255, 0.09);
    --surface: #252525;
    --callout: #252525;
    --code-bg: #202020;
    --accent-soft: rgba(35, 131, 226, 0.2);
    --good: #4dab9a;
    --good-bg: #242b26;
    --bad: #e16259;
    --bad-bg: #362421;
    --series: #3987e5;
    --series-strong: #9ec5f4;
    --inline-code: #ff7b72;
    --tok-comment: #8b949e;
    --tok-keyword: #6cb6ff;
    --tok-string: #8ddb8c;
    --tok-number: #f69d50;
    --tok-function: #f47067;
    --tok-constant: #dcbdfb;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 var(--sans);
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; }
code { font-family: var(--mono); font-size: 85%; }
:not(pre) > code {
  background: var(--hover);
  color: var(--inline-code);
  border-radius: 4px;
  padding: 0.15em 0.35em;
}

.icon { width: 16px; height: 16px; flex: none; display: inline-block; vertical-align: middle; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(15, 15, 15, 0.05);
  transition: background 0.12s, border-color 0.12s;
}
.btn:hover { background: var(--hover); }
.btn:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn .icon { width: 15px; height: 15px; }
.btn-small { height: 28px; padding: 0 10px; font-size: 13px; }
.btn-small .icon { width: 14px; height: 14px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-icon { width: 32px; padding: 0; }
.btn[hidden] { display: none; }

/* Layout */
.app { display: flex; min-height: 100%; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* Top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 12px;
  height: 52px;
  padding: 0 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.brand { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; font-size: 15px; font-weight: 600; }
.brand-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand-name-short { display: none; white-space: nowrap; }
.brand-mark {
  width: 28px;
  height: 28px;
  flex: none;
  border-radius: 7px;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #fff;
}
.status { display: inline-flex; align-items: center; gap: 6px; color: var(--text-3); font-size: 13px; white-space: nowrap; }
.status .icon { width: 14px; height: 14px; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.switch { display: inline-flex; align-items: center; gap: 8px; color: var(--text-2); cursor: pointer; white-space: nowrap; user-select: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track { position: relative; width: 30px; height: 18px; border-radius: 9px; background: var(--line-strong); transition: background 0.15s; }
.switch .track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
  transition: transform 0.15s;
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(12px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Page */
.page { width: 100%; max-width: 900px; margin: 0 auto; padding: 40px 96px 120px; }
h1 { font-size: 40px; line-height: 1.2; font-weight: 700; margin: 20px 0 6px; letter-spacing: -0.01em; }
h2 { font-size: 24px; line-height: 1.3; font-weight: 600; margin: 40px 0 6px; }
.page > .callout:first-child { margin-top: 0; }
h3 { font-size: 18px; line-height: 1.4; font-weight: 600; margin: 28px 0 4px; }
p { margin: 4px 0 10px; }
.muted { color: var(--text-2); font-size: 15px; }
.divider { border: 0; border-top: 1px solid var(--line); margin: 28px 0 12px; }

.callout {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 16px 18px 14px 14px;
  border-radius: 8px;
  background: var(--callout);
  margin: 12px 0;
}
.callout .callout-icon { width: 20px; height: 20px; margin-top: 2px; color: #cb912f; }
.callout p:last-child { margin-bottom: 0; }
.callout.error { background: var(--bad-bg); }
.callout.error .callout-icon { color: var(--bad); }
.callout.error .title { font-weight: 600; color: var(--bad); margin-bottom: 2px; }
.callout .location { font-size: 14px; color: var(--text-2); }
.callout .actions { margin-top: 10px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* Example picker */
.template-row { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; margin: 14px 0 4px; }
.field-label { font-size: 14px; font-weight: 500; color: var(--text-2); }
.select-wrap { position: relative; display: inline-flex; align-items: center; }
.select-wrap select {
  appearance: none;
  height: 32px;
  min-width: 220px;
  padding: 0 34px 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font: 500 14px var(--sans);
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(15, 15, 15, 0.05);
}
.select-wrap select:hover { background-color: var(--hover); }
.select-wrap select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.select-chevron { position: absolute; right: 10px; pointer-events: none; color: var(--text-2); }
.template-description { flex-basis: 100%; margin: 0; font-size: 14px; color: var(--text-3); }
.notice { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); }
.notice[hidden] { display: none; }

/* Code block */
.code-block { background: var(--code-bg); border: 1px solid var(--line); border-radius: 8px; margin: 10px 0; }
.code-head { display: flex; align-items: center; gap: 8px; padding: 8px 8px 0 16px; font-size: 12px; color: var(--text-3); }
.code-head .lang { flex: 1; }
.editor { position: relative; }
.editor pre,
.editor textarea {
  margin: 0;
  padding: 8px 16px 18px;
  font: 13.5px/1.6 var(--mono);
  tab-size: 2;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  letter-spacing: 0;
  border: 0;
}
.editor pre { color: var(--text); pointer-events: none; min-height: 120px; }
.editor textarea {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  resize: none;
  overflow: hidden;
  background: transparent;
  color: transparent;
  caret-color: var(--text);
  outline: none;
}
.editor textarea::selection { background: rgba(35, 131, 226, 0.28); }
.tok-comment { color: var(--tok-comment); font-style: italic; }
.tok-keyword { color: var(--tok-keyword); }
.tok-string { color: var(--tok-string); }
.tok-number { color: var(--tok-number); }
.tok-function { color: var(--tok-function); }
.tok-constant { color: var(--tok-constant); font-weight: 600; }

.text-input {
  display: block;
  width: 100%;
  min-height: 96px;
  margin-top: 10px;
  padding: 12px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font: 15px/1.6 var(--mono);
  resize: none;
  overflow: hidden;
  outline: none;
}
.text-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px 16px; flex-wrap: wrap; margin-top: 8px; }
.input-count { font-size: 14px; color: var(--text-2); line-height: 28px; }
.input-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin: 14px 0; }
.stat { border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; min-width: 0; }
.stat .label { font-size: 13px; font-weight: 500; color: var(--text-2); }
.stat .value { display: flex; align-items: center; gap: 6px; font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.25; margin: 4px 0 2px; }
.stat .value .unit { font-size: 15px; font-weight: 500; color: var(--text-2); align-self: flex-end; margin-bottom: 3px; }
.stat .value .icon { width: 22px; height: 22px; }
.stat .sub { font-size: 13px; line-height: 1.4; color: var(--text-3); }
.stat.good .value { color: var(--good); }
.stat.bad .value { color: var(--bad); }
.badge { display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px; border-radius: 4px; font-size: 13px; font-weight: 500; }
.badge .icon { width: 14px; height: 14px; }
.badge.good { background: var(--good-bg); color: var(--good); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }

/* Heatmap */
.heatmap { font: 15px/2.1 var(--mono); margin-top: 6px; }
.heatmap .word { white-space: nowrap; }
.cell {
  display: inline-block;
  min-width: 1.05em;
  padding: 3px 1px;
  margin: 0 1px 2px 0;
  border-radius: 3px;
  text-align: center;
  line-height: 1.2;
  vertical-align: middle;
  cursor: pointer;
  outline-offset: 1px;
}
.cell.space { min-width: 0.6em; }
.cell.selected { outline: 2px solid var(--text); }
.cell.eof { font: 600 10px/1.2 var(--sans); padding: 5px 4px; letter-spacing: 0.02em; }
.legend { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 13px; color: var(--text-2); margin: 12px 0 6px; }
.legend .ramp { display: flex; gap: 2px; }
.legend .ramp span { width: 18px; height: 10px; border-radius: 2px; }

/* Distribution */
.dist-head { font-size: 15px; color: var(--text-2); margin: 4px 0 14px; }
.dist-head code { color: var(--text); }
.bars { display: grid; grid-template-columns: 72px minmax(0, 1fr) 112px; gap: 6px 12px; align-items: center; font-size: 13px; }
.bars .sym { font-family: var(--mono); text-align: right; color: var(--text); line-height: 16px; }
.bars .track { height: 16px; display: flex; align-items: center; border-left: 1px solid var(--line-strong); }
.bars .bar { height: 14px; border-radius: 0 4px 4px 0; background: var(--series); min-width: 2px; }
.bars .bar.actual { background: var(--series-strong); }
.bars .val { display: flex; align-items: center; gap: 8px; font-variant-numeric: tabular-nums; color: var(--text); white-space: nowrap; line-height: 16px; }
.bars .tag { font-size: 11px; font-weight: 600; color: var(--series-strong); background: var(--accent-soft); border-radius: 4px; padding: 1px 6px; line-height: 16px; }
.bars .gap { grid-column: 2 / -1; font-size: 13px; color: var(--text-3); }

/* Toggles, tables, reference */
details { margin: 4px 0; }
summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  padding: 0 6px;
  margin-left: -6px;
  border-radius: 6px;
  font-weight: 500;
}
summary:hover { background: var(--hover); }
summary::-webkit-details-marker { display: none; }
summary .chevron { color: var(--text-2); transition: transform 0.15s; }
details[open] > summary .chevron { transform: rotate(90deg); }
.toggle-body { padding: 4px 0 12px 24px; }
.hex { font: 13px/1.7 var(--mono); color: var(--text-2); word-break: break-all; }
table.compare { width: 100%; border-collapse: collapse; font-size: 14px; margin: 14px 0 4px; }
table.compare th { text-align: left; font-weight: 500; color: var(--text-2); border-bottom: 1px solid var(--line); padding: 8px; }
table.compare td { border-bottom: 1px solid var(--line); padding: 8px; font-variant-numeric: tabular-nums; vertical-align: middle; }
table.compare tr.current td { font-weight: 600; }
table.compare .model { display: flex; align-items: center; gap: 8px; }
table.compare .model .icon { color: var(--text-2); }
table.compare .num { text-align: right; }
.api dt { display: flex; align-items: center; gap: 8px; margin-top: 16px; }
.api dd { margin: 4px 0 0; color: var(--text-2); font-size: 15px; }
.optional { font-size: 12px; font-weight: 500; color: var(--text-2); background: var(--hover); border-radius: 4px; padding: 1px 6px; }

.tooltip {
  position: fixed;
  z-index: 20;
  pointer-events: none;
  background: #252525;
  color: #fff;
  font-size: 13px;
  line-height: 1.5;
  padding: 7px 10px;
  border-radius: 6px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
  max-width: 280px;
}
.tooltip[hidden] { display: none; }
.empty { color: var(--text-3); font-size: 14px; }

/* Responsive */
@media (max-width: 1080px) {
  .page { padding: 32px 48px 96px; }
}
@media (max-width: 820px) {
  .topbar { padding: 0 12px; gap: 10px; }
  .page { padding: 24px 20px 80px; }
  .select-wrap, .select-wrap select { width: 100%; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .status span { display: none; }
  .legend .ramp span { width: 12px; }
  .bars { grid-template-columns: 56px minmax(0, 1fr) 100px; }
}
@media (max-width: 420px) {
  .topbar { gap: 8px; }
  .brand { gap: 8px; }
  .stat { padding: 12px; }
  .stat .value { font-size: 22px; }
}
@media (max-width: 480px) {
  .brand-name { display: none; }
  .brand-name-short { display: inline; }
}
