*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0a0a0a;
  --surface:   #111111;
  --surface2:  #1a1a1a;
  --border:    #444444;
  --accent:    #c8c8c8;
  --accent2:   #666666;
  --accent3:   #aaaaaa;
  --warn:      #909060;
  --text:      #888888;
  --text-dim:  #333333;
  --red:       #c03030;
  --pixel:     'Press Start 2P', monospace;
  --vt:        'VT323', monospace;
}

/* Scanlines overlay */
.scanlines {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 999;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0px,
    transparent 3px,
    rgba(0,0,0,0.15) 3px,
    rgba(0,0,0,0.15) 4px
  );
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--pixel);
  font-size: 10px;
  min-height: 100vh;
  padding: 32px 16px 60px;
  image-rendering: pixelated;
}

/* CRT vignette */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse at center, rgba(20,20,20,0.3) 0%, rgba(0,0,0,0.85) 100%);
  pointer-events: none;
  z-index: 0;
}

.container {
  position: relative;
  z-index: 1;
  max-width: 680px;
  margin: 0 auto;
}

/* ── Header ── */
header {
  text-align: center;
  margin-bottom: 28px;
}

.logo-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 10px;
}

.pixel-icon {
  font-size: 20px;
  color: var(--accent2);
  animation: flicker 3s infinite;
}

h1 {
  font-family: var(--pixel);
  font-size: 28px;
  color: var(--accent);
  text-shadow: 2px 2px 0 #222;
  letter-spacing: 4px;
  line-height: 1;
}

.blink {
  animation: blink 1s step-end infinite;
  color: var(--accent2);
}

.subtitle {
  font-family: var(--pixel);
  font-size: 9px;
  color: var(--accent2);
  letter-spacing: 3px;
  margin-bottom: 6px;
}

/* ── Panel ── */
.panel {
  border: 2px solid var(--border);
  background: var(--surface);
  margin-bottom: 20px;
  position: relative;
  box-shadow: 0 0 10px rgba(200,200,200,0.04);
}

.panel::before {
  content: '';
  position: absolute;
  inset: 2px;
  border: 1px solid rgba(255,255,255,0.04);
  pointer-events: none;
}

.panel-title {
  font-family: var(--pixel);
  font-size: 7px;
  color: var(--accent2);
  padding: 8px 12px 6px;
  border-bottom: 1px solid #222;
  letter-spacing: 1px;
}

/* ── Search ── */
.search-box {
  display: flex;
  gap: 0;
  padding: 12px;
}

#url {
  flex: 1;
  background: #000;
  border: 2px solid var(--border);
  border-right: none;
  padding: 10px 12px;
  color: var(--accent);
  font-family: var(--vt);
  font-size: 20px;
  outline: none;
  caret-color: var(--accent);
  letter-spacing: 1px;
}

#url::placeholder { color: var(--text-dim); }

#url:focus {
  border-color: #666;
}

/* ── Scan button — two states ── */
#analyzeBtn {
  /* DISABLED / EMPTY — apagado */
  background: #1a1a1a;
  color: #3a3a3a;
  border: 2px solid #2a2a2a;
  padding: 10px 16px;
  font-family: var(--pixel);
  font-size: 8px;
  cursor: not-allowed;
  letter-spacing: 1px;
  transition: background 0.15s, color 0.15s, border-color 0.15s, box-shadow 0.15s;
  white-space: nowrap;
  text-shadow: none;
}

#analyzeBtn.enabled {
  /* ENABLED — vermelho vivo */
  background: #c0392b;
  color: #fff;
  border-color: #c0392b;
  cursor: pointer;
}

#analyzeBtn.enabled:hover {
  background: #000;
  color: #e05040;
  border-color: #e05040;
  box-shadow: 0 0 10px rgba(192,57,43,0.35);
}

#analyzeBtn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ── Loading ── */
.loading {
  border: 2px solid var(--border);
  background: var(--surface);
  padding: 32px;
  text-align: center;
  box-shadow: 0 0 10px rgba(200,200,200,0.04);
}

.pixel-loader {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-bottom: 16px;
}

.pixel-loader span {
  width: 10px; height: 10px;
  background: var(--accent);
  display: block;
  animation: pixelBounce 0.6s ease-in-out infinite;
}
.pixel-loader span:nth-child(2) { animation-delay: 0.1s; background: var(--accent2); }
.pixel-loader span:nth-child(3) { animation-delay: 0.2s; background: #555; }
.pixel-loader span:nth-child(4) { animation-delay: 0.3s; }
.pixel-loader span:nth-child(5) { animation-delay: 0.4s; background: var(--accent2); }

.loading p {
  font-family: var(--vt);
  font-size: 22px;
  color: var(--accent3);
  letter-spacing: 2px;
  animation: blink 1s step-end infinite;
}

/* ── Erro ── */
.error-box {
  border: 2px solid var(--red);
  background: rgba(192,48,48,0.08);
  padding: 16px;
  color: var(--red);
  font-family: var(--vt);
  font-size: 20px;
  letter-spacing: 1px;
  text-shadow: 0 0 5px rgba(192,48,48,0.4);
  box-shadow: 0 0 10px rgba(192,48,48,0.15);
}

.error-box::before {
  content: '!! ERROR: ';
  color: #7a4030;
  font-family: var(--pixel);
  font-size: 8px;
  display: block;
  margin-bottom: 6px;
}

/* ── Video card ── */
.video-card {
  border: 2px solid var(--border);
  background: var(--surface);
  box-shadow: 0 0 10px rgba(200,200,200,0.04);
}

.video-info {
  display: flex;
  gap: 12px;
  padding: 12px;
  border-bottom: 1px solid #222;
}

.video-thumb {
  width: 112px;
  height: 64px;
  object-fit: cover;
  flex-shrink: 0;
  border: 2px solid var(--text-dim);
  image-rendering: auto;
}

.video-meta { flex: 1; overflow: hidden; }

.video-title {
  font-family: var(--vt);
  font-size: 20px;
  color: var(--accent3);
  line-height: 1.3;
  margin-bottom: 6px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.video-details {
  font-family: var(--pixel);
  font-size: 7px;
  color: var(--text-dim);
  letter-spacing: 1px;
}

/* ── Formats ── */
.formats-header {
  font-family: var(--pixel);
  font-size: 7px;
  color: var(--accent2);
  padding: 10px 12px 8px;
  letter-spacing: 1px;
  border-bottom: 1px solid #1e1e1e;
}

.formats-list { padding: 8px; }

.format-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: #000;
  border: 2px solid #2a2a2a;
  padding: 9px 12px;
  margin-bottom: 6px;
  color: var(--text);
  cursor: pointer;
  font-family: var(--vt);
  font-size: 18px;
  text-align: left;
  letter-spacing: 1px;
  transition: all 0.08s;
  position: relative;
}

.format-btn:last-child { margin-bottom: 0; }

.format-btn:hover {
  background: var(--surface2);
  border-color: #888;
  color: #ccc;
  box-shadow: 0 0 8px rgba(200,200,200,0.08);
}

.format-btn:hover .dl-icon { color: #aaa; animation: blink 0.4s step-end infinite; }

.format-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.format-btn:disabled:hover { background: #000; border-color: #2a2a2a; box-shadow: none; }

.format-badge {
  font-family: var(--pixel);
  font-size: 7px;
  padding: 3px 6px;
  letter-spacing: 1px;
  border: 1px solid currentColor;
  flex-shrink: 0;
}

.badge-mp4  { color: #6090b8; }
.badge-webm { color: #5a9a7a; }
.badge-mp3  { color: #909060; }
.badge-other { color: #666; }

.format-label { display: flex; align-items: center; gap: 10px; }
.format-resolution { color: var(--text); }
.format-size { color: var(--text-dim); font-size: 16px; }
.dl-icon { color: var(--text-dim); font-size: 18px; flex-shrink: 0; }

/* ── Downloading indicator (legado, mantido por compatibilidade) ── */
.downloading-indicator {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--vt);
  font-size: 18px;
  color: var(--accent3);
  letter-spacing: 1px;
  animation: blink 0.6s step-end infinite;
}

/* ── Botão bloqueado durante download de outro formato ── */
.format-btn.dl-locked {
  opacity: 0.2;
  cursor: not-allowed;
  filter: grayscale(1);
  pointer-events: none;
}

/* ── Progress wrap — container interno do botão durante download ── */
.progress-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 20px;
}

.progress-icon {
  font-family: var(--pixel);
  font-size: 10px;
  color: #39ff14;
  text-shadow: 0 0 6px #39ff14;
  flex-shrink: 0;
  width: 14px;
  text-align: center;
}

.progress-icon.phase-pulse {
  animation: phasePulse 0.8s step-end infinite;
}

.progress-col {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-width: 0;
}

.progress-label {
  font-family: var(--pixel);
  font-size: 7px;
  color: #39ff14;
  text-shadow: 0 0 4px rgba(57,255,20,0.6);
  letter-spacing: 1px;
  white-space: nowrap;
}

/* ── Barra de progresso 8-bit ── */
.progress-bar-outer {
  width: 100%;
  height: 10px;
  background: #000;
  border: 1px solid #2a2a2a;
  background-image:
    linear-gradient(45deg, #0d0d0d 25%, transparent 25%),
    linear-gradient(-45deg, #0d0d0d 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #0d0d0d 75%),
    linear-gradient(-45deg, transparent 75%, #0d0d0d 75%);
  background-size: 4px 4px;
  background-position: 0 0, 0 2px, 2px -2px, -2px 0px;
  position: relative;
  overflow: hidden;
}

.progress-bar-fill {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 0%;
  background: #39ff14;
  background-image: repeating-linear-gradient(
    90deg,
    #39ff14 0px, #39ff14 5px,
    #2dcc10 5px, #2dcc10 7px
  );
  box-shadow: 0 0 6px #39ff14, 0 0 12px rgba(57,255,20,0.3);
  transition: width 0.18s steps(8, end);
}

.progress-bar-fill::after {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0px, transparent 2px,
    rgba(0,0,0,0.25) 2px, rgba(0,0,0,0.25) 3px
  );
}

.progress-pct {
  font-family: var(--pixel);
  font-size: 7px;
  color: #39ff14;
  text-shadow: 0 0 5px #39ff14;
  min-width: 26px;
  text-align: right;
  flex-shrink: 0;
  letter-spacing: 0;
}

/* ── Dots animados para fases de espera ── */
.progress-dots {
  display: flex;
  gap: 4px;
  align-items: center;
  height: 10px;
}

.progress-dots span {
  width: 5px;
  height: 5px;
  background: #39ff14;
  box-shadow: 0 0 4px #39ff14;
  display: block;
  animation: dotBlink 1s step-end infinite;
}
.progress-dots span:nth-child(2) { animation-delay: 0.33s; }
.progress-dots span:nth-child(3) { animation-delay: 0.66s; }

@keyframes phasePulse {
  0%, 100% { opacity: 1; color: #39ff14; }
  50%       { opacity: 0.3; color: #1a7a08; }
}

@keyframes dotBlink {
  0%, 100% { opacity: 1; }
  33%       { opacity: 0.1; }
}

/* ── Progress bar 8-bit ── */
.progress-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  font-family: var(--pixel);
}

.progress-label {
  font-family: var(--vt);
  font-size: 18px;
  color: var(--accent3);
  white-space: nowrap;
  flex-shrink: 0;
}

.progress-bar-outer {
  flex: 1;
  height: 14px;
  background: #000;
  border: 2px solid #3a3a3a;
  /* Padrão de checkerboard 8-bit no fundo */
  background-image:
    linear-gradient(45deg, #111 25%, transparent 25%),
    linear-gradient(-45deg, #111 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #111 75%),
    linear-gradient(-45deg, transparent 75%, #111 75%);
  background-size: 4px 4px;
  background-position: 0 0, 0 2px, 2px -2px, -2px 0px;
  position: relative;
  overflow: hidden;
  image-rendering: pixelated;
}

.progress-bar-fill {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 0%;
  /* Verde limão 8-bit com blocos pixelados */
  background: #39ff14;
  background-image:
    repeating-linear-gradient(
      90deg,
      #39ff14 0px,
      #39ff14 6px,
      #2ecc0f 6px,
      #2ecc0f 8px
    );
  box-shadow: 0 0 8px #39ff14, 0 0 16px rgba(57,255,20,0.4);
  transition: width 0.15s steps(10, end);
  image-rendering: pixelated;
}

/* Scanline na barra */
.progress-bar-fill::after {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0px,
    transparent 2px,
    rgba(0,0,0,0.2) 2px,
    rgba(0,0,0,0.2) 3px
  );
}

.progress-pct {
  font-family: var(--pixel);
  font-size: 7px;
  color: #39ff14;
  text-shadow: 0 0 6px #39ff14;
  min-width: 28px;
  text-align: right;
  flex-shrink: 0;
  letter-spacing: 0;
}

/* ── Footer ── */
footer {
  text-align: center;
  margin-top: 24px;
}

.footer-txt {
  font-family: var(--pixel);
  font-size: 7px;
  color: var(--text-dim);
  letter-spacing: 2px;
  animation: blink 1.5s step-end infinite;
}

/* ── Animations ── */
@keyframes blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0; }
}

@keyframes flicker {
  0%, 95%, 100% { opacity: 1; }
  96%           { opacity: 0.4; }
  97%           { opacity: 1; }
  98%           { opacity: 0.2; }
}

@keyframes pixelBounce {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-8px); }
}

/* ── v2: indicador DASH ── */
.dash-note {
  font-family: var(--pixel);
  font-size: 6px;
  color: var(--warn);
  border: 1px solid var(--warn);
  padding: 2px 4px;
  letter-spacing: 0;
  flex-shrink: 0;
}

/* ── v2: progress wrap ── */
.format-btn.dl-locked { opacity: 0.2; cursor: not-allowed; filter: grayscale(1); pointer-events: none; }

.progress-wrap { display: flex; align-items: center; gap: 8px; width: 100%; min-height: 20px; }
.progress-icon { font-family: var(--pixel); font-size: 10px; color: #39ff14; text-shadow: 0 0 6px #39ff14; flex-shrink: 0; width: 14px; text-align: center; }
.progress-icon.phase-pulse { animation: phasePulse 0.8s step-end infinite; }
.progress-col { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 0; }
.progress-label { font-family: var(--pixel); font-size: 7px; color: #39ff14; text-shadow: 0 0 4px rgba(57,255,20,.6); letter-spacing: 1px; white-space: nowrap; }

.progress-bar-outer { width: 100%; height: 10px; background: #000; border: 1px solid #2a2a2a; background-image: linear-gradient(45deg,#0d0d0d 25%,transparent 25%),linear-gradient(-45deg,#0d0d0d 25%,transparent 25%),linear-gradient(45deg,transparent 75%,#0d0d0d 75%),linear-gradient(-45deg,transparent 75%,#0d0d0d 75%); background-size: 4px 4px; background-position: 0 0,0 2px,2px -2px,-2px 0; position: relative; overflow: hidden; }
.progress-bar-fill { position: absolute; left: 0; top: 0; bottom: 0; width: 0%; background: #39ff14; background-image: repeating-linear-gradient(90deg,#39ff14 0px,#39ff14 5px,#2dcc10 5px,#2dcc10 7px); box-shadow: 0 0 6px #39ff14,0 0 12px rgba(57,255,20,.3); transition: width .18s steps(8,end); }
.progress-bar-fill::after { content:''; position: absolute; inset: 0; background: repeating-linear-gradient(to bottom,transparent 0px,transparent 2px,rgba(0,0,0,.25) 2px,rgba(0,0,0,.25) 3px); }
.progress-pct { font-family: var(--pixel); font-size: 7px; color: #39ff14; text-shadow: 0 0 5px #39ff14; min-width: 26px; text-align: right; flex-shrink: 0; }

.progress-dots { display: flex; gap: 4px; align-items: center; height: 10px; }
.progress-dots span { width: 5px; height: 5px; background: #39ff14; box-shadow: 0 0 4px #39ff14; display: block; animation: dotBlink 1s step-end infinite; }
.progress-dots span:nth-child(2) { animation-delay: .33s; }
.progress-dots span:nth-child(3) { animation-delay: .66s; }

@keyframes phasePulse { 0%,100%{opacity:1;color:#39ff14} 50%{opacity:.3;color:#1a7a08} }
@keyframes dotBlink { 0%,100%{opacity:1} 33%{opacity:.1} }
