:root {
  color-scheme: dark;
  --page: #090d17;
  --page-glow: rgb(37 99 235 / 16%);
  --page-glow-secondary: rgb(220 38 38 / 11%);
  --surface: #111827;
  --surface-raised: #151e2e;
  --surface-subtle: #0e1523;
  --text: #f8fafc;
  --muted: #a4b0c2;
  --quiet: #718096;
  --line: rgb(148 163 184 / 19%);
  --line-strong: rgb(148 163 184 / 35%);
  --primary: #4f8cff;
  --primary-strong: #2563eb;
  --primary-tint: rgb(79 140 255 / 14%);
  --success: #34d399;
  --success-tint: rgb(52 211 153 / 13%);
  --warning: #fbbf24;
  --warning-tint: rgb(251 191 36 / 14%);
  --danger: #fb7185;
  --danger-tint: rgb(251 113 133 / 13%);
  --focus: #93c5fd;
  --shadow: 0 20px 48px rgb(0 0 0 / 24%);
  --radius-xl: 24px;
  --radius-lg: 16px;
  --radius-md: 12px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --page: #f3f6fb;
    --page-glow: rgb(37 99 235 / 12%);
    --page-glow-secondary: rgb(220 38 38 / 8%);
    --surface: #ffffff;
    --surface-raised: #f9fbff;
    --surface-subtle: #f3f6fb;
    --text: #0f172a;
    --muted: #526076;
    --quiet: #6b7a90;
    --line: rgb(51 65 85 / 13%);
    --line-strong: rgb(51 65 85 / 24%);
    --primary: #2563eb;
    --primary-strong: #1d4ed8;
    --primary-tint: rgb(37 99 235 / 9%);
    --success: #047857;
    --success-tint: rgb(4 120 87 / 9%);
    --warning: #b45309;
    --warning-tint: rgb(180 83 9 / 10%);
    --danger: #be123c;
    --danger-tint: rgb(190 18 60 / 8%);
    --focus: #1d4ed8;
    --shadow: 0 18px 44px rgb(15 23 42 / 9%);
  }
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--page); }
body {
  min-width: 320px;
  min-height: 100dvh;
  margin: 0;
  overflow-x: hidden;
  color: var(--text);
  background:
    radial-gradient(circle at 12% -8%, var(--page-glow), transparent 33rem),
    radial-gradient(circle at 96% 5%, var(--page-glow-secondary), transparent 28rem),
    var(--page);
}
button, input { font: inherit; }
button { touch-action: manipulation; }

.skip-link {
  position: fixed;
  z-index: 10;
  top: 12px;
  left: 12px;
  padding: 10px 14px;
  color: var(--text);
  background: var(--surface-raised);
  border: 1px solid var(--focus);
  border-radius: 8px;
  transform: translateY(-160%);
}
.skip-link:focus { transform: translateY(0); }

.app-shell { width: min(1400px, calc(100% - 48px)); margin: 0 auto; padding: 52px 0 32px; }
.topbar { display: grid; grid-template-columns: minmax(0, 1fr) minmax(320px, 400px); align-items: end; gap: 32px; margin-bottom: 26px; }
.brand-block { max-width: 720px; }
.brand-identity { display: flex; align-items: center; gap: 18px; }
.brand-logo { flex: 0 0 auto; width: clamp(76px, 9vw, 116px); aspect-ratio: 1; object-fit: contain; filter: drop-shadow(0 10px 16px rgb(0 0 0 / 16%)); }
.brand-identity h1 { max-width: none; margin-bottom: 0; }
.eyebrow, .section-label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  color: var(--quiet);
  font-size: .72rem;
  font-weight: 800;
  letter-spacing: .13em;
  line-height: 1.2;
}
.eyebrow { color: var(--primary); }
.eyebrow > span, .stream-badge > span, .task-state::before, .status::before {
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  content: "";
}
.eyebrow > span { box-shadow: 0 0 0 5px var(--primary-tint); }
h1, h2, h3, p { margin-top: 0; }
h1 { max-width: 14ch; margin: 10px 0 14px; font-size: clamp(2.25rem, 5.4vw, 4.65rem); line-height: .98; letter-spacing: -.055em; }
h2 { margin: 0; font-size: clamp(1.15rem, 2vw, 1.45rem); line-height: 1.2; letter-spacing: -.025em; }
h3 { margin: 5px 0 0; font-size: 1.06rem; line-height: 1.25; }
.intro { max-width: 61ch; margin-bottom: 0; color: var(--muted); font-size: 1.02rem; line-height: 1.72; }
.muted, .help, .footer, .section-note { color: var(--muted); }

.backend-card, .control-card, .runtime-panel, .task-workspace { border: 1px solid var(--line); box-shadow: var(--shadow); }
.backend-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 20px;
  background: linear-gradient(145deg, var(--surface-raised), var(--surface));
  border-radius: var(--radius-lg);
}
.backend-card h2 { margin-top: 6px; font-size: 1.08rem; }
.backend-card .muted { max-width: 26ch; margin: 7px 0 0; font-size: .86rem; line-height: 1.5; }
.status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-height: 40px;
  padding: 8px 12px;
  color: var(--muted);
  background: var(--surface-subtle);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: .9rem;
  font-weight: 750;
  white-space: nowrap;
}
.status::before { background: var(--quiet); }
.status[data-state="ready"] { color: var(--success); background: var(--success-tint); border-color: var(--success); }
.status[data-state="ready"]::before { background: var(--success); }
.status[data-state="busy"] { color: var(--warning); background: var(--warning-tint); border-color: var(--warning); }
.status[data-state="busy"]::before { background: var(--warning); }
.status[data-state="offline"], .status[data-state="error"] { color: var(--danger); background: var(--danger-tint); border-color: var(--danger); }
.status[data-state="offline"]::before, .status[data-state="error"]::before { background: var(--danger); }

.workspace { display: grid; gap: 18px; }
.workspace:focus { outline: none; }
.control-card, .runtime-panel { padding: 24px; background: var(--surface); border-radius: var(--radius-lg); }
.section-heading, .task-header, .pane-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.section-heading { margin-bottom: 20px; }
.section-heading h2 { margin-top: 6px; }
.section-note { margin: 0; font-size: .82rem; line-height: 1.4; text-align: right; }
label { display: block; margin-bottom: 9px; font-size: .9rem; font-weight: 750; }
.form-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; }
input {
  width: 100%;
  min-height: 50px;
  padding: 12px 14px;
  color: var(--text);
  background: var(--surface-subtle);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  outline: none;
  transition: border-color .2s ease, box-shadow .2s ease, background-color .2s ease;
}
input::placeholder { color: var(--quiet); }
input:hover { border-color: var(--primary); }
input:focus { border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-tint); background: var(--surface-raised); }
button {
  min-height: 50px;
  padding: 11px 18px;
  color: #fff;
  background: var(--primary-strong);
  border: 1px solid var(--primary-strong);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 18px rgb(37 99 235 / 18%);
  font-size: .92rem;
  font-weight: 780;
  cursor: pointer;
  transition: background-color .2s ease, border-color .2s ease, color .2s ease, opacity .2s ease, transform .2s ease;
}
button:hover:not(:disabled) { background: var(--primary); border-color: var(--primary); transform: translateY(-1px); }
button:active:not(:disabled) { transform: translateY(0); }
button:disabled { cursor: not-allowed; opacity: .48; box-shadow: none; }
button.secondary { color: var(--text); background: transparent; border-color: var(--line-strong); box-shadow: none; }
button.secondary:hover:not(:disabled) { color: var(--primary); background: var(--primary-tint); border-color: var(--primary); }
button.stop-button { color: var(--danger); border-color: var(--danger); }
button.stop-button:hover:not(:disabled) { color: var(--danger); background: var(--danger-tint); border-color: var(--danger); }
input:focus-visible, button:focus-visible, video:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
.help { margin: 10px 0 0; font-size: .86rem; line-height: 1.55; }
.error { min-height: 0; margin: 0; color: var(--danger); font-size: .9rem; font-weight: 700; }
.error:not(:empty) { margin-top: 12px; padding: 10px 12px; background: var(--danger-tint); border: 1px solid var(--danger); border-radius: 10px; }
.access-key-gate {
  position: fixed;
  z-index: 20;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgb(15 23 42 / 42%);
  backdrop-filter: blur(8px);
}
.access-key-gate[hidden] { display: none; }
.access-key-dialog {
  width: min(100%, 430px);
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}
.access-key-dialog h2 { margin: 7px 0 0; }
.access-key-dialog .muted { margin: 9px 0 22px; }
.access-key-dialog button { width: 100%; margin-top: 14px; }
.access-key-error { min-height: 1.5em; margin: 10px 0 0; color: var(--danger); font-size: .88rem; font-weight: 700; }

.runtime-panel { background: linear-gradient(135deg, var(--surface), var(--surface-raised)); }
.runtime-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; margin: 0; }
.runtime-metric { min-width: 0; min-height: 104px; padding: 15px; background: var(--surface-subtle); border: 1px solid var(--line); border-radius: var(--radius-md); }
.runtime-metric dt { color: var(--quiet); font-size: .78rem; font-weight: 700; line-height: 1.35; }
.runtime-metric dd { margin: 10px 0 0; overflow-wrap: anywhere; color: var(--text); font-size: .98rem; font-weight: 760; font-variant-numeric: tabular-nums; line-height: 1.32; }

.task-workspace { padding: 24px; background: var(--surface); border-radius: var(--radius-xl); }
.task-header { padding-bottom: 22px; border-bottom: 1px solid var(--line); }
.task-header h2 { margin-top: 6px; }
.task-state { display: inline-flex; align-items: center; gap: 8px; margin: 12px 0 0; color: var(--muted); font-size: .91rem; font-weight: 700; }
.task-state::before { background: var(--quiet); }
.task-state[data-state="assigning"], .task-state[data-state="connecting"], .task-state[data-state="transcribing"] { color: var(--success); }
.task-state[data-state="assigning"]::before, .task-state[data-state="connecting"]::before, .task-state[data-state="transcribing"]::before { background: var(--success); box-shadow: 0 0 0 5px var(--success-tint); }
.task-state[data-state="stopping"], .task-state[data-state="time_limit_reached"] { color: var(--warning); }
.task-state[data-state="stopping"]::before, .task-state[data-state="time_limit_reached"]::before { background: var(--warning); }
.task-state[data-state="failed"], .task-state[data-state="worker_lost"] { color: var(--danger); }
.task-state[data-state="failed"]::before, .task-state[data-state="worker_lost"]::before { background: var(--danger); }
.task-header-side { display: flex; align-items: center; justify-content: flex-end; gap: 18px; }
.timer { min-width: 104px; padding: 10px 0 10px 16px; border-left: 1px solid var(--line); text-align: right; }
.timer span { display: block; color: var(--quiet); font-size: .75rem; font-weight: 750; letter-spacing: .04em; }
.timer strong { display: block; margin-top: 2px; color: var(--text); font-size: 1.48rem; font-variant-numeric: tabular-nums; letter-spacing: -.04em; }
.actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; }
.actions button { min-height: 44px; padding-inline: 14px; }

.media-pane { min-width: 0; padding: 18px; background: var(--surface-subtle); border: 1px solid var(--line); border-radius: var(--radius-lg); }
.pane-heading { align-items: center; margin-bottom: 16px; }
.pane-heading h3 { margin-bottom: 0; }
.stream-badge { display: inline-flex; align-items: center; gap: 7px; padding: 6px 9px; color: var(--danger); background: var(--danger-tint); border: 1px solid var(--danger); border-radius: 999px; font-size: .75rem; font-weight: 780; white-space: nowrap; }
.stream-badge > span { width: 6px; height: 6px; background: var(--danger); box-shadow: 0 0 0 4px rgb(251 113 133 / 16%); }
.media-stage { position: relative; isolation: isolate; }
.media-pane video { display: block; width: 100%; aspect-ratio: 16 / 9; background: #000; border: 1px solid var(--line); border-radius: var(--radius-md); }
.media-loading {
  position: absolute;
  z-index: 2;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  color: #fff;
  background: rgb(0 0 0 / 66%);
  border-radius: var(--radius-md);
  font-size: clamp(1rem, 2vw, 1.2rem);
  font-weight: 760;
  letter-spacing: .01em;
  pointer-events: none;
  text-align: center;
}
.media-loading[hidden] { display: none; }
.caption-overlay {
  position: absolute;
  z-index: 3;
  right: clamp(12px, 4vw, 48px);
  bottom: clamp(62px, 10vw, 92px);
  left: clamp(12px, 4vw, 48px);
  display: flex;
  justify-content: center;
  pointer-events: none;
}
.caption-text {
  max-width: min(100%, 62rem);
  margin: 0;
  padding: .48em .78em;
  color: #fff;
  background: rgb(0 0 0 / 72%);
  border: 1px solid rgb(255 255 255 / 22%);
  border-radius: .45em;
  box-shadow: 0 2px 14px rgb(0 0 0 / 32%);
  font-size: clamp(1rem, 2.1vw, 1.45rem);
  font-weight: 720;
  line-height: 1.5;
  overflow-wrap: anywhere;
  text-align: center;
  text-shadow: 0 1px 2px #000;
}
.caption-keyword { color: #fb7185; font-weight: 850; }
.media-status { min-height: 1.5em; margin: 10px 0 0; font-size: .86rem; }
.footer { max-width: 85ch; margin-top: 20px; padding: 0 4px; font-size: .82rem; line-height: 1.6; }
.footer p { margin: 0; }

@media (max-width: 1120px) {
  .topbar { grid-template-columns: 1fr; align-items: stretch; }
  .backend-card { max-width: 560px; }
}

@media (max-width: 780px) {
  .app-shell { width: min(100% - 28px, 1400px); padding-top: 28px; }
  .topbar { gap: 20px; margin-bottom: 18px; }
  h1 { max-width: 12ch; font-size: clamp(2.2rem, 13vw, 3.55rem); }
  .control-card, .runtime-panel, .task-workspace { padding: 18px; }
  .backend-card { max-width: none; padding: 17px; }
  .section-heading, .task-header { gap: 14px; }
  .section-note { max-width: 13ch; }
  .form-row { grid-template-columns: 1fr; }
  .form-row button { width: 100%; }
  .runtime-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .task-header { flex-direction: column; }
  .task-header-side { width: 100%; justify-content: space-between; }
  .actions { justify-content: flex-end; }
}

@media (max-width: 520px) {
  .app-shell { width: min(100% - 22px, 1400px); padding-bottom: 24px; }
  .backend-card { align-items: flex-start; flex-direction: column; }
  .status { min-height: 38px; }
  .section-heading { align-items: flex-start; flex-direction: column; }
  .section-note { max-width: none; text-align: left; }
  .runtime-grid { grid-template-columns: 1fr; }
  .runtime-metric { min-height: auto; }
  .task-header-side { align-items: flex-start; flex-direction: column; }
  .timer { padding: 0; border: 0; text-align: left; }
  .actions { width: 100%; }
  .actions button { flex: 1 1 136px; }
  .media-pane { padding: 14px; }
  .pane-heading { align-items: flex-start; }
  .stream-badge { margin-top: 2px; }
  .caption-overlay { right: 10px; bottom: 54px; left: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0s !important; animation-duration: 0s !important; }
}

/* Public protection page and the separate password-protected admin console. */
.public-topbar { grid-template-columns: minmax(0, 1fr); align-items: start; }
.admin-topbar { grid-template-columns: minmax(0, 1fr) auto; align-items: start; }
.admin-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 14px;
  color: var(--text);
  background: var(--surface-raised);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  font-size: .9rem;
  font-weight: 760;
  text-decoration: none;
  white-space: nowrap;
  transition: border-color .2s ease, color .2s ease, background-color .2s ease;
}
.admin-link:hover { color: var(--primary); background: var(--primary-tint); border-color: var(--primary); }
textarea {
  display: block;
  width: 100%;
  min-height: 116px;
  padding: 12px 14px;
  resize: vertical;
  color: var(--text);
  background: var(--surface-subtle);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  font: inherit;
  line-height: 1.55;
  outline: none;
}
textarea::placeholder { color: var(--quiet); }
textarea:hover { border-color: var(--primary); }
textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-tint); background: var(--surface-raised); }
.submit-row { grid-template-columns: minmax(0, 1fr) auto; align-items: center; margin-top: 14px; }
.submit-row .help { max-width: 64ch; margin: 0; }
.test-page-note { color: var(--primary); font-size: 1rem; font-weight: 780; }
.media-pane-wide { margin-top: 22px; }
.media-pane-wide video { max-height: min(72dvh, 820px); object-fit: contain; }

.admin-shell { max-width: 1180px; }
.admin-login { width: min(100%, 500px); margin: 0 auto; }
.login-form { display: grid; gap: 10px; }
.login-form label:nth-of-type(2) { margin-top: 8px; }
.login-form button { margin-top: 8px; }
.admin-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 0 0 18px; }
.admin-toolbar .help { margin: 0; }
.status-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.status-card {
  min-width: 0;
  min-height: 142px;
  padding: 18px;
  background: linear-gradient(135deg, var(--surface), var(--surface-raised));
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}
.status-card p { margin: 0; color: var(--quiet); font-size: .78rem; font-weight: 800; letter-spacing: .07em; }
.status-card strong { display: block; margin: 14px 0 6px; overflow-wrap: anywhere; color: var(--text); font-size: 1.42rem; letter-spacing: -.035em; }
.status-card span { display: block; color: var(--muted); font-size: .82rem; line-height: 1.45; }
.key-form { max-width: 680px; }
.key-form .help { margin-bottom: 0; }
.generated-keys-wrap { margin-top: 20px; padding: 16px; background: var(--surface-subtle); border: 1px solid var(--success); border-radius: var(--radius-md); }
.key-list-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; color: var(--success); }
.key-list-heading button { min-height: 38px; padding: 6px 11px; }
.generated-keys-wrap pre { max-height: 320px; margin: 0; overflow: auto; padding: 14px; color: var(--text); background: var(--surface-raised); border: 1px solid var(--line); border-radius: 10px; font: 700 .95rem/1.8 ui-monospace, SFMono-Regular, Consolas, monospace; letter-spacing: .06em; }
.share-key-list { display: grid; max-height: 420px; overflow: auto; gap: 8px; }
.share-key-row { display: grid; grid-template-columns: 18ch minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 9px 10px; background: var(--surface-raised); border: 1px solid var(--line); border-radius: 10px; }
.share-key-row code { overflow-wrap: anywhere; color: var(--text); font: 700 .9rem/1.3 ui-monospace, SFMono-Regular, Consolas, monospace; letter-spacing: .05em; }
.share-key-url { min-height: 40px; padding: 8px 10px; font: .82rem/1.3 ui-monospace, SFMono-Regular, Consolas, monospace; letter-spacing: 0; }
.share-link-copy { min-height: 40px !important; padding: 7px 11px !important; white-space: nowrap; }
.unused-key-list { margin-top: 18px; }

@media (max-width: 780px) {
  .public-topbar, .admin-topbar { grid-template-columns: 1fr; }
  .admin-link { justify-self: start; }
  .status-grid { grid-template-columns: 1fr; }
  .submit-row { grid-template-columns: 1fr; }
  .submit-row button { width: 100%; }
  .share-key-row { grid-template-columns: 1fr; align-items: stretch; }
  .share-link-copy { width: 100%; }
}
