:root {
  --panel: rgba(22, 24, 33, 0.82);
  --panel-strong: rgba(22, 24, 33, 0.95);
  --line: rgba(255, 255, 255, 0.12);
  --text: #f2f3f7;
  --muted: #a8adbd;
  --accent: #ff8fb1;
  --accent-2: #8fb8ff;
  --danger: #ff6b6b;
  font-family: "Pretendard", "Malgun Gothic", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: transparent; color: var(--text); user-select: none;
}

#titlebar {
  position: fixed; top: 0; left: 0; right: 0; height: 34px; z-index: 5;
  display: flex; align-items: center; gap: 6px; padding: 0 8px;
  opacity: .45; transition: opacity .2s; cursor: grab;
}
body:hover #titlebar { opacity: 1; }
#title { font-size: 12px; color: var(--muted); background: var(--panel); padding: 3px 8px; border-radius: 99px; }
#status-dot { width: 8px; height: 8px; border-radius: 50%; background: #6ee7a8; box-shadow: 0 0 6px #6ee7a8; }
#status-dot.busy { background: #ffd166; box-shadow: 0 0 6px #ffd166; }
#status-dot.off { background: var(--danger); box-shadow: 0 0 6px var(--danger); }
.spacer { flex: 1; }
button.icon {
  width: 26px; height: 26px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); cursor: pointer; font-size: 13px;
}

#stage { position: fixed; inset: 0; width: 100%; height: 100%; cursor: grab; }
#stage:active, #titlebar:active { cursor: grabbing; }
#drop-hint {
  position: fixed; inset: 40px 16px 80px; display: grid; place-items: center;
  border: 2px dashed var(--accent); border-radius: 18px; background: rgba(0,0,0,.4); font-size: 15px;
}

#bubble {
  position: fixed; left: 14px; right: 14px; bottom: 74px; z-index: 3;
  max-height: 38%; overflow-y: auto; padding: 12px 14px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  backdrop-filter: blur(10px); line-height: 1.55; font-size: 14.5px; user-select: text;
  animation: pop .18s ease-out;
}
#bubble::after {
  content: ""; position: absolute; top: -8px; left: 50%; width: 14px; height: 14px;
  background: var(--panel); border-left: 1px solid var(--line); border-top: 1px solid var(--line);
  transform: translateX(-50%) rotate(45deg);
}
#tool-line { font-size: 12px; color: var(--accent-2); margin-bottom: 4px; }
#tool-line::before { content: "⚙ "; }
#you {
  position: fixed; right: 14px; bottom: 74px; max-width: 75%; z-index: 2;
  padding: 7px 12px; border-radius: 14px 14px 4px 14px;
  background: rgba(143, 184, 255, 0.85); color: #0d1424; font-size: 13.5px;
}
#bubble:not([hidden]) ~ #you { display: none; }
#notice {
  position: fixed; left: 14px; right: 14px; top: 42px; z-index: 4; font-size: 12.5px;
  padding: 8px 12px; border-radius: 12px; background: var(--panel-strong); color: var(--muted);
  border: 1px solid var(--line);
}
#notice.error { color: #ffc2c2; border-color: rgba(255,107,107,.5); }

#composer {
  position: fixed; left: 10px; right: 10px; bottom: 12px; height: 50px; z-index: 4;
  display: flex; gap: 6px; align-items: center; padding: 6px;
  background: var(--panel-strong); border: 1px solid var(--line); border-radius: 99px;
}
#composer input {
  flex: 1; min-width: 0; height: 100%; border: 0; outline: 0; background: transparent;
  color: var(--text); font: inherit; font-size: 14px; padding: 0 6px; user-select: text;
}
#composer button {
  flex: none; width: 38px; height: 38px; border-radius: 50%; border: 0; cursor: pointer;
  background: rgba(255,255,255,.08); color: var(--text); font-size: 16px;
}
#btn-send { background: var(--accent); color: #2a0b16; }
button.icon.off { opacity: .55; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-cat { flex-basis: 100%; font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.chips:empty::before { content: "아직 없어요. .vrma 파일을 창에 끌어다 놓거나 추가 버튼을 누르세요."; font-size: 12px; color: var(--muted); }
.card .chips button { padding: 4px 10px; font-size: 12px; font-weight: 500; border-radius: 99px; background: rgba(143,184,255,.18); color: var(--text); }
#btn-mic.listening { background: var(--danger); animation: pulse 1s infinite; }
#btn-mic.thinking { background: #ffd166; color: #2b2000; }

.overlay {
  position: fixed; inset: 0; z-index: 10; display: grid; place-items: center;
  background: rgba(0, 0, 0, 0.45); padding: 14px;
}
.overlay[hidden], [hidden] { display: none !important; }
.card {
  width: 100%; max-height: 100%; overflow-y: auto; padding: 16px;
  background: var(--panel-strong); border: 1px solid var(--line); border-radius: 16px;
  display: flex; flex-direction: column; gap: 10px;
}
.card h3 { margin: 0 0 2px; font-size: 16px; }
.card p { margin: 0; color: var(--muted); font-size: 13px; }
.card pre {
  margin: 0; padding: 10px; border-radius: 10px; background: rgba(0,0,0,.4); font-size: 12px;
  white-space: pre-wrap; word-break: break-all; max-height: 180px; overflow-y: auto; user-select: text;
}
.card label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); }
.card small { color: var(--accent-2); }
.card input, .card textarea, .card select {
  font: inherit; font-size: 13.5px; color: var(--text); background: rgba(255,255,255,.06);
  border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; outline: 0; user-select: text;
}
.card select option { background: #1b1d27; }
.card .row { display: flex; gap: 8px; align-items: center; }
.card .row select { flex: 1; min-width: 0; }
.card #btn-preview { flex: none; padding: 8px 12px; }
.card button {
  font: inherit; font-size: 13px; padding: 8px 14px; border-radius: 10px; border: 0; cursor: pointer;
  background: var(--accent); color: #2a0b16; font-weight: 600;
}
.card button.ghost { background: rgba(255,255,255,.08); color: var(--text); font-weight: 500; }
.card button.danger { color: #ffb3b3; }

@keyframes pop { from { transform: translateY(6px); opacity: 0; } }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(255,107,107,.25); } }

/* 꾸미기 패널: 캐릭터가 보이게 아래쪽에만 */
#wardrobe { position: fixed; left: 10px; right: 10px; bottom: 12px; z-index: 6; max-height: 56%; display: flex; }
#wardrobe .card { max-height: 100%; gap: 8px; padding: 12px 14px; }
#wardrobe .card h3 { margin: 0; }
#wardrobe .card button { padding: 6px 10px; font-size: 12.5px; }
/* 광택 슬라이더: 채운 막대가 손잡이 가운데까지 딱 맞게 (100%면 끝까지 꽉 참) */
#wardrobe #gloss {
  -webkit-appearance: none; appearance: none; width: 100%; height: 6px; margin: 8px 0; border-radius: 99px; outline: none;
  background: linear-gradient(to right, var(--accent) 0 var(--fill, 0%), rgba(255,255,255,.15) var(--fill, 0%) 100%);
}
#wardrobe #gloss::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; border: 3px solid var(--accent); box-shadow: 0 1px 3px rgba(0,0,0,.4); cursor: pointer;
}
#wardrobe #cloth-row, #wardrobe #layer-row, #wardrobe #gloss-row, #wardrobe #slot-row { display: flex; flex-direction: column; gap: 6px; }
#wardrobe label { flex-direction: row; align-items: baseline; gap: 6px; }
#wardrobe #outfit-row { align-items: center; }
#wardrobe #outfit-row select { flex: 1; min-width: 0; }
.card .chips.toggles button:disabled { opacity: .45; cursor: not-allowed; }
.chips.toggles:empty::before { content: none; }
.card .chips.toggles button { background: rgba(255,255,255,.08); color: var(--muted); }
.card .chips.toggles button.on { background: rgba(255,143,177,.85); color: #2a0b16; }

#eleven-box, #azure-box { display: flex; flex-direction: column; gap: 8px; font-size: 12.5px; color: var(--muted); }
#eleven-box[open], #azure-box[open] { padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; }
#eleven-box summary, #azure-box summary { cursor: pointer; }
#eleven-box label, #azure-box label { margin-top: 6px; }
#voice-error { color: #ffb3b3; }

/* 설정: 접어 둔 모션 목록 */
#motion-box { display: flex; flex-direction: column; gap: 8px; font-size: 12.5px; color: var(--muted); padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; }
#motion-box summary { cursor: pointer; }
#motion-box[open] summary { margin-bottom: 4px; }

#wardrobe .card .row button { white-space: nowrap; }
#wardrobe .card h3 { white-space: nowrap; }

/* ── 옆 패널: 설정·꾸미기를 캐릭터 옆에 붙인다 (창이 그만큼 넓어지고, 캐릭터 쪽은 그대로) ── */
:root { --ml: 0px; --mr: 0px; --pw: 340px; }
body.dock-left { --ml: var(--pw); }
body.dock-right { --mr: var(--pw); }
#titlebar { left: var(--ml); right: var(--mr); }
#stage { left: var(--ml); right: var(--mr); width: calc(100% - var(--ml) - var(--mr)); }
#drop-hint { left: calc(16px + var(--ml)); right: calc(16px + var(--mr)); }
#bubble { left: calc(14px + var(--ml)); right: calc(14px + var(--mr)); }
#you { right: calc(14px + var(--mr)); }
#notice { left: calc(14px + var(--ml)); right: calc(14px + var(--mr)); }
#composer { left: calc(10px + var(--ml)); right: calc(10px + var(--mr)); }
body.dock-left #settings, body.dock-left #wardrobe,
body.dock-right #settings, body.dock-right #wardrobe {
  position: fixed; top: 0; bottom: 0; width: var(--pw); max-height: none; z-index: 10;
  display: flex; padding: 8px; background: transparent; place-items: stretch;
}
body.dock-left #settings, body.dock-left #wardrobe { left: 0; right: auto; }
body.dock-right #settings, body.dock-right #wardrobe { right: 0; left: auto; }
body.dock-left #settings > .card, body.dock-left #wardrobe > .card,
body.dock-right #settings > .card, body.dock-right #wardrobe > .card { height: 100%; max-height: 100%; }
/* 옆 패널은 폭이 좁아서 꾸미기 위쪽 버튼이 줄을 넘기게 */
#wardrobe .card { overflow-x: hidden; }
#wardrobe .card > .row:first-child { flex-wrap: wrap; row-gap: 6px; }

/* ── 대화 기록 · 기억 패널 ── */
#history { position: fixed; left: 10px; right: 10px; bottom: 12px; top: 44px; z-index: 6; display: flex; }
#history .card { gap: 8px; padding: 12px 14px; height: 100%; overflow: hidden; }
#history .card > .row { flex: none; }
#history .card button { padding: 6px 10px; font-size: 12.5px; white-space: nowrap; }
#history-search { flex: none; }
#history-list {
  flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 6px;
  padding-right: 4px; user-select: text;
}
#history-list .day { align-self: center; font-size: 11.5px; color: var(--muted); padding: 6px 0 2px; }
#history-list .msg { max-width: 88%; padding: 7px 11px; font-size: 13.5px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; }
#history-list .msg.user { align-self: flex-end; background: rgba(143, 184, 255, 0.85); color: #0d1424; border-radius: 14px 14px 4px 14px; }
#history-list .msg.assistant { align-self: flex-start; background: rgba(255, 255, 255, 0.08); border: 1px solid var(--line); border-radius: 14px 14px 14px 4px; }
#history-list .msg time { display: block; font-size: 10.5px; opacity: 0.6; margin-top: 2px; }
#history-list .msg mark { background: #ffd166; color: #2b2000; border-radius: 3px; }
#history-list .empty { color: var(--muted); font-size: 13px; text-align: center; margin-top: 30px; }
#notes-box { flex: none; max-height: 38%; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 12px; }
#notes-list { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 4px; }
#notes-list li { display: flex; gap: 6px; align-items: baseline; font-size: 13px; user-select: text; }
#notes-list li span { flex: 1; }
#notes-list li button { padding: 0 6px !important; background: transparent; color: var(--muted); }
#history-info { color: var(--muted); font-size: 11.5px; }
body.dock-left #history, body.dock-right #history {
  position: fixed; top: 0; bottom: 0; width: var(--pw); z-index: 10; display: flex; padding: 8px;
}
body.dock-left #history { left: 0; right: auto; }
body.dock-right #history { right: 0; left: auto; }
/* 말풍선: 누르면 기록이 열린다 */
#bubble { cursor: pointer; }
#bubble .more { display: block; margin-top: 4px; font-size: 11px; color: var(--muted); }
#btn-close:hover { background: var(--danger); color: #fff; }

/* ── 폰 브라우저 (web-shim.js가 html에 .web을 붙인다) ── */
#mobile-box { display: flex; flex-direction: column; gap: 6px; }
#mobile-box label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
#mobile-box input[type=checkbox] { width: auto; }
#mobile-info { font-size: 12px; color: var(--muted); line-height: 1.5; user-select: text; }
#mobile-info code { display: block; color: var(--accent-2); font-size: 13px; word-break: break-all; margin: 2px 0; }
html.web, html.web body { height: 100dvh; background: radial-gradient(120% 80% at 50% 30%, #2a2f45 0%, #161821 70%); }
html.web #stage { touch-action: none; }
html.web #titlebar { opacity: 1; top: env(safe-area-inset-top); height: 42px; cursor: default; }
html.web button.icon { width: 34px; height: 34px; font-size: 15px; }
html.web #btn-hide, html.web #btn-close, html.web #btn-quit, html.web #btn-shortcuts,
html.web #btn-motion-folder, html.web #history-folder, html.web .pc-only { display: none !important; }
html.web.insecure #btn-mic { display: none; }
html.web #composer { bottom: calc(12px + env(safe-area-inset-bottom)); }
html.web #composer input, html.web .card input, html.web .card textarea, html.web .card select { font-size: 16px; } /* 아이폰 자동 확대 방지 */
html.web #settings, html.web #wardrobe { max-height: 75%; }
html.web #history { top: calc(50px + env(safe-area-inset-top)); }
#web-banner { position: fixed; top: calc(50px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); z-index: 20;
  background: var(--danger); color: #fff; padding: 6px 12px; border-radius: 99px; font-size: 13px; }
/* API 키는 PC에서만 넣는다 (폰에서 보내도 서버가 버린다) */
html.web .card label:has(> input[type=password]) { display: none; }

/* ── 아이폰 웹앱 전용 (web/build.mjs가 style.css 뒤에 붙인다) ── */
html.web.standalone .card label:has(> input[type=password]) { display: flex; }
html.web.standalone #btn-mic { display: none; } /* 받아쓰기는 키보드의 🎤 */
html.web.standalone #btn-vrm-clear { display: none; }
#pack-box { display: flex; flex-direction: column; gap: 6px; }
#pack-box small { color: var(--muted); }
#welcome .card { max-width: 340px; }
#welcome p { line-height: 1.5; }
#welcome .pack-state { display: block; margin-top: 8px; color: var(--muted); }
