:root {
  --ink: #2b2420;
  --ink-soft: #6b5f57;
  --paper: #fffaf3;
  --card: #ffffff;
  --line: #eadfd2;
  --accent: #e8664a;
  --accent-dark: #c94f36;
  --like: #e0507a;
  --shadow: 0 18px 50px rgba(60, 35, 20, .22);
  --font: "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR", "Malgun Gothic", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #f3ece2; color: var(--ink); font-family: var(--font); -webkit-tap-highlight-color: transparent; }
#stage { position: fixed; inset: 0; touch-action: none; }
#stage canvas { display: block; width: 100%; height: 100%; outline: none; }
.hidden { display: none !important; }

.btn { font: inherit; font-size: 15px; font-weight: 600; border: 1px solid var(--line); background: rgba(255,255,255,.94); color: var(--ink); padding: 10px 16px; border-radius: 999px; cursor: pointer; box-shadow: 0 4px 14px rgba(60,35,20,.12); white-space: nowrap; }
.btn:hover { background: #fff; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .6; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-lg { font-size: 18px; padding: 14px 40px; }
.btn-like.liked { background: var(--like); border-color: var(--like); color: #fff; }

/* 첫 화면 */
.overlay { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 20; }
.intro { background: radial-gradient(ellipse at center, rgba(255,247,236,.55), rgba(70,45,30,.55)); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
.intro-card { background: rgba(255,250,243,.96); border-radius: 22px; padding: 34px 32px 24px; max-width: 620px; width: 100%; text-align: center; box-shadow: var(--shadow); max-height: calc(100% - 8px); overflow: auto; }
.intro-kicker { margin: 0 0 6px; color: var(--accent); font-weight: 700; letter-spacing: .02em; }
.intro h1 { margin: 0 0 8px; font-size: clamp(28px, 6vw, 42px); letter-spacing: -.02em; }
.intro-lead { margin: 0 0 22px; font-size: 17px; color: var(--ink-soft); }
.intro-guide { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 24px; text-align: left; }
.intro-guide > div { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.intro-guide h3 { margin: 0 0 6px; font-size: 14px; color: var(--accent-dark); }
.intro-guide ul { margin: 0; padding-left: 18px; font-size: 13.5px; line-height: 1.65; color: var(--ink-soft); }
.intro-note { margin: 16px 0 0; font-size: 12.5px; color: #9a8c80; }

/* HUD */
.hud { position: fixed; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: max(12px, env(safe-area-inset-top)) 14px 0; z-index: 10; pointer-events: none; }
.hud > * { pointer-events: auto; }
.hud-room { background: rgba(255,255,255,.92); border-radius: 999px; padding: 9px 14px; font-weight: 700; font-size: 14px; box-shadow: 0 4px 14px rgba(60,35,20,.12); display: flex; align-items: center; gap: 8px; white-space: nowrap; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.hud-room .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; }
.hud-actions { display: flex; gap: 8px; flex: none; }

.prompt { position: fixed; left: 50%; bottom: 34px; transform: translateX(-50%); z-index: 10; font: inherit; font-weight: 700; font-size: 16px; background: rgba(43,36,32,.9); color: #fff; border: 0; border-radius: 999px; padding: 13px 24px; cursor: pointer; box-shadow: 0 8px 22px rgba(0,0,0,.25); animation: pop .25s ease; white-space: nowrap; }
@keyframes pop { from { transform: translateX(-50%) scale(.9); opacity: 0; } }

.joystick { position: fixed; left: 22px; bottom: 26px; width: 120px; height: 120px; border-radius: 50%; background: rgba(255,255,255,.35); border: 2px solid rgba(255,255,255,.75); z-index: 9; touch-action: none; backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px); }
.joy-knob { position: absolute; left: 50%; top: 50%; width: 50px; height: 50px; margin: -25px 0 0 -25px; border-radius: 50%; background: rgba(255,255,255,.95); box-shadow: 0 4px 12px rgba(0,0,0,.2); }

.toast { position: fixed; left: 50%; top: 74px; transform: translateX(-50%); background: rgba(43,36,32,.92); color: #fff; padding: 11px 18px; border-radius: 12px; font-size: 14.5px; z-index: 40; box-shadow: var(--shadow); max-width: calc(100% - 32px); text-align: center; }

/* 모달 공통 */
.modal { background: rgba(40,28,20,.45); z-index: 30; }
.modal-card { position: relative; background: var(--paper); border-radius: 20px; box-shadow: var(--shadow); max-height: calc(100% - 8px); overflow: auto; }
.close-x { position: absolute; top: 12px; right: 12px; font: inherit; font-size: 13px; background: #fff; border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; cursor: pointer; z-index: 2; }
.modal h2 { margin: 0 0 4px; font-size: 22px; }
.form-note { margin: 0 0 16px; color: var(--accent-dark); font-size: 13.5px; font-weight: 600; }

/* 미리보기 카드 */
.preview-card { position: fixed; right: 16px; bottom: 24px; z-index: 11; width: 260px; padding: 10px 10px 8px; border: 0; border-radius: 16px; background: rgba(255,250,243,.97); box-shadow: var(--shadow); cursor: pointer; font: inherit; display: flex; flex-direction: column; gap: 6px; animation: slideIn .22s ease; }
@keyframes slideIn { from { transform: translateY(14px); opacity: 0; } }
.preview-card img { width: 100%; height: 190px; object-fit: contain; background: #efe6da; border-radius: 10px; display: block; }
.preview-no { font-weight: 800; font-size: 15px; color: var(--accent-dark); text-align: left; letter-spacing: .02em; }
.preview-hint { font-size: 12.5px; color: var(--ink-soft); }

/* 전체 보기 */
.viewer { position: fixed; inset: 0; z-index: 30; background: rgba(24,18,14,.94); display: flex; flex-direction: column; }
.viewer-img { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 16px; position: relative; }
.viewer-img img { max-width: 100%; max-height: 100%; object-fit: contain; display: block; box-shadow: 0 10px 40px rgba(0,0,0,.5); background: #fff; }
.viewer-loading { position: absolute; bottom: 24px; left: 50%; transform: translateX(-50%); color: #fff; font-size: 13px; background: rgba(0,0,0,.45); padding: 6px 12px; border-radius: 999px; }
.viewer-bar { display: flex; align-items: center; gap: 12px; padding: 12px 16px max(14px, env(safe-area-inset-bottom)); color: #f3ece2; }
.viewer-meta { flex: 1; min-width: 0; text-align: center; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.viewer-meta b { color: #ffb59f; margin-right: 6px; }
.viewer-artist { color: #c9bcae; margin-left: 6px; font-size: 13px; }

/* 출품 창 */
.form-card { width: min(460px, 100%); padding: 24px 22px 20px; display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; }
.field input[type=text], .field input[type=file] { font: inherit; font-weight: 400; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; width: 100%; }
.file-preview { max-height: 120px; max-width: 100%; object-fit: contain; border-radius: 8px; border: 1px solid var(--line); align-self: flex-start; }
.line-choices { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.line-choice { position: relative; border: 2px solid var(--line); border-radius: 10px; background: #fff; padding: 4px; cursor: pointer; font-size: 11.5px; font-weight: 600; text-align: center; color: var(--ink-soft); }
.line-choice img { width: 100%; height: 56px; object-fit: cover; display: block; border-radius: 6px; margin-bottom: 3px; }
.line-choice input { position: absolute; opacity: 0; pointer-events: none; }
.line-choice:has(input:checked) { border-color: var(--accent); color: var(--ink); }
.line-choice.checked { border-color: var(--accent); color: var(--ink); }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

/* 지도 */
.map-card { width: min(380px, 100%); padding: 24px 22px 22px; }
.map { display: flex; flex-direction: column; align-items: stretch; gap: 0; }
.map-room { width: 100%; font: inherit; border: 2px solid var(--line); background: #fff; border-radius: 12px; padding: 8px 12px; cursor: pointer; display: flex; flex-direction: column; gap: 3px; text-align: left; position: relative; }
.map-room:hover { border-color: var(--accent); }
.map-room b { font-size: 15px; }
.map-room span { font-size: 12.5px; color: var(--ink-soft); }
.map-room.here { border-color: var(--accent); background: #fff4ef; }
.map-room.here::after { content: "지금 여기"; position: absolute; right: 12px; top: 12px; font-size: 11.5px; font-weight: 700; color: #fff; background: var(--accent); border-radius: 999px; padding: 3px 8px; }
.map-arrow { text-align: center; font-size: 11px; color: #9a8c80; padding: 2px 0; }
.map-arrow::before { content: ""; display: block; width: 2px; height: 5px; background: #d9cbb8; margin: 0 auto 2px; }

@media (max-width: 720px) {
  .preview-card { width: 200px; right: 12px; bottom: 16px; }
  .preview-card img { height: 140px; }
  .intro-card { padding: 26px 18px 18px; }
  .intro-guide { grid-template-columns: 1fr; gap: 10px; margin-top: 18px; }
}
@media (max-width: 420px) {
  .hud { padding-left: 10px; padding-right: 10px; }
  .btn { font-size: 13.5px; padding: 9px 12px; }
  .hud-room { font-size: 13px; padding: 8px 11px; }
  .btn-lg { font-size: 17px; padding: 13px 34px; }
  .prompt { bottom: 160px; font-size: 15px; }
  .joystick { width: 108px; height: 108px; left: 16px; bottom: 20px; }
}

/* 스테이지 넘어갈 때 하얗게 */
.fade { position: fixed; inset: 0; background: #fff8ee; opacity: 0; pointer-events: none; transition: opacity .36s ease; z-index: 50; }
.fade.on { opacity: 1; pointer-events: auto; }
.map-stage { background: #fff3e6; border-style: dashed; }

/* 닉네임 */
.nick-row { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.nick-input { font: inherit; font-size: 17px; width: min(300px, 100%); padding: 12px 16px; border: 2px solid var(--line); border-radius: 999px; background: #fff; text-align: center; outline: none; }
.nick-input:focus { border-color: var(--accent); }
.nick-note { margin: 8px 0 0; font-size: 12.5px; color: #9a8c80; }
@media (max-height: 560px) { .intro-guide { display: none; } .intro-lead { margin-bottom: 12px; } .intro-card { padding-top: 18px; } }

/* 점프 버튼(휴대폰) */
.jump-btn { position: fixed; right: 18px; bottom: 28px; width: 78px; height: 78px; border-radius: 50%; border: 2px solid rgba(255,255,255,.85); background: rgba(232,102,74,.88); color: #fff; font: inherit; font-weight: 800; font-size: 16px; z-index: 9; touch-action: none; box-shadow: 0 6px 16px rgba(0,0,0,.22); -webkit-user-select: none; user-select: none; }
.jump-btn:active { transform: scale(.94); }
.touch .preview-card { bottom: 122px; }
/* 자동 카메라 스위치 */
.switch-row { display: flex; gap: 12px; align-items: center; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin: 6px 0 10px; }
.switch-row div { display: flex; flex-direction: column; gap: 2px; font-size: 14px; }
.switch-row span { font-size: 12px; color: var(--ink-soft); line-height: 1.4; }
.switch { position: relative; width: 48px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; inset: 0; background: #d9cfc4; border-radius: 999px; transition: background .2s; cursor: pointer; }
.slider::before { content: ""; position: absolute; width: 22px; height: 22px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: transform .2s; box-shadow: 0 1px 4px rgba(0,0,0,.2); }
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(20px); }

/* 성별(옷) 선택 */
.gender-row { display: flex; gap: 10px; }
.g-btn { display: flex; align-items: center; gap: 6px; font: inherit; font-weight: 700; font-size: 16px; padding: 6px 16px 6px 8px; border: 2px solid var(--line); background: #fff; border-radius: 999px; cursor: pointer; color: var(--ink-soft); }
.g-btn svg { width: 30px; height: 36px; }
.g-btn.on { border-color: var(--accent); color: var(--ink); background: #fff4ef; }

/* 건배 버튼 */
.cheers-btn { position: fixed; left: 16px; bottom: 24px; width: 70px; height: 70px; border-radius: 50%; border: 2px solid rgba(255,255,255,.85); background: rgba(201,162,74,.92); color: #fff; font: inherit; font-weight: 800; font-size: 15px; z-index: 9; touch-action: none; box-shadow: 0 6px 16px rgba(0,0,0,.22); display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1; -webkit-user-select: none; user-select: none; }
.cheers-btn:active { transform: scale(.94); }
.cheers-btn.cool { opacity: .55; }
.cheers-count { font-size: 11px; font-weight: 600; opacity: .9; }
.touch .cheers-btn { left: auto; right: 106px; bottom: 32px; width: 66px; height: 66px; }
/* 오프닝 */
.open-banner { position: fixed; left: 50%; top: 70px; transform: translateX(-50%); z-index: 12; background: linear-gradient(90deg, #e8664a, #c9a24a); color: #fff; font-weight: 800; font-size: 18px; padding: 12px 22px; border-radius: 999px; box-shadow: var(--shadow); white-space: nowrap; animation: pop .35s ease; max-width: calc(100% - 24px); }
.countdown { position: fixed; left: 50%; top: 40%; transform: translate(-50%, -50%); z-index: 12; font-size: 96px; font-weight: 900; color: #fff; text-shadow: 0 6px 24px rgba(0,0,0,.35); pointer-events: none; }
.countdown.go { font-size: 64px; }
/* 굿즈샵 카드 */
.shop-card { position: fixed; right: 16px; bottom: 24px; z-index: 11; width: 260px; padding: 14px; border-radius: 16px; background: rgba(255,250,243,.97); box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 8px; animation: slideIn .22s ease; }
.shop-card b { font-size: 17px; color: var(--accent-dark); }
.shop-card span { font-size: 13px; color: var(--ink-soft); }
.shop-card .btn { text-align: center; text-decoration: none; font-size: 14px; }
.touch .shop-card { right: 12px; bottom: 122px; width: 220px; }
/* 전체 보기 구매 링크 */
.viewer-meta { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.buy-link { color: #ffcfb8; font-size: 12.5px; text-decoration: underline; }
.replay-btn { width: 100%; margin: 0 0 10px; }

/* 머리 모양·색 고르기 */
.hair-pick { display: flex; flex-direction: column; align-items: center; gap: 6px; width: 100%; }
.pick-label { font-size: 12.5px; font-weight: 700; color: var(--ink-soft); }
.hair-grid { display: grid; grid-template-columns: repeat(4, 68px); gap: 8px; justify-content: center; }
.hair-btn { width: 68px; height: 68px; border-radius: 14px; border: 2px solid var(--line); background-color: #f1efec; background-repeat: no-repeat; cursor: pointer; padding: 0; position: relative; }
.hair-btn.on { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(232,102,74,.25); }
.hair-btn span { position: absolute; left: 4px; top: 3px; font-size: 10px; font-weight: 800; color: #8a7a6c; }
.hair-colors { display: flex; gap: 12px; justify-content: center; }
.hair-chip { width: 34px; height: 34px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 2px var(--line); cursor: pointer; padding: 0; }
.hair-chip.on { box-shadow: 0 0 0 3px var(--accent); }
.guide-toggle { display: none; margin: 10px auto 0; font: inherit; font-size: 13px; background: none; border: 0; color: var(--accent-dark); text-decoration: underline; cursor: pointer; }
@media (max-width: 480px) {
  .intro-card { padding: 18px 14px 14px; }
  .intro h1 { font-size: 26px; }
  .intro-kicker { font-size: 13px; margin-bottom: 2px; }
  .intro-lead { font-size: 14px; margin-bottom: 12px; }
  .nick-row { gap: 8px; }
  .nick-input { padding: 9px 14px; font-size: 16px; }
  .g-btn { padding: 3px 14px 3px 6px; }
  .g-btn svg { width: 24px; height: 30px; }
  .guide-toggle { display: block; }
  .intro-guide { display: none; }
  .intro-guide.open { display: grid; }
  .nick-note { font-size: 11.5px; margin-top: 6px; }
}
