/* SincroNarra — "Cabine": a Brazilian radio-narration booth for your pocket.
   Warm amber broadcast dial over a pitch-at-night green-black; the sync control
   is the hero, styled as a tuner. Boldness spent in one place (the tuner);
   everything else stays quiet. */
:root {
  color-scheme: dark;
  --campo: #0B1410;      /* pitch under floodlights — background */
  --campo-2: #13211A;    /* raised surface (cards, inputs, buttons) */
  --linha: #24382E;      /* chalk-line hairlines / borders */
  --dial: #F4B740;       /* amber radio-dial glow — primary accent */
  --dial-2: #FFC85A;     /* dial, hover */
  --gol: #E9FF5A;        /* electric lime — the live "no ar" pulse only */
  --osso: #EAE6D9;       /* bone — primary text */
  --mute: #7E8B82;       /* sage — secondary text */
  --alerta: #FF8159;     /* coral — real warnings only */
  --r: 10px;
  --display: "Anton", system-ui, sans-serif;
  --body: "Inter", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", monospace;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100dvh; font-family: var(--body); font-size: 16px; line-height: 1.45;
  color: var(--osso);
  background:
    radial-gradient(130% 70% at 50% -8%, rgba(244, 183, 64, 0.10), transparent 62%),
    var(--campo);
}
/* Static film grain — the analog-broadcast texture. No motion (reduced-motion safe). */
body::before {
  content: ""; position: fixed; inset: 0; z-index: 0; pointer-events: none; opacity: 0.05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
/* viewport-fit=cover extends the page under the status bar / punch-hole and the
   gesture-nav pill on Android (e.g. Pixel); env(safe-area-inset-*) keeps content
   clear of them. max() preserves the comfortable base padding in a normal tab
   (insets are 0 there) and only grows when installed standalone on a device. */
main {
  position: relative; z-index: 1; max-width: 560px; margin: 0 auto;
  padding:
    max(1.2rem, env(safe-area-inset-top))
    max(1.15rem, env(safe-area-inset-right))
    max(4rem, env(safe-area-inset-bottom))
    max(1.15rem, env(safe-area-inset-left));
}

/* ── Masthead ─────────────────────────────────────────────── */
.masthead {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 0.7rem;
  border-bottom: 1px solid var(--linha); padding-bottom: 0.85rem; margin-bottom: 1.2rem;
}
h1 {
  margin: 0; font-family: var(--display); font-weight: 400; text-transform: uppercase;
  font-size: clamp(2.1rem, 10vw, 3rem); line-height: 0.86; letter-spacing: 0.03em;
}
h1 .dial { color: var(--dial); }
.tagline { margin: 0.45rem 0 0; color: var(--mute); font-size: 0.9rem; max-width: 30ch; }
.eyebrow {
  margin: 0 0 0.5rem; font-family: var(--mono); font-size: 0.68rem; font-weight: 500;
  letter-spacing: 0.26em; text-transform: uppercase; color: var(--mute);
}

/* ── On-air pill ──────────────────────────────────────────── */
.onair {
  flex: none; font-family: var(--mono); font-size: 0.6rem; font-weight: 600;
  letter-spacing: 0.2em; text-transform: uppercase; color: var(--gol);
  display: inline-flex; align-items: center; gap: 0.4rem; white-space: nowrap;
  border: 1px solid rgba(233, 255, 90, 0.35); border-radius: 999px; padding: 0.28rem 0.55rem;
}
.onair::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--gol);
  box-shadow: 0 0 9px var(--gol); animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

/* ── Inputs & selects ─────────────────────────────────────── */
input[type="url"], input[type="password"] {
  width: 100%; padding: 0.8rem 0.9rem; border-radius: var(--r);
  border: 1px solid var(--linha); background: var(--campo-2); color: var(--osso); font: inherit;
}
input::placeholder { color: var(--mute); }
select {
  font: inherit; background: var(--campo-2); color: var(--osso);
  border: 1px solid var(--linha); border-radius: var(--r); padding: 0.5rem;
}
:focus-visible { outline: 2px solid var(--dial); outline-offset: 2px; }
input:focus-visible { border-color: var(--dial); }
#auth-row { margin-bottom: 1.2rem; }

/* ── Buttons ──────────────────────────────────────────────── */
button {
  font: inherit; font-weight: 600; padding: 0.62rem 0.9rem; border-radius: var(--r);
  border: 1px solid var(--linha); background: var(--campo-2); color: var(--osso);
  cursor: pointer; transition: border-color 0.12s, background 0.12s, transform 0.04s;
}
button:hover { border-color: var(--dial); }
button:active { transform: translateY(1px); }

/* ── Channel picker (the idle hero) ───────────────────────── */
#presets { display: flex; flex-wrap: wrap; gap: 0.45rem; }
#presets > button { background: var(--campo-2); border-color: var(--linha); }
#presets > button:hover { border-color: var(--dial); color: var(--dial-2); }
#presets button.live-loading { position: relative; padding-right: 2.25rem; }
#presets button.live-loading::after {
  content: ""; position: absolute; right: 0.8rem; top: 50%;
  width: 0.8rem; height: 0.8rem; margin-top: -0.45rem;
  border: 2px solid rgba(244, 183, 64, 0.25); border-top-color: var(--dial);
  border-radius: 50%; animation: live-spin 0.75s linear infinite;
}
@keyframes live-spin { to { transform: rotate(360deg); } }
.more-toggle {
  flex-basis: 100%; text-align: left; background: transparent; border-color: transparent;
  color: var(--mute); font-family: var(--mono); font-size: 0.78rem; letter-spacing: 0.06em;
  padding: 0.4rem 0.2rem;
}
.more-toggle:hover { color: var(--dial); border-color: transparent; }
#more-presets { display: flex; flex-wrap: wrap; gap: 0.45rem; flex-basis: 100%; }
#more-presets button { background: var(--campo-2); border-color: var(--linha); }

/* ── Faixa de Ajustes (sempre à vista, valem p/ todo canal) ── */
#settings-strip, #settings-strip * { box-sizing: border-box; }
#settings-strip {
  display: flex; flex-direction: column; gap: 14px;
  margin: 1rem 0 0.4rem; padding: 14px;
  background: var(--campo-2); border: 1px solid var(--linha); border-radius: var(--r);
}
.strip__eyebrow, .strip__label {
  margin: 0; font: 600 10px/1 var(--mono); letter-spacing: 1.4px; text-transform: uppercase;
  color: var(--mute);
}
.strip__label { float: none; width: auto; padding: 0; margin: 0 0 8px; }

/* latência — toggle switch sobre o <input id="ll"> real */
.toggle {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  min-height: 44px; cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.toggle__copy { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.toggle__title { font: 500 14px/1.2 var(--body); color: var(--osso); }
.toggle__hint { font: 500 11px/1.3 var(--body); color: var(--mute); }
.toggle__hint--warning { color: var(--alerta); }
.toggle--disabled { cursor: not-allowed; }
.toggle--disabled .toggle__copy, .toggle input:disabled + .toggle__track { opacity: 0.55; }
.toggle input { position: absolute; width: 1px; height: 1px; opacity: 0; }  /* hidden, focusable */
.toggle__track {
  flex: 0 0 auto; position: relative; width: 52px; height: 30px; border-radius: 999px;
  background: var(--campo); border: 1px solid var(--linha); transition: background 0.18s, border-color 0.18s;
}
.toggle__track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: var(--mute); transition: transform 0.18s, background 0.18s;
}
.toggle input:checked + .toggle__track {
  background: rgba(244, 183, 64, 0.18);
  background: color-mix(in srgb, var(--dial) 18%, transparent);
  border-color: var(--dial);
}
.toggle input:checked + .toggle__track::after { transform: translateX(22px); background: var(--dial); }
.toggle input:focus-visible + .toggle__track { outline: 2px solid var(--dial-2); outline-offset: 3px; }

/* sincronismo — segmented control de rádios nativos */
.seg { border: 0; padding: 0; margin: 0; min-inline-size: 0; }
.seg__opts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.seg__pill { position: relative; display: flex; }
.seg__pill input { position: absolute; width: 1px; height: 1px; opacity: 0; }  /* hidden, focusable */
.seg__pill label {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  min-height: 52px; padding: 8px 6px; border: 1px solid var(--linha); border-radius: 8px;
  background: var(--campo); color: var(--osso); cursor: pointer; text-align: center;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.seg__main { font: 600 13px/1.1 var(--body); letter-spacing: 0.2px; }
.seg__sub { font: 600 9px/1 var(--mono); text-transform: uppercase; letter-spacing: 0.6px; color: var(--mute); }
.seg__sub--rec { color: var(--dial); }
.seg__pill input:checked + label {
  border-color: var(--dial);
  background: rgba(244, 183, 64, 0.12);
  background: color-mix(in srgb, var(--dial) 12%, transparent);
}
.seg__pill input:checked + label .seg__main { color: var(--dial-2); }
.seg__pill input:focus-visible + label { outline: 2px solid var(--dial-2); outline-offset: 2px; }
.seg__pill label:active { transform: translateY(1px); }
.seg__help { margin: 8px 2px 0; min-height: 15px; font: 500 11px/1.35 var(--mono); color: var(--mute); }

/* fallback raro: colar link (demovido, colapsado) */
.link-more { border-top: 1px solid var(--linha); padding-top: 12px; }
.link-more__summary {
  display: flex; align-items: center; gap: 8px; min-height: 44px; list-style: none; cursor: pointer;
  font: 600 11px/1 var(--mono); letter-spacing: 0.8px; text-transform: uppercase; color: var(--mute);
}
.link-more__summary::-webkit-details-marker { display: none; }
.link-more__summary:hover { color: var(--osso); }
.link-more[open] .link-more__summary { color: var(--osso); margin-bottom: 10px; }
.link-more__summary:focus-visible { outline: 2px solid var(--dial-2); outline-offset: 3px; border-radius: 6px; }
.link-more__body { display: flex; gap: 8px; align-items: center; }
#url {
  flex: 1; min-width: 0; min-height: 44px; padding: 10px 12px; border-radius: 8px;
  background: var(--campo); color: var(--osso); border: 1px solid var(--linha);
  font: 500 16px var(--body);  /* 16px evita o zoom-no-foco do iOS */
}
#url::placeholder { color: var(--mute); }
#url:focus-visible { outline: 2px solid var(--dial-2); outline-offset: 1px; border-color: var(--dial); }
#start {
  flex: 0 0 auto; min-height: 44px; padding: 0 16px; border: 0; border-radius: 8px; cursor: pointer;
  background: var(--dial); color: var(--campo); font: 700 13px var(--mono);
  text-transform: uppercase; letter-spacing: 1px; transition: background 0.15s;
}
#start:hover { background: var(--dial-2); }
#start:focus-visible { outline: 2px solid var(--osso); outline-offset: 2px; }

#install { margin-top: 0.6rem; background: transparent; color: var(--mute); border-style: dashed; }

/* ── Status / warnings ────────────────────────────────────── */
.status {
  font-family: var(--mono); font-size: 0.8rem; letter-spacing: 0.02em;
  color: var(--mute); margin: 1.1rem 0 0.3rem;
}
.status::before { content: "› "; color: var(--dial); }
.warn { color: var(--alerta); font-size: 0.88rem; }
.muted { color: var(--mute); font-size: 0.85rem; }

#player { width: 100%; margin-top: 0.85rem; border-radius: var(--r); }

/* ── The tuner (the playing hero / signature) ─────────────── */
#delay-control {
  margin-top: 1.3rem; padding: 1.2rem 1rem 1.25rem; border-radius: 16px;
  border: 1px solid var(--linha); background: linear-gradient(180deg, var(--campo-2), #0D1712);
  box-shadow: inset 0 1px 0 rgba(244, 183, 64, 0.06), inset 0 0 50px rgba(244, 183, 64, 0.04);
}
.tuner { text-align: center; }
.tuner-value {
  font-family: var(--mono); font-weight: 600; font-size: clamp(3.4rem, 20vw, 5.2rem);
  line-height: 0.95; color: var(--dial); letter-spacing: -0.02em; font-variant-numeric: tabular-nums;
  text-shadow: 0 0 26px rgba(244, 183, 64, 0.38);
}
.tuner-unit { font-size: 0.34em; color: var(--mute); margin-left: 0.08em; text-shadow: none; }
.tuner-label {
  font-family: var(--mono); font-size: 0.7rem; letter-spacing: 0.32em; text-transform: uppercase;
  color: var(--mute); margin-top: 0.35rem;
}
.tuner-live {  /* secondary, smoothed "how far behind live" — quiet, not the hero */
  font-family: var(--mono); font-size: 0.72rem; color: var(--mute);
  text-align: center; margin-top: 0.55rem; min-height: 1em;
}

/* tuning track */
#delay-slider {
  -webkit-appearance: none; appearance: none; width: 100%; height: 4px; border-radius: 4px;
  background: linear-gradient(90deg, var(--dial) 0%, var(--linha) 0%); margin: 1.3rem 0 0.5rem;
}
#delay-slider::-webkit-slider-thumb {
  -webkit-appearance: none; width: 26px; height: 26px; border-radius: 50%;
  background: var(--dial); border: 3px solid #10160F;
  box-shadow: 0 0 0 1px var(--dial), 0 0 16px rgba(244, 183, 64, 0.6); cursor: pointer;
}
#delay-slider::-moz-range-thumb {
  width: 22px; height: 22px; border-radius: 50%; background: var(--dial); border: 3px solid #10160F;
  box-shadow: 0 0 16px rgba(244, 183, 64, 0.6); cursor: pointer;
}
.nudges { display: flex; gap: 0.35rem; justify-content: center; margin: 0.35rem 0 0.7rem; }
.nudges button { flex: 1; font-family: var(--mono); font-size: 0.95rem; padding: 0.55rem 0.2rem; }
#save-preset { width: 100%; margin-top: 0.5rem; background: transparent; color: var(--mute); }

/* ── Help ─────────────────────────────────────────────────── */
#help {
  margin-top: 1.4rem; font-size: 0.9rem; color: var(--osso);
  border: 1px solid var(--linha); border-radius: var(--r); padding: 0.5rem 0.8rem;
}
#help summary { cursor: pointer; color: var(--mute); font-family: var(--mono); font-size: 0.8rem; }
#help p { margin: 0.5rem 0; line-height: 1.45; }
#help ul { margin: 0.4rem 0; padding-left: 1.1rem; }
#help li { margin: 0.35rem 0; line-height: 1.45; }
#help b { color: var(--osso); }
#help i { color: var(--dial); font-style: normal; }

/* Release provenance — deliberately quiet, but selectable for bug reports. */
.app-footer {
  display: flex; align-items: center; justify-content: center; gap: 0.45rem;
  margin: 1.35rem 0 0.2rem; color: color-mix(in srgb, var(--mute) 72%, transparent);
  font: 500 0.64rem/1.4 var(--mono); letter-spacing: 0.08em; text-transform: uppercase;
}
#app-version, .app-footer time { font-variant-numeric: tabular-nums; text-transform: none; }

/* ── Stall notice + diagnostics ───────────────────────────── */
#stall-warning { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.6rem; }
.inline-btn {
  padding: 0.28rem 0.7rem; font: 700 0.8rem var(--mono); text-transform: uppercase;
  letter-spacing: 0.06em; background: var(--alerta); color: var(--campo); border: 0;
}
.inline-btn:hover { background: #ff9873; }
#diag { margin-top: 1.2rem; }
#diag > summary {
  cursor: pointer; color: var(--mute); font-family: var(--mono); font-size: 0.76rem;
  letter-spacing: 0.08em; text-transform: uppercase; list-style: none;
}
#diag > summary::-webkit-details-marker { display: none; }
#diag > summary::before { content: "⚑ "; color: var(--dial); }
#diag-body {
  font-family: var(--mono); font-size: 0.76rem; line-height: 1.55; color: var(--osso);
  margin: 0.55rem 0; word-break: break-word;
}
#copy-diag { background: transparent; color: var(--mute); border-color: var(--linha); font-size: 0.82rem; }

/* auto-sync: type the TV clock → the server reads the BR clock → sets the delay */
.autosync { margin-top: 0.75rem; display: flex; flex-direction: column; gap: 0.4rem; }
.autosync-row { display: flex; gap: 0.5rem; }
#tv-clock {
  flex: 1; min-width: 0; padding: 0.55rem 0.7rem; font-family: var(--mono);
  font-size: 1.05rem; letter-spacing: 0.04em; text-align: center;
  color: var(--osso); background: var(--campo-2);
  border: 1px solid var(--linha); border-radius: var(--r);
}
#tv-clock::placeholder { color: var(--mute); font-size: 0.9rem; letter-spacing: 0; }
#tv-clock:focus-visible { border-color: var(--dial); outline: none; }
.tv-clock-running {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.45rem 0.65rem; border: 1px solid rgba(244, 183, 64, 0.3);
  border-radius: var(--r); background: rgba(244, 183, 64, 0.06);
  color: var(--mute); font: 0.72rem var(--mono);
  letter-spacing: 0.05em; text-transform: uppercase;
}
#tv-clock-live {
  color: var(--dial); font-size: 1rem; font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
}
#autosync-btn { flex: 0 0 auto; border-color: var(--dial); color: var(--dial); background: transparent; }
#autosync-btn:disabled { opacity: 0.5; }
.photo-btn { width: 100%; background: var(--campo-2); border-color: var(--linha); color: var(--osso); }
.photo-btn:disabled { opacity: 0.5; }
#autosync-result:empty { display: none; }

.hidden { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  .onair::before { animation: none; }
  #presets button.live-loading::after { animation: none; }
  * { transition: none !important; }
}
