:root {
  color-scheme: light;
  font-family: system-ui, -apple-system, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', 'Noto Sans CJK SC', sans-serif;
  --page-bg: #f6f7f9;
  --text: #1f2328;
  --muted: #57606a;
  --border: #d0d7de;
  --accent: #0969da;
  --caption-bg: #0d1117;
  --caption-final: #ffffff;
  --caption-interim: #b6c2cf;
  --caption-size: 32px;
  --state-color: #57606a;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
}

body {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  min-width: 0;
  background: var(--page-bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

/* Explicit rows: a hidden notice must not shift the caption area into an auto-sized row. */
body > .topbar {
  grid-row: 1;
}

body > .notice {
  grid-row: 2;
}

body > .workspace {
  grid-row: 3;
}

/* ---------- control bar ---------- */

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 20px;
  min-width: 0;
  padding: 10px 20px;
  background: #ffffff;
  border-bottom: 1px solid var(--border);
}

.topbar h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  white-space: nowrap;
}

.controls {
  display: flex;
  flex: 1 1 auto;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  min-width: 0;
}

.choice {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.choice legend {
  float: left;
  padding: 0;
  margin-right: 4px;
  font-size: 15px;
  color: var(--muted);
}

.choice label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #ffffff;
  font-size: 15px;
  cursor: pointer;
  white-space: nowrap;
}

.choice input {
  margin: 0;
  accent-color: var(--accent);
}

.choice label:has(input:checked) {
  border-color: var(--accent);
  background: #ddf4ff;
  color: #0a3069;
  font-weight: 600;
}

.choice label:has(input:disabled) {
  color: #8c959f;
  background: #f6f8fa;
  border-style: dashed;
  cursor: not-allowed;
}

.actions {
  display: flex;
  gap: 8px;
}

button {
  font: inherit;
  font-size: 16px;
  padding: 6px 18px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #ffffff;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}

button.primary {
  border-color: #1a7f37;
  background: #1f883d;
  color: #ffffff;
  font-weight: 600;
}

button.secondary {
  border-color: #cf222e;
  background: #ffffff;
  color: #a40e26;
  font-weight: 600;
}

button:disabled,
button.primary:disabled,
button.secondary:disabled {
  border-color: #d0d7de;
  background: #eaeef2;
  color: #8c959f;
  cursor: not-allowed;
  font-weight: 400;
}

button:focus-visible,
.choice label:has(input:focus-visible) {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button.link {
  border-color: transparent;
  background: transparent;
  color: var(--accent);
  padding: 6px 8px;
  font-size: 15px;
  text-decoration: underline;
}

.pip-control {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
  min-width: 0;
}

.pip-unsupported {
  min-width: 0;
  color: #82071e;
  font-size: 14px;
}

/* ---------- status (text + colour + icon, distinct per state) ---------- */

.status-box {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border: 2px solid var(--state-color);
  border-radius: 999px;
  background: #ffffff;
  color: var(--state-color);
  font-size: 16px;
  white-space: nowrap;
}

.status-caption {
  color: var(--muted);
  font-size: 14px;
}

#status {
  color: var(--state-color);
}

.status-indicator {
  display: inline-block;
  width: 1.2em;
  text-align: center;
  color: var(--state-color);
}

body[data-state='idle'] {
  --state-color: #57606a;
}

body[data-state='starting'] {
  --state-color: #9a6700;
}

body[data-state='running'] {
  --state-color: #1a7f37;
}

body[data-state='stopped'] {
  --state-color: #424a53;
}

body[data-state='error'] {
  --state-color: #cf222e;
}

body[data-state='running'] .status-indicator {
  animation: pulse 1.6s ease-in-out infinite;
}

@keyframes pulse {
  50% {
    opacity: 0.45;
  }
}

@media (prefers-reduced-motion: reduce) {
  body[data-state='running'] .status-indicator {
    animation: none;
  }
}

/* ---------- notice ---------- */

.notice {
  margin: 10px 20px 0;
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 15px;
  border: 1px solid #ff818266;
  background: #ffebe9;
  color: #a40e26;
}

.notice[data-kind='info'] {
  border-color: #54aeff66;
  background: #ddf4ff;
  color: #0a3069;
}

/* ---------- workspace and captions ---------- */

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  gap: 16px;
  min-width: 0;
  min-height: 0;
  padding: 12px 20px 16px;
}

/* Wide layout: captions keep the left column, the system-audio instructions get a scrolling right column. */
body[data-source='system'] .workspace {
  grid-template-columns: minmax(0, 1fr) 360px;
}

/* ---------- system audio instructions ---------- */

.system-panel {
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #ffffff;
  font-size: 14px;
  line-height: 1.55;
}

.system-panel summary {
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.system-unsupported {
  margin: 0 0 10px;
  padding: 8px 10px;
  border: 1px solid #ff818266;
  border-radius: 6px;
  background: #ffebe9;
  color: #82071e;
  font-size: 15px;
}

.system-steps,
.system-notes {
  margin: 8px 0;
  padding-left: 1.4em;
}

.system-steps li + li,
.system-notes li + li {
  margin-top: 4px;
}

.system-notes {
  color: var(--muted);
}

.system-matrix-title {
  margin: 12px 0 6px;
  font-size: 15px;
  font-weight: 600;
}

.matrix-wrap {
  min-width: 0;
}

.support-matrix {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  font-size: 14px;
}

.support-matrix th,
.support-matrix td {
  padding: 4px 5px;
  border: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
}

.support-matrix thead th {
  background: #f6f8fa;
  font-weight: 600;
}

.support-matrix tbody th {
  font-weight: 500;
}

.support-matrix tr[data-current='true'] {
  background: #ddf4ff;
}

.support-matrix .level-full {
  color: #1a7f37;
  font-weight: 600;
}

.support-matrix .level-partial {
  color: #9a6700;
  font-weight: 600;
}

.support-matrix .level-none {
  color: #cf222e;
}

.caption-panel {
  position: relative;
  min-width: 0;
  min-height: 0;
  border-radius: 10px;
  background: var(--caption-bg);
  overflow: hidden;
}

/* Absolutely positioned so caption content never grows the page: only this element scrolls. */
.caption-scroll {
  position: absolute;
  inset: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 16px 24px 24px;
  overscroll-behavior: contain;
}

[data-caption-size='s'] {
  --caption-size: 24px;
}

[data-caption-size='m'] {
  --caption-size: 32px;
}

[data-caption-size='l'] {
  --caption-size: 40px;
}

[data-caption-size='xl'] {
  --caption-size: 52px;
}

.hint {
  margin: 0 0 8px;
  color: #9da7b3;
  font-size: 15px;
}

.caption-scroll:has(.caption:not(:empty)) .hint {
  display: none;
}

.captions {
  list-style: none;
  margin: 0;
  padding: 0;
}

.caption {
  min-width: 0;
  margin: 0;
  padding: 4px 0 4px 16px;
  border-left: 4px solid transparent;
  color: var(--caption-final);
  font-size: var(--caption-size);
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: normal;
}

.caption + .caption {
  margin-top: 6px;
}

.caption:empty {
  display: none;
}

.caption[data-status='interim'],
.caption[data-status='finalizing'] {
  color: var(--caption-interim);
  border-left: 4px dashed var(--caption-interim);
}

.caption[data-status='interim']::after,
.caption[data-status='finalizing']::after {
  content: '…';
}

.caption[data-status='interrupted'] {
  color: var(--caption-interim);
  font-style: italic;
}

.jump-latest {
  position: absolute;
  right: 20px;
  bottom: 16px;
  border-color: #388bfd;
  background: #1f6feb;
  color: #ffffff;
  font-size: 15px;
  box-shadow: 0 2px 8px rgb(0 0 0 / 40%);
}

/* ---------- floating caption window (Document PiP document, TD-104) ---------- */

body.pip {
  grid-template-rows: auto minmax(0, 1fr);
  background: var(--caption-bg);
  color: var(--caption-final);
}

body.pip .pip-bar {
  grid-row: 1;
  justify-self: start;
  margin: 6px 10px 0;
  font-size: 14px;
}

body.pip .pip-scroll {
  grid-row: 2;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 6px 14px 10px;
}

/* ---------- first-run guide ---------- */

.guide {
  width: min(600px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  padding: 20px 24px;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
}

.guide::backdrop {
  background: rgb(13 17 23 / 55%);
}

.guide h2 {
  margin: 0 0 8px;
  font-size: 18px;
}

.guide-steps {
  margin: 0;
  padding-left: 1.4em;
}

.guide-steps li + li {
  margin-top: 6px;
}

.guide-note {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.guide-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 16px;
}

/* ---------- narrow windows ---------- */

@media (max-width: 1099.98px) {
  body {
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
  }

  .topbar {
    padding: 10px 12px;
  }

  .workspace,
  body[data-source='system'] .workspace {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: none;
    padding: 10px 12px 12px;
  }

  .caption-panel {
    min-height: 55vh;
  }

  /* Instructions (and the unsupported notice) above the captions, so they are read before clicking "开始". */
  .system-panel {
    order: -1;
    overflow-y: visible;
  }

  .caption-scroll {
    padding: 12px 16px 20px;
  }
}
