:root {
  --ink: #2b2420;
  --paper: #f3ede1;
  --paper-2: #e8dfcd;
  --gold: #c9a24a;
  --red: #a8432f;
  --glass: rgba(30, 24, 20, 0.55);
  --glass-line: rgba(255, 244, 222, 0.18);
  --text-on-glass: #fbf5e8;
  --font: 'Gowun Dodum', system-ui, sans-serif;
  --font-round: 'Jua', 'Gowun Dodum', sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--ink); color: var(--text-on-glass); font-family: var(--font); }
body { -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none; overscroll-behavior: none; }
button { font: inherit; color: inherit; }

#stage { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }

/* 위 막대 */
.topbar {
  position: fixed; top: max(12px, env(safe-area-inset-top)); left: 12px; right: 12px; z-index: 10;
  display: flex; justify-content: space-between; align-items: center; pointer-events: none;
}
.pill {
  pointer-events: auto; display: flex; align-items: center; gap: 6px; height: 44px; padding: 0 14px;
  background: var(--glass); border: 1px solid var(--glass-line); border-radius: 999px;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); color: var(--text-on-glass);
}
.brand b { font-family: var(--font-round); font-weight: 400; font-size: 17px; letter-spacing: .08em; }
.brand-mark { opacity: .8; }
.brand-mark.big { font-size: 30px; }
.zone { font-size: 13px; opacity: .7; padding-left: 8px; margin-left: 4px; border-left: 1px solid var(--glass-line); }
.zone:empty { display: none; }
.tools { padding: 0 4px; gap: 0; }
.icon-btn {
  width: 40px; height: 40px; border: 0; background: none; border-radius: 50%; display: grid; place-items: center; cursor: pointer;
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:hover { background: rgba(255,255,255,.1); }
.icon-btn:focus-visible, .act:focus-visible, .primary:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
#btn-sound .wave { display: none; }
#btn-sound[aria-pressed="true"] .wave { display: inline; }
#btn-sound[aria-pressed="true"] .mute { display: none; }

.hint {
  position: fixed; top: calc(max(12px, env(safe-area-inset-top)) + 58px); left: 0; right: 0; margin: 0; text-align: center;
  font-size: 13px; color: var(--text-on-glass); text-shadow: 0 1px 4px rgba(0,0,0,.6); pointer-events: none;
  transition: opacity 1s ease; z-index: 5;
}
.hint.hide { opacity: 0; }

/* 아래 행동 막대 */
.actions {
  position: fixed; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 10;
  display: flex; gap: 4px; padding: 6px; background: var(--glass); border: 1px solid var(--glass-line); border-radius: 22px;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); transition: opacity .3s ease, transform .3s ease;
}
.actions:empty { opacity: 0; pointer-events: none; transform: translate(-50%, 10px); }
.act {
  min-width: 76px; height: 56px; border: 0; border-radius: 16px; background: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 13px;
}
.act:hover { background: rgba(255,255,255,.1); }
.act .glyph { font-size: 20px; line-height: 1; }
.act.on { background: rgba(201,162,74,.35); }
.counter {
  position: fixed; left: 50%; bottom: calc(max(16px, env(safe-area-inset-bottom)) + 80px); transform: translateX(-50%); z-index: 10;
  font-family: var(--font-round); font-size: 26px; letter-spacing: .06em; color: #fff7e4; text-shadow: 0 2px 10px rgba(0,0,0,.55);
}
.counter small { font-size: 15px; opacity: .75; }

.toast {
  position: fixed; left: 12px; bottom: calc(max(16px, env(safe-area-inset-bottom)) + 80px); z-index: 11; max-width: calc(100% - 24px);
  padding: 9px 14px; border-radius: 12px; background: var(--glass); border: 1px solid var(--glass-line); font-size: 13px;
  opacity: 0; transform: translateY(6px); transition: opacity .35s ease, transform .35s ease; pointer-events: none;
}
.toast.show { opacity: 1; transform: none; }

/* 나가기 */
.leave { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; background: rgba(243,237,225,.96); color: var(--ink); padding: 16px; }
.leave[hidden] { display: none; }
.leave-card { text-align: center; }
.leave-card h2 { font-family: var(--font-round); font-weight: 400; font-size: 26px; margin: 10px 0 6px; letter-spacing: .1em; }
.leave-card p { margin: 0 0 22px; line-height: 1.7; opacity: .75; }
.primary {
  height: 48px; padding: 0 26px; border-radius: 999px; border: 0; cursor: pointer;
  background: var(--ink); color: var(--paper); font-size: 15px;
}
/* 설정 시트 */
.sheet {
  position: fixed; top: calc(max(12px, env(safe-area-inset-top)) + 54px); right: 12px; z-index: 30;
  width: min(360px, calc(100% - 24px)); max-height: calc(100% - 90px); overflow-y: auto;
  padding: 14px 16px 18px; border-radius: 18px; background: rgba(250,246,238,.97); color: var(--ink);
  box-shadow: 0 12px 40px rgba(0,0,0,.25);
}
.sheet[hidden] { display: none; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.sheet h2 { margin: 0; font-family: var(--font-round); font-weight: 400; font-size: 20px; }
.sheet h3 { margin: 16px 0 6px; font-size: 13px; opacity: .6; font-weight: 400; }
.sheet .row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 40px; font-size: 14px; }
.sheet input[type=range] { width: 55%; accent-color: var(--red); }
.sheet input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--red); }
.sheet .note { margin: 4px 0 8px; font-size: 12.5px; opacity: .7; line-height: 1.5; }
.sheet .close { color: var(--ink); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chip { height: 34px; padding: 0 12px; border-radius: 999px; border: 1px solid rgba(43,36,32,.2); background: none; color: var(--ink); cursor: pointer; font-size: 13px; }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }

/* 염주 화면 */
.beads {
  position: fixed; inset: 0; z-index: 35; overflow: hidden; touch-action: none;
  background: radial-gradient(120% 90% at 30% 40%, #3b2a20 0%, #1e1611 70%);
}
.beads[hidden] { display: none; }
.beads .back { position: absolute; top: max(12px, env(safe-area-inset-top)); left: 12px; cursor: pointer; font-size: 14px; }
.beads-count {
  position: absolute; left: 28px; top: 50%; transform: translateY(-50%); font-family: var(--font-round);
  color: #fbf0d8; text-shadow: 0 2px 12px rgba(0,0,0,.5);
}
.beads-count b { font-weight: 400; font-size: 64px; }
.beads-count small { font-size: 22px; opacity: .7; }
.beads-count .rounds { display: block; font-size: 16px; opacity: .7; }
.beads-ring { position: absolute; right: 0; top: 0; height: 100%; width: auto; max-width: 70%; }
.beads-ring .ring { transition: transform .18s ease-out; }
.beads-hint {
  position: absolute; bottom: max(24px, env(safe-area-inset-bottom)); left: 0; right: 0; text-align: center;
  margin: 0; font-size: 13px; color: #fbf0d8; opacity: .65;
}
@media (prefers-reduced-motion: reduce) { .beads-ring .ring { transition: none; } }

/* 쉼터 */
.scene-list { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 8px 0 4px; }
.scene-card {
  min-height: 52px; padding: 8px 10px; border-radius: 12px; border: 1px solid rgba(43,36,32,.15);
  background: #efe6d4; color: var(--ink); cursor: pointer; font-size: 13.5px; text-align: left;
}
.scene-card:hover { background: #e6dac2; }
.retreat-sheet .retreat-live { display: none; }
.retreat-sheet.live .retreat-live { display: block; }
.retreat-sheet .primary { width: 100%; margin-top: 8px; }
body.retreating .topbar, body.retreating .actions, body.retreating .hint, body.retreating .counter { opacity: 0; pointer-events: none; }
.retreat-peek {
  position: fixed; left: 50%; bottom: max(18px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 12;
  display: flex; gap: 8px; align-items: center;
}
.retreat-peek[hidden] { display: none; }
.retreat-peek .pill { cursor: pointer; border: 1px solid var(--glass-line); font-size: 14px; }
.peek-timer { color: #fff7e6; font-family: var(--font-round); text-shadow: 0 1px 6px rgba(0,0,0,.6); }
.peek-timer:empty { display: none; }

/* 연등·소원지 쓰기 시트 */
.write-sheet { top: auto; bottom: max(12px, env(safe-area-inset-bottom)); right: 50%; transform: translateX(50%); width: min(420px, calc(100% - 24px)); max-height: calc(100% - 100px); }
.write-form { display: grid; gap: 12px; margin-top: 10px; }
.swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch { width: 40px; height: 40px; border-radius: 50%; border: 3px solid transparent; background: radial-gradient(circle at 35% 30%, #fff8, transparent 45%), var(--c); cursor: pointer; }
.swatch[aria-checked="true"] { border-color: var(--ink); box-shadow: 0 0 0 2px #fff inset; }
.field { display: grid; gap: 4px; font-size: 13px; }
.field-label { display: flex; justify-content: space-between; opacity: .8; }
.field input, .field textarea {
  width: 100%; padding: 10px 12px; border: 1px solid rgba(43,36,32,.2); border-radius: 10px; background: #fffdf8;
  font: 16px/1.5 var(--font); color: var(--ink); resize: vertical;
}
.field textarea { min-height: 110px; }
.form-msg { margin: 0; min-height: 1.2em; color: var(--red); font-size: 13px; }
.write-form .primary { width: 100%; }
.write-form .primary:disabled { opacity: .5; }
.write-sheet > .sheet-body > .ghost { margin-top: 10px; width: 100%; }
.past-list { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 6px; font-size: 13.5px; max-height: 40vh; overflow-y: auto; }
.past-list li { display: flex; gap: 8px; align-items: baseline; }
.past-list li b { white-space: nowrap; }
.past-list li span:last-child { word-break: break-word; }
.past-list .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; align-self: center; }
.past-list .empty { opacity: .6; }

/* 소원지 읽기 카드 */
.hanji {
  margin-top: 10px; padding: 16px 18px; border-radius: 6px; max-height: 46vh; overflow-y: auto;
  background: linear-gradient(180deg, rgba(255,255,255,.4), transparent), #f5ecd7; box-shadow: inset 0 0 0 1px rgba(122,74,44,.15);
  border-top: 3px solid #a8332a;
}
.hanji .wish-name { margin: 0 0 6px; font-weight: 700; }
.hanji .wish-text { margin: 0; white-space: pre-wrap; word-break: break-word; line-height: 1.7; }
.card-acts { display: flex; gap: 8px; margin-top: 12px; }
.card-acts .cheer { flex: 1; }
.card-acts .cheer[aria-pressed="true"] { background: var(--red); }
.card-acts .report { flex: none; padding: 0 16px; }

/* 길 따라가기 전환 */
.veil { position: fixed; inset: 0; z-index: 45; background: #120e0b; opacity: 0; pointer-events: none; transition: opacity .42s ease; }
.veil.on { opacity: 1; }

/* 무지개 동산 창 */
.write-sheet .select, .row-form input, #pet-name, #pet-breed-free {
  width: 100%; height: 44px; padding: 0 12px; border: 1px solid rgba(43,36,32,.2); border-radius: 10px; background: #fffdf8;
  font: 16px var(--font); color: var(--ink);
}
#pet-breed-free { margin-top: 6px; }
#pet-breed-free[hidden] { display: none; }
.recovery-code {
  margin: 14px 0; padding: 14px; text-align: center; font: 26px/1.2 ui-monospace, Consolas, monospace; letter-spacing: .12em;
  background: #fffdf8; border: 2px dashed rgba(168,67,47,.4); border-radius: 12px; user-select: all; -webkit-user-select: all;
}
.pet-list { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 10px; }
.pet-list li { padding: 10px 12px; border-radius: 12px; background: #fffdf8; border: 1px solid rgba(43,36,32,.12); display: grid; gap: 8px; }
.pet-list .empty { opacity: .7; font-size: 13.5px; }
.pet-acts { display: flex; flex-wrap: wrap; gap: 6px; }
.pet-acts button { height: 40px; font-size: 14px; padding: 0 14px; }
.pet-acts .primary { flex: 1 1 100%; }
.ghost.danger { color: var(--red); border-color: rgba(168,67,47,.35); }
.row-form { display: flex; gap: 8px; }
.row-form button { flex: none; }

/* 동물 이름표 */
.animal-tag {
  position: fixed; left: 0; top: 0; z-index: 7; padding: 4px 10px; border-radius: 999px; pointer-events: none;
  background: rgba(30,24,20,.6); color: #fff7e6; font-size: 13px; white-space: nowrap;
}
.animal-tag[hidden] { display: none; }
.animal-tag .hearts { color: #f29bbb; letter-spacing: 1px; font-size: 11px; }

/* 연등 이름표 */
.lantern-tag {
  position: fixed; left: 0; top: 0; z-index: 8; max-width: min(260px, 70vw); padding: 8px 12px; border-radius: 12px;
  background: rgba(250,246,238,.94); color: var(--ink); font-size: 13px; line-height: 1.45; box-shadow: 0 6px 20px rgba(0,0,0,.25);
  display: grid; gap: 2px; pointer-events: auto; word-break: break-word;
}
.lantern-tag[hidden] { display: none; }
.lantern-tag .tag-report { justify-self: end; border: 0; background: none; color: var(--red); font-size: 12px; cursor: pointer; padding: 2px 0 0; }
body.retreating .lantern-tag { display: none; }

.dedication { background: rgba(243,237,225,.93); }
.leave-card .row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.ghost { height: 48px; padding: 0 22px; border-radius: 999px; border: 1px solid rgba(43,36,32,.3); background: none; color: var(--ink); cursor: pointer; font-size: 15px; }
.gaze-note {
  position: fixed; left: 0; right: 0; bottom: max(22px, env(safe-area-inset-bottom)); margin: 0; z-index: 9;
  text-align: center; font-size: 13px; color: #fff7e6; opacity: .75; text-shadow: 0 1px 6px rgba(0,0,0,.7); pointer-events: none;
}
.gaze-note[hidden] { display: none; }
body.gazing .topbar, body.gazing .actions, body.gazing .hint, body.gazing .counter { opacity: 0; pointer-events: none; }

@media (max-width: 420px) {
  .act { min-width: 66px; }
  .zone { display: none; }
}

/* 첫 화면: 선 하나 굵기로 그린 기와집 로고와 이름. 다 불러오면 산문 들어가기 */
.loading {
  position: fixed; inset: 0; z-index: 50; overflow: hidden; display: grid; place-items: center;
  background: #f6f4ef; color: #343a46; transition: opacity .9s ease;
}
.loading.hide { opacity: 0; pointer-events: none; }
/* 원 지름 기준(cqw)으로 안의 크기를 맞춘다 */
.intro-logo {
  position: relative; width: min(86vw, 440px); aspect-ratio: 1; margin-bottom: 10vh; container-type: inline-size;
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
}
.intro-circle { position: absolute; inset: 0; width: 100%; height: 100%; }
.intro-seal {
  position: absolute; right: 2cqw; top: 30cqw; width: 8cqw; height: 8cqw; border-radius: 1cqw;
  display: grid; place-items: center; background: var(--red); color: #f6f4ef; font-size: 4cqw;
}
.intro-hall { position: relative; display: block; width: 46cqw; height: auto; margin-top: 2cqw; }
.intro-name { position: relative; margin: 4cqw 0 0; font-family: var(--font-round); font-weight: 400; font-size: 13cqw; line-height: 1; letter-spacing: .08em; padding-left: .08em; }
.intro-sub { position: relative; margin: 4cqw 0 0; font-family: 'Gowun Batang', serif; font-size: 3.6cqw; letter-spacing: .3em; padding-left: .3em; color: #7d7f86; }
.intro-foot {
  position: absolute; z-index: 1; left: 0; right: 0; bottom: max(clamp(48px, 10vh, 96px), env(safe-area-inset-bottom));
  height: 52px; display: grid; place-items: center;
}
.intro-status { margin: 0; font-size: 14px; color: #7d7f86; letter-spacing: .08em; }
.intro-enter {
  min-width: 156px; height: 50px; padding: 0 32px; border: 0; border-radius: 999px; cursor: pointer;
  background: #343a46; color: #f6f4ef; font-size: 16px; letter-spacing: .2em; padding-left: calc(32px + .2em);
}
.intro-enter:focus-visible { outline: 2px solid #343a46; outline-offset: 4px; }

/* 연못 물속 */
.underwater-bar { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 30; display: flex; gap: 10px; }
.underwater-bar[hidden] { display: none; }
body.underwater .topbar, body.underwater .actions, body.underwater .hint, body.underwater .counter, body.underwater .animal-tag, body.underwater .lantern-tag { opacity: 0; pointer-events: none; }
