@import url('https://fonts.googleapis.com/css2?family=Gowun+Dodum&family=VT323&display=swap');
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #000; color: #eadfcb; font-family: 'Gowun Dodum', system-ui, sans-serif;
  touch-action: none; user-select: none; -webkit-user-select: none; overscroll-behavior: none; }
#gl, #ov { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#ov { pointer-events: none; z-index: 2; }
#fade { position: fixed; inset: 0; background: #000; opacity: 0; pointer-events: none; z-index: 3; transition: opacity .8s; }
#fade.on { opacity: 1; }
.hidden { display: none !important; }

.screen { position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; overflow: auto;
  background: radial-gradient(ellipse at 50% 30%, rgba(90,10,10,.55), rgba(0,0,0,.94) 70%); }
.title-box { width: min(460px, 92vw); text-align: center; padding: 16px 0; }
.tape-label { display: inline-block; font-family: 'VT323', monospace; font-size: 18px; letter-spacing: 2px; background: #eadfcb; color: #1a1410; padding: 2px 10px; transform: rotate(-2deg); }
h1 { font-size: clamp(36px, 8vh, 62px); margin: 8px 0 0; letter-spacing: 4px; color: #f0e4cc;
  text-shadow: 3px 0 rgba(255,0,40,.55), -3px 0 rgba(0,200,255,.35); animation: jit 4s infinite; }
@keyframes jit { 0%,92%,100% { transform: none } 93% { transform: translateX(4px) skewX(8deg) } 95% { transform: translateX(-3px) } }
.en { font-family: 'VT323', monospace; letter-spacing: 10px; font-size: 20px; color: #a8806a; }
.lead { color: #c3b39a; font-size: 15px; margin: 10px 0 14px; }
input { font: inherit; font-size: 16px; background: rgba(0,0,0,.6); color: #f3ead2; border: 1px solid #6d4a3e; border-radius: 10px; padding: 10px 12px; outline: none; }
input:focus { border-color: #e06a50; }
#nick { width: 100%; font-size: 18px; text-align: center; }
.seg { display: flex; gap: 8px; margin: 10px 0; }
.seg button { flex: 1; font: inherit; padding: 9px; border-radius: 10px; border: 1px solid #5a4036; background: #1a1210; color: #cdbda4; cursor: pointer; }
.seg button.on { background: #3a1f1a; border-color: #e06a50; color: #fff; }
.modes { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 8px; }
.mode { font: inherit; cursor: pointer; text-align: left; background: #1d1310; border: 1px solid #5a4036; border-radius: 12px; padding: 10px; color: #f0e4cc; min-height: 64px; }
.mode:hover { border-color: #e06a50; }
.mode b { display: block; font-size: 15px; }
.mode span { font-size: 12px; color: #a08c76; }
.code-row { display: flex; gap: 8px; margin-top: 8px; }
.code-row input { flex: 1; min-width: 0; text-transform: uppercase; letter-spacing: 4px; text-align: center; }
.btn { font: inherit; font-size: 15px; cursor: pointer; border-radius: 10px; border: 1px solid #5a4036; background: #221613; color: #f0e4cc; padding: 10px 14px; }
.btn:hover { background: #2e1d18; }
.btn.primary { background: #c9503a; border-color: #c9503a; color: #fff; }
.btn.danger { background: #4a1212; }
.btn.red { background: #8a1414; border-color: #b52020; }
.btn.blue { background: #142a6a; border-color: #2040a0; }
.warn { font-size: 13px; color: #e08f7a; margin: 12px 0 4px; }
.note { font-size: 12px; color: #8f7f6c; margin: 4px 0; }

#hud { position: fixed; inset: 0; z-index: 5; pointer-events: none; }
#hud button, #hud input, #hud form { pointer-events: auto; }
#hudTop { position: absolute; top: max(10px, env(safe-area-inset-top)); left: max(14px, env(safe-area-inset-left)); text-shadow: 0 0 6px #000; }
#where { font-size: 20px; }
#members { font-size: 13px; color: #c7b49a; margin-top: 2px; }
#hudRight { position: absolute; top: max(10px, env(safe-area-inset-top)); right: max(14px, env(safe-area-inset-right)); display: flex; gap: 8px; align-items: center; }
#codeChip { background: rgba(0,0,0,.6); border: 1px solid #6d4a3e; border-radius: 10px; padding: 7px 10px; font-family: 'VT323', monospace; font-size: 20px; letter-spacing: 3px; }
.icon { width: 40px; height: 40px; border-radius: 10px; background: rgba(0,0,0,.5); border: 1px solid #4d3a32; color: #fff; font-size: 17px; cursor: pointer; }
#chatLog { position: absolute; left: max(14px, env(safe-area-inset-left)); top: 66px; width: min(300px, 38vw); font-size: 13px; }
#chatLog div { background: rgba(0,0,0,.45); padding: 3px 8px; border-radius: 6px; margin-bottom: 3px; transition: opacity 1s; }
#chatLog b { color: #f0a080; }
#chatForm { position: absolute; bottom: max(14px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); width: min(380px, 42vw); }
#chatInput { width: 100%; background: rgba(0,0,0,.55); }
#caption { position: absolute; left: 50%; bottom: 22%; transform: translateX(-50%); font-size: clamp(18px, 3.2vh, 26px); color: #f0e4d0;
  text-shadow: 0 0 10px #000, 0 0 3px #000; opacity: 0; transition: opacity .5s; text-align: center; width: 90vw; }
#caption.on { opacity: 1; }
#toast { position: absolute; top: 16%; left: 50%; transform: translateX(-50%); font-size: 18px; text-shadow: 0 0 8px #000; opacity: 0; transition: opacity .4s; white-space: nowrap; }
#toast.on { opacity: 1; }
#hint { position: absolute; bottom: 64px; left: 50%; transform: translateX(-50%); font-size: 13px; color: #c7b49a; text-shadow: 0 0 6px #000; transition: opacity 1s; white-space: nowrap; }
#stick { position: absolute; width: 120px; height: 120px; border-radius: 50%; border: 2px solid rgba(255,255,255,.25); background: rgba(0,0,0,.2);
  transform: translate(-50%,-50%); display: none; pointer-events: none; }
#stick.on { display: block; }
#knob { position: absolute; left: 50%; top: 50%; width: 50px; height: 50px; border-radius: 50%; background: rgba(255,255,255,.35); transform: translate(-50%,-50%); }
#jumpBtn, #chatBtn { display: none; }
@media (pointer: coarse) {
  #jumpBtn { display: block; position: absolute; right: max(22px, env(safe-area-inset-right)); bottom: max(22px, env(safe-area-inset-bottom)); width: 78px; height: 78px; border-radius: 50%;
    border: 1px solid rgba(255,255,255,.3); background: rgba(0,0,0,.4); color: #fff; font: 600 16px 'Gowun Dodum'; }
  #chatBtn { display: block; position: absolute; right: calc(max(22px, env(safe-area-inset-right)) + 92px); bottom: max(30px, env(safe-area-inset-bottom)); width: 52px; height: 52px;
    border-radius: 50%; border: 1px solid rgba(255,255,255,.25); background: rgba(0,0,0,.4); font-size: 20px; }
  #chatForm { width: 34vw; }
  #chatForm:not(.open) { display: none; }
}

.modal { position: fixed; inset: 0; z-index: 15; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.45); }
.card { width: min(440px, 92vw); background: #140d0b; border: 1px solid #4d3a32; border-radius: 16px; padding: 18px 20px; box-shadow: 0 0 60px rgba(0,0,0,.8); }
.card.center { text-align: center; }
.card h2 { margin: 8px 0 12px; font-size: 22px; }
.row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.row.col { flex-direction: column; }
.whisper { font-size: 22px; color: #f2d8cc; letter-spacing: 2px; animation: shiver .15s infinite; }
@keyframes shiver { 50% { transform: translateX(1px); } }
.timer { height: 4px; background: #2a1a16; border-radius: 4px; margin-top: 14px; overflow: hidden; }
.timer i { display: block; height: 100%; background: #c9503a; width: 100%; }
#choice { background: none; align-items: flex-end; padding-bottom: 9vh; pointer-events: none; }
#choice .card { pointer-events: auto; background: rgba(0,0,0,.35); border: none; box-shadow: none; }
#choice .whisper { text-shadow: 0 0 8px #000, 0 0 2px #000; }
#rStats { font-family: 'VT323', monospace; font-size: 22px; margin: 6px 0 16px; line-height: 1.4; }
#loading { position: fixed; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center; background: #000; font-size: 18px; }
#rotate { display: none; }
@media (orientation: portrait) and (pointer: coarse) and (hover: none) {
  #rotate { display: flex; position: fixed; inset: 0; z-index: 100; background: #000; color: #eadfcb; align-items: center; justify-content: center; text-align: center; font-size: 20px; line-height: 2; }
}
@media (max-height: 460px) { .title-box { transform: scale(.86); } }

#roofHint { position: absolute; left: 50%; top: 30%; transform: translateX(-50%); background: rgba(0,0,0,.55); padding: 8px 14px; border-radius: 10px; font-size: 15px; white-space: nowrap; }
#spectBar { position: absolute; left: 50%; top: 12px; transform: translateX(-50%); background: rgba(160,30,30,.75); padding: 6px 14px; border-radius: 10px; font-size: 14px; pointer-events: auto; cursor: pointer; }
#emotes { position: absolute; right: max(14px, env(safe-area-inset-right)); top: 130px; display: flex; flex-direction: column; gap: 6px; }
#emotes button { width: 40px; height: 40px; border-radius: 10px; background: rgba(0,0,0,.5); border: 1px solid #4d3a32; font-size: 18px; cursor: pointer; }
@media (pointer: coarse) { #emotes { top: auto; bottom: 120px; right: max(22px, env(safe-area-inset-right)); } #emotes button { width: 48px; height: 48px; } }
.scoreHead { margin-top: 10px; color: #c9503a; font-size: 16px; }

.credit { font-size: 11px; color: #7d6e60; margin-top: 10px; line-height: 1.5; }
.credit a { color: #a98f7c; }

/* 방탈출: 조사 버튼, 쪽지, 금고 키패드 */
#actBtn { position: absolute; left: 50%; bottom: calc(9vh + 14px); transform: translateX(-50%); pointer-events: auto; background: rgba(20,12,10,.82); color: #f1e6da; border: 1px solid #a2614d; border-radius: 22px; padding: 10px 18px; font-size: 15px; white-space: nowrap; box-shadow: 0 0 18px rgba(160,40,20,.35); }
#actBtn b { display: inline-block; background: #e8d9c8; color: #1a0f0c; border-radius: 4px; padding: 0 6px; margin-right: 8px; font-size: 13px; }
#paper .note { width: min(380px, 88vw); background: #e9e2cf; color: #2a1f1a; border-radius: 4px; padding: 26px 24px 18px; box-shadow: 0 0 60px rgba(0,0,0,.9); transform: rotate(-1.2deg); font-family: "Nanum Pen Script", "Gaegu", cursive, sans-serif; font-size: 23px; line-height: 1.45; white-space: pre-line; background-image: linear-gradient(transparent 31px, rgba(80,60,40,.18) 32px); background-size: 100% 33px; }
#paper .note .wet { color: #4a3a6a; filter: blur(.4px); }
#paper .note .btn { margin-top: 14px; font-family: inherit; }
#keypad .safe { width: min(300px, 88vw); }
#kpScreen { font: 32px/1.4 "Courier New", monospace; letter-spacing: 6px; background: #071a0c; color: #4dff7a; border-radius: 6px; padding: 6px 0; margin: 6px 0 12px; text-shadow: 0 0 8px #2f9; }
#kpScreen.bad { color: #ff4d4d; text-shadow: 0 0 8px #f33; }
.kp { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.kp button { font-size: 22px; padding: 12px 0; background: #2a2624; color: #eee; border: 1px solid #555; border-radius: 8px; }
.kp button:active { background: #3f3936; }

/* 조사 버튼이 떠 있으면 자막을 그 위로 올려서 겹치지 않게 */
#caption { transition: bottom .2s, opacity .4s; }
body.hasAct #caption { bottom: calc(9vh + 76px); }

/* Keep touch controls clear of the host badge and the iPhone home area. */
@media (orientation: landscape) and (pointer: coarse) {
  #hud { --touch-floor: calc(64px + env(safe-area-inset-bottom, 0px)); }
  #jumpBtn { bottom: var(--touch-floor); }
  #chatBtn { bottom: calc(var(--touch-floor) + 13px); }
  #emotes {
    top: calc(max(10px, env(safe-area-inset-top)) + 48px);
    bottom: auto;
    flex-direction: row;
  }
  #chatForm.open {
    left: max(14px, env(safe-area-inset-left));
    bottom: max(10px, env(safe-area-inset-bottom));
    transform: none;
    width: min(46vw, 360px);
  }
  #chatInput { font-size: 16px; }
}
