:root {
  color-scheme: dark light;
  --bg: #0b0f14; --panel: #151b24; --text: #e8edf4; --muted: #8b97a8;
  --user: #2f6df6; --user-text: #fff; --bot: #1c2430; --line: #263041;
  --accent: #2f6df6; --rec: #f04747; --err: #ff8a80;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6fa; --panel: #ffffff; --text: #121821; --muted: #5d6a7c;
    --user: #2f6df6; --user-text: #fff; --bot: #e6ebf3; --line: #d5dce8;
    --err: #c62828;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 17px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  display: flex; flex-direction: column;
  height: 100dvh;
  padding-top: env(safe-area-inset-top);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button, select, input { font: inherit; color: inherit; touch-action: manipulation; }
button { cursor: pointer; -webkit-user-select: none; user-select: none; }

.bar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px max(14px, env(safe-area-inset-left)) 8px max(14px, env(safe-area-inset-right));
  border-bottom: 1px solid var(--line);
}
.bar h1 { margin: 0; font-size: 20px; white-space: nowrap; }
.bar-actions { display: flex; gap: 6px; align-items: center; }
.chip, #lang {
  white-space: nowrap;
  min-height: 44px; padding: 0 12px; border-radius: 22px;
  background: var(--panel); border: 1px solid var(--line); font-size: 16px;
}
#lang { max-width: 78px; padding: 0 8px; }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }

.chat {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 12px max(14px, env(safe-area-inset-left)) 12px max(14px, env(safe-area-inset-right));
  display: flex; flex-direction: column; gap: 10px;
}
.empty { margin: auto; color: var(--muted); text-align: center; }
.msg {
  max-width: 85%; padding: 10px 14px; border-radius: 18px;
  white-space: pre-wrap; overflow-wrap: anywhere; user-select: text; -webkit-user-select: text;
}
.msg.user { align-self: flex-end; background: var(--user); color: var(--user-text); border-bottom-right-radius: 6px; }
.msg.assistant { align-self: flex-start; background: var(--bot); border-bottom-left-radius: 6px; }
.msg.error { align-self: center; background: transparent; border: 1px solid var(--err); color: var(--err); font-size: 15px; }
.msg.pending { color: var(--muted); font-style: italic; }

.dock {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 8px max(14px, env(safe-area-inset-left)) calc(10px + env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-right));
  border-top: 1px solid var(--line); background: var(--bg);
}
.status { margin: 0; min-height: 22px; font-size: 15px; color: var(--muted); text-align: center; overflow-wrap: anywhere; }
.status.live { color: var(--text); }
.mic {
  width: 92px; height: 92px; border-radius: 50%; border: 0;
  background: var(--accent); color: #fff;
  display: grid; place-items: center;
  box-shadow: 0 6px 20px rgba(47,109,246,.35);
}
.mic:active { transform: scale(.96); }
.mic.rec { background: var(--rec); animation: pulse 1.2s infinite; box-shadow: 0 6px 24px rgba(240,71,71,.45); }
.mic:disabled { opacity: .4; box-shadow: none; }
@keyframes pulse { 50% { transform: scale(1.06); } }
@media (prefers-reduced-motion: reduce) { .mic.rec { animation: none; } }

.row { display: flex; gap: 8px; width: 100%; max-width: 640px; }
.row input {
  flex: 1; min-width: 0; min-height: 52px; padding: 0 16px; font-size: 17px;
  border-radius: 26px; border: 1px solid var(--line); background: var(--panel); color: var(--text);
  -webkit-appearance: none; appearance: none;
}
.send {
  min-height: 52px; min-width: 76px; padding: 0 20px; border: 0; border-radius: 26px;
  background: var(--accent); color: #fff; font-weight: 600; font-size: 17px;
}
.send:disabled { opacity: .45; }

.gate-wrap {
  position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; padding: 20px;
  background: rgba(0,0,0,.6); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
.gate-wrap[hidden] { display: none; }
.gate {
  width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 12px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 20px;
}
.gate h2 { margin: 0; }
.gate p { margin: 0; color: var(--muted); font-size: 15px; }
.gate input {
  min-height: 52px; padding: 0 16px; font-size: 17px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
}

.google-row {
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px; font-size: 14px; color: var(--muted);
  padding: 4px max(14px, env(safe-area-inset-left)) 6px max(14px, env(safe-area-inset-right));
  border-bottom: 1px solid var(--line);
}
.google-row a { color: var(--accent); }
.chip.small { min-height: 32px; padding: 0 10px; font-size: 14px; margin-left: auto; }
