:root {
  --ink: #f4ecdc;
  --ink-dim: #b9ad97;
  --paper: #f3ead7;
  --paper-ink: #2b2116;
  --red: #b3332c;
  --red-deep: #7e2320;
  --gold: #d8b25a;
  --night: #0b0f1f;
  --glass: rgba(16, 14, 22, 0.72);
  --line: rgba(216, 178, 90, 0.28);
  --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(--night); color: var(--ink);
  font-family: 'Pretendard Variable', Pretendard, -apple-system, system-ui, sans-serif; }
canvas#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
button { font: inherit; cursor: pointer; border: 0; color: inherit; }
input { font: inherit; }
.hidden { display: none !important; }

.pill { border-radius: 999px; padding: 12px 20px; font-weight: 700; background: var(--glass); border: 1px solid var(--line);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.pill.primary { background: linear-gradient(180deg, #c5413a, #8e2722); border-color: #e2725f; color: #fff7ea;
  box-shadow: 0 6px 20px rgba(179, 51, 44, .45), inset 0 1px 0 rgba(255,255,255,.25); }
.pill.big { width: 100%; padding: 16px; font-size: 17px; }
.pill:active, .round:active { transform: scale(.96); }
.ghost { background: transparent; border: 1px solid var(--line); border-radius: 999px; padding: 8px 12px; font-size: 13px; color: var(--ink-dim); }
.round { width: 54px; height: 54px; border-radius: 50%; background: var(--glass); border: 1px solid var(--line);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); font-size: 15px; font-weight: 700; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #6b6b6b; margin-right: 6px; }
.dot.live { background: #ff5a4a; box-shadow: 0 0 0 0 rgba(255, 90, 74, .7); animation: pulse 1.6s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 8px rgba(255, 90, 74, 0); } 100% { box-shadow: 0 0 0 0 rgba(255, 90, 74, 0); } }

/* HUD */
#hud-top { position: fixed; top: calc(10px + var(--safe-t)); left: 10px; right: 10px; display: flex; gap: 8px; align-items: stretch; pointer-events: none; z-index: 5; }
.brand, #now-card { background: var(--glass); border: 1px solid var(--line); border-radius: 16px; padding: 8px 12px;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.brand { display: flex; gap: 8px; align-items: center; }
.brand b { font-family: 'Gowun Batang', serif; font-size: 17px; letter-spacing: .04em; display: block; }
.brand small { color: var(--ink-dim); font-size: 11px; }
.brand-mark { width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center; background: var(--red); color: #fff3df;
  font-family: 'Gowun Batang', serif; font-weight: 700; box-shadow: inset 0 0 0 2px rgba(255,255,255,.15); }
#now-card { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; gap: 2px; }
.now-row { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; }
.now-row.sub { color: var(--ink-dim); font-weight: 500; font-size: 12px; padding-left: 14px; }

#my-ticket { position: fixed; left: 50%; transform: translateX(-50%); top: calc(74px + var(--safe-t)); z-index: 6; display: flex; align-items: center; gap: 12px;
  background: linear-gradient(180deg, #f6eedc, #e9dcc0); color: var(--paper-ink); border-radius: 16px; padding: 10px 12px 10px 10px;
  box-shadow: 0 10px 30px rgba(0,0,0,.45); width: min(92vw, 380px); }
#my-ticket.next { animation: wiggle .9s ease-in-out infinite; }
@keyframes wiggle { 50% { transform: translateX(-50%) translateY(-3px); } }
.ticket-no { width: 56px; height: 56px; border-radius: 12px; background: var(--red); color: #fff4e2; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ticket-no small { font-size: 10px; opacity: .85; }
.ticket-no b { font-family: 'Gowun Batang', serif; font-size: 24px; line-height: 1; }
.ticket-info { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.ticket-info b { font-size: 15px; }
.ticket-info span { font-size: 12px; color: #6d5d45; }
#my-ticket .ghost { color: #6d5d45; border-color: rgba(0,0,0,.15); }

#chat-log { position: fixed; left: 10px; bottom: calc(200px + var(--safe-b)); width: min(70vw, 320px); max-height: 30vh; overflow: hidden;
  display: flex; flex-direction: column; justify-content: flex-end; gap: 4px; pointer-events: none; z-index: 4;
  mask-image: linear-gradient(to bottom, transparent, #000 30%); -webkit-mask-image: linear-gradient(to bottom, transparent, #000 30%); }
.chat-line { font-size: 13px; background: rgba(10,10,16,.55); padding: 5px 9px; border-radius: 10px; width: fit-content; max-width: 100%; word-break: break-all; }
.chat-line b { color: var(--gold); margin-right: 4px; }
.chat-line.sys { color: #ffd9a0; background: rgba(126, 35, 32, .55); }
#chat-form { position: fixed; left: 10px; right: 10px; bottom: calc(12px + var(--safe-b)); z-index: 9; display: flex; gap: 6px; }
#chat-form input { flex: 1; background: rgba(20,18,26,.92); border: 1px solid var(--line); color: var(--ink); border-radius: 999px; padding: 12px 16px; outline: none; }
#chat-form button { background: var(--red); color: #fff; border-radius: 999px; padding: 0 18px; font-weight: 700; }

#joystick { position: fixed; left: calc(18px); bottom: calc(24px + var(--safe-b)); width: 128px; height: 128px; border-radius: 50%;
  background: radial-gradient(circle, rgba(255,255,255,.06), rgba(255,255,255,.12)); border: 1px solid rgba(255,255,255,.18); z-index: 5; touch-action: none; }
#stick { position: absolute; left: 50%; top: 50%; width: 56px; height: 56px; margin: -28px 0 0 -28px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff8ea, #cdb992); box-shadow: 0 4px 14px rgba(0,0,0,.4); }
#actions { position: fixed; right: 14px; bottom: calc(26px + var(--safe-b)); display: flex; gap: 10px; align-items: center; z-index: 5; }
#btn-sit { background: rgba(216,178,90,.9); color: #2a1d08; }
#hint { position: fixed; left: 50%; bottom: calc(8px + var(--safe-b)); transform: translateX(-50%); font-size: 11px; color: var(--ink-dim); z-index: 3; white-space: nowrap; }
@media (pointer: coarse) { #hint { display: none !important; } }
@media (pointer: fine) { #joystick { opacity: .0; pointer-events: none; } }

#toast { position: fixed; left: 50%; top: 40%; transform: translate(-50%, -50%) scale(.95); background: rgba(14,12,20,.92); border: 1px solid var(--line);
  padding: 12px 18px; border-radius: 14px; font-weight: 600; z-index: 30; opacity: 0; pointer-events: none; transition: all .25s; max-width: 86vw; text-align: center; }
#toast.on { opacity: 1; transform: translate(-50%, -50%) scale(1); }

/* 입장 */
#intro { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(ellipse at 50% 30%, rgba(60, 22, 20, .55), rgba(5, 6, 14, .9)); }
.intro-card { width: min(100%, 380px); background: linear-gradient(180deg, rgba(28,22,26,.92), rgba(16,13,18,.95)); border: 1px solid var(--line);
  border-radius: 24px; padding: 28px 22px 20px; text-align: center; box-shadow: 0 30px 80px rgba(0,0,0,.6); }
.intro-seal { width: 64px; height: 64px; margin: 0 auto 10px; border-radius: 14px; background: var(--red); display: grid; place-items: center;
  font-family: 'Gowun Batang', serif; font-size: 34px; font-weight: 700; color: #fff3df; transform: rotate(-4deg);
  box-shadow: inset 0 0 0 3px rgba(255,255,255,.18), 0 10px 30px rgba(179,51,44,.5); }
.intro-card h1 { font-family: 'Gowun Batang', serif; font-size: 34px; margin: 4px 0 6px; letter-spacing: .12em; }
.intro-sub { color: var(--ink-dim); line-height: 1.6; margin: 0 0 22px; font-size: 14px; }
.field { display: block; text-align: left; margin-bottom: 14px; }
.field > span { display: block; font-size: 12px; color: var(--ink-dim); margin-bottom: 6px; }
.field input { width: 100%; background: rgba(255,255,255,.06); border: 1px solid var(--line); border-radius: 12px; padding: 13px 14px; color: var(--ink); outline: none; font-size: 16px; }
.field input:focus { border-color: var(--gold); }
#colors { display: flex; gap: 8px; flex-wrap: wrap; }
#colors button { width: 38px; height: 38px; border-radius: 50%; border: 2px solid transparent; box-shadow: inset 0 0 0 2px rgba(0,0,0,.2); }
#colors button.on { border-color: #fff; transform: scale(1.08); }
.intro-foot { font-size: 11px; color: #85796a; margin: 14px 0 0; }

/* 1:1 점사 — 배경은 3D(할매와 마주 앉은 장면), 위는 머리줄, 아래는 자막·고르기 */
#consult { position: fixed; inset: 0; z-index: 25; display: flex; flex-direction: column; pointer-events: none; animation: rise .5s ease-out; }
#consult > * { pointer-events: auto; }
@keyframes rise { from { opacity: 0; transform: translateY(20px); } }
.c-head { display: flex; align-items: center; gap: 8px; padding: calc(10px + var(--safe-t)) 12px 10px;
  background: linear-gradient(180deg, rgba(8,6,6,.7), transparent); }
.c-who { flex: 1; min-width: 0; }
.c-who b { font-family: 'Gowun Batang', serif; font-size: 18px; display: block; text-shadow: 0 2px 8px #000; }
.c-who small { font-size: 12px; color: var(--ink-dim); display: flex; align-items: center; }
.c-timer { font-variant-numeric: tabular-nums; font-weight: 700; background: rgba(179,51,44,.3); border: 1px solid rgba(226,114,95,.5); color: #ffcbb8; padding: 6px 10px; border-radius: 999px; font-size: 14px; }
.c-timer.warn { background: var(--red); color: #fff; }
.round.small { width: 40px; height: 40px; font-size: 16px; flex: none; }
.c-low { margin-top: auto; padding: 40px 12px calc(12px + var(--safe-b)); background: linear-gradient(180deg, transparent, rgba(8,5,4,.82) 38%); display: flex; flex-direction: column; gap: 10px; }
.c-sub { position: relative; max-width: 640px; width: 100%; margin: 0 auto; background: rgba(20,13,10,.72); border: 1px solid rgba(216,178,90,.35);
  border-radius: 16px; padding: 12px 16px 18px; cursor: pointer; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); min-height: 84px; }
.c-name { font-size: 12px; color: var(--gold); font-weight: 700; letter-spacing: .06em; }
#c-line { margin: 4px 0 0; font-family: 'Gowun Batang', serif; font-size: 18px; line-height: 1.6; word-break: keep-all; overflow-wrap: anywhere; color: #fff6e6; text-shadow: 0 1px 2px #000; }
#c-line.stage { font-style: italic; color: #e8c98a; font-size: 15px; }
.c-tap { position: absolute; right: 12px; bottom: 6px; font-size: 10px; color: #8d7d66; }
#c-me { align-self: flex-end; max-width: 80%; background: linear-gradient(180deg, #a5352e, #7e2320); color: #fff4e6; border-radius: 16px 4px 16px 16px; padding: 8px 13px; font-size: 14px; animation: pop .25s ease-out; }
.c-foot { max-width: 640px; width: 100%; margin: 0 auto; }
#c-card { margin: 4px auto 0; width: min(94vw, 460px); max-height: 42vh; overflow-y: auto; position: relative; animation: pop .35s ease-out; }
#c-card .card { margin: 0; max-width: 100%; }
.c-card-x { position: sticky; top: 0; float: right; z-index: 2; margin: 6px 6px -34px 0; background: rgba(43,33,22,.85); color: #f3ead7; border-radius: 999px; padding: 5px 11px; font-size: 12px; }
#c-log { position: absolute; inset: 0; background: rgba(14,10,8,.96); display: flex; flex-direction: column; z-index: 3; padding-top: var(--safe-t); }
.c-log-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-bottom: 1px solid rgba(216,178,90,.2); font-family: 'Gowun Batang', serif; }
.c-body { flex: 1; overflow-y: auto; padding: 16px 14px 24px; display: flex; flex-direction: column; gap: 10px; -webkit-overflow-scrolling: touch; }
.msg { display: flex; gap: 8px; align-items: flex-end; max-width: 100%; }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }
.bubble { padding: 10px 13px; border-radius: 4px 16px 16px 16px; line-height: 1.6; font-size: 14px; max-width: 86%; word-break: keep-all; overflow-wrap: anywhere; }
.msg.g .bubble { background: var(--paper); color: var(--paper-ink); font-family: 'Gowun Batang', serif; }
.msg.g.stage .bubble { background: transparent; color: #c9b48a; font-style: italic; padding-left: 0; }
.msg.u { justify-content: flex-end; }
.msg.u .bubble { background: linear-gradient(180deg, #a5352e, #7e2320); color: #fff4e6; border-radius: 16px 4px 16px 16px; }
#c-log .card { margin: 4px 0; max-width: 100%; }

/* 처음 이야기 */
#story { position: fixed; inset: 0; z-index: 22; pointer-events: none; }
#story .bar { position: absolute; left: 0; right: 0; height: 11vh; background: #000; }
#story .bar.top { top: 0; } #story .bar.bot { bottom: 0; }
#story-line { position: absolute; left: 50%; bottom: calc(14vh + var(--safe-b)); transform: translateX(-50%); width: min(90vw, 620px); margin: 0; text-align: center;
  font-family: 'Gowun Batang', serif; font-size: clamp(17px, 2.4vw, 22px); line-height: 1.7; color: #fff3df; text-shadow: 0 2px 10px #000, 0 0 2px #000; word-break: keep-all; opacity: 0; transition: opacity .6s; }
#story-line.on { opacity: 1; }
#story-skip { position: absolute; right: 14px; top: calc(11vh + 10px); pointer-events: auto; color: #e8dcc4; background: rgba(0,0,0,.4); }
#fade { position: fixed; inset: 0; background: #000; opacity: 0; pointer-events: none; z-index: 40; transition: opacity .5s; }
#fade.on { opacity: 1; }

/* 공지 · 설정 */
#notice { position: fixed; top: calc(70px + var(--safe-t)); left: 50%; transform: translateX(-50%); width: min(92vw, 420px); z-index: 5; background: rgba(126,35,32,.85);
  border: 1px solid rgba(226,114,95,.6); color: #ffe9d6; font-size: 13px; padding: 8px 12px; border-radius: 12px; text-align: center; }
#settings { position: fixed; inset: 0; z-index: 35; display: grid; place-items: center; padding: 20px; background: rgba(5,6,14,.6); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
.set-list { display: flex; flex-direction: column; gap: 2px; margin: 10px 0 4px; }
.set-row { display: flex; justify-content: space-between; align-items: center; padding: 13px 4px; border-bottom: 1px solid rgba(216,178,90,.14); font-size: 15px; background: none; color: var(--ink); width: 100%; text-align: left; min-height: 48px; }
.set-row b { color: var(--ink-dim); font-weight: 600; }
.set-row input { width: 22px; height: 22px; accent-color: var(--red); }
#ver-row { user-select: none; -webkit-user-select: none; }
.rename-actions.one { grid-template-columns: 1fr; }
#hud-top #btn-set { pointer-events: auto; align-self: center; }
#my-ticket { top: calc(118px + var(--safe-t)); }

.card { margin: 6px 0 6px 40px; background: linear-gradient(180deg, #f7f0df, #ecdfc4); color: var(--paper-ink); border-radius: 16px; padding: 14px;
  box-shadow: 0 8px 24px rgba(0,0,0,.35); animation: pop .35s ease-out; max-width: calc(100% - 40px); }
.card h4 { margin: 0 0 10px; font-family: 'Gowun Batang', serif; font-size: 15px; display: flex; justify-content: space-between; align-items: baseline; }
.card h4 small { font-family: Pretendard, sans-serif; font-weight: 500; color: #7b6a50; font-size: 11px; }
.pillars { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; text-align: center; }
.pillars .lab { font-size: 11px; color: #7b6a50; margin-bottom: 4px; }
.pillars .ch { border-radius: 10px; padding: 6px 0 4px; margin-bottom: 4px; font-family: 'Gowun Batang', serif; }
.pillars .ch b { display: block; font-size: 26px; line-height: 1.1; }
.pillars .ch small { font-size: 10px; opacity: .85; font-family: Pretendard, sans-serif; }
.pillars .ch.me { box-shadow: 0 0 0 2px #2b2116; }
.pillars .empty { background: rgba(0,0,0,.06); color: #9b8b70; height: 52px; display: grid; place-items: center; font-size: 11px; border-radius: 10px; margin-bottom: 4px; }
.bars { display: flex; flex-direction: column; gap: 7px; }
.bar { display: grid; grid-template-columns: 44px 1fr 22px; align-items: center; gap: 8px; font-size: 13px; }
.bar .track { height: 10px; background: rgba(0,0,0,.08); border-radius: 99px; overflow: hidden; }
.bar .fill { height: 100%; border-radius: 99px; width: 0; transition: width .9s cubic-bezier(.2,.8,.2,1); }
.bar .n { text-align: right; font-weight: 700; }
.lucky-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.lucky-grid div { background: rgba(255,255,255,.55); border-radius: 10px; padding: 8px 10px; font-size: 13px; }
.lucky-grid small { display: block; color: #7b6a50; font-size: 11px; }


.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chip { background: rgba(243,234,215,.08); border: 1px solid rgba(216,178,90,.45); color: var(--ink); padding: 10px 14px; border-radius: 999px; font-size: 14px; font-weight: 600; }
.chip small { display: block; font-size: 10px; color: var(--ink-dim); font-weight: 500; }
.chip.main { background: var(--red); border-color: #e2725f; color: #fff; }
.chip:active { transform: scale(.96); }
.chips.grid { display: grid; grid-template-columns: repeat(4, 1fr); }
.chips.grid .chip { padding: 8px 4px; text-align: center; }
.row-input { display: flex; gap: 8px; }
.row-input input, .row-input select { flex: 1; min-width: 0; background: rgba(255,255,255,.07); border: 1px solid rgba(216,178,90,.4); color: var(--ink); border-radius: 12px; padding: 12px; outline: none; font-size: 16px; color-scheme: dark; }
.row-input button { background: var(--red); color: #fff; border-radius: 12px; padding: 0 18px; font-weight: 700; }
.date-row { display: grid; grid-template-columns: 1.3fr 1fr 1fr auto; gap: 6px; }
.date-row select { padding: 12px 6px; }
.foot-note { text-align: center; font-size: 11px; color: #85796a; margin-top: 8px; }

/* 이름 */
.nick-row { display: flex; gap: 8px; }
.nick-row input { flex: 1; min-width: 0; width: 100%; background: rgba(255,255,255,.06); border: 1px solid var(--line); border-radius: 12px; padding: 13px 14px; color: var(--ink); outline: none; font-size: 16px; }
.nick-row input:focus { border-color: var(--gold); }
.dice { flex: none; width: 50px; border-radius: 12px; background: rgba(216,178,90,.14); border: 1px solid var(--line); font-size: 22px; transition: transform .35s; }
.dice.spin { transform: rotate(360deg) scale(1.08); }
.nick-help { display: block; margin-top: 6px; font-size: 11px; color: #85796a; }
#rename { position: fixed; inset: 0; z-index: 28; display: grid; place-items: center; padding: 20px; background: rgba(5,6,14,.6); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
.rename-card { width: min(100%, 360px); background: linear-gradient(180deg, rgba(30,24,28,.97), rgba(16,13,18,.98)); border: 1px solid var(--line); border-radius: 20px; padding: 20px; box-shadow: 0 30px 80px rgba(0,0,0,.6); animation: rise .25s ease-out; }
.rename-card h3 { margin: 0 0 4px; font-family: 'Gowun Batang', serif; font-size: 20px; }
.rename-card p { margin: 0 0 14px; font-size: 13px; color: var(--ink-dim); }
.rename-actions { display: grid; grid-template-columns: 1fr 1.4fr; gap: 8px; margin-top: 14px; }
#btn-name { font-size: 18px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
