:root {
  --caption-size: 1.5rem;
}

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* barra superiore: piccola e discreta, il protagonista è il testo */
.bar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  padding: 0.6rem 1rem;
  padding-top: max(0.6rem, env(safe-area-inset-top));
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
}

.identity {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.status {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.95rem;
  color: var(--ink-soft);
}

.dot {
  width: 0.65rem;
  height: 0.65rem;
  border-radius: 50%;
  background: var(--ink-soft);
}

.status[data-state="live"] {
  color: var(--ink);
  font-weight: 650;
}

.status[data-state="live"] .dot {
  background: var(--signal-on);
  animation: pulse 2s ease-in-out infinite;
}

.status[data-state="offline"] .dot {
  background: var(--signal-off);
}

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

.controls {
  display: flex;
  gap: 0.6rem;
}

.langs button {
  min-width: 2.75rem;
  padding: 0 0.6rem;
}

/* "Aa": apre il pannello con dimensione del testo e tema */
.display-toggle {
  min-width: 2.75rem;
  min-height: 2.5rem;
  border: 1px solid var(--rule);
  border-radius: 0.5rem;
  background: transparent;
  font-weight: 700;
  cursor: pointer;
}

.display-toggle[aria-expanded="true"] {
  background: var(--ink);
  color: var(--paper);
}

.display-panel {
  position: absolute;
  top: calc(100% + 0.4rem);
  right: 0.75rem;
  display: grid;
  gap: 1rem;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 0.75rem;
  box-shadow: 0 0.5rem 1.5rem rgb(0 0 0 / 0.2);
}

.setting-label {
  margin: 0 0 0.4rem;
  font-size: 0.9rem;
  color: var(--ink-soft);
}

.setting .segmented button {
  flex: 1;
}

/* area dei sottotitoli: il testo nuovo entra dal basso, come in TV */
.captions {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  width: 100%;
  max-width: 42rem;
  margin: 0 auto;
  padding: 1.5rem 1rem;
  padding-bottom: max(2rem, env(safe-area-inset-bottom));
  font-size: calc(var(--caption-size) * var(--caption-scale, 1));
  line-height: 1.45;
}

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

.lines li {
  margin: 0 0 0.7em;
  overflow-wrap: anywhere;
}

/* le righe più vecchie si attenuano, l'occhio resta sulla fine */
.lines li:not(:nth-last-child(-n + 3)) {
  color: var(--ink-soft);
}

.live-line {
  margin: 0;
  min-height: 1.45em;
  overflow-wrap: anywhere;
}

.live-line:not(:empty) {
  align-self: flex-start;
  padding: 0 0.2em;
  background: var(--live);
  color: var(--live-ink);
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
  display: inline;
}

/* attesa prima della diretta: il primo colpo d'occhio di chi inquadra il QR */
.welcome {
  margin: auto 0;
  display: grid;
  justify-items: start;
  gap: 1.25rem;
}

.welcome .brand-mark {
  height: 4.5rem;
}

.welcome p {
  margin: 0;
  max-width: 24ch;
  color: var(--ink-soft);
  font-size: 1.15rem;
}

.back-to-live {
  position: fixed;
  left: 50%;
  bottom: max(1rem, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  padding: 0.7rem 1.2rem;
  border: 0;
  border-radius: 2rem;
  background: var(--live);
  color: var(--live-ink);
  font-weight: 700;
  box-shadow: 0 0.25rem 1rem rgb(0 0 0 / 0.25);
  cursor: pointer;
}

/* telefoni stretti: controlli più compatti per tenere la barra su una riga */
@media (max-width: 26rem) {
  .bar {
    padding-inline: 0.75rem;
  }

  .identity {
    gap: 0.6rem;
  }

  .brand-mark {
    height: 1.25rem;
  }

  .controls {
    gap: 0.4rem;
  }

  .langs button,
  .display-toggle {
    min-width: 2.4rem;
    padding: 0 0.4rem;
  }
}

@media (min-width: 48rem) {
  :root {
    --caption-size: 2rem;
  }
}
