/* Minimal, dependency-free. No build step (SPEC.md §4). */

:root {
  --bg: #faf8f5;
  --fg: #23201c;
  --muted: #6b645c;
  --line: #ddd6cc;
  --accent: #8a5a2b;
  --error: #9b2c2c;
  --error-bg: #fdf0f0;
  color-scheme: light;
}

/* The OS preference applies unless the user picked a theme with the toggle
   (#41); `theme-init.js` sets `data-theme` before the first paint. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1916;
    --fg: #ece7e0;
    --muted: #a49c92;
    --line: #3a352f;
    --accent: #d99b5c;
    --error: #f0a0a0;
    --error-bg: #2e1c1c;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #1b1916;
  --fg: #ece7e0;
  --muted: #a49c92;
  --line: #3a352f;
  --accent: #d99b5c;
  --error: #f0a0a0;
  --error-bg: #2e1c1c;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  /* The top clears the theme toggle. */
  padding: 56px 16px 24px;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

.card {
  width: 100%;
  max-width: 24rem;
  padding: 32px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: color-mix(in srgb, var(--bg) 88%, white);
}

.brand {
  margin: 0 0 4px;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

h2 { margin: 0 0 16px; font-size: 1.5rem; }

.intro { margin: 0 0 20px; color: var(--muted); }

label {
  display: block;
  margin: 16px 0 6px;
  font-size: 0.875rem;
  font-weight: 500;
}

input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
  font: inherit;
}

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

button {
  width: 100%;
  margin-top: 24px;
  padding: 11px 16px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

button:hover { filter: brightness(1.08); }

.error {
  margin: 0 0 16px;
  padding: 10px 12px;
  border-radius: 6px;
  background: var(--error-bg);
  color: var(--error);
  font-size: 0.9375rem;
}

/* ---- theme toggle (#41) ---- */

.theme-toggle {
  position: absolute;
  top: 12px;
  right: 16px;
  width: auto;
  margin: 0;
  padding: 6px 12px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--fg);
  font-size: 0.875rem;
  font-weight: 500;
}

.theme-toggle:hover { filter: none; border-color: var(--accent); }

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

/* ---- conversation pages ---- */

.page {
  width: 100%;
  max-width: 44rem;
  margin: 0 auto;
  padding: 24px 0 96px;
}

body:has(.page) { align-items: flex-start; }

.page-head {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 20px;
}

.page-head h2 { margin: 0; }
.page-head form { margin: 0; }
.page-head button { width: auto; margin: 0; padding: 8px 14px; }

/* The conversation title, editable in place. It takes the space the heading
   used to, so the page head still reads as a title and a back link. */
.rename { display: flex; gap: 8px; align-items: center; flex: 1 1 260px; }

.rename input {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  padding: 6px 8px;
  font-size: 1.25rem;
  font-weight: 600;
  color: inherit;
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
}

.rename input:hover { border-color: var(--line); }
.rename input:focus { border-color: var(--line); background: var(--card, transparent); }

.page-links { display: flex; gap: 14px; align-items: baseline; }

.back,
.download { color: var(--muted); font-size: 0.9375rem; }
.download:hover { color: var(--accent); }

.conversations { margin: 0; padding: 0; list-style: none; }

.conversations li {
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--line);
}

.conversations a {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  align-items: baseline;
  justify-content: space-between;
  padding: 14px 4px;
  color: inherit;
  text-decoration: none;
}

.conversations a:hover { color: var(--accent); }
.conversations time { color: var(--muted); font-size: 0.8125rem; }

.conversations form { margin: 0; }

.link-button {
  width: auto;
  margin: 0;
  padding: 4px 10px;
  background: none;
  border: 0;
  color: var(--muted);
  font-size: 1.125rem;
  cursor: pointer;
}

.link-button:hover { color: var(--error); filter: none; }

.signout {
  display: flex;
  gap: 16px;
  align-items: baseline;
  justify-content: flex-end;
  margin-top: 40px;
}

.signout a { color: var(--muted); font-size: 0.9375rem; }
.signout a:hover { color: var(--accent); }
.signout form { margin: 0; }
.signout .link-button { font-size: 0.9375rem; }

.turns { margin: 0 0 24px; padding: 0; list-style: none; }

.turn { margin-bottom: 20px; }

.who {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.said { white-space: pre-wrap; overflow-wrap: anywhere; }

.turn--user .said {
  padding: 12px 14px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

/* The wait before the first token was ~15 s on a recorded turn, so this is a
   real state a user sits in, not a flicker. */
.thinking .said { color: var(--muted); font-style: italic; }

.thinking .said::after {
  content: "";
  display: inline-block;
  width: 0.5em;
  height: 0.5em;
  margin-left: 0.4em;
  border-radius: 50%;
  background: currentColor;
  animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse { 0%, 100% { opacity: 0.25; } 50% { opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  .thinking .said::after { animation: none; opacity: 0.6; }
}

#composer {
  position: sticky;
  bottom: 0;
  display: flex;
  gap: 10px;
  align-items: flex-end;
  padding: 12px 0;
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}

#composer textarea {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
  font: inherit;
  resize: vertical;
}

#composer textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
#composer button { width: auto; margin: 0; padding: 10px 20px; }
#composer textarea:disabled, #composer button:disabled { opacity: 0.6; cursor: not-allowed; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.retry {
  width: auto;
  margin: 8px 0 0;
  padding: 6px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: none;
  color: var(--fg);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
}

.retry:hover { border-color: var(--accent); color: var(--accent); filter: none; }
.retry:disabled { opacity: 0.5; cursor: not-allowed; }

/* Quiet until the turn is hovered or the button is focused: one per turn,
   and they would otherwise compete with the text for attention. */
.copy {
  width: auto;
  margin: 6px 0 0;
  padding: 2px 8px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: none;
  color: var(--muted);
  font-size: 0.8125rem;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s ease-in;
}

.turn:hover .copy,
.copy:focus-visible { opacity: 1; }
.copy:hover { border-color: var(--line); color: var(--accent); filter: none; }

/* A touch screen has no hover, so the button would never appear. */
@media (hover: none) {
  .copy { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .copy { transition: none; }
}

/* ---- admin ---- */

.legend {
  margin: 0 0 20px;
  padding: 12px 14px;
  border-left: 3px solid var(--line);
  color: var(--muted);
  font-size: 0.875rem;
}

.legend p { margin: 0 0 6px; }
.legend p:last-child { margin-bottom: 0; }

.admin-nav { display: flex; gap: 16px; }
.admin-nav a { color: var(--muted); font-size: 0.9375rem; }
.admin-nav a:hover { color: var(--accent); }

.scroller { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 0.9375rem; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-size: 0.8125rem; font-weight: 600; white-space: nowrap; }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; }
tr.muted td { color: var(--muted); }

.tag {
  padding: 1px 6px;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--muted);
  font-size: 0.6875rem;
  text-transform: uppercase;
}

.created {
  margin: 0 0 16px;
  padding: 10px 12px;
  border-radius: 6px;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}

.created code, td code { font-size: 0.875rem; overflow-wrap: anywhere; }

.invite-form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
  margin-bottom: 24px;
}

.invite-form label { flex-basis: 100%; margin: 0; }
.invite-form input { flex: 1; min-width: 14rem; }
.invite-form button { width: auto; margin: 0; padding: 10px 18px; }

/* ---- voice input (#37) ---- */

/* Revealed by `voice.js` only when the browser can actually record, so the
   consent notice never advertises a feature that cannot run. */
#voice {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  align-items: start;
  margin: 0 0 12px;
}

#record {
  width: auto;
  margin: 0;
  padding: 8px 16px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: none;
  color: var(--fg);
  font: inherit;
  font-size: 0.875rem;
  cursor: pointer;
}

#record:hover { border-color: var(--accent); color: var(--accent); filter: none; }
#record:disabled { opacity: 0.5; cursor: not-allowed; }

/* Recording is the one state where the control must be unmistakable: the
   microphone is open, and the user needs to see that at a glance. */
#record.recording {
  border-color: var(--error);
  color: var(--error);
  background: var(--error-bg);
}

#record.recording::before {
  content: "";
  display: inline-block;
  width: 0.5em;
  height: 0.5em;
  margin-right: 0.5em;
  border-radius: 50%;
  background: var(--error);
  animation: pulse 1.4s ease-in-out infinite;
}

.consent {
  margin: 0;
  color: var(--muted);
  font-size: 0.8125rem;
  line-height: 1.45;
}

/* Second row, under both columns: a status line is about the last action, not
   about the button. Empty most of the time, so it claims no space. */
.voice-status {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--accent);
  font-size: 0.8125rem;
}

.voice-status:empty { display: none; }

@media (prefers-reduced-motion: reduce) {
  #record.recording::before { animation: none; }
}

/* The notice is long enough to deserve the full width on a narrow screen. */
@media (max-width: 30rem) {
  #voice { grid-template-columns: 1fr; }
  .consent { grid-column: 1 / -1; }
}
