:root {
  --bg-obsidian: #060908;
  --bg-panel: rgba(10, 16, 13, 0.86);
  --bg-panel-solid: #0a100d;
  --bg-elevated: rgba(16, 25, 20, 0.92);
  --border-subtle: rgba(245, 184, 46, 0.2);
  --border-strong: rgba(245, 184, 46, 0.5);
  --border-muted: rgba(154, 176, 164, 0.16);
  --amber: #f5b82e;
  --amber-soft: rgba(245, 184, 46, 0.14);
  --emerald: #34d399;
  --emerald-soft: rgba(52, 211, 153, 0.14);
  --alert: #f87171;
  --alert-soft: rgba(248, 113, 113, 0.14);
  --text-primary: #ebf2ee;
  --text-secondary: #a1b6aa;
  --text-muted: #768d80;
  --font-display: "Chakra Petch", "PingFang SC", "HarmonyOS Sans SC", "Microsoft YaHei", sans-serif;
  --font-body: "PingFang SC", "HarmonyOS Sans SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Consolas, monospace;
}

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

::selection {
  background: var(--amber);
  color: #060908;
}

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: rgba(6, 9, 8, 0.7);
}

::-webkit-scrollbar-thumb {
  background: rgba(245, 184, 46, 0.35);
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(245, 184, 46, 0.6);
}

html,
body {
  width: 100%;
  height: 100%;
  background: var(--bg-obsidian);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
}

.mono-num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.text-amber {
  color: var(--amber);
}

.text-emerald {
  color: var(--emerald);
}

/* 3D Globe Stage */
#globe-stage {
  position: fixed;
  inset: 0;
  z-index: 1;
  background: radial-gradient(circle at 50% 52%, #0e1913 0%, #060908 72%);
}

#globe-canvas,
#fallback-map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.reticle-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
}

.globe-loading {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 3;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 13px;
  pointer-events: none;
}

.globe-loading[hidden] {
  display: none;
}

.spinner-ring {
  width: 12px;
  height: 12px;
  border: 2px solid rgba(245, 184, 46, 0.28);
  border-top-color: var(--amber);
  border-radius: 50%;
  animation: spinRing 0.9s linear infinite;
  flex-shrink: 0;
}

@keyframes spinRing {
  to { transform: rotate(360deg); }
}

/* HUD Shell */
.hud-shell {
  position: relative;
  z-index: 10;
  width: 100%;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  padding: 12px 16px;
  gap: 10px;
  pointer-events: none;
}

.topbar,
.thesis-stage,
.rail,
.bottombar {
  pointer-events: auto;
}

/* Top Bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  backdrop-filter: blur(8px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.icon-brand {
  width: 20px;
  height: 20px;
  color: var(--amber);
  flex-shrink: 0;
}

.brand-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.06em;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.link-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border: 1px solid var(--border-muted);
  background: rgba(6, 9, 8, 0.72);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
}

.link-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--amber);
}

.link-badge.is-live {
  border-color: rgba(52, 211, 153, 0.45);
  color: var(--emerald);
}

.link-badge.is-live .link-dot {
  background: var(--emerald);
}

.link-badge.is-error {
  border-color: rgba(248, 113, 113, 0.45);
  color: var(--alert);
}

.link-badge.is-error .link-dot {
  background: var(--alert);
}

.hud-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border: 1px solid var(--border-muted);
  background: rgba(12, 19, 15, 0.85);
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 500;
  transition: border-color 140ms ease, background-color 140ms ease, color 140ms ease;
}

.hud-btn svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.hud-btn:hover {
  border-color: var(--amber);
  background: rgba(245, 184, 46, 0.12);
}

.hud-btn[aria-pressed="true"] {
  border-color: var(--emerald);
  color: var(--emerald);
  background: var(--emerald-soft);
}

.hud-btn-accent {
  border-color: rgba(245, 184, 46, 0.5);
  color: var(--amber);
  background: rgba(245, 184, 46, 0.1);
}

.hud-btn-accent:hover {
  background: rgba(245, 184, 46, 0.22);
}

/* Thesis Banner */
.thesis-stage {
  justify-self: center;
  width: min(820px, 100%);
  text-align: center;
  padding: 8px 18px 10px;
  background: linear-gradient(180deg, rgba(6, 9, 8, 0.84) 0%, rgba(6, 9, 8, 0.56) 100%);
  border: 1px solid rgba(245, 184, 46, 0.18);
  backdrop-filter: blur(6px);
  pointer-events: none;
}

.thesis-headline-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

.thesis-title {
  font-family: var(--font-display);
  font-size: clamp(26px, 3.6vw, 44px);
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: 0.03em;
  color: #ffffff;
}

.verdict-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 11px;
  border: 1px solid rgba(52, 211, 153, 0.45);
  background: rgba(52, 211, 153, 0.12);
  color: var(--emerald);
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.verdict-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--emerald);
}

.thesis-summary {
  margin-top: 6px;
  font-size: clamp(13px, 1.35vw, 16px);
  color: var(--text-secondary);
}

.num-amber,
.num-emerald {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 1.25em;
  font-weight: 700;
  margin: 0 3px;
}

.num-amber {
  color: var(--amber);
}

.num-emerald {
  color: var(--emerald);
}

.ticker-bar {
  margin-top: 7px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 3px 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 12px;
  color: var(--text-secondary);
  max-width: 100%;
  transition: opacity 200ms ease;
}

.ticker-tag {
  padding: 1px 6px;
  background: var(--amber-soft);
  border: 1px solid rgba(245, 184, 46, 0.35);
  color: var(--amber);
  font-size: 11px;
  font-weight: 600;
  flex-shrink: 0;
}

.ticker-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Main Perimeter Columns */
.hud-columns {
  min-height: 0;
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 16px;
  pointer-events: none;
}

.rail {
  width: clamp(280px, 24vw, 340px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  overflow-y: auto;
  transition: opacity 220ms ease, transform 220ms ease;
}

.panel {
  position: relative;
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  backdrop-filter: blur(8px);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.panel::before,
.panel::after {
  content: "";
  position: absolute;
  width: 8px;
  height: 8px;
  pointer-events: none;
}

.panel::before {
  top: -1px;
  left: -1px;
  border-top: 2px solid var(--amber);
  border-left: 2px solid var(--amber);
}

.panel::after {
  bottom: -1px;
  right: -1px;
  border-bottom: 2px solid var(--amber);
  border-right: 2px solid var(--amber);
}

.panel-grow {
  flex: 1 1 auto;
  min-height: 190px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: 7px;
  border-bottom: 1px solid rgba(245, 184, 46, 0.14);
}

.panel-title-wrap {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.panel-title-wrap svg {
  width: 15px;
  height: 15px;
  color: var(--amber);
  flex-shrink: 0;
}

.panel-title-wrap h2 {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text-primary);
  white-space: nowrap;
}

.panel-status {
  padding: 2px 7px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  border: 1px solid transparent;
  flex-shrink: 0;
}

.status-idle {
  color: var(--emerald);
  background: var(--emerald-soft);
  border-color: rgba(52, 211, 153, 0.35);
}

.status-warn {
  color: var(--alert);
  background: var(--alert-soft);
  border-color: rgba(248, 113, 113, 0.35);
}

.mini-btn {
  padding: 2px 8px;
  border: 1px solid var(--border-subtle);
  background: rgba(245, 184, 46, 0.08);
  color: var(--amber);
  font-size: 11px;
  font-weight: 600;
  transition: background-color 140ms ease, border-color 140ms ease;
}

.mini-btn:hover {
  background: rgba(245, 184, 46, 0.2);
  border-color: var(--amber);
}

/* CRT Monitor */
.crt-monitor {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 10.5;
  background: #060908;
  border: 1px solid rgba(52, 211, 153, 0.26);
  overflow: hidden;
}

.crt-monitor img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 42%;
  display: block;
}

.crt-scanlines {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center, transparent 58%, rgba(4, 7, 6, 0.62) 100%);
  pointer-events: none;
}

.crt-hud-top,
.crt-hud-bottom {
  position: absolute;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  pointer-events: none;
}

.crt-hud-top {
  top: 0;
  background: linear-gradient(180deg, rgba(6, 9, 8, 0.85) 0%, transparent 100%);
  color: var(--text-secondary);
}

.crt-hud-bottom {
  bottom: 0;
  background: linear-gradient(0deg, rgba(6, 9, 8, 0.9) 0%, transparent 100%);
  color: var(--text-secondary);
}

.rec-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--emerald);
  font-weight: 700;
}

.rec-dot {
  width: 6px;
  height: 6px;
  background: var(--emerald);
}

.win-pill {
  color: var(--amber);
  font-weight: 700;
}

.cam-caption {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.45;
  min-height: 35px;
}

/* Coordinates & Idle Meter */
.coord-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
}

.coord-item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 5px 8px;
  background: rgba(6, 9, 8, 0.55);
  border: 1px solid var(--border-muted);
}

.meta-label {
  font-size: 11px;
  color: var(--text-muted);
}

.meta-value {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
  text-align: right;
}

.idle-meter {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.idle-meter-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 11px;
  color: var(--text-secondary);
}

.progress-track {
  width: 100%;
  height: 7px;
  background: rgba(6, 9, 8, 0.9);
  border: 1px solid rgba(52, 211, 153, 0.28);
  overflow: hidden;
}

.progress-fill {
  width: 0%;
  height: 100%;
  background: var(--emerald);
  transition: width 120ms linear, background-color 180ms ease;
}

.progress-fill.is-paused {
  background: var(--amber);
}

.idle-stats-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-secondary);
}

/* Right Rail: Intervention Buttons */
.panel-note {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.45;
}

.action-stack {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.tactical-action {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 8px 10px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
  background: rgba(16, 25, 20, 0.9);
  border: 1px solid rgba(248, 113, 113, 0.3);
  transition: border-color 140ms ease, background-color 140ms ease, transform 80ms ease;
}

.tactical-action svg {
  width: 15px;
  height: 15px;
  color: var(--alert);
  flex-shrink: 0;
}

.tactical-action:hover {
  border-color: var(--alert);
  background: rgba(248, 113, 113, 0.14);
}

.tactical-action:active {
  transform: scale(0.99);
}

.intercept-box {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  background: rgba(6, 9, 8, 0.65);
  border: 1px solid var(--border-muted);
  transition: border-color 200ms ease, background-color 200ms ease;
}

.intercept-box.is-triggered {
  border-color: rgba(248, 113, 113, 0.6);
  background: rgba(248, 113, 113, 0.08);
}

.dinergate-thumb {
  width: 52px;
  height: 52px;
  object-fit: cover;
  border: 1px solid rgba(245, 184, 46, 0.25);
  flex-shrink: 0;
}

.intercept-copy {
  min-width: 0;
  flex: 1;
}

.intercept-badge {
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--amber);
}

.intercept-box.is-triggered .intercept-badge {
  color: var(--alert);
}

.intercept-text {
  margin-top: 2px;
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.4;
}

/* Tabs & Feed */
.tab-bar {
  display: inline-flex;
  border: 1px solid var(--border-muted);
  background: rgba(6, 9, 8, 0.6);
}

.tab-btn {
  padding: 2px 8px;
  font-size: 11px;
  color: var(--text-muted);
  transition: color 120ms ease, background-color 120ms ease;
}

.tab-btn.is-active {
  color: #060908;
  background: var(--amber);
  font-weight: 700;
}

.tab-panel {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

.tab-panel[hidden] {
  display: none;
}

.feed-list,
.regions-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.feed-empty {
  font-size: 12px;
  color: var(--text-muted);
  padding: 12px 0;
  text-align: center;
}

.feed-item {
  padding: 6px 8px;
  background: rgba(6, 9, 8, 0.52);
  border: 1px solid var(--border-muted);
  font-size: 12px;
}

.feed-item.is-intercept {
  border-color: rgba(248, 113, 113, 0.32);
}

.feed-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.feed-place {
  color: var(--amber);
  font-weight: 600;
}

.feed-item.is-intercept .feed-place {
  color: var(--alert);
}

.feed-detail {
  color: var(--text-secondary);
  line-height: 1.38;
}

.region-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px 8px;
  background: rgba(6, 9, 8, 0.52);
  border: 1px solid var(--border-muted);
}

.region-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
}

.region-name {
  font-weight: 600;
  color: var(--text-primary);
}

.region-wins {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  color: var(--amber);
  font-weight: 600;
}

.region-bar-track {
  height: 4px;
  background: rgba(255, 255, 255, 0.06);
}

.region-bar-fill {
  height: 100%;
  background: var(--emerald);
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.metric-cell {
  padding: 7px 8px;
  background: rgba(6, 9, 8, 0.55);
  border: 1px solid var(--border-muted);
}

.metric-cell dt {
  font-size: 11px;
  color: var(--text-muted);
}

.metric-cell dd {
  margin-top: 2px;
  font-size: 16px;
  font-weight: 700;
}

/* Bottom Bar */
.bottombar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 12px;
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  backdrop-filter: blur(8px);
  font-size: 12px;
  color: var(--text-secondary);
}

.node-readout {
  color: var(--text-secondary);
}

.node-readout.is-active {
  color: var(--amber);
}

/* Pure Globe Mode */
body.is-pure-globe .rail,
body.is-pure-globe .ticker-bar {
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
}

/* Share Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(4, 7, 6, 0.8);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-box {
  width: min(680px, 100%);
  background: var(--bg-panel-solid);
  border: 1px solid var(--border-strong);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.share-preview {
  width: 100%;
  height: auto;
  border: 1px solid var(--border-subtle);
  background: #060908;
  display: block;
}

.modal-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

/* Toast Notifications */
.toast-stack {
  position: fixed;
  bottom: 54px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
}

.toast {
  padding: 6px 12px;
  background: rgba(10, 16, 13, 0.94);
  border: 1px solid var(--emerald);
  color: var(--emerald);
  font-size: 12px;
  font-weight: 600;
  animation: toastIn 160ms ease-out;
}

.toast.is-alert {
  border-color: var(--alert);
  color: var(--alert);
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Responsive Mobile Layout */
@media (max-width: 960px) {
  html,
  body {
    overflow-y: auto;
    height: auto;
    min-height: 100%;
  }

  #globe-stage {
    position: fixed;
    inset: 0;
    height: 100dvh;
  }

  .hud-shell {
    height: auto;
    min-height: 100dvh;
    grid-template-rows: auto auto 46vh auto auto;
    padding: 10px;
    padding-bottom: calc(14px + env(safe-area-inset-bottom));
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .topbar-controls {
    justify-content: space-between;
  }

  .thesis-stage {
    padding: 8px 10px;
  }

  .hud-columns {
    grid-row: 4;
    flex-direction: column;
    gap: 10px;
  }

  .rail {
    width: 100%;
    overflow: visible;
  }

  .panel-grow {
    min-height: 240px;
  }

  .bottombar {
    grid-row: 5;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  body.is-pure-globe .hud-shell {
    min-height: 100dvh;
    grid-template-rows: auto auto 1fr auto;
  }

  body.is-pure-globe .hud-columns {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .spinner-ring,
  .toast {
    animation: none;
  }
  .progress-fill,
  .hud-btn,
  .rail {
    transition: none;
  }
}
