/* Fontes do logotipo, embarcadas em public/fonts/ para o app funcionar
   offline. Ambas SIL OFL, com as licencas ao lado dos arquivos.
   Science Gothic e variavel: da para ajustar peso e largura sem trocar de fonte. */
@font-face {
  font-family: "Science Gothic";
  src: url("/fonts/science-gothic-latin.woff2") format("woff2-variations");
  font-weight: 400 700;
  font-stretch: 75% 125%;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Nova Round";
  src: url("/fonts/nova-round-latin.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

/* ============================================================================
   FrostCast — sistema visual
   Paleta monocromatica derivada do emblema: grafite sobre prata escovada.
   Tres estados de tema: sistema (sem stamp), claro e escuro explicitos.
   Nenhuma fonte externa — o app precisa funcionar offline e pelo tunel.
   ========================================================================= */

:root {
  /* --- CLARO (padrao) --- */
  --bg: #BDC0C0;          /* cloud gray */
  --bg-deep: #A9ACAC;
  --surface: #DCDCDC;     /* light gray */
  --surface-2: #D9D9D9;   /* platinum   */
  --line: #94999d;
  --line-soft: #C0C0C0;   /* silver     */
  --text: #000000;
  --dim: #4a4950;
  --accent: #3b3b41;
  --accent-hover: #000000;
  --on-accent: #DCDCDC;
  --live: #2c6b51;
  --danger: #8a3535;
  --sheen: rgba(255, 255, 255, 0.75);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.16);
  --shadow-md: 0 6px 18px rgba(0, 0, 0, 0.18);
  --shadow-lg: 0 22px 55px rgba(0, 0, 0, 0.3);
  --inset-top: inset 0 1px 0 rgba(255, 255, 255, 0.55);

  /* Logotipo: Science Gothic. As formas quadradas e os terminais retos ecoam
     as facetas do emblema. Trocar para "Nova Round" e questao de uma linha. */
  --wordmark: "Science Gothic", Bahnschrift, "Segoe UI Variable Display", system-ui, sans-serif;
  /* Rotulos, botoes e titulos: Bahnschrift (DIN que vem no Windows). */
  --display: Bahnschrift, "DIN Alternate", "Franklin Gothic Medium",
             "Segoe UI Variable Display", system-ui, sans-serif;
  --sans: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: "Cascadia Mono", Consolas, ui-monospace, monospace;

  --radius: 14px;
  --radius-sm: 10px;
  --ease: cubic-bezier(0.22, 0.68, 0.36, 1);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000;
    --bg-deep: #000000;
    --surface: #131317;
    --surface-2: #1c1c21;
    --line: #3b3b41;
    --line-soft: #26262c;
    --text: #DCDCDC;
    --dim: #94999d;
    --accent: #C0C0C0;
    --accent-hover: #DCDCDC;
    --on-accent: #000000;
    --live: #8fbfa6;
    --danger: #d99191;
    --sheen: rgba(220, 220, 220, 0.5);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.6);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.55);
    --shadow-lg: 0 26px 60px rgba(0, 0, 0, 0.75);
    --inset-top: inset 0 1px 0 rgba(220, 220, 220, 0.08);
  }
}

:root[data-theme="dark"] {
  --bg: #000000;
  --bg-deep: #000000;
  --surface: #131317;
  --surface-2: #1c1c21;
  --line: #3b3b41;
  --line-soft: #26262c;
  --text: #DCDCDC;
  --dim: #94999d;
  --accent: #C0C0C0;
  --accent-hover: #DCDCDC;
  --on-accent: #000000;
  --live: #8fbfa6;
  --danger: #d99191;
  --sheen: rgba(220, 220, 220, 0.5);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.6);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.55);
  --shadow-lg: 0 26px 60px rgba(0, 0, 0, 0.75);
  --inset-top: inset 0 1px 0 rgba(220, 220, 220, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  /* cor solida explicita primeiro: o gradiente e enfeite, nao o fundo real */
  background-color: var(--bg);
  background-image:
    radial-gradient(1200px 620px at 50% -18%, var(--surface-2) 0%, transparent 62%),
    linear-gradient(180deg, transparent 0%, var(--bg-deep) 100%);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 34px 20px 64px;
  transition: background-color 0.35s var(--ease), color 0.35s var(--ease);
}

/* -------------------------------------------------------------- cabecalho */

.topbar {
  width: 100%;
  max-width: 760px;
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 26px;
  animation: rise 0.5s var(--ease) both;
}

.brand { display: flex; align-items: center; gap: 13px; min-width: 0; }

.brand img {
  width: 44px;
  height: 44px;
  display: block;
  flex: none;
  filter: drop-shadow(var(--shadow-sm));
  animation: mark-in 0.7s var(--ease) both;
}

.brand-text { min-width: 0; }

h1 {
  margin: 0;
  font-family: var(--wordmark);
  font-size: 26px;
  font-weight: 600;
  font-variation-settings: "wght" 600, "wdth" 100;
  letter-spacing: 0.02em;
  line-height: 1.05;
}

.brand-text p {
  margin: 3px 0 0;
  color: var(--dim);
  font-size: 13px;
}

/* seletor de tema: sistema / claro / escuro */
.theme-switch {
  margin-left: auto;
  display: flex;
  gap: 2px;
  padding: 3px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: var(--inset-top);
  flex: none;
}

.theme-switch button {
  all: unset;
  width: 32px;
  height: 27px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  cursor: pointer;
  color: var(--dim);
  transition: color 0.2s var(--ease), background-color 0.2s var(--ease);
}
.theme-switch button:hover { color: var(--text); }
.theme-switch button[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }
.theme-switch button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.theme-switch svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.7; }

/* ------------------------------------------------------------------ layout */

main {
  width: 100%;
  max-width: 760px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card {
  position: relative;
  background: linear-gradient(180deg, var(--surface) 0%, var(--surface-2) 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow-md), var(--inset-top);
  animation: rise 0.55s var(--ease) both;
}
main > .card:nth-child(1) { animation-delay: 0.05s; }
main > .card:nth-child(2) { animation-delay: 0.11s; }
main > .card:nth-child(3) { animation-delay: 0.17s; }

/* ----------------------------------------------------------------- botoes */

button {
  font: inherit;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 11px 18px;
  cursor: pointer;
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: var(--shadow-sm);
  transition: transform 0.18s var(--ease), background-color 0.18s var(--ease),
              box-shadow 0.18s var(--ease), opacity 0.18s var(--ease);
}
button:hover:not(:disabled) { background: var(--accent-hover); transform: translateY(-1px); box-shadow: var(--shadow-md); }
button:active:not(:disabled) { transform: translateY(0); box-shadow: var(--shadow-sm); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button:disabled { opacity: 0.4; cursor: not-allowed; box-shadow: none; }

button.ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--text);
  box-shadow: none;
}
button.ghost:hover:not(:disabled) { background: var(--surface-2); border-color: var(--text); }

button.danger { background: var(--danger); color: var(--surface); }
button.danger:hover:not(:disabled) { background: var(--danger); filter: brightness(1.12); }

/* botao principal: uma luz atravessa o metal ao passar o mouse */
button.big {
  width: 100%;
  padding: 17px;
  font-family: var(--display);
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  position: relative;
  overflow: hidden;
}
button.big::after {
  content: "";
  position: absolute;
  inset: 0 auto 0 -60%;
  width: 40%;
  background: linear-gradient(100deg, transparent, var(--sheen), transparent);
  transform: skewX(-18deg);
  opacity: 0;
}
button.big:hover:not(:disabled)::after { animation: sweep 0.75s var(--ease); }

/* ----------------------------------------------------------- formularios */

input, select {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  width: 100%;
  transition: border-color 0.18s var(--ease), box-shadow 0.18s var(--ease);
}
input:focus, select:focus {
  outline: none;
  border-color: var(--text);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}

label {
  display: block;
  font-family: var(--display);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--dim);
  margin-bottom: 7px;
}

.row { display: flex; gap: 10px; align-items: center; }
.row > input, .row > select { flex: 1; }
.hidden { display: none !important; }
.field + .field { margin-top: 16px; }

/* ------------------------------------------------- codigo da transmissao */

.code {
  position: relative;
  overflow: hidden;
  font-family: var(--mono);
  font-size: clamp(30px, 8vw, 44px);
  font-weight: 700;
  letter-spacing: 0.14em;
  text-align: center;
  padding: 20px 10px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  user-select: all;
  box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.16);
  animation: code-in 0.5s var(--ease) both;
}
/* luz correndo sobre o metal — o floreio da interface */
.code::after {
  content: "";
  position: absolute;
  inset: 0 auto 0 -50%;
  width: 45%;
  background: linear-gradient(100deg, transparent, var(--sheen), transparent);
  transform: skewX(-20deg);
  animation: sweep 4.5s var(--ease) 1s infinite;
  pointer-events: none;
}

/* --------------------------------------------------------------- estados */

.status { display: flex; align-items: center; gap: 10px; color: var(--dim); font-size: 14px; }

.dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--dim); flex: none;
  transition: background-color 0.25s var(--ease);
}
.dot.live { background: var(--live); animation: beacon 2s ease-out infinite; }
.dot.error { background: var(--danger); }

.hint { color: var(--dim); font-size: 13px; margin: 11px 0 0; }
.hint code {
  font-family: var(--mono); font-size: 12px;
  background: var(--bg); border: 1px solid var(--line);
  padding: 1px 6px; border-radius: 5px;
}
a { color: var(--text); text-underline-offset: 3px; }

ul.viewers { list-style: none; margin: 14px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
ul.viewers li {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 13px;
  font-size: 12.5px;
  color: var(--dim);
  animation: rise 0.35s var(--ease) both;
}

video {
  width: 100%;
  background: #000;
  border-radius: 12px;
  border: 1px solid var(--line);
  display: block;
  aspect-ratio: 16 / 9;
  object-fit: contain;
  box-shadow: var(--shadow-md);
}

/* ---------------------------------------------------- pagina de quem ve */

.viewer-page main, .viewer-page .topbar { max-width: 1100px; }

.diag { margin-top: 16px; font-size: 13px; color: var(--dim); }
.diag summary { cursor: pointer; user-select: none; padding: 6px 0; transition: color 0.2s var(--ease); }
.diag summary:hover { color: var(--text); }
.diag dl {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 7px 16px;
  margin: 11px 0 0;
  padding: 14px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-family: var(--mono);
  font-size: 12.5px;
  animation: rise 0.3s var(--ease) both;
}
.diag dt { color: var(--dim); }
.diag dd { margin: 0; color: var(--text); word-break: break-word; }
.diag dd.good { color: var(--live); }
.diag dd.bad { color: var(--danger); }

/* ------------------------------------------------------------------ aviso */

.toast {
  position: fixed;
  bottom: 26px;
  left: 50%;
  background: var(--accent);
  color: var(--on-accent);
  border-radius: 999px;
  padding: 11px 22px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translate(-50%, 14px);
  pointer-events: none;
  transition: opacity 0.25s var(--ease), transform 0.25s var(--ease);
  z-index: 60;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ------------------------------------- seletor de tela (so no FrostCast) */

.picker-overlay {
  position: fixed;
  inset: 0;
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 26px;
  z-index: 50;
  animation: fade 0.22s var(--ease) both;
}

.picker {
  width: min(900px, 100%);
  max-height: 100%;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, var(--surface) 0%, var(--surface-2) 100%);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow-lg), var(--inset-top);
  overflow: hidden;
  animation: modal-in 0.32s var(--ease) both;
}

.picker header { padding: 20px 22px 15px; border-bottom: 1px solid var(--line-soft); }
.picker h2 {
  margin: 0 0 14px;
  font-family: var(--display);
  font-size: 19px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.picker-tabs { display: flex; gap: 8px; }
.picker-tabs button {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--dim);
  padding: 7px 17px;
  border-radius: 999px;
  font-size: 13.5px;
  box-shadow: none;
}
.picker-tabs button:hover { color: var(--text); transform: none; box-shadow: none; }
.picker-tabs button.active { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

.picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 14px;
  padding: 20px 22px;
  overflow-y: auto;
  flex: 1;
}

.picker-card {
  display: flex;
  flex-direction: column;
  gap: 9px;
  padding: 9px;
  background: var(--bg);
  border: 2px solid var(--line-soft);
  border-radius: 12px;
  text-align: left;
  font-weight: 400;
  color: var(--text);
  box-shadow: none;
  animation: rise 0.3s var(--ease) both;
}
.picker-card:hover { background: var(--surface-2); border-color: var(--line); transform: translateY(-2px); }
.picker-card.selected { border-color: var(--accent); background: var(--surface-2); box-shadow: var(--shadow-md); }
.picker-card img { width: 100%; aspect-ratio: 16 / 10; object-fit: contain; background: #000; border-radius: 7px; }
.picker-card span {
  display: flex; align-items: center; gap: 7px;
  font-size: 12.5px; line-height: 1.3;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.picker-appicon {
  width: 16px !important; height: 16px;
  aspect-ratio: auto !important; background: none !important; flex: none;
}
.picker-noshot {
  width: 100%; aspect-ratio: 16 / 10; border-radius: 7px;
  background: var(--surface-2); border: 1px dashed var(--line);
  display: flex; align-items: center; justify-content: center;
  color: var(--dim); font-size: 12px;
}
.picker-empty { grid-column: 1 / -1; color: var(--dim); text-align: center; padding: 40px 10px; }

.picker footer {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 16px 22px;
  border-top: 1px solid var(--line-soft);
  flex-wrap: wrap;
}
.picker-audio {
  display: flex; align-items: center; gap: 9px; margin: 0;
  font-family: var(--sans); font-size: 13.5px; color: var(--text);
  text-transform: none; letter-spacing: normal; font-weight: 400;
}
.picker-audio input { width: auto; accent-color: var(--accent); }
.picker-actions { display: flex; gap: 10px; margin-left: auto; }

/* -------------------------------------------------------------- animacoes */

@keyframes rise {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-in {
  from { opacity: 0; transform: translateY(16px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes code-in {
  from { opacity: 0; letter-spacing: 0.4em; filter: blur(6px); }
  to   { opacity: 1; letter-spacing: 0.14em; filter: blur(0); }
}
@keyframes sweep {
  0%   { left: -50%; opacity: 0; }
  12%  { opacity: 1; }
  55%  { opacity: 1; }
  100% { left: 130%; opacity: 0; }
}
@keyframes beacon {
  0%   { box-shadow: 0 0 0 0 color-mix(in srgb, var(--live) 55%, transparent); }
  70%  { box-shadow: 0 0 0 9px color-mix(in srgb, var(--live) 0%, transparent); }
  100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--live) 0%, transparent); }
}
@keyframes mark-in {
  from { opacity: 0; transform: scale(0.82) rotate(-14deg); }
  to   { opacity: 1; transform: scale(1) rotate(0); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

@media (max-width: 560px) {
  .topbar { flex-wrap: wrap; }
  .theme-switch { margin-left: 0; }
  .picker-actions { width: 100%; }
}
