:root {
  --ink: #d6d0c4;
  --dim: #8a8478;
  --red: #c4241a;
  --paper: #d8d0b8;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #000; color: var(--ink);
  font-family: 'Nanum Myeongjo', 'Noto Serif KR', serif; user-select: none; -webkit-user-select: none; }
canvas#game { display: block; position: fixed; inset: 0; cursor: crosshair; }
.hidden { display: none !important; }
button { font-family: inherit; }
.touch-only { display: none; }
body.touch .touch-only { display: block; }
body.touch .mouse-only { display: none !important; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; text-shadow: 0 1px 3px #000, 0 0 8px #000; }
#hud-tl { position: absolute; top: max(14px, env(safe-area-inset-top)); left: max(16px, env(safe-area-inset-left)); }
#h-night { font-family: 'Special Elite', monospace; font-size: 15px; letter-spacing: 3px; color: #9a9080; }
#h-obj { font-size: 15px; margin-top: 3px; }
#h-obj b { color: #ffd060; font-weight: 400; }
#h-obj .go { color: #6cff8c; animation: blink 0.8s infinite alternate; }
@keyframes blink { to { opacity: 0.45; } }
#hud-bl { position: absolute; left: max(16px, env(safe-area-inset-left)); bottom: max(16px, env(safe-area-inset-bottom)); width: 190px; }
#h-hp { font-size: 20px; letter-spacing: 3px; margin-bottom: 6px; }
#h-hp .lost { filter: grayscale(1) brightness(0.35); }
.bar { display: flex; align-items: center; gap: 8px; margin-top: 5px; }
.bar i { font-style: normal; font-size: 12px; width: 18px; text-align: center; color: var(--dim); }
.track { flex: 1; height: 6px; background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.12); border-radius: 3px; overflow: hidden; }
.fill { height: 100%; width: 100%; transition: width 0.1s linear; }
.fill.sta { background: linear-gradient(90deg, #8a8a8a, #e0e0d8); }
.fill.sta.ex { background: #a03020; }
.fill.bat { background: linear-gradient(90deg, #b8a040, #fff0a0); }
.fill.bat.low { background: #c04030; animation: blink 0.4s infinite alternate; }
.fill.breath { background: linear-gradient(90deg, #4070c0, #a0d0ff); }
.fill.breath.low { background: #c04030; }
#hud-tr { position: absolute; top: max(12px, env(safe-area-inset-top)); right: max(16px, env(safe-area-inset-right)); display: flex; align-items: center; gap: 12px; pointer-events: auto; }
#h-inv { font-size: 15px; letter-spacing: 1px; pointer-events: none; }
#h-inv span { margin-left: 10px; }
#h-inv .fz { color: #ffd060; }
#hud-tr button { background: rgba(0,0,0,0.4); border: 1px solid rgba(255,255,255,0.15); color: var(--dim); border-radius: 4px; width: 34px; height: 30px; cursor: pointer; font-size: 13px; }
#prompt { position: absolute; left: 50%; bottom: 22%; transform: translateX(-50%); font-size: 16px; padding: 6px 14px; background: rgba(0,0,0,0.55); border: 1px solid rgba(255,255,255,0.15); border-radius: 4px; white-space: nowrap; }
#prompt:empty { display: none; }
#prompt kbd { font-family: 'Special Elite', monospace; color: #ffd060; margin-right: 6px; }
#hint { position: absolute; top: 15%; left: 50%; transform: translateX(-50%); width: min(560px, 86vw); text-align: center; font-size: 15px; line-height: 1.6; color: #e8dcc0;
  background: rgba(0,0,0,0.5); border-left: 2px solid #8a1a12; padding: 8px 14px; transition: opacity 0.6s; }
#hint:empty { display: none; }
#msgs { position: absolute; left: 50%; bottom: 30%; transform: translateX(-50%); text-align: center; width: 90vw; }
.msg { font-size: 17px; margin-top: 4px; transition: opacity 0.8s, transform 0.8s; }
.msg.out { opacity: 0; transform: translateY(-10px); }
#hidebox { position: absolute; left: 50%; bottom: 10%; transform: translateX(-50%); width: min(340px, 70vw); text-align: center; }
#hide-warn { color: #ff5a4a; font-size: 18px; margin-bottom: 8px; opacity: 0; transition: opacity 0.3s; }
#hide-warn.on { opacity: 1; animation: blink 0.5s infinite alternate; }
.bar.wide .track { height: 9px; }
.hide-keys { margin-top: 8px; font-size: 13px; color: var(--dim); }
.hide-keys b { color: #ffd060; font-weight: 400; font-family: 'Special Elite', monospace; }
#crouch-tag { position: absolute; left: max(16px, env(safe-area-inset-left)); bottom: calc(max(16px, env(safe-area-inset-bottom)) + 92px); font-size: 12px; color: #9ab; letter-spacing: 2px; }

/* ---------- 오버레이 ---------- */
.ov { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 20; background: rgba(0,0,0,0.78); overflow-y: auto; padding: 16px; }
#ov-title { background: radial-gradient(ellipse at 50% 40%, rgba(40,0,0,0.5), #000 70%); }
.box { text-align: center; max-width: 560px; width: 100%; margin: auto; }
h1 { font-size: clamp(56px, 14vw, 110px); font-weight: 800; margin: 0; color: #d8d0c4; letter-spacing: 0.1em; position: relative;
  text-shadow: 0 0 30px rgba(180,0,0,0.6); animation: flick 5s infinite; }
h1::after { content: attr(data-t); position: absolute; left: 0; right: 0; top: 0; color: #a01010; mix-blend-mode: screen; opacity: 0; animation: ghost 5s infinite; }
@keyframes flick { 0%, 92%, 100% { opacity: 1; } 93% { opacity: 0.3; } 94% { opacity: 1; } 96% { opacity: 0.5; } 97% { opacity: 1; } }
@keyframes ghost { 0%, 91%, 100% { opacity: 0; transform: none; } 92% { opacity: 0.8; transform: translate(6px, -2px) skewX(-8deg); } 95% { opacity: 0.6; transform: translate(-5px, 2px); } }
.sub { font-family: 'Special Elite', monospace; letter-spacing: 0.6em; color: #8a1a12; margin: 6px 0 26px; font-size: 14px; }
.lead { color: #a8a090; line-height: 1.9; font-size: 15px; margin: 0 0 26px; white-space: pre-line; }
.lead em { color: #d8c8a8; font-style: normal; }
.btn { display: block; width: 240px; margin: 10px auto; padding: 12px; font-size: 17px; background: transparent; color: #e8e0d0; border: 1px solid #6a1a14;
  cursor: pointer; letter-spacing: 0.2em; transition: background 0.2s, border-color 0.2s; }
.btn:hover { background: rgba(140,20,14,0.25); border-color: #c4241a; }
.btn.ghost { border-color: #333; color: var(--dim); }
.btn.small { width: 160px; padding: 8px; font-size: 15px; }
.rec { color: var(--dim); font-size: 13px; margin-top: 18px; min-height: 18px; }
.phones { color: #6a645a; font-size: 12px; margin-top: 10px; }
.night-big { font-family: 'Special Elite', monospace; font-size: clamp(40px, 10vw, 72px); letter-spacing: 0.25em; color: #d8d0c4; margin-bottom: 14px; text-shadow: 0 0 24px rgba(160,0,0,0.6); }
.night-big.small { font-size: 32px; }
.night-big.red { color: #c4241a; font-family: 'Nanum Myeongjo', serif; font-weight: 800; }
.night-big.green { color: #8ad8a0; text-shadow: 0 0 24px rgba(40,160,80,0.5); }
.tap { color: var(--dim); font-size: 13px; animation: blink 1s infinite alternate; }
#ov-intro { cursor: pointer; background: #000; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0 22px; }
.stats div { border: 1px solid #2a2420; padding: 10px 4px; }
.stats b { display: block; font-size: 22px; color: #e8dcc0; font-family: 'Special Elite', monospace; }
.stats span { font-size: 12px; color: var(--dim); }
.paper { background: var(--paper); color: #2a2018; width: min(460px, 92vw); padding: 26px 28px 18px; margin: auto; transform: rotate(-1deg);
  box-shadow: 0 10px 50px #000; background-image: repeating-linear-gradient(transparent 0 27px, rgba(60,80,140,0.15) 27px 28px); font-family: 'Nanum Myeongjo', serif; }
.paper-h { font-weight: 800; font-size: 17px; margin-bottom: 14px; border-bottom: 1px solid rgba(0,0,0,0.25); padding-bottom: 8px; }
.paper-b { font-size: 16px; line-height: 1.85; white-space: pre-line; min-height: 90px; }
.paper-f { font-size: 12px; color: #6a5a48; margin: 14px 0 6px; text-align: right; }
.paper .btn { color: #2a2018; border-color: #6a5a48; }
.mapbox { max-width: 900px; }
.map-h { font-family: 'Special Elite', monospace; letter-spacing: 0.3em; margin-bottom: 8px; }
#plan { width: min(860px, 92vw); height: min(560px, 62vh); display: block; margin: 0 auto; box-shadow: 0 6px 30px #000; }
.map-f { color: var(--dim); font-size: 13px; margin: 8px 0; }
.help div { margin: 7px 0; font-size: 15px; }
.help p { color: #a8a090; font-size: 14px; line-height: 1.7; text-align: left; margin: 8px 0; }
kbd { font-family: 'Special Elite', monospace; color: #ffd060; border: 1px solid #4a4030; padding: 0 5px; border-radius: 3px; font-size: 13px; }
#rotate { display: none; }

/* ---------- 터치 ---------- */
#touch { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#joy { position: absolute; width: 120px; height: 120px; margin: -60px 0 0 -60px; border-radius: 50%; border: 2px solid rgba(255,255,255,0.15); background: rgba(255,255,255,0.04); display: none; }
body.touch #joy { display: block; opacity: 0.55; transition: opacity 0.2s; }
#joy.on { display: block; opacity: 1 !important; transition: none; }
#joy::after { content: '끌어서 이동 · 멀리 끌면 달리기'; position: absolute; left: 50%; top: 100%; transform: translateX(-50%); margin-top: 6px; white-space: nowrap; font-size: 10px; color: rgba(255,255,255,0.45); }
#joy.on::after { content: ''; }
#b-act:not(.none) { animation: actPulse 1.1s ease-in-out infinite; }
@keyframes actPulse { 50% { box-shadow: 0 0 0 6px rgba(220,90,70,0.25); } }
#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,0.18); border: 1px solid rgba(255,255,255,0.3); }
#joy.run #joy-knob { background: rgba(255,90,60,0.35); border-color: rgba(255,120,90,0.7); }
.tb { position: absolute; pointer-events: auto; width: 58px; height: 58px; border-radius: 50%; background: rgba(15,12,10,0.6); border: 1px solid rgba(255,255,255,0.2); color: var(--ink);
  font-size: 22px; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1; touch-action: none; -webkit-tap-highlight-color: transparent; }
.tb small { font-size: 9px; margin-top: 3px; color: var(--dim); }
.tb:active, .tb.down { background: rgba(140,30,20,0.5); }
.tb.on { border-color: #ffd060; }
.tb.off { opacity: 0.4; }
.tb.big { width: 84px; height: 84px; font-size: 15px; background: rgba(60,14,10,0.6); border-color: rgba(220,90,70,0.6); }
#b-act { right: calc(max(18px, env(safe-area-inset-right)) + 10px); bottom: calc(max(18px, env(safe-area-inset-bottom)) + 70px); }
#b-act.none { opacity: 0.35; }
#b-throw { right: calc(max(18px, env(safe-area-inset-right)) + 104px); bottom: calc(max(18px, env(safe-area-inset-bottom)) + 40px); }
#b-light { right: calc(max(18px, env(safe-area-inset-right)) + 104px); bottom: calc(max(18px, env(safe-area-inset-bottom)) + 108px); }
#b-crouch { right: calc(max(18px, env(safe-area-inset-right)) + 22px); bottom: calc(max(18px, env(safe-area-inset-bottom)) + 166px); }
#b-band { right: calc(max(18px, env(safe-area-inset-right)) + 172px); bottom: calc(max(18px, env(safe-area-inset-bottom)) + 40px); }
#b-breath { right: calc(max(18px, env(safe-area-inset-right)) + 10px); bottom: calc(max(18px, env(safe-area-inset-bottom)) + 166px); width: 96px; height: 96px; }
body.touch #hud-bl { bottom: max(14px, env(safe-area-inset-bottom)); width: 150px; }
body.touch #prompt { bottom: auto; top: 24%; }
body.touch #msgs { bottom: auto; top: 32%; }
@media (max-height: 500px) {
  .tb { width: 50px; height: 50px; font-size: 19px; }
  .tb.big { width: 72px; height: 72px; }
  #b-act { bottom: calc(max(12px, env(safe-area-inset-bottom)) + 52px); }
  #b-throw { right: calc(max(18px, env(safe-area-inset-right)) + 92px); bottom: calc(max(12px, env(safe-area-inset-bottom)) + 24px); }
  #b-light { right: calc(max(18px, env(safe-area-inset-right)) + 92px); bottom: calc(max(12px, env(safe-area-inset-bottom)) + 84px); }
  #b-crouch { bottom: calc(max(12px, env(safe-area-inset-bottom)) + 134px); }
  #b-band { right: calc(max(18px, env(safe-area-inset-right)) + 152px); bottom: calc(max(12px, env(safe-area-inset-bottom)) + 24px); }
  #b-breath { bottom: calc(max(12px, env(safe-area-inset-bottom)) + 134px); width: 84px; height: 84px; }
  #hint { top: 12%; font-size: 13px; padding: 6px 10px; }
  .btn { padding: 9px; margin: 7px auto; }
  .lead { margin-bottom: 14px; line-height: 1.7; }
  .sub { margin-bottom: 14px; }
}
@media (orientation: portrait) {
  body.touch #hud-bl { bottom: auto; top: calc(max(14px, env(safe-area-inset-top)) + 64px); }
  body.touch:not(.rot-ok) #rotate { position: fixed; left: 50%; top: calc(max(10px, env(safe-area-inset-top)) + 46px); transform: translateX(-50%); z-index: 50; display: flex; align-items: center; gap: 10px;
    background: rgba(10,8,7,0.88); border: 1px solid rgba(255,255,255,0.15); border-radius: 10px; padding: 8px 12px; font-size: 22px; white-space: nowrap; pointer-events: auto; }
  #rotate p { font-size: 12px; color: var(--dim); margin: 0; }
  #rotate .btn { margin: 0; padding: 6px 10px; font-size: 12px; width: auto; }
}

/* 첫 밤 안내 */
.howto { margin: -8px auto 22px; max-width: 480px; }
.howto .steps { display: flex; gap: 8px; justify-content: center; margin-bottom: 14px; }
.howto .steps div { flex: 1; border: 1px solid #4a2a20; padding: 10px 4px; font-size: 15px; background: rgba(60,10,6,0.25); }
.howto .steps b { display: block; font-family: 'Special Elite', monospace; color: #ffd060; font-size: 22px; font-weight: 400; margin-bottom: 4px; }
.howto p { margin: 6px 0; font-size: 14px; color: #b8b0a0; line-height: 1.6; }
.howto em { color: #e8d8b0; font-style: normal; }
.howto .arrow { color: #ffd250; }
.howto .r { color: #ff3a2a; }
@media (max-height: 500px) {
  .howto { margin-bottom: 10px; }
  .howto .steps div { padding: 6px 2px; font-size: 13px; }
  .howto .steps b { font-size: 17px; margin-bottom: 2px; }
  .howto p { font-size: 12px; margin: 3px 0; }
  #ov-intro .night-big { font-size: 34px; margin-bottom: 6px; }
  #ov-intro .lead { margin-bottom: 10px; }
}
