:root {
  --bg: #05070d;
  --panel: rgba(12, 17, 30, 0.94);
  --panel-border: #2a3550;
  --text: #e8edf7;
  --muted: #a9b4c9;
  --accent: #8fb4ff;
  --ok: #7fd18b;
  --warn: #ffc46b;
  --focus: #ffd34d;
  --panel-w: 360px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { overflow: hidden; }

.skip-link { position: absolute; left: -9999px; top: 0; z-index: 100; background: var(--focus); color: #000; padding: 6px 10px; }
.skip-link:focus { left: 8px; top: 8px; }

#app { display: grid; grid-template-columns: 1fr var(--panel-w); height: 100vh; height: 100dvh; }
#stage { position: relative; min-width: 0; min-height: 0; overflow: hidden; }
#viewport { position: absolute; inset: 0; }
#viewport canvas { display: block; width: 100%; height: 100%; outline: none; }
#viewport canvas:focus-visible { outline: 3px solid var(--focus); outline-offset: -3px; }

.hud-title { position: absolute; left: 14px; top: 10px; pointer-events: none; text-shadow: 0 1px 3px #000; }
.hud-title h1 { margin: 0; font-size: 20px; letter-spacing: 0.02em; }
.hud-title p { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; }

.views { position: absolute; left: 14px; bottom: 14px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.views-label { color: var(--muted); font-size: 12px; }
.views [role="group"] { display: flex; gap: 4px; flex-wrap: wrap; }

.focus-card { position: absolute; left: 14px; top: 70px; width: min(360px, calc(100% - 28px)); max-height: 55%; overflow: auto; background: var(--panel); border: 1px solid var(--panel-border); border-radius: 10px; padding: 10px 14px; box-shadow: 0 6px 24px rgba(0,0,0,0.5); }
.focus-card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.focus-card h2 { margin: 0; font-size: 15px; }
.focus-card p { margin: 8px 0; color: #d3dbea; font-size: 13px; }
#focus-close { font-size: 18px; line-height: 1; padding: 2px 9px; }

.loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); }

#panel { overflow-y: auto; background: var(--panel); border-left: 1px solid var(--panel-border); padding: 10px 14px 24px; }
#panel h2 { font-size: 14px; margin: 4px 0 6px; color: var(--accent); }
fieldset { border: 1px solid var(--panel-border); border-radius: 8px; margin: 10px 0; padding: 6px 10px 10px; }
legend { padding: 0 6px; color: var(--accent); font-weight: 600; }

.field { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 2px 8px; margin: 8px 0; }
.field label { font-weight: 500; }
.field output { font-variant-numeric: tabular-nums; color: #fff; font-size: 13px; }
.field input[type="range"], .field select { grid-column: 1 / -1; width: 100%; }
.field .hint { grid-column: 1 / -1; margin: 0; color: var(--muted); font-size: 11.5px; }
.field.check { grid-template-columns: auto 1fr; }
.field.check input { width: 18px; height: 18px; margin: 0; }

input[type="range"] { accent-color: var(--accent); height: 22px; }
select { background: #0f1626; color: var(--text); border: 1px solid var(--panel-border); border-radius: 6px; padding: 5px 6px; font: inherit; }

button { background: #1b2742; color: var(--text); border: 1px solid #3a4b73; border-radius: 6px; padding: 6px 12px; font: inherit; cursor: pointer; }
button:hover { background: #24345a; }
button:disabled { opacity: 0.55; cursor: not-allowed; }
button[aria-pressed="true"], button.on { background: #6b3cf0; border-color: #a58bff; color: #fff; box-shadow: 0 0 12px rgba(150,120,255,0.6); }
.button-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.threshold { border: 1px solid var(--panel-border); border-radius: 8px; padding: 6px 10px; background: rgba(30, 40, 70, 0.4); }
.threshold .vb { margin: 2px 0; }
.threshold .vb strong { font-size: 16px; color: #fff; }
.small { font-size: 11.5px; color: var(--muted); margin: 2px 0; }
.status { margin: 6px 0 2px; padding: 6px 8px; border-radius: 6px; background: rgba(255,255,255,0.05); font-weight: 600; }
.status[data-kind="warn"] { color: var(--warn); background: rgba(255,196,107,0.08); }
.status[data-kind="ok"] { color: var(--ok); background: rgba(127,209,139,0.10); }
.status[data-kind="info"] { color: var(--accent); }

.readouts dl { display: grid; grid-template-columns: 1fr; margin: 0; }
.readouts dl > div { display: flex; justify-content: space-between; gap: 8px; padding: 3px 0; border-bottom: 1px dashed rgba(255,255,255,0.07); }
.readouts dt { color: var(--muted); }
.readouts dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.swatch { display: inline-block; width: 14px; height: 14px; border-radius: 3px; vertical-align: -2px; margin-right: 6px; border: 1px solid rgba(255,255,255,0.4); }
.advisory { color: var(--warn); font-size: 12px; margin: 6px 0; }
.chart { display: block; width: 100%; height: 170px; margin-top: 8px; border-radius: 6px; border: 1px solid var(--panel-border); }

.info details { border: 1px solid var(--panel-border); border-radius: 8px; margin: 8px 0; padding: 4px 10px; }
.info summary { cursor: pointer; font-weight: 600; padding: 4px 0; }
.info pre { white-space: pre-wrap; background: rgba(0,0,0,0.35); padding: 6px 8px; border-radius: 6px; font-size: 12px; }
.info ul { padding-left: 18px; }
.info li { margin: 4px 0; }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; font-size: 12px; width: 100%; }
caption { text-align: left; color: var(--muted); padding-bottom: 4px; }
th, td { border: 1px solid var(--panel-border); padding: 3px 5px; text-align: right; }
th[scope="row"] { text-align: left; }
a { color: var(--accent); }
.refs .tag { color: var(--ok); font-size: 11px; }

.panel-toggle { display: none; }
.noscript { padding: 20px; }

@media (max-width: 899px) {
  #app { grid-template-columns: 1fr; grid-template-rows: 1fr; }
  #panel { position: fixed; left: 0; right: 0; bottom: 0; max-height: 62vh; border-left: 0; border-top: 1px solid var(--panel-border); border-radius: 14px 14px 0 0; z-index: 20; transition: transform 0.25s ease; padding-top: 44px; }
  #panel.collapsed { transform: translateY(calc(100% - 0px)); visibility: hidden; }
  .panel-toggle { display: block; position: fixed; right: 12px; bottom: 12px; z-index: 30; }
  #panel:not(.collapsed) ~ .panel-toggle, .panel-toggle[aria-expanded="true"] { bottom: calc(62vh - 38px); }
  .chart { height: 130px; }
  .hud-title h1 { font-size: 16px; }
  .hud-title p { display: none; }
  .views { bottom: 60px; }
  .focus-card { top: 50px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* Author credit at the bottom of the control panel */
.panel-credit {
  margin: 16px 4px 8px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  text-align: center;
  font-size: 0.85rem;
  color: #aab4c8;
}
