/* ========================
   MAIN CSS INITIALISATION
   FILE: css/main.css
   ======================== /*

/* =================================================== */
/* LAYER 1: FOUNDATION */
/* =================================================== */

/* SECTION: Root Variables - Theme colours and defaults */
/*
 * Purpose: Central place for CSS custom properties used across the app
 * - --current-colour is updated dynamically by the parser
 * - Fallback values ensure the page looks decent before any input
 * - Dark mode friendly base palette
 *
 * Features:
 * - **Dynamic properties**: --current-colour, --swatch-glow-colour-alpha updated by JS
 * - **Theme consistency**: All colours, shadows, and spacing defined in one place
 * - **Accessibility**: Text colours ensure proper contrast ratios
 * - **Adaptability**: --bg-safe lightens automatically for dark swatches
*/
:root {
    /* Purpose: Colour palette - dynamic and accent colours */
    --current-colour:      #ffffff;     /* Updated live by JS parser */
    --current-colour-text: #000000;     /* High-contrast text on light backgrounds */
    --swatch-text-colour:  #000000;     /* Swatch text contrast */
    --accent:              #4cc9f0;     /* Primary accent for focus rings and highlights */
    
    /* Purpose: Background and surface colours */
    --bg:                  #1a1a1f;     /* Main background */
    --bg-safe:             var(--bg);   /* Dynamically set to lightened value when needed */
    --surface:             #24242c;     /* Input field and dropdown backgrounds */
    
    /* Purpose: Text colour hierarchy */
    --text:                #e0e0e8;     /* Primary text */
    --text-muted:          #a0a0b0;     /* Secondary/placeholder text */
    
    /* Purpose: Layout and spacing */
    --radius:              12px;        /* Universal border radius */
    
    /* Purpose: Shadow effects */
    --shadow-sm:           0 4px 12px rgba(0, 0, 0, 0.25);  /* Small elevation shadow */
    --swatch-text-shadow:  0 1px 4px rgba(0,0,0,0.6);      /* Adaptive shadow for swatch text */
    --dropdown-glow-colour-alpha: rgba(76, 201, 240, 0.25);
}


/* SECTION: Global Reset & Base Styles */
/*
 * Purpose: Normalise browser defaults and set app-wide foundation
 * - **Box-sizing** border-box everywhere
 * - Smooth font rendering
 * - Prevent unwanted scrollbars
 *
 * Features:
 * - **Universal box-sizing**: Consistent sizing calculations across all elements
 * - **Font rendering**: Antialiasing for cleaner typography
 * - **Full viewport**: html and body fill available space
 * - **Flex layout**: Body uses column flex for sticky footer pattern
*/
*,
*::before,
*::after {
    /* Purpose: Reset sizing model and remove default spacing */
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    /* Purpose: Establish baseline height for percentage calculations */
    height: 100%;
}

body {
    /* Purpose: Full viewport height, dark background, system font stack */
    min-height: 100dvh;
    background: var(--bg-safe);     /* Use safe variant when swatch is too dark */
    color: var(--text);
    font-family: system-ui, -apple-system, sans-serif;
    line-height: 1.5;
    
    /* Purpose: Improve font rendering on modern systems */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    
    /* Purpose: Establish flex column layout for sticky footer */
    display: flex;
    flex-direction: column;
}

/* =================================================== */
/* LAYER 2: LAYOUT */
/* =================================================== */

/* SECTION: Main Layout Container */
/*
 * Purpose: Flexible central area that grows to fill space
 * - Centers content vertically and horizontally
 * - Adds breathing room on small screens
 *
 * Features:
 * - **Flex growth**: Expands to fill remaining viewport space
 * - **Center alignment**: Perfect vertical and horizontal centering
 * - **Responsive constraints**: Max-width prevents line-length issues
 * - **Consistent spacing**: Gap and padding create visual rhythm
*/
main {
    /* Purpose: Flex behavior and sizing */
    flex: 1;
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    
    /* Purpose: Layout alignment */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    
    /* Purpose: Spacing and breathing room */
    gap: 1.5rem;
    padding: 2rem 1.5rem;
}

/* =================================================== */
/* LAYER 3: COMPONENTS */
/* =================================================== */

/* SECTION: Hero Swatch - Large colour preview */
/*
 * Purpose: Dominant visual element showing the current parsed colour
 * - Full-width on mobile, constrained on larger screens
 * - Uses CSS var for instant background updates
 * - Centred contrasting text for quick readability check
 * - **Dynamic coloured glow** matching current colour or accent fallback
 *
 * Features:
 * - **Dynamic theming**: Glow effect matches input focus ring for visual cohesion
 * - **Contrast safety**: JS logic prevents low-contrast glows on light colours
 * - **Layered shadows**: Combines base shadow with colour-aware glow effect
*/
.hero-swatch {
    /* Purpose: Responsive sizing with viewport and max constraints */
    width: min(90vw, 720px);
    aspect-ratio: 3 / 2;
    max-height: 55vh;    /* Prevent swatch dominating viewport when panels are present */
    min-height: 180px;   /* Prevent swatch collapsing when panels push layout on small desktops */
    
    /* Purpose: Visual styling and depth */
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm), 0 0 0 6px var(--swatch-glow-colour-alpha, rgba(76, 201, 240, 0.25));
    overflow: hidden;
    
    /* Purpose: Positioning and background control */
    position: relative;
    background: var(--current-colour);
    transition: background 0.18s ease;
    
    /* Purpose: Center content alignment */
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.swatch-content {
    /* Purpose: Text container with spacing and width constraints */
    padding: 2rem;
    max-width: 90%;
    
    /* Purpose: Dynamic text styling using CSS variables */
    color: var(--swatch-text-colour);       /* Dynamic contrast */
    text-shadow: var(--swatch-text-shadow); /* subtle shadow helps on light backgrounds */
}

.swatch-content h1 {
    /* Purpose: Typography - responsive heading size */
    font-size: clamp(2.2rem, 6vw, 4.5rem);
    font-weight: 700;
    
    /* Purpose: Spacing below title */
    margin-bottom: 0.5rem;
    
    /* Purpose: Text colour and shadow for readability */
    color: var(--current-colour-text);
    text-shadow: 0 2px 8px rgba(0,0,0,0.5);
}

.swatch-content h2 {
    margin-bottom: 0.5rem;
}

.swatch-content p {
    /* Purpose: Typography - responsive paragraph size */
    font-size: clamp(1.1rem, 3vw, 1.8rem);
    opacity: 0.95;
    
    /* Purpose: Text colour inheritance */
    color: var(--current-colour-text);
}

/* SECTION: Swatch Content Inheritance – Prevent colour overrides */
/*
 * Purpose: Force text colour inheritance on child elements
 * - Prevents browser defaults or other styles from overriding swatch text
 * - Ensures consistent appearance across all display elements
 * - Uses !important to guarantee specificity
*/
.swatch-content h1,
.swatch-content p,
#display-colour-value,
#contrast-info {
    /* Purpose: Enforce parent colour with highest specificity */
    color: inherit !important;
}

/* =================================================== */
/* SECTION: Display Values – Monospace Font for Code   */
/* =================================================== */
/*
 * Purpose: Apply monospace font to hex/RGB/HSL values for code-like appearance
 * - Consistent alignment and improved readability of technical values
 * - Maintains readability across different colour backgrounds
 * - Hover feedback indicates interactivity (click-to-copy)
 *
 * Font stack rationale:
 * - ui-monospace   → SF Mono on macOS and iOS/iPadOS (clean, modern, screen-optimised)
 * - SF Mono        → Explicit fallback for older Apple OS versions
 * - Cascadia Code  → Ships with Windows 11; preferred on Edge/Chrome/Firefox on Windows
 * - Consolas       → Reliable Windows fallback (Vista+); clean hinting at all sizes
 * - monospace      → Generic last resort for edge-case platforms
 *
 * Features:
 * - **Modern stack**: Purpose-built screen monospace on all major platforms
 * - **Visual hierarchy**: font-size 1em keeps values subordinate to colour name
 * - **Interactive feedback**: Subtle opacity change on hover
 * - **Standards compliance**: Hex values uppercase per developer convention
*/
#display-hex-value,
#display-rgb-value,
#display-hsl-value {
    /* Purpose: Typography - monospace styling for code appearance */
    font-family: ui-monospace, 'SF Mono', 'Cascadia Code', Consolas, monospace;
    font-size: 1em;
    letter-spacing: 0.02em;         /* Slight spacing for cleaner monospace look */
    font-weight: 400;               /* Lighter weight for cleaner code appearance */
    
    /* Purpose: Interaction - click-to-copy affordance */
    cursor: pointer;
    transition: opacity 0.2s ease;  /* Smooth hover transition */
}

/* Purpose: Interaction affordance for clickable colour name (no monospace) */
#display-named-colour {
    cursor: pointer;
    transition: opacity 0.2s ease;  /* Smooth hover transition */
}

#display-hex-value:hover,
#display-rgb-value:hover,
#display-hsl-value:hover {
    /* Purpose: Visual feedback on hover */
    opacity: 0.85;                   /* Subtle feedback for interactivity */
}

/* Purpose: Hover feedback for clickable colour name */
#display-named-colour:hover {
    opacity: 0.85;
}

#display-hex-value {
    /* Purpose: Standards convention for hex values */
    text-transform: uppercase;      /* Standard practice for hex values */
}

/* =================================================== */
/* SECTION: Copy Tooltip – Click-to-copy feedback      */
/* =================================================== */
/*
 * Purpose: Shows "Copied!" message when user clicks hex/RGB/HSL values
 * - Positioned dynamically near the clicked element
 * - Fades in quickly, fades out after 1.5s
 * - Uses fixed positioning for viewport stability
 * - **Bright Green (#66ff00) indicates success**, red indicates error
 *
 * Features:
 * - **Dynamic positioning**: Appears above/below clicked element based on viewport
 * - **Smooth animations**: Fade and slide transitions for polished UX
 * - **State management**: Success (green) and error (red) visual states
 * - **Accessibility**: High contrast colours and fixed positioning for stability
 * - **Non-blocking**: pointer-events: none prevents interaction interference
*/
.tooltip {
    /* Purpose: Positioning - fixed to viewport for stability */
    position: fixed;
    z-index: 1000;
    white-space: nowrap;
    transform: translate(-50%, 10px);
    pointer-events: none;
    
    /* Purpose: Appearance - dark background with success colour */
    background: rgba(30, 30, 46, 0.95);
    color: #66ff00;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    backdrop-filter: blur(4px);
    
    /* Purpose: Typography */
    font-size: 0.9rem;
    font-weight: 500;
    
    /* Purpose: Animation - smooth fade and slide */
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.tooltip.show {
    /* Purpose: Visible state for success feedback */
    opacity: 1;
    transform: translate(-50%, 0);
}

.tooltip.error {
    /* Purpose: Error state colour for failed copy operations */
    color: #ff6b6b;
}


/* SECTION: Input Container - Colour entry field */
/*
 * Purpose: Prominent, wide input for typing/pasting colours
 * - Large touch target for mobile usability
 * - Subtle styling that doesn’t compete with hero swatch
 * - **Relative positioning** for absolute clear button placement
 * - **Narrower width (500px)** for better visual hierarchy
 *
 * Features:
 * - **Responsive sizing**: Constrained width with viewport maximum
 * - **Position context**: Anchor point for absolutely positioned clear button
 * - **Mobile friendly**: Large touch target on all screen sizes
 * - **Visual balance**: Reduced width prevents dominance over swatch
*/
.input-container {
    /* Purpose: Responsive width with max constraint */
    width: min(90vw, 500px);
    
    /* Purpose: Position context for absolute children (clear button) */
    position: relative;
}


/* =================================================== */
/* SECTION: Clear Button – Input reset control         */
/* =================================================== */
/*
 * Purpose: Styled button to clear the colour input field
 * - Positioned absolutely inside the input container
 * - **Fades in/out** based on input content
 * - Subtle hover effect for better UX
 * - Accessible via keyboard and screen readers
 * - **Hidden during demo mode** when irrelevant
 *
 * Features:
 * - **Smart visibility**: Only appears when input contains text
 * - **Smooth transitions**: Fades in/out with CSS opacity
 * - **Hover feedback**: Colour brightens on hover/focus for better UX
 * - **Mobile responsive**: Adjusts size and position on small screens
 * - **Demo coordination**: Hidden during screensaver with .hidden-during-demo class
*/
.clear-input {
    /* Purpose: Absolute positioning within input container */
    position: absolute;
    right: 1.2rem;
    top: 50%;
    transform: translateY(-50%);
    
    /* Purpose: Button appearance */
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.8rem;
    font-weight: 300;
    line-height: 1;
    padding: 0.2rem 0.5rem;
    cursor: pointer;
    
    /* Purpose: Initial hidden state (faded out, no pointer events) */
    opacity: 0;
    pointer-events: none;
    
    /* Purpose: Smooth transitions for show/hide and hover */
    transition: opacity 0.3s ease, color 0.2s ease;
}

.clear-input.visible {
    /* Purpose: Show button when input has content */
    opacity: 1;
    pointer-events: auto;
}

.clear-input.hidden-during-demo.clear-input {
    /* Purpose: Hide during demo mode (overrides visible state) */
    opacity: 0;
    pointer-events: none;
}

.clear-input:hover,
.clear-input:focus {
    /* Purpose: Subtle hover state for better UX */
    color: var(--text);
    outline: none;
}

/* SECTION: Clear Button Mobile – Responsive adjustments */
/*
 * Purpose: Ensure clear button doesn't overlap text on small screens
 * - Reduces size for better fit
 * - Adjusts positioning for narrow viewports
*/
@media (max-width: 480px) {
    .clear-input {
        /* Purpose: Adjust positioning for mobile */
        right: 0.8rem;
        
        /* Purpose: Reduce size for better mobile fit */
        font-size: 1.6rem;
    }
}


/* =================================================== */
/* SECTION: Input Field – Colour entry and states      */
/* =================================================== */
/*
 * Purpose: Comprehensive styling for colour input field
 * - Prominent, accessible, and visually integrated with swatch
 * - Supports dynamic theming based on current colour
 * - Provides clear feedback for all states (default, focused, error)
 *
 * Features:
 * - **Monospace typography**: Consistent with hex/rgb/hsl display
 * - **Dynamic theming**: Focus ring and glow match current colour
 * - **Error integration**: Red border/glow when invalid
 * - **Accessibility**: Large touch target, proper contrast ratios
 * - **Mobile friendly**: Responsive sizing and spacing
*/

/* Sub-section: Base Input Styling */
/*
 * Purpose: Default appearance of colour input field
 * - Centered text and placeholder for visual balance
 * - Subtle border that becomes vibrant on focus
*/
#colour-input {
    /* Purpose: Layout - full width with comfortable padding; right extended for clear button + btn group */
    width: 100%;
    padding: 1.2rem 9.8rem 1.2rem 1.6rem;
    text-align: center; /* Center align input text */
    
    /* Purpose: Typography - monospace for consistency */
    font-family: monospace;
    font-size: 1.0rem;
    
    /* Purpose: Appearance - dark surface with subtle border */
    background: var(--surface);
    color: var(--text);
    border: 2px solid var(--text-muted);
    border-radius: var(--radius);
    outline: none;
    
    /* Purpose: Animation - smooth focus/error transitions */
    transition: border-color 0.18s ease, box-shadow 0.18s ease;
}


/* Sub-section: Input Focus State */
/*
 * Purpose: Dynamic focus styling that matches current colour or accent fallback
 * - Uses CSS custom property for runtime theming
 * - Applies subtle glow effect via box-shadow
*/
#colour-input:focus {
    /* Purpose: Border - dynamic colour from JS with accent fallback */
    border-color: var(--focus-colour, var(--accent));
    
    /* Purpose: Shadow - subtle glow using colour-aware alpha */
    box-shadow: 0 0 0 4px var(--focus-colour-alpha, rgba(76, 201, 240, 0.25));
}


/* Sub-section: Input Error State */
/*
 * Purpose: Red outline and styling for invalid colour input
 * - Overrides normal focus styles when invalid
 * - Stronger glow for clear error indication
*/
#colour-input.invalid {
    /* Purpose: Border - red indicates error state */
    border-color: #ff6b6b;
    
    /* Purpose: Shadow - strong red glow for feedback */
    box-shadow: 0 0 0 4px rgba(255, 107, 107, 0.3);
}


/* Sub-section: Placeholder Text */
/*
 * Purpose: Styled placeholder for input field
 * - Muted colour and centered alignment
 * - Automatically updates in demo mode
*/
#colour-input::placeholder {
    /* Purpose: Typography - muted and centred */
    color: var(--text-muted);
    opacity: 0.7;
    text-align: center;
}

/* ====================================================== */
/* SECTION: Visually Hidden – Screen reader accessibility */
/* ====================================================== */
/*
 * Purpose: Hide labels/elements visually but keep them accessible to screen readers
 * - Removes element from visual layout while preserving DOM presence
 * - Maintains keyboard focusability and screen reader announcement
 * - Complies with WCAG accessibility guidelines for visually hidden content
 *
 * Features:
 * - **Screen reader friendly**: Content remains in accessibility tree
 * - **Keyboard accessible**: Can still receive focus if needed
 * - **Semantic preservation**: Doesn't affect document structure or tab order
 * - **Standards compliant**: Follows established visually-hidden pattern
*/
.visually-hidden {
    /* Purpose: Remove from document flow */
    position: absolute;
    
    /* Purpose: Shrink to minimal size */
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    
    /* Purpose: Hide overflow and prevent content bleed */
    overflow: hidden;
    
    /* Purpose: Clip to invisible rectangle (legacy browser support) */
    clip: rect(0, 0, 0, 0);
    
    /* Purpose: Remove border if present */
    border: 0;
}


/* =================================================== */
/* SECTION: Colour Dropdown – Autocomplete Search      */
/* =================================================== */
/*
 * Purpose: Custom searchable dropdown for colour name suggestions
 * - Filters extendedNamedColours in real-time as user types
 * - Shows matching results below input field
 * - Click to select, keyboard navigable
 * - Accessible with proper contrast and styling
 * - Includes colour swatch preview for each result
 *
 * Features:
 * - **Real-time filtering**: Updates on every keystroke with 150ms debounce
 * - **Visual preview**: Colour swatches next to each result
 * - **Keyboard accessible**: Full navigation without mouse
 * - **Performance**: Limited to 20 results, debounced input
 * - **Smart UX**: Auto-hides when no matches or clicking outside
 * - **Custom scrollbar**: Styled to match app theme
*/
.colour-dropdown {
    /* Purpose: Positioning - below input field */
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 0.5rem;
    
    /* Purpose: Appearance - surface colour with glow */
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm), 0 0 0 6px var(--swatch-glow-colour-alpha, rgba(76, 201, 240, 0.25));
    
    /* Purpose: Layout constraints */
    max-height: 300px;
    overflow-y: auto;
    z-index: 1000;
    display: block;
}

.colour-dropdown.hidden {
    /* Purpose: Hide dropdown when not needed */
    display: none;
}

.dropdown-results {
    /* Purpose: Remove default list styling */
    list-style: none;
    margin: 0;
    padding: 0.5rem 0;
}

.dropdown-item {
    /* Purpose: Layout - flex row for swatch, name, and hex */
    display: flex;
    align-items: center;
    gap: 0.75rem;
    
    /* Purpose: Interactive styling */
    padding: 0.75rem 1rem;
    cursor: pointer;
    color: var(--text);
    
    /* Purpose: Smooth hover transition */
    transition: background 0.15s ease;
}

.dropdown-item:hover,
.dropdown-item.highlighted {
    /* Purpose: Highlight on hover or keyboard focus */
    background: rgba(76, 201, 240, 0.15);
}

.dropdown-item-swatch {
    /* Purpose: Visual colour preview */
    width: 20px;
    height: 20px;
    border-radius: 4px;
    border: 1px solid var(--text-muted);
    
    /* Purpose: Prevent shrinking on small screens */
    flex-shrink: 0;
}

.dropdown-item-name {
    /* Purpose: Colour name typography */
    font-weight: 500;
    
    /* Purpose: Fill remaining space in flex row */
    flex: 1;
}

.dropdown-item-hex {
    /* Purpose: Technical hex value display */
    font-family: monospace;
    font-size: 0.85em;
    color: var(--text-muted);
}


/* =================================================== */
/* SECTION: Dropdown Scrollbar – Custom styling        */
/* =================================================== */
/*
 * Purpose: Style the dropdown scrollbar to match app theme
 * - Consistent with overall dark aesthetic
 * - Uses accent colour for thumb (interactive part)
 * - Dark track blends with dropdown background
*/
.dropdown-results::-webkit-scrollbar {
    /* Purpose: Scrollbar width */
    width: 8px;
}

.dropdown-results::-webkit-scrollbar-track {
    /* Purpose: Track (background) styling */
    background: rgba(0, 0, 0, 0.3);
}

.dropdown-results::-webkit-scrollbar-thumb {
    /* Purpose: Thumb (draggable) styling */
    background: var(--accent);
    border-radius: 4px;
}


/* ================================================================= */
/* SECTION: Screensaver Demo Mode – Transitions                      */
/* ================================================================= */
/*
 * Purpose: Smooth background transition during automated colour cycling
 * - Extended transition duration creates an ambient, relaxed feel
 * - No visual indicators or animations — clean demo experience
 */
.hero-swatch.demo-active {
    /* Purpose: Extended transition for ambient effect */
    transition-duration: 0.6s;
}

/* SECTION: Input Demo Styling – Placeholder text indicator */
/*
 * Purpose: Styles the input placeholder when screensaver demo is active
 * - Italic styling distinguishes demo state from user input
 */
input.demo-active::placeholder {
    font-style: italic;
    opacity: 0.7;
}

/* SECTION: Clear Button Demo Mode – Hide during screensaver */
/*
 * Purpose: Hides clear button when screensaver demo is active
 * - Overrides visible state to prevent display during demo
 * - Maintains fade transition for smooth appearance
 * - Restores automatically when demo exits
*/
.clear-input.hidden-during-demo {
    /* Purpose: Force hide regardless of content state */
    opacity: 0 !important;
    pointer-events: none !important;
}


/* ===================================================== */
/* SECTION: Portrait Mobile – Small screen optimisations */
/* ===================================================== */
/*
 * Purpose: Improve readability and layout balance on narrow phone screens
 * - Shifts layout to top-aligned to eliminate dead vertical space
 * - Lets swatch grow to fit its content — no fixed height clipping
 * - Tightens inner padding so all colour values are visible
 * - Uses clamp() for smooth font scaling across device sizes
 *
 * Features:
 * - **Top-aligned layout**: justify-content: flex-start prevents centred dead space
 * - **Content-driven swatch**: height auto, no aspect-ratio — content sets the height
 * - **Overflow visible**: content is never clipped inside the swatch
 * - **Tighter padding**: swatch-content padding reduced to prevent overflow
 * - **Responsive typography**: fluid scaling prevents text being too small
 * - **Hierarchy preservation**: title and name sizes increase proportionally
*/
@media (max-width: 480px) {
    /* Purpose: Top-align layout to eliminate dead space above/below swatch */
    main {
        justify-content: flex-start;
        padding-top: 1.5rem;
        gap: 1rem;
    }

    /* Purpose: Let content height drive swatch size — remove clipping */
    .hero-swatch {
        width: min(92vw, 420px);
        aspect-ratio: unset;
        height: auto;
        max-height: none;
        overflow: visible;
    }

    /* Purpose: Tighter padding so all values fit comfortably */
    .swatch-content {
        padding: 1.25rem 1rem;
    }

    /* Purpose: Typography - scale down title slightly for narrow screens */
    .swatch-content h1 {
        font-size: clamp(2.2rem, 8vw, 3.2rem);
        margin-bottom: 0.25rem;
    }

    /* Purpose: Typography - scale up colour name for hierarchy */
    .swatch-content h2 {
        font-size: clamp(1.4rem, 6vw, 2rem);
        margin-bottom: 0.5rem;
    }

    /* Purpose: Typography - readable colour values, tighter line rhythm */
    .swatch-content p {
        font-size: clamp(0.95rem, 4vw, 1.3rem) !important;
        line-height: 1.5;
        letter-spacing: 0.02em;
        margin: 0.2rem 0;
    }
}

/* ============================================================ */
/* SECTION: Landscape Mobile – Optimised for horizontal viewing */
/* ============================================================ */
/*
 * Purpose: Adjusts layout and typography for landscape orientation on phones/tablets
 * - Reduces hero swatch dominance to show more UI elements without scrolling
 * - Increases text size for better readability in landscape mode
 * - Optimises spacing and layout for horizontal screen space
 *
 * Features:
 * - **Reduced swatch height**: Prevents swatch from dominating viewport (max 60vh)
 * - **Improved typography**: Larger, more readable text using clamp()
 * - **Smart spacing**: Adjusted margins and padding for horizontal orientation
 * - **Stacked layout**: Column flex layout works better in landscape
*/
@media (orientation: landscape) and (max-width: 960px) {
    /* Purpose: Main container layout adjustments for landscape */
    main {
        display: flex;
        flex-direction: column;
        align-items: center;
        padding: 2rem;
        height: auto;
    }

    /* Purpose: Increase colour value readability in landscape */
    .swatch-content p {
        font-size: clamp(1.0rem, 1.5vw, 1.5rem) !important;
        line-height: 1.4;
        letter-spacing: 0.02em;
        margin: 0.4rem 0;
    }

    /* Purpose: Hero swatch sizing and positioning */
    .hero-swatch {
        display: block !important;
        width: min(80vw, 500px) !important;
        aspect-ratio: 4 / 3;
        max-height: 40vh !important;
        margin: 0 auto 0.1rem auto !important;
        height: auto !important;
    }

    /* Purpose: Swatch content container constraints */
    .swatch-content {
        width: 100%;
        max-width: 500px;
        text-align: center;
        padding-bottom: 3rem;
        padding-top: 0 !important;
        margin-top: 0 !important;
    }

    /* Purpose: Title typography and spacing */
    .swatch-content h1 {
        margin-top: 1rem !important;
        margin-bottom: 0.5rem !important;
        font-size: clamp(1.2rem, 5vw, 3.0rem) !important;
    }

    /* Purpose: Input field layout and centering */
    #colour-input {
        display: block;
        width: 100%;
        margin-left: auto;
        margin-right: auto;
    }
}

/* =================================================== */
/* SECTION: Error States – Invalid colour feedback     */
/* =================================================== */
/*
 * Purpose: Comprehensive error styling for invalid colour input
 * - Provides visual feedback across multiple UI elements
 * - Uses consistent red accent (#ff6b6b) for cohesive error state
 * - Applied temporarily during validation errors, cleared immediately when valid
 *
 * Features:
 * - **Multi-element coordination**: Error styling on input, swatch, and text
 * - **High specificity**: Overrides default styling without !important (except glows)
 * - **Smooth transitions**: All error states animate in/out gracefully
 * - **Accessibility**: Colour + text-shadow ensures visibility on any background
 * - **Debounced application**: Only appears after user stops typing
*/

/* Sub-section: Colour Name Error Display */
/*
 * Purpose: Styles the "Invalid colour" message in h2 when parsing fails
 * - Larger, bolder text for prominence
 * - Red colour and glow matching input error state
*/
#display-named-colour.error-message {
    /* Purpose: Typography - prominent error text */
    font-size: 1.8rem !important;
    font-weight: 600 !important;
    
    /* Purpose: Colour - red indicates error state */
    color: #ff6b6b !important;
    
    /* Purpose: Visual effect - red glow for emphasis */
    text-shadow: 0 0 12px rgba(255, 107, 107, 0.6) !important;
    
    /* Purpose: Animation - smooth transition for appearance */
    transition: all 0.3s ease;
}

/* Purpose: Prevent click affordance during error display (overrides base rule) */
#display-named-colour.error-message {
    cursor: default;
    opacity: 1;
}

/* Sub-section: Error Title Styling */
/*
 * Purpose: Forces ChromaSense title (h1) to white during error state
 * - High specificity to override inherited colour
 * - Does not affect hex/rgb/hsl text elements
*/
.swatch-content h1.error-title {
    /* Purpose: Text colour - white for contrast on red glow */
    color: #ffffff !important;
    
    /* Purpose: Shadow - stronger shadow for readability */
    text-shadow: 0 1px 3px rgba(0,0,0,0.8) !important;
}


/* Sub-section: Hero Swatch Invalid State */
/*
 * Purpose: Applies red border and glow to swatch during error state
 * - Visual consistency with input error styling
 * - Provides cohesive error feedback across UI
*/
.hero-swatch.invalid {
    /* Purpose: Border - red indicates error */
    border: 2px solid #ff6b6b;
    
    /* Purpose: Shadow - red glow effect */
    box-shadow: var(--shadow-sm), 0 0 0 6px rgba(255, 107, 107, 0.3);
}


/* Sub-section: Error Title Red Glow */
/*
 * Purpose: Enhanced red glow effect for error title
 * - Stronger glow than base error state
 * - Final chosen intensity after testing
*/
.hero-swatch.invalid .swatch-content h1.error-title {
    /* Purpose: Combined red glow and shadow for maximum visibility */
    text-shadow: 0 0 25px rgba(255, 107, 107, 0.85), 0 1px 3px rgba(0,0,0,0.8) !important;
}


/* =================================================== */
/* SECTION: Dropdown Results Counter                  */
/* =================================================== */
/*
 * Purpose: Displays number of matches at top of dropdown
 * - Gives immediate feedback on search breadth
 * - **Sticky**: Remains visible while scrolling results
 * - Accessible via aria-live for screen readers
 * - Subtle styling that doesn't compete with results
*/
.dropdown-results-counter {
    /* Purpose: Layout and spacing */
    padding: 0.5rem 1rem;
    margin: 0;
    
    /* Purpose: Typography */
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
    
    /* Purpose: Visual separation */
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    
    /* Purpose: Prevent text wrapping */
    white-space: nowrap;
    
    /* Purpose: Sticky positioning - stays at top while scrolling */
    position: sticky;
    top: 0;
    background: var(--surface);
    z-index: 10;
}

/* =================================================== */
/* SECTION: Eyedropper Button – Screen colour picker   */
/* =================================================== */
/*
 * Purpose: Trigger button for the screen eyedropper feature
 * - Positioned inside the input container, left of the clear (\xd7) button
 * - Uses an inline SVG icon consistent with app aesthetic
 * - Always visible (not conditional on input content, unlike clear button)
 * - Hidden on browsers lacking both EyeDropper API and getDisplayMedia
 *
 * Features:
 * - **Persistent visibility**: Always available as a colour input method
 * - **Busy state**: Dims and disables during active pick session
 * - **Error state**: Brief red flash on permission denial
 * - **Demo coordination**: Hidden during screensaver mode
 * - **Accessible**: aria-label + title; keyboard focusable
*/
/* =================================================== */
/* SECTION: Input Button Group                         */
/* =================================================== */
/*
 * Purpose: Flex container for eyedropper, contrast, harmony, and help buttons
 * - Absolutely anchored to the right of the input container
 * - Buttons inside use flex layout — hidden buttons collapse automatically
 * - No need for per-button right: values or no-eyedropper padding hacks
 * - Clear button remains separately absolutely positioned (opacity-based show/hide)
 */
.input-btn-group {
    position: absolute;
    right: 3.4rem;
    top: 50%;
    transform: translateY(-50%);

    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.1rem;
}

@media (max-width: 480px) {
    .input-btn-group {
        right: 2.4rem;
    }
}


.eyedropper-btn {
    /* Purpose: Flex child — no absolute positioning needed */
    background: transparent;
    border: none;
    padding: 0.2rem 0.4rem;
    cursor: pointer;
    line-height: 1;

    /* Purpose: Icon colour — muted by default, accent on hover */
    color: var(--text-muted);
    opacity: 0.75;

    /* Purpose: Smooth transitions */
    transition: opacity 0.2s ease, color 0.2s ease;
}

.eyedropper-btn:hover,
.eyedropper-btn:focus {
    /* Purpose: Accent colour on hover for clear affordance */
    color: var(--accent);
    opacity: 1;
    outline: none;
}

.eyedropper-btn:focus-visible {
    /* Purpose: Keyboard focus ring (WCAG 2.4.7) */
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 4px;
}

.eyedropper-btn.eyedropper-busy {
    /* Purpose: Dimmed, non-interactive during active pick session */
    opacity: 0.35;
    cursor: wait;
}

.eyedropper-btn.eyedropper-error {
    /* Purpose: Brief red flash on permission denial */
    color: #ff6b6b;
    opacity: 1;
}

.eyedropper-btn[hidden] {
    /* Purpose: Truly remove from flex flow when unsupported */
    display: none;
}


/* =================================================== */
/* SECTION: Input Help Toggle Button (CR-035)          */
/* =================================================== */
/*
 * Purpose: ? button in the input container — opens/closes input help panel
 * - Flex child of .input-btn-group — no absolute positioning needed
 * - Circular pill shape consistent with panel help toggle pattern
 */
.input-help-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 50%;
    width: 1.3rem;
    height: 1.3rem;
    padding: 0;
    cursor: pointer;
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text-muted);
    opacity: 0.75;
    transition: opacity 0.2s ease, color 0.2s ease, border-color 0.2s ease;
    flex-shrink: 0;
}

.input-help-toggle:hover,
.input-help-toggle:focus {
    color: var(--accent);
    border-color: var(--accent);
    opacity: 1;
    outline: none;
}

.input-help-toggle:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.input-help-toggle.active {
    color: var(--accent);
    border-color: var(--accent);
    opacity: 1;
}


/* =================================================== */
/* SECTION: Input Help Panel (CR-035)                  */
/* =================================================== */
/*
 * Purpose: Novice-friendly help panel for the input container
 * - Injected below the input container by setupInputHelp() in main.js
 * - Same visual pattern as harmony and contrast panels
 * - Collapsed by default via max-height; revealed by .visible class
 * - pointer-events: none when collapsed to prevent click-trap issues
 */
.input-help-panel {
    width: min(90vw, 500px);
    margin-left: auto;
    margin-right: auto;

    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    border: 1px solid rgba(255, 255, 255, 0.06);

    max-height: 0;
    opacity: 0;
    pointer-events: none;

    transition: max-height 0.35s ease, opacity 0.25s ease,
                border-color 0.3s ease, box-shadow 0.3s ease;
}

.input-help-panel.visible {
    max-height: 800px;
    opacity: 1;
    pointer-events: auto;

    border-color: transparent;
    box-shadow: var(--shadow-sm),
                0 0 0 2px var(--swatch-glow-colour-alpha, rgba(76, 201, 240, 0.25));
}

.input-help-panel__inner {
    padding: 1rem 1.1rem 1.1rem;
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    max-height: 60vh;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--accent) transparent;
}

.input-help-panel__inner::-webkit-scrollbar {
    width: 4px;
}

.input-help-panel__inner::-webkit-scrollbar-thumb {
    background: var(--accent);
    border-radius: 4px;
}

.input-help-panel__header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}

.input-help-panel__header {
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.input-help-panel__close {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.1rem;
    font-weight: 300;
    line-height: 1;
    padding: 0.1rem 0.3rem;
    cursor: pointer;
    transition: color 0.2s ease;
}

.input-help-panel__close:hover,
.input-help-panel__close:focus {
    color: var(--text);
    outline: none;
}

.input-help-panel__close:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 3px;
}

.input-help__title {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text);
    margin: 0.65rem 0 0.2rem;
    letter-spacing: 0.01em;
}

.input-help__title:first-of-type {
    margin-top: 0;
}

.input-help__body {
    font-size: 0.72rem;
    color: var(--text);
    line-height: 1.6;
    margin: 0 0 0.3rem;
}
/* =================================================== */
/*
 * Purpose: Full-viewport overlays for Strategy B (getDisplayMedia fallback)
 *
 * Two overlay types:
 *  1. Instruction overlay — pre-permission information panel
 *  2. Canvas overlay — screenshot displayed for pixel picking
 *
 * Features:
 * - **Full viewport coverage**: Fixed positioning covers entire screen
 * - **High z-index**: Sits above changelog modal and all other UI
 * - **Focus trap**: tabindex and role=dialog for accessibility
 * - **Keyboard dismissal**: Escape key wired in JS
*/

/* Sub-section: Shared overlay backdrop */
#eyedropper-instruction-overlay,
#eyedropper-canvas-overlay {
    /* Purpose: Full-viewport fixed overlay */
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

/* Sub-section: Instruction overlay — dark backdrop with centred panel */
#eyedropper-instruction-overlay {
    /* Purpose: Semi-transparent backdrop */
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(4px);
}

#eyedropper-instruction-panel {
    /* Purpose: Centred content panel */
    background: var(--surface);
    border-radius: var(--radius);
    padding: 2rem 2.5rem;
    max-width: min(90vw, 480px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

#eyedropper-instruction-title {
    /* Purpose: Panel heading typography */
    font-size: 1.3rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 1rem;
}

#eyedropper-instruction-panel p {
    /* Purpose: Body copy */
    font-size: 0.95rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
    line-height: 1.6;
}

#eyedropper-instruction-panel ul {
    /* Purpose: Bullet list styling */
    list-style: none;
    padding: 0;
    margin: 0 0 1.5rem 0;
}

#eyedropper-instruction-panel li {
    /* Purpose: List item spacing and colour */
    font-size: 0.9rem;
    color: var(--text-muted);
    padding: 0.3rem 0;
    line-height: 1.5;
}

#eyedropper-instruction-panel li strong {
    /* Purpose: Emphasise key privacy points */
    color: var(--text);
    font-weight: 600;
}

#eyedropper-instruction-actions {
    /* Purpose: Action button row */
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
}

#eyedropper-cancel-instruction,
#eyedropper-continue {
    /* Purpose: Shared button base */
    padding: 0.6rem 1.4rem;
    border-radius: 8px;
    border: none;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: opacity 0.2s ease;
}

#eyedropper-cancel-instruction {
    /* Purpose: Secondary/cancel action — muted */
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-muted);
}

#eyedropper-continue {
    /* Purpose: Primary action — accent colour */
    background: var(--accent);
    color: #0f0f11;
}

#eyedropper-cancel-instruction:hover,
#eyedropper-continue:hover {
    opacity: 0.85;
}

#eyedropper-cancel-instruction:focus-visible,
#eyedropper-continue:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Sub-section: Canvas overlay — screenshot with crosshair cursor */
#eyedropper-canvas-overlay {
    /* Purpose: Dark backdrop around screenshot */
    background: rgba(0, 0, 0, 0.92);
    justify-content: flex-start;
}

#eyedropper-overlay-bar {
    /* Purpose: Instruction bar pinned to top of overlay */
    width: 100%;
    padding: 0.75rem 1.5rem;
    background: rgba(15, 15, 17, 0.95);
    color: var(--text);
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    flex-shrink: 0;
}

#eyedropper-display-canvas {
    /* Purpose: Screenshot canvas — fills remaining space, preserves aspect ratio */
    max-width: 100%;
    max-height: calc(100vh - 48px);
    object-fit: contain;
    cursor: crosshair;
    display: block;
}

#eyedropper-overlay-cancel {
    /* Purpose: Cancel button in overlay bar */
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: var(--text);
    padding: 0.35rem 1rem;
    border-radius: 6px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.2s ease;
    flex-shrink: 0;
}

#eyedropper-overlay-cancel:hover {
    background: rgba(255, 255, 255, 0.18);
}

#eyedropper-overlay-cancel:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}


/* =================================================== */
/* SECTION: Eyedropper Magnifier – Zoom inset panel    */
/* =================================================== */
/*
 * Purpose: Fixed inset panel showing a magnified preview of the area
 *          under the cursor during the Strategy B canvas pick session
 *
 * - Positioned in the bottom-right corner of the canvas overlay
 * - Contains a canvas (magnified pixels) and a hex label
 * - Hex label background matches the live preview colour
 * - Hidden until first mousemove (avoids blank panel on entry)
 *
 * Features:
 * - **Pixel-accurate**: imageSmoothingEnabled=false gives sharp pixel edges
 * - **Live contrast**: hex label text colour adapts to background luminance
 * - **Non-intrusive**: semi-transparent border, subtle shadow
 * - **Responsive**: fixed positioning relative to viewport, not canvas
*/
#eyedropper-magnifier {
    /* Purpose: Fixed position in bottom-right of overlay */
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 2100;

    /* Purpose: Layout — stack canvas above hex label */
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;

    /* Purpose: Visual container styling */
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.15);

    /* Purpose: Hidden until cursor enters canvas */
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
}

#eyedropper-magnifier.visible {
    /* Purpose: Show once cursor is over the screenshot canvas */
    opacity: 1;
}

#eyedropper-magnifier-canvas {
    /* Purpose: The magnified pixel view */
    display: block;
    width: 160px;
    height: 160px;
    image-rendering: pixelated;   /* Enforce sharp pixels in supporting browsers */
    image-rendering: crisp-edges;
}

#eyedropper-magnifier-hex {
    /* Purpose: Live hex value label — background matches preview colour */
    width: 100%;
    padding: 0.35rem 0.5rem;
    text-align: center;

    /* Purpose: Typography — monospace for hex values */
    font-family: monospace;
    font-size: 0.85rem;
    font-weight: 600;
    letter-spacing: 0.05em;

    /* Purpose: Default state before first sample */
    background: #1a1a20;
    color: var(--text);
    transition: background 0.08s ease, color 0.08s ease;
}

/* Sub-section: Overlay bar hint text */
#eyedropper-overlay-hint {
    /* Purpose: Flexible hint text that updates with zoom state */
    flex: 1;
    font-size: 0.9rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
