* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #111418; color: #eee6d2;
  font-family: 'Pretendard', 'Malgun Gothic', sans-serif; user-select: none; -webkit-user-select: none; touch-action: none; }
/* 모바일 주소창이 나타나고 사라져도 보이는 높이에 맞춘다 (dvh 미지원 브라우저는 100%) */
body { height: 100dvh; display: flex; align-items: center; justify-content: center; background: #000; }
#stage { position: relative; flex: 0 0 auto; overflow: hidden; container: stage / inline-size; }
#world { display: block; width: 100%; height: 100%; image-rendering: pixelated; }
/* 전체 화면 + 세로(가로 잠금 실패): 무대를 가로 크기로 잡고 90° 돌린다 */
body.rotated #stage { transform: rotate(90deg); }
/* 세로 화면 캐릭터 만들기: 무대 = 화면 전체, 뒤 맵은 잘라서 채운다 */
body.portrait-panel #world { object-fit: cover; }
/* 세로 화면 마을 둘러보기: 맵을 물러나 넓게 그리고 남는 위아래는 어두운 배경 */
body.browsing-portrait #stage { background: radial-gradient(#1c2a20, #070b08 75%); }
.hidden { display: none !important; }

/* 인트로: 검은 잉크를 걷어 내고, 황금빛 종이 위에 다음 기억이 번진다. */
#intro { position: absolute; inset: 0; z-index: 20; overflow: hidden; background: #000; isolation: isolate; }
#intro[hidden], #intro [hidden] { display: none !important; }
#intro-canvas { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }
.intro-start { position: absolute; inset: 0; width: 100%; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 22px; border: 0; padding: 24px;
  background: #000; color: #e3e4dc; font: inherit; font-size: clamp(16px, 1.6cqw, 20px);
  letter-spacing: .1em; cursor: pointer; touch-action: manipulation; }
.intro-start-icon { width: 32px; height: 32px; opacity: .8; }
.intro-start-title { margin-bottom: 14px; color: #f3e6c7; font: 400 clamp(23px,3.2cqw,42px)/1.5 'Batang','AppleMyungjo',serif; letter-spacing: .08em; }
.intro-start:focus-visible { outline: 1px solid #94b69e; outline-offset: -12px; }
.intro-start:disabled { cursor: wait; }
.intro-copy { position: absolute; top: 50%; left: 50%; width: max-content; max-width: 90%; margin: 0;
  transform: translate(-50%, -50%); color: #fffdf6; text-align: center; pointer-events: none; opacity: 0;
  font-size: clamp(17px, 2.3cqw, 30px); line-height: 1.75; font-weight: 400; letter-spacing: .03em;
  text-shadow: 0 2px 14px #000, 0 0 36px #000; }
#intro-still { font-size: clamp(15px, 1.85cqw, 24px); }
#intro-melody { top: 42%; font-family: 'Batang', 'Noto Serif KR', 'AppleMyungjo', serif; }
#intro-melody span { letter-spacing: .12em; }
.intro-question { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center;
  justify-content: center; padding: 32px 24px; color: #fff5eb; opacity: 0; }
.intro-q { font-family: Georgia, serif; color: #fff1ca; font-size: clamp(18px, 2cqw, 28px); margin-bottom: 18px;
  text-shadow: 0 1px 8px #30220c; }
.intro-question h1 { margin: 0 0 36px; text-align: center; font-family: 'Batang', 'Noto Serif KR', 'AppleMyungjo', serif;
  font-size: clamp(20px, 2.8cqw, 36px); font-weight: 400; line-height: 1.65; letter-spacing: .025em;
  text-shadow: 0 2px 6px #17251c, 0 0 22px #17251c; outline: none; }
.intro-mobile-break { display: none; }
.intro-answers { display: flex; justify-content: center; gap: 18px; width: min(680px, 84%); }
.intro-answer { position: relative; display: flex; align-items: center; justify-content: center; gap: 18px; flex: 1;
  min-width: 0; min-height: 64px; padding: 16px 20px; border: 1px solid rgba(255, 225, 154, .75);
  color: #fff8e7; background: rgba(47, 37, 19, .75); font: inherit; font-size: clamp(14px, 1.6cqw, 20px);
  cursor: pointer; transition: background .25s, border-color .25s, transform .25s, box-shadow .25s; }
.intro-answer-number { font: 12px Georgia, serif; color: #eccb85; letter-spacing: .12em; }
.intro-answer:hover, .intro-answer:focus-visible { background: rgba(143, 95, 30, .9); border-color: #ffe9b5;
  box-shadow: 0 0 30px #ffce5b30; transform: translateY(-3px); outline: 1px solid #ffe9b5; outline-offset: 4px; }
.intro-answer:disabled { cursor: default; transform: none; }
.intro-answer.is-selected { background: #8b641f; border-color: #ffe9b5; }
.intro-skip { position: absolute; top: 22px; right: 26px; display: flex; align-items: center; gap: 12px;
  padding: 8px 0 8px 12px; border: 0; background: transparent; color: #b9b7ac;
  font: inherit; font-size: 12px; letter-spacing: .06em; cursor: pointer; }
.intro-skip span { font-size: 22px; line-height: 1; }
.intro-skip:hover, .intro-skip:focus-visible { color: #fff; outline-offset: 4px; }
.intro-sound { position: absolute; top: 26px; left: 26px; padding: 7px 10px; color: #e8e3ce;
  border: 1px solid #b7b18d66; background: #0005; font: inherit; font-size: 12px; cursor: pointer; }
.intro-sound:hover, .intro-sound:focus-visible { color: #fff; outline-offset: 4px; }
.intro-error { position: absolute; bottom: 24px; left: 20px; right: 20px; margin: 0; text-align: center; color: #f4d6c5; font-size: 13px; }
body.intro-active #customize, body.intro-active #hud, body.intro-active #toast { visibility: hidden; }
.memory-question { position: absolute; inset: 0; text-align: center; pointer-events: none; color: #fff8e9; }
.memory-step { margin: 0; position: absolute; top: 7%; left: 0; width: 100%; color: #d5be89;
  font-size: clamp(10px, 1cqw, 13px); letter-spacing: .2em; text-shadow: 0 2px 8px #000; }
.memory-question h1 { position: absolute; top: 12%; left: 0; width: 100%; margin: 0; padding: 0 20px;
  font: 400 clamp(22px, 2.8cqw, 36px)/1.5 'Batang', 'AppleMyungjo', serif; text-shadow: 0 2px 12px #000; outline: none; }
.memory-answers { position: absolute; bottom: 5%; left: 50%; transform: translateX(-50%); width: min(640px, 86%);
  display: flex; justify-content: center; gap: 18px; pointer-events: auto; }
.memory-choice { position: relative; flex: 1; min-width: 0; max-width: 190px; display: flex; flex-direction: column;
  align-items: center; padding: 8px 10px 14px; border: 1px solid #dac79680; background: linear-gradient(150deg,#1c241ddb,#0c120fef);
  color: #fff4d6; font: inherit; cursor: pointer; transition: background .2s, border-color .2s, transform .2s;
  box-shadow: 0 6px 30px #0003; }
.memory-choice canvas { display: block; width: 100%; max-height: 150px; object-fit: contain; image-rendering: pixelated; }
.memory-choice span { font-size: 14px; letter-spacing: .12em; }
.memory-choice:hover, .memory-choice:focus-visible, .memory-choice.is-selected { border-color: #ffe7a3; background: #655331d9;
  outline: 1px solid #ffe7a3; outline-offset: 3px; transform: translateY(-4px); }
.memory-choice:disabled { cursor: default; transform: none; }
.memory-choice-face canvas { max-height: 105px; }
.memory-question[data-kind="gender"] .memory-step { top: 24%; }
.memory-question[data-kind="gender"] h1 { top: 30%; }
.memory-question[data-kind="gender"] .memory-answers { bottom: 19%; max-width: 410px; }
.memory-name-form { position: absolute; bottom: 8%; left: 50%; transform: translateX(-50%); width: min(480px, 86%);
  padding: 20px; text-align: left; color: #fff0cd; background: #0b1513e8; border: 1px solid #bda47199; pointer-events: auto; }
.memory-name-form label { display: block; margin-bottom: 10px; font-size: 13px; letter-spacing: .08em; }
.memory-name-controls { display: flex; gap: 10px; }
.memory-name-controls input { flex: 1; min-width: 0; height: 48px; border: 1px solid #bca87d; border-radius: 0; background: #08100d;
  color: #fff7e5; padding: 10px 12px; font: inherit; font-size: 17px; user-select: text; -webkit-user-select: text; touch-action: manipulation; }
.memory-name-controls input:focus { outline: 1px solid #ffe1a0; outline-offset: 2px; }
.memory-name-controls input[aria-invalid="true"] { border-color: #efb08a; }
.memory-name-controls button { border: 1px solid #edc888; background: #c6a15e; color: #162019; font: inherit; padding: 10px 16px; cursor: pointer; }
.memory-name-controls button:disabled { opacity: .6; cursor: wait; }
.memory-name-form p { margin: 10px 0 0; font-size: 11px; color: #bfb9a3; }
#memory-name-error { min-height: 1em; color: #ffcbab; }
.memory-result { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  gap: clamp(28px, 5cqw, 80px); padding: 7%; opacity: 0; color: #fff5df; }
.memory-photo-card { position: relative; flex: 0 1 43%; min-width: 0; margin: 0; color: #65563a; }
.memory-photo-card::before { content: ''; position: absolute; inset: 3px; z-index: 0; background: #c8b995;
  border: 1px solid #e7d7ae; transform: translate(3px, 5px) rotate(2.8deg); box-shadow: 0 12px 35px #0006; }
.memory-photo-front { position: relative; z-index: 1; margin: 0; padding: 10px 10px 22px; background: #ede5cf; box-shadow: 0 15px 60px #0006; }
.memory-photo-card img { display: block; width: 100%; aspect-ratio: 16/9; object-fit: contain; image-rendering: auto; }
.memory-photo-card figcaption { margin-top: 18px; font: 400 clamp(12px, 1.3cqw, 17px)/1.5 'Batang', serif; text-align: center; letter-spacing: .1em; }
.memory-result-copy { flex: 0 1 48%; min-width: 0; }
/* 미니게임 캐릭터가 실제 캐릭터 사전 생성으로 오해되지 않게 하는 안내 */
.memory-notice { margin: -16px 0 28px; color: #cfc3a4; font-size: clamp(11px, 1.1cqw, 14px); line-height: 1.6; word-break: keep-all; text-shadow: 0 1px 4px #000; }
.memory-eyebrow { color: #cdb77f; font-size: clamp(11px, 1.2cqw, 16px); letter-spacing: .16em; margin: 0 0 22px; }
.memory-result h1 { font: 400 clamp(23px, 2.8cqw, 38px)/1.65 'Batang', 'AppleMyungjo', serif; margin: 0 0 36px; outline: none;
  word-break: keep-all; text-shadow: 0 2px 20px #0008; }
.memory-result-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.memory-result-actions .memory-primary { grid-column: 1 / -1; }
.memory-result-actions button, .memory-result-actions a { flex: 1; text-align: center; min-width: 0; padding: 17px 10px;
  border: 1px solid #d1bc8380; color: #fff4d4; background: #17261ddd; font: inherit; font-size: clamp(12px,1.3cqw,17px);
  text-decoration: none; cursor: pointer; }
.memory-result-actions .memory-primary { background: #ba9453; color: #141b15; border-color: #e4c486; }
.memory-result-actions button:hover, .memory-result-actions a:hover { filter: brightness(1.18); }
.memory-browse { display: block; margin-top: 22px; padding: 9px 0; color: #e5dfcb; background: none; border: 0; font: inherit; font-size: 16px; cursor: pointer; }
.memory-browse span { margin-left: 8px; }
.memory-controls { position: absolute; inset: 0; pointer-events: none; color: #fff5df; }
#intro-canvas.is-controllable { cursor: grab; touch-action: none; }
#intro-canvas.is-controllable:active { cursor: grabbing; }
.memory-move-guide { position: absolute; bottom: 8%; left: 50%; transform: translateX(-50%); width: max-content; max-width: 94%;
  padding: 18px 26px; text-align: center; border: 1px solid #ebd5a24d; background: #07130cbb; box-shadow: 0 8px 38px #0004; }
.memory-move-guide p { margin: 12px 0 8px; font-size: clamp(15px,1.5cqw,20px); letter-spacing: .02em; }
.memory-move-guide small { font-size: 11px; color: #d6c8a8; }
.memory-guide-stick { position: relative; display: block; width: 62px; height: 62px; margin: auto; border: 1px solid #e9d3a28c; border-radius: 50%; background: #d6d7b310; }
.memory-guide-stick span { position: absolute; inset: 17px; border: 1px solid #ffe3a4; border-radius: 50%; background: #d4b47299; animation: memory-drag-guide 2.3s ease-in-out infinite; }
.memory-guide-stick i { position: absolute; right: -19px; top: -7px; font: 28px Georgia,serif; color: #ffe3a4; animation: memory-guide-glow 2.3s ease-in-out infinite; }
@keyframes memory-drag-guide { 0%,15%,100% { transform: translate(0,0); } 45%,70% { transform: translate(18px,-14px); } }
@keyframes memory-guide-glow { 0%,15%,100% { opacity: .3; } 45%,70% { opacity: 1; } }
.memory-move-timer { position: absolute; top: 7%; left: 50%; transform: translateX(-50%); margin: 0; width: max-content; max-width: 94%;
  padding: 14px 24px; background: #07130cd9; border: 1px solid #e6cc9280; text-align: center; font-size: clamp(14px,1.7cqw,23px); line-height: 1.5; text-shadow: 0 2px 8px #000; }
.memory-joystick { position: absolute; width: 124px; height: 124px; margin: -62px; border: 1px solid #f6e4b780; border-radius: 50%; background: #121c1866; box-shadow: 0 0 0 8px #e3d39d0c; }
.memory-joystick span { position: absolute; left: 40px; top: 40px; width: 42px; height: 42px; border: 1px solid #ffe2a5c9; border-radius: 50%; background: #d4b77e99; }
.memory-message { position: absolute; bottom: 16px; left: 8%; right: 8%; text-align: center; font-size: 12px; color: #f4ddad; margin: 0; pointer-events: none; }
.memory-retry { position: absolute; bottom: 50px; left: 50%; transform: translateX(-50%); padding: 10px 22px; cursor: pointer;
  color: #fff2cc; background: #51442f; border: 1px solid #d4be87; font: inherit; }
@container stage (max-width: 560px) {
  .intro-copy { font-size: 22px; line-height: 1.9; }
  #intro-still { font-size: 18px; }
  .intro-question { padding: 28px 18px; }
  .intro-question h1 { font-size: clamp(21px, 5.8cqw, 30px); margin-bottom: 30px; }
  .intro-mobile-break { display: initial; }
  .intro-answers { flex-direction: row; width: 100%; gap: 10px; }
  .intro-answer { flex: 1; gap: 8px; padding: 14px 8px; font-size: 14px; min-height: 62px; }
  .intro-skip { top: 18px; right: 20px; }
  .intro-sound { top: 22px; left: 20px; }
  .memory-step { top: 9%; }
  .memory-question h1 { top: 14%; font-size: 26px; }
  .memory-answers { width: 92%; gap: 10px; bottom: 8%; }
  .memory-choice { padding: 8px 4px 12px; }
  .memory-choice canvas { max-height: 118px; }
  .memory-choice-face canvas { max-height: 94px; }
  .memory-question[data-kind="gender"] .memory-answers { bottom: 26%; width: 78%; gap: 18px; }
  .memory-question[data-kind="gender"] h1 { top: 32%; }
  .memory-result { flex-direction: column; gap: 30px; padding: 10% 7% 12%; }
  .memory-photo-card { flex: 0 1 auto; width: min(88%, 330px); }
  .memory-photo-front { padding-bottom: 14px; }
  .memory-photo-card figcaption { margin-top: 10px; }
  .memory-result-copy { flex: 0 1 auto; width: 100%; text-align: center; }
  .memory-eyebrow { margin-bottom: 12px; font-size: 11px; }
  .memory-result h1 { font-size: clamp(22px, 6cqw, 30px); line-height: 1.6; margin-bottom: 24px; }
  .memory-notice { margin: -12px 0 20px; font-size: 11px; }
  .memory-result-actions button, .memory-result-actions a { font-size: 14px; padding: 16px 8px; }
  .memory-browse { margin: 16px auto 0; }
  .memory-name-form { bottom: 8%; width: 91%; padding: 16px; }
  .memory-name-controls button { padding: 10px 12px; font-size: 14px; }
}
@media (max-width: 560px) and (max-height: 740px) {
  .memory-result { padding: 28px 7% 40px; gap: 22px; }
  .memory-photo-card { width: min(72%, 250px); }
  .memory-result h1 { font-size: 21px; margin-bottom: 18px; line-height: 1.55; }
  .memory-notice { margin: -10px 0 14px; }
  .memory-eyebrow { margin-bottom: 8px; }
  .memory-result-actions { gap: 9px; }
  .memory-result-actions button, .memory-result-actions a { padding: 12px 8px; }
}
@media (prefers-reduced-motion: reduce) {
  .intro-answer, .memory-choice { transition: none; }
}

.panel-screen { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(8, 10, 14, 0.72); }
.panel { width: min(860px, 96%); max-height: 94%; overflow: auto; padding: 18px 20px;
  background: #2a2420; border: 3px solid #6b5536; box-shadow: inset 0 0 0 2px #1a1612, 0 8px 30px rgba(0,0,0,.6); }
.panel h1 { margin: 0 0 14px; font-size: 20px; text-align: center; color: #f3d48a; letter-spacing: 2px; }
.custom-body { display: flex; gap: 16px; }
/* 창을 스크롤해도 미리보기는 위에 붙어 계속 보인다 */
.preview-box { position: sticky; top: 0; z-index: 1; flex: 0 0 auto; align-self: flex-start; display: flex; flex-direction: column; align-items: center; gap: 8px;
  background: #1a1612; border: 2px solid #4a3c28; padding: 8px; }
#preview { width: 160px; height: 200px; image-rendering: pixelated; background: radial-gradient(#3a4a30, #1e2618); }
.dir-buttons button { width: 40px; }
.rows { flex: 1; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.row { display: flex; align-items: center; gap: 8px; }
.row-label { flex: 0 0 64px; font-size: 13px; color: #cbb68a; white-space: nowrap; }
.options { display: flex; flex-wrap: wrap; gap: 4px; }
.options button, .dir-buttons button { min-width: 30px; height: 30px; padding: 0 6px; font-size: 12px; color: #eee6d2; cursor: pointer;
  background: #3a3128; border: 2px solid #5a4a34; }
.options button.selected { border-color: #f3d48a; background: #5a4a30; }
.options button.chip { width: 30px; padding: 0; }
.options button.icon { width: 44px; height: 44px; padding: 1px; }
.options button.icon canvas { display: block; image-rendering: pixelated; }
/* 장비 줄은 전부 펼쳐 보여 준다 (넘치면 창 자체가 스크롤) */
.row.equip { align-items: flex-start; }
.row.equip .row-label { padding-top: 12px; }
.row.equip .options button:not(.icon) { height: 44px; }
.nickname input { flex: 1; min-width: 0; height: 32px; padding: 0 8px; font-size: 14px; color: #fff; background: #1a1612; border: 2px solid #5a4a34; }
.actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 16px; }
.btn { white-space: nowrap; height: 38px; padding: 0 18px; font-size: 15px; color: #eee6d2; cursor: pointer; background: #3a3128; border: 2px solid #6b5536; }
.btn.primary { background: #6b4a1c; border-color: #f3d48a; color: #fff3cf; }
.btn.small { height: 30px; padding: 0 10px; font-size: 12px; }
.status { margin: 10px 0 0; text-align: center; font-size: 12px; color: #9a8a6a; }

#hud { position: absolute; inset: 0; display: block; font-size: 13px;
  text-shadow: 0 1px 2px #000; pointer-events: none; }
#hud button { pointer-events: auto; }
#places { position: absolute; left: 50%; bottom: 24px; transform: translateX(-50%); display: flex; justify-content: center; gap: 10px; padding: 9px; max-width: 96%; background: #09130dc9; border: 1px solid #bcaa7559; }
#places .btn { min-width: 90px; min-height: 48px; padding: 12px 18px; font-size: 16px; white-space: nowrap; }
#memory-open-card { position: absolute; top: 22px; right: 24px; padding: 0 22px; min-height: 48px; display: flex; align-items: center; justify-content: center; text-align: center; line-height: 1; font-size: 15px; }
@container stage (max-width:560px) {
  #places { bottom: 22px; gap: 5px; padding: 6px; width: 95%; }
  #places .btn { min-width: 0; flex: 1; padding: 12px 7px; font-size: 13px; }
  #memory-open-card { top: 22px; right: 20px; padding: 10px 16px; font-size: 14px; }
}
#places .btn.selected { border-color: #f3d48a; background: #5a4a30; color: #fff3cf; }
#hud #edit { margin-left: auto; }
a.btn { display: inline-flex; align-items: center; text-decoration: none; }

#toast { position: absolute; left: 50%; top: 20%; transform: translateX(-50%); padding: 8px 16px; background: rgba(0,0,0,.75); border: 1px solid #6b5536; font-size: 14px; }

/* 무대가 좁으면(iframe 이 작을 때) 미리보기를 위에 */
@container stage (max-width: 560px) {
  .custom-body { flex-direction: column; align-items: center; }
  /* 세로 배치: 미리보기를 작게 줄여 옆에 회전 버튼을 두고, 창 맨 위(안쪽 여백 18px 만큼 올려)에 붙인다 */
  .preview-box { top: -18px; flex-direction: row; align-self: stretch; justify-content: center; gap: 12px; padding: 6px;
    box-shadow: 0 6px 10px -4px rgba(0,0,0,.7); }
  #preview { width: 112px; height: 140px; }
  .dir-buttons { display: flex; flex-direction: column; gap: 8px; }
  .dir-buttons button { width: 44px; height: 44px; }
  .rows { width: 100%; }
}
.fatal { margin: 40px; color: #f3d48a; font: 15px "Malgun Gothic", sans-serif; }
/* 캐릭터 만들기 창이 떠 있으면 탐방 HUD 는 숨긴다 */
#customize:not(.hidden) ~ #hud { display: none !important; }
/* 세로 화면 창 모드: 게임은 작은 가로 화면, HUD 는 그 아래에 세로 화면 UI 로 */
body.portrait-small #stage { overflow: visible; }
body.portrait-small #hud { top: calc(100% + 12px); flex-wrap: wrap; justify-content: center; }
body.portrait-small #hud #edit { margin-left: 0; }
body.portrait-small #places { flex-basis: 100%; justify-content: center; }
/* 인원·프레임은 테스트 주소(?test)에서만 */
body:not(.test) #online { display: none; }
#hud span { white-space: nowrap; }

/* 사진 */
.photo-sheet { position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); display: flex; gap: 8px; padding: 10px;
  background: #2a2420; border: 3px solid #6b5536; }
#photo-view .photo-box { width: min(860px, 94%); max-height: 94%; display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 12px; background: #2a2420; border: 3px solid #6b5536; }
#photo-img { display: block; max-width: 100%; max-height: calc(var(--u-num, 0.5) * 1080px - 120px); min-height: 0; object-fit: contain; image-rendering: pixelated; border: 2px solid #1a1612; }
#photo-view .actions { margin-top: 8px; }
/* 세로 창 모드: 사진 메뉴는 무대 아래 버튼 줄 자리에 띄우고, 그동안 버튼 줄은 숨긴다 */
body.portrait-small .photo-sheet { bottom: auto; top: calc(100% + 12px); }
body.portrait-small.photo-menu-open #hud { visibility: hidden; }
