:root {
  --bg: #0b0d10;
  --panel: #15191f;
  --text: #f4f6f8;
  --muted: #a3acb8;
  --line: #2a313b;
  --idle: #2f6fed;
  --listening: #e5383b;
  --thinking: #f2a900;
  --speaking: #19b46b;
  --error: #ff6b35;
  --on-color: #ffffff;
  --on-thinking: #111111;
  --btn: min(64vmin, 34rem);
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #ffffff;
  --panel: #f1f3f6;
  --text: #0b0d10;
  --muted: #4a5360;
  --line: #d5dae1;
  --idle: #1f56d6;
  --listening: #c8102e;
  --thinking: #c78a00;
  --speaking: #0b8a4f;
  --error: #c2410c;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

button { font: inherit; color: inherit; }

.app {
  flex: 1;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: clamp(1rem, 3vmin, 2rem);
  padding: clamp(1rem, 3vmin, 2rem) 16px;
  width: 100%;
  max-width: 90rem;
  margin: 0 auto;
}

/* Wide screens (a parked car, a laptop): button left, words right. */
@media (min-aspect-ratio: 4/3) and (min-width: 60rem) {
  .app { grid-template-columns: auto 1fr; grid-template-rows: 1fr; align-items: center; }
  :root { --btn: min(70vh, 36rem); }
}

.stage { display: flex; justify-content: center; align-items: center; padding: calc(var(--btn) * 0.05); }

.talk {
  position: relative;
  width: var(--btn);
  height: var(--btn);
  border-radius: 50%;
  border: 0;
  background: var(--idle);
  color: var(--on-color);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: calc(var(--btn) * 0.03);
  padding: 8%;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  box-shadow: 0 0 0 calc(var(--btn) * 0.02) color-mix(in srgb, var(--idle) 35%, transparent);
  transition: background-color 120ms linear, transform 80ms ease-out;
}
.talk:active { transform: scale(0.98); }
.talk:focus-visible { outline: 4px solid var(--text); outline-offset: 6px; }

.icon { width: calc(var(--btn) * 0.28); height: calc(var(--btn) * 0.28); fill: currentColor; }
.label { font-size: calc(var(--btn) * 0.105); font-weight: 800; line-height: 1.05; text-align: center; }
.sub { font-size: calc(var(--btn) * 0.05); font-weight: 600; opacity: 0.92; text-align: center; min-height: 1.2em; }

.ring {
  position: absolute;
  inset: calc(var(--btn) * -0.045);
  border-radius: 50%;
  border: calc(var(--btn) * 0.025) solid transparent;
  pointer-events: none;
}

body[data-state="listening"] .talk { background: var(--listening); box-shadow: none; }
body[data-state="listening"] .ring { border-color: var(--listening); animation: pulse 1.1s ease-out infinite; }

body[data-state="thinking"] .talk { background: var(--thinking); color: var(--on-thinking); box-shadow: none; }
body[data-state="thinking"] .ring {
  border-color: color-mix(in srgb, var(--thinking) 25%, transparent);
  border-top-color: var(--thinking);
  animation: spin 1s linear infinite;
}

body[data-state="speaking"] .talk,
body[data-state="ready"] .talk { background: var(--speaking); box-shadow: none; }
body[data-state="speaking"] .ring { border-color: var(--speaking); animation: pulse 1.6s ease-in-out infinite; }

body[data-state="error"] .talk { background: var(--error); box-shadow: none; }

@keyframes pulse {
  0% { transform: scale(0.96); opacity: 1; }
  100% { transform: scale(1.08); opacity: 0; }
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .ring { animation: none !important; }
}

.words {
  display: flex;
  flex-direction: column;
  gap: clamp(0.75rem, 2vmin, 1.5rem);
  min-width: 0;
  overflow-y: auto;
}

.line { display: grid; gap: 0.25rem; }
.who { font-size: clamp(0.85rem, 1.8vmin, 1.1rem); font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
.said { margin: 0; font-size: clamp(1.3rem, 3.6vmin, 2.3rem); line-height: 1.3; font-weight: 600; overflow-wrap: anywhere; white-space: pre-wrap; }
.said:empty::before { content: "…"; color: var(--muted); }
.reply { max-height: 40vh; overflow-y: auto; }

details { border-top: 1px solid var(--line); padding-top: 0.75rem; }
summary { font-size: clamp(1rem, 2.4vmin, 1.4rem); font-weight: 700; color: var(--muted); cursor: pointer; padding: 0.4rem 0; }
#history { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.75rem; }
#history li { background: var(--panel); border-radius: 0.75rem; padding: 0.75rem 1rem; font-size: clamp(1rem, 2.4vmin, 1.35rem); line-height: 1.35; overflow-wrap: anywhere; }
#history .q { color: var(--muted); display: block; margin-bottom: 0.3rem; }

.bar { display: flex; justify-content: flex-end; gap: 0.5rem; padding: 0 16px 0.75rem; }

.small {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 0.6rem;
  padding: 0.6rem 1rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
}

/* Login page */
.locked { max-width: 34rem; margin: auto; padding: 2rem 16px; display: grid; gap: 1rem; }
.locked h1 { margin: 0; font-size: 2.5rem; }
.locked p { margin: 0; font-size: 1.3rem; line-height: 1.4; }
.locked form { display: grid; gap: 0.6rem; margin-top: 1rem; }
.locked label { color: var(--muted); }
.locked input {
  font: inherit;
  font-size: 1.2rem;
  padding: 0.8rem;
  border-radius: 0.6rem;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
}
code { font-size: 0.95em; }
