:root {
  color-scheme: light;
  --page: #eef2fb;
  --surface: #ffffff;
  --surface-soft: #f8f9fe;
  --surface-blue: #e8effe;
  --ink: #0d1630;
  --muted: #66708a;
  --blue: #3567dc;
  --blue-dark: #1b3a6b;
  --blue-deep: #112d59;
  --blue-ring: rgba(59, 111, 232, 0.22);
  --green: #18794e;
  --green-soft: #e5f6ee;
  --red: #c63f55;
  --red-soft: #fff0f2;
  --line: #dfe4f0;
  --focus: #ffb000;
  --shadow: 0 24px 64px rgba(27, 58, 107, 0.16);
  --shadow-soft: 0 12px 32px rgba(27, 58, 107, 0.1);
  --radius-sm: 12px;
  --radius: 20px;
  --radius-lg: 28px;
  --text-sm: 0.8125rem;
  --text-base: 1rem;
  --text-lg: 1.25rem;
  --text-display: clamp(1.9rem, 7vw, 2.25rem);
  font-family: Inter, ui-rounded, "SF Pro Display", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--page);
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  background:
    radial-gradient(circle at 20% 0%, rgba(59, 111, 232, 0.15), transparent 25rem),
    linear-gradient(180deg, #f6f8fd, var(--page));
  color: var(--ink);
  font-size: var(--text-base);
  line-height: 1.5;
}

button,
select,
input {
  font: inherit;
}

button,
a,
select,
label {
  -webkit-tap-highlight-color: transparent;
}

button,
a {
  touch-action: manipulation;
}

button:focus-visible,
a:focus-visible,
select:focus-visible,
input:focus-visible + .check-box,
input:focus-visible ~ .radio-dot {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

a {
  color: inherit;
}

svg {
  display: block;
}

h1,
h2,
p,
figure,
fieldset {
  margin-top: 0;
}

h1 {
  margin-bottom: 12px;
  font-size: var(--text-display);
  line-height: 1.08;
  letter-spacing: -0.035em;
}

h2 {
  margin-bottom: 8px;
  font-size: var(--text-lg);
  line-height: 1.2;
}

p {
  color: var(--muted);
}

[hidden] {
  display: none !important;
}

.sr-only,
.skip-link:not(:focus) {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link:focus {
  position: fixed;
  z-index: 1000;
  top: 12px;
  left: 12px;
  border-radius: var(--radius-sm);
  background: var(--ink);
  color: #fff;
  padding: 12px 16px;
}

.demo-shell {
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: var(--surface-soft);
}

.app-header {
  position: sticky;
  z-index: 20;
  top: 0;
  min-height: 72px;
  display: grid;
  grid-template-columns: 44px 1fr auto;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid rgba(223, 228, 240, 0.88);
  background: rgba(248, 249, 254, 0.94);
  padding: max(12px, env(safe-area-inset-top)) 16px 12px;
  backdrop-filter: blur(18px);
}

.back-link {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--blue-dark);
  text-decoration: none;
}

.back-link:hover {
  background: var(--surface-blue);
}

.back-link svg {
  width: 24px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.app-brand {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  text-decoration: none;
}

.app-brand strong,
.app-brand small {
  display: block;
  line-height: 1.15;
}

.app-brand strong {
  font-size: var(--text-base);
}

.app-brand small {
  color: var(--muted);
  font-size: var(--text-sm);
}

.brand-icon {
  width: 38px;
  height: 38px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  background: linear-gradient(145deg, var(--blue-deep), var(--blue));
  box-shadow: 0 8px 18px rgba(59, 111, 232, 0.24), inset 0 1px rgba(255, 255, 255, 0.25);
}

.brand-icon svg {
  width: 26px;
  fill: none;
  stroke: #fff;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.demo-badge,
.test-phase,
.ear-chip,
.step-kicker {
  font-size: var(--text-sm);
  font-weight: 700;
}

.demo-badge {
  border: 1px solid rgba(59, 111, 232, 0.22);
  border-radius: 999px;
  background: var(--surface-blue);
  color: var(--blue-dark);
  padding: 6px 10px;
}

.app-main {
  min-width: 0;
}

.screen {
  width: 100%;
  min-height: calc(100dvh - 118px);
  padding: 32px 20px max(48px, calc(24px + env(safe-area-inset-bottom)));
}

.screen:focus {
  outline: none;
}

.screen.is-centered {
  min-height: calc(100dvh - 118px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.screen.is-centered > p {
  max-width: 32rem;
}

.screen-heading {
  margin-bottom: 28px;
}

.screen-heading > p {
  max-width: 34rem;
  margin-bottom: 0;
}

.step-kicker {
  display: block;
  margin-bottom: 8px;
  color: var(--blue);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.loader {
  width: 48px;
  height: 48px;
  border: 4px solid var(--surface-blue);
  border-top-color: var(--blue);
  border-radius: 50%;
  margin-bottom: 24px;
  animation: spin 900ms linear infinite;
}

.loader.small {
  width: 36px;
  height: 36px;
  border-width: 3px;
  margin-bottom: 20px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.type-fieldset {
  min-width: 0;
  border: 0;
  margin-bottom: 28px;
  padding: 0;
}

.type-fieldset legend,
.field-group > label {
  display: block;
  margin-bottom: 12px;
  color: var(--ink);
  font-weight: 700;
}

.type-card {
  position: relative;
  min-height: 80px;
  display: grid;
  grid-template-columns: 48px 1fr 24px;
  align-items: center;
  gap: 12px;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 12px 16px;
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease, box-shadow 160ms ease;
}

.type-card + .type-card {
  margin-top: 12px;
}

.type-card:hover {
  transform: translateY(-1px);
  border-color: #b9c7e9;
  box-shadow: var(--shadow-soft);
}

.type-card:has(input:checked) {
  border-color: var(--blue);
  background: #f5f8ff;
  box-shadow: 0 0 0 4px var(--blue-ring);
}

.type-card input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.type-card strong,
.type-card small {
  display: block;
}

.type-card small {
  margin-top: 2px;
  color: var(--muted);
  font-size: var(--text-sm);
}

.type-card-icon {
  width: 48px;
  height: 48px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  background: var(--surface-blue);
  color: var(--blue-dark);
}

.type-card-icon svg {
  width: 30px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.radio-dot {
  width: 22px;
  height: 22px;
  border: 2px solid #aeb8cc;
  border-radius: 50%;
  box-shadow: inset 0 0 0 4px var(--surface);
}

.type-card:has(input:checked) .radio-dot {
  border-color: var(--blue);
  background: var(--blue);
}

.field-group {
  margin-bottom: 24px;
}

.select-wrap {
  position: relative;
}

.select-wrap select {
  width: 100%;
  min-height: 56px;
  appearance: none;
  border: 2px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  padding: 0 48px 0 16px;
}

.select-wrap select:enabled:hover {
  border-color: #b9c7e9;
}

.select-wrap select:disabled {
  color: var(--muted);
  opacity: 0.76;
}

.select-wrap svg {
  position: absolute;
  top: 50%;
  right: 16px;
  width: 22px;
  transform: translateY(-50%);
  fill: none;
  stroke: var(--muted);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
  pointer-events: none;
}

.field-help {
  margin: 8px 0 0;
  font-size: var(--text-sm);
}

.privacy-note,
.clinical-note {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 12px;
  border: 1px solid rgba(59, 111, 232, 0.18);
  border-radius: var(--radius);
  background: var(--surface-blue);
  padding: 16px;
}

.privacy-note {
  margin-bottom: 28px;
}

.privacy-note svg,
.clinical-note svg {
  width: 28px;
  fill: none;
  stroke: var(--blue-dark);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.privacy-note strong,
.privacy-note span,
.clinical-note strong,
.clinical-note span {
  display: block;
}

.privacy-note span,
.clinical-note span {
  margin-top: 2px;
  color: var(--muted);
  font-size: var(--text-sm);
}

.button {
  width: 100%;
  min-height: 56px;
  border: 2px solid transparent;
  border-radius: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  font-weight: 700;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.button svg {
  width: 22px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.button:hover:not(:disabled) {
  transform: translateY(-1px);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.46;
}

.button-primary {
  background: linear-gradient(145deg, var(--blue-dark), var(--blue));
  color: #fff;
  box-shadow: 0 14px 28px rgba(59, 111, 232, 0.23), inset 0 1px rgba(255, 255, 255, 0.24);
}

.button-secondary {
  border-color: var(--line);
  background: var(--surface);
  color: var(--blue-dark);
}

.button-quiet {
  background: transparent;
  color: var(--muted);
}

.sticky-action {
  position: sticky;
  bottom: 0;
  z-index: 10;
  margin: 0 -20px -48px;
  background: linear-gradient(180deg, rgba(248, 249, 254, 0), var(--surface-soft) 30%);
  padding: 28px 20px max(24px, calc(16px + env(safe-area-inset-bottom)));
}

.action-stack {
  display: grid;
  gap: 12px;
}

.instruction-list {
  list-style: none;
  margin: 0 0 28px;
  padding: 0;
}

.instruction-list li {
  display: grid;
  grid-template-columns: 40px 1fr;
  gap: 12px;
  align-items: start;
}

.instruction-list li + li {
  margin-top: 20px;
}

.instruction-list li > span {
  width: 40px;
  height: 40px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: var(--surface-blue);
  color: var(--blue-dark);
  font-weight: 700;
}

.instruction-list strong {
  display: block;
  margin-bottom: 2px;
}

.instruction-list p {
  margin-bottom: 0;
  font-size: var(--text-sm);
}

.acknowledgements {
  display: grid;
  gap: 12px;
  margin-bottom: 24px;
}

.check-row {
  position: relative;
  min-height: 64px;
  display: grid;
  grid-template-columns: 28px 1fr;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 14px 16px;
  cursor: pointer;
}

.check-row input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.check-box {
  width: 26px;
  height: 26px;
  border: 2px solid #aeb8cc;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--surface);
}

.check-box svg {
  width: 18px;
  fill: none;
  stroke: transparent;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 3;
}

.check-row:has(input:checked) {
  border-color: var(--blue);
  background: #f5f8ff;
}

.check-row input:checked + .check-box {
  border-color: var(--blue);
  background: var(--blue);
}

.check-row input:checked + .check-box svg {
  stroke: #fff;
}

.test-screen {
  display: flex;
  flex-direction: column;
}

.test-header,
.progress-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.test-header h1 {
  margin-bottom: 0;
  font-size: var(--text-lg);
  letter-spacing: -0.01em;
}

.test-phase {
  color: var(--blue);
}

.ear-chip {
  border-radius: 999px;
  background: var(--surface-blue);
  color: var(--blue-dark);
  padding: 8px 12px;
}

.progress-meta {
  margin-top: 24px;
  color: var(--muted);
  font-size: var(--text-sm);
}

.test-progress {
  width: 100%;
  height: 10px;
  appearance: none;
  border: 0;
  border-radius: 999px;
  overflow: hidden;
  margin-top: 8px;
  background: var(--line);
}

.test-progress::-webkit-progress-bar {
  background: var(--line);
}

.test-progress::-webkit-progress-value {
  border-radius: 999px;
  background: linear-gradient(90deg, var(--blue-dark), var(--blue));
}

.test-progress::-moz-progress-bar {
  border-radius: 999px;
  background: linear-gradient(90deg, var(--blue-dark), var(--blue));
}

.tone-stage {
  min-height: 430px;
  display: grid;
  place-items: center;
  flex: 1;
  padding: 32px 0;
  text-align: center;
}

.tone-stage > div {
  width: 100%;
}

.tone-stage p {
  margin-bottom: 0;
}

.sound-pulse {
  position: relative;
  width: 152px;
  height: 152px;
  display: grid;
  place-items: center;
  margin: 0 auto 32px;
}

.sound-pulse::before {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  content: "";
  background: linear-gradient(145deg, var(--blue-dark), var(--blue));
  box-shadow: 0 18px 42px rgba(59, 111, 232, 0.3), inset 0 1px rgba(255, 255, 255, 0.28);
}

.sound-pulse span {
  position: absolute;
  inset: 18px;
  border: 2px solid rgba(59, 111, 232, 0.3);
  border-radius: 50%;
  animation: pulse 1.8s ease-out infinite;
}

.sound-pulse span:nth-child(2) { animation-delay: 600ms; }
.sound-pulse span:nth-child(3) { animation-delay: 1200ms; }

@keyframes pulse {
  from { opacity: 0.72; transform: scale(0.62); }
  to { opacity: 0; transform: scale(1.18); }
}

.tone-question h2 {
  font-size: var(--text-display);
  font-weight: 500;
}

.tone-question h2:focus {
  outline: none;
}

.response-buttons {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 40px;
}

.response-button {
  min-width: 0;
  aspect-ratio: 1;
  border: 4px solid currentColor;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  cursor: pointer;
  box-shadow: var(--shadow-soft), inset 0 1px rgba(255, 255, 255, 0.72);
  transition: transform 150ms ease, background 150ms ease;
}

.response-button:hover {
  transform: translateY(-2px) scale(1.015);
}

.response-button:active {
  transform: scale(0.97);
}

.response-button.heard {
  color: var(--blue);
}

.response-button.not-heard {
  color: var(--red);
}

.response-button.heard:hover {
  background: #f4f7ff;
}

.response-button.not-heard:hover {
  background: var(--red-soft);
}

.response-button svg {
  width: 32px;
  margin-bottom: 4px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.4;
}

.response-button span {
  color: currentColor;
  font-size: var(--text-lg);
  font-weight: 700;
}

.response-button small {
  color: var(--muted);
  font-size: var(--text-sm);
}

.tone-waiting {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.live-status {
  min-height: 24px;
  margin: 0;
  text-align: center;
  font-size: var(--text-sm);
}

.end-test {
  min-width: 96px;
  min-height: 44px;
  align-self: center;
  border: 0;
  background: transparent;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 4px;
  cursor: pointer;
}

.result-celebration {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  margin: 0 auto 20px;
  background: var(--green-soft);
  color: var(--green);
  box-shadow: 0 0 0 10px rgba(24, 121, 78, 0.07);
}

.result-celebration svg {
  width: 34px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.4;
}

.result-heading {
  text-align: center;
}

.audiogram-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

.audiogram-chart {
  width: 100%;
  height: auto;
  background: #fff;
}

.audiogram-card figcaption {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px 20px;
  border-top: 1px solid var(--line);
  padding: 12px;
  color: var(--muted);
  font-size: var(--text-sm);
}

.audiogram-card figcaption span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-o {
  width: 14px;
  height: 14px;
  border: 2px solid #c43d4f;
  border-radius: 50%;
}

.legend-x,
.legend-nr {
  color: #2962c5;
  font-style: normal;
  font-weight: 700;
}

.legend-nr {
  color: var(--muted);
}

.values-panel {
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.values-panel summary {
  min-height: 48px;
  display: flex;
  align-items: center;
  padding: 10px 16px;
  color: var(--blue-dark);
  font-weight: 700;
  cursor: pointer;
}

.table-scroll {
  overflow-x: auto;
  border-top: 1px solid var(--line);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

th,
td {
  min-width: 88px;
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
  text-align: center;
}

th {
  color: var(--muted);
  font-size: var(--text-sm);
}

.clinical-note {
  margin-top: 16px;
  border-color: rgba(24, 121, 78, 0.18);
  background: var(--green-soft);
}

.clinical-note svg {
  stroke: var(--green);
}

.result-privacy {
  margin: 16px 0 24px;
  text-align: center;
  font-size: var(--text-sm);
}

.error-icon {
  width: 72px;
  height: 72px;
  border-radius: 24px;
  display: grid;
  place-items: center;
  margin-bottom: 24px;
  background: var(--red-soft);
  color: var(--red);
}

.error-icon svg {
  width: 38px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.error-actions {
  width: min(100%, 360px);
  margin-top: 16px;
}

.app-footer {
  min-height: 46px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 16px;
  border-top: 1px solid var(--line);
  padding: 12px 16px max(12px, env(safe-area-inset-bottom));
  color: var(--muted);
  font-size: var(--text-sm);
  text-align: center;
}

@media (min-width: 600px) {
  body {
    padding: 32px;
  }

  .demo-shell {
    width: min(100%, 500px);
    min-height: calc(100vh - 64px);
    min-height: calc(100dvh - 64px);
    margin: 0 auto;
    overflow: clip;
    border: 1px solid rgba(223, 228, 240, 0.9);
    border-radius: 32px;
    box-shadow: var(--shadow);
  }

  .app-header {
    border-radius: 32px 32px 0 0;
  }

  .screen,
  .screen.is-centered {
    min-height: calc(100dvh - 182px);
    padding-right: 28px;
    padding-left: 28px;
  }

  .sticky-action {
    margin-right: -28px;
    margin-left: -28px;
    padding-right: 28px;
    padding-left: 28px;
  }

  .response-buttons {
    gap: 24px;
  }
}

@media (max-width: 359px) {
  .screen {
    padding-right: 16px;
    padding-left: 16px;
  }

  .app-brand small,
  .demo-badge {
    display: none;
  }

  .type-card {
    padding-right: 12px;
    padding-left: 12px;
  }

  .sticky-action {
    margin-right: -16px;
    margin-left: -16px;
    padding-right: 16px;
    padding-left: 16px;
  }

  .response-buttons {
    gap: 10px;
  }
}

@media (max-height: 799px) {
  .sticky-action {
    position: static;
    margin: 12px 0 0;
    background: transparent;
    padding: 16px 0 max(16px, env(safe-area-inset-bottom));
  }
}

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

@media (forced-colors: active) {
  .button,
  .type-card,
  .check-row,
  .response-button {
    forced-color-adjust: auto;
  }
}
