/*
 * Caption overlay for broadcast tools (/captions). Loaded inside OBS / vMix /
 * ProPresenter browser sources, which ship older Chromium builds: plain CSS only
 * (no :has(), container queries, color-mix(), nesting, dvh, inset or flex gap).
 * Every look-and-feel value comes from the URL and is set as a custom property
 * on <html> by /js/captions.js; the defaults below are the "Lower third" look.
 */
:root {
  --cap-font: 'Inter', 'Noto Sans', 'Segoe UI', 'Helvetica Neue', Arial, 'PingFang SC', 'Microsoft YaHei', 'Malgun Gothic', sans-serif;
  --cap-size: 4.444vmin;          /* 48px on a 1920x1080 source */
  --cap-weight: 600;
  --cap-color: #ffffff;
  --cap-color2: #ffffff;
  --cap-lh: 1.36;
  --cap-lines: 2;
  --cap-pad: 0.12em;              /* room for the caption box above/below the text */
  --cap-margin: 5.926vmin;        /* 64px from the bottom/top edge at 1080p */
  --cap-maxw: 80%;
  --cap-bg: rgba(0, 0, 0, 0.7);
  --cap-shadow: none;
  --cap-align: center;
}

html, body {
  background: transparent;
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}
body { -webkit-font-smoothing: antialiased; }

/* The caption area: anchored to the bottom (or top) edge, full width. */
.cap-area {
  position: absolute;
  left: 0;
  right: 0;
  bottom: var(--cap-margin);
  font-family: var(--cap-font);
  font-size: var(--cap-size);
  font-weight: var(--cap-weight);
  line-height: var(--cap-lh);
  color: var(--cap-color);
  text-align: var(--cap-align);
  text-shadow: var(--cap-shadow);
  pointer-events: none;
}
.cap-pos-top .cap-area { top: var(--cap-margin); bottom: auto; }
.cap-uppercase .cap-area { text-transform: uppercase; }

/* "bar" background: a full-width band that fades in while captions show. */
.cap-area::before {
  content: '';
  position: absolute;
  left: 0; right: 0; top: 0; bottom: 0;
  background: var(--cap-bg);
  opacity: 0;
  transition: opacity 0.45s ease;
}
.cap-bg-bar .cap-area { padding: 0.3em 0; }
.cap-bg-bar .cap-area.is-active::before { opacity: 1; }

.cap-inner {
  position: relative;
  margin: 0 auto;
  width: var(--cap-maxw);
  max-width: 100%;
}

.cap-block { position: relative; }
.cap-block + .cap-block { margin-top: 0.24em; }
.cap-block.is-second { color: var(--cap-color2); }

/*
 * At most `lines` lines tall. The track sits at the bottom (flex-end), so when it
 * grows past the limit its oldest lines overflow off the top and are clipped.
 */
.cap-window {
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  max-height: calc(var(--cap-lines) * var(--cap-lh) * 1em);
  padding: var(--cap-pad) 0;
  transition: opacity 0.6s ease;
}
.cap-block.is-clearing .cap-window { opacity: 0; }

.cap-track { flex-shrink: 0; will-change: transform; }

.cap-piece {
  display: block;
  /* backwards, not both: a finished animation must not pin opacity over .is-leaving */
  -webkit-animation: capIn 0.4s ease-out backwards;
  animation: capIn 0.4s ease-out backwards;
  transition: opacity 0.4s ease;
}
.cap-piece.is-leaving { opacity: 0; }

.cap-text { word-wrap: break-word; overflow-wrap: break-word; }
.cap-bg-box .cap-text {
  background: var(--cap-bg);
  padding: 0.04em 0.32em;
  border-radius: 0.14em;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}
.cap-piece.is-singing .cap-text { font-style: italic; }
.cap-piece.is-singing .cap-text::before { content: '\266A\00a0'; font-style: normal; }

@-webkit-keyframes capIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes capIn { from { opacity: 0; } to { opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  .cap-piece { -webkit-animation: none; animation: none; }
  .cap-track { transition: none !important; }
}
