/* OpenCaptions UI components. Colours, type and motion come from tokens.css (light + dark). */
@import url('/tokens.css');

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--fg); font-family: var(--font); -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-rendering: optimizeLegibility; }
body { font-size: 16px; line-height: 1.5; }
h1, h2, h3 { font-family: var(--font-display); font-weight: 800; letter-spacing: -.02em; line-height: 1.12; }
h1 { letter-spacing: -.03em; }
a { color: inherit; text-underline-offset: .18em; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }
code { font-family: var(--mono); font-size: .9em; background: var(--bg3); padding: .1em .35em; border-radius: 6px; }
::selection { background: var(--hl); color: var(--hl-ink); }
button, select, input, textarea { font: inherit; color: inherit; }
button {
  background: var(--bg2); border: 1px solid var(--line-strong); border-radius: 10px; padding: 8px 14px; cursor: pointer;
  box-shadow: var(--shadow-sm); transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
button:hover { background: color-mix(in srgb, var(--bg3) 55%, var(--bg2)); border-color: color-mix(in srgb, var(--fg) 28%, var(--line-strong)); }
button:active { transform: translateY(1px); box-shadow: none; }
button.primary { background: var(--primary-bg); border-color: var(--primary-bg); color: var(--primary-fg); font-weight: 700; }
button.primary:hover { background: color-mix(in srgb, var(--primary-bg) 88%, var(--fg)); border-color: color-mix(in srgb, var(--primary-bg) 88%, var(--fg)); }
button.danger { border-color: color-mix(in srgb, var(--bad) 45%, var(--line)); color: var(--bad); }
button:disabled { opacity: .5; cursor: default; transform: none; }
select, input, textarea {
  background: var(--bg2); border: 1px solid var(--line-strong); border-radius: 10px; padding: 8px 10px; min-width: 0;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
select {
  -webkit-appearance: none; appearance: none; cursor: pointer; padding-right: 34px; text-overflow: ellipsis;
  background-image: var(--chevron); background-repeat: no-repeat; background-position: right 12px center; background-size: 11px 8px;
}
select::-ms-expand { display: none; }
input::placeholder, textarea::placeholder { color: color-mix(in srgb, var(--fg2) 75%, transparent); }
input[type='checkbox'], input[type='radio'], input[type='range'] { accent-color: var(--fg); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 18%, transparent); }
button:focus-visible, a:focus-visible, summary:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.muted { color: var(--fg2); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 13px; border-radius: var(--pill);
  border: 1px solid var(--line-strong); background: var(--bg2); cursor: pointer; font-size: 14px; white-space: nowrap; box-shadow: none;
}
.pill[aria-pressed='true'] { background: var(--primary-bg); border-color: var(--primary-bg); color: var(--primary-fg); font-weight: 700; }
.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; padding: 2px 9px; border-radius: var(--pill); background: var(--bg3); border: 1px solid transparent; line-height: 1.5; }
.chip.ok { color: var(--ok); background: color-mix(in srgb, var(--ok) 11%, var(--bg2)); border-color: color-mix(in srgb, var(--ok) 28%, transparent); }
.chip.warn { color: var(--warn); background: color-mix(in srgb, var(--warn) 11%, var(--bg2)); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.chip.bad { color: var(--bad); background: color-mix(in srgb, var(--bad) 10%, var(--bg2)); border-color: color-mix(in srgb, var(--bad) 28%, transparent); font-weight: 700; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--fg2); display: inline-block; flex: none; }
.dot.live { background: var(--bad); box-shadow: 0 0 0 0 color-mix(in srgb, var(--bad) 60%, transparent); animation: pulse 1.6s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--bad) 55%, transparent); } 70% { box-shadow: 0 0 0 7px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
.card { background: var(--bg2); border: 1px solid var(--line); border-radius: 16px; padding: 18px; box-shadow: var(--shadow-sm); }
a.card { transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease); }
a.card:hover { border-color: var(--line-strong); box-shadow: var(--shadow); transform: translateY(-1px); }
.meter { height: 8px; background: var(--bg3); border-radius: 4px; overflow: hidden; position: relative; }
.meter > i { position: absolute; inset: 0 auto 0 0; background: linear-gradient(90deg, var(--ok), var(--ok) 70%, var(--warn) 85%, var(--bad)); width: 0; transition: width .12s linear; border-radius: 4px; }
.meter > b { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--fg); opacity: .7; transition: left .3s; }

/* ---- logo + wordmark ---- */
.brand { font-family: var(--font-display); font-weight: 800; letter-spacing: -.025em; display: inline-flex; align-items: center; gap: .4em; white-space: nowrap; }
a.brand { color: inherit; text-decoration: none; }
.brand::before { print-color-adjust: exact; -webkit-print-color-adjust: exact; content: ''; display: inline-block; flex: none; width: 1.55em; height: 1.17em; background: var(--logo) center / contain no-repeat; }
.brand .sub { font-family: var(--font); font-weight: 400; letter-spacing: 0; color: var(--fg2); }
/* Inline logo (<svg class="oc-logo" viewBox="0 0 878 664"><use class="o" …/><use class="ln" …/></svg>), coloured per theme. */
.oc-logo { display: block; overflow: visible; }
.oc-logo .o { fill: var(--logo-o); }
.oc-logo .ln { fill: var(--logo-line); }
/* Signature motion: the caption line "types" out of the O. */
.oc-logo.typing .ln { transform-box: fill-box; transform-origin: 0 50%; animation: oc-type 2.6s steps(6, end) infinite; }
@keyframes oc-type { 0% { transform: scaleX(0); } 45%, 80% { transform: scaleX(1); } 100% { transform: scaleX(0); } }
.oc-logo.typed .ln { transform-box: fill-box; transform-origin: 0 50%; animation: oc-type-once .9s steps(6, end) .2s both; }
@keyframes oc-type-once { from { transform: scaleX(0); } to { transform: scaleX(1); } }

/* ---- signature motion: highlighter sweep on the live word ----
   The lime (::before) and an ink copy of the word (::after) are revealed together, left to right, so the word is
   always ink on lime or plain text on the page — never light text on lime. Final state is the resting style. */
.live-word { position: relative; z-index: 0; white-space: nowrap; }
.live-word::before, .live-word::after { position: absolute; top: 0; bottom: 0; left: -.1em; right: -.1em; padding: 0 .1em; border-radius: .18em; clip-path: inset(0 0 0 0 round .18em); animation: oc-sweep var(--sweep) var(--ease) both; }
.live-word::before { content: ''; z-index: -1; background: var(--hl); top: .04em; bottom: .02em; }
.live-word::after { content: attr(data-w); content: attr(data-w) / ''; color: var(--hl-ink); line-height: normal; white-space: nowrap; }
@keyframes oc-sweep { from { clip-path: inset(0 100% 0 0 round .18em); } }
.translation { color: var(--translation); }

.hidden { display: none !important; }
dialog { background: var(--bg2); color: var(--fg); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 22px; max-width: min(640px, 92vw); width: 100%; box-shadow: var(--shadow-lg); }
dialog::backdrop { background: var(--scrim); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
dialog h3 { font-size: 20px; }
label.field { display: grid; gap: 5px; font-size: 13px; color: var(--fg2); }
label.field > * { color: var(--fg); }
.prefs { gap: 6px; flex-wrap: nowrap; }
.prefs select { padding: 5px 28px 5px 10px; font-size: 13px; background-position: right 10px center; border-radius: 9px; }
.prefs button { padding: 5px 10px; border-radius: 9px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: 10px 18px; border-radius: 12px; z-index: 50; box-shadow: var(--shadow-lg); font-weight: 700; animation: oc-rise .24s var(--ease); }
@keyframes oc-rise { from { opacity: 0; transform: translate(-50%, 8px); } }
.empty-state { display: grid; justify-items: center; gap: 14px; text-align: center; color: var(--fg2); }
.empty-state .oc-logo { width: 64px; }

/* ---------- audience: sheets, assistant, reading ---------- */
dialog.sheet { margin: auto auto 0; width: 100%; max-width: 720px; max-height: 88dvh; border-radius: var(--radius-lg) var(--radius-lg) 0 0; padding: 10px 20px calc(20px + env(safe-area-inset-bottom)); overflow: auto; border-bottom: 0; }
dialog.sheet::before { content: ''; display: block; width: 40px; height: 4px; border-radius: 4px; background: var(--line-strong); margin: 0 auto 12px; }
dialog.sheet[open] { animation: oc-sheet .28s var(--ease); }
@keyframes oc-sheet { from { transform: translateY(24px); opacity: .4; } }
dialog.sheet .sheet-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
dialog.sheet .sheet-head h2 { font-size: 21px; margin: 0; flex: 1; }
dialog.sheet .sheet-head button { border-radius: var(--pill); width: 36px; height: 36px; padding: 0; box-shadow: none; border: 0; background: var(--bg3); }
.seg { display: inline-flex; background: var(--bg3); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 9px; font-size: 14px; box-shadow: none; }
.seg button[aria-pressed='true'] { background: var(--bg2); box-shadow: var(--shadow-sm); font-weight: 700; }
.as-sum { margin: 14px 0 6px; min-height: 60px; }
.as-sum h3 { font-size: 19px; margin: 0 0 8px; line-height: 1.3; }
.as-sum ul { margin: 0; padding-left: 20px; display: grid; gap: 6px; font-size: 16px; line-height: 1.5; }
.as-terms { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.as-note { font-size: 12px; color: var(--fg2); margin-top: 10px; }
.as-ask { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 14px; }
.as-ask label { font-weight: 700; display: block; margin-bottom: 8px; }
.as-ask .row { flex-wrap: nowrap; }
.as-ask input { flex: 1; font-size: 16px; min-width: 0; width: 100%; }
.as-ans { margin-top: 12px; font-size: 16px; line-height: 1.55; }
.as-ans blockquote { margin: 8px 0 0; padding: 8px 12px; border-left: 3px solid var(--fg); background: var(--bg3); border-radius: 0 10px 10px 0; font-size: 15px; }
.as-ans blockquote b { font-family: var(--mono); font-size: 12px; color: var(--fg2); margin-right: 6px; }
.skeleton { background: linear-gradient(90deg, var(--bg3), var(--bg2), var(--bg3)); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: 8px; height: 14px; margin: 8px 0; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.set-row { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.set-row:last-child { border-bottom: 0; }
mark { background: var(--hl); color: var(--hl-ink); border-radius: 3px; padding: 0 2px; }
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
svg.i { width: 16px; height: 16px; flex: none; vertical-align: -3px; }
button:has(> svg.i), .btn-i { display: inline-flex; align-items: center; gap: 7px; }
