/* StudioDesk shared styles. No build step; plain CSS custom properties.
   Colours are chosen for WCAG AA: body text >= 4.5:1 and UI borders >= 3:1 on their surfaces. */

:root {
  color-scheme: light dark;
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-alt: #eef0f5;
  --text: #1b1d23;
  --muted: #4a4f5c;
  --border: #d5d8df;
  --control-border: #6b7080;
  --primary: #1f4fd1;
  --primary-hover: #183fa8;
  --on-primary: #ffffff;
  --secondary-text: #1f4fd1;
  --focus: #1f4fd1;
  --error: #b3261e;
  --error-bg: #fdecea;
  --success: #1d6b34;
  --success-bg: #e8f5ec;
  --note-bg: #fff6dc;
  --note-text: #5c4300;
  --speaking: #1d6b34;
  --listening: #1f4fd1;
  --idle: #6b7080;
  --user-bubble: #e7edfd;
  --agent-bubble: #eef0f5;
  --radius: 0.5rem;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121418;
    --surface: #1c1f26;
    --surface-alt: #252933;
    --text: #eceef3;
    --muted: #b4b9c5;
    --border: #3a3f4b;
    --control-border: #8a90a0;
    --primary: #8fb0ff;
    --primary-hover: #b3caff;
    --on-primary: #0b1530;
    --secondary-text: #a9c2ff;
    --focus: #ffd166;
    --error: #ff9b94;
    --error-bg: #3a1d1b;
    --success: #7fd99a;
    --success-bg: #17301f;
    --note-bg: #3a3218;
    --note-text: #f3dd9c;
    --speaking: #7fd99a;
    --listening: #8fb0ff;
    --idle: #8a90a0;
    --user-bubble: #22304f;
    --agent-bubble: #252933;
  }
}

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

h1,
h2,
h3 {
  line-height: 1.25;
  margin: 0 0 0.5rem;
}

h1 { font-size: 1.75rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; margin-top: 1rem; }

p { margin: 0 0 0.75rem; }

a {
  color: var(--secondary-text);
  text-decoration-thickness: 0.08em;
  text-underline-offset: 0.15em;
}

/* Visible focus everywhere, keyboard-first. */
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.skip-link {
  position: absolute;
  left: 0.5rem;
  top: -3rem;
  z-index: 10;
  padding: 0.5rem 0.75rem;
  background: var(--surface);
  color: var(--text);
  border: 2px solid var(--focus);
  border-radius: var(--radius);
}

.skip-link:focus {
  top: 0.5rem;
}

.site-header,
.site-footer {
  max-width: 72rem;
  margin: 0 auto;
  padding: 1.25rem 1rem 0.5rem;
}

.site-footer {
  padding-bottom: 2rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.tagline {
  color: var(--muted);
}

main:focus {
  outline: none;
}

.layout {
  max-width: 72rem;
  margin: 0 auto;
  padding: 0 1rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
}

/* Each column stacks its panels. DOM order (voice, transcript, typing, bug check, answer) is
   the reading order on phones and column by column on wide screens. */
.column {
  display: grid;
  gap: 1rem;
  align-content: start;
  min-width: 0;
}

/* Wide screens: the voice controls span the top; the transcript and typing form sit beside
   the bug check and answer, so results are visible during a call. */
@media (min-width: 56rem) {
  .layout {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  .panel-wide {
    grid-column: 1 / -1;
  }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  min-width: 0;
}

.hint,
.meta {
  color: var(--muted);
  font-size: 0.925rem;
}

/* Forms */
.form {
  display: grid;
  gap: 0.35rem;
  margin-bottom: 0.5rem;
}

.form .hint {
  margin-bottom: 0.5rem;
}

label {
  font-weight: 600;
}

input,
textarea,
select {
  width: 100%;
  max-width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--control-border);
  border-radius: 0.375rem;
  padding: 0.5rem 0.625rem;
}

textarea {
  resize: vertical;
}

.form-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.5rem;
}

@media (min-width: 36rem) {
  .form-row {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 2.75rem;
  padding: 0.5rem 1rem;
  font: inherit;
  font-weight: 600;
  border-radius: 0.375rem;
  border: 2px solid var(--primary);
  cursor: pointer;
  justify-self: start;
}

.btn-primary {
  background: var(--primary);
  color: var(--on-primary);
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

.btn-secondary {
  background: transparent;
  color: var(--secondary-text);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-alt);
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0.75rem 0;
}

/* Voice controls */
.voice-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1rem;
}

.voice-toggle .toggle-state {
  display: inline-block;
  min-width: 2.25rem;
  padding: 0 0.35rem;
  border-radius: 999px;
  background: var(--on-primary);
  color: var(--primary);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.voice-toggle[aria-pressed="true"] {
  background: var(--surface);
  color: var(--secondary-text);
}

.voice-toggle[aria-pressed="true"] .toggle-state {
  background: var(--primary);
  color: var(--on-primary);
}

/* "Issue preview ready" banner next to the voice controls, shown while a preview is pending. */
.banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
  margin-top: 0.75rem;
  padding: 0.75rem;
  background: var(--user-bubble);
  border: 2px solid var(--primary);
  border-left-width: 6px;
  border-radius: var(--radius);
}

.banner-text {
  margin: 0;
  font-weight: 700;
}

.voice-state p {
  margin: 0;
}

.status-line {
  min-height: 1.5em;
  margin: 0.25rem 0;
}

.mode-line {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--muted);
}

.mode-dot {
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 50%;
  background: var(--idle);
  flex: none;
}

.mode-line[data-mode="listening"] .mode-dot {
  background: var(--listening);
}

.mode-line[data-mode="speaking"] .mode-dot {
  background: var(--speaking);
  animation: pulse 1.1s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.35); opacity: 0.7; }
}

/* Messages */
.error,
.success,
.note {
  padding: 0.5rem 0.75rem;
  border-radius: 0.375rem;
}

.error {
  color: var(--error);
  background: var(--error-bg);
  border-left: 4px solid var(--error);
}

.success {
  color: var(--success);
  background: var(--success-bg);
  border-left: 4px solid var(--success);
}

.note {
  color: var(--note-text);
  background: var(--note-bg);
}

.status-line.is-error {
  color: var(--error);
}

/* Transcript */
.transcript {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.5rem;
  max-height: 24rem;
  overflow-y: auto;
}

.transcript li {
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  background: var(--agent-bubble);
  white-space: pre-wrap;
}

.transcript li.from-user {
  background: var(--user-bubble);
}

.transcript .speaker {
  display: block;
  font-weight: 700;
  font-size: 0.85rem;
}

/* Answer, sources, candidates */
.answer-text {
  white-space: pre-wrap;
}

.card-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.5rem;
}

.card-list li {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 0.75rem;
  background: var(--surface-alt);
}

.card-list .card-title {
  display: block;
  font-weight: 700;
}

.card-list .card-meta {
  display: block;
  color: var(--muted);
  font-size: 0.875rem;
}

.card-list .card-text {
  margin: 0.25rem 0 0;
  white-space: pre-wrap;
}

.ai-label {
  font-weight: 700;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.kv {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 0.25rem 0.75rem;
  margin: 0 0 0.75rem;
}

.kv dt {
  font-weight: 600;
}

.kv dd {
  margin: 0;
  min-width: 0;
}

.tags {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.tags li {
  font-family: var(--mono);
  font-size: 0.85rem;
  padding: 0 0.4rem;
  border: 1px solid var(--control-border);
  border-radius: 0.25rem;
}

.verdict {
  font-size: 1.05rem;
}

.proposal {
  margin-top: 1rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
  scroll-margin-top: 0.75rem;
}

/* A pending (confirmable) preview is framed so it stands out from the rest of the result. */
.proposal.is-pending {
  padding: 0.5rem 0.75rem 0.75rem;
  border: 3px solid var(--primary);
  border-radius: var(--radius);
}

/* Set only by the "pending but not visible" guard in voice.js. */
.proposal.is-forced-visible {
  display: block !important;
  visibility: visible !important;
}

/* Headings that receive focus from script (tabindex="-1") show a ring however focus arrived. */
h3[tabindex="-1"]:focus {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

/* A preview that replaced a pending one is outlined until it is confirmed or cancelled.
   The border colour is the note text colour (>= 3:1 on the surface in both themes). */
.proposal.is-changed {
  padding: 0.5rem 0.75rem 0.75rem;
  border: 3px solid var(--note-text);
  border-radius: var(--radius);
}

.note-changed {
  font-weight: 600;
  border-left: 4px solid var(--note-text);
}

#voice-fallback {
  margin-top: 0.5rem;
}

.pre-label {
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.issue-body {
  margin: 0;
  padding: 0.75rem;
  /* Capped by the viewport too, so Confirm and Cancel stay on screen with the heading. */
  max-height: min(22rem, 35vh);
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: var(--mono);
  font-size: 0.875rem;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 0.375rem;
}

details.typed-bug {
  margin-bottom: 0.75rem;
}

details.typed-bug summary {
  cursor: pointer;
  font-weight: 600;
  padding: 0.25rem 0;
}

details.typed-bug[open] summary {
  margin-bottom: 0.5rem;
}

/* ---------------------------------------------------------------------------------------
   Main page (index.html)
   --------------------------------------------------------------------------------------- */

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

.hero h1 {
  font-size: clamp(1.5rem, 1.1rem + 2vw, 2.25rem);
}

.hero .title-sub {
  font-weight: 600;
}

.lead {
  font-size: 1.075rem;
  max-width: 48rem;
}

.demo-note {
  max-width: 48rem;
  border-left: 4px solid var(--note-text);
}

.link-row {
  list-style: none;
  margin: 0.5rem 0 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1.25rem;
}

.link-row a {
  display: inline-block;
  padding: 0.35rem 0;
  font-weight: 600;
}

.home-main {
  max-width: 72rem;
  margin: 0 auto;
  padding: 0 1rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
}

.home-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
  min-width: 0;
}

@media (min-width: 56rem) {
  .home-grid {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }
}

/* "Try these" chips: real buttons, wrapped onto as many lines as needed. */
.chips {
  list-style: none;
  margin: 0 0 0.75rem;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.chips-bugs {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.75rem;
}

@media (min-width: 48rem) {
  .chips-bugs {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.chips li {
  min-width: 0;
  max-width: 100%;
}

.chip {
  min-height: 2.75rem;
  max-width: 100%;
  padding: 0.45rem 0.9rem;
  font: inherit;
  font-weight: 600;
  text-align: left;
  color: var(--secondary-text);
  background: var(--surface-alt);
  border: 2px solid var(--control-border);
  border-radius: 1.5rem;
  cursor: pointer;
  overflow-wrap: anywhere;
}

.chip:hover {
  border-color: var(--primary);
  background: var(--user-bubble);
}

.chip-alt {
  border-style: dashed;
}

.chip-note {
  font-weight: 400;
  color: var(--muted);
}

.chip-caption {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.925rem;
}

.ai-badge {
  display: inline-block;
  margin-left: 0.35rem;
  padding: 0 0.4rem;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  vertical-align: middle;
  color: var(--muted);
  border: 1px solid var(--control-border);
  border-radius: 0.25rem;
}

.file-anyway {
  margin: 0.5rem 0 0.75rem;
  padding: 0.75rem;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.file-anyway .hint {
  margin-bottom: 0.5rem;
}

.limits {
  margin: 0 0 0.5rem;
  padding-left: 1.25rem;
  font-weight: 600;
}

.say-list {
  margin: 0 0 0.75rem;
  padding-left: 1.25rem;
}

.say-list li + li {
  margin-top: 0.35rem;
}

/* "How it works": an HTML flow diagram. Stacks on phones, runs left to right when wide. */
.flow-figure {
  margin: 0 0 1rem;
}

.flow {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1.5rem;
}

.flow li {
  position: relative;
  padding: 0.5rem 0.75rem;
  background: var(--surface-alt);
  border: 2px solid var(--control-border);
  border-radius: var(--radius);
  min-width: 0;
}

.flow li strong,
.flow li span {
  display: block;
}

.flow li span {
  color: var(--muted);
  font-size: 0.875rem;
}

/* Arrows between steps: decorative, so drawn by CSS (not read by screen readers). */
.flow li + li::before {
  content: "";
  position: absolute;
  left: 1.5rem;
  top: -1.4rem;
  width: 0;
  height: 0;
  border-left: 0.5rem solid transparent;
  border-right: 0.5rem solid transparent;
  border-top: 0.9rem solid var(--control-border);
}

.flow-branches {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
  margin-top: 1rem;
}

.flow-branch {
  padding: 0.75rem;
  border: 1px dashed var(--control-border);
  border-radius: var(--radius);
  min-width: 0;
}

.flow-branch-title {
  font-weight: 700;
  margin-bottom: 0.5rem;
}

@media (min-width: 56rem) {
  .flow {
    grid-auto-flow: column;
    grid-auto-columns: minmax(0, 1fr);
    grid-template-columns: none;
    gap: 1.5rem;
  }

  .flow li + li::before {
    left: -1.3rem;
    top: 50%;
    margin-top: -0.5rem;
    border-top: 0.5rem solid transparent;
    border-bottom: 0.5rem solid transparent;
    border-left: 0.9rem solid var(--control-border);
    border-right: 0;
  }

  .flow-branches {
    grid-template-columns: minmax(0, 1fr) minmax(0, 2fr);
  }
}

.scores {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.5rem;
  margin: 0;
}

@media (min-width: 36rem) {
  .scores {
    grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr));
  }
}

.scores > div {
  padding: 0.5rem 0.75rem;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.scores dt {
  font-size: 0.9rem;
  color: var(--muted);
}

.scores dd {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
}

.scores .score-weak {
  border-left: 4px solid var(--note-text);
}

.scores .score-weak .meta {
  font-size: 0.85rem;
  font-weight: 400;
}

#voice,
#ask,
#bug-panel,
#issues-info,
#how {
  scroll-margin-top: 0.75rem;
}

.page-links {
  margin-top: 0.25rem;
}

[hidden] {
  display: none !important;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  /* Without the pulse, speaking is shown by a ring instead of motion. */
  .mode-line[data-mode="speaking"] .mode-dot {
    animation: none;
    box-shadow: 0 0 0 3px var(--surface), 0 0 0 5px var(--speaking);
  }
}
