/* Pintig styles. Tokens follow DESIGN.md section 2; this is the only place colours are defined. */

:root {
  color-scheme: light;

  /* Base (room) */
  --bg: #eef3f7;
  --surface: #ffffff;
  --surface-2: #dde6ee;
  --ink: #0b1a2a;
  --muted: #46596e;
  --faint: #8a9bad;
  --line: #c4d2df;
  --focus: #006d7a;

  /* Accent */
  --accent: #0a8fa0;
  --accent-ink: #006d7a;
  --on-accent: #ffffff;

  /* Screen (same in both themes) */
  --screen-bg: #02060b;
  --hero-bg: #0a1726;
  --hero-fg: #e6f2fc;
  --hero-muted: #95b2c9;
  --hero-accent: #5fe0ee;
  --hero-line: #23415e;

  /* Meaning colours on the screen (same in both themes) */
  --q0: #95b2c9;
  --q1: #ffd23f;
  --q2: #ff8a3d;
  --q3: #ff5468;
  --volc: #ff6a3d;
  --plate: #4cd3e3;
  --fault: #f59fd0;

  /* Meaning colours in the room (light values) */
  --q0-room: #46596e;
  --q1-room: #8a6d00;
  --q2-room: #c24f00;
  --q3-room: #c8102e;
  --volc-room: #b5300b;
  --plate-room: #0a8fa0;
  --fault-room: #a3306f;

  /* Type and shape */
  --sans: "Saira", sans-serif;
  --mono: "Azeret Mono", monospace;
  --r: 4px;
  --r-switch: 3px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #060c14;
    --surface: #0c1724;
    --surface-2: #142538;
    --ink: #e2ecf6;
    --muted: #8ea4bb;
    --faint: #4d6580;
    --line: #1d3249;
    --focus: #5fdcea;
    --accent: #4cd3e3;
    --accent-ink: #5fdcea;
    --on-accent: #04121a;
    --q0-room: #95b2c9;
    --q1-room: #ffd23f;
    --q2-room: #ff8a3d;
    --q3-room: #ff5468;
    --volc-room: #ff6a3d;
    --plate-room: #4cd3e3;
    --fault-room: #f59fd0;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #060c14;
  --surface: #0c1724;
  --surface-2: #142538;
  --ink: #e2ecf6;
  --muted: #8ea4bb;
  --faint: #4d6580;
  --line: #1d3249;
  --focus: #5fdcea;
  --accent: #4cd3e3;
  --accent-ink: #5fdcea;
  --on-accent: #04121a;
  --q0-room: #95b2c9;
  --q1-room: #ffd23f;
  --q2-room: #ff8a3d;
  --q3-room: #ff5468;
  --volc-room: #ff6a3d;
  --plate-room: #4cd3e3;
  --fault-room: #f59fd0;
}

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

[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--sans);
  font-stretch: 87.5%;
  -webkit-text-size-adjust: 100%;
}

h2, h3, p, ul, dl, dd { margin: 0; }
button { font: inherit; color: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.icon { width: 20px; height: 20px; flex: none; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* Focus: --focus in the room, --hero-accent on the screen. */
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
#topbar :focus-visible, #sheet :focus-visible { outline-color: var(--hero-accent); }

/* ---------- The screen: top bar, stage, panels (dark in both themes) ---------- */

#stage { position: relative; background: var(--screen-bg); color: var(--hero-fg); }
#globe { background: var(--screen-bg); isolation: isolate; } /* keeps globe labels under the panels */

#topbar {
  display: flex;
  align-items: center;
  gap: 12px 16px;
  padding: 0 16px;
  background: var(--screen-bg);
  color: var(--hero-fg);
  border-bottom: 1px solid var(--hero-line);
}

.brand { display: flex; align-items: center; gap: 10px; }
.pulse {
  width: 8px; height: 8px; flex: none;
  border-radius: 50%;
  background: var(--hero-accent);
  animation: breathe 2.4s ease-in-out infinite;
}
@keyframes breathe { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
.wordmark { font: 600 18px/1 var(--sans); letter-spacing: .22em; color: var(--hero-fg); }

.seg { display: flex; border: 1px solid var(--hero-line); border-radius: var(--r); }
.seg button {
  position: relative;
  min-height: 44px;
  padding: 0 16px;
  border: 0;
  background: transparent;
  color: var(--hero-fg);
  font-weight: 600;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}
.seg button:first-child { border-radius: calc(var(--r) - 1px) 0 0 calc(var(--r) - 1px); }
.seg button:last-child { border-radius: 0 calc(var(--r) - 1px) calc(var(--r) - 1px) 0; }
.seg button + button { border-left: 1px solid var(--hero-line); }
.seg button[aria-pressed="true"] { background: var(--hero-accent); color: var(--screen-bg); }
.seg button:focus-visible { z-index: 1; }

.clocks {
  margin-left: auto;
  font: 400 13px/1.2 var(--mono);
  font-variant-numeric: tabular-nums;
  color: var(--hero-muted);
  white-space: nowrap;
}

.bar-actions { display: flex; gap: 4px; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 44px;
  min-height: 44px;
  padding: 0 11px;
  border: 1px solid var(--hero-line);
  border-radius: var(--r);
  background: transparent;
  color: var(--hero-fg);
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
}
.icon-btn:hover { background: var(--hero-line); }
.about-text { display: none; }

/* Glass panels */
.panel {
  background: color-mix(in srgb, var(--hero-bg) 92%, transparent);
  border: 1px solid var(--hero-line);
  border-radius: var(--r);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  color: var(--hero-fg);
}
.panel-head { font-size: inherit; }
.panel-title {
  font: 600 13px/1.2 var(--sans);
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--hero-muted);
}
#events-panel .panel-head { padding: 12px 12px 8px; }

.eyebrow {
  font: 500 12px/1.3 var(--mono);
  /* design-lint: ok mono readouts are instrument output, see DESIGN.md */
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--hero-muted);
}

/* Layers */
.panel-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 0;
  background: transparent;
  color: var(--hero-muted);
  cursor: pointer;
}
.panel-toggle .chev { transition: transform .15s; }
#layers-panel[data-open="false"] .chev { transform: rotate(-90deg); }

.layer-list { display: flex; flex-direction: column; }
.layer {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 0;
  border-top: 1px solid var(--hero-line);
  background: transparent;
  color: var(--hero-fg);
  text-align: left;
  cursor: pointer;
}
.layer:hover { background: color-mix(in srgb, var(--hero-line) 50%, transparent); }
.layer:focus-visible, .ev:focus-visible, .panel-toggle:focus-visible { outline-offset: -2px; }
.layer-name {
  flex: 1;
  font: 600 13px/1.2 var(--sans);
  text-transform: uppercase;
  letter-spacing: .08em;
}

.glyph { flex: none; display: grid; place-items: center; width: 16px; height: 16px; }
.glyph::before { content: ""; display: block; }
.g-plates::before { width: 16px; height: 2px; background: var(--plate); }
.g-faults::before { width: 16px; height: 2px; background: var(--fault); }
.g-quakes::before { width: 10px; height: 10px; border-radius: 50%; background: var(--q2); }
.g-volcanoes::before { width: 10px; height: 10px; background: var(--volc); clip-path: polygon(50% 0, 100% 100%, 0 100%); }
.g-trenches::before { width: 16px; height: 0; border-top: 2px dashed var(--hero-fg); }

.track {
  position: relative;
  flex: none;
  width: 36px;
  height: 20px;
  border-radius: var(--r-switch);
  background: var(--hero-line);
}
.track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 14px;
  height: 14px;
  border-radius: var(--r-switch);
  background: var(--hero-muted);
  transition: transform .15s;
}
.layer[aria-checked="true"] .track { background: var(--hero-accent); }
.layer[aria-checked="true"] .track::after { background: var(--screen-bg); transform: translateX(16px); }

/* Counts (the only panel with corner brackets) */
.counts { position: relative; padding: 18px 16px 14px; }
.counts::before, .counts::after {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  border: 2px solid var(--hero-accent);
  pointer-events: none;
}
.counts::before { top: 6px; left: 6px; border-right: 0; border-bottom: 0; }
.counts::after { bottom: 6px; right: 6px; border-left: 0; border-top: 0; }

.big { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 10px; margin-top: 8px; }
.big b {
  font: 600 clamp(44px, 9vw, 64px)/0.95 var(--mono);
  font-variant-numeric: tabular-nums;
  color: var(--hero-accent);
}
.big span { font-size: 15px; color: var(--hero-muted); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }
.stats div { min-width: 0; padding-top: 8px; border-top: 1px solid var(--hero-line); }
.stats b {
  display: block;
  font: 600 22px/1 var(--mono);
  font-variant-numeric: tabular-nums;
  color: var(--hero-fg);
}
.stats small { display: block; margin-top: 4px; font-size: 12px; line-height: 1.3; color: var(--hero-muted); }

.status {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  margin-top: 12px;
  font: 400 12px/1.4 var(--mono);
  font-variant-numeric: tabular-nums;
  color: var(--hero-muted);
}
.status .warn { width: 16px; height: 16px; color: var(--q2); }

/* Events */
.ev-list { list-style: none; padding: 0; }
.ev {
  display: flex;
  align-items: stretch;
  gap: 10px;
  width: 100%;
  min-height: 56px;
  padding: 0 12px 0 0;
  border: 0;
  border-top: 1px solid var(--hero-line);
  background: transparent;
  color: var(--hero-fg);
  text-align: left;
  cursor: pointer;
}
.ev[data-q="0"] { --qc: var(--q0); }
.ev[data-q="1"] { --qc: var(--q1); }
.ev[data-q="2"] { --qc: var(--q2); }
.ev[data-q="3"] { --qc: var(--q3); }
.ev:hover { background: color-mix(in srgb, var(--hero-line) 50%, transparent); }
.ev[aria-current="true"] { background: var(--hero-line); }
.ev-bar { flex: none; width: 3px; background: var(--qc); }
.ev[aria-current="true"] .ev-bar { background: var(--hero-accent); }
.ev-mag {
  flex: none;
  align-self: center;
  width: 44px;
  text-align: center;
  font: 600 18px/1 var(--mono);
  font-variant-numeric: tabular-nums;
  color: var(--qc);
}
.ev-text { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; gap: 2px; padding: 6px 0; }
.ev-place { font-size: 15px; line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ev-sub { font: 400 12px/1.3 var(--mono); font-variant-numeric: tabular-nums; color: var(--hero-muted); }
.ev-empty { padding: 12px; border-top: 1px solid var(--hero-line); color: var(--hero-muted); }

/* Phone tabs */
.sheet-tabs { display: flex; border-bottom: 1px solid var(--hero-line); }
.sheet-tabs [role="tab"] {
  flex: 1;
  min-height: 44px;
  margin-bottom: -1px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--hero-muted);
  font: 600 13px/1 var(--sans);
  text-transform: uppercase;
  letter-spacing: .08em;
  cursor: pointer;
}
.sheet-tabs [aria-selected="true"] { color: var(--hero-fg); border-bottom-color: var(--hero-accent); }
.sheet-tabs [role="tab"]:focus-visible { outline-offset: -2px; }

/* Globe tooltips and labels (emitted by globe.js) */
:is(#globe, body) .float-tooltip-kap {
  padding: 6px 8px;
  background: color-mix(in srgb, var(--hero-bg) 92%, transparent);
  border: 1px solid var(--hero-line);
  border-radius: var(--r);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  color: var(--hero-fg);
  font: 400 13px/1.35 var(--sans);
}
.float-tooltip-kap .tip-title { font-weight: 600; }
.float-tooltip-kap .tip-sub { font: 400 12px/1.3 var(--mono); font-variant-numeric: tabular-nums; color: var(--hero-muted); }
.trench-label {
  font: 400 11px/1 var(--mono);
  /* design-lint: ok mono readouts are instrument output, see DESIGN.md */
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--hero-muted);
  /* A glass backing like the panels, so the label holds 4.5:1 over bright land too. */
  padding: 2px 4px;
  background: color-mix(in srgb, var(--hero-bg) 92%, transparent);
  border-radius: var(--r);
  pointer-events: none;
  white-space: nowrap;
}

/* ---------- The room: detail sheet, dialog, dashboard (follow the theme) ---------- */

.room :focus-visible, #detail :focus-visible { outline-color: var(--focus); }
.room .icon-btn { border-color: var(--line); color: var(--ink); background: var(--surface); }
.room .icon-btn:hover { background: var(--surface-2); }

#detail {
  z-index: 4;
  padding: 16px;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--r);
}
.detail-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
#detail .eyebrow { color: var(--muted); }
.detail-title { margin-top: 4px; font: 600 20px/1.25 var(--sans); color: var(--ink); }

#detail dl { display: grid; gap: 8px; margin-bottom: 16px; }
#detail dl div { display: grid; grid-template-columns: 88px 1fr; gap: 12px; }
#detail dd .num { font-size: 14px; }
#detail dt { color: var(--muted); }
#detail dd { min-width: 0; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface);
  color: var(--ink);
  font-weight: 600;
  line-height: 1;
  text-decoration: none;
}
.btn.primary { background: var(--accent-ink); border-color: var(--accent-ink); color: var(--on-accent); }

#about {
  width: calc(100% - 32px);
  max-width: 560px;
  padding: 16px 20px 20px;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--r);
}
#about::backdrop { background: color-mix(in srgb, var(--screen-bg) 70%, transparent); }
.about-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 4px; }
#about h2 { font: 600 22px/1.2 var(--sans); }
.src { padding: 8px 0 12px; border-top: 1px solid var(--line); }
.src h3 { font: 600 15px/1.3 var(--sans); }
.src a {
  display: inline-flex;
  align-items: center;
  position: relative;
  z-index: 1;
  min-height: 44px;
  color: var(--accent-ink);
  text-decoration: underline;
  text-underline-offset: 3px;
}
/* Invisible 2 px margin above and below, so sub-pixel layout never trims the hit area under 44 px. */
.src a::after { content: ""; position: absolute; inset: -2px 0; }
.src-meta { margin-top: 4px; font-size: 13px; color: var(--muted); }
.src-asof { margin-top: 2px; font: 400 12px/1.4 var(--mono); font-variant-numeric: tabular-nums; color: var(--muted); }
.about-note { padding-top: 12px; border-top: 1px solid var(--line); }

#dashboard {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 16px 48px;
  color: var(--ink);
}

/* ---------- Phone: under 760 px ---------- */

@media (max-width: 759.98px) {
  #topbar {
    display: grid;
    grid-template-columns: auto 1fr auto;
    grid-template-areas: "brand clocks actions" "seg seg seg";
    gap: 8px 12px;
    padding: 6px 16px 12px;
  }
  .brand { grid-area: brand; }
  .clocks { grid-area: clocks; justify-self: end; }
  .bar-actions { grid-area: actions; }
  .seg { grid-area: seg; }
  .seg button { flex: 1; }

  #globe { position: relative; height: 58vh; }

  #sheet { display: flex; flex-direction: column; gap: 12px; padding: 0 16px 16px; }
  #sheet[data-tab="live"] #layers-panel,
  #sheet[data-tab="layers"] #counts-panel,
  #sheet[data-tab="layers"] #events-panel { display: none; }
  #layers-panel .panel-head { display: none; }
  #layers-panel .layer:first-child { border-top: 0; }

  #detail {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10;
    max-height: 70vh;
    overflow: auto;
    border-width: 1px 0 0;
    border-radius: var(--r) var(--r) 0 0;
  }
}

/* ---------- 760 px and up: floating panels on a full-viewport globe ---------- */

@media (min-width: 760px) {
  #topbar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 3;
    height: 56px;
    background: color-mix(in srgb, var(--hero-bg) 92%, transparent);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
  }
  #stage { height: 100svh; min-height: 560px; overflow: hidden; overflow: clip; }
  #globe { position: absolute; inset: 0; }

  #sheet {
    position: absolute;
    top: 72px;
    left: 16px;
    right: 16px;
    bottom: 16px;
    z-index: 2;
    display: grid;
    grid-template-columns: 260px 1fr 340px;
    grid-template-rows: auto minmax(0, 1fr);
    gap: 12px 16px;
    pointer-events: none;
  }
  #sheet > * { pointer-events: auto; }
  .sheet-tabs { display: none; }

  #layers-panel { grid-column: 1; grid-row: 1 / span 2; align-self: start; max-height: 100%; overflow: auto; }
  #layers-panel[data-open="false"] .layer-list { display: none; }
  #counts-panel { grid-column: 3; grid-row: 1; }
  #events-panel {
    grid-column: 3;
    grid-row: 2;
    align-self: start;
    display: flex;
    flex-direction: column;
    min-height: 0;
    max-height: 100%;
  }
  .ev-list { flex: 1 1 auto; min-height: 0; overflow: auto; }

  #detail {
    position: absolute;
    left: 16px;
    bottom: 16px;
    width: 360px;
    max-height: calc(100% - 88px);
    overflow: auto;
  }
}

@media (max-width: 1099.98px) {
  .clock-utc { display: none; }
}

@media (min-width: 1100px) {
  .about-text { display: inline; }
  .about-btn { padding: 0 14px 0 11px; }
}

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

/* ---------- Dashboard (the room: follows the theme) ---------- */

#dashboard { background: var(--bg); }
.dash-head { margin-bottom: 16px; }
.dash-head h2 { font: 600 22px/1.2 var(--sans); color: var(--ink); }
.dash-sub { margin-top: 4px; font-size: 15px; color: var(--muted); }
.dash-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
.ch-card {
  min-width: 0;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
}
.ch-title { font: 600 15px/1.3 var(--sans); color: var(--ink); }
.ch-take { margin: 4px 0 12px; font-size: 15px; line-height: 1.4; color: var(--ink); }
.ch-plot { width: 100%; }
.ch-svg { display: block; overflow: visible; }
.ch-src { margin-top: 8px; font-size: 13px; color: var(--muted); }
.ch-axis { font: 400 12px var(--mono); font-variant-numeric: tabular-nums; fill: var(--muted); }
.ch-value { fill: var(--ink); }
.ch-cat { font: 400 13px var(--sans); fill: var(--muted); }
.ch-grid { stroke: var(--line); stroke-width: 1; shape-rendering: crispEdges; }
.ch-ref { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 4 3; }
.ch-hit { fill: transparent; }
.ch-dot { fill-opacity: .8; }
.ch-mark:hover .ch-hit { fill: var(--surface-2); fill-opacity: .6; }
.ch-mark:hover circle.ch-hit { fill-opacity: 0; }
.ch-mark:hover .ch-dot { fill-opacity: 1; }

@media (min-width: 760px) {
  .dash-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
