/* ============================================================
   AI 친구들 — 프리미엄 다크 챗 UI
   Linear / Vercel / ChatGPT 감성의 세련된 미니멀 다크 톤
   ============================================================ */

:root {
  --bg: #0b0b10;
  --bg-elevated: #121218;
  --sidebar: #101016;
  --panel: #17171e;
  --panel-2: #1e1e27;
  --panel-3: #23232e;
  --line: rgba(255, 255, 255, 0.07);
  --line-strong: rgba(255, 255, 255, 0.12);
  --text: #f2f2f7;
  --text-secondary: #c6c6d1;
  --muted: #8a8a98;
  --faint: #5f5f6d;

  --accent: #6e79d6;
  --accent-2: #8b5cf6;
  --accent-3: #a78bfa;
  --accent-soft: rgba(110, 121, 214, 0.16);
  --accent-ring: rgba(139, 92, 246, 0.35);
  --grad: linear-gradient(135deg, #6e79d6 0%, #8b5cf6 100%);
  --grad-soft: linear-gradient(135deg, rgba(110, 121, 214, 0.16), rgba(139, 92, 246, 0.16));

  --green: #4ade80;
  --danger: #f87171;

  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 10px;
  --radius-xl: 12px;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 20px 50px rgba(0, 0, 0, 0.5);

  --font: "Inter", "Noto Sans KR", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(139, 92, 246, 0.08), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(110, 121, 214, 0.06), transparent 55%),
    var(--bg);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

button, textarea, input, select {
  font: inherit;
}

button { cursor: pointer; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-ring);
}

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 8px;
}
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.18); }

/* ---------- App shell ---------- */
.app-shell {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  max-width: 1600px;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  margin: auto;
  overflow: hidden;
  background: var(--bg-elevated);
}

/* ---------- Sidebar ---------- */
.sidebar {
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  padding: 28px 18px 20px;
  background: var(--sidebar);
  border-right: 1px solid var(--line);
}

.brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px 6px;
}

.brand-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent-3);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 1.4px;
  text-transform: uppercase;
}

h1, h2, p { margin: 0; }

h1 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.icon-button {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.03);
  font-size: 20px;
  line-height: 1;
  transition: all 0.18s var(--ease);
}
.icon-button:hover {
  color: #fff;
  background: var(--grad);
  border-color: transparent;
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(139, 92, 246, 0.35);
}

.app-install-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.03);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.18s var(--ease);
}
.app-install-btn:hover {
  color: #fff;
  background: var(--grad);
  border-color: transparent;
  box-shadow: 0 4px 14px rgba(139, 92, 246, 0.35);
}
.icon-button:active { transform: translateY(0); }

.profile-card {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 24px 0 26px;
  padding: 12px;
  background: linear-gradient(180deg, rgba(255,255,255,0.04), rgba(255,255,255,0.02));
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
}
.profile-card strong, .profile-card span { display: block; }
.profile-card strong { font-size: 14px; font-weight: 600; color: var(--text); }
.profile-card span:not(.online-dot) { color: var(--muted); font-size: 13px; }

.online-dot {
  width: 8px;
  height: 8px;
  margin-left: auto;
  border-radius: 4px;
  background: var(--green);
  box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.15);
}

.avatar {
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 6px;
  color: #fff;
  background: var(--grad);
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
}
.avatar img, img.avatar { width: 100%; height: 100%; object-fit: cover; }

.user-avatar { background: var(--grad); }

/* Section heading */
.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 8px 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.4px;
  text-transform: uppercase;
}
.section-heading span:last-child {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

/* Room list */
.room-list {
  display: grid;
  gap: 4px;
  margin-bottom: 24px;
}

.room-item {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 11px 12px;
  color: var(--text-secondary);
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  transition: all 0.16s var(--ease);
}
.room-item:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
}
.room-item.active {
  background: var(--accent-soft);
  border-color: rgba(139, 92, 246, 0.22);
  color: var(--text);
  box-shadow: inset 0 0 0 1px rgba(139, 92, 246, 0.08);
}
.room-mark {
  width: 22px;
  flex: 0 0 auto;
  color: var(--accent-3);
  text-align: center;
  font-size: 15px;
}
.room-copy { display: grid; gap: 2px; min-width: 0; }
.room-copy strong {
  font-size: 14px;
  font-weight: 500;
  color: inherit;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.room-copy small { color: var(--muted); font-size: 13px; }
.room-arrow {
  margin-left: auto;
  color: var(--faint);
  font-size: 18px;
  transition: transform 0.16s var(--ease), color 0.16s var(--ease);
}
.room-item:hover .room-arrow { color: var(--muted); transform: translateX(2px); }

/* Character list */
.add-character-btn {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 7px;
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.06);
  font-size: 16px;
  line-height: 1;
  transition: all 0.16s var(--ease);
}
.add-character-btn:hover { color: #fff; background: var(--grad); }

.character-list {
  display: grid;
  gap: 3px;
  max-height: 210px;
  overflow-y: auto;
}

.character-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  transition: all 0.16s var(--ease);
}
.character-item:hover {
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--line);
}
.character-avatar { width: 28px; height: 28px; font-size: 13px; }
.character-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13.5px;
  color: var(--text-secondary);
}
.character-delete {
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 4px;
  color: var(--faint);
  background: transparent;
  font-size: 16px;
  line-height: 1;
  opacity: 0;
  transition: all 0.16s var(--ease);
}
.character-item:hover .character-delete { opacity: 1; }
.character-delete:hover { color: #fff; background: var(--danger); }

.sidebar-footer {
  margin: auto 8px 0;
  padding-top: 16px;
  color: var(--faint);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
}
.sidebar-footer span { color: var(--accent-3); }

/* ---------- Chat panel ---------- */
.chat-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  min-width: 0;
  background:
    radial-gradient(1000px 500px at 100% 0%, rgba(139, 92, 246, 0.05), transparent 55%),
    var(--bg-elevated);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 28px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(18, 18, 24, 0.7);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
.chat-header h2 {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}

.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

/* Delay select */
.delay-select-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.delay-label { color: var(--muted); font-size: 13px; }
.delay-select {
  padding: 2px 4px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
}
.delay-select option { background: var(--panel-2); color: var(--text); }

/* Auto toggle button */
.auto-toggle-btn {
  padding: 7px 13px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.03);
  font-size: 13px;
  font-weight: 500;
  transition: all 0.16s var(--ease);
  white-space: nowrap;
}
.auto-toggle-btn.is-on {
  color: var(--green);
  border-color: rgba(74, 222, 128, 0.35);
  background: rgba(74, 222, 128, 0.1);
}
.auto-toggle-btn.is-on:hover {
  background: rgba(248, 113, 113, 0.14);
  border-color: rgba(248, 113, 113, 0.35);
  color: var(--danger);
}
.auto-toggle-btn:not(.is-on) {
  color: var(--danger);
  border-color: rgba(248, 113, 113, 0.35);
  background: rgba(248, 113, 113, 0.1);
}
.auto-toggle-btn:not(.is-on):hover {
  background: rgba(74, 222, 128, 0.14);
  border-color: rgba(74, 222, 128, 0.35);
  color: var(--green);
}

/* Participant stack */
.participant-stack {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
}
.participant { cursor: pointer; position: relative; transition: transform 0.15s var(--ease); }
.participant:hover { transform: translateY(-2px); }
.participant.banned .tiny-avatar { filter: grayscale(1); opacity: 0.35; }
.participant.banned::after {
  content: "×";
  position: absolute;
  top: -4px;
  right: -4px;
  width: 14px;
  height: 14px;
  display: grid;
  place-items: center;
  border-radius: 4px;
  background: var(--danger);
  color: #fff;
  font-size: 13px;
  line-height: 1;
}
.participant-stack .tiny-avatar {
  margin-left: -8px;
  border: 2px solid var(--bg-elevated);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}
.participant-stack .tiny-avatar:first-child { margin-left: 0; }

.participant-add-wrap { position: relative; }
.participant-add-btn {
  width: 24px;
  height: 24px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border: 2px dashed var(--line-strong);
  border-radius: 4px;
  color: var(--muted);
  background: transparent;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  transition: all 0.16s var(--ease);
}
.participant-add-btn:hover {
  border-color: var(--accent-2);
  color: var(--accent-3);
  background: var(--accent-soft);
}

.participant-dropdown {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  z-index: 100;
  min-width: 210px;
  max-height: 280px;
  overflow-y: auto;
  padding: 6px;
  background: var(--panel-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
}
.participant-dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: background 0.14s var(--ease);
}
.participant-dropdown-item:hover { background: rgba(255, 255, 255, 0.06); }
.participant-dropdown-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}
.participant-dropdown-add { color: var(--accent-3); font-size: 17px; }
.participant-dropdown-empty { padding: 12px 10px; color: var(--muted); font-size: 13px; text-align: center; }

/* TTS toggle button */
.tts-toggle-btn {
  padding: 7px 13px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.03);
  font-size: 13px;
  font-weight: 500;
  transition: all 0.16s var(--ease);
  white-space: nowrap;
}
.tts-toggle-btn.is-on {
  color: var(--accent-3);
  border-color: rgba(139, 92, 246, 0.35);
  background: var(--accent-soft);
}
.tts-toggle-btn.is-on:hover {
  background: rgba(248, 113, 113, 0.14);
  border-color: rgba(248, 113, 113, 0.35);
  color: var(--danger);
}
.tts-toggle-btn.is-off {
  color: var(--muted);
}
.tts-toggle-btn.is-off:hover {
  color: var(--accent-3);
  border-color: rgba(139, 92, 246, 0.35);
  background: var(--accent-soft);
}

/* Header action buttons */
.clear-chat-btn {
  padding: 7px 13px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.03);
  font-size: 13px;
  font-weight: 500;
  transition: all 0.16s var(--ease);
  white-space: nowrap;
}
.clear-chat-btn:hover { color: #fff; background: rgba(248, 113, 113, 0.14); border-color: rgba(248, 113, 113, 0.35); }

.close-room-btn {
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 6px;
  color: var(--text-secondary);
  background: transparent;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  transition: color 0.16s var(--ease), background 0.16s var(--ease);
}
.close-room-btn:hover { color: #fff; background: var(--danger); border-color: transparent; }

/* ---------- Message list ---------- */
.message-list {
  min-height: 0;
  overflow-y: auto;
  padding: 32px 28px;
}

.message-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  max-width: 760px;
  margin-bottom: 20px;
}
.message-row .avatar, .message-row img.avatar {
  width: 34px;
  height: 34px;
  min-width: 34px;
  min-height: 34px;
  flex: 0 0 34px;
  font-size: 13px;
  margin-top: 2px;
}

.message-content { flex: 1; min-width: 0; }

.sender-name {
  display: block;
  margin: 0 0 5px 2px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}

.message-line {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  min-width: 0;
}

.bubble {
  flex: 0 1 auto;
  max-width: 80%;
  min-width: 0;
  padding: 12px 16px;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  border-bottom-left-radius: 4px;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  font-size: 17.5px;
  line-height: 1.55;
  transition: background 0.16s var(--ease);
}

.message-line time {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}

/* My messages */
.mine { justify-content: flex-end; margin-left: auto; }
.mine .message-content { order: -1; }
.mine .sender-name { text-align: right; margin-right: 2px; }
.mine .message-line {
  flex-direction: row-reverse;
  justify-content: flex-end;
}
.mine .bubble {
  color: #fff;
  background: var(--grad);
  border-color: transparent;
  border-radius: 10px;
  border-bottom-right-radius: 4px;
  text-align: left;
  box-shadow: 0 4px 14px rgba(139, 92, 246, 0.25);
}

/* ---------- Composer ---------- */
.composer {
  display: flex;
  gap: 12px;
  align-items: center;
  flex: 0 0 auto;
  margin: 0 28px 28px;
  padding: 10px 12px 10px 16px;
  background: var(--panel-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
  flex-wrap: nowrap;
}
.composer:focus-within {
  border-color: var(--accent-ring);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.14), var(--shadow-md);
}

.composer textarea {
  display: block;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 42px;
  max-height: 140px;
  padding: 10px 6px;
  resize: none;
  color: var(--text);
  background: transparent;
  border: 0;
  outline: 0;
  box-shadow: none;
  font-size: 18px;
  line-height: 1.5;
  vertical-align: middle;
}
.composer textarea:focus,
.composer textarea:focus-visible {
  outline: none;
  border: 0;
  box-shadow: none;
}
.composer textarea::placeholder { color: var(--faint); }

.send-button {
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 12px;
  color: #fff;
  background: var(--grad);
  font-size: 20px;
  line-height: 1;
  box-shadow: 0 4px 14px rgba(139, 92, 246, 0.35);
  transition: all 0.18s var(--ease);
}
.send-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(139, 92, 246, 0.5);
  filter: brightness(1.06);
}
.send-button:active { transform: translateY(0); }

/* ---------- Auth overlay ---------- */
.auth-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  background:
    radial-gradient(1000px 600px at 50% 0%, rgba(139, 92, 246, 0.1), transparent 60%),
    rgba(11, 11, 16, 0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  padding: 44px 40px 40px;
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.auth-card h2 {
  margin-bottom: 8px;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.auth-card form { margin-top: 24px; text-align: left; }

.auth-card input {
  width: 100%;
  padding: 12px 14px;
  margin-bottom: 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 15px;
  transition: border-color 0.18s var(--ease), box-shadow 0.18s var(--ease);
}
.auth-card input:focus {
  outline: none;
  border-color: var(--accent-ring);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.14);
}
.auth-card input::placeholder { color: var(--faint); }

.auth-card button {
  width: 100%;
  padding: 12px;
  margin-top: 6px;
  border: none;
  border-radius: var(--radius-md);
  background: var(--grad);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(139, 92, 246, 0.3);
  transition: all 0.18s var(--ease);
}
.auth-card button:hover { filter: brightness(1.06); transform: translateY(-1px); }
.auth-card button:active { transform: translateY(0); }

.auth-card p {
  margin-top: 22px;
  font-size: 13.5px;
  color: var(--muted);
}
.auth-card span {
  color: var(--accent-3);
  font-weight: 600;
  cursor: pointer;
}
.auth-card span:hover { text-decoration: underline; }

/* ---------- Modals ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  background: rgba(11, 11, 16, 0.7);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 2000;
}

.modal-card {
  width: 100%;
  max-width: 460px;
  padding: 32px;
  background: var(--panel-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}
.modal-card h2 {
  margin-bottom: 22px;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.modal-card input,
.modal-card textarea {
  width: 100%;
  padding: 11px 13px;
  margin-bottom: 13px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  transition: border-color 0.18s var(--ease), box-shadow 0.18s var(--ease);
}
.modal-card input:focus,
.modal-card textarea:focus {
  outline: none;
  border-color: var(--accent-ring);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.14);
}
.modal-card input::placeholder,
.modal-card textarea::placeholder { color: var(--faint); }
.modal-card textarea { resize: vertical; min-height: 100px; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
}
.modal-actions button {
  padding: 10px 20px;
  border: 0;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.16s var(--ease);
}

.primary-btn {
  color: #fff;
  background: var(--grad);
  box-shadow: 0 4px 14px rgba(139, 92, 246, 0.3);
}
.primary-btn:hover { filter: brightness(1.06); transform: translateY(-1px); }
.primary-btn:active { transform: translateY(0); }

.secondary-btn {
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line-strong) !important;
}
.secondary-btn:hover { background: rgba(255, 255, 255, 0.09); color: var(--text); }

/* ---------- Utility ---------- */
.hidden { display: none !important; }

.avatar.tiny-avatar, img.avatar.tiny-avatar {
  width: 26px !important;
  height: 26px !important;
  min-width: 26px;
  min-height: 26px;
  font-size: 13px !important;
  line-height: 1;
}


/* ---------- PWA install banner ---------- */
.pwa-install-banner {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 3000;
  display: flex;
  align-items: center;
  gap: 12px;
  width: min(420px, calc(100vw - 24px));
  padding: 12px 14px;
  background: rgba(23, 23, 30, 0.96);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  animation: pwa-banner-in 0.35s var(--ease);
}
@keyframes pwa-banner-in {
  from { opacity: 0; transform: translate(-50%, 16px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}
.pwa-install-icon {
  flex: 0 0 auto;
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  overflow: hidden;
  background: var(--grad);
  box-shadow: 0 4px 14px rgba(139, 92, 246, 0.35);
}
.pwa-install-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.pwa-install-copy {
  flex: 1 1 auto;
  min-width: 0;
  display: grid;
  gap: 2px;
}
.pwa-install-copy strong {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}
.pwa-install-copy span {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.4;
}
.pwa-install-btn {
  flex: 0 0 auto;
  min-height: 44px;
  padding: 0 18px;
  border: 0;
  border-radius: var(--radius-md);
  color: #fff;
  background: var(--grad);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(139, 92, 246, 0.35);
  transition: all 0.18s var(--ease);
  white-space: nowrap;
}
.pwa-install-btn:hover { filter: brightness(1.06); transform: translateY(-1px); }
.pwa-install-btn:active { transform: translateY(0); }
.pwa-install-close {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  transition: all 0.16s var(--ease);
}
.pwa-install-close:hover { color: #fff; background: rgba(255, 255, 255, 0.08); }

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
  .pwa-install-banner {
    bottom: calc(84px + env(safe-area-inset-bottom));
    width: calc(100vw - 20px);
  }
  .pwa-install-copy strong { font-size: 15px; }
  .pwa-install-copy span { font-size: 13px; }

  .app-shell {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    max-width: 100vw;
    overflow: hidden;
  }

  /* 사이드바 → 상단 브랜드 + 가로 스크롤 채팅방 바 */
  .sidebar {
    flex: 0 0 auto;
    min-height: 0;
    overflow: visible;
    padding: 12px 12px 10px;
    padding-top: calc(12px + env(safe-area-inset-top));
    border-right: 0;
    border-bottom: 1px solid var(--line);
    background: var(--sidebar);
  }
  .brand-row {
    padding: 0 4px 8px;
  }
  .brand-row h1 { font-size: 18px; }
  .profile-card, .section-heading, .sidebar-footer { display: none; }

  /* 채팅방 목록을 가로 스크롤 칩으로 변환 */
  .room-list {
    display: flex;
    gap: 8px;
    margin: 0 -2px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 4px 2px 4px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    scroll-snap-type: x proximity;
  }
  .room-list .room-item { scroll-snap-align: start; }
  .room-list::-webkit-scrollbar { display: none; }
  .room-item {
    flex: 0 0 auto;
    width: auto;
    min-height: 44px;
    gap: 8px;
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--line);
    border-radius: 8px;
    white-space: nowrap;
  }
  .room-item .room-arrow { display: none; }
  .room-item.active {
    background: var(--accent-soft);
    border-color: rgba(139, 92, 246, 0.35);
  }

  /* 캐릭터 목록(사이드바)은 모바일에서 숨김 유지 */
  .character-list { display: none; }

  .chat-panel {
    flex: 1 1 auto;
    height: 100%;
    min-height: 0;
    min-width: 0;
    max-width: 100vw;
    overflow-x: hidden;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
  }

  /* 헤더: 제목 + 액션 2줄 구조, 액션은 가로 스크롤 */
  .chat-header {
    flex-wrap: wrap;
    gap: 10px;
    padding: 12px 14px 10px;
    max-width: 100%;
    box-sizing: border-box;
    overflow-x: hidden;
  }
  .chat-header h2 { font-size: 17px; }
  .chat-header-actions {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    gap: 8px;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    scroll-snap-type: x proximity;
  }
  .chat-header-actions > * { scroll-snap-align: start; }
  .chat-header-actions::-webkit-scrollbar { display: none; }
  .chat-header-actions > * { flex: 0 0 auto; }

  /* 터치 편의: 버튼 최소 44px */
  .auto-toggle-btn,
  .tts-toggle-btn,
  .clear-chat-btn,
  .app-install-btn {
    min-height: 44px;
    padding: 11px 15px;
    font-size: 15px;
    border-radius: 6px;
  }
  .delay-select-wrap {
    min-height: 44px;
    padding: 10px 12px;
  }
  .delay-select { font-size: 15px; }
  .close-room-btn {
    width: 44px;
    height: 44px;
    font-size: 22px;
  }
  .participant-add-btn {
    width: 44px;
    height: 44px;
    font-size: 20px;
  }
  .participant-stack .tiny-avatar { margin-left: -6px; }

  /* 채팅 메시지: 여백 최적화, 말풍선 폭 확대 */
  .message-list { padding: 16px 12px 12px; }
  .message-row { gap: 8px; margin-bottom: 16px; }
  .bubble {
    max-width: 90%;
    padding: 11px 14px;
    font-size: 16.5px;
    line-height: 1.5;
    border-radius: 10px;
  }

  /* 컴포저: 하단 고정감 + safe-area */
  .composer {
    margin: 0 12px 12px;
    margin-bottom: calc(12px + env(safe-area-inset-bottom));
    gap: 6px;
    padding: 8px 8px 8px 14px;
    flex-wrap: nowrap;
    flex: 0 0 auto;
  }
  .composer textarea { font-size: 16px; min-height: 44px; }
  .send-button {
    width: 44px;
    height: 44px;
    min-width: 44px;
    border-radius: 9px;
    font-size: 22px;
  }

  /* 로그인/모달 카드: 모바일 꽉찬 패딩 */
  .auth-card {
    margin: 20px;
    padding: 32px 24px 28px;
    border-radius: 8px;
  }
  .auth-card h2 { font-size: 22px; }
  .auth-card input { font-size: 16px; padding: 14px 16px; }
  .auth-card button { font-size: 16px; padding: 14px; }

  .modal-card {
    margin: 20px;
    padding: 24px 20px;
    border-radius: 8px;
  }
  .modal-card input,
  .modal-card textarea { font-size: 16px; }
  .modal-actions button {
    min-height: 44px;
    font-size: 15px;
    border-radius: 6px;
  }
}

@media (max-width: 380px) {
  .chat-header-actions { gap: 6px; }
  .auto-toggle-btn,
  .tts-toggle-btn,
  .clear-chat-btn { padding: 8px 12px; font-size: 13px; }
  .bubble { max-width: 92%; }
  .delay-label { display: none; }
}

/* Mobile text wrap fix */
.message-row, .message-content, .message-line {
  max-width: 100%;
  min-width: 0;
}
.bubble {
  word-break: break-word;
  overflow-wrap: break-word;
  word-wrap: break-word;
}
.bubble pre, .bubble code {
  white-space: pre-wrap;
  word-break: break-all;
  max-width: 100%;
  overflow-x: auto;
}
