:root {
  color-scheme: light;
  --bg: #f4f1ea;
  --ink: #1c1915;
  --muted: #5e584e;
  --partial: #5c3d2e;
  --line: #ddd6c8;
  --ok: #0f6b3c;
  --warn: #8a5a00;
  --danger: #9d2c2c;
  --button: #1c1915;
  --button-text: #f7f4ee;
  --stop: #8e1e1e;
  --stop-text: #fff;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #141311;
    --ink: #f3efe6;
    --muted: #c4baab;
    --partial: #e4c2a2;
    --line: #3a342c;
    --ok: #8ed4ae;
    --warn: #e6c07b;
    --danger: #f0a3a3;
    --button: #f3efe6;
    --button-text: #141311;
    --stop: #c44545;
    --stop-text: #1a0d0d;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

.app {
  height: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
  padding-right: env(safe-area-inset-right);
  padding-left: env(safe-area-inset-left);
}

header,
footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  padding: 1rem 1.25rem;
}

header {
  flex-wrap: wrap;
  border-bottom: 1px solid var(--line);
}

h1 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

#status {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
  max-width: 100%;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.3;
}

#status::before {
  content: "";
  width: 0.65rem;
  height: 0.65rem;
  flex: none;
  border-radius: 50%;
  background: var(--muted);
}

#status[data-state="connecting"] {
  color: var(--warn);
}

#status[data-state="connecting"]::before {
  background: var(--warn);
}

#status[data-state="listening"] {
  color: var(--ok);
}

#status[data-state="listening"]::before {
  background: var(--ok);
}

#status[data-state="error"] {
  color: var(--danger);
}

#status[data-state="error"]::before {
  background: var(--danger);
}

@media (prefers-reduced-motion: no-preference) {
  #status[data-state="listening"]::before {
    animation: pulse 1.4s ease-in-out infinite;
  }
}

@keyframes pulse {
  50% {
    opacity: 0.35;
  }
}

#transcript {
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overflow-anchor: none;
  overscroll-behavior: contain;
  padding: 1.25rem 1.25rem 2rem;
}

#placeholder,
#flow {
  max-width: 42rem;
  margin: 0 auto;
  font-family: Georgia, "Iowan Old Style", "Palatino Linotype", Palatino, serif;
  font-size: clamp(1.75rem, 4.6vw, 3.15rem);
  line-height: 1.35;
  letter-spacing: -0.015em;
  overflow-wrap: break-word;
}

#flow {
  display: flex;
  flex-direction: column;
  gap: 0.9em;
}

#flow[hidden] {
  display: none;
}

#flow p {
  margin: 0;
}

#placeholder {
  margin-top: 8vh;
  color: var(--muted);
}

.partial {
  color: var(--partial);
  font-style: italic;
}

footer {
  border-top: 1px solid var(--line);
  padding-bottom: calc(1rem + env(safe-area-inset-bottom));
}

button {
  flex: 1;
  max-width: 12rem;
  min-height: 3rem;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0.75rem 1.25rem;
  font: inherit;
  font-size: 1rem;
  touch-action: manipulation;
  cursor: pointer;
}

#toggle {
  background: var(--button);
  color: var(--button-text);
}

#toggle[aria-pressed="true"] {
  background: var(--stop);
  color: var(--stop-text);
}

#clear {
  background: transparent;
  color: var(--ink);
  border-color: var(--line);
}

button:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
}

@media (max-width: 480px) {
  button {
    max-width: none;
  }
}
