:root {
  color-scheme: light;
  --bg: #f7f7fa;
  --surface: #ffffff;
  --surface-2: #f4f4f7;
  --border: #e7e7ec;
  --border-strong: #d4d4dc;
  --text: #18181b;
  --muted: #71717a;
  --accent: #5b5bd6;
  --accent-hover: #4d4dc5;
  --accent-soft: #eeeeff;
  --danger: #be3952;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow: 0 1px 2px rgb(24 24 27 / 0.04), 0 10px 30px rgb(24 24 27 / 0.035);
  --font: "Inter", system-ui, sans-serif;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
}

body {
  font-family: var(--font);
  font-size: 0.9375rem;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
}

[hidden] { display: none !important; }

.app {
  height: 100%;
  max-width: 760px;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: 0 18px calc(14px + var(--safe-bottom));
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  min-height: 68px;
  border-bottom: 1px solid var(--border);
  padding: calc(10px + env(safe-area-inset-top, 0px)) 0 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #fff;
  font-size: 0.875rem;
  font-weight: 700;
  box-shadow: 0 6px 16px rgb(91 91 214 / 0.2);
}

.brand h1 {
  font-size: 0.875rem;
  font-weight: 650;
  letter-spacing: -0.015em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand p {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.12rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-shrink: 0;
}

.mode-tag,
.header-link {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1;
  padding: 0.42rem 0.7rem;
  border-radius: 999px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

.mode-tag:hover,
.header-link:hover {
  border-color: var(--border-strong);
  color: var(--text);
  background: var(--surface-2);
}

.mode-tag[aria-pressed="true"] {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: #d7d7ff;
}

main {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 14px 0 8px;
}

.google-reconnect {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
  padding: 0.75rem 0.9rem;
  border-radius: var(--radius-lg);
  background: #fff7ed;
  border: 1px solid #fed7aa;
}

.google-reconnect[hidden] { display: none; }

.google-reconnect p {
  margin: 0;
  font-size: 0.92rem;
}

.google-reconnect a {
  flex: none;
  border-radius: 999px;
  background: var(--accent);
  color: white;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.88rem;
  padding: 0.45rem 0.8rem;
}

.chat-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  padding: 0.25rem 0 0.5rem;
  scroll-behavior: smooth;
}

.chat-empty {
  color: var(--muted);
  font-size: 0.8125rem;
  text-align: center;
  line-height: 1.5;
  padding: 2.5rem 0.5rem;
}

.msg {
  max-width: 88%;
  padding: 0.7rem 0.95rem;
  border-radius: var(--radius-lg);
  font-size: 0.9375rem;
  line-height: 1.45;
  text-align: left;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.msg.assistant {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  border-bottom-left-radius: 4px;
}

.msg.assistant.streaming::after {
  content: "▍";
  animation: blink 1s step-end infinite;
  color: var(--accent);
}

.msg-file {
  align-self: flex-start;
  max-width: 88%;
  padding: 0.7rem 0.95rem;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  text-align: left;
}

.msg-file a {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.9375rem;
  font-weight: 600;
}

.msg-file a:hover { text-decoration: underline; }

.msg-file p {
  margin-top: 0.35rem;
  font-size: 0.8125rem;
  color: var(--muted);
}

.composer {
  width: 100%;
  display: grid;
  gap: 0.55rem;
  padding-top: 4px;
}

.status {
  font-size: 0.75rem;
  color: var(--muted);
  min-height: 1rem;
  text-align: center;
}

.status.live { color: var(--accent); font-weight: 600; }

.presets {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  justify-content: flex-start;
}

.preset-chip {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.75rem;
  line-height: 1.2;
  padding: 0.4rem 0.7rem;
  border-radius: 999px;
  cursor: pointer;
}

.preset-chip:hover {
  border-color: var(--border-strong);
  background: var(--surface-2);
}

.preset-chip:disabled {
  opacity: 0.5;
  cursor: wait;
}

.preset-chip[aria-pressed="true"] {
  border-color: #d7d7ff;
  background: var(--accent-soft);
  color: var(--accent);
}

.composer-form {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.4rem 0.4rem 0.95rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow);
}

.composer-form:focus-within {
  border-color: #c9c9f5;
  box-shadow: 0 0 0 3px var(--accent-soft);
}

#text-input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.9375rem;
  outline: none;
}

#text-input::placeholder { color: #a1a1aa; }
#text-input:disabled { opacity: 0.55; }

.composer-voice {
  position: relative;
  flex-shrink: 0;
  width: 36px;
  height: 36px;
}

.btn-icon {
  appearance: none;
  border: none;
  padding: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
  color: var(--muted);
  background: var(--surface-2);
  transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.composer-voice .btn-icon {
  position: absolute;
  inset: 0;
}

.btn-icon:hover { background: #ececf3; color: var(--text); }
.btn-icon:active:not(:disabled) { transform: scale(0.96); }
.btn-icon:disabled { opacity: 0.5; cursor: wait; }

.btn-icon svg {
  width: 18px;
  height: 18px;
}

.btn-talk.live,
.btn-talk[aria-pressed="true"] {
  background: var(--accent-soft);
  color: var(--accent);
}

.btn-stop {
  background: #fde8ec;
  color: var(--danger);
}

.btn-stop:hover { background: #f8d4db; color: var(--danger); }

.btn-send {
  flex-shrink: 0;
  background: var(--accent);
  color: #fff;
}

.btn-send:hover { background: var(--accent-hover); color: #fff; }

.gate {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background: rgb(247 247 250 / 0.92);
  backdrop-filter: blur(8px);
}

.gate-card {
  width: min(360px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  text-align: center;
}

.gate-card h2 {
  font-size: 1.125rem;
  margin-bottom: 0.5rem;
}

.gate-card p {
  color: var(--muted);
  font-size: 0.875rem;
  line-height: 1.5;
  margin-bottom: 1.25rem;
}

.gate-card a {
  display: inline-block;
  padding: 0.7rem 1.15rem;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.875rem;
}

@keyframes blink {
  50% { opacity: 0; }
}
