:root {
  color-scheme: dark;
  --bg: #080b0d;
  --panel: rgba(16, 21, 24, 0.94);
  --panel-soft: rgba(20, 27, 30, 0.8);
  --line: rgba(194, 210, 198, 0.13);
  --line-strong: rgba(194, 210, 198, 0.25);
  --text: #e8ede8;
  --muted: #7d8983;
  --accent: #b7ef45;
  --accent-dim: rgba(183, 239, 69, 0.14);
  --hostile: #ff5e4d;
  --friendly: #58c8ff;
  --inactive: #75807a;
  --font-display: "Barlow Condensed", sans-serif;
  --font-mono: "IBM Plex Mono", monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { min-height: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(circle at 18% 15%, rgba(183, 239, 69, 0.055), transparent 28rem),
    linear-gradient(rgba(255, 255, 255, 0.012) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.012) 1px, transparent 1px),
    var(--bg);
  background-size: auto, 48px 48px, 48px 48px, auto;
  color: var(--text);
  font-family: var(--font-mono);
}

button, output, select { font: inherit; }
button { color: inherit; }

.auth-screen {
  min-height: 100vh;
  padding: 24px;
  display: grid;
  place-items: center;
}

.auth-card {
  width: min(100%, 430px);
  padding: 30px;
}

.auth-brand { width: max-content; }
.auth-copy { margin-top: 56px; }
.auth-copy h1 { margin-top: 8px; font-size: 38px; }
.auth-copy p { margin: 13px 0 0; color: var(--muted); font-size: 10px; line-height: 1.7; }
.logout-button {
  border: 1px solid rgba(183, 239, 69, 0.35);
  background: var(--accent);
  color: #11160c;
  cursor: pointer;
  font: 600 10px var(--font-mono);
  letter-spacing: 0.12em;
}
.share-button { height: 35px; padding: 0 11px; background: rgba(183, 239, 69, 0.08); color: var(--accent); border: 1px solid rgba(183, 239, 69, 0.35); cursor: pointer; font-size: 8px; letter-spacing: 0.08em; }
.share-button:hover { background: rgba(183, 239, 69, 0.14); border-color: var(--accent); }
.share-button:disabled { cursor: wait; opacity: 0.6; }

.viewer-pill {
  min-height: 32px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.025);
}
.viewer-pill span,
.viewer-pill strong { display: block; }
.viewer-pill span { color: var(--muted); font-size: 7px; letter-spacing: 0.16em; }
.viewer-pill strong { margin-top: 3px; font: 600 11px/1 var(--font-mono); color: var(--text); }
.auth-status { margin-top: 30px; min-height: 44px; border: 1px solid var(--line); display: flex; align-items: center; gap: 10px; padding: 0 13px; color: var(--muted); font-size: 9px; letter-spacing: 0.1em; }
.auth-status.exchanging { color: #d4a73d; }
.auth-status.exchanging .status-dot { background: #d4a73d; }
.auth-error { margin: 12px 0 0; color: var(--hostile); font-size: 9px; line-height: 1.5; }

.app-shell { min-height: 100vh; }

.topbar {
  min-height: 78px;
  padding: 0 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(8, 11, 13, 0.9);
  backdrop-filter: blur(16px);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  color: var(--text);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  justify-self: start;
}

.brand-mark {
  width: 32px;
  height: 32px;
  border: 1px solid var(--line-strong);
  display: flex;
  align-items: flex-end;
  gap: 3px;
  padding: 7px;
  transform: skew(-7deg);
}

.brand-mark i { width: 4px; background: var(--accent); display: block; }
.brand-mark i:nth-child(1) { height: 42%; }
.brand-mark i:nth-child(2) { height: 100%; }
.brand-mark i:nth-child(3) { height: 68%; }

.brand strong,
.brand small { display: block; }
.brand strong { font: 700 23px/0.9 var(--font-display); letter-spacing: 0.12em; }
.brand small { margin-top: 5px; color: var(--muted); font-size: 8px; letter-spacing: 0.24em; }

.session-strip { display: flex; align-items: center; }
.session-strip div { padding: 0 34px; border-left: 1px solid var(--line); }
.session-strip div:last-child { border-right: 1px solid var(--line); }
.session-strip span,
.session-strip strong { display: block; }
.session-strip span { color: var(--muted); font-size: 8px; letter-spacing: 0.16em; }
.session-strip strong { margin-top: 5px; font: 600 15px/1 var(--font-display); letter-spacing: 0.08em; text-transform: uppercase; }

.connection-pill {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  border: 1px solid var(--line);
  padding: 9px 12px;
  color: var(--muted);
  font-size: 9px;
  letter-spacing: 0.14em;
}

.topbar-actions { justify-self: end; display: flex; align-items: center; gap: 9px; }
.account-label { max-width: 120px; overflow: hidden; text-overflow: ellipsis; color: var(--muted); font-size: 8px; white-space: nowrap; }
.logout-button { height: 35px; padding: 0 11px; background: transparent; color: var(--muted); border-color: var(--line); }
.logout-button:hover { color: var(--accent); border-color: var(--accent); }

.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #d4a73d; box-shadow: 0 0 10px currentColor; }
.connection-pill.online { color: var(--accent); border-color: rgba(183, 239, 69, 0.25); }
.connection-pill.online .status-dot { background: var(--accent); }
.connection-pill.stale { color: #d4a73d; }
.connection-pill.error { color: var(--hostile); }
.connection-pill.error .status-dot { background: var(--hostile); }

.dashboard {
  padding: 22px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  gap: 18px;
  min-height: calc(100vh - 78px);
}

.panel { border: 1px solid var(--line); background: var(--panel); box-shadow: 0 16px 50px rgba(0, 0, 0, 0.16); }
.panel-heading { min-height: 76px; padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.eyebrow { color: var(--accent); font-size: 8px; letter-spacing: 0.22em; }
h1, h2 { margin: 4px 0 0; font-family: var(--font-display); text-transform: uppercase; letter-spacing: 0.04em; }
h1 { font-size: clamp(24px, 2.2vw, 34px); }
h2 { font-size: 23px; }

.radar-panel { min-width: 0; display: flex; flex-direction: column; }
.radar-actions { display: flex; align-items: center; gap: 6px; }
.map-select-label {
  height: 32px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 8px;
  margin-right: 5px;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 8px;
  letter-spacing: 0.12em;
}
.map-select-label select {
  max-width: 130px;
  border: 0;
  outline: 0;
  background: #111719;
  color: var(--text);
  cursor: pointer;
  font-size: 9px;
  text-transform: uppercase;
}
.radar-actions button,
.radar-actions output,
.filter-button {
  height: 32px;
  min-width: 32px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.02);
  display: inline-grid;
  place-items: center;
  font-size: 11px;
}
.radar-actions button,
.filter-button { cursor: pointer; }
.radar-actions button:hover,
.filter-button:hover { border-color: var(--accent); color: var(--accent); }
.radar-actions output { padding: 0 10px; color: var(--muted); }
.radar-actions .text-button { padding: 0 12px; margin-left: 5px; }

.radar-stage {
  position: relative;
  flex: 1;
  min-height: 580px;
  overflow: hidden;
  background:
    radial-gradient(circle at center, rgba(183, 239, 69, 0.035), transparent 58%),
    #0b1012;
}

#radar-canvas { width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
#radar-canvas.dragging { cursor: grabbing; }

.radar-readout { position: absolute; top: 18px; pointer-events: none; }
.radar-readout.top-left { left: 20px; }
.radar-readout.top-right { right: 20px; text-align: right; }
.radar-readout span,
.radar-readout strong { display: block; }
.radar-readout span { color: var(--muted); font-size: 8px; letter-spacing: 0.18em; }
.radar-readout strong { margin-top: 4px; color: rgba(232, 237, 232, 0.72); font-size: 10px; }

.radar-legend { position: absolute; left: 20px; bottom: 18px; display: flex; gap: 18px; color: var(--muted); font-size: 8px; letter-spacing: 0.11em; pointer-events: none; }
.radar-legend span { display: flex; align-items: center; gap: 7px; }
.radar-legend i { width: 6px; height: 6px; transform: rotate(45deg); }
.radar-legend .friendly { background: var(--friendly); }
.radar-legend .hostile { background: var(--hostile); }
.radar-legend .inactive { background: var(--inactive); }

.scan-line { position: absolute; inset: 0 auto 0 0; width: 1px; background: linear-gradient(transparent 5%, rgba(183, 239, 69, 0.2), transparent 95%); animation: scan 8s linear infinite; pointer-events: none; }
@keyframes scan { from { transform: translateX(0); } to { transform: translateX(calc(100vw - 430px)); } }

.radar-footer { min-height: 42px; padding: 0 18px; border-top: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 15px; color: var(--muted); font-size: 8px; letter-spacing: 0.1em; }

.side-column { display: grid; grid-template-rows: auto minmax(260px, 1fr) auto; gap: 14px; min-height: 0; }
.metrics-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.metric-card { min-height: 94px; padding: 13px 14px; position: relative; overflow: hidden; }
.metric-card::after { content: ""; position: absolute; width: 36px; height: 36px; right: -18px; top: -18px; border: 1px solid var(--line); transform: rotate(45deg); }
.metric-card span,
.metric-card strong,
.metric-card small { display: block; }
.metric-card span { color: var(--muted); font-size: 8px; letter-spacing: 0.13em; }
.metric-card strong { margin-top: 7px; font: 700 27px/1 var(--font-display); letter-spacing: 0.04em; }
.metric-card small { margin-top: 6px; color: var(--muted); font-size: 7px; letter-spacing: 0.14em; }
.metric-card.alert strong { color: var(--accent); }

.roster-panel { min-height: 0; display: flex; flex-direction: column; }
.roster-heading { min-height: 70px; }
.filter-button { padding: 0 10px; color: var(--muted); font-size: 8px; letter-spacing: 0.1em; }
.roster-list { padding: 6px; overflow: auto; min-height: 0; }
.roster-list::-webkit-scrollbar { width: 5px; }
.roster-list::-webkit-scrollbar-thumb { background: var(--line-strong); }
.roster-item { width: 100%; min-height: 56px; padding: 8px 9px; border: 1px solid transparent; background: transparent; display: grid; grid-template-columns: 9px 1fr 62px 52px; align-items: center; gap: 10px; text-align: left; cursor: pointer; }
.roster-item:hover { background: rgba(255, 255, 255, 0.025); }
.roster-item.selected { border-color: rgba(183, 239, 69, 0.26); background: var(--accent-dim); }
.roster-signal { width: 7px; height: 7px; transform: rotate(45deg); background: var(--hostile); }
.roster-item.friendly .roster-signal { background: var(--friendly); }
.roster-item.inactive .roster-signal { background: var(--inactive); }
.roster-identity { min-width: 0; }
.roster-identity strong,
.roster-identity small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.roster-identity strong { font: 600 15px/1 var(--font-display); letter-spacing: 0.04em; text-transform: uppercase; }
.roster-identity small { margin-top: 5px; color: var(--muted); font-size: 8px; }
.roster-health { height: 3px; background: rgba(255, 255, 255, 0.07); }
.roster-health i { display: block; height: 100%; background: var(--accent); }
.roster-distance { color: var(--muted); font-size: 8px; text-align: right; }
.empty-roster { padding: 44px 20px; color: var(--muted); font-size: 10px; text-align: center; }

.detail-panel { min-height: 196px; padding: 18px; }
.empty-detail { height: 158px; display: grid; place-items: center; align-content: center; gap: 14px; color: var(--muted); font-size: 9px; text-transform: uppercase; letter-spacing: 0.12em; text-align: center; }
.target-icon { width: 28px; height: 28px; border: 1px solid var(--line-strong); border-radius: 50%; position: relative; }
.target-icon::before,
.target-icon::after { content: ""; position: absolute; background: var(--line-strong); }
.target-icon::before { width: 38px; height: 1px; left: -6px; top: 13px; }
.target-icon::after { width: 1px; height: 38px; left: 13px; top: -6px; }
.detail-header { display: flex; justify-content: space-between; align-items: start; gap: 12px; }
.team-badge { padding: 6px 8px; border: 1px solid var(--line); color: var(--friendly); font-size: 8px; }
.health-line { margin-top: 18px; display: flex; justify-content: space-between; color: var(--muted); font-size: 8px; }
.health-line strong { color: var(--text); }
.health-track { height: 4px; margin-top: 8px; background: rgba(255, 255, 255, 0.07); }
.health-track i { display: block; height: 100%; background: var(--accent); }
.detail-grid { margin: 19px 0 0; display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.detail-grid div { min-width: 0; }
.detail-grid dt { color: var(--muted); font-size: 7px; letter-spacing: 0.12em; }
.detail-grid dd { margin: 5px 0 0; overflow: hidden; text-overflow: ellipsis; font: 600 14px/1 var(--font-display); white-space: nowrap; }

@media (max-width: 1080px) {
  .topbar { grid-template-columns: 1fr auto; }
  .session-strip { display: none; }
  .dashboard { grid-template-columns: 1fr; }
  .radar-stage { min-height: 62vh; }
  .side-column { grid-template-columns: 1fr 1fr; grid-template-rows: auto auto; }
  .metrics-grid { grid-column: 1 / -1; }
  .roster-panel { min-height: 360px; }
  @keyframes scan { to { transform: translateX(100vw); } }
}

@media (max-width: 680px) {
  .topbar { min-height: 66px; padding: 0 15px; }
  .brand small { display: none; }
  .account-label, .viewer-pill, .connection-pill, .share-button { display: none; }
  .dashboard { padding: 10px; gap: 10px; }
  .panel-heading { padding: 13px 14px; }
  .radar-heading { align-items: flex-start; flex-direction: column; }
  .radar-actions { width: 100%; flex-wrap: wrap; }
  .map-select-label { flex: 1; }
  .map-select-label select { max-width: none; width: 100%; }
  .radar-stage { min-height: 58vh; }
  .radar-footer span:nth-child(-n+2) { display: none; }
  .radar-footer { justify-content: flex-end; }
  .radar-legend { gap: 10px; }
  .side-column { display: flex; flex-direction: column; }
  .roster-panel { min-height: 330px; }
  .detail-panel { min-height: 196px; }
}

@media (prefers-reduced-motion: reduce) {
  .scan-line { animation: none; }
}
