:root {
  --primary-color: #2f8fff;
  --primary-hover: #4da1ff;
  --primary-dark: #1d6fe0;
  --primary-glow: rgba(47, 143, 255, 0.28);
  --accent-teal: #1fb8c4;
  --accent-cyan: #00e5ff;
  --font-mono: 'JetBrains Mono', source-code-pro, Menlo, Monaco, Consolas, 'Courier New', monospace;
  --text-scale: 1;
  --background: #0a1018;
  --background-elevated: #0e1520;
  --surface: #131d2a;
  --surface-hover: #1a2736;
  --surface-border: #1e2d3d;
  --sidebar-bg: #0c1420;
  --text-primary: #e8edf2;
  --text-secondary: #7a8fa3;
  --text-muted: #7488a0;
  --border: #1a2a3a;
  --border-light: #243447;
  --error: #ef5350;
  --success: #66bb6a;
  --warning: #ffa726;
  --sidebar-width: 240px;
  --header-height: 60px;
  --card-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
  --card-shadow-hover: 0 8px 24px rgba(0, 0, 0, 0.5);
  --glow-sm: 0 0 12px rgba(47, 143, 255, 0.12);
  --glow-md: 0 0 20px rgba(47, 143, 255, 0.16);
  --gradient-surface: linear-gradient(180deg, #131d2a 0%, #0e1520 100%);
  --gradient-card: linear-gradient(145deg, #162233 0%, #111c28 100%);
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;

  /* Aliases: several components reference these names but the canonical
     tokens above were never defined under them, so var() silently resolved
     to nothing (no fallback) - killing borders/backgrounds/badge colors on
     whatever used them. Defining the aliases here fixes every call site at
     once instead of hunting down and renaming each one individually. */
  --border-color: var(--border);
  --warning-color: var(--warning);
  --error-color: var(--error);
  --danger-color: var(--error);
  --accent-color: var(--accent-teal);
  --primary: var(--primary-color);
  --card-bg: var(--surface);
  --surface-color: var(--surface);
  --surface-elevated: var(--background-elevated);
  --bg-primary: var(--background);
  --bg-secondary: var(--surface);
  --bg-hover: var(--surface-hover);
  --text-tertiary: var(--text-muted);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  /* §2/§14: one root multiplier scales every rem-based size in the app;
     toggled by the Settings text-size control (small/medium/large). */
  font-size: calc(100% * var(--text-scale));
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
    'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background-color: var(--background);
  color: var(--text-primary);
  min-height: 100vh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

code {
  font-family: var(--font-mono);
}

/* DESIGN.md §2: technical/telemetry values (timestamps, durations, counts,
   IDs, file sizes, progress) use monospace with tabular figures wherever
   they appear outside <code>, not just inside it. */
.mono-data {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

h1 {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.3;
}

h2 {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.4;
}

h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.4;
}

p {
  font-size: 0.9375rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

#root {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* DESIGN.md §14: Firefox has no ::-webkit-scrollbar support, so without
   this it falls back to the OS-default scrollbar while every other
   browser gets the thin dark one above. */
* { scrollbar-color: var(--border-light) transparent; scrollbar-width: thin; }

/* Utility classes */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1rem;
}

/* Buttons */
/* Styled wrapper for a native <input type="file">: the OS-drawn "Choose
   File" button doesn't take a background-color, so it stays whatever gray
   the browser and OS default to no matter what theme the rest of the page
   uses - this hides the real input and lets a normal .btn label trigger it
   instead. Shared here (not per-page) since import.html and
   backup_restore.html both need it. */
.file-input-label {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
}

.file-input {
  display: none;
}

.btn {
  padding: 0.625rem 1.25rem;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  /* Flex items default to justify-content:flex-start - invisible on a
     button sized to its own content, but every full-width .btn (the login
     button, "Backup Selected Playlist(s)", the settings Save/Reset row on
     mobile, ...) left its label pinned to the left edge instead of
     centered like a normal button. */
  justify-content: center;
  gap: 0.5rem;
  /* .btn is applied to real <button>s everywhere except cross_import.html's
     "Connect YouTube" (an <a> so it can be a plain navigable link) - an
     anchor carries a default underline a button never would, so without
     this override that one link looked broken/half-styled next to every
     other .btn in the app. */
  text-decoration: none;
}

.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

/* Global click feedback (see layout.html's htmx:beforeRequest/afterRequest
   listeners): every disabled button dims instead of looking identical to
   an enabled one, and whichever button was actually clicked additionally
   gets a spinner appended after its label for the request's duration. */
button:disabled,
input[type=submit]:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn.is-loading,
button.is-loading {
  position: relative;
}

.is-loading::after {
  content: "";
  display: inline-block;
  width: 0.8em;
  height: 0.8em;
  flex-shrink: 0;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: btn-spin 0.6s linear infinite;
}

@keyframes btn-spin {
  to { transform: rotate(360deg); }
}

/* Keyboard-only users got no visible focus indicator on any button/icon-
   button/link-styled-as-button in the app - only .input/select replace the
   browser's default outline with something visible (a box-shadow ring
   above). Reusing that same ring here rather than just re-enabling the
   default outline, so keyboard focus looks like part of this theme
   instead of a generic browser blue rectangle. */
.btn:focus-visible,
.icon-btn:focus-visible,
a:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(47, 143, 255, 0.4);
}

.btn-small {
  padding: 0.375rem 0.75rem;
  font-size: 0.75rem;
}

/* Changed: was a solid --gradient-primary fill with white text - clashed
   once every other control switched to the flat dark/glowing-border
   instrument-panel language (§4), and --gradient-primary itself is gone
   now (banned app-wide, per user direction, for ftl-themes compatibility -
   that theme system's tokens have no gradient concept, only flat accent
   colors + glow). Primary actions now use the same transparent-with-
   glowing-border shape as everything else, distinguished from
   .btn-secondary only by using the accent color instead of a neutral
   border. Every other former --gradient-primary call site (active tab/
   pill fills, progress bars, the .logo-lab wordmark) moved to a flat
   var(--primary-color)/var(--accent-cyan) fill for the same reason. */
.btn-primary {
  background: transparent;
  color: var(--accent-cyan);
  border: 1px solid var(--accent-cyan);
}

.btn-primary:hover {
  background: rgba(0, 229, 255, 0.12);
  box-shadow: 0 0 14px rgba(0, 229, 255, 0.4);
}

.btn-secondary {
  background-color: var(--surface);
  color: var(--text-primary);
  border: 1px solid var(--border-light);
}

.btn-secondary:hover {
  background-color: var(--surface-hover);
  border-color: var(--accent-cyan);
  box-shadow: 0 0 10px rgba(0, 229, 255, 0.3);
}

/* Cards */
.card {
  position: relative;
  background: var(--gradient-card);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  border: 1px solid var(--border);
  box-shadow: var(--card-shadow);
  transition: all 0.25s ease;
}

.card:hover {
  border-color: var(--border-light);
  box-shadow: var(--card-shadow-hover);
}

/* HUD-reticle corner accent (promoted from LoginPage.css's
   .hero-backdrop-card, which introduced this for the Login/Setup hero
   cards) - every .card now carries the same thin cyan bracket treatment,
   the reference instrument-panel stylesheet's universal .panel::before/
   ::after. Purely decorative (pointer-events:none), so it never interferes
   with a card's own content or click targets. */
.card::before,
.card::after {
  content: '';
  position: absolute;
  width: 14px;
  height: 14px;
  pointer-events: none;
  opacity: 0.55;
}

.card::before {
  top: -1px;
  left: -1px;
  border-top: 2px solid var(--accent-cyan);
  border-left: 2px solid var(--accent-cyan);
}

.card::after {
  bottom: -1px;
  right: -1px;
  border-bottom: 2px solid var(--accent-cyan);
  border-right: 2px solid var(--accent-cyan);
}

/* Inputs */
.input {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background-color: var(--background);
  color: var(--text-primary);
  font-size: 0.875rem;
  transition: all 0.2s ease;
}

.input:focus {
  outline: none;
  border-color: var(--accent-cyan);
  background-color: var(--background-elevated);
  box-shadow: 0 0 0 3px rgba(47, 143, 255, 0.1), 0 0 12px rgba(0, 229, 255, 0.25);
}

.input:hover:not(:focus) {
  border-color: var(--border-light);
}

.label {
  display: block;
  margin-bottom: 0.5rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
}

/* Tab Buttons */
.tab-buttons {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}

.tab-button {
  padding: 0.5rem 1rem;
  background-color: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 0.8125rem;
  font-weight: 500;
  transition: all 0.2s ease;
}

.tab-button:hover {
  background-color: var(--surface-hover);
  color: var(--text-primary);
  border-color: var(--accent-cyan);
  box-shadow: 0 0 8px rgba(0, 229, 255, 0.25);
}

.tab-button.active {
  background: var(--primary-color);
  color: #ffffff;
  border-color: transparent;
  box-shadow: 0 2px 8px rgba(47, 143, 255, 0.25);
}

/* Grid Layouts */
.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1.5rem;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.5rem;
}

.grid-4 {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 1.5rem;
}

/* Playlist Card */
.playlist-card {
  background: var(--gradient-card);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  border: 1px solid var(--border);
  box-shadow: var(--card-shadow);
  transition: all 0.25s ease;
  cursor: pointer;
}

.playlist-card:hover {
  box-shadow: var(--card-shadow-hover);
  border-color: var(--border-light);
}

.playlist-card-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
}

.playlist-card-description {
  font-size: 0.875rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

/* Mix Card Hover Effect */
.mix-card:hover:not([style*="opacity: 0.5"]) {
  border-color: var(--primary-color) !important;
  box-shadow: var(--glow-sm);
}

/* Page Layout
   Every page's own CSS used to hand-roll this padding itself (each one
   independently re-discovering that .page-container had none, at
   inconsistent values - 0.875rem here, 1.5rem there) since .page-container
   is a flex item of .layout-main (a flex column) and defaults to
   min-width:auto, refusing to shrink below its widest child's min-content
   (a data table) rather than scrolling within itself - the editor page's
   640px-wide tracks table forced the whole page 800px+ wide on a 390px
   phone. One definition here fixes both at once for every page carrying
   this class. */
.page-container {
  flex: 1;
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: 0;
  margin: 0 auto;
  width: 100%;
}

/* Padding only on phone-width screens (small, not the page/generic
   .page-container spacing this used to carry at every width) - desktop
   stays flush at 0 per user feedback. */
@media (max-width: 768px) {
  .page-container { padding: 0.5rem; }
}

.page-container > h1 {
  margin-top: 0;
  margin-bottom: 0.75rem;
}

.page-header { margin-bottom: 0.75rem; }

.page-title {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
}

.page-description {
  font-size: 0.9375rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

/* Section */
.section { margin-bottom: 2rem; }

.section-title {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 1rem;
}

/* Every page styles its own checkboxes (Settings' toggles, Home's row
   selects) individually, but plain unstyled ones - Backup & Restore's
   playlist picker - fell back to the browser's raw white checkbox with no
   theming at all. One rule here covers every checkbox the app doesn't
   already style more specifically (accent-color doesn't touch size, so it
   can't fight Home's deliberately touch-sized .row-select). */
input[type="checkbox"] { accent-color: var(--primary-color); }
input[type="checkbox"]:checked { box-shadow: 0 0 6px rgba(0, 229, 255, 0.5); }

/* Form Groups */
.form-group { margin-bottom: 1.5rem; }

.form-label {
  display: block;
  margin-bottom: 0.5rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-primary);
}

.form-hint {
  display: block;
  margin-top: 0.375rem;
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

/* Select Dropdown */
select {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background-color: var(--surface);
  color: var(--text-primary);
  font-size: 0.875rem;
  transition: all 0.2s ease;
  cursor: pointer;
}

select:focus {
  outline: none;
  border-color: var(--accent-cyan);
  box-shadow: 0 0 0 3px rgba(47, 143, 255, 0.1), 0 0 12px rgba(0, 229, 255, 0.25);
}

/* Most of the app's actual text fields carry a per-page/component class
   (.form-input, .settings-input, .search-input, ...) rather than the bare
   element or the .input class above, each with its own :focus rule that
   only ever sets border-color - never box-shadow. A bare-element rule here
   reaches every one of them for the glow specifically (box-shadow, not
   border-color, so nothing above gets overridden) without editing the
   dozen-plus component stylesheets that define those classes. */
input:focus,
textarea:focus {
  box-shadow: 0 0 10px rgba(0, 229, 255, 0.25);
}

select option {
  background-color: var(--surface);
  color: var(--text-primary);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 500;
}

.badge-primary { background-color: rgba(47, 143, 255, 0.15); color: var(--primary-color); }
.badge-success { background-color: rgba(102, 187, 106, 0.15); color: var(--success); }
.badge-warning { background-color: rgba(255, 167, 38, 0.15); color: var(--warning); }
.badge-error { background-color: rgba(239, 83, 80, 0.15); color: var(--error); }

/* Status Dot (DESIGN.md §8.3) - the canonical status primitive: a solid
   dot colored by state, with a pulsing animation reserved for "in
   progress" states. Reuse this anywhere status is currently shown as a
   badge alone (e.g. connected/disconnected). */
.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--text-muted);
  display: inline-block;
}

.status-dot-success { background: var(--success); }
.status-dot-failed { background: var(--error); }
.status-dot-running { background: var(--primary-color); animation: status-pulse 1.2s ease-in-out infinite; }
.status-dot-never { background: var(--text-muted); }

@keyframes status-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* Loading Spinner */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--primary-color);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--text-secondary);
}

.empty-state-icon { font-size: 3rem; margin-bottom: 1rem; opacity: 0.5; }
.empty-state-title { font-size: 1.125rem; font-weight: 600; color: var(--text-primary); margin-bottom: 0.5rem; }
.empty-state-description { font-size: 0.9375rem; color: var(--text-secondary); margin-bottom: 1.5rem; }

/* Divider */
.divider { height: 1px; background-color: var(--border); margin: 1.5rem 0; }

/* Flex Utilities */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }
.gap-3 { gap: 1.5rem; }

/* Spacing Utilities */
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mt-4 { margin-top: 2rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.mb-4 { margin-bottom: 2rem; }
.p-1 { padding: 0.5rem; }
.p-2 { padding: 1rem; }
.p-3 { padding: 1.5rem; }
.p-4 { padding: 2rem; }

/* Mobile responsive */
@media (max-width: 768px) {
  :root { --header-height: 56px; }
  body { font-size: 16px; }
  .btn { padding: 0.625rem 1rem; font-size: 0.875rem; min-height: 44px; }
  .btn-small { padding: 0.5rem 0.75rem; font-size: 0.8125rem; min-height: 36px; }
  /* `input`, not `.input` - nothing but a couple of fields actually use that
     class, so this was silently missing every `.form-input`/`.settings-input`/
     `.search-input`/etc field in the app (there are many, each defined in its
     own component's CSS). font-size needs !important because each of those
     classes sets its own smaller size with higher specificity than a bare
     element selector - and iOS Safari auto-zooms the whole page on focusing
     any field under 16px, so this one property has to win unconditionally. */
  input, select, textarea { font-size: 16px !important; min-height: 44px; padding: 0.625rem 0.75rem; }
  .card { padding: 1rem; border-radius: var(--radius-md); }
  .container { padding: 0 0.75rem; }
  h1 { font-size: 1.5rem; }
  h2 { font-size: 1.25rem; }
  h3 { font-size: 1.125rem; }
  a, button { min-height: 44px; display: inline-flex; align-items: center; }
  html { -webkit-text-size-adjust: 100%; }
}

.grid-split { display: grid; gap: 1.5rem; }
@media (min-width: 769px) { .grid-split-1-2 { grid-template-columns: 1fr 2fr; } }
@media (max-width: 768px) { .grid-split { grid-template-columns: 1fr; } }

.table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.mobile-only { display: none; }
.desktop-only { display: block; }

/* Wide tables/tab bars scroll horizontally on narrow screens (each page
   sets its own overflow-x: auto on these shared marker classes - see
   CollectionsPage.css's comment on .data-table-container - no shared rule
   owns that property), but real mobile browsers (iOS Safari, Android
   Chrome) render that scroll with an invisible-until-touched overlay
   scrollbar - unlike desktop Chrome/Firefox, they ignore
   ::-webkit-scrollbar styling entirely - so a table wider than the screen
   just looks like its rightmost columns are permanently clipped, with
   nothing suggesting there's more to see. A mask-image fade on whichever
   edge still has hidden content (layout.html's shared script toggles
   .has-scroll-left/-right based on scroll position) fixes that
   everywhere: unlike a pseudo-element overlay, a mask is calculated
   against the element's own visible box on every frame, so it stays
   pinned to the edge with no sticky/flex layout tricks needed. */
.data-table-container.has-scroll-right,
.admin-tabbar.has-scroll-right {
  -webkit-mask-image: linear-gradient(to right, black calc(100% - 24px), transparent);
  mask-image: linear-gradient(to right, black calc(100% - 24px), transparent);
}
.data-table-container.has-scroll-left,
.admin-tabbar.has-scroll-left {
  -webkit-mask-image: linear-gradient(to left, black calc(100% - 24px), transparent);
  mask-image: linear-gradient(to left, black calc(100% - 24px), transparent);
}
.data-table-container.has-scroll-left.has-scroll-right,
.admin-tabbar.has-scroll-left.has-scroll-right {
  -webkit-mask-image: linear-gradient(to right, transparent, black 24px, black calc(100% - 24px), transparent);
  mask-image: linear-gradient(to right, transparent, black 24px, black calc(100% - 24px), transparent);
}

/* Generic show/hide toggle - server-rendered as the initial state (a
   template conditionally adding/omitting this class) and/or toggled by JS
   in response to user input (classList.toggle), instead of either side
   writing a raw style="display:none" inline. */
.is-hidden { display: none; }

/* Recolors a button/link's text as the error color without changing its
   shape (border, background, hover) - for a "this is destructive" cue on
   an otherwise plain btn-secondary, smaller than committing to a full
   btn-danger treatment. */
.text-error { color: var(--error); }

@media (max-width: 768px) {
  .mobile-only { display: block; }
  .desktop-only { display: none; }
  .flex-wrap-mobile { flex-wrap: wrap; }
  .full-width-mobile { width: 100% !important; }
  .hide-mobile { display: none !important; }
  .gap-mobile-sm { gap: 0.5rem !important; }
}

@media (min-width: 769px) and (max-width: 1024px) { .container { max-width: 960px; } }
@media (min-width: 1441px) { .container { max-width: 1400px; } }
@media (hover: none) and (pointer: coarse) { .btn { min-height: 48px; } .input, select, textarea { min-height: 48px; } }
