:root {
  --bg: #03030c;
  --panel: rgba(8, 6, 20, 0.88);
  --line: #2e1d52;
  --line-glow: rgba(0, 240, 255, 0.25);
  --text: #00f0ff;
  --muted: #625088;
  --up: #00ffcc;
  --down: #ff0055;
  --accent: #00f0ff;
  --yellow: #ffcc00;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: 'Share Tech Mono', monospace;
  font-size: 13px;
  line-height: 1.4;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

/* ---------------------------------------------------------------- CRT Overlay Effects */
#stage {
  position: fixed;
  inset: 0;
}
#stage canvas {
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

/* Radial Vignette */
#stage::before {
  content: " ";
  display: block;
  position: absolute;
  inset: 0;
  background: radial-gradient(circle, rgba(3, 3, 12, 0) 50%, rgba(3, 3, 12, 0.6) 80%, rgba(1, 1, 5, 0.95) 100%);
  z-index: 5;
  pointer-events: none;
}

/* Scanlines and screen flicker */
#stage::after {
  content: " ";
  display: block;
  position: absolute;
  inset: 0;
  background: linear-gradient(
    rgba(18, 16, 16, 0) 50%, 
    rgba(0, 0, 0, 0.28) 50%
  );
  background-size: 100% 4px;
  z-index: 6;
  pointer-events: none;
  opacity: 0.95;
  animation: crt-flicker 0.15s infinite alternate;
}

@keyframes crt-flicker {
  0% { opacity: 0.94; }
  50% { opacity: 0.98; }
  100% { opacity: 0.95; }
}

/* ---------------------------------------------------------------- banner */
#banner {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 16px;
  padding-top: calc(8px + env(safe-area-inset-top, 0px));
  padding-left: calc(16px + env(safe-area-inset-left, 0px));
  padding-right: calc(16px + env(safe-area-inset-right, 0px));
  background: rgba(3, 3, 12, 0.75);
  border-bottom: 1px solid rgba(46, 29, 82, 0.6);
  backdrop-filter: blur(8px);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: 'Orbitron', sans-serif;
  font-weight: 900;
  letter-spacing: 1.5px;
  font-size: 16px;
  color: #fff;
  text-shadow: 0 0 8px var(--accent);
}
.brand .thin { color: var(--accent); font-weight: 400; }
.brand .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--up);
  box-shadow: 0 0 10px 2px var(--up);
  animation: pulse-dot 1.5s infinite alternate;
}

@keyframes pulse-dot {
  from { opacity: 0.4; box-shadow: 0 0 4px 1px var(--up); }
  to { opacity: 1; box-shadow: 0 0 12px 3px var(--up); }
}

#examples {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  touch-action: pan-x;
}
#examples::-webkit-scrollbar { display: none; }

.ex {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 12px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: rgba(20, 15, 38, 0.7);
  color: var(--muted);
  font-family: 'Share Tech Mono', monospace;
  font-size: 12px;
  white-space: nowrap;
  cursor: pointer;
  transition: all .2s ease;
  box-shadow: inset 0 0 4px rgba(0, 0, 0, 0.4);
}
.ex:hover:not(:disabled) {
  color: var(--accent);
  border-color: var(--accent);
  background: rgba(0, 240, 255, 0.08);
  box-shadow: 0 0 10px rgba(0, 240, 255, 0.2), inset 0 0 4px rgba(0, 240, 255, 0.08);
}
.ex.active {
  color: #fff;
  border-color: var(--accent);
  background: rgba(0, 240, 255, 0.18);
  box-shadow: 0 0 12px rgba(0, 240, 255, 0.4), inset 0 0 6px rgba(0, 240, 255, 0.2);
  text-shadow: 0 0 5px #fff;
}
.ex:disabled { opacity: .3; cursor: default; }
.ex em {
  font-style: normal; font-size: 9px; letter-spacing: .06em;
  text-transform: uppercase; color: #a3003b;
  border: 1px solid #7d002d; border-radius: 2px; padding: 1px 4px;
  text-shadow: none;
}

.meta { 
  margin-left: auto; 
  color: var(--muted); 
  font-size: 11px; 
  letter-spacing: 0.5px;
  white-space: nowrap; 
}

/* ---------------------------------------------------------------- HUD Corner Decorations */
.hud-corner {
  position: fixed;
  width: 18px;
  height: 18px;
  border: 2px solid var(--accent);
  z-index: 9;
  pointer-events: none;
  filter: drop-shadow(0 0 5px var(--accent));
  opacity: 0.85;
}
.top-left { top: 62px; left: 16px; border-right: none; border-bottom: none; }
.top-right { top: 62px; right: 16px; border-left: none; border-bottom: none; }
.bottom-left { bottom: 56px; left: 16px; border-right: none; border-top: none; }
.bottom-right { bottom: 56px; right: 16px; border-left: none; border-top: none; }

/* ---------------------------------------------------------------- Telemetry Overlay */
#telemetry {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(38px + env(safe-area-inset-bottom, 0px));
  background: rgba(3, 3, 12, 0.75);
  border-top: 1px solid rgba(46, 29, 82, 0.6);
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 0 calc(16px + env(safe-area-inset-right, 0px)) env(safe-area-inset-bottom, 0px) calc(16px + env(safe-area-inset-left, 0px));
  backdrop-filter: blur(10px);
}
.ex-log {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: rgba(20, 15, 38, 0.8);
  color: var(--accent);
  font-family: 'Share Tech Mono', monospace;
  font-size: 10px;
  cursor: pointer;
  box-shadow: inset 0 0 4px rgba(0, 0, 0, 0.4);
  transition: all 0.2s ease;
  user-select: none;
  -webkit-user-select: none;
}
.ex-log:hover, .ex-log.active {
  color: #fff;
  border-color: var(--accent);
  background: rgba(0, 240, 255, 0.15);
  box-shadow: 0 0 10px rgba(0, 240, 255, 0.3);
}
@media (min-width: 769px) {
  .ex-log {
    display: none;
  }
}
.tel-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11.5px;
  letter-spacing: 0.5px;
}
.tel-item .label {
  color: var(--muted);
}
.tel-item .val {
  color: var(--accent);
  font-weight: bold;
  text-shadow: 0 0 6px rgba(0, 240, 255, 0.6);
}
.tel-item .val.pulse {
  color: var(--up);
  text-shadow: 0 0 6px rgba(0, 255, 204, 0.6);
  animation: pulse-online 1s infinite alternate;
}
@keyframes pulse-online {
  from { opacity: 0.7; }
  to { opacity: 1; }
}

/* ---------------------------------------------------------------- Diagnostic Log Panel */
#log-box {
  position: fixed;
  bottom: calc(56px + env(safe-area-inset-bottom, 0px));
  right: calc(16px + env(safe-area-inset-right, 0px));
  width: 250px;
  height: 150px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-top: 3px solid var(--accent);
  border-radius: 2px;
  z-index: 8;
  display: flex;
  flex-direction: column;
  box-shadow: 0 0 15px rgba(0, 0, 0, 0.5), inset 0 0 8px rgba(46, 29, 82, 0.3);
  backdrop-filter: blur(6px);
  transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.3s ease, border-top-color 0.25s ease;
}
.log-header {
  padding: 4px 8px;
  background: rgba(46, 29, 82, 0.4);
  border-bottom: 1px solid var(--line);
  font-family: 'Orbitron', sans-serif;
  font-size: 10px;
  font-weight: bold;
  letter-spacing: 1px;
  color: #fff;
}
.log-content {
  flex: 1;
  padding: 8px;
  overflow-y: auto;
  font-size: 10.5px;
  color: var(--muted);
  scrollbar-width: none;
  touch-action: pan-y;
}
.log-content::-webkit-scrollbar { display: none; }
.log-content div {
  margin-bottom: 5px;
  word-break: break-all;
  animation: log-fade-in 0.2s ease-out;
}
.log-content div.log-info {
  color: var(--accent);
}
.log-content div.log-alert {
  color: var(--yellow);
  text-shadow: 0 0 4px rgba(255, 204, 0, 0.4);
}
.log-content div.log-success {
  color: var(--up);
  text-shadow: 0 0 4px rgba(0, 255, 204, 0.4);
}
@keyframes log-fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

/* ---------------------------------------------------------------- chrome overlay */
#back {
  position: fixed;
  top: calc(72px + env(safe-area-inset-top, 0px));
  right: calc(20px + env(safe-area-inset-right, 0px));
  z-index: 12;
  padding: 8px 16px;
  border: 2px solid var(--down);
  border-radius: 2px;
  background: rgba(255, 0, 85, 0.12);
  color: #fff;
  font-family: 'Orbitron', sans-serif;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 1.5px;
  cursor: pointer;
  backdrop-filter: blur(8px);
  box-shadow: 0 0 12px rgba(255, 0, 85, 0.3), inset 0 0 6px rgba(255, 0, 85, 0.15);
  transition: all .2s ease;
  animation: pop .28s cubic-bezier(.2,.9,.3,1.3);
}
#back:hover {
  background: rgba(255, 0, 85, 0.28);
  box-shadow: 0 0 18px rgba(255, 0, 85, 0.6), inset 0 0 10px rgba(255, 0, 85, 0.3);
  text-shadow: 0 0 5px #fff;
}

@keyframes pop {
  from { opacity: 0; transform: translateY(-8px) scale(.92); }
  to   { opacity: 1; transform: none; }
}

#crumb {
  position: fixed;
  top: calc(72px + env(safe-area-inset-top, 0px));
  left: calc(20px + env(safe-area-inset-left, 0px));
  /* reserve room for the ABORT button on the same row — the crumb used to run
     underneath it (and #back has the higher z-index, so it drew on top) */
  right: calc(180px + env(safe-area-inset-right, 0px));
  max-width: max-content;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  z-index: 11;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  background: var(--panel);
  color: #fff;
  font-family: 'Share Tech Mono', monospace;
  font-size: 12px;
  letter-spacing: 0.5px;
  border-radius: 2px;
  box-shadow: 0 0 12px rgba(0, 240, 255, 0.15);
  animation: pop .3s ease-out;
}

#hint {
  position: fixed;
  bottom: calc(56px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 11;
  padding: 6px 16px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: var(--panel);
  color: var(--muted);
  font-family: 'Share Tech Mono', monospace;
  font-size: 11px;
  letter-spacing: 0.5px;
  white-space: nowrap;
  max-width: calc(100vw - 32px);
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: 0 0 15px rgba(0, 0, 0, 0.4);
}

#tip {
  position: fixed;
  z-index: 13;
  transform: translate(14px, -50%);
  pointer-events: none;
  display: grid;
  gap: 3px;
  padding: 10px 14px;
  min-width: 175px;
  border: 1px solid var(--accent);
  border-radius: 2px;
  background: rgba(5, 4, 12, 0.95);
  box-shadow: 0 0 18px rgba(0, 240, 255, 0.4), inset 0 0 8px rgba(0, 240, 255, 0.1);
  font-family: 'Share Tech Mono', monospace;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  backdrop-filter: blur(5px);
}
#tip b {
  color: #fff;
  font-size: 12px;
  margin-bottom: 6px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 4px;
}
#tip span { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); }
#tip i { font-style: normal; color: var(--accent); text-shadow: 0 0 4px rgba(0, 240, 255, 0.5); }

/* ---------------------------------------------------------------- 3D labels */
#labels { position: fixed; inset: 0; pointer-events: none; z-index: 9; }
.lab {
  position: absolute;
  top: 0; left: 0;
  font-family: 'Share Tech Mono', monospace;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  white-space: nowrap;
  transition: opacity .12s linear;
}
.lab.ref { 
  color: var(--yellow); 
  font-weight: bold; 
  font-size: 11.5px;
  text-shadow: 0 0 5px rgba(255, 204, 0, 0.5);
}

@media (max-width: 768px) {
  #stage::after {
    animation: none; /* Disable screen flicker on mobile to save CPU/GPU repaint cost */
    opacity: 0.4;
  }
  /* No room to sit beside ABORT on a phone — give the crumb its own row under it
     so the whole block/time readout stays legible instead of being clipped. */
  #crumb {
    top: calc(112px + env(safe-area-inset-top, 0px));
    right: calc(12px + env(safe-area-inset-right, 0px));
    left: calc(12px + env(safe-area-inset-left, 0px));
    font-size: 10.5px;
    padding: 5px 9px;
  }
  #back {
    top: calc(66px + env(safe-area-inset-top, 0px));
    right: calc(12px + env(safe-area-inset-right, 0px));
    padding: 10px 14px; /* >=44px touch target */
  }
  #log-box {
    display: flex;
    position: fixed;
    bottom: calc(48px + env(safe-area-inset-bottom, 0px));
    right: calc(12px + env(safe-area-inset-right, 0px));
    left: calc(12px + env(safe-area-inset-left, 0px));
    width: auto;
    height: 140px;
    transform: translateY(200px); /* start hidden below screen */
    opacity: 0;
    pointer-events: none;
    z-index: 15; /* overlay above navigation elements */
  }
  #log-box.open {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
  }
  .hud-corner { display: none; }
  #telemetry { justify-content: space-between; font-size: 10px; }
  .tel-item { gap: 4px; }
  .tel-item:nth-child(3), .tel-item:nth-child(4) { display: none; } /* Hide temp & latency on mobile */
  .meta { display: none; }
  #hint {
    font-size: 10px;
    bottom: calc(52px + env(safe-area-inset-bottom, 0px));
  }
  #banner { gap: 10px; }
  
  #tip {
    position: fixed !important;
    left: 50% !important;
    top: auto !important;
    bottom: calc(52px + env(safe-area-inset-bottom, 0px)) !important;
    transform: translateX(-50%) !important;
    width: calc(100vw - 24px) !important;
    max-width: 360px !important;
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: wrap !important;
    justify-content: space-between !important;
    gap: 6px !important;
    padding: 8px 12px !important;
    font-size: 10px !important;
  }
  #tip b {
    width: 100% !important;
    margin-bottom: 2px !important;
    padding-bottom: 2px !important;
    font-size: 10px !important;
    border-bottom: 1px solid var(--line) !important;
  }
  #tip span {
    display: flex !important;
    justify-content: space-between !important;
    gap: 4px !important;
    font-size: 10px !important;
    color: var(--muted) !important;
  }
  #tip i {
    font-size: 10px !important;
  }
}
