:root {
  --bg: #140f0c;
  --bg-raise: #1f1813;
  --bg-raise-2: #2a211b;
  --bg-user: #4a2f1d;
  --bg-ai: #241c16;
  --line: rgba(248, 226, 201, 0.12);
  --text: #f6eee6;
  --muted: #b9a898;
  --accent: #f0a466;
  --accent-deep: #c7783a;
  --accent-soft: rgba(240, 164, 102, 0.16);
  --danger: #e07a5f;
  --ok: #9dbe8f;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  --radius: 22px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --header-h: 72px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Pretendard Variable", Pretendard, "Noto Sans KR", "Apple SD Gothic Neo", sans-serif;
  font-size: 18px;
  line-height: 1.5;
}
body {
  min-height: 100dvh;
  overflow: hidden;
}
button, textarea, input { font: inherit; color: inherit; }
button { border: 0; background: none; cursor: pointer; }
button:disabled { opacity: 0.5; cursor: default; }

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  height: 100svh;
  max-width: 820px;
  margin: 0 auto;
  position: relative;
}

header.app-header {
  flex: 0 0 auto;
  min-height: var(--header-h);
  padding: calc(10px + var(--safe-t)) 12px 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #1a1410 0%, rgba(20, 15, 12, 0.92) 100%);
}
.icon-btn {
  width: 56px;
  height: 56px;
  min-width: 56px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  color: var(--text);
  background: var(--bg-raise);
  border: 1px solid var(--line);
}
.icon-btn:active { transform: scale(0.97); background: var(--bg-raise-2); }
.icon-btn svg { width: 26px; height: 26px; }
.brand {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand img {
  width: 44px;
  height: 44px;
  border-radius: 12px;
}
.brand h1 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.brand p {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}
.empty-hint {
  margin: auto;
  text-align: center;
  color: var(--muted);
  padding: 24px 16px 80px;
  max-width: 28rem;
}
.empty-hint strong {
  display: block;
  color: var(--text);
  font-size: 1.25rem;
  margin: 12px 0 8px;
}
.bubble {
  max-width: 92%;
  padding: 14px 16px;
  border-radius: 20px;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.55;
}
.bubble.user {
  align-self: flex-end;
  background: var(--bg-user);
  border-bottom-right-radius: 6px;
}
.bubble.ai {
  align-self: flex-start;
  background: var(--bg-ai);
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
}
.bubble.pending { color: var(--muted); }
.bubble.error { border-color: rgba(224, 122, 95, 0.4); color: #ffc9bb; }

.composer {
  flex: 0 0 auto;
  padding: 10px 12px calc(12px + var(--safe-b));
  border-top: 1px solid var(--line);
  background: #17120e;
}
.transcript {
  display: none;
  margin: 0 4px 10px;
  padding: 12px 14px;
  border-radius: 16px;
  background: var(--accent-soft);
  color: var(--accent);
  min-height: 24px;
}
.transcript.on { display: block; }
.row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}
textarea#input {
  flex: 1;
  min-height: 56px;
  max-height: 160px;
  resize: none;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: var(--bg-raise);
  padding: 14px 16px;
  outline: none;
}
textarea#input:focus { border-color: var(--accent-deep); }
.mic-btn {
  width: 72px;
  height: 72px;
  min-width: 72px;
  border-radius: 50%;
  background: linear-gradient(180deg, #f3b27a 0%, #d4843c 100%);
  color: #2a160b;
  box-shadow: 0 8px 20px rgba(212, 132, 60, 0.35);
  display: grid;
  place-items: center;
}
.mic-btn svg { width: 34px; height: 34px; }
.mic-btn.listening {
  background: linear-gradient(180deg, #e07a5f 0%, #c14b32 100%);
  color: #fff;
  animation: pulse 1.1s ease-in-out infinite;
}
.mic-btn:active { transform: scale(0.96); }
.send-btn {
  width: 64px;
  height: 64px;
  min-width: 64px;
  border-radius: 20px;
  background: var(--bg-raise-2);
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
}
.send-btn.ready {
  background: var(--accent);
  color: #2a160b;
  border-color: transparent;
}
.send-btn svg { width: 28px; height: 28px; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(224, 122, 95, 0.45); }
  50% { box-shadow: 0 0 0 14px rgba(224, 122, 95, 0); }
}

/* Drawer */
.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
  z-index: 40;
}
.backdrop.on { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed;
  top: 0;
  left: 0;
  width: min(86vw, 380px);
  height: 100dvh;
  background: #1a1410;
  border-right: 1px solid var(--line);
  z-index: 50;
  transform: translateX(-105%);
  transition: transform .22s ease;
  display: flex;
  flex-direction: column;
  padding: calc(12px + var(--safe-t)) 16px calc(16px + var(--safe-b));
  overflow: auto;
}
.drawer.on { transform: translateX(0); }
.drawer h2 { margin: 8px 0 4px; font-size: 1.15rem; }
.drawer .hint { color: var(--muted); font-size: 0.9rem; margin: 0 0 16px; }
.big-action {
  width: 100%;
  min-height: 56px;
  border-radius: 16px;
  background: var(--accent);
  color: #2a160b;
  font-weight: 700;
  margin-bottom: 12px;
}
.big-action.ghost {
  background: var(--bg-raise);
  color: var(--text);
  border: 1px solid var(--line);
  font-weight: 600;
}
.section-label {
  margin: 18px 0 8px;
  font-size: 0.82rem;
  color: var(--muted);
  letter-spacing: 0.04em;
}
.chat-list { display: flex; flex-direction: column; gap: 8px; }
.chat-item {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 56px;
  padding: 8px 8px 8px 14px;
  border-radius: 14px;
  background: var(--bg-raise);
  border: 1px solid transparent;
  text-align: left;
  width: 100%;
}
.chat-item.active { border-color: var(--accent-deep); background: var(--accent-soft); }
.chat-item span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item .del {
  width: 44px;
  height: 44px;
  min-width: 44px;
  border-radius: 12px;
  color: var(--muted);
}
.toggle, .model-opt {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
  padding: 10px 14px;
  border-radius: 14px;
  background: var(--bg-raise);
  margin-bottom: 8px;
  width: 100%;
  text-align: left;
}
.model-opt.active { border: 1px solid var(--accent-deep); background: var(--accent-soft); }
.switch {
  width: 52px;
  height: 32px;
  border-radius: 99px;
  background: #3a312b;
  position: relative;
  flex-shrink: 0;
}
.switch::after {
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #efe4d8;
  transition: transform .15s;
}
.switch.on { background: var(--accent-deep); }
.switch.on::after { transform: translateX(20px); }
.badge {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 56px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--bg-raise);
  color: var(--muted);
  margin-bottom: 8px;
  border: 1px dashed var(--line);
}
.badge b { color: var(--text); font-weight: 600; }
.tag {
  margin-left: auto;
  font-size: 0.75rem;
  padding: 4px 8px;
  border-radius: 999px;
  background: #3a312b;
  white-space: nowrap;
}
.install-banner {
  display: none;
  margin: 0 0 12px;
}
.install-banner.show { display: block; }

/* PIN */
#pin-screen {
  position: fixed;
  inset: 0;
  background: #140f0c;
  z-index: 80;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: calc(28px + var(--safe-t)) 20px calc(24px + var(--safe-b));
  overflow: auto;
}
#pin-screen.on { display: flex; }
#pin-screen img { width: 88px; height: 88px; border-radius: 24px; margin-top: 12px; }
#pin-screen h1 { margin: 16px 0 6px; font-size: 1.7rem; }
#pin-screen .sub { color: var(--muted); text-align: center; margin: 0 0 22px; max-width: 22rem; }
.dots {
  display: flex;
  gap: 16px;
  margin-bottom: 22px;
}
.dots i {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  display: block;
}
.dots i.filled { background: var(--accent); }
.keypad {
  display: grid;
  grid-template-columns: repeat(3, 88px);
  gap: 14px;
  justify-content: center;
}
.key {
  width: 88px;
  height: 72px;
  border-radius: 20px;
  background: var(--bg-raise);
  border: 1px solid var(--line);
  font-size: 1.7rem;
  font-weight: 700;
}
.key:active { background: var(--bg-raise-2); transform: scale(0.97); }
.key.ghost { font-size: 1rem; color: var(--muted); font-weight: 600; }
#pin-msg { min-height: 1.4em; margin: 14px 0 0; color: var(--danger); text-align: center; }

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(110px + var(--safe-b));
  transform: translateX(-50%) translateY(20px);
  background: #2e241c;
  color: var(--text);
  padding: 12px 18px;
  border-radius: 14px;
  opacity: 0;
  pointer-events: none;
  transition: .2s;
  z-index: 90;
  max-width: 90vw;
  box-shadow: var(--shadow);
}
#toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (min-width: 800px) {
  .bubble { max-width: 75%; }
}
