/* ============================================================================
   bib design system.
   All colours come from CSS custom properties injected by the base template
   from branding.yaml — change the palette there, not here.
   ========================================================================== */

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { color-scheme: dark; }

body {
  margin: 0;
  background: var(--brand-bg);
  color: var(--brand-text);
  font-family: ui-sans-serif, system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15.5px;
  line-height: 1.55;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--brand-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

code, kbd, .mono {
  font-family: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
  font-size: 0.92em;
}
code { background: var(--brand-surface-2); padding: 0.1em 0.35em; border-radius: 4px; }

h1, h2, h3 { line-height: 1.2; letter-spacing: -0.01em; }
h1 { font-size: 1.9rem; margin: 0.4em 0; }
h2 { font-size: 1.35rem; margin: 1.2em 0 0.5em; }
h3 { font-size: 1.05rem; margin: 1em 0 0.4em; }

.muted { color: var(--brand-muted); }
.small { font-size: 0.86rem; }

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

.site-header {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 1.5rem;
  padding: 0.55rem 1.4rem;
  background: color-mix(in srgb, var(--brand-bg) 82%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--brand-border);
}

.brand { display: flex; align-items: baseline; gap: 0.55rem; color: var(--brand-text); }
.brand:hover { text-decoration: none; }
.brand-logo { width: 26px; height: 26px; align-self: center; }
.brand-name { font-weight: 700; font-size: 1.15rem; }
.brand-sub { color: var(--brand-muted); font-size: 0.85rem; }

.site-nav { margin-left: auto; display: flex; gap: 0.2rem; flex-wrap: wrap; }
.site-nav a {
  color: var(--brand-muted); padding: 0.35rem 0.7rem; border-radius: 8px;
  font-size: 0.93rem;
}
.site-nav a:hover { color: var(--brand-text); background: var(--brand-surface); text-decoration: none; }
.site-nav a.active { color: var(--brand-text); background: var(--brand-surface-2); }

/* ---- banner ------------------------------------------------------------- */

.synthetic-banner {
  background: color-mix(in srgb, var(--brand-warn) 18%, var(--brand-bg));
  border-bottom: 1px solid color-mix(in srgb, var(--brand-warn) 45%, transparent);
  color: var(--brand-text);
  padding: 0.45rem 1.4rem;
  font-size: 0.9rem;
}
.synthetic-banner a { color: inherit; text-decoration: underline; }

/* ---- layout ------------------------------------------------------------- */

.site-main { flex: 1; width: min(1200px, 100% - 2.8rem); margin: 1.2rem auto 2.5rem; }
.site-main.wide { width: min(1600px, 100% - 2rem); }

.site-footer {
  border-top: 1px solid var(--brand-border);
  padding: 1rem 1.4rem 1.6rem;
  font-size: 0.85rem;
  color: var(--brand-muted);
  display: flex; flex-direction: column; gap: 0.3rem;
}

.grid { display: grid; gap: 1rem; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }

.row { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.spacer { flex: 1; }

/* ---- cards & panels ------------------------------------------------------ */

.card {
  background: var(--brand-surface);
  border: 1px solid var(--brand-border);
  border-radius: 14px;
  padding: 1rem 1.2rem;
}
.card.tight { padding: 0.7rem 0.9rem; }
.card h2:first-child, .card h3:first-child { margin-top: 0.1em; }

.feature-card { transition: transform 0.12s ease, border-color 0.12s ease; display: block; color: var(--brand-text); }
.feature-card:hover { transform: translateY(-2px); border-color: var(--brand-primary); text-decoration: none; }
.feature-card .icon { font-size: 1.5rem; }

/* Explorer layout: controls sidebar + plot area */
.explorer {
  display: grid;
  grid-template-columns: 315px minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}
@media (max-width: 900px) { .explorer { grid-template-columns: 1fr; } }

.controls { display: flex; flex-direction: column; gap: 0.85rem; position: sticky; top: 4rem; }

/* SSP and Star Explorers: each column scrolls under the pointer, not the whole page. */
body:has(.split-stage) { height: 100vh; overflow: hidden; }
body:has(.split-stage) .site-footer { display: none; }
.site-main.split-stage {
  min-height: 0;
  margin-bottom: 0.6rem;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.split-stage .explorer { flex: 1; min-height: 0; align-items: stretch; }
.split-stage .controls,
.split-stage .explorer-main {
  overflow-y: auto;
  overscroll-behavior: contain;
  min-height: 0;
  max-height: 100%;
}
.split-stage .controls { position: static; }
.explorer-main { display: flex; flex-direction: column; gap: 0.8rem; min-width: 0; }
@media (max-width: 900px) {
  body:has(.split-stage) { height: auto; overflow: auto; }
  body:has(.split-stage) .site-footer { display: flex; }
  .site-main.split-stage { display: block; overflow: visible; }
  .split-stage .controls,
  .split-stage .explorer-main { overflow: visible; max-height: none; }
}
.control-group { display: flex; flex-direction: column; gap: 0.3rem; }
.control-group > label { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--brand-muted); }
.control-group > label .hint {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1rem;
  height: 1rem;
  margin-left: 0.3rem;
  border: 1px solid var(--brand-border);
  border-radius: 999px;
  font-size: 0.68rem;
  letter-spacing: 0;
  text-transform: none;
  cursor: help;
  vertical-align: 0.05em;
}
.control-inline { display: flex; gap: 0.5rem; align-items: center; }
.control-inline output { min-width: 4.2em; text-align: right; font-variant-numeric: tabular-nums; }

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

select, input[type="text"], input[type="number"], input[type="file"] {
  background: var(--brand-surface-2);
  color: var(--brand-text);
  border: 1px solid var(--brand-border);
  border-radius: 8px;
  padding: 0.42rem 0.6rem;
  font: inherit;
  width: 100%;
}
select:focus, input:focus { outline: 2px solid color-mix(in srgb, var(--brand-primary) 60%, transparent); outline-offset: 1px; }

input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 6px; border-radius: 3px;
  background: linear-gradient(to right, var(--brand-primary) var(--fill, 0%), var(--brand-surface-2) var(--fill, 0%));
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--brand-primary);
  border: 2px solid var(--brand-bg);
  box-shadow: 0 0 0 1px var(--brand-primary);
}
input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--brand-primary); border: 2px solid var(--brand-bg);
  box-shadow: 0 0 0 1px var(--brand-primary);
}
input[type="range"].is-cosmowarn {
  background: linear-gradient(to right, #c45c5c var(--fill, 0%), var(--brand-surface-2) var(--fill, 0%));
}
input[type="range"].is-cosmowarn::-webkit-slider-thumb {
  background: #d07070;
  box-shadow: 0 0 0 1px #d07070;
}
input[type="range"].is-cosmowarn::-moz-range-thumb {
  background: #d07070;
  box-shadow: 0 0 0 1px #d07070;
}
.cosmo-bang {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.05rem;
  height: 1.05rem;
  margin-left: 0.35rem;
  border-radius: 999px;
  background: color-mix(in srgb, #c45454 78%, #2a1010);
  color: #fff7f5;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: none;
  cursor: help;
  vertical-align: 0.05em;
}
input[type="range"]:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

button, .btn {
  background: var(--brand-surface-2);
  color: var(--brand-text);
  border: 1px solid var(--brand-border);
  border-radius: 9px;
  padding: 0.45rem 0.9rem;
  font: inherit; font-weight: 550;
  cursor: pointer;
  transition: filter 0.1s ease, background 0.1s ease;
}
button:hover, .btn:hover { filter: brightness(1.15); text-decoration: none; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.primary, .btn.primary { background: var(--brand-primary); color: var(--brand-primary-contrast); border-color: transparent; }
button.accent, .btn.accent { background: var(--brand-accent); color: var(--brand-primary-contrast); border-color: transparent; }
button.ghost { background: transparent; }
button.icon-btn { padding: 0.35rem 0.55rem; line-height: 1; }

fieldset.seg {
  display: inline-flex; flex-wrap: wrap; max-width: 100%;
  border: 1px solid var(--brand-border); border-radius: 9px;
  padding: 2px; margin: 0; gap: 2px; background: var(--brand-surface-2);
}
fieldset.seg label {
  padding: 0.28rem 0.7rem; border-radius: 7px; cursor: pointer;
  color: var(--brand-muted); font-size: 0.9rem;
}
fieldset.seg input { display: none; }
fieldset.seg label:has(input:checked) { background: var(--brand-primary); color: var(--brand-primary-contrast); }
fieldset.seg.compact label { padding: 0.12rem 0.5rem; font-size: 0.84rem; }

/* ---- chips (kept SEDs, event toggles) ------------------------------------ */

.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.chip {
  display: inline-flex; align-items: center; gap: 0.4rem;
  background: var(--brand-surface-2);
  border: 1px solid var(--brand-border);
  border-radius: 999px;
  padding: 0.18rem 0.4rem 0.18rem 0.7rem;
  font-size: 0.84rem;
}
.chip .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--chip-color, var(--brand-primary)); }
.chip button { border: none; background: transparent; padding: 0 0.3rem; color: var(--brand-muted); font-size: 1rem; }
.chip button:hover { color: var(--brand-warn); }

.chip.sync-chip { cursor: pointer; user-select: none; padding: 0.18rem 0.7rem; }
.chip.sync-chip input { margin: 0 0.2rem 0 0; accent-color: var(--brand-primary); }
.chip.sync-chip:has(input:checked) { border-color: var(--brand-primary); color: var(--brand-primary); }

table.data input[type="checkbox"] { accent-color: var(--brand-primary); vertical-align: -1.5px; }
.plot-note label input[type="checkbox"] { accent-color: var(--brand-primary); vertical-align: -2px; }

/* ---- tables --------------------------------------------------------------- */

table.data {
  border-collapse: collapse; width: 100%; font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}
table.data th, table.data td { padding: 0.4rem 0.6rem; text-align: right; border-bottom: 1px solid var(--brand-border); }
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data thead th { color: var(--brand-muted); font-weight: 600; position: sticky; top: 0; background: var(--brand-surface); }
table.data tbody tr:hover { background: var(--brand-surface-2); }

/* ---- plots ---------------------------------------------------------------- */

.plot-host { width: 100%; min-height: 420px; border-radius: 12px; overflow: hidden; }
.plot-host.compact { min-height: 320px; overflow: visible; }
.plot-host.compact.imf-stack { min-height: 520px; }

.sed-with-key {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.7rem;
  align-items: start;
}
.ssp-color-key {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  min-width: 10.5rem;
  max-width: 14rem;
  padding: 0.35rem 0.15rem 0.2rem;
  font-size: 0.8rem;
  line-height: 1.25;
}
.ssp-color-key .key-row {
  display: flex;
  align-items: flex-start;
  gap: 0.4rem;
}
.ssp-color-key .key-dot {
  width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto;
  margin-top: 0.2rem;
  background: var(--key-color, var(--brand-primary));
}
.ssp-color-key .key-label { color: var(--brand-text); word-break: break-word; }
.ssp-color-key .key-shared {
  margin: 0 0 0.15rem;
  color: var(--brand-muted);
  font-size: 0.74rem;
  line-height: 1.35;
}
.ssp-color-key .key-hint {
  color: var(--brand-muted);
  font-size: 0.74rem;
  margin-top: 0.15rem;
}
.sed-hover-tip {
  position: fixed;
  z-index: 40;
  pointer-events: none;
  background: var(--brand-surface, var(--brand-bg));
  color: var(--brand-text);
  border: 1px solid rgba(154, 167, 199, 0.28);
  border-radius: 6px;
  padding: 0.45rem 0.65rem 0.5rem;
  font-size: 0.8rem;
  line-height: 1.35;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  min-width: 8.5rem;
}
.sed-hover-legend {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}
.sed-hover-swatch { display: block; flex: 0 0 auto; }
.sed-hover-note { color: var(--brand-muted); font-size: 0.75rem; }
@media (max-width: 800px) {
  .sed-with-key { grid-template-columns: 1fr; }
  .ssp-color-key {
    flex-direction: row; flex-wrap: wrap; max-width: none; min-width: 0;
  }
}
.plot-note { font-size: 0.8rem; color: var(--brand-muted); margin-top: 0.35rem; }

.panel-title {
  font-size: 1.08rem;
  font-weight: 650;
  letter-spacing: 0.01em;
  margin: 0 0 0.15rem;
  padding-left: 0.55rem;
  border-left: 3px solid var(--brand-primary);
}
.panel-sub { font-size: 0.8rem; color: var(--brand-muted); margin: 0 0 0.4rem; }
.ssp-aux {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.8rem;
}
@media (max-width: 1100px) { .ssp-aux { grid-template-columns: 1fr; } }
.plot-toggle {
  display: flex; align-items: center; gap: 0.4rem;
  text-transform: none; letter-spacing: 0; font-size: 0.86rem;
  color: var(--brand-text); cursor: pointer;
}
.plot-toggle input { width: auto; accent-color: var(--brand-primary); }
details.phot-panel { padding: 0.7rem 0.9rem; }
details.phot-panel > summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 0.5rem;
  min-height: 1.7rem;
}
details.phot-panel > summary::-webkit-details-marker { display: none; }
details.phot-panel > summary::before {
  content: "";
  width: 0.42em;
  height: 0.42em;
  flex: 0 0 auto;
  margin: 0 0.15em;
  border-right: 2.5px solid var(--brand-primary);
  border-bottom: 2.5px solid var(--brand-primary);
  transform: rotate(-45deg);
  transform-origin: 50% 50%;
}
details.phot-panel[open] > summary::before {
  content: "";
  transform: rotate(45deg) translate(-0.08em, -0.08em);
}
details.phot-panel > summary .panel-title {
  margin: 0;
  line-height: 1.2;
  display: flex;
  align-items: center;
}
details.phot-panel > summary .btn { margin-left: auto; flex-shrink: 0; }

.pin-action { gap: 0.4rem; }
#btn-pin {
  width: 100%;
  padding: 0.75rem 1rem;
  font-size: 1.02rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  box-shadow:
    0 0 0 1px color-mix(in srgb, var(--brand-accent) 65%, transparent),
    0 8px 22px color-mix(in srgb, var(--brand-primary) 32%, transparent);
}

/* ---- playback bar ---------------------------------------------------------- */

.playback {
  display: flex; align-items: center; gap: 0.7rem;
  background: var(--brand-surface);
  border: 1px solid var(--brand-border);
  border-radius: 12px;
  padding: 0.5rem 0.8rem;
  flex-wrap: wrap;
}
.playback .scrub { flex: 1; min-width: 160px; }
.playback .readout { font-variant-numeric: tabular-nums; min-width: 11em; }
.playback .speed { width: 130px; }

/* ---- readout panel (HR explorer) ------------------------------------------ */

.readout-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.45rem 0.9rem; font-size: 0.88rem;
}
.readout-grid .item { display: flex; flex-direction: column; }
.readout-grid .item .k { color: var(--brand-muted); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; }
.readout-grid .item .v { font-variant-numeric: tabular-nums; }

/* ---- misc ------------------------------------------------------------------ */

.ack-box {
  background: var(--brand-surface-2);
  border-left: 3px solid var(--brand-accent);
  border-radius: 8px;
  padding: 0.7rem 0.9rem;
  font-size: 0.92rem;
  position: relative;
}
.ack-box .copy-btn { position: absolute; top: 0.5rem; right: 0.5rem; }

.lede { font-size: 1.15rem; color: var(--brand-muted); max-width: 40rem; margin-top: 0.2rem; }
.home-title { font-size: 2.4rem; margin-bottom: 0.25rem; }
.page-kicker { margin: 0.15rem 0 0.85rem; color: var(--brand-muted); max-width: 42rem; }
.page-kicker.is-one-line { max-width: none; white-space: nowrap; }
@media (max-width: 720px) { .page-kicker.is-one-line { white-space: normal; } }
#col-table { table-layout: fixed; width: 100%; }
#col-table col.col-unit { width: 28rem; }
#col-table th:nth-child(2),
#col-table td:nth-child(2) { width: 28rem; white-space: normal; }
.contents { max-width: 42rem; margin: 0.4rem 0 1.6rem; }
.contents dt { margin-top: 0.85rem; font-weight: 650; }
.contents dd { margin: 0.15rem 0 0; color: var(--brand-muted); }

details.help { border: 1px dashed var(--brand-border); border-radius: 10px; padding: 0.5rem 0.8rem; }
details.help summary { cursor: pointer; color: var(--brand-muted); font-size: 0.9rem; }

pre {
  background: var(--brand-surface-2);
  border: 1px solid var(--brand-border);
  border-radius: 10px;
  padding: 0.75rem 1rem;
  overflow-x: auto;
  font-size: 0.86rem;
  line-height: 1.55;
}
pre code { background: transparent; padding: 0; }

.cta-row { display: flex; gap: 0.7rem; flex-wrap: wrap; margin: 1.3rem 0 0.9rem; }
.cta-row .btn { padding: 0.6rem 1.2rem; font-size: 1rem; }

.prose { max-width: 820px; }
.prose h2 { margin-top: 1.7em; }
.prose li { margin: 0.25rem 0; }

ul.cites { padding-left: 1.2rem; }
ul.cites li { margin: 0.35rem 0; }

.copy-btn.copied { background: var(--brand-accent-2); color: var(--brand-primary-contrast); border-color: transparent; }

.callout {
  display: flex; gap: 1rem; align-items: flex-start;
  background: color-mix(in srgb, var(--brand-primary) 9%, var(--brand-surface));
  border: 1px solid color-mix(in srgb, var(--brand-primary) 45%, var(--brand-border));
  border-left: 4px solid var(--brand-primary);
  border-radius: 12px;
  padding: 1rem 1.2rem;
}
.callout .icon { font-size: 1.7rem; line-height: 1; margin-top: 0.15rem; }

.table-wrap { max-height: 430px; overflow: auto; border: 1px solid var(--brand-border); border-radius: 10px; }
.table-wrap.wide { max-height: min(70vh, 640px); }
.table-wrap table.data { width: 100%; }
.table-wrap table.data th, .table-wrap table.data td { white-space: nowrap; }
.table-wrap table.data td.wrap { white-space: normal; max-width: 28rem; }
.table-wrap table.data tr.col-group td {
  font-weight: 650;
  background: var(--brand-surface-2);
}
pre.api-examples {
  max-width: none;
  overflow-x: auto;
  white-space: pre;
}

hr { border: none; border-top: 1px solid var(--brand-border); margin: 1.4rem 0; }

.recipe-list { display: flex; flex-direction: column; gap: 0.4rem; }
.recipe {
  display: flex; flex-direction: column; align-items: flex-start; gap: 0.15rem;
  width: 100%; text-align: left;
  background: var(--brand-surface-2);
  border: 1px solid var(--brand-border);
  border-radius: 10px;
  padding: 0.5rem 0.65rem;
  font-weight: 500;
}
.recipe strong { font-size: 0.92rem; }
.recipe span { color: var(--brand-muted); font-size: 0.78rem; font-weight: 400; line-height: 1.35; }
.recipe.is-active {
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--brand-primary) 55%, transparent);
}
.request-meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); gap: 0.55rem 1rem; margin: 0.6rem 0 0; }
.request-meta div { margin: 0; }
.request-meta dt { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--brand-muted); }
.request-meta dd { margin: 0.1rem 0 0; }
.request-preview { min-width: 0; }
.request-url-line {
  display: flex;
  gap: 0.45rem;
  align-items: baseline;
  margin: 0.7rem 0 0;
  min-width: 0;
}
.request-url-line code {
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  white-space: nowrap;
}
@media (max-width: 900px) { .request-layout { grid-template-columns: 1fr; } }

.badge {
  display: inline-block; padding: 0.08rem 0.5rem; border-radius: 999px;
  font-size: 0.75rem; font-weight: 600;
  background: var(--brand-surface-2); color: var(--brand-muted);
  border: 1px solid var(--brand-border);
}
.badge.warn { background: color-mix(in srgb, var(--brand-warn) 25%, transparent); color: var(--brand-text); }
.badge.ok { background: color-mix(in srgb, var(--brand-accent-2) 25%, transparent); color: var(--brand-text); }
