:root {
  color-scheme: light;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Noto Sans TC", sans-serif;
  --ink: #0f172a;
  --muted: #526176;
  --line: #dbe6ef;
  --blue: #0369a1;
  --blue-dark: #075985;
  --blue-soft: #e0f2fe;
  --teal: #0f766e;
  --surface: #ffffff;
  --danger: #be123c;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: #eaf3f8;
}

body {
  min-height: 100dvh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 20% -10%, rgba(14, 165, 233, 0.2), transparent 35rem),
    linear-gradient(180deg, #eef8fc 0%, #f8fafc 48%, #eaf4f7 100%);
}

button,
input {
  font: inherit;
}

button {
  touch-action: manipulation;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid #facc15;
  outline-offset: 3px;
}

[hidden] {
  display: none !important;
}

.app-shell {
  width: min(100%, 72rem);
  min-height: 100dvh;
  margin: 0 auto;
  background: rgba(248, 250, 252, 0.82);
  box-shadow: 0 0 0 1px rgba(148, 163, 184, 0.16);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: calc(0.9rem + env(safe-area-inset-top)) clamp(1rem, 4vw, 2rem) 0.9rem;
  border-bottom: 1px solid rgba(148, 163, 184, 0.32);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(16px);
}

.topbar h1,
.section-heading h2,
.correction-dialog h2,
.route-error h1 {
  margin: 0;
  letter-spacing: -0.025em;
}

.topbar h1 {
  font-size: clamp(1.35rem, 4vw, 1.8rem);
}

.eyebrow,
.section-kicker {
  margin: 0 0 0.2rem;
  color: var(--blue);
  font-size: 0.7rem;
  font-weight: 900;
  letter-spacing: 0.13em;
}

.patient-label {
  margin: 0.2rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
}

.mode-area {
  display: flex;
  flex-shrink: 0;
  justify-content: flex-end;
}

.mode-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.25rem;
  padding: 0.25rem;
  border: 1px solid #bae6fd;
  border-radius: 0.9rem;
  background: #f0f9ff;
}

.mode-toggle button {
  min-height: 44px;
  border: 0;
  border-radius: 0.7rem;
  padding: 0.55rem 0.75rem;
  color: #475569;
  background: transparent;
  font-size: 0.8rem;
  font-weight: 850;
  cursor: pointer;
}

.mode-toggle button[aria-pressed="true"] {
  color: #ffffff;
  background: var(--blue-dark);
  box-shadow: 0 4px 12px rgba(3, 105, 161, 0.25);
}

.local-only-badge,
.engine-badge,
.scene-request-status {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border-radius: 999px;
  padding: 0.3rem 0.65rem;
  color: var(--blue-dark);
  background: var(--blue-soft);
  font-size: 0.72rem;
  font-weight: 850;
  white-space: nowrap;
}

.content {
  display: grid;
  gap: 1rem;
  padding: 1rem clamp(0.8rem, 3vw, 1.5rem) 11rem;
}

.result-card,
.panel {
  border: 1px solid rgba(186, 230, 253, 0.85);
  border-radius: 1.35rem;
  background: var(--surface);
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.07);
}

.result-card {
  padding: clamp(1rem, 4vw, 1.5rem);
  background:
    linear-gradient(135deg, rgba(224, 242, 254, 0.85), rgba(255, 255, 255, 0.98) 55%),
    #ffffff;
}

.panel {
  padding: clamp(0.9rem, 3vw, 1.25rem);
}

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}

.section-heading h2 {
  font-size: 1.05rem;
}

.section-heading.compact h2 {
  font-size: 1.1rem;
}

.primary-text {
  min-height: 2.8em;
  margin: 1rem 0 0.55rem;
  overflow-wrap: anywhere;
  font-size: clamp(1.65rem, 7vw, 3.25rem);
  font-weight: 900;
  line-height: 1.35;
}

.asr-meta,
.interaction-hint,
.model-label,
.dialog-status {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.5;
}

.asr-meta {
  min-height: 1.3rem;
  margin: 0;
}

.interaction-hint {
  margin: 0.45rem 0 0.8rem;
}

.status-line {
  min-height: 1.5rem;
  margin: -0.25rem 0;
  color: var(--blue-dark);
  font-size: 0.85rem;
  font-weight: 750;
  text-align: center;
}

.candidate-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.65rem;
}

.candidate-button,
.scene-card {
  min-height: 64px;
  border: 1.5px solid var(--line);
  border-radius: 1rem;
  padding: 0.7rem 0.8rem;
  color: var(--ink);
  background: #ffffff;
  text-align: left;
  cursor: pointer;
}

.candidate-button {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 0.65rem;
}

.candidate-button[data-rank="1"] {
  border-color: #38bdf8;
  background: #f0f9ff;
}

.rank-badge {
  display: inline-grid;
  width: 2rem;
  height: 2rem;
  place-items: center;
  border-radius: 999px;
  color: var(--blue-dark);
  background: var(--blue-soft);
  font-size: 0.78rem;
  font-weight: 900;
}

.candidate-text,
.scene-card-text {
  overflow-wrap: anywhere;
  font-size: 1rem;
  font-weight: 850;
  line-height: 1.35;
}

.candidate-button:hover,
.scene-card:hover {
  border-color: #0ea5e9;
  transform: translateY(-1px);
}

.scene-panel {
  border-color: #99f6e4;
  background: linear-gradient(180deg, #f0fdfa 0%, #ffffff 20%);
}

.scene-request-status {
  color: var(--teal);
  background: #ccfbf1;
}

.scene-categories {
  display: grid;
  gap: 0.8rem;
}

.scene-category {
  border: 1px solid #ccfbf1;
  border-radius: 1rem;
  padding: 0.8rem;
  background: rgba(255, 255, 255, 0.9);
}

.scene-category-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
}

.scene-category h3 {
  margin: 0;
  font-size: 1rem;
}

.scene-page-button {
  min-height: 40px;
  border: 1px solid #5eead4;
  border-radius: 999px;
  padding: 0.4rem 0.75rem;
  color: #115e59;
  background: #f0fdfa;
  font-size: 0.75rem;
  font-weight: 850;
  cursor: pointer;
}

.scene-card-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.55rem;
}

.scene-card {
  position: relative;
  min-height: 72px;
  border-color: #99f6e4;
  background: #ffffff;
  text-align: center;
}

.scene-rank {
  display: block;
  margin-bottom: 0.2rem;
  color: var(--teal);
  font-size: 0.67rem;
  font-weight: 900;
}

.scene-empty {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.self-test-panel {
  border-color: #fbbf24;
  background: linear-gradient(180deg, #fffbeb 0%, #ffffff 28%);
}

.self-test-summary {
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  border-radius: 999px;
  padding: 0.3rem 0.65rem;
  color: #92400e;
  background: #fef3c7;
  font-size: 0.72rem;
  font-weight: 850;
}

.self-test-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  margin-bottom: 0.8rem;
}

.self-test-actions button,
.self-test-preset {
  min-height: 44px;
  border: 1px solid #f59e0b;
  border-radius: 0.8rem;
  padding: 0.55rem 0.8rem;
  color: #78350f;
  background: #ffffff;
  font-weight: 800;
  cursor: pointer;
}

.self-test-actions button:disabled,
.self-test-preset:disabled {
  cursor: wait;
  opacity: 0.55;
}

.self-test-presets {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem;
}

.self-test-preset {
  display: grid;
  gap: 0.15rem;
  text-align: left;
}

.self-test-preset small {
  color: var(--muted);
  font-size: 0.68rem;
}

.self-test-results {
  display: grid;
  gap: 0.45rem;
  margin: 0.85rem 0 0;
  padding: 0;
  list-style: none;
}

.self-test-result {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.55rem;
  border: 1px solid #fde68a;
  border-radius: 0.75rem;
  padding: 0.6rem;
  background: #ffffff;
  font-size: 0.78rem;
}

.self-test-result[data-status="pass"] {
  border-color: #86efac;
  background: #f0fdf4;
}

.self-test-result[data-status="fail"] {
  border-color: #fda4af;
  background: #fff1f2;
}

.self-test-result strong {
  color: #92400e;
}

.correction-button {
  min-height: 50px;
  border: 1.5px solid #fda4af;
  border-radius: 1rem;
  padding: 0.75rem 1rem;
  color: var(--danger);
  background: #fff1f2;
  font-weight: 850;
  cursor: pointer;
}

.record-dock {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 9;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.45rem;
  width: min(100%, 72rem);
  margin: 0 auto;
  padding: 0.85rem 1rem calc(0.65rem + env(safe-area-inset-bottom));
  border-top: 1px solid rgba(148, 163, 184, 0.3);
  background: rgba(248, 250, 252, 0.94);
  backdrop-filter: blur(18px);
}

.record-button {
  display: inline-flex;
  min-width: min(88vw, 22rem);
  min-height: 58px;
  align-items: center;
  justify-content: center;
  gap: 0.7rem;
  border: 0;
  border-radius: 999px;
  padding: 0.8rem 1.4rem;
  color: #ffffff;
  background: linear-gradient(135deg, #0284c7, #0369a1);
  box-shadow: 0 10px 24px rgba(3, 105, 161, 0.28);
  font-size: 1.05rem;
  font-weight: 900;
  cursor: pointer;
}

.record-button.recording {
  background: linear-gradient(135deg, #f43f5e, #be123c);
  box-shadow: 0 10px 24px rgba(190, 18, 60, 0.25);
}

.record-button:disabled,
.mode-toggle button:disabled {
  cursor: wait;
  opacity: 0.58;
}

.record-icon {
  width: 1rem;
  height: 1rem;
  border-radius: 999px;
  background: currentColor;
  box-shadow: 0 0 0 5px rgba(255, 255, 255, 0.2);
}

.record-button.recording .record-icon {
  border-radius: 0.2rem;
}

.model-label {
  max-width: 100%;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.correction-dialog {
  width: min(calc(100% - 2rem), 30rem);
  border: 0;
  border-radius: 1.25rem;
  padding: 0;
  box-shadow: 0 24px 80px rgba(15, 23, 42, 0.3);
}

.correction-dialog::backdrop {
  background: rgba(15, 23, 42, 0.56);
  backdrop-filter: blur(4px);
}

.correction-dialog form {
  display: grid;
  gap: 0.75rem;
  padding: 1.25rem;
}

.correction-dialog p {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.correction-dialog label {
  font-weight: 850;
}

.correction-dialog input {
  width: 100%;
  min-height: 50px;
  border: 1.5px solid #94a3b8;
  border-radius: 0.8rem;
  padding: 0.7rem 0.8rem;
  color: var(--ink);
  background: #ffffff;
  font-size: 1rem;
}

.dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
}

.dialog-actions button {
  min-height: 48px;
  border-radius: 0.8rem;
  padding: 0.65rem;
  font-weight: 850;
  cursor: pointer;
}

.button-secondary {
  border: 1px solid #cbd5e1;
  color: #334155;
  background: #ffffff;
}

.button-primary {
  border: 1px solid var(--blue-dark);
  color: #ffffff;
  background: var(--blue-dark);
}

.route-error {
  display: grid;
  min-height: 100dvh;
  place-items: center;
  padding: 1rem;
}

.route-error-card {
  width: min(100%, 32rem);
  border: 1px solid #fecdd3;
  border-radius: 1.5rem;
  padding: clamp(1.25rem, 5vw, 2rem);
  background: #ffffff;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.12);
}

.route-error-card > p:not(.eyebrow) {
  color: var(--muted);
  line-height: 1.6;
}

.route-error-hint code {
  color: var(--danger);
  font-weight: 800;
}

@media (min-width: 54rem) {
  .content {
    grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr);
    align-items: start;
  }

  .result-card,
  .status-line,
  .correction-button {
    grid-column: 1;
  }

  #selfTestPanel {
    grid-column: 1 / -1;
  }

  #asrSection,
  #sceneSection {
    grid-column: 2;
  }

  #asrSection {
    grid-row: 1 / span 2;
  }

  #sceneSection {
    grid-row: 3 / span 3;
  }
}

@media (max-width: 42rem) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .mode-area,
  .mode-toggle {
    width: 100%;
  }

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

  .scene-card-list {
    grid-template-columns: 1fr;
  }

  .self-test-presets {
    grid-template-columns: 1fr;
  }

  .scene-card {
    min-height: 56px;
  }
}

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

