:root {
  --paper: #eef1f6;
  --surface: #ffffff;
  --surface-2: #f6f7fb;
  --ink: #1c2340;
  --ink-soft: #5b6283;
  --line: #d9dde9;
  --remote: #3d4fd6;
  --remote-ink: #ffffff;
  --ok: #1e8a6a;
  --ok-tint: #e1f3ec;
  --stop: #c8323c;
  --stop-tint: #fbe5e6;
  --wait: #b67c0c;
  --wait-tint: #fbf0d9;
  --bezel: #1c2340;
  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 9px;
  --display: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --body: "Atkinson Hyperlegible", "Segoe UI", system-ui, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #12152a;
    --surface: #1b1f38;
    --surface-2: #232845;
    --ink: #e8eaf6;
    --ink-soft: #a3a9c8;
    --line: #2f3557;
    --remote: #7b8bff;
    --remote-ink: #10132a;
    --ok: #4cc79f;
    --ok-tint: #173a33;
    --stop: #ff6b72;
    --stop-tint: #45202a;
    --wait: #f1b84a;
    --wait-tint: #3d3220;
    --bezel: #060814;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--remote); outline-offset: 2px; border-radius: 6px; }
.hidden { display: none !important; }

.shell {
  max-width: 560px;
  margin: 0 auto;
  padding: 12px 16px calc(96px + env(safe-area-inset-bottom));
}

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0 18px;
}
.brand {
  font-family: var(--display);
  font-weight: 700;
  font-size: 22px;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand img { width: 30px; height: 30px; border-radius: 8px; }

.filter-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 0;
  border-radius: 999px;
  padding: 8px 14px 8px 10px;
  font-weight: 700;
  font-size: 14px;
  background: var(--ok-tint);
  color: var(--ok);
}
.filter-pill .dot { width: 10px; height: 10px; border-radius: 50%; background: currentColor; }
.filter-pill[data-state="off"] { background: var(--stop-tint); color: var(--stop); }
.filter-pill[data-state="snoozed"] { background: var(--wait-tint); color: var(--wait); }

h1, h2, h3 { font-family: var(--display); letter-spacing: -0.015em; margin: 0; }
h2 { font-size: 24px; font-weight: 700; line-height: 1.2; }
h3 { font-size: 17px; font-weight: 650; }
.lede { color: var(--ink-soft); margin: 6px 0 18px; }
.muted { color: var(--ink-soft); }
.small { font-size: 14px; }

/* ---------- the TV ---------- */
.tv { margin-bottom: 28px; }
.tv-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 10px;
}
.tv-name { font-family: var(--display); font-weight: 700; font-size: 19px; }
.tv-link { font-size: 13px; color: var(--ink-soft); display: flex; align-items: center; gap: 6px; }
.tv-link::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.tv-link[data-status="connected"]::before { background: var(--ok); }
.tv-link[data-status="error"]::before, .tv-link[data-status="unsupported"]::before { background: var(--stop); }

.bezel {
  background: var(--bezel);
  border-radius: var(--radius-lg);
  padding: 10px;
  position: relative;
  box-shadow: inset 0 0 0 1px var(--line);
}
.screen {
  position: relative;
  aspect-ratio: 16 / 9;
  border-radius: 13px;
  overflow: hidden;
  background: #0d1024;
}
.screen img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: filter 0.4s ease;
}
.screen[data-verdict="blocked"] img { filter: grayscale(1) brightness(0.45) blur(6px); }
.screen[data-verdict="checking"] img { filter: brightness(0.75); }
.screen .idle {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
  color: #a3a9c8;
  padding: 24px;
  font-size: 15px;
}
.screen .stamp {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
}
.stamp span {
  font-family: var(--display);
  font-weight: 800;
  font-size: 26px;
  color: #fff;
  border: 3px solid #fff;
  border-radius: 12px;
  padding: 4px 16px;
  transform: rotate(-4deg);
  background: rgba(200, 50, 60, 0.85);
}
.stand {
  width: 34%;
  height: 10px;
  margin: 0 auto;
  background: var(--bezel);
  border-radius: 0 0 10px 10px;
  opacity: 0.85;
}

.verdict {
  margin-top: 14px;
  border-radius: var(--radius-md);
  padding: 12px 14px;
  background: var(--surface);
  border-left: 5px solid var(--line);
}
.verdict[data-verdict="allowed"] { border-left-color: var(--ok); }
.verdict[data-verdict="blocked"] { border-left-color: var(--stop); }
.verdict[data-verdict="checking"] { border-left-color: var(--wait); }
.verdict .title { font-weight: 700; line-height: 1.3; }
.verdict .channel { color: var(--ink-soft); font-size: 14px; }
.verdict .why { margin-top: 8px; font-size: 14px; }
.verdict .why strong { font-weight: 700; }
.verdict[data-verdict="allowed"] .why strong { color: var(--ok); }
.verdict[data-verdict="blocked"] .why strong { color: var(--stop); }
.verdict[data-verdict="checking"] .why strong { color: var(--wait); }
.verdict .row-actions { margin-top: 10px; display: flex; gap: 8px; flex-wrap: wrap; }

.remote {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 12px;
}
.remote button {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 10px 4px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-size: 13px;
  color: var(--ink-soft);
}
.remote button svg { width: 22px; height: 22px; color: var(--ink); }
.remote button:active { transform: translateY(1px); }
.remote button:disabled { opacity: 0.45; cursor: default; }

.today { color: var(--ink-soft); font-size: 15px; margin: 4px 0 24px; }
.today b { color: var(--ink); }

/* ---------- generic blocks ---------- */
.panel {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 14px;
}
.panel > h3 { margin-bottom: 4px; }
.panel > p.muted { margin: 0 0 12px; font-size: 14px; }
.notice {
  background: var(--wait-tint);
  color: var(--ink);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  font-size: 14px;
  margin-bottom: 16px;
}
.notice ul { margin: 6px 0 0; padding-left: 18px; }

.btn {
  border: 0;
  border-radius: 999px;
  padding: 10px 18px;
  font-weight: 700;
  background: var(--remote);
  color: var(--remote-ink);
}
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn.small { padding: 6px 12px; font-size: 14px; }
.btn.danger { background: transparent; color: var(--stop); border: 1px solid var(--stop); }
.btn:disabled { opacity: 0.55; cursor: default; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field label { font-weight: 700; font-size: 14px; }
.field .hint { font-size: 13px; color: var(--ink-soft); }
input[type="text"], input[type="password"], input[type="number"], select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 16px;
}
textarea { resize: vertical; min-height: 64px; }
.inline { display: flex; gap: 8px; align-items: stretch; }
.inline > input { flex: 1; min-width: 0; }

.seg {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  background: var(--surface-2);
  border-radius: 12px;
  padding: 4px;
  gap: 4px;
  margin-bottom: 12px;
}
.seg button {
  border: 0;
  background: transparent;
  border-radius: 9px;
  padding: 9px 6px;
  font-weight: 700;
  font-size: 14px;
  color: var(--ink-soft);
}
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(28, 35, 64, 0.15); }

.switch-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}
.switch-row:first-of-type { border-top: 0; }
.switch-row .txt { font-size: 15px; }
.switch-row .txt small { display: block; color: var(--ink-soft); font-size: 13px; }
.toggle { position: relative; width: 48px; height: 28px; flex: none; }
.toggle input { opacity: 0; width: 100%; height: 100%; margin: 0; position: absolute; cursor: pointer; z-index: 1; }
.toggle span {
  position: absolute; inset: 0; border-radius: 999px; background: var(--line); transition: background 0.2s;
}
.toggle span::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: #fff; transition: transform 0.2s;
}
.toggle input:checked + span { background: var(--remote); }
.toggle input:checked + span::after { transform: translateX(20px); }
.toggle input:focus-visible + span { outline: 3px solid var(--remote); outline-offset: 2px; }

/* rules */
.rule {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}
.rule:first-child { border-top: 0; }
.rule .text { flex: 1; font-size: 15px; padding-top: 3px; }
.rule[data-off="true"] .text { color: var(--ink-soft); text-decoration: line-through; }
.icon-btn {
  border: 0; background: transparent; color: var(--ink-soft); padding: 4px; border-radius: 8px; line-height: 0;
}
.icon-btn svg { width: 20px; height: 20px; }

.radio-list label {
  display: flex; gap: 12px; align-items: flex-start; padding: 10px 0; border-top: 1px solid var(--line); cursor: pointer;
}
.radio-list label:first-child { border-top: 0; }
.radio-list input { margin-top: 4px; accent-color: var(--remote); width: 18px; height: 18px; flex: none; }
.radio-list small { display: block; color: var(--ink-soft); font-size: 13px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px;
  padding: 3px 4px 3px 12px; font-size: 14px;
}
.chip button { border: 0; background: transparent; color: var(--ink-soft); padding: 2px 6px; border-radius: 999px; }
.chips .empty { font-size: 13px; color: var(--ink-soft); }

details.more { margin-top: 4px; }
details.more summary { cursor: pointer; font-weight: 700; padding: 8px 0; color: var(--remote); }

/* test result */
.test-result { margin-top: 12px; }

/* history */
.filters { margin-bottom: 14px; }
.hist-item {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 12px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}
.hist-item:first-child { border-top: 0; }
.hist-item img { width: 96px; aspect-ratio: 16/9; object-fit: cover; border-radius: 8px; background: var(--surface-2); }
.hist-item .t { font-weight: 700; font-size: 15px; line-height: 1.3; }
.hist-item .meta { font-size: 13px; color: var(--ink-soft); }
.hist-item .why { font-size: 13px; margin-top: 4px; }
.tag {
  display: inline-block; font-size: 12px; font-weight: 700; border-radius: 6px; padding: 1px 7px; margin-right: 6px;
}
.tag.stop { background: var(--stop-tint); color: var(--stop); }
.tag.ok { background: var(--ok-tint); color: var(--ok); }
.hist-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.load-more { display: block; margin: 12px auto 0; }

/* TVs */
.steps { margin: 0 0 14px; padding-left: 20px; font-size: 15px; }
.steps li { margin-bottom: 6px; }
.tv-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 0; }
.tv-row + .tv-row { border-top: 1px solid var(--line); }

/* tab bar */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  z-index: 10;
}
.tabbar nav { max-width: 560px; margin: 0 auto; display: grid; grid-template-columns: repeat(5, 1fr); }
.tabbar button {
  border: 0; background: transparent; display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 12px; font-weight: 700; color: var(--ink-soft); padding: 6px 0; border-radius: 12px;
}
.tabbar button svg { width: 24px; height: 24px; }
.tabbar button[aria-current="page"] { color: var(--remote); }

/* sheet */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(10, 12, 30, 0.45); z-index: 20; display: flex; align-items: flex-end;
}
.sheet {
  background: var(--surface); width: 100%; max-width: 560px; margin: 0 auto;
  border-radius: 22px 22px 0 0; padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
}
.sheet h3 { margin-bottom: 12px; }
.sheet .opts { display: grid; gap: 8px; }
.sheet .opts .btn { width: 100%; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--paper); padding: 9px 16px; border-radius: 999px; font-size: 14px; font-weight: 700;
  z-index: 30; max-width: calc(100% - 32px);
}
.toast.error { background: var(--stop); color: #fff; }

/* login */
.lock-panel.is-locked { border: 2px solid var(--stop); background: var(--stop-tint); }
.lock-panel p { margin: 8px 0 0; }
#play-panel label { display: block; margin-bottom: 6px; font-weight: 700; }
#play-panel hr { border: 0; border-top: 1px solid var(--line); margin: 20px 0; }
.search-item { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 12px; padding: 14px 0; border-top: 1px solid var(--line); }
.search-item img { width: 96px; aspect-ratio: 16/9; object-fit: cover; border-radius: 8px; }
.search-item strong { font-size: 14px; overflow-wrap: anywhere; }
.search-item p { margin: 4px 0 8px; }
.ai-log-list { margin-top: 16px; }
.ai-entry { border-top: 1px solid var(--line); padding: 12px 0; }
.ai-entry:first-child { border-top: 0; }
.ai-entry summary { cursor: pointer; overflow-wrap: anywhere; }
.ai-entry summary strong, .ai-entry summary > .muted { display: block; margin-top: 5px; }
.ai-detail { min-width: 0; margin-top: 16px; }
.ai-detail p { overflow-wrap: anywhere; }
.ai-detail pre { max-height: 360px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; padding: 12px; border-radius: 8px; background: var(--surface-2); font-size: 12px; }

.login { max-width: 400px; margin: 12vh auto 0; padding: 0 16px; }
.login .brand { margin-bottom: 18px; font-size: 26px; }
.login .brand img { width: 40px; height: 40px; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
