:root {
  --bg: #000814;
  --grid: #0a2a1a;
  --neon: #00ff9c;
  --neon-dim: #00b86b;
  --danger: #ff2a4d;
  --text: #c8ffe6;
  --terminal-amber: #ffb000;

  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --font-display: 'Orbitron', var(--font-mono);

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

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

[hidden] {
  display: none !important;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-mono);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body {
  position: fixed;
  inset: 0;
  font-size: clamp(0.9rem, 2.4vw, 1.05rem);
  line-height: 1.4;
}

button {
  font-family: inherit;
  color: inherit;
  background: transparent;
  border: 0;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
}

button:focus {
  outline: none;
}

.bg-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}

.screen {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-rows: auto 1fr auto;
  width: 100%;
  height: 100dvh;
  padding:
    calc(var(--safe-top) + clamp(0.75rem, 2.5vh, 1.5rem))
    calc(var(--safe-right) + clamp(1rem, 4vw, 2rem))
    calc(var(--safe-bottom) + clamp(0.75rem, 2.5vh, 1.5rem))
    calc(var(--safe-left) + clamp(1rem, 4vw, 2rem));
}

.hud-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  font-size: clamp(0.8rem, 2.2vw, 1.2rem);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.hud-status {
  display: inline-flex;
  align-items: center;
  gap: 0.6em;
  color: var(--neon);
}

.status-dot {
  display: inline-block;
  width: 0.6em;
  height: 0.6em;
  border-radius: 50%;
  background: var(--neon);
  box-shadow: 0 0 6px var(--neon), 0 0 14px var(--neon);
  animation: blink 1.4s steps(2, end) infinite;
}

.hud-node {
  display: inline-flex;
  align-items: baseline;
  gap: 0.4em;
  color: var(--text);
}

.hud-node-label {
  color: var(--neon-dim);
}

.hud-node-value {
  color: var(--neon);
  font-weight: 700;
  text-shadow: 0 0 6px rgba(0, 255, 156, 0.55);
}

.stage {
  position: relative;
  min-height: 0;
  width: 100%;
  height: 100%;
}

.panel {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(1rem, 3.5vh, 2.5rem);
  text-align: center;
  min-height: 0;
}

body[data-state='idle'] .panel-idle,
body[data-state='requesting-camera'] .panel-scan,
body[data-state='scanning'] .panel-scan,
body[data-state='granted'] .panel-granted,
body[data-state='cooldown'] .panel-cooldown,
body[data-state='error'] .panel-error {
  display: flex;
}

.reticle {
  color: var(--neon);
  width: clamp(240px, 60vw, 560px);
  max-width: 100%;
  aspect-ratio: 1 / 1;
  filter: drop-shadow(0 0 14px rgba(0, 255, 156, 0.45));
}

.reticle-svg {
  width: 100%;
  height: 100%;
  display: block;
}

.terminal {
  margin: 0;
  font-family: var(--font-mono);
  font-size: clamp(0.85rem, 2.4vw, 1.15rem);
  line-height: 1.6;
  color: var(--text);
  text-align: left;
  white-space: pre-wrap;
  max-width: min(90vw, 560px);
  min-height: 5.4em;
  letter-spacing: 0.02em;
  text-shadow: 0 0 6px rgba(0, 255, 156, 0.25);
}

.terminal .cursor {
  display: inline-block;
  width: 0.55em;
  height: 1.05em;
  vertical-align: -0.15em;
  background: var(--neon);
  margin-left: 0.1em;
  box-shadow: 0 0 6px var(--neon);
  animation: blink 0.9s steps(2, end) infinite;
}

.cmd-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.6em;
  min-height: 56px;
  min-width: 44px;
  padding: 0.8rem clamp(1rem, 3vw, 1.6rem);
  font-family: var(--font-mono);
  font-size: clamp(1rem, 2.6vw, 1.2rem);
  font-weight: 700;
  letter-spacing: 0.18em;
  color: var(--neon);
  border: 1px solid var(--neon);
  background: rgba(0, 255, 156, 0.04);
  box-shadow:
    0 0 0 1px rgba(0, 255, 156, 0.15) inset,
    0 0 14px rgba(0, 255, 156, 0.25),
    0 0 28px rgba(0, 255, 156, 0.15);
  text-shadow: 0 0 8px rgba(0, 255, 156, 0.6);
  transition: transform 80ms ease-out, box-shadow 160ms ease-out, background-color 160ms ease-out;
}

.cmd-btn:active,
.cmd-btn.is-pressed {
  transform: translateY(1px) scale(0.99);
  background: rgba(0, 255, 156, 0.12);
  box-shadow:
    0 0 0 1px rgba(0, 255, 156, 0.4) inset,
    0 0 22px rgba(0, 255, 156, 0.5);
}

.cmd-btn-bracket {
  opacity: 0.7;
}

.hud-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(0.6rem, 1.6vw, 0.78rem);
  letter-spacing: 0.32em;
  color: var(--neon-dim);
  text-transform: uppercase;
  opacity: 0.85;
}

.dev-badge {
  position: fixed;
  top: calc(var(--safe-top) + 0.4rem);
  left: calc(var(--safe-left) + 0.5rem);
  z-index: 5;
  padding: 0.25rem 0.5rem;
  font-family: var(--font-mono);
  font-size: clamp(0.6rem, 1.6vw, 0.75rem);
  letter-spacing: 0.2em;
  color: var(--terminal-amber);
  border: 1px solid var(--terminal-amber);
  background: rgba(255, 176, 0, 0.06);
  text-transform: uppercase;
  pointer-events: none;
}

@keyframes blink {
  0%, 50% { opacity: 1; }
  50.01%, 100% { opacity: 0; }
}
