:root {
  --bg-1: #070910;
  --bg-2: #0e1422;
  --bg-3: #131f30;
  --neon-cyan: #52f0ff;
  --neon-pink: #ff5ecf;
  --neon-lime: #77ff9f;
  --ink: #d9e7ff;
  --muted: #88a2c6;
  --panel: rgba(9, 14, 25, 0.84);
  --line: rgba(119, 211, 255, 0.34);
  --ratio-w: 4;
  --ratio-h: 5;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
}

body {
  min-height: 100dvh;
  font-family: 'Silkscreen', 'Noto Sans KR', sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 15%, rgba(80, 0, 160, 0.28), transparent 24%),
    radial-gradient(circle at 88% 8%, rgba(0, 190, 255, 0.24), transparent 26%),
    linear-gradient(165deg, var(--bg-1) 0%, var(--bg-2) 45%, var(--bg-3) 100%);
  overflow: hidden;
}

#viewport {
  position: relative;
  width: 100vw;
  height: 100dvh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.ambient {
  position: absolute;
  top: 0;
  bottom: 0;
  width: min(28vw, 260px);
  pointer-events: none;
  background-image:
    linear-gradient(transparent 0 47%, rgba(76, 205, 255, 0.16) 50%, transparent 53%),
    linear-gradient(90deg, transparent 0 47%, rgba(255, 109, 214, 0.13) 50%, transparent 53%);
  background-size: 22px 22px;
  opacity: 0.5;
}

.ambient.left {
  left: 0;
  border-right: 1px solid rgba(119, 211, 255, 0.22);
}

.ambient.right {
  right: 0;
  border-left: 1px solid rgba(255, 112, 204, 0.22);
}

#machineWrap {
  position: relative;
  z-index: 1;
  width: min(98vw, calc((100dvh - 96px) * 0.8));
  height: auto;
  max-height: 100dvh;
  align-self: center;
  justify-self: center;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 10px;
}

.panel {
  border: 3px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  backdrop-filter: blur(4px);
  box-shadow:
    0 0 0 1px rgba(31, 116, 164, 0.2) inset,
    0 10px 32px rgba(0, 0, 0, 0.35);
}

.neon {
  box-shadow:
    0 0 0 3px rgba(103, 230, 255, 0.24) inset,
    0 0 24px rgba(58, 210, 255, 0.26),
    0 10px 32px rgba(0, 0, 0, 0.45);
}

#topBar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  gap: 12px;
}

.brand-kicker {
  margin: 0;
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  color: #8ec3ff;
  letter-spacing: 0.08em;
}

h1 {
  margin: 6px 0 0;
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(14px, 2.6vw, 20px);
  color: #b6eeff;
  text-shadow: 0 0 12px rgba(82, 240, 255, 0.64);
}

.top-actions {
  display: flex;
  gap: 8px;
}

.pixel-btn {
  border: 3px solid rgba(117, 214, 255, 0.58);
  background: rgba(11, 27, 43, 0.88);
  color: #b9eaff;
  border-radius: 10px;
  padding: 8px 10px;
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  cursor: pointer;
}

.pixel-btn:hover {
  background: rgba(22, 46, 74, 0.92);
}

.pixel-btn.primary {
  border-color: rgba(255, 130, 225, 0.7);
  background: rgba(52, 15, 52, 0.92);
  color: #ffd5f4;
}

#gameShell {
  position: relative;
  aspect-ratio: var(--ratio-w) / var(--ratio-h);
  width: 100%;
  min-height: 0;
  border-radius: 18px;
  overflow: hidden;
  border: 6px solid rgba(81, 221, 255, 0.44);
  background: rgba(6, 10, 18, 0.9);
  box-shadow:
    0 0 0 6px rgba(30, 95, 131, 0.4) inset,
    0 0 38px rgba(64, 218, 255, 0.26),
    0 24px 58px rgba(0, 0, 0, 0.52);
}

#phaserHost,
#phaserHost canvas {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
}

#hudLayer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: block;
  padding: 10px;
}

#statusToast {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  width: fit-content;
  max-width: min(88%, 740px);
  border: 3px solid rgba(106, 222, 255, 0.58);
  border-radius: 999px;
  background: linear-gradient(120deg, rgba(6, 18, 32, 0.92), rgba(10, 31, 52, 0.9));
  box-shadow:
    0 0 18px rgba(83, 233, 255, 0.3),
    0 8px 24px rgba(0, 0, 0, 0.32);
  padding: 9px 14px;
  z-index: 28;
  display: flex;
  align-items: center;
  gap: 12px;
}

.status-label {
  margin: 0;
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(10px, 1.8vw, 12px);
  color: #d7f8ff;
  text-shadow: 0 0 10px rgba(90, 244, 255, 0.48);
  white-space: nowrap;
}

.status-hint {
  margin: 0;
  font-size: clamp(10px, 1.9vw, 12px);
  color: #9ab9df;
  line-height: 1.45;
}

.status-mini {
  margin: 0;
  font-size: 11px;
  color: #8af0ca;
  white-space: nowrap;
}

#historyList {
  list-style: none;
  margin: 0;
  padding: 8px;
  overflow: auto;
  display: grid;
  gap: 6px;
  max-height: 100%;
  border: 3px solid rgba(109, 201, 255, 0.3);
  border-radius: 12px;
  background: rgba(8, 20, 34, 0.74);
}

#historyList li {
  border: 3px solid rgba(118, 195, 255, 0.26);
  border-radius: 8px;
  background: rgba(8, 18, 30, 0.75);
  padding: 6px 8px;
  font-size: 11px;
  line-height: 1.35;
}

#guideText {
  margin: 14px 0 18px;
  font-size: 13px;
  line-height: 1.55;
  color: #b5ceef;
}

#helpModal {
  position: fixed;
  inset: 0;
  z-index: 70;
}

#helpModal[hidden] {
  display: none !important;
}

#helpModalBackdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 9, 17, 0.72);
}

#helpModalPanel {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(92vw, 560px);
  padding: 16px;
}

#helpModalTitle {
  margin: 0;
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(14px, 2.6vw, 18px);
  color: #c5f2ff;
}

#historyModal {
  position: fixed;
  inset: 0;
  z-index: 71;
}

#historyModal[hidden] {
  display: none !important;
}

#historyModalBackdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 9, 17, 0.72);
}

#historyModalPanel {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(92vw, 540px);
  max-height: min(78dvh, 720px);
  padding: 14px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 10px;
}

#historyModalTitle {
  margin: 0;
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(13px, 2.4vw, 16px);
  color: #c5f2ff;
}

#revealOverlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
}

#revealOverlay[hidden] {
  display: none !important;
}

.reveal-bg {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at center, rgba(88, 30, 115, 0.4) 0%, rgba(7, 10, 16, 0.94) 65%),
    linear-gradient(120deg, rgba(12, 20, 34, 0.6), rgba(12, 20, 34, 0.9));
  animation: revealPulse 1.4s ease-in-out infinite alternate;
}

.reveal-content {
  position: relative;
  z-index: 1;
  width: min(90vw, 560px);
  border: 3px solid rgba(146, 229, 255, 0.44);
  border-radius: 16px;
  background: rgba(10, 17, 29, 0.88);
  box-shadow: 0 0 32px rgba(93, 240, 255, 0.32);
  padding: 18px 16px;
  text-align: center;
}

.reveal-step {
  margin: 0;
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(10px, 2vw, 12px);
  color: #a3ddff;
}

.reveal-capsule {
  margin: 14px auto 0;
  width: 126px;
  height: 126px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-size: 75px;
  color: #d9f7ff;
  text-shadow: 0 0 18px rgba(132, 241, 255, 0.7);
  border: 6px solid rgba(123, 234, 255, 0.56);
  background: radial-gradient(circle at 28% 22%, rgba(255, 255, 255, 0.34), rgba(35, 73, 112, 0.2));
}

.reveal-prize {
  margin-top: 14px;
  border: 3px solid rgba(150, 213, 255, 0.36);
  border-radius: 12px;
  padding: 14px 10px;
  background: rgba(8, 16, 29, 0.75);
}

.reveal-tier {
  margin: 0;
  font-family: 'Press Start 2P', monospace;
  font-size: 12px;
  color: #96f6c0;
}

.reveal-glyph {
  margin: 10px auto 0;
  font-size: clamp(30px, 8vw, 48px);
  line-height: 1;
  text-shadow: 0 0 16px rgba(116, 231, 255, 0.58);
  animation: glyphPop 0.6s ease-out;
}

#revealPrizeName {
  margin: 10px 0 0;
  font-size: clamp(18px, 4vw, 24px);
  color: #e2f6ff;
  text-shadow: 0 0 12px rgba(123, 226, 255, 0.5);
}

#revealPrizeCode {
  margin: 8px 0 16px;
  font-size: 12px;
  color: #8cb7e6;
}

#testControls {
  position: fixed;
  bottom: 8px;
  left: 8px;
  z-index: 80;
  display: flex;
  gap: 6px;
}

#testControls[hidden] {
  display: none !important;
}

#testControls button {
  font-size: 11px;
}

@keyframes revealPulse {
  from {
    opacity: 0.92;
  }
  to {
    opacity: 1;
  }
}

@keyframes glyphPop {
  from {
    transform: scale(0.76);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

@media (max-width: 860px) {
  .ambient {
    display: none;
  }

  #machineWrap {
    width: min(98vw, calc((100dvh - 90px) * 0.8));
    gap: 8px;
  }
}

@media (max-width: 520px) {
  #topBar {
    padding: 8px 9px;
  }

  .pixel-btn {
    font-size: 9px;
    padding: 7px 8px;
  }

  #statusToast {
    width: min(92%, 520px);
    border-radius: 16px;
    display: grid;
    gap: 6px;
  }

  #historyModalPanel {
    width: min(94vw, 460px);
    max-height: min(74dvh, 620px);
  }
}
