/* ============================================================
   DISPLAY-CFG — self-contained stylesheet
   Palette and controls referenced from /glitch-fx/css/style.css
   (independent copy).
   ============================================================ */

* {
    margin: 0;
    padding: 0;
    border: 0;
    outline: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: rgba(0,0,0,0);
}

@font-face {

    font-display: swap;
    font-family: 'JetBrains Mono';
    font-style: normal;
    font-weight: 100 800;
    src: url('../fonts/jetbrains-mono-vf.ttf') format('truetype');

}

:root {

    --fx-purple:        #6c47ff;
    --fx-purple-soft:   #221456;
    --fx-purple-glow:   hsla(252, 100%, 64%, 0.45);
    --fx-purple-glow-alt:   hsla(252, 100%, 64%, 0.2);
    --fx-red:           color(display-p3 1 .25 .39);
    --fx-green:         color(display-p3 0.3 1 0.7);
    --fx-green-soft:    color(display-p3 0.3 1 0.7 / 0.15);
    --fx-yellow:        color(display-p3 1 0.7 0.18);

    --fx-txt:           hsl(240, 20%, 80%);
    --fx-txt-dim:       hsl(240, 10%, 50%);
    --fx-txt-low:       hsl(240, 15%, 30%);

    --fx-bg:            #111117;
    --fx-bg-2:          #15151d;
    --fx-bg-3:          #232333;
    --fx-bg-4:          #1c1c28;
    --fx-bg-toggle:     #323248;
    --fx-range-trail:   #39267f;
    --fx-line:          hsla(240, 15%, 25%, 0.5);
    --fx-line-strong:   hsla(240, 15%, 30%, 0.85);

    --fx-pad:           1.5em;
    --fx-radius:        0.5em;
    --fx-radius-small:  0.25em;
    --fx-mono:          "JetBrains Mono", Consolas, "Andale Mono", "DejaVu Sans Mono", "Liberation Mono", Monaco, "Courier New", Courier, monospace;
    --fx-letter-spacing: 0;
    --fx-letter-spacing-progress-bar: 0.1em;

}

html, body {
    height: 100%;
    background: var(--fx-bg);
    color: var(--fx-txt);
    font-family: var(--fx-mono);
    font-size: 15px;
    line-height: 1.4;
    font-weight: 500;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ---------- Layout ---------- */

.app {
    display: grid;
    grid-template-rows: minmax(0, 1fr);
    height: 100%;
}

/* Controls sit on the left, the stage on the right. */
.app-main {
    display: grid;
    grid-template-columns: 26em minmax(0, 1fr);
    min-height: 0;
}

.panel {
    min-height: 0;
    min-width: 0;
    overflow: hidden;
}

/* The real /display iframe fills the whole panel. */
.panel-stage {
    background: var(--fx-bg);
    border-left: 1px solid rgb(0 0 0 / 50%);
}
.panel-stage iframe {
    display: block;
    width: 100%;
    height: 100%;
    border: 0;
    background: var(--fx-bg);
}

.panel-controls {
    background: var(--fx-bg-2);
    overflow-y: auto;
    border-right: 1px solid var(--fx-line);
}

/* ---------- Buttons ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4em;
    padding: 0.85em 1.2em;
    font-family: inherit;
    font-size: 0.85em;
    font-weight: 700;
    letter-spacing: var(--fx-letter-spacing);
    color: var(--fx-txt);
    background: var(--fx-bg-3);
    border: 1px solid var(--fx-line-strong);
    border-radius: var(--fx-radius);
    cursor: pointer;
    user-select: none;
    transition: background 0.12s, border-color 0.12s, color 0.12s;
    text-transform: uppercase;
}
.btn:hover {
    border-color: var(--fx-purple);
    color: var(--fx-purple);
    background: var(--fx-purple-soft);
}
.btn:disabled {
    opacity: 1;
    cursor: not-allowed;
    color: var(--fx-txt-low);
    background: transparent;
    border-color: var(--fx-line);
}
.btn:disabled:hover {
    color: var(--fx-txt-low);
    border-color: var(--fx-line);
    background: var(--fx-bg-2);
}
.btn-ghost {
    background: transparent;
    border-color: var(--fx-line);
    color: var(--fx-txt-dim);
}
.btn-ghost:hover {
    color: var(--fx-purple);
    border-color: var(--fx-purple);
}

.btn-primary {
    background: var(--fx-purple);
    border-color: var(--fx-purple);
    color: #fff;
}
.btn-primary:hover {
    color: #fff;
    background: hsl(252, 100%, 70%);
    border-color: hsl(252, 100%, 70%);
}

/* ---------- Controls panel ---------- */

.ctl-section {
    border-bottom: 1px solid var(--fx-line);
    padding: var(--fx-pad);
}

.ctl-section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.1em;
}

.ctl-section.is-collapsible .ctl-section-head {
    cursor: pointer;
    user-select: none;
}
.ctl-section.is-collapsible:not(.is-open) .ctl-section-head {
    margin-bottom: 0;
}
.ctl-section.is-collapsible:not(.is-open) .ctl-section-body {
    display: none;
}
.ctl-section-caret {
    color: var(--fx-txt-low);
    font-size: 0.85em;
    line-height: 1;
}
.ctl-section-caret .fa-angle-up { display: none; }
.ctl-section.is-open .ctl-section-caret .fa-angle-down { display: none; }
.ctl-section.is-open .ctl-section-caret .fa-angle-up { display: inline; }

.ctl-title {
    font-size: 0.85em;
    font-weight: 700;
    letter-spacing: var(--fx-letter-spacing);
    color: var(--fx-purple);
}

.effects-list {
    display: flex;
    flex-direction: column;
    gap: 0.7em;
}

.fx-card {
    border: 1px solid var(--fx-line);
    border-radius: var(--fx-radius);
    background: var(--fx-bg);
    overflow: hidden;
    transition: border-color 0.15s;
}

.fx-head {
    display: flex;
    align-items: center;
    gap: 0.85em;
    padding: 0.85em 1em;
    cursor: pointer;
    background: var(--fx-bg-4);
    -webkit-user-select: none;
    user-select: none;
}

.fx-toggle {
    width: 2em;
    height: 1.1em;
    border-radius: 1em;
    background: var(--fx-bg-toggle);
    position: relative;
    flex-shrink: 0;
    transition: background 0.15s, border-color 0.15s;
}
.fx-toggle::after {
    content: '';
    position: absolute;
    width: 0.75em;
    height: 0.75em;
    border-radius: 50%;
    background: var(--fx-txt-dim);
    top: 50%;
    left: 0.15em;
    transform: translateY(-50%);
    transition: left 0.15s, background 0.15s;
}
.fx-card.is-on .fx-toggle {
    background: var(--fx-purple);
}
.fx-card.is-on .fx-toggle::after {
    left: calc(100% - 0.9em);
    background: #fff;
}

.fx-name {
    flex: 1;
    font-size: 0.9em;
    font-weight: 700;
    letter-spacing: var(--fx-letter-spacing);
    color: var(--fx-txt);
    text-transform: uppercase;
}
.fx-card.is-on .fx-name { color: var(--fx-purple); }

.fx-caret {
    color: var(--fx-txt-low);
    font-size: 0.78em;
}

.fx-caret .fa-angle-up { display: none; }
.fx-card.is-open .fx-caret .fa-angle-down { display: none; }
.fx-card.is-open .fx-caret .fa-angle-up { display: inline; }

.fx-body {
    display: none;
    padding: 1em 1em 1.1em;
    border-top: 1px solid var(--fx-line);
    background: var(--fx-bg-2);
}
.fx-card.is-open .fx-body { display: block; }

.fx-param {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0.4em 0.6em;
    margin-bottom: 1em;
}
.fx-param:last-child { margin-bottom: 0; }

.fx-param-label {
    font-size: 0.8em;
    color: var(--fx-txt-dim);
    letter-spacing: var(--fx-letter-spacing);
    text-transform: uppercase;
}
.fx-param-val {
    font-size: 0.8em;
    color: var(--fx-green);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}
.fx-param input[type="range"] {
    grid-column: 1 / -1;
    width: 100%;
}

input[type="range"] {
    appearance: none;
    -webkit-appearance: none;
    /* --fx-range-t is the 0..1 value ratio, kept in sync by js/app.js.
       The thumb centre only travels across (100% - thumb width). */
    --fx-range-t: 0;
    --fx-range-thumb: 1.2em;
    --fx-range-pos: calc(var(--fx-range-thumb) / 2 + var(--fx-range-t) * (100% - var(--fx-range-thumb)));
    background: linear-gradient(to right, var(--fx-range-trail) 0 var(--fx-range-pos), var(--fx-bg-3) var(--fx-range-pos) 100%);
    border-radius: 1em;
    outline: none;
    cursor: pointer;
}
input[type="range"]::-moz-range-track {
    background: var(--fx-bg-3);
    border-radius: 1em;
}
input[type="range"]::-moz-range-progress {
    background: var(--fx-range-trail);
    border-radius: 1em;
}
input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    -webkit-appearance: none;
    width: var(--fx-range-thumb);
    height: var(--fx-range-thumb);
    border-radius: 50%;
    background: var(--fx-purple);
    border: none;
    cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
    width: var(--fx-range-thumb);
    height: var(--fx-range-thumb);
    border-radius: 50%;
    background: var(--fx-purple);
    border: none;
    cursor: pointer;
}

.ctl-row {
    display: flex;
    gap: 0.6em;
}
.ctl-row .btn { flex: 1; }

.ctl-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.7em;
    font-size: 0.85em;
    font-weight: 700;
    letter-spacing: var(--fx-letter-spacing);
    text-transform: uppercase;
    color: var(--fx-txt-dim);
    cursor: pointer;
    user-select: none;
}
.ctl-toggle input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
    pointer-events: none;
}
.ctl-toggle-box {
    position: relative;
    width: 1.5em;
    height: 1.5em;
    border-radius: calc(var(--fx-radius) - 0.15em);
    background: var(--fx-bg-3);
    flex-shrink: 0;
    transition: background 0.15s;
}
.ctl-toggle-box::after {
    content: "";
    position: absolute;
    left: 50%;
    top: 45%;
    width: 0.36em;
    height: 0.7em;
    border-right: 2px solid #fff;
    border-bottom: 2px solid #fff;
    transform: translate(-50%, -50%) rotate(45deg) scale(0);
    opacity: 0;
    transition: transform 0.18s cubic-bezier(0.4, 1.5, 0.5, 1), opacity 0.12s;
}
.ctl-toggle input:checked ~ .ctl-toggle-box {
    background: var(--fx-purple);
}
.ctl-toggle input:checked ~ .ctl-toggle-box::after {
    transform: translate(-50%, -50%) rotate(45deg) scale(0.8);
    opacity: 1;
}
.ctl-toggle input:focus-visible ~ .ctl-toggle-box {
    outline: 2px solid var(--fx-purple);
    outline-offset: 2px;
}
.ctl-toggle input:checked ~ .ctl-toggle-label {
    color: var(--fx-txt);
}
.ctl-toggle-label {
    transition: color 0.12s;
}

/* ---------- Scrollbar ---------- */
.panel-controls::-webkit-scrollbar { width: 0.5em; }
.panel-controls::-webkit-scrollbar-track { background: transparent; }
.panel-controls::-webkit-scrollbar-thumb {
    background: var(--fx-line-strong);
    border-radius: 1em;
}
.panel-controls::-webkit-scrollbar-thumb:hover { background: var(--fx-purple); }

/* ---------- Custom Dropdown ---------- */

.dropdown {
    position: relative;
    display: inline-block;
    min-width: 11em;
    user-select: none;
}

.dropdown-trigger {
    display: flex;
    align-items: center;
    gap: 0.6em;
    width: 100%;
    padding: 0.85em 1.2em;
    background: transparent;
    border: 1px solid var(--fx-line);
    border-radius: var(--fx-radius);
    color: var(--fx-txt-dim);
    font-family: inherit;
    font-size: 0.85em;
    font-weight: 700;
    letter-spacing: var(--fx-letter-spacing);
    text-transform: uppercase;
    cursor: pointer;
    transition: border-color 0.12s, color 0.12s;
}
.dropdown-trigger:hover {
    background: var(--fx-purple-soft);
    color: var(--fx-purple);
}
.dropdown.is-open .dropdown-trigger {
    background: var(--fx-purple-soft);
    border-color: var(--fx-purple);
    color: var(--fx-purple);
}
.dropdown-trigger-label {
    flex: 1;
    text-align: left;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}
.dropdown-trigger-arrow {
    flex-shrink: 0;
    font-size: 0.9em;
    line-height: 1;
}
.dropdown-trigger-arrow .fa-angle-up { display: none; }
.dropdown.is-open .dropdown-trigger-arrow .fa-angle-down { display: none; }
.dropdown.is-open .dropdown-trigger-arrow .fa-angle-up { display: inline; }

.dropdown-menu {
    position: fixed;
    z-index: 200;
    max-height: 18em;
    overflow-y: auto;
    background: var(--fx-bg-2);
    border: 1px solid var(--fx-line-strong);
    border-radius: var(--fx-radius);
    padding: 0.3em;
    display: none;
    box-shadow: 0 0.6em 1.5em rgba(0,0,0,0.4);
}
.dropdown.is-open .dropdown-menu { display: block; }

.dropdown-option {
    display: block;
    padding: 0.75em 0.8em;
    font-size: 0.85em;
    font-weight: 700;
    letter-spacing: var(--fx-letter-spacing);
    color: var(--fx-txt);
    border-radius: calc(var(--fx-radius) - 0.1em);
    cursor: pointer;
    transition: background 0.1s, color 0.1s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 1px;
}
.dropdown-option:last-child { margin-bottom: 0; }

.dropdown-option:hover {
    background: var(--fx-purple);
    color: #fff;
}
.dropdown-option.is-active {
    background: var(--fx-bg-3);
    color: var(--fx-txt);
}
.dropdown-option.is-active:hover {
    background: var(--fx-purple);
    color: #fff;
}

.dropdown-menu::-webkit-scrollbar { width: 0.45em; }
.dropdown-menu::-webkit-scrollbar-thumb {
    background: var(--fx-line-strong);
    border-radius: 1em;
}

/* In-card (param) dropdown variant — sits inside .fx-param */
.fx-param .dropdown {
    grid-column: 1 / -1;
    width: 100%;
}
.fx-param .dropdown-trigger {
    background: var(--fx-bg-3);
    color: var(--fx-txt);
    padding: 0.85em 1.2em;
    letter-spacing: var(--fx-letter-spacing);
    text-transform: none;
    font-weight: 600;
}

/* ============================================================
   DISPLAY-CFG additions — built from the tokens above
   ============================================================ */

/* Text field shared by the URL output and the hex inputs. */
.cfg-input {
    flex: 1 1 auto;
    min-width: 0;
    padding: 0.85em 1.2em;
    background: var(--fx-bg-3);
    border: 1px solid var(--fx-line);
    border-radius: var(--fx-radius);
    color: var(--fx-txt);
    font-family: inherit;
    font-size: 0.85em;
    font-weight: 600;
}

/* URL output: single-line read-only field above the URL actions. */
.cfg-url {
    display: block;
    width: 100%;
    margin-bottom: 0.6em;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.btn.copied,
.btn-primary.copied,
.btn-primary.copied:hover {
    background: var(--fx-green-soft);
    color: var(--fx-green);
    border-color: var(--fx-green);
}

/* Param key tags, e.g. "?bgc" */
.cfg-key {
    flex-shrink: 0;
    font-size: 0.78em;
    font-weight: 700;
    color: var(--fx-txt-low);
    text-transform: none;
    transition: color 0.12s;
}
.fx-card.is-on .cfg-key,
.ctl-toggle input:checked ~ .cfg-key {
    color: var(--fx-green);
}

/* Vertical stack of layout checkboxes */
.ctl-stack {
    display: flex;
    flex-direction: column;
    gap: 0.9em;
}
.ctl-stack .ctl-toggle {
    display: flex;
}
.ctl-stack .cfg-key {
    margin-left: auto;
}

.cfg-note {
    margin-top: 1.1em;
    font-size: 0.8em;
    color: var(--fx-txt-dim);
    line-height: 1.5;
}
.cfg-note:first-child { margin-top: 0; }
.cfg-note code {
    font-family: inherit;
    color: var(--fx-txt);
}

/* Color field: swatch (opens the picker) + hex text input */
.cfg-color {
    grid-column: 1 / -1;
    display: flex;
    gap: 0.6em;
    height: 2.72em;
}
.cfg-picker {
    position: relative;
    display: flex;
    flex: 0 0 auto;
}
/* Square: width matches the row height. Buttons don't inherit font-size,
   so it has to be set for the em to resolve against the row's. */
.cfg-swatch {
    font-size: inherit;
    width: 2.72em;
    border-radius: var(--fx-radius);
    cursor: pointer;
    /* checkerboard shows through hex colors with an alpha channel */
    background:
        linear-gradient(var(--cfg-swatch, #000), var(--cfg-swatch, #000)),
        repeating-conic-gradient(var(--fx-bg-3) 0 25%, var(--fx-bg-2) 0 50%) 0 0 / 0.8em 0.8em;
    box-shadow: inset 0 0 0 1px hsla(0, 0%, 100%, 0.12);
}

/* Picker popover — same shell as .dropdown-menu */
.cfg-picker-pop {
    position: fixed;
    z-index: 200;
    /* Shrinks as a whole so the square area and hue slider always fit the
       viewport (the 2.7em covers slider, gap and margins below the area). */
    width: min(16em, 100vw - 1em, 100vh - 2.7em);
    display: none;
    flex-direction: column;
    gap: 0.9em;
    padding: 0.8em;
    background: var(--fx-bg-2);
    border: 1px solid var(--fx-line-strong);
    border-radius: var(--fx-radius);
    box-shadow: 0 0.6em 1.5em rgba(0,0,0,0.4);
}
.cfg-picker.is-open .cfg-picker-pop { display: flex; }

.cfg-sv {
    position: relative;
    flex: none;
    aspect-ratio: 1;
    border-radius: var(--fx-radius-small);
    cursor: crosshair;
    touch-action: none;
    background:
        linear-gradient(to top, #000, transparent),
        linear-gradient(to right, #fff, hsl(var(--cfg-hue, 0), 100%, 50%));
}
.cfg-sv:focus-visible {
    outline: 2px solid var(--fx-purple);
    outline-offset: 2px;
}
.cfg-sv-knob {
    position: absolute;
    width: 1em;
    height: 1em;
    margin: -0.5em 0 0 -0.5em;
    border: 2px solid #fff;
    border-radius: 50%;
    box-shadow: 0 0 0 1px rgba(0,0,0,0.35);
    pointer-events: none;
}

/* Hue slider: app range control with a spectrum track. */
input[type="range"].cfg-hue-range {
    width: 100%;
    background: linear-gradient(to right,
        hsl(0, 100%, 50%), hsl(60, 100%, 50%), hsl(120, 100%, 50%),
        hsl(180, 100%, 50%), hsl(240, 100%, 50%), hsl(300, 100%, 50%), hsl(360, 100%, 50%));
}
input[type="range"].cfg-hue-range::-moz-range-track { background: transparent; }
input[type="range"].cfg-hue-range::-moz-range-progress { background: transparent; }
input[type="range"].cfg-hue-range::-webkit-slider-thumb {
    background: hsl(var(--cfg-hue, 0), 100%, 50%);
    box-shadow: 0 0 0 2px #fff, 0 0 0 3px rgba(0,0,0,0.35);
}
input[type="range"].cfg-hue-range::-moz-range-thumb {
    background: hsl(var(--cfg-hue, 0), 100%, 50%);
    box-shadow: 0 0 0 2px #fff, 0 0 0 3px rgba(0,0,0,0.35);
}
.cfg-hex {
    text-transform: uppercase;
}
.cfg-hex.is-invalid {
    border-color: var(--fx-red);
    color: var(--fx-red);
}

/* Particle colour preview strip */
.cfg-strip {
    grid-column: 1 / -1;
    height: 0.75em;
    border-radius: 1em;
}

.fx-param.is-hidden { display: none; }

/* Swatch edge: a lighter shade of the colour it shows, same hue and
   saturation. Needs @supports rather than a fallback line, since a
   declaration using var() always parses and would drop the edge. */
@supports (color: hsl(from red h s l)) {
    .cfg-swatch {
        box-shadow: inset 0 0 0 1px hsl(from var(--cfg-swatch, #000) h s calc(l + 12));
    }
}

/* ---------- Responsive ---------- */
@media (max-width: 800px) {
    .app-main {
        grid-template-columns: 1fr;
        grid-template-rows: 50% 1fr;
    }
    .panel-stage {
        order: -1;
        border-left: 0;
        border-bottom: 1px solid rgb(0 0 0 / 50%);
    }
    .panel-controls {
        border-right: 0;
        border-top: 1px solid var(--fx-line);
    }
}

@supports (corner-shape: superellipse(2)) {

    :root {

        --fx-radius:        1em;
        --fx-radius-small:  0.5em;

    }

    .btn,
    .fx-card,
    .ctl-toggle-box,
    .dropdown-trigger,
    .dropdown-menu,
    .dropdown-option,
    .cfg-input,
    .cfg-swatch,
    .cfg-picker-pop,
    .cfg-sv {
        corner-shape: superellipse(2);
    }

}
