/**
 * Room Paint Visualizer — Unified Visualizer Stylesheet
 *
 * Single source of truth for the visualizer page.
 * Contains: design tokens, utilities, theme reset, and all layout/component styles.
 * Replaces the legacy 5-file chain (tokens → utilities → visualizer → modern → v2).
 */

/* ================================================================
   1. DESIGN TOKENS
   ================================================================ */

:root {
    /* ── Colour ─────────────────────────────────── */
    --rpv-color-bg: #f9fafb;
    --rpv-color-surface: #ffffff;
    --rpv-color-text: #111827;
    --rpv-color-muted: #6b7280;
    --rpv-color-border: #6b728098;
    --rpv-color-accent: #0D2C4C;
    --rpv-color-focus: #0D2C4C;
    --rpv-color-hover: #f3f4f6;
    --rpv-compare-a-color: #0D2C4C;
    --rpv-compare-b-color: #DC2626;

    /* Glassmorphism surfaces */
    --rpv-glass-bg: rgba(255, 255, 255, 0.70);
    --rpv-glass-sheet-bg: rgba(150, 150, 150, 0.20);
    --rpv-glass-sheet-border: rgba(150, 150, 150, 0.15);
    --rpv-glass-border: rgba(255, 255, 255, 0.3);
    --rpv-glass-blur: 12px;

    /* Glassmorphism layered shadows */
    --rpv-glass-shadow:
        0 8px 32px rgba(0, 0, 0, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.50),
        inset 0 -1px 0 rgba(255, 255, 255, 0.10),
        inset 0 0 4px 2px rgba(255, 255, 255, 0.2);
    --rpv-glass-shadow-btn:
        0 8px 32px rgba(0, 0, 0, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.5),
        inset 0 -1px 0 rgba(255, 255, 255, 0.1),
        inset 0 0 10px 5px rgba(255, 255, 255, 0.5);
    --rpv-glass-shadow-btn-hover:
        0 10px 36px rgba(0, 0, 0, 0.12),
        inset 0 1px 0 rgba(255, 255, 255, 0.6),
        inset 0 -1px 0 rgba(255, 255, 255, 0.1),
        inset 0 0 12px 6px rgba(255, 255, 255, 0.55);

    /* ── Spacing (4-px grid) ────────────────────── */
    --rpv-space-1: 4px;
    --rpv-space-2: 8px;
    --rpv-space-3: 12px;
    --rpv-space-4: 16px;
    --rpv-space-5: 24px;
    --rpv-space-6: 32px;
    --rpv-space-7: 48px;
    --rpv-space-8: 64px;

    /* ── Typography ─────────────────────────────── */
    --rpv-font-family: inherit;
    --rpv-font-size-xs: 0.6875rem;
    --rpv-font-size-sm: 0.75rem;
    --rpv-font-size-base: 0.875rem;
    --rpv-font-size-md: 1rem;
    --rpv-font-size-lg: 1.25rem;
    --rpv-font-size-xl: 1.5rem;
    --rpv-font-weight-normal: 400;
    --rpv-font-weight-medium: 500;
    --rpv-font-weight-bold: 600;

    /* ── Border radius ──────────────────────────── */
    --rpv-radius-sm: 8px;
    --rpv-radius-md: 12px;
    --rpv-radius-lg: 16px;
    --rpv-radius-xl: 24px;
    --rpv-radius-full: 9999px;

    /* ── Shadows ─────────────────────────────────── */
    --rpv-shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
    --rpv-shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.06);
    --rpv-shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --rpv-shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.10);
    --rpv-shadow-xl: 0 16px 48px rgba(0, 0, 0, 0.12);

    /* ── Motion ──────────────────────────────────── */
    --rpv-duration-fast: 120ms;
    --rpv-duration-normal: 200ms;
    --rpv-duration-slow: 350ms;
    --rpv-ease-default: cubic-bezier(0.25, 0.1, 0.25, 1);
    --rpv-ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
    --rpv-ease-out: cubic-bezier(0, 0, 0.2, 1);

    /* Shorthand transitions */
    --rpv-motion-color: var(--rpv-duration-normal) var(--rpv-ease-default);
    --rpv-motion-ui: var(--rpv-duration-fast) var(--rpv-ease-out);
    --rpv-motion-sheet: var(--rpv-duration-slow) var(--rpv-ease-spring);

    /* ── Z-index scale ───────────────────────────── */
    --rpv-z-base: 1;
    --rpv-z-toolbar: 400;
    --rpv-z-overlay: 420;
    --rpv-z-sheet: 450;
    --rpv-z-toast: 500;

    /* ── Safe-area insets (notch / home-bar devices) ─ */
    /* Default 0px — overridden below when env() is supported */
    --rpv-safe-bottom: 0px;
    --rpv-safe-left: 0px;
    --rpv-safe-right: 0px;

    /* ── Canvas aspect ratio (W:H) — override per-instance via inline style ─ */
    --rpv-canvas-ar-w: 4;
    /* numerator   */
    --rpv-canvas-ar-h: 3;
    /* denominator */

    /* ── Viewport top offset — JS writes measured container offsetTop here ─ */
    --rpv-topbar-h: 0px;
}

/* Override safe-area vars on devices that expose env() insets */
@supports (padding: env(safe-area-inset-bottom)) {
    :root {
        --rpv-safe-bottom: env(safe-area-inset-bottom, 0px);
        --rpv-safe-left: env(safe-area-inset-left, 0px);
        --rpv-safe-right: env(safe-area-inset-right, 0px);
    }
}

/* ================================================================
   2. UTILITIES
   ================================================================ */

.rpv-sr-only,
.rpv-visually-hidden {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

.rpv-viz [class*="rpv-"]:focus-visible {
    outline: 2px solid var(--rpv-color-focus);
    outline-offset: 2px;
}

.rpv-touch-target {
    min-height: 44px;
    min-width: 44px;
}

/* ================================================================
   3. THEME NEUTRALIZER — reset WordPress theme button styles
   ================================================================ */

.rpv-viz :is(button, [type="button"], [type="submit"]) {
    --btn-brd-radius: revert;
    --btn-bgcolor: transparent;
    --btn-bgcolor-hover: transparent;
    --btn-brd-width: 0;
    --btn-brd-color: transparent;
    --btn-brd-color-hover: transparent;
    --btn-color: inherit;
    --btn-color-hover: inherit;
    --btn-box-shadow: none;
    --btn-box-shadow-hover: none;
    --btn-height: auto;
    --btn-padding: 0;
    --btn-font-size: inherit;
    --btn-font-weight: inherit;
    --btn-transform: none;
    appearance: none;
    -webkit-appearance: none;
}

/* ================================================================
   4. ROOT SHELL
   ================================================================ */

/* Viewport-bounded height for the visualizer shell.
   dvh = dynamic viewport height (shrinks when mobile browser chrome is visible).
   --rpv-topbar-h is set by JS to the measured container top-offset so the
   visualizer never extends below the visible viewport even when a sticky
   page header is present. */
.rpv-viz {
    --rpv-viz-height: calc(100dvh - var(--rpv-topbar-h));
}

@supports not (height: 100dvh) {
    .rpv-viz {
        --rpv-viz-height: calc(100vh - var(--rpv-topbar-h));
    }
}

.rpv-viz {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    /* max-width: 1200px; */
    margin: 0 auto;
    gap: 0;
    font-family: var(--rpv-font-family);
    color: var(--rpv-color-text);
    background: var(--rpv-color-bg);
    border-radius: var(--rpv-radius-lg);
    overflow: hidden;
    height: var(--rpv-viz-height, 100dvh);
    /* Contain internal layout — no theme flex leak */
    box-sizing: border-box;
}

.rpv-viz *,
.rpv-viz *::before,
.rpv-viz *::after {
    box-sizing: border-box;
}

/* ================================================================
   5. STAGE — canvas + floating overlays
   ================================================================ */

.rpv-viz__stage {
    position: relative;
    width: 100%;
    flex: 1 1 auto;
    min-height: 200px;
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow: hidden;
    /* Reserve space for drawer handle + device home bar */
    padding-bottom: calc(44px + var(--rpv-safe-bottom));
}

.rpv-viz__stage .rpv-canvas-wrapper {
    position: relative;
    width: 100%;
    /* AR driven by tokens — shortcode can override via inline style vars */
    aspect-ratio: var(--rpv-canvas-ar-w) / var(--rpv-canvas-ar-h);
    /* max-height: 100% contains the wrapper to the stage's flex height;
       when height-constrained the browser reduces width via aspect-ratio */
    max-height: 100%;
    min-height: 150px;
    margin: 0 auto;
    background: var(--rpv-color-surface);
    border-radius: var(--rpv-radius-lg);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(107, 114, 128, 0.22);
    box-shadow:
        0 3px 10px rgba(15, 23, 42, 0.08),
        0 18px 34px rgba(15, 23, 42, 0.08);
}

/* Placeholder state when canvas is empty */
.rpv-viz__stage .rpv-canvas-wrapper:empty::before {
    content: 'Select a room to begin';
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    min-height: 150px;
    color: var(--rpv-color-muted);
    font-size: var(--rpv-font-size-sm);
    text-align: center;
    padding: var(--rpv-space-4);
}

.rpv-viz__stage .rpv-canvas-wrapper::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    pointer-events: none;
    /* Subtle inner rim and falloff to soften the canvas cutoff. */
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.68),
        inset 0 0 0 1px rgba(255, 255, 255, 0.30),
        inset 0 -14px 30px rgba(15, 23, 42, 0.06);
}

.rpv-viz__stage .rpv-canvas,
.rpv-viz__stage canvas {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.rpv-viz__stage .rpv-loading {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.6);
    color: var(--rpv-color-muted);
    font-size: var(--rpv-font-size-base);
    z-index: var(--rpv-z-base);
}

.rpv-viz__stage .rpv-loading p {
    margin: 0;
}

.rpv-viz__stage .rpv-error {
    position: absolute;
    bottom: var(--rpv-space-4);
    left: var(--rpv-space-4);
    right: var(--rpv-space-4);
    background: #fef2f2;
    color: #b91c1c;
    padding: var(--rpv-space-3) var(--rpv-space-4);
    border-radius: var(--rpv-radius-sm);
    border-left: 4px solid #b91c1c;
    font-size: var(--rpv-font-size-sm);
    z-index: var(--rpv-z-base);
}

/* ================================================================
   6. OVERLAY BAR — floating on top of canvas (hidden by default)
   ================================================================ */

.rpv-viz__overlay-bar {
    display: none;
    /* Unified: hidden until toggled */
    position: absolute;
    top: var(--rpv-space-3);
    left: var(--rpv-space-3);
    right: var(--rpv-space-3);
    z-index: var(--rpv-z-overlay);
    flex-wrap: wrap;
    align-items: center;
    gap: var(--rpv-space-2);
    padding: var(--rpv-space-3) var(--rpv-space-4);
    background: var(--rpv-glass-bg);
    border: 1px solid var(--rpv-glass-border);
    border-radius: var(--rpv-radius-xl);
    backdrop-filter: blur(var(--rpv-glass-blur));
    -webkit-backdrop-filter: blur(var(--rpv-glass-blur));
    transition: opacity var(--rpv-duration-normal) var(--rpv-ease-out),
        box-shadow var(--rpv-duration-normal) var(--rpv-ease-out);
    box-shadow: var(--rpv-glass-shadow);
    overflow: hidden;
    min-width: 0;
}

/* Show overlay bar when toggled open — Unified for all devices */
.rpv-viz__overlay-bar.rpv-viz__overlay-bar--open {
    display: flex;
    animation: rpv-toolbar-slide-down 280ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

@keyframes rpv-toolbar-slide-down {
    from {
        opacity: 0;
        transform: translateY(-12px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.rpv-viz__overlay-bar::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.8), transparent);
    pointer-events: none;
}

.rpv-viz__overlay-bar::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 1px;
    height: 100%;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.8), transparent, rgba(255, 255, 255, 0.3));
    pointer-events: none;
}

.rpv-viz__overlay-bar>* {
    min-width: 0;
}

/* Room categories row */
.rpv-viz__overlay-bar .rpv-viz__room-categories {
    order: 1;
}

.rpv-viz__room-categories {
    display: flex;
    gap: var(--rpv-space-1);
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x;
    overscroll-behavior-x: contain;
    flex: 1 1 100%;
    min-width: 0;
    padding: var(--rpv-space-1) 0;
}

.rpv-viz__room-categories::-webkit-scrollbar {
    display: none;
}

.rpv-viz__room-categories.rpv-dragging {
    cursor: grabbing;
    user-select: none;
    -webkit-user-select: none;
}

.rpv-viz__room-categories .rpv-viz__room-category-pill,
.rpv-viz__palette-bar .rpv-viz__palette-pill {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    min-height: 32px;
    padding: var(--rpv-space-1) var(--rpv-space-3);
    border: 1px solid var(--rpv-glass-border);
    border-radius: var(--rpv-radius-full);
    background: var(--rpv-glass-bg);
    backdrop-filter: blur(var(--rpv-glass-blur));
    -webkit-backdrop-filter: blur(var(--rpv-glass-blur));
    color: var(--rpv-color-muted);
    font-size: var(--rpv-font-size-xs);
    font-weight: var(--rpv-font-weight-medium);
    white-space: nowrap;
    cursor: pointer;
    line-height: 1.4;
    transition: background var(--rpv-motion-ui),
        color var(--rpv-motion-ui),
        border-color var(--rpv-motion-ui),
        box-shadow var(--rpv-motion-ui),
        transform var(--rpv-motion-ui);
    box-shadow: var(--rpv-glass-shadow-btn);
}

.rpv-viz__room-categories .rpv-viz__room-category-pill:hover,
.rpv-viz__palette-bar .rpv-viz__palette-pill:hover {
    background: rgba(255, 255, 255, 0.85);
    color: var(--rpv-color-text);
    transform: translateY(-1px);
    box-shadow: var(--rpv-glass-shadow-btn-hover);
}

.rpv-viz__room-categories .rpv-viz__room-category-pill[aria-pressed="true"],
.rpv-viz__palette-bar .rpv-viz__palette-pill[aria-pressed="true"] {
    background: var(--rpv-color-accent);
    border-color: var(--rpv-color-accent);
    color: #fff;
    box-shadow: 0 2px 10px rgba(13, 44, 76, 0.25);
}

/* Room thumbnail bar */
.rpv-viz__overlay-bar .rpv-viz__room-bar {
    order: 2;
}

.rpv-viz__room-bar {
    display: flex;
    gap: var(--rpv-space-2);
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    flex: 1 1 100%;
    min-width: 0;
    padding: var(--rpv-space-1) 0;
}

.rpv-viz__room-bar::-webkit-scrollbar {
    display: none;
}

.rpv-viz__room-empty {
    display: inline-flex;
    align-items: center;
    min-height: 36px;
    padding: 0 var(--rpv-space-3);
    border-radius: var(--rpv-radius-full);
    background: rgba(255, 255, 255, 0.55);
    border: 1px dashed var(--rpv-glass-border);
    color: var(--rpv-color-muted);
    font-size: var(--rpv-font-size-xs);
    white-space: nowrap;
}

.rpv-viz__room-thumb {
    flex: 0 0 auto;
    width: 64px;
    height: 48px;
    border-radius: var(--rpv-radius-sm);
    border: 2px solid transparent;
    overflow: hidden;
    cursor: pointer;
    transition: border-color var(--rpv-motion-ui),
        transform var(--rpv-motion-ui),
        box-shadow var(--rpv-motion-ui);
    box-shadow: var(--rpv-shadow-xs);
}

.rpv-viz__room-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.rpv-viz__room-thumb:hover {
    transform: translateY(-1px);
    box-shadow: var(--rpv-shadow-sm);
}

.rpv-viz__room-thumb--active {
    border-color: var(--rpv-color-accent);
    box-shadow: 0 0 0 2px rgba(13, 44, 76, 0.2);
}

/* Palette pill bar */
.rpv-viz__overlay-bar .rpv-viz__palette-bar {
    order: 3;
}

.rpv-viz__palette-bar {
    display: flex;
    gap: var(--rpv-space-2);
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x;
    overscroll-behavior-x: contain;
    flex: 1 1 100%;
    min-width: 0;
    padding: var(--rpv-space-1) 0;
}

.rpv-viz__palette-bar::-webkit-scrollbar {
    display: none;
}

.rpv-viz__palette-bar.rpv-dragging {
    cursor: grabbing;
    user-select: none;
    -webkit-user-select: none;
}

.rpv-viz__palette-bar .rpv-viz__palette-pill {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    min-height: 36px;
    padding: var(--rpv-space-1) var(--rpv-space-3);
    border: 1px solid var(--rpv-glass-border);
    border-radius: var(--rpv-radius-full);
    background: var(--rpv-glass-bg);
    backdrop-filter: blur(var(--rpv-glass-blur));
    -webkit-backdrop-filter: blur(var(--rpv-glass-blur));
    color: var(--rpv-color-muted);
    font-size: var(--rpv-font-size-xs);
    font-weight: var(--rpv-font-weight-medium);
    white-space: nowrap;
    cursor: pointer;
    transition: background var(--rpv-motion-ui),
        color var(--rpv-motion-ui),
        border-color var(--rpv-motion-ui),
        box-shadow var(--rpv-motion-ui),
        transform var(--rpv-motion-ui);
    line-height: 1.4;
    box-shadow: var(--rpv-glass-shadow-btn);
}

.rpv-viz__palette-bar .rpv-viz__palette-pill:hover {
    background: rgba(255, 255, 255, 0.85);
    color: var(--rpv-color-text);
    transform: translateY(-1px);
    box-shadow: var(--rpv-glass-shadow-btn-hover);
}

.rpv-viz__palette-bar .rpv-viz__palette-pill[aria-pressed="true"] {
    background: var(--rpv-color-accent);
    border-color: var(--rpv-color-accent);
    color: #fff;
    box-shadow: 0 2px 10px rgba(13, 44, 76, 0.25);
}

/* ================================================================
   7. ACTIVE COLOR CHIP — floating on canvas
   ================================================================ */

.rpv-viz__compare-chips {
    position: absolute;
    bottom: var(--rpv-space-3);
    left: var(--rpv-space-3);
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: var(--rpv-space-2);
    z-index: var(--rpv-z-overlay);
    pointer-events: none;
}

.rpv-viz__active-color {
    pointer-events: auto;
    display: inline-flex;
    align-items: center;
    gap: var(--rpv-space-2);
    padding: var(--rpv-space-1) var(--rpv-space-2) var(--rpv-space-1) var(--rpv-space-1);
    background: var(--rpv-glass-bg);
    border: 1px solid var(--rpv-glass-border);
    border-radius: var(--rpv-radius-full);
    backdrop-filter: blur(var(--rpv-glass-blur));
    -webkit-backdrop-filter: blur(var(--rpv-glass-blur));
    box-shadow: var(--rpv-glass-shadow);
    font-size: var(--rpv-font-size-sm);
    font-weight: var(--rpv-font-weight-medium);
    color: var(--rpv-color-text);
    transition: opacity var(--rpv-duration-normal) var(--rpv-ease-out),
        transform var(--rpv-duration-normal) var(--rpv-ease-out);
}

.rpv-viz__active-color-swatch {
    width: 28px;
    height: 28px;
    border-radius: var(--rpv-radius-full);
    border: 1px solid rgba(255, 255, 255, 0.6);
    box-shadow: var(--rpv-shadow-xs);
    flex-shrink: 0;
}

.rpv-viz__active-color-label {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 180px;
}

/* A/B role badge inside chip */
.rpv-viz__active-color-badge {
    display: none;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: var(--rpv-radius-full);
    font-size: 10px;
    font-weight: 700;
    line-height: 1;
    flex-shrink: 0;
}

/* Show badge + accent border when compare mode is active */
.rpv-viz__active-color--compare-a {
    border-color: var(--rpv-color-accent);
}

.rpv-viz__active-color--compare-a .rpv-viz__active-color-badge {
    display: inline-flex;
    background: var(--rpv-color-accent);
    color: #fff;
}

/* B chip — mirrors A chip but uses orange accent */
.rpv-viz__compare-color {
    pointer-events: auto;
    display: inline-flex;
    align-items: center;
    gap: var(--rpv-space-2);
    padding: var(--rpv-space-1) var(--rpv-space-2) var(--rpv-space-1) var(--rpv-space-1);
    background: var(--rpv-glass-bg);
    border: 1px solid #DC2626;
    border-radius: var(--rpv-radius-full);
    backdrop-filter: blur(var(--rpv-glass-blur));
    -webkit-backdrop-filter: blur(var(--rpv-glass-blur));
    box-shadow: var(--rpv-glass-shadow);
    font-size: var(--rpv-font-size-sm);
    font-weight: var(--rpv-font-weight-medium);
    color: var(--rpv-color-text);
    transition: opacity var(--rpv-duration-normal) var(--rpv-ease-out);
}

.rpv-viz__compare-color .rpv-viz__active-color-badge {
    display: inline-flex;
    background: var(--rpv-compare-b-color);
    color: #fff;
    width: 18px;
    height: 18px;
    border-radius: var(--rpv-radius-full);
    font-size: 10px;
    font-weight: 700;
    line-height: 1;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* B marker on grid swatch */
.rpv-viz__drawer-grid .rpv-color-item.rpv-compare .rpv-color-swatch {
    outline: 2px solid var(--rpv-compare-b-color);
    outline-offset: 2px;
}

.rpv-viz__drawer-grid .rpv-color-item.rpv-compare::after {
    content: 'B';
    position: absolute;
    top: 2px;
    right: 2px;
    background: var(--rpv-compare-b-color);
    color: #fff;
    font-size: 9px;
    font-weight: 700;
    line-height: 1;
    padding: 1px 3px;
    border-radius: 3px;
}

/* ================================================================
   8. FLOATING STAGE CONTROLS
   ================================================================ */

.rpv-viz__stage-controls {
    position: absolute;
    bottom: calc(44px + var(--rpv-safe-bottom) + var(--rpv-space-3));
    right: var(--rpv-space-4);
    z-index: var(--rpv-z-overlay);
    display: flex;
    gap: var(--rpv-space-2);
}

.rpv-viz__stage-controls .rpv-button {
    display: inline-flex;
    align-items: center;
    gap: var(--rpv-space-1);
    padding: var(--rpv-space-2) var(--rpv-space-3);
    border: 1px solid var(--rpv-glass-border);
    border-radius: var(--rpv-radius-full);
    background: var(--rpv-glass-bg);
    backdrop-filter: blur(var(--rpv-glass-blur));
    -webkit-backdrop-filter: blur(var(--rpv-glass-blur));
    color: var(--rpv-color-text);
    font-size: var(--rpv-font-size-sm);
    font-weight: var(--rpv-font-weight-medium);
    cursor: pointer;
    white-space: nowrap;
    transition: background var(--rpv-motion-ui),
        color var(--rpv-motion-ui),
        box-shadow var(--rpv-motion-ui),
        transform var(--rpv-motion-ui);
    box-shadow: var(--rpv-glass-shadow-btn);
    width: auto;
    margin-top: 0;
    min-height: 44px;
    min-width: 44px;
}

.rpv-viz__stage-controls .rpv-button:hover {
    background: rgba(255, 255, 255, 0.85);
    transform: translateY(-1px);
    box-shadow: var(--rpv-glass-shadow-btn-hover);
}

.rpv-viz__stage-controls .rpv-button[aria-pressed="true"] {
    background: var(--rpv-color-accent);
    border-color: var(--rpv-color-accent);
    color: #fff;
    box-shadow: 0 2px 10px rgba(13, 44, 76, 0.3);
}

.rpv-viz__btn-icon {
    font-size: var(--rpv-font-size-md);
    line-height: 1;
}

.rpv-viz__btn-label {
    line-height: 1;
}

.rpv-stage-compare-meta {
    position: absolute;
    top: var(--rpv-space-4);
    left: 50%;
    transform: translateX(-50%);
    z-index: var(--rpv-z-overlay);
    display: flex;
    gap: var(--rpv-space-4);
    pointer-events: none;
    white-space: nowrap;
}

.rpv-stage-compare-label {
    padding: var(--rpv-space-1) var(--rpv-space-3);
    background: rgba(0, 0, 0, 0.5);
    color: #fff;
    border-radius: var(--rpv-radius-full);
    font-size: var(--rpv-font-size-xs);
    font-weight: var(--rpv-font-weight-medium);
}

/* ================================================================
   9. DRAWER — collapsible bottom panel
   ================================================================ */

.rpv-viz__drawer {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    width: 100%;
    background: var(--rpv-color-surface);
    border-top: 1px solid var(--rpv-color-border);
    border-radius: var(--rpv-radius-lg) var(--rpv-radius-lg) var(--rpv-radius-lg) var(--rpv-radius-lg);
    transition: max-height 360ms cubic-bezier(0.22, 0.61, 0.36, 1);
    will-change: max-height;
    overflow: hidden;
    z-index: var(--rpv-z-sheet);
    /* Flex child sizing — prevent parent from forcing height */
    flex: 0 0 auto;
    box-shadow: var(--rpv-shadow-lg);
    /* Pad scrollable content clear of device home bar */
    padding-bottom: var(--rpv-safe-bottom);
}

.rpv-viz__drawer.rpv-viz__drawer--dragging {
    transition: none;
}

.rpv-viz__drawer.rpv-viz__drawer--opening-full {
    animation: rpv-drawer-open-bounce 420ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

@keyframes rpv-drawer-open-bounce {
    0% {
        transform: translateY(6px);
    }

    55% {
        transform: translateY(-4px);
    }

    100% {
        transform: translateY(0);
    }
}

/* Drawer states — max-height controls visible size.
   Simplified to 2 states: collapsed (44px) or full (expand to content).
   Capped at calc(100% - 44px) so the drawer never extends above the .rpv-viz
   container, keeping the handle always on-screen regardless of viewport size. */
.rpv-viz__drawer--collapsed {
    max-height: 44px;
}

.rpv-viz__drawer--half {
    max-height: calc(50% - 22px);
}

.rpv-viz__drawer--full {
    max-height: calc(100% - 44px);
}

/* ── Drawer handle ──────────────────────────────── */

.rpv-viz__drawer-handle {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 44px;
    cursor: grab;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    flex-shrink: 0;
}

.rpv-viz__drawer-handle:active {
    cursor: grabbing;
}

.rpv-viz__drawer-handle-bar {
    width: 40px;
    height: 4px;
    border-radius: var(--rpv-radius-full);
    background: var(--rpv-color-border);
    transition: background var(--rpv-motion-ui);
}

.rpv-viz__drawer-handle:hover .rpv-viz__drawer-handle-bar {
    background: var(--rpv-color-muted);
}

/* Chevron state indicator — rotates based on aria-expanded */
.rpv-viz__drawer-chevron {
    position: absolute;
    right: var(--rpv-space-4);
    top: 50%;
    transform: translateY(-50%) rotate(0deg);
    width: 16px;
    height: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--rpv-color-muted);
    transition: transform 280ms var(--rpv-ease-out), color var(--rpv-motion-ui);
    pointer-events: none;
}

.rpv-viz__drawer-chevron::before {
    content: '';
    display: block;
    width: 8px;
    height: 8px;
    border-right: 2px solid currentColor;
    border-top: 2px solid currentColor;
    transform: rotate(-45deg) translateY(2px);
    transition: border-color var(--rpv-motion-ui);
}

/* When drawer is open (aria-expanded=true) point chevron downward */
.rpv-viz__drawer-handle[aria-expanded="true"] .rpv-viz__drawer-chevron {
    transform: translateY(-50%) rotate(180deg);
    color: var(--rpv-color-accent);
}

.rpv-viz__drawer-handle:hover .rpv-viz__drawer-chevron {
    color: var(--rpv-color-text);
}

/* Drawer hint pill — floats above the handle, visible when collapsed */
.rpv-viz__drawer-hint {
    position: absolute;
    bottom: calc(44px + var(--rpv-safe-bottom) + 80px);
    left: 50%;
    transform: translateX(-50%);
    z-index: var(--rpv-z-overlay);
    display: inline-flex;
    align-items: center;
    gap: var(--rpv-space-1);
    padding: 5px 14px;
    background: rgba(13, 44, 76, 0.80);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    color: #fff;
    border-radius: var(--rpv-radius-full);
    font-size: var(--rpv-font-size-xs);
    font-weight: var(--rpv-font-weight-medium);
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 350ms ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
}

.rpv-viz__drawer-hint--visible {
    opacity: 1;
}

.rpv-viz__drawer-hint-arrow {
    font-size: 1.1em;
    line-height: 1;
}

/* ── Drawer palettes (Collections/Brands) ───────── */

.rpv-viz__drawer-palettes {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: var(--rpv-space-1);
    padding: var(--rpv-space-1) 0 0 0;
    flex-shrink: 0;
}

/* ── Drawer toolbar (family pills) ──────────────── */

.rpv-viz__drawer-toolbar {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: var(--rpv-space-2);
    padding: var(--rpv-space-1) var(--rpv-space-4);
    flex-shrink: 0;
    border-bottom: 1px solid var(--rpv-color-border);
}

.rpv-viz__fav-toggle,
.rpv-viz .rpv-btn--icon {
    width: 36px;
    height: 36px;
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--rpv-glass-border);
    border-radius: var(--rpv-radius-full);
    background: var(--rpv-glass-bg);
    backdrop-filter: blur(var(--rpv-glass-blur));
    -webkit-backdrop-filter: blur(var(--rpv-glass-blur));
    color: var(--rpv-color-muted);
    font-size: var(--rpv-font-size-md);
    cursor: pointer;
    transition: background var(--rpv-motion-ui),
        color var(--rpv-motion-ui),
        border-color var(--rpv-motion-ui),
        box-shadow var(--rpv-motion-ui),
        transform var(--rpv-motion-ui);
    box-shadow: var(--rpv-glass-shadow-btn);
}

.rpv-viz__fav-toggle:hover,
.rpv-viz .rpv-btn--icon:hover {
    background: rgba(255, 255, 255, 0.85);
    color: var(--rpv-color-text);
    transform: scale(1.05);
    box-shadow: var(--rpv-glass-shadow-btn-hover);
}

.rpv-viz__fav-toggle[aria-pressed="true"],
.rpv-viz .rpv-btn--icon[aria-pressed="true"] {
    background: var(--rpv-color-accent);
    border-color: var(--rpv-color-accent);
    color: #fff;
    box-shadow: 0 2px 10px rgba(13, 44, 76, 0.3);
}

.rpv-viz :is(.rpv-tab, .rpv-pill, .rpv-search__toggle, .rpv-search__input, .rpv-viz__fav-toggle, .rpv-btn--icon, .rpv-btn, .rpv-swatch__fav) {
    position: relative;
    overflow: hidden;
}

.rpv-viz :is(.rpv-tab, .rpv-pill, .rpv-search__toggle, .rpv-search__input, .rpv-viz__fav-toggle, .rpv-btn--icon, .rpv-btn, .rpv-swatch__fav)::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.8), transparent);
    pointer-events: none;
}

.rpv-viz :is(.rpv-tab, .rpv-pill, .rpv-search__toggle, .rpv-search__input, .rpv-viz__fav-toggle, .rpv-btn--icon, .rpv-btn, .rpv-swatch__fav)::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 1px;
    height: 100%;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.8), transparent, rgba(255, 255, 255, 0.3));
    pointer-events: none;
}

.rpv-viz__palette-bar,
.rpv-viz__family-pills {
    display: flex;
    gap: var(--rpv-space-1);
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x;
    overscroll-behavior-x: contain;
    flex: 1 1 auto;
    min-width: 0;
    padding: 2px 0;
}

.rpv-viz__palette-bar::-webkit-scrollbar,
.rpv-viz__family-pills::-webkit-scrollbar {
    display: none;
}

.rpv-viz__family-pills.rpv-dragging {
    cursor: grabbing;
    user-select: none;
    -webkit-user-select: none;
}

.rpv-viz__family-pills .rpv-family-tab {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    min-height: 36px;
    padding: var(--rpv-space-1) var(--rpv-space-3);
    border: 1px solid var(--rpv-glass-border);
    border-radius: var(--rpv-radius-full);
    background: var(--rpv-glass-bg);
    backdrop-filter: blur(var(--rpv-glass-blur));
    -webkit-backdrop-filter: blur(var(--rpv-glass-blur));
    color: var(--rpv-color-muted);
    font-size: var(--rpv-font-size-xs);
    font-weight: var(--rpv-font-weight-medium);
    white-space: nowrap;
    cursor: pointer;
    transition: background var(--rpv-motion-ui),
        color var(--rpv-motion-ui),
        border-color var(--rpv-motion-ui),
        box-shadow var(--rpv-motion-ui),
        transform var(--rpv-motion-ui);
    line-height: 1.4;
    box-shadow: var(--rpv-glass-shadow-btn);
}

.rpv-viz__family-pills .rpv-family-tab:hover {
    background: rgba(255, 255, 255, 0.85);
    color: var(--rpv-color-text);
    transform: translateY(-1px);
    box-shadow: var(--rpv-glass-shadow-btn-hover);
}

.rpv-viz__family-pills .rpv-family-tab.rpv-tab-active {
    background: var(--rpv-color-accent);
    border-color: var(--rpv-color-accent);
    color: #fff;
    box-shadow: 0 2px 10px rgba(13, 44, 76, 0.25);
}

/* ── Drawer grid (scrollable color swatches) ────── */

.rpv-viz__drawer-grid {
    padding: var(--rpv-space-4) var(--rpv-space-4);
    overflow-y: auto;
    flex: 1 1 auto;
    min-height: 0;
}

.rpv-viz__drawer-grid .rpv-colors-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(52px, 1fr));
    gap: var(--rpv-space-2);
    padding-bottom: var(--rpv-space-3);
}

.rpv-viz__drawer-grid .rpv-color-item {
    position: relative;
    cursor: pointer;
    transition: transform var(--rpv-motion-ui),
        box-shadow var(--rpv-motion-ui);
}

.rpv-viz__drawer-grid .rpv-color-item:hover {
    transform: scale(1.08);
}

.rpv-viz__drawer-grid .rpv-color-item.rpv-selected .rpv-color-swatch {
    outline: 3px solid var(--rpv-color-accent);
    outline-offset: 2px;
}

/* Favorite star on swatch */
.rpv-viz__drawer-grid .rpv-swatch__fav {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 18px;
    height: 18px;
    border: none;
    background: rgba(0, 0, 0, 0.4);
    color: #fff;
    border-radius: 50%;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    padding: 0;
    z-index: 1;
    transition: background var(--rpv-motion-ui),
        color var(--rpv-motion-ui);
}

.rpv-viz__drawer-grid .rpv-color-item:hover .rpv-swatch__fav,
.rpv-viz__drawer-grid .rpv-swatch__fav[aria-pressed="true"] {
    display: flex;
}

.rpv-viz__drawer-grid .rpv-swatch__fav[aria-pressed="true"] {
    background: rgba(234, 179, 8, 0.9);
    color: #fff;
}

.rpv-viz__drawer-grid .rpv-swatch__fav:hover {
    background: rgba(234, 179, 8, 1);
}

/* A badge on selected item — only shown when compare mode is active */
.rpv-viz--comparing .rpv-viz__drawer-grid .rpv-color-item.rpv-selected::after {
    content: 'A';
    position: absolute;
    top: 2px;
    right: 2px;
    background: var(--rpv-compare-a-color);
    color: #fff;
    font-size: 9px;
    font-weight: 700;
    line-height: 1;
    padding: 1px 3px;
    border-radius: 3px;
}

.rpv-viz__drawer-grid .rpv-color-swatch {
    width: 100%;
    aspect-ratio: 1;
    border-radius: var(--rpv-radius-sm);
    border: 1px solid rgba(0, 0, 0, 0.08);
    cursor: pointer;
    transition: transform var(--rpv-motion-ui),
        box-shadow var(--rpv-motion-ui);
    box-shadow: var(--rpv-shadow-xs);
}

.rpv-viz__drawer-grid .rpv-color-swatch:hover {
    box-shadow: var(--rpv-shadow-sm);
}

.rpv-viz__drawer-grid .rpv-color-label {
    font-size: var(--rpv-font-size-xs);
    text-align: center;
    margin-top: 2px;
    color: var(--rpv-color-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.rpv-viz__drawer-grid .rpv-colors-loading {
    padding: var(--rpv-space-4);
    text-align: center;
    color: var(--rpv-color-muted);
    font-size: var(--rpv-font-size-sm);
}

.rpv-viz__drawer-grid .rpv-colors-loading p {
    margin: 0;
}

/* ── Drawer detail panel ────────────────────────── */

.rpv-viz__drawer-detail {
    padding: 0 var(--rpv-space-4) var(--rpv-space-4);
    flex-shrink: 0;
    display: flex;
    flex-direction: row;
    gap: var(--rpv-space-3);
    border-radius: var(--rpv-radius-lg) var(--rpv-radius-lg) 0 0;
    align-items: flex-start;
}

/* ── Mobile floating chip (Approach C) ──────────── */

.rpv-viz__mobile-chip {
    display: flex;
    opacity: 0;
    pointer-events: none;
    transform: translateY(8px) scale(0.95);
    transition: opacity 200ms ease, transform 200ms ease, pointer-events 0ms 200ms;
}

/* Default: hide chips */
.rpv-viz__mobile-chip--a,
.rpv-viz__mobile-chip--b {
    opacity: 0;
    pointer-events: none;
    transform: translateY(8px) scale(0.95);
}

/* Visible state with animation */
.rpv-viz__mobile-chip--a.rpv-chip--visible,
.rpv-viz__mobile-chip--b.rpv-chip--visible {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0) scale(1);
    transition: opacity 200ms ease, transform 200ms ease;
}

/* In compare mode: CSS fallback for visibility */
.rpv-viz--comparing .rpv-viz__mobile-chip--a,
.rpv-viz--comparing .rpv-viz__mobile-chip--b {
    /* JS controls actual visibility via rpv-chip--visible class */
}

.rpv-viz__mobile-chip-button {
    display: flex;
    align-items: center;
    gap: var(--rpv-space-2);
    padding: var(--rpv-space-1) var(--rpv-space-3) var(--rpv-space-1) var(--rpv-space-1);
    background: var(--rpv-glass-bg);
    border: 1px solid var(--rpv-glass-border);
    border-radius: var(--rpv-radius-full);
    backdrop-filter: blur(var(--rpv-glass-blur));
    -webkit-backdrop-filter: blur(var(--rpv-glass-blur));
    box-shadow: var(--rpv-glass-shadow);
    color: var(--rpv-color-text);
    font-size: var(--rpv-font-size-sm);
    font-weight: var(--rpv-font-weight-medium);
    cursor: pointer;
    transition: background var(--rpv-motion-ui),
        transform var(--rpv-motion-ui);
}

.rpv-viz__mobile-chip-button:hover {
    background: rgba(255, 255, 255, 0.85);
    transform: translateY(-1px);
}

.rpv-viz__mobile-chip-swatch {
    width: 32px;
    height: 32px;
    border-radius: var(--rpv-radius-full);
    border: 1px solid rgba(255, 255, 255, 0.6);
    box-shadow: var(--rpv-shadow-xs);
    flex-shrink: 0;
}

.rpv-viz__mobile-chip-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100px;
}

.rpv-viz__mobile-chip-expand {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    color: var(--rpv-color-muted);
    transition: transform var(--rpv-motion-ui);
}

.rpv-viz__mobile-chip-button[aria-expanded="true"] .rpv-viz__mobile-chip-expand {
    transform: rotate(180deg);
}

.rpv-viz__mobile-chip-button .rpv-viz__mobile-chip-expand::before {
    content: '';
    display: block;
    width: 6px;
    height: 6px;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg) translateY(-2px);
}

.rpv-viz__mobile-expanded-panel {
    display: flex;
    flex-direction: column;
    position: fixed;
    bottom: calc(44px + var(--rpv-safe-bottom));
    left: 0;
    right: 0;
    max-height: calc(50dvh - 44px);
    background: var(--rpv-color-surface);
    border-top: 1px solid var(--rpv-color-border);
    border-radius: var(--rpv-radius-lg) var(--rpv-radius-lg) 0 0;
    z-index: 500;
    overflow-y: auto;
    padding: var(--rpv-space-3) var(--rpv-space-4);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
    opacity: 0;
    pointer-events: none;
    transform: translateY(100%);
    transition: opacity 250ms cubic-bezier(0.2, 0.8, 0.2, 1),
                transform 250ms cubic-bezier(0.2, 0.8, 0.2, 1),
                pointer-events 0ms 250ms;
}

.rpv-viz__mobile-expanded-panel--open {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
    transition: opacity 250ms cubic-bezier(0.2, 0.8, 0.2, 1),
                transform 250ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.rpv-viz__mobile-expanded-panel .rpv-selected-color {
    width: 100%;
    flex-direction: column;
    margin-bottom: var(--rpv-space-2);
}

.rpv-viz__mobile-expanded-panel .rpv-color-detail-card {
    padding: var(--rpv-space-2);
    border-radius: var(--rpv-radius-md);
    background: rgba(255, 255, 255, 0.58);
    border: 1px solid rgba(255, 255, 255, 0.35);
    box-shadow: var(--rpv-shadow-xs);
}

.rpv-viz__mobile-expanded-panel .rpv-color-detail-card:not(:last-child) {
    margin-bottom: var(--rpv-space-2);
}

.rpv-viz__mobile-expanded-panel .rpv-color-detail-head {
    display: flex;
    align-items: center;
    gap: var(--rpv-space-2);
    margin-bottom: var(--rpv-space-2);
}

.rpv-viz__mobile-expanded-panel .rpv-color-detail-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: var(--rpv-radius-full);
    background: var(--rpv-compare-a-color);
    color: #fff;
    font-size: 10px;
    font-weight: var(--rpv-font-weight-bold);
    line-height: 1;
}

.rpv-viz__mobile-expanded-panel .rpv-color-detail-card--compare .rpv-color-detail-badge {
    background: var(--rpv-compare-b-color);
}

.rpv-viz__mobile-expanded-panel .rpv-color-detail-label {
    font-size: var(--rpv-font-size-xs);
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: var(--rpv-color-muted);
    font-weight: var(--rpv-font-weight-bold);
}

.rpv-viz__mobile-expanded-panel .rpv-color-detail-body {
    display: flex;
    align-items: center;
    gap: var(--rpv-space-3);
}

.rpv-viz__mobile-expanded-panel .rpv-color-preview {
    width: 44px;
    height: 44px;
    border-radius: var(--rpv-radius-sm);
    border: 2px solid rgba(255, 255, 255, 0.6);
    box-shadow: var(--rpv-shadow-sm);
    flex-shrink: 0;
}

.rpv-viz__mobile-expanded-panel .rpv-color-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: var(--rpv-font-size-sm);
    line-height: 1.4;
    color: var(--rpv-color-muted);
    min-width: 0;
}

.rpv-viz__mobile-expanded-panel .rpv-color-name {
    font-weight: var(--rpv-font-weight-bold);
    color: var(--rpv-color-text);
    font-size: var(--rpv-font-size-base);
}

.rpv-viz__mobile-expanded-panel .rpv-color-code,
.rpv-viz__mobile-expanded-panel .rpv-color-hex,
.rpv-viz__mobile-expanded-panel .rpv-color-rgb {
    font-size: var(--rpv-font-size-xs);
    color: var(--rpv-color-muted);
}

.rpv-viz__mobile-expanded-panel .rpv-viz__similar-row {
    flex: none;
    width: 100%;
    margin-top: var(--rpv-space-2);
    padding: var(--rpv-space-2);
    background: var(--rpv-glass-bg);
    border: 1px solid var(--rpv-glass-border);
    border-radius: var(--rpv-radius-lg);
    backdrop-filter: blur(var(--rpv-glass-blur));
    -webkit-backdrop-filter: blur(var(--rpv-glass-blur));
    box-shadow: var(--rpv-glass-shadow);
    min-height: 64px;
    align-items: center;
}

.rpv-viz__mobile-expanded-panel .rpv-viz__similar-row::-webkit-scrollbar {
    display: none;
}

.rpv-viz__mobile-expanded-panel .rpv-viz__similar-row .rpv-color-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 48px;
    cursor: pointer;
}

.rpv-viz__mobile-expanded-panel .rpv-viz__similar-row .rpv-color-swatch {
    width: 40px;
    height: 40px;
    border-radius: var(--rpv-radius-sm);
    border: 1px solid var(--rpv-color-border);
    box-shadow: var(--rpv-shadow-xs);
    transition: transform var(--rpv-motion-ui), box-shadow var(--rpv-motion-ui);
}

.rpv-viz__mobile-expanded-panel .rpv-viz__similar-row .rpv-color-item:hover .rpv-color-swatch {
    transform: translateY(-1px);
    box-shadow: var(--rpv-shadow-sm);
}

.rpv-viz__mobile-expanded-panel .rpv-viz__similar-row .rpv-color-label {
    margin-top: 4px;
    font-size: var(--rpv-font-size-xs);
    color: var(--rpv-color-muted);
    white-space: nowrap;
}

.rpv-viz__mobile-expanded-close {
    position: absolute;
    top: var(--rpv-space-2);
    right: var(--rpv-space-2);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: var(--rpv-radius-full);
    background: var(--rpv-glass-bg);
    color: var(--rpv-color-muted);
    cursor: pointer;
    font-size: 16px;
    transition: background var(--rpv-motion-ui), color var(--rpv-motion-ui);
}

.rpv-viz__mobile-expanded-close:hover {
    background: var(--rpv-color-hover);
    color: var(--rpv-color-text);
}

.rpv-viz__mobile-chips-row {
    display: none;
    flex-wrap: wrap;
    gap: var(--rpv-space-2);
    margin-bottom: var(--rpv-space-2);
}

.rpv-viz__mobile-chips-row--visible {
    display: flex;
}

.rpv-viz__mobile-chip.rpv-viz__mobile-chip--compare-a {
    border-color: var(--rpv-color-accent);
}

.rpv-viz__mobile-chip.rpv-viz__mobile-chip--compare-b {
    border-color: var(--rpv-compare-b-color);
}

/* Mobile similar colors section */
.rpv-viz__mobile-similar-section {
    margin-top: var(--rpv-space-3);
    padding-top: var(--rpv-space-2);
    border-top: 1px solid var(--rpv-color-border);
}

.rpv-viz__mobile-similar-label {
    font-size: var(--rpv-font-size-xs);
    font-weight: var(--rpv-font-weight-bold);
    text-transform: uppercase;
    letter-spacing: 0.02em;
    color: var(--rpv-color-muted);
    margin-bottom: var(--rpv-space-2);
}

.rpv-viz__mobile-similar-row {
    display: flex;
    gap: var(--rpv-space-2);
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    padding: var(--rpv-space-1);
    min-height: 56px;
    align-items: center;
}

.rpv-viz__mobile-similar-row::-webkit-scrollbar {
    display: none;
}

.rpv-viz__mobile-similar-row .rpv-color-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 44px;
    max-width: 44px;
    width: 44px;
    cursor: pointer;
    flex: 0 0 auto;
}

.rpv-viz__mobile-similar-row .rpv-color-swatch {
    width: 40px;
    height: 40px;
    border-radius: var(--rpv-radius-sm);
    border: 1px solid var(--rpv-color-border);
    box-shadow: var(--rpv-shadow-xs);
    transition: transform var(--rpv-motion-ui), box-shadow var(--rpv-motion-ui);
}

.rpv-viz__mobile-similar-row .rpv-color-item:hover .rpv-color-swatch {
    transform: translateY(-1px);
    box-shadow: var(--rpv-shadow-sm);
}

.rpv-viz__mobile-similar-loading {
    font-size: var(--rpv-font-size-sm);
    color: var(--rpv-color-muted);
    padding: var(--rpv-space-2);
    text-align: center;
}

.rpv-viz__drawer-detail .rpv-color-detail-card {
    padding: var(--rpv-space-2);
    border-radius: var(--rpv-radius-md);
    background: rgba(255, 255, 255, 0.58);
    border: 1px solid rgba(255, 255, 255, 0.35);
    box-shadow: var(--rpv-shadow-xs);
}

.rpv-viz__drawer-detail .rpv-color-detail-head {
    display: flex;
    align-items: center;
    gap: var(--rpv-space-2);
    margin-bottom: var(--rpv-space-2);
}

.rpv-viz__drawer-detail .rpv-color-detail-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: var(--rpv-radius-full);
    background: var(--rpv-compare-a-color);
    color: #fff;
    font-size: 10px;
    font-weight: var(--rpv-font-weight-bold);
    line-height: 1;
}

.rpv-viz__drawer-detail .rpv-color-detail-label {
    font-size: var(--rpv-font-size-xs);
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: var(--rpv-color-muted);
    font-weight: var(--rpv-font-weight-bold);
}

.rpv-viz__drawer-detail .rpv-color-detail-body {
    display: flex;
    align-items: center;
    gap: var(--rpv-space-3);
}

.rpv-viz__drawer-detail .rpv-color-detail-card--compare-placeholder {
    display: flex;
    flex-direction: column;
}

.rpv-viz__drawer-detail .rpv-color-detail-card--compare .rpv-color-detail-badge,
.rpv-viz__drawer-detail .rpv-color-detail-card--compare-placeholder .rpv-color-detail-badge {
    background: var(--rpv-compare-b-color);
}

.rpv-viz__drawer-detail .rpv-color-compare-placeholder {
    margin: 0;
    font-size: var(--rpv-font-size-xs);
    color: var(--rpv-color-muted);
}

.rpv-viz__drawer-detail .rpv-color-preview {
    width: 56px;
    height: 56px;
    border-radius: var(--rpv-radius-sm);
    border: 2px solid rgba(255, 255, 255, 0.6);
    box-shadow: var(--rpv-shadow-sm);
    flex-shrink: 0;
    margin-bottom: 0;
}

.rpv-viz__drawer-detail .rpv-color-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: var(--rpv-font-size-sm);
    line-height: 1.4;
    color: var(--rpv-color-muted);
    min-width: 0;
}

/* Horizontal scroll edge fades — set dynamically via JS (_updateFades)
   so the fade disappears when the row is scrolled to an edge. */
.rpv-viz__room-categories,
.rpv-viz__palette-bar,
.rpv-viz__family-pills {
    -webkit-mask-size: 100% 100%;
    mask-size: 100% 100%;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
}

/* Mobile panel similar row fade */
.rpv-viz__mobile-expanded-panel .rpv-viz__similar-row {
    -webkit-mask-size: 100% 100%;
    mask-size: 100% 100%;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
}

/* Vertical scroll edge fades — set dynamically via JS (_updateFadesV)
   so the fade disappears when the grid is scrolled to an edge. */
.rpv-viz__drawer-grid {
    -webkit-mask-size: 100% 100%;
    mask-size: 100% 100%;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
}

/* ================================================================
   9b. MOBILE TOOLBAR TOGGLE BUTTON
   ================================================================ */

/* Toolbar toggle button — unified behavior for all devices */
.rpv-viz .rpv-viz__toolbar-toggle {
    display: inline-flex !important;
    position: relative !important;
    top: auto !important;
    left: auto !important;
    z-index: var(--rpv-z-overlay) !important;
    margin-top: var(--rpv-space-2) !important;
    margin-bottom: var(--rpv-space-2) !important;
    align-items: center;
    gap: var(--rpv-space-1);
    min-height: 44px !important;
    padding: var(--rpv-space-2) var(--rpv-space-3) !important;
    border: 1px solid var(--rpv-glass-border) !important;
    border-radius: var(--rpv-radius-full) !important;
    background: var(--rpv-glass-bg) !important;
    backdrop-filter: blur(var(--rpv-glass-blur)) !important;
    -webkit-backdrop-filter: blur(var(--rpv-glass-blur)) !important;
    box-shadow: var(--rpv-glass-shadow-btn) !important;
    color: var(--rpv-color-text) !important;
    font-size: var(--rpv-font-size-sm) !important;
    font-weight: var(--rpv-font-weight-medium) !important;
    cursor: pointer;
    white-space: nowrap;
    transition: background var(--rpv-motion-ui),
        color var(--rpv-motion-ui),
        box-shadow var(--rpv-motion-ui),
        transform var(--rpv-motion-ui);
}

.rpv-viz .rpv-viz__toolbar-toggle:hover {
    background: rgba(255, 255, 255, 0.85) !important;
    transform: translateY(-1px) !important;
    box-shadow: var(--rpv-glass-shadow-btn-hover) !important;
}

.rpv-viz .rpv-viz__toolbar-toggle[aria-expanded="true"] {
    background: var(--rpv-color-accent) !important;
    border-color: var(--rpv-color-accent) !important;
    color: #fff !important;
    box-shadow: 0 2px 10px rgba(13, 44, 76, 0.3) !important;
}

.rpv-viz .rpv-viz__toolbar-toggle-icon {
    font-size: var(--rpv-font-size-md);
    line-height: 1;
}

.rpv-viz .rpv-viz__toolbar-toggle-label {
    line-height: 1;
}

/* ================================================================
   10. RESPONSIVE BREAKPOINTS
   ================================================================ */

@media (max-width: 768px) {
    .rpv-viz__overlay-bar {
        top: var(--rpv-space-2);
        left: max(var(--rpv-space-2), var(--rpv-safe-left));
        right: max(var(--rpv-space-2), var(--rpv-safe-right));
        padding: var(--rpv-space-2) max(var(--rpv-space-3), var(--rpv-safe-right)) var(--rpv-space-2) max(var(--rpv-space-3), var(--rpv-safe-left));
        border-radius: var(--rpv-radius-lg);
    }

    /* Density: compact pills on tablets */
    .rpv-viz__family-pills .rpv-family-tab,
    .rpv-viz__room-categories .rpv-viz__room-category-pill,
    .rpv-viz__palette-bar .rpv-viz__palette-pill {
        min-height: 32px;
        padding-top: 4px;
        padding-bottom: 4px;
    }

    .rpv-viz__room-categories {
        order: 1;
        flex-basis: 100%;
    }

    .rpv-viz__room-bar {
        order: 2;
        flex-basis: 100%;
    }

    .rpv-viz__palette-bar {
        order: 3;
        flex-basis: 100%;
    }

    .rpv-viz__stage-controls .rpv-viz__btn-label {
        display: none;
    }

    .rpv-viz__stage-controls .rpv-button {
        padding: var(--rpv-space-2);
        border-radius: var(--rpv-radius-full);
        min-width: 44px;
        min-height: 44px;
        justify-content: center;
    }

    .rpv-viz__drawer-grid .rpv-colors-grid {
        grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
    }

    /* ── Mobile: Approach C - Minimal floating chip ── */
    
    /* Mobile drawer only has 2 states: collapsed (44px) and full (100% - 44px) */
    .rpv-viz__drawer--half {
        max-height: 44px;
    }
    
    /* Override any intermediate states to be either collapsed or full */
    .rpv-viz__drawer:not(.rpv-viz__drawer--collapsed):not(.rpv-viz__drawer--full) {
        max-height: 44px;
    }
    
    .rpv-viz__drawer-detail {
        flex-direction: column;
        gap: var(--rpv-space-2);
    }

    /* Mobile chips: opacity-based visibility for smooth animations */
    .rpv-viz__mobile-chip--a,
    .rpv-viz__mobile-chip--b {
        opacity: 0;
        pointer-events: none;
        transform: translateY(8px) scale(0.95);
    }
    
    .rpv-viz__mobile-chip--a.rpv-chip--visible,
    .rpv-viz__mobile-chip--b.rpv-chip--visible {
        opacity: 1;
        pointer-events: auto;
        transform: translateY(0) scale(1);
    }
}

@media (max-width: 480px) {
    .rpv-viz {
        border-radius: 0;
    }

    /* ── Hide overlay bar by default ── */
    .rpv-viz__overlay-bar {
        gap: var(--rpv-space-1);
        top: var(--rpv-space-1);
        left: max(var(--rpv-space-1), var(--rpv-safe-left));
        right: max(var(--rpv-space-1), var(--rpv-safe-right));
        padding: var(--rpv-space-1) max(var(--rpv-space-2), var(--rpv-safe-right)) var(--rpv-space-1) max(var(--rpv-space-2), var(--rpv-safe-left));
        border-radius: var(--rpv-radius-md);
    }

    .rpv-viz__room-thumb {
        width: 52px;
        height: 44px;
    }

    /* Move stage controls above the drawer hint so they are not hidden */
    .rpv-viz__stage-controls {
        bottom: calc(44px + var(--rpv-safe-bottom) + var(--rpv-space-4));
        right: var(--rpv-space-2);
        gap: var(--rpv-space-1);
    }

    /* Density: compact pills on phones */
    .rpv-viz__room-categories .rpv-viz__room-category-pill,
    .rpv-viz__palette-bar .rpv-viz__palette-pill {
        min-height: 28px;
        padding: 3px var(--rpv-space-2);
        font-size: var(--rpv-font-size-xs);
    }

    /* Shrink chip label so it doesn't overflow narrow screens */
    .rpv-viz__active-color-label {
        max-width: 120px;
    }

    /* Larger swatches for easier touch targeting (4 columns) */
    .rpv-viz__drawer-grid .rpv-colors-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: var(--rpv-space-2);
    }

    /* ── Mobile: Even more compact chip styles ── */
    
    .rpv-viz__mobile-chip {
        position: relative;
        z-index: 460;
    }
    
    .rpv-viz__mobile-chip-button {
        padding: var(--rpv-space-1) var(--rpv-space-2) var(--rpv-space-1) var(--rpv-space-1);
        pointer-events: auto;
        cursor: pointer;
        touch-action: manipulation;
    }

    .rpv-viz__mobile-chip-swatch {
        width: 28px;
        height: 28px;
    }

    .rpv-viz__mobile-chip-text {
        max-width: 80px;
        font-size: var(--rpv-font-size-xs);
    }

    .rpv-viz__mobile-expanded-panel {
        padding: var(--rpv-space-2) var(--rpv-space-3);
        max-height: calc(45dvh - 44px);
    }

    .rpv-viz__mobile-expanded-panel .rpv-color-preview {
        width: 40px;
        height: 40px;
    }

    .rpv-viz__mobile-expanded-panel .rpv-color-detail-body {
        gap: var(--rpv-space-2);
    }

    .rpv-viz__mobile-expanded-panel .rpv-viz__similar-row .rpv-color-swatch {
        width: 36px;
        height: 36px;
    }

    .rpv-viz__mobile-expanded-panel .rpv-viz__similar-row .rpv-color-item {
        min-width: 44px;
    }
}

/* ================================================================
   11. REDUCED MOTION
   ================================================================ */

@media (prefers-reduced-motion: reduce) {

    .rpv-viz *,
    .rpv-viz *::before,
    .rpv-viz *::after {
        animation-duration: 1ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 1ms !important;
        scroll-behavior: auto !important;
    }
}

/* ================================================================
   12. FULLSCREEN LIGHTBOX
   ================================================================ */

/* Fullscreen expand button inherits all glass + size styles from .rpv-button in stage-controls */

/* Native <dialog> as lightbox overlay */
dialog.rpv-lb {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    margin: 0;
    padding: 0;
    border: none;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--rpv-z-toast);
    outline: none;
}

dialog.rpv-lb:not([open]) {
    display: none;
}

dialog.rpv-lb::backdrop {
    background: rgba(0, 0, 0, 0.92);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

/* Content area — fills entire dialog, provides positioning context */
.rpv-lb__content {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

/* The visualized room image */
.rpv-lb__img {
    display: block;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    transform-origin: center center;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    cursor: zoom-in;
    border-radius: var(--rpv-radius-md);
    box-shadow: var(--rpv-shadow-xl);
    will-change: transform;
    transition: transform var(--rpv-duration-fast) var(--rpv-ease-out);
}

.rpv-lb__img.rpv-lb--zoomed {
    cursor: grab;
}

.rpv-lb__img.rpv-lb--dragging {
    cursor: grabbing;
    transition: none;
}

/* Zoom toolbar — centered at bottom */
.rpv-lb__toolbar {
    position: fixed;
    bottom: calc(var(--rpv-space-5) + env(safe-area-inset-bottom, 0px));
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: var(--rpv-space-2);
    padding: var(--rpv-space-2) var(--rpv-space-3);
    background: var(--rpv-glass-bg);
    border: 1px solid var(--rpv-glass-border);
    border-radius: var(--rpv-radius-full);
    backdrop-filter: blur(var(--rpv-glass-blur));
    -webkit-backdrop-filter: blur(var(--rpv-glass-blur));
    box-shadow: var(--rpv-glass-shadow);
    z-index: 1;
    white-space: nowrap;
}

.rpv-lb__toolbar .rpv-button {
    min-width: 36px;
    min-height: 36px;
    padding: var(--rpv-space-1) var(--rpv-space-2);
    border-radius: var(--rpv-radius-sm);
    font-size: var(--rpv-font-size-md);
    font-weight: var(--rpv-font-weight-bold);
    background: transparent;
    color: var(--rpv-color-text);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--rpv-motion-ui);
}

.rpv-lb__toolbar .rpv-button:hover {
    background: rgba(0, 0, 0, 0.08);
}

.rpv-lb__zoom-level {
    font-size: var(--rpv-font-size-sm);
    font-weight: var(--rpv-font-weight-medium);
    color: var(--rpv-color-muted);
    min-width: 36px;
    text-align: center;
}

/* Close button — top right corner (high specificity via element + class + parent) */
dialog.rpv-lb button.rpv-lb__close,
.rpv-lb .rpv-lb__close {
    position: fixed;
    top: calc(var(--rpv-space-4) + env(safe-area-inset-top, 0px));
    right: calc(var(--rpv-space-4) + env(safe-area-inset-right, 0px));
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--rpv-glass-bg);
    border: 1px solid var(--rpv-glass-border);
    border-radius: var(--rpv-radius-full);
    backdrop-filter: blur(var(--rpv-glass-blur));
    -webkit-backdrop-filter: blur(var(--rpv-glass-blur));
    box-shadow: var(--rpv-glass-shadow);
    font-size: 1.1rem;
    line-height: 1;
    color: var(--rpv-color-text);
    cursor: pointer;
    z-index: 1;
    transition: background var(--rpv-motion-ui), transform var(--rpv-motion-ui);
    appearance: none;
    -webkit-appearance: none;
    padding: 0;
    margin: 0;
}

dialog.rpv-lb button.rpv-lb__close:hover,
.rpv-lb .rpv-lb__close:hover {
    background: rgba(255, 255, 255, 0.9);
    transform: scale(1.08);
}

dialog.rpv-lb button.rpv-lb__close:focus-visible,
.rpv-lb .rpv-lb__close:focus-visible {
    outline: 2px solid var(--rpv-color-accent);
    outline-offset: 2px;
}

/* Zoom level hint label inside toolbar */
.rpv-lb__zoom-reset {
    font-size: var(--rpv-font-size-sm);
    min-width: 44px;
    color: var(--rpv-color-muted);
}

@media (max-width: 480px) {
    .rpv-lb__toolbar {
        bottom: calc(var(--rpv-space-4) + env(safe-area-inset-bottom, 0px));
        gap: var(--rpv-space-1);
        padding: var(--rpv-space-1) var(--rpv-space-2);
    }
}

/* === UI/UX Polish === */

/* Swatch Accessibility Resets */
.rpv-viz__drawer-grid .rpv-color-item,
.rpv-viz__mobile-expanded-panel .rpv-viz__similar-row .rpv-color-item {
    background: transparent;
    border: none;
    padding: 0;
    outline: none;
    font: inherit;
    color: inherit;
    width: 100%;
    text-align: left;
    appearance: none;
}

.rpv-viz__drawer-grid .rpv-color-item:focus-visible .rpv-color-swatch,
.rpv-viz__mobile-expanded-panel .rpv-viz__similar-row .rpv-color-item:focus-visible .rpv-color-swatch {
    outline: 2px solid var(--rpv-color-accent);
    outline-offset: 2px;
}

/* Interactive Onboarding Dot */
.rpv-btn--has-new-dot {
    position: relative;
}

.rpv-btn--has-new-dot::after {
    content: '';
    position: absolute;
    top: -2px;
    right: -2px;
    width: 10px;
    height: 10px;
    background: #ef4444;
    border-radius: 50%;
    animation: rpv-pulse-dot 2s infinite;
    z-index: 10;
}

@keyframes rpv-pulse-dot {
    0% {
        transform: scale(0.95);
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7);
    }

    70% {
        transform: scale(1);
        box-shadow: 0 0 0 6px rgba(239, 68, 68, 0);
    }

    100% {
        transform: scale(0.95);
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0);
    }
}

/* Canvas Loading Feedback */
.rpv-canvas--processing {
    opacity: 0.7;
    filter: blur(2px) grayscale(20%);
    transition: opacity 0.15s ease, filter 0.15s ease;
}