/* ========================
   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:                  #0f0f11;     /* Main background */
    --bg-safe:             var(--bg);   /* Dynamically set to lightened value when needed */
    --surface:             #1a1a20;     /* 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: 3rem;
    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, 700px);
    aspect-ratio: 4 / 3;
    
    /* 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 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
 * - Reduced size to compensate for monospace visual weight
 * - Hover feedback indicates interactivity (click-to-copy)
 *
 * Features:
 * - **Monospace typography**: Cleaner alignment for technical values
 * - **Interactive feedback**: Subtle opacity change on hover
 * - **Standards compliance**: Hex values uppercase per developer convention
 * - **Weight balance**: Lighter font-weight compensates for monospace density
*/
#display-hex-value,
#display-rgb-value,
#display-hsl-value {
    /* Purpose: Typography - monospace styling for code appearance */
    font-family: monospace;
    font-size: 1.2em;
    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 */
    width: 100%;
    padding: 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 – Visual indicator and transitions */
/* ================================================================= */
/*
 * Purpose: Styles the subtle demo mode indicator and controls transition speed
 * - Small pulsing dot in top-right corner of hero swatch
 * - Provides gentle visual feedback during automated colour cycling
 * - Extends transition duration for smooth, ambient colour changes
 *
 * Features:
 * - **Position**: Absolute positioning keeps dot in swatch corner during scroll
 * - **Animation**: 2s pulse cycle with opacity and scale transitions
 * - **Opacity transition**: Smooth fade in/out when demo starts/ends
 * - **Background safety**: Semi-transparent white works on any background colour
 * - **Speed control**: Extends transition duration during demo for ambient effect
*/
.hero-swatch::after {
    /* Purpose: Layout and positioning */
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    
    /* Purpose: Appearance styling */
    background: rgba(255, 255, 255, 0.4);
    opacity: 0;
    
    /* Purpose: Smooth fade in/out transition */
    transition: opacity 0.3s;
}

.hero-swatch.demo-active::after {
    /* Purpose: Show indicator during demo mode */
    opacity: 1;
    
    /* Purpose: Continuous pulsing animation */
    animation: pulse 2s infinite;
}

/* SECTION: Keyframe Animations – Demo mode pulsing effect */
/*
 * Purpose: Defines the pulsing animation for demo mode indicator
 * - Smooth scale and opacity cycle
 * - Subtle but noticeable visual cue
*/
@keyframes pulse {
    0%, 100% { 
        transform: scale(1); 
        opacity: 0.4; 
    }
    50% { 
        transform: scale(1.5); 
        opacity: 0.1; 
    }
}

/* SECTION: Hero Swatch Demo Transition – Ambient effect */
/*
 * Purpose: Slower background transition for ambient demo effect
 * - Extends transition duration during automated cycling
 * - Creates smooth, relaxed visual 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
 * - Provides subtle visual distinction for demo state awareness
 * - Uses italic styling to differentiate from user input
 * - Maintains readability with appropriate opacity
*/
input.demo-active::placeholder {
    /* Purpose: Typography - italic to indicate demo state */
    font-style: italic;
    
    /* Purpose: Appearance - reduced opacity for subtlety */
    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
 * - Increases hex/rgb/hsl text size for better legibility in portrait
 * - Boosts title hierarchy for visual balance
 * - Uses clamp() for smooth scaling across device sizes and zoom levels
 *
 * Features:
 * - **Responsive typography**: Fluid scaling prevents text being too small
 * - **Hierarchy preservation**: Title and name sizes increase proportionally
 * - **Performance**: Modern clamp() avoids multiple media query breakpoints
 * - **User comfort**: Larger text reduces eye strain on small screens
*/
@media (max-width: 480px) {
    /* Purpose: Typography - larger colour values for readability */
    .swatch-content p {
        font-size: clamp(1.0rem, 4.5vw, 1.5rem) !important;
        line-height: 1.4;
        letter-spacing: 0.02em;
        margin: 0.4rem 0;
    }

    /* Purpose: Typography - scale up title for hierarchy */
    .swatch-content h1 {
        font-size: clamp(2.8rem, 10vw, 4.2rem);
    }

    /* Purpose: Typography - scale up colour name for balance */
    .swatch-content h2 {
        font-size: clamp(1.6rem, 7vw, 2.2rem);
    }
}

/* ============================================================ */
/* 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: 60vh !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: Demo Mode Enhanced Pulsing Effects           */
/* ===================================================== */
/*
 * Purpose: Creates dramatic, synchronized pulsing animations during demo mode
 * - Uses CSS custom properties that Chrome cannot optimize away
 * - Works reliably in both Chrome and Safari
*/

/* Sub-section: Demo Pulsing Glow Animation */
@keyframes demo-pulse-glow {
    0%, 100% { 
        box-shadow: var(--shadow-sm), 0 0 0 6px var(--swatch-glow-colour-alpha, rgba(76, 201, 240, 0.25));
    }
    50% { 
        box-shadow: var(--shadow-sm), 0 0 0 15px var(--swatch-glow-colour-alpha, rgba(76, 201, 240, 0.5));
    }
}

/* Sub-section: Demo Text Pulse Animation (Chrome-compatible) */
/*
 * Purpose: Uses custom property trick to force Chrome to animate
 * - Animates a CSS variable that the placeholder inherits
 * - Chrome can't optimize this away because it's "live"
*/
@keyframes demo-pulse-text-chrome {
    0%, 100% { 
        --placeholder-opacity: 1;
        --placeholder-color: var(--text-muted);
    }
    50% { 
        --placeholder-opacity: 0.3;
        --placeholder-color: var(--accent);
    }
}

/* Sub-section: Swatch & Input Demo Glow */
.hero-swatch.demo-active {
    animation: demo-pulse-glow 2.5s infinite ease-in-out;
}

input.demo-active {
    animation: demo-pulse-glow 2.5s infinite ease-in-out;
    /* Define custom properties on input itself */
    --placeholder-opacity: 1;
    --placeholder-color: var(--text-muted);
    animation: demo-pulse-glow 2.5s infinite ease-in-out,
               demo-pulse-text-chrome 2.5s infinite ease-in-out;
}

/* Sub-section: Chrome-compatible Placeholder Animation */
input.demo-active::placeholder {
    opacity: var(--placeholder-opacity);
    color: var(--placeholder-color) !important;
    transition: opacity 0.3s ease, color 0.3s ease;
}

/* Sub-section: Remove Dot Indicator */
.hero-swatch::after,
.hero-swatch.demo-active::after {
    display: none !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;
}