@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500&family=Space+Grotesk:wght@400;500;600&display=swap');

:root {
    --bg-0:        #05070d;
    --ink:         #eef1f8;
    --ink-dim:     #8a93a8;
    --ink-faint:   #565d74;
    --accent:      #7cf1ff;
    --line:        rgba(232, 236, 245, 0.10);
    --line-strong: rgba(232, 236, 245, 0.22);
    --glass:       rgba(10, 14, 26, 0.55);

    --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
    --sans: 'Space Grotesk', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

    --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: radial-gradient(ellipse at 50% 50%, #0b1226 0%, #05070d 55%, #02030a 100%);
    color: var(--ink);
    font-family: var(--sans);
    letter-spacing: 0.01em;
    -webkit-font-smoothing: antialiased;
    cursor: crosshair;
}

canvas { display: block; }

#canvas_container {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

/* ───── Atmospheric overlays ───── */
.vignette {
    position: fixed;
    inset: 0;
    z-index: 5;
    pointer-events: none;
    background:
        radial-gradient(ellipse at 50% 50%, transparent 45%, rgba(2, 3, 10, 0.7) 100%),
        radial-gradient(ellipse at 50% 120%, rgba(124, 241, 255, 0.06), transparent 60%);
}

.grain {
    position: fixed;
    inset: 0;
    z-index: 6;
    pointer-events: none;
    opacity: 0.16;
    mix-blend-mode: overlay;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='1.6' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.9 0 0 0 0 0.9 0 0 0 0 1 0 0 0 0.3 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
    background-size: 180px 180px;
    animation: grain-shift 4s steps(6) infinite;
}

@keyframes grain-shift {
    0%   { transform: translate3d(0, 0, 0);   }
    25%  { transform: translate3d(-6%, 4%, 0);}
    50%  { transform: translate3d(4%, -6%, 0);}
    75%  { transform: translate3d(-3%, 5%, 0);}
    100% { transform: translate3d(0, 0, 0);   }
}

/* ───── Brand wordmark (top-left) ───── */
.brand {
    position: fixed;
    top: 24px;
    left: 28px;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 12px;
    pointer-events: none;
    animation: fadeup 1s var(--ease) both;
}

.brand__mark {
    position: relative;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: radial-gradient(circle at 30% 30%, rgba(124, 241, 255, 0.35), rgba(124, 241, 255, 0) 70%);
    border: 1px solid var(--line-strong);
    box-shadow: 0 0 20px rgba(124, 241, 255, 0.16), inset 0 0 10px rgba(124, 241, 255, 0.12);
}

.brand__dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 10px var(--accent);
    animation: pulse 2.6s ease-in-out infinite;
}

.brand__wordmark {
    font-family: var(--sans);
    font-weight: 500;
    font-size: 12px;
    letter-spacing: 0.34em;
    color: var(--ink);
}

@keyframes pulse {
    0%, 100% { transform: scale(1);   opacity: 1;   }
    50%      { transform: scale(1.4); opacity: 0.55;}
}

@keyframes fadeup {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0);   }
}

/* ───── Bottom hint ───── */
.hint {
    position: fixed;
    bottom: 26px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 10px;
    font-family: var(--mono);
    font-size: 10px;
    color: var(--ink-dim);
    letter-spacing: 0.18em;
    pointer-events: none;
    animation: fadeup 1.2s var(--ease) both;
    animation-delay: 0.1s;
}

.hint kbd {
    font-family: var(--mono);
    font-size: 9px;
    padding: 3px 7px;
    border: 1px solid var(--line-strong);
    border-radius: 4px;
    color: var(--ink);
    background: var(--glass);
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.hint span {
    margin-right: 6px;
    text-transform: uppercase;
}

/* ───── Control surface ───── */
.controls {
    position: fixed;
    top: 24px;
    right: 24px;
    z-index: 12;
    width: 300px;
    padding: 18px 18px 16px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: linear-gradient(180deg, rgba(12, 17, 30, 0.82), rgba(8, 11, 22, 0.74));
    backdrop-filter: blur(20px) saturate(160%);
    -webkit-backdrop-filter: blur(20px) saturate(160%);
    box-shadow:
        0 20px 60px rgba(0, 0, 0, 0.45),
        inset 0 1px 0 rgba(255, 255, 255, 0.04);
    color: var(--ink);
    animation: fadeup 0.9s var(--ease) both;
    animation-delay: 0.15s;
}

.controls.is-collapsed .controls__body { display: none; }
.controls.is-collapsed { width: auto; padding: 10px 12px; }
.controls.is-collapsed .controls__head { margin-bottom: 0; }
.controls.is-collapsed .controls__toggle-bar:nth-child(2) { opacity: 0; }
.controls.is-collapsed .controls__toggle-bar:first-child  { transform: translateY(5px) rotate(45deg); }
.controls.is-collapsed .controls__toggle-bar:last-child   { transform: translateY(-5px) rotate(-45deg); }

.controls__toggle {
    position: absolute;
    top: 14px;
    right: 14px;
    width: 28px;
    height: 28px;
    padding: 0;
    display: grid;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: rgba(255, 255, 255, 0.03);
    cursor: pointer;
    transition: background .2s;
}

.controls__toggle:hover { background: rgba(255, 255, 255, 0.07); }

.controls__toggle-bar {
    display: block;
    width: 12px;
    height: 1px;
    margin: 2px 0;
    background: var(--ink);
    transition: transform .3s var(--ease), opacity .2s;
}

.controls__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-right: 40px;
    margin-bottom: 16px;
}

.controls__title {
    font-family: var(--sans);
    font-weight: 600;
    font-size: 11px;
    letter-spacing: 0.34em;
    color: var(--ink);
}

.controls__preset {
    font-family: var(--mono);
    font-size: 10px;
    letter-spacing: 0.22em;
    padding: 4px 10px;
    border-radius: 999px;
    background: linear-gradient(180deg, rgba(124, 241, 255, 0.14), rgba(124, 241, 255, 0.04));
    box-shadow: inset 0 0 0 1px rgba(124, 241, 255, 0.3);
    color: var(--accent);
}

.controls__body {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

/* ───── Groups ───── */
.group {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 0;
}

.group + .group {
    padding-top: 14px;
    border-top: 1px solid var(--line);
}

.group__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.group__label {
    font-family: var(--mono);
    font-size: 9px;
    letter-spacing: 0.28em;
    color: var(--ink-faint);
    text-transform: uppercase;
}

/* ───── Fields (sliders) ───── */
.field label {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    font-family: var(--sans);
    font-size: 12px;
    color: var(--ink-dim);
    margin-bottom: 8px;
    letter-spacing: 0.02em;
}

.field label output {
    font-family: var(--mono);
    font-size: 11px;
    color: var(--ink);
    font-feature-settings: "tnum" 1;
    padding: 2px 8px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--line);
    transition: color .2s, background .2s;
}

.field.is-active label output {
    color: var(--accent);
    background: rgba(124, 241, 255, 0.08);
    border-color: rgba(124, 241, 255, 0.3);
}

/* Native range — styled deeply */
input[type="range"] {
    --fill: 0%;
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 24px;
    background: transparent;
    cursor: pointer;
    outline: none;
    margin: 0;
}

input[type="range"]::-webkit-slider-runnable-track {
    height: 3px;
    background: linear-gradient(
        to right,
        var(--accent) 0%,
        var(--accent) var(--fill),
        rgba(255, 255, 255, 0.08) var(--fill),
        rgba(255, 255, 255, 0.08) 100%
    );
    border-radius: 999px;
}

input[type="range"]::-moz-range-track {
    height: 3px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 999px;
}

input[type="range"]::-moz-range-progress {
    height: 3px;
    background: var(--accent);
    border-radius: 999px;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #0c1324;
    border: 1.5px solid var(--accent);
    margin-top: -5.5px;
    box-shadow: 0 0 10px rgba(124, 241, 255, 0.5), inset 0 0 4px rgba(124, 241, 255, 0.4);
    cursor: grab;
    transition: transform .15s var(--ease), box-shadow .15s;
}

input[type="range"]::-webkit-slider-thumb:hover,
input[type="range"]:focus::-webkit-slider-thumb {
    transform: scale(1.15);
    box-shadow: 0 0 18px rgba(124, 241, 255, 0.8), inset 0 0 6px rgba(124, 241, 255, 0.5);
}

input[type="range"]:active::-webkit-slider-thumb { cursor: grabbing; }

input[type="range"]::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #0c1324;
    border: 1.5px solid var(--accent);
    box-shadow: 0 0 10px rgba(124, 241, 255, 0.5);
    cursor: grab;
}

/* Hue field gets a spectrum track */
.field--hue input[type="range"]::-webkit-slider-runnable-track {
    background: linear-gradient(90deg,
        hsl(0, 80%, 60%), hsl(60, 80%, 60%), hsl(120, 80%, 60%),
        hsl(180, 80%, 60%), hsl(240, 80%, 60%), hsl(300, 80%, 60%), hsl(360, 80%, 60%));
    opacity: 0.8;
}
.field--hue input[type="range"]::-moz-range-track {
    background: linear-gradient(90deg,
        hsl(0, 80%, 60%), hsl(60, 80%, 60%), hsl(120, 80%, 60%),
        hsl(180, 80%, 60%), hsl(240, 80%, 60%), hsl(300, 80%, 60%), hsl(360, 80%, 60%));
    opacity: 0.8;
}
.field--hue input[type="range"]::-moz-range-progress { background: transparent; }

/* ───── Toggles ───── */
.toggles {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toggle {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    user-select: none;
    font-size: 12px;
    color: var(--ink-dim);
    transition: color .2s;
}

.toggle:hover { color: var(--ink); }

.toggle input { position: absolute; opacity: 0; pointer-events: none; }

.toggle__track {
    position: relative;
    width: 30px;
    height: 16px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--line);
    transition: background .25s var(--ease), border-color .25s;
    flex-shrink: 0;
}

.toggle__thumb {
    position: absolute;
    top: 1px;
    left: 1px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--ink-dim);
    transition: transform .25s var(--ease), background .25s;
}

.toggle input:checked ~ .toggle__track {
    background: rgba(124, 241, 255, 0.2);
    border-color: rgba(124, 241, 255, 0.5);
}

.toggle input:checked ~ .toggle__track .toggle__thumb {
    transform: translateX(14px);
    background: var(--accent);
    box-shadow: 0 0 10px var(--accent);
}

.toggle__text {
    font-family: var(--sans);
    letter-spacing: 0.02em;
}

/* ───── Action buttons ───── */
.actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 2px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 12px;
    border-radius: 8px;
    font-family: var(--sans);
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    cursor: pointer;
    border: 1px solid var(--line-strong);
    background: rgba(255, 255, 255, 0.03);
    color: var(--ink);
    transition: all .2s var(--ease);
}

.btn:hover {
    background: rgba(255, 255, 255, 0.07);
    transform: translateY(-1px);
}

.btn:active { transform: translateY(0); }

.btn__icon {
    font-size: 14px;
    line-height: 1;
    display: inline-block;
}

.btn--ghost .btn__icon {
    display: inline-block;
    transition: transform .45s var(--ease);
}

.btn--ghost:hover .btn__icon { transform: rotate(180deg); }

.btn--primary {
    background: linear-gradient(180deg, rgba(124, 241, 255, 0.18), rgba(124, 241, 255, 0.06));
    border-color: rgba(124, 241, 255, 0.5);
    color: var(--accent);
    box-shadow: 0 0 16px rgba(124, 241, 255, 0.15);
}

.btn--primary:hover {
    background: linear-gradient(180deg, rgba(124, 241, 255, 0.3), rgba(124, 241, 255, 0.1));
    box-shadow: 0 0 24px rgba(124, 241, 255, 0.3);
}

/* ───── Presets ───── */
.presets {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
}

.preset {
    padding: 8px 6px;
    font-family: var(--mono);
    font-size: 9px;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.02);
    color: var(--ink-dim);
    cursor: pointer;
    transition: all .2s var(--ease);
    position: relative;
    overflow: hidden;
}

.preset::before {
    content: "";
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at 50% 120%, var(--preset-color, rgba(124, 241, 255, 0.4)), transparent 70%);
    opacity: 0;
    transition: opacity .25s;
}

.preset:hover { color: var(--ink); border-color: var(--line-strong); }
.preset:hover::before { opacity: 0.5; }

.preset.is-active {
    color: var(--ink);
    border-color: rgba(124, 241, 255, 0.4);
    background: rgba(124, 241, 255, 0.06);
}

.preset.is-active::before { opacity: 0.7; }

.preset[data-preset="aurora"] { --preset-color: rgba(124, 241, 255, 0.5); }
.preset[data-preset="ember"]  { --preset-color: rgba(255, 140, 80, 0.55);  }
.preset[data-preset="abyss"]  { --preset-color: rgba(110, 90, 220, 0.5);   }
.preset[data-preset="bloom"]  { --preset-color: rgba(255, 120, 180, 0.55); }
.preset[data-preset="pulse"]  { --preset-color: rgba(180, 255, 200, 0.5);  }

/* ───── Responsive ───── */
@media (max-width: 680px) {
    .controls {
        top: auto;
        bottom: 16px;
        right: 16px;
        left: 16px;
        width: auto;
    }
    .hint { display: none; }
    .brand__wordmark { display: none; }
}
