:root {
  --bg-gradient: linear-gradient(140deg, #eef2ff 0%, #f8fafc 45%, #ecfeff 100%);
  --card-bg: rgba(255, 255, 255, .62);
  --card-border: rgba(255, 255, 255, .85);
  --field-bg: rgba(255, 255, 255, .72);
  --field-border: rgba(148, 163, 184, .28);
  --text-primary: #0f172a;
  --text-secondary: #5b6b80;
  --accent-primary: #6366f1;
  --accent-secondary: #4f46e5;
  --accent-glow: rgba(99, 102, 241, .18);
  --gold: #b7791f;
  --ease: cubic-bezier(.16, 1, .3, 1);
  --font-main: 'Pretendard', -apple-system, 'Malgun Gothic', sans-serif;
  --font-accent: 'Outfit', 'Pretendard', sans-serif;
  color-scheme: light;
}
* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  transition: background-color .25s ease, border-color .25s ease, color .25s ease,
              box-shadow .25s ease, transform .25s var(--ease), opacity .3s ease;
}
html, body { height: 100%; margin: 0; overflow: hidden; }
body {
  font-family: var(--font-main);
  color: var(--text-primary);
  background: var(--bg-gradient);
  -webkit-user-select: none; user-select: none;
  overscroll-behavior: none;
}
[hidden] { display: none !important; }
#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; outline: none; }
#scene:active { cursor: grabbing; }

svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent-primary); outline-offset: 2px; }

.glass {
  background: var(--card-bg);
  backdrop-filter: blur(22px) saturate(160%);
  -webkit-backdrop-filter: blur(22px) saturate(160%);
  border: 1px solid var(--card-border);
  box-shadow: 0 18px 45px rgba(15, 23, 42, .12), inset 0 1px 0 rgba(255, 255, 255, .75);
}
.muted { color: var(--text-secondary); }
.small { font-size: 13px; margin: 2px 0 8px; }

/* HUD */
#hud {
  position: fixed; z-index: 2; left: 0; right: 0;
  top: calc(env(safe-area-inset-top) + 12px);
  padding: 0 12px; display: flex; gap: 8px; align-items: center; justify-content: space-between;
  pointer-events: none; animation: dropIn .6s var(--ease) both;
}
#hud > * { pointer-events: auto; }
.chip { display: flex; align-items: center; gap: 7px; height: 42px; padding: 0 14px; border-radius: 21px; font-size: 14px; font-weight: 600; max-width: 34vw; min-width: 0; }
.chip #whoName { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #f59e0b; box-shadow: 0 0 8px #f59e0b; flex: none; }
.counter { border-radius: 16px; padding: 6px 14px 8px; min-width: 132px; text-align: center; }
.counter-row { display: flex; gap: 5px; align-items: baseline; justify-content: center; font-size: 13px; font-weight: 600; white-space: nowrap; }
.counter-link { display: block; margin: 1px auto 0; padding: 1px 8px; font-size: 11.5px; font-weight: 600; color: var(--accent-secondary); background: none; border: 0; border-radius: 8px; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.counter-link:hover { background: rgba(148, 163, 184, .18); }
.counter-link[hidden] { display: none; }
.counter-row b { font-family: var(--font-accent); font-size: 21px; font-weight: 800; color: var(--accent-secondary); line-height: 1.1; }
.bar { height: 4px; border-radius: 2px; background: rgba(99, 102, 241, .16); overflow: hidden; margin-top: 3px; }
.bar i { display: block; height: 100%; width: 0; border-radius: 2px; background: linear-gradient(90deg, #818cf8, #4f46e5); transition: width .6s var(--ease); }
.hud-right { display: flex; gap: 8px; align-items: center; flex: none; }
.exit-btn { display: flex; align-items: center; gap: 6px; height: 42px; padding: 0 14px; border-radius: 21px; font-size: 14px; font-weight: 600; cursor: pointer; }
.exit-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.exit-btn:hover { transform: translateY(-2px); }
.gate-note { margin: 6px 0 2px; padding: 8px 12px; border-radius: 12px; background: rgba(99, 102, 241, .12); color: var(--accent-secondary); font-size: 13px; font-weight: 600; }
.icon-btn { width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; flex: none; }
.icon-btn:hover { transform: translateY(-2px); }

/* 도크 */
#dock {
  position: fixed; z-index: 2; left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom) + 14px);
  display: flex; gap: 2px; padding: 6px; border-radius: 22px;
  animation: dockIn .7s var(--ease) both;
  max-width: calc(100vw - 16px);
}
#dock button {
  width: 62px; height: 58px; border-radius: 16px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 3px; font-size: 12px; font-weight: 600;
}
#dock button:hover { background: rgba(255, 255, 255, .7); transform: translateY(-2px); }
#dock button:active { transform: scale(.96); }
#dock button[aria-pressed="true"] { background: var(--accent-primary); color: #fff; box-shadow: 0 8px 20px rgba(99, 102, 241, .4); }
#dock button:disabled { opacity: .45; cursor: default; transform: none; }

#toast {
  position: fixed; z-index: 3; left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom) + 96px);
  padding: 10px 18px; border-radius: 18px; font-size: 14px; font-weight: 600;
  white-space: nowrap; max-width: calc(100vw - 24px); overflow: hidden; text-overflow: ellipsis;
  animation: rise .45s var(--ease) both; pointer-events: none;
}

/* 입장 */
#gate {
  position: fixed; inset: 0; z-index: 5; display: grid; place-items: center; padding: 20px;
  background: rgba(238, 242, 255, .18);
}
#gate.leaving { opacity: 0; pointer-events: none; }
.gate-card { width: min(370px, 100%); border-radius: 26px; padding: 30px 26px 22px; text-align: center; animation: rise .8s var(--ease) both; }
.eyebrow { margin: 0; font-size: 13px; font-weight: 600; color: var(--gold); letter-spacing: 3px; }
.gate-card h1 { margin: 4px 0 8px; font-size: 44px; font-weight: 800; letter-spacing: -.3px; }
.gate-card label { display: block; text-align: left; font-size: 13px; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; }
.name-row { display: flex; gap: 8px; margin-bottom: 14px; }
.name-row input {
  flex: 1; min-width: 0; height: 48px; padding: 0 14px; font: inherit; font-size: 16px; font-weight: 600;
  border-radius: 14px; background: var(--field-bg); border: 1px solid var(--field-border); color: inherit;
  -webkit-user-select: text; user-select: text;
}
.name-row input:focus { outline: 0; border-color: var(--accent-primary); box-shadow: 0 0 0 3px var(--accent-glow); }
.ghost { background: var(--field-bg); border: 1px solid var(--field-border); border-radius: 14px; font-weight: 600; }
.ghost:hover { background: #fff; transform: translateY(-1px); }
.name-row .ghost { width: 48px; height: 48px; display: grid; place-items: center; flex: none; }
.primary {
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary)); color: #fff;
  border-radius: 14px; font-weight: 700; box-shadow: 0 10px 22px rgba(99, 102, 241, .32);
}
.primary:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 12px 26px rgba(99, 102, 241, .42); }
.primary:active:not(:disabled) { transform: scale(.985); }
.primary:disabled { opacity: .65; cursor: progress; }
#enterBtn, #enterCathBtn { width: 100%; height: 52px; font-size: 17px; }
.fine { margin: 14px 0 0; font-size: 12px; color: var(--text-secondary); }

/* 모달 */
.overlay {
  position: fixed; inset: 0; z-index: 4; display: grid; place-items: center; padding: 14px;
  background: rgba(15, 23, 42, .16); animation: fade .25s ease both;
}
.modal {
  position: relative; width: min(390px, 100%); max-height: calc(100dvh - 28px); overflow-y: auto;
  padding: 22px 20px 18px; border-radius: 22px; background: rgba(255, 255, 255, .8);
  animation: rise .45s var(--ease) both;
}
.modal h2 { margin: 0 34px 4px 0; font-size: 20px; font-weight: 800; letter-spacing: -.3px; }
.modal-x {
  position: absolute; top: 12px; right: 12px; width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center; background: rgba(148, 163, 184, .16);
}
.modal-x svg { width: 18px; height: 18px; }
.modal-x:hover { background: rgba(148, 163, 184, .32); transform: rotate(90deg); }
.modal-actions { display: flex; gap: 8px; margin-top: 14px; }
.wide { flex: 1; height: 46px; font-size: 15px; }

#beadRing { position: relative; width: min(300px, 100%); margin: 0 auto; aspect-ratio: 1; touch-action: none; cursor: pointer; }
#beadSvg { width: 100%; height: 100%; stroke: none; }
#beadSvg circle { fill: #d6c6aa; transition: fill .2s ease; }
#beadSvg circle.on { fill: #7c4a1e; }
#beadSvg circle.head { fill: #6366f1; }
.bead-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; pointer-events: none; }
.bead-center b { font-family: var(--font-accent); font-size: 64px; font-weight: 800; line-height: 1; color: var(--accent-secondary); }
.bead-center span { font-family: var(--font-accent); color: var(--text-secondary); font-weight: 600; }
.bead-center small { margin-top: 4px; min-height: 16px; color: var(--gold); font-weight: 600; }

.field { margin-top: 14px; }
.field label { display: flex; justify-content: space-between; font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.field label b { font-family: var(--font-accent); color: var(--accent-secondary); }
input[type=range] { width: 100%; height: 26px; margin: 0; accent-color: var(--accent-primary); }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 16px; }
.stats div { background: var(--field-bg); border: 1px solid var(--field-border); border-radius: 14px; padding: 10px; text-align: center; }
.stats b { display: block; font-family: var(--font-accent); font-size: 24px; font-weight: 800; color: var(--accent-secondary); }
.stats span { font-size: 12px; color: var(--text-secondary); }
.guide { list-style: none; margin: 14px 0 0; padding: 0; font-size: 13px; line-height: 1.6; color: #334155; }
.guide li { padding: 4px 0; }
.guide b { display: inline-block; min-width: 34px; color: var(--accent-secondary); }

#fatal { position: fixed; z-index: 9; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(340px, 90vw); padding: 24px; border-radius: 22px; text-align: center; }

@keyframes rise { from { opacity: 0; translate: 0 14px; scale: .985; } to { opacity: 1; translate: 0 0; scale: 1; } }
@keyframes dropIn { from { opacity: 0; translate: 0 -12px; } to { opacity: 1; translate: 0 0; } }
@keyframes dockIn { from { opacity: 0; translate: 0 18px; } to { opacity: 1; translate: 0 0; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

@media (max-width: 640px) {
  .exit-btn { width: 42px; padding: 0; justify-content: center; }
  .exit-btn span { display: none; }
  .counter { min-width: 112px; padding: 5px 10px 7px; }
}
@media (max-width: 420px) {
  #dock button { width: 54px; font-size: 11px; }
  .counter { min-width: 112px; padding: 5px 10px 7px; }
  .chip { padding: 0 10px; font-size: 13px; }
}
@media (max-height: 460px) {
  #dock button { height: 46px; } #dock svg { width: 18px; height: 18px; }
  #toast { bottom: 70px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition-duration: .01ms !important; }
}

/* 법당 ↔ 정원 */
#modeBtn, .side-chip {
  position: fixed; z-index: 2; left: 12px; top: calc(env(safe-area-inset-top) + 62px);
  height: 40px; padding: 0 14px 0 11px; border-radius: 20px;
  display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 700;
  animation: dropIn .7s var(--ease) both;
}
#modeBtn svg, .side-chip svg { width: 19px; height: 19px; color: var(--accent-secondary); }
#modeBtn:hover, .side-chip:hover { transform: translateY(-2px); background: rgba(255, 255, 255, .82); }
#modeBtn:active, .side-chip:active { transform: scale(.97); }
#fade { position: fixed; inset: 0; z-index: 4; background: #f6f8ff; opacity: 0; pointer-events: none; transition: opacity .4s ease; }
#fade.on { opacity: 1; pointer-events: auto; }

/* 염불 고르기 */
.track-list { display: grid; gap: 6px; margin-top: 4px; }
.track-list button {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 52px;
  padding: 8px 14px; text-align: left; border-radius: 14px;
  background: var(--field-bg); border: 1px solid var(--field-border);
  animation: rise .4s var(--ease) both;
}
.track-list button:hover { background: #fff; transform: translateY(-1px); }
.track-list button[aria-checked="true"] { background: var(--accent-primary); border-color: var(--accent-primary); color: #fff; box-shadow: 0 8px 20px rgba(99, 102, 241, .32); }
.track-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.track-text b { font-size: 15px; font-weight: 700; }
.track-text small { font-size: 12px; color: var(--text-secondary); }
.track-list button[aria-checked="true"] small { color: rgba(255, 255, 255, .82); }
.track-state { flex: none; font-size: 12px; font-weight: 600; }

.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px; margin: 10px 0 8px; border-radius: 14px; background: var(--field-bg); border: 1px solid var(--field-border); }
.seg button { min-height: 38px; border-radius: 10px; font-size: 14px; font-weight: 600; color: var(--text-secondary); background: transparent; border: 0; }
.seg button[aria-selected="true"] { background: #fff; color: var(--text-primary, inherit); box-shadow: 0 2px 8px rgba(15, 23, 42, .1); }

#seasonBtn { top: calc(env(safe-area-inset-top) + 110px); }
#skyBtn { top: calc(env(safe-area-inset-top) + 158px); }
#ambBtn { top: calc(env(safe-area-inset-top) + 110px); }
#ambBtn.below { top: calc(env(safe-area-inset-top) + 206px); }
#starBtn { top: calc(env(safe-area-inset-top) + 254px); }
#starBtn[aria-pressed="true"] { background: var(--accent-primary); color: #fff; }
#starBtn[aria-pressed="true"] svg { color: #fff; }
.const-block { margin-top: 12px; }
.const-block b { display: block; font-size: 13px; font-weight: 700; color: var(--accent-primary); }
.const-block p { margin: 3px 0 0; font-size: 14px; line-height: 1.6; }
.side-chip svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.check-row { display: flex; align-items: center; gap: 10px; min-height: 40px; margin-top: 8px; font-size: 14px; font-weight: 600; cursor: pointer; }
.check-row input { width: 18px; height: 18px; accent-color: var(--accent-primary); }
#vowReset { margin-top: 8px; }

.field select {
  width: 100%; min-height: 44px; padding: 0 12px; border-radius: 12px; font: inherit; font-size: 16px; font-weight: 600;
  color: var(--text-primary); background: var(--field-bg); border: 1px solid var(--field-border); cursor: pointer;
}
.primary.alt {
  margin-top: 10px;
  background: linear-gradient(135deg, #7c5a3c, #a4553f); box-shadow: 0 10px 22px rgba(124, 90, 60, .3);
}
#btnChant span { white-space: nowrap; letter-spacing: -.04em; }
#btnTower[aria-pressed="true"] { background: rgba(99, 102, 241, .16); }
.confess p { margin: 8px 0; font-size: 14.5px; line-height: 1.6; }
.confess-eyebrow { margin: 0 34px 2px 0 !important; font-size: 12px !important; font-weight: 700; letter-spacing: .04em; color: #7c5a3c; }
.confess-prayer { padding: 12px 14px; border-radius: 14px; background: rgba(124, 90, 60, .1); font-weight: 600; }
.confess .confess-note { font-size: 12.5px; line-height: 1.5; color: var(--text-secondary); }
.confess-label { margin-bottom: 0 !important; font-size: 13px !important; font-weight: 700; }
#confessAdvice p { margin: 8px 0; }
#confessTopics { display: grid; gap: 6px; }
.confess-topic {
  display: block; width: 100%; padding: 9px 12px; text-align: left; border-radius: 12px;
  background: var(--field-bg); border: 1px solid var(--field-border); transition: background .2s, border-color .2s;
}
.confess-topic b { display: block; font-size: 14px; }
.confess-topic span { display: block; margin-top: 1px; font-size: 12.5px; line-height: 1.4; color: var(--text-secondary); }
.confess-topic[aria-pressed="true"] { background: rgba(124, 90, 60, .16); border-color: #7c5a3c; }
#confessText {
  display: block; width: 100%; box-sizing: border-box; padding: 11px 13px; resize: vertical; font: inherit; font-size: 15px; line-height: 1.55;
  border-radius: 14px; background: var(--field-bg); border: 1px solid var(--field-border); color: inherit;
}
#confessText:focus { outline: 2px solid #7c5a3c; outline-offset: 1px; }
#talkBar {
  position: fixed; z-index: 2; left: 50%; transform: translateX(-50%); width: min(620px, calc(100vw - 24px));
  bottom: calc(env(safe-area-inset-bottom) + 96px); padding: 9px 14px 10px; border-radius: 18px;
  background: rgba(255, 255, 255, .78); animation: rise .4s var(--ease) both;
}
#talkBar[hidden] { display: none; }
#talkTop { display: flex; align-items: center; gap: 6px; }
#talkWho { flex: 1; min-width: 0; font-size: 12.5px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#talkTop button { width: 30px; height: 30px; flex: none; display: grid; place-items: center; border-radius: 50%; background: rgba(148, 163, 184, .18); }
#talkTop button:hover { background: rgba(148, 163, 184, .34); }
#talkTop svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
#talkPause .i-play { display: none; fill: currentColor; }
#talkPause.paused .i-play { display: block; }
#talkPause.paused .i-pause { display: none; }
#talkText { margin: 3px 0 7px; min-height: 2.9em; font-size: 15.5px; font-weight: 600; line-height: 1.45; word-break: keep-all; }
#talkProg { height: 3px; border-radius: 2px; background: rgba(148, 163, 184, .3); overflow: hidden; }
#talkFill { display: block; width: 0; height: 100%; background: var(--accent-secondary); transition: width .3s linear; }
#btnTalk[aria-pressed="true"] { background: rgba(99, 102, 241, .16); }
body.talk-on #toast { bottom: calc(env(safe-area-inset-bottom) + 216px); }
@media (max-width: 420px) { #talkText { font-size: 14px; } #talkBar { bottom: calc(env(safe-area-inset-bottom) + 84px); } }
@media (max-width: 420px) { #dock button span { white-space: nowrap; letter-spacing: -.06em; } }

/* 좁은 화면의 정원에서는 하단 메뉴가 넘치므로 염주, 앉기, 소리 고르기를 뺀다 */
@media (max-width: 470px) {
  #dock.outside #btnSit, #dock.outside #btnBeads, #dock.outside #btnChant { display: none; }
}
