:root {
  --glass: rgba(32, 40, 37, 0.62);
  --glass-strong: rgba(28, 35, 32, 0.8);
  --glass-line: rgba(255, 255, 255, 0.1);
  --cream: #f5efe3;
  --cream-soft: rgba(245, 239, 227, 0.66);
  --amber: #f1b768;
  --amber-ink: #2b2115;
  --brand-ink: #2f3a34;
  --brand-soft: rgba(47, 58, 52, 0.86);
  --brand-glow: 0 0 14px rgba(250, 242, 228, 0.7);
  --sans: "Noto Sans KR", "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  --serif: "Gowun Batang", "Noto Serif KR", serif;
}
body.is-night {
  --brand-ink: #f5efe3;
  --brand-soft: rgba(245, 239, 227, 0.75);
  --brand-glow: 0 0 12px rgba(16, 22, 30, 0.6);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: #e9d2c2; color: var(--cream);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
p { margin: 0; }
#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#scene:active { cursor: grabbing; }
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }
.soft { color: var(--cream-soft); }
.glass {
  background: var(--glass);
  border: 1px solid var(--glass-line);
  backdrop-filter: blur(14px) saturate(1.1); -webkit-backdrop-filter: blur(14px) saturate(1.1);
}

/* ── 왼쪽 위 ── */
.brand {
  position: fixed; z-index: 5;
  top: max(22px, env(safe-area-inset-top)); left: 26px;
  color: var(--brand-ink); text-shadow: var(--brand-glow);
  transition: color .8s;
}
.brand h1 { margin: 0; font-family: var(--serif); font-weight: 700; font-size: 25px; letter-spacing: -.02em; pointer-events: none; }
.status { margin-top: 4px; font-size: 13px; font-weight: 500; color: var(--brand-soft); pointer-events: none; }
.who { margin-top: 8px; display: flex; align-items: center; gap: 6px; font-size: 13px; }
.who-label { color: var(--brand-soft); }
.who b { font-weight: 700; }
.reroll {
  width: 24px; height: 24px; border: 0; border-radius: 50%; padding: 0;
  background: transparent; color: var(--brand-soft); font-size: 15px; line-height: 1;
  transition: transform .35s ease, color .2s;
}
.reroll:hover { transform: rotate(-120deg); color: var(--brand-ink); }
.presence { margin-top: 4px; display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--brand-soft); pointer-events: none; }
.presence-dot { width: 7px; height: 7px; border-radius: 50%; background: #9aa29c; }
.presence.online .presence-dot { background: #7fbf6a; box-shadow: 0 0 0 3px rgba(127, 191, 106, 0.25); }

/* ── 오른쪽 위 ── */
.corner {
  position: fixed; z-index: 6;
  top: max(20px, env(safe-area-inset-top)); right: 22px;
  display: flex; gap: 8px; align-items: center;
}
.icon-btn, .chip-btn {
  height: 38px; border: 1px solid var(--glass-line); border-radius: 19px;
  background: var(--glass); color: var(--cream);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: background .2s;
}
.icon-btn { width: 38px; padding: 0; font-size: 15px; font-weight: 700; }
.chip-btn { padding: 0 14px 0 11px; font-size: 13px; font-weight: 500; }
.icon-btn:hover, .chip-btn:hover { background: var(--glass-strong); }
.icon-btn[aria-expanded="true"], .chip-btn[aria-expanded="true"] { background: var(--amber); color: var(--amber-ink); border-color: transparent; }
.corner svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
#sound .mute { display: inline; }
#sound .wave { display: none; }
#sound[aria-pressed="true"] { color: var(--amber); }
#sound[aria-pressed="true"] .mute { display: none; }
#sound[aria-pressed="true"] .wave { display: inline; }

.pop {
  position: absolute; top: 48px; right: 0; width: 272px;
  padding: 14px; border-radius: 16px;
  background: var(--glass-strong); border: 1px solid var(--glass-line);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  font-size: 12.5px; line-height: 1.6;
}
.seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; padding: 3px; border-radius: 12px; background: rgba(255, 255, 255, 0.06); }
.seg button { border: 0; border-radius: 9px; padding: 7px 0; background: transparent; font-size: 12.5px; }
.seg button:hover { background: rgba(255, 255, 255, 0.08); }
.seg button.on { background: var(--amber); color: var(--amber-ink); font-weight: 700; }
.note { margin-top: 10px; font-size: 11.5px; color: var(--amber); }
.wx { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--glass-line); }
#weather-meta { font-size: 11.5px; }
#weather-meta.warn { color: #f0a07a; }
.credit { margin-top: 4px; font-size: 10.5px; }
.credit a { color: var(--cream-soft); text-decoration: none; }
.credit a:hover { text-decoration: underline; }
#help ul { margin: 0 0 10px; padding-left: 16px; }
#help li + li { margin-top: 3px; }
#help .soft { font-size: 11.5px; }

/* ── 아래 ── */
.bottom {
  position: fixed; z-index: 5; left: 50%; transform: translateX(-50%);
  bottom: max(18px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  max-width: calc(100% - 24px);
}
.place {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 6px 13px; border-radius: 999px;
  background: var(--glass); border: 1px solid var(--glass-line);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  font-size: 12px; font-weight: 500;
}
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--amber); box-shadow: 0 0 0 0 rgba(241, 183, 104, .6); animation: pulse 2.4s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(241, 183, 104, .55); } 70% { box-shadow: 0 0 0 7px rgba(241, 183, 104, 0); } 100% { box-shadow: 0 0 0 0 rgba(241, 183, 104, 0); } }
.subchips { display: flex; gap: 4px; padding: 3px; border-radius: 999px; background: var(--glass); border: 1px solid var(--glass-line); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); }
.subchips button { border: 0; border-radius: 999px; padding: 5px 12px; background: transparent; font-size: 12px; }
.subchips button.on { background: var(--cream); color: var(--amber-ink); font-weight: 700; }

.tray {
  display: flex; align-items: stretch; gap: 2px;
  padding: 6px; border-radius: 22px;
  background: var(--glass); border: 1px solid var(--glass-line);
  backdrop-filter: blur(16px) saturate(1.1); -webkit-backdrop-filter: blur(16px) saturate(1.1);
  box-shadow: 0 12px 34px rgba(20, 16, 12, 0.18);
  max-width: 100%; overflow-x: auto; scrollbar-width: none;
}
.tray::-webkit-scrollbar { display: none; }
.tray button {
  flex: none; min-width: 60px; padding: 8px 8px 7px; border: 0; border-radius: 16px;
  background: transparent; color: var(--cream);
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 500; white-space: nowrap;
  transition: background .2s, color .2s;
}
.tray button:hover { background: rgba(255, 255, 255, 0.08); }
.tray button.on { background: var(--amber); color: var(--amber-ink); font-weight: 700; }
.tray button[data-cmd] { color: var(--amber); }
.tray svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.tray .sep { flex: none; width: 1px; margin: 10px 4px; background: var(--glass-line); }
.tray button.appear { animation: appear .35s ease; }
@keyframes appear { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.toast {
  position: fixed; z-index: 4; left: 50%; transform: translateX(-50%);
  bottom: calc(max(18px, env(safe-area-inset-bottom)) + 124px);
  padding: 9px 16px; border-radius: 999px; max-width: calc(100% - 32px); text-align: center;
  background: rgba(250, 246, 238, 0.9); color: #2f3a34; font-size: 12.5px; font-weight: 500;
  box-shadow: 0 8px 24px rgba(40, 30, 20, 0.15);
  transition: opacity .8s, transform .8s; pointer-events: none;
}
.toast.gone { opacity: 0; transform: translate(-50%, 6px); }

/* ── 사진 ── */
.flash { position: fixed; inset: 0; z-index: 30; background: #fff; opacity: 0; pointer-events: none; }
.flash.go { animation: flash .5s ease-out; }
@keyframes flash { 0% { opacity: .85; } 100% { opacity: 0; } }
.photo {
  position: fixed; inset: 0; z-index: 20;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  padding: 24px 16px; background: rgba(24, 28, 26, 0.55);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  animation: fadein .3s ease;
}
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
.polaroid { margin: 0; transform: rotate(-1.6deg); animation: drop .5s cubic-bezier(.2, .9, .3, 1.2); }
@keyframes drop { from { transform: rotate(-6deg) translateY(-20px) scale(.94); opacity: 0; } to { transform: rotate(-1.6deg); opacity: 1; } }
.polaroid img { display: block; max-width: min(520px, 86vw); max-height: 68vh; box-shadow: 0 18px 40px rgba(0, 0, 0, 0.35); }
.photo-actions { display: flex; gap: 10px; }
.btn {
  padding: 10px 18px; border-radius: 999px; border: 1px solid var(--glass-line);
  background: var(--glass-strong); color: var(--cream); font-size: 13px; font-weight: 500; text-decoration: none;
}
.btn.primary { background: var(--amber); color: var(--amber-ink); border-color: transparent; font-weight: 700; }

.fallback { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 16px; background: #2b332f; color: var(--cream); text-align: center; line-height: 1.7; }
.fallback h1 { margin: 0 0 12px; font-family: var(--serif); }

/* ── 모바일 ── */
@media (max-width: 720px) {
  .brand { left: 16px; top: max(14px, env(safe-area-inset-top)); }
  .brand h1 { font-size: 21px; }
  .status, .who { font-size: 11.5px; }
  .who { margin-top: 6px; }
  .corner { right: 12px; top: max(14px, env(safe-area-inset-top)); gap: 6px; }
  .icon-btn, .chip-btn { height: 34px; }
  .icon-btn { width: 34px; }
  .pop { top: 42px; width: min(272px, calc(100vw - 24px)); }
  .bottom { bottom: max(10px, env(safe-area-inset-bottom)); max-width: calc(100% - 16px); }
  .tray { border-radius: 18px; padding: 5px; }
  .tray button { min-width: 54px; padding: 7px 5px 6px; font-size: 10.5px; }
  .toast { bottom: calc(max(10px, env(safe-area-inset-bottom)) + 112px); font-size: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
