:root {
  color-scheme: light;
  --ink: #17211f;
  --muted: #5f6e69;
  --line: #d8e1de;
  --line-strong: #b9c9c4;
  --paper: #ffffff;
  --canvas: #f3f6f5;
  --teal: #0b6259;
  --teal-dark: #084a44;
  --teal-soft: #e5f2ef;
  --coral: #c95843;
  --coral-soft: #fbece8;
  --amber: #936418;
  --amber-soft: #fff4d9;
  --green: #247553;
  --green-soft: #e7f4ed;
  --shadow: 0 14px 36px rgba(23, 33, 31, 0.08);
  --focus: 0 0 0 3px rgba(11, 98, 89, 0.22);
  font-family: Inter, "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--canvas);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, #edf5f2 0, var(--canvas) 240px, var(--canvas) 100%);
}

button,
input,
select {
  font: inherit;
}

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

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

a {
  color: inherit;
}

svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 72px;
  padding: 12px max(20px, calc((100vw - 1120px) / 2));
  border-bottom: 1px solid rgba(11, 98, 89, 0.14);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(16px);
  position: sticky;
  top: 0;
  z-index: 20;
}

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

.brand-mark {
  display: grid;
  place-items: center;
  flex: 0 0 42px;
  width: 42px;
  height: 42px;
  border-radius: 6px;
  color: #fff;
  background: var(--teal);
  font-size: 16px;
  font-weight: 800;
}

.brand strong,
.brand small {
  display: block;
  letter-spacing: 0;
}

.brand strong {
  font-size: 15px;
}

.brand small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.language-control select {
  min-height: 40px;
  padding: 0 34px 0 12px;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
}

.icon-link {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  color: var(--teal);
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
}

.icon-link svg {
  width: 20px;
  height: 20px;
}

.icon-link:hover,
.icon-link:focus-visible,
.language-control select:focus {
  border-color: var(--teal);
  box-shadow: var(--focus);
  outline: none;
}

.app-shell {
  width: min(100% - 32px, 960px);
  margin: 34px auto 28px;
}

.stepper {
  margin-bottom: 18px;
}

.stepper ol {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0;
  padding: 0;
  margin: 0;
  list-style: none;
}

.stepper li {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  color: #7b8985;
}

.stepper li:not(:last-child)::after {
  content: "";
  position: absolute;
  z-index: -1;
  top: 15px;
  right: 12px;
  left: 44px;
  height: 1px;
  background: var(--line-strong);
}

.stepper span {
  display: grid;
  place-items: center;
  flex: 0 0 30px;
  width: 30px;
  height: 30px;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  background: var(--canvas);
  font-size: 12px;
  font-weight: 800;
}

.stepper b {
  overflow: hidden;
  font-size: 12px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stepper li.is-active,
.stepper li.is-complete {
  color: var(--teal);
}

.stepper li.is-active span {
  color: #fff;
  border-color: var(--teal);
  background: var(--teal);
}

.stepper li.is-complete span {
  color: var(--teal);
  border-color: var(--teal);
  background: var(--teal-soft);
}

.stepper li.is-complete:not(:last-child)::after {
  background: var(--teal);
}

.screen {
  min-height: 620px;
  padding: clamp(28px, 6vw, 58px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.screen[hidden] {
  display: none;
}

.screen-heading {
  max-width: 750px;
}

.screen-heading.compact {
  max-width: 700px;
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--teal);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2,
p {
  letter-spacing: 0;
}

h1,
h2 {
  margin: 0;
  line-height: 1.18;
}

h1 {
  max-width: 780px;
  font-size: clamp(30px, 5vw, 48px);
}

h2 {
  font-size: 19px;
}

.screen-heading > p:last-child {
  max-width: 680px;
  margin: 20px 0 0;
  color: var(--muted);
  font-size: 17px;
  line-height: 1.75;
}

.feature-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin: 32px 0 38px;
  border-block: 1px solid var(--line);
}

.feature-strip > div {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px;
  color: var(--muted);
  font-size: 14px;
}

.feature-strip > div + div {
  border-left: 1px solid var(--line);
}

.feature-strip svg {
  flex: 0 0 21px;
  width: 21px;
  height: 21px;
  color: var(--teal);
}

.setup-form {
  max-width: 780px;
}

.section-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
}

.section-label p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.field {
  display: grid;
  gap: 7px;
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.field em {
  color: var(--coral);
  font-style: normal;
}

.field input,
.field select {
  width: 100%;
  min-height: 48px;
  padding: 0 13px;
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--paper);
  font-size: 16px;
}

.field input:focus,
.field select:focus {
  border-color: var(--teal);
  box-shadow: var(--focus);
  outline: none;
}

.field-static {
  align-content: center;
  min-height: 72px;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f7f9f8;
}

.field-static strong {
  color: var(--ink);
  font-size: 16px;
}

.check-panel {
  display: grid;
  gap: 12px;
  margin: 24px 0 0;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8faf9;
}

.check-panel legend {
  padding: 0 7px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 800;
}

.check-panel label,
.confirmation-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  color: #3d4b47;
  font-size: 14px;
  line-height: 1.5;
}

.check-panel input,
.confirmation-row input {
  flex: 0 0 19px;
  width: 19px;
  height: 19px;
  margin: 1px 0 0;
  accent-color: var(--teal);
}

.inline-message {
  min-height: 24px;
  margin: 14px 0 8px;
  color: var(--coral);
  font-size: 13px;
  font-weight: 700;
}

.inline-message[data-tone="success"] {
  color: var(--green);
}

.inline-message[data-tone="warning"] {
  color: var(--coral);
}

.primary-button,
.text-button,
.small-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-height: 46px;
  padding: 0 18px;
  border-radius: 6px;
  font-weight: 800;
  text-decoration: none;
}

.primary-button {
  color: #fff;
  border: 1px solid var(--teal);
  background: var(--teal);
}

.primary-button svg {
  width: 18px;
  height: 18px;
}

.primary-button:hover:not(:disabled),
.primary-button:focus-visible {
  border-color: var(--teal-dark);
  background: var(--teal-dark);
  box-shadow: var(--focus);
  outline: none;
}

.primary-button:disabled {
  color: #93a39e;
  border-color: #d7dfdc;
  background: #e7ecea;
}

.text-button {
  color: var(--teal);
  border: 1px solid var(--line-strong);
  background: var(--paper);
}

.text-button:hover,
.text-button:focus-visible,
.small-button:hover,
.small-button:focus-visible {
  border-color: var(--teal);
  box-shadow: var(--focus);
  outline: none;
}

.screen-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 28px;
}

.load-panel {
  margin: 28px 0 24px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8faf9;
}

.load-status {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
}

.status-indicator {
  display: block;
  width: 12px;
  height: 12px;
  border: 2px solid var(--teal);
  border-radius: 50%;
}

[data-state="loading"] > .load-status .status-indicator,
.upload-panel[data-state="uploading"] .status-indicator {
  border-right-color: transparent;
  animation: spin 0.8s linear infinite;
}

.load-panel[data-state="ready"] .status-indicator,
.upload-panel[data-state="saved"] .status-indicator {
  border-color: var(--green);
  background: var(--green);
}

.load-panel[data-state="error"] .status-indicator,
.upload-panel[data-state="failed"] .status-indicator {
  border-color: var(--coral);
  background: var(--coral);
}

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

.load-status strong,
.load-status span {
  display: block;
}

.load-status strong {
  color: var(--ink);
  font-size: 14px;
}

.load-status span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.load-status > b {
  color: var(--teal);
  font-size: 13px;
}

.progress-track,
.trial-progress {
  height: 5px;
  overflow: hidden;
  background: #dfe7e4;
}

.progress-track {
  margin-top: 13px;
  border-radius: 3px;
}

.progress-track span,
.trial-progress span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--teal);
  transition: width 180ms ease;
}

.calibration-workspace {
  border-block: 1px solid var(--line);
}

.listen-control {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 26px 0;
}

.listen-control p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.listen-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  flex: 0 0 170px;
  min-height: 48px;
  color: var(--teal);
  border: 1px solid var(--teal);
  border-radius: 6px;
  background: var(--paper);
  font-weight: 800;
}

.listen-button svg {
  width: 19px;
  height: 19px;
}

.listen-button .icon-stop {
  display: none;
}

.listen-button.is-playing {
  color: #fff;
  background: var(--teal);
}

.listen-button.is-playing .icon-play {
  display: none;
}

.listen-button.is-playing .icon-stop {
  display: block;
}

.listen-button:disabled {
  color: #9ba8a4;
  border-color: var(--line);
  background: #eef2f0;
}

.volume-control {
  display: grid;
  gap: 15px;
  padding: 26px 0;
  border-top: 1px solid var(--line);
}

.volume-label {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 800;
}

.volume-label output {
  color: var(--teal);
  font-variant-numeric: tabular-nums;
}

.range-wrap {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) 22px;
  align-items: center;
  gap: 12px;
  color: var(--muted);
}

.range-wrap svg {
  width: 22px;
  height: 22px;
}

.range-wrap input {
  width: 100%;
  accent-color: var(--teal);
}

.confirmation-row {
  padding: 20px 0;
  border-top: 1px solid var(--line);
}

.screening-screen {
  min-height: 730px;
}

.screening-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.screening-header h1 {
  font-size: 30px;
  font-variant-numeric: tabular-nums;
}

.test-status {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 138px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  background: #f8faf9;
  font-size: 13px;
}

.test-status span {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #82908c;
}

.test-status[data-state="playing"] {
  color: var(--teal);
  border-color: #b9d9d2;
  background: var(--teal-soft);
}

.test-status[data-state="playing"] span {
  background: var(--teal);
  animation: pulse 1.1s ease-in-out infinite;
}

.test-status[data-state="response"] {
  color: var(--amber);
  border-color: #e9ce94;
  background: var(--amber-soft);
}

.test-status[data-state="response"] span {
  background: var(--amber);
}

.test-status[data-state="error"] {
  color: var(--coral);
  border-color: #e4b8af;
  background: var(--coral-soft);
}

.test-status[data-state="error"] span {
  background: var(--coral);
}

@keyframes pulse {
  50% { opacity: 0.35; }
}

.trial-progress {
  margin: 16px 0 0;
}

.test-stage {
  display: grid;
  justify-items: center;
  grid-template-rows: 54px 54px 78px 336px;
  gap: 15px;
  width: min(100%, 430px);
  margin: 32px auto 0;
}

.test-stage > p {
  align-self: center;
  margin: 0;
  color: var(--muted);
  text-align: center;
  line-height: 1.5;
}

.play-trial-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-width: 150px;
  height: 48px;
  color: #fff;
  border: 1px solid var(--teal);
  border-radius: 6px;
  background: var(--teal);
  font-weight: 800;
}

.play-trial-button svg {
  width: 20px;
  height: 20px;
}

.play-trial-button:disabled {
  visibility: hidden;
}

.digit-display {
  display: grid;
  grid-template-columns: repeat(2, 60px);
  align-items: center;
  gap: 10px;
  height: 78px;
}

.digit-display span {
  display: grid;
  place-items: center;
  width: 60px;
  height: 66px;
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fbfcfc;
  font-size: 29px;
  font-weight: 800;
}

.digit-display span.is-filled {
  border-color: var(--teal);
  background: var(--teal-soft);
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 92px);
  grid-auto-rows: 66px;
  gap: 10px;
  width: 296px;
  height: 294px;
  align-self: start;
}

.keypad button {
  min-width: 0;
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--paper);
  font-size: 22px;
  font-weight: 750;
}

.keypad button:hover:not(:disabled),
.keypad button:focus-visible {
  color: var(--teal);
  border-color: var(--teal);
  background: var(--teal-soft);
  box-shadow: var(--focus);
  outline: none;
}

.keypad .keypad-icon svg {
  width: 23px;
  height: 23px;
}

.keypad .keypad-submit {
  color: #fff;
  border-color: var(--teal);
  background: var(--teal);
  font-size: 15px;
}

.keypad.is-disabled {
  opacity: 0.48;
}

.keypad.is-disabled button {
  pointer-events: none;
}

.outcome-panel {
  text-align: center;
}

.outcome-icon {
  display: grid;
  place-items: center;
  width: 66px;
  height: 66px;
  margin: 0 auto 20px;
  border-radius: 50%;
}

.outcome-icon svg {
  display: none;
  width: 32px;
  height: 32px;
}

.outcome-panel[data-outcome="pass"] .outcome-icon {
  color: var(--green);
  background: var(--green-soft);
}

.outcome-panel[data-outcome="pass"] .outcome-pass {
  display: block;
}

.outcome-panel[data-outcome="refer"] .outcome-icon {
  color: var(--coral);
  background: var(--coral-soft);
}

.outcome-panel[data-outcome="refer"] .outcome-refer {
  display: block;
}

.outcome-panel h1 {
  margin: 0 auto;
  font-size: clamp(28px, 5vw, 42px);
}

.outcome-panel > p:not(.eyebrow) {
  max-width: 630px;
  margin: 15px auto 0;
  color: var(--muted);
  line-height: 1.65;
}

.result-metric {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: baseline;
  gap: 8px;
  width: min(100%, 430px);
  margin: 28px auto 0;
  padding: 18px 20px;
  border-block: 1px solid var(--line);
  text-align: left;
}

.result-metric span {
  color: var(--muted);
  font-size: 13px;
}

.result-metric strong {
  color: var(--ink);
  font-size: 28px;
  font-variant-numeric: tabular-nums;
}

.result-metric small {
  color: var(--muted);
}

.next-step-panel {
  max-width: 720px;
  margin: 36px auto 0;
  padding: 22px 0;
  border-block: 1px solid var(--line);
}

.next-step-panel p {
  color: var(--muted);
  line-height: 1.65;
}

.next-step-panel .result-limit {
  margin-bottom: 0;
  color: #74817d;
  font-size: 12px;
}

.upload-panel {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  max-width: 720px;
  margin: 18px auto 0;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8faf9;
}

.upload-panel strong {
  font-size: 13px;
}

.upload-panel p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.small-button {
  min-height: 34px;
  padding: 0 12px;
  color: var(--teal);
  border: 1px solid var(--line-strong);
  background: var(--paper);
  font-size: 12px;
}

.result-actions {
  max-width: 720px;
  margin-inline: auto;
}

.site-footer {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  width: min(100% - 32px, 960px);
  margin: 0 auto;
  padding: 0 0 28px;
  color: #74817d;
  font-size: 11px;
}

@media (max-width: 720px) {
  .topbar {
    min-height: 64px;
    padding-inline: 16px;
  }

  .brand small {
    display: none;
  }

  .app-shell {
    width: min(100% - 20px, 960px);
    margin-top: 20px;
  }

  .screen {
    min-height: 0;
    padding: 28px 20px;
  }

  .stepper b {
    display: none;
  }

  .stepper li {
    gap: 0;
  }

  .stepper li:not(:last-child)::after {
    right: 7px;
    left: 36px;
  }

  h1 {
    font-size: clamp(28px, 9vw, 38px);
  }

  .feature-strip {
    grid-template-columns: 1fr;
    margin-block: 26px 30px;
  }

  .feature-strip > div {
    padding: 13px 4px;
  }

  .feature-strip > div + div {
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .section-label {
    display: block;
  }

  .section-label p {
    margin-top: 7px;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .listen-control {
    display: grid;
  }

  .listen-button {
    width: 100%;
  }

  .test-stage {
    grid-template-rows: 58px 54px 76px 318px;
    margin-top: 22px;
  }

  .keypad {
    grid-template-columns: repeat(3, minmax(72px, 88px));
    grid-auto-rows: 61px;
    width: min(100%, 284px);
    height: 274px;
  }

  .screen-actions,
  .site-footer {
    align-items: stretch;
    flex-direction: column;
  }

  .screen-actions > * {
    width: 100%;
  }

  .result-actions {
    flex-direction: column-reverse;
  }

  .site-footer {
    text-align: center;
  }
}

@media (max-width: 410px) {
  .brand-mark {
    flex-basis: 38px;
    width: 38px;
    height: 38px;
  }

  .brand strong {
    font-size: 14px;
  }

  .language-control select {
    width: 96px;
    padding-left: 8px;
  }

  .screen {
    padding-inline: 16px;
  }

  .test-status {
    min-width: 0;
  }

  .test-status b {
    display: none;
  }
}

@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;
  }
}
