/* ═══════════════════════════════════════════════════════════════════
   Belief State Geometry — Observatory Instrument aesthetic
   ═══════════════════════════════════════════════════════════════════ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:         #08090c;
  --surface:    #0f1014;
  --card:       #16171e;
  --border:     #1e2029;
  --border-hi:  #2e3040;

  --accent:     #c9944a;
  --accent-dim: rgba(201, 148, 74, 0.10);
  --accent-hi:  #ddb070;

  --teal:       #5b9a8b;
  --text:       #cdc5b4;
  --text-hi:    #e8e0d4;
  --muted:      #8a8478;   /* secondary text: ≥4.5:1 on --surface */
  --faint:      #4a473f;   /* decoration only */
  --red:        #d4685a;

  --font-display: 'Fraunces', 'Georgia', serif;
  --font-body: 'Instrument Sans', system-ui, -apple-system, sans-serif;
  --font-mono: 'Fira Code', 'JetBrains Mono', monospace;

  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

html, body { height: 100%; overflow: hidden; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

::selection { background: rgba(221, 176, 112, 0.28); color: var(--text-hi); }

:focus-visible {
  outline: 1.5px solid var(--accent-hi);
  outline-offset: 2px;
  border-radius: 3px;
}

/* Noise grain overlay */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  opacity: 0.025;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 200px 200px;
}

.hidden { display: none !important; }

/* ── Layout ──────────────────────────────────────────────────────── */
.layout { display: flex; height: 100vh; }

/* ── Sidebar ─────────────────────────────────────────────────────── */
.sidebar {
  width: 296px;
  min-width: 296px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--border-hi) transparent;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 22px 20px 18px;
}

.logo-mark { width: 20px; height: 20px; color: var(--accent); flex-shrink: 0; }

h1 {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 400;
  font-style: italic;
  color: var(--text-hi);
  letter-spacing: -0.01em;
  font-variation-settings: 'opsz' 36;
}

.section {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

.section-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ── Process picker ──────────────────────────────────────────────── */
.process-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
}
.process-grid.ghmm-row {
  grid-template-columns: 1fr 1fr;
  margin-top: 10px;
}

.proc-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  padding: 8px 4px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
  font-family: var(--font-mono);
  letter-spacing: 0.03em;
  white-space: nowrap;
}
.proc-btn:hover { border-color: var(--border-hi); color: var(--text); }
.proc-btn.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent-hi);
}

.description {
  margin-top: 14px;
  font-size: 12px;
  color: var(--text);
  line-height: 1.6;
}
.description em {
  color: var(--accent-hi);
  font-style: normal;
  font-family: var(--font-mono);
  font-size: 11px;
}
.process-meta {
  margin-top: 6px;
  font-size: 11px;
  color: var(--muted);
  font-family: var(--font-mono);
}

/* ── Parameters ──────────────────────────────────────────────────── */
.param-row + .param-row { margin-top: 14px; }

.param-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
}

.param-label {
  font-size: 13px;
  color: var(--text);
  font-style: italic;
  font-family: var(--font-display);
  font-variation-settings: 'opsz' 14;
}

.param-val {
  font-size: 12px;
  font-weight: 500;
  color: var(--accent-hi);
  font-family: var(--font-mono);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

input.param-num {
  background: transparent;
  border: 1px solid var(--border-hi);
  border-radius: 3px;
  padding: 2px 6px;
  width: 72px;
  outline: none;
}
input.param-num:focus { border-color: var(--accent-hi); }

.slider {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  width: 100%;
  height: 2px;
  background: var(--border-hi);
  border-radius: 1px;
  outline: none;
  cursor: pointer;
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.45);
  transition: transform 0.15s var(--ease-out), background 0.15s;
}
.slider::-webkit-slider-thumb:hover { background: var(--accent-hi); transform: scale(1.12); }
.slider::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); border: none;
}
.slider:focus-visible { outline-offset: 6px; }

.depth-hint {
  font-size: 11px;
  color: var(--muted);
  margin-top: 8px;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

/* ── Sampling (collapsed by default) ─────────────────────────────── */
details > summary { list-style: none; cursor: pointer; }
details > summary::-webkit-details-marker { display: none; }

.sampling summary {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}
.sampling summary .section-label::after {
  content: '';
  display: inline-block;
  width: 5px; height: 5px;
  margin-left: 8px;
  border-right: 1.2px solid var(--muted);
  border-bottom: 1.2px solid var(--muted);
  transform: translateY(-2px) rotate(-45deg);
  transition: transform 0.2s var(--ease-out);
}
.sampling[open] summary .section-label::after { transform: translateY(-3px) rotate(45deg); }
.sampling-summary {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.sampling[open] > summary { margin-bottom: 14px; }
.sampling #sample-section,
.sampling #enum-section { margin-top: 14px; }

.mode-toggle {
  display: flex;
  gap: 2px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 2px;
}
.mode-btn {
  flex: 1;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 3px;
  color: var(--muted);
  font: 600 11px var(--font-body);
  padding: 5px 8px;
  cursor: pointer;
}
.mode-btn:hover { color: var(--text); }
.mode-btn.active { background: var(--accent-dim); border-color: var(--accent); color: var(--accent-hi); }

.compute-btn {
  width: 100%;
  margin-top: 16px;
  padding: 9px 14px;
  background: transparent;
  border: 1px solid var(--accent);
  border-radius: 5px;
  color: var(--accent-hi);
  font: 600 11px var(--font-body);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.15s;
}
.compute-btn:hover:not(:disabled) { background: var(--accent-dim); }
.compute-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Geometry thumbnail (Sweep and Emissions views) ──────────────── */
.mini-geo-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 10px;
}
.mini-geo-hint { font-size: 11px; color: var(--muted); }
#mini-plot {
  height: 190px;
  flex: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: border-color 0.15s;
}
#mini-plot:hover { border-color: var(--accent); }

/* ── Footer ──────────────────────────────────────────────────────── */
.sidebar-footer {
  margin-top: auto;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
}
.ref-link {
  font-size: 11px;
  color: var(--muted);
  text-decoration: none;
  font-family: var(--font-mono);
}
.ref-link:hover { color: var(--accent-hi); }

/* ══════════════════════════════════════════════════════════════════
   MAIN AREA
   ══════════════════════════════════════════════════════════════════ */
.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  background: var(--bg);
}

.view-bar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 20px;
  height: 44px;
  flex: 0 0 44px;
  border-bottom: 1px solid var(--border);
}
.view-tabs { display: flex; gap: 18px; height: 100%; }
.view-tab {
  position: relative;
  background: none;
  border: none;
  color: var(--muted);
  font: 500 12px var(--font-body);
  letter-spacing: 0.02em;
  cursor: pointer;
  padding: 0 2px;
}
.view-tab:hover { color: var(--text); }
.view-tab.active { color: var(--text-hi); }
.view-tab.active::after {
  content: '';
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 1.5px;
  background: var(--accent);
}
.view-caption {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}

.view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
}

.viz { flex: 1 1 auto; min-height: 0; overflow: hidden; }
#main-plot { min-height: 320px; }
#view-emissions .viz { flex: 1 1 0; min-height: 160px; }
#view-emissions .viz + .viz { border-top: 1px solid var(--border); }

/* ── Shared small controls ───────────────────────────────────────── */
.chip-btn {
  background: transparent;
  border: 1px solid var(--border-hi);
  color: var(--muted);
  font: 500 11px var(--font-body);
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.chip-btn:hover { color: var(--text); }
.chip-btn.active,
.chip-btn.toggle[aria-pressed="true"] {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent-hi);
}

.seg {
  display: inline-flex;
  border: 1px solid var(--border-hi);
  border-radius: 4px;
  overflow: hidden;
}
.seg-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  font: 500 11px var(--font-mono);
  padding: 4px 9px;
  cursor: pointer;
}
.seg-btn + .seg-btn { border-left: 1px solid var(--border-hi); }
.seg-btn:hover { color: var(--text); }
.seg-btn.active { background: var(--accent-dim); color: var(--accent-hi); }

.readout { display: flex; flex-direction: column; gap: 6px; }
.readout > div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  font-size: 11px;
}
.readout dt { color: var(--muted); font-family: var(--font-mono); }
.readout dd {
  color: var(--accent-hi);
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}

.hint {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
  margin-top: 8px;
}

/* ── Sweep view ──────────────────────────────────────────────────── */
.sweep-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
}
.sweep-axes { display: inline-flex; gap: 10px; }
.sweep-axes:empty { display: none; }
.sweep-axes label {
  font: italic 12px var(--font-display);
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.sweep-axes select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border-hi);
  border-radius: 4px;
  font: 11px var(--font-mono);
  padding: 3px 4px;
}
.sweep-readout {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 14px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.sweep-readout b { color: var(--accent-hi); font-weight: 500; }
.regime-chip {
  padding: 2px 8px;
  border-radius: 10px;
  border: 1px solid var(--border-hi);
  color: var(--muted);
}
.regime-chip.in { border-color: rgba(221, 176, 112, 0.5); color: var(--accent-hi); }

.metrics-pop { position: relative; }
.metrics-pop > summary {
  font-size: 11px;
  color: var(--muted);
  padding: 4px 2px;
}
.metrics-pop > summary:hover,
.metrics-pop[open] > summary { color: var(--text); }
.metrics-pop > .readout {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 50;
  width: 330px;
  padding: 14px 16px;
  background: var(--card);
  border: 1px solid var(--border-hi);
  border-radius: 6px;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.45);
}

.sweep-plots {
  flex: 1;
  display: flex;
  min-height: 360px;
}
.sweep-plots > .viz { flex: 1 1 0; min-width: 0; }
.sweep-plots > .viz + .viz { border-left: 1px solid var(--border); }

/* ── Bloch Walk view ─────────────────────────────────────────────── */
.bloch-view { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; }
.bloch-top { flex: 1 1 auto; display: flex; min-height: 420px; }
#bloch-plot { flex: 1 1 auto; min-width: 0; }
.bloch-purity { flex: 0 0 120px !important; border-top: 1px solid var(--border); }

.bloch-panel {
  flex: 0 0 268px;
  padding: 18px;
  border-left: 1px solid var(--border);
  overflow-y: auto;
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-areas: ". n ." "w c e" ". s .";
  gap: 6px;
}
.dpad-n { grid-area: n; --tok: #c9944a; }
.dpad-s { grid-area: s; --tok: #5b9a8b; }
.dpad-e { grid-area: e; --tok: #8bba7f; }
.dpad-w { grid-area: w; --tok: #d4685a; }
.dpad-c { grid-area: c; }

.dpad-btn {
  --p: 0.5;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  height: 60px;
  background: var(--bg);
  border: 1px solid var(--border-hi);
  border-radius: 6px;
  color: var(--text);
  font-family: var(--font-mono);
  cursor: pointer;
  transition: border-color 0.15s, transform 0.08s;
}
/* Fill height = P(token), on a 0–50% scale (the largest it can be). */
.dpad-btn[data-tok]::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--tok);
  opacity: 0.2;
  transform: scaleY(var(--p));
  transform-origin: bottom;
  transition: transform 0.25s var(--ease-out);
}
.dpad-btn > span { position: relative; }
.dpad-btn:hover:not(:disabled) { border-color: var(--tok, var(--accent)); }
.dpad-btn:active:not(:disabled) { transform: scale(0.96); }
.dpad-btn:disabled { opacity: 0.3; cursor: not-allowed; }

.dpad-tok { font-size: 17px; font-weight: 600; color: var(--tok); line-height: 1.1; }
.dpad-dir { font-size: 11px; color: var(--muted); }
.dpad-p   { font-size: 11px; color: var(--text-hi); font-variant-numeric: tabular-nums; }
.dpad-c {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.dpad-c:hover { color: var(--accent-hi); }

.bloch-actions { display: flex; gap: 6px; margin: 10px 0 18px; }
.bloch-actions .chip-btn { flex: 1; }
.bloch-tokens { letter-spacing: 0.08em; }

.bloch-rules { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 12px; }
.bloch-rules > summary { font-size: 11px; color: var(--muted); margin-bottom: 10px; }
.bloch-rules > summary:hover, .bloch-rules[open] > summary { color: var(--text); }
.bloch-rules .rule code {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-hi);
  white-space: nowrap;
  line-height: 1.8;
}
#bloch-sc { color: var(--accent-hi); }
#bloch-mirror { margin-left: 4px; padding: 1px 7px; }

/* ── Loading / errors ────────────────────────────────────────────── */
.loading-overlay {
  position: absolute;
  top: 56px; right: 20px;
  z-index: 200;
}
.spinner-ring {
  width: 16px;
  height: 16px;
  border: 1.5px solid var(--border-hi);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-toast {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(212, 104, 90, 0.08);
  border: 1px solid var(--red);
  border-radius: 6px;
  padding: 10px 18px;
  color: var(--red);
  font-size: 12px;
  z-index: 300;
  display: none;
  font-family: var(--font-mono);
}
.error-toast.show { display: block; }

/* ── Scrollbar ───────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-hi); border-radius: 2px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ── Narrow windows: stack the sidebar above the views ───────────── */
@media (max-width: 860px) {
  html, body { overflow: auto; }
  .layout { flex-direction: column; height: auto; }
  .sidebar { width: auto; min-width: 0; border-right: none; border-bottom: 1px solid var(--border); overflow: visible; }
  .main { height: 100vh; }
  .view-bar { gap: 12px; padding: 0 16px; }
  .sweep-plots { flex-direction: column; }
  .sweep-plots > .viz { flex: 0 0 340px; }
  .sweep-plots > .viz + .viz { border-left: none; border-top: 1px solid var(--border); }
  .sweep-readout { margin-left: 0; }
}

@media (max-width: 1080px) {
  .bloch-view { flex: 0 0 auto; }
  .bloch-top { flex: 0 0 auto; flex-direction: column; min-height: 0; }
  #bloch-plot { flex: 0 0 420px; }
  .bloch-panel { flex: 0 0 auto; border-left: none; border-top: 1px solid var(--border); overflow: visible; }
  .dpad { max-width: 260px; margin: 0 auto; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation-duration: 0.01ms !important; }
}
