:root {
  --bg: #020807;
  --card: #071a16;
  --text: #c4ffe2;
  --muted: #76b59a;
  --accent: #30ff90;
  --danger: #ff4d6d;
  --switch-off: #0f2c24;
  --switch-on: #18b367;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Consolas", "Courier New", monospace;
  background:
    linear-gradient(transparent 96%, #103c2e66 100%),
    linear-gradient(90deg, transparent 96%, #103c2e66 100%),
    radial-gradient(circle at top, #073126 0%, var(--bg) 60%);
  background-size: 24px 24px, 24px 24px, cover;
  color: var(--text);
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.container {
  width: 100%;
  max-width: 760px;
}

.card {
  background: var(--card);
  border: 1px solid #1f6a4f;
  border-radius: 14px;
  padding: 1.25rem;
  box-shadow: 0 0 24px #0f3d2c77, inset 0 0 20px #03140f;
}

h1 {
  margin-top: 0;
  color: var(--accent);
  text-shadow: 0 0 10px #30ff9060;
}

p {
  color: var(--muted);
}

form {
  display: grid;
  gap: 0.9rem;
  margin-top: 1rem;
}

label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.95rem;
}

input {
  border: 1px solid #1f6a4f;
  background: #03140f;
  color: var(--text);
  border-radius: 8px;
  padding: 0.6rem 0.7rem;
  font-size: 1rem;
}

button {
  border: none;
  border-radius: 8px;
  padding: 0.65rem 0.9rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--accent);
  color: #032012;
  box-shadow: 0 0 10px #30ff9060;
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.status-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin: 0.75rem 0 1rem;
}

.switch-board {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.75rem;
  margin-top: 0.3rem;
}

.lamp {
  height: 22px;
  width: 22px;
  border-radius: 999px;
  margin: 0 auto;
  background: #7f1d1d;
  border: 1px solid #fecaca55;
  box-shadow: 0 0 8px #7f1d1d;
  transition: background 0.2s ease, box-shadow 0.2s ease;
}

.lamp.on {
  background: #16a34a;
  box-shadow: 0 0 12px #22c55e;
}

.switch-unit {
  display: grid;
  justify-items: center;
  gap: 0.7rem;
  padding: 0.75rem;
  border: 1px solid #1f6a4f;
  border-radius: 12px;
  background: linear-gradient(180deg, #072019 0%, #041710 100%);
  box-shadow: inset 0 0 14px #022016;
}

.switch-label {
  font-size: 0.9rem;
  color: var(--muted);
}

.switch {
  width: 86px;
  height: 122px;
  border-radius: 14px;
  border: 1px solid #1f6a4f;
  background:
    linear-gradient(115deg, #24483a 0%, #122a22 24%, #0a1a15 49%, #16352a 74%, #264f3f 100%);
  position: relative;
  padding: 0;
  transition: box-shadow 0.2s ease, border-color 0.2s ease, transform 0.06s ease;
  box-shadow: inset 0 0 14px #00000088, 0 0 8px #0b2f2280;
}

.switch::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 16px;
  width: 12px;
  height: 60px;
  border-radius: 8px;
  background: linear-gradient(180deg, #edf7f2 0%, #9ab9ab 40%, #6f8e81 100%);
  transform-origin: 50% 85%;
  transform: translateX(-50%) rotate(-30deg);
  transition: transform 0.12s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 0 6px #7be0ae35;
}

.switch::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 16px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #f2fbf6 0%, #aec9bd 45%, #748f83 100%);
  transform: translateX(-50%);
  box-shadow: inset 0 0 6px #ffffff22, 0 0 7px #00000066;
}

.switch:active {
  transform: translateY(1px) scale(0.995);
}

.switch.on {
  border-color: #2bd17c;
  box-shadow: inset 0 0 14px #00000088, 0 0 14px #22c55e90;
}

.switch.on::before {
  transform: translateX(-50%) rotate(30deg);
}

.message {
  min-height: 1.35rem;
  margin: 0.85rem 0 0;
  font-weight: 600;
}

.message.error {
  color: var(--danger);
}

.message.success {
  color: var(--accent);
  text-shadow: 0 0 8px #30ff9040;
}

.victory {
  margin-top: 1rem;
  font-size: 1.1rem;
  color: var(--accent);
  font-weight: 700;
  text-shadow: 0 0 10px #30ff9080;
}

.hidden {
  display: none !important;
}

.lamp.error-flicker {
  background: #ff2f45;
  border-color: #ffd1d7;
  box-shadow: 0 0 16px #ff2f45;
  animation: redFlicker 0.12s steps(2, end) infinite;
}

@keyframes redFlicker {
  0% {
    opacity: 1;
    filter: brightness(1.2);
  }
  50% {
    opacity: 0.45;
    filter: brightness(0.8);
  }
  100% {
    opacity: 1;
    filter: brightness(1.15);
  }
}

/* Test button - skip level */
.skip-btn {
  margin-top: 1rem;
  padding: 0.5rem 1rem;
  background: #555;
  color: #fff;
  border: 1px dashed #999;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  opacity: 0.7;
}

.skip-btn:hover {
  opacity: 1;
  background: #666;
}

/* ========== Room Transition Doors ========== */

.room-transition {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 900;
  pointer-events: none;
}

.room-door {
  position: absolute;
  top: 0;
  width: 50%;
  height: 100%;
  background: linear-gradient(180deg, #1a1a1a 0%, #0a0a0a 100%);
  transition: transform 1.5s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: inset 0 0 50px rgba(0, 0, 0, 0.8);
}

.room-door::before {
  content: "";
  position: absolute;
  top: 0;
  width: 100%;
  height: 100%;
  background: 
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 80px,
      #252525 80px,
      #252525 82px
    );
}

.room-door::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 30px;
  height: 60px;
  background: linear-gradient(145deg, #444, #222);
  border-radius: 4px;
  transform: translateY(-50%);
  box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.5);
}

.room-door-left {
  left: 0;
  border-right: 3px solid #333;
  transform: translateX(0);
}

.room-door-left::after {
  right: 20px;
}

.room-door-right {
  right: 0;
  border-left: 3px solid #333;
  transform: translateX(0);
}

.room-door-right::after {
  left: 20px;
}

/* Doors opening animation */
.room-transition.doors-opening .room-door-left {
  transform: translateX(-100%);
}

.room-transition.doors-opening .room-door-right {
  transform: translateX(100%);
}

/* Doors closing animation */
.room-transition.doors-closing .room-door-left {
  transform: translateX(-100%);
  transition: none;
}

.room-transition.doors-closing .room-door-right {
  transform: translateX(100%);
  transition: none;
}

/* Room label */
.room-label {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 3rem;
  font-weight: bold;
  color: var(--accent);
  text-shadow: 0 0 30px #30ff90, 0 0 60px #30ff9080;
  letter-spacing: 5px;
  opacity: 0;
  transition: opacity 0.5s ease;
  z-index: 901;
}

.room-transition.doors-closed .room-label {
  opacity: 1;
}

.room-transition.doors-opening .room-label {
  opacity: 0;
  transition: opacity 0.3s ease;
}

/* ========== Victory Screen with Vault Animation ========== */

.victory-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background:
    linear-gradient(transparent 96%, #103c2e66 100%),
    linear-gradient(90deg, transparent 96%, #103c2e66 100%),
    radial-gradient(circle at top, #073126 0%, var(--bg) 60%);
  background-size: 24px 24px, 24px 24px, cover;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.vault-container {
  perspective: 1000px;
}

.vault-frame {
  position: relative;
  width: 400px;
  height: 320px;
  background: linear-gradient(145deg, #1a1a1a, #0d0d0d);
  border: 8px solid #333;
  border-radius: 12px;
  box-shadow: 
    0 0 60px rgba(48, 255, 144, 0.2),
    inset 0 0 30px rgba(0, 0, 0, 0.8);
  overflow: hidden;
}

/* Vault content (behind doors) */
.vault-content {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(180deg, #0f3d2c 0%, #071a16 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
}

.code-reveal {
  text-align: center;
  opacity: 0;
  transform: scale(0.8);
  transition: all 0.8s ease 1.5s;
}

.vault-opening .code-reveal {
  opacity: 1;
  transform: scale(1);
}

.stars {
  font-size: 2rem;
  margin-bottom: 0.5rem;
  animation: starPulse 1s ease-in-out infinite;
}

@keyframes starPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

.code-reveal h2 {
  color: var(--accent);
  font-size: 1.8rem;
  margin: 0 0 1rem;
  text-shadow: 0 0 20px #30ff90;
  letter-spacing: 3px;
}

.code-display {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-bottom: 1rem;
}

.code-digit {
  width: 60px;
  height: 80px;
  background: linear-gradient(180deg, #1a1a1a 0%, #0a0a0a 100%);
  border: 3px solid var(--accent);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
  font-weight: bold;
  color: var(--accent);
  text-shadow: 0 0 15px #30ff90;
  box-shadow: 
    0 0 20px rgba(48, 255, 144, 0.3),
    inset 0 0 15px rgba(48, 255, 144, 0.1);
  animation: digitGlow 1.5s ease-in-out infinite alternate;
}

.code-digit:nth-child(1) { animation-delay: 0s; }
.code-digit:nth-child(2) { animation-delay: 0.2s; }
.code-digit:nth-child(3) { animation-delay: 0.4s; }
.code-digit:nth-child(4) { animation-delay: 0.6s; }

@keyframes digitGlow {
  0% { box-shadow: 0 0 20px rgba(48, 255, 144, 0.3), inset 0 0 15px rgba(48, 255, 144, 0.1); }
  100% { box-shadow: 0 0 35px rgba(48, 255, 144, 0.6), inset 0 0 25px rgba(48, 255, 144, 0.2); }
}

.victory-text {
  color: var(--text);
  font-size: 1.1rem;
  margin: 0;
}

/* Vault doors */
.vault-door {
  position: absolute;
  top: 0;
  width: 50%;
  height: 100%;
  background: linear-gradient(145deg, #2a2a2a, #1a1a1a);
  z-index: 10;
  transition: transform 1.2s cubic-bezier(0.68, -0.55, 0.27, 1.55);
  transform-origin: left center;
  box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.5);
}

.vault-door-left {
  left: 0;
  transform-origin: left center;
  border-right: 4px solid #444;
}

.vault-door-right {
  right: 0;
  transform-origin: right center;
  border-left: 4px solid #444;
}

/* Door details */
.vault-detail {
  position: absolute;
  top: 50%;
  width: 60px;
  height: 60px;
  border: 4px solid #555;
  border-radius: 50%;
  transform: translateY(-50%);
  background: linear-gradient(145deg, #333, #222);
  box-shadow: inset 0 0 15px rgba(0, 0, 0, 0.8);
}

.vault-door-left .vault-detail {
  right: 20px;
}

.vault-door-right .vault-detail {
  left: 20px;
}

.vault-detail::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  background: #666;
  border-radius: 50%;
  transform: translate(-50%, -50%);
}

/* Door bolts */
.vault-bolts {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 25px;
}

.vault-door-left .vault-bolts {
  right: 8px;
}

.vault-door-right .vault-bolts {
  left: 8px;
}

.vault-bolts span {
  width: 8px;
  height: 30px;
  background: linear-gradient(90deg, #888, #555);
  border-radius: 2px;
}

/* Opening animation */
.vault-opening .vault-door-left {
  transform: perspective(800px) rotateY(-105deg);
}

.vault-opening .vault-door-right {
  transform: perspective(800px) rotateY(105deg);
}

/* Confetti */
.confetti-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: hidden;
  z-index: 1001;
}

.confetti {
  position: absolute;
  width: 10px;
  height: 10px;
  top: -20px;
  animation: confettiFall linear forwards;
  opacity: 0;
}

.vault-opening .confetti {
  opacity: 1;
}

@keyframes confettiFall {
  0% {
    transform: translateY(0) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translateY(100vh) rotate(720deg);
    opacity: 0;
  }
}

/* Responsive vault */
@media (max-width: 500px) {
  .vault-frame {
    width: 300px;
    height: 240px;
  }
  
  .code-digit {
    width: 45px;
    height: 60px;
    font-size: 2rem;
  }
  
  .code-reveal h2 {
    font-size: 1.3rem;
  }
}
