/* Hedgie TV components. Every value comes from tokens.css. Class names match the parent app's stylesheet, so it can adopt this file directly. */

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font: 400 16px/24px var(--font-body);
}

h1,
h2,
h3 {
  margin: 0 0 var(--space-2);
  font-family: var(--font-display);
  text-wrap: balance;
}

h1 {
  font-size: 30px;
  font-weight: 700;
  line-height: 36px;
}

h2 {
  font-size: 22px;
  font-weight: 700;
  line-height: 28px;
}

h3 {
  font-size: 18px;
  font-weight: 600;
  line-height: 24px;
}

p {
  margin: 0;
}

a {
  color: var(--accent-text);
}

img {
  display: block;
  max-width: 100%;
}

:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}

.muted {
  color: var(--ink-muted);
}

.small {
  font-size: 14px;
  line-height: 20px;
}

.icon {
  flex: none;
  width: 1.25em;
  height: 1.25em;
  fill: currentColor;
}

/* Brand */

.spine-edge {
  height: 24px;
  margin-bottom: -1px;
  background: var(--spine-colour, var(--band-spine));
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='24'%3E%3Cpath d='M0 24 16.6 2.6Q20 -1.2 23.4 2.6L40 24Z'/%3E%3C/svg%3E") bottom left / 40px 24px repeat-x;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='24'%3E%3Cpath d='M0 24 16.6 2.6Q20 -1.2 23.4 2.6L40 24Z'/%3E%3C/svg%3E") bottom left / 40px 24px repeat-x;
}

.spine-edge-large {
  height: 40px;
  -webkit-mask-size: 67px 40px;
  mask-size: 67px 40px;
}

/* Put both logos in the markup, and the theme shows the right one. */
.logo-on-dark,
[data-theme="dark"] .logo-on-light {
  display: none;
}

[data-theme="dark"] .logo-on-dark {
  display: block;
}

/* Buttons */

.button,
.button-quiet {
  font: 600 16px/20px var(--font-display);
  cursor: pointer;
}

.button {
  display: inline-flex;
  gap: var(--space-2);
  align-items: center;
  justify-content: center;
  min-height: var(--control-height);
  padding: 0 18px;
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
}

.button:hover {
  background: var(--surface-hover);
}

.button-primary {
  margin-bottom: 3px;
  border-color: transparent;
  background: var(--accent);
  box-shadow: var(--shadow-shelf);
  color: var(--on-accent);
}

.button-primary:hover {
  background: var(--accent-hover);
}

.button-primary:active {
  box-shadow: none;
  transform: translateY(3px);
}

.button-small {
  min-height: 36px;
  padding: 0 12px;
  font-size: 14px;
}

.button-large {
  min-height: 56px;
  padding: 0 28px;
  font-size: 18px;
}

.button-quiet {
  padding: 4px 6px;
  border: 0;
  background: none;
  color: var(--ink-muted);
  font-size: 14px;
  text-decoration: underline;
}

.button-quiet:hover {
  color: var(--ink);
}

.button-quiet:disabled {
  cursor: default;
  opacity: 0.5;
}

.button-danger {
  border-color: currentColor;
  color: var(--error);
}

.button-danger:hover {
  background: var(--error-tint);
}

.button-quiet.button-danger {
  border: 0;
}

/* Fields */

.field {
  display: grid;
  gap: 6px;
  width: 100%;
  font-size: 14px;
  font-weight: 600;
  line-height: 20px;
}

.field .hint {
  color: var(--ink-muted);
  font-weight: 400;
}

input,
select {
  min-height: var(--control-height);
  padding: 0 12px;
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--ink);
  font: 400 16px/24px var(--font-body);
}

.field input,
.field select {
  width: 100%;
}

input::placeholder {
  color: var(--ink-muted);
}

input:disabled {
  background: var(--surface-hover);
  color: var(--ink-muted);
}

.search-form {
  display: flex;
  gap: var(--space-2);
}

.search-form input {
  flex: 1;
  min-width: 0;
}

/* Avatars. A child is a tile, like the logo. A channel is a circle, like YouTube. */

.child-avatar {
  flex: none;
  border-radius: var(--radius-tile);
  background: var(--surface-media);
}

.avatar {
  flex: none;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--surface-media);
  object-fit: cover;
}

.avatar-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: var(--space-3);
}

.avatar-choice {
  position: relative;
  display: grid;
  justify-items: center;
  gap: var(--space-1);
  padding: var(--space-2) var(--space-1);
  border-radius: var(--radius-md);
  font-size: 14px;
  line-height: 20px;
  cursor: pointer;
}

.avatar-choice input {
  position: absolute;
  min-height: 0;
  opacity: 0;
}

.avatar-choice:hover {
  background: var(--surface-hover);
}

.avatar-choice:has(input:checked) {
  background: var(--accent-tint);
  outline: 3px solid var(--accent-text);
}

.avatar-choice:has(input:focus-visible) {
  outline: 3px solid var(--ink);
}

/* The app bar. On a wide screen it holds the sections. On a narrow one they become tabs along the bottom. */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  gap: var(--space-4);
  align-items: center;
  justify-content: space-between;
  min-height: 64px;
  padding: var(--space-2) max(var(--space-4), env(safe-area-inset-right)) var(--space-2) max(var(--space-4), env(safe-area-inset-left));
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.brand {
  flex: none;
  border-radius: var(--radius-sm);
}

.appnav {
  display: flex;
  flex: 1;
  gap: var(--space-1);
  min-width: 0;
}

.appnav-item {
  display: inline-flex;
  flex: none;
  gap: var(--space-2);
  align-items: center;
  min-height: var(--control-height);
  padding: 0 var(--space-3);
  border-radius: var(--radius-md);
  color: var(--ink-muted);
  font: 600 16px/20px var(--font-display);
  text-decoration: none;
  white-space: nowrap;
  transition: background-color 120ms ease-out, color 120ms ease-out;
}

/* This one holds the child's name, which can be long, so it's the one that gives way. */
.appnav-item:last-child {
  flex: 0 1 auto;
  min-width: 0;
}

.appnav-item:hover {
  background: var(--surface-hover);
  color: var(--ink);
}

.appnav-item[aria-current] {
  background: var(--accent-tint);
  color: var(--ink);
}

.appnav-item[aria-current] .icon {
  color: var(--accent-text);
}

.appnav-label {
  overflow: hidden;
  max-width: 16ch;
  text-overflow: ellipsis;
}

.appnav-count {
  font-family: var(--font-body);
  font-variant-numeric: tabular-nums;
}

.topbar-menus {
  display: flex;
  flex: 0 1 auto;
  gap: var(--space-2);
  min-width: 0;
}

.menu-button {
  display: inline-flex;
  flex: 0 1 auto;
  gap: var(--space-2);
  align-items: center;
  min-width: 0;
  min-height: var(--control-height);
  padding: 6px var(--space-3) 6px 6px;
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--surface-hover);
  color: var(--ink);
  font: 600 16px/20px var(--font-display);
  cursor: pointer;
  transition: background-color 120ms ease-out;
}

.menu-button:hover {
  background: var(--line);
}

.menu-button img {
  width: 32px;
  height: 32px;
}

.menu-button-account {
  flex: none;
  padding-left: var(--space-3);
}

.menu-button-name {
  overflow: hidden;
  min-width: 0;
  max-width: 14ch;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* A popover floats above the page and isn't tied to its button, so it's placed under the end of the bar. */
.app-menu {
  position: fixed;
  inset: 60px max(var(--space-4), env(safe-area-inset-right)) auto auto;
  width: min(300px, 100vw - 2 * var(--space-4));
  max-height: calc(100dvh - 76px);
  margin: 0;
  overflow-y: auto;
  padding: var(--space-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface-raised);
  box-shadow: var(--shadow-pop);
  color: var(--ink);
}

@media (prefers-reduced-motion: no-preference) {
  .app-menu:popover-open {
    animation: app-menu-open 120ms ease-out;
  }
}

@keyframes app-menu-open {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
}

.app-menu ul {
  display: grid;
  gap: 2px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.app-menu-group {
  display: grid;
  gap: 2px;
  margin-top: var(--space-2);
  padding-top: var(--space-2);
  border-top: 1px solid var(--line);
}

.app-menu-item {
  display: flex;
  gap: var(--space-3);
  align-items: center;
  min-height: var(--touch-target);
  padding: var(--space-2);
  border-radius: var(--radius-sm);
  border: 0;
  background: none;
  color: var(--ink);
  font: 600 16px/20px var(--font-display);
  text-align: left;
  text-decoration: none;
}

/* The menu's button sits among its links, and has to fill the row as they do. */
button.app-menu-item {
  width: 100%;
}

.app-menu-item:disabled {
  color: var(--ink-muted);
}

.app-menu-item:hover:not(:disabled) {
  background: var(--surface-hover);
}

.app-menu-item[aria-current] {
  background: var(--accent-tint);
}

.app-menu-item[aria-current] .icon {
  color: var(--accent-text);
}

/* Lines up with the pictures of the children above. */
.app-menu-group .icon {
  width: 32px;
  color: var(--ink-muted);
}

.app-menu-heading {
  padding: var(--space-1) var(--space-2) var(--space-2);
  color: var(--ink-muted);
  font-size: 14px;
  font-weight: 600;
  line-height: 20px;
}

.app-menu-hint {
  display: block;
  font: 400 13px/18px var(--font-body);
  white-space: normal;
}

/* Three choices in a well. The chosen one is filled, as a selected chip is. */
.theme-choice {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-1);
  padding: var(--space-1);
  border-radius: var(--radius-md);
  background: var(--surface-hover);
}

.theme-option {
  display: inline-flex;
  gap: var(--space-1);
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 var(--space-1);
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--ink);
  font: 600 14px/20px var(--font-display);
  cursor: pointer;
}

.theme-option:hover {
  background: var(--line);
}

.theme-option[aria-pressed="true"] {
  background: var(--accent);
  color: var(--on-accent);
}

.app-menu-name {
  flex: 1;
  overflow: hidden;
  min-width: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* The sections still need the room here, so the parent's button keeps only its icon. */
@media (min-width: 961px) and (max-width: 1160px) {
  .menu-button-account .menu-button-name,
  .menu-button-account .icon:last-child {
    display: none;
  }

  .menu-button-account {
    padding: 0 var(--space-3);
  }
}

@media (max-width: 960px) {
  .appnav {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 10;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 0;
    padding: var(--space-1) max(var(--space-1), env(safe-area-inset-right)) max(var(--space-1), env(safe-area-inset-bottom)) max(var(--space-1), env(safe-area-inset-left));
    border-top: 1px solid var(--line);
    background: var(--surface);
  }

  .appnav-item {
    position: relative;
    flex-direction: column;
    gap: 2px;
    justify-content: center;
    min-height: 56px;
    padding: 2px;
    border-radius: var(--radius-sm);
    font: 500 13px/18px var(--font-body);
  }

  .appnav-item:hover {
    background: none;
  }

  /* The fill goes behind the icon alone, so that the row of words stays level. */
  .appnav-item[aria-current] {
    background: none;
    font-weight: 700;
  }

  .appnav-item .icon {
    box-sizing: border-box;
    width: 52px;
    height: 28px;
    padding: 3px 0;
    border-radius: var(--radius-pill);
  }

  .appnav-item[aria-current] .icon {
    background: var(--accent-tint);
  }

  .appnav-label {
    max-width: 100%;
  }

  .appnav-item .appnav-count {
    position: absolute;
    top: 0;
    left: calc(50% + 6px);
    padding: 0 6px;
  }

}

/* On a phone, the same goes for the bar itself. */
@media (max-width: 480px) {
  .menu-button-account .menu-button-name,
  .menu-button-account .icon:last-child {
    display: none;
  }

  .menu-button-account {
    padding: 0 var(--space-3);
  }
}

@media (max-width: 360px) {
  .topbar {
    gap: var(--space-2);
  }

  .topbar-menus {
    gap: var(--space-1);
  }

  .menu-button .icon:last-child:not(:first-child) {
    display: none;
  }
}

/* Page */

.page {
  max-width: var(--page-max);
  margin: 0 auto;
  padding: var(--space-6) max(var(--space-4), env(safe-area-inset-right)) var(--space-16) max(var(--space-4), env(safe-area-inset-left));
}

/* Leaves room for the tabs along the bottom. */
@media (max-width: 960px) {
  .page {
    padding-bottom: calc(var(--space-16) + 64px + env(safe-area-inset-bottom));
  }
}

.child-heading {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3) var(--space-4);
  align-items: center;
  margin-bottom: var(--space-4);
}

.child-heading h1 {
  margin: 0;
}

.panel {
  padding: var(--space-5);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.empty {
  padding: var(--space-8) var(--space-4);
  color: var(--ink-muted);
  text-align: center;
}

/* Notices and badges */

.notice {
  display: block;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  background: var(--accent-tint);
  color: var(--ink);
}

.notice-action {
  background: var(--attention-tint);
  text-decoration: none;
}

.notice-error {
  background: var(--error-tint);
}

.badge {
  display: inline-block;
  padding: 1px var(--space-2);
  border-radius: var(--radius-pill);
  background: var(--surface-hover);
  color: var(--ink-muted);
  font-size: 13px;
  font-weight: 500;
  line-height: 18px;
}

.badge-good {
  background: var(--good-tint);
  color: var(--good);
}

.badge-attention {
  background: var(--attention-tint);
  color: var(--attention);
}

.badge-error {
  background: var(--error-tint);
  color: var(--error);
}

/* Channels */

.channel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr));
  gap: var(--space-3);
}

.channel-card {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-4);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: inherit;
  text-decoration: none;
}

.channel-card:hover {
  border-color: var(--accent-text);
}

.channel-card-body {
  display: grid;
  align-content: start;
  gap: 2px;
  justify-items: start;
  min-width: 0;
}

.channel-card h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  line-height: 24px;
}

.channel-card p {
  font-size: 14px;
  line-height: 20px;
}

.channel-card .badge {
  margin-top: var(--space-1);
  font-size: 13px;
  line-height: 18px;
}

.result {
  display: flex;
  gap: var(--space-4);
  align-items: flex-start;
  padding: var(--space-4);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.result-body {
  flex: 1;
  min-width: 0;
}

.result h2 {
  margin-bottom: 2px;
}

.facts {
  display: flex;
  flex-wrap: wrap;
  gap: 2px var(--space-3);
  align-items: center;
  margin: 0 0 6px;
  padding: 0;
  color: var(--ink-muted);
  font-size: 14px;
  line-height: 20px;
  list-style: none;
}

.handle {
  color: var(--ink);
  font-weight: 600;
}

.description {
  color: var(--ink-muted);
  font-size: 14px;
  line-height: 20px;
}

/* Modes */

.mode-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
  gap: var(--space-3);
}

.mode {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-4);
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.mode strong {
  font: 600 18px/24px var(--font-display);
}

.mode:hover:not(:disabled) {
  background: var(--surface-hover);
}

.mode span {
  color: var(--ink-muted);
  font-size: 14px;
  line-height: 20px;
}

.mode .mode-count {
  margin-top: auto;
  padding-top: 6px;
  font-weight: 600;
}

.mode-current {
  border: 2px solid var(--accent-text);
  background: var(--accent-tint);
  cursor: default;
}

.mode-current:hover:not(:disabled) {
  background: var(--accent-tint);
}

.mode-current span {
  color: var(--ink);
}

.mode-current .mode-count {
  color: var(--accent-text);
}

/* Switches. Filled is on, and the word beside it says so too. It's for what can be turned back on. */

.switch-form {
  display: inline-flex;
  flex-shrink: 0;
  gap: var(--space-2);
  align-items: center;
}

.switch-word {
  min-width: 2ch;
  color: var(--ink-muted);
  font-size: 14px;
  line-height: 20px;
}

.switch {
  position: relative;
  display: inline-block;
  flex-shrink: 0;
  width: 52px;
  height: 32px;
  margin: 6px 0;
  padding: 3px;
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius-pill);
  background: var(--surface);
  cursor: pointer;
  transition: background 120ms ease-out;
}

/* Reaches the height of a control, around a switch that looks better smaller. */
.switch::after {
  position: absolute;
  inset: -8px -4px;
  content: "";
}

.switch span {
  display: block;
  width: 23px;
  height: 23px;
  border-radius: 50%;
  background: var(--line-strong);
  transition: transform 120ms ease-out;
}

.switch:hover {
  background: var(--surface-hover);
}

.switch[aria-checked="true"] {
  border-color: var(--accent-edge);
  background: var(--accent);
}

.switch[aria-checked="true"]:hover {
  background: var(--accent-hover);
}

.switch[aria-checked="true"] span {
  background: var(--on-accent);
  transform: translateX(20px);
}

@media (prefers-reduced-motion: reduce) {
  .switch,
  .switch span {
    transition: none;
  }
}

/* Rules. What hides and what approves stand side by side. A heading's word says which, so colour is never the only signal. */

.rule-text {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
  min-width: 0;
}

.rule-board {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 400px), 1fr));
  gap: var(--space-4);
  align-items: start;
}

.rule-column {
  display: grid;
  gap: var(--space-6);
  padding: var(--space-5);
  border: 1px solid var(--line);
  border-top-width: 4px;
  border-radius: var(--radius-lg);
  background: var(--surface);
}

.rule-column > * + * {
  margin-top: 0;
}

.rule-column-exclude {
  border-top-color: var(--error);
}

.rule-column-include {
  border-top-color: var(--good);
}

.rule-column-head {
  display: flex;
  gap: var(--space-3);
  align-items: flex-start;
}

.rule-column-icon {
  display: grid;
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: var(--radius-md);
}

.rule-column-icon .icon {
  width: 24px;
  height: 24px;
}

.rule-column-exclude .rule-column-icon {
  background: var(--error-tint);
  color: var(--error);
}

.rule-column-include .rule-column-icon {
  background: var(--good-tint);
  color: var(--good);
}

.rule-tally {
  margin-left: var(--space-1);
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

.rule-group {
  display: grid;
  gap: var(--space-2);
}

.rule-group h3 {
  color: var(--ink-muted);
  font: 600 14px/20px var(--font-body);
}

.rule-group h3 .small {
  margin-left: var(--space-1);
  font: 400 14px/20px var(--font-body);
}

.rule-cards {
  display: grid;
  gap: var(--space-2);
  margin: 0;
  padding: 0;
  list-style: none;
}

.rule-card {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) auto auto;
  gap: var(--space-3);
  align-items: center;
  padding: var(--space-2) var(--space-2) var(--space-2) var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
}

.rule-card:has(.rule-card-foot) {
  grid-template-columns: 40px minmax(0, 1fr) auto;
}

.rule-tile {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border-radius: var(--radius-sm);
  background: var(--surface-hover);
  color: var(--ink-muted);
}

.rule-card-text strong {
  display: block;
  font: 600 18px/24px var(--font-display);
  overflow-wrap: anywhere;
}

.rule-count {
  display: grid;
  justify-items: end;
  color: var(--ink-muted);
  font-size: 13px;
  line-height: 16px;
}

.rule-count b {
  color: var(--ink);
  font: 600 18px/22px var(--font-display);
  font-variant-numeric: tabular-nums;
}

/* A set width, so that the counts line up whichever control a card has. */
.rule-control {
  display: flex;
  justify-content: flex-end;
  width: 104px;
}

.rule-card-foot {
  display: flex;
  grid-column: 2 / -1;
  gap: var(--space-1);
  justify-content: flex-end;
  margin-top: calc(-1 * var(--space-2));
}

/* A rule that's doing nothing, here or for anyone. */
.rule-card-off {
  border-style: dashed;
  border-color: var(--line-strong);
}

.rule-card-off .rule-card-text strong,
.rule-card-off .rule-count b {
  color: var(--ink-muted);
}

.rule-card-off .rule-tile {
  background: none;
}

.rule-action {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  min-height: var(--control-height);
  padding: 0 var(--space-2);
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--ink-muted);
  font: 500 14px/20px var(--font-body);
  text-decoration: none;
  cursor: pointer;
}

.rule-action .icon {
  width: 18px;
  height: 18px;
}

.rule-action:hover {
  background: var(--surface-hover);
  color: var(--ink);
}

/* Removing can't be undone, so it has its own look, and a switch never does this. */
.rule-action-remove:hover {
  background: var(--error-tint);
  color: var(--error);
}

.rule-add summary {
  display: flex;
  gap: var(--space-2);
  align-items: center;
  justify-content: center;
  min-height: var(--control-height);
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--radius-md);
  font: 600 16px/22px var(--font-display);
  cursor: pointer;
  list-style: none;
}

.rule-add summary::-webkit-details-marker {
  display: none;
}

.rule-add summary:hover {
  background: var(--surface-hover);
}

.rule-add[open] summary {
  border-style: solid;
  border-color: var(--line);
  color: var(--ink-muted);
}

.rule-choices {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0;
  padding: 0;
  border: 0;
}

.rule-choices legend {
  margin-bottom: var(--space-2);
  padding: 0;
  font-size: 14px;
  font-weight: 600;
  line-height: 20px;
}

.rule-choice {
  position: relative;
  display: inline-flex;
  gap: 6px;
  align-items: center;
  min-height: var(--control-height);
  padding: 0 var(--space-3);
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius-pill);
  font-size: 14px;
  font-weight: 500;
  line-height: 20px;
  cursor: pointer;
}

.rule-choice input {
  position: absolute;
  min-height: 0;
  opacity: 0;
}

.rule-choice:has(input:checked) {
  border-color: var(--accent-edge);
  background: var(--accent);
  color: var(--on-accent);
}

.rule-choice:has(input:focus-visible) {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}

/* On a phone the words get the card's width, and the count and control share a line below. */
@media (max-width: 600px) {
  .rule-card {
    grid-template-columns: 40px minmax(0, 1fr) auto;
    row-gap: 0;
  }

  .rule-card-text {
    grid-column: 2 / -1;
  }

  .rule-count {
    grid-column: 2;
    display: flex;
    gap: var(--space-1);
    align-items: baseline;
  }

  .rule-count b {
    font: 600 14px/20px var(--font-body);
  }

  .rule-control {
    grid-column: 3;
    width: auto;
  }

  .rule-card-foot {
    margin-top: 0;
  }
}

/* Tabs and pagination */

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  align-items: center;
  border-bottom: 1px solid var(--line);
}

.tab {
  padding: var(--space-2) var(--space-3);
  border-bottom: 3px solid transparent;
  color: var(--ink-muted);
  text-decoration: none;
}

.tab:hover {
  color: var(--ink);
}

.tab-current {
  border-bottom-color: var(--accent-text);
  color: var(--ink);
  font-weight: 600;
}

.tabs-end {
  margin-left: auto;
}

.pagination {
  display: flex;
  gap: var(--space-3);
  align-items: center;
  justify-content: space-between;
}

/* Videos in the parent app */

.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr));
  gap: var(--space-3);
}

.video {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.video-hidden img {
  opacity: 0.45;
  filter: grayscale(0.7);
}

.thumb {
  position: relative;
  display: block;
}

.thumb img {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: var(--surface-media);
  object-fit: cover;
}

.duration {
  position: absolute;
  right: 6px;
  bottom: 6px;
  padding: 0 6px;
  border-radius: var(--radius-xs);
  background: var(--scrim);
  color: var(--on-scrim);
  font-size: 13px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  line-height: 18px;
}

.video-body {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: var(--space-1);
  align-items: flex-start;
  padding: 10px var(--space-3) var(--space-3);
}

.video-body h3 {
  display: -webkit-box;
  overflow: hidden;
  margin: 0;
  font: 600 15px/20px var(--font-body);
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.video-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  align-items: center;
  margin-top: auto;
  padding-top: var(--space-2);
}

/* Activity */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr));
  gap: var(--space-3);
}

.stat {
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.stat-value {
  font: 700 30px/36px var(--font-display);
}

.day-chart {
  display: grid;
  grid-template-columns: repeat(14, minmax(0, 1fr));
  margin: 0;
  padding: 0;
  list-style: none;
}

.day {
  position: relative;
  border-radius: var(--radius-xs);
}

.day:hover {
  background: var(--surface-hover);
}

.day-plot {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 120px;
  border-bottom: 1px solid var(--line-strong);
}

.day-bar {
  flex: none;
  width: min(24px, calc(100% - 4px));
  border-radius: var(--radius-xs) var(--radius-xs) 0 0;
  background: var(--chart-bar);
}

.day-peak {
  margin-bottom: 2px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  line-height: 18px;
  white-space: nowrap;
}

.day-label {
  display: block;
  padding-top: var(--space-1);
  color: var(--ink-muted);
  font-size: 13px;
  line-height: 18px;
  text-align: center;
}

.table-scroll {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.watch-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  line-height: 20px;
}

.watch-table th,
.watch-table td {
  padding: 10px var(--space-3);
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.watch-table tbody tr:last-child td {
  border-bottom: 0;
}

.watch-table th {
  color: var(--ink-muted);
  font-weight: 600;
  white-space: nowrap;
}

.watch-table .number {
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}

.watched-video {
  display: flex;
  gap: var(--space-3);
  min-width: 260px;
}

.watched-video img {
  flex: none;
  align-self: flex-start;
  width: 88px;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius-sm);
  background: var(--surface-media);
  object-fit: cover;
}

/* Child surfaces. Put .surface-tv or .surface-touch on the screen's root. */

.surface-tv,
.surface-touch {
  background: var(--ground);
  color: var(--ink);
}

.surface-tv {
  --focus-gap: 3px;
  font-size: 20px;
  line-height: 28px;
}

.watch-card {
  display: grid;
  align-content: start;
  min-width: 0;
  color: inherit;
  text-decoration: none;
}

.surface-tv .watch-card {
  width: var(--tv-card-width);
}

.watch-thumb {
  position: relative;
  display: block;
  overflow: hidden;
  border-radius: var(--radius-lg);
  background: var(--surface-media);
  transition: transform 120ms ease-out;
}

.watch-thumb img {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
}

.watch-title {
  display: -webkit-box;
  overflow: hidden;
  margin-top: var(--space-2);
  font: 600 16px/22px var(--font-body);
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

/* Leaves room for the enlarged thumbnail and its ring. */
.surface-tv .watch-title {
  margin-top: var(--space-4);
}

.watch-meta {
  margin-top: 2px;
  color: var(--ink-muted);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  line-height: 20px;
}

.surface-touch .watch-title {
  font: 600 18px/23px var(--font-display);
}

/* The .is-focused class stands in for real D-pad focus in mock-ups. */
.watch-card.is-focused .watch-thumb,
.watch-card:focus-visible .watch-thumb {
  outline: var(--focus-width) solid var(--focus-ring);
  outline-offset: var(--focus-gap, 3px);
  transform: scale(1.06);
}

.watch-card:focus-visible {
  outline: 0;
}

.watch-card.is-focused .watch-title {
  color: var(--ink);
}

.watched-bar {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 6px;
  background: var(--progress-track);
}

.watched-bar span {
  display: block;
  height: 100%;
  min-width: 20px; /* A video only just started still shows, instead of hiding behind the thumbnail's corner. */
  border-radius: 0 var(--radius-pill) var(--radius-pill) 0;
  background: var(--progress-fill);
}

.favourite-mark {
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--scrim);
  color: var(--favourite);
  font-size: 16px;
}

.watch-row {
  display: flex;
  gap: var(--space-6);
  overflow: hidden;
  padding: var(--space-5);
  margin: calc(var(--space-5) * -1);
}

.row-heading {
  margin: 0 0 var(--space-3);
  font: 700 24px/30px var(--font-display);
}

.surface-touch .row-heading {
  font-size: 26px;
  line-height: 32px;
}

.child-tile {
  display: grid;
  gap: var(--space-4);
  justify-items: center;
  border: 0;
  background: none;
  color: var(--ink);
  font: 700 24px/30px var(--font-display);
  cursor: pointer;
}

.child-tile img {
  width: var(--tv-child-tile);
  height: var(--tv-child-tile);
  border-radius: var(--radius-tile);
  transition: transform 120ms ease-out;
}

.child-tile.is-focused img,
.child-tile:focus-visible img {
  outline: var(--focus-width) solid var(--focus-ring);
  outline-offset: 4px;
  transform: scale(1.06);
}

.child-tile:focus-visible {
  outline: 0;
}

.surface-tv .child-tile {
  gap: var(--space-5);
}

.child-button {
  display: inline-flex;
  gap: var(--space-3);
  align-items: center;
  padding: var(--space-2) var(--space-4) var(--space-2) var(--space-2);
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--ink);
  font: 700 20px/24px var(--font-display);
}

.child-button img {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-tile);
}

.child-button.is-focused,
.child-button:focus-visible {
  outline: var(--focus-width) solid var(--focus-ring);
  outline-offset: 3px;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
}

.chip {
  display: inline-flex;
  gap: var(--space-2);
  align-items: center;
  min-height: 44px;
  padding: 0 var(--space-5);
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--ink);
  font: 600 16px/22px var(--font-body);
  cursor: pointer;
}

.chip-selected {
  background: var(--accent);
  color: var(--on-accent);
}

/* An icon with no word, which needs an accessible label. */
.chip-icon {
  justify-content: center;
  width: 44px;
  padding: 0;
}

.chip.is-focused,
.chip:focus-visible {
  outline: var(--focus-width) solid var(--focus-ring);
  outline-offset: 3px;
}

.surface-touch .chip {
  min-height: var(--touch-target);
  font: 600 18px/23px var(--font-display);
}

/* The TV's home screen: a top bar over the channel list and the chosen channel's videos. */

.tv-home {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
}

.tv-top-bar {
  display: flex;
  gap: var(--space-4);
  align-items: center;
  padding: var(--tv-safe-y) var(--tv-safe-x) var(--space-3);
}

.tv-top-bar-icon {
  width: 40px;
  height: 40px;
  margin-left: auto;
  border-radius: var(--radius-tile);
}

.tv-top-bar .chip-icon {
  margin-left: auto;
}

.tv-top-bar .chip-icon + .tv-top-bar-icon {
  margin-left: 0;
}

.tv-top-bar-name {
  font: 700 24px/30px var(--font-display);
}

.icon-favourite {
  color: var(--favourite);
}

.tv-home-body {
  display: flex;
  min-height: 0;
}

.channel-list {
  display: grid;
  flex: none;
  align-content: start;
  gap: var(--space-2);
  width: var(--tv-list-width);
  overflow: hidden;
  padding: var(--space-3) var(--space-4) var(--tv-safe-y) var(--tv-safe-x);
  background: var(--surface);
}

.channel-row {
  display: flex;
  gap: var(--space-3);
  align-items: center;
  padding: var(--space-2);
  border-radius: var(--radius-md);
  color: var(--ink);
  font: 600 16px/22px var(--font-body);
  text-decoration: none;
  transition: transform 120ms ease-out;
}

.channel-row > img {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--surface-media);
  object-fit: cover;
}

/* All videos and Carry on watching aren't channels, so they're a tile rather than a circle. */
.channel-row-glyph {
  display: grid;
  flex: none;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-tile);
  background: var(--surface-media);
  color: var(--ink);
}

.channel-row-glyph .icon {
  width: 24px;
  height: 24px;
}

.channel-row-name {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

/* Folded to pictures while the focus is elsewhere, if Folds away is chosen in the TV's settings. */
.channel-list-folded {
  width: var(--tv-list-folded-width);
  padding-right: var(--space-6);
  padding-left: var(--space-6);
}

.channel-list-folded .channel-row-name {
  display: none;
}

/* Selected is a fill and focused is a ring, and one channel can be both. */
.channel-row.is-selected {
  background: var(--accent);
  color: var(--on-accent);
}

.channel-row.is-focused,
.channel-row:focus-visible {
  outline: var(--focus-width) solid var(--focus-ring);
  outline-offset: var(--focus-gap, 3px);
  transform: scale(1.06);
}

/* The other TV screens */

.tv-video-grid {
  display: grid;
  flex: 1;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-content: start;
  gap: var(--space-8) var(--space-6);
  min-width: 0;
  overflow: hidden;
  padding: var(--tv-safe-y) var(--tv-safe-x);
}

.surface-tv .tv-video-grid .watch-card {
  width: auto;
}

.tv-home .tv-video-grid {
  padding: var(--space-3) var(--tv-safe-x) 40px var(--space-6);
}

.tv-screen {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  width: 960px;
  height: 540px;
  overflow: hidden;
  padding-top: var(--tv-safe-y);
}

/* With the channel names folded away, this says which channel it is. */
.tv-video-grid-title {
  grid-column: 1 / -1;
  font: 700 24px/30px var(--font-display);
}

.tv-screen-title {
  margin: 0;
  padding: 0 var(--tv-safe-x);
  font: 700 32px/40px var(--font-display);
}

.tv-screen-heading {
  display: flex;
  gap: var(--space-6);
  align-items: center;
  margin-bottom: var(--space-2);
}

.tv-screen-heading .tv-screen-title {
  padding-right: 0;
}

.tv-chip-row {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-2) var(--tv-safe-x);
}

.tv-row {
  padding: var(--space-5) var(--tv-safe-x);
  margin: calc(var(--space-5) * -1) 0;
}

.tv-search {
  display: flex;
  flex: none;
  gap: var(--space-3);
  align-items: center;
  margin: 0 var(--tv-safe-x);
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-md);
  background: var(--surface);
  font: 400 20px/28px var(--font-body);
}

.tv-search.is-focused,
.tv-search:focus-within {
  box-shadow: inset 0 0 0 var(--focus-width) var(--focus-ring);
}

.tv-search > .icon {
  width: 24px;
  height: 24px;
  color: var(--ink-muted);
}

.tv-menu {
  display: grid;
  gap: var(--space-4);
  justify-items: start;
  max-width: 480px;
  padding: var(--space-6);
  border-radius: var(--radius-xl);
  background: var(--surface-raised);
  box-shadow: var(--shadow-pop);
}

.tv-menu-title {
  display: -webkit-box;
  overflow: hidden;
  font: 700 24px/30px var(--font-display);
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.tv-menu .chip {
  background: var(--surface-sunken);
}

.tv-settings {
  gap: var(--space-8);
}

.tv-setting {
  display: grid;
  gap: var(--space-3);
  padding: 0 var(--tv-safe-x);
}

.tv-setting-title {
  margin: 0;
  font: 700 24px/30px var(--font-display);
}

.tv-setting-note {
  margin: 0;
  color: var(--ink-muted);
  font: 400 20px/28px var(--font-body);
}

/* The player */

/* Below the video, never over it, because YouTube's terms forbid drawing on the player. */
.player-controls {
  display: grid;
  align-content: start;
  gap: var(--space-2);
  padding: var(--space-3) var(--tv-safe-x) 0;
  background: var(--ground);
  color: var(--ink);
}

.player-title {
  overflow: hidden;
  font: 600 18px/24px var(--font-body);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-progress {
  height: 6px;
  border-radius: var(--radius-pill);
  background: var(--surface-raised);
}

.player-progress span {
  display: block;
  height: 100%;
  border-radius: var(--radius-pill);
  background: var(--progress-fill);
}

.player-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: center;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  line-height: 20px;
}

.player-row > .icon {
  width: 20px;
  height: 20px;
}

.player-control {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  min-height: 36px;
  padding: 0 var(--space-3);
  border-radius: var(--radius-pill);
  color: var(--ink);
  font: 600 14px/20px var(--font-body);
  box-shadow: inset 0 0 0 1px var(--ink);
}

.player-control .icon {
  width: 16px;
  height: 16px;
}

.player-control.is-focused {
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: none;
}

.player-spacer {
  flex: 1;
}

/* The website */

.band {
  padding: var(--space-24) max(var(--space-4), calc((100% - var(--site-max)) / 2));
}

.band-aqua {
  background: var(--accent);
  color: var(--on-accent);
}

.band-cream {
  background: var(--band-cream);
  color: var(--on-accent);
}

.band-spine {
  background: var(--band-spine);
  color: var(--on-spine);
}

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

  .watch-card.is-focused .watch-thumb,
  .watch-card:focus-visible .watch-thumb,
  .child-tile.is-focused img,
  .child-tile:focus-visible img,
  .channel-row.is-focused,
  .channel-row:focus-visible {
    transform: none;
  }
}

@media (max-width: 600px) {
  .result {
    flex-wrap: wrap;
  }

  .result-body {
    flex-basis: calc(100% - 88px);
  }

  .band {
    padding-block: var(--space-16);
  }
}

/* Confirm dialog */

/* The browser hides a closed dialog, so setting display here would have to wait for [open]. */
.confirm-dialog {
  width: min(480px, calc(100vw - 2 * var(--space-4)));
  max-width: none;
  margin: auto;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-pop);
}

.confirm-dialog::backdrop {
  background: var(--scrim, rgba(29, 18, 8, 0.74));
}

@media (prefers-reduced-motion: no-preference) {
  .confirm-dialog[open] {
    animation: app-menu-open 120ms ease-out;
  }
}

.confirm-dialog-content {
  display: grid;
  gap: var(--space-3);
  padding: var(--space-6);
  overflow-wrap: anywhere;
}

.confirm-dialog-content > h2,
.confirm-dialog-content > p {
  margin: 0;
}

.confirm-dialog-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--space-3);
  margin-top: var(--space-2);
}
