:root {
  --bg: #e8f0ec;
  --surface: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --accent: #0d9488;
  --accent-dark: #0f766e;
  --user-bg: #ccfbf1;
  --user-border: #5eead4;
  --bot-bg: #f8fafc;
  --think-bg: #f1f5f9;
  --think-border: #cbd5e1;
  --danger: #b91c1c;
  --radius: 14px;
  --shadow: 0 4px 24px rgba(15, 23, 42, 0.08);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  color: var(--ink);
  line-height: 1.5;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body.page {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(165deg, #d8ebe4 0%, var(--bg) 45%, #dce8f0 100%);
}

.skip-link {
  position: absolute;
  left: 0.75rem;
  top: 0.5rem;
  padding: 0.45rem 0.75rem;
  background: #fff;
  color: #0f766e;
  font-weight: 600;
  font-size: 0.9rem;
  border-radius: 8px;
  z-index: 100;
  box-shadow: 0 2px 12px rgba(15, 23, 42, 0.15);
  transform: translateY(-120%);
  transition: transform 0.15s ease;
}

.skip-link:focus {
  transform: translateY(0);
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.hero {
  background: linear-gradient(135deg, #042f2e 0%, #0f766e 48%, #115e59 100%);
  color: #ecfdf5;
  padding: 1.75rem 1.25rem 2rem;
  box-shadow: 0 8px 32px rgba(4, 47, 46, 0.35);
}

.hero-inner {
  max-width: 44rem;
  margin: 0 auto;
}

.hero-title {
  margin: 0 0 0.5rem;
  font-size: clamp(1.35rem, 3vw, 1.65rem);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.hero-lead {
  margin: 0;
  font-size: 0.98rem;
  opacity: 0.94;
  max-width: 36rem;
}

.shell {
  max-width: 44rem;
  margin: -1.25rem auto 2.5rem;
  padding: 0 1rem;
  position: relative;
  z-index: 1;
}

.chat-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem 1.35rem 1.35rem;
  border: 1px solid rgba(15, 118, 110, 0.12);
}

.pill-status {
  min-height: 1.5rem;
  margin: 0 0 0.75rem;
  padding: 0.35rem 0.75rem;
  font-size: 0.82rem;
  color: var(--muted);
  background: #f1f5f9;
  border-radius: 999px;
  border: 1px solid #e2e8f0;
}

.thread {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  min-height: 14rem;
  max-height: min(52vh, 26rem);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0.35rem 0.15rem 1rem;
  margin-bottom: 1rem;
  scroll-behavior: smooth;
}

.thread:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.msg-row {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  max-width: 100%;
}

.msg-row.user {
  align-items: flex-end;
}

.msg-row.assistant {
  align-items: flex-start;
}

.bubble {
  max-width: min(100%, 34rem);
  padding: 0.75rem 1rem;
  border-radius: 16px;
  word-break: break-word;
  font-size: 0.95rem;
  line-height: 1.55;
}

.bubble.user {
  background: var(--user-bg);
  border: 1px solid var(--user-border);
  color: #134e4a;
  border-bottom-right-radius: 4px;
  white-space: pre-wrap;
}

.bubble.answer {
  background: var(--bot-bg);
  border: 1px solid #e2e8f0;
  border-bottom-left-radius: 4px;
  white-space: normal;
}

.markdown-body > *:first-child {
  margin-top: 0;
}

.markdown-body > *:last-child {
  margin-bottom: 0;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
  margin: 0.85rem 0 0.45rem;
  font-weight: 700;
  line-height: 1.25;
  color: #0f172a;
}

.markdown-body h1 {
  font-size: 1.15rem;
}

.markdown-body h2 {
  font-size: 1.05rem;
}

.markdown-body h3,
.markdown-body h4 {
  font-size: 0.98rem;
}

.markdown-body p {
  margin: 0.45rem 0;
}

.markdown-body ul,
.markdown-body ol {
  margin: 0.45rem 0;
  padding-left: 1.35rem;
}

.markdown-body li {
  margin: 0.2rem 0;
}

.markdown-body blockquote {
  margin: 0.5rem 0;
  padding: 0.35rem 0.65rem;
  border-left: 3px solid var(--accent);
  background: #f1f5f9;
  color: #334155;
}

.markdown-body hr {
  border: none;
  border-top: 1px solid #e2e8f0;
  margin: 0.75rem 0;
}

.markdown-body a {
  color: #0f766e;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.markdown-body a:hover {
  color: #115e59;
}

.markdown-body code {
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 0.86em;
  background: #e2e8f0;
  padding: 0.12rem 0.35rem;
  border-radius: 4px;
  word-break: break-word;
}

.markdown-body pre {
  margin: 0.55rem 0;
  padding: 0.65rem 0.75rem;
  background: #1e293b;
  color: #e2e8f0;
  border-radius: 8px;
  overflow-x: auto;
  font-size: 0.82rem;
  line-height: 1.45;
}

.markdown-body pre code {
  background: transparent;
  padding: 0;
  font-size: inherit;
  color: inherit;
}

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.55rem 0;
  font-size: 0.88rem;
}

.markdown-body th,
.markdown-body td {
  border: 1px solid #e2e8f0;
  padding: 0.35rem 0.5rem;
  text-align: left;
  vertical-align: top;
}

.markdown-body th {
  background: #f1f5f9;
  font-weight: 600;
}

.source-wrap {
  max-width: min(100%, 36rem);
  border: 1px solid #a7f3d0;
  border-radius: 12px;
  background: #ecfdf5;
  overflow: hidden;
}

.source-wrap[hidden] {
  display: none !important;
}

.source-wrap summary {
  cursor: pointer;
  padding: 0.5rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: #0f766e;
  list-style: none;
  user-select: none;
}

.source-wrap summary::-webkit-details-marker {
  display: none;
}

.source-wrap summary::before {
  content: "▸ ";
  opacity: 0.75;
}

.source-wrap[open] summary::before {
  content: "▾ ";
}

.source-body {
  padding: 0.55rem 0.85rem 0.75rem;
  font-size: 0.82rem;
  color: #334155;
  line-height: 1.5;
  border-top: 1px solid #a7f3d0;
  max-height: 12rem;
  overflow-y: auto;
}

.feedback-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
  margin-top: 0.25rem;
}

.feedback-row[hidden] {
  display: none !important;
}

.feedback-label {
  font-size: 0.78rem;
  color: var(--muted);
  margin-right: 0.25rem;
}

.btn-feedback {
  padding: 0.4rem 0.75rem;
  font-size: 0.82rem;
  font-weight: 600;
  border-radius: 8px;
  border: 1px solid #cbd5e1;
  background: #fff;
  color: #334155;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}

.btn-feedback:hover:not(:disabled) {
  background: #f8fafc;
  border-color: #94a3b8;
}

.btn-feedback:disabled {
  opacity: 0.55;
  cursor: default;
}

.btn-feedback.yes:not(:disabled):hover {
  border-color: #14b8a6;
  color: #0f766e;
}

.btn-feedback.no:not(:disabled):hover {
  border-color: #f87171;
  color: #b91c1c;
}

.think-wrap {
  max-width: min(100%, 36rem);
  border: 1px solid var(--think-border);
  border-radius: 12px;
  background: var(--think-bg);
  overflow: hidden;
}

.think-wrap[hidden] {
  display: none !important;
}

.think-wrap summary {
  cursor: pointer;
  padding: 0.5rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: #475569;
  list-style: none;
  user-select: none;
}

.think-wrap summary::-webkit-details-marker {
  display: none;
}

.think-wrap summary::before {
  content: "▸ ";
  opacity: 0.7;
}

.think-wrap[open] summary::before {
  content: "▾ ";
}

.think-body {
  margin: 0;
  padding: 0.65rem 0.85rem 0.85rem;
  max-height: 14rem;
  overflow: auto;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 0.78rem;
  line-height: 1.45;
  color: #334155;
  white-space: pre-wrap;
  word-break: break-word;
  border-top: 1px solid var(--think-border);
}

.composer {
  margin-top: 1rem;
  padding-top: 0.25rem;
  border-top: none;
}

.composer-shell {
  background: linear-gradient(165deg, #2d353c 0%, #1a2128 55%, #222a32 100%);
  border-radius: 1.75rem;
  padding: 0.65rem 1rem 0.55rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow:
    0 4px 24px rgba(15, 23, 42, 0.18),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.composer-input-wrap {
  min-width: 0;
}

.composer-input {
  display: block;
  width: 100%;
  min-height: 2.85rem;
  max-height: 10rem;
  resize: vertical;
  padding: 0.45rem 0.15rem 0.35rem;
  border: none;
  border-radius: 0.5rem;
  font: inherit;
  font-size: 1.02rem;
  line-height: 1.45;
  color: #f1f5f9;
  background: transparent;
  box-sizing: border-box;
}

.composer-input::placeholder {
  color: #94a3b8;
}

.composer-input:focus {
  outline: none;
}

.composer-input:focus-visible {
  outline: 2px solid rgba(45, 212, 191, 0.65);
  outline-offset: 2px;
  border-radius: 0.35rem;
}

.composer-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 0.75rem;
  margin-top: 0.4rem;
  padding-top: 0.55rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.composer-toolbar-left {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.65rem;
  min-width: 0;
}

.composer-locale-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #94a3b8;
}

.composer-select-dark {
  font: inherit;
  font-size: 0.8rem;
  padding: 0.28rem 0.55rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(0, 0, 0, 0.25);
  color: #e2e8f0;
  cursor: pointer;
}

.composer-select-dark:focus-visible {
  outline: 2px solid rgba(45, 212, 191, 0.7);
  outline-offset: 2px;
}

.composer-key-hint {
  font-size: 0.72rem;
  color: #64748b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 12rem;
}

.composer-toolbar-right {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.4rem;
}

.btn-toolbar {
  font-weight: 600;
  font-size: 0.86rem;
  border-radius: 999px;
  padding: 0.45rem 1rem;
  cursor: pointer;
  border: none;
  transition: filter 0.12s, transform 0.08s;
}

.btn-send-pill {
  background: linear-gradient(180deg, #14b8a6 0%, #0d9488 100%);
  color: #f0fdfa;
  box-shadow: 0 2px 12px rgba(13, 148, 136, 0.45);
}

.btn-send-pill:hover:not(:disabled) {
  filter: brightness(1.06);
}

.btn-send-pill:active:not(:disabled) {
  transform: scale(0.98);
}

.btn-send-pill:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

.btn-stop-dark {
  background: rgba(255, 255, 255, 0.08);
  color: #e2e8f0;
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.btn-stop-dark:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.12);
}

.btn-stop-dark:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.btn-mic {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.65rem;
  height: 2.65rem;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  color: #e2e8f0;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, transform 0.08s;
}

.btn-mic:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
}

.btn-mic:active:not(:disabled) {
  transform: scale(0.95);
}

.btn-mic.is-listening {
  background: rgba(239, 68, 68, 0.35);
  color: #fff;
  animation: mic-pulse 1.2s ease-in-out infinite;
}

.btn-mic:disabled,
.btn-mic.is-unsupported {
  opacity: 0.35;
  cursor: not-allowed;
}

@keyframes mic-pulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.35);
  }
  50% {
    box-shadow: 0 0 0 8px rgba(239, 68, 68, 0);
  }
}

.btn-send-pill:focus-visible,
.btn-stop-dark:focus-visible,
.btn-mic:focus-visible,
.btn-feedback:focus-visible {
  outline: 2px solid rgba(45, 212, 191, 0.9);
  outline-offset: 2px;
}

@media (min-width: 640px) {
  .composer-toolbar {
    flex-wrap: nowrap;
  }

  .composer-key-hint {
    max-width: none;
  }
}

.banner-error {
  margin: 0.75rem 0 0;
  padding: 0.6rem 0.85rem;
  font-size: 0.88rem;
  color: #7f1d1d;
  background: #fee2e2;
  border: 1px solid #fecaca;
  border-radius: 10px;
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 540px) {
  .hero {
    padding: 1.2rem max(1rem, env(safe-area-inset-right)) 1.5rem max(1rem, env(safe-area-inset-left));
  }

  .shell {
    padding-left: max(0.75rem, env(safe-area-inset-left));
    padding-right: max(0.75rem, env(safe-area-inset-right));
    margin-bottom: max(1.5rem, env(safe-area-inset-bottom));
  }

  .chat-card {
    padding: 1rem;
  }

  .thread {
    max-height: min(48vh, 22rem);
  }

  .composer-shell {
    border-radius: 1.35rem;
    padding: 0.55rem 0.75rem 0.5rem;
  }

  .composer-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .composer-toolbar-left,
  .composer-toolbar-right {
    width: 100%;
    justify-content: space-between;
  }

  .composer-toolbar-right {
    justify-content: stretch;
    gap: 0.5rem;
  }

  .btn-send-pill,
  .btn-stop-dark {
    min-height: 48px;
    flex: 1;
    touch-action: manipulation;
  }

  .btn-mic {
    width: 48px;
    height: 48px;
    flex: 0 0 48px;
    touch-action: manipulation;
  }

  .composer-input {
    font-size: 16px;
    min-height: 3.25rem;
  }
}
