:root {
  color-scheme: light;
  --bg: #f8fafc;
  --card: #ffffff;
  --ink: #191f28;
  --muted: #6b7280;
  --line: #e5e8eb;
  --soft: #f2f4f6;
  --soft-strong: #e8edf3;
  --primary: #3182f6;
  --primary-hover: #1b64da;
  --primary-soft: #eaf3ff;
  --success-soft: #e9f8f2;
  --success-ink: #16705a;
  --danger-soft: #fff1f2;
  --danger-ink: #be123c;
  --warning-soft: #fff8e1;
  --warning-ink: #8a6d1d;
  --shadow: 0 10px 28px rgba(25, 31, 40, 0.045);
  --shadow-strong: 0 14px 32px rgba(49, 130, 246, 0.10);
}

html {
  color-scheme: light;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  background: var(--bg);
}

/* Mobile-first layout with touch-sized controls. */
* {
  box-sizing: border-box;
  min-width: 0;
}

[hidden] {
  display: none !important;
}

body {
  width: 100%;
  max-width: 100%;
  margin: 0;
  padding: 14px 12px 0;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  letter-spacing: 0;
}

.app-header,
.app-shell,
.app-footer {
  width: 100%;
  max-width: 860px;
  margin-inline: auto;
}

.app-header {
  display: grid;
  gap: 12px;
  padding: 18px 18px 16px;
  background: var(--card);
  border: 1px solid rgba(229, 232, 235, 0.82);
  border-radius: 24px;
  box-shadow: var(--shadow);
}

.app-header h1 {
  margin: 0 0 4px;
  color: var(--ink);
  font-size: 1.5rem;
  font-weight: 800;
}

.app-header p {
  margin: 0;
  color: var(--muted);
  font-size: 0.98rem;
}

.api-status-box {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  align-items: center;
}

.status-pill {
  width: max-content;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 0.82rem;
  font-weight: 800;
  white-space: nowrap;
}

.checking {
  background: var(--soft);
  color: var(--muted);
  border-color: var(--line);
}

.connected {
  background: var(--success-soft);
  color: var(--success-ink);
  border-color: #c8efe2;
}

.disconnected {
  background: var(--danger-soft);
  color: var(--danger-ink);
  border-color: #ffd7de;
}

.status-retry {
  width: auto;
  min-height: 38px;
  padding: 7px 12px;
  background: var(--soft);
  border: 1px solid var(--line);
  color: var(--ink);
  box-shadow: none;
}

.status-pill.connected + .status-retry,
.status-pill.checking + .status-retry {
  display: none;
}

.app-shell {
  display: grid;
  gap: 18px;
  padding: 16px 0 36px;
}

.app-footer {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
  margin-top: 20px;
  padding: 10px 0 max(28px, env(safe-area-inset-bottom));
  color: #8b95a1;
  font-size: 12px;
  line-height: 1.3;
}

.footer-logo {
  width: auto;
  max-width: 128px;
  height: 24px;
  object-fit: contain;
  opacity: 0.78;
}

.panel,
.step-nav-card,
.current-step-card,
.result-subcard,
.chart-note-card,
.reasoning-card,
.details-card,
.developer-details {
  max-width: 100%;
  background: var(--card);
  border: 1px solid rgba(229, 232, 235, 0.86);
  border-radius: 24px;
  box-shadow: var(--shadow);
}

.panel {
  padding: 18px;
}

.input-panel {
  display: grid;
  gap: 14px;
}

button,
select,
input,
textarea {
  width: 100%;
  max-width: 100%;
  min-height: 48px;
  border-radius: 14px;
  font: inherit;
}

button {
  border: 0;
  background: var(--primary);
  color: #fff;
  color-scheme: light;
  font-weight: 800;
  cursor: pointer;
  transition: background 120ms ease, box-shadow 120ms ease;
}

.primary-button {
  background: var(--primary);
  color: #fff;
}

.primary-button:active {
  background: var(--primary-hover);
}

button:active {
  background: var(--primary-hover);
}

button:disabled {
  opacity: 0.55;
  cursor: default;
}

.secondary-button {
  background: var(--soft);
  color: var(--ink);
  border: 1px solid var(--line);
}

.danger-button {
  background: var(--danger-soft);
  color: var(--danger-ink);
  border: 1px solid #ffd7de;
  font-weight: 750;
}

#formAnalyzeButton {
  margin-top: 0;
}

.section-title {
  display: flex;
  gap: 10px;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 12px;
}

.section-title h2,
.section-title h3 {
  margin: 0;
  color: var(--ink);
}

.section-title h2 {
  font-size: 1.08rem;
}

.section-title h3 {
  font-size: 1.02rem;
}

.step-heading h2 {
  font-size: 1.32rem;
  font-weight: 800;
}

.section-title span,
.hint {
  color: var(--muted);
  font-size: 0.9rem;
}

#resultState {
  max-width: min(62%, 420px);
  text-align: right;
  line-height: 1.35;
}

.app-mode-title {
  margin-bottom: 0;
}

.step-nav-card {
  position: sticky;
  top: 0;
  z-index: 5;
  padding: 10px;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(10px);
}

.step-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  max-width: 100%;
  padding: 0 2px 2px;
  color: var(--muted);
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.step-tabs::-webkit-scrollbar {
  display: none;
}

.step-tabs button {
  flex: 0 0 auto;
  width: auto;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: var(--soft);
  color: var(--ink);
  box-shadow: none;
}

.step-tabs button.active {
  background: var(--primary);
  color: #fff;
}

.current-step-card {
  padding: 20px;
}

.progress-track {
  height: 8px;
  border-radius: 999px;
  background: var(--soft);
  overflow: hidden;
  margin-bottom: 16px;
}

#progressBar {
  height: 100%;
  width: 16.67%;
  border-radius: inherit;
  background: var(--primary);
}

.form-grid {
  display: grid;
  gap: 14px;
}

.form-grid.two,
.lr-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr;
}

.field-label {
  display: grid;
  gap: 7px;
  color: var(--ink);
  font-weight: 700;
}

select,
input,
textarea {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  -webkit-text-fill-color: var(--ink);
  color-scheme: light;
  padding: 11px 12px;
}

select:focus,
input:focus,
textarea:focus,
button:focus-visible {
  outline: 3px solid rgba(49, 130, 246, 0.18);
  outline-offset: 2px;
}

textarea {
  min-height: 250px;
  resize: vertical;
  font-family: inherit;
  font-size: 0.95rem;
}

.field-card {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #fbfcfe;
  padding: 14px;
  margin-bottom: 12px;
  max-width: 100%;
}

.field-card h3 {
  margin: 0 0 12px;
  color: var(--ink);
  font-size: 1rem;
  font-weight: 750;
}

.side-score-row {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
}

.side-label {
  display: grid;
  place-items: center;
  min-height: 42px;
  color: var(--muted);
  font-weight: 800;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(var(--score-option-count, 4), minmax(0, 1fr));
  gap: 8px;
  max-width: 100%;
}

.seg-option {
  min-width: 0;
  min-height: 48px;
  padding: 0 5px;
  background: var(--soft);
  color: var(--ink);
  border: 1px solid transparent;
  border-radius: 12px;
  box-shadow: none;
  white-space: normal;
  overflow-wrap: anywhere;
  line-height: 1.2;
  font-size: clamp(12px, 3.2vw, 15px);
}

.seg-option.selected {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  box-shadow: 0 6px 14px rgba(49, 130, 246, 0.18);
}

.score-card {
  padding: 16px 18px 16px 16px;
  box-sizing: border-box;
  overflow: hidden;
}

.score-card h3 {
  padding-inline: 0;
}

.field-help {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.35;
}

.step-help-text {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.4;
}

.optional-refinement-panel {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #f8fafc;
  padding: 12px;
  margin: 16px 0 12px;
  box-shadow: none;
}

.tone-segmented .seg-option {
  white-space: nowrap;
  overflow-wrap: normal;
}

.result-example-loader {
  border: 1px solid #dbeafe;
  border-radius: 18px;
  background: #f7fbff;
  overflow: hidden;
}

.result-example-loader > summary {
  cursor: pointer;
  padding: 14px 16px;
  color: #245b96;
  font-weight: 800;
}

.result-example-content {
  display: grid;
  gap: 12px;
  padding: 0 16px 16px;
}

.result-example-content .hint,
.result-example-note {
  margin: 0;
  line-height: 1.5;
}

.result-example-actions {
  display: grid;
  gap: 10px;
  align-items: end;
}

.result-example-note {
  color: var(--muted);
  font-size: 0.82rem;
}

.cn-optional-refinement-panel {
  margin-top: 20px;
  border-top: 2px solid rgba(49, 130, 246, 0.18);
}

.optional-refinement-panel summary {
  min-height: 36px;
  color: var(--ink);
  line-height: 1.35;
}

.optional-refinement-content {
  display: grid;
  gap: 12px;
  padding-top: 10px;
}

.optional-refinement-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.4;
}

.optional-refinement-grid,
.optional-refinement-inputs {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
}

.optional-refinement-item {
  display: grid;
  gap: 8px;
  align-items: start;
  border: 1px solid rgba(229, 232, 235, 0.92);
  border-radius: 14px;
  background: #fff;
  padding: 12px;
}

.optional-refinement-label {
  color: var(--ink);
  font-size: 0.94rem;
  font-weight: 750;
  line-height: 1.35;
}

.optional-refinement-control {
  background: #fff;
}

.optional-refinement-comment {
  min-height: 92px;
  height: 110px;
}

.optional-refinement-comment-item {
  grid-column: 1 / -1;
}

.checkbox-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(138px, 1fr));
}

.check-pill {
  display: flex;
  gap: 10px;
  align-items: center;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 10px;
  color: var(--ink);
}

.check-pill input {
  width: 20px;
  min-height: 20px;
  accent-color: var(--primary);
}

.step-actions,
.result-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
  height: auto;
  margin-top: 14px;
  position: static;
}

.wizard-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
  height: auto;
  margin: 0;
  position: static;
}

.step-actions > button,
.result-actions > button,
.wizard-actions > button {
  margin: 0;
  position: static;
}

#formAnalyzeButton,
#recentAnalysisButton,
#resetFormButton {
  grid-column: 1 / -1;
}

.cards,
.result-primary-cards,
.top3-cards {
  display: grid;
  gap: 12px;
  max-width: 100%;
}

.result-scroll-anchor {
  scroll-margin-top: 16px;
}

.summary-card {
  margin-top: 0;
}

.result-card,
.top3-card {
  border: 1px solid rgba(229, 232, 235, 0.78);
  border-radius: 22px;
  background: #fff;
  padding: 18px;
}

.result-card span,
.result-card small,
.top3-card span,
.top3-card small {
  color: var(--muted);
}

.localization-result-card {
  border-color: rgba(49, 130, 246, 0.18);
  background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
  box-shadow: var(--shadow-strong);
}

.result-label {
  display: inline-flex;
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

.rank-pill {
  display: grid;
  place-items: center;
  width: 34px;
  height: 28px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary) !important;
  font-size: 0.92rem;
  font-weight: 850;
}

.result-card strong {
  display: block;
  margin-top: 7px;
  color: var(--ink);
  font-size: 1.42rem;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.localization-result-card strong {
  font-size: 1.52rem;
}

.mri-result-card strong {
  font-size: 1.62rem;
}

.result-metric {
  display: grid;
  gap: 2px;
  margin-top: 14px;
}

.result-metric > span {
  color: var(--primary);
  font-size: 2.55rem;
  font-weight: 850;
  line-height: 1;
}

.result-metric small,
.validation-caption,
.mri-caption {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.94rem;
  line-height: 1.45;
}

.support-badge {
  display: inline-block;
  width: max-content;
  margin-top: 10px;
  border-radius: 999px;
  padding: 5px 9px;
  background: var(--warning-soft);
  color: var(--warning-ink);
  font-size: 0.82rem;
  font-weight: 800;
}

.core-warning {
  color: var(--muted);
  font-weight: 650;
}

.top3-section,
.top3-summary-card,
.clinical-reasoning-card,
.clinical-concern-card,
.result-summary-card,
.caution-card,
.ddx-card,
.chart-note-card,
.reasoning-card,
.details-card {
  padding: 20px;
  margin-top: 18px;
}

.result-panel {
  padding-bottom: 26px;
}

.result-bottom-actions {
  display: grid;
  gap: 12px;
  height: auto;
  margin-top: 24px;
  margin-bottom: 8px;
  position: static;
}

.result-bottom-actions button {
  margin: 0;
  position: static;
}

.top3-card strong {
  display: block;
  margin: 4px 0 8px;
  color: var(--ink);
  font-size: 0.98rem;
  line-height: 1.25;
}

.print-report {
  display: none;
}

.localization-subtitle {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.35;
}

.estimate-badge {
  display: inline-flex;
  width: max-content;
  max-width: 100%;
  margin-top: 10px;
  border: 1px solid rgba(49, 130, 246, 0.24);
  border-radius: 999px;
  padding: 4px 9px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 0.82rem;
  font-weight: 850;
}

.top3-summary-card h3 {
  margin: 0 0 10px;
  color: var(--ink);
  font-size: 1.02rem;
}

.top3-summary-cards {
  gap: 8px;
}

.top3-summary-cards .top3-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  column-gap: 10px;
  row-gap: 3px;
  align-items: start;
  padding: 12px;
  border-radius: 16px;
}

.top3-summary-cards .rank-pill {
  grid-row: span 4;
  width: 28px;
  height: 26px;
  font-size: 0.82rem;
}

.top3-context {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 850;
  letter-spacing: 0;
  text-transform: uppercase;
}

.top3-summary-cards .estimate-label {
  display: flex;
  flex-wrap: wrap;
  column-gap: 0.35rem;
  row-gap: 0.12rem;
  align-items: baseline;
  color: var(--primary);
  font-size: 0.82rem;
  font-weight: 800;
  line-height: 1.35;
}

.top3-summary-cards .estimate-segment {
  white-space: nowrap;
}

.top3-summary-cards small {
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.35;
  word-break: keep-all;
  overflow-wrap: break-word;
  text-wrap: pretty;
}

.clinical-reasoning-grid {
  display: grid;
  gap: 12px;
}

.clinical-reasoning-column {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fbfcfe;
  padding: 14px;
}

.clinical-reasoning-column h4 {
  margin: 0 0 8px;
  color: var(--ink);
  font-size: 0.96rem;
}

.clinical-reasoning-column ul {
  margin: 0;
  padding-left: 20px;
}

.clinical-reasoning-column li {
  margin-bottom: 7px;
}

.mri-rationale-column p,
.interpretation-note,
.guardrail-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.5;
}

.interpretation-note {
  margin-top: 12px;
}

.clinical-concern-card {
  border-color: rgba(190, 18, 60, 0.16);
  background: #fff8f8;
}

.clinical-concern-card h3,
.caution-card h3,
.ddx-card h3 {
  margin: 0 0 8px;
  color: var(--ink);
  font-size: 1.02rem;
}

.clinical-concern-card p {
  margin: 0;
  color: var(--danger-ink);
  font-weight: 750;
  line-height: 1.5;
}

.caution-card {
  background: #fffef9;
}

.caution-card ul,
.ddx-card ul {
  margin: 0;
  padding-left: 20px;
}

.caution-card li,
.ddx-card li {
  margin-bottom: 7px;
}

.ddx-card,
.ddx-details {
  background: #fbfcfe;
}

.ddx-card .guardrail-note {
  margin-bottom: 10px;
}

.ddx-details ul {
  margin: 10px 0 0;
  padding-left: 20px;
}

.ddx-details li {
  margin-bottom: 7px;
}

.validation-export-details {
  background: #fbfcfe;
}

.validation-review-note {
  min-height: 96px;
  height: 110px;
}

.validation-record-preview {
  min-height: 180px;
  height: 200px;
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.86rem;
  line-height: 1.45;
}

.estimate-percent {
  margin-top: 4px;
  color: var(--primary);
  font-size: 2.18rem;
  font-weight: 850;
  line-height: 1.05;
}

.prior-note {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.94rem;
  line-height: 1.45;
}

.estimate-label {
  color: var(--muted);
  font-size: 0.9rem;
}

details {
  overflow: hidden;
}

summary {
  min-height: 48px;
  cursor: pointer;
  color: var(--ink);
  font-weight: 800;
}

.warning-details {
  background: #fffef9;
}

.top3-table-details {
  margin-top: 12px;
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

.table-wrap {
  overflow-x: auto;
  max-width: 100%;
  margin-top: 12px;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  min-width: 520px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px;
  text-align: left;
  vertical-align: top;
}

tr:last-child td {
  border-bottom: 0;
}

th {
  background: var(--soft);
  color: var(--muted);
  font-size: 0.88rem;
}

.chart-note-card h3,
.reasoning-card h3,
#evidenceDetails h3 {
  margin: 0 0 10px;
  color: var(--ink);
  font-size: 1.04rem;
}

#chartNote {
  height: 190px;
  min-height: 170px;
  max-height: 360px;
  background: #fbfcfe;
  font-size: 0.92rem;
  line-height: 1.5;
  overflow: auto;
}

.chart-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-top: 12px;
}

.reasoning-card ul,
#evidenceSummaryList,
#keyReferencesList,
#warningsList {
  margin: 0;
  padding-left: 20px;
}

.reasoning-card li,
#evidenceSummaryList li,
#keyReferencesList li,
#warningsList li {
  margin-bottom: 8px;
}

.reasoning-card li,
.warning-details li {
  font-size: 0.9rem;
  line-height: 1.45;
}

.evidence-meta,
.evidence-note {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.9rem;
}

.reference-badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 8px;
  margin-right: 6px;
  border-radius: 999px;
  background: rgba(49, 130, 246, 0.12);
  color: var(--primary-strong);
  font-size: 12px;
  font-weight: 800;
  vertical-align: middle;
}

.reference-note {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.9rem;
}

.details-card,
.details-card p,
.details-card li,
.details-card td,
.details-card label,
.details-card .muted,
.details-card .guardrail-note,
.details-card .interpretation-note,
.details-card .evidence-meta,
.details-card .evidence-note,
.details-card .reference-note,
.details-card #chartNote,
.reasoning-evidence,
.reference-list,
.chart-note-box {
  font-size: 0.9rem;
  line-height: 1.45;
}

.details-card > summary {
  font-size: 1rem;
  line-height: 1.5;
}

.error-box,
.message-box {
  margin-top: 12px;
  border-radius: 14px;
  padding: 12px;
}

.recent-panel {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #fbfcfe;
  padding: 14px;
}

.compact-action {
  width: auto;
  min-height: 36px;
  padding: 6px 10px;
  font-size: 0.86rem;
}

.recent-list {
  display: grid;
  gap: 10px;
}

.recent-item {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 10px;
}

.recent-item strong,
.recent-item small {
  overflow-wrap: anywhere;
}

.error-box {
  border: 1px solid #ffd7de;
  background: var(--danger-soft);
  color: var(--danger-ink);
}

.message-box {
  border: 1px solid #cbe5ff;
  background: var(--primary-soft);
  color: #245b96;
  overflow-wrap: normal;
  word-break: normal;
  hyphens: none;
}

#warningsList {
  color: var(--warning-ink);
}

.developer-panel {
  opacity: 0.72;
  box-shadow: none;
}

.developer-details {
  padding: 14px;
  background: #fbfcfe;
  box-shadow: none;
}

.developer-details textarea {
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.88rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: light;
    --bg: #f8fafc;
    --card: #ffffff;
    --ink: #191f28;
    --muted: #6b7280;
    --line: #e5e8eb;
    --soft: #f2f4f6;
  }

  body {
    background: var(--bg);
    color: var(--ink);
  }
}

@media (max-width: 390px) {
  .app-header {
    border-radius: 18px;
  }

  body {
    padding-inline: 10px;
  }

  .app-shell {
    padding: 12px 0 32px;
  }

  .panel,
  .current-step-card,
  .top3-section,
  .top3-summary-card,
  .clinical-concern-card,
  .result-summary-card,
  .caution-card,
  .ddx-card,
  .chart-note-card,
  .reasoning-card,
  .details-card {
    padding: 14px;
  }

  .segmented {
    gap: 6px;
  }
}

@media (max-width: 420px) {
  .side-score-row {
    grid-template-columns: 28px minmax(0, 1fr);
    gap: 6px;
  }

  .side-label {
    justify-content: center;
    min-height: 48px;
    padding-inline: 0;
  }
}

@media (min-width: 400px) and (max-width: 559px) {
  .side-score-row {
    grid-template-columns: 28px minmax(0, 1fr);
  }

  .side-label {
    justify-content: center;
    min-height: 48px;
    padding-inline: 0;
  }
}

@media (min-width: 390px) and (max-width: 559px) {
  body {
    padding-inline: 12px;
  }
}

@media (min-width: 560px) {
  .result-example-actions {
    grid-template-columns: minmax(0, 1fr) minmax(180px, 0.45fr);
  }

  .form-grid.two,
  .lr-grid,
  .clinical-reasoning-grid {
    grid-template-columns: 1fr 1fr;
  }

  .chart-actions,
  .result-bottom-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .chart-note-card .chart-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .validation-actions {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .mri-rationale-column {
    grid-column: 1 / -1;
  }

  .result-primary-cards {
    grid-template-columns: 1fr;
  }

  .top3-cards {
    grid-template-columns: repeat(3, 1fr);
  }
}

@page {
  size: 297mm 210mm;
  margin: 8mm 10mm;
}

@page neuro-landscape {
  size: 297mm 210mm;
  margin: 8mm 10mm;
}

@media print {
  html,
  body {
    width: auto;
    max-width: none;
    margin: 0;
    padding: 0;
    overflow: visible;
    background: #fff;
    color: #111;
    font-family: Arial, "Noto Sans KR", sans-serif;
  }

  body > :not(.print-report) {
    display: none !important;
  }

  .print-report {
    display: block !important;
    page: neuro-landscape;
    padding: 0;
    font-size: 8.4pt;
    line-height: 1.22;
  }

  .print-report > .print-report-header {
    display: none !important;
  }

  .print-page-header {
    position: absolute;
    inset: 0 0 auto;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 12mm;
    border-bottom: 0.4mm solid #1f2937;
    background: #fff;
  }

  .print-brand {
    display: flex;
    align-items: center;
    gap: 3mm;
  }

  .print-brand img {
    width: auto;
    max-width: 33mm;
    height: 8mm;
    object-fit: contain;
  }

  .print-brand h1,
  .print-brand p,
  .print-page-title h2 {
    margin: 0;
  }

  .print-brand h1 {
    font-size: 12pt;
    line-height: 1.1;
  }

  .print-brand p,
  .print-generated-at {
    color: #4b5563;
    font-size: 7.5pt;
  }

  .print-page {
    page: neuro-landscape;
    box-sizing: border-box;
    padding: 14mm 0 0;
    position: relative;
    width: 100%;
  }

  .print-input-page {
    break-after: page;
    page-break-after: always;
  }

  .print-page-title {
    display: flex;
    align-items: baseline;
    border-bottom: 0.5mm solid #1f2937;
    margin-bottom: 2mm;
    padding-bottom: 1mm;
  }

  .print-page-title h2 {
    font-size: 11pt;
  }

  .print-scoring-legend {
    display: grid;
    grid-template-columns: auto 1fr;
    column-gap: 2mm;
    border: 0.3mm solid #4b5563;
    margin-bottom: 1mm;
    padding: 0.8mm 1.3mm;
    font-size: 6.1pt;
    line-height: 1.14;
  }

  .print-scoring-legend strong {
    grid-row: 1 / 4;
  }

  .print-checklist-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    column-gap: 6mm;
    row-gap: 1.3mm;
    align-items: start;
  }

  .print-checklist-grid > div {
    min-width: 0;
  }

  .print-check-section {
    break-inside: avoid;
    page-break-inside: avoid;
    margin: 0 0 1.3mm;
  }

  .print-check-section h2 {
    margin: 0 0 0.5mm;
    border-bottom: 0.35mm solid #374151;
    padding: 0 0 0.4mm;
    color: #111;
    font-size: 8.2pt;
  }

  .print-check-section table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
  }

  .print-check-section th,
  .print-check-section td {
    border: 0.2mm solid #6b7280;
    padding: 0.65mm 0.9mm;
    text-align: left;
    vertical-align: top;
    font-size: 6.1pt;
    line-height: 1.16;
  }

  .print-check-section th {
    width: 28%;
    background: #f3f4f6;
    font-weight: 700;
  }

  .print-check-section td {
    overflow-wrap: normal;
    word-break: normal;
  }

  .print-two-column-table th {
    width: 29%;
  }

  .print-three-column td:not([colspan="2"]) .print-choice {
    margin-right: 0.45mm;
    font-size: 5.8pt;
  }

  .print-three-column td:not([colspan="2"]) .print-checkbox {
    width: 1.65mm;
  }

  .print-choice-group {
    display: inline;
  }

  .print-choice {
    display: inline-block;
    margin-right: 0.75mm;
    white-space: nowrap;
  }

  .print-choice.checked {
    font-weight: 800;
  }

  .print-checkbox {
    display: inline-block;
    width: 1.9mm;
    color: #111;
    font-family: "Arial Unicode MS", "Segoe UI Symbol", sans-serif;
  }

  .print-subline {
    display: block;
    margin-top: 0.45mm;
  }

  .print-result-page {
    min-height: 0;
    padding-bottom: 0;
    break-after: auto;
    page-break-after: auto;
  }

  .print-two-column {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2.2mm;
    align-items: start;
  }

  .print-section {
    break-inside: avoid;
    page-break-inside: avoid;
    border: 0.25mm solid #9ca3af;
    margin: 0 0 1.5mm;
  }

  .print-section h2 {
    margin: 0;
    border-bottom: 0.25mm solid #9ca3af;
    padding: 0.8mm 1.2mm;
    background: #eef2f6;
    color: #111;
    font-size: 8.2pt;
  }

  .print-section table {
    width: 100%;
    border-collapse: collapse;
  }

  .print-section th,
  .print-section td {
    border: 0;
    border-bottom: 0.2mm solid #d1d5db;
    padding: 0.7mm 1.2mm;
    text-align: left;
    vertical-align: top;
  }

  .print-section tr:last-child th,
  .print-section tr:last-child td {
    border-bottom: 0;
  }

  .print-section th {
    width: 35%;
    background: #f8fafc;
    color: #374151;
    font-size: 7.2pt;
  }

  .print-section ul {
    margin: 0;
    padding: 1mm 1.5mm 1mm 5mm;
  }

  .print-section li {
    margin: 0 0 0.4mm;
  }

  .print-result-highlight {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2.5mm;
    margin-bottom: 2.5mm;
  }

  .print-result-highlight > div {
    min-height: 24mm;
    border: 0.45mm solid #1d4ed8;
    border-radius: 2mm;
    padding: 2mm;
  }

  .print-result-highlight span,
  .print-result-highlight small,
  .print-result-highlight strong {
    display: block;
  }

  .print-result-highlight span {
    color: #4b5563;
    font-size: 8pt;
    font-weight: 700;
  }

  .print-result-highlight strong {
    margin: 1mm 0 0.7mm;
    color: #111827;
    font-size: 12pt;
    line-height: 1.15;
  }

  .print-result-highlight small {
    color: #374151;
    font-size: 7.8pt;
  }

  .print-summary-text {
    padding: 1mm 1.5mm;
    color: #111827;
    font-size: 7.4pt;
    line-height: 1.25;
  }

  .print-summary-text p {
    margin: 0 0 0.7mm;
  }

  .print-summary-text p:last-child {
    margin-bottom: 0;
  }

  .print-result-details .print-section {
    height: auto;
  }

  .print-result-details-expanded {
    display: block;
  }

  .print-result-details-expanded .print-section {
    break-inside: auto;
    page-break-inside: auto;
  }

  .print-result-details-expanded .print-section h2,
  .print-result-details-expanded .print-section li,
  .print-result-details-expanded .print-section tr {
    break-inside: avoid;
    page-break-inside: avoid;
  }
}

@media (min-width: 820px) {
  .app-header {
    grid-template-columns: 1fr auto;
    align-items: start;
  }
}
