/* Colours follow the "Irivue Blue" theme from the irivue app, with an optional
   low-glare dark palette ("dim") for darkened exam rooms and eye surgery suites. */
:root {
  --primary: #0b5cd5; --strong: #082e70; --hover: #084ba9; --soft: #e8f1fe;
  --surface: #f5f8fd; --card: #ffffff; --card-sub: #f7faff; --border: #d4dfef; --border-soft: #e6eef9;
  --ink: #1d2940; --muted-ink: #5f6e87; --white: #ffffff;
  --patient-bg: linear-gradient(155deg, #0a357f 0%, #07265c 100%); --patient-border: #082e70; --patient-label: #c9dcfb;
  --status-bg: #eaf6ef; --status-ink: #155939;
  --seg-bg: #e6eef9; --seg-active-bg: #ffffff; --seg-active-ink: #082e70;
  /* Status colours, kept apart from the brand blues. */
  --warning-bg: #fef3c7; --warning-ink: #78350f; --warning-border: #f5d67b;
  --danger-bg: #fce6de; --danger-ink: #82331d; --danger-border: #f3cbc0;
  --ok-bg: #e6f5ed; --ok-ink: #166534; --ok-border: #a7e0be;
  --live: #c2410c; --ready: #2f8a5b; --busy: #b2701b;
  --caption-size: 40px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink); background: var(--surface); font-synthesis: none;
}

/* Low-glare OR / darkened exam-room palette */
body.dim {
  --primary: #2563eb; --strong: #dbeafe; --hover: #1d4ed8; --soft: #1b3661;
  --surface: #09111f; --card: #0f1c32; --card-sub: #13223b; --border: #223659; --border-soft: #1a2b49;
  --ink: #e8f0fc; --muted-ink: #8ca4c8;
  --patient-bg: linear-gradient(155deg, #102447 0%, #0b1830 100%); --patient-border: #243d66; --patient-label: #8ab4f8;
  --status-bg: #10253a; --status-ink: #7dd3fc;
  --seg-bg: #0f1c32; --seg-active-bg: #1e3a68; --seg-active-ink: #ffffff;
  --warning-bg: #2b2112; --warning-ink: #fde68a; --warning-border: #7c5618;
  --danger-bg: #361816; --danger-ink: #fca5a5; --danger-border: #7f2d28;
  --ok-bg: #102b24; --ok-ink: #a7f3d0; --ok-border: #1f6b54;
}

* { box-sizing: border-box; }
html, body { height: 100%; height: 100dvh; }
body { margin: 0; display: flex; flex-direction: column; background: var(--surface); color: var(--ink); }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }
button, a, input, label { -webkit-tap-highlight-color: transparent; }
button {
  font: inherit; color: inherit; cursor: pointer; min-height: 52px; padding: 10px 18px;
  border: 1px solid var(--border); border-radius: 14px; background: var(--card);
  transition: background-color .12s ease, border-color .12s ease, transform .08s ease;
}
button:disabled { opacity: .42; cursor: default; }
button:focus-visible, a:focus-visible, input:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }

main { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow-y: auto; }
.error { background: var(--danger-bg); color: var(--danger-ink); border: 1px solid var(--danger-border); border-radius: 12px; padding: 13px 16px; font-size: 16px; line-height: 1.45; }
@keyframes warn-nudge { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }

/* Language picker */
#picker { width: 100%; max-width: 1120px; margin: 0 auto; padding: 26px 32px 36px; }
.picker-top { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.brand { display: inline-block; max-width: 100%; }
.logo { display: block; height: 96px; width: auto; max-width: 100%; }
body.dim .logo { filter: brightness(0) invert(1); opacity: .92; }
h1 { font-size: clamp(28px, 4.2vw, 44px); font-weight: 650; line-height: 1.12; letter-spacing: -0.9px; margin: 28px 0 8px; color: var(--strong); }
.lead { font-size: 18px; color: var(--muted-ink); margin: 0 0 18px; }
.picker-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 8px; }
.search {
  flex: 1 1 280px; max-width: 460px; min-height: 54px; padding: 11px 16px;
  font: inherit; font-size: 18px; color: var(--ink); background: var(--card); border: 1px solid var(--border); border-radius: 14px;
}
.search::placeholder { color: var(--muted-ink); }
.offline-switch {
  display: inline-flex; align-items: center; gap: 10px; min-height: 54px; padding: 8px 16px;
  border-radius: 14px; border: 1px solid var(--border); background: var(--card); color: var(--strong);
  font-size: 16px; font-weight: 600; cursor: pointer; user-select: none;
}
.offline-switch:has(input:checked) { background: var(--soft); border-color: var(--primary); }
.offline-switch input { width: 22px; height: 22px; accent-color: var(--primary); margin: 0; }
.human-picker-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 9px;
  min-height: 54px; padding: 8px 16px; border-radius: 14px;
  border: 1px solid var(--border); background: var(--card); color: var(--strong);
  font-size: 16px; font-weight: 600;
}
.human-picker-btn:active { background: var(--soft); border-color: var(--primary); }
.phone-icon { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2.1; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.human-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; color: var(--strong); }
.human-btn:active { background: var(--soft); border-color: var(--primary); }

.group h2 { margin: 22px 0 12px; font-size: 13px; font-weight: 700; letter-spacing: 1.1px; text-transform: uppercase; color: var(--muted-ink); }
.languages { display: grid; grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); grid-auto-rows: 1fr; gap: 13px; }
.lang {
  text-align: left; min-height: 116px; padding: 18px 20px; font-size: 24px; font-weight: 650; line-height: 1.2; color: var(--strong);
  display: flex; flex-direction: column; justify-content: space-between; gap: 6px;
}
.lang small { display: block; margin-top: 4px; font-size: 15px; font-weight: 450; color: var(--muted-ink); }
.lang-tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.lang-tag {
  font-size: 11.5px; font-weight: 650; padding: 2px 8px; border-radius: 999px; line-height: 1.35;
}
.lang-tag.ok { background: var(--ok-bg); color: var(--ok-ink); }
.lang-tag.warn { background: var(--warning-bg); color: var(--warning-ink); }
.lang-tag.voice { background: var(--soft); color: var(--primary); }
body.dim .lang-tag.voice { color: #93c5fd; }
.lang:hover { border-color: var(--primary); }
.lang:active { background: var(--soft); border-color: var(--primary); }
.privacy { margin: 28px 0 0; font-size: 14px; line-height: 1.6; color: var(--muted-ink); max-width: 780px; }
#pickerError { margin-top: 20px; }
.load-error { visibility: hidden; animation: reveal 0s 3s forwards; }
body.ready .load-error { display: none; }
@keyframes reveal { to { visibility: visible; } }

/* Room top bar */
#room { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 10px; padding: 10px 14px calc(12px + env(safe-area-inset-bottom)); }
.bar { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 10px; position: relative; }
.status-pill {
  display: inline-flex; align-items: center; gap: 10px; min-width: 0; min-height: 44px;
  padding: 6px 14px; border: 1px solid transparent; border-radius: 999px;
  background: var(--status-bg); color: var(--status-ink); font-size: 17px; cursor: default;
}
.status-pill.nudge { animation: warn-nudge .35s ease; }
.status-pill strong { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { flex: none; width: 11px; height: 11px; border-radius: 50%; background: var(--muted-ink); }
body[data-state="listening"] .dot { background: var(--ready); }
body[data-state="doctor"] .status-pill, body[data-state="hearing"] .status-pill { background: var(--danger-bg); color: var(--danger-ink); }
body[data-state="doctor"] .dot, body[data-state="hearing"] .dot { background: var(--live); animation: pulse 1s infinite; }
body[data-state="translating"] .status-pill { background: var(--warning-bg); color: var(--warning-ink); }
body[data-state="translating"] .dot { background: var(--busy); animation: pulse 1s infinite; }
body[data-state="speaking"] .status-pill { background: var(--soft); color: var(--strong); }
body[data-state="speaking"] .dot { background: var(--primary); }
body[data-state="muted"] .status-pill { background: var(--warning-bg); color: var(--warning-ink); }
body[data-state="muted"] .dot { background: var(--live); animation: none; }
body[data-state="offline"] .status-pill { background: var(--ok-bg); color: var(--ok-ink); }
body[data-state="offline"] .dot { background: var(--ready); }
body[data-mic="muted"] .status-pill, body[data-mic="paused"] .status-pill, body[data-mic="silent"] .status-pill {
  background: var(--danger-bg); color: var(--danger-ink); border-color: var(--danger-border); cursor: pointer;
}
body[data-mic="muted"] .dot, body[data-mic="paused"] .dot, body[data-mic="silent"] .dot {
  background: var(--live); animation: none;
}
@keyframes pulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .dot, .pin.nudge, .pin-dots.nudge, .pin-dots.verifying .pin-dot.filled, .status-pill.nudge { animation: none !important; } }

/* Live mic level bars */
.mic-meter { display: inline-flex; align-items: center; gap: 2.5px; height: 16px; margin-left: 2px; }
.mic-meter i {
  display: block; width: 3px; height: 14px; border-radius: 2px; background: currentColor; opacity: .78;
  transform: scaleY(var(--lvl, .2)); transform-origin: center; transition: transform .07s linear;
}

.bar-brand { display: flex; align-items: center; gap: 10px; font: 650 20px/24px -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: var(--strong); }
.bar-mark { display: block; height: 26px; width: 30px; flex: none; }
body.dim .bar-mark { filter: brightness(1.45) saturate(1.1); }
.bar-wordmark { display: block; height: 21px; width: auto; }
body.dim .bar-wordmark { filter: brightness(0) invert(1); }
.bar-beta { margin-left: -2px; font-size: 12px; font-weight: 650; line-height: 1; color: var(--muted-ink); border: 1px solid var(--border); border-radius: 999px; padding: 3px 8px; }

.tools { display: flex; align-items: center; gap: 6px; }
.small { min-height: 44px; padding: 6px 13px; font-size: 15px; font-weight: 600; border-radius: 11px; }
.small[aria-pressed="true"] { background: var(--soft); border-color: var(--primary); color: var(--strong); }
.end-btn { color: var(--danger-ink); border-color: var(--danger-border); background: var(--danger-bg); }

/* In-app speaker volume popover */
.vol-wrap { position: relative; }
.vol-btn { display: inline-flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; }
.vol-icon { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2.1; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.vol-menu {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 30;
  width: 240px; padding: 12px 14px; border-radius: 16px;
  background: var(--card); border: 1px solid var(--border);
  box-shadow: 0 14px 32px rgba(8, 46, 112, .22);
  display: flex; flex-direction: column; gap: 10px;
}
body.dim .vol-menu { box-shadow: 0 14px 32px rgba(0, 0, 0, .55); }
.vol-head { display: flex; align-items: center; justify-content: space-between; font-size: 14px; font-weight: 650; color: var(--strong); font-variant-numeric: tabular-nums; }
.vol-slider { width: 100%; height: 28px; accent-color: var(--primary); cursor: pointer; margin: 0; }
.vol-presets { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.vol-preset, .speed-preset {
  min-height: 36px; padding: 4px 6px; border-radius: 10px; font-size: 13px; font-weight: 650;
  background: var(--card-sub); color: var(--strong); border: 1px solid var(--border);
}
.vol-preset[aria-pressed="true"], .speed-preset[aria-pressed="true"] { background: var(--soft); border-color: var(--primary); color: var(--primary); }
body.dim .vol-preset[aria-pressed="true"], body.dim .speed-preset[aria-pressed="true"] { color: var(--white); }
.speed-section { display: flex; flex-direction: column; gap: 6px; padding-top: 8px; border-top: 1px solid var(--border-soft); }
.speed-presets { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }

/* Caption panels */
.captions { flex: 1; min-height: 0; display: grid; grid-template-rows: 1fr 1fr; gap: 10px; }
.captions.phrases-open { grid-template-rows: auto minmax(0, 1fr); }
.panel { min-height: 0; display: flex; flex-direction: column; border-radius: 18px; padding: 14px 20px 16px; border: 1px solid var(--border); background: var(--card); }
.panel.patient { background: var(--patient-bg); border-color: var(--patient-border); color: var(--white); transition: transform .25s ease; }
.captions.phrases-open .panel.patient { padding: 10px 18px 12px; max-height: 112px; }
.captions.phrases-open .panel.patient .prev-caption, .captions.phrases-open .panel.patient .patient-intro { display: none; }
.captions.phrases-open .panel.patient .caption { flex: none; max-height: 64px; margin-top: 4px; font-size: clamp(20px, 2.5vw, 30px); line-height: 1.2; }
#room.phrases-open .hint { display: none; }
#room.flipped .panel.patient { transform: rotate(180deg); }

.label { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 14px; font-weight: 600; letter-spacing: .4px; color: var(--muted-ink); }
.panel.patient .label { color: var(--patient-label); }
.label-badges { display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.unsure, .verify-chip {
  background: var(--warning-bg); color: var(--warning-ink); border: 1px solid var(--warning-border);
  border-radius: 999px; padding: 2px 10px; font-size: 12.5px; font-weight: 650; letter-spacing: 0;
}
.offline-pill {
  background: var(--ok-bg); color: var(--ok-ink); border: 1px solid var(--ok-border);
  border-radius: 999px; padding: 2px 10px; font-size: 12.5px; font-weight: 650; letter-spacing: 0;
}
.stop-pill {
  min-height: 32px; padding: 3px 12px; border-radius: 9px; font-size: 13px; font-weight: 700;
  background: var(--danger-bg); color: var(--danger-ink); border: 1px solid var(--danger-border);
}

.prev-caption {
  flex: none; margin: 8px 0 0; padding-bottom: 7px; font-size: 15px; line-height: 1.3;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  border-bottom: 1px solid var(--border-soft); color: var(--muted-ink);
}
.panel.patient .prev-caption { border-bottom-color: rgba(255,255,255,.14); color: rgba(219,234,254,.72); }

.caption {
  flex: 1; min-height: 0; margin: 8px 0 0; overflow: auto; overflow-wrap: anywhere; white-space: pre-wrap;
  font-size: var(--caption-size); line-height: 1.24; font-weight: 550;
}
.caption.pending { opacity: .58; }
.patient-intro {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  text-align: center; padding: 12px 8px;
}
.patient-intro:not([hidden]) + .caption { display: none; }
.intro-actions { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 10px; }
.intro-play-btn {
  min-height: 50px; padding: 10px 22px; border-radius: 999px;
  background: rgba(255, 255, 255, .18); border: 1px solid rgba(255, 255, 255, .38); color: var(--white);
  font-size: 17px; font-weight: 650; touch-action: manipulation;
}
.intro-skip-btn {
  min-height: 50px; padding: 10px 18px; border-radius: 999px;
  background: transparent; border: 1px solid rgba(255, 255, 255, .24); color: rgba(219, 234, 254, .88);
  font-size: 16px; font-weight: 600; touch-action: manipulation;
}
.intro-play-btn:active { background: rgba(255, 255, 255, .28); transform: scale(.97); }
.intro-skip-btn:active { background: rgba(255, 255, 255, .12); color: var(--white); transform: scale(.97); }
.intro-sub { margin: 0; font-size: 14px; color: rgba(201, 220, 251, .8); }
@media (hover: hover) {
  .intro-play-btn:hover { background: rgba(255, 255, 255, .25); border-color: rgba(255, 255, 255, .52); }
  .intro-skip-btn:hover { background: rgba(255, 255, 255, .10); color: var(--white); }
}

/* Stored phrases panel */
.panel.phrases { padding: 10px 14px 12px; }
.phrase-status { flex: none; margin: 6px 0 0; font-size: 14px; color: var(--danger-ink); }
.phrase-list { flex: 1; min-height: 0; overflow: auto; margin-top: 6px; display: flex; flex-direction: column; }
.phrase-list .empty { font-size: 18px; color: var(--muted-ink); margin: 12px 0; }

/* Surgery cockpit: Spatial Gaze Compass + 5 clinical cards */
.surgery-cockpit { flex: 1; min-height: 0; display: grid; grid-template-columns: 1.05fr 1fr; gap: 10px; }
.gaze-compass {
  min-height: 0; background: var(--card-sub); border: 1px solid var(--border); border-radius: 14px; padding: 8px;
  display: grid; grid-template-columns: 1fr 1fr 1fr; grid-template-rows: 1fr 1fr 1fr; gap: 6px;
}
.gaze-btn {
  min-height: 0; padding: 6px 8px; border-radius: 12px; background: var(--card); border: 1px solid var(--border);
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 2px;
  color: var(--strong);
}
.gaze-btn .gaze-arrow { font-size: clamp(15px, 1.7vw, 20px); line-height: 1; color: var(--primary); }
body.dim .gaze-btn .gaze-arrow { color: #93c5fd; }
.gaze-btn .gaze-en { font-size: clamp(15px, 1.65vw, 18px); font-weight: 700; line-height: 1.15; }
.gaze-btn.gaze-center { background: var(--soft); border-color: var(--primary); }
.gaze-btn.pos-up { grid-column: 2; grid-row: 1; }
.gaze-btn.pos-left { grid-column: 1; grid-row: 2; }
.gaze-btn.pos-center { grid-column: 2; grid-row: 2; }
.gaze-btn.pos-right { grid-column: 3; grid-row: 2; }
.gaze-btn.pos-down { grid-column: 2; grid-row: 3; }

.surgery-list { min-height: 0; display: flex; flex-direction: column; gap: 6px; }
.surgery-row-3 { flex: 1; min-height: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.surgery-row-2 { flex: 1; min-height: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.phrase-card {
  flex: 1; min-height: 0; padding: 6px 14px; border-radius: 12px; text-align: left;
  background: var(--card-sub); border: 1px solid var(--border); color: var(--strong);
  display: flex; flex-direction: column; justify-content: center;
}
.phrase-card.center { align-items: center; text-align: center; padding: 6px 10px; }
.phrase-card .phrase-en { font-size: clamp(14.5px, 1.6vw, 18px); font-weight: 650; line-height: 1.2; }
.phrase-card.sense { background: var(--soft); border-color: var(--primary); color: var(--strong); }
.phrase-card.sense .phrase-en { font-size: clamp(13.5px, 1.45vw, 16.5px); }
.phrase-card.safety { background: var(--warning-bg); border-color: var(--warning-border); color: var(--warning-ink); }
.phrase-card.finish { background: var(--ok-bg); border-color: var(--ok-border); color: var(--ok-ink); }

/* Exam cockpit: 3 grouped clinical columns */
.exam-cockpit { flex: 1; min-height: 0; display: grid; grid-template-columns: 1.08fr 0.82fr 1.1fr; gap: 8px; }
.exam-col {
  background: var(--card-sub); border: 1px solid var(--border); border-radius: 14px; padding: 8px;
  display: flex; flex-direction: column; gap: 6px; min-height: 0;
}
.exam-col-title {
  margin: 0; font-size: 11.5px; font-weight: 750; letter-spacing: .9px; text-transform: uppercase; color: var(--muted-ink);
}
.mini-compass { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr 1fr 1fr; grid-template-rows: 1fr 1fr 1fr; gap: 5px; }
.mini-compass .gaze-btn { min-height: 0; padding: 4px; }
.mini-compass .gaze-btn .gaze-arrow { font-size: 13px; }
.mini-compass .gaze-btn .gaze-en { font-size: 14px; }
.exam-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.exam-btn {
  min-height: 48px; padding: 8px 12px; border-radius: 11px; text-align: left;
  background: var(--card); border: 1px solid var(--border); color: var(--strong);
  display: flex; flex-direction: column; justify-content: center;
}
.exam-btn .phrase-en { font-size: clamp(14px, 1.5vw, 16.5px); font-weight: 650; line-height: 1.2; }
.exam-btn.tint { background: var(--soft); border-color: var(--primary); }
.exam-btn.subtle {
  min-height: 40px; padding: 6px 10px; background: var(--card); border-color: var(--border); color: var(--muted-ink);
  align-items: center; text-align: center;
}
.exam-btn.subtle .phrase-en { font-size: clamp(13px, 1.35vw, 15px); font-weight: 650; }
.exam-btn.grow { flex: 1; }
.exam-col.refraction > .exam-pair, .exam-col.refraction > .exam-btn { flex: 1; }
.exam-col.refraction > .exam-pair-slim { flex: 0.72; }
.exam-btn.phoropter {
  flex: 1.45; background: var(--primary); border-color: var(--primary); color: var(--white);
  align-items: center; text-align: center;
}
.exam-btn.phoropter .phrase-en { font-size: clamp(18px, 2.2vw, 23px); font-weight: 700; }

.phrase:hover:not(:disabled) { border-color: var(--primary); }
.phrase:active { transform: scale(.985); }
.phrase.is-speaking {
  background: var(--primary) !important; border-color: var(--primary) !important; color: var(--white) !important;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .32);
}
.phrase.is-speaking small, .phrase.is-speaking .gaze-arrow { color: rgba(255,255,255,.9) !important; }

/* Bottom dock */
.actions { flex: none; display: grid; grid-template-columns: auto auto auto 1fr auto auto; align-items: center; gap: 9px; }
.phrase-toggle, #repeat { min-height: 62px; padding: 8px 16px; font-size: 17px; font-weight: 650; color: var(--strong); }
.phrase-toggle[aria-pressed="true"] { background: var(--soft); border-color: var(--primary); color: var(--primary); }
body.dim .phrase-toggle[aria-pressed="true"] { color: var(--white); }

.talk {
  min-height: 62px; font-size: 20px; font-weight: 700; color: var(--white); background: var(--primary); border-color: var(--primary);
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.talk:hover:not(:disabled):not(.held) { background: var(--hover); border-color: var(--hover); }
.talk.held { background: var(--live); border-color: var(--live); }
.mic-icon, .mute-icon { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.mute-btn {
  min-height: 62px; min-width: 118px; padding: 8px 16px; font-size: 18px; font-weight: 700;
  color: var(--strong); background: var(--card); border: 1.5px solid var(--border);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.mute-btn:hover:not(:disabled) { border-color: var(--live); color: var(--live); }
.mute-btn[aria-pressed="true"] {
  background: var(--live); border-color: var(--live); color: var(--white);
  box-shadow: 0 0 0 3px rgba(194, 65, 12, .22);
}
.mute-btn[aria-pressed="true"]:hover:not(:disabled) { color: var(--white); opacity: .94; }

.mode-seg {
  min-height: 62px; background: var(--seg-bg); border: 1px solid var(--border); border-radius: 14px;
  padding: 4px; display: inline-flex; align-items: stretch; gap: 4px; position: relative;
}
.seg-opt {
  min-height: 0; padding: 0 14px; border-radius: 10px; border: 1px solid transparent;
  background: transparent; color: var(--muted-ink); font-size: 16px; font-weight: 650;
}
.seg-opt[aria-pressed="true"] {
  background: var(--seg-active-bg); color: var(--seg-active-ink);
  box-shadow: 0 1px 3px rgba(8, 46, 112, .14);
}
.hint { flex: none; margin: 0; font-size: 14px; color: var(--muted-ink); text-align: center; }

/* Phone-only elements stay hidden on iPad & desktop */
.more-btn, .more-menu, .patient-repeat, .auto-chip, .mobile-tabs, .exam-subtabs, .talk-short { display: none; }

/* PIN screen */
#lock {
  flex: 1 0 auto; width: 100%; display: flex; flex-direction: column;
  padding: calc(16px + env(safe-area-inset-top)) 24px calc(28px + env(safe-area-inset-bottom));
}
.lock-top {
  flex: none; width: 100%; max-width: 1120px; margin: 0 auto;
  display: flex; justify-content: flex-end;
}
.lock-inner { width: 100%; max-width: 400px; margin: auto; padding: 12px 0; text-align: center; }
.version-pill {
  min-height: 32px; padding: 5px 13px; border-radius: 999px;
  font-size: 12.5px; font-weight: 550; letter-spacing: 0.01em; line-height: 1.2;
  color: var(--muted-ink); background: var(--seg-bg); border: 1px solid var(--border-soft);
  box-shadow: 0 1px 2px rgba(8, 46, 112, .05); touch-action: manipulation;
}
.version-pill:active { background: var(--soft); color: var(--strong); border-color: var(--border); transform: scale(.97); }
#lock .logo { height: 64px; max-width: 100%; margin: 0 auto; }
.lock-form { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; margin-top: 22px; width: 100%; }
.lock-form h1 { font-size: clamp(24px, 3.6vw, 32px); margin: 0; }
.pin {
  display: block; width: 100%; max-width: 100%; min-width: 0;
  min-height: 62px; padding: 12px 18px; font: inherit; font-size: 30px; letter-spacing: 8px; text-align: center;
  color: var(--ink); background: var(--card); border: 1px solid var(--border); border-radius: 14px;
  caret-color: transparent; user-select: none; -webkit-user-select: none;
}
.pin:focus-visible { outline: 3px solid var(--primary); outline-offset: 3px; }
.pin.nudge { animation: warn-nudge .35s ease; }
.pin-dots {
  display: flex; align-items: center; justify-content: center; gap: 16px;
  min-height: 44px; padding: 8px 4px;
}
.pin-dots.compact { gap: 11px; }
.pin-dot {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--border); background: var(--card);
  transition: background-color .1s ease, border-color .1s ease, transform .12s ease;
}
.pin-dots.compact .pin-dot { width: 14px; height: 14px; }
.pin-dot.filled { background: var(--primary); border-color: var(--primary); transform: scale(1.08); }
.pin-dots.verifying .pin-dot.filled { animation: pulse .7s infinite; }
.pin-dots.nudge { animation: warn-nudge .35s ease; }
.pin-dots.has-error .pin-dot { border-color: var(--danger-border); }
.keypad { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.pin-key {
  min-height: 66px; padding: 10px; border-radius: 14px;
  font-size: 28px; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1;
  color: var(--strong); background: var(--card); border: 1px solid var(--border);
  display: inline-flex; align-items: center; justify-content: center;
  touch-action: manipulation; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.pin-key:active:not(:disabled) { background: var(--soft); border-color: var(--primary); transform: scale(.96); }
.pin-key-action { font-size: 16px; font-weight: 650; color: var(--muted-ink); background: var(--card-sub); }
.pin-key-action:active:not(:disabled) { color: var(--strong); }
.pin-back-icon { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.unlock {
  width: 100%; min-height: 60px; font-size: 20px; font-weight: 650; color: var(--white);
  background: var(--primary); border-color: var(--primary); touch-action: manipulation;
}
.unlock:active:not(:disabled) { transform: scale(.985); }
#lockError { margin: 0; text-align: center; }
@media (hover: hover) {
  .version-pill:hover { background: var(--soft); color: var(--strong); border-color: var(--border); }
  .pin-key:hover:not(:disabled) { border-color: var(--primary); }
  .unlock:hover:not(:disabled) { background: var(--hover); border-color: var(--hover); }
  .modal-close:hover { background: var(--soft); color: var(--strong); }
  .human-picker-btn:hover, .human-btn:hover { border-color: var(--primary); }
  .human-call-btn:hover { background: var(--hover); border-color: var(--hover); }
  .human-copy-btn:hover { border-color: var(--primary); }
}

/* What's new modal */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(10, 22, 46, .48);
  display: flex; align-items: center; justify-content: center;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
}
body.dim .modal-backdrop { background: rgba(2, 6, 16, .72); }
.modal-card {
  width: 100%; max-width: 540px; max-height: min(80dvh, 660px);
  background: var(--card); border: 1px solid var(--border); border-radius: 20px;
  box-shadow: 0 24px 60px rgba(8, 25, 60, .24);
  display: flex; flex-direction: column; overflow: hidden;
}
body.dim .modal-card { box-shadow: 0 24px 60px rgba(0, 0, 0, .6); }
.modal-head {
  flex: none; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 18px 18px 16px 24px; border-bottom: 1px solid var(--border-soft);
}
.modal-head h2 {
  margin: 0; font-family: Georgia, "Times New Roman", serif;
  font-size: 21px; font-weight: 600; line-height: 1.25; color: var(--strong);
}
.modal-close {
  flex: none; width: 34px; height: 34px; min-height: 34px; padding: 0; border-radius: 10px;
  border: 1px solid transparent; background: var(--seg-bg); color: var(--muted-ink);
  display: inline-flex; align-items: center; justify-content: center;
}
.modal-close svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }
.modal-close:active { background: var(--soft); color: var(--strong); }
.modal-body {
  flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 20px 24px 24px; display: flex; flex-direction: column; gap: 22px;
}
.release-head { display: flex; align-items: baseline; gap: 6px; margin: 0 0 8px; font-size: 14.5px; line-height: 1.3; }
.release-ver { font-weight: 700; color: var(--primary); }
body.dim .release-ver { color: #93c5fd; }
.release-date { font-weight: 500; color: var(--muted-ink); }
.release-list { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 7px; font-size: 14.5px; line-height: 1.5; color: var(--ink); }
.modal-card-narrow { max-width: 440px; }
.human-body { gap: 14px; text-align: center; }
.human-lang {
  margin: 0; align-self: center; padding: 4px 12px; border-radius: 999px;
  background: var(--soft); color: var(--strong); font-size: 13.5px; font-weight: 650;
}
.human-number {
  margin: 4px 0; font-size: 32px; font-weight: 700; letter-spacing: 0.5px;
  font-variant-numeric: tabular-nums; color: var(--strong);
}
.human-actions { display: grid; grid-template-columns: 1fr; gap: 10px; }
.human-call-btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 54px; padding: 10px 18px; border-radius: 14px; text-decoration: none;
  background: var(--primary); border: 1px solid var(--primary); color: var(--white);
  font-size: 17px; font-weight: 650;
}
.human-copy-btn { min-height: 48px; font-size: 16px; font-weight: 600; color: var(--strong); }
.human-note { margin: 2px 0 0; font-size: 13.5px; line-height: 1.45; color: var(--muted-ink); }

/* Portrait iPad */
@media (max-width: 960px) {
  .bar-product, .bar-beta { display: none; }
  .actions { grid-template-columns: 1fr 1fr 1fr auto; }
  .actions .talk { grid-column: 1 / 4; grid-row: 1; }
  .actions .mute-btn { grid-column: 4; grid-row: 1; }
  .exam-cockpit { grid-template-columns: 1fr 1fr; }
  .exam-col.refraction { grid-column: 1 / -1; }
}

/* Phone-first layout */
@media (max-width: 640px) {
  /* Picker */
  #picker { padding: 16px 14px calc(24px + env(safe-area-inset-bottom)); }
  .logo { height: 58px; }
  h1 { font-size: 26px; margin: 18px 0 6px; letter-spacing: -0.5px; }
  .lead { font-size: 15.5px; margin-bottom: 14px; }
  .picker-controls { gap: 8px; }
  .search, .offline-switch, .human-picker-btn { min-height: 46px; font-size: 15.5px; border-radius: 12px; }
  .offline-switch, .human-picker-btn { width: 100%; }
  .group h2 { margin: 16px 0 8px; }
  .languages { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .lang { font-size: 18.5px; min-height: 92px; padding: 12px 13px; border-radius: 14px; }
  .lang small { font-size: 13.5px; }
  .lang-tag { font-size: 10.5px; padding: 2px 6px; }

  /* Room shell & clean top bar */
  #room { gap: 8px; padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); }
  .bar { position: relative; gap: 8px; }
  .bar-brand, #flip, #dim, .vol-wrap, #smaller, #larger { display: none; }
  .status-pill { min-height: 42px; padding: 5px 12px; font-size: 14.5px; gap: 8px; flex: 0 1 auto; }
  .human-btn { min-width: 42px; min-height: 42px; padding: 0 10px; }
  .human-label { display: none; }
  .more-btn {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 42px; min-height: 42px; padding: 0 10px; font-size: 20px; font-weight: 700; line-height: 1;
    color: var(--strong);
  }
  .end-btn { min-height: 42px; padding: 6px 13px; font-size: 15px; }

  /* Overflow popover menu */
  .more-menu {
    display: flex; flex-direction: column; gap: 4px;
    position: absolute; top: calc(100% + 6px); right: 0; z-index: 30;
    min-width: 224px; padding: 8px; border-radius: 16px;
    background: var(--card); border: 1px solid var(--border);
    box-shadow: 0 14px 32px rgba(8, 46, 112, .22);
  }
  body.dim .more-menu { box-shadow: 0 14px 32px rgba(0, 0, 0, .55); }
  .more-item {
    display: flex; align-items: center; justify-content: space-between; width: 100%;
    min-height: 44px; padding: 8px 12px; border: 0; border-radius: 10px;
    background: transparent; color: var(--strong); font-size: 15px; font-weight: 600;
  }
  .more-item:active { background: var(--soft); }
  .more-badge {
    font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px;
    background: var(--seg-bg); color: var(--muted-ink);
  }
  .more-item[aria-checked="true"] .more-badge { background: var(--primary); color: var(--white); }
  .more-vol-row, .more-speed-row {
    display: flex; flex-direction: column; gap: 6px;
    padding: 8px 10px 6px 12px; border-top: 1px solid var(--border-soft); margin-top: 2px;
  }
  .more-size-row {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    padding: 6px 8px 2px 12px; border-top: 1px solid var(--border-soft); margin-top: 2px;
  }
  .more-size-label { font-size: 14px; font-weight: 600; color: var(--muted-ink); }
  .more-size-btns { display: flex; gap: 6px; }
  .more-size-btn {
    min-height: 38px; min-width: 48px; padding: 4px 10px; border-radius: 10px;
    font-size: 15px; font-weight: 700; color: var(--strong);
  }

  /* Captions & inline patient repeat */
  .captions { gap: 8px; }
  .panel { border-radius: 16px; padding: 11px 14px 12px; }
  .label { font-size: 13px; }
  .prev-caption { font-size: 13px; margin-top: 5px; padding-bottom: 5px; }
  .caption { font-size: calc(var(--caption-size) * 0.78); line-height: 1.22; margin-top: 6px; }
  .patient-intro { gap: 7px; padding: 8px 4px; }
  .intro-actions { gap: 8px; }
  .intro-play-btn { min-height: 44px; padding: 8px 16px; font-size: 15px; }
  .intro-skip-btn { min-height: 44px; padding: 8px 14px; font-size: 14.5px; }
  .intro-sub { font-size: 12.5px; }
  .patient-repeat {
    display: inline-flex; align-items: center; gap: 4px;
    min-height: 30px; padding: 2px 10px; border-radius: 999px;
    font-size: 12.5px; font-weight: 650;
    background: rgba(255, 255, 255, .14); color: var(--white); border: 1px solid rgba(255, 255, 255, .26);
  }
  .patient-repeat:active { background: rgba(255, 255, 255, .26); }

  /* Compact patient card & clean phrase header when cockpit is open */
  .captions.phrases-open { grid-template-rows: auto minmax(0, 1fr); }
  .captions.phrases-open .panel.patient { padding: 9px 13px 10px; max-height: 86px; }
  .captions.phrases-open .panel.patient .caption { max-height: 44px; font-size: 18px; line-height: 1.2; margin-top: 3px; }
  .panel.phrases { padding: 8px 10px 10px; }
  .panel.phrases .label { display: none; }
  .phrase-list { margin-top: 0; }

  /* Surgery cockpit: flex column eliminates overlap */
  .surgery-cockpit { display: flex; flex-direction: column; gap: 7px; height: 100%; min-height: 0; }
  .gaze-compass {
    flex: none; height: clamp(150px, 24dvh, 188px); padding: 6px; gap: 5px; border-radius: 12px;
  }
  .gaze-btn { min-height: 0; padding: 4px 5px; border-radius: 10px; gap: 1px; }
  .gaze-btn .gaze-arrow { font-size: 14px; }
  .gaze-btn .gaze-en { font-size: 13px; line-height: 1.1; }
  .surgery-list { flex: 1; min-height: 0; gap: 5px; }
  .surgery-row-3, .surgery-row-2 { gap: 5px; }
  .phrase-card { flex: 1; min-height: 40px; padding: 5px 10px; border-radius: 11px; }
  .phrase-card.center { padding: 5px 6px; }
  .phrase-card .phrase-en { font-size: 14.5px; line-height: 1.16; }
  .phrase-card.sense .phrase-en { font-size: 13px; }

  /* Exam cockpit: 3 focused sub-tabs */
  .exam-cockpit { display: flex; flex-direction: column; gap: 8px; height: 100%; min-height: 0; }
  .exam-subtabs {
    flex: none; display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px;
    padding: 3px; border-radius: 12px; background: var(--seg-bg); border: 1px solid var(--border);
  }
  .exam-subtab {
    min-height: 36px; padding: 4px 6px; border: 0; border-radius: 9px;
    background: transparent; color: var(--muted-ink); font-size: 13.5px; font-weight: 700;
  }
  .exam-subtab[aria-pressed="true"] {
    background: var(--seg-active-bg); color: var(--seg-active-ink);
    box-shadow: 0 1px 3px rgba(8, 46, 112, .14);
  }
  .exam-col { flex: 1; min-height: 0; padding: 8px; gap: 7px; border-radius: 12px; }
  .exam-col:not(.exam-active) { display: none; }
  .exam-col-title { display: none; }
  .mini-compass { flex: 1; min-height: 156px; gap: 5px; }
  .mini-compass .gaze-btn { min-height: 0; padding: 4px; }
  .mini-compass .gaze-btn .gaze-arrow { font-size: 14px; }
  .mini-compass .gaze-btn .gaze-en { font-size: 13.5px; }
  .exam-btn { min-height: 44px; padding: 7px 12px; }
  .exam-btn.subtle { min-height: 36px; padding: 5px 8px; }
  .exam-btn .phrase-en { font-size: 15px; }
  .exam-btn.subtle .phrase-en { font-size: 13.5px; }
  .exam-btn.phoropter .phrase-en { font-size: 20px; }

  /* Slim bottom dock + 3-tab bar */
  .phrase-toggle, #repeat, .mode-seg, .hint { display: none; }
  body[data-state="offline"] .actions { display: none; }
  .talk-full { display: none; }
  .talk-short { display: inline; }
  .actions { display: grid; grid-template-columns: 1fr auto auto; gap: 7px; }
  .actions .talk { grid-column: 1; grid-row: 1; min-height: 54px; padding: 8px 12px; font-size: 16px; border-radius: 14px; gap: 7px; }
  .actions .mute-btn {
    grid-column: 2; grid-row: 1; min-height: 54px; min-width: 78px; padding: 6px 10px;
    font-size: 14px; border-radius: 14px; gap: 5px;
  }
  .actions .mute-icon { width: 17px; height: 17px; }
  .auto-chip {
    grid-column: 3; grid-row: 1;
    display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
    min-width: 60px; min-height: 54px; padding: 6px 8px; border-radius: 14px;
    background: var(--card); border: 1px solid var(--border); color: var(--strong); line-height: 1.1;
  }
  .auto-title { font-size: 14px; font-weight: 700; }
  .auto-state { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; color: var(--muted-ink); }
  .auto-chip[aria-pressed="true"] { background: var(--soft); border-color: var(--primary); color: var(--primary); }
  .auto-chip[aria-pressed="true"] .auto-state { color: var(--primary); }
  body.dim .auto-chip[aria-pressed="true"], body.dim .auto-chip[aria-pressed="true"] .auto-state { color: var(--white); }

  .mobile-tabs {
    flex: none; display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px;
    padding: 4px; border-radius: 14px; background: var(--seg-bg); border: 1px solid var(--border);
  }
  .mobile-tab {
    min-height: 40px; padding: 6px 8px; border: 0; border-radius: 10px;
    background: transparent; color: var(--muted-ink); font-size: 14.5px; font-weight: 700;
  }
  .mobile-tab[aria-pressed="true"] {
    background: var(--seg-active-bg); color: var(--seg-active-ink);
    box-shadow: 0 1px 3px rgba(8, 46, 112, .14);
  }

  /* PIN screen */
  #lock { padding: calc(10px + env(safe-area-inset-top)) 18px calc(20px + env(safe-area-inset-bottom)); }
  .lock-inner { padding: 8px 0; }
  #lock .logo { height: 50px; }
  .lock-form { margin-top: 16px; gap: 11px; }
  .lock-form h1 { font-size: 23px; }
  .pin { min-height: 54px; padding: 10px 14px; font-size: 26px; letter-spacing: 6px; }
  .pin-dots { min-height: 38px; gap: 14px; }
  .pin-dot { width: 15px; height: 15px; }
  .keypad { gap: 9px; }
  .pin-key { min-height: 58px; font-size: 26px; border-radius: 13px; }
  .pin-key-action { font-size: 15px; }
  .unlock { min-height: 54px; font-size: 18px; }
  .modal-head { padding: 16px 14px 14px 18px; }
  .modal-head h2 { font-size: 19px; }
  .modal-body { padding: 16px 18px 20px; gap: 18px; }
}

@media (max-height: 680px) {
  #lock { padding-top: calc(10px + env(safe-area-inset-top)); padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
  .lock-inner { padding: 4px 0; }
  #lock .logo { height: 42px; }
  .lock-form { margin-top: 12px; gap: 8px; }
  .pin { min-height: 48px; font-size: 24px; }
  .pin-dots { min-height: 34px; padding: 4px; }
  .keypad { gap: 8px; }
  .pin-key { min-height: 52px; font-size: 24px; }
  .unlock { min-height: 50px; font-size: 17px; }
}
