/* G-Divergence & Information Landscape. Layout: title with the three surfaces; the descent bar (transport, epsilon,
   delta, steepness); the 3D surface beside the distribution matcher; then G over the steps and the gradient compass.
   Changing text has a fixed size, so nothing moves while it runs. */
:root {
  color-scheme: dark;
  --bg: #070a13;
  --panel: #0c111d;
  --panel-2: #121a29;
  --line: #1a2335;
  --line-2: #29364f;
  --fg: #e4e9f3;
  --muted: #8b97ad;
  --dim: #56627a;
  --cyan: #00f5ff;
  --amber: #f59e0b;
  --gd: #ff4d5e;
  --green: #10b981;
  --display: "Literata", "Iowan Old Style", Georgia, serif;
  --sans: "Instrument Sans", "Segoe UI", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --r: 6px;
}
[hidden] { display: none !important; }
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--fg); font: 14px/1.45 var(--sans); }
button, select, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }

.app { display: grid; gap: 12px; padding-block: 12px 20px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.top { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 24px; }
.eyebrow { font: 500 11px/1.2 var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
h1 { margin: 4px 0 0; font: 600 24px/1.15 var(--display); text-wrap: balance; }
h1 span { display: block; margin-top: 3px; font: 400 13px/1.3 var(--sans); color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font: 12.5px var(--sans); padding: 5px 11px; border-radius: 999px; border: 1px solid var(--line-2); background: var(--panel); cursor: pointer; transition: border-color .15s, color .15s; }
.chip:hover { border-color: var(--cyan); }
.chip.on { border-color: var(--cyan); color: var(--cyan); background: rgba(0,245,255,.07); }
.note { margin: 0; font-size: 13.5px; color: #c7cfdf; max-width: 130ch; min-height: calc(3 * 1.45em); }
.note b { color: var(--fg); }

select, .btn { background: var(--panel-2); border: 1px solid var(--line-2); border-radius: var(--r); padding: 5px 9px; min-height: 32px; max-width: 100%; }
.btn { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; transition: border-color .15s; white-space: nowrap; }
.btn:hover { border-color: var(--cyan); }
.btn svg { width: 14px; height: 14px; flex: none; }
.btn.icon { padding: 5px 8px; }
.btn.sm { min-height: 26px; padding: 2px 9px; font-size: 12px; }
.btn.primary { background: rgba(0,245,255,.09); border-color: rgba(0,245,255,.5); color: var(--cyan); }
.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: var(--r); overflow: hidden; flex: none; }
.segb { background: var(--panel-2); border: 0; padding: 3px 9px; font: 12px var(--mono); cursor: pointer; color: var(--muted); white-space: nowrap; }
.segb + .segb { border-left: 1px solid var(--line-2); }
.segb.on { background: rgba(0,245,255,.12); color: var(--cyan); }

.card { border: 1px solid var(--line); border-radius: 8px; background: var(--panel); padding: 10px 12px 12px; display: grid; gap: 8px; min-width: 0; align-content: start; }
.card-h { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 12px; }
.sec-h { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; margin: 0; font: 500 11px var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); min-width: 0; }
.sec-h em { font-style: normal; text-transform: none; letter-spacing: 0; color: var(--dim); }
.cap { margin: 0; font: 11.5px/1.45 var(--mono); color: var(--dim); }
.tag { white-space: nowrap; font: 500 11.5px var(--mono); color: var(--muted); padding: 3px 8px; border-radius: 4px; border: 1px solid var(--line-2); font-variant-numeric: tabular-nums; }
.tag:empty { visibility: hidden; }
canvas { display: block; width: 100%; border-radius: 6px; border: 1px solid var(--line); background: #04060c; }

/* descent bar */
.tr-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; }
.spacer { flex: 1; }
.sl { display: inline-flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.sl input { width: 120px; }
.sl b { font: 500 12.5px var(--mono); min-width: 5.5ch; font-variant-numeric: tabular-nums; color: var(--fg); }
.sl.gd b { color: var(--gd); } .sl.sg b { color: var(--cyan); }
.clock { font: 500 12.5px var(--mono); color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; min-width: 14ch; text-align: right; }
.clock b { color: var(--fg); display: inline-block; min-width: 3ch; text-align: right; }
input[type=range] { -webkit-appearance: none; appearance: none; background: transparent; height: 18px; margin: 0; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: var(--line-2); }
input[type=range]::-moz-range-track { height: 4px; border-radius: 2px; background: var(--line-2); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; margin-top: -5px; border-radius: 50%; background: var(--fg); border: 2px solid var(--bg); box-shadow: 0 0 0 1px var(--cyan); }
input[type=range]::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: var(--fg); border: 2px solid var(--bg); }

/* stage */
.main { display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 12px; align-items: start; }
.legend { display: flex; align-items: center; gap: 12px; font: 12px var(--mono); }
.lg.gd { color: var(--gd); } .lg.sg { color: var(--cyan); }
.stage-wrap { position: relative; height: 560px; border-radius: 6px; overflow: hidden; border: 1px solid var(--line); background: radial-gradient(100% 90% at 50% 40%, #0d1628 0%, #04060c 75%); }
#cvStage { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: transparent; cursor: grab; }
.hint { position: absolute; left: 10px; bottom: 8px; font: 11px var(--mono); color: var(--dim); pointer-events: none; }
.flag { position: absolute; right: 10px; top: 10px; padding: 6px 10px; border-radius: 5px; font: 600 12px var(--mono); color: #fff; background: rgba(255,77,94,.85); box-shadow: 0 0 18px rgba(255,77,94,.6); pointer-events: none; }

/* matcher */
.side { display: grid; gap: 12px; min-width: 0; }
.mini-tr { display: flex; gap: 6px; }
.envs { display: flex; flex-wrap: wrap; gap: 6px; }
.envs .chip { font-size: 12px; padding: 3px 9px; }
.m-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; font-size: 12.5px; color: var(--muted); }
.m-sel select { min-height: 26px; padding: 1px 4px; font-size: 12px; }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 12.5px; color: var(--muted); }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch i { width: 30px; height: 17px; border-radius: 9px; background: var(--line-2); position: relative; transition: background .15s; flex: none; }
.switch i::after { content: ""; position: absolute; left: 3px; top: 3px; width: 11px; height: 11px; border-radius: 50%; background: var(--fg); transition: transform .15s; }
.switch input:checked + i { background: var(--cyan); }
.switch input:checked + i::after { transform: translateX(13px); background: #04060c; }
#cvBars { height: 190px; }
#cvBars.drag { cursor: ns-resize; }
.gauge { display: grid; grid-template-columns: 92px minmax(0, 1fr); grid-template-rows: auto auto; gap: 6px 12px; align-items: center; }
#cvRing { width: 92px; height: 92px; border: 0; background: transparent; grid-row: span 2; }
.g-read { display: grid; gap: 1px; font: 11.5px var(--mono); color: var(--muted); }
.g-read b { font: 700 26px/1.1 var(--mono); font-variant-numeric: tabular-nums; color: var(--fg); }
.g-read span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#cvMG { height: 42px; }
#mCap { height: calc(3 * 1.45em); overflow: hidden; }

/* lower */
.lower { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 12px; align-items: start; }
#cvTrace { height: 220px; }
.conv { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.conv div { border: 1px solid var(--line-2); border-radius: 6px; padding: 6px 10px; display: grid; gap: 1px; background: var(--panel-2); }
.conv span { font: 11px var(--mono); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv b { font: 600 18px/1.2 var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
.conv .gd b { color: var(--gd); } .conv .sg b { color: var(--cyan); }
.grad-grid { display: grid; grid-template-columns: 180px minmax(0, 1fr); gap: 12px; align-items: start; }
#cvCompass { height: 180px; }
.kv { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 3px 10px; font: 12px var(--mono); font-variant-numeric: tabular-nums; }
.kv span { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kv b { font-weight: 500; text-align: right; white-space: nowrap; }
.kv .h { color: var(--fg); grid-column: 1 / -1; font-weight: 600; margin-top: 4px; }
.kv .h.gd { color: var(--gd); } .kv .h.sg { color: var(--cyan); }
#gradCap { height: calc(2 * 1.45em); overflow: hidden; }

@media (max-width: 1200px) {
  .main { grid-template-columns: minmax(0, 1fr); }
  .lower { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 720px) {
  h1 { font-size: 20px; }
  .stage-wrap { height: 420px; }
  .sl input { width: 90px; }
  .note { min-height: 0; }
  .grad-grid { grid-template-columns: minmax(0, 1fr); }
  .clock { text-align: left; }
}
.pg-embedded .top > div:first-child { display: none; }
@media (prefers-reduced-motion: reduce) { .btn, .chip, .switch i, .switch i::after { transition: none; } }
