* { box-sizing: border-box; }
:root {
  --paper: #fffdf6;
  --navy: #1d2a44;
  --ink: #2e3850;
  --orange: #f08a24;
  --orange-deep: #d96b12;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}
html, body { width: 100%; height: 100%; overflow: hidden; background: #d4e0e8; }
body {
  margin: 0;
  color: var(--navy);
  font-family: 'Pretendard Variable', Pretendard, -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
#stage {
  position: relative; width: 100%; height: 100dvh; overflow: hidden; isolation: isolate; transform: translateZ(0);
  background: linear-gradient(#e6eef2, #ccd8de);
  touch-action: none;
}
#game { position: absolute; inset: 0; display: block; width: 100%; height: 100%; touch-action: none; }

.back-link {
  position: absolute; top: calc(12px + var(--safe-top)); left: calc(12px + var(--safe-left)); z-index: 30;
  padding: 7px 12px; border: 1px solid rgba(29,42,68,.12); border-radius: 999px;
  background: rgba(255,253,246,.92); color: var(--navy); box-shadow: 0 3px 10px rgba(30,40,30,.12);
  font: inherit; font-size: 12px; font-weight: 600; text-decoration: none; line-height: 1.2;
}

/* 모드별 문구: html[data-scene]은 game.js가 붙인다 */
html[data-scene="campus"] [data-only="test"],
html[data-scene="test"] [data-only="campus"],
html:not([data-scene]) [data-only="test"] { display: none !important; }

/* 시험 공간 표시 + 위치 숫자 */
#hud {
  position: absolute; top: calc(50px + var(--safe-top)); left: 50%; z-index: 10;
  transform: translateX(-50%); width: min(calc(100% - 24px), 640px);
  display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none;
}
#hud[hidden] { display: none; }
.readout {
  margin: 0; padding: 4px 10px; border-radius: 10px; background: rgba(255,253,246,.85);
  color: var(--ink); font-size: 11px; font-weight: 600; line-height: 1.45; text-align: center;
  font-variant-numeric: tabular-nums; word-break: keep-all;
}
.readout:empty { display: none; }

#reticle {
  position: absolute; left: 50%; top: 50%; z-index: 9; width: 6px; height: 6px; margin: -3px 0 0 -3px;
  border-radius: 50%; background: rgba(255,255,255,.95); box-shadow: 0 0 0 1.5px rgba(20,30,40,.45);
  pointer-events: none; opacity: 0; transition: opacity .2s;
}
#stage.playing #reticle { opacity: 1; }
#stage.no-reticle #reticle { display: none; }
@media (pointer: coarse) { #reticle { display: none; } }   /* 폰은 가운데 점 없음 */

/* 휴대폰 조이스틱 — 왼쪽 아래 누른 자리에 생긴다 */
.stick {
  --sx: calc(78px + var(--safe-left)); --sy: calc(100% - 110px - var(--safe-bottom));
  position: absolute; inset: 0; z-index: 8; pointer-events: none; display: none;
}
#stage.playing .stick { display: block; }
.stick-base, .stick-knob { position: absolute; left: var(--sx); top: var(--sy); border-radius: 50%; }
.stick-base {
  width: 104px; height: 104px; margin: -52px 0 0 -52px;
  border: 2px solid rgba(255,255,255,.75); background: rgba(20,30,40,.12);
  box-shadow: 0 2px 10px rgba(0,0,0,.12); opacity: .55; transition: opacity .15s;
}
.stick-knob {
  width: 46px; height: 46px; margin: -23px 0 0 -23px;
  background: rgba(255,255,255,.85); box-shadow: 0 2px 8px rgba(0,0,0,.2); opacity: .6;
}
.stick.on .stick-base, .stick.on .stick-knob { opacity: 1; }
@media (pointer: fine) { .stick { display: none !important; } }
/* 휴대폰 감도 휘두르기 버튼: 오른쪽 아래. 걷는 중에만, 터치 화면에서만 */
.swing-btn { display: none; position: absolute; right: max(18px, env(safe-area-inset-right)); bottom: max(26px, env(safe-area-inset-bottom)); width: 76px; height: 76px; border-radius: 50%; border: 2px solid rgba(255,255,255,0.85); background: rgba(29,42,68,0.55); color: #fff; font: 700 14px/1 "Pretendard Variable", Pretendard, sans-serif; touch-action: none; user-select: none; -webkit-user-select: none; z-index: 5; }
.swing-btn:active { background: rgba(29,42,68,0.8); }
@media (pointer: coarse) { #stage.playing.holding .swing-btn { display: block; } }   /* P3: 감도를 들었을 때만 */
/* P3·4차 2번 도구 칸(1 감도 · 2 감봉): 화면 아래 가운데. 휴대폰은 조이스틱 자리(왼쪽)와 앉기·눕기·사진 버튼 사이 */
.tool-bar { display: none; position: absolute; left: 50%; bottom: max(18px, env(safe-area-inset-bottom)); transform: translateX(-50%); gap: 8px; z-index: 5; }
@media (pointer: coarse) { #stage.playing .tool-bar { display: flex; } }   /* PC는 1·2 키(설명 팝업), 폰만 칸 */
.tool-slot { position: relative; width: 56px; height: 56px; padding: 5px; border-radius: 14px; border: 2px solid rgba(29,42,68,0.55); background: rgba(255,255,255,0.72); touch-action: none; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; cursor: pointer; }
.tool-slot img { display: block; width: 100%; height: 100%; object-fit: contain; pointer-events: none; opacity: 0.55; border-radius: 9px; }   /* 공용 스프라이트는 흰 바탕이라 칸도 밝게 */
.tool-key { position: absolute; left: 5px; top: 3px; font: 700 11px/1 "Pretendard Variable", Pretendard, sans-serif; color: #1d2a44; pointer-events: none; }
/* 4차 1번(2026-11-26): 앉기·눕기·사진 버튼(휴대폰, 도구 칸 오른쪽 세로 줄) · 사진 모드(화면만 남김) */
.pose-btns { display: none; position: absolute; left: calc(50% + 51px); bottom: max(18px, env(safe-area-inset-bottom)); flex-direction: column-reverse; gap: 5px; z-index: 5; }
@media (pointer: coarse) { #stage.playing .pose-btns { display: flex; } }
.pose-btns button { width: 42px; height: 34px; padding: 0; border-radius: 10px; border: 2px solid rgba(29,42,68,0.55); background: rgba(255,255,255,0.72); color: #1d2a44; font: 700 12px/1 "Pretendard Variable", Pretendard, sans-serif; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; }
.pose-btns button[aria-pressed="true"] { border-color: #f08a1c; background: #fff; }
.photo-ui { display: none; }
#stage.photo .photo-ui { display: block; }
#stage.photo #reticle, #stage.photo #hud, #stage.photo .tool-bar, #stage.photo .tool-slot, #stage.photo .swing-btn, #stage.photo .pose-btns, #stage.photo .back-link, #stage.photo .help-btn, #stage.photo .stick { display: none !important; }
.shutter-btn { position: absolute; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); width: 64px; height: 64px; margin-left: -32px; border-radius: 50%; border: 4px solid #fff; background: rgba(255,255,255,0.3); box-shadow: 0 0 0 2px rgba(0,0,0,0.25); cursor: pointer; touch-action: none; z-index: 6; }
.photo-exit { position: absolute; top: max(14px, env(safe-area-inset-top)); right: max(14px, env(safe-area-inset-right)); width: 40px; height: 40px; border-radius: 50%; border: 0; background: rgba(0,0,0,0.35); color: #fff; font: 400 24px/1 sans-serif; cursor: pointer; touch-action: none; z-index: 6; }
/* 휴대폰 사진: 셔터 없음(인스타 앱 안에서는 내려받기가 막힘) → 안내 1.5초 뒤 화면을 비워 스크린샷으로 찍게. 톡 치면 × 3초 */
.photo-hint { display: none; position: absolute; left: 50%; bottom: max(40px, calc(env(safe-area-inset-bottom) + 24px)); transform: translateX(-50%); margin: 0; padding: 10px 16px; border-radius: 999px; background: rgba(20,28,40,.55); color: #fff; font-size: 14px; font-weight: 600; white-space: nowrap; pointer-events: none; z-index: 6; transition: opacity .3s; }
@media (pointer: coarse) { .shutter-btn { display: none; } .photo-hint { display: block; } }
.photo-exit { transition: opacity .3s; }
#stage.photo-clean .photo-exit, #stage.photo-hinted .photo-hint { opacity: 0; pointer-events: none; }
.photo-flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; z-index: 7; }
.photo-flash.on { animation: photo-flash 0.35s ease-out; }
@keyframes photo-flash { from { opacity: 0.7; } to { opacity: 0; } }
.tool-slot[aria-pressed="true"] { border-color: #f08a1c; background: #fff; box-shadow: 0 0 0 3px rgba(240,138,28,0.35); }
.tool-slot[aria-pressed="true"] img { opacity: 1; }
@media (pointer: coarse) { .tool-bar { left: calc(50% - 57px); transform: none; gap: 6px; } .tool-slot { width: 48px; height: 48px; border-radius: 12px; } .tool-key { display: none; } }

/* 화면들 */
.screen { position: absolute; inset: 0; z-index: 20; }
.screen[hidden] { display: none !important; }
.screen.center {
  display: grid; place-items: center; padding: 24px;
  background: rgba(25,35,30,.3); backdrop-filter: blur(3px);
}
#loading { background: linear-gradient(#e6eef2, #ccd8de); backdrop-filter: none; }
.loading-text { margin: 0; color: #5f6f78; font-size: 14px; font-weight: 600; animation: breathe 1.2s ease-in-out infinite alternate; }
@keyframes breathe { to { opacity: .45; } }

.panel {
  width: min(100%, 320px); padding: 22px 20px 18px; border-radius: 16px; text-align: center;
  background: rgba(255,255,255,.9); border: 1px solid rgba(29,42,68,.07);
  box-shadow: 0 10px 30px rgba(20,30,40,.14); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.panel-title { color: var(--navy); font-size: 19px; font-weight: 750; letter-spacing: -.03em; }
.panel p { margin: 6px 0 16px; color: #7a8192; font-size: 13.5px; line-height: 1.5; }
.main-btn {
  width: 100%; padding: 12px 18px; border: 0; border-radius: 12px; cursor: pointer;
  background: var(--navy); color: #fff; font: inherit; font-size: 15px; font-weight: 700; letter-spacing: -.01em;
}
.main-btn:hover { background: #2a3a5c; }
.main-btn:active { transform: translateY(1px); }
.sub-btn {
  width: 100%; margin-top: 8px; padding: 11px 18px; border: 1px solid rgba(29,42,68,.14); border-radius: 12px; cursor: pointer;
  background: transparent; color: var(--ink); font: inherit; font-size: 14px; font-weight: 600;
}
.sub-btn:hover { background: rgba(29,42,68,.04); }

/* 오른쪽 위 설명 버튼 + 팝업 */
.stage-title { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; margin: 0; }
.help-btn {
  position: absolute; top: calc(12px + var(--safe-top)); right: calc(12px + var(--safe-right)); z-index: 30;
  padding: 7px 12px; border: 1px solid rgba(29,42,68,.12); border-radius: 999px; cursor: pointer;
  background: rgba(255,255,255,.85); color: var(--navy); box-shadow: 0 2px 8px rgba(30,40,30,.1);
  font: inherit; font-size: 12px; font-weight: 600; line-height: 1.2;
}
#help { z-index: 40; background: rgba(25,35,45,.18); }
.help-panel { position: relative; text-align: left; padding: 22px 20px 16px; }
.help-close {
  position: absolute; top: 10px; right: 10px; width: 30px; height: 30px; border: 0; border-radius: 50%;
  background: transparent; color: #8a91a1; font: 400 22px/1 sans-serif; cursor: pointer;
}
.help-close:hover { background: rgba(29,42,68,.06); }
.help-panel .help-lead { margin: 2px 34px 14px 0; color: var(--navy); font-size: 15px; font-weight: 650; }
.help-panel .keys { justify-content: flex-start; margin: 0 0 10px; }
.help-keys { margin: 0 0 14px; display: grid; gap: 5px; }
.help-keys div { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; }
.help-keys dt { color: #7a8192; }
.help-keys dd { margin: 0; color: var(--ink); font-weight: 600; }
.help-keys.coarse { display: none; }
@media (pointer: coarse) { .help-keys.fine { display: none; } .help-keys.coarse { display: grid; } }
.help-panel .help-by { margin: 0 0 12px; padding-top: 12px; border-top: 1px solid rgba(29,42,68,.08); color: #7a8192; font-size: 12.5px; }
.help-by a { color: var(--ink); font-weight: 600; text-decoration: none; }
.support { text-align: center; }
.support-btn {
  display: inline-block; padding: 8px 14px; border: 1px solid rgba(29,42,68,.14); border-radius: 999px;
  color: var(--ink); background: transparent; font: inherit; font-size: 12.5px; font-weight: 600; cursor: pointer;
}
.support-btn:hover { background: rgba(29,42,68,.05); }
.support-btn svg { vertical-align: -2px; margin-right: 2px; }
#toss-ask { z-index: 41; }
#toss-ask .panel { width: 230px; padding: 16px 14px 14px; }
#toss-ask .panel-title { font-size: 15.5px; }
#toss-go { display: block; box-sizing: border-box; margin-top: 12px; text-decoration: none; }
#toss-go, #toss-cancel { padding: 9px 14px; border-radius: 10px; font-size: 13.5px; }
#toss-cancel { margin-top: 6px; }
.support-qr { margin-top: 10px; }
.support-qr[hidden] { display: none; }
.support-qr img { display: block; margin: 0 auto; width: 120px; height: 120px; border: 1px solid rgba(29,42,68,.1); border-radius: 8px; }
.help-panel .support-qr p { margin: 6px 0 0; font-size: 11.5px; color: #8a91a1; text-align: center; }

#title { pointer-events: none; }
#title .panel { pointer-events: auto; }
.title-panel {
  position: absolute; left: 50%; bottom: calc(40px + var(--safe-bottom)); transform: translateX(-50%);
  width: min(calc(100% - 32px), 340px); padding: 18px 18px 16px;
}
.title-panel .title-copy { margin: 0 0 12px; color: var(--ink); font-size: 14px; font-weight: 600; word-break: keep-all; overflow-wrap: break-word; }
.keys { display: flex; justify-content: center; gap: 14px; margin: 0 0 14px; }
.key-group { display: inline-flex; gap: 3px; align-items: center; }
.keys kbd {
  display: inline-grid; place-items: center; min-width: 24px; height: 24px; padding: 0 5px; border-radius: 6px;
  background: #fff; border: 1px solid rgba(29,42,68,.16); box-shadow: 0 1px 0 rgba(29,42,68,.12);
  color: var(--ink); font: inherit; font-size: 11px; font-weight: 800;
}
.keys svg { width: 26px; height: 26px; fill: none; stroke: var(--ink); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.keys svg .fill { fill: var(--ink); }
.keys svg .arrow { stroke: var(--orange-deep); }
.keys.coarse { display: none; }
@media (pointer: coarse) { .keys.fine { display: none; } .keys.coarse { display: flex; } }


@media (max-height: 640px) {
  .title-panel { bottom: calc(14px + var(--safe-bottom)); padding: 12px 16px 12px; }
  .keys { margin-bottom: 10px; }
}
@media (max-height: 640px) and (min-width: 560px) {
  .title-panel { left: auto; right: calc(16px + var(--safe-right)); transform: none; width: 300px; }
}
@media (max-height: 420px) {
  #hud { top: calc(12px + var(--safe-top)); width: min(calc(100% - 260px), 520px); }
}

/* 운영자 제보 키(F8) '복사됨' 표시 — localhost·?debug=1에서만 뜬다 */
.report-toast {
  position: absolute; left: 50%; top: 18%; transform: translateX(-50%); z-index: 30; margin: 0;
  padding: 6px 12px; border-radius: 8px; background: rgba(20, 24, 28, 0.78); color: #fff;
  font: 600 13px/1.3 system-ui, sans-serif; pointer-events: none;
}
.report-toast[hidden] { display: none; }
