:root {
  --bg: #f6f6f4; --panel: #ffffff; --text: #1f2937; --muted: #6b7280; --line: #e5e7eb;
  --accent: #facc15; --accent-ink: #1f2937; --me: #1f2937; --me-ink: #ffffff;
  --tool: #f1f5f9; --tool-ink: #475569; --err: #b91c1c; --ok: #15803d;
  --safe-b: env(safe-area-inset-bottom); --safe-t: env(safe-area-inset-top);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111318; --panel: #1a1d24; --text: #e5e7eb; --muted: #9ca3af; --line: #2a2f3a;
    --me: #facc15; --me-ink: #111318; --tool: #20242d; --tool-ink: #a3adbd; --err: #f87171; --ok: #4ade80;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Segoe UI", sans-serif; }
#app { height: 100dvh; max-width: 760px; margin: 0 auto; }
.screen { height: 100%; display: flex; flex-direction: column; }
[hidden] { display: none !important; }
h1 { font-size: 18px; margin: 0; } h2 { font-size: 18px; margin: 0 0 12px; }
.muted { color: var(--muted); } .small { font-size: 13px; } .center { text-align: center; }
.err { color: var(--err); min-height: 1.5em; }
button { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--text);
  border-radius: 10px; padding: 10px 14px; cursor: pointer; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
button.small { padding: 6px 12px; font-size: 14px; }
button.icon { border: 0; background: none; font-size: 30px; line-height: 1; padding: 0 8px 0 0; }
input, select, textarea { font: inherit; width: 100%; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 10px; background: var(--panel); color: var(--text); }

.bar { display: flex; align-items: center; gap: 10px; padding: calc(10px + var(--safe-t)) 16px 10px;
  background: var(--panel); border-bottom: 1px solid var(--line); }
.bar h1 { flex: 1; }
.title-wrap { flex: 1; min-width: 0; }
.title-wrap h1 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* 짝짓기 */
.pair-box { margin: auto; width: 100%; max-width: 360px; padding: 24px 16px; text-align: center; }
.pair-icon { width: 72px; height: 72px; border-radius: 18px; }
.pair-box form { display: grid; gap: 10px; margin-top: 16px; }
#pair-code { text-align: center; font-size: 24px; letter-spacing: 4px; }

/* 기기·목록 */
.devices { display: flex; gap: 8px; padding: 12px 16px 4px; flex-wrap: wrap; }
.dev { font-size: 13px; padding: 4px 10px; border-radius: 99px; background: var(--panel); border: 1px solid var(--line); }
.dev::before { content: "●"; margin-right: 5px; color: var(--muted); }
.dev.on::before { color: var(--ok); }
.threads { list-style: none; margin: 0; padding: 8px 16px; overflow-y: auto; flex: 1; }
.threads li { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px;
  margin-bottom: 8px; cursor: pointer; }
.threads .t { font-weight: 600; } .threads .l { color: var(--muted); font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.threads .meta { color: var(--muted); font-size: 12px; margin-top: 2px; }

dialog { border: 1px solid var(--line); border-radius: 14px; background: var(--panel); color: var(--text);
  width: min(92vw, 420px); padding: 18px; }
dialog::backdrop { background: rgb(0 0 0 / .4); }
dialog label { display: grid; gap: 4px; margin-bottom: 12px; font-size: 14px; color: var(--muted); }
.row { display: flex; gap: 8px; justify-content: flex-end; }

/* 대화 */
.msgs { flex: 1; overflow-y: auto; padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; }
.m { max-width: 88%; padding: 9px 13px; border-radius: 16px; white-space: pre-wrap; word-break: break-word; }
.m.user { align-self: flex-end; background: var(--me); color: var(--me-ink); border-bottom-right-radius: 4px; }
.m.assistant { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.m.tool { align-self: flex-start; background: var(--tool); color: var(--tool-ink); font-size: 13px;
  padding: 5px 10px; border-radius: 8px; max-width: 100%; }
.m.system { align-self: center; color: var(--muted); font-size: 13px; padding: 2px 8px; }
.m.error { align-self: flex-start; color: var(--err); font-size: 14px; }
.m pre { background: rgb(127 127 127 / .12); padding: 8px 10px; border-radius: 8px; overflow-x: auto;
  white-space: pre; font-size: 13px; margin: 6px 0; }
.m code { font-family: ui-monospace, Menlo, monospace; font-size: .9em; }
.m a { color: inherit; }
.typing { align-self: flex-start; color: var(--muted); font-size: 14px; }
.typing::after { content: "…"; animation: blink 1.2s infinite; }
@keyframes blink { 50% { opacity: .2; } }
.composer { display: flex; gap: 8px; padding: 10px 12px calc(10px + var(--safe-b));
  background: var(--panel); border-top: 1px solid var(--line); align-items: flex-end; }
.composer textarea { resize: none; max-height: 40vh; }
.composer button { width: 44px; height: 44px; padding: 0; font-size: 20px; border-radius: 22px; flex: none; }

/* 첨부 */
.m.file { align-self: flex-start; padding: 0; background: none; max-width: 88%; display: grid; gap: 6px; }
.att { display: grid; gap: 4px; }
.att img { max-width: 100%; max-height: 60vh; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); cursor: zoom-in; }
.att-name { text-align: left; font-size: 14px; padding: 6px 10px; }
