:root {
  --paper: #edf0f3;
  --surface: #ffffff;
  --surface-2: #f5f7f9;
  --ink: #15202a;
  --muted: #5e6b78;
  --line: #dbe1e6;
  --accent: #0a7c78;
  --accent-soft: #e0f1f0;
  --on-accent: #ffffff;
  --live: #d7263d;
  --ok: #1d7f49;
  --ok-soft: #e1f3e8;
  --warn: #9a5b00;
  --warn-soft: #fbefdc;
  --bad: #c0283a;
  --bad-soft: #fbe5e8;
  --bar: rgba(237, 240, 243, 0.72);
  --shadow: 0 1px 0 rgba(21, 32, 42, 0.04), 0 1px 3px rgba(21, 32, 42, 0.06);
  --radius: 14px;
  --osd: "Big Shoulders Display", "Arial Narrow", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --spring: cubic-bezier(0.2, 0.9, 0.3, 1);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0e1418;
    --surface: #172026;
    --surface-2: #1c262d;
    --ink: #e6ecf0;
    --muted: #8d9aa6;
    --line: #26323a;
    --accent: #3fb8b1;
    --accent-soft: #15302f;
    --on-accent: #062221;
    --live: #ff5468;
    --ok: #4cc584;
    --ok-soft: #12291d;
    --warn: #f0b04a;
    --warn-soft: #2d2311;
    --bad: #ff6b7d;
    --bad-soft: #301419;
    --bar: rgba(14, 20, 24, 0.72);
    --shadow: 0 1px 0 rgba(0, 0, 0, 0.3);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 100%/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}

a { color: inherit; }
h1, h2 { margin: 0; }
.mono { font-family: var(--mono); font-size: 0.86em; letter-spacing: 0; }
[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* ---------- chrome ---------- */

.bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  background: var(--bar);
  backdrop-filter: blur(20px) saturate(170%);
  -webkit-backdrop-filter: blur(20px) saturate(170%);
  mask-image: linear-gradient(#000 calc(100% - 1px), transparent);
}

.bar-actions { display: flex; gap: 8px; align-items: center; }

.wordmark {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--osd);
  font-weight: 800;
  font-size: 1.6rem;
  line-height: 1;
  letter-spacing: 0.01em;
  text-decoration: none;
  text-transform: uppercase;
}

.wordmark-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--live);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--live) 22%, transparent);
}

.back {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  min-height: 44px;
  margin-left: -8px;
  padding-right: 8px;
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}
.back svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }

.page {
  max-width: 720px;
  margin: 0 auto;
  padding: 8px max(16px, env(safe-area-inset-right)) calc(40px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.page-head { padding: 14px 4px 18px; }
.page-head h1 { font-size: 2rem; line-height: 1.1; letter-spacing: -0.02em; font-weight: 750; }
.page-sub { margin: 6px 0 0; color: var(--muted); font-size: 0.94rem; }
.edit-head { display: flex; align-items: center; gap: 14px; }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 16px;
  border: 0;
  border-radius: 999px;
  font: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  text-decoration: none;
  cursor: pointer;
  transition: transform 100ms ease-out, background-color 150ms ease;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-quiet { background: color-mix(in srgb, var(--ink) 7%, transparent); color: var(--ink); }
.btn-quiet[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.btn-link { background: none; color: var(--accent); padding: 0 4px; min-height: 36px; }
.btn-danger { background: var(--bad-soft); color: var(--bad); width: 100%; min-height: 48px; border-radius: 12px; }
.btn-block { width: 100%; min-height: 48px; }

/* ---------- channel list ---------- */

.channels {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.channel {
  position: relative;
  display: grid;
  grid-template-columns: 3.1rem minmax(0, 1fr) auto;
  align-items: center;
  gap: 4px;
  padding: 0 14px 0 6px;
  min-height: 72px;
  background: var(--surface);
}
.channel + .channel::before {
  content: "";
  position: absolute;
  top: 0;
  left: 3.5rem;
  right: 0;
  border-top: 1px solid var(--line);
}

.osd {
  font-family: var(--osd);
  font-weight: 800;
  font-size: 2rem;
  line-height: 1;
  text-align: center;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  letter-spacing: -0.01em;
}
.channel.is-off .osd { color: var(--line); }
.channel.is-off .channel-main { opacity: 0.55; }

.channel-main {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  padding: 12px 8px 12px 4px;
  text-decoration: none;
  border-radius: 10px;
}
.channel-main:active { background: var(--surface-2); }
.channel-text { display: grid; gap: 2px; min-width: 0; }
.channel-name { font-weight: 650; font-size: 1.05rem; letter-spacing: -0.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.channel-meta { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 0.85rem; min-width: 0; }
.channel-meta .mono { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag {
  flex: none;
  padding: 1px 7px;
  border-radius: 6px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--muted);
}

.logo {
  flex: none;
  position: relative;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--accent-soft);
  overflow: hidden;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--ink) 8%, transparent);
}
.logo::before {
  content: attr(data-initials);
  font-family: var(--osd);
  font-weight: 800;
  font-size: 1.05rem;
  color: var(--accent);
}
.logo img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #fff; padding: 4px; }
.logo-lg { width: 56px; height: 56px; border-radius: 14px; }
.logo-lg::before { font-size: 1.5rem; }

.move { display: none; gap: 4px; }
.move-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--ink);
  cursor: pointer;
  transition: transform 100ms ease-out;
}
.move-btn:active { transform: scale(0.94); background: var(--accent-soft); }
.move-btn:disabled { opacity: 0.3; }
.move-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }

.reordering .move { display: flex; }
.reordering .channel .switch { display: none; }
.reordering .channel-main { pointer-events: none; }

.logout { margin-top: 28px; text-align: center; }

.empty {
  display: grid;
  justify-items: center;
  gap: 14px;
  padding: 40px 20px;
  background: var(--surface);
  border-radius: var(--radius);
  text-align: center;
  color: var(--muted);
}

/* ---------- switch ---------- */

.switch { position: relative; display: inline-flex; align-items: center; min-height: 44px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch-track {
  position: relative;
  width: 51px;
  height: 31px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--ink) 16%, transparent);
  transition: background-color 200ms ease;
}
.switch-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.18);
  transition: transform 260ms var(--spring);
}
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(20px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- forms ---------- */

.sheet { display: grid; gap: 22px; }

.group {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  padding: 16px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.group-title {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
details.group { display: block; }
.group-body { display: grid; grid-template-columns: 1fr; gap: 14px; margin-top: 14px; }
details.group > summary { cursor: pointer; list-style: none; display: flex; justify-content: space-between; align-items: center; min-height: 28px; }
details.group > summary::-webkit-details-marker { display: none; }
details.group > summary::after { content: "+"; font-size: 1.3rem; font-weight: 400; color: var(--accent); }
details.group[open] > summary::after { content: "–"; }

.field { display: grid; gap: 6px; min-width: 0; align-content: start; }
.field-label { font-size: 0.86rem; font-weight: 600; }
.field-hint { font-size: 0.8rem; color: var(--muted); }
.field-error { font-size: 0.82rem; color: var(--bad); font-weight: 600; }
.field-inline { grid-template-columns: 1fr auto; align-items: center; }

input:not([type="checkbox"]):not([type="radio"]) {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--ink);
  font: inherit;
  font-size: 1rem; /* 16px keeps iOS from zooming on focus */
  transition: border-color 150ms ease, background-color 150ms ease;
}
input.mono { font-family: var(--mono); font-size: 0.92rem; }
input:focus { outline: none; border-color: var(--accent); background: var(--surface); }
.field.has-error input { border-color: var(--bad); }

.segmented {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 3px;
  border-radius: 11px;
  background: color-mix(in srgb, var(--ink) 7%, transparent);
}
.segment { position: relative; }
.segment input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.segment span {
  display: grid;
  place-items: center;
  min-height: 36px;
  border-radius: 8px;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--muted);
  transition: background-color 180ms ease, color 180ms ease;
}
.segment input:checked + span { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }
.segment input:focus-visible + span { outline: 2px solid var(--accent); }

.kv { display: grid; gap: 8px; }
.kv:empty { display: none; }
[data-field="hints.headers"] > .btn-link { justify-self: start; }
.kv-row { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 3fr) 40px; gap: 6px; }
.kv-remove { border: 0; background: none; color: var(--muted); font-size: 1.4rem; cursor: pointer; border-radius: 10px; }

.danger { padding-top: 4px; }

/* ---------- test ---------- */

.btn-test {
  justify-self: start;
  min-height: 46px;
  padding: 0 20px 0 16px;
  background: var(--ink);
  color: var(--paper);
}
.btn-test-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--live); }
.btn-test.is-running .btn-test-dot { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.25; } }

.report {
  display: grid;
  gap: 14px;
  padding: 16px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  animation: arrive 320ms var(--spring);
  scroll-margin-top: 76px;
}
@keyframes arrive { from { opacity: 0; transform: translateY(-6px); } }

.verdict { display: grid; gap: 4px; }
.verdict-code {
  font-family: var(--osd);
  font-weight: 800;
  font-size: 2.4rem;
  line-height: 0.95;
  letter-spacing: 0.01em;
  text-transform: uppercase;
}
.verdict.ok .verdict-code { color: var(--ok); }
.verdict.fail .verdict-code { color: var(--bad); }
.verdict-detail { color: var(--muted); font-size: 0.9rem; overflow-wrap: anywhere; }

.winner {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: start;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--ok-soft);
}
.winner code { font-family: var(--mono); font-size: 0.8rem; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

.stages { display: grid; gap: 10px; }
.stage { border-top: 1px solid var(--line); padding-top: 10px; }
.stage-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.stage-name { font-weight: 700; font-size: 0.92rem; }
.stage-time { font-family: var(--mono); font-size: 0.8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.stage-note { margin: 4px 0 0; font-size: 0.82rem; color: var(--muted); overflow-wrap: anywhere; }
.cands { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 6px; }
.cand { display: grid; grid-template-columns: 5.6rem minmax(0, 1fr); gap: 8px; align-items: start; font-size: 0.8rem; }
.cand-url { font-family: var(--mono); overflow-wrap: anywhere; color: var(--ink); }
.cand-url.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; cursor: pointer; }
.cand-reason { display: block; color: var(--muted); font-family: system-ui, sans-serif; }
.pill {
  justify-self: start;
  padding: 2px 7px;
  border-radius: 6px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.pill-valid { background: var(--ok-soft); color: var(--ok); }
.pill-geo, .pill-invalid { background: var(--bad-soft); color: var(--bad); }
.pill-drm { background: var(--warn-soft); color: var(--warn); }
.pill-filtered, .pill-untested { background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.cands-more { font-size: 0.8rem; }

.suggest { display: grid; gap: 8px; }
.suggest-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 8px 8px 8px 10px;
  border-radius: 10px;
  background: var(--accent-soft);
}
.suggest-kind { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--accent); }
.suggest-value { font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.suggest-row .btn { min-height: 34px; padding: 0 12px; font-size: 0.85rem; }
/* Checkerboard so white-on-transparent logos stay visible. */
.suggest-row img {
  width: 40px;
  height: 32px;
  object-fit: contain;
  border-radius: 6px;
  background: repeating-conic-gradient(#c9d1d8 0 25%, #eef1f4 0 50%) 0 0 / 10px 10px;
}

.preview { display: grid; gap: 8px; }
.preview video { width: 100%; aspect-ratio: 16 / 9; background: #000; border-radius: 10px; }
.preview-note { font-size: 0.8rem; color: var(--muted); margin: 0; }
.preview-state { font-size: 0.82rem; font-weight: 600; margin: 0; }

/* ---------- login ---------- */

body.login { display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: 100%;
  max-width: 360px;
  display: grid;
  gap: 6px;
  padding: 28px 22px 22px;
  background: var(--surface);
  border-radius: 20px;
  box-shadow: var(--shadow);
}
.login-card .wordmark { font-size: 2.6rem; }
.login-lede { margin: 0 0 18px; color: var(--muted); }
.login-form { display: grid; gap: 14px; }
.form-error { margin: 0; color: var(--bad); font-weight: 600; font-size: 0.9rem; }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--paper);
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  animation: arrive 260ms var(--spring);
  z-index: 20;
  max-width: calc(100vw - 32px);
}
.toast.is-error { background: var(--bad); color: #fff; }

/* ---------- wider screens ---------- */

@media (min-width: 760px) {
  .page-head h1 { font-size: 2.4rem; }
  .group, .group-body { grid-template-columns: 1fr 1fr; gap: 16px 18px; }
  .group { padding: 20px; }
  .group-title, .field-wide, .group > .btn-test, .field-inline { grid-column: 1 / -1; }
  .channel { grid-template-columns: 3.6rem minmax(0, 1fr) auto; padding-right: 18px; }
  .channel + .channel::before { left: 4rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; transition-duration: 1ms !important; }
}
@media (prefers-reduced-transparency: reduce) {
  .bar { background: var(--paper); backdrop-filter: none; -webkit-backdrop-filter: none; }
}
