@font-face { font-family: 'Bowlby One SC'; font-style: normal; font-weight: 400; font-display: swap; src: url('../fonts/bowlby-one-sc-latin.woff2') format('woff2'); }
@font-face { font-family: 'DM Sans'; font-style: normal; font-weight: 500 700; font-display: swap; src: url('../fonts/dm-sans-500-700-latin.woff2') format('woff2'); }

:root {
  color-scheme: dark;
  --page: oklch(17% 0.012 190);
  --surface: oklch(22% 0.014 190);
  --border: oklch(40% 0.018 190);
  --paper: oklch(94% 0.012 95);
  --muted: oklch(73% 0.018 190);
  --cyan: oklch(82% 0.16 205);
  --cyan-dark: oklch(45% 0.09 205);
  --green: oklch(74% 0.15 150);
  --amber: oklch(82% 0.15 83);
  --coral: oklch(70% 0.18 27);
  --ease-out: cubic-bezier(.22, 1, .36, 1);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--page); }
body {
  min-height: 100svh;
  margin: 0;
  background: linear-gradient(180deg, oklch(20% 0.016 190), var(--page) 58%);
  color: var(--paper);
  font-family: 'DM Sans', sans-serif;
  font-size: 1rem;
  letter-spacing: 0;
}
button, select { font: inherit; letter-spacing: 0; }
button { color: inherit; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; margin: -1px; padding: 0; border: 0; clip: rect(0, 0, 0, 0); white-space: nowrap; }
.skip-link { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.skip-link:focus-visible { z-index: 20; left: 12px; top: 8px; width: auto; height: auto; overflow: visible; clip-path: none; padding: 10px 14px; background: var(--cyan); color: var(--page); font-weight: 700; }

.topbar {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px max(18px, env(safe-area-inset-right)) 8px max(18px, env(safe-area-inset-left));
  border-bottom: 1px solid oklch(35% 0.014 190);
  background: oklch(14% 0.01 190);
}
.brand { min-width: 0; display: flex; align-items: center; gap: 10px; color: var(--paper); text-decoration: none; }
.brand-mark { width: 40px; height: 40px; flex: 0 0 40px; display: block; border: 2px solid oklch(55% 0.018 190); border-radius: 3px; object-fit: cover; }
.brand span { overflow: hidden; font: 400 .78rem/1.1 'Bowlby One SC'; text-overflow: ellipsis; white-space: nowrap; }
.brand i { color: var(--cyan); font-style: normal; }
.back-link { min-height: 44px; display: inline-flex; align-items: center; color: var(--muted); font-size: .875rem; font-weight: 700; text-underline-offset: 3px; white-space: nowrap; }

main { width: min(680px, 100%); margin: 0 auto; padding: 24px 18px max(40px, env(safe-area-inset-bottom)); }
.stage {
  min-height: calc(100svh - 128px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.step-label { margin: 0 0 26px; color: var(--cyan); font-size: .8125rem; font-weight: 700; text-transform: uppercase; }
.hero-icon, .result-icon {
  width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
  margin-bottom: 22px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--cyan);
}
.hero-icon svg, .result-icon svg { width: 30px; height: 30px; }
.result-icon { color: var(--green); }
.result-icon.is-warning { color: var(--amber); }
.result-icon.is-error { color: var(--coral); }
h1, p { margin-top: 0; }
h1 { max-width: 18ch; margin-bottom: 14px; font: 400 clamp(1.8rem, 1.5rem + 1vw, 2.35rem)/1.15 'Bowlby One SC'; }
.stage-intro, .result-summary, .error-message { max-width: 47ch; margin-bottom: 28px; color: var(--muted); font-size: 1.0625rem; line-height: 1.55; }

button, select { min-height: 50px; border-radius: 4px; }
button { border: 0; cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .5; }
button:focus-visible, select:focus-visible, summary:focus-visible, audio:focus-visible, a:focus-visible { outline: 3px solid var(--amber); outline-offset: 3px; }
.primary-button, .secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 0 20px;
  font-weight: 700;
  transition: filter 120ms linear, transform 120ms var(--ease-out);
}
.primary-button { background: var(--cyan); color: oklch(16% 0.025 195); }
.secondary-button { border: 1px solid var(--border); background: var(--surface); color: var(--paper); }
.primary-button svg, .secondary-button svg, .privacy-note svg, .fallback-note svg { width: 20px; height: 20px; flex: 0 0 20px; }
.stage-action { width: min(100%, 360px); min-height: 58px; font-size: 1.0625rem; }
.privacy-note { display: flex; align-items: center; justify-content: center; gap: 7px; margin: 14px 0 0; color: var(--muted); font-size: .8125rem; line-height: 1.4; }
.privacy-note svg { color: var(--green); }

.device-form { width: min(100%, 520px); display: grid; gap: 12px; text-align: left; }
.device-form label { color: var(--paper); font-size: .9375rem; font-weight: 700; }
.device-help { margin: -4px 0 0; color: var(--muted); font-size: .8125rem; line-height: 1.4; }
.device-form .stage-action { width: 100%; margin-top: 4px; }

.test-stage { justify-content: center; }
.test-kicker { margin: 0 0 12px; color: var(--cyan); font-size: .875rem; font-weight: 700; text-transform: uppercase; }
.test-prompt { max-width: none; margin-bottom: 16px; color: var(--paper); font-size: clamp(2.5rem, 2rem + 2vw, 4rem); line-height: 1.05; }
.test-stage.is-speaking .test-prompt { color: var(--cyan); }
.speak-instruction { max-width: 34ch; margin-bottom: 24px; color: var(--paper); font-size: clamp(1.15rem, 1rem + .5vw, 1.4rem); font-weight: 700; line-height: 1.4; }
.countdown { display: grid; justify-items: center; margin: 0 0 24px; font-variant-numeric: tabular-nums; }
.countdown strong { font: 400 4.5rem/.9 'Bowlby One SC'; color: var(--paper); }
.countdown span { margin-top: 7px; color: var(--muted); font-size: .75rem; font-weight: 700; text-transform: uppercase; }
.signal-wrap { width: min(100%, 520px); }
.meter { height: 30px; overflow: hidden; padding: 4px; border: 1px solid var(--border); border-radius: 4px; background: oklch(12% 0.012 190); }
.meter i { width: 100%; height: 100%; display: block; border-radius: 2px; background: linear-gradient(90deg, var(--green), var(--amber) 72%, var(--coral)); transform: scaleX(0); transform-origin: left center; transition: transform 70ms linear; }
.meter-label { margin: 8px 0 0; color: var(--muted); font-size: .8125rem; font-weight: 700; }
.melody-answer-row { width: min(100%, 520px); }

.melody-visual {
  width: 112px;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  margin-bottom: 24px;
  color: var(--amber);
}
.melody-visual i { width: 7px; height: 18px; border-radius: 2px; background: currentColor; transform: scaleY(.55); transform-origin: center; }
.melody-visual i:nth-child(2), .melody-visual i:nth-child(5) { height: 34px; }
.melody-visual i:nth-child(3), .melody-visual i:nth-child(4) { height: 52px; }
.melody-visual.is-playing i { animation: melody-pulse 560ms var(--ease-out) infinite alternate; }
.melody-visual.is-playing i:nth-child(2) { animation-delay: 80ms; }
.melody-visual.is-playing i:nth-child(3) { animation-delay: 160ms; }
.melody-visual.is-playing i:nth-child(4) { animation-delay: 240ms; }
.melody-visual.is-playing i:nth-child(5) { animation-delay: 320ms; }
.melody-visual.is-playing i:nth-child(6) { animation-delay: 400ms; }
.melody-answer { width: 100%; margin-top: 8px; }
.melody-answer .answer-row { margin: 0 auto; }

.review-stage, .report-stage { justify-content: flex-start; padding-top: clamp(24px, 6vh, 64px); }
.result-summary { margin-bottom: 22px; }
audio { width: min(100%, 520px); min-height: 48px; display: block; margin: 16px auto 0; }
.playback-status { min-height: 22px; margin: 12px 0 0; color: var(--muted); font-size: .8125rem; }
.review-questions { width: 100%; margin-top: 34px; padding-top: 28px; border-top: 1px solid var(--border); text-align: left; }
fieldset { min-width: 0; margin: 0 0 26px; padding: 0; border: 0; }
legend { margin: 0 auto 12px; color: var(--paper); font-size: 1rem; font-weight: 700; line-height: 1.4; text-align: center; }
.answer-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.answer-row[data-answer-group='voice'] { grid-template-columns: 1fr; }
.answer-row button { min-width: 0; border: 1px solid var(--border); padding: 8px 12px; background: var(--surface); color: var(--muted); font-weight: 700; line-height: 1.25; }
.answer-row button[aria-pressed='true'] { border-color: var(--cyan); background: var(--cyan-dark); color: var(--paper); }
.review-questions .stage-action { display: flex; margin: 8px auto 0; }
.answer-hint { margin: 9px 0 0; color: var(--muted); font-size: .8125rem; text-align: center; }
.fallback-note { width: 100%; display: grid; grid-template-columns: 22px minmax(0, 1fr); gap: 10px; margin-top: 24px; padding: 16px; border-left: 3px solid var(--amber); background: oklch(21% 0.025 83); color: var(--amber); text-align: left; }
.fallback-note p { margin: 0; color: oklch(86% 0.035 83); font-size: .875rem; line-height: 1.5; }

.copy-status { min-height: 21px; margin: 10px 0 24px; color: var(--muted); font-size: .8125rem; line-height: 1.5; }
details { width: 100%; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); text-align: left; }
summary { min-height: 52px; display: flex; align-items: center; color: var(--muted); cursor: pointer; font-size: .875rem; font-weight: 700; }
pre { max-height: 360px; overflow: auto; margin: 0 0 16px; padding: 14px; border: 1px solid var(--border); border-radius: 4px; background: oklch(13% 0.012 190); color: oklch(84% 0.02 190); font: .75rem/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }
select { width: 100%; border: 1px solid var(--border); padding: 0 42px 0 14px; appearance: none; background-color: var(--surface); background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 22px, calc(100% - 13px) 22px; background-repeat: no-repeat; background-size: 5px 5px; color: var(--paper); }
select:disabled { opacity: .62; }
.report-retry { width: min(100%, 360px); margin-top: 28px; }
.report-home { margin-bottom: 14px; border-radius: 4px; text-decoration: none; }
.text-button { min-height: 44px; margin-top: 12px; padding: 0 12px; background: transparent; color: var(--muted); font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }

@keyframes melody-pulse {
  from { opacity: .55; transform: scaleY(.45); }
  to { opacity: 1; transform: scaleY(1); }
}

@media (hover: hover) {
  .primary-button:hover:not(:disabled), .secondary-button:hover:not(:disabled) { filter: brightness(1.08); transform: translateY(-1px); }
  .answer-row button:hover { border-color: var(--muted); color: var(--paper); }
}

@media (max-width: 520px) {
  main { padding-top: 16px; }
  .stage { min-height: calc(100svh - 104px); }
  .brand span { display: none; }
  .step-label { margin-bottom: 20px; }
  .test-prompt { font-size: 2.55rem; }
  .answer-row { grid-template-columns: 1fr; }
  .review-stage, .report-stage { padding-top: 20px; }
}

@media (pointer: coarse) {
  button, select { min-height: 52px; }
  .stage-action { min-height: 60px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
