:root {
  color-scheme: light;
  font: 16px system-ui, sans-serif;
  --ink: #142c4b;
  --muted: #536b87;
  --blue: #1769df;
  --pale: #eaf3ff;
  --border: #dce9f8;
  background: #f3f8ff;
  color: var(--ink);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body, h1, h2, p { margin: 0; }
.icon-library { position: absolute; width: 0; height: 0; overflow: hidden; }
main { max-width: 680px; margin: auto; padding: 20px 16px 24px; }
.topbar, .caption-heading, .language-bar, .my-language, .video-row, .video-actions {
  display: flex;
  align-items: center;
}
.topbar { justify-content: space-between; gap: 8px; padding-bottom:4px; }
h1, h2 { font-size: 1.25rem; line-height: 1.25; }
.status, .hint { color: var(--muted); line-height: 1.45; }
.status { margin: 8px 0 12px; font-size: .875rem; }
.recover-mic { align-self: flex-start; margin-bottom: 8px; }
.permission-help { display: grid; grid-template-columns: 24px minmax(0, 1fr); align-items: start; flex-shrink: 0; gap: 10px; margin-bottom: 12px; padding: 12px; border: 1px solid var(--border); border-radius: 14px; background: white; }
.permission-help > svg, .permission-retry svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.permission-help > svg { color: var(--blue); }
.permission-copy h2 { font-size: 1rem; margin-bottom: 4px; }
.permission-help p, .permission-settings { color: var(--muted); font-size: .875rem; line-height: 1.45; }
.permission-retry { grid-column: 1 / -1; display: flex; justify-content: center; align-items: center; gap: 8px; }
.permission-settings { grid-column: 1 / -1; }
.permission-settings summary { min-height: 32px; padding: 6px 0; color: #155dbf; cursor: pointer; }
.permission-settings ol { margin: 4px 0 0; padding-inline-start: 22px; }
.permission-settings li + li { margin-top: 6px; }
.hint { font-size: .875rem; }
section { background: white; border: 1px solid var(--border); border-radius: 18px; }
#setup { display: grid; gap: 14px; width:100%; max-width: 480px; margin:20px auto 0; padding: 22px; }
#setup > p:first-child { padding:12px 14px; border-radius:12px; background:var(--pale); font-size:.9375rem; color:var(--muted); }
#setup > p:first-child strong { color:var(--ink); }
#setup #join { min-height:52px; margin-top:2px; }
.optional-name { color:var(--muted); font-size:.9375rem; }
.optional-name summary { cursor:pointer; padding:10px 0; min-height:44px; }
.optional-name input { width:100%; margin-top:4px; }
#setup label { margin-top: 6px; font-weight: 600; }
select, button, #guestName { min-height: 44px; padding: 6px 10px; border-radius: 12px; font: inherit; }
select, #guestName { min-width: 0; border: 1px solid var(--border); background: white; color: inherit; }
.camera-choice, .caption-settings label { display: flex; align-items: center; gap: 10px; }
.camera-choice { padding:12px 0; border-top:1px solid var(--border); font-size:.9375rem; }
.camera-choice input { width:20px; height:20px; accent-color:var(--blue); flex-shrink:0; }
button { border: 0; background: var(--blue); color: white; cursor: pointer; font-weight: 600; }
button:disabled { opacity: .6; cursor: default; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid #1769df80; outline-offset: 2px; }
.language-trigger { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; min-width: 0; min-height: 54px; padding: 12px 14px; text-align: start; color: var(--ink); background: #f3f8ff; border: 1px solid var(--border); border-radius: 16px; }
.language-trigger span { min-width: 0; overflow-wrap: anywhere; }
.language-trigger svg, .picker-search > svg, .language-empty svg { flex: 0 0 24px; width: 24px; height: 24px; fill: none; stroke: var(--blue); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.language-trigger.compact { width: auto; max-width: 100%; min-height: 44px; padding: 7px 10px; font-size: .875rem; border-radius: 12px; }
.language-picker-open { overflow: hidden; }
.language-picker { width: min(560px, calc(100% - 24px)); max-width: none; max-height: calc(100vh - 24px); max-height: calc(100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); margin: auto; padding: 0; border: 1px solid var(--border); border-radius: 24px; background: white; color: var(--ink); box-shadow: 0 16px 60px #142c4b26; overflow: hidden; }
.language-picker::backdrop { background: #142c4b80; }
.picker-shell { height: min(680px, calc(100vh - 24px)); height: min(680px, calc(100dvh - 24px)); max-height: inherit; min-height: 0; display: flex; flex-direction: column; }
.picker-header { padding: 12px 16px 12px 20px; flex-shrink: 0; }
.picker-title-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.picker-title-row h2 { font-size: 1.375rem; overflow-wrap: anywhere; }
.picker-title-row button { flex-shrink: 0; background: transparent; color: var(--muted); }
.picker-header > p { margin-top: 6px; color: var(--muted); font-size: .875rem; line-height: 1.5; }
.picker-current { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 10px; padding-top: 4px; }
.picker-current strong { color: var(--blue); overflow-wrap: anywhere; }
.picker-search { margin: 0 20px 12px; display: flex; align-items: center; gap: 8px; padding: 0 10px; border: 1px solid var(--border); border-radius: 16px; min-height: 48px; background: #f3f8ff; flex-shrink: 0; }
.picker-search:focus-within { border-color: var(--blue); }
.picker-search input { width: 100%; min-width: 0; min-height: 46px; border: 0; padding: 10px 0; color: var(--ink); background: transparent; font: inherit; outline: none; }
.picker-search input::-webkit-search-cancel-button { appearance: none; }
.picker-search button { min-width: 44px; flex-shrink: 0; background: transparent; color: var(--muted); }
.language-choices { flex: 1; min-height: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 11rem), 1fr)); gap: 10px; align-content: start; overflow-y: auto; overscroll-behavior: contain; padding: 2px 20px 8px; scroll-padding: 8px; }
.language-option { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-width: 0; min-height: 64px; padding: 12px 14px; border: 2px solid transparent; box-shadow: inset 0 0 0 1px var(--border); border-radius: 16px; color: var(--ink); background: #f3f8ff; text-align: start; font-weight: 500; }
.language-option[aria-selected="true"] { border-color: var(--blue); box-shadow: none; background: var(--pale); color: var(--blue); }
.language-option .language-copy { min-width: 0; display: flex; flex-direction: column; gap: 4px; overflow-wrap: anywhere; }
.language-option strong { font-size: 1rem; line-height: 1.4; font-weight: 600; }
.language-option small { color: var(--muted); font-size: .8125rem; line-height: 1.35; }
.language-check { width: 20px; height: 20px; flex: 0 0 20px; visibility: hidden; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.language-option[aria-selected="true"] .language-check { visibility: visible; }
.language-empty { flex: 1; min-height: 0; overflow: auto; padding: 24px; text-align: center; color: var(--muted); line-height: 1.5; }
.language-empty svg { width: 36px; height: 36px; margin-bottom: 10px; stroke: var(--muted); }
.picker-footer { display: flex; justify-content: center; flex-wrap: wrap; gap: 4px 12px; padding: 12px 20px max(12px, env(safe-area-inset-bottom)); color: var(--muted); font-size: .8125rem; line-height: 1.5; border-top: 1px solid var(--border); flex-shrink: 0; }
.quiet { background: var(--pale); color: #155dbf; }
.icon-button { display: inline-grid; place-items: center; min-width: 44px; padding: 0; }
.icon-button svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-button.is-off { background: #e5ebf4; color: #405570; }
.locale, .video-actions button { font-size: .8125rem; }

.in-call main {
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding:12px 12px max(8px, env(safe-area-inset-bottom));
}
.in-call .permission-help { max-height: min(24dvh, 160px); overflow-y: auto; }
.in-call .topbar h1 { font-size:1.0625rem; }
.in-call .topbar, .in-call .status, .in-call #media, .in-call .controls { flex-shrink:0; }
.in-call .status { margin:2px 0 10px; font-size:.8125rem; }
.language-bar { display:grid; grid-template-columns:minmax(0,1fr) minmax(0,1fr); gap:12px; padding:10px 12px; margin-bottom:10px; border:1px solid var(--border); border-radius:14px; background:white; font-size:.875rem; align-items:start; }
.my-language, .peer-language { display:flex; flex-direction:column; align-items:flex-start; gap:3px; min-width:0; text-align:start; overflow-wrap:anywhere; }
.my-language > span, .peer-language > span { font-size:.75rem; color:var(--muted); }
.peer-language { border-inline-start:1px solid var(--border); padding-inline-start:12px; }
.video-row { display:block; position:relative; margin-bottom:10px; }
.translations-only .video-row { display:none; }
.video-actions { position:absolute; inset:8px 8px auto auto; display:flex; gap:6px; }
.video-actions button { color:white; background:#142c4bbf; border:1px solid #ffffff40; border-radius:12px; }
.video { width:100%; position:relative; height:clamp(150px,30vh,340px); overflow:hidden; background:#142745; border-radius:16px; }
video { display:block; width:100%; height:100%; object-fit:contain; }
#local { position:absolute; width:28%; height:47%; right:8px; bottom:8px; background:#274462; border:1px solid #ffffff66; border-radius:10px; object-fit:cover; transform:scaleX(-1); }
.video-row.video-hidden { min-height:44px; }
.video-row.video-hidden .video-actions { position:static; justify-content:flex-end; }
.video-row.video-hidden .video-actions button { background:var(--pale); color:var(--blue); border-color:var(--border); }

#captions { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.caption-heading { justify-content: space-between; gap: 6px; padding: 4px 12px; border-bottom: 1px solid var(--border); }
.caption-heading h2 { font-size:1rem; }
.caption-heading .icon-button { background:transparent; color:var(--muted); }
.caption-settings { display: flex; flex-wrap: wrap; gap: 12px; padding: 8px 12px; color: var(--muted); font-size: .875rem; }
#asr { color: var(--muted); font-size: .78rem; line-height: 1.3; overflow-wrap: anywhere; padding: 6px 12px 0; }
#asr:empty { display: none; }
#messages { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; display: flex; flex-direction: column; gap: 10px; padding: 12px; }
.bubble { max-width: 91%; align-self: flex-start; border: 1px solid var(--border); border-radius: 14px 14px 14px 4px; background: #f7faff; padding: 10px 12px; overflow-wrap: anywhere; }
.mine { align-self: flex-end; border-radius: 14px 14px 4px 14px; background: var(--pale); }
.bubble small { display: block; color: var(--muted); font-size: .75rem; }
.bubble .primary { margin-top: 3px; font-size: 1.25rem; font-weight: 600; line-height: 1.4; }
.bubble .secondary { margin-top: 4px; color: var(--muted); font-size: .9375rem; line-height: 1.45; }
.bubble .progress { margin-top: 4px; }
.bubble.provisional { border-style: dashed; }
.large-captions .bubble .primary { font-size: 1.55rem; }
.caption-footer { display: flex; justify-content: center; }
#follow { margin: 4px 0; }
.transcript-download { display: inline-grid; place-items: center; min-height: 44px; padding: 8px 12px; margin: 4px 0; border-radius: 12px; text-decoration: none; font-weight: 600; }
.controls { display: flex; justify-content: space-evenly; gap:16px; margin-top:10px; padding:10px 12px; background:white; border:1px solid var(--border); border-radius:20px; }
.controls button { width:52px; height:48px; border-radius:50%; }
#end { background: #c52c41; }

@media (max-height: 500px) {
  .in-call main { padding-top: 4px; }
  .in-call .status { margin: 2px 0 4px; }
  .video-row { margin-bottom: 4px; }
  .video { height:80px; }
  .language-bar { padding:6px 10px; margin-bottom:6px; }
  .controls { padding:5px 10px; margin-top:6px; }
  .in-call .topbar { display:none; }
  .picker-header > p { display: none; }
  .picker-header { padding: 8px 16px; }
  .picker-search { margin-bottom: 8px; }
  .picker-footer { padding-top: 8px; padding-bottom: 8px; }
  .picker-footer [data-text="languagePickAction"] { display: none; }
}

/* Media faults stay actionable without covering captions or call controls. */
#videoHealth { display:flex; flex-wrap:wrap; align-items:center; gap:10px; padding:10px 12px; border-radius:12px; background:#fff3dc; color:#674719; }
#videoHealth[hidden] { display:none; }
#videoHealth button { margin-inline-start:auto; min-height:44px; }

#startupHelp { padding:16px; border-radius:16px; background:#fff; border:1px solid var(--line); }
#startupHelp button { display:block; width:100%; margin-block:8px; white-space:normal; overflow-wrap:anywhere; }
#startupLink { width:100%; box-sizing:border-box; }

/* Ending a call stays deliberate; completed invitations never show a dead join form. */
.hangup-dialog { width:min(440px, calc(100% - 32px)); max-height:calc(100vh - 32px); max-height:calc(100dvh - 32px); box-sizing:border-box; overflow:auto; padding:24px; border:1px solid var(--border); border-radius:24px; color:var(--ink); background:white; box-shadow:0 20px 60px #142c4b26; }
.hangup-dialog::backdrop { background:#142c4b66; }
.hangup-dialog h2 { margin:0 0 12px; }
.hangup-dialog p { margin:0 0 22px; line-height:1.55; color:var(--muted); }
.hangup-actions { display:grid; gap:10px; }
.hangup-actions button { min-height:48px; padding:10px 16px; white-space:normal; overflow-wrap:anywhere; }
#confirmEnd { background:#c52c41; }
.finished-call { padding:24px; margin-bottom:16px; text-align:center; }
.finished-call h2 { margin:12px 0; overflow-wrap:anywhere; }
.finished-call p { margin:10px 0 0; line-height:1.55; }
.finished-icon { display:grid; place-items:center; width:56px; height:56px; margin:auto; border-radius:50%; background:var(--pale); color:var(--blue); }
.finished-icon svg { width:30px; height:30px; }
/* Completed calls use the document scroll, not the live transcript scroller. */
.call-ended #captions { display:block; overflow:visible; }
.call-ended #messages { flex:none; overflow:visible; overscroll-behavior:auto; }
.call-ended .bubble { flex-shrink:0; }
.call-ended #follow { display:none; }

#finishedTitle:focus { outline:none; }
.finished-call .transcript-download { display:inline-flex; justify-content:center; margin-top:16px; background:var(--blue); color:white; padding:10px 18px; }

/* Spoken languages are selected before joining and read-only during the call. */
#liveLanguagePickerOpen { min-height:0; padding:0; border:0; background:none; color:var(--ink); opacity:1; cursor:default; font-size:inherit; max-width:100%; overflow-wrap:anywhere; }
#liveLanguagePickerOpen svg { display:none; }
.live-language-value { min-width:0; }

.in-call.media-help-visible .video { height:90px; }
