:root {
  color-scheme: dark;
  --yellow: #ffe200;
  --yellow-hover: #ffea4d;
  --canvas: #080c10;
  --bar: #292b2c;
  --bar-dark: #222425;
  --danger: #e42158;
  --green: #28b877;
  --white: #f1f1f3;
  --muted: #a3a5a7;
  --caption-font: "Helvetica Neue", Helvetica, Arial, sans-serif;
  --caption-weight: 300;
  --caption-size: clamp(2.45rem, 4.65vw, 7rem);
  --caption-line-height: 1.18;
  --caption-padding: clamp(1.4rem, 2.6vw, 3.75rem);
  --caption-transform: none;
  --highlight-color: rgb(0 0 0 / 88%);
  --highlight-padding: 14px;
  font-family: Inter, Arial, Helvetica, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--canvas);
}

button {
  font: inherit;
}

.captioner {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  height: 100dvh;
  min-height: 360px;
  background: var(--canvas);
  color: var(--white);
}

.captioner[hidden] {
  display: none;
}

.transcript {
  position: relative;
  min-height: 0;
  overflow-y: auto;
  scroll-behavior: smooth;
  outline: none;
  scrollbar-width: thin;
  scrollbar-color: #444 transparent;
  background: var(--canvas);
}

.transcript:focus-visible {
  box-shadow: inset 0 0 0 2px var(--yellow);
}

.transcript-content {
  display: flex;
  align-items: flex-start;
  min-height: 100%;
  padding: var(--caption-padding);
  padding-bottom: calc(var(--caption-padding) + 0.3em);
  font-family: var(--caption-font);
  font-size: var(--caption-size);
  font-weight: var(--caption-weight);
  line-height: var(--caption-line-height);
  letter-spacing: -0.035em;
  text-transform: var(--caption-transform);
  word-break: normal;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  text-wrap: pretty;
}

.transcript-copy {
  width: 100%;
  margin-top: 0;
}

.caption-highlight,
.preview-highlight {
  padding: 0.04em var(--highlight-padding) 0.08em;
  border-radius: 0.08em;
  background: var(--highlight-color);
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

.transcript-content[data-horizontal="left"] .transcript-copy,
.transcript-content[data-horizontal="middle"] .transcript-copy,
.transcript-content[data-horizontal="right"] .transcript-copy {
  width: 52%;
}

.transcript-content[data-horizontal="middle"] .transcript-copy {
  margin-inline: auto;
}

.transcript-content[data-horizontal="right"] .transcript-copy {
  margin-left: auto;
}

.transcript-content[data-vertical="middle"] .transcript-copy {
  margin-block: auto;
}

.transcript-content[data-vertical="bottom"] .transcript-copy,
.transcript-content[data-vertical="lowerThird"] .transcript-copy {
  margin-top: auto;
}

.transcript-content[data-vertical="lowerThird"] .transcript-copy {
  min-height: 25%;
}

.placeholder {
  color: #555b60;
}

.interim {
  color: #8d9297;
}

.notice {
  position: absolute;
  left: 50%;
  bottom: 76px;
  width: min(92vw, 650px);
  padding: 0.85rem 1rem;
  transform: translateX(-50%);
  border: 1px solid #755421;
  border-radius: 0.2rem;
  background: #2e2414;
  color: #ffeab0;
  box-shadow: 0 0.5rem 2rem rgb(0 0 0 / 55%);
  text-align: center;
  z-index: 4;
}

.controls {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-height: 58px;
  padding: 0.5rem 1rem;
  border-top: 1px solid #343637;
  background: var(--bar);
  z-index: 2;
}

.fullscreen-button {
  position: fixed;
  top: 1rem;
  right: 1rem;
  border-color: rgb(255 255 255 / 10%);
  background: rgb(18 23 28 / 72%);
  backdrop-filter: blur(8px);
  z-index: 6;
}

.captioner:fullscreen,
.captioner:-webkit-full-screen {
  grid-template-rows: minmax(0, 1fr);
}

.captioner:fullscreen .controls,
.captioner:fullscreen .notice,
.captioner:-webkit-full-screen .controls,
.captioner:-webkit-full-screen .notice {
  display: none;
}

.brand {
  display: flex;
  align-items: center;
  min-width: max-content;
  margin-right: 0.65rem;
}

.brand-logo {
  display: block;
  width: auto;
  height: 38px;
  object-fit: contain;
}

.status {
  display: flex;
  align-items: center;
  gap: 0.48rem;
  min-width: 148px;
  color: var(--muted);
  font-size: 0.82rem;
}

.status-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #777;
}

.status.is-live {
  color: #9ce7c5;
}

.status.is-live .status-dot {
  background: var(--green);
  box-shadow: 0 0 0 4px rgb(40 184 119 / 13%);
  animation: pulse 1.8s ease-in-out infinite;
}

.status.is-error .status-dot {
  background: var(--danger);
}

.control-group {
  position: relative;
  display: flex;
  gap: 0.25rem;
  margin-left: auto;
}

.icon-only-button {
  width: 38px;
  min-width: 38px;
  padding: 0;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.clear-popover {
  position: absolute;
  right: -0.25rem;
  bottom: calc(100% + 0.9rem);
  display: grid;
  width: min(290px, calc(100vw - 2rem));
  gap: 0.35rem;
  padding: 0.9rem;
  border: 1px solid #43494e;
  border-radius: 0.55rem;
  background: #171c20;
  box-shadow: 0 0.8rem 2.4rem rgb(0 0 0 / 55%);
  color: #f4f5f6;
  z-index: 8;
}

.clear-popover[hidden] {
  display: none;
}

.clear-popover::after {
  content: "";
  position: absolute;
  right: 0.8rem;
  bottom: -0.42rem;
  width: 0.72rem;
  height: 0.72rem;
  transform: rotate(45deg);
  border-right: 1px solid #43494e;
  border-bottom: 1px solid #43494e;
  background: #171c20;
}

.clear-popover strong {
  font-size: 0.9rem;
}

.clear-popover > span {
  color: #aeb5ba;
  font-size: 0.78rem;
  line-height: 1.4;
}

.clear-popover-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.45rem;
  margin-top: 0.45rem;
}

.popover-button {
  min-height: 34px;
  padding: 0.4rem 0.7rem;
  border: 1px solid #3a4146;
  border-radius: 0.3rem;
  background: #242a2f;
  color: #eef0f2;
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 650;
}

.popover-button:hover,
.popover-button:focus-visible {
  border-color: #596169;
  background: #30373d;
}

.popover-confirm {
  border-color: var(--danger);
  background: var(--danger);
  color: #fff;
}

.popover-confirm:hover,
.popover-confirm:focus-visible {
  border-color: #f13c6a;
  background: #f13c6a;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.42rem;
  min-height: 38px;
  padding: 0.45rem 0.72rem;
  border: 1px solid transparent;
  border-radius: 0.2rem;
  background: transparent;
  color: #e8e8e8;
  cursor: pointer;
  font-size: 0.86rem;
  font-weight: 600;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}

.button:hover:not(:disabled) {
  border-color: #47494a;
  background: var(--bar-dark);
  color: #fff;
}

.button:focus-visible {
  outline: 2px solid var(--yellow);
  outline-offset: 2px;
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.35;
}

.button svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.button-primary {
  min-width: 146px;
  margin-left: 0.4rem;
  border-color: var(--green);
  background: var(--green);
  color: #fff;
}

.button-primary:hover:not(:disabled) {
  border-color: #38c88a;
  background: #38c88a;
  color: #fff;
}

.button-primary.is-live {
  border-color: var(--danger);
  background: var(--danger);
  color: #fff;
}

.button-primary.is-live:hover:not(:disabled) {
  border-color: #f13c6a;
  background: #f13c6a;
  color: #fff;
}

.button-danger.is-confirming {
  border-color: var(--danger);
  background: var(--danger);
  color: #fff;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 50%;
  background: transparent;
  color: #b9bbbd;
  cursor: pointer;
}

.icon-button:hover {
  border-color: #464849;
  background: #222425;
  color: #fff;
}

.icon-button:focus-visible {
  outline: 2px solid var(--yellow);
  outline-offset: 2px;
}

.icon-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.settings-button {
  flex: 0 0 auto;
}

.settings-view {
  height: 100dvh;
  overflow-y: auto;
  background: var(--canvas);
  color: var(--white);
}

.settings-view[hidden] {
  display: none;
}

.settings-header {
  position: sticky;
  top: 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  min-height: 72px;
  padding: 0 1.25rem;
  border-bottom: 1px solid #171d22;
  background: rgb(8 12 16 / 92%);
  backdrop-filter: blur(12px);
  z-index: 5;
}

.settings-header h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 650;
  text-align: center;
}

.back-button {
  justify-self: start;
  background: #11171c;
}

.settings-live-status {
  display: flex;
  align-items: center;
  justify-self: end;
  gap: 0.5rem;
  color: var(--muted);
  font-size: 0.78rem;
}

.settings-live-status.is-live {
  color: #9ce7c5;
}

.settings-live-status.is-live .status-dot {
  background: var(--green);
  box-shadow: 0 0 0 4px rgb(40 184 119 / 13%);
}

.settings-body {
  width: min(100% - 2rem, 1080px);
  margin: 0 auto;
  padding: 1.4rem 0 5rem;
}

.settings-section {
  padding: 1.25rem 0 1.5rem;
  border-bottom: 1px solid #1d252c;
}

.section-heading,
.setting-row {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(300px, 1.15fr);
  align-items: center;
  gap: 1.5rem;
}

.section-heading {
  margin-bottom: 0.75rem;
}

.section-heading h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

.section-heading p,
.setting-row p,
.help-card p {
  margin: 0.2rem 0 0;
  color: #777f87;
  font-size: 0.78rem;
  line-height: 1.45;
}

.setting-row {
  min-height: 58px;
  padding: 0.45rem 0;
}

.setting-row > label,
.setting-row > div > label,
.preview-block > span,
legend {
  color: #d4d6d8;
  font-size: 0.9rem;
  font-weight: 600;
}

.inline-fields,
.range-wrap {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

select,
.secondary-button {
  min-height: 40px;
  border: 1px solid #202a32;
  border-radius: 1.25rem;
  background: #11171c;
  color: #d9dcdf;
  font: inherit;
}

select {
  width: 100%;
  padding: 0.5rem 2.2rem 0.5rem 0.85rem;
}

.inline-fields select:first-child {
  flex: 1;
}

.inline-fields select:last-child {
  width: 138px;
}

select:focus-visible,
input:focus-visible,
.secondary-button:focus-visible {
  outline: 2px solid #9bd1ff;
  outline-offset: 2px;
}

.switch {
  position: relative;
  justify-self: end;
  width: 45px;
  height: 24px;
}

.switch input {
  position: absolute;
  opacity: 0;
}

.switch span {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 999px;
  background: #242b31;
  cursor: pointer;
}

.switch span::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #78818a;
  transition: transform 140ms ease, background 140ms ease;
}

.switch input:checked + span {
  background: #98cbf5;
}

.switch input:checked + span::after {
  transform: translateX(21px);
  background: #102c46;
}

.color-input {
  justify-self: end;
  width: 40px;
  height: 40px;
  padding: 0;
  overflow: hidden;
  border: 1px solid #273139;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
}

.color-input::-webkit-color-swatch-wrapper {
  padding: 0;
}

.color-input::-webkit-color-swatch {
  border: 0;
  border-radius: 50%;
}

.range-wrap input[type="range"] {
  flex: 1;
  accent-color: #9bd1ff;
}

.range-wrap > span {
  color: #9299a0;
  font-size: 0.8rem;
}

.range-wrap .range-large {
  font-size: 1.35rem;
}

.range-wrap strong {
  min-width: 54px;
  color: #aeb4b9;
  font-size: 0.76rem;
  font-weight: 500;
  text-align: right;
}

.preview-block {
  margin-top: 0.8rem;
}

.settings-preview {
  height: 145px;
  margin-top: 0.55rem;
  padding: 1rem 1.25rem;
  overflow: hidden;
  border: 1px solid #1d2830;
  border-radius: 0.7rem;
  background: var(--canvas);
  font-family: var(--caption-font);
  font-size: 3.15rem;
  font-weight: var(--caption-weight);
  line-height: var(--caption-line-height);
  text-transform: var(--caption-transform);
}

.preview-interim {
  color: #8d9297;
}

.alignment-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-top: 1.2rem;
}

fieldset {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

legend {
  margin-bottom: 0.55rem;
}

.alignment-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  overflow: hidden;
  border: 1px solid #202a32;
  border-radius: 0.7rem;
  background: #10161b;
}

.alignment-options label {
  position: relative;
  min-height: 96px;
  border: 1px solid #202a32;
  cursor: pointer;
}

.alignment-options input {
  position: absolute;
  opacity: 0;
}

.alignment-options label > span {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 0.45rem;
}

.alignment-options input:checked + span {
  background: #202a33;
  box-shadow: inset 0 0 0 1px #34424e;
}

.alignment-options b {
  color: #cdd1d4;
  font-size: 0.72rem;
  font-weight: 550;
}

.lines,
.v-lines {
  flex: 1;
  margin-top: 0.5rem;
  background: repeating-linear-gradient(to bottom, #eef1f2 0 4px, transparent 4px 8px);
}

.left-lines { width: 55%; }
.center-lines { width: 55%; margin-inline: auto; }
.right-lines { width: 55%; margin-left: auto; }
.v-lines { max-height: 32px; }
.full-v { max-height: 52px; }
.middle-v { margin-block: auto; }
.bottom-v, .lower-v { margin-top: auto; }
.lower-v { max-height: 8px; }

.secondary-button {
  padding: 0.55rem 0.9rem;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
}

.secondary-button:hover {
  border-color: #35434d;
  background: #192128;
}

.mic-fields select:last-child {
  width: auto;
}

.microphone-meter {
  height: 10px;
  margin: 0.4rem 0 1rem calc(50% + 0.75rem);
  overflow: hidden;
  border-radius: 999px;
  background: #182027;
}

.microphone-meter span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green), var(--yellow), var(--danger));
  transition: width 80ms linear;
}

.help-card {
  margin-left: calc(50% + 0.75rem);
  padding: 1rem;
  border: 1px solid #202a32;
  border-radius: 0.7rem;
  background: #0d1318;
}

.help-card strong {
  font-size: 0.88rem;
}

.help-card ol {
  margin: 0.65rem 0;
  padding-left: 1.2rem;
  color: #b7bdc2;
  font-size: 0.8rem;
  line-height: 1.6;
}

.settings-actions {
  display: flex;
  justify-content: flex-end;
  padding-top: 1rem;
}

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

@media (max-width: 840px) {
  .settings-header {
    grid-template-columns: auto 1fr;
    gap: 0.75rem;
  }

  .settings-header h1 {
    text-align: left;
  }

  .settings-live-status {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-self: start;
    padding-bottom: 0.65rem;
  }

  .section-heading,
  .setting-row {
    grid-template-columns: 1fr;
    gap: 0.6rem;
  }

  .switch,
  .color-input {
    justify-self: start;
  }

  .alignment-grid {
    grid-template-columns: 1fr;
  }

  .microphone-meter,
  .help-card {
    margin-left: 0;
  }

  .controls {
    flex-wrap: nowrap;
  }

  .status {
    min-width: 0;
    margin-left: 0;
  }

  .control-group {
    order: initial;
    flex: 0 0 auto;
    width: auto;
    min-width: 0;
    margin-left: auto;
  }

  .control-group .button {
    flex: 0 0 auto;
    width: 38px;
    min-width: 38px;
    padding: 0;
  }

  .button-primary {
    order: initial;
  }
}

@media (max-width: 560px) {
  .settings-body {
    width: min(100% - 1.25rem, 1080px);
  }

  .inline-fields,
  .mic-fields {
    align-items: stretch;
    flex-direction: column;
  }

  .inline-fields select:last-child,
  .mic-fields select:last-child {
    width: 100%;
  }

  .alignment-options label {
    min-height: 84px;
  }

  .controls {
    gap: 0.25rem;
    padding: 0.45rem 0.55rem;
  }

  .brand-logo {
    height: 32px;
  }

  .brand {
    margin-right: 0.25rem;
  }

  .settings-button {
    margin-left: 0;
  }

  .status {
    min-width: auto;
    font-size: 0.74rem;
  }

  .status-dot {
    display: none;
  }

  .control-group {
    flex: 0 0 auto;
    width: auto;
  }

  .control-group .button {
    width: 36px;
    min-width: 36px;
    padding: 0;
  }

  .control-group .button svg {
    width: 19px;
    height: 19px;
  }

  .button-primary {
    min-width: 122px;
    margin-left: 0;
    font-size: 0.78rem;
  }

  .transcript-content {
    font-size: clamp(2.1rem, 10.5vw, 4rem);
    padding: 1.15rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
