: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; white-space: nowrap; flex: none; 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; z-index: 35; right: 16px; top: 50%; transform: translateY(-50%);
  width: 232px; padding: 12px 14px; border-radius: 22px; touch-action: none; user-select: none;
  background: rgba(24, 18, 14, .62); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(251, 240, 216, .14); box-shadow: 0 12px 36px rgba(0,0,0,.35); color: #fbf0d8; outline: none;
}
.beads[hidden] { display: none; }
.beads-head { display: flex; align-items: center; justify-content: space-between; }
.beads-head h2 { margin: 0; font-size: 15px; font-weight: 600; letter-spacing: .02em; }
.beads .back {
  width: 32px; height: 32px; border: 0; border-radius: 50%; cursor: pointer; font-size: 14px;
  background: rgba(251,240,216,.12); color: #fbf0d8;
}
.beads .back:hover { background: rgba(251,240,216,.22); }
.beads-dial { position: relative; margin-top: 4px; cursor: pointer; }
.beads-ring { display: block; width: 100%; height: auto; }
.beads-ring .ring { transition: transform .18s ease-out; }
.beads-count {
  position: absolute; left: 0; right: 0; top: 46%; transform: translateY(-50%); text-align: center;
  font-family: var(--font-round); text-shadow: 0 2px 10px rgba(0,0,0,.45); pointer-events: none;
}
.beads-count b { display: block; font-weight: 400; font-size: 46px; line-height: 1; }
.beads-count small { font-size: 14px; opacity: .7; }
.beads-count .rounds { display: block; font-size: 12px; opacity: .7; margin-top: 2px; }
.beads-hint { margin: 2px 0 0; text-align: center; font-size: 11.5px; opacity: .6; }
@media (max-width: 600px) {
  .beads { width: 176px; right: 10px; padding: 10px 10px 8px; top: 42%; }
  .beads-count b { font-size: 36px; }
  .beads-hint { display: none; }
}
@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: 13px; cursor: pointer; padding: 8px 10px; margin: -6px -10px -8px; min-height: 32px; }
.past-list .tag-report { margin-left: auto; border: 0; background: none; color: var(--red); font-size: 13px; cursor: pointer; padding: 6px 4px; }
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; }
/* 산문 들어가기 아래 소개 페이지로 가는 작은 버튼 */
.intro-about {
  position: absolute; z-index: 1; left: 50%; transform: translateX(-50%);
  bottom: max(calc(clamp(48px, 10vh, 96px) - 46px), calc(env(safe-area-inset-bottom) + 4px));
  min-height: 36px; padding: 0 18px; display: grid; place-items: center; border-radius: 999px;
  border: 1px solid rgba(52,58,70,.28); color: #5d616b; font-size: 14px; letter-spacing: .12em; text-decoration: none;
}
.intro-about:hover { color: #343a46; border-color: #343a46; }
.intro-about:focus-visible { outline: 2px solid #343a46; outline-offset: 3px; }

/* 연못 물속 */
.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; }

/* 테스트 결제 */
.test-pay { margin: 0 0 10px; padding: 6px 10px; border-radius: 8px; background: #fff3d6; color: #8a5a00; font-size: 12.5px; font-weight: 600; }
.special-row { display: flex; gap: 8px; align-items: flex-start; margin: 4px 0 8px; font-size: 13.5px; cursor: pointer; }
.special-row input { margin-top: 3px; accent-color: var(--red); }
.special-row small { color: #8a5a00; }

/* 법당으로 바로 가기 */
.go-hall { margin-left: 8px; height: 40px; padding: 0 14px; border: 0; cursor: pointer; font-size: 14px; font-weight: 600; }
.go-hall[hidden] { display: none; }
#btn-go-gaze { margin-right: auto; }
/* 좁은 화면: 바로 가기 단추는 그림만 (이름은 aria-label 로) */
@media (max-width: 600px) {
  .go-hall { width: 44px; padding: 0; justify-content: center; margin-left: 6px; }
  .go-hall .lbl { display: none; }
  .go-hall .ico { font-size: 18px; }
  .zone { display: none; }
}
body.gazing .go-hall, body.retreating .go-hall, body.underwater .go-hall { opacity: 0; pointer-events: none; }
.special-row[hidden] { display: none; }

/* 로그인 방식 고르기 */
.choice-acts { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
.choice-acts[hidden], #acct-form[hidden] { display: none; }
.acct-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 6px 0 2px; }
.acct-row[hidden] { display: none; }
.acct-row .note { margin: 0; }
#login-form input { min-width: 0; }

/* 미니맵: 오른쪽 위 단추 막대 아래. 누르면 온 절 지도로 커진다 */
.minimap {
  position: fixed; z-index: 9; right: 12px; top: calc(max(12px, env(safe-area-inset-top)) + 54px);
  padding: 0; border: 2px solid rgba(255, 250, 240, .75); border-radius: 16px; overflow: hidden; cursor: pointer;
  background: #d8ccae; box-shadow: 0 6px 18px rgba(0,0,0,.28); line-height: 0;
}
.minimap canvas { display: block; }
.minimap.wide { border-radius: 18px; }
body.gazing .minimap, body.retreating .minimap, body.underwater .minimap, body.intro .minimap { opacity: 0; pointer-events: none; }
@media (max-width: 600px) { .minimap:not(.wide) canvas { width: 104px !important; height: 104px !important; } }

/* 지금 접속자 수: 미니맵 바로 아래 */
.online {
  position: fixed; z-index: 9; right: 12px; top: calc(max(12px, env(safe-area-inset-top)) + 54px + 150px);
  padding: 4px 10px; border-radius: 999px; font-size: 12px; white-space: nowrap; pointer-events: none;
  background: var(--glass); border: 1px solid var(--glass-line); color: var(--text-on-glass);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.online::before { content: ''; display: inline-block; width: 7px; height: 7px; margin-right: 6px; border-radius: 50%; background: #6fd27a; vertical-align: 1px; }
.online[hidden] { display: none; }
body:has(.minimap.wide) .online { opacity: 0; }
body.gazing .online, body.retreating .online, body.underwater .online { opacity: 0; }
@media (max-width: 600px) { .online { top: calc(max(12px, env(safe-area-inset-top)) + 54px + 114px); font-size: 11px; } }

/* 불멍·물멍 바로 가기 */
.gaze-list { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 6px 0 4px; }
.gaze-pick {
  display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 0 14px; border-radius: 14px; cursor: pointer;
  border: 1px solid rgba(43,36,32,.15); background: rgba(255,255,255,.55); color: var(--ink); font-size: 15px; text-align: left;
}
.gaze-pick:hover { background: rgba(255,255,255,.85); }
.gaze-ico { font-size: 22px; }
@media (max-width: 600px) { .gaze-list { grid-template-columns: 1fr; } }

/* 좁은 화면 위 막대: 바로 가기 단추가 셋이라 이름 글자는 빼고 로고만, 오른쪽 아이콘은 조금 좁게 */
@media (max-width: 600px) {
  .brand b { display: none; }
  .brand { padding: 0 13px; }
  .tools .icon-btn { width: 36px; }
}
