@font-face {
  font-family: "Atkinson Mono";
  src: url("../fonts/AtkinsonHyperlegibleMono-Regular.woff2") format("woff2"),
       url("../fonts/AtkinsonHyperlegibleMono-Regular.otf") format("opentype");
  font-weight: normal;
  font-display: swap;
}
@font-face {
  font-family: "Atkinson Mono";
  src: url("../fonts/AtkinsonHyperlegibleMono-Bold.woff2") format("woff2"),
       url("../fonts/AtkinsonHyperlegibleMono-Bold.otf") format("opentype");
  font-weight: bold;
  font-display: swap;
}

:root {
  --fg: #e8e4de;
  --fg-title: #f5f1eb;
  --fg-muted: #9a9588;
  --fg-disabled: #5a5548;
  --bg: #141210;
  --bg-surface: #1e1b16;
  --bg-elevated: #282420;
  --sidebar-bg: var(--bg-surface);
  --accent: #ffffff;
  --border-color: #3a3528;
  --border: 1px solid var(--border-color);
  --radius: 8px;
  --cell-gap: 12px;
  --font-mono: "Atkinson Mono", "Courier New", Courier, monospace;
  --font-family: var(--font-mono);
  --font-base: 12px;
  --subtitle-size: clamp(22px, 4.5vw, 48px);
  --font-md: 1.3em;
  --font-lg: 1.75em;
  --font-xl: 2.25em;
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-xxl: 48px;
  --cell-pad: 16px 24px;
  /* Muted text already uses --fg-muted; these opacities dim it further, so keep
     them high enough to stay legible at 10 ft (avoid compounding into mush). */
  --muted: 0.72;
  --muted-half: 0.75;
  --muted-future: 0.72;
  --muted-loading: 0.35;
  --z-base: 1;
  --z-sticky: 5;
  --z-toolbar: 100;
  --z-overlay: 200;
  --z-toast: 300;
  --z-settings: 400;
  --header-height: 64px;
  --sidebar-width: 60px;
  --mobilenav-height: 56px;
  --cell-bg: var(--bg-surface);
  --cell-bg-alt: var(--bg-elevated);
  --color-on: rgba(255, 255, 255, 0.15);
  --color-on-hover: rgba(255, 255, 255, 0.2);
  --color-on-focused: rgba(255, 255, 255, 0.18);
  --color-on-active: rgba(255, 255, 255, 0.25);
  --color-watching: #000;
  --color-watching-text: #e0dcd6;
  --color-red: #E03030;
  --color-green: #30D030;
  --color-blue: #4060E0;
  --color-overlay: rgba(0, 0, 0, 0.85);
  --color-overlay-light: rgba(0, 0, 0, 0.7);
  --color-label-hover: rgba(255, 255, 255, 0.05);
  --gradient-bottom: linear-gradient(to top, rgba(0, 0, 0, 1) 0%, rgba(0, 0, 0, 0.92) 60%, rgba(0, 0, 0, 0.4) 85%, transparent 100%);
  --shadow-press: inset 0 1px 4px rgba(0, 0, 0, 0.3);
  --shadow-press-on: inset 0 1px 4px rgba(255, 255, 255, 0.06);
  --shadow-text: 0 0 4px rgba(0, 0, 0, 0.8);
  --focus-ring: 1px;
  --focus-bg: var(--bg-elevated);
  --focus-color: var(--accent);
  --color-border: 6px;
  --focus-shadow: inset 0 0 0 var(--focus-ring) var(--fg-muted);
  --focus-shadow-inv: inset 0 0 0 var(--focus-ring) var(--bg);
  --safe-x: 90px;
  --safe-y: 0px;
}

* {
  touch-action: manipulation;
  scrollbar-width: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: none !important;
}
button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
}
*:focus { outline: none; }
*::-webkit-scrollbar {
  display: none;
}
html,
body {
  height: 100dvh;
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-size: var(--font-base);
  font-family: var(--font-family);
  font-weight: normal;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: pan-x pan-y;
}
.hidden {
  display: none !important;
}

/* --- Sidebar Navigation --- */
.sidebar {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--sidebar-bg, var(--bg));
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0;
  z-index: calc(var(--z-settings) + 1);
  transition: transform 0.35s ease !important;
}
.sidebar--hidden {
  display: none;
}
.sidebar-item {
  width: 100%;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  outline: none;
  color: var(--fg-muted);
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
  position: relative;
}
.sidebar-item:hover {
  color: var(--fg-title);
}
.sidebar-item:focus-visible {
  color: var(--fg-title);
  box-shadow: var(--focus-shadow);
}
.sidebar-item--active {
  color: var(--fg-title);
  background: var(--bg);
}
.sidebar-clock {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--fg);
  height: 44px;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: default;
  border-bottom: var(--border);
  width: 100%;
}
.sidebar-spacer {
  flex: 1;
}
.sidebar-qr {
  width: 44px;
  padding: var(--space-xs);
  padding-bottom: var(--space-md);
}
.sidebar-qr svg {
  width: 100%;
  height: auto;
  display: block;
}
.sidebar-qr svg rect[fill="#ffffff"] {
  fill: var(--fg-muted);
}
.sidebar-qr svg path[fill="#000000"],
.sidebar-qr svg rect[fill="#000000"] {
  fill: var(--fg-muted);
}

/* --- Screens --- */
.screen {
  position: fixed;
  inset: 0;
  left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  overflow: auto;
}

/* --- Shared button base --- */
.btn {
  background: var(--bg-surface);
  border: var(--border);
  color: var(--fg);
  padding: var(--cell-pad);
  min-height: 48px;
  font-family: inherit;
  font-weight: normal;
}
.btn--active {
  background: var(--bg-elevated);
  box-shadow: var(--focus-shadow);
}
.btn strong {
  text-decoration: underline;
}
.btn:disabled {
  opacity: 0.3;
  pointer-events: none;
}

[data-screen="settings"] {
  z-index: var(--z-settings);
  background: var(--bg);
}

/* --- Channels screen --- */
[data-screen="channels"] {
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--space-md);
  display: flex;
  flex-direction: column;
  z-index: 10;
  background: var(--bg);
}

/* --- Card Grid (channels overview) --- */
.card-grid {
  display: grid;
  grid-template-columns: repeat(var(--grid-cols, 4), 1fr);
  grid-auto-rows: 1fr;
  gap: var(--cell-gap);
  flex: 1;
}
.card-grid-section {
  grid-column: 1 / -1;
  grid-row: auto / span 1;
  font-family: var(--font-family);
  font-weight: bold;
  font-size: var(--font-lg);
  color: var(--fg-title);
  padding: var(--space-sm) 0;
  text-transform: uppercase;
  letter-spacing: 1px;
  align-self: end;
}
.card-grid-section:not(:first-child) {
  margin-top: var(--space-md);
  padding-top: var(--space-md);
  border-top: var(--border);
}

/* --- Channel Grid (legacy/shared) --- */
.grid-header {
  position: relative;
  display: flex;
  align-items: stretch;
  height: var(--header-height);
  box-sizing: border-box;
  border-bottom: var(--border);
}
.grid-header-actions {
  display: flex;
}
.grid-cell {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-start;
  background: var(--cell-bg);
  border: none;
  border-radius: var(--radius);
  user-select: none;
  padding: var(--space-lg);
  box-sizing: border-box;
  overflow: hidden;
  cursor: pointer;
  /* Mild dim for non-focused cards — the focus ring is the real cue. Kept high
     enough that the muted "next" text stays above WCAG AA contrast. */
  opacity: 0.85;
  /* Floor close to the loaded height (label + now-playing) so cards don't jump
     when the schedule info loads in — keeps CLS low on the single-column layout. */
  min-height: max(var(--card-row-height, 190px), 190px);
}
.grid-cell--custom {
  border-top: var(--color-border) solid var(--channel-color, var(--fg));
}
.grid-cell.grid-cell--focused {
  background: var(--bg-elevated);
  opacity: 1;
  /* Thick ring in the channel's PM5544 colour (set via --focus-color in JS) —
     the 10-ft focus cue. Falls back to the accent for presets. */
  box-shadow: inset 0 0 0 3px var(--focus-color);
}
.grid-cell--slot {
  background: transparent;
  border: 2px solid var(--fg-muted);
  align-items: center;
  justify-content: center;
  opacity: 0.5;
}
.grid-cell--slot.grid-cell--focused {
  opacity: 1;
  background: var(--bg-elevated);
}
.grid-cell-slot-plus {
  font-size: 3em;
  font-weight: 200;
  line-height: 1;
}
.grid-cell-slot-label {
  font-size: 1em;
  color: var(--channel-color, var(--fg-muted));
  margin-top: var(--space-xs);
}
.grid-cell-edit {
  position: absolute;
  bottom: var(--space-sm);
  right: var(--space-sm);
  background: none;
  border: none;
  color: var(--fg-muted);
  cursor: pointer;
  padding: var(--space-sm);
  opacity: 0;
  transition: opacity 0.2s;
}
.grid-cell--focused .grid-cell-edit {
  opacity: 1;
}
.grid-cell--loading {
  opacity: var(--muted-loading);
}
@keyframes pulse {
  0%, 100% { opacity: var(--muted-loading); }
  50% { opacity: var(--muted-future); }
}
.grid-cell--loading .grid-cell-label {
  animation: pulse 1.2s ease-in-out infinite;
}
.grid-cell-label {
  font-family: var(--font-mono);
  font-weight: bold;
  font-size: var(--font-lg);
  line-height: 1.1;
  text-align: left;
  color: var(--fg-title);
}
.grid-cell-status {
  margin-top: var(--space-sm);
  color: var(--fg-muted);
}
.grid-cell-info {
  margin-top: var(--space-lg);
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-xs);
}
.grid-cell-now,
.grid-cell-next {
  max-width: 100%;
  text-align: left;
  font-family: var(--font-family);
}
.grid-cell-now {
  color: var(--fg-title);
}
.grid-cell-next {
  color: var(--fg);
}
.grid-cell-scroller {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  flex-shrink: 0;
}
@keyframes card-scroll {
  0%, 13% { transform: translateY(0); }
  47%, 100% { transform: translateY(var(--scroll-dist)); }
}
.grid-cell--focused .grid-cell-scroller {
  animation: card-scroll 15s linear infinite alternate;
}

/* --- Toast --- */
.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  background: var(--fg-title);
  color: var(--bg);
  padding: var(--space-md) var(--space-lg);
  font-weight: normal;
  text-transform: none;
  letter-spacing: normal;
  border-radius: var(--radius);
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
  z-index: var(--z-toast);
}
.toast--visible {
  opacity: 1;
}
.toast--bottom {
  bottom: var(--space-xl);
}
.toast--center {
  top: 50%;
  transform: translate(-50%, -50%);
}

/* --- Watching --- */
[data-screen="watching"] {
  background: var(--color-watching);
  z-index: 1;
  left: 0;
}
[data-screen="watching"] .schedule-overlay {
  left: 0;
}
[data-screen="watching"] .schedule-content {
  padding: 0 var(--space-md) var(--space-md);
}
.watching-player {
  position: fixed;
  inset: 0;
  z-index: 1;
}
.watching-player video {
  width: 100%;
  height: 100%;
  border: none;
  background: var(--color-watching);
  object-fit: contain;
}
/* --- Radio visual --- */
.radio-visual {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-watching);
  color: var(--color-watching-text);
  font-family: var(--font-family);
  font-size: clamp(28px, 5vw, 56px);
  pointer-events: none;
}
.watching-player video::cue {
  font-size: var(--subtitle-size);
  background: var(--color-overlay);
  color: var(--color-watching-text);
  line-height: 1.15;
}
.watching-player video.custom-subs::cue {
  font-size: 1px;
  color: transparent;
  background: transparent;
}

/* --- Volume slider --- */
.volume-slider {
  position: fixed;
  right: calc(var(--safe-x) + var(--space-lg));
  top: 50%;
  transform: translateY(-50%);
  width: 32px;
  height: 150px;
  background: var(--color-overlay-light);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  z-index: var(--z-overlay);
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}
.volume-slider--visible {
  opacity: 1;
}
.volume-slider-fill {
  width: 100%;
  background: var(--fg-title);
  border-radius: 0 0 var(--radius) var(--radius);
  transition: height 0.1s;
}
.volume-slider-label {
  position: absolute;
  top: -28px;
  color: var(--fg-title);
  font-family: var(--font-mono);
}

.info-channel-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  padding: var(--space-lg) var(--safe-x);
  font-family: var(--font-mono);
  font-weight: bold;
  font-size: var(--font-lg);
  color: var(--fg-title);
  z-index: var(--z-toolbar);
  transition: transform 0.35s ease !important;
}

/* --- Program info bar --- */
.program-info-overlay {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: var(--space-lg) var(--safe-x) calc(var(--space-lg) + env(safe-area-inset-bottom, 0px));
  background: var(--gradient-bottom);
  color: var(--fg-title);
  z-index: var(--z-toolbar);
  cursor: pointer;
  opacity: 1;
  transition: transform 0.35s ease !important;
  transform: translateY(0);
}
.info-title {
  font-family: var(--font-family);
  font-weight: bold;
  font-size: var(--font-xl);
  line-height: 1.1;
  margin-bottom: var(--space-sm);
  padding-right: 80px;
}
.info-time {
  font-family: var(--font-mono);
  color: var(--fg-muted);
}
.info-desc {
  font-family: var(--font-family);
  line-height: 1.3;
  margin-top: var(--space-lg);
  max-height: 80vh;
  overflow-y: auto;
  color: var(--fg);
  opacity: 1;
  transition: opacity 0.25s ease;
}
.info-desc--collapsed {
  opacity: 0;
  max-height: 0 !important;
  margin-top: 0;
  overflow: hidden;
  pointer-events: none;
}
@media (min-width: 1000px) {
  .info-desc {
    max-width: 75vw;
  }
}
.info-heart {
  position: absolute;
  top: var(--space-lg);
  right: var(--safe-x);
  background: none;
  border: none;
  color: var(--fg-muted);
  cursor: pointer;
  padding: var(--space-xs);
  transition: color 0.2s;
}
.info-heart.hidden {
  display: none;
}
.info-heart:focus-visible {
  color: var(--fg-title);
  box-shadow: var(--focus-shadow);
  border-radius: var(--radius);
}
.info-heart.info-heart--liked {
  color: var(--color-red);
}
.info-heart.info-heart--liked .info-heart-icon {
  fill: var(--color-red);
}
.info-heart.info-heart--disliked {
  color: var(--fg-muted);
}
.info-heart.info-heart--disliked .info-heart-icon {
  fill: none;
}
.info-heart.info-heart--disliked .info-heart-cross {
  display: block !important;
  position: absolute;
  top: var(--space-xs);
  left: var(--space-xs);
}
.info-link {
  display: inline-block;
  margin-left: var(--space-md);
  color: var(--fg-title);
  text-decoration: none;
  border-bottom: 2px solid var(--fg-muted);
  padding-bottom: 1px;
}

/* --- Schedule overlay --- */
.schedule-overlay {
  position: fixed;
  inset: 0;
  left: var(--sidebar-width);
  background: var(--bg);
  z-index: var(--z-overlay);
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  padding: 0;
}
[data-screen="guide"] {
  background: var(--bg);
  z-index: var(--z-settings);
}
[data-screen="guide"] .schedule-content {
  padding: 0 var(--space-md) var(--space-md);
}
.schedule-grid-header-bar {
  display: grid;
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg);
  padding-top: var(--space-md);
  padding-bottom: var(--space-sm);
}
.schedule-content {
  flex: 1;
  overflow: auto;
  overscroll-behavior: none;
  position: relative;
}
.schedule-grid {
  display: grid;
  min-width: 100%;
  position: relative;
  z-index: 0;
}
.schedule-grid-header {
  background: var(--bg-surface);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: var(--space-sm) var(--space-md);
  text-align: left;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  font-family: var(--font-family);
  font-weight: bold;
  font-size: var(--font-md);
  color: var(--fg-title);
}
.schedule-grid-col {
  position: relative;
  background: var(--bg-surface);
  border-radius: var(--radius);
  overflow: hidden;
}
.schedule-grid-block {
  position: absolute;
  left: 0;
  right: 0;
  padding: var(--space-sm);
  border-top: var(--border);
  line-height: 1.2;
  box-sizing: border-box;
  overflow: hidden;
  font-family: var(--font-family);
  color: var(--fg);
}
.schedule-grid-block:nth-child(even) {
  background: var(--bg-elevated);
}
.schedule-grid-block--current {
  font-weight: 400;
  color: var(--fg-title);
  z-index: 3;
}
.schedule-grid-block--future {
  opacity: var(--muted-future);
}
.schedule-grid-block--past {
  opacity: var(--muted);
}
.schedule-grid-block.schedule-grid-block--focused {
  background: var(--bg-elevated);
  opacity: 1;
  box-shadow: inset 0 0 0 var(--focus-ring) var(--fg-muted);
}
.schedule-grid-block--focused .schedule-grid-block-desc {
  opacity: 1;
}
.schedule-grid-block--focused .schedule-block-scroller {
  animation: card-scroll 15s linear infinite alternate;
}
.schedule-grid-header--focused {
  background: var(--bg-elevated);
  color: var(--fg-title);
}
.schedule-grid-block-time {
  color: var(--fg-muted);
  font-family: var(--font-mono);
}
.schedule-grid-block-desc {
  opacity: var(--muted-half);
}
.schedule-grid-now {
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--color-red);
  z-index: 10;
  pointer-events: none;
}
.schedule-empty {
  text-align: center;
  padding: var(--space-xxl) 0;
  grid-column: 1 / -1;
  color: var(--fg-muted);
}


/* --- Tag Editor --- */
.tag-editor {
  position: fixed;
  inset: 0;
  left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.tag-editor-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 var(--space-md) var(--safe-y);
}
/* --- Inline save button (tag editor) --- */
.tag-editor-actions {
  display: flex;
  gap: var(--space-md);
  padding: var(--space-lg) 0;
  margin-top: var(--space-md);
}
.tag-editor-inline-save {
  flex: 1;
  padding: var(--cell-pad);
  background: var(--bg-elevated);
  border: var(--border);
  border-radius: var(--radius);
  color: var(--fg-title);
  font-family: inherit;
  cursor: pointer;
  opacity: 0.3;
  pointer-events: none;
  transition: opacity 0.3s;
  box-sizing: border-box;
  text-align: center;
}
.tag-editor-inline-save--visible {
  opacity: 1;
  pointer-events: auto;
  color: var(--color-green);
}
.tag-editor-hint {
  grid-column: 1 / -1;
  color: var(--fg-muted);
  padding: var(--space-lg) var(--cell-gap);
  line-height: 1.4;
}
.tag-editor-inline-delete {
  padding: var(--cell-pad);
  background: none;
  border: var(--border);
  border-radius: var(--radius);
  color: var(--fg-muted);
  font-family: var(--font-family);
  cursor: pointer;
}
.tag-editor-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--cell-min-width, 140px), 1fr));
  gap: var(--cell-gap);
  padding: var(--cell-gap) 0;
}
.tag-editor-row-label {
  grid-column: 1 / -1;
  padding: var(--space-sm) 0 0;
  margin-top: var(--space-sm);
  margin-bottom: 0;
  text-transform: uppercase;
  font-weight: bold;
  letter-spacing: 1px;
  color: var(--fg-title);
  font-family: var(--font-family);
}
.settings-group {
  transition: opacity 0.15s ease;
}
.settings-about {
  flex: 1;
  min-width: 0;
  line-height: 1.5;
  color: var(--fg-muted);
  padding: var(--cell-gap);
}
.settings-about a {
  color: var(--fg);
  text-decoration: underline;
}
.settings-reset-btn {
  margin-top: var(--space-md);
  padding: var(--cell-pad);
  width: 100%;
  background: var(--bg-surface);
  border: var(--border);
  border-radius: var(--radius);
  color: var(--fg-muted);
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
  text-align: left;
}
.settings-reset-btn.tag-editor-cell--focused {
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--fg-muted);
}
.settings-reset-btn--armed {
  color: var(--color-red);
  border-color: var(--color-red);
}
.settings-about p {
  margin: 0 0 var(--space-sm);
}
.settings-divider {
  border: none;
  border-top: var(--border);
  margin: var(--space-lg) 0;
}
.setting-description {
  display: block;
  font-weight: 400;
  text-transform: none;
  letter-spacing: normal;
  color: var(--fg-muted);
  margin-top: 2px;
}
/* --- Category label buttons --- */
button.tag-editor-row-label {
  background: transparent;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  text-align: left;
  font-family: var(--font-family);
  font-size: inherit;
  text-transform: uppercase;
  color: var(--fg-title);
}
button.tag-editor-row-label:hover,
button.tag-editor-row-label:focus-visible {
  background: var(--color-label-hover);
}
button.tag-editor-row-label.tag-editor-row-label--focused {
  background: var(--bg-elevated);
  box-shadow: inset 0 0 0 var(--focus-ring) var(--fg-muted);
}

.tag-editor-cell {
  background: var(--bg-surface);
  border: var(--border);
  border-radius: var(--radius);
  color: var(--fg);
  padding: var(--cell-pad);
  font-family: inherit;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
  outline: none;
}
.tag-editor-cell--on {
  background: var(--color-on);
  color: var(--fg-title);
  box-shadow: inset 0 0 0 1px var(--color-on);
  border-color: var(--fg-muted);
}
.tag-editor-cell--on::after {
  content: "\a0\2713";
  display: inline;
  line-height: 0;
}
.tag-editor-cell.tag-editor-cell--focused {
  background: var(--bg-elevated);
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--fg-muted);
}
.tag-editor-cell--on.tag-editor-cell--focused {
  background: var(--color-on-focused);
  color: var(--fg-title);
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--fg-muted);
}
.tag-editor-cell:active,
.tag-editor-cell.tag-editor-cell--active {
  box-shadow: var(--shadow-press);
}
.tag-editor-cell--on:hover {
  background: var(--color-on-hover);
}
.tag-editor-cell--on:active,
.tag-editor-cell--on.tag-editor-cell--active {
  background: var(--color-on-active);
  box-shadow: inset 0 0 0 1px var(--color-on), var(--shadow-press-on);
}

/* --- Tag editor tabs --- */
.tag-editor-intro {
  padding: var(--space-lg) 0;
  color: var(--fg);
  font-size: 1.3em;
  line-height: 1.6;
}

.tag-editor-tabs {
  display: flex;
  border-bottom: var(--border);
}
.tag-editor-tabs .btn {
  flex: 1;
  text-align: center;
  border: none;
  border-bottom: 2px solid transparent;
}
.tag-editor-tabs .btn--on {
  border-bottom-color: var(--accent);
  color: var(--fg-title);
}

/* --- Series sort bar --- */
.series-sort-bar {
  display: flex;
  border-bottom: var(--border);
}
.series-sort-bar .btn {
  flex: 1;
  text-align: center;
  border: none;
  border-right: var(--border);
  min-height: 48px;
  padding: var(--space-sm) var(--space-md);
}
.series-sort-bar .btn--on {
  background: var(--color-on);
  color: var(--fg-title);
}
.series-sort-bar .btn:last-child {
  border-right: none;
}

/* --- Series search --- */
select.tag-editor-cell {
  appearance: none;
  -webkit-appearance: none;
  background: var(--bg-surface);
  color: var(--fg);
  cursor: pointer;
}

.series-search-input {
  display: block;
  width: 100%;
  box-sizing: border-box;
  padding: var(--cell-pad);
  border: none;
  border-bottom: var(--border);
  font-family: inherit;
  font-size: inherit;
  background: var(--bg-surface);
  color: var(--fg);
  outline: none;
}
.series-search-input::placeholder {
  color: var(--fg-muted);
}
.series-search-input--focused {
  background: var(--bg-elevated);
  box-shadow: var(--focus-shadow);
}

/* --- Video error --- */
.video-error {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.video-error-content {
  text-align: center;
  padding: var(--space-xl);
  font-family: var(--font-family);
}
.video-error-title {
  margin-bottom: var(--space-sm);
  color: var(--fg-title);
  font-weight: bold;
}
.video-error-message {
  color: var(--fg-muted);
}
.video-error-next {
  margin-top: var(--space-md);
  color: var(--fg-muted);
}

.info-remaining--started { color: var(--color-green); }
.info-remaining--ending { color: var(--color-red); }

/* --- Progress bar --- */
.progress-bar {
  position: fixed;
  bottom: env(safe-area-inset-bottom, 0px);
  left: 0;
  opacity: 0;
  transition: opacity 0.3s;
  right: 0;
  height: var(--space-xs);
  background: var(--color-on);
  z-index: 150;
}
.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
}

/* --- Portrait: always single column --- */
@media (orientation: portrait) {
  :root {
    --grid-cols: 1;
  }
}

/* --- Mobile --- */
@media (max-width: 600px) {
  .sidebar {
    position: fixed;
    left: 0;
    right: 0;
    top: auto;
    bottom: 0;
    width: 100%;
    height: var(--mobilenav-height);
    flex-direction: row;
    justify-content: space-around;
    padding: 0;
    border-right: none;
    border-top: var(--border);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    transition: transform 0.35s ease !important;
  }
  .sidebar-clock,
  .sidebar-spacer,
  .sidebar-qr {
    display: none;
  }
  .sidebar-item {
    height: 100%;
    outline: none;
  }
  .sidebar-item svg {
    width: 26px;
    height: 26px;
  }
  .screen,
  .schedule-overlay,
  .tag-editor {
    left: 0;
    bottom: calc(var(--mobilenav-height) + env(safe-area-inset-bottom, 0px));
  }
  [data-screen="watching"],
  [data-screen="watching"] .schedule-overlay {
    bottom: 0;
  }
  [data-screen="watching"] .program-info-overlay {
    bottom: 0;
    max-height: 60dvh;
  }
  [data-screen="watching"] .info-desc {
    max-height: 40vh;
  }
  [data-screen="watching"] .progress-bar {
    bottom: 0;
  }
  :root {
    --safe-x: 16px;
    --safe-y: 16px;
    --font-base: 16px;
  }
  .grid-cell-label,
  .schedule-grid-header {
    font-size: inherit;
  }
  .info-title {
    font-size: 24px;
  }
  .info-heart {
    right: var(--space-md);
  }
  .info-desc {
    max-height: 20vh;
  }
  .program-info-overlay {
    max-height: 50dvh;
    overflow-y: auto;
    bottom: calc(var(--mobilenav-height) + env(safe-area-inset-bottom, 0px));
  }
  .progress-bar {
    bottom: calc(var(--mobilenav-height) + env(safe-area-inset-bottom, 0px));
  }
}



/* --- Subtitles --- */
::cue {
  font-size: var(--subtitle-size);
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  line-height: 1.15;
}
.subtitle-overlay {
  position: absolute;
  bottom: 10%;
  left: 5%;
  right: 5%;
  text-align: center;
  color: #fff;
  font-size: var(--subtitle-size);
  font-family: var(--font-family);
  line-height: 1.15;
  text-shadow: 1px 1px 3px #000, -1px -1px 3px #000;
  pointer-events: none;
  z-index: 2;
}
.subtitle-overlay div + div {
  margin-top: 0.05em;
}

/* --- Account / friends rows --- */
.account-row { display: flex; justify-content: space-between; align-items: center; text-align: left; gap: var(--space-sm); }
.account-row-info { flex: 1; }
.account-row-activity { opacity: 0.5; font-size: 0.85em; display: inline; }
.account-cell-sm { padding: 2px 8px !important; }
.account-input-readonly { opacity: 0.5; cursor: default; text-align: left; }
.account-input-text { text-align: left; }
.account-logout { opacity: 0.6; }

/* --- Chat panel --- */
.chat-panel { position: fixed; top: 0; right: 0; width: 280px; height: 100dvh; background: var(--bg-surface); border-left: var(--border); display: flex; flex-direction: column; z-index: 100; transition: transform 0.2s ease; }
.chat-panel.chat-panel--hidden { transform: translateX(100%); }
body.chat-visible .watching-player { right: 280px; }
body.chat-visible .watching-player video { width: 100%; }
.chat-toggle-btn { position: fixed; top: var(--space-sm); right: var(--space-sm); z-index: 101; background: none; border: none; color: var(--fg); padding: var(--space-xs); cursor: pointer; font-size: 1.4em; line-height: 1; opacity: 0.7; }
.chat-toggle-btn.chat-visible { right: calc(280px + var(--space-sm)); }
.chat-members { display: flex; gap: var(--space-xs); padding: var(--space-xs); border-bottom: var(--border); flex-wrap: wrap; }
.chat-member { background: var(--bg-elevated); padding: 2px var(--space-xs); border-radius: var(--radius); font-size: 0.8em; }
.chat-messages { flex: 1; overflow-y: auto; padding: var(--space-xs); display: flex; flex-direction: column; gap: 2px; }
.chat-message { font-size: 0.85em; line-height: 1.3; }
.chat-name { color: var(--fg-muted); margin-right: 0.4em; }
.chat-name::after { content: ":"; }
.chat-input-row { display: flex; gap: var(--space-xs); padding: var(--space-xs); border-top: var(--border); }
.chat-input { flex: 1; background: var(--bg-elevated); border: var(--border); color: var(--fg); padding: var(--space-xs); border-radius: var(--radius); font-family: inherit; font-size: 0.85em; }
.chat-send-btn { background: var(--bg-elevated); color: var(--fg); border: var(--border); padding: var(--space-xs) var(--space-sm); border-radius: var(--radius); cursor: pointer; font-family: inherit; font-size: 0.85em; }
.chat-toggle-btn:focus-visible, .chat-send-btn:focus-visible, .chat-input:focus-visible { outline: none; box-shadow: var(--focus-shadow); }

/* ==========================================================================
   Raspberry Pi performance overrides
   Activated when rpi/server.js injects <meta name="device-type" content="pi">
   ========================================================================== */
body[data-device="tv"], body[data-device="tv"] * { cursor: none !important; }
/* Disable every transition + animation on Pi. Several component rules use
   `transition: ... !important` (sidebar/overlay/progress), so this must also be
   !important AND higher specificity (0,1,1 > 0,1,0) to actually win. */
body[data-device="tv"] *,
body[data-device="tv"] *::before,
body[data-device="tv"] *::after {
  transition: none !important;
  animation: none !important;
}
/* Simplify subtitle text-shadow to single layer */
body[data-device="tv"] .subtitle-overlay {
  text-shadow: 1px 1px 2px #000;
}
/* Remove gradient overlay — use flat color instead */
body[data-device="tv"] .program-info-overlay {
  background: var(--color-overlay);
}
/* Simplify color-mix on sidebar */
body[data-device="tv"] .sidebar {
  background: var(--bg);
}
