/* SIGNAL — rust-broadcast WASM analyzer.
   Aesthetic: broadcast test gear / waveform-monitor. Dark phosphor screen,
   monospace throughout, hairline grids, LED status dots. No external fonts,
   no CDN — every asset here is CSS + system font stacks. */

:root {
  --bg:            #05080a;
  --bg-raised:     #0a1210;
  --bg-panel:      #0b1512;
  --grid-line:     rgba(120, 200, 170, 0.09);
  --hair:          rgba(140, 220, 190, 0.16);
  --hair-strong:   rgba(140, 220, 190, 0.32);
  --text:          #d7ecdf;
  --text-dim:      #7f9c90;
  --text-faint:    #4f6960;

  --green:   #4ade80;
  --teal:    #34d9c4;
  --amber:   #f5b942;
  --red:     #ff5c5c;
  --blue:    #6ea8ff;
  --magenta: #ff6ec7;
  --muted:   #5b6b63;

  --mono: ui-monospace, "SF Mono", "Cascadia Code", "Fira Code", Menlo, Consolas, "Liberation Mono", monospace;

  --glow-green: 0 0 10px rgba(74, 222, 128, 0.35);
}

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

html { color-scheme: dark; }

body {
  margin: 0;
  padding: 2.25rem 1.75rem 4rem;
  background:
    radial-gradient(ellipse 90% 60% at 50% -10%, rgba(74, 222, 128, 0.07), transparent 60%),
    radial-gradient(ellipse 70% 50% at 100% 100%, rgba(52, 217, 196, 0.05), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.5;
  max-width: 1180px;
  margin-inline: auto;
  position: relative;
}

/* faint CRT scanline overlay */
.scanlines {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1000;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0) 0px,
    rgba(0, 0, 0, 0) 2px,
    rgba(0, 0, 0, 0.06) 3px
  );
  mix-blend-mode: overlay;
  opacity: 0.5;
}

/* ── Header ─────────────────────────────────────────────────────────── */

header { margin-bottom: 2rem; }

.brand { display: flex; align-items: baseline; gap: 0.6rem; }

.brand-led {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: var(--glow-green);
  flex: none;
  animation: pulse 2.6s ease-in-out infinite;
  align-self: center;
}

/* Set once a capture reports TR 101 290 sync loss. */
.brand-led.led-lost {
  background: var(--red);
  box-shadow: 0 0 10px rgba(255, 92, 92, 0.45);
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

h1 {
  margin: 0;
  font-size: 1.5rem;
  letter-spacing: 0.08em;
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
}

.brand-mono {
  font-weight: 700;
  color: var(--text);
}

.brand-sub {
  font-size: 0.75rem;
  font-weight: 400;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  text-transform: lowercase;
}

.subtitle {
  margin: 0.6rem 0 0;
  max-width: 62ch;
  color: var(--text-dim);
  font-size: 0.82rem;
  line-height: 1.6;
}

/* ── Drop zone ──────────────────────────────────────────────────────── */

#dropzone {
  position: relative;
  border: 1px solid var(--hair);
  border-radius: 2px;
  padding: 3rem 1rem;
  text-align: center;
  cursor: pointer;
  background: linear-gradient(180deg, var(--bg-raised), var(--bg));
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
  user-select: none;
  overflow: hidden;
}

#dropzone:hover, #dropzone:focus-visible {
  border-color: var(--hair-strong);
  box-shadow: 0 0 0 1px rgba(74, 222, 128, 0.12), var(--glow-green);
  outline: none;
}

#dropzone.drag-over {
  border-color: var(--green);
  background: linear-gradient(180deg, rgba(74, 222, 128, 0.08), var(--bg));
  box-shadow: var(--glow-green);
}

.dropzone-frame { position: absolute; inset: 10px; pointer-events: none; }
.corner {
  position: absolute;
  width: 16px;
  height: 16px;
  border: 1.5px solid var(--text-faint);
  opacity: 0.7;
}
.corner.tl { top: 0; left: 0; border-right: none; border-bottom: none; }
.corner.tr { top: 0; right: 0; border-left: none; border-bottom: none; }
.corner.bl { bottom: 0; left: 0; border-right: none; border-top: none; }
.corner.br { bottom: 0; right: 0; border-left: none; border-top: none; }

#dropzone-label {
  display: block;
  pointer-events: none;
  color: var(--text);
  font-size: 0.85rem;
  letter-spacing: 0.12em;
  font-weight: 600;
}

.dropzone-hint {
  display: block;
  margin-top: 0.5rem;
  color: var(--text-faint);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  pointer-events: none;
}

#dropzone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

/* ── Loading / error ────────────────────────────────────────────────── */

#loading {
  margin-top: 1.25rem;
  color: var(--green);
  font-weight: 600;
  letter-spacing: 0.08em;
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.spinner {
  width: 11px;
  height: 11px;
  border: 2px solid rgba(74, 222, 128, 0.25);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

#error-banner {
  margin-top: 1.25rem;
  background: rgba(255, 92, 92, 0.08);
  color: var(--red);
  border: 1px solid rgba(255, 92, 92, 0.35);
  border-radius: 2px;
  padding: 0.75rem 1rem;
  font-size: 0.82rem;
}

/* ── Panels ─────────────────────────────────────────────────────────── */

#results {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  margin-top: 1.5rem;
}

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--hair);
  border-radius: 2px;
  padding: 1rem 1.1rem 1.2rem;
  animation: reveal 0.4s ease both;
}

@keyframes reveal {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.panel h2 {
  margin: 0 0 0.85rem;
  font-size: 0.78rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: baseline;
  gap: 0.55rem;
  border-bottom: 1px solid var(--hair);
  padding-bottom: 0.6rem;
}

.panel-index {
  color: var(--text-faint);
  font-weight: 400;
  font-size: 0.72rem;
}

.panel-sub {
  color: var(--text-dim);
  text-transform: none;
  font-weight: 400;
  letter-spacing: 0.02em;
}

.panel-note {
  margin: 0.75rem 0 0;
  color: var(--amber);
  font-size: 0.75rem;
}

/* ── Stats ──────────────────────────────────────────────────────────── */

dl#stats-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(128px, 1fr));
  gap: 1rem 1.5rem;
  margin: 0;
}

dl#stats-list div, .inline-stats div {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
}

/* Long filenames shrink rather than wrap mid-word. */
dl#stats-list div:first-child dd {
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

dt {
  font-size: 0.65rem;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

dd {
  font-size: 1.15rem;
  font-weight: 700;
  margin: 0;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

dd.warn { color: var(--red); }

.inline-stats {
  display: flex;
  gap: 2rem;
  margin: 0 0 1rem;
  flex-wrap: wrap;
}

/* ── Tables ─────────────────────────────────────────────────────────── */

.table-scroll {
  overflow-x: auto;
  border: 1px solid var(--hair);
  border-radius: 2px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}

thead th {
  text-align: left;
  padding: 0.5rem 0.7rem;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  background: rgba(74, 222, 128, 0.05);
  border-bottom: 1px solid var(--hair);
  position: sticky;
  top: 0;
}

th.num, td.num { text-align: right; }

tbody tr { border-top: 1px solid rgba(140, 220, 190, 0.06); transition: background 0.12s; }
tbody tr:hover { background: rgba(74, 222, 128, 0.05); }

tbody td { padding: 0.42rem 0.7rem; vertical-align: top; }

.pid-cell { font-variant-numeric: tabular-nums; white-space: nowrap; }
.pid-hex { color: var(--text-dim); }

.badge {
  display: inline-block;
  padding: 0.12rem 0.5rem;
  border-radius: 999px;
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border: 1px solid currentColor;
  line-height: 1.5;
}

.badge-pat, .badge-pmt { color: var(--blue); }
.badge-si { color: var(--teal); }
.badge-pcr { color: var(--amber); }
.badge-video { color: var(--green); }
.badge-audio { color: var(--teal); }
.badge-subtitle { color: var(--magenta); }
.badge-scte-35 { color: var(--magenta); }
.badge-null, .badge-other, .badge-data { color: var(--muted); }
.badge-encrypted { color: var(--red); }

.dot-on {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 6px rgba(245, 185, 66, 0.7);
}

.dot-off { color: var(--text-faint); }

details > summary {
  cursor: pointer;
  color: var(--teal);
  font-size: 0.72rem;
  list-style: none;
}
details > summary::-webkit-details-marker { display: none; }
details > summary::before { content: "▸ "; }
details[open] > summary::before { content: "▾ "; }

td.json-cell pre {
  margin: 0.4rem 0 0;
  font-size: 0.72rem;
  white-space: pre-wrap;
  word-break: break-word;
  max-width: 640px;
  color: var(--text-dim);
}

/* ── Timing charts ──────────────────────────────────────────────────── */

.timing-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.25rem;
}

.chart-block { min-width: 0; }

.chart-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin-bottom: 0.4rem;
}

canvas {
  width: 100%;
  height: auto;
  display: block;
  background: #04070a;
  border: 1px solid var(--hair);
  border-radius: 2px;
}

/* ── TR 101 290 ─────────────────────────────────────────────────────── */

.priority-group { margin-bottom: 1rem; }
.priority-group:last-child { margin-bottom: 0; }

.priority-heading {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.priority-first { color: var(--red); }
.priority-first .dot-on { background: var(--red); box-shadow: 0 0 6px rgba(255, 92, 92, 0.7); }
.priority-second { color: var(--amber); }
.priority-second .dot-on { background: var(--amber); box-shadow: 0 0 6px rgba(245, 185, 66, 0.7); }
.priority-third { color: var(--green); }
.priority-third .dot-on { background: var(--green); box-shadow: 0 0 6px rgba(74, 222, 128, 0.7); }

.indicator-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.15rem 1rem;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--hair);
  border-radius: 2px;
  margin-bottom: 0.5rem;
  background: rgba(255, 255, 255, 0.015);
}

.indicator-name { font-weight: 700; font-size: 0.78rem; color: var(--text); }
.indicator-clause { grid-column: 1; color: var(--text-faint); font-size: 0.68rem; }
.indicator-count {
  grid-row: 1 / span 2;
  grid-column: 2;
  align-self: center;
  font-size: 1.1rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.indicator-detail {
  grid-column: 1 / -1;
  color: var(--text-dim);
  font-size: 0.7rem;
  margin-top: 0.3rem;
  padding-left: 0.1rem;
}
.indicator-pids {
  grid-column: 1 / -1;
  color: var(--text-faint);
  font-size: 0.68rem;
}

.conformance-clean {
  color: var(--green);
  font-size: 0.82rem;
  padding: 0.5rem 0;
}

/* ── SCTE-35 timeline ───────────────────────────────────────────────── */

.timeline {
  list-style: none;
  margin: 0;
  padding: 0;
  border-left: 2px solid var(--hair-strong);
}

.timeline li {
  position: relative;
  padding: 0 0 1rem 1.1rem;
}

.timeline li::before {
  content: "";
  position: absolute;
  left: -5px;
  top: 0.3rem;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--magenta);
  box-shadow: 0 0 6px rgba(255, 110, 199, 0.7);
}

.timeline-head {
  display: flex;
  gap: 0.75rem;
  align-items: baseline;
  font-size: 0.78rem;
  flex-wrap: wrap;
}

.timeline-cmd { font-weight: 700; color: var(--magenta); }
.timeline-meta { color: var(--text-faint); font-size: 0.7rem; }

.timeline-fields {
  margin-top: 0.3rem;
  color: var(--text-dim);
  font-size: 0.72rem;
}

/* ── DVB subtitle preview ───────────────────────────────────────────── */

.subtitle-preview-wrap {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

/* A checkerboard backdrop (not the plain canvas fill used by the line
   charts) so a fully- or partially-transparent decoded pixel reads as
   "transparent", not "black". `image-rendering: pixelated` keeps the
   (usually small) bitmap crisp when the browser upscales it to fill the
   panel width, instead of the line charts' smooth interpolation. */
.subtitle-canvas {
  width: 100%;
  height: auto;
  display: block;
  image-rendering: pixelated;
  background-color: #04070a;
  background-image:
    linear-gradient(45deg, rgba(255, 255, 255, 0.07) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(255, 255, 255, 0.07) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(255, 255, 255, 0.07) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(255, 255, 255, 0.07) 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0px;
  border: 1px solid var(--hair);
  border-radius: 2px;
}

.subtitle-caption {
  margin: 0;
  color: var(--text-faint);
  font-size: 0.68rem;
}

/* ── Raw JSON ───────────────────────────────────────────────────────── */

pre#json-pre {
  background: #04070a;
  border: 1px solid var(--hair);
  color: var(--text-dim);
  padding: 1rem;
  border-radius: 2px;
  overflow-x: auto;
  font-size: 0.75rem;
  max-height: 50vh;
}

.panel h2 button#json-toggle { margin-left: auto; }

button#json-toggle {
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.2rem 0.7rem;
  border: 1px solid var(--hair-strong);
  border-radius: 999px;
  background: transparent;
  color: var(--green);
  cursor: pointer;
  font-family: var(--mono);
}

button#json-toggle:hover { background: rgba(74, 222, 128, 0.1); }

/* ── Footer ─────────────────────────────────────────────────────────── */

footer {
  margin-top: 3rem;
  display: flex;
  gap: 0.6rem;
  justify-content: center;
  color: var(--text-faint);
  font-size: 0.7rem;
  letter-spacing: 0.02em;
}
footer .dot { color: var(--text-faint); }

/* ── Utility ────────────────────────────────────────────────────────── */

.hidden { display: none !important; }

@media (max-width: 640px) {
  body { padding: 1.25rem 1rem 3rem; font-size: 13px; }
  .panel { padding: 0.85rem 0.8rem 1rem; }
}

/* Respect reduced-motion preferences. */
@media (prefers-reduced-motion: reduce) {
  .brand-led, .spinner, .panel { animation: none; }
}
