:root {
  --emr-paper: #f6f1e7;
  --emr-card: #fffdf8;
  --emr-ink: #1e2933;
  --emr-muted: #64707a;
  --emr-line: #d8d0c2;
  --emr-red: #8a2f2f;
  --emr-red-soft: #f5e6e2;
  --emr-teal: #155e65;
  --emr-teal-soft: #e3f1f0;
  --emr-amber: #9a5b16;
  --emr-amber-soft: #fff2d8;
  --emr-green: #356544;
  --emr-green-soft: #e8f2e8;
  --emr-shadow: 0 16px 36px rgba(55, 43, 29, 0.08);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

.emr-page {
  margin: 0;
  color: var(--emr-ink);
  background:
    radial-gradient(circle at 92% 0, rgba(138, 47, 47, 0.09), transparent 26rem),
    linear-gradient(180deg, #faf7f0 0, var(--emr-paper) 34rem);
  font-family: Helvetica, 'Helvetica Neue', Arial, 'Noto Sans TC', sans-serif;
  font-size: 16px;
  line-height: 1.65;
  overflow-x: clip;
}

.emr-page button,
.emr-page a,
.emr-page summary { -webkit-tap-highlight-color: transparent; }

.emr-page button { font: inherit; }

.emr-page a:focus-visible,
.emr-page button:focus-visible,
.emr-page summary:focus-visible {
  outline: 3px solid #2563eb;
  outline-offset: 3px;
}

.emr-page .site-header {
  position: static;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 54px;
  padding: 5px max(14px, env(safe-area-inset-right)) 5px max(14px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--emr-line);
  background: rgba(255, 253, 248, 0.94);
}

.emr-page .breadcrumb {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  font-size: 0.88rem;
}

.emr-page .breadcrumb a,
.emr-header-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: var(--emr-red);
  font-weight: 750;
  text-decoration: none;
}

.emr-header-link { padding-inline: 4px; }

.emr-app {
  width: min(100%, 900px);
  margin: 0 auto;
  padding:
    26px
    max(14px, env(safe-area-inset-right))
    calc(52px + env(safe-area-inset-bottom, 0px))
    max(14px, env(safe-area-inset-left));
}

.emr-hero {
  position: relative;
  padding: clamp(20px, 6vw, 42px);
  overflow: hidden;
  border: 1px solid var(--emr-line);
  border-radius: 24px;
  background: rgba(255, 253, 248, 0.92);
  box-shadow: var(--emr-shadow);
}

.emr-hero::after {
  position: absolute;
  right: -3rem;
  bottom: -5.5rem;
  width: 14rem;
  height: 14rem;
  border: 2.7rem solid rgba(138, 47, 47, 0.055);
  border-radius: 50%;
  content: '';
  pointer-events: none;
}

.emr-eyebrow {
  margin: 0;
  color: var(--emr-red);
  font-size: 0.77rem;
  font-weight: 850;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.emr-hero h1 {
  max-width: 13ch;
  margin: 6px 0 8px;
  font-family: Georgia, 'Noto Serif TC', serif;
  font-size: clamp(2.35rem, 10vw, 4.7rem);
  line-height: 0.98;
  letter-spacing: -0.05em;
}

.emr-lede {
  max-width: 55ch;
  margin: 0;
  color: var(--emr-muted);
  font-size: clamp(1rem, 2.8vw, 1.16rem);
}

.emr-source-status {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  margin: 14px 0 0;
  padding: 4px 10px;
  border: 1px solid #b8cec9;
  border-radius: 999px;
  color: var(--emr-teal);
  background: var(--emr-teal-soft);
  font-size: 0.78rem;
  font-weight: 800;
}

.emr-source-status[data-state='warning'] {
  border-color: #e1c68e;
  color: #7e4a11;
  background: var(--emr-amber-soft);
}

.emr-mode-shell {
  position: sticky;
  z-index: 8;
  top: env(safe-area-inset-top, 0px);
  margin: 18px -4px 20px;
  padding: 7px 4px;
  background: rgba(246, 241, 231, 0.96);
  backdrop-filter: blur(10px);
}

.emr-mode-switch {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.emr-mode-switch button {
  min-width: 0;
  min-height: 50px;
  padding: 7px 4px;
  border: 1px solid var(--emr-line);
  border-radius: 12px;
  color: var(--emr-ink);
  background: var(--emr-card);
  font-weight: 850;
  line-height: 1.15;
  cursor: pointer;
}

.emr-mode-switch button small {
  display: block;
  margin-top: 4px;
  color: var(--emr-muted);
  font-size: 0.64rem;
  font-weight: 650;
}

.emr-mode-switch button[aria-pressed='true'] {
  border-color: var(--emr-red);
  color: #fff;
  background: var(--emr-red);
  box-shadow: 0 7px 18px rgba(92, 31, 31, 0.2);
}

.emr-mode-switch button[aria-pressed='true'] small { color: #fae9e7; }

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

.emr-app[data-view='core'] [data-depth='brief'],
.emr-app[data-view='core'] [data-depth='full'],
.emr-app[data-view='brief'] [data-depth='full'] { display: none !important; }

.emr-section {
  margin: 28px 0;
  scroll-margin-top: 96px;
}

.emr-section-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 12px;
}

.emr-section-index {
  margin: 0 0 1px;
  color: var(--emr-red);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.1em;
}

.emr-section h2 {
  margin: 0;
  font-family: Georgia, 'Noto Serif TC', serif;
  font-size: clamp(1.55rem, 5vw, 2.25rem);
  line-height: 1.15;
}

.emr-section-intro {
  max-width: 58ch;
  margin: 4px 0 0;
  color: var(--emr-muted);
}

.emr-rule-grid,
.emr-card-grid,
.emr-cue-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.emr-rule,
.emr-card,
.emr-cue,
.emr-note,
.emr-table-shell,
.emr-combo {
  border: 1px solid var(--emr-line);
  border-radius: 16px;
  background: var(--emr-card);
}

.emr-rule {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 11px;
  padding: 15px;
}

.emr-rule-number {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  color: #fff;
  background: var(--emr-red);
  font-family: Georgia, serif;
  font-size: 1.1rem;
  font-weight: 800;
}

.emr-rule h3,
.emr-card h3,
.emr-cue h3 {
  margin: 0;
  font-size: 1.02rem;
  line-height: 1.35;
}

.emr-rule p,
.emr-card p,
.emr-cue p { margin: 5px 0 0; }

.emr-rule strong { color: var(--emr-red); }

.emr-card,
.emr-cue { padding: 15px; }

.emr-card.signal-good { border-top: 4px solid var(--emr-teal); }
.emr-card.signal-bad { border-top: 4px solid var(--emr-red); }
.emr-card.signal-weak { border-top: 4px solid var(--emr-amber); }

.emr-badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.emr-badge {
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  padding: 2px 8px;
  border-radius: 999px;
  color: var(--emr-muted);
  background: #f0ece4;
  font-size: 0.7rem;
  font-weight: 850;
  letter-spacing: 0.02em;
}

.emr-badge.strong { color: var(--emr-teal); background: var(--emr-teal-soft); }
.emr-badge.caution { color: #7c480f; background: var(--emr-amber-soft); }
.emr-badge.danger { color: var(--emr-red); background: var(--emr-red-soft); }

.emr-stat {
  color: var(--emr-red);
  font-family: Georgia, serif;
  font-size: 1.5rem;
  font-weight: 800;
  line-height: 1;
}

.emr-mini {
  color: var(--emr-muted);
  font-size: 0.82rem;
}

.emr-note {
  margin: 12px 0;
  padding: 13px 15px;
  color: #264c4f;
  background: var(--emr-teal-soft);
}

.emr-note.warning {
  color: #70430f;
  background: var(--emr-amber-soft);
}

.emr-note.danger {
  color: #742323;
  background: var(--emr-red-soft);
}

.emr-note p { margin: 0; }

.emr-jump {
  display: flex;
  gap: 7px;
  max-width: 100%;
  margin: 14px 0 0;
  padding: 0 0 4px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scroll-snap-type: x proximity;
}

.emr-jump a {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 6px 12px;
  border: 1px solid var(--emr-line);
  border-radius: 999px;
  color: var(--emr-red);
  background: var(--emr-card);
  font-size: 0.82rem;
  font-weight: 800;
  text-decoration: none;
  scroll-snap-align: start;
}

.emr-table-shell {
  max-width: 100%;
  overflow-x: auto;
}

.emr-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

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

.emr-table tr:last-child th,
.emr-table tr:last-child td { border-bottom: 0; }

.emr-table thead th {
  color: var(--emr-muted);
  background: #f3eee5;
  font-size: 0.74rem;
  letter-spacing: 0.04em;
}

.emr-table td strong { color: var(--emr-red); }

.emr-combo { padding: 16px; }

.emr-combo-flow {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.emr-combo-step {
  padding: 11px 8px;
  border-radius: 12px;
  background: #f1ede6;
  text-align: center;
  font-size: 0.82rem;
}

.emr-combo-step strong {
  display: block;
  color: var(--emr-red);
  font-size: 1.05rem;
}

.emr-pair {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 8px;
}

.emr-pair > div {
  height: 100%;
  padding: 10px;
  border-radius: 11px;
  background: #f2eee7;
}

.emr-pair-arrow {
  color: var(--emr-red);
  font-weight: 900;
}

.emr-cue {
  position: relative;
  padding-top: 42px;
}

.emr-cue::before {
  position: absolute;
  top: 13px;
  left: 15px;
  color: var(--emr-teal);
  font-size: 0.7rem;
  font-weight: 900;
  letter-spacing: 0.09em;
  content: '看到這組訊號';
}

.emr-cue .emr-answer {
  display: block;
  margin-top: 9px;
  padding-top: 8px;
  border-top: 1px solid var(--emr-line);
  color: var(--emr-red);
  font-weight: 850;
}

.emr-details {
  margin: 10px 0;
  border: 1px solid var(--emr-line);
  border-radius: 14px;
  background: var(--emr-card);
}

.emr-details summary {
  min-height: 48px;
  padding: 11px 38px 11px 14px;
  font-weight: 850;
  cursor: pointer;
}

.emr-details-body { padding: 0 14px 14px; }
.emr-details-body > :first-child { margin-top: 0; }
.emr-details-body > :last-child { margin-bottom: 0; }

.emr-question-ref {
  white-space: nowrap;
  color: var(--emr-teal);
  font-size: 0.76rem;
  font-weight: 800;
}

.emr-list {
  margin: 8px 0 0;
  padding-left: 1.25rem;
}

.emr-list li + li { margin-top: 6px; }

.emr-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.emr-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 7px 14px;
  border: 1px solid var(--emr-red);
  border-radius: 999px;
  color: var(--emr-red);
  background: var(--emr-card);
  font-size: 0.85rem;
  font-weight: 850;
  text-decoration: none;
}

.emr-action.primary { color: #fff; background: var(--emr-red); }

.emr-method {
  margin-top: 34px;
  padding: 18px;
  border-top: 3px double var(--emr-line);
  color: var(--emr-muted);
  font-size: 0.83rem;
}

.emr-method h2 {
  margin: 0 0 6px;
  color: var(--emr-ink);
  font-family: Georgia, serif;
  font-size: 1.25rem;
}

.emr-method p { margin: 5px 0; }

@media (max-width: 640px) {
  .emr-page .breadcrumb strong { display: none; }
  .emr-rule-grid,
  .emr-card-grid,
  .emr-cue-grid { grid-template-columns: 1fr; }
  .emr-section-head { align-items: start; }
  .emr-combo-flow { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .emr-pair { grid-template-columns: 1fr; }
  .emr-pair-arrow { transform: rotate(90deg); text-align: center; }
}

@media (max-width: 390px) {
  .emr-mode-switch button { font-size: 0.9rem; }
  .emr-mode-switch button small { font-size: 0.6rem; }
  .emr-rule { grid-template-columns: 30px minmax(0, 1fr); padding: 13px; }
  .emr-rule-number { width: 30px; height: 30px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}

@media print {
  .emr-page { background: #fff; font-size: 10pt; }
  .emr-page .site-header,
  .emr-mode-shell,
  .emr-jump,
  .emr-actions { display: none !important; }
  .emr-app { width: 100%; padding: 0; }
  .emr-app [data-depth] { display: block !important; }
  .emr-hero { padding: 18px; box-shadow: none; }
  .emr-hero h1 { font-size: 30pt; }
  .emr-rule-grid,
  .emr-card-grid,
  .emr-cue-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .emr-rule,
  .emr-card,
  .emr-cue,
  .emr-details,
  .emr-table-shell { break-inside: avoid; box-shadow: none; }
  .emr-details[open] .emr-details-body,
  .emr-details .emr-details-body { display: block; }
}

