/*
 * QR-Stream design system.
 *
 * Dark by default: the sender is meant to be pointed at with a camera in a room
 * where someone is watching a screen, and the receiver is usually a phone held
 * up to it. Light mode is supported for people who prefer it, but the QR canvas
 * itself is always black on white -- scanners are far less reliable on inverted
 * symbols, and that is not a place to be clever.
 */

:root {
  color-scheme: dark light;

  --bg: #0a0c10;
  --bg-grid: rgba(148, 163, 184, 0.05);
  --surface: #12151c;
  --surface-2: #171b24;
  --surface-3: #1e232e;
  --border: #262d3a;
  --border-strong: #36405230;

  --text: #e6edf3;
  --text-dim: #9aa7b8;
  --text-faint: #6b7888;

  --accent: #22d3ee;
  --accent-2: #a78bfa;
  --accent-glow: rgba(34, 211, 238, 0.25);
  --success: #34d399;
  --warn: #fbbf24;
  --danger: #f87171;

  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 18px 48px -18px rgba(0, 0, 0, 0.75);

  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Fira Code", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

:root[data-theme='light'] {
  color-scheme: light;
  --bg: #f4f7fb;
  --bg-grid: rgba(15, 23, 42, 0.045);
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #eef2f7;
  --border: #dfe6ef;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-dim: #55637a;
  --text-faint: #8494a8;
  --accent: #0891b2;
  --accent-2: #7c3aed;
  --accent-glow: rgba(8, 145, 178, 0.18);
  --shadow: 0 18px 40px -22px rgba(15, 23, 42, 0.35);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme='dark']) {
    color-scheme: light;
    --bg: #f4f7fb;
    --bg-grid: rgba(15, 23, 42, 0.045);
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --surface-3: #eef2f7;
    --border: #dfe6ef;
    --border-strong: #cbd5e1;
    --text: #0f172a;
    --text-dim: #55637a;
    --text-faint: #8494a8;
    --accent: #0891b2;
    --accent-2: #7c3aed;
    --accent-glow: rgba(8, 145, 178, 0.18);
    --shadow: 0 18px 40px -22px rgba(15, 23, 42, 0.35);
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background-color: var(--bg);
  background-image:
    linear-gradient(var(--bg-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--bg-grid) 1px, transparent 1px);
  background-size: 44px 44px;
  -webkit-font-smoothing: antialiased;
}

/* ---------- layout ---------- */

.shell {
  max-width: 1180px;
  margin: 0 auto;
  padding: 20px 20px 72px;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 0 22px;
  flex-wrap: wrap;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 650;
  letter-spacing: -0.02em;
  text-decoration: none;
  color: var(--text);
  font-size: 17px;
}

.brand .mark {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #06121a;
  font-weight: 800;
  font-size: 15px;
  font-family: var(--mono);
}

.topbar nav {
  display: flex;
  gap: 4px;
  margin-left: auto;
  align-items: center;
  flex-wrap: wrap;
}

.topbar nav a {
  color: var(--text-dim);
  text-decoration: none;
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}

.topbar nav a:hover { color: var(--text); background: var(--surface-2); }
.topbar nav a[aria-current='page'] { color: var(--accent); background: var(--surface-2); }

.grid-2 {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

@media (max-width: 900px) {
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
}

/* ---------- surfaces ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

/* Cards stack in normal flow; inside a grid the gap already spaces them. */
.card + .card { margin-top: 18px; }
.feature-grid > .card + .card { margin-top: 0; }

.card h2 {
  margin: 0 0 4px;
  font-size: 15px;
  font-weight: 620;
  letter-spacing: -0.01em;
}

.card .hint {
  margin: 0 0 16px;
  color: var(--text-dim);
  font-size: 13px;
}

.section-label {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin: 0 0 10px;
}

/* ---------- controls ---------- */

button, .btn {
  font: inherit;
  font-weight: 560;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  padding: 9px 16px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.08s, opacity 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
}

button:hover:not(:disabled), .btn:hover { background: var(--surface-3); border-color: var(--border-strong); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: 0.42; cursor: not-allowed; }

button:focus-visible, .btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent;
  color: #06121a;
  font-weight: 640;
}

.primary:hover:not(:disabled) { filter: brightness(1.08); background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
button.danger { color: var(--danger); }
button.ghost { background: transparent; }
button.small { padding: 6px 11px; font-size: 13px; }

.button-row { display: flex; gap: 10px; flex-wrap: wrap; }

label { display: block; font-size: 13px; font-weight: 550; margin-bottom: 6px; }

input[type='text'], input[type='number'], select, textarea {
  font: inherit;
  width: 100%;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
}

textarea {
  min-height: 168px;
  resize: vertical;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.5;
}

select { cursor: pointer; }

input[type='range'] {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
  margin: 4px 0 0;
}

.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }

.field-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
}

.field-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.field-head .value {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--accent);
}

.switch {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  margin: 0;
}

.switch input { accent-color: var(--accent); width: 16px; height: 16px; cursor: pointer; }

/* ---------- tabs ---------- */

.tabs {
  display: inline-flex;
  gap: 3px;
  padding: 3px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 16px;
}

.tabs button {
  border: none;
  background: transparent;
  padding: 6px 15px;
  font-size: 13.5px;
  border-radius: 7px;
  color: var(--text-dim);
}

.tabs button[aria-selected='true'] {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}

/* ---------- stats ---------- */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(112px, 1fr));
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

/* Fixed column counts, for grids whose item count would otherwise leave a
   ragged empty cell on the last row. */
.stats.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stats.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.stat { background: var(--surface); padding: 11px 13px; }

.stat dt {
  font-size: 10.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin: 0 0 3px;
  font-family: var(--mono);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat dd {
  margin: 0;
  font-family: var(--mono);
  font-size: 17px;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.stat dd small { font-size: 11px; color: var(--text-faint); font-weight: 400; }
.stat.accent dd { color: var(--accent); }
.stat.good dd { color: var(--success); }

/* ---------- badges & messages ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-dim);
  background: var(--surface-2);
  white-space: nowrap;
}

.badge.live { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.badge.good { color: var(--success); border-color: color-mix(in srgb, var(--success) 40%, transparent); }
.badge.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.badge.bad  { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }

.badge .dot {
  width: 6px; height: 6px; border-radius: 50%; background: currentColor;
}

.badge.live .dot { animation: pulse 1.6s ease-in-out infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.35; transform: scale(0.75); }
}

.message {
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  font-size: 13.5px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  margin-top: 14px;
}

.message.error { border-color: color-mix(in srgb, var(--danger) 45%, transparent); color: var(--danger); }
.message.ok { border-color: color-mix(in srgb, var(--success) 45%, transparent); color: var(--success); }
.message[hidden] { display: none; }

/* ---------- drop zone ---------- */

.dropzone {
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 34px 20px;
  text-align: center;
  color: var(--text-dim);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
  background: var(--surface-2);
}

.dropzone:hover, .dropzone.dragging {
  border-color: var(--accent);
  color: var(--text);
  background: color-mix(in srgb, var(--accent) 7%, var(--surface-2));
}

.dropzone strong { display: block; color: var(--text); font-size: 14.5px; margin-bottom: 4px; }
.dropzone .sub { font-size: 12.5px; }

.file-chip {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.file-chip .icon {
  width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center;
  background: var(--surface-3); font-size: 15px; flex: none;
}

.file-chip .meta { min-width: 0; flex: 1; }
.file-chip .name { font-weight: 550; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-chip .size { font-family: var(--mono); font-size: 11.5px; color: var(--text-faint); }

/* ---------- QR stage ---------- */

.stage {
  display: grid;
  place-items: center;
  gap: 14px;
}

.qr-frame {
  position: relative;
  background: #fff;
  border-radius: 12px;
  padding: 14px;
  line-height: 0;
  box-shadow: 0 0 0 1px var(--border), 0 24px 60px -30px var(--accent-glow);
  width: min(100%, 460px);
  aspect-ratio: 1;
}

.qr-frame canvas {
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  display: block;
}

.qr-frame.idle::after {
  content: 'Idle';
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #94a3b8;
  background: #fff;
  border-radius: 12px;
}

/* Fullscreen presentation: nothing but the symbol, as large as it will go. */
.qr-frame:fullscreen {
  width: 100vmin;
  height: 100vmin;
  max-width: 100vw;
  max-height: 100vh;
  border-radius: 0;
  padding: min(4vmin, 40px);
  box-shadow: none;
}

.stage-caption {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-faint);
  text-align: center;
}

/* ---------- progress ---------- */

.progress-ring { display: grid; place-items: center; position: relative; }
.progress-ring svg { transform: rotate(-90deg); display: block; }
.progress-ring circle { fill: none; stroke-width: 9; stroke-linecap: round; }
.progress-ring .track { stroke: var(--surface-3); }
/* The gradient reference is set inline per instance, so it must not be
   overridden here -- a CSS `stroke` would beat the presentation attribute. */
.progress-ring .value { transition: stroke-dashoffset 0.25s ease; }

.progress-ring .readout {
  position: absolute;
  text-align: center;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

.progress-ring .readout .pct { font-size: 27px; letter-spacing: -0.03em; display: block; }
.progress-ring .readout .sub { font-size: 10.5px; color: var(--text-faint); letter-spacing: 0.08em; text-transform: uppercase; }

.bar {
  height: 6px;
  border-radius: 999px;
  background: var(--surface-3);
  overflow: hidden;
}

.bar > span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.2s ease;
}

/* Block recovery map: one cell per source block, lit as it is recovered.
   Cells are a fixed size and the column count follows the available width, so
   the map reads the same whether the payload is four blocks or four thousand. */
.block-map {
  display: grid;
  gap: 2px;
  margin-top: 4px;
  grid-template-columns: repeat(auto-fill, var(--cell, 12px));
  justify-content: start;
}

.block-map i {
  width: var(--cell, 12px);
  height: var(--cell, 12px);
  border-radius: 2px;
  background: var(--surface-3);
  transition: background 0.3s ease;
}

.block-map i.on { background: var(--accent); }
.block-map i.fresh { background: var(--accent-2); }

/* ---------- video ---------- */

.viewport {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}

.viewport video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.viewport canvas.overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.viewport .placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 24px;
  color: var(--text-faint);
  font-size: 13.5px;
}

.viewport .corner-hud {
  position: absolute;
  top: 10px;
  left: 10px;
  right: 10px;
  display: flex;
  gap: 8px;
  justify-content: space-between;
  pointer-events: none;
}

/* ---------- result ---------- */

.result-text {
  font-family: var(--mono);
  font-size: 12.5px;
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 13px;
  max-height: 320px;
  overflow: auto;
  margin: 0;
}

/* ---------- landing page ---------- */

.hero { text-align: center; padding: 56px 0 40px; }

.hero h1 {
  font-size: clamp(2.4rem, 7vw, 4rem);
  line-height: 1.02;
  margin: 0 0 16px;
  letter-spacing: -0.045em;
  font-weight: 700;
  background: linear-gradient(135deg, var(--text) 30%, var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.hero p.lead {
  font-size: clamp(1rem, 2.2vw, 1.2rem);
  color: var(--text-dim);
  max-width: 640px;
  margin: 0 auto 30px;
}

.hero .actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.hero .actions .btn { padding: 12px 24px; font-size: 15px; }

.feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(248px, 1fr));
  gap: 16px;
  margin-top: 40px;
}

.feature { padding: 20px; }
.feature .glyph { font-size: 20px; margin-bottom: 10px; display: block; }
.feature h3 { margin: 0 0 6px; font-size: 14.5px; font-weight: 620; }
.feature p { margin: 0; font-size: 13.5px; color: var(--text-dim); line-height: 1.55; }

.callout {
  border-left: 2px solid var(--accent);
  padding: 2px 0 2px 16px;
  color: var(--text-dim);
  font-size: 14px;
  margin: 28px 0;
}

/* ---------- misc ---------- */

.mono { font-family: var(--mono); }
.dim { color: var(--text-dim); }
.hstack { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spacer { flex: 1; }
[hidden] { display: none !important; }

footer.site {
  text-align: center;
  color: var(--text-faint);
  font-size: 12.5px;
  padding: 40px 0 0;
}

footer.site a { color: var(--text-dim); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
