:root {
  --cream: #f4ece0;
  --cream-2: #fbf6ee;
  --ink: #3a2a1e;
  --ink-soft: #7a6552;
  --coral: #e8735a;
  --pink: #f2a7b5;
  --teal: #3f9c8f;
  --gold: #d9a441;
  --card: rgba(255, 251, 245, 0.94);
  --shadow: 0 8px 28px rgba(80, 50, 20, 0.18);
  --r: 20px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--cream); color: var(--ink);
  font-family: "Pretendard Variable", Pretendard, -apple-system, "Apple SD Gothic Neo", sans-serif;
  -webkit-text-size-adjust: 100%; overscroll-behavior: none; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
[hidden] { display: none !important; }

#scene { position: fixed; inset: 0; width: 100vw; height: 100dvh; display: block; touch-action: none; }

/* Top bar */
#topbar { position: fixed; top: calc(10px + var(--safe-t)); left: 12px; right: 12px; display: flex; gap: 8px;
  align-items: center; justify-content: space-between; pointer-events: none; z-index: 5; }
#topbar > * { pointer-events: auto; }
.chip { background: var(--card); border-radius: 999px; padding: 8px 14px; font-size: 14px; font-weight: 600; box-shadow: var(--shadow); }
.counters { background: var(--card); border-radius: 999px; padding: 8px 12px; font-size: 13px; color: var(--ink-soft); box-shadow: var(--shadow); white-space: nowrap; }

/* Bubble (child monk) */
.bubble { position: fixed; left: 16px; right: 16px; top: calc(62px + var(--safe-t)); z-index: 6; background: var(--card);
  border-radius: var(--r); padding: 14px 16px; font-size: 16px; line-height: 1.5; box-shadow: var(--shadow);
  animation: pop .25s ease-out; }
.bubble::before { content: "동자승"; display: block; font-size: 12px; font-weight: 700; color: var(--teal); margin-bottom: 2px; }

/* Bottom action bar */
.actionbar { position: fixed; left: 10px; right: 10px; bottom: calc(26px + var(--safe-b)); z-index: 5; display: grid;
  grid-template-columns: repeat(6, 1fr); gap: 2px; background: var(--card); border-radius: 24px; padding: 6px; box-shadow: var(--shadow); }
.actionbar button { min-height: 56px; border-radius: 18px; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 2px; font-size: 11.5px; font-weight: 600; color: var(--ink); letter-spacing: -0.02em; }
.actionbar button:active { background: rgba(232, 115, 90, .12); transform: scale(.97); }
.actionbar .ico { font-size: 20px; line-height: 1; }

.taphint { position: fixed; left: 50%; bottom: calc(110px + var(--safe-b)); transform: translateX(-50%); z-index: 6;
  background: var(--ink); color: #fff; border-radius: 999px; padding: 10px 18px; font-size: 15px; font-weight: 600;
  box-shadow: var(--shadow); white-space: nowrap; animation: breathe 1.6s ease-in-out infinite; }

/* Full screens */
.screen { position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; justify-content: center;
  background: linear-gradient(180deg, rgba(244,236,224,.15) 0%, rgba(244,236,224,.85) 45%, var(--cream) 70%); }
.screen-inner { width: min(460px, 100%); padding: 24px 20px calc(36px + var(--safe-b)); }
.eyebrow { margin: 0 0 6px; font-size: 14px; font-weight: 600; color: var(--teal); }
h1 { margin: 0 0 20px; font-size: 30px; line-height: 1.3; letter-spacing: -0.02em; }
.reason-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.reason-grid button { background: #fff; border-radius: var(--r); min-height: 84px; font-size: 18px; font-weight: 700;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; box-shadow: var(--shadow); }
.reason-grid button span { font-size: 26px; }
.reason-grid button:active { transform: scale(.97); }
.disclaimer { margin: 18px 0 0; font-size: 12px; color: var(--ink-soft); text-align: center; }

.char-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.char-grid button { background: #fff; border-radius: var(--r); padding: 10px 8px 14px; display: flex; flex-direction: column;
  align-items: center; gap: 2px; box-shadow: var(--shadow); border: 3px solid transparent; }
.char-grid button[aria-checked="true"] { border-color: var(--coral); }
.char-grid img { width: 100%; max-width: 140px; height: auto; aspect-ratio: 3/4; object-fit: cover; border-radius: 14px; background: #eee; }
.char-grid b { font-size: 18px; margin-top: 4px; }
.char-grid small { font-size: 12px; color: var(--ink-soft); text-align: center; }

.field { display: block; font-size: 15px; font-weight: 600; margin-bottom: 16px; }
.field small { font-weight: 400; color: var(--ink-soft); }
.field input, .field textarea { display: block; width: 100%; margin-top: 6px; padding: 14px; border-radius: 14px;
  border: 1.5px solid #e2d6c4; background: #fff; font: inherit; font-size: 16px; color: var(--ink); }
.field textarea { min-height: 96px; resize: none; line-height: 1.5; }
.field input:focus, .field textarea:focus { outline: none; border-color: var(--coral); }

.primary { width: 100%; min-height: 54px; border-radius: 16px; background: var(--coral); color: #fff; font-size: 17px; font-weight: 700; }
.primary:disabled { background: #d9cbb8; }
.ghost { width: 100%; min-height: 48px; border-radius: 14px; background: transparent; color: var(--ink-soft); font-size: 15px; }

/* Bottom sheet */
.sheet { position: fixed; inset: 0; z-index: 30; display: flex; align-items: flex-end; justify-content: center; background: rgba(40, 25, 10, .25); }
.sheet-card { width: min(520px, 100%); background: var(--cream-2); border-radius: 24px 24px 0 0;
  padding: 22px 20px calc(20px + var(--safe-b)); box-shadow: var(--shadow); animation: up .25s ease-out; max-height: 88dvh; overflow: auto; }
.sheet-card h2 { margin: 0 0 14px; font-size: 21px; }
.sheet-actions { display: grid; gap: 8px; margin-top: 8px; }
.swatches { display: flex; gap: 10px; margin: 4px 0 16px; }
.swatches button { width: 42px; height: 42px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 1.5px #e2d6c4; }
.swatches button[aria-checked="true"] { box-shadow: 0 0 0 3px var(--ink); }
.more-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.more-grid button { background: #fff; border-radius: 16px; min-height: 64px; font-weight: 600; box-shadow: 0 2px 8px rgba(80,50,20,.08); }
.more-grid button small { display: block; font-weight: 400; font-size: 11px; color: var(--ink-soft); }

.toast { position: fixed; left: 50%; top: calc(64px + var(--safe-t)); transform: translateX(-50%); z-index: 40; background: var(--ink); color: #fff;
  padding: 10px 16px; border-radius: 999px; font-size: 14px; max-width: calc(100% - 32px); text-align: center; animation: pop .2s ease-out; }

.loading { position: fixed; inset: 0; z-index: 50; background: var(--cream); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; color: var(--ink-soft); transition: opacity .4s; }
.loading.done { opacity: 0; pointer-events: none; }
.loading .bar { width: 160px; height: 6px; border-radius: 3px; background: #e6dac8; overflow: hidden; }
.loading .bar i { display: block; height: 100%; width: 0; background: var(--coral); transition: width .2s; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 4px solid #e6dac8; border-top-color: var(--coral); animation: spin 1s linear infinite; }

.credit { position: fixed; left: 0; right: 0; bottom: calc(4px + var(--safe-b)); z-index: 4; text-align: center; font-size: 10px; color: rgba(58,42,30,.55); pointer-events: none; }

@keyframes pop { from { opacity: 0; transform: translateY(-6px) scale(.98); } }
@keyframes up { from { transform: translateY(40px); opacity: .6; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes breathe { 50% { transform: translateX(-50%) scale(1.04); } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* Sutra reader */
.sutra { position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; background: var(--cream-2); border-radius: 24px 24px 0 0;
  box-shadow: 0 -8px 28px rgba(80,50,20,.18); padding: 14px 16px calc(14px + var(--safe-b)); max-height: 66dvh; overflow: auto; --su-size: 1; animation: up .25s ease-out; }
.su-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.su-sec { margin: 0; font-size: 17px; font-weight: 700; }
.su-title { margin: 2px 0 0; font-size: 13px; color: var(--ink-soft); font-family: "Noto Serif TC", "Apple LiSung", serif; }
.su-head-btns { display: flex; gap: 6px; }
.su-head-btns button, .su-tools button { min-height: 40px; padding: 0 12px; border-radius: 12px; background: #fff; font-size: 14px; font-weight: 600; box-shadow: 0 1px 4px rgba(80,50,20,.1); }
.su-bar { height: 4px; border-radius: 2px; background: #eadfce; margin: 12px 0 4px; overflow: hidden; }
.su-bar i { display: block; height: 100%; background: var(--coral); }
.su-prog { margin: 0; font-size: 12px; color: var(--ink-soft); }
.su-toc { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 10px 0; max-height: 34dvh; overflow: auto; }
.su-toc button { text-align: left; background: #fff; border-radius: 10px; padding: 10px; font-size: 14px; }
.su-toc button[aria-current="true"] { outline: 2px solid var(--coral); }
.su-toc b { color: var(--teal); margin-right: 4px; }
.su-body { padding: 14px 4px 8px; min-height: 120px; }
.su-read { margin: 0; font-size: calc(26px * var(--su-size)); line-height: 1.45; font-weight: 700; letter-spacing: 0.04em; word-break: keep-all; color: #b9a990; }
.su-read span.on { color: var(--ink); }
.su-read span.cur { color: var(--coral); }
.su-read .gap { display: inline-block; width: .35em; }
.su-hanja { margin: 8px 0 0; font-size: calc(18px * var(--su-size)); line-height: 1.5; color: var(--ink-soft); letter-spacing: .08em; font-family: "Noto Serif TC", "Apple LiSung", serif; }
.su-next { margin: 10px 0 0; font-size: calc(15px * var(--su-size)); color: #c9bba5; }
.su-controls { display: grid; grid-template-columns: 56px 1fr 56px; gap: 8px; margin-top: 6px; }
.su-controls button { min-height: 52px; border-radius: 16px; font-size: 18px; font-weight: 700; background: #fff; box-shadow: 0 1px 4px rgba(80,50,20,.1); }
.su-controls .primary { background: var(--coral); color: #fff; font-size: 17px; }
.su-speed { display: flex; align-items: center; gap: 6px; margin-top: 12px; }
.su-speed .lbl { font-size: 13px; color: var(--ink-soft); width: 32px; }
.su-speed button { flex: 1; min-height: 40px; border-radius: 12px; background: #fff; font-size: 14px; font-weight: 600; box-shadow: 0 1px 4px rgba(80,50,20,.1); }
.su-speed button[aria-pressed="true"] { background: var(--ink); color: #fff; }
.su-fine { display: flex; align-items: center; gap: 10px; margin-top: 8px; font-size: 13px; color: var(--ink-soft); }
.su-fine input { flex: 1; accent-color: var(--coral); height: 32px; }
.su-tools { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.su-tools button[aria-pressed="true"] { background: var(--teal); color: #fff; }

/* Zones */
.zones { position: fixed; top: calc(56px + var(--safe-t)); left: 50%; transform: translateX(-50%); z-index: 5; display: flex; gap: 4px;
  background: var(--card); border-radius: 999px; padding: 4px; box-shadow: var(--shadow); }
.zones button { min-height: 36px; padding: 0 12px; white-space: nowrap; border-radius: 999px; font-size: 13.5px; font-weight: 600; color: var(--ink-soft); }
.zones button[aria-current="true"] { background: var(--ink); color: #fff; }
body.has-zones .bubble { top: calc(104px + var(--safe-t)); }
.zonebar { position: fixed; left: 12px; right: 12px; bottom: calc(22px + var(--safe-b)); z-index: 5; display: grid; grid-template-columns: 1fr auto; grid-template-areas: "tool hold"; align-items: end; gap: 10px; pointer-events: none; }
.zonebar .zoneprogress { position: fixed; top: calc(102px + var(--safe-t)); left: 50%; transform: translateX(-50%); white-space: nowrap; }
body.outdoor .bubble { top: calc(146px + var(--safe-t)); }
.zonebar .zonetool { grid-area: tool; justify-self: start; }
.zonebar .holdbtn { grid-area: hold; }
.zonebar > * { pointer-events: auto; }
.zoneprogress { margin: 0; background: var(--card); border-radius: 999px; padding: 8px 14px; font-size: 14px; font-weight: 600; box-shadow: var(--shadow); }
.holdbtn { width: 112px; height: 112px; border-radius: 50%; background: var(--coral); color: #fff; font-size: 15px; font-weight: 800; line-height: 1.25;
  padding: 0 14px; box-shadow: 0 10px 26px rgba(232,115,90,.45), inset 0 -6px 0 rgba(0,0,0,.08); touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; transition: transform .12s; }
.holdbtn.down { transform: scale(.93); background: #d9634b; }
.zonetool { min-height: 40px; padding: 0 16px; border-radius: 999px; background: var(--card); font-size: 14px; font-weight: 600; box-shadow: var(--shadow); }
.fade { position: fixed; inset: 0; z-index: 45; background: var(--cream); opacity: 0; pointer-events: none; transition: opacity .35s; }
.fade.on { opacity: 1; }
