:root {
  --bg-0: #070806;
  --bg-1: #12140e;
  --bg-2: #1c1e16;
  --metal: #3a3c32;
  --metal-hi: #5c5e50;
  --phosphor: #d8f737;
  --phosphor-dim: #6a8a14;
  --phosphor-bright: #f4ff8c;
  --amber: #c8b44a;
  --amber-dim: #8a7820;
  --alert: #ff3b3b;
  --alert-dim: #8a1212;
  --cyan: #07b5a6;
  --text: #e8f0c8;
  --muted: #8a9068;
  --line: rgba(216, 247, 55, 0.22);
  --shadow: 0 0 28px rgba(216, 247, 55, 0.22);
  --font-brand: "Trebuchet MS", "Avenir Next", "Segoe UI Rounded", ui-rounded, "Segoe UI", sans-serif;
  --font-ui: "Segoe UI", "Helvetica Neue", ui-sans-serif, system-ui, sans-serif;
  --font-mono: ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, monospace;
  --radius: 16px;
  --header-h: 76px;
  --footer-h: 64px;
}

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

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg-0);
  color: var(--text);
  font-family: var(--font-ui);
  color-scheme: dark;
}

body {
  min-height: 100dvh;
  overflow: hidden;
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  touch-action: manipulation;
}

.crt,
.vignette {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 40;
}

.crt {
  background: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent 2px,
    rgba(0, 0, 0, 0.14) 2px,
    rgba(0, 0, 0, 0.14) 3px
  );
  mix-blend-mode: multiply;
  opacity: 0.55;
}

.vignette {
  background: radial-gradient(ellipse at center, transparent 40%, rgba(0, 0, 0, 0.55) 100%);
  z-index: 39;
}

.shell {
  position: relative;
  z-index: 1;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom)
    env(safe-area-inset-left);
}

.bridge {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 12px 18px 10px;
  border-bottom: 2px solid rgba(216, 247, 55, 0.2);
  background:
    radial-gradient(circle at 12px 18px, var(--metal-hi) 1.4px, transparent 1.6px),
    radial-gradient(circle at calc(100% - 12px) 18px, var(--metal-hi) 1.4px, transparent 1.6px),
    linear-gradient(180deg, #2a2c24 0%, #12140e 72%, transparent);
}

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

.mark {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: #0b0c08;
  object-fit: contain;
  flex: 0 0 auto;
  box-shadow:
    0 0 0 2px rgba(216, 247, 55, 0.7),
    0 0 0 5px #2a2c24,
    0 0 22px rgba(216, 247, 55, 0.4);
}

.brand-text h1 {
  margin: 0;
  font-family: var(--font-brand);
  font-size: 1.7rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.05;
  color: var(--phosphor);
  text-shadow: 0 2px 0 #3d4a10, 0 0 18px rgba(216, 247, 55, 0.45);
}

.tagline {
  margin: 4px 0 0;
  font-size: 0.64rem;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted);
}

.domain {
  margin: 3px 0 0;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--cyan);
  letter-spacing: 0.08em;
}

.bridge-status {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  justify-content: flex-end;
}

.stat {
  min-width: 72px;
}

.stat-k {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.16em;
  color: var(--muted);
}

.stat-v {
  display: block;
  font-family: var(--font-mono);
  font-size: 1.05rem;
  color: var(--phosphor);
  text-shadow: 0 0 8px var(--phosphor-dim);
}

.stat-mode .stat-v {
  color: var(--amber);
}

.cic {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(280px, 0.9fr);
  min-height: 0;
  gap: 12px;
  padding: 8px 14px 4px;
}

.radar-well {
  position: relative;
  min-height: 0;
  display: grid;
  grid-template-rows: 1fr auto;
  place-items: center;
  padding: 8px 8px 4px;
}

.porthole {
  position: relative;
  width: min(100%, calc(100dvh - 220px));
  max-width: 100%;
  aspect-ratio: 1;
  min-height: 280px;
  border-radius: 50%;
  border: 10px solid #2e3028;
  background:
    radial-gradient(circle at 50% 50%, #0d1a08 0%, #070806 72%);
  box-shadow:
    0 0 0 2px var(--phosphor),
    0 0 28px rgba(216, 247, 55, 0.28),
    inset 0 0 48px rgba(0, 0, 0, 0.7);
  overflow: hidden;
}

.porthole::before {
  content: "";
  position: absolute;
  inset: -10px;
  border-radius: 50%;
  pointer-events: none;
  background: repeating-conic-gradient(from 12deg, var(--metal-hi) 0 5deg, transparent 5deg 30deg);
  -webkit-mask: radial-gradient(closest-side, transparent calc(100% - 9px), #000 calc(100% - 8px));
  mask: radial-gradient(closest-side, transparent calc(100% - 9px), #000 calc(100% - 8px));
  z-index: 2;
}

#radar {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 280px;
  border-radius: 50%;
}

.radar-caption {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 4px 2px;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  color: var(--muted);
}

.sep {
  opacity: 0.4;
}

.console {
  display: flex;
  flex-direction: column;
  min-height: 0;
  gap: 10px;
}

.controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.controls .btn-amber {
  grid-column: 1 / -1;
}

.btn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  padding: 10px 12px 10px 28px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, #2c2e26, #12140c);
  box-shadow: inset 0 1px 0 rgba(216, 247, 55, 0.08);
  text-align: left;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.12s, background 0.15s;
}

.btn:hover {
  border-color: rgba(216, 247, 55, 0.55);
  box-shadow: 0 0 16px rgba(216, 247, 55, 0.12);
}

.btn:active {
  transform: translateY(1px);
}

.btn .led {
  position: absolute;
  left: 10px;
  top: 50%;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  transform: translateY(-50%);
  background: #3a3c20;
  box-shadow: inset 0 0 3px #000;
}

.btn.is-on {
  border-color: var(--phosphor);
  box-shadow: 0 0 18px rgba(216, 247, 55, 0.22);
}

.btn.is-on .led {
  background: var(--phosphor);
  box-shadow: 0 0 8px var(--phosphor);
}

.btn:disabled {
  opacity: 0.55;
  cursor: wait;
  pointer-events: none;
}

.btn-kicker {
  font-family: var(--font-mono);
  font-size: 0.58rem;
  letter-spacing: 0.18em;
  color: var(--muted);
}

.btn-label {
  font-size: 0.82rem;
  letter-spacing: 0.12em;
  font-weight: 700;
}

.btn-sub {
  font-size: 0.68rem;
  color: var(--muted);
}

.btn-dive.is-on,
.btn-dive:hover {
  border-color: var(--phosphor-bright);
}

.btn-dive.is-on::after {
  content: "";
  position: absolute;
  inset: -2px;
  border-radius: inherit;
  border: 1px solid rgba(216, 247, 55, 0.55);
  animation: divePing 1.6s ease-out infinite;
  pointer-events: none;
}

@keyframes divePing {
  0% {
    opacity: 0.7;
    transform: scale(1);
  }
  100% {
    opacity: 0;
    transform: scale(1.06);
  }
}

.btn-ghost.is-on {
  border-color: var(--cyan);
}

.btn-ghost.is-on .led {
  background: var(--cyan);
  box-shadow: 0 0 8px var(--cyan);
}

.btn-amber.is-on {
  border-color: var(--amber);
}

.btn-amber.is-on .led {
  background: var(--amber);
  box-shadow: 0 0 8px var(--amber);
}

.support {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.pill {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  padding: 3px 7px;
  border-radius: 999px;
  border: 1px solid var(--line);
}

.pill-ok {
  color: var(--phosphor);
  border-color: rgba(216, 247, 55, 0.4);
}

.pill-no {
  color: var(--amber);
  border-color: rgba(255, 179, 71, 0.35);
}

.radio-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 10px 10px;
  background: rgba(1, 10, 6, 0.85);
}

.radio-head {
  display: flex;
  align-items: center;
  gap: 8px;
  letter-spacing: 0.14em;
  font-size: 0.72rem;
}

.radio-led {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #143326;
  flex: 0 0 auto;
}

.radio-led[data-state="live"] {
  background: var(--phosphor);
  box-shadow: 0 0 10px var(--phosphor);
}

.radio-led[data-state="wait"] {
  background: var(--amber);
  box-shadow: 0 0 10px var(--amber);
  animation: divePing 1.4s ease-out infinite;
}

.radio-led[data-state="lock"] {
  background: var(--cyan);
  box-shadow: 0 0 10px var(--cyan);
}

.radio-led[data-state="sim"] {
  background: var(--amber);
}

.radio-led[data-state="off"] {
  background: var(--alert);
}

.radio-stats {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  margin: 8px 0 6px;
}

.radio-stats div {
  min-width: 0;
}

.radio-stats dt {
  font-family: var(--font-mono);
  font-size: 0.58rem;
  letter-spacing: 0.12em;
  color: var(--muted);
}

.radio-stats dd {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.92rem;
  color: var(--phosphor);
}

.radio-note {
  margin: 0;
  font-size: 0.72rem;
  line-height: 1.4;
  color: var(--muted);
}

.https-banner {
  margin: 8px 0 0;
  padding: 8px 10px;
  border: 1px solid var(--alert);
  border-radius: 6px;
  background: rgba(255, 59, 59, 0.12);
  color: #ffd0d0;
  font-size: 0.78rem;
  line-height: 1.4;
}

.https-banner[hidden] {
  display: none !important;
}

.log-drawer {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(12, 14, 8, 0.88);
  overflow: hidden;
}

.log-toggle {
  display: flex;
  justify-content: space-between;
  width: 100%;
  padding: 8px 12px;
  border: 0;
  background: rgba(216, 247, 55, 0.06);
  letter-spacing: 0.16em;
  font-size: 0.72rem;
}

.log-meta {
  color: var(--muted);
  letter-spacing: 0.08em;
}

.log-panels {
  display: grid;
  grid-template-rows: 1fr 0.7fr;
  min-height: 0;
  flex: 1;
}

.log-drawer:not(.is-open) .log-panels {
  display: none;
}

.tel-body,
.event-log {
  overflow: auto;
  padding: 8px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
}

.tel-body[data-empty="1"]::before {
  content: "No devices yet. Start Scan to listen for nearby Bluetooth, or Demo Mode to try the radar.";
  color: var(--muted);
}

.tel-body[data-empty="live"]::before {
  content: "Chrome is scanning in this tab. Nearby gadgets will appear here. Keep this tab in the foreground.";
  color: var(--amber);
}

.tel-body[data-empty="sim"]::before {
  content: "Demo Mode is on. These are simulated devices, not your Bluetooth adapter.";
  color: var(--amber);
}

.tel-row {
  display: grid;
  grid-template-columns: 32px 1fr 64px 40px 72px 62px 58px;
  gap: 6px;
  padding: 4px 0;
  border-bottom: 1px solid rgba(216, 247, 55, 0.08);
  align-items: center;
}

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

.tel-anchor .tel-flag {
  color: var(--phosphor);
}

.tel-mobile .tel-flag {
  color: var(--amber);
}

.tel-src {
  color: var(--cyan);
  font-size: 0.62rem;
  letter-spacing: 0.08em;
}

.tel-rssi,
.tel-sigma,
.tel-r,
.tel-sec {
  color: var(--muted);
}

.event-log {
  border-top: 1px solid var(--line);
  background: #0a0c08;
}

.log-row {
  display: grid;
  grid-template-columns: 88px 64px 1fr;
  gap: 8px;
  padding: 3px 0;
  color: var(--text);
}

.log-ts,
.log-kind {
  color: var(--muted);
}

.log-alert .log-kind,
.log-alert .log-msg {
  color: var(--alert);
}

.log-ghost .log-kind {
  color: var(--cyan);
}

.log-ripple .log-kind {
  color: var(--phosphor);
}

.log-warn .log-kind,
.log-warn .log-msg {
  color: var(--amber);
}

.keel {
  padding: 6px 16px 10px;
  border-top: 2px solid rgba(216, 247, 55, 0.18);
  background: linear-gradient(0deg, #1a1c14, transparent);
}

.ticker {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.86rem;
  color: var(--phosphor-bright);
  text-shadow: 0 0 10px var(--phosphor-dim);
  min-height: 1.2em;
}

.fineprint {
  margin: 4px 0 0;
  font-size: 0.68rem;
  color: var(--muted);
  letter-spacing: 0.06em;
}

.modal,
.alert-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: rgba(7, 8, 6, 0.78);
  padding: 20px;
}

.modal[hidden],
.alert-overlay[hidden],
.btn[hidden],
.cal-wrap[hidden] {
  display: none !important;
}

.modal-hatch,
.alert-panel {
  width: min(520px, 100%);
  padding: 22px 22px 18px;
  border: 1px solid var(--phosphor);
  border-radius: 14px;
  background: linear-gradient(180deg, #2c2e26, #0c0e0a);
  box-shadow: 0 0 40px rgba(216, 247, 55, 0.18);
}

.modal-kicker,
.alert-kicker {
  margin: 0 0 6px;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.22em;
  color: var(--muted);
}

.modal-hatch h2,
.alert-panel h2 {
  margin: 0 0 10px;
  letter-spacing: 0.12em;
}

.modal-hatch p,
.alert-panel p {
  line-height: 1.45;
}

.radio-steps {
  margin: 12px 0 0;
  padding-left: 1.2em;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  line-height: 1.55;
  color: var(--text);
}

.radio-steps li {
  margin: 0 0 8px;
}

.flag-box {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  padding: 10px 12px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.25);
}

.flag-box[hidden] {
  display: none;
}

.flag-label {
  flex: 1 0 100%;
  margin: 0;
  font-size: 0.68rem;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.flag-box code {
  flex: 1 1 180px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  word-break: break-all;
  color: var(--phosphor-bright);
}

.flag-box .btn {
  flex: 0 0 auto;
  padding: 8px 12px;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.cal-wrap {
  margin: 14px 0;
}

.cal-track {
  height: 8px;
  border-radius: 99px;
  background: #12140e;
  border: 1px solid var(--line);
  overflow: hidden;
}

.cal-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--phosphor-dim), var(--phosphor-bright));
  box-shadow: 0 0 12px var(--phosphor);
  transition: width 0.2s linear;
}

.modal-actions .btn {
  flex: 1;
  align-items: center;
  padding: 12px;
}

.alert-panel {
  border-color: var(--alert);
  background: linear-gradient(180deg, #3a0b0b, #140202);
  box-shadow: 0 0 48px rgba(255, 59, 59, 0.28);
  text-align: center;
}

.alert-panel h2 {
  color: #ffd0d0;
  text-shadow: 0 0 16px var(--alert);
}

.btn-alert {
  width: 100%;
  align-items: center;
  border-color: var(--alert);
  background: #4a1010;
}

body.is-alert {
  --phosphor: #ff6b6b;
  --phosphor-dim: #8a1212;
  --phosphor-bright: #ffd0d0;
  --line: rgba(255, 59, 59, 0.35);
}

body.is-alert .bridge,
body.is-alert .keel,
body.is-alert .radar-well {
  animation: alertPulse 0.7s ease-in-out infinite alternate;
}

@keyframes alertPulse {
  from {
    box-shadow: inset 0 0 0 rgba(255, 59, 59, 0);
  }
  to {
    box-shadow: inset 0 0 40px rgba(255, 59, 59, 0.28);
  }
}

body.is-ghost .stat-mode .stat-v {
  color: var(--cyan);
}

@media (max-width: 920px) {
  body {
    overflow: auto;
  }

  .shell {
    height: auto;
    min-height: 100dvh;
  }

  .bridge {
    flex-direction: column;
    align-items: flex-start;
  }

  .cic {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
  }

  .porthole {
    width: min(100%, 92vw);
    min-height: 0;
  }

  #radar {
    height: 100%;
  }

  .controls {
    grid-template-columns: 1fr 1fr;
  }

  .log-panels {
    grid-template-rows: 180px 140px;
  }

  .radio-stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .tel-row {
    grid-template-columns: 28px 1fr 56px 36px 64px;
  }

  .tel-sigma,
  .tel-r {
    display: none;
  }
}

@media (max-width: 560px) {
  .mark {
    width: 56px;
    height: 56px;
  }

  .brand-text h1 {
    font-size: 1.25rem;
    letter-spacing: -0.02em;
  }

  .controls {
    grid-template-columns: 1fr;
  }

  .radar-caption {
    display: none;
  }
}
