/* ═══════════════════════════════════════════════════════════════════════
   Ghost Rider CB — stylesheet
   1980s CB-radio faceplate at night: brushed dark metal, amber phosphor,
   scanlines, CRT glow.  All text contrast ≥ 7:1 against its background.
   Touch targets ≥ 64 px.  One-handed, glove-friendly.
   ═══════════════════════════════════════════════════════════════════════ */

/* ── Reset & base ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Palette */
  --bg:          #0a0b0c;   /* near-black metal body */
  --panel:       #111416;   /* slightly lighter panel face */
  --panel-edge:  #1e2124;   /* panel border highlight */
  --metal-hi:    #2a2d31;   /* brushed-metal highlight stripe */
  --amber:       #e8a020;   /* phosphor amber — primary text / active */
  --amber-dim:   #7a4a08;   /* dimmed amber for labels */
  --amber-glow:  rgba(232,160,32,0.18);
  --green:       #22c55e;   /* RX lamp green */
  --green-dim:   #14532d;
  --red:         #ef4444;   /* TX lamp red */
  --red-dim:     #7f1d1d;
  --ghost-tint:  rgba(168,85,247,0.85);  /* ghost pin purple */
  --map-bg:      #0d1117;

  /* Typography */
  --font-mono: "Courier New", Courier, monospace;
  --font-ui:   system-ui, -apple-system, sans-serif;

  /* Sizes */
  --radius:  6px;
  --radius-lg: 12px;

  /* Z layers */
  --z-map:    10;
  --z-drawer: 20;
  --z-ui:     30;
  --z-toast:  40;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--amber);
  font-family: var(--font-mono);
  font-size: 16px;
  line-height: 1.4;
  overflow: hidden;        /* radio face never scrolls */
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* ── Scanline overlay (CRT effect) ───────────────────────────────────── */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0px,
    transparent 3px,
    rgba(0,0,0,0.18) 3px,
    rgba(0,0,0,0.18) 4px
  );
  pointer-events: none;
  z-index: 999;
}

/* ── App shell ────────────────────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  position: relative;
}

/* ── Onboarding modal ─────────────────────────────────────────────────── */
#onboarding {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  z-index: 100;
  padding: 24px;
}
#onboarding.hidden { display: none; }

#onboarding h1 {
  font-family: var(--font-mono);
  font-size: 1.6rem;
  color: var(--amber);
  text-shadow: 0 0 12px var(--amber);
  letter-spacing: 0.08em;
  text-align: center;
}
#onboarding p {
  color: var(--amber-dim);
  font-size: 0.9rem;
  text-align: center;
  max-width: 320px;
}

.ob-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  max-width: 320px;
}
.ob-field label {
  font-size: 0.75rem;
  color: var(--amber-dim);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.ob-field input,
.ob-field select {
  background: #0d0f11;
  border: 1px solid var(--amber-dim);
  color: var(--amber);
  font-family: var(--font-mono);
  font-size: 1.1rem;
  padding: 14px 16px;
  border-radius: var(--radius);
  outline: none;
  min-height: 52px;
  width: 100%;
}
.ob-field input:focus,
.ob-field select:focus {
  border-color: var(--amber);
  box-shadow: 0 0 8px var(--amber-glow);
}
.ob-field select option { background: #0d0f11; }

#ob-go {
  width: 100%;
  max-width: 320px;
  min-height: 64px;
  background: var(--amber);
  color: #000;
  font-family: var(--font-mono);
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  border: none;
  border-radius: var(--radius-lg);
  cursor: pointer;
  text-transform: uppercase;
}
#ob-go:active { opacity: 0.85; transform: scale(0.98); }

/* ── Radio faceplate ──────────────────────────────────────────────────── */
#radio-face {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 16px 8px;
  gap: 12px;
  background:
    linear-gradient(180deg, var(--metal-hi) 0%, var(--panel) 6%, var(--panel) 94%, var(--metal-hi) 100%);
  border-bottom: 2px solid var(--metal-hi);
  position: relative;
  z-index: var(--z-ui);
  /* don't grow beyond what we need so the PTT has max room */
  flex-shrink: 0;
}

/* ── Top bar: channel display + lamps ────────────────────────────────── */
#top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  gap: 12px;
}

/* 7-segment amber channel display */
#channel-display {
  background: #040506;
  border: 2px solid #1a1c1f;
  border-radius: 4px;
  padding: 6px 14px;
  min-width: 120px;
  text-align: center;
  box-shadow: inset 0 0 10px rgba(0,0,0,0.8), 0 0 8px var(--amber-glow);
  position: relative;
}
#channel-display::before {
  /* ghost digit overlay — common 7-segment background bleed */
  content: "88";
  position: absolute;
  inset: 6px 14px;
  color: rgba(232,160,32,0.07);
  font-size: 1.5rem;
  line-height: 1;
  pointer-events: none;
}
#ch-label {
  font-size: 0.6rem;
  color: var(--amber-dim);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  display: block;
}
#ch-number {
  font-family: "Courier New", monospace;
  font-size: 1.5rem;
  color: var(--amber);
  text-shadow: 0 0 10px var(--amber);
  letter-spacing: 0.08em;
  display: block;
  line-height: 1.1;
}

/* lamp cluster */
#lamps {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-end;
}
.lamp {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.65rem;
  color: var(--amber-dim);
  letter-spacing: 0.1em;
}
.lamp-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.1);
  transition: background 0.1s, box-shadow 0.1s;
}
.lamp-dot.rx { background: var(--green-dim); }
.lamp-dot.tx { background: var(--red-dim); }
.lamp-dot.rx.active {
  background: var(--green);
  box-shadow: 0 0 8px var(--green), 0 0 16px rgba(34,197,94,0.4);
}
.lamp-dot.tx.active {
  background: var(--red);
  box-shadow: 0 0 8px var(--red), 0 0 16px rgba(239,68,68,0.4);
}

/* signal strength bars */
#signal-bars {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 20px;
}
.sig-bar {
  width: 5px;
  background: var(--amber-dim);
  border-radius: 1px;
  transition: background 0.3s;
}
.sig-bar.active { background: var(--amber); box-shadow: 0 0 4px var(--amber-glow); }
.sig-bar:nth-child(1) { height: 30%; }
.sig-bar:nth-child(2) { height: 50%; }
.sig-bar:nth-child(3) { height: 65%; }
.sig-bar:nth-child(4) { height: 80%; }
.sig-bar:nth-child(5) { height: 100%; }

/* listener count */
#listener-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}
#listener-count {
  font-size: 1.1rem;
  color: var(--amber);
  text-shadow: 0 0 6px var(--amber-glow);
}
#listener-label {
  font-size: 0.65rem;
  color: var(--amber-dim);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* ── Transcript display ───────────────────────────────────────────────── */
#transcript-box {
  width: 100%;
  background: #040506;
  border: 1px solid #1a1c1f;
  border-radius: var(--radius);
  padding: 8px 12px;
  min-height: 48px;
  font-size: 0.85rem;
  color: var(--amber);
  text-shadow: 0 0 6px var(--amber-glow);
  line-height: 1.4;
  /* phosphor persistence: fade-in only */
  transition: opacity 0.2s;
  position: relative;
}
#transcript-box::before {
  content: "SPIRIT BOX";
  position: absolute;
  top: -8px;
  left: 10px;
  font-size: 0.6rem;
  color: var(--amber-dim);
  letter-spacing: 0.15em;
  background: var(--panel);
  padding: 0 4px;
}
#transcript-text {
  display: block;
  word-break: break-word;
}

/* ── Knob row ─────────────────────────────────────────────────────────── */
#knob-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0 8px;
}

.knob-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.knob-label {
  font-size: 0.6rem;
  color: var(--amber-dim);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.knob {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 35%, #3a3d42, #18191c 70%);
  border: 2px solid #2a2d31;
  box-shadow: 2px 2px 6px rgba(0,0,0,0.6), inset 0 1px 2px rgba(255,255,255,0.08);
  position: relative;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
/* tick mark on knob */
.knob::after {
  content: "";
  width: 2px;
  height: 10px;
  background: var(--amber-dim);
  border-radius: 1px;
  position: absolute;
  top: 4px;
}
/* Channel up/down arrows around channel knob */
#ch-arrows {
  display: flex;
  gap: 4px;
}
.ch-arrow {
  background: #1a1c1f;
  border: 1px solid #2a2d31;
  color: var(--amber-dim);
  font-size: 1rem;
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.1s, border-color 0.1s;
}
.ch-arrow:active, .ch-arrow:hover {
  color: var(--amber);
  border-color: var(--amber);
}

/* ── Giant PTT button ─────────────────────────────────────────────────── */
#ptt-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px 0 16px;
  gap: 8px;
  position: relative;
  z-index: var(--z-ui);
  /* take remaining vertical space */
  min-height: 0;
}

#ptt {
  /* At least 45% of the viewport width, max 320px, min 200px */
  width: min(max(45vw, 200px), 320px);
  height: min(max(45vw, 200px), 320px);
  border-radius: 50%;
  border: none;
  cursor: pointer;
  position: relative;
  touch-action: none;    /* prevent scroll during hold */
  -webkit-touch-callout: none;
  outline: none;

  /* Layered radial gradient for 3-D depth */
  background:
    radial-gradient(circle at 38% 32%, #3a1a1a 0%, #1a0808 50%, #0d0404 100%);
  box-shadow:
    0 0 0 6px #1e0808,
    0 0 0 10px #120505,
    0 8px 24px rgba(0,0,0,0.7),
    0 0 40px rgba(239,68,68,0.08),
    inset 0 2px 4px rgba(255,255,255,0.08);
  transition: transform 0.08s, box-shadow 0.08s;
}

/* PTT label */
#ptt::before {
  content: "PTT";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: 0.25em;
  color: rgba(239,68,68,0.6);
  text-shadow: 0 0 10px rgba(239,68,68,0.3);
}

#ptt:hover::before { color: rgba(239,68,68,0.8); }

/* Recording state */
#ptt.recording {
  background:
    radial-gradient(circle at 38% 32%, #5a1a1a 0%, #3a0808 50%, #200404 100%);
  box-shadow:
    0 0 0 6px #3a0808,
    0 0 0 10px #200505,
    0 8px 24px rgba(0,0,0,0.7),
    0 0 60px rgba(239,68,68,0.5),
    inset 0 2px 4px rgba(255,255,255,0.1);
  animation: ptt-pulse 0.8s ease-in-out infinite;
}
#ptt.recording::before { color: var(--red); text-shadow: 0 0 16px var(--red); }

@keyframes ptt-pulse {
  0%, 100% { box-shadow: 0 0 0 6px #3a0808, 0 0 0 10px #200505, 0 8px 24px rgba(0,0,0,0.7), 0 0 40px rgba(239,68,68,0.4), inset 0 2px 4px rgba(255,255,255,0.1); }
  50%       { box-shadow: 0 0 0 6px #3a0808, 0 0 0 10px #200505, 0 8px 24px rgba(0,0,0,0.7), 0 0 80px rgba(239,68,68,0.7), inset 0 2px 4px rgba(255,255,255,0.1); }
}

#ptt:active, #ptt.pressed {
  transform: scale(0.96);
  box-shadow:
    0 0 0 6px #1e0808,
    0 0 0 10px #120505,
    0 4px 12px rgba(0,0,0,0.7),
    inset 0 2px 8px rgba(0,0,0,0.5);
}

/* PTT mode / status text */
#ptt-status {
  font-size: 0.75rem;
  color: var(--amber-dim);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  text-align: center;
  min-height: 1.2em;
}

/* Hold-vs-tap toggle */
#mode-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.7rem;
  color: var(--amber-dim);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.toggle-pill {
  width: 48px;
  height: 26px;
  background: #1a1c1f;
  border: 1px solid #2a2d31;
  border-radius: 13px;
  position: relative;
  cursor: pointer;
  transition: background 0.2s;
}
.toggle-pill::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--amber-dim);
  transition: transform 0.2s, background 0.2s;
}
.toggle-pill.on {
  background: rgba(232,160,32,0.15);
  border-color: var(--amber-dim);
}
.toggle-pill.on::after {
  transform: translateX(22px);
  background: var(--amber);
}

/* ── Map drawer ───────────────────────────────────────────────────────── */
#map-handle-bar {
  height: 36px;
  background: var(--panel-edge);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  cursor: pointer;
  flex-shrink: 0;
  border-top: 1px solid var(--metal-hi);
  z-index: var(--z-drawer);
  position: relative;
}
#map-handle-bar::before {
  content: "";
  width: 40px;
  height: 4px;
  border-radius: 2px;
  background: var(--amber-dim);
  opacity: 0.6;
}
#map-label {
  font-size: 0.65rem;
  color: var(--amber-dim);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  position: absolute;
  right: 16px;
}

#map-drawer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  /* collapsed: drawer is invisible; pointer-events off so the #map-handle-bar
     inside #app (which sits directly above) can receive clicks */
  height: 0;
  pointer-events: none;
  transition: height 0.35s cubic-bezier(0.4,0,0.2,1);
  background: var(--map-bg);
  z-index: var(--z-drawer);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#map-drawer.open {
  height: 65vh;
  min-height: 280px;
  /* restore pointer events on the whole drawer when open */
  pointer-events: auto;
}

#map {
  flex: 1;
  min-height: 0;
  opacity: 0;
  transition: opacity 0.2s;
}
#map-drawer.open #map { opacity: 1; }

/* ── Toast / signal-lost banner ──────────────────────────────────────── */
#toast {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(10,11,12,0.92);
  border: 1px solid var(--amber-dim);
  color: var(--amber);
  font-size: 0.85rem;
  padding: 10px 20px;
  border-radius: 24px;
  z-index: var(--z-toast);
  opacity: 0;
  transition: opacity 0.25s;
  pointer-events: none;
  white-space: nowrap;
}
#toast.visible { opacity: 1; }

/* Signal-lost full-width bar */
#signal-lost {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: var(--red-dim);
  color: var(--red);
  font-size: 0.75rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  text-align: center;
  padding: 6px;
  z-index: var(--z-toast);
  display: none;
}
#signal-lost.visible { display: block; }

/* ── Ghost pin count badge on map toggle ─────────────────────────────── */
#ghost-badge {
  background: var(--ghost-tint);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  position: absolute;
  left: 16px;
}
#ghost-badge.visible { display: flex; }

/* ── Proximity warning overlay ───────────────────────────────────────── */
#proximity-warn {
  position: fixed;
  bottom: 48px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(168,85,247,0.15);
  border: 1px solid rgba(168,85,247,0.6);
  color: #d8b4fe;
  font-size: 0.85rem;
  padding: 10px 20px;
  border-radius: var(--radius);
  z-index: var(--z-toast);
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
  text-align: center;
  max-width: 90vw;
}
#proximity-warn.visible { opacity: 1; }

/* ── Accessibility ───────────────────────────────────────────────────── */
/* Make sure all interactive elements can be tab-focused visibly */
:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
}
button, [role="button"] { cursor: pointer; }

/* ── Landscape phones: widen PTT, shrink faceplate vertically ─────────── */
@media (orientation: landscape) and (max-height: 500px) {
  #radio-face {
    flex-direction: row;
    flex-wrap: wrap;
    padding: 8px;
    gap: 8px;
  }
  #ptt-wrap {
    padding: 4px 0 4px;
    min-width: 180px;
  }
  #ptt {
    width: 160px;
    height: 160px;
  }
  #transcript-box { font-size: 0.8rem; }
}

/* ── Map-open PTT dock (Bug 2 fix, revised) ───────────────────────────────
   Problem: when the map drawer opens #radio-face still has flex:1 and
   z-index:var(--z-ui) (30).  Pulling the PTT wrap out of the flex flow lets
   #radio-face grow to full viewport height; its z-index 30 then paints over
   the drawer (z-index 20) AND the docked PTT (z-index 25), so both become
   invisible.

   Two-part fix applied in the two rule blocks below:
   Part 1 (radio-face rule) — stop the section from expanding (flex:none)
     and drop its z-index below the drawer.
   Part 2 (ptt-wrap rule) — dock the PTT to the bottom-right corner above
     the open drawer at exactly 64×64 px (touch-target ≥ 64 px, Req 6.1).

   Closing the drawer removes .map-open and restores the full-size layout.
   ──────────────────────────────────────────────────────────────────────── */

/* Part 1 — prevent #radio-face from expanding and covering the map/PTT */
#app.map-open #radio-face {
  /* Stop growing to fill remaining space once PTT wrap leaves the flow */
  flex: none;
  flex-shrink: 1;
  /* Must be below the drawer (--z-drawer = 20) so the map shows through */
  z-index: 1;
}

/* Part 2 — dock #ptt-wrap to the bottom-right corner above the drawer */
#app.map-open #ptt-wrap {
  position: fixed;
  /* Sit 8 px above the open drawer (65 vh, min 280 px) */
  bottom: max(calc(65vh + 8px), 288px);
  right: 12px;
  /* Remove from flex flow */
  width: auto;
  padding: 0;
  gap: 4px;
  flex: none;
  /* Above the drawer (20) but radio-face is now 1, so this is clearly on top */
  z-index: calc(var(--z-drawer) + 5);
  pointer-events: auto;
}

#app.map-open #ptt {
  width: 64px;
  height: 64px;
  /* Keep the circular shape; shrink the glow rings proportionally */
  box-shadow:
    0 0 0 4px #1e0808,
    0 0 0 6px #120505,
    0 4px 12px rgba(0,0,0,0.7),
    0 0 20px rgba(239,68,68,0.08),
    inset 0 1px 2px rgba(255,255,255,0.08);
}

#app.map-open #ptt::before {
  font-size: 0.8rem;
  letter-spacing: 0.15em;
}

#app.map-open #ptt.recording {
  box-shadow:
    0 0 0 4px #3a0808,
    0 0 0 6px #200505,
    0 4px 12px rgba(0,0,0,0.7),
    0 0 30px rgba(239,68,68,0.5),
    inset 0 1px 2px rgba(255,255,255,0.1);
}

/* Hide the status text and mode toggle while the PTT is docked — not enough room */
#app.map-open #ptt-status,
#app.map-open #mode-toggle {
  display: none;
}
