/* Header, brand lockup and status-pill rules live in
   ../shared/chrome.css — do not redefine them here. */
/* Design tokens ---------------------------------------------------------
   Field Notes: kraft-paper chassis, ink text, one rust accent thread
   running through every interactive/live element — matches the homepage
   and every other Thermalsock Labs app. The scope canvas itself is
   separately themeable (see js/themes.js — Field Notes is the default
   canvas theme too, with CRT/Modern Lab/Aurora/Woven still selectable),
   but the chrome around it (topbar, panels, buttons) always stays in
   this one house style regardless of which canvas theme is active.
   Type: Space Grotesk (display) + system sans (chrome labels) + IBM-Plex-style
   mono for dense numeric alignment, matching the homepage's type system.
   Corner radii follow the shared scale: 10px windows/panels, 6px
   controls/buttons, fully-rounded pills for status/nav badges.
------------------------------------------------------------------------- */

:root {
  --chassis: #0B0D12;
  --panel: #0F1118;
  --panel-raised: #161A22;
  --hairline: rgba(138, 160, 184, 0.16);
  --hairline-strong: rgba(138, 160, 184, 0.30);
  --text: #E7F4FF;
  --text-dim: #8AA0B8;
  --mono: 'JetBrains Mono', ui-monospace, 'SF Mono', 'Cascadia Code', Consolas, monospace;
  --sans: 'Space Grotesk', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --serif-display: 'Space Grotesk', -apple-system, system-ui, sans-serif;

  --accent: #00C8FF;
  --accent-dim: rgba(0, 200, 255, 0.32);
  --accent-fg: #04222C;
  --danger: #FF5A6E;

  --amber: #FFB454;
  --violet: #A98CFF;
  --teal: #3FD9C4;
  --pink: #FF7BB0;
  --blue: #6FA8FF;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--chassis);
  color: var(--text);
  font-family: var(--sans);
}

/* --- Permission gate ("boot screen") ------------------------------------ */

.gate {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(ellipse at 50% 30%, rgba(0, 200, 255, 0.08), transparent 60%),
    var(--chassis);
}

/* [hidden] must win over the .gate/.app display:flex rules above and below —
   otherwise the browser's built-in "hidden means display:none" behavior gets
   silently overridden by our own class, and toggling .hidden in JS does
   nothing visible. This exact bug has already regressed once (lost during a
   full stylesheet rewrite) — do not remove this rule when restyling. */
.gate[hidden],
.app[hidden] {
  display: none;
}

.gate-panel {
  width: 100%;
  max-width: 440px;
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: 10px;
  padding: 32px;
  box-shadow: 0 20px 50px rgba(138, 160, 184, 0.18);
}

.gate-panel h1 {
  font-family: var(--serif-display);
  font-size: 24px;
  font-weight: 600;
  margin: 0 0 2px;
  letter-spacing: 0.005em;
}

.gate-sub {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin: 0 0 20px;
}

.gate-copy {
  font-size: 14px;
  line-height: 1.55;
  color: var(--text-dim);
  margin: 0 0 24px;
}

.field {
  display: block;
  margin-bottom: 20px;
}

.field span {
  display: block;
  font-family: var(--sans);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.field select {
  width: 100%;
}

select, input[type="range"], button {
  font-family: var(--sans);
}

select {
  width: 100%;
  background: var(--panel-raised);
  color: var(--text);
  border: 1px solid var(--hairline-strong);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13px;
}

.btn-primary, .btn-secondary {
  width: 100%;
  padding: 11px 16px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.03em;
  cursor: pointer;
  border: 1px solid transparent;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-fg);
  border: none;
}
.btn-primary:hover { filter: brightness(1.08); }

.btn-secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--hairline-strong);
  margin-top: 10px;
}
.btn-secondary:hover { border-color: var(--accent-dim); }

.gate-error {
  color: var(--danger);
  font-size: 13px;
  margin-top: 14px;
  line-height: 1.4;
}

/* --- Main app shell ------------------------------------------------------ */

.app {
  height: 100%;
  display: flex;
  flex-direction: column;
}


.brand {
  font-family: var(--sans);
  font-size: 13px;
  letter-spacing: 0.03em;
}
.brand span { color: var(--text-dim); }
.brand-home { color: inherit; text-decoration: none; }
.brand-home:hover { color: var(--accent, #e8a33d); text-decoration: underline; }


.page-nav {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  background: rgba(138, 160, 184, 0.04);
  border: 1px solid var(--hairline);
  border-radius: 3px;
  padding: 3px;
}
.page-nav-link {
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-decoration: none;
  color: var(--text-dim);
  padding: 6px 14px;
  border-radius: 3px;
}
.page-nav-link:hover { color: var(--text); }
.page-nav-link.active {
  color: var(--accent-fg);
  background: var(--accent);
  font-weight: 600;
}


.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 5px 11px;
  border-radius: 3px;
  border: 1px solid var(--hairline-strong);
  background: rgba(138, 160, 184, 0.04);
  color: var(--text-dim);
}

.pill.mode {
  color: var(--violet);
  border-color: rgba(106, 90, 156, 0.35);
  background: rgba(106, 90, 156, 0.08);
}

.pill.live { color: var(--text-dim); }

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
}
.status-dot.live {
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
}

.stage {
  flex: 1;
  display: flex;
  gap: 18px;
  padding: 18px 22px 26px 22px;
  min-height: 0;
}

.stage-left {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
}

/* --- Scope display --------------------------------------------------- */

.scope-wrap {
  flex: 1;
  min-width: 0;
  min-height: 0;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--hairline);
  box-shadow: inset 0 0 60px rgba(0, 0, 0, 0.6), inset 0 0 2px rgba(0, 0, 0, 0.9), 0 0 0 1px rgba(138, 160, 184, 0.08);
  position: relative;
  background: #000;
}

#scopeCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* --- Bottom row: secondary/read-out cards, using the space below the scope
   so the right sidebar never needs to scroll ---------------------------- */

.bottom-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  flex-shrink: 0;
}
.bottom-row .card { padding: 14px; }
.bottom-row .row { font-size: 12px; }
@media (max-width: 1200px) {
  .bottom-row { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 700px) {
  .bottom-row { grid-template-columns: 1fr; }
}

/* --- Right panel ------------------------------------------------------ */

.panel {
  width: 280px;
  flex-shrink: 0;
  max-height: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-self: flex-start;
  gap: 14px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: 10px;
  padding: 16px;
}

/* --- Stereo Analysis meters --------------------------------------------- */

.meter-row { margin-bottom: 14px; }
.meter-row:last-child { margin-bottom: 0; }
.meter-label-row {
  display: flex;
  justify-content: space-between;
  font-size: 11.5px;
  color: var(--text-dim);
  margin-bottom: 5px;
}
.meter-label-row span:last-child {
  font-family: var(--mono);
  color: var(--accent);
  font-size: 12px;
}
.meter-track {
  position: relative;
  height: 10px;
  border-radius: 5px;
  background: var(--panel-raised);
  border: 1px solid var(--hairline-strong);
  overflow: hidden;
}
.meter-center-tick {
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--hairline-strong);
  z-index: 2;
}
.meter-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 0;
  background: var(--accent);
  transition: width 0.05s linear, left 0.05s linear;
}
.meter-fill.width {
  left: 0;
  background: linear-gradient(90deg, var(--accent), var(--pink));
}
.meter-needle {
  position: absolute;
  top: -2px;
  bottom: -2px;
  width: 2px;
  background: var(--text);
  left: 50%;
  transition: left 0.05s linear;
}
.meter-scale {
  display: flex;
  justify-content: space-between;
  font-size: 9.5px;
  color: var(--text-dim);
  opacity: 0.75;
  margin-top: 3px;
  font-family: var(--mono);
}

.phase-dial {
  position: relative;
  width: 56px;
  height: 56px;
  margin: 4px auto 0;
  border-radius: 50%;
  border: 1px solid var(--hairline-strong);
  background: var(--panel-raised);
}
.phase-dial::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 4px;
  height: 4px;
  margin: -2px 0 0 -2px;
  border-radius: 50%;
  background: var(--hairline-strong);
}
.phase-dial-needle {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 2px;
  height: 24px;
  margin-left: -1px;
  transform-origin: 50% 0%;
  background: var(--accent);
  transition: transform 0.05s linear;
}

.panel-group h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  margin: 0 0 12px;
  font-weight: 600;
}

.chip {
  width: 18px;
  height: 18px;
  border-radius: 6px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.chip svg { width: 11px; height: 11px; }
.chip.amber { background: rgba(154, 106, 31, 0.15); color: var(--amber); }
.chip.violet { background: rgba(106, 90, 156, 0.15); color: var(--violet); }
.chip.teal { background: rgba(47, 122, 114, 0.15); color: var(--teal); }
.chip.pink { background: rgba(163, 74, 114, 0.15); color: var(--pink); }
.chip.blue { background: rgba(51, 71, 92, 0.15); color: var(--blue); }

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}
.row:last-child { margin-bottom: 0; }

.row label {
  font-size: 12px;
  color: var(--text);
}

.row select { width: auto; flex: 1; }
.row input[type="range"] { flex: 1; accent-color: var(--accent); }
.row input[type="checkbox"] { accent-color: var(--accent); }

.readout dl {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 10px;
}
.readout dt {
  font-size: 12px;
  color: var(--text-dim);
}
.readout dd {
  margin: 0;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--accent);
  text-align: right;
}

.status-value {
  font-family: var(--sans);
  font-size: 12px;
  color: var(--text-dim);
  letter-spacing: 0.04em;
}
.status-value.trig { color: var(--accent); }
.status-value.hold { color: #fbbf24; }
.status-value.armed { color: #fbbf24; }

/* --- Hero stat card ----------------------------------------------------- */

.hero-card {
  background: linear-gradient(160deg, var(--panel-raised), var(--panel));
  border: 1px solid rgba(0, 200, 255, 0.22);
  box-shadow: 0 0 0 1px rgba(0, 200, 255, 0.08), 0 8px 24px rgba(138, 160, 184, 0.14);
}

.hero-label {
  font-family: var(--sans);
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 6px;
}

.hero-value {
  font-family: var(--mono);
  font-size: 36px;
  font-weight: 600;
  color: var(--accent);
  line-height: 1.1;
  text-shadow: 0 0 1px rgba(0, 200, 255, 0.15);
  margin-bottom: 4px;
  word-break: break-word;
}
.hero-unit {
  font-size: 16px;
  color: var(--text-dim);
  text-shadow: none;
  margin-left: 4px;
}

.hero-sub {
  font-family: var(--sans);
  font-size: 12px;
  color: var(--text-dim);
  min-height: 15px;
}

@media (max-width: 800px) {
  .stage { flex-direction: column; }
  .panel { width: 100%; flex-direction: row; flex-wrap: wrap; }
  .card { flex: 1 1 220px; }
}

/* --- Support widget & legal bar ------------------------------------------ */

#supportWidget {
  position: fixed;
  left: 14px;
  bottom: 34px;
  z-index: 10;
}
#supportWidget img { display: block; }

#legalBar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 9;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 5px 12px;
  font-size: 10.5px;
  color: var(--text-dim);
  background: rgba(11, 13, 18, 0.9);
  border-top: 1px solid var(--hairline);
}
#legalBar a { color: var(--text-dim); text-decoration: none; }
#legalBar a:hover { color: var(--accent); }

/* Site-wide brand thread: header lockup uses the shared Thermalsock Labs
   display face (Space Grotesk), legal bar stays mono for that technical-footer
   feel — matches the homepage and every other app page. Scoped to just
   these connective-tissue elements -- the app's own interior chrome
   (buttons, panel labels, chips) keeps its established --sans/--mono
   system untouched. */
.brand-sub, #legalBar, #legalBar a {
  font-family: var(--mono);
}

/* --- Topbar mode selector, action pills, readout rows ---------------------
   Display mode used to live in a <select> in the right sidebar while its
   readout (#modePill) sat in the topbar — the control and its own readout
   in two different places. The control is now the readout. */

.topbar-mode {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.topbar-mode-label {
  font-family: var(--mono, var(--mono), monospace);
  font-size: 9.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.topbar-mode select {
  font-family: var(--mono, var(--mono), monospace);
  font-size: 11.5px;
  color: var(--text);
  background: rgba(138, 160, 184, 0.05);
  border: 1px solid var(--hairline);
  border-radius: 3px;
  padding: 5px 10px;
  cursor: pointer;
}
.topbar-mode select:hover { border-color: var(--accent); }

.toggle-pill {
  font-family: var(--mono, var(--mono), monospace);
  font-size: 10.5px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-dim);
  background: rgba(138, 160, 184, 0.05);
  border: 1px solid var(--hairline);
  border-radius: 3px;
  padding: 6px 12px;
  cursor: pointer;
  transition: color .2s, border-color .2s, background .2s;
}
.toggle-pill:hover { color: var(--text); border-color: var(--accent); }
/* Freeze is a mode, not a momentary action — it has to look latched. */
.toggle-pill[aria-pressed="true"] {
  color: var(--accent-fg, #FDF8EF);
  background: var(--accent);
  border-color: var(--accent);
}

/* Sliders had no numeric readout at all, so you couldn't dial in a known
   value. These rows pair each one with its number. */
.readout-row {
  justify-content: space-between;
}
.readout-name {
  font-family: var(--mono, var(--mono), monospace);
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
}

/* Readout-only cards are reference, not controls — they recede a step so the
   panels you actually operate read louder. */
.card.readout {
  background: transparent;
  box-shadow: none;
}

@media (max-width: 900px) {
  .topbar-mode-label { display: none; }
}
