/* Fossegrim UI. Generated from the Fossegrim design system (tokens.json + components/bundle.css).
   Change values in :root; components only reference tokens.
   Themes: :root holds the light (default) theme. A theme redefines color tokens only, under
   :root[data-theme="..."]; js/theme.js sets data-theme from the saved choice or the OS preference. */

:root {
    color-scheme: light;
    /* Color */
    --brand-indigo: #667eea;
    --brand-violet: #764ba2;
    --brand-violet-hover: #643f8b;
    --on-brand: #ffffff;
    --ink: #212529;
    --ink-soft: #333333;
    --text-secondary: #495057;
    --text-muted: #6c757d;
    --text-subtle: #666666;
    --text-faint: #adb5bd;
    --canvas: #eceef2;
    --surface: #ffffff;
    --surface-muted: #f8f9fa;
    --border: #e9ecef;
    --border-strong: #dee2e6;
    --border-list: #f0f0f0;
    --border-compact: #dddddd;
    --divider-soft: #eeeeee;
    --secondary: #6c757d;
    --secondary-hover: #5a6268;
    --danger: #dc3545;
    --danger-hover: #c82333;
    --danger-strong: #a71d2a;
    --success-bg: #d4edda;
    --success-fg: #155724;
    --success-border: #c3e6cb;
    --error-bg: #f8d7da;
    --error-fg: #721c24;
    --error-border: #f5c6cb;
    --info-bg: #e7f3ff;
    --info-fg: #004085;
    --selection-bg: #eef2ff;
    --selection-fg: #3949ab;
    --player-error: #ff8787;
    --overlay: rgba(0, 0, 0, 0.5);
    --chip: rgba(255, 255, 255, 0.15);
    --chip-hover: rgba(255, 255, 255, 0.25);
    --notice-bg: #ffffe0;
    /* Color roles that diverge between themes: the topbar and player bar ("chrome") stay dark in
       every theme, and accent/danger used as text need lighter values than as fills on dark surfaces. */
    --chrome-bg: #212529;
    --chrome-fg: #ffffff;
    --chrome-muted: #adb5bd;
    --accent-fg: #764ba2;
    --accent-fg-hover: #643f8b;
    --danger-fg: #dc3545;
    --warning-fg: #9a6b00;
    /* Gradient */
    --gradient-brand: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    /* Type */
    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: "Courier New", monospace;
    /* Spacing */
    --space-2: 2px;
    --space-4: 4px;
    --space-6: 6px;
    --space-8: 8px;
    --space-12: 12px;
    --space-16: 16px;
    --space-24: 24px;
    /* Radius */
    --radius-sm: 2px;
    --radius-md: 4px;
    --radius-lg: 6px;
    --radius-round: 50%;
    /* Shadow */
    --shadow-menu: 0 4px 12px rgba(0, 0, 0, 0.12);
    --shadow-modal: 0 12px 32px rgba(0, 0, 0, 0.2);
    --shadow-focus: 0 0 0 2px var(--brand-indigo);
    --shadow-drop-target: inset 0 2px 0 var(--brand-indigo);
}

/* Dark theme: color tokens only. Every text/background pair meets WCAG AA (4.5:1; 3:1 for
   borders and focus rings). --brand-violet and --danger stay as fills behind white text. */
:root[data-theme="dark"] {
    color-scheme: dark;
    --brand-indigo: #8b9cf4;
    --ink: #e9ecef;
    --ink-soft: #dee2e6;
    --text-secondary: #c3c9d0;
    --text-muted: #9ea6af;
    --text-subtle: #9ea6af;
    --text-faint: #959da6;
    --canvas: #121418;
    --surface: #1b1e23;
    --surface-muted: #23272d;
    --border: #2f343b;
    --border-strong: #6c7480;
    --border-list: #2a2e34;
    --border-compact: #6c7480;
    --divider-soft: #2a2e34;
    --secondary: #6c757d;
    --secondary-hover: #5a6268;
    --success-bg: #15301d;
    --success-fg: #9be3ad;
    --success-border: #3f8a54;
    --error-bg: #3b1a1e;
    --error-fg: #ffadb5;
    --error-border: #b8505a;
    --info-bg: #142a44;
    --info-fg: #a8cdff;
    --selection-bg: #2b3058;
    --selection-fg: #c9d0ff;
    --overlay: rgba(0, 0, 0, 0.65);
    --notice-bg: #3a3714;
    --chrome-bg: #0d0f12;
    --accent-fg: #c4a7ec;
    --accent-fg-hover: #d8c4f4;
    --danger-fg: #ff8a95;
    --warning-fg: #f0c050;
    --shadow-menu: 0 4px 12px rgba(0, 0, 0, 0.5);
    --shadow-modal: 0 12px 32px rgba(0, 0, 0, 0.6);
}

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

body {
    font-family: var(--font-sans);
    font-size: 0.875rem;
    line-height: 20px;
    color: var(--ink);
    background: var(--canvas);
}

:focus-visible { outline: 2px solid var(--brand-indigo); outline-offset: 1px; }

/* ---- App shell: ink topbar, canvas workspace, ink player bar ---- */
.app-shell { min-height: 100vh; display: flex; flex-direction: column; background: var(--canvas); }
.app-content { flex: 1; padding: var(--space-8); display: flex; flex-direction: column; gap: var(--space-8); }

.topbar {
    background: var(--chrome-bg);
    color: var(--chrome-fg);
    height: 40px;
    padding: 0 var(--space-12);
    display: flex;
    align-items: center;
    gap: var(--space-16);
}
.topbar-title { font-size: 0.875rem; font-weight: 700; letter-spacing: 0.01em; white-space: nowrap; }
.topbar-nav { display: flex; gap: var(--space-2); flex: 1; }
.topbar-nav a {
    color: var(--chrome-fg);
    text-decoration: none;
    white-space: nowrap;
    font-size: 0.8125rem;
    padding: var(--space-4) var(--space-8);
    border-radius: var(--radius-md);
    opacity: 0.75;
}
.topbar-nav a:hover { opacity: 1; background: var(--chip); }
.topbar-nav a.active { opacity: 1; background: var(--chip-hover); }

.topbar-stats {
    display: flex;
    gap: var(--space-12);
    font-size: 0.75rem;
    color: var(--chrome-muted);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}
.topbar-stats strong { color: var(--chrome-fg); font-weight: 600; }
/* Library search, in the top bar on every page */
.topbar-search { width: 220px; min-width: 0; }
.topbar-search input {
    width: 100%;
    height: 26px;
    padding: 0 var(--space-8);
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    background: var(--chip);
    color: var(--chrome-fg);
    font: inherit;
    font-size: 0.8125rem;
}
.topbar-search input::placeholder { color: var(--chrome-muted); }
.topbar-search input:focus { outline: none; border-color: var(--brand-indigo); box-shadow: var(--shadow-focus); }

/* The library stats are the first thing to go as the bar narrows. */
@media (max-width: 1100px) {
    .topbar-stats { display: none; }
}

/* Phones and narrow tablets: two rows. The title, pages and account menu
   share the first; the library search gets the whole second row. */
@media (max-width: 760px) {
    .topbar {
        height: auto;
        flex-wrap: wrap;
        row-gap: var(--space-6);
        column-gap: var(--space-8);
        padding: var(--space-6) var(--space-12) var(--space-8);
    }
    .topbar-nav { min-width: 0; overflow-x: auto; scrollbar-width: none; }
    .topbar-nav::-webkit-scrollbar { display: none; }
    .topbar-nav a { padding: var(--space-4) var(--space-6); }
    .topbar-search { order: 1; flex: 1 0 100%; width: auto; }
    .topbar-search input { height: 32px; font-size: 1rem; } /* 16px stops iOS zooming in on focus */
    .user-menu-toggle { max-width: 10rem; overflow: hidden; text-overflow: ellipsis; }
}

/* Phones: the account button shrinks to an icon, and on the smallest
   screens the title to its note. Both names stay readable to screen readers. */
@media (max-width: 480px) {
    .user-menu-toggle .user-menu-icon { display: inline; }
    .user-menu-toggle .user-menu-name { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
}
@media (max-width: 360px) {
    .topbar-title-text { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
}

.user-menu { position: relative; }
.user-menu-icon { display: none; }
.user-menu-toggle {
    white-space: nowrap;
    background: var(--chip);
    color: var(--chrome-fg);
    border: none;
    padding: var(--space-4) var(--space-8);
    border-radius: var(--radius-md);
    cursor: pointer;
    font: inherit;
    font-size: 0.8125rem;
}
.user-menu-toggle:hover { background: var(--chip-hover); }
.user-menu-dropdown {
    position: absolute;
    right: 0;
    top: calc(100% + var(--space-4));
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-menu);
    min-width: 180px;
    padding: var(--space-4);
    z-index: 100;
}
.user-menu-dropdown a,
.user-menu-dropdown button {
    display: block;
    width: 100%;
    text-align: left;
    padding: var(--space-4) var(--space-8);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    text-decoration: none;
    background: none;
    border: none;
    font: inherit;
    cursor: pointer;
}
.user-menu-dropdown a:hover,
.user-menu-dropdown button:hover { background: var(--surface-muted); color: var(--ink); }
.user-menu-theme { margin-top: var(--space-4); padding: var(--space-4) var(--space-8); border-top: 1px solid var(--border); }
.user-menu-theme-label { display: block; font-size: 0.6875rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-muted); margin-bottom: var(--space-4); }
.theme-switch { display: flex; border: 1px solid var(--border-strong); border-radius: var(--radius-md); overflow: hidden; }
.user-menu-dropdown .theme-switch button { flex: 1; width: auto; text-align: center; padding: var(--space-2) var(--space-4); border-radius: 0; font-size: 0.75rem; }
.user-menu-dropdown .theme-switch button + button { border-left: 1px solid var(--border-strong); }
.user-menu-dropdown .theme-switch button.active { background: var(--selection-bg); color: var(--selection-fg); font-weight: 600; }
.user-menu-theme-custom { display: block; margin-top: var(--space-4); font-size: 0.75rem; color: var(--text-muted); }
.user-menu-dropdown .user-menu-theme-more { padding: var(--space-4) 0 0; font-size: 0.75rem; color: var(--accent-fg); }
.user-menu-dropdown .user-menu-theme-more:hover { background: none; color: var(--accent-fg-hover); text-decoration: underline; }
.user-menu-logout { margin-top: var(--space-4); border-top: 1px solid var(--border) !important; border-radius: 0 0 var(--radius-md) var(--radius-md) !important; color: var(--danger-fg) !important; }

.player-bar {
    background: var(--chrome-bg);
    color: var(--chrome-fg);
    min-height: 52px;
    padding: var(--space-6) var(--space-16);
    display: flex;
    align-items: center;
    gap: var(--space-16);
    flex-wrap: wrap;
    position: sticky;
    bottom: 0;
    z-index: 500;
}
.player-track-info { display: flex; flex-direction: column; min-width: 160px; }
.player-title { font-weight: 600; }
.player-artist { font-size: 0.75rem; line-height: 16px; color: var(--chrome-muted); }
/* Play/seek/volume, built by playerControls.js in each place the player shows. */
.player-transport { flex: 1; min-width: 240px; display: flex; }
.player-transport[hidden] { display: none; }
.transport { flex: 1; min-width: 0; display: flex; align-items: center; gap: var(--space-6); }
.transport-time { min-width: 4ch; font-size: 0.75rem; color: var(--chrome-muted); font-variant-numeric: tabular-nums; text-align: center; }
.transport input[type="range"] { margin: 0; padding: 0; width: auto; border: none; background: none; accent-color: var(--chrome-fg); cursor: pointer; }
.transport input[type="range"]:disabled { opacity: 0.4; cursor: default; }
.transport-seek { flex: 1; min-width: 60px; }
.transport-volume { flex: 0 1 88px; min-width: 48px; }
.player-error { color: var(--player-error); }
.player-controls { display: flex; gap: var(--space-4); }
.player-button {
    background: var(--chip);
    color: var(--chrome-fg);
    border: none;
    border-radius: var(--radius-md);
    min-width: 32px;
    height: 32px;
    padding: 0 var(--space-8);
    font: inherit;
    cursor: pointer;
    white-space: nowrap;
}
.player-button:hover:not(:disabled), .player-button.active { background: var(--chip-hover); }
.player-button:disabled { opacity: 0.4; cursor: default; }

/* ---- Player panel: the player as a Library module (hides the bar) ---- */
.layout-module > .player-panel-module { height: 100%; }
.player-panel-module {
    background: var(--chrome-bg);
    color: var(--chrome-fg);
    border-radius: var(--radius-lg);
    overflow: hidden;
    container-type: size;
}
/* Wide: a square cover on the left, as tall as the panel allows. Narrow or
   tall: the cover on top, above the controls (about 150px of them). */
.player-panel { height: 100%; display: flex; align-items: center; gap: var(--space-16); padding: var(--space-12); box-sizing: border-box; }
.player-panel .player-panel-cover { --cover-side: max(48px, min(calc(100cqh - 24px), 45cqw)); flex: 0 0 auto; width: var(--cover-side); height: var(--cover-side); border-radius: var(--radius-md); }
.player-panel-cover .album-art-placeholder { font-size: 3rem; }
.player-panel-main { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; gap: var(--space-8); }
.player-panel .player-track-info { min-width: 0; }
.player-panel .player-title { font-size: 1.125rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-panel .player-artist { font-size: 0.8125rem; line-height: 18px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-panel .player-transport { flex: 0 0 auto; min-width: 0; }
/* A narrow panel puts mute and volume on a second line rather than cutting them off. */
.player-panel .transport { flex-wrap: wrap; row-gap: var(--space-4); }
.player-panel .transport-seek { flex: 1 1 80px; }
.player-panel-extras { display: flex; gap: var(--space-4); }
@container (max-aspect-ratio: 5/4) {
    .player-panel { flex-direction: column; justify-content: center; gap: var(--space-8); }
    .player-panel .player-panel-cover { --cover-side: max(48px, min(calc(100cqw - 24px), calc(100cqh - 180px))); }
    .player-panel-main { flex: 0 0 auto; width: 100%; }
}
.player-panel-idle { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--space-8); padding: var(--space-12); color: var(--chrome-muted); font-size: 0.8125rem; text-align: center; }
.player-panel-idle-icon { font-size: 2rem; }

/* ---- Up next: the queue, opened from the player bar ---- */
.up-next-panel {
    position: fixed;
    right: var(--space-16);
    bottom: 60px;
    width: min(380px, calc(100vw - 2 * var(--space-16)));
    max-height: min(60vh, 520px);
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-modal);
    z-index: 600;
    overflow: hidden;
}
.transitions-panel-body { padding: var(--space-8) var(--space-12); overflow-y: auto; color: var(--ink); }
.crossfade-length { display: flex; align-items: center; gap: var(--space-8); margin: var(--space-8) 0; font-size: 0.8125rem; color: var(--text-secondary); }
.crossfade-length input[type="range"] { flex: 1; min-width: 0; width: auto; margin: 0; padding: 0; }
.crossfade-length output { min-width: 3ch; text-align: right; font-variant-numeric: tabular-nums; }
/* Player bar at the top (Appearance setting): it sticks under the top bar, and the
   Up next panel and toasts drop down from it instead of rising above it. */
.player-top .player-bar { top: 0; bottom: auto; }
.player-top .up-next-panel { top: 104px; bottom: auto; }
.player-top .toasts { top: 112px; bottom: auto; }
.up-next-header { display: flex; justify-content: space-between; align-items: center; padding: var(--space-6) var(--space-12); background: var(--chrome-bg); color: var(--chrome-fg); font-weight: 600; }
.up-next-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; }
.up-next-list li { display: flex; align-items: center; gap: var(--space-8); padding-right: var(--space-8); border-bottom: 1px solid var(--border); }
.up-next-list li.current { background: var(--selection-bg); box-shadow: inset 2px 0 0 var(--brand-indigo); }
.up-next-list li.played .up-next-track { opacity: 0.55; }
.up-next-track { flex: 1; min-width: 0; display: flex; align-items: center; gap: var(--space-8); padding: var(--space-6) var(--space-12); background: none; border: none; font: inherit; text-align: left; cursor: pointer; color: var(--ink); }
.up-next-track:hover:not(:disabled) { background: var(--surface-muted); }
.up-next-track:disabled { cursor: default; }
.up-next-text { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; }
.up-next-title, .up-next-artist { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up-next-title { font-weight: 600; }
.up-next-artist { font-size: 0.75rem; color: var(--text-muted); }
.up-next-now { font-size: 0.6875rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--selection-fg); white-space: nowrap; }
.up-next-remove { background: none; border: none; color: var(--text-muted); cursor: pointer; padding: var(--space-4); border-radius: var(--radius-md); }
.up-next-remove:hover { color: var(--danger-fg); background: var(--surface-muted); }

/* ---- Toasts ---- */
.toasts { position: fixed; left: 50%; bottom: 72px; transform: translateX(-50%); display: flex; flex-direction: column; gap: var(--space-6); align-items: center; z-index: 700; pointer-events: none; }
.toast { background: var(--chrome-bg); color: var(--chrome-fg); border: 1px solid var(--border); padding: var(--space-8) var(--space-16); border-radius: var(--radius-md); font-size: 0.8125rem; box-shadow: var(--shadow-menu); max-width: calc(100vw - 2 * var(--space-16)); }

/* ---- Visualizer module: MilkDrop presets rendered with WebGL by js/visualizer.js ---- */
.visualizer-module {
    display: flex;
    flex-direction: column;
    align-self: stretch;
    min-height: 280px;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    overflow: hidden;
    min-width: 0;
}
.visualizer-header {
    min-height: 36px;
    padding: var(--space-4) var(--space-12);
    display: flex;
    align-items: center;
    gap: var(--space-4);
    background: var(--surface-muted);
    border-bottom: 1px solid var(--border);
}
.visualizer-header h2 { font-size: 0.875rem; font-weight: 600; color: var(--ink); margin: 0 auto 0 0; }
.visualizer-header .button-secondary[aria-pressed="true"] { background: var(--selection-bg); color: var(--selection-fg); border-color: var(--selection-fg); }
/* Black in every theme: the presets are drawn for a dark backdrop (and --ink turns light in dark themes). */
.visualizer-stage { position: relative; flex: 1; min-height: 0; background: #000; }
.visualizer-canvas { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }
.visualizer-message {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-12);
    padding: var(--space-16);
    color: var(--text-faint);
    text-align: center;
    font-size: 0.8125rem;
}
.visualizer-message p { max-width: 36ch; }
.visualizer-footer {
    min-height: 36px;
    padding: var(--space-4) var(--space-12);
    display: flex;
    align-items: center;
    border-top: 1px solid var(--border);
}
.visualizer-preset { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.75rem; color: var(--text-muted); }

/* Fullscreen: the stage fills the screen and the bars float over it, hiding when idle. */
.visualizer-module.is-fullscreen { border: none; border-radius: 0; background: #000; }
.visualizer-module.is-fullscreen .visualizer-stage { position: fixed; inset: 0; }
.visualizer-module.is-fullscreen .visualizer-header,
.visualizer-module.is-fullscreen .visualizer-footer {
    position: fixed;
    left: 0;
    right: 0;
    z-index: 1;
    background: var(--overlay);
    border: none;
    transition: opacity 0.2s;
}
.visualizer-module.is-fullscreen .visualizer-header { top: 0; }
.visualizer-module.is-fullscreen .visualizer-footer { bottom: 0; }
.visualizer-module.is-fullscreen .visualizer-header h2 { color: var(--on-brand); }
.visualizer-module.is-fullscreen .visualizer-preset { color: var(--text-faint); }
.visualizer-module.is-fullscreen.is-idle { cursor: none; }
.visualizer-module.is-fullscreen.is-idle .visualizer-header,
.visualizer-module.is-fullscreen.is-idle .visualizer-footer { opacity: 0; }
.visualizer-module.is-fullscreen .visualizer-header:focus-within { opacity: 1; }
@media (prefers-reduced-motion: reduce) {
    .visualizer-module.is-fullscreen .visualizer-header,
    .visualizer-module.is-fullscreen .visualizer-footer { transition: none; }
}

.app-footer { text-align: right; padding: var(--space-4) var(--space-8); font-size: 0.75rem; color: var(--text-muted); }
.app-footer .update-badge { margin-right: var(--space-8); padding: var(--space-2) var(--space-6); border-radius: var(--radius-md); background: var(--info-bg); color: var(--info-fg); text-decoration: none; font-weight: 600; }
.app-footer .update-badge:hover { text-decoration: underline; }
.app-footer .https-badge { background: var(--error-bg); color: var(--danger-fg); }
.https-staging { color: var(--warning-fg); }

/* ---- Setup wizard: a wider card on the sign-in canvas ---- */
.container.setup-wizard { max-width: 760px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); }
.setup-steps { display: flex; flex-wrap: wrap; gap: var(--space-4) var(--space-12); list-style: none; counter-reset: setup-step; padding: 0 var(--space-16) var(--space-12); margin: 0; border-bottom: 1px solid var(--border); }
.setup-steps li { counter-increment: setup-step; font-size: 0.75rem; color: var(--text-muted); }
.setup-steps li::before { content: counter(setup-step) ". "; }
.setup-steps li.done { color: var(--text-secondary); }
.setup-steps li.current { color: var(--ink); font-weight: 600; }
.setup-wizard .content { padding-top: var(--space-12); }
.setup-title { font-size: 1rem; font-weight: 600; color: var(--ink); margin-bottom: var(--space-6); }
.setup-nav { display: flex; align-items: center; justify-content: flex-end; gap: var(--space-8); margin-top: var(--space-16); padding-top: var(--space-12); border-top: 1px solid var(--border); }
.setup-nav .button-secondary:first-child { margin-right: auto; }
.setup-skip-all { font-size: 0.8125rem; color: var(--text-muted); }
.setup-summary { list-style: none; padding: 0; margin: 0 0 var(--space-12); }
.setup-summary li { padding: var(--space-4) 0; font-size: 0.8125rem; color: var(--text-secondary); }
.setup-summary li span { display: inline-block; width: 1.25em; color: var(--text-muted); }
.setup-summary li.ok span { color: var(--success-fg); }
a.button, a.button-secondary { text-decoration: none; }

/* ---- Library scans ---- */
.scan-actions { display: flex; gap: var(--space-8); flex-wrap: wrap; margin-bottom: var(--space-8); }
.scan-progress { margin: var(--space-8) 0; }
.scan-progress-label { display: flex; justify-content: space-between; gap: var(--space-8); font-size: 0.8125rem; color: var(--text-secondary); margin-bottom: var(--space-4); }
.scan-progress-track { height: 6px; border-radius: 3px; background: var(--surface-muted); border: 1px solid var(--border); overflow: hidden; }
.scan-progress-fill { height: 100%; background: var(--brand-violet); transition: width 0.3s; }
.scan-progress-fill.indeterminate { opacity: 0.4; animation: scan-pulse 1.2s ease-in-out infinite; }
@keyframes scan-pulse { 50% { opacity: 0.8; } }
@media (prefers-reduced-motion: reduce) { .scan-progress-fill { transition: none; } .scan-progress-fill.indeterminate { animation: none; } }
.scan-queued { font-size: 0.75rem; color: var(--text-muted); margin-bottom: var(--space-4); }
.scan-result { margin-top: var(--space-8); }
.scan-result details { margin-top: var(--space-4); }
.scan-result ul { margin: var(--space-4) 0 0 var(--space-16); }
.scan-indicator { font-size: 0.75rem; font-weight: 600; color: var(--brand-violet); text-decoration: none; white-space: nowrap; }
.scan-indicator:hover { text-decoration: underline; }

/* ---- Renaming and library health ---- */
.rename-table td { vertical-align: top; }
.rename-sub { font-size: 0.75rem; color: var(--text-muted); }
.rename-problem td { background: var(--surface-muted); }
.health-tabs { display: flex; gap: var(--space-4); margin-bottom: var(--space-12); border-bottom: 1px solid var(--border); }
.health-tabs button { background: none; border: none; border-bottom: 2px solid transparent; padding: var(--space-6) var(--space-8); font: inherit; font-size: 0.8125rem; color: var(--text-secondary); cursor: pointer; }
.health-tabs button.active { color: var(--ink); border-bottom-color: var(--brand-violet); font-weight: 600; }
.health-count { display: inline-block; min-width: 1.5em; padding: 0 var(--space-4); border-radius: var(--radius-md); background: var(--surface-muted); font-size: 0.75rem; text-align: center; }
.checkbox-cell { width: 32px; }
.api-key-secret code { display: block; margin: var(--space-4) 0; word-break: break-all; }
.api-key-secret pre { margin: 0; white-space: pre-wrap; word-break: break-all; font-size: 0.75rem; }
.api-key-new { margin-top: var(--space-8); }

/* ---- Modules: the unit of layout ---- */
.module-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr));
    gap: var(--space-8);
    align-items: start;
}
.module-span { grid-column: 1 / -1; }

.container,
.artist-list-component,
.album-list-component,
.track-list-component {
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    overflow: hidden;
    min-width: 0;
}
.container { width: 100%; }
.container.narrow { max-width: 360px; margin: 0 auto; }
.container.medium { max-width: 640px; }

/* Module header: title left, tools right, one 36px row */
.header,
.artist-list-header,
.album-list-header {
    min-height: 36px;
    padding: var(--space-4) var(--space-12);
    display: flex;
    align-items: center;
    gap: var(--space-8);
    flex-wrap: wrap;
    background: var(--surface-muted);
    border-bottom: 1px solid var(--border);
}
.header h1,
.artist-list-header h2,
.album-list-header h2 { font-size: 0.875rem; font-weight: 600; color: var(--ink); margin: 0; }
.header p { font-size: 0.8125rem; color: var(--text-muted); }
.header.error { background: var(--error-bg); }
.header.error h1 { color: var(--error-fg); }

.artist-list-header .search-box,
.album-list-header .search-box { flex: 1; min-width: 120px; max-width: 220px; margin-left: auto; }

/* Search, sort and direction above a library list (BrowseControls) */
.browse-controls { flex: 1; display: flex; gap: var(--space-6); align-items: center; flex-wrap: wrap; justify-content: flex-end; min-width: 0; }
.browse-controls .filter-group select { width: auto; max-width: 160px; }
.browse-order { min-width: 28px; height: 28px; padding: 0 var(--space-6); }
.track-list-component .controls h2 { font-size: 0.875rem; font-weight: 600; color: var(--ink); margin: 0; }

/* Search results page: artists and albums side by side, tracks below */
.search-results { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-12); padding: var(--space-12) 0; }
.search-results-column,
.search-results-tracks { min-width: 0; border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; background: var(--surface); }
.search-results-tracks { grid-column: 1 / -1; }
@media (max-width: 720px) {
    .search-results { grid-template-columns: 1fr; }
}

.content { padding: var(--space-12); }
.content.centered { text-align: center; }
.content p { color: var(--text-secondary); margin-bottom: var(--space-8); }

/* Sign-in: a single card on the canvas */
.login-page { min-height: 100vh; display: flex; flex-direction: column; background: var(--canvas); }
.login-shell { flex: 1; display: flex; align-items: center; justify-content: center; padding: var(--space-16); }
.login-shell .header { flex-direction: column; align-items: flex-start; gap: var(--space-2); padding: var(--space-16) var(--space-16) var(--space-12); background: var(--surface); border-bottom: none; }
.login-shell .header h1 { font-size: 1.5rem; line-height: 1.2; font-weight: 700; }
.login-shell .content { padding: 0 var(--space-16) var(--space-16); }

/* ---- Forms ---- */
.form-group { margin-bottom: var(--space-12); }
.form-group label { display: block; font-size: 0.8125rem; font-weight: 600; color: var(--text-secondary); margin-bottom: var(--space-4); }
.form-group input[type="text"],
.form-group input:not([type]),
.form-group input[type="email"],
.form-group input[type="password"],
.form-group input[type="number"],
.form-group input[type="tel"],
.form-group input[type="time"],
.form-group select,
.form-group textarea,
.search-box input,
.filter-group select,
.new-playlist-box input[type="text"],
.share-add input,
.share-add select,
.tag-edit-table input,
.album-art-search-form input {
    width: 100%;
    height: 28px;
    padding: 0 var(--space-8);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    background: var(--surface);
    color: var(--ink);
    font: inherit;
}
.form-group textarea { height: auto; padding: var(--space-4) var(--space-8); }
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus,
.search-box input:focus,
.filter-group select:focus,
.new-playlist-box input[type="text"]:focus,
.share-add input:focus,
.share-add select:focus,
.tag-edit-table input:focus,
.album-art-search-form input:focus { outline: none; border-color: var(--brand-indigo); box-shadow: var(--shadow-focus); }

/* ---- Playlist sharing and picker ---- */
.share-add { display: flex; gap: var(--space-6); margin-top: var(--space-8); }
.share-add input { flex: 1; }
.share-add select { width: auto; }
.share-results { list-style: none; margin: var(--space-4) 0 0; padding: 0; border: 1px solid var(--border-strong); border-radius: var(--radius-md); max-width: 420px; }
.share-results li + li { border-top: 1px solid var(--border); }
.share-results .context-menu-item { display: flex; align-items: center; gap: var(--space-8); }
.share-results-action { margin-left: auto; color: var(--selection-fg); font-size: 0.75rem; font-weight: 600; }
.playlist-picker-new { margin-top: var(--space-8); }
.playlist-picker-new input { flex: 1; }

/* ---- Appearance page ---- */
.appearance-notice { padding: var(--space-8) var(--space-12); border-radius: var(--radius-md); margin-bottom: var(--space-12); }
.appearance-actions { display: flex; flex-wrap: wrap; gap: var(--space-6); margin-top: var(--space-8); }
.appearance-hint { margin-top: var(--space-8); font-size: 0.8125rem; color: var(--text-muted); }
.appearance-switch { display: inline-flex; }
.appearance-switch button { background: var(--surface); color: var(--text-secondary); border: none; padding: var(--space-4) var(--space-12); font: inherit; cursor: pointer; }
.appearance-switch button + button { border-left: 1px solid var(--border-strong); }
.appearance-switch button.active { background: var(--selection-bg); color: var(--selection-fg); font-weight: 600; }
.theme-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: var(--space-8); }
.theme-card { display: flex; flex-direction: column; gap: var(--space-6); padding: var(--space-8); background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-lg); font: inherit; color: var(--ink); cursor: pointer; text-align: left; }
.theme-card:hover { background: var(--surface-muted); }
.theme-card.active { border-color: var(--brand-indigo); box-shadow: var(--shadow-focus); }
.theme-card-name { font-size: 0.8125rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.theme-swatches { display: flex; height: 28px; border-radius: var(--radius-md); overflow: hidden; border: 1px solid var(--border); }
.theme-swatches span { flex: 1; }
.theme-editor { margin-top: var(--space-12); padding: var(--space-12); border: 1px solid var(--border-strong); border-radius: var(--radius-lg); background: var(--surface-muted); }
.theme-editor-header { display: grid; grid-template-columns: 1fr auto; gap: var(--space-12); }
.theme-editor-group { margin: var(--space-12) 0 var(--space-4); font-size: 0.6875rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-muted); }
.theme-color-row { display: flex; align-items: center; gap: var(--space-8); min-height: 32px; }
.theme-color-row input[type="color"] { width: 40px; height: 28px; padding: 0 2px; border: 1px solid var(--border-strong); border-radius: var(--radius-md); background: var(--surface); cursor: pointer; }
.theme-color-row label { flex: 1; font-size: 0.8125rem; color: var(--text-secondary); }
.link-button { background: none; border: none; padding: 0; font: inherit; font-size: 0.75rem; color: var(--accent-fg); cursor: pointer; }
.link-button:hover { color: var(--accent-fg-hover); text-decoration: underline; }
.file-button { position: relative; display: inline-flex; align-items: center; cursor: pointer; }
.file-button input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.file-button:focus-within { box-shadow: var(--shadow-focus); }
.import-summary { margin-top: var(--space-12); padding: var(--space-12); border: 1px solid var(--border-strong); border-radius: var(--radius-lg); background: var(--info-bg); color: var(--info-fg); }
.import-summary p { color: inherit; }
/* Custom CSS in a theme: the editor, and the preview shown before importing a theme that has some. */
.theme-css-editor { width: 100%; min-height: 220px; box-sizing: border-box; padding: var(--space-8); border: 1px solid var(--border-strong); border-radius: var(--radius-md); background: var(--surface); color: var(--ink); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.8125rem; line-height: 1.5; resize: vertical; tab-size: 2; }
.theme-css-size { margin: var(--space-4) 0 0; font-size: 0.75rem; color: var(--text-muted); text-align: right; font-variant-numeric: tabular-nums; }
.theme-css-preview { max-height: 240px; overflow: auto; margin: var(--space-8) 0; padding: var(--space-8); border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface-muted); color: var(--ink); font-size: 0.75rem; white-space: pre-wrap; word-break: break-word; }
/* Safe mode (custom CSS off for this tab): js/theme.js */
.safe-mode-banner { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-12); padding: var(--space-8) var(--space-12); border: 1px solid var(--border-strong); border-radius: var(--radius-md); background: var(--selection-bg); color: var(--selection-fg); font-size: 0.8125rem; }

/* ---- Buttons: 28px, solid, no lift ---- */
.button,
.button-secondary,
.button-danger {
    height: 28px;
    padding: 0 var(--space-12);
    border-radius: var(--radius-md);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-4);
    transition: background 0.1s;
    white-space: nowrap;
}
.button { background: var(--brand-violet); color: var(--on-brand); border: 1px solid var(--brand-violet); }
.button:hover { background: var(--brand-violet-hover); border-color: var(--brand-violet-hover); }
.button.block, form > .button { width: 100%; }
.button-secondary { background: var(--surface); color: var(--ink); border: 1px solid var(--border-strong); }
.button-secondary:hover { background: var(--surface-muted); }
.button-danger { background: var(--danger); color: var(--on-brand); border: 1px solid var(--danger); }
.button-danger:hover { background: var(--danger-hover); border-color: var(--danger-hover); }
.button:disabled,
.button-secondary:disabled,
.button-danger:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---- Feedback ---- */
.success-message,
.error,
.error-message,
.validation-summary,
.info-text {
    padding: var(--space-6) var(--space-12);
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    margin-bottom: var(--space-8);
    font-size: 0.8125rem;
}
.success-message { background: var(--success-bg); color: var(--success-fg); border-color: var(--success-border); }
.error, .error-message, .validation-summary { background: var(--error-bg); color: var(--error-fg); border-color: var(--error-border); }
.error strong { margin-right: var(--space-4); }
.validation-summary ul { list-style: none; }
.info-text { background: var(--info-bg); color: var(--info-fg); }
.text-danger,
.validation-message { color: var(--danger-fg); font-size: 0.75rem; margin-top: var(--space-2); display: block; }

.playlist-access-badge {
    display: inline-block;
    background: var(--brand-violet);
    color: var(--on-brand);
    padding: var(--space-2) var(--space-6);
    border-radius: var(--radius-sm);
    font-size: 0.6875rem;
    line-height: 14px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

/* ---- Key/value and stats ---- */
.info-section { border: 1px solid var(--border); border-radius: var(--radius-md); margin-bottom: var(--space-8); }
.info-section h3 { font-size: 0.6875rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-secondary); padding: var(--space-6) var(--space-12); background: var(--surface-muted); border-bottom: 1px solid var(--border); }
.info-item { display: flex; justify-content: space-between; gap: var(--space-12); padding: var(--space-6) var(--space-12); border-bottom: 1px solid var(--border); }
.info-item:last-child { border-bottom: none; }
.info-label { color: var(--text-secondary); }
.info-value { color: var(--ink); font-variant-numeric: tabular-nums; }

.result-card { margin-top: var(--space-8); }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); border: 1px solid var(--border-strong); border-radius: var(--radius-lg); overflow: hidden; background: var(--border); gap: 1px; }
.stat { background: var(--surface); padding: var(--space-8) var(--space-12); }
.stat-value { font-size: 1.5rem; line-height: 1.2; font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }
.stat-label { font-size: 0.6875rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-muted); }

.section-header { font-size: 0.6875rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-secondary); margin: var(--space-12) 0 var(--space-6); }
.folder-item { padding: var(--space-8) var(--space-12); border: 1px solid var(--border); border-radius: var(--radius-md); margin-bottom: var(--space-4); }
.checkbox-row { display: flex; align-items: center; gap: var(--space-6); margin: var(--space-8) 0; font-size: 0.8125rem; color: var(--text-secondary); cursor: pointer; }
.update-status p { margin-bottom: var(--space-6); }
.update-checked-at { color: var(--text-muted); font-size: 0.75rem; }
.backup-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 0 var(--space-12); }
.backup-days { display: flex; flex-wrap: wrap; gap: 0 var(--space-12); margin-bottom: var(--space-8); }
.backup-days .checkbox-row { margin: 0; }
.backup-hint { font-size: 0.75rem; color: var(--text-muted); margin-bottom: var(--space-8); }
.account-list { list-style: none; margin: 0 0 var(--space-8); padding: 0; }
.account-list > li { padding: var(--space-6) 0; border-top: 1px solid var(--border); }
.account-list > li:first-child { border-top: none; }
.account-row { display: flex; align-items: center; justify-content: space-between; gap: var(--space-12); }
.account-who { min-width: 0; overflow-wrap: anywhere; }
.account-who .backup-hint { margin-bottom: 0; }
.account-badge { margin-left: var(--space-6); padding: var(--space-2) var(--space-6); border-radius: var(--radius-md); background: var(--info-bg); color: var(--info-fg); font-size: 0.6875rem; font-weight: 600; }
.account-badge.warning { background: transparent; border: 1px solid currentColor; color: var(--warning-fg); }
.reset-link { display: flex; gap: var(--space-6); margin: var(--space-6) 0 var(--space-4); }
.reset-link input { flex: 1; min-width: 0; font-family: monospace; font-size: 0.75rem; }
.backup-schedule { margin-bottom: var(--space-12); }
.backup-status { margin-bottom: var(--space-12); }
.backup-status p { margin-bottom: var(--space-6); }

.loading, .scanning, .no-results { text-align: center; padding: var(--space-24); color: var(--text-muted); }
.no-results h2 { font-size: 0.875rem; color: var(--text-secondary); }
.scanning::after, .loading::after { content: '...'; animation: dots 1.5s steps(4, end) infinite; }
@keyframes dots { 0%, 20% { content: '.'; } 40% { content: '..'; } 60%, 100% { content: '...'; } }

/* ---- Toolbar (search + sort) ---- */
.controls,
.playlist-toolbar {
    min-height: 36px;
    padding: var(--space-4) var(--space-12);
    background: var(--surface-muted);
    border-bottom: 1px solid var(--border);
    display: flex;
    gap: var(--space-8);
    flex-wrap: wrap;
    align-items: center;
}
.search-box { flex: 1; min-width: 180px; }
.filter-group { display: flex; gap: var(--space-6); align-items: center; }
.filter-group label { font-size: 0.8125rem; color: var(--text-secondary); white-space: nowrap; }
.filter-group select { width: auto; cursor: pointer; }

/* ---- Tables: 32px rows, hairlines ---- */
.track-list-component .content { padding: 0; }
table { width: 100%; border-collapse: collapse; background: var(--surface); }
thead { background: var(--surface-muted); position: sticky; top: 0; z-index: 10; }
th {
    height: 28px;
    padding: 0 var(--space-12);
    text-align: left;
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-strong);
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}
th:hover { color: var(--ink); }
th::after { content: ' ⇅'; opacity: 0.35; }
th.select-cell::after, th.drag-handle-cell::after, th.remove-cell::after { content: none; }
tbody tr { border-bottom: 1px solid var(--border); cursor: default; }
tbody tr:hover { background: var(--surface-muted); }
tbody tr.selected { background: var(--selection-bg); box-shadow: inset 2px 0 0 var(--brand-indigo); }
td { height: 32px; padding: 0 var(--space-12); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 0; }
.title-cell { font-weight: 600; color: var(--ink); }
.artist-cell { color: var(--accent-fg); }
.album-cell { color: var(--text-muted); }
.file-path { font-family: var(--font-mono); font-size: 0.75rem; color: var(--text-muted); }
.select-cell { width: 32px; padding: 0; text-align: center; }

.track-list-selection-bar {
    display: flex;
    align-items: center;
    gap: var(--space-8);
    min-height: 32px;
    padding: var(--space-2) var(--space-12);
    background: var(--selection-bg);
    color: var(--selection-fg);
    font-weight: 600;
    font-size: 0.8125rem;
    border-bottom: 1px solid var(--border);
}

/* ---- Movable, resizable page modules (ModuleGrid + GridStack) ---- */
.layout-toolbar { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: var(--space-6); }
.layout-toolbar-hint { margin-right: auto; font-size: 0.8125rem; color: var(--text-muted); }
@media (max-width: 720px) {
    /* The grid is a single column here, and layouts are only edited at full width. */
    .layout-toolbar { display: none; }
}
.module-grid-host { margin: 0 calc(-1 * var(--space-4)); } /* cancels the grid's outer margin so panels line up with the page */
.module-grid-host .grid-stack > .grid-stack-item > .grid-stack-item-content { overflow: hidden; }
.layout-module { position: relative; height: 100%; }
/* Each module fills its panel; its list scrolls inside instead of the page growing. */
.layout-module > .artist-list-component,
.layout-module > .album-list-component,
.layout-module > .track-list-component,
.layout-module > .visualizer-module { height: 100%; display: flex; flex-direction: column; }
.layout-module > .visualizer-module { min-height: 0; }
/* Random album / track modules: mode switch and reroll on the right of the header. */
.random-controls { display: flex; gap: var(--space-4); margin-left: auto; }
.random-controls .button-secondary[aria-pressed="true"] { background: var(--selection-bg); color: var(--selection-fg); border-color: var(--selection-fg); }
.random-module .album-list-header > .button-secondary { margin-left: auto; }
.random-module .album-list-header > .button-secondary + .random-controls { margin-left: 0; }
.random-track { cursor: pointer; }
.recent-played-at { flex-shrink: 0; font-size: 0.75rem; color: var(--text-muted); white-space: nowrap; }
.layout-module .artist-list-container,
.layout-module .album-list-container { max-height: none; flex: 1; min-height: 0; }
.layout-module .track-list-component > .content { flex: 1; min-height: 0; overflow-y: auto; }
.layout-module-overlay {
    position: absolute;
    inset: 0;
    z-index: 20;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-8);
    padding: var(--space-8);
    background: color-mix(in srgb, var(--selection-bg) 70%, transparent);
    border: 2px dashed var(--brand-indigo);
    border-radius: var(--radius-lg);
    cursor: move;
}
.layout-module-name { padding: var(--space-4) var(--space-8); border-radius: var(--radius-md); background: var(--surface); color: var(--ink); font-size: 0.8125rem; font-weight: 600; box-shadow: var(--shadow-menu); }
.layout-module-hide { padding: var(--space-4) var(--space-8); border: 1px solid var(--border-strong); border-radius: var(--radius-md); background: var(--surface); color: var(--text-secondary); font: inherit; font-size: 0.75rem; cursor: pointer; }
.layout-module-hide:hover { color: var(--danger-fg); }
.grid-stack-placeholder > .placeholder-content { border: 2px dashed var(--border-strong); border-radius: var(--radius-lg); background: var(--surface-muted); }
.up-next-module-header { min-height: 36px; padding: var(--space-4) var(--space-12); display: flex; align-items: center; background: var(--surface-muted); border-bottom: 1px solid var(--border); }
.up-next-module-header h2 { font-size: 0.875rem; font-weight: 600; color: var(--ink); margin: 0; }
.up-next-module-body { flex: 1; min-height: 0; overflow-y: auto; }
.up-next-empty { padding: var(--space-12); font-size: 0.8125rem; color: var(--text-muted); }

/* ---- Artist and album lists: 40px rows ---- */
.artist-list-container,
.album-list-container { max-height: 400px; overflow-y: auto; }
.artist-list, .album-list { list-style: none; }
.artist-item,
.album-item {
    display: flex;
    align-items: center;
    gap: var(--space-8);
    height: 40px;
    padding: 0 var(--space-12);
    border-bottom: 1px solid var(--border);
    cursor: default;
}
.artist-item:hover, .album-item:hover { background: var(--surface-muted); }
.artist-item:last-child, .album-item:last-child { border-bottom: none; }
.artist-info { display: flex; align-items: center; gap: var(--space-8); flex: 1; min-width: 0; }
.artist-avatar {
    width: 28px;
    height: 28px;
    border-radius: var(--radius-round);
    background: var(--gradient-brand);
    color: var(--on-brand);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.75rem;
    flex-shrink: 0;
}
.artist-details { flex: 1; min-width: 0; display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-8); }
.artist-name, .album-title { font-weight: 600; color: var(--ink); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.artist-track-count, .album-artist { font-size: 0.75rem; color: var(--text-muted); flex-shrink: 0; font-variant-numeric: tabular-nums; }

.album-art {
    position: relative;
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    flex-shrink: 0;
    background: var(--gradient-brand);
    display: flex;
    align-items: center;
    justify-content: center;
}
.album-art img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; z-index: 1; }
.album-art-placeholder { font-size: 0.875rem; }
/* Cover columns in track tables, and the now-playing cover in the player bar. */
th.cover-cell, td.cover-cell { width: 40px; padding-right: 0; }
.player-cover { width: 40px; height: 40px; }
.album-play-overlay { position: absolute; inset: 0; z-index: 2; display: none; align-items: center; justify-content: center; background: var(--overlay); color: var(--on-brand); font-size: 0.75rem; cursor: pointer; }
.album-art:hover .album-play-overlay { display: flex; }

/* ---- Listens ---- */
.listens-count { color: var(--text-muted); font-size: 0.8125rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.listens-table th { cursor: default; }
.listens-table th::after { content: none; }
.listens-table tbody tr { cursor: pointer; }
.listens-table .played-cell { width: 150px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.listens-table .year-cell { width: 64px; font-variant-numeric: tabular-nums; }
.listens-table .listened-cell { width: 80px; text-align: right; font-variant-numeric: tabular-nums; }
.listens-table .scrobble-cell { width: 72px; text-align: center; color: var(--text-muted); }
.listens-table .scrobble-scrobbled { color: var(--success-fg); }
.listens-table .scrobble-ignored, .listens-table .scrobble-failed { color: var(--error-fg); }

/* ---- Pager: a footer row inside the module ---- */
.pager {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-8);
    min-height: 36px;
    padding: var(--space-4) var(--space-12);
    border-top: 1px solid var(--border);
    background: var(--surface);
}
.pager-status { color: var(--text-muted); font-size: 0.8125rem; font-variant-numeric: tabular-nums; margin-right: auto; }

/* ---- Playlists ---- */
.new-playlist-box { display: flex; gap: var(--space-6); align-items: center; }
.new-playlist-box input[type="text"] { width: 200px; }
.playlist-detail { padding: 0; }
.playlist-detail-header { display: flex; align-items: center; gap: var(--space-8); flex-wrap: wrap; padding: var(--space-6) var(--space-12); border-bottom: 1px solid var(--border); }
.playlist-name-input { font: inherit; font-size: 1rem; font-weight: 600; height: 28px; padding: 0 var(--space-6); border: 1px solid transparent; border-radius: var(--radius-md); flex: 1; min-width: 160px; background: none; color: var(--ink); }
.playlist-name-input:hover:not(:disabled), .playlist-name-input:focus { border-color: var(--border-strong); outline: none; }
.playlist-editor-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); gap: var(--space-8); padding: var(--space-8); align-items: start; }
.playlist-editor-column h3 { font-size: 0.6875rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-secondary); margin-bottom: var(--space-6); }
.playlist-editor-column .button { margin-top: var(--space-8); }
.playlist-owner { font-size: 0.8125rem; color: var(--text-muted); }
.playlist-share-section { padding: var(--space-8) var(--space-12); border-bottom: 1px solid var(--border); }
.playlist-share-section h3 { font-size: 0.6875rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-secondary); margin-bottom: var(--space-6); }
.playlist-share-empty { font-size: 0.8125rem; color: var(--text-muted); }
.playlist-share-section select { width: auto; }
.playlist-track-table .drag-handle-cell { width: 24px; padding: 0; text-align: center; color: var(--text-faint); cursor: grab; }
.playlist-track-table .remove-cell { width: 32px; padding: 0; text-align: center; }
.track-remove-button { background: none; border: none; color: var(--text-muted); cursor: pointer; width: 24px; height: 24px; border-radius: var(--radius-md); }
.track-remove-button:hover { color: var(--danger-fg); background: var(--error-bg); }
.playlist-track-table tbody tr.dragging { opacity: 0.4; }
.playlist-track-table tbody tr.drag-over { box-shadow: var(--shadow-drop-target); }
.playlist-drop-zone-row td { text-align: center; color: var(--text-muted); font-size: 0.75rem; border-bottom: none; }
.playlist-drop-zone-row.drag-over td { color: var(--accent-fg); font-weight: 600; }

/* ---- Modal ---- */
.modal-overlay { position: fixed; inset: 0; background: var(--overlay); display: flex; align-items: center; justify-content: center; z-index: 1000; padding: var(--space-16); }
.modal-card { background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-modal); max-width: 400px; width: 100%; overflow: hidden; }
.modal-header { padding: var(--space-12) var(--space-16) 0; }
.modal-header h3 { color: var(--ink); font-size: 1rem; font-weight: 600; }
.modal-body { padding: var(--space-6) var(--space-16) var(--space-16); color: var(--text-secondary); }
.modal-actions { display: flex; justify-content: flex-end; gap: var(--space-8); padding: var(--space-8) var(--space-16); background: var(--surface-muted); border-top: 1px solid var(--border); }

/* ---- Context menu ---- */
.context-menu-overlay { position: fixed; inset: 0; z-index: 1000; }
.context-menu { position: fixed; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-lg); box-shadow: var(--shadow-menu); min-width: 180px; padding: var(--space-4); }
.context-menu-item { display: block; width: 100%; text-align: left; height: 28px; padding: 0 var(--space-8); background: none; border: none; border-radius: var(--radius-md); font: inherit; color: var(--text-secondary); cursor: pointer; }
.context-menu-item:hover { background: var(--surface-muted); color: var(--ink); }
.context-menu-item:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---- Add to playlist picker ---- */
.playlist-picker-list { max-height: 280px; overflow-y: auto; margin-top: var(--space-6); }
.playlist-picker-list .context-menu-item { display: flex; align-items: center; gap: var(--space-8); }
.playlist-picker-count { margin-left: auto; font-size: 0.75rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.modal-body > .error { margin-bottom: var(--space-6); }

/* ---- Tag editing ---- */
.tag-edit-modal { max-width: 480px; }
.tag-fields .form-group:last-child { margin-bottom: 0; }
.tag-fields-row { display: flex; gap: var(--space-8); }
.tag-fields-row .form-group { flex: 1; }
.tag-edit-table-wrapper { overflow-x: auto; }
.tag-edit-table td { padding: var(--space-2) var(--space-4); max-width: none; }
.tag-edit-table input { min-width: 90px; }
.tag-edit-table input[type="number"] { min-width: 64px; }
.tag-edit-apply-row { background: var(--surface-muted); border-bottom: 1px solid var(--border-strong); }
.tag-edit-apply-row button { white-space: nowrap; }
.tag-edit-actions { display: flex; justify-content: flex-end; gap: var(--space-8); padding: var(--space-8) var(--space-12); border-top: 1px solid var(--border); }

/* ---- Page-specific pieces ---- */
.playlist-track-list-component { background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-lg); overflow: hidden; min-width: 0; }
.playlist-detail > .error { margin: var(--space-8) var(--space-12) 0; }

.loading h2, .scanning h2 { display: inline; font-size: 0.875rem; font-weight: 400; }
.error h3 { display: inline; font-size: inherit; margin-right: var(--space-4); }
.error p, .content .error p { display: inline; margin: 0; color: inherit; font-size: inherit; }
.no-results p { color: var(--text-muted); margin: 0; }

.result-card h2 { display: inline; font-size: 0.875rem; font-weight: 600; color: var(--ink); }
.success-icon { display: inline; margin-right: var(--space-4); }
.result-card .stats-grid { margin-top: var(--space-8); }
.result-meta { margin-top: var(--space-8); font-size: 0.8125rem; color: var(--text-muted); }

.nav-links { display: flex; gap: var(--space-12); padding-top: var(--space-4); }
.nav-links.centered { justify-content: center; }
.nav-links a { color: var(--accent-fg); text-decoration: none; font-weight: 600; font-size: 0.8125rem; }
.nav-links a:hover { color: var(--accent-fg-hover); text-decoration: underline; }

.actions-cell { width: 160px; max-width: none; overflow: visible; text-align: right; }
.actions-cell > * + * { margin-left: var(--space-4); }
.playlist-editor-grid { background: var(--canvas); border-top: 1px solid var(--border); }
.tag-edit-table td { overflow: visible; }
.actions-cell .button-secondary, .actions-cell .button-danger { height: 24px; padding: 0 var(--space-8); font-size: 0.8125rem; }

/* ---- Boot and Blazor framework UI ---- */
.initial-loading { display: flex; align-items: center; justify-content: center; min-height: 100vh; color: var(--text-muted); }
#blazor-error-ui {
    background: var(--notice-bg);
    bottom: 0;
    border-top: 1px solid var(--border-strong);
    display: none;
    left: 0;
    padding: var(--space-8) var(--space-16);
    position: fixed;
    width: 100%;
    z-index: 1000;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: var(--space-12); top: var(--space-8); }

/* ---- Album art editor: a module, or across the top of the Library when opened from a right-click ---- */
.album-art-panel { height: min(460px, 70vh); margin-bottom: var(--space-8); }
.album-art-editor {
    height: 100%;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    overflow: hidden;
    min-width: 0;
}
.layout-module > .album-art-editor { height: 100%; }
.album-art-header {
    min-height: 36px;
    padding: var(--space-4) var(--space-12);
    display: flex;
    align-items: center;
    gap: var(--space-8);
    background: var(--surface-muted);
    border-bottom: 1px solid var(--border);
}
.album-art-header h2 { font-size: 0.875rem; font-weight: 600; color: var(--ink); margin: 0 auto 0 0; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.album-art-header-album { font-weight: 400; color: var(--text-secondary); }
.album-art-empty { padding: var(--space-16); color: var(--text-muted); font-size: 0.8125rem; }
.album-art-body { flex: 1; min-height: 0; overflow-y: auto; display: flex; gap: var(--space-16); padding: var(--space-12); }
.album-art-preview { flex: 0 0 180px; display: flex; flex-direction: column; gap: var(--space-6); align-items: stretch; }
.album-art-frame { position: relative; aspect-ratio: 1; display: flex; align-items: center; justify-content: center; background: var(--surface-muted); border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; }
.album-art-frame img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.album-art-frame-placeholder { font-size: 2.5rem; opacity: 0.5; }
.album-art-caption { font-size: 0.75rem; color: var(--text-muted); overflow-wrap: anywhere; }
.album-art-note { font-size: 0.75rem; color: var(--text-faint); }
.album-art-file { display: none; }
.album-art-search { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: var(--space-8); }
.album-art-search-form { display: flex; gap: var(--space-6); flex-wrap: wrap; }
.album-art-search-form input { flex: 1 1 140px; width: auto; }
.album-art-providers { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-4); font-size: 0.75rem; color: var(--text-secondary); }
.album-art-provider { display: flex; gap: var(--space-6); align-items: baseline; }
.album-art-provider strong { color: var(--ink); margin-right: var(--space-4); }
.album-art-provider-dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--success-fg); transform: translateY(-1px); }
.album-art-provider.is-limited .album-art-provider-dot { background: var(--warning-fg); }
.album-art-provider.is-unavailable .album-art-provider-dot { background: var(--danger-fg); }
.album-art-error { margin: 0; font-size: 0.8125rem; color: var(--danger-fg); }
.album-art-results h3 { font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); margin: var(--space-4) 0 var(--space-6); }
.album-art-none { margin: 0; font-size: 0.75rem; color: var(--text-faint); }
.album-art-result-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: var(--space-8); }
.album-art-result { width: 100%; display: flex; flex-direction: column; gap: 2px; padding: var(--space-4); background: none; border: 2px solid transparent; border-radius: var(--radius-md); font: inherit; text-align: left; color: var(--ink); cursor: pointer; }
.album-art-result:hover { background: var(--surface-muted); }
.album-art-result.selected { border-color: var(--brand-violet); background: var(--selection-bg); }
.album-art-result img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: var(--radius-sm, 4px); background: var(--surface-muted); }
.album-art-result-title { font-size: 0.75rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.album-art-result-detail { font-size: 0.6875rem; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 720px) {
    .album-art-panel { height: auto; max-height: 80vh; }
    .album-art-body { flex-direction: column; }
    .album-art-preview { flex-basis: auto; max-width: 220px; }
}

/* ---- Favourites ---- */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
.favorite-button {
    background: none;
    border: none;
    padding: 0 var(--space-4);
    font-size: 1rem;
    line-height: 1;
    color: var(--text-muted);
    cursor: pointer;
}
.favorite-button:hover { color: var(--brand-violet); }
.favorite-button.on { color: var(--brand-violet); }
.favorite-button:focus-visible { outline: none; box-shadow: var(--shadow-focus); border-radius: var(--radius-md); }
.player-bar .favorite-button { color: var(--chrome-muted); }
.player-bar .favorite-button.on,
.player-bar .favorite-button:hover { color: var(--chrome-fg); }
/* ♥ comes from a wider fallback font than ♡ in some browsers, so the button
   has a fixed width and the cell leaves room for it rather than clipping. */
.favorite-button { min-width: 1.75em; text-align: center; }
td.favorite-cell,
th.favorite-cell { width: 44px; padding: 0 var(--space-4); text-align: center; overflow: visible; }
.browse-favorites { min-width: 28px; height: 28px; padding: 0 var(--space-6); }
.browse-favorites.active { color: var(--brand-violet); border-color: var(--brand-violet); }

.favorites-module { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.favorites-tabs {
    display: flex;
    gap: var(--space-4);
    align-items: center;
    padding: var(--space-4) var(--space-12);
    background: var(--surface-muted);
    border-bottom: 1px solid var(--border);
}
.favorites-tab {
    background: none;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    padding: var(--space-2) var(--space-8);
    font: inherit;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    cursor: pointer;
}
.favorites-tab.active { background: var(--surface); border-color: var(--border); color: var(--ink); font-weight: 600; }
.favorites-play { margin-left: auto; }
.favorites-body { flex: 1; min-height: 0; overflow: auto; }
