:root {
  --bg: #050805;
  --bg-panel: rgba(6, 14, 8, 0.88);
  --green: #39ff14;
  --green-dim: #1f8f0c;
  --green-faint: rgba(57, 255, 20, 0.12);
  --red: #ff2e4d;
  --red-dim: #9e1a2f;
  --gold: #ffd166;
  --text: #c8ffc0;
  --muted: #5f8f58;
  --font-term: 'VT323', 'Share Tech Mono', ui-monospace, 'Courier New', monospace;
  --font-mono: 'Share Tech Mono', ui-monospace, 'Courier New', monospace;
}

* { box-sizing: border-box; }

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

body {
  padding: 16px;
  overflow-x: hidden;
}

::selection { background: var(--green); color: var(--bg); }

#matrix {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: -2;
  opacity: 0.22;
}

.scanlines {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 50;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0) 0px,
    rgba(0, 0, 0, 0) 2px,
    rgba(0, 0, 0, 0.18) 3px
  );
  mix-blend-mode: multiply;
}

.red { color: var(--red); }
.gold { color: var(--gold); }

/* ---------- Header ---------- */
.top {
  max-width: 1200px;
  margin: 0 auto 20px;
  text-align: center;
}

.banner {
  margin: 0 auto;
  color: var(--green);
  text-shadow: 0 0 6px rgba(57, 255, 20, 0.7);
  font-family: var(--font-mono);
  font-size: clamp(5px, 1.55vw, 15px);
  line-height: 1.15;
  overflow: hidden;
  display: inline-block;
  text-align: left;
}

.subtitle {
  font-family: var(--font-term);
  font-size: clamp(16px, 2.6vw, 24px);
  letter-spacing: 1px;
  margin: 10px 0 12px;
}

.glitch { position: relative; display: inline-block; }
.glitch::before,
.glitch::after {
  content: attr(data-text);
  position: absolute;
  left: 0; top: 0;
  opacity: 0.8;
}
.glitch::before { color: var(--green); animation: glitch 2.6s infinite steps(1); clip-path: inset(0 0 55% 0); }
.glitch::after  { color: var(--gold);  animation: glitch 3.1s infinite reverse steps(1); clip-path: inset(55% 0 0 0); }

@keyframes glitch {
  0%, 88%, 100% { transform: translate(0, 0); opacity: 0; }
  90% { transform: translate(-2px, 1px); opacity: 0.8; }
  93% { transform: translate(2px, -1px); opacity: 0.8; }
  96% { transform: translate(-1px, 0); opacity: 0.8; }
}

.statusbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 8px 24px;
  font-size: 14px;
  color: var(--muted);
}
.statusbar b { color: var(--green); font-weight: normal; }

.progressbar {
  max-width: 600px;
  height: 6px;
  margin: 12px auto 0;
  border: 1px solid var(--green-dim);
  background: rgba(0, 0, 0, 0.5);
}
#progress-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--green), var(--gold), var(--red));
  box-shadow: 0 0 8px var(--green);
  transition: width 0.8s ease;
}

.btn-ghost {
  font: inherit;
  color: var(--green);
  background: transparent;
  border: 1px solid transparent;
  padding: 4px 8px;
  cursor: pointer;
}
.btn-ghost:hover, .btn-ghost:focus-visible { border-color: var(--green); outline: none; }

/* ---------- Grid ---------- */
.grid {
  max-width: 1200px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 14px;
}

@media (max-width: 900px) { .grid { grid-template-columns: repeat(4, 1fr); } }
@media (max-width: 560px) { .grid { grid-template-columns: repeat(3, 1fr); gap: 10px; } }

.door {
  position: relative;
  aspect-ratio: 1 / 1.1;
  padding: 10px;
  border: 1px solid var(--green-dim);
  background: var(--bg-panel);
  color: var(--text);
  font: inherit;
  text-align: left;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  cursor: pointer;
  overflow: hidden;
  transition: transform 0.15s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}
.door:hover, .door:focus-visible { transform: translateY(-2px); outline: none; }

/* corner brackets */
.door::before, .door::after {
  content: '';
  position: absolute;
  width: 12px; height: 12px;
  border-color: currentColor;
  border-style: solid;
  opacity: 0.8;
}
.door::before { top: 4px; left: 4px; border-width: 2px 0 0 2px; }
.door::after { bottom: 4px; right: 4px; border-width: 0 2px 2px 0; }

.door-num {
  font-family: var(--font-term);
  font-size: clamp(34px, 5vw, 56px);
  line-height: 1;
}
.door-label {
  font-size: clamp(9px, 1.1vw, 12px);
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.door-sub {
  font-family: var(--font-term);
  font-size: clamp(13px, 1.6vw, 18px);
  min-height: 1.2em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.door-icon {
  position: absolute;
  top: 8px; right: 10px;
  font-size: clamp(14px, 2vw, 20px);
}

.door.locked {
  color: var(--muted);
  border-color: #1d2d1a;
  border-style: dashed;
}
.door.locked .door-num { color: #2d4a28; }
.door.locked .door-label { animation: flicker 4s infinite; }

.door.ready {
  color: var(--green);
  border-color: var(--green);
  animation: pulse 2s ease-in-out infinite;
}
.door.ready .door-num { text-shadow: 0 0 10px var(--green); }

.door.solved {
  color: var(--gold);
  border-color: var(--red);
  background:
    linear-gradient(135deg, rgba(255, 46, 77, 0.16), rgba(255, 209, 102, 0.06)),
    var(--bg-panel);
}
.door.solved .door-num { color: var(--red); text-shadow: 0 0 10px rgba(255, 46, 77, 0.7); }


@keyframes pulse {
  0%, 100% { box-shadow: 0 0 4px rgba(57, 255, 20, 0.3), inset 0 0 0 rgba(57, 255, 20, 0); }
  50% { box-shadow: 0 0 18px rgba(57, 255, 20, 0.55), inset 0 0 18px rgba(57, 255, 20, 0.12); }
}
@keyframes flicker {
  0%, 92%, 100% { opacity: 1; }
  93% { opacity: 0.3; }
  95% { opacity: 0.9; }
  96% { opacity: 0.2; }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

/* ---------- Syslog ---------- */
.syslog {
  max-width: 1200px;
  margin: 24px auto 0;
  border-top: 1px solid var(--green-dim);
  padding-top: 8px;
  font-size: 12px;
  color: var(--muted);
}
.syslog-title { color: var(--green-dim); margin-bottom: 4px; }
.syslog ol {
  list-style: none;
  margin: 0;
  padding: 0;
  height: 7.5em;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}
.syslog li { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.25em; }
.syslog li .ok { color: var(--green); }
.syslog li .fail { color: var(--red); }

/* ---------- Terminal ---------- */
.terminal {
  width: min(760px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 0;
  border: 1px solid var(--green);
  background: #020402;
  color: var(--green);
  box-shadow: 0 0 40px rgba(57, 255, 20, 0.25), 0 0 0 1px rgba(0, 0, 0, 0.6);
  font-family: var(--font-term);
  font-size: 21px;
  overflow: hidden;
}
.terminal::backdrop {
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(2px);
}
.terminal[open] { display: flex; flex-direction: column; animation: crt-on 0.25s ease-out; }

@keyframes crt-on {
  0% { transform: scale(1, 0.02); filter: brightness(3); }
  60% { transform: scale(1, 1.02); }
  100% { transform: scale(1, 1); filter: brightness(1); }
}

.term-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px;
  background: var(--green-faint);
  border-bottom: 1px solid var(--green-dim);
  font-family: var(--font-mono);
  font-size: 13px;
}
.term-bar #term-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dots i {
  display: inline-block;
  width: 10px; height: 10px;
  margin-right: 4px;
  border-radius: 50%;
  background: var(--red);
}
.dots i:nth-child(2) { background: var(--gold); }
.dots i:nth-child(3) { background: var(--green); }

.term-body {
  padding: 14px 16px 18px;
  overflow-y: auto;
  min-height: 300px;
  text-shadow: 0 0 4px rgba(57, 255, 20, 0.6);
}

.term-output p {
  margin: 0 0 4px;
  white-space: pre-wrap;
  word-break: break-word;
}
.term-output .dim { color: var(--muted); text-shadow: none; }
.term-output .story { color: var(--text); }
.term-output .hint { color: var(--gold); text-shadow: 0 0 4px rgba(255, 209, 102, 0.5); }
.term-output .err { color: var(--red); text-shadow: 0 0 6px rgba(255, 46, 77, 0.6); }
.term-output .ok { color: var(--green); }
.term-output .big {
  font-size: 1.6em;
  letter-spacing: 2px;
  margin: 8px 0;
}
.term-output .echo { color: var(--text); }

.term-media img,
.term-media audio,
.term-media video {
  display: block;
  max-width: 100%;
  max-height: 260px;
  margin: 10px 0;
  border: 1px solid var(--green-dim);
}

.prompt {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  margin-top: 10px;
  cursor: text;
}
.ps1 { color: var(--red); margin-right: 10px; text-shadow: 0 0 6px rgba(255, 46, 77, 0.6); cursor: text; }
.typed { color: var(--text); white-space: pre; }
.cursor {
  display: inline-block;
  width: 0.6em;
  height: 1em;
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
  vertical-align: text-bottom;
  animation: blink 1s steps(1) infinite;
}
.prompt input {
  position: absolute;
  inset: 0;
  width: 100%;
  opacity: 0;
  font-size: 16px; /* avoid iOS zoom */
  border: 0;
  background: transparent;
  color: transparent;
  caret-color: transparent;
}
.prompt.disabled { opacity: 0.35; }
.prompt.disabled .cursor { animation: none; background: var(--muted); box-shadow: none; }

@keyframes blink { 50% { opacity: 0; } }

.lockout {
  margin: 14px 0 6px;
  padding: 12px;
  border: 1px solid var(--red);
  background: rgba(255, 46, 77, 0.08);
  color: var(--red);
  text-shadow: 0 0 6px rgba(255, 46, 77, 0.6);
  animation: alarm 1s ease-in-out infinite;
}
.lockout-msg { margin-bottom: 6px; }
.lockout-timer { font-size: 2.4em; text-align: center; line-height: 1; }
.lockout-bar { height: 6px; margin-top: 8px; background: rgba(255, 46, 77, 0.2); }
#lockout-fill { height: 100%; width: 100%; background: var(--red); transition: width 0.25s linear; }

@keyframes alarm {
  0%, 100% { box-shadow: 0 0 0 rgba(255, 46, 77, 0); }
  50% { box-shadow: 0 0 20px rgba(255, 46, 77, 0.5); }
}

.term-body.shake { animation: shake 0.4s; }
.terminal.success { box-shadow: 0 0 60px rgba(255, 209, 102, 0.5); border-color: var(--gold); }

/* ---------- Snow burst on success ---------- */
.flake {
  position: fixed;
  top: -20px;
  z-index: 100;
  pointer-events: none;
  color: var(--gold);
  font-size: 18px;
  animation: fall linear forwards;
}
@keyframes fall {
  to { transform: translateY(110vh) rotate(360deg); opacity: 0.2; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
  #matrix { display: none; }
}
