:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --border: #d9dde5;
  --text: #16181d;
  --muted: #6b7280;
  --accent: #2f6df6;
  --accent-text: #ffffff;
  --danger: #c0392b;
  --ok: #1f9d55;
  --bubble-phone: #e8f0ff;
  --bubble-web: #eef0f4;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1e222b;
    --border: #2a2f3a;
    --text: #e8eaf0;
    --muted: #99a1b3;
    --accent: #4b82ff;
    --accent-text: #ffffff;
    --danger: #ef6a5c;
    --ok: #46c48a;
    --bubble-phone: #1d2b47;
    --bubble-web: #23272f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, "Segoe UI", "Malgun Gothic", "Apple SD Gothic Neo",
        Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }

button {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 14px;
  transition: filter .12s ease;
}
button:hover:not(:disabled) { filter: brightness(1.08); }
button:disabled { opacity: .5; cursor: default; }

/* 툴바에서 버튼처럼 보여야 하는 링크 */
.btnlink {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 15px;
  text-decoration: none;
  transition: filter .12s ease;
}
.btnlink:hover { filter: brightness(1.08); }

button.danger {
  color: var(--danger);
  border-color: var(--border);
}

button.primary {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-text);
  font-weight: 600;
}

input, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  width: 100%;
}
input:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

/* ── 페어링 페이지 ─────────────────────────────── */
.pair-wrap {
  max-width: 520px;
  margin: 0 auto;
  padding: 40px 20px 60px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -.01em;
  margin-bottom: 6px;
}
.brand .dot {
  width: 12px; height: 12px; border-radius: 4px;
  background: var(--accent);
}
.tagline { color: var(--muted); margin: 0 0 28px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}

.code {
  font: 700 44px/1.1 ui-monospace, "SFMono-Regular", Consolas, monospace;
  letter-spacing: .18em;
  text-align: center;
  padding: 18px 0 10px;
  user-select: all;
}

.countdown { text-align: center; color: var(--muted); margin-bottom: 18px; }
.countdown.expired { color: var(--danger); }

.steps { margin: 20px 0 0; padding-left: 20px; color: var(--muted); }
.steps li { margin: 6px 0; }

.recent { margin-top: 24px; }
.recent h3 { font-size: 13px; text-transform: uppercase; color: var(--muted);
             letter-spacing: .06em; margin: 0 0 8px; }
.recent a {
  display: block; padding: 10px 12px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--border);
  text-decoration: none; color: var(--text); margin-bottom: 6px;
  font: 13px ui-monospace, Consolas, monospace;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.button-link {
  display: inline-block;
  margin-top: 16px;
  padding: 10px 18px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
  text-decoration: none;
}

.field-label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }

.slug {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  overflow: hidden;
}
.slug:focus-within { outline: 2px solid var(--accent); outline-offset: -1px; }
.slug-prefix {
  display: flex;
  align-items: center;
  padding: 0 2px 0 12px;
  color: var(--muted);
  font: 15px ui-monospace, Consolas, monospace;
  white-space: nowrap;
}
.slug input {
  border: 0;
  border-radius: 0;
  background: transparent;
  padding-left: 0;
  font: 15px ui-monospace, Consolas, monospace;
}
.slug input:focus { outline: none; }

.warn-box {
  margin-top: 16px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

/* ── 아이폰 설정 페이지 ─────────────────────────── */
.roomline {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  font-size: 14px;
  word-break: break-all;
}

.copyrow {
  display: flex;
  align-items: stretch;
  gap: 8px;
}
.copyval {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  font: 13px/1.45 ui-monospace, Consolas, monospace;
  word-break: break-all;
  user-select: all;
}
.copybtn {
  flex: none;
  align-self: stretch;
  padding: 0 16px;
  font-weight: 600;
}

.recipe { margin: 12px 0 0; padding-left: 22px; }
.recipe li { margin: 9px 0; line-height: 1.55; }
.recipe code {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1px 5px;
  font: 13px ui-monospace, Consolas, monospace;
}

.hint { color: var(--muted); font-size: 13px; }
.error { color: var(--danger); }
.center { text-align: center; }
.hidden { display: none !important; }

/* ── 대화창 ────────────────────────────────────── */
.room {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex: none;
  flex-wrap: wrap;
}
.topbar .brand { font-size: 16px; margin: 0; }
.topbar .spacer { flex: 1; }

.status { display: flex; align-items: center; gap: 6px; color: var(--muted);
          font-size: 13px; }
.led { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status.live .led { background: var(--ok); }
.status.down .led { background: var(--danger); }

.toggle { display: flex; align-items: center; gap: 6px; font-size: 13px;
          color: var(--muted); cursor: pointer; user-select: none; }
.toggle input { width: auto; }

.feed {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.empty { margin: auto; text-align: center; color: var(--muted); max-width: 340px; }

.msg { display: flex; flex-direction: column; max-width: min(640px, 86%); }
.msg.from-phone { align-self: flex-start; }
.msg.from-web { align-self: flex-end; align-items: flex-end; }

.bubble {
  background: var(--bubble-phone);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 13px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.msg.from-web .bubble { background: var(--bubble-web); }
.bubble.media { padding: 4px; }

.bubble pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font: inherit;
}
.bubble a.link { word-break: break-all; }

.bubble img, .bubble video {
  display: block;
  max-width: 100%;
  max-height: 46vh;
  border-radius: 10px;
  background: #000;
}
.bubble img { cursor: zoom-in; }
/* 끌어다 놓을 수 있다는 걸 커서로 알린다 */
.bubble[draggable="true"] { cursor: grab; }
.bubble[draggable="true"]:active { cursor: grabbing; }
.bubble.media[draggable="true"] img { cursor: grab; }

.filecard { display: flex; align-items: center; gap: 10px; min-width: 200px; }
.filecard .glyph { font-size: 22px; }
.filecard .fname { font-weight: 600; word-break: break-all; }

.meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 5px;
  font-size: 12px;
  color: var(--muted);
}
.meta button {
  padding: 2px 8px;
  font-size: 12px;
  border-radius: 7px;
  background: transparent;
}
.meta .warn { color: var(--muted); }

.jump {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 92px;
  z-index: 5;
  background: var(--accent);
  color: var(--accent-text);
  border-color: transparent;
  box-shadow: var(--shadow);
}

.composer {
  flex: none;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.composer textarea { resize: none; max-height: 140px; }
.composer button { flex: none; white-space: nowrap; }
.composer #attach {
  width: 40px; padding: 8px 0; font-size: 18px; line-height: 1;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 92px;
  transform: translateX(-50%) translateY(8px);
  background: var(--text);
  color: var(--bg);
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
  z-index: 10;
}
.toast.show { opacity: .95; transform: translateX(-50%) translateY(0); }

.dropzone {
  position: fixed;
  inset: 0;
  background: rgba(47, 109, 246, .12);
  border: 3px dashed var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 600;
  z-index: 20;
}

.progress {
  align-self: center;
  font-size: 13px;
  color: var(--muted);
}

@media (max-width: 520px) {
  .topbar { gap: 8px; padding: 8px 12px; }
  .msg { max-width: 94%; }
}
