/* ── 디자인 토큰 ─────────────────────────────────────────
   서체: Galmuri(갈무리) 한글 픽셀 폰트. 픽셀 감성 + 한글 가독성.
   타입 스케일: 1.333 비율 (16 / 21 / 28 / 38 / 50)
   간격: 8px 배수만 사용
   색: 따뜻한 종이색 뉴트럴 + 행사별 포인트 1색                   */
:root {
  --font: 'Galmuri11', 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  --font-display: 'Galmuri14', 'Galmuri11', sans-serif;
  --t0: 16px; --t1: 21px; --t2: 28px; --t3: 38px; --t4: 50px;
  --s1: 8px; --s2: 16px; --s3: 24px; --s4: 32px; --s5: 48px; --s6: 64px;

  --ink: #2a2118;
  --ink-soft: #5c4f42;
  --paper: #f7f0e1;
  --paper-2: #efe5cf;
  --line: #2a2118;
  --accent: #d9577a;
  --accent-ink: #ffffff;
  --focus: #1c64d8;
}
body[data-theme='funeral'] {
  --paper: #ecebe8; --paper-2: #dddcd7; --ink: #232427; --ink-soft: #55575c; --line: #232427;
  --accent: #3f4248; --accent-ink: #ffffff;
}
body[data-theme='birthday'] { --accent: #d98a12; --accent-ink: #2a2118; }
body[data-theme='general'] { --accent: #3f7a52; }

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  font-size: var(--t0);
  line-height: 1.6;
  color: var(--ink);
  background: #cfe6f5;
  overflow: hidden;
  -webkit-font-smoothing: none;
  touch-action: manipulation;
}
#stage { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

h1, h2, h3, p { margin: 0; }
h1 { font-family: var(--font-display); font-size: var(--t3); line-height: 1.2; letter-spacing: -0.02em; font-weight: 700; }
h2 { font-family: var(--font-display); font-size: var(--t2); line-height: 1.2; letter-spacing: -0.01em; }
h3 { font-size: var(--t0); display: flex; align-items: center; gap: var(--s1); margin-bottom: var(--s2); }
.eyebrow { font-size: 14px; letter-spacing: 0.04em; color: var(--ink-soft); margin-bottom: var(--s2); }
.lead { color: var(--ink-soft); margin-top: var(--s2); max-width: 36ch; }
.lead.small { margin-top: var(--s1); }

/* ── 패널: 인벤토리 창처럼 각지고 계단식 그림자 ── */
.screen {
  position: fixed; inset: 0; z-index: 2;
  display: flex; align-items: stretch;
  padding: var(--s3);
  pointer-events: none;
  overflow-y: auto;
}
.panel {
  pointer-events: auto;
  width: min(460px, 100%);
  max-height: 100%;
  overflow-y: auto;
  background: var(--paper);
  border: 3px solid var(--line);
  box-shadow: 6px 6px 0 var(--line);
  padding: var(--s4);
  align-self: center;
}
.panel.wide { width: min(1040px, 100%); }
.privacy { margin-top: var(--s3); font-size: 14px; color: var(--ink-soft); padding-top: var(--s2); border-top: 2px dashed var(--ink-soft); }

/* ── 폼 ── */
form { margin-top: var(--s4); }
.field { display: block; margin-top: var(--s2); font-size: 14px; color: var(--ink-soft); }
.field em { font-style: normal; opacity: 0.7; }
.row { display: grid; grid-template-columns: 1fr 1.3fr; gap: var(--s2); }
input:not([type='color']):not([type='range']):not([type='radio']):not([type='checkbox']):not([type='file']), textarea {
  display: block; width: 100%; margin-top: 4px;
  font: inherit; font-size: var(--t0); color: var(--ink);
  background: #fffdf6;
  border: 3px solid var(--line); border-radius: 0;
  padding: 8px 12px; min-height: 44px;
  box-shadow: inset 3px 3px 0 rgba(42, 33, 24, 0.12);
}
textarea { resize: none; }
input[type='color'] { width: 44px; height: 44px; border: 3px solid var(--line); padding: 0; background: none; cursor: pointer; }

.types { border: 0; padding: 0; margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: var(--s1); }
.types legend { font-size: 14px; color: var(--ink-soft); padding: 0; margin-bottom: var(--s1); }
.type input { position: absolute; opacity: 0; pointer-events: none; }
.type span {
  display: grid; grid-template-columns: 24px 1fr; column-gap: var(--s1); align-items: center;
  border: 3px solid var(--line); background: var(--paper-2);
  padding: var(--s1) 12px; min-height: 56px; cursor: pointer;
}
.type i { grid-row: span 2; width: 24px; height: 24px; background: var(--c); border: 2px solid var(--line); }
.type b { font-size: var(--t0); line-height: 1.2; }
.type small { font-size: 12px; color: var(--ink-soft); line-height: 1.2; }
.type input:checked + span { background: var(--accent); color: var(--accent-ink); box-shadow: 3px 3px 0 var(--line); }
.type input:checked + span small { color: inherit; opacity: 0.85; }
.type input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ── 버튼 ── */
.btn {
  font: inherit; font-size: var(--t0); color: var(--ink);
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s1);
  min-height: 44px; padding: 8px var(--s2);
  background: var(--paper-2);
  border: 3px solid var(--line); border-radius: 0;
  box-shadow: 3px 3px 0 var(--line);
  cursor: pointer;
  transition: transform 120ms ease-out, box-shadow 120ms ease-out;
}
.btn:hover { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--line); }
.btn:active { transform: translate(3px, 3px); box-shadow: 0 0 0 var(--line); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; box-shadow: none; }
.btn.ghost:hover { background: var(--paper-2); transform: none; box-shadow: none; }
.btn.big { width: 100%; min-height: 52px; margin-top: var(--s3); font-size: var(--t1); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; box-shadow: 3px 3px 0 var(--line); transform: none; }
.btnrow { display: flex; gap: var(--s1); margin-top: var(--s2); flex-wrap: wrap; }

.linkrow { display: flex; gap: var(--s1); margin-top: var(--s2); align-items: stretch; }
.linkrow input { margin: 0; font-size: 16px; } /* 16px 미만이면 아이폰이 입력칸을 누를 때 화면을 확대한다 */

/* ── 입장 화면 (스킨 공방) ── */
.evhead { padding-bottom: var(--s3); margin-bottom: var(--s3); border-bottom: 3px solid var(--line); }
.evhead .meta { margin-top: var(--s1); color: var(--ink-soft); }
.evhead .note { margin-top: var(--s1); }
.workshop { display: grid; grid-template-columns: 280px 200px 1fr; gap: var(--s4); align-items: start; }
.step {
  display: inline-grid; place-items: center; width: 24px; height: 24px;
  background: var(--ink); color: var(--paper); font-size: 14px;
}
.cropbox { position: relative; width: 240px; height: 240px; border: 3px solid var(--line); background: #1e1a16; }
.cropbox canvas { display: block; width: 100%; height: 100%; image-rendering: pixelated; }
.cropbox .empty { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; color: #d8ccb4; font-size: 14px; line-height: 1.7; }
.slider { display: grid; grid-template-columns: 48px 1fr; align-items: center; gap: var(--s1); margin-top: var(--s1); font-size: 14px; color: var(--ink-soft); }
input[type='range'] { width: 100%; accent-color: var(--accent); height: 32px; }
.col-preview { display: flex; flex-direction: column; align-items: center; justify-content: center; align-self: stretch; background: var(--paper-2); border: 3px solid var(--line); padding: var(--s3) var(--s2); min-height: 360px; }
#preview { width: 160px; height: 320px; image-rendering: pixelated; }
.hint.tip { margin: var(--s2) 0 0; text-align: left; }
.hint { margin-top: var(--s2); font-size: 14px; color: var(--ink-soft); }
.opt { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s1) var(--s2); margin-bottom: var(--s2); }
.lbl { font-size: 14px; color: var(--ink-soft); width: 56px; flex: none; }
.seg { display: inline-flex; border: 3px solid var(--line); }
.seg button {
  font: inherit; font-size: 14px; color: var(--ink); background: var(--paper-2);
  border: 0; border-right: 3px solid var(--line); min-height: 40px; padding: 4px 12px; cursor: pointer;
}
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--ink); color: var(--paper); }
.swatches { display: flex; gap: 6px; flex-wrap: wrap; }
.swatches button { width: 32px; height: 32px; border: 3px solid var(--line); padding: 0; cursor: pointer; }
.swatches button.on { outline: 3px solid var(--focus); outline-offset: 2px; }
.col-style h3:nth-of-type(2) { margin-top: var(--s3); }
.col-style .btn.ghost { width: 100%; margin-top: var(--s1); }

/* ── HUD ── */
#hud { position: fixed; inset: 0; z-index: 3; pointer-events: none; }
#hud > * { pointer-events: auto; }
.hud-top { position: absolute; top: max(var(--s2), env(safe-area-inset-top)); left: var(--s2); right: var(--s2); display: flex; justify-content: space-between; gap: var(--s1); align-items: flex-start; pointer-events: none; }
.hud-top > * { pointer-events: auto; }
.hud-title { background: var(--paper); border: 3px solid var(--line); box-shadow: 3px 3px 0 var(--line); padding: 4px 12px; max-width: 52vw; display: flex; flex-direction: column; }
.hud-title b { font-size: var(--t0); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-title span { font-size: 12px; color: var(--ink-soft); }
.hud-actions { display: flex; gap: var(--s1); }
#demoBanner { position: absolute; left: var(--s2); top: calc(max(var(--s2), env(safe-area-inset-top)) + 92px + 148px); background: #fff3b8; border: 3px solid var(--line); padding: 2px 8px; font-size: 11px; line-height: 1.4; margin: 0; max-width: 148px; pointer-events: none; }
#prompt { position: absolute; left: 50%; bottom: 168px; transform: translateX(-50%); width: min(320px, 90vw); }
#prompt .btn { margin: 0; }
.hud-bottom { position: absolute; left: var(--s2); right: var(--s2); bottom: max(var(--s2), env(safe-area-inset-bottom)); display: flex; flex-direction: column; align-items: center; gap: var(--s1); pointer-events: none; }
.hud-bottom > * { pointer-events: auto; }
#sayForm { margin: 0; display: flex; gap: var(--s1); width: min(420px, 100%); }
#sayForm input { margin: 0; min-height: 44px; flex: 1; min-width: 0; }
#sayForm .btn { white-space: nowrap; flex: none; }
#emotes { display: flex; gap: var(--s1); flex-wrap: wrap; justify-content: center; }
#hint { position: absolute; left: var(--s2); bottom: 112px; font-size: 12px; background: rgba(42, 33, 24, 0.78); color: #fff; padding: 4px 8px; margin: 0; max-width: 70vw; pointer-events: none; }
#joy { position: absolute; left: var(--s3); bottom: 176px; width: 120px; height: 120px; border: 3px solid var(--line); background: rgba(247, 240, 225, 0.55); touch-action: none; }
#joyKnob { position: absolute; left: 36px; top: 36px; width: 48px; height: 48px; background: var(--paper); border: 3px solid var(--line); box-shadow: 3px 3px 0 var(--line); }

/* ── 방명록 ── */
dialog { border: 0; padding: 0; background: none; max-width: 100vw; max-height: 100dvh; color: var(--ink); }
dialog::backdrop { background: rgba(30, 24, 18, 0.55); }
.bookwrap { width: min(920px, 100vw - 24px); max-height: calc(100dvh - 24px); display: flex; flex-direction: column; background: var(--paper); border: 3px solid var(--line); box-shadow: 6px 6px 0 var(--line); padding: var(--s3); }
.bookwrap header { display: flex; justify-content: space-between; align-items: center; margin-bottom: var(--s2); }
.bookcols { display: grid; grid-template-columns: 320px 1fr; gap: var(--s3); min-height: 0; overflow: hidden; }
#entryForm { margin: 0; overflow-y: auto; padding: 0 4px 4px 0; }
#entryForm .field:first-child { margin-top: 0; }
#entryForm small { display: block; text-align: right; margin-top: 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: var(--s1); }
.chips button { font: inherit; font-size: 12px; min-height: 32px; padding: 2px 8px; background: var(--paper-2); border: 2px solid var(--line); cursor: pointer; color: var(--ink); }
.chips button:hover { background: var(--accent); color: var(--accent-ink); }
.listwrap { min-height: 0; display: flex; flex-direction: column; }
.listwrap h3 { margin-bottom: var(--s1); }
#entryList { list-style: none; margin: 0; padding: 0 4px 4px 0; overflow-y: auto; display: flex; flex-direction: column; gap: var(--s2); max-height: 60dvh; }
#entryList li { display: grid; grid-template-columns: 40px 1fr; gap: var(--s2); padding: var(--s2); background: #fffdf6; border: 3px solid var(--line); }
#entryList img { width: 40px; height: 40px; image-rendering: pixelated; border: 2px solid var(--line); }
#entryList .who { font-weight: 700; }
#entryList .side { font-size: 12px; margin-left: 6px; background: var(--ink); color: var(--paper); padding: 0 6px; }
#entryList .when { font-size: 12px; color: var(--ink-soft); margin-left: 6px; }
#entryList .msg { margin-top: 4px; white-space: pre-wrap; word-break: break-all; }
#entryList .none { grid-template-columns: 1fr; color: var(--ink-soft); text-align: center; border-style: dashed; }
.bookwrap footer { display: flex; justify-content: flex-end; margin-top: var(--s2); }

#toast { position: fixed; left: 50%; bottom: 32px; transform: translate(-50%, 16px); opacity: 0; z-index: 20; background: var(--ink); color: var(--paper); padding: 8px var(--s2); border: 3px solid var(--paper); transition: opacity 200ms ease-out, transform 200ms ease-out; pointer-events: none; max-width: 90vw; }
#toast.on { opacity: 1; transform: translate(-50%, 0); }

/* ── 모바일 ── */
@media (max-width: 900px) {
  .screen { padding: var(--s1); align-items: flex-start; }
  .panel { padding: var(--s3); align-self: flex-start; box-shadow: 4px 4px 0 var(--line); }
  h1 { font-size: var(--t2); }
  .workshop { grid-template-columns: 1fr; gap: var(--s3); }
  .col-preview { min-height: 0; order: -1; flex-direction: row; gap: var(--s3); justify-content: center; padding: var(--s2); }
  #preview { width: 80px; height: 160px; }
  .cropbox { width: 100%; max-width: 280px; height: auto; aspect-ratio: 1; margin: 0 auto; }
  .bookcols { grid-template-columns: 1fr; overflow-y: auto; }
  .listwrap { padding-top: var(--s2); border-top: 3px dashed var(--ink-soft); }
  #entryList { max-height: none; overflow: visible; }
  #entryForm { overflow: visible; }
  .hud-title { max-width: 44vw; }
}
@media (max-width: 480px) {
  .row { grid-template-columns: 1fr; }
  .btn { padding: 8px 12px; }
}
@media (prefers-reduced-motion: reduce) {
  .btn, #toast { transition: none; }
}

/* ── 체크박스 / 건설 / 미니맵 / 이동 메뉴 ── */
.check { display: flex; gap: var(--s1); align-items: flex-start; margin-top: var(--s2); font-size: 14px; color: var(--ink-soft); cursor: pointer; }
.check input { width: 24px; height: 24px; flex: none; margin: 2px 0 0; accent-color: var(--accent); cursor: pointer; }
.check span { line-height: 1.5; }
.check em { font-style: normal; opacity: 0.7; }

#minimap { position: absolute; left: var(--s2); top: calc(max(var(--s2), env(safe-area-inset-top)) + 92px); width: 140px; height: 140px; border: 3px solid var(--line); box-shadow: 3px 3px 0 var(--line); background: var(--paper); image-rendering: pixelated; pointer-events: none; }
#placesMenu { position: absolute; right: var(--s2); top: calc(max(var(--s2), env(safe-area-inset-top)) + 52px); min-width: 200px; max-height: 60dvh; overflow-y: auto; background: var(--paper); border: 3px solid var(--line); box-shadow: 4px 4px 0 var(--line); padding: 4px; z-index: 5; }
#placesMenu button { display: block; width: 100%; text-align: left; font: inherit; font-size: 15px; color: var(--ink); background: none; border: 0; padding: 8px 12px; min-height: 44px; cursor: pointer; }
#placesMenu button:hover, #placesMenu button:focus-visible { background: var(--accent); color: var(--accent-ink); }
.btn.on { background: var(--ink); color: var(--paper); }

#buildBar { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(max(var(--s2), env(safe-area-inset-bottom)) + 56px); width: min(640px, calc(100vw - 16px)); background: var(--paper); border: 3px solid var(--line); box-shadow: 4px 4px 0 var(--line); padding: var(--s1); }
.bb-top { display: flex; align-items: center; gap: var(--s1); flex-wrap: wrap; margin-bottom: var(--s1); }
.bb-top .btn { min-height: 40px; padding: 4px 12px; box-shadow: 2px 2px 0 var(--line); }
#selName { font-size: 14px; flex: 1; min-width: 56px; }
#bCount { font-size: 12px; color: var(--ink-soft); }
#palette { display: flex; gap: 6px; overflow-x: auto; padding: 4px 2px 6px; scrollbar-width: thin; }
#palette button { flex: none; width: 40px; height: 40px; border: 3px solid var(--line); padding: 0; cursor: pointer; position: relative; }
#palette button.on { outline: 3px solid var(--focus); outline-offset: 2px; }
#palette button span { position: absolute; left: 2px; top: 0; font-size: 10px; color: #fff; text-shadow: 1px 1px 0 #000; }
.building #sayForm, .building #emotes { display: none; }

#touchBtns { position: absolute; right: var(--s2); bottom: 176px; display: flex; flex-direction: column; gap: var(--s1); align-items: flex-end; }
.building #touchBtns { bottom: 250px; }
.btn.round { width: 72px; height: 72px; border-radius: 0; padding: 0; font-size: 14px; }
.btn.round[aria-pressed='true'] { background: var(--accent); color: var(--accent-ink); }

@media (max-width: 600px) {
  .hud-actions { flex-direction: column; align-items: flex-end; }
  .hud-actions .btn { min-height: 40px; padding: 4px 12px; font-size: 14px; }
  #minimap { width: 104px; height: 104px; top: calc(max(var(--s2), env(safe-area-inset-top)) + 88px); }
  #placesMenu { top: calc(max(var(--s2), env(safe-area-inset-top)) + 4px); right: 88px; }
  #demoBanner { top: calc(max(var(--s2), env(safe-area-inset-top)) + 88px + 112px); max-width: 112px; font-size: 10px; }
}

/* ── 앱(PWA): 탭 · 내 행사 · QR · 카메라 · 설치 ── */
html { overscroll-behavior: none; -webkit-tap-highlight-color: transparent; }
.screen { padding-left: max(var(--s3), env(safe-area-inset-left)); padding-right: max(var(--s3), env(safe-area-inset-right)); padding-top: max(var(--s3), env(safe-area-inset-top)); padding-bottom: max(var(--s3), env(safe-area-inset-bottom)); }

.tabs { display: flex; width: 100%; margin-top: var(--s3); }
.tabs button { flex: 1; min-height: 44px; font-size: var(--t0); }
.tabs b { font-weight: 700; margin-left: 2px; }
#myEvents { margin-top: var(--s3); }
#eventList { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--s2); }
#eventList li { background: #fffdf6; border: 3px solid var(--line); padding: var(--s2); box-shadow: 3px 3px 0 var(--line); }
#eventList .ev-top { display: flex; align-items: center; gap: var(--s1); flex-wrap: wrap; }
#eventList .ev-title { font-weight: 700; font-size: var(--t1); line-height: 1.25; word-break: keep-all; }
#eventList .ev-meta { font-size: 13px; color: var(--ink-soft); margin-top: 2px; }
#eventList .chip { font-size: 12px; background: var(--ink); color: var(--paper); padding: 0 6px; }
#eventList .chip.host { background: var(--accent); color: var(--accent-ink); }
#eventList .ev-actions { display: flex; gap: var(--s1); flex-wrap: wrap; margin-top: var(--s2); }
#eventList .btn { min-height: 40px; padding: 4px 12px; font-size: 14px; box-shadow: 2px 2px 0 var(--line); }
#eventList .btn.primary { flex: 1; }
#installBox { margin-top: var(--s2); }
#installBox .btn { margin-top: 0; }

.qrwrap, .camwrap { width: min(440px, 100vw - 24px); align-items: stretch; }
.qrwrap #qrCanvas { width: min(320px, 100%); height: auto; aspect-ratio: 1; image-rendering: pixelated; align-self: center; border: 3px solid var(--line); background: #fff; }
.qrtitle { text-align: center; font-weight: 700; margin-top: var(--s1); word-break: keep-all; }
.qrwrap .btnrow { justify-content: center; }
.camview { position: relative; align-self: center; width: min(360px, 100%); aspect-ratio: 1; border: 3px solid var(--line); background: #1e1a16; overflow: hidden; }
.camview video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.camguide { position: absolute; inset: 14%; border: 3px dashed rgba(255, 255, 255, 0.85); border-radius: 50%; pointer-events: none; box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.28); }
.camwrap .lead { max-width: none; text-align: center; }

/* 설치된 앱으로 열렸을 때는 설치 안내를 숨기고, 상태 표시줄 영역을 비운다 */
@media (display-mode: standalone) {
  #installBox { display: none !important; }
  body { -webkit-user-select: none; user-select: none; }
  input, textarea { -webkit-user-select: text; user-select: text; }
}

/* 성능 진단 표시: 제목을 길게 누르면 켜고 끈다 */
#fpsBox { position: absolute; left: var(--s2); bottom: 112px; background: rgba(0, 0, 0, 0.72); color: #7dffb0; font: 12px/1.4 monospace; padding: 2px 8px; z-index: 6; pointer-events: none; }

/* 게임 화면에서는 글자 선택·길게 누르기 메뉴(복사/번역)·이미지 롱프레스를 끈다. 입력칸만 예외 */
html, body, #stage, #hud, .screen, .panel, button, dialog {
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
input, textarea { -webkit-user-select: text; user-select: text; }
#fpsBox { bottom: calc(max(var(--s2), env(safe-area-inset-bottom)) + 200px); }

/* ── 입장자 목록 ── */
.who-btn { all: unset; box-sizing: border-box; font-size: 12px; color: var(--ink-soft); cursor: pointer; min-height: 22px; display: flex; align-items: center; text-decoration: underline dotted; -webkit-user-select: none; user-select: none; }
.who-btn:focus-visible { outline: 3px solid var(--focus); }
#whoPanel { position: absolute; left: var(--s2); top: calc(max(var(--s2), env(safe-area-inset-top)) + 62px); width: min(260px, 68vw); max-height: 50dvh; overflow-y: auto; background: var(--paper); border: 3px solid var(--line); box-shadow: 4px 4px 0 var(--line); padding: var(--s1); z-index: 6; }
#whoPanel p { margin: 0 0 4px; font-weight: 700; font-size: 14px; }
#whoList { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
#whoList li { display: grid; grid-template-columns: 28px 1fr auto; gap: 8px; align-items: center; min-height: 32px; font-size: 14px; }
#whoList img, #whoList i { width: 28px; height: 28px; image-rendering: pixelated; border: 2px solid var(--line); background: var(--paper-2); }
#whoList span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#whoList em { font-style: normal; font-size: 11px; color: var(--ink-soft); }

/* ── 건설 중 버튼 겹침 정리 ──
   건설 바는 맨 아래에 붙이고(말하기 줄은 건설 중 숨겨져 있다), 그 높이(--bb) 위로 다른 조작 버튼을 올린다 */
#hud { --bb: 0px; }
#buildBar { bottom: max(var(--s1), env(safe-area-inset-bottom)); }
.building #joy { bottom: calc(var(--bb) + 12px); }
.building #touchBtns { bottom: calc(var(--bb) + 12px); }
.building #prompt { bottom: calc(var(--bb) + 12px); }
.building #hint, .building #fpsBox { bottom: calc(var(--bb) + 12px); }
.building #hint { display: none; }
#palette button { width: 34px; height: 34px; }
.bb-top .btn { min-height: 36px; }
@media (max-width: 600px) {
  .bb-top { gap: 6px; margin-bottom: 4px; }
  #selName { flex-basis: 100%; order: 5; }
  #buildBar { padding: 6px; }
}
/* 낮은 화면(가로로 든 폰): 둥근 버튼을 줄이고 가로로 늘어놓는다 */
@media (max-height: 520px) {
  .btn.round { width: 56px; height: 56px; font-size: 12px; }
  #touchBtns { flex-direction: row; align-items: flex-end; }
  #joy { width: 96px; height: 96px; }
  #joyKnob { left: 24px; top: 24px; }
}

.legal { font-size: 12px; margin: var(--s2) 0 0; color: var(--ink-soft); }
.legal a { color: inherit; }

/* ── 이동 속도 조절 ── */
#touchBtns { position: absolute; }
#btnSpeed { font-size: 12px; line-height: 1.2; }
#btnSpeed b { font-size: 14px; }
#speedPop { position: absolute; right: calc(100% + var(--s1)); top: 0; width: min(220px, 62vw); background: var(--paper); border: 3px solid var(--line); box-shadow: 4px 4px 0 var(--line); padding: var(--s1) var(--s2); z-index: 5; }
#speedPop label { display: block; font-size: 14px; }
#speedPop input[type=range] { width: 100%; min-height: 44px; margin: 0; accent-color: var(--accent); }
.speedmarks { display: flex; justify-content: space-between; align-items: center; font-size: 11px; color: var(--ink-soft); }
.speedmarks .btn { min-height: 32px; padding: 0 10px; font-size: 12px; box-shadow: 2px 2px 0 var(--line); }

/* ── 우리 스타일: 둥근 모서리 + 부드러운 그림자 (건설 UI) ── */
#buildBar { border-radius: 18px; box-shadow: 0 6px 18px rgba(42, 33, 24, 0.28); border-width: 2px; }
#palette { gap: 8px; padding: 6px 4px 8px; }
#palette button { width: 36px; height: 36px; border-radius: 12px; border: 2px solid rgba(42, 33, 24, 0.55); box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.14), inset 0 3px 0 rgba(255, 255, 255, 0.3); transition: transform 120ms ease-out; }
#palette button.on { outline: none; transform: translateY(-3px) scale(1.12); border-color: var(--ink); box-shadow: 0 0 0 3px var(--accent), 0 4px 8px rgba(42, 33, 24, 0.3); }
.bb-top .btn, .bb-top .seg, .bb-top .seg button { border-radius: 12px; }
.bb-top .btn { box-shadow: 0 2px 0 var(--line); }
@media (prefers-reduced-motion: reduce) { #palette button { transition: none; } }

/* 아이폰 확대 방지: 입력칸은 항상 16px 이상, 두 번 탭·핀치 확대 끄기 */
input, textarea, select { font-size: max(16px, 1em); }
html, body { touch-action: manipulation; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

/* 게임 화면은 손가락 동작을 직접 처리한다 (한 손가락 시점 돌리기, 두 손가락 확대·축소) */
#stage { touch-action: none; }

/* 둥근 버튼이 많아지면 한 줄로 길게 늘이지 않고 두 줄로 나눠 위쪽 버튼과 겹치지 않게 한다 */
#touchBtns { flex-wrap: wrap-reverse; align-content: flex-end; justify-content: flex-start; max-height: min(330px, 42vh); max-width: 160px; }
#btnGaze { font-size: 12px; line-height: 1.2; }
#btnGaze b { font-size: 14px; }
#btnGaze[aria-pressed='true'] { background: var(--accent); color: var(--accent-ink); }

/* 3D 미리보기 */
#preview3d { width: 180px; height: 330px; display: block; }
.col-preview .chips, #exprs { display: flex; flex-wrap: wrap; gap: 6px; }
#exprs button { font: inherit; font-size: 12px; min-height: 32px; padding: 2px 8px; background: var(--paper-2); border: 2px solid var(--line); cursor: pointer; color: var(--ink); }
#exprs button.on { background: var(--ink); color: var(--paper); }
@media (max-width: 900px) { #preview3d { width: 110px; height: 200px; } }

/* 입장 화면: 칩 목록 */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { font: inherit; font-size: 12px; min-height: 34px; padding: 2px 9px; background: var(--paper-2); border: 2px solid var(--line); cursor: pointer; color: var(--ink); }
.chips button.on { background: var(--ink); color: var(--paper); }
.opt.blockopt { flex-direction: column; align-items: stretch; }
.opt.blockopt .lbl { width: auto; }
details.more { margin: 4px 0 var(--s2); }
details.more > summary { cursor: pointer; font-size: 14px; color: var(--ink-soft); min-height: 36px; display: flex; align-items: center; }
.swatches button { border-radius: 6px; }
