:root {
    /* --- Colors (OKLCH) --- */
    --background: oklch(1.0000 0 0);
    --foreground: oklch(0.2686 0 0);
    --card: oklch(1.0000 0 0);
    --card-foreground: oklch(0.2686 0 0);
    --primary: oklch(0.7686 0.1647 70.0804);
    --primary-foreground: oklch(0 0 0);
    --secondary: oklch(0.9670 0.0029 264.5419);
    --secondary-foreground: oklch(0.4461 0.0263 256.8018);
    --muted: oklch(0.9846 0.0017 247.8389);
    --muted-foreground: oklch(0.5510 0.0234 264.3637);
    --accent: oklch(0.9869 0.0214 95.2774);
    --accent-foreground: oklch(0.4732 0.1247 46.2007);
    --border: oklch(0.9276 0.0058 264.5313);

    /* --- Typography --- */
    --font-sans: 'Inter', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    --font-title: 'Orbitron', sans-serif;

    /* --- Spacing & Radius --- */
    --radius: 0.375rem;
    --radius-sm: 4px;
    --spacing: 0.25rem;

    /* --- Shadows --- */
    --shadow-sm: 0px 1px 2px 0px hsl(0 0% 0% / 0.05);
    --shadow: 0px 4px 6px -1px hsl(0 0% 0% / 0.1), 0px 2px 4px -2px hsl(0 0% 0% / 0.1);
}

/* --- Base --- */
body {
    font-family: var(--font-sans);
    background-color: var(--background);
    color: var(--foreground);
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    margin: 0;
}

/* --- Header --- */
.header-row {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: calc(var(--spacing) * 3) calc(var(--spacing) * 6);
    background-color: var(--card);
    border-bottom: 1px solid var(--border);
    z-index: 10;
}

.glitch-title {
    margin: 0;
    font-family: var(--font-title);
    font-size: 1.25rem;
    font-weight: 800;
    letter-spacing: 0.15em;
    color: var(--foreground);
    position: relative;
    text-shadow: 0 0 10px rgba(121, 196, 236, 0.2);
    animation: title-flicker 4s linear infinite;
    text-transform: uppercase;
}

.glitch-title::after {
    content: attr(data-text);
    position: absolute;
    left: 0; top: 0; width: 100%; height: 100%;
    opacity: 0.1;
    color: var(--primary);
    z-index: -1;
    filter: blur(2px);
    animation: title-ghost 4s ease-out infinite;
}

@keyframes title-flicker {
    0%, 19.999%, 22%, 62.999%, 64%, 64.999%, 70%, 100% { opacity: 1; }
    20%, 21.999%, 63%, 63.999%, 65%, 69.999% { opacity: 0.8; }
}

@keyframes title-ghost {
    0%, 100% { transform: translate(0); }
    10%, 15% { transform: translate(-2px, 1px); }
    11% { transform: translate(2px, -1px); }
    12% { transform: translate(0); }
}

/* --- Controls --- */
.controls-container {
    display: flex;
    align-items: center;
    gap: calc(var(--spacing) * 4);
    position: relative;
}

.control-btn {
    padding: 7px 16px;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--primary-foreground);
    background-color: var(--primary);
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: opacity 0.2s, background-color 0.2s;
    font-family: inherit;
    line-height: 1;
}

.control-btn:hover { opacity: 0.9; }

.secondary-btn {
    background-color: var(--secondary);
    color: var(--secondary-foreground);
}

.mode-selector {
    display: flex;
    background-color: var(--muted);
    padding: 1px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    align-items: center;
}

.mode-btn {
    background: transparent;
    border: none;
    padding: 6px 14px;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--muted-foreground);
    cursor: pointer;
    border-radius: calc(var(--radius) - 2px);
    transition: all 0.15s ease;
    font-family: inherit;
    line-height: 1;
}

.mode-btn.active {
    background-color: var(--card);
    color: var(--foreground);
    box-shadow: var(--shadow-sm);
}

/* --- Settings Panel --- */
#settingsBtn {
    display: flex;
    align-items: center;
    gap: 6px;
    background: transparent;
    border: 1px solid var(--border);
    padding: 6px 12px;
    border-radius: var(--radius);
    color: var(--muted-foreground);
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s;
    font-family: inherit;
    line-height: 1.2;
}

#settingsBtn:hover, #settingsBtn.active {
    background-color: var(--muted);
    color: var(--foreground);
}

.settings-panel {
    position: absolute;
    top: 120%; left: 50%;
    transform: translateX(-50%);
    width: 240px;
    background-color: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: calc(var(--spacing) * 5);
    box-shadow: var(--shadow);
    z-index: 50;
    display: flex;
    flex-direction: column;
    gap: calc(var(--spacing) * 5);
    max-height: 80vh;
    overflow-y: auto;
}

.settings-panel.hidden { display: none; }

.setting-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.setting-group label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--muted-foreground);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.setting-group select, .setting-group input {
    font-family: var(--font-sans);
    font-size: 0.875rem;
    padding: 4px;
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) - 2px);
    background-color: var(--background);
    color: var(--foreground);
}

/* --- Image Area --- */
.image-container {
    flex: 1;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    background-color: var(--muted);
    padding: calc(var(--spacing) * 4);
}

.canvas-container {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%; height: 100%;
}

canvas {
    display: block;
    max-width: 100%; max-height: 100%;
    width: auto; height: auto;
    border-radius: var(--radius);
    background-color: var(--card);
    cursor: crosshair;
}

/* --- Overlays --- */
.loading-overlay, .tone-overlay {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background-color: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(8px) grayscale(0.5);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 20;
    overflow: hidden;
}

.tone-overlay {
    background-color: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(4px);
    z-index: 30;
    cursor: wait;
}

.hidden { display: none; }

.alien-spinner {
    width: 50px; height: 50px;
    background: var(--accent);
    border-radius: 50%;
    animation: alien-pulse 0.5s infinite linear alternate;
    box-shadow: 0 0 40px var(--accent);
}

@keyframes alien-pulse {
    0% { transform: scale(0.85); opacity: 0.6; }
    100% { transform: scale(1.15); opacity: 1; }
}

/* --- Footer --- */
.info-panel {
    flex: 0 0 auto;
    display: flex;
    justify-content: center;
    gap: calc(var(--spacing) * 6);
    padding: calc(var(--spacing) * 3) calc(var(--spacing) * 6);
    background-color: var(--card);
    border-top: 1px solid var(--border);
    flex-wrap: wrap;
}

.info-item {
    display: flex;
    align-items: center;
    gap: calc(var(--spacing) * 2);
}

.info-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--muted-foreground);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    min-width: 35px;
    margin-right: var(--spacing);
    flex-shrink: 0;
}

#hexValue { min-width: 70px; }
#rgbValue { min-width: 130px; }
#coordsValue { min-width: 90px; }

#hexValue, #rgbValue, #coordsValue {
    font-family: var(--font-mono);
    font-size: 0.875rem;
    color: var(--foreground);
    display: inline-block;
    text-align: left;
}

#visualizer {
    display: block;
    background-color: var(--muted);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    width: 80px; height: 24px;
    cursor: default;
}

.colour-preview-container {
    display: flex;
    align-items: center;
    gap: calc(var(--spacing) * 2);
}

.colour-swatch {
    width: 18px; height: 18px;
    border-radius: 4px;
    border: 1px solid var(--border);
    background-color: var(--muted);
}