/* glasses-agent HUD stylesheet (spec section 8.1).
 *
 * Optical contract for the Meta Ray-Ban Display waveguide:
 *   - the only opaque background anywhere is #000000 (black is transparent on
 *     the waveguide); everything else is outlined, never filled;
 *   - a 24 px safe margin on all four sides, applied once on .canvas;
 *   - no font below 22 px (--fs-small);
 *   - the only motion is a 200 ms opacity crossfade when the channel changes.
 * Shared by index.html (glasses), remote.html (phone) and pair.html.
 */

:root {
  --bg: #000000;            /* mandatory, never overridden */
  --safe-margin: 24px;      /* mandatory waveguide edge margin */
  --fg: #FFFFFF;
  --fg-dim: #9AA0A6;
  --line: #333333;
  --up: #3DDC84;
  --down: #FF5252;
  --warn: #FFC107;
  --accent: #4FC3F7;
  --font: -apple-system, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  --fs-body: 28px; --fs-small: 22px; --fs-title: 36px; --fs-hero: 44px;
}
html, body { margin: 0; height: 100%; background: #000000; color: var(--fg); font-family: var(--font); }
.canvas { box-sizing: border-box; width: 100vw; height: 100vh; padding: var(--safe-margin); display: grid; grid-template-rows: auto 1fr auto; }

/* ---------------------------------------------------------------------------
 * Base
 * ------------------------------------------------------------------------- */

html { box-sizing: border-box; color-scheme: dark; }
*, *::before, *::after { box-sizing: inherit; }
body { font-size: var(--fs-body); line-height: 1.25; -webkit-font-smoothing: antialiased; overflow: hidden; }
[hidden] { display: none !important; }
h1, h2, p { margin: 0; font-weight: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.num { font-variant-numeric: tabular-nums; }
.dim { color: var(--fg-dim); }
.up { color: var(--up); }
.down { color: var(--down); }
.warn { color: var(--warn); }
.accent { color: var(--accent); }
.flat { color: var(--fg-dim); }
.noscript { padding: var(--fs-body); color: var(--warn); font-size: var(--fs-body); }

/* ---------------------------------------------------------------------------
 * Header: channel name, connection dot, agent chips, clock
 * ------------------------------------------------------------------------- */

.hud-head {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: baseline;
  column-gap: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.channel-name { font-size: var(--fs-title); font-weight: 700; letter-spacing: 0.02em; }
.status { display: flex; align-items: baseline; gap: 16px; min-width: 0; overflow: hidden; }
.conn { display: inline-flex; align-items: baseline; gap: 8px; font-size: var(--fs-small); color: var(--fg-dim); }
.conn-dot { font-size: var(--fs-small); color: var(--fg-dim); }
.conn.open .conn-dot { color: var(--up); }
.conn.reconnecting .conn-dot { color: var(--warn); }
.conn.offline .conn-dot { color: var(--down); }
.chips { display: inline-flex; gap: 8px; }
.chip {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 0;
  padding: 0 10px;
  font-size: var(--fs-small);
  line-height: 1.5;
  color: var(--fg-dim);
  white-space: nowrap;
}
.chip.ok { color: var(--up); }
.chip.busy { color: var(--warn); }
.chip.bad { color: var(--down); }
.clock { font-size: var(--fs-body); font-variant-numeric: tabular-nums; color: var(--fg); }

/* ---------------------------------------------------------------------------
 * Body: one section per channel, stacked, crossfaded on switch
 * ------------------------------------------------------------------------- */

.hud-body { position: relative; min-height: 0; overflow: hidden; }
section[data-channel] {
  position: absolute;
  inset: 0;
  padding-top: 12px;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  overflow: hidden;
  transition: opacity 200ms ease-out, visibility 0s linear 200ms;
}
section[data-channel].active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transition: opacity 200ms ease-out, visibility 0s linear 0s;
}
@media (prefers-reduced-motion: reduce) {
  section[data-channel], section[data-channel].active { transition: none; }
}
section.is-stale .price, section.is-stale .change { color: var(--fg-dim); }
.empty { color: var(--fg-dim); font-size: var(--fs-body); padding-top: 24px; }

/* Ticker: one quote per row, six rows per page */
.quote, .option {
  display: grid;
  grid-template-columns: minmax(5ch, auto) 1fr auto auto;
  column-gap: 20px;
  align-items: baseline;
  padding: 2px 0;
  font-variant-numeric: tabular-nums;
}
.quote .sym { font-size: 32px; font-weight: 700; }
.quote .price { font-size: 32px; text-align: right; }
.quote .change { font-size: var(--fs-body); text-align: right; min-width: 5.5ch; }
.quote .flag { font-size: var(--fs-small); text-align: right; min-width: 4ch; color: var(--fg-dim); }
.quote .flag.set { color: var(--warn); }
.option { grid-template-columns: minmax(0, 1fr) auto auto auto; font-size: var(--fs-small); }
.option .contract { font-size: var(--fs-body); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Scores: four games per page, two lines each */
.game { padding: 3px 0; }
.game .line1 {
  display: grid;
  grid-template-columns: 4.5ch auto auto auto 1fr;
  column-gap: 12px;
  align-items: baseline;
  font-variant-numeric: tabular-nums;
}
.game .league { font-size: var(--fs-small); color: var(--fg-dim); text-transform: uppercase; }
.game .team { font-weight: 700; }
.game .lead { color: var(--fg); }
.game .trail { color: var(--fg-dim); }
.game .at { color: var(--fg-dim); font-size: var(--fs-small); }
.game .clock-cell { text-align: right; font-size: var(--fs-small); color: var(--fg-dim); white-space: nowrap; }
.game .line2 { padding-left: calc(4.5ch + 12px); font-size: var(--fs-small); color: var(--fg-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.matchup { padding: 6px 0; }
.matchup .mhead { font-size: var(--fs-small); color: var(--fg-dim); text-transform: uppercase; letter-spacing: 0.04em; }
.matchup .mrow {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  column-gap: 16px;
  align-items: baseline;
  font-variant-numeric: tabular-nums;
}
.matchup .mrow .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.matchup .mrow.opp { color: var(--fg-dim); }
.matchup .mrow .left { font-size: var(--fs-small); color: var(--fg-dim); }

/* Agent: newest six events, two lines each */
.event { padding: 3px 0; }
.event .meta {
  display: grid;
  grid-template-columns: 6ch 3ch minmax(0, 1fr);
  column-gap: 12px;
  font-size: var(--fs-small);
  color: var(--fg-dim);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.event .meta .src { font-weight: 700; }
.event .meta .ctx { overflow: hidden; text-overflow: ellipsis; }
.event .text { display: grid; grid-template-columns: 1.4ch minmax(0, 1fr); column-gap: 10px; white-space: nowrap; }
.event .text .glyph { color: var(--fg-dim); }
.event .text .body { overflow: hidden; text-overflow: ellipsis; }
.event.error .text .glyph, .event.error .text .body { color: var(--down); }

/* Pinned: one card per page */
.card .title { font-size: var(--fs-title); font-weight: 700; line-height: 1.2; padding-bottom: 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .body {
  font-size: var(--fs-body);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 8;
  overflow: hidden;
}
.card .kv { display: grid; grid-template-columns: auto 1fr; column-gap: 16px; row-gap: 2px; font-size: var(--fs-body); }
.card .kv .k { color: var(--fg-dim); white-space: nowrap; }
.card .kv .v { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
img.card-image { max-width: 552px; max-height: 400px; object-fit: contain; background: #000000; display: block; width: 100%; height: auto; }
.card .unavailable { color: var(--fg-dim); font-size: var(--fs-body); padding-top: 24px; }

/* Alert overlay: 6 s on top of whatever channel is active */
.alert-overlay {
  position: absolute;
  inset: 0;
  background: #000000;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-content: center;
  row-gap: 12px;
  padding-top: 12px;
}
.alert-title { font-size: var(--fs-title); font-weight: 700; color: var(--warn); line-height: 1.2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.alert-body { font-size: var(--fs-body); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Compact mode: channel name, clock, dot, and one line (spec section 2.2) */
.compact-line { font-size: var(--fs-title); padding-top: 24px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.canvas.compact section[data-channel], .canvas.compact .hud-foot, .canvas.compact .chips, .canvas.compact .conn-text { display: none !important; }
.canvas.compact .compact-line { display: block !important; }

/* ---------------------------------------------------------------------------
 * Footer: channel dots, page, stale badge
 * ------------------------------------------------------------------------- */

.hud-foot {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: baseline;
  column-gap: 16px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  font-size: var(--fs-small);
  color: var(--fg-dim);
  white-space: nowrap;
}
.hud-foot .dots { letter-spacing: 0.3em; }
.hud-foot .page { text-align: center; font-variant-numeric: tabular-nums; }
.hud-foot .stale { color: var(--warn); text-align: right; font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------------------
 * Pairing keypad (pair.html): 96 x 72 px keys, 44 px digit boxes
 * ------------------------------------------------------------------------- */

.pair-title { font-size: var(--fs-hero); font-weight: 700; }
.pair-status { font-size: var(--fs-body); color: var(--fg-dim); }
.pair-error { font-size: var(--fs-body); color: var(--warn); min-height: 1.3em; }
.digits { display: flex; gap: 8px; justify-content: center; padding: 12px 0; }
.digit-box {
  width: 44px;
  height: 44px;
  line-height: 44px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  text-align: center;
  font-size: var(--fs-title);
  font-variant-numeric: tabular-nums;
}
.digit-box.filled { border-color: var(--fg); }
.keypad { display: grid; grid-template-columns: repeat(3, 96px); gap: 8px; justify-content: center; }
.key {
  width: 96px;
  height: 72px;
  margin: 0;
  padding: 0;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 0;
  color: var(--fg);
  font-family: inherit;
  font-size: var(--fs-title);
  line-height: 1;
  cursor: pointer;
}
.key:hover, .key:focus-visible, .key.focused { border-color: var(--accent); outline: none; }
.key:active { transform: scale(0.98); }
.key:disabled { color: var(--fg-dim); border-color: var(--line); cursor: default; }
.otp-input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

/* ---------------------------------------------------------------------------
 * Phone remote (remote.html): scrolling page, safe-area insets added
 * ------------------------------------------------------------------------- */

.canvas.remote {
  height: auto;
  min-height: 100vh;
  min-height: 100dvh;
  padding-top: calc(var(--safe-margin) + env(safe-area-inset-top, 0px));
  padding-right: calc(var(--safe-margin) + env(safe-area-inset-right, 0px));
  padding-bottom: calc(var(--safe-margin) + env(safe-area-inset-bottom, 0px));
  padding-left: calc(var(--safe-margin) + env(safe-area-inset-left, 0px));
  grid-template-rows: auto 1fr;
  row-gap: 24px;
}
body.remote { overflow: auto; }
.remote-section { display: grid; row-gap: 12px; padding-top: 16px; border-top: 1px solid var(--line); }
.remote-section h2 { font-size: var(--fs-title); font-weight: 700; }
.channel-bar { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.btn {
  min-height: 56px;
  padding: 0 16px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 0;
  color: var(--fg);
  font-family: inherit;
  font-size: var(--fs-body);
  line-height: 1.2;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover, .btn:focus-visible { border-color: var(--accent); outline: none; }
.btn:active { transform: scale(0.98); }
.btn.active { border-color: var(--accent); color: var(--accent); }
.btn.danger { color: var(--down); }
.btn:disabled { color: var(--fg-dim); cursor: default; }
.field { display: grid; row-gap: 4px; }
.field label { font-size: var(--fs-small); color: var(--fg-dim); }
input[type="text"], input[type="url"], input[type="number"], select, textarea {
  width: 100%;
  min-height: 56px;
  padding: 8px 12px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 0;
  color: var(--fg);
  font-family: inherit;
  font-size: var(--fs-body);
}
textarea { min-height: 112px; resize: vertical; }
input::placeholder, textarea::placeholder { color: var(--fg-dim); opacity: 1; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; }
input[type="checkbox"], input[type="radio"] { width: 28px; height: 28px; margin: 0 12px 0 0; accent-color: var(--accent); }
input[type="range"] { width: 100%; accent-color: var(--accent); }
.check { display: flex; align-items: center; font-size: var(--fs-body); }
.chip-list { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-list .chip { font-size: var(--fs-body); color: var(--fg); padding: 4px 12px; }
.chip-list .chip .remove { color: var(--fg-dim); padding-left: 12px; }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.list { display: grid; row-gap: 8px; }
.list .item { display: grid; grid-template-columns: 1fr auto; column-gap: 12px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.list .item .label { font-size: var(--fs-body); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .item .sub { font-size: var(--fs-small); color: var(--fg-dim); }
.now-line { font-size: var(--fs-title); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

@media (max-width: 599px) {
  .quote .sym, .quote .price { font-size: var(--fs-body); }
  .channel-bar { grid-template-columns: repeat(2, 1fr); }
}
