/* ===== Self-hosted pixel fonts =======================================
 * 16-bit-feel display stack: Silkscreen (SNES/Amiga menu vibe) backed by
 * VT323 (retro monospace fallback). Files live under /static/fonts/ and
 * are not checked into the repo; see fonts/README.md for fetch
 * instructions and scripts/fetch-pixel-fonts.sh.
 * `font-display: swap` keeps the page readable with the system fallback
 * while the WOFF2 streams in (or stays missing forever, harmless).
 *
 * Press Start 2P was used in the 8-bit pass and is no longer referenced
 * here. The legacy WOFF2 may still be on disk; the CSS does not load it.
 */
@font-face {
    font-family: 'Silkscreen';
    src: url('/static/fonts/silkscreen.woff2') format('woff2');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: 'VT323';
    src: url('/static/fonts/vt323.woff2') format('woff2');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

/* ===== Design tokens =================================================
 * Single source of truth for typography, spacing, colour tints, shadows
 * and transitions. Keep new rules referencing these instead of literal
 * px / rem values so the look stays consistent across the app and a
 * future theme swap stays cheap.
 */

:root {
    /* Typography scale (modular, ratio ~1.2) */
    --fs-xs: 0.75rem;       /* 12px - micro / kbd / small chips */
    --fs-sm: 0.875rem;      /* 14px - secondary text, table cells */
    --fs-md: 1rem;          /* 16px - body */
    --fs-lg: 1.125rem;      /* 18px - card subtitles, emphasised */
    --fs-xl: 1.5rem;        /* 24px - section headers */
    --fs-2xl: 2rem;         /* 32px - hero numbers / dashboard stats */

    --lh-tight: 1.25;       /* headings */
    --lh-base: 1.5;         /* body */

    --font-stack-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
                       'Helvetica Neue', Arial, system-ui, sans-serif;
    --font-stack-mono: 'JetBrains Mono', 'SFMono-Regular', Menlo, Consolas,
                       'Liberation Mono', monospace;
    /* Retro display stack — 16-bit pixel font for headings, brand mark,
     * stat numbers, badges. Body text deliberately stays on the system
     * stack: pixel fonts hurt readability at body size. Silkscreen renders
     * cleaner and slightly narrower than Press Start 2P, with a 16-bit
     * (SNES menu) feel rather than the 8-bit NES look. */
    --font-display: 'Silkscreen', 'VT323', 'JetBrains Mono', monospace;
    --font-mono-retro: 'VT323', 'JetBrains Mono', monospace;

    /* Spacing scale (4px base) */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-6: 24px;
    --space-8: 32px;
    --space-12: 48px;

    /* Shared shape tokens */
    --radius: 8px;
    --radius-sm: 4px;
    --radius-pill: 999px;

    /* Motion */
    --transition-base: 150ms ease;
    --transition-transform: 200ms ease;
}

[data-theme="dark"] {
    --bg: #0f1117;
    --surface: #1f2436;          /* slightly warmer than 8-bit pass for 16-bit feel */
    --surface-hover: #262c42;
    --surface-gradient: linear-gradient(180deg, #1f2436 0%, #1a1d27 100%);
    --surface-gradient-hover: linear-gradient(180deg, #262c42 0%, #1f2436 100%);
    --border: #2a2e3d;
    --bevel-light: rgba(255, 255, 255, 0.10);   /* top + left highlight */
    --bevel-dark: rgba(0, 0, 0, 0.55);          /* bottom + right shadow */
    --bevel-outline: rgba(0, 0, 0, 0.65);       /* outer 1px definition */
    --text: #e1e4ed;
    --text-muted: #8b8fa3;
    --accent: #7d6ef0;                          /* slightly brighter purple */
    --accent-hover: #8e80ff;
    --accent-soft: rgba(125, 110, 240, 0.14);
    --accent-border: rgba(125, 110, 240, 0.45);
    --accent-ring: rgba(125, 110, 240, 0.30);
    --accent2: #ff7eb3;                         /* 16-bit pink secondary */
    --green: #00b894;
    --red: #e74c3c;
    --orange: #f39c12;
    --blue: #3498db;
    --gold: #ffd060;
    /* Elevation */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
    --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.30);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.45);
}

[data-theme="light"] {
    --bg: #f5f6fa;
    --surface: #ffffff;
    --surface-hover: #f0f1f5;
    --surface-gradient: linear-gradient(180deg, #ffffff 0%, #f3f4f8 100%);
    --surface-gradient-hover: linear-gradient(180deg, #f6f7fb 0%, #ebeef4 100%);
    --border: #e0e2e9;
    --bevel-light: rgba(255, 255, 255, 0.95);
    --bevel-dark: rgba(15, 17, 23, 0.18);
    --bevel-outline: rgba(15, 17, 23, 0.20);
    --text: #1a1d27;
    --text-muted: #5b6273;        /* slightly darker than the old #6b7280 to lift WCAG AA on light bg */
    --accent: #5a4bd1;            /* darker purple, AA on white */
    --accent-hover: #4a3cba;
    --accent-soft: rgba(90, 75, 209, 0.10);
    --accent-border: rgba(90, 75, 209, 0.32);
    --accent-ring: rgba(90, 75, 209, 0.25);
    --accent2: #b03a76;           /* 16-bit pink secondary, AA-safe */
    --green: #00875a;             /* darker green for contrast on white */
    --red: #c0392b;               /* darker red for contrast on white */
    --orange: #b8651a;            /* darker orange for contrast on white */
    --blue: #1f6aa5;              /* darker blue for contrast on white */
    --gold: #a87100;              /* darker gold for contrast on light surface */
    --shadow-sm: 0 1px 2px rgba(15, 17, 23, 0.06);
    --shadow-md: 0 4px 14px rgba(15, 17, 23, 0.08);
    --shadow-lg: 0 12px 32px rgba(15, 17, 23, 0.14);
}

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

body {
    font-family: var(--font-stack-sans);
    background: var(--bg);
    color: var(--text);
    line-height: var(--lh-base);
    font-size: var(--fs-md);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6 {
    line-height: var(--lh-tight);
}

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

/* Layout */
.container { max-width: 1200px; margin: 0 auto; padding: 0 var(--space-6); }

nav {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: var(--space-3) 0;
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: saturate(140%);
}

nav .container {
    display: flex;
    align-items: center;
    gap: var(--space-6);
}

nav .logo {
    font-size: var(--fs-lg);
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.01em;
    padding-right: var(--space-3);
    border-right: 1px solid var(--border);
    margin-right: var(--space-2);
}

nav .links { display: flex; gap: var(--space-1); }

/* Pill-style nav links with a clear active state. The .active class is
 * applied by templates (base.html) based on active_page. */
nav .links a {
    color: var(--text-muted);
    font-size: var(--fs-sm);
    padding: 6px var(--space-3);
    border-radius: var(--radius-sm);
    transition: color var(--transition-base), background var(--transition-base);
    position: relative;
}
nav .links a:hover { color: var(--text); background: var(--surface-hover); }
nav .links a.active {
    color: var(--text);
    background: var(--accent-soft);
}
nav .links a.active::after {
    content: "";
    position: absolute;
    left: var(--space-3);
    right: var(--space-3);
    bottom: -2px;
    height: 2px;
    border-radius: 2px;
    background: var(--accent);
}

main { padding: var(--space-8) 0; }

/* Stats cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-4);
    margin-bottom: var(--space-8);
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: var(--space-4) var(--space-6);
    box-shadow: var(--shadow-sm);
    transition: transform var(--transition-transform), box-shadow var(--transition-base);
}

.stat-card:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.stat-card .label {
    font-size: var(--fs-xs);
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: var(--space-2);
    font-weight: 600;
}

.stat-card .value {
    font-size: var(--fs-2xl);
    font-weight: 700;
    line-height: var(--lh-tight);
    font-variant-numeric: tabular-nums;
}

.stat-card .value.green { color: var(--green); }
.stat-card .value.red { color: var(--red); }
.stat-card .value.blue { color: var(--blue); }

/* Tables */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: var(--space-6);
}

.card-header {
    padding: var(--space-4) var(--space-6);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--space-4);
    flex-wrap: wrap;
}

.card-header h2 {
    font-size: var(--fs-lg);
    font-weight: 600;
    letter-spacing: -0.01em;
}

.card-header h3 {
    font-size: var(--fs-md);
    font-weight: 600;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: var(--space-3) var(--space-6);
    text-align: left;
}

th {
    font-size: var(--fs-xs);
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 600;
    border-bottom: 1px solid var(--border);
    background: color-mix(in srgb, var(--surface) 92%, transparent);
}

/* Subtle zebra rows -- alternate background so dense tables stay scannable.
 * Hover wins over zebra; transitions are colour-only and reduced-motion safe. */
tbody tr {
    transition: background var(--transition-base);
    border-bottom: 1px solid var(--border);
}
tbody tr:last-child { border-bottom: none; }
tbody tr:nth-child(even) {
    background: color-mix(in srgb, var(--surface-hover) 35%, transparent);
}
tbody tr:hover { background: var(--surface-hover); }

td { font-size: var(--fs-sm); }

.badge {
    display: inline-block;
    padding: 2px var(--space-2);
    border-radius: var(--radius-pill);
    font-size: var(--fs-xs);
    font-weight: 600;
    letter-spacing: 0.02em;
}

.badge.ebay { background: #e74c3c22; color: var(--red); }
.badge.kleinanzeigen { background: #00b89422; color: var(--green); }
.badge.active { background: #00b89422; color: var(--green); }
.badge.inactive { background: #e74c3c22; color: var(--red); }
.badge.sold { background: #f39c1222; color: var(--orange); }
.badge.removed { background: rgba(139, 143, 163, 0.18); color: var(--text-muted); }
.badge.ended { background: rgba(139, 143, 163, 0.18); color: var(--text-muted); }

.price { font-weight: 600; font-variant-numeric: tabular-nums; }
.price-drop { color: var(--green); }
.price-up { color: var(--red); }

/* Forms */
.form-row {
    display: flex;
    gap: var(--space-3);
    align-items: flex-end;
    flex-wrap: wrap;
    padding: var(--space-4) var(--space-6);
    border-bottom: 1px solid var(--border);
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    flex: 1;
    min-width: 150px;
}

.form-group label {
    font-size: var(--fs-xs);
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 600;
}

input[type="text"],
input[type="number"] {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: var(--space-2) var(--space-3);
    color: var(--text);
    font-size: var(--fs-sm);
}

input:focus {
    outline: none;
    border-color: var(--accent);
}

.btn {
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: var(--fs-sm);
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    line-height: 1.2;
}

.btn:hover { background: var(--surface-hover); border-color: var(--accent-border); }
.btn:disabled, .btn[aria-disabled="true"] {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { color: var(--red); }
.btn-danger:hover { background: #e74c3c22; border-color: var(--red); }
.btn-sm { padding: var(--space-1) var(--space-3); font-size: var(--fs-xs); }

/* Price history chart */
.chart-container {
    padding: 20px;
    height: 300px;
    position: relative;
}

.chart-svg {
    width: 100%;
    height: 100%;
}

.chart-line {
    fill: none;
    stroke: var(--accent);
    stroke-width: 2;
}

.chart-area {
    fill: url(#gradient);
    opacity: 0.3;
}

.chart-dot {
    fill: var(--accent);
    r: 4;
}

.chart-label {
    fill: var(--text-muted);
    font-size: 11px;
}

/* Thumbnail */
.thumb {
    width: 48px;
    height: 48px;
    border-radius: 6px;
    object-fit: cover;
    background: var(--bg);
}

/* Empty state -- friendly icon-mark + message; primary CTA optional via
   children. Cap message line length so long sentences wrap nicely. */
.empty {
    text-align: center;
    padding: var(--space-12) var(--space-6);
    color: var(--text-muted);
    font-size: var(--fs-sm);
    max-width: 56ch;
    margin: 0 auto;
}
.empty a {
    color: var(--accent);
    font-weight: 500;
}
.empty a:hover { color: var(--accent-hover); }

/* Nav: health dot */
.nav-health-dot {
    width: 12px;
    height: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    text-decoration: none;
    line-height: 0;
}
.nav-health-inner {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--green);
    animation: pulse 2s ease-in-out infinite;
}
.nav-health-dot.nav-health-error .nav-health-inner {
    background: var(--red);
}

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

/* Responsive */
@media (max-width: 768px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .form-row { flex-direction: column; }
    .container { padding: 0 var(--space-4); }
    th, td { padding: var(--space-2) var(--space-3); }
    /* Submit buttons span the row on narrow screens; auto width above 768px. */
    button[type="submit"].btn { width: 100%; }
    button[type="submit"].btn-sm { width: auto; }
}

/* ----- Auth pages (login / register) ---------------------------------- */
.auth-body {
    background:
        radial-gradient(circle at 0% 0%, rgba(108, 92, 231, 0.18), transparent 45%),
        radial-gradient(circle at 100% 100%, rgba(0, 184, 148, 0.14), transparent 45%),
        var(--bg);
    min-height: 100vh;
}

.auth-shell {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-12);
    max-width: 1100px;
    margin: 0 auto;
    padding: 64px var(--space-8);
    min-height: 100vh;
    align-items: center;
}

.auth-hero { color: var(--text); }

.auth-brand {
    display: inline-flex;
    align-items: baseline;
    gap: var(--space-3);
    padding: 6px var(--space-3);
    background: var(--accent-soft);
    border: 1px solid var(--accent-border);
    border-radius: var(--radius);
    margin-bottom: var(--space-6);
    font-family: var(--font-stack-mono);
}

.auth-brand-mark {
    color: var(--accent);
    font-size: var(--fs-sm);
    letter-spacing: 2px;
}

.auth-brand-name {
    font-weight: 700;
    font-size: var(--fs-sm);
    letter-spacing: 1px;
    text-transform: uppercase;
}

.auth-headline {
    font-size: var(--fs-2xl);
    line-height: 1.15;
    font-weight: 800;
    margin-bottom: var(--space-4);
    color: var(--text);
    letter-spacing: -0.02em;
}

.auth-subhead {
    font-size: var(--fs-md);
    color: var(--text-muted);
    margin-bottom: var(--space-6);
    max-width: 460px;
    line-height: var(--lh-base);
}

.auth-features {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    gap: 10px;
}

.auth-features li {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.95rem;
    color: var(--text);
}

.auth-feature-icon {
    color: var(--green);
    font-weight: 700;
    width: 18px;
    text-align: center;
}

.auth-card-wrap { display: flex; justify-content: center; }

.auth-card {
    width: 100%;
    max-width: 440px;
    box-shadow: var(--shadow-lg);
}

.auth-card .card-header {
    padding: var(--space-6) var(--space-8) 0;
    border-bottom: none;
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-1);
}

.auth-card .card-header h2 {
    margin-bottom: var(--space-1);
    font-size: var(--fs-xl);
    letter-spacing: -0.01em;
}

.auth-card-sub {
    color: var(--text-muted);
    font-size: var(--fs-sm);
}

.auth-form {
    padding: var(--space-4) var(--space-8) var(--space-8);
    display: grid;
    gap: var(--space-4);
}

.auth-form .form-group { margin: 0; }

.auth-form input[type="text"],
.auth-form input[type="password"] {
    width: 100%;
    padding: 11px var(--space-3);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: var(--fs-md);
    transition: border-color var(--transition-base), box-shadow var(--transition-base);
}

.auth-form input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-ring);
}

.auth-hint {
    color: var(--text-muted);
    font-weight: 400;
    font-size: var(--fs-xs);
    margin-left: var(--space-1);
}

.auth-error {
    background: rgba(231, 76, 60, 0.12);
    color: var(--red);
    padding: var(--space-2) var(--space-3);
    border-left: 3px solid var(--red);
    border-radius: var(--radius-sm);
    font-size: var(--fs-sm);
}

.auth-submit {
    width: 100%;
    padding: var(--space-3);
    font-size: var(--fs-md);
    font-weight: 600;
    margin-top: var(--space-1);
}

.auth-alt {
    text-align: center;
    font-size: var(--fs-sm);
    color: var(--text-muted);
    margin: 0;
}

@media (max-width: 880px) {
    .auth-shell {
        grid-template-columns: 1fr;
        gap: 32px;
        padding: 40px 20px;
    }
    .auth-hero { text-align: left; }
    .auth-headline { font-size: 1.85rem; }
}

/* ----- Per-watchlist activity / stats --------------------------------- */
.wl-activity {
    font-size: 0.82rem;
    color: var(--text-muted);
    line-height: 1.4;
    min-width: 180px;
}

.wl-status {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text);
}

.wl-substatus { color: var(--text-muted); margin-top: 2px; }

.wl-status-pending { color: var(--text-muted); }
.wl-status-error {
    color: var(--red);
    background: rgba(231, 76, 60, 0.08);
    padding: 4px 8px;
    border-radius: 4px;
    border-left: 2px solid var(--red);
}

.wl-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
.wl-dot-ok { background: var(--green); box-shadow: 0 0 0 3px rgba(0, 184, 148, 0.18); }
.wl-dot-pending { background: var(--text-muted); opacity: 0.5; }

.wl-link {
    display: inline-block;
    margin-top: 4px;
    font-size: 0.78rem;
    color: var(--accent);
}

/* Detail page */
.wl-stats-sub { color: var(--text-muted); font-size: 0.9rem; margin-top: 4px; }
.wl-stats-body { padding: 24px; }

.wl-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.wl-stat {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
}

.wl-stat-label {
    font-size: 0.78rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}

.wl-stat-value {
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--text);
}

.wl-stat-empty { color: var(--text-muted); font-weight: 400; font-style: italic; }

.wl-stats-section {
    margin: 8px 0 14px;
    font-size: 1rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.wl-stats-when { color: var(--text-muted); margin-left: 6px; font-size: 0.85rem; }

.wl-stats-details {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 16px;
    margin-top: 16px;
}

.wl-stats-details summary {
    cursor: pointer;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.wl-stats-detail-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}
.wl-stats-detail-row:last-child { border-bottom: none; }

.wl-stats-back { margin-top: 24px; font-size: 0.9rem; }

/* ===== UX foundations: toasts, modals, kbd help, polish ===============
 * Owned by WP-C. Vanilla CSS, theme-token driven, no framework deps.
 */

/* ---- Toasts ---------------------------------------------------------- */
.toast-container {
    position: fixed;
    right: var(--space-4);
    bottom: var(--space-4);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    pointer-events: none;
    max-width: min(420px, calc(100vw - 32px));
}

.toast {
    pointer-events: auto;
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-left: 4px solid var(--accent);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: var(--space-3) var(--space-3);
    font-size: var(--fs-sm);
    animation: toast-in 0.18s ease-out;
}

.toast-info { border-left-color: var(--blue); }
.toast-success { border-left-color: var(--green); }
.toast-error { border-left-color: var(--red); }

.toast-message { flex: 1; line-height: 1.4; }

.toast-close {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
    padding: 0 4px;
    transition: color 0.15s ease;
}
.toast-close:hover { color: var(--text); }

/* Undo toast — extra grace window, inline button POSTs to undo_url. */
.toast-undo { border-left-color: var(--orange); }
.toast-undo-form { display: inline-flex; margin: 0; }
.toast-undo-btn {
    background: var(--orange);
    color: #fff;
    border: none;
    border-radius: 4px;
    padding: 4px 10px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
}
.toast-undo-btn:hover { filter: brightness(1.1); }

.toast-leaving { animation: toast-out 0.18s ease-in forwards; }

@keyframes toast-in {
    from { transform: translateY(8px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

@keyframes toast-out {
    from { transform: translateY(0); opacity: 1; }
    to { transform: translateY(8px); opacity: 0; }
}

/* ---- Modal (confirm + kbd help) ------------------------------------- */
.ux-modal {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 24px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
    max-width: 480px;
    width: calc(100vw - 32px);
}

.ux-modal::backdrop {
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(2px);
}

.ux-modal h3 {
    font-size: 1.05rem;
    font-weight: 600;
    margin-bottom: 8px;
}

.ux-modal p { color: var(--text-muted); margin-bottom: 16px; }

.ux-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 16px;
}

/* ---- Keyboard hints -------------------------------------------------- */
.ux-kbd-table {
    width: 100%;
    border-collapse: collapse;
}

.ux-kbd-table td {
    padding: 6px 0;
    font-size: 0.9rem;
    border: none;
}

.ux-kbd-table td:first-child {
    width: 110px;
    color: var(--text-muted);
}

kbd {
    display: inline-block;
    padding: 2px 7px;
    font-family: 'JetBrains Mono', 'SFMono-Regular', Menlo, Consolas, monospace;
    font-size: 0.78rem;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-bottom-width: 2px;
    border-radius: 4px;
    line-height: 1;
}

/* ---- Visual unification pass ----------------------------------------
 * Match dashboard cards/inputs to the auth-page palette: subtle shadow,
 * focus rings, hover lift on buttons, denser empty states.
 */
.card {
    box-shadow: var(--shadow-md);
    transition: box-shadow var(--transition-transform), transform var(--transition-transform);
}

.card-body { padding: var(--space-4) var(--space-6); }

/* Hover-lift on interactive cards (rows in listings table opt in via the
 * .listings-row selector which already exists). Plain content cards stay
 * still; only stat-card already opts in. */

input[type="text"],
input[type="number"],
input[type="password"],
input[type="email"],
input[type="url"],
input[type="search"],
textarea,
select {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: var(--space-2) var(--space-3);
    color: var(--text);
    font-size: var(--fs-sm);
    font-family: inherit;
    transition: border-color var(--transition-base), box-shadow var(--transition-base), background var(--transition-base);
}

input[type="text"]:hover:not(:focus),
input[type="number"]:hover:not(:focus),
input[type="password"]:hover:not(:focus),
input[type="email"]:hover:not(:focus),
input[type="url"]:hover:not(:focus),
input[type="search"]:hover:not(:focus),
textarea:hover:not(:focus),
select:hover:not(:focus) {
    border-color: var(--accent-border);
}

input[type="text"]:focus,
input[type="number"]:focus,
input[type="password"]:focus,
input[type="email"]:focus,
input[type="url"]:focus,
input[type="search"]:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-ring);
}

input:disabled,
textarea:disabled,
select:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.btn {
    transition: background var(--transition-base), border-color var(--transition-base),
                transform var(--transition-transform), box-shadow var(--transition-base),
                color var(--transition-base);
}

.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn:active { transform: translateY(0); box-shadow: var(--shadow-sm); }
.btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--accent-ring);
    border-color: var(--accent);
}

.empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-2);
    font-weight: 400;
}

/* Soft marker / placeholder icon for empty states. Pure CSS, no image. */
.empty::before {
    content: "";
    display: block;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--accent-soft);
    border: 1px dashed var(--accent-border);
    opacity: 0.9;
    margin-bottom: var(--space-1);
}

/* ---- Mobile breakpoint: table → card list at < 700px ----------------- */
@media (max-width: 700px) {
    table thead { display: none; }
    table, tbody, tr, td { display: block; width: 100%; }
    table tr {
        background: var(--bg);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        margin: 8px 12px;
        padding: 8px 4px;
    }
    table tr:hover { background: var(--bg); }
    table td {
        padding: 6px 12px;
        text-align: left;
        font-size: 0.88rem;
        border: none;
    }
    table td[data-label]::before {
        content: attr(data-label) " ";
        color: var(--text-muted);
        font-size: 0.72rem;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        display: block;
        margin-bottom: 2px;
    }
    .toast-container { left: 16px; right: 16px; max-width: none; }
}

/* --- WP-D: Watchlist tabs, DSL editor, tag chips ------------------------ */
.wl-tabs {
    display: flex;
    gap: 4px;
    padding: 8px 20px 0;
    border-bottom: 1px solid var(--border);
}
.wl-tab {
    background: transparent;
    border: 1px solid var(--border);
    border-bottom: none;
    border-radius: var(--radius) var(--radius) 0 0;
    padding: 6px 14px;
    color: var(--text-muted);
    font-size: 0.9rem;
    cursor: pointer;
    transition: background 0.12s ease, color 0.12s ease;
}
.wl-tab:hover { color: var(--text); }
.wl-tab.active {
    background: var(--surface, var(--bg));
    color: var(--text);
    border-color: var(--border);
    position: relative;
    top: 1px;
}
.wl-pane { padding: 12px 20px 16px; }
.wl-pane[hidden] { display: none !important; }

.dsl-meta {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-top: 6px;
    font-size: 0.85rem;
}
.dsl-status { color: var(--text-muted); }
.dsl-status.ok { color: #4ade80; }
.dsl-status.err { color: #f87171; }
.dsl-status.loading { color: var(--text-muted); font-style: italic; }
.dsl-errors { margin-top: 8px; }
.dsl-errors:empty { display: none; }
.dsl-error {
    background: rgba(248, 113, 113, 0.08);
    border-left: 3px solid #f87171;
    padding: 6px 10px;
    margin-bottom: 4px;
    font-size: 0.85rem;
    border-radius: 0 var(--radius) var(--radius) 0;
}
.dsl-error-pos { color: var(--text-muted); font-family: monospace; }
.dsl-error-suggest { color: var(--text-muted); font-style: italic; margin-top: 2px; }
.dsl-preview {
    margin-top: 8px;
    padding: 6px 10px;
    background: rgba(74, 222, 128, 0.06);
    border-left: 3px solid #4ade80;
    border-radius: 0 var(--radius) var(--radius) 0;
    font-size: 0.85rem;
}
.dsl-preview-fields { color: var(--text-muted); margin-top: 4px; font-size: 0.8rem; }

#dsl-cheatsheet[open] {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg, #14171e);
    color: var(--text);
    max-width: 640px;
    padding: 0;
}
.dsl-cheatsheet-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}
.dsl-cheatsheet-body { padding: 16px; max-height: 70vh; overflow-y: auto; }
.dsl-cheatsheet-body code { background: rgba(255, 255, 255, 0.05); padding: 1px 4px; border-radius: 3px; }
.dsl-cheatsheet-foot { margin-top: 12px; color: var(--text-muted); font-size: 0.85rem; }

.chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 12px;
    font-size: 0.78rem;
    color: var(--text);
    line-height: 1.4;
}
.chip-tag { background: rgba(99, 102, 241, 0.16); }
.chip-exclude { background: rgba(248, 113, 113, 0.16); color: #fca5a5; }
.chip-term { background: rgba(74, 222, 128, 0.16); color: #86efac; }
.chip-remove {
    background: transparent;
    border: none;
    color: inherit;
    padding: 0 2px;
    margin-left: 2px;
    cursor: pointer;
    font-size: 0.9rem;
    line-height: 1;
}
.chip-remove:hover { color: #f87171; }
.chip-form { display: inline; margin: 0; }
.chip-add-form { display: inline; margin: 0; }
.chip-add-input {
    width: 80px;
    padding: 2px 6px;
    font-size: 0.78rem;
    background: transparent;
    border: 1px dashed var(--border);
    border-radius: 12px;
    color: var(--text);
}

.wl-tags-cell { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.wl-dsl {
    background: rgba(99, 102, 241, 0.12);
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 0.82rem;
    word-break: break-word;
}
.wl-excludes { margin-top: 4px; font-size: 0.75rem; color: var(--text-muted); }
.wl-excludes .chip { font-size: 0.72rem; }

.wl-layout {
    display: grid;
    grid-template-columns: 220px 1fr;
    gap: 16px;
    align-items: start;
}
.wl-layout .wl-main { min-width: 0; }
.wl-tag-list {
    list-style: none;
    padding: 8px 0;
    margin: 0;
}
.wl-tag-list li { padding: 0; margin: 0; }
.wl-tag-link {
    display: block;
    padding: 6px 16px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.88rem;
    border-left: 2px solid transparent;
}
.wl-tag-link:hover { background: rgba(255, 255, 255, 0.04); color: var(--text); }
.wl-tag-link.active { color: var(--text); border-left-color: var(--accent, #6366f1); }
.wl-tag-count { color: var(--text-muted); font-size: 0.78rem; }

@media (max-width: 760px) {
    .wl-layout { grid-template-columns: 1fr; }
}

/* Watchlist: URL-import quick-add row ------------------------------- */

.wl-url-import {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
    margin: 0 20px 12px;
    padding: 10px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.wl-url-import-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin: 0;
    white-space: nowrap;
}
.wl-url-import input[type="url"] {
    flex: 1;
    min-width: 240px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 6px 10px;
    color: var(--text);
    font-size: 0.85rem;
}
.wl-url-import-hint {
    flex-basis: 100%;
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Listings: image lightbox ------------------------------------------ */

.thumb[data-lightbox-trigger] {
    cursor: zoom-in;
}
.thumb[data-lightbox-trigger]:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}
.listings-lightbox {
    padding: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    max-width: min(900px, 92vw);
    max-height: 92vh;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.4);
}
.listings-lightbox::backdrop {
    background: rgba(0, 0, 0, 0.65);
}
.listings-lightbox-close-form {
    margin: 0;
    padding: 0;
    position: absolute;
    top: 8px;
    right: 8px;
}
.listings-lightbox-close {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
}
.listings-lightbox-image {
    display: block;
    max-width: 100%;
    max-height: 70vh;
    object-fit: contain;
    background: var(--bg);
}
.listings-lightbox-meta {
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 0.9rem;
}
.listings-lightbox-meta h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
}
.listings-lightbox-row {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    color: var(--text-muted);
}

/* Listings page -- filter bar, view tabs, row actions, pagination ---- */

.listings-view-tabs {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 4px;
}
.listings-view-tab {
    display: inline-flex;
    gap: 6px;
    align-items: center;
    padding: 4px 10px;
    border-radius: 999px;
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.82rem;
    text-decoration: none;
}
.listings-view-tab:hover { color: var(--text); background: var(--surface-hover); }
.listings-view-tab.active {
    color: var(--text);
    background: var(--accent);
    border-color: var(--accent);
}
.listings-view-tab.active .listings-view-count { color: var(--text); }
.listings-view-count {
    color: var(--text-muted);
    font-size: 0.72rem;
    font-variant-numeric: tabular-nums;
}
.text-muted { color: var(--text-muted); font-size: 0.85rem; font-weight: 400; }

.listings-filter {
    margin: 12px 20px 0;
    padding: 8px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.listings-filter > summary {
    cursor: pointer;
    color: var(--text-muted);
    font-size: 0.88rem;
    padding: 4px 0;
}
.listings-filter[open] > summary { color: var(--text); }
.listings-filter-form { padding-top: 8px; }
.listings-mp-check {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-right: 12px;
    font-size: 0.88rem;
    color: var(--text);
}

.listings-table { width: 100%; }
.listings-row { transition: background 0.15s ease; }
.listings-row:focus { outline: 2px solid var(--accent); outline-offset: -2px; }
.listings-row-state-hidden { opacity: 0.55; }
.listings-row-state-bought td:nth-child(2) { text-decoration: line-through; }

.listings-state-chip {
    display: inline-block;
    margin-left: 6px;
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.listings-state-hidden { background: #6b728022; color: var(--text-muted); }
.listings-state-snoozed { background: #3498db22; color: var(--blue); }
.listings-state-interested { background: #00b89422; color: var(--green); }
.listings-state-bought { background: #f39c1222; color: var(--orange); }

/* Listings: unseen badge — shown for listings whose first_seen postdates
   the user's previous /listings visit. Header chip + per-row "NEW" chip. */
.listings-new-count {
    display: inline-block;
    margin-left: 8px;
    padding: 2px 8px;
    border-radius: 10px;
    background: var(--green);
    color: #fff;
    font-size: 0.75rem;
    font-weight: 600;
    vertical-align: middle;
}
.listings-new-chip {
    display: inline-block;
    margin-left: 6px;
    padding: 1px 5px;
    border-radius: 3px;
    background: var(--green);
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.05em;
}

/* Listings: saved views — pinned filter presets above the filter card. */
.listings-saved-views {
    margin: 8px 0 12px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}
.listings-saved-views-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.listings-saved-views-item {
    display: inline-flex;
    align-items: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 2px 4px 2px 10px;
}
.listings-saved-views-link {
    font-size: 0.85rem;
    color: var(--text);
    text-decoration: none;
}
.listings-saved-views-link:hover {
    text-decoration: underline;
}
.listings-saved-views-delete {
    display: inline-flex;
    margin-left: 4px;
}
.listings-saved-views-delete button {
    padding: 0 6px;
    line-height: 1;
}
.listings-saved-views-save {
    display: inline-flex;
    gap: 6px;
    align-items: center;
    margin-left: auto;
}
.listings-saved-views-save input[type="text"] {
    padding: 4px 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--surface);
    color: var(--text);
    min-width: 220px;
}

/* Listings: ad-hoc compare — checkboxes per row + floating bar + grid. */
.listings-compare-check-cell { width: 28px; text-align: center; }
.listings-compare-check { cursor: pointer; }
.listings-compare-check:disabled { cursor: not-allowed; opacity: 0.4; }

.listings-compare-bar {
    position: fixed;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    display: inline-flex;
    align-items: center;
    gap: 12px;
    padding: 8px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
    z-index: 90;
}
.listings-compare-bar-count {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.listings-compare-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px;
    margin-top: 12px;
}
.listings-compare-col {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.listings-compare-image {
    width: 100%;
    max-height: 180px;
    object-fit: contain;
    background: #0001;
}
.listings-compare-title {
    margin: 0;
    font-size: 1rem;
    line-height: 1.3;
}
.listings-compare-title a {
    color: var(--text);
    text-decoration: none;
}
.listings-compare-title a:hover { text-decoration: underline; }
.listings-compare-fields {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 4px 10px;
    margin: 0;
    font-size: 0.85rem;
}
.listings-compare-fields dt {
    color: var(--text-muted);
    font-weight: 500;
}
.listings-compare-fields dd { margin: 0; }
.listings-compare-actions {
    margin-top: auto;
}

.listings-row-actions { position: relative; }
.listings-row-actions > summary {
    list-style: none;
    cursor: pointer;
}
.listings-row-actions > summary::-webkit-details-marker { display: none; }
.listings-row-actions-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 4px);
    z-index: 10;
    min-width: 200px;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}
.listings-row-actions-menu form {
    display: flex;
    gap: 4px;
    align-items: center;
    margin: 0;
}
.listings-row-actions-menu form button { flex: 1; text-align: left; }
.listings-snooze-form select {
    padding: 4px 6px;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.78rem;
}

.listings-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 16px;
    border-top: 1px solid var(--border);
}
.listings-pagination-info {
    color: var(--text-muted);
    font-size: 0.85rem;
    font-variant-numeric: tabular-nums;
}

.listings-update-pill {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    background: var(--surface);
    padding: 6px 8px;
    border-radius: 999px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
    border: 1px solid var(--border);
}

@media (max-width: 760px) {
    .listings-table thead { display: none; }
    .listings-table tr {
        display: block;
        margin: 8px 0;
        padding: 8px;
        border: 1px solid var(--border);
        border-radius: var(--radius);
    }
    .listings-table td { display: block; padding: 4px 0; }
    .listings-row-actions-menu {
        position: static;
        box-shadow: none;
        margin-top: 4px;
    }
}

/* Legal pages: privacy + ToS. Long-form prose; keep line length readable
   and surface the operator-template banner so reviewers and auditors
   know placeholders haven't been replaced yet. */
.legal-content {
    max-width: 70ch;
    line-height: 1.55;
}
.legal-content h3 {
    margin-top: 1.6em;
    margin-bottom: 0.4em;
    font-size: 1.05rem;
}
.legal-content p,
.legal-content ul,
.legal-content ol {
    margin: 0 0 0.8em 0;
}
.legal-content ul,
.legal-content ol {
    padding-left: 1.4em;
}
.legal-content li { margin-bottom: 0.3em; }
.legal-content code {
    font-size: 0.9em;
    padding: 1px 4px;
    background: var(--surface-alt, rgba(127, 127, 127, 0.12));
    border-radius: 3px;
}
.legal-template-banner {
    margin: 12px 0 18px;
    padding: 10px 14px;
    border: 1px solid var(--orange);
    border-radius: var(--radius);
    background: rgba(243, 156, 18, 0.08);
    font-size: 0.9rem;
    line-height: 1.4;
}

.site-footer {
    margin-top: 32px;
    padding: 16px 0;
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.85rem;
    text-align: center;
}
.site-footer a {
    color: var(--text-muted);
    text-decoration: none;
    margin: 0 8px;
}
.site-footer a:hover {
    color: var(--text);
    text-decoration: underline;
}

/* Listings page: classes that replace formerly-inline `style="..."`
   attributes so the page renders under a tightened CSP that no longer
   allows `style-src 'unsafe-inline'`. Visual semantics are unchanged;
   each class encodes exactly what the inline attribute did. */
.listings-form-grow {
    flex: 2;
}
.listings-form-fieldset {
    flex: 2;
    border: 0;
    padding: 0;
}
.listings-form-legend {
    font-size: 0.85rem;
    color: var(--text-muted);
    padding: 0;
    margin-bottom: 4px;
}
.listings-form-actions {
    flex: 0;
    align-self: flex-end;
    display: flex;
    gap: 8px;
}
.listings-condition-text {
    font-size: 0.75rem;
    color: var(--text-muted);
}
.listings-score-good { color: var(--green); }
.listings-score-warn { color: var(--orange); }
.listings-score-bad { color: var(--text-muted); }

/* Score bar: 0..100% fill rendered as two nested divs. The outer track
 * carries the background colour; the inner fill's width is set by
 * ux.js::wireScoreBars from a data-score="N" attribute so we stay
 * inside the CSP (no inline style="..." attribute). */
.score-bar {
    display: inline-block;
    width: 100%;
    max-width: 200px;
    height: 0.6rem;
    background: var(--bg-elevated, rgba(255, 255, 255, 0.05));
    border: 1px solid var(--border, rgba(255, 255, 255, 0.12));
    border-radius: 3px;
    overflow: hidden;
    vertical-align: middle;
}
.score-bar-fill {
    display: block;
    height: 100%;
    width: 0;
    background: var(--green, #2ecc71);
    transition: width 240ms ease-out;
}
.score-bar-fill.score-warn { background: var(--orange, #f39c12); }
.score-bar-fill.score-bad  { background: var(--text-muted, #95a5a6); }
@media (prefers-reduced-motion: reduce) {
    .score-bar-fill { transition: none; }
}
.score-bar-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.score-bar-pct {
    font-variant-numeric: tabular-nums;
    min-width: 3rem;
    text-align: right;
}

/* Watchlist-detail page "currently checking" indicator. The pulse is
 * gated on prefers-reduced-motion: no-preference so vestibular-sensitive
 * users see a static dot instead. */
.wl-active-indicator {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}
.wl-active-dot {
    display: inline-block;
    width: 0.7rem;
    height: 0.7rem;
    border-radius: 50%;
    background: var(--green, #2ecc71);
}
.wl-active-dot.wl-active-dot-idle {
    background: var(--text-muted, #95a5a6);
}
@media (prefers-reduced-motion: no-preference) {
    @keyframes wl-active-pulse {
        0%   { box-shadow: 0 0 0 0 rgba(46, 204, 113, 0.6); }
        70%  { box-shadow: 0 0 0 6px rgba(46, 204, 113, 0); }
        100% { box-shadow: 0 0 0 0 rgba(46, 204, 113, 0); }
    }
    .wl-active-dot {
        animation: wl-active-pulse 1600ms ease-out infinite;
    }
    .wl-active-dot.wl-active-dot-idle { animation: none; }
}

/* Per-marketplace summary table on the watchlist-detail page. */
.wl-mp-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 0.5rem;
}
.wl-mp-table th, .wl-mp-table td {
    text-align: left;
    padding: 0.35rem 0.5rem;
    border-bottom: 1px solid var(--border, rgba(255, 255, 255, 0.08));
}
.wl-mp-table th { color: var(--text-muted, #95a5a6); font-weight: 600; }
.wl-mp-status-ok    { color: var(--green, #2ecc71); }
.wl-mp-status-error { color: var(--red, #e74c3c); }

/* Watchlist-detail history list (recent crawl cycles). */
.wl-history {
    list-style: none;
    padding: 0;
    margin: 0.5rem 0;
}
.wl-history-row {
    display: grid;
    grid-template-columns: minmax(8rem, auto) 7rem auto 1fr;
    gap: 0.5rem;
    padding: 0.3rem 0.5rem;
    border-bottom: 1px solid var(--border, rgba(255, 255, 255, 0.08));
    align-items: center;
}
.wl-history-row.wl-history-error { color: var(--red, #e74c3c); }

/* Listing-detail page layout. */
.listing-detail-grid {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) 2fr;
    gap: 1.5rem;
}
.listing-detail-image img {
    max-width: 100%;
    border-radius: 4px;
    cursor: zoom-in;
}
.listing-detail-meta dl {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.25rem 0.75rem;
    margin: 0.5rem 0;
}
.listing-detail-meta dt { color: var(--text-muted, #95a5a6); }
.listing-detail-score-breakdown {
    margin-top: 0.75rem;
}
.listing-detail-score-breakdown li {
    display: flex;
    justify-content: space-between;
    padding: 0.2rem 0;
    border-bottom: 1px dashed var(--border, rgba(255, 255, 255, 0.08));
}

.listings-first-seen-cell {
    color: var(--text-muted);
}

/* CSP-sweep classes -- extracted from inline styles.
   The CSP header (see app.py security_headers middleware) no longer
   allows `style-src 'unsafe-inline'`, so every former `style="..."`
   attribute moved here. Visual semantics are unchanged; each class
   encodes exactly what the inline attribute did. Grouped roughly by
   utility -> form -> card / layout -> per-template, alphabetically
   inside each group. */

/* Color utilities */
.color-muted { color: var(--text-muted); }
.color-orange { color: var(--orange); }
.color-green { color: var(--green); }

/* Font-size + muted combinations (color + size only -- no weight) */
.muted-xs { color: var(--text-muted); font-size: 0.8rem; }
.muted-sm { color: var(--text-muted); font-size: 0.85rem; }
.muted-md { color: var(--text-muted); font-size: 0.9rem; }

/* Plain font-size utilities */
.fs-xs { font-size: 0.8rem; }
.fs-sm { font-size: 0.85rem; }
.fs-md { font-size: 0.9rem; }
.fs-lg { font-size: 1.2rem; }
.fs-xl { font-size: 1.5rem; }
.fs-xxl { font-size: 2rem; }

/* Margin / padding utilities (Tailwind-ish naming, px-equivalents) */
.m-0 { margin: 0; }
.mt-0 { margin-top: 0; }
.mt-4 { margin-top: 4px; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-20 { margin-top: 20px; }
.mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; }
.mb-12 { margin-bottom: 12px; }
.mb-14 { margin-bottom: 14px; }
.mb-16 { margin-bottom: 16px; }
.ml-8 { margin-left: 8px; }
.pad-20 { padding: 20px; }
.pad-24 { padding: 24px; }
.pad-top-8 { padding-top: 8px; }
.pad-top-24 { padding-top: 24px; }

/* Flex / display utilities */
.d-inline { display: inline; }
.flex-0 { flex: 0; }
.flex-1 { flex: 1; }
.flex-2 { flex: 2; }
.flex-3 { flex: 3; }
.self-flex-end { align-self: flex-end; }
.flex-0-end { flex: 0; align-self: flex-end; }
.opacity-70 { opacity: 0.7; }

/* Width utilities (fixed-pixel and percent only -- continuous
   dynamic widths cannot use a class; see budget.html). */
.w-60p { width: 60%; }
.w-100p { width: 100%; }
.w-120 { width: 120px; }
.w-140 { width: 140px; }

/* User-select utility, for copy-on-click code blocks */
.select-all { user-select: all; }

/* Form: a `<select>` / textarea style that matches the project's
   form control aesthetic (var(--bg) background, var(--border)
   border, var(--radius), 8px-by-12px padding). Used by rules.html,
   watchlist.html, settings.html. */
.form-select {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 12px;
    color: var(--text);
}
.form-textarea {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 12px;
    color: var(--text);
    width: 100%;
    font-family: monospace;
}

/* Inline-flex checkbox label (icon + label gap, cursor:pointer) */
.label-checkbox {
    display: flex;
    gap: 6px;
    align-items: center;
    cursor: pointer;
}

/* OTP / TOTP code input (wide letter spacing, large font, full width) */
.code-input {
    width: 100%;
    letter-spacing: 4px;
    font-size: 1.2rem;
}
.code-input-narrow {
    letter-spacing: 4px;
    font-size: 1.2rem;
}

/* A wide button that fills its container with consistent padding,
   used on share / 2FA login submit buttons. */
.btn-block {
    width: 100%;
    padding: 10px;
}

/* Toast-like inline error banner (red tint) -- used by
   login_2fa.html and settings_2fa_setup.html. */
.banner-error {
    background: #e74c3c22;
    color: var(--red);
    padding: 10px 14px;
    border-radius: var(--radius);
    margin-bottom: 16px;
}
.banner-error-md { font-size: 0.9rem; }

/* Generic "scam score / high-risk" badge banner (solid red) */
.banner-danger {
    background: var(--red);
    color: white;
    padding: 8px 12px;
    border-radius: var(--radius);
    margin-top: 8px;
}

/* Listing image thumbnail in price_history.html */
.listing-detail-image {
    width: 120px;
    height: 120px;
    border-radius: 8px;
    object-fit: cover;
}

/* price_history.html "Current Price" caption */
.price-history-caption {
    color: var(--text-muted);
    font-size: 0.8rem;
    text-transform: uppercase;
}
/* price_history.html top-of-page header row: padding + flex gap */
.price-history-header {
    padding: 20px;
    display: flex;
    gap: 32px;
}

/* "monospace small" cell for rule conditions table */
.cell-monospace-xs {
    font-family: monospace;
    font-size: 0.8rem;
}

/* Centered helper line under auth / share buttons. Slightly different
   margins -- two variants kept to preserve original spacing. */
.center-help-sm {
    text-align: center;
    margin-top: 8px;
    font-size: 0.85rem;
    color: var(--text-muted);
}
.center-help-md {
    text-align: center;
    margin-top: 12px;
    font-size: 0.85rem;
    color: var(--text-muted);
}
.center-help-pad {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
    padding: 20px;
}

/* Help-text under a button (size + muted color + small top margin) */
.muted-sm-mt {
    margin-top: 8px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* Form help text: trailing margin-top + muted + small font.
   Different ordering / wording of the same rule than .muted-sm-mt,
   but identical computed style -- kept as alias for readability of
   the call site. */
.muted-sm-end {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 8px;
}

/* Webhook payload help block */
.webhook-help {
    padding: 20px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* Webhook-secret display + per-page copy blocks: monospace code
   on var(--bg-alt) chip, user-select:all for click-to-copy. Three
   shape variants kept to preserve their original size profile. */
.copy-block {
    display: block;
    padding: 12px;
    background: var(--bg-alt, #1a1d24);
    border-radius: var(--radius);
    user-select: all;
    word-break: break-all;
}
.copy-block-tight {
    display: block;
    padding: 8px;
    background: var(--bg-alt, #1a1d24);
    border-radius: var(--radius);
    user-select: all;
    word-break: break-all;
}
.copy-block-otp {
    display: block;
    padding: 8px 12px;
    background: var(--bg-alt, #1a1d24);
    border-radius: var(--radius);
    word-break: break-all;
    user-select: all;
}
.copy-block-inline {
    display: inline-block;
    padding: 8px 12px;
    background: var(--bg-alt, #1a1d24);
    border-radius: var(--radius);
    user-select: all;
}

/* Word-break helper for long opaque tokens / URLs */
.fs-sm-break { font-size: 0.85rem; word-break: break-all; }
.muted-xs-break { color: var(--text-muted); font-size: 0.8rem; word-break: break-all; }

/* nav / base header right-side group (auto-margin + flex toolbar) */
.nav-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 12px;
}

/* "modal" overlay shells for login_2fa.html and share.html: centred
   full-viewport, plus the card sizes the two pages use. */
.modal-overlay {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}
.modal-card-sm {
    width: 100%;
    max-width: 400px;
}
.modal-card-md {
    width: 100%;
    max-width: 500px;
}

/* Subtle share-card inner highlight panel */
.share-panel {
    background: var(--bg);
    padding: 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
}
.share-keywords { font-size: 1.1rem; font-weight: 600; }
.share-price { font-size: 1.5rem; margin-top: 4px; }
.share-condition { margin-top: 4px; color: var(--text-muted); }

/* Public dashboard row of stats */
.public-stats-row {
    padding: 20px;
    display: flex;
    gap: 24px;
    flex-wrap: wrap;
}
.public-dashboard-footnote {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
    padding: 20px;
}

/* price_index.html intro paragraph */
.price-index-intro {
    padding: 0 20px;
    color: var(--text-muted);
}

/* Rules-form help block (multi-line conditions explanation) */
.rules-help {
    padding: 0 20px 16px;
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* Admin federation: peer-add form help text */
.federation-help {
    padding: 0 20px 16px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* Billing: tier card and current-tier highlight */
.billing-tiers-grid {
    padding: 20px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
}
.billing-tier {
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.billing-tier-current {
    background: rgba(80, 200, 120, 0.08);
}
.billing-tier-list { padding-left: 18px; }
.billing-limit-warn {
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: rgba(255, 80, 80, 0.08);
}
.billing-tier-meta { margin: 0; opacity: 0.7; }
.billing-tier-current-text { margin: 0; font-weight: 600; }

/* settings.html admin tools row */
.admin-tools-row {
    padding: 20px;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* settings.html backup admin row (file-input + flex wrap) */
.backup-row {
    padding: 20px;
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    align-items: center;
}
.backup-form-inline {
    display: flex;
    gap: 8px;
    align-items: center;
}
.backup-form-wrap {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}
.backup-encrypted-row { padding: 0 20px 20px; }
.backup-file-input { font-size: 0.85rem; color: var(--text-muted); }
.backup-passphrase-input { font-size: 0.85rem; }

/* Onboarding niche fieldsets */
.onboarding-fieldset {
    margin: 16px 0;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.onboarding-fieldset-legend { padding: 0 8px; }
.onboarding-preset-label {
    display: block;
    margin: 6px 0;
    cursor: pointer;
}
.onboarding-preset-note {
    margin-left: 24px;
    font-size: 0.9em;
    opacity: 0.7;
}

/* Webhook URL cell -- ellipsis truncation, fixed max width */
.webhook-url-cell {
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Budget progress bar -- the bar track is a static class, the
   inner fill width is dynamic (driven by Jinja `{{ pct }}`) and
   stays inline. See DEBT note at the call site in budget.html. */
.budget-bar-track {
    background: var(--border);
    height: 18px;
    border-radius: 9px;
    overflow: hidden;
}

/* Listings-compare per-cell text colour for score / scam_pct.
   Discrete buckets, picked via Jinja {% if %} -> class. */
.cmp-score-high { color: var(--green); }
.cmp-score-mid { color: var(--orange); }
.cmp-score-low { color: var(--text-muted); }
.cmp-scam-high { color: var(--red, #c0392b); }
.cmp-scam-mid { color: var(--orange); }
.cmp-scam-low { color: var(--text-muted); }

/* admin_ratelimit.html: "headroom" cell colour goes red when within
   20% of the limit. Discrete two-state branching. */
.ratelimit-warn { color: var(--red); }
.ratelimit-ok { color: var(--text-muted); }

/* _kbd_help.html section header row inside shortcut table */
.kbd-section-header {
    padding-top: 8px;
    color: var(--text-muted);
    font-weight: 600;
}

/* watchlist.html row-action cells (small button groups) */
.wl-row-actions {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}
.wl-row-actions-tight {
    display: flex;
    gap: 4px;
}

/* export.html sub-header */
.export-section-title {
    margin-top: 24px;
    margin-bottom: 12px;
    font-size: 0.9rem;
}

/* export.html row of action buttons */
.export-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

/* settings_2fa_setup.html ordered list of setup steps. Browsers
   default `<ol>` to padding-left:40px; the original inline style
   overrode that to 20px to align with the surrounding card padding. */
.ol-tight {
    margin-bottom: 16px;
    padding-left: 20px;
}

/* webhook_secret.html "Each request now carries headers:" paragraph.
   Equivalent to .muted-md + margin-top:16px, kept as one class so the
   call site is a single attribute. */
.muted-md-mt {
    margin-top: 16px;
    font-size: 0.9rem;
    color: var(--text-muted);
}

/* budget.html progress-bar fill. Width is dynamic (driven by Jinja
   {{ pct }} via data-width) and applied at DOMContentLoaded by
   /static/data_styles.js -- this avoids inline `style="..."` which
   the CSP now forbids. The colour buckets are discrete and live as
   three modifier classes. */
.budget-bar-fill {
    height: 100%;
    width: 0;
}
.budget-bar-fill-ok { background: var(--green); }
.budget-bar-fill-warn { background: var(--yellow); }
.budget-bar-fill-over { background: var(--red); }

/* ============================================================
 * Polish pass (typography / spacing / interactive states).
 * Living at the bottom so cascade order keeps the polish wins.
 * Adds nothing structural; only colour, spacing, focus, motion.
 * ============================================================ */

/* Hover-lift for interactive listing rows. The row already gets a
 * background swap on hover (see `tbody tr:hover`); add a subtle
 * shadow so the row visually rises. Motion is colour/shadow only
 * so a position-changing translate doesn't cause table reflow. */
.listings-row {
    box-shadow: inset 0 0 0 0 transparent;
    transition: background var(--transition-base), box-shadow var(--transition-base);
}
.listings-row:hover {
    box-shadow: inset 3px 0 0 0 var(--accent);
}

/* Listings filter card: a touch more breathing room around the
 * summary, and a focus ring matching the rest of the app. */
.listings-filter > summary:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--accent-ring);
    border-radius: var(--radius-sm);
}

/* Settings page: section spacing between cards is consistent
 * via --space-6 on .card. Add a tighter row spacing inside the
 * settings forms so labels and inputs read as one group. */
.pad-20 .form-row + .form-row { padding-top: var(--space-2); }

/* Watchlist sidebar: align tag-link active indicator with the
 * nav-link convention (accent left bar) and tighten typography. */
.wl-tag-link {
    transition: background var(--transition-base), color var(--transition-base),
                border-color var(--transition-base);
}

/* Auth pages: keep the layout, just refine the brand mark + features
 * micro-typography for a calmer feel. */
.auth-features li {
    font-size: var(--fs-sm);
    line-height: var(--lh-base);
}

/* Login_2fa / share modal cards inherit .card shadow now; widen the
 * inner padding so the form doesn't feel cramped. */
.modal-overlay .card { box-shadow: var(--shadow-lg); }

/* Footer polish: subtle separator, comfortable hit targets. */
.site-footer {
    margin-top: var(--space-12);
    padding: var(--space-4) 0;
    font-size: var(--fs-sm);
}
.site-footer a {
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-sm);
    transition: color var(--transition-base), background var(--transition-base);
}
.site-footer a:hover { background: var(--surface-hover); }

/* Make selection match the brand. */
::selection {
    background: var(--accent-soft);
    color: var(--text);
}

/* Code blocks reuse the mono stack token. */
code, kbd, pre, samp { font-family: var(--font-stack-mono); }

/* Universal :focus-visible polish on links and form-affordances that
 * aren't already explicitly styled. */
a:focus-visible,
button:focus-visible,
summary:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

/* Inline form-validation hint. Use .field-error in templates beside the
 * offending input to surface a red message close to the field. */
.field-error {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    margin-top: var(--space-1);
    color: var(--red);
    font-size: var(--fs-xs);
}
.field-error::before {
    content: "!";
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--red);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    line-height: 1;
}
input[aria-invalid="true"],
textarea[aria-invalid="true"],
select[aria-invalid="true"] {
    border-color: var(--red);
}
input[aria-invalid="true"]:focus,
textarea[aria-invalid="true"]:focus,
select[aria-invalid="true"]:focus {
    box-shadow: 0 0 0 3px rgba(231, 76, 60, 0.22);
}

/* ============================================================
 * Retro layer (8-bit / NES + Game Boy, tasteful).
 * Adds brand mark + iconography styling, pixel-frame utilities,
 * score-number treatment, scanlines, power-up animation, and
 * the Game Boy / CRT theme variants.
 * ============================================================ */

/* Headings + brand surfaces use the pixel display font.
 * Press Start 2P renders ~30% taller than equivalent system fonts at the
 * same nominal size; scale heading sizes down so the visual size matches
 * what the body grid expects. */
h1, h2, h3 {
    font-family: var(--font-display);
    letter-spacing: 0;
    line-height: 1.4;
}
h1 { font-size: calc(var(--fs-xl) * 0.75); }
h2 { font-size: calc(var(--fs-lg) * 0.75); }
h3 { font-size: calc(var(--fs-md) * 0.85); }
.card-header h2 { font-size: calc(var(--fs-md) * 0.9); }
.card-header h3 { font-size: calc(var(--fs-sm) * 0.95); }

/* Brand mark in the nav. The cartridge silhouette + wordmark live in
 * /static/logo.svg as paths (no SVG-internal font dependency, CSP safe). */
nav .brand {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    color: var(--text);
    text-decoration: none;
    padding-right: var(--space-3);
    border-right: 1px solid var(--border);
    margin-right: var(--space-2);
}
nav .brand:hover { color: var(--text); }
nav .brand-logo {
    /* Crisp pixel scaling — important for the cartridge silhouette */
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    display: block;
    color: var(--accent);
}
nav .brand-text {
    font-family: var(--font-display);
    /* Press Start 2P at 11px reads about the same height as 14px of the
     * system stack — keep the wordmark visually balanced with the links. */
    font-size: 11px;
    letter-spacing: 0;
    color: var(--text);
}
@media (max-width: 768px) {
    /* On narrow screens the SVG wordmark already conveys the brand;
     * hide the redundant text label to free up nav real estate. */
    nav .brand-text { display: none; }
}

/* Icon class — sits in line with adjacent text, inherits text colour,
 * stays a fixed 1em box. Used by every nav link + button below. */
.icon {
    width: 1em;
    height: 1em;
    vertical-align: -2px;
    fill: currentColor;
    flex-shrink: 0;
}
/* Nav links + buttons get an inline icon + text. Switch the link layout
 * to inline-flex so the icon gap stays consistent. */
nav .links a {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.btn .icon { margin-right: 4px; }

/* Theme-toggle button: keep the icon + label balanced; no special chrome. */
.theme-toggle {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

/* Pixel border utility — superseded by .bevel-card below (16-bit pass).
 * The .pixel-border class is kept as an alias on the bevel rule so older
 * templates render with the new 3D-bevel look without a template churn. */

/* Score-number — for prominent numeric values on stat cards. Pixel font
 * is fine here because the digits are short and the value is visually
 * the focal point. Tabular nums keeps the column aligned. */
.score-number {
    font-family: var(--font-display);
    font-size: calc(var(--fs-2xl) * 0.85);
    font-variant-numeric: tabular-nums;
    line-height: 1.25;
    display: inline-flex;
    align-items: baseline;
    gap: var(--space-2);
}
.score-number .icon {
    width: 0.8em;
    height: 0.8em;
    color: var(--orange);
}

/* Stat-card value: when the template uses the .score-number class we
 * inherit; the plain .value still gets the tabular-nums treatment from
 * the original rule. */
.stat-card .score-number { color: var(--text); }

/* Badges use the display font at small size — looks like a NES HUD chip. */
.badge {
    font-family: var(--font-display);
    font-size: 9px;
    letter-spacing: 0;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    text-transform: uppercase;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.badge .icon {
    width: 10px;
    height: 10px;
}

/* High-score flash — brief gold tint when a stat increases. The JS layer
 * adds the class on stat-value change; CSS handles the animation.
 * Wrapped in prefers-reduced-motion: no-preference so the flash is fully
 * skipped (not just shortened) for vestibular-sensitive users. */
@media (prefers-reduced-motion: no-preference) {
    @keyframes high-score-flash {
        0%   { background: rgba(243, 156, 18, 0.45); color: var(--orange); }
        100% { background: transparent; color: inherit; }
    }
    .high-score-flash {
        animation: high-score-flash 700ms ease-out;
    }
}

/* Optional scanlines overlay. OFF by default — user opts in from Settings.
 * Pure CSS, no JS, pointer-events: none so it never blocks input.
 * Repeating gradient at 8% opacity, 4px stripe, fixed position so it
 * stays put as the page scrolls. */
body.retro-scanlines::after {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 9999;
    background: repeating-linear-gradient(
        to bottom,
        rgba(0, 0, 0, 0.08) 0,
        rgba(0, 0, 0, 0.08) 1px,
        transparent 1px,
        transparent 4px
    );
}

/* Power-up treatment — applied to a listing card / row when
 * price_drop_percent >= 20. Animated sparkling gold frame. The default
 * is a static gold edge; the animation kicks in only when the user
 * hasn't requested reduced motion. */
.power-up {
    box-shadow: inset 3px 0 0 0 var(--orange);
}
/* Animated 3-step colour cycle defined later in the 16-bit retro layer
 * (see @keyframes power-up-pulse-16bit). The static gold edge above is
 * what users with prefers-reduced-motion: reduce see. */

/* Empty-state retro illustration — sits above headline/copy in the
 * _empty.html partial. Pixelated rendering keeps the 64x64 silhouette
 * crisp at any DPR. */
.empty-illustration {
    display: block;
    margin: 0 auto var(--space-4) auto;
    width: 64px;
    height: 64px;
    color: var(--text-muted);
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
}
.empty-headline {
    font-family: var(--font-display);
    font-size: calc(var(--fs-md) * 0.85);
    line-height: 1.4;
    margin-bottom: var(--space-3);
    color: var(--text);
}
.empty-cta { margin-top: var(--space-4); }

/* ============================================================
 * Theme variants — Game Boy + CRT amber.
 * Both swap the palette via the same CSS variables every other
 * rule already consumes. Headings keep the pixel font.
 * ============================================================ */

[data-theme="gameboy"] {
    --bg: #0f380f;
    --surface: #306230;
    --surface-hover: #356c35;
    /* DMG-screen 2-step gradient: a touch brighter at the top fades into
     * the standard surface — feels like a backlit Gallium-green LCD. */
    --surface-gradient: linear-gradient(180deg, #3a7a3a 0%, #2a5a2a 100%);
    --surface-gradient-hover: linear-gradient(180deg, #408540 0%, #306230 100%);
    --border: #8bac0f;
    --bevel-light: rgba(155, 188, 15, 0.55);    /* #9bbc0f highlight */
    --bevel-dark: rgba(15, 56, 15, 0.85);       /* #0f380f shadow */
    --bevel-outline: rgba(15, 56, 15, 0.95);
    --text: #d0ec5f;
    --text-muted: #9bbc0f;
    --accent: #d0ec5f;
    --accent-hover: #e8ff80;
    --accent-soft: rgba(155, 188, 15, 0.22);
    --accent-border: rgba(155, 188, 15, 0.55);
    --accent-ring: rgba(155, 188, 15, 0.32);
    --accent2: #f3a012;
    --green: #9bbc0f;
    --red: #e84d10;
    --orange: #f3a012;
    --blue: #66a0ff;
    --yellow: #f3c012;
    --gold: #f3c012;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.45);
    --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.40);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.55);
}
[data-theme="gameboy"] body,
[data-theme="gameboy"] .stat-card,
[data-theme="gameboy"] .card,
[data-theme="gameboy"] .badge,
[data-theme="gameboy"] .btn {
    font-family: var(--font-display);
}
[data-theme="gameboy"] body {
    /* Pixel font is too dense at full body size — keep readability sane. */
    font-family: var(--font-stack-sans);
}
[data-theme="gameboy"] .icon,
[data-theme="gameboy"] .brand-logo,
[data-theme="gameboy"] .empty-illustration {
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
}

[data-theme="crt"] {
    --bg: #0a0805;
    --surface: #1a1408;
    --surface-hover: #221a0c;
    --surface-gradient: linear-gradient(180deg, #221a0c 0%, #15100a 100%);
    --surface-gradient-hover: linear-gradient(180deg, #2a2010 0%, #1c160b 100%);
    --border: #b4530a;
    --bevel-light: rgba(240, 168, 48, 0.32);
    --bevel-dark: rgba(0, 0, 0, 0.75);
    --bevel-outline: rgba(0, 0, 0, 0.85);
    --text: #f0a830;
    --text-muted: #b88838;       /* lifted from #a07020 for AA on CRT surface */
    --accent: #f0a830;
    --accent-hover: #ffd060;
    --accent-soft: rgba(240, 168, 48, 0.14);
    --accent-border: rgba(240, 168, 48, 0.50);
    --accent-ring: rgba(240, 168, 48, 0.30);
    --accent2: #ffd060;
    --green: #d0d030;
    --red: #ff5530;
    --orange: #ffb040;
    --blue: #80c0ff;
    --yellow: #ffd060;
    --gold: #ffd060;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.6);
    --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.55);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.7);
}
[data-theme="crt"] body {
    /* CRT theme: scanlines applied by JS in base.html (auto-enabled).
     * Body font stays system-stack for readability. */
    text-shadow: 0 0 1px rgba(240, 168, 48, 0.25);
}

/* ============================================================
 * SNES theme — most "menu-y" of the variants. Off-white surface,
 * dark navy text, classic SNES box-art purple, prominent bevels.
 * Built on the same token contract as every other theme.
 * ============================================================ */
[data-theme="snes"] {
    --bg: #d4cfc4;                  /* cream backdrop */
    --surface: #e6e0d4;             /* off-white menu plate */
    --surface-hover: #efe9dc;
    --surface-gradient: linear-gradient(180deg, #efe9dc 0%, #d8d2c5 100%);
    --surface-gradient-hover: linear-gradient(180deg, #f5efe2 0%, #e0dacd 100%);
    --border: #16164c;              /* dark navy box outline */
    --bevel-light: rgba(255, 255, 255, 0.85);
    --bevel-dark: rgba(22, 22, 76, 0.55);
    --bevel-outline: rgba(22, 22, 76, 0.85);
    --text: #16164c;                /* dark navy */
    --text-muted: #4848b0;
    --accent: #4848b0;              /* classic SNES box-art purple */
    --accent-hover: #5a5acc;
    --accent-soft: rgba(72, 72, 176, 0.14);
    --accent-border: rgba(72, 72, 176, 0.50);
    --accent-ring: rgba(72, 72, 176, 0.28);
    --accent2: #e85540;             /* coral red secondary */
    --green: #1c7a3c;
    --red: #e85540;                 /* coral red for warnings */
    --orange: #c87010;
    --blue: #2a4cc8;
    --yellow: #e8b840;
    --gold: #e8b840;                /* gold emphasis */
    --shadow-sm: 0 1px 2px rgba(22, 22, 76, 0.16);
    --shadow-md: 0 4px 14px rgba(22, 22, 76, 0.18);
    --shadow-lg: 0 12px 32px rgba(22, 22, 76, 0.24);
}

/* ============================================================
 * Bevelled surfaces — replaces the flat .pixel-border. Uses a
 * stack of inset box-shadows to compose a 16-bit "raised tile"
 * look:
 *   • top + left  : --bevel-light  (1px highlight)
 *   • bottom + right: --bevel-dark  (1px shadow)
 *   • outer       : --bevel-outline (1px definition)
 * No images, no SVG borders. The previous .pixel-border class is
 * kept as an alias so existing templates still render correctly.
 * ============================================================ */
.bevel-card,
.pixel-border {
    background: var(--surface-gradient, var(--surface));
    border-radius: 0;
    /* shadow order (outer first, inner last):
     *   1) outer 1px outline
     *   2) top highlight
     *   3) left highlight
     *   4) bottom shadow
     *   5) right shadow */
    box-shadow:
        0 0 0 1px var(--bevel-outline, var(--border)),
        inset 0 1px 0 0 var(--bevel-light, rgba(255, 255, 255, 0.10)),
        inset 1px 0 0 0 var(--bevel-light, rgba(255, 255, 255, 0.10)),
        inset 0 -1px 0 0 var(--bevel-dark, rgba(0, 0, 0, 0.45)),
        inset -1px 0 0 0 var(--bevel-dark, rgba(0, 0, 0, 0.45));
    border: none;
}

/* Sunken / pressed variant — swap the bevel direction. Used for
 * input wells and the :active state of bevelled buttons. */
.bevel-card-inset {
    background: var(--bg);
    border-radius: 0;
    box-shadow:
        0 0 0 1px var(--bevel-outline, var(--border)),
        inset 0 1px 0 0 var(--bevel-dark, rgba(0, 0, 0, 0.45)),
        inset 1px 0 0 0 var(--bevel-dark, rgba(0, 0, 0, 0.45)),
        inset 0 -1px 0 0 var(--bevel-light, rgba(255, 255, 255, 0.10)),
        inset -1px 0 0 0 var(--bevel-light, rgba(255, 255, 255, 0.10));
    border: none;
}

/* Apply the gradient surface to the major surface elements so the
 * 16-bit "menu plate" feel comes through without touching the rules
 * that already set border / radius. Older themes that didn't define
 * --surface-gradient fall back to the flat --surface colour. */
nav,
.stat-card,
.card,
.ux-modal,
.toast {
    background: var(--surface-gradient, var(--surface));
}

/* Stat cards adopt the bevel by default (richer SNES feel) while
 * keeping the existing hover lift. */
.stat-card {
    border-radius: 0;
    box-shadow:
        0 0 0 1px var(--bevel-outline, var(--border)),
        inset 0 1px 0 0 var(--bevel-light, rgba(255, 255, 255, 0.10)),
        inset 1px 0 0 0 var(--bevel-light, rgba(255, 255, 255, 0.10)),
        inset 0 -1px 0 0 var(--bevel-dark, rgba(0, 0, 0, 0.45)),
        inset -1px 0 0 0 var(--bevel-dark, rgba(0, 0, 0, 0.45)),
        var(--shadow-sm);
    border: none;
}
.stat-card:hover {
    box-shadow:
        0 0 0 1px var(--bevel-outline, var(--border)),
        inset 0 1px 0 0 var(--bevel-light, rgba(255, 255, 255, 0.10)),
        inset 1px 0 0 0 var(--bevel-light, rgba(255, 255, 255, 0.10)),
        inset 0 -1px 0 0 var(--bevel-dark, rgba(0, 0, 0, 0.45)),
        inset -1px 0 0 0 var(--bevel-dark, rgba(0, 0, 0, 0.45)),
        var(--shadow-md);
}

/* ============================================================
 * Raised buttons — 16-bit gradient + bevel. Highlight at the top,
 * shadow at the bottom; on :active, swap to the sunken bevel for
 * a tactile press feel. Primary buttons darken the gradient slightly
 * so the white text stays legible.
 * ============================================================ */
.btn {
    background: var(--surface-gradient, var(--surface));
    border-radius: var(--radius-sm);
    box-shadow:
        inset 0 1px 0 0 var(--bevel-light, rgba(255, 255, 255, 0.18)),
        inset 0 -1px 0 0 var(--bevel-dark, rgba(0, 0, 0, 0.35)),
        var(--shadow-sm);
}
.btn:hover {
    background: var(--surface-gradient-hover, var(--surface-hover));
}
.btn:active,
.btn[aria-pressed="true"] {
    background: var(--bg);
    box-shadow:
        inset 0 1px 0 0 var(--bevel-dark, rgba(0, 0, 0, 0.35)),
        inset 0 -1px 0 0 var(--bevel-light, rgba(255, 255, 255, 0.10));
    transform: translateY(0);
}
.btn-primary {
    /* Highlight the top edge with a 12% white blend on the accent so the
     * gradient reads as a raised key. color-mix normalises the second
     * stop's percentage so the two stops add up to 100%. */
    background: linear-gradient(180deg,
        color-mix(in srgb, var(--accent) 88%, white) 0%,
        var(--accent) 100%);
    color: #fff;
    box-shadow:
        inset 0 1px 0 0 rgba(255, 255, 255, 0.30),
        inset 0 -1px 0 0 rgba(0, 0, 0, 0.30),
        var(--shadow-sm);
}
.btn-primary:hover {
    background: linear-gradient(180deg,
        color-mix(in srgb, var(--accent-hover) 88%, white) 0%,
        var(--accent-hover) 100%);
}
.btn-primary:active {
    background: var(--accent);
    box-shadow:
        inset 0 1px 0 0 rgba(0, 0, 0, 0.30),
        inset 0 -1px 0 0 rgba(255, 255, 255, 0.16);
}

/* Inset / sunken inputs read as little "wells" in the bevelled UI.
 * Keep the existing border colour fallback for older themes. */
input[type="text"],
input[type="number"],
input[type="password"],
input[type="email"],
input[type="url"],
input[type="search"],
textarea,
select {
    background: var(--bg);
    box-shadow:
        inset 0 1px 0 0 var(--bevel-dark, rgba(0, 0, 0, 0.20)),
        inset 1px 0 0 0 var(--bevel-dark, rgba(0, 0, 0, 0.20)),
        inset 0 -1px 0 0 var(--bevel-light, rgba(255, 255, 255, 0.10)),
        inset -1px 0 0 0 var(--bevel-light, rgba(255, 255, 255, 0.10));
}

/* ============================================================
 * Icon multi-shade rendering — sprite-16bit.svg uses three layers
 * keyed by `currentColor` (mid), `--icon-light`, and `--icon-dark`.
 * Each theme derives the two extras from the surrounding text
 * colour so the icon naturally inherits any hue swap. color-mix
 * has wide modern-browser support (Chrome 111+, Safari 16.4+,
 * Firefox 113+); browsers without it fall back to currentColor
 * for the mid tone, leaving the silhouette intact.
 * ============================================================ */
:root {
    --icon-light: color-mix(in srgb, currentColor 60%, white 40%);
    --icon-dark: color-mix(in srgb, currentColor 60%, black 40%);
}
[data-theme="dark"],
[data-theme="crt"],
[data-theme="gameboy"] {
    --icon-light: color-mix(in srgb, currentColor 70%, white 30%);
    --icon-dark: color-mix(in srgb, currentColor 65%, black 35%);
}
[data-theme="light"],
[data-theme="snes"] {
    --icon-light: color-mix(in srgb, currentColor 55%, white 45%);
    --icon-dark: color-mix(in srgb, currentColor 65%, black 35%);
}

/* Slightly larger native icons read better at body size now that
 * each glyph carries shading. Bump the box up a hair from 1em → 1.1em. */
.icon {
    width: 1.1em;
    height: 1.1em;
}

/* ============================================================
 * Power-up: three-step 16-bit colour cycle (gold → coral → gold).
 * Still gated on prefers-reduced-motion: no-preference so the
 * static gold edge is what users with reduced motion see.
 * ============================================================ */
@media (prefers-reduced-motion: no-preference) {
    @keyframes power-up-pulse-16bit {
        0%   { box-shadow: inset 3px 0 0 0 var(--orange), 0 0 0 1px rgba(243, 156, 18, 0.20); }
        33%  { box-shadow: inset 3px 0 0 0 var(--gold, #ffd060), 0 0 0 1px rgba(255, 208, 96, 0.40); }
        66%  { box-shadow: inset 3px 0 0 0 var(--accent2, #ff7eb3), 0 0 0 1px rgba(255, 126, 179, 0.35); }
        100% { box-shadow: inset 3px 0 0 0 var(--orange), 0 0 0 1px rgba(243, 156, 18, 0.20); }
    }
    .power-up {
        animation: power-up-pulse-16bit 2400ms ease-in-out infinite;
    }
}

/* Empty-state illustrations now render at 96x96 native to match the
 * larger pixel grid used by the 16-bit sprite redraws. Pixelated
 * rendering keeps the silhouette crisp at any DPR. */
.empty-illustration {
    width: 96px;
    height: 96px;
}

/* Game Boy theme: prefer the 1.1em icon size and bevel highlights using
 * the DMG palette pair already declared in the theme block. */
[data-theme="gameboy"] .bevel-card,
[data-theme="gameboy"] .pixel-border,
[data-theme="gameboy"] .stat-card {
    /* slightly chunkier 2px highlight reads better on Gallium green */
    box-shadow:
        0 0 0 1px var(--bevel-outline, var(--border)),
        inset 0 2px 0 0 var(--bevel-light, rgba(155, 188, 15, 0.55)),
        inset 2px 0 0 0 var(--bevel-light, rgba(155, 188, 15, 0.55)),
        inset 0 -2px 0 0 var(--bevel-dark, rgba(15, 56, 15, 0.85)),
        inset -2px 0 0 0 var(--bevel-dark, rgba(15, 56, 15, 0.85));
}

/* Reduced motion: kill non-essential transitions and animations.
 * Keep instant state swaps; users with vestibular sensitivity get
 * a flat interface but no information is hidden. */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }
    .btn:hover,
    .stat-card:hover,
    .listings-row:hover {
        transform: none !important;
    }
}

/* ============================================================
 * Theme picker (Settings -> Appearance).
 * Radio-group with a small two-tone swatch per theme so the
 * surface and accent of each art style is visible at a glance,
 * regardless of which theme is currently active. Colour values
 * are CSP-safe (no inline styles): each theme has its own
 * .theme-swatch-<name> class.
 * ============================================================ */
.theme-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 12px;
    margin: 0;
}
.theme-picker > legend {
    padding: 0 6px;
    font-weight: 600;
}
.theme-option {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 6px 8px;
    border: 1px solid transparent;
    border-radius: 4px;
}
.theme-option:hover {
    background: var(--surface-hover);
}
.theme-option input[type="radio"]:checked + .theme-swatch {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}
.theme-swatch {
    display: inline-flex;
    width: 36px;
    height: 18px;
    border-radius: 3px;
    overflow: hidden;
    border: 1px solid var(--border);
}
.theme-swatch-surface,
.theme-swatch-accent {
    display: inline-block;
    width: 50%;
    height: 100%;
}
/* Per-theme surface + accent colors. Hard-coded (not var()) so
 * the swatches always show that theme's identity, not whatever
 * is currently active. */
.theme-swatch-dark    .theme-swatch-surface { background: #1f2436; }
.theme-swatch-dark    .theme-swatch-accent  { background: #7d6ef0; }
.theme-swatch-light   .theme-swatch-surface { background: #ffffff; }
.theme-swatch-light   .theme-swatch-accent  { background: #5a4bd1; }
.theme-swatch-gameboy .theme-swatch-surface { background: #306230; }
.theme-swatch-gameboy .theme-swatch-accent  { background: #d0ec5f; }
.theme-swatch-snes    .theme-swatch-surface { background: #e6e0d4; }
.theme-swatch-snes    .theme-swatch-accent  { background: #16164c; }
.theme-swatch-crt     .theme-swatch-surface { background: #1a1408; }
.theme-swatch-crt     .theme-swatch-accent  { background: #f0a830; }
