:root { color-scheme: dark; background: #050505; }
* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body {
  font-family: Arial, Helvetica, sans-serif;
  background: #050505;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
button { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  background: #080808;
}

/* PNG 전체를 그대로 사용하고, 동일 비율 기준으로 터치/표시 요소를 올립니다. */
.keypad {
  position: relative;
  width: min(100vw, calc(100dvh * 1478 / 2047));
  max-height: 100dvh;
  aspect-ratio: 1478 / 2047;
  flex-shrink: 0;
  overflow: hidden;
}
.keypad-art {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
  -webkit-user-drag: none;
}

.touch-buttons { position: absolute; inset: 0; }
.hotspot {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: 12.3%;
  height: 9.2%;
  transform: translate(-50%, -50%);
  border: 0;
  border-radius: 14%;
  background: transparent;
  cursor: pointer;
  padding: 0;
}
.hotspot:active,
.hotspot.pressed {
  background: rgba(255, 44, 44, .16);
  box-shadow: inset 0 0 2.2vw rgba(255, 44, 44, .38);
}
.hotspot:focus-visible {
  outline: 2px solid #ff7777;
  outline-offset: -2px;
}

/* 상단 3자리 입력 표시: 각 네모칸 중앙에 정확히 맞춥니다. */
.entry-display {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.digit {
  position: absolute;
  top: 20.35%;
  width: 7.4%;
  height: 7.2%;
  display: grid;
  place-items: center;
  transform: translate(-50%, -50%);
  color: #fff1f1;
  font-size: clamp(28px, 4vw, 62px);
  font-weight: 700;
  line-height: 1;
  text-shadow: 0 0 7px #ff3737, 0 0 14px #ff1e1e, 0 0 24px #dc0000;
}
.digit[data-digit="0"] { left: 46.95%; }
.digit[data-digit="1"] { left: 56.28%; }
.digit[data-digit="2"] { left: 65.60%; }

/* 상태 문구는 디스플레이 하단 중앙의 검은 영역 안에 배치합니다. */
.status-text {
  position: absolute;
  left: 33.6%;
  top: 27.05%;
  width: 37.2%;
  min-height: 1.6%;
  transform: translateY(-50%);
  text-align: center;
  color: #ff7777;
  font-size: clamp(9px, 1.45vw, 19px);
  line-height: 1;
  letter-spacing: .06em;
  font-weight: 700;
  text-shadow: 0 0 7px #e00000;
  pointer-events: none;
  white-space: nowrap;
}
.status-text:empty { display: none; }
.keypad.error { animation: error-shake .35s linear; }
.keypad.success .status-text {
  color: #fff;
  text-shadow: 0 0 10px #e63232;
}

@keyframes error-shake {
  0%,100% { transform: translateX(0); }
  20%,60% { transform: translateX(-5px); }
  40%,80% { transform: translateX(5px); }
}

/* 화면 전체 문 열림 연출 */
.door-scene {
  position: fixed;
  inset: 0;
  z-index: 3;
  overflow: hidden;
  pointer-events: none;
  visibility: hidden;
  opacity: 0;
  background: radial-gradient(ellipse at center, #8e1a1a 0%, #2f0808 30%, #000 75%);
  transition: opacity .18s ease;
}
.door-scene.active { visibility: visible; opacity: 1; }
.door-panel {
  position: absolute;
  top: 0;
  width: 50.5%;
  height: 100%;
  background:
    repeating-linear-gradient(98deg, transparent 0, rgba(255,255,255,.035) 2px, transparent 5px),
    linear-gradient(90deg,#161616 0%,#464646 13%,#252525 30%,#4a4a4a 72%,#171717 100%);
  border: 5px solid #666;
  box-shadow: inset 0 0 35px #000, 0 0 18px #000;
  transition: transform 1.45s cubic-bezier(.65,0,.25,1) .22s;
}
.door-left { left: 0; border-right: 5px solid #e72a2a; }
.door-right { right: 0; border-left: 5px solid #e72a2a; }
.door-scene.open .door-left { transform: translateX(-103%); }
.door-scene.open .door-right { transform: translateX(103%); }
.door-glow {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center, #dd2929 0%, #320606 36%, transparent 76%);
  animation: pulse 1.3s infinite alternate;
}
.door-message {
  position: absolute;
  top: 48%;
  left: 0;
  width: 100%;
  text-align: center;
  font-size: clamp(20px, 5vw, 48px);
  color: white;
  font-weight: bold;
  letter-spacing: .12em;
  text-shadow: 0 0 20px #fa2020;
  opacity: 0;
  transition: opacity .45s .8s;
}
.door-scene.open .door-message { opacity: 1; }

@keyframes pulse { from { opacity: .55; } to { opacity: 1; } }

@media (orientation: landscape) {
  .digit { font-size: clamp(24px, 5vh, 54px); }
  .status-text { font-size: clamp(9px, 1.7vh, 16px); }
}

@media (prefers-reduced-motion: reduce) {
  .keypad.error { animation: none; }
  .door-panel { transition-duration: .2s; }
}
