:root {
  color-scheme: dark;
  --bg: #0a0f1c;
  --bg-deep: #070b14;
  --amber: #ffbf3f;
  --amber-dim: #a07c35;
  --cream: #fff4d6;
  --cyan: #53e0ff;
  --cyan-pale: #d6f7ff;
  --red: #ff3048;
  --neon-red: #ff2e4d;
  --red-bright: #ff4a5e;
}

* { box-sizing: border-box; }
html { background: var(--bg-deep); }
body.gate {
  margin: 0;
  min-height: 100svh;
  background: var(--bg-deep);
  color: var(--amber);
  font-family: 'VT323', ui-monospace, monospace;
  overflow-x: hidden;
  position: relative;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Scene ---------- */
.gate-sky {
  position: fixed; inset: 0; pointer-events: none;
  background:
    radial-gradient(70% 38% at 50% 30%, rgba(255, 46, 77, .20), transparent 70%),
    radial-gradient(90% 30% at 50% 62%, rgba(83, 224, 255, .10), transparent 70%),
    linear-gradient(180deg, #05070f 0%, #0a0f1c 55%, #0b0716 100%);
}
.gate-floor {
  position: fixed; left: -50%; right: -50%; bottom: 0; height: 44vh;
  perspective: 280px; perspective-origin: 50% 0%;
  pointer-events: none; overflow: hidden;
  -webkit-mask-image: linear-gradient(180deg, transparent 0%, #000 40%);
          mask-image: linear-gradient(180deg, transparent 0%, #000 40%);
}
.gate-floor::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px;
  background: var(--neon-red);
  box-shadow: 0 0 12px var(--neon-red), 0 0 40px rgba(255, 46, 77, .8);
  opacity: .7;
}
.gate-grid {
  position: absolute; inset: 0 0 -60px 0;
  transform: rotateX(62deg); transform-origin: 50% 0;
  background-image:
    linear-gradient(rgba(255, 46, 77, .55) 2px, transparent 2px),
    linear-gradient(90deg, rgba(255, 46, 77, .45) 2px, transparent 2px);
  background-size: 60px 60px;
  animation: grid-run 2.4s linear infinite;
}
@keyframes grid-run { to { background-position: 0 60px; } }

.gate-scan {
  position: fixed; inset: 0; pointer-events: none; z-index: 3;
  background: repeating-linear-gradient(0deg, rgba(0, 0, 0, .26) 0 1px, transparent 1px 3px);
}
.gate-beam {
  position: fixed; left: 0; right: 0; top: -20vh; height: 18vh; pointer-events: none; z-index: 2;
  background: linear-gradient(180deg, transparent, rgba(83, 224, 255, .035) 60%, rgba(83, 224, 255, .12) 88%, transparent);
  animation: beam 7s cubic-bezier(.6, 0, .4, 1) infinite 1.6s;
  opacity: 0;
}
@keyframes beam {
  0% { transform: translateY(0); opacity: 0; }
  6% { opacity: 1; }
  40% { transform: translateY(130vh); opacity: 1; }
  41%, 100% { transform: translateY(130vh); opacity: 0; }
}

/* ---------- Status strip ---------- */
.gate-status {
  position: relative; z-index: 4;
  display: flex; justify-content: space-between; align-items: center;
  padding: calc(14px + env(safe-area-inset-top)) 18px 0;
  font-family: 'Silkscreen', monospace; font-size: 10px; letter-spacing: .14em;
  text-transform: uppercase; color: #4f6a78;
}
.gate-led { display: inline-flex; align-items: center; gap: 8px; color: #ff8a98; }
.gate-led i {
  width: 8px; height: 8px; border-radius: 50%; background: var(--neon-red);
  box-shadow: 0 0 6px var(--neon-red), 0 0 14px rgba(255, 46, 77, .8);
  animation: led 1.4s steps(1) infinite;
}
@keyframes led { 50% { opacity: .15; } }
.led-denied, .sign-denied, .press-denied { display: none; }

/* ---------- Sign ---------- */
.gate-main {
  position: relative; z-index: 4;
  width: min(100%, 26rem); margin: 0 auto;
  min-height: calc(100svh - 40px);
  display: flex; flex-direction: column; align-items: stretch;
  padding: 1vh 22px calc(20px + env(safe-area-inset-bottom));
}
.gate-sign {
  margin: 1vh 0 0; font: inherit; text-align: center; line-height: 1; position: relative;
  animation: ignite 1.5s linear both, buzz 7s 2s infinite;
}
.gate-sign::before {
  content: ''; position: absolute; left: 50%; top: 55%; width: 120%; height: 120%;
  transform: translate(-50%, -50%); pointer-events: none; z-index: -1;
  background: radial-gradient(closest-side, rgba(255, 46, 77, .16), transparent);
}
.gate-lock { display: block; width: 52px; height: 52px; margin: 0 auto 2px; }
.tube-glow { stroke: var(--cyan); stroke-width: 12; stroke-opacity: .28; }
.tube-core { stroke: var(--cyan-pale); stroke-width: 3.5; filter: drop-shadow(0 0 3px var(--cyan)) drop-shadow(0 0 10px rgba(83, 224, 255, .8)); }
.gate-script {
  display: block;
  font-family: 'Yellowtail', cursive; font-weight: 400;
  font-size: clamp(64px, 21vw, 92px);
  color: #ffe6e9;
  text-shadow: 0 0 2px #ff9aa8, 0 0 8px var(--red), 0 0 20px rgba(255, 46, 77, .85), 0 0 42px rgba(255, 46, 77, .55), 0 0 90px rgba(255, 46, 77, .35);
  transform: rotate(-5deg); margin: 0 0 6px -4px;
}
.gate-word {
  display: block; margin-top: 4px;
  font-family: 'Silkscreen', monospace; font-weight: 700; text-transform: uppercase;
  font-size: clamp(14px, 4.4vw, 18px); line-height: 1.55; letter-spacing: .3em; padding-left: .3em;
  color: #e8fbff;
  text-shadow: 0 0 4px var(--cyan), 0 0 14px var(--cyan), 0 0 30px rgba(83, 224, 255, .7);
}
@keyframes ignite {
  0%, 8% { opacity: .06; filter: saturate(0); }
  9%, 12% { opacity: 1; filter: none; }
  13%, 30% { opacity: .1; filter: saturate(0); }
  31%, 34% { opacity: .9; filter: none; }
  35%, 44% { opacity: .2; }
  45%, 100% { opacity: 1; }
}
@keyframes buzz {
  0%, 31%, 33.5%, 74%, 76%, 100% { opacity: 1; }
  32%, 75% { opacity: .55; }
  33% { opacity: .9; }
}

/* Neon keg: amber tubes, red tap handle; buzzes on its own schedule. */
.gate-keg {
  flex: 1 1 auto; min-height: 80px;
  display: flex; align-items: center; justify-content: center;
  padding: 10px 0 0;
}
.gate-keg svg { height: clamp(78px, 15vh, 150px); width: auto; overflow: visible; animation: ignite 1.8s .5s linear both, buzz 9s 4s infinite; }
.keg-body .tube-glow { stroke: var(--amber); stroke-width: 10; stroke-opacity: .26; }
.keg-body .tube-core { stroke: var(--cream); stroke-width: 3; filter: drop-shadow(0 0 3px var(--amber)) drop-shadow(0 0 12px rgba(255, 191, 63, .85)); }
.keg-tap .tube-glow { stroke: var(--neon-red); stroke-width: 10; stroke-opacity: .3; }
.keg-tap .tube-core { stroke: #ffe6e9; stroke-width: 3; filter: drop-shadow(0 0 3px var(--neon-red)) drop-shadow(0 0 12px rgba(255, 46, 77, .85)); }

/* ---------- Alert ---------- */
.gate-alert {
  margin: 20px 0 0; padding: 12px 14px;
  background: rgba(30, 3, 8, .82); border: 1.5px solid var(--red-bright); border-radius: 6px;
  box-shadow: 0 0 14px rgba(255, 74, 94, .45), inset 0 0 12px rgba(255, 74, 94, .14);
  color: #ffd6db; font-size: 21px; line-height: 1.1; text-transform: uppercase; text-align: center;
  animation: shake .5s cubic-bezier(.36, .07, .19, .97) both;
}
@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-7px); }
  40%, 60% { transform: translateX(7px); }
}

/* ---------- Panel ---------- */
.gate-panel {
  padding-top: 12px;
  display: flex; flex-direction: column; gap: 10px;
}
.gate-press {
  margin: 0 0 6px; text-align: center;
  font-size: 28px; line-height: 1; text-transform: uppercase; letter-spacing: .02em;
  color: var(--cream); text-shadow: 0 0 8px rgba(255, 191, 63, .8);
}
.gate-press i { font-style: normal; animation: led 1.1s steps(1) infinite; }
.gate-label {
  margin: 6px 0 0;
  font-family: 'Silkscreen', monospace; font-size: 11px; letter-spacing: .14em; text-transform: uppercase;
  color: var(--cyan);
}
.gate-lcd {
  width: 100%; height: 54px; padding: 0 16px;
  background: #050608; border: 0; border-radius: 6px;
  box-shadow: inset 0 0 0 1.5px rgba(83, 224, 255, .4);
  color: var(--cyan-pale); caret-color: var(--cyan);
  font-family: 'VT323', monospace; font-size: 28px; letter-spacing: .04em;
  transition: box-shadow .15s;
}
.gate-lcd:focus {
  outline: none;
  box-shadow: inset 0 0 0 2px var(--cyan), 0 0 16px rgba(83, 224, 255, .5);
  text-shadow: 0 0 6px rgba(83, 224, 255, .7);
}
.gate-go {
  margin-top: 10px; height: 60px; width: 100%;
  border: 0; border-radius: 999px; cursor: pointer;
  background: var(--red); color: #fff;
  font-family: 'Silkscreen', monospace; font-weight: 700; font-size: 17px; letter-spacing: .2em; text-transform: uppercase;
  text-shadow: 1px 1px 0 #6a0010;
  box-shadow: 0 0 8px rgba(255, 48, 72, .8), 0 0 22px rgba(255, 48, 72, .5), 0 0 60px rgba(255, 48, 72, .2);
  touch-action: manipulation;
  transition: transform .08s, background .15s;
}
.gate-go:hover, .gate-go:focus-visible { background: #ff5a6e; }
.gate-go:active { transform: scale(.97); }
.gate-go:focus-visible { outline: 2px solid var(--cream); outline-offset: 4px; }
/* ---------- Denied ---------- */
[data-state="denied"] .sign-ready,
[data-state="denied"] .press-ready,
[data-state="denied"] .led-ready { display: none; }
[data-state="denied"] .sign-denied,
[data-state="denied"] .press-denied,
[data-state="denied"] .led-denied { display: inline; }
[data-state="denied"] .gate-sign { animation: ignite 1s linear both, buzz 2.2s 1.2s infinite; }
[data-state="denied"] .gate-word {
  color: #26323d; text-shadow: none; /* dead tube */
}
[data-state="denied"] .tube-glow { stroke: var(--neon-red); }
[data-state="denied"] .tube-core { stroke: #ffd6dc; filter: drop-shadow(0 0 3px var(--neon-red)) drop-shadow(0 0 10px rgba(255, 46, 77, .8)); }
[data-state="denied"] .gate-led i { animation-duration: .4s; }
[data-state="denied"] .keg-body .tube-glow { stroke-opacity: .08; }
[data-state="denied"] .keg-body .tube-core { stroke: #3a3426; filter: none; }
[data-state="denied"] .gate-press { color: #ffd6db; text-shadow: 0 0 8px rgba(255, 74, 94, .9); }
[data-state="denied"] .gate-sky {
  background:
    radial-gradient(80% 45% at 50% 30%, rgba(255, 46, 77, .32), transparent 70%),
    linear-gradient(180deg, #0c0408 0%, #0a0f1c 55%, #12050b 100%);
}

@media (min-height: 860px) { .gate-sign { margin-top: 5vh; } }

@media (prefers-reduced-motion: reduce) {
  .gate-sign, .gate-keg svg, .gate-grid, .gate-beam, .gate-led i, .gate-press i, .gate-alert { animation: none !important; }
  .gate-beam { display: none; }
}
