:root {
  color-scheme: dark;
  --bg: #0e0e10;
  --panel: #17171a;
  --bubble-user: #2a2a30;
  --bubble-bot: #1c1c21;
  --text: #f3f3f4;
  --muted: #9b9ba3;
  --line: rgba(255, 255, 255, 0.08);
  --accent: #d7f5e4;
  --accent-ink: #10241a;
  --danger: #ffb4b4;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  --top: env(safe-area-inset-top, 0px);
  --bottom: env(safe-area-inset-bottom, 0px);
  --font: "Segoe UI", ui-sans-serif, system-ui, -apple-system, sans-serif;
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #f6f6f7;
  --panel: #ffffff;
  --bubble-user: #e7e7ea;
  --bubble-bot: #ffffff;
  --text: #16161a;
  --muted: #5e5e66;
  --line: rgba(0, 0, 0, 0.08);
  --accent: #143026;
  --accent-ink: #f3fff8;
  --danger: #9d1c1c;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.12);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, textarea, input, select { font: inherit; color: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.app {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding-top: var(--top);
}

.top {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 56px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--line);
}
.titles { flex: 1; min-width: 0; }
.app-name { font-size: 16px; font-weight: 650; letter-spacing: -0.02em; }
.model-name {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn, .send, .jump {
  border: 0;
  background: transparent;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  cursor: pointer;
}
.icon-btn:active, .text-btn:active, .ghost:active, .send:active { transform: scale(0.96); }
.icon-btn svg, .send svg { width: 22px; height: 22px; }
.text-btn {
  border: 0;
  background: transparent;
  color: var(--accent);
  padding: 8px 10px;
  cursor: pointer;
}

.transcript {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.pull {
  height: 0;
  overflow: hidden;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  line-height: 44px;
}
.messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px 14px 12px;
  min-height: 100%;
}
.bubble {
  max-width: min(86%, 640px);
  padding: 12px 14px;
  border-radius: 18px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
  border: 1px solid var(--line);
}
.bubble.user {
  align-self: flex-end;
  background: var(--bubble-user);
  border-bottom-right-radius: 6px;
}
.bubble.assistant {
  align-self: flex-start;
  background: var(--bubble-bot);
  border-bottom-left-radius: 6px;
}
.bubble.pending::after {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-left: 4px;
  border-radius: 50%;
  background: var(--muted);
  animation: blink 1s steps(2) infinite;
  vertical-align: baseline;
}
.empty {
  margin: auto;
  max-width: 280px;
  text-align: center;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.45;
}
@keyframes blink { 50% { opacity: 0; } }

.jump {
  position: fixed;
  right: 16px;
  bottom: calc(84px + var(--bottom));
  width: auto;
  padding: 0 12px;
  height: 34px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  font-size: 13px;
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin: 0 12px calc(10px + var(--bottom));
  padding: 8px 8px 8px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 24px;
}
.composer textarea {
  flex: 1;
  resize: none;
  border: 0;
  outline: none;
  background: transparent;
  max-height: 140px;
  padding: 8px 0;
  font-size: 16px;
  line-height: 1.35;
}
.send {
  background: var(--accent);
  color: var(--accent-ink);
  flex: none;
}
.send:disabled { opacity: 0.35; }
.call-btn { color: var(--text); }

.call-screen {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 28px;
  padding: 24px;
  background: #070708;
  color: #f3f3f4;
  text-align: center;
}
.call-screen[hidden] { display: none; }
.call-screen p { margin: 0; max-width: 22rem; font-size: 20px; line-height: 1.4; }
.hangup {
  min-width: 160px;
  min-height: 52px;
  border: 0;
  border-radius: 999px;
  background: #c53434;
  color: white;
  font-size: 17px;
}

.scrim {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 20;
}
.drawer {
  position: fixed;
  z-index: 21;
  top: 0;
  bottom: 0;
  left: 0;
  width: min(84vw, 320px);
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: var(--top) 8px var(--bottom);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
}
.drawer-head, .sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 6px;
}
.history {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow: auto;
}
.history button {
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  border-radius: 12px;
  padding: 12px;
  cursor: pointer;
}
.history button.active { background: var(--bubble-user); }
.history .title { display: block; font-size: 15px; }
.history .when { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.history .row { display: flex; align-items: stretch; }
.history .trash {
  border: 0;
  background: transparent;
  color: var(--muted);
  width: 42px;
  cursor: pointer;
}

.sheet {
  width: min(440px, calc(100vw - 24px));
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--panel);
  color: var(--text);
  padding: 8px 16px 18px;
  box-shadow: var(--shadow);
}
.sheet::backdrop { background: rgba(0, 0, 0, 0.5); }
.sheet h2 { font-size: 18px; margin: 0; }
.sheet label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  margin-top: 12px;
}
.sheet input, .sheet select {
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 12px;
  padding: 12px;
  font-size: 16px;
}
.sheet-actions { display: flex; gap: 8px; margin-top: 16px; }
.ghost {
  flex: 1;
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 12px;
  padding: 12px;
  cursor: pointer;
}
.ghost.danger { color: var(--danger); }
.note { min-height: 1.2em; color: var(--muted); font-size: 13px; }
