:root {
  --ink: #f4efe2;
  --ink-dim: rgba(244, 239, 226, 0.72);
  --ink-faint: rgba(244, 239, 226, 0.5);
  --night: #141b2d;
  --glass: rgba(18, 24, 40, 0.62);
  --glass-strong: rgba(18, 24, 40, 0.86);
  --line: rgba(255, 255, 255, 0.12);
  --moon: #e8c872;
  --moon-deep: #c9a443;
  --leaf: #7fb069;
  --danger: #ff8f7a;
  --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --font: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--night); color: var(--ink); font-family: var(--font); -webkit-font-smoothing: antialiased; }
body { overscroll-behavior: none; -webkit-tap-highlight-color: transparent; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

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

/* ───────── 로딩 ───────── */
.boot { position: fixed; inset: 0; z-index: 50; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; background: radial-gradient(ellipse at 50% 35%, #26304d 0%, #10162a 70%); transition: opacity .8s ease; }
.boot.done { opacity: 0; pointer-events: none; }
.boot-mark { width: 44px; height: 44px; color: var(--moon); filter: drop-shadow(0 0 18px rgba(232, 200, 114, .5)); }
.boot h1 { margin: 0; font-size: 30px; font-weight: 600; letter-spacing: 8px; padding-left: 8px; }
.boot p { margin: 0; color: var(--ink-dim); font-size: 13px; }
.boot-dot { width: 5px; height: 5px; margin-top: 14px; border-radius: 50%; background: var(--moon); animation: breathe 1.8s ease-in-out infinite; }
.boot.error .boot-dot { display: none; }
@keyframes breathe { 50% { opacity: .2; } }

/* ───────── 입장 화면 ───────── */
.entry { position: fixed; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center; padding: 20px; padding-bottom: calc(20px + var(--safe-b)); background: linear-gradient(180deg, rgba(10, 14, 28, .15) 0%, rgba(10, 14, 28, .55) 100%); overflow-y: auto; }
.entry-card { width: min(420px, 100%); padding: 28px 26px 22px; border-radius: 24px; background: var(--glass-strong); border: 1px solid var(--line); box-shadow: 0 30px 80px rgba(0, 0, 0, .45); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); animation: rise .7s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }
.eyebrow { margin: 0; color: var(--moon); font-size: 12px; letter-spacing: 2px; }
.entry-title { margin: 6px 0 4px; font-size: 40px; font-weight: 700; letter-spacing: 10px; }
.lead { margin: 0 0 12px; color: var(--ink-dim); font-size: 14.5px; line-height: 1.6; }
.live { display: flex; align-items: center; gap: 8px; margin: 0 0 18px; font-size: 13.5px; color: var(--ink-dim); }
.live b { color: var(--ink); }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: #6fe08b; box-shadow: 0 0 0 0 rgba(111, 224, 139, .6); animation: ping 2s infinite; }
@keyframes ping { 70% { box-shadow: 0 0 0 8px rgba(111, 224, 139, 0); } 100% { box-shadow: 0 0 0 0 rgba(111, 224, 139, 0); } }
.field-label { display: block; margin: 14px 0 6px; font-size: 13px; color: var(--ink-dim); }
.text-input { width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: rgba(255, 255, 255, .07); outline: none; font-size: 16px; transition: border-color .2s, background .2s; }
.text-input:focus { border-color: var(--moon); background: rgba(255, 255, 255, .1); }
select.text-input { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--ink-dim) 50%), linear-gradient(135deg, var(--ink-dim) 50%, transparent 50%); background-position: calc(100% - 20px) 52%, calc(100% - 14px) 52%; background-size: 6px 6px; background-repeat: no-repeat; }
select.text-input option { color: #111; }
.hint { margin: 6px 2px 0; font-size: 12px; color: var(--ink-faint); }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch { width: 30px; height: 30px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .25); padding: 0; transition: transform .15s; }
.swatch[aria-checked="true"] { border-color: var(--ink); transform: scale(1.12); box-shadow: 0 0 0 3px rgba(232, 200, 114, .5); }
.error { min-height: 18px; margin: 10px 0 0; font-size: 13px; color: var(--danger); }
.primary { width: 100%; margin-top: 10px; padding: 14px; border: 0; border-radius: 14px; background: linear-gradient(180deg, #f1d58a, var(--moon-deep)); color: #2a2110; font-weight: 700; font-size: 16px; letter-spacing: 2px; box-shadow: 0 8px 24px rgba(201, 164, 67, .35); transition: transform .1s, filter .2s; }
.primary:hover { filter: brightness(1.05); }
.primary:active { transform: translateY(1px); }
.primary:disabled { filter: grayscale(.6) brightness(.8); cursor: wait; }
.howto { margin-top: 16px; font-size: 13px; color: var(--ink-dim); }
.howto summary { cursor: pointer; }
.howto ul { margin: 8px 0 0; padding-left: 18px; line-height: 1.8; }
.howto b { color: var(--ink); font-weight: 600; }

/* ───────── HUD ───────── */
.hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
.hud > * { pointer-events: auto; }
.topbar { position: absolute; top: calc(10px + var(--safe-t)); left: 10px; right: 10px; display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; pointer-events: none; }
.topbar > * { pointer-events: auto; }
.place { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 9px 14px; border-radius: 14px; border: 1px solid var(--line); background: var(--glass); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); text-align: left; max-width: 52vw; }
.place span { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.place small { color: var(--ink-dim); font-size: 11.5px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.icon-btn { display: inline-flex; align-items: center; gap: 5px; min-width: 40px; height: 40px; padding: 0 11px; border-radius: 12px; border: 1px solid var(--line); background: var(--glass); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); font-size: 16px; justify-content: center; }
.icon-btn em { font-style: normal; font-size: 12.5px; color: var(--ink-dim); }
.icon-btn:hover { background: rgba(40, 50, 76, .75); }

.minimap { position: absolute; top: calc(62px + var(--safe-t)); right: 10px; width: 150px; height: 150px; border-radius: 18px; border: 1px solid var(--line); box-shadow: 0 8px 24px rgba(0, 0, 0, .3); cursor: pointer; background: #1b2236; }

.guide { position: absolute; top: calc(222px + var(--safe-t)); right: 10px; display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px 12px; border-radius: 12px; background: var(--glass); border: 1px solid var(--line); font-size: 13px; backdrop-filter: blur(10px); }
.guide-arrow { display: inline-block; color: var(--moon); font-size: 18px; transition: transform .15s linear; }
.guide button { border: 0; background: none; color: var(--ink-faint); padding: 2px 4px; }

.place-card { position: absolute; left: 50%; top: calc(70px + var(--safe-t)); transform: translate(-50%, -8px); width: min(380px, calc(100vw - 190px)); padding: 12px 16px; border-radius: 16px; background: var(--glass-strong); border: 1px solid var(--line); text-align: center; opacity: 0; transition: opacity .5s, transform .5s; pointer-events: none; }
.place-card.show { opacity: 1; transform: translate(-50%, 0); }
.place-card h3 { margin: 0 0 4px; font-size: 17px; letter-spacing: 1px; }
.place-card h3 small { display: block; margin-bottom: 2px; color: var(--moon); font-size: 11px; font-weight: 500; letter-spacing: 2px; }
.place-card p { margin: 0; font-size: 13px; color: var(--ink-dim); line-height: 1.5; }

.announce { position: absolute; left: 50%; top: 32%; transform: translateX(-50%); width: min(520px, 92vw); padding: 16px 20px; border-radius: 18px; background: linear-gradient(180deg, rgba(60, 46, 14, .92), rgba(36, 28, 10, .92)); border: 1px solid rgba(232, 200, 114, .5); text-align: center; font-size: 15px; line-height: 1.6; opacity: 0; pointer-events: none; transition: opacity .5s; }
.announce.show { opacity: 1; }
.announce b { display: block; color: var(--moon); font-size: 12px; letter-spacing: 2px; margin-bottom: 4px; }

.toasts { position: absolute; left: 50%; bottom: calc(150px + var(--safe-b)); transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; }
.toast { padding: 8px 14px; border-radius: 999px; background: var(--glass-strong); border: 1px solid var(--line); font-size: 13px; animation: toast 3.2s ease forwards; white-space: nowrap; }
@keyframes toast { 0% { opacity: 0; transform: translateY(6px); } 10%, 85% { opacity: 1; transform: none; } 100% { opacity: 0; } }

/* 대화 */
.chat { position: absolute; left: 10px; bottom: calc(66px + var(--safe-b)); width: min(380px, calc(100vw - 20px)); display: flex; flex-direction: column; gap: 6px; }
.chat-log { list-style: none; margin: 0; padding: 0 2px; max-height: 30vh; overflow-y: auto; display: flex; flex-direction: column; gap: 3px; mask-image: linear-gradient(180deg, transparent 0, #000 22px); -webkit-mask-image: linear-gradient(180deg, transparent 0, #000 22px); scrollbar-width: none; }
.chat-log::-webkit-scrollbar { display: none; }
.chat-log li { align-self: flex-start; max-width: 100%; padding: 5px 10px; border-radius: 12px; background: rgba(14, 19, 32, .55); font-size: 13.5px; line-height: 1.45; word-break: break-word; text-shadow: 0 1px 2px rgba(0, 0, 0, .4); }
.chat-log li .who { font-weight: 700; margin-right: 6px; }
.chat-log li.me .who { color: var(--moon); }
.chat-log li.sys { background: none; color: var(--ink-faint); font-size: 12px; padding: 1px 10px; }
.chat-log li.ann { background: rgba(70, 54, 16, .7); border: 1px solid rgba(232, 200, 114, .35); }
.chat-form { display: flex; gap: 6px; }
.chat-form .text-input { padding: 10px 12px; font-size: 15px; background: var(--glass); backdrop-filter: blur(10px); }
.send { width: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--glass); color: var(--moon); }
.chat.idle .chat-log { opacity: .75; }

/* 동작 */
.emotes { position: absolute; left: 50%; bottom: calc(10px + var(--safe-b)); transform: translateX(-50%); display: flex; gap: 6px; padding: 6px; border-radius: 18px; background: var(--glass); border: 1px solid var(--line); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.emote { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; width: 56px; height: 44px; border: 0; border-radius: 12px; background: transparent; font-size: 19px; line-height: 1; }
.emote small { margin-top: 3px; font-size: 10px; color: var(--ink-dim); white-space: nowrap; }
.emote:hover, .emote.on { background: rgba(232, 200, 114, .18); }
.emote kbd { position: absolute; top: 2px; right: 4px; font: 9px var(--font); color: var(--ink-faint); }
.emote.mobile-only { display: none; }

/* 조이스틱 */
.joystick { position: absolute; left: 22px; bottom: calc(86px + var(--safe-b)); width: 112px; height: 112px; border-radius: 50%; background: radial-gradient(circle, rgba(255, 255, 255, .08), rgba(255, 255, 255, .02)); border: 1px solid rgba(255, 255, 255, .18); display: none; touch-action: none; }
.joystick .knob { position: absolute; left: 50%; top: 50%; width: 48px; height: 48px; margin: -24px 0 0 -24px; border-radius: 50%; background: rgba(244, 239, 226, .75); box-shadow: 0 4px 12px rgba(0, 0, 0, .3); pointer-events: none; }

.net-status { position: absolute; left: 50%; top: calc(64px + var(--safe-t)); transform: translateX(-50%); padding: 8px 14px; border-radius: 999px; background: rgba(120, 40, 30, .85); font-size: 13px; }

/* ───────── 패널 ───────── */
.panel { position: fixed; z-index: 30; top: calc(62px + var(--safe-t)); right: 10px; bottom: calc(10px + var(--safe-b)); width: min(400px, calc(100vw - 20px)); display: flex; flex-direction: column; border-radius: 20px; background: var(--glass-strong); border: 1px solid var(--line); box-shadow: 0 20px 60px rgba(0, 0, 0, .45); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); animation: slide .25s ease both; }
@keyframes slide { from { opacity: 0; transform: translateX(16px); } }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 10px 18px; border-bottom: 1px solid var(--line); }
.panel-head h2 { margin: 0; font-size: 17px; }
.panel-body { flex: 1; overflow-y: auto; padding: 12px 16px 18px; font-size: 14px; }
.panel-body h3 { margin: 18px 0 8px; font-size: 13px; color: var(--moon); letter-spacing: 1px; font-weight: 600; }
.panel-body h3:first-child { margin-top: 4px; }
.panel-body p.note { color: var(--ink-faint); font-size: 12.5px; line-height: 1.6; }
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.row { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 12px; background: rgba(255, 255, 255, .04); }
.row:hover { background: rgba(255, 255, 255, .08); }
.row .grow { flex: 1; min-width: 0; }
.row .grow b { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .grow small { display: block; color: var(--ink-faint); font-size: 12px; margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row.current { outline: 1px solid rgba(232, 200, 114, .5); }
.dot { width: 12px; height: 12px; border-radius: 50%; flex: none; border: 1px solid rgba(255, 255, 255, .3); }
.chip { flex: none; padding: 6px 10px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255, 255, 255, .06); font-size: 12.5px; }
.chip.gold { border-color: rgba(232, 200, 114, .6); color: var(--moon); }
.chip:disabled { opacity: .45; cursor: default; }
.bigmap { width: 100%; aspect-ratio: 1; border-radius: 14px; border: 1px solid var(--line); background: #1b2236; display: block; cursor: crosshair; }
.course { margin: 6px 0 2px; display: flex; flex-wrap: wrap; gap: 4px; align-items: center; font-size: 12.5px; }
.course button { padding: 4px 8px; border-radius: 8px; border: 1px solid var(--line); background: rgba(255, 255, 255, .05); font-size: 12px; }
.course i { color: var(--ink-faint); font-style: normal; }
.news-item { display: flex; gap: 12px; padding: 10px; border-radius: 14px; background: rgba(255, 255, 255, .04); text-decoration: none; color: inherit; }
.news-item:hover { background: rgba(255, 255, 255, .09); }
.news-item img { width: 84px; height: 64px; flex: none; object-fit: cover; border-radius: 10px; background: #2a3148; }
.news-item b { display: block; font-weight: 600; line-height: 1.4; }
.news-item p { margin: 3px 0 0; color: var(--ink-dim); font-size: 12.5px; line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.news-item small { color: var(--ink-faint); font-size: 11.5px; }
.links { display: flex; flex-direction: column; gap: 6px; }
.links a { color: var(--moon); text-decoration: none; font-size: 13.5px; }
.links a:hover { text-decoration: underline; }
.setting { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid rgba(255, 255, 255, .06); }
.setting select, .setting input[type="range"] { max-width: 55%; }
.setting select { padding: 6px 10px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255, 255, 255, .07); }
.setting select option { color: #111; }
.toggle { appearance: none; width: 42px; height: 24px; border-radius: 999px; background: rgba(255, 255, 255, .18); position: relative; cursor: pointer; transition: background .2s; flex: none; }
.toggle::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .2s; }
.toggle:checked { background: var(--moon-deep); }
.toggle:checked::after { transform: translateX(18px); }
.spinner { padding: 20px; text-align: center; color: var(--ink-faint); }

/* ───────── 휴대폰 ───────── */
@media (pointer: coarse) {
  .joystick { display: block; }
  .emote.mobile-only { display: flex; }
  .emote kbd { display: none; }
}
@media (max-width: 720px) {
  .icon-btn em { display: none; }
  .icon-btn { min-width: 38px; height: 38px; padding: 0 9px; }
  .minimap { width: 104px; height: 104px; top: calc(56px + var(--safe-t)); border-radius: 14px; }
  .guide { top: calc(166px + var(--safe-t)); }
  .place-card { top: auto; bottom: calc(220px + var(--safe-b)); width: calc(100vw - 32px); }
  .emote { width: 42px; height: 42px; font-size: 18px; }
  .emote small { display: none; }
  .emotes { gap: 2px; padding: 4px; max-width: calc(100vw - 16px); overflow-x: auto; }
  .chat { width: calc(100vw - 150px); left: auto; right: 10px; bottom: calc(66px + var(--safe-b)); }
  .chat-log { max-height: 22vh; }
  .chat-log li { font-size: 12.5px; }
  .entry-title { font-size: 34px; }
  .panel { top: auto; left: 0; right: 0; bottom: 0; width: 100%; height: 78vh; border-radius: 20px 20px 0 0; padding-bottom: var(--safe-b); animation-name: up; }
  @keyframes up { from { opacity: 0; transform: translateY(24px); } }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
