/* CSS Gradient Generator - inline app: preview, stop bar, controls, code,
   then the advanced sections. Everything sits inside .page-container, so
   the layout is a single column that stacks down instead of a studio. */

.cgg {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

/* --- Preview --------------------------------------------------------- */

.cgg-stage {
    position: relative;
    border: 1px solid var(--gn-card-border);
    border-radius: 0.75rem;
    overflow: hidden;
}

/* The checkerboard lives on the stage, behind the preview, so a gradient
   with transparent stops reads as see-through rather than white. */
.cgg-transparent {
    background-color: #fff;
    background-image: repeating-conic-gradient(#dfdfdf 0% 25%, #ffffff 0% 50%);
    background-size: 20px 20px;
}

/* Wide enough to judge a gradient, capped so the stop bar and the first
   controls still land on the first screen - this tool is the page, and a
   visitor who has to scroll to find the controls has already left. */
.cgg-preview {
    position: relative;
    width: 100%;
    aspect-ratio: 24 / 9;
    min-height: 220px;
    max-height: 320px;
}

.cgg-expand {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    width: 2rem;
    height: 2rem;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 0.4rem;
    color: #fff;
    background: rgb(0 0 0 / 0.35);
    backdrop-filter: blur(4px);
}

.cgg-expand:hover {
    background: rgb(0 0 0 / 0.55);
}

/* The centre handle of a radial or conic gradient, dragged on the preview */
.cgg-centre {
    position: absolute;
    width: 1.5rem;
    height: 1.5rem;
    margin: -0.75rem 0 0 -0.75rem;
    padding: 0;
    border: 2px solid #fff;
    border-radius: 50%;
    background: rgb(0 0 0 / 0.25);
    box-shadow: 0 0 0 1px rgb(0 0 0 / 0.4);
    cursor: move;
    touch-action: none;
}

/* Expanded: the preview alone fills the viewport. No app chrome, because
   the gradient is the only thing worth seeing big. */
.cgg-expanded .cgg-stage {
    position: fixed;
    inset: 0;
    z-index: 1080;
    border: 0;
    border-radius: 0;
}

.cgg-expanded .cgg-preview {
    height: 100%;
    max-height: none;
    aspect-ratio: auto;
}

/* --- Stop bar -------------------------------------------------------- */

.cgg-bar {
    padding: 0 0.75rem;
}

.cgg-track {
    position: relative;
    height: 2.25rem;
    border: 1px solid var(--gn-card-border);
    border-radius: 0.4rem;
    background-color: #fff;
    background-repeat: no-repeat;
    background-size: 100% 100%;
    cursor: copy;
    touch-action: none;
}

.cgg-stop,
.cgg-hint {
    position: absolute;
    padding: 0;
    border: 0;
    background: none;
    transform: translateX(-50%);
    touch-action: none;
}

.cgg-stop {
    top: -0.35rem;
    width: 1.1rem;
    height: 2.9rem;
    cursor: grab;
}

.cgg-stop-dot {
    display: block;
    width: 1.1rem;
    height: 1.1rem;
    margin-top: 1.8rem;
    border: 2px solid #fff;
    border-radius: 50%;
    box-shadow: 0 0 0 1px rgb(0 0 0 / 0.45);
}

.cgg-stop.is-active .cgg-stop-dot {
    box-shadow: 0 0 0 2px var(--gn-accent);
    transform: scale(1.15);
}

/* The handles are buttons, so they are reachable by keyboard - arrow keys
   move a focused stop. Keep the ring visible on all of them. */
.cgg-stop:focus-visible,
.cgg-hint:focus-visible,
.cgg-preset:focus-visible,
.cgg-expand:focus-visible,
.cgg-centre:focus-visible,
.cgg-layer-swatch:focus-visible {
    outline: 2px solid var(--gn-accent);
    outline-offset: 2px;
}

/* The colour hint: the point where the blend is half way. A diamond, so it
   never reads as another colour stop. */
.cgg-hint {
    top: 0.55rem;
    width: 0.7rem;
    height: 0.7rem;
    border: 1px solid rgb(0 0 0 / 0.5);
    background: rgb(255 255 255 / 0.8);
    rotate: 45deg;
    cursor: ew-resize;
}

.cgg-hint.is-set {
    background: var(--gn-accent);
    border-color: #fff;
}

/* --- Stop editor row ------------------------------------------------- */

.cgg-stopbar,
.cgg-layer-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--gn-card-border);
    border-radius: 0.5rem;
    background-color: var(--gn-card-bg);
}

.cgg-stop-label {
    font-weight: 600;
    font-size: 0.85rem;
    min-width: 6.5rem;
}

.cgg-hex {
    width: 7.5rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.cgg-num {
    width: 5rem;
}

.cgg-range {
    width: 8rem;
}

.cgg-out {
    min-width: 3rem;
    font-size: 0.85rem;
    color: var(--gn-muted);
}

.cgg-inline-label {
    font-size: 0.85rem;
    color: var(--gn-muted);
    margin: 0;
}

.cgg-check {
    padding-left: 2.4em;
}

.cgg-check .form-check-label {
    font-size: 0.85rem;
}

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

.cgg-controls {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 0.75rem 1.25rem;
    padding: 0.85rem 0.75rem;
    border: 1px solid var(--gn-card-border);
    border-radius: 0.5rem;
    background-color: var(--gn-card-bg);
}

.cgg-label {
    display: block;
    margin-bottom: 0.3rem;
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: var(--gn-muted);
}

.cgg-angle,
.cgg-pos {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* The dial: a compass for the gradient line. Dragging anywhere on it sets
   the angle, which is faster than typing degrees. */
.cgg-dial {
    position: relative;
    flex: 0 0 auto;
    width: 2.4rem;
    height: 2.4rem;
    border: 1px solid var(--gn-card-border);
    border-radius: 50%;
    background: var(--gn-body-bg);
    cursor: grab;
    touch-action: none;
}

.cgg-dial-hand {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 2px;
    height: 45%;
    margin-left: -1px;
    background: var(--gn-accent);
    transform-origin: 50% 100%;
    translate: 0 -100%;
}

.cgg-dial-hand::after {
    content: "";
    position: absolute;
    top: -3px;
    left: -3px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--gn-accent);
}

.cgg-control-actions .cgg-label {
    display: none;
}

@media (min-width: 992px) {
    .cgg-control-actions .cgg-label {
        display: block;
    }
}

/* --- Code ------------------------------------------------------------ */

.cgg-code {
    border: 1px solid var(--gn-card-border);
    border-radius: 0.5rem;
    background-color: var(--gn-card-bg);
    overflow: hidden;
}

.cgg-code-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--gn-card-border);
}

.cgg-format {
    width: auto;
}

.cgg-code-text {
    margin: 0;
    padding: 0.85rem;
    max-height: 20rem;
    overflow: auto;
    font-size: 0.82rem;
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-word;
}

.cgg-note {
    margin: 0;
    padding: 0 0.85rem 0.6rem;
    font-size: 0.85rem;
}

.cgg-section-body .cgg-note {
    padding: 0.4rem 0 0;
}

/* --- Sections -------------------------------------------------------- */

.cgg-section {
    border: 1px solid var(--gn-card-border);
    border-radius: 0.5rem;
    background-color: var(--gn-card-bg);
}

.cgg-section > summary {
    padding: 0.7rem 0.85rem;
    font-weight: 600;
    cursor: pointer;
}

.cgg-section > summary .bi {
    margin-right: 0.4rem;
    color: var(--gn-accent);
}

.cgg-section[open] > summary {
    border-bottom: 1px solid var(--gn-card-border);
}

.cgg-section-body {
    padding: 0.85rem;
}

.cgg-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1rem;
}

/* Side by side, so the difference between colour spaces is visible rather
   than described */
.cgg-compare {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 0.75rem;
    margin-top: 0.85rem;
}

.cgg-compare-label {
    display: block;
    margin-bottom: 0.25rem;
    font-size: 0.78rem;
    color: var(--gn-muted);
}

.cgg-strip {
    height: 2.5rem;
    border: 1px solid var(--gn-card-border);
    border-radius: 0.4rem;
}

/* --- Layers ---------------------------------------------------------- */

.cgg-layer-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.cgg-layer {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem;
    border: 1px solid transparent;
    border-radius: 0.4rem;
    background-color: var(--gn-body-bg);
}

.cgg-layer.is-active {
    border-color: var(--gn-accent);
}

.cgg-layer-swatch {
    flex: 0 0 auto;
    width: 3.5rem;
    height: 1.8rem;
    padding: 0;
    border: 1px solid var(--gn-card-border);
    border-radius: 0.3rem;
}

.cgg-layer-name {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 0.85rem;
    text-transform: capitalize;
}

.cgg-layer-blend,
.cgg-blend {
    width: auto;
    max-width: 9rem;
}

/* --- Presets --------------------------------------------------------- */

.cgg-preset-group + .cgg-preset-group {
    margin-top: 1rem;
}

.cgg-preset-heading {
    margin: 0 0 0.4rem;
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: var(--gn-muted);
}

.cgg-preset-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.6rem;
}

.cgg-preset {
    position: relative;
    height: 4.5rem;
    padding: 0;
    border: 1px solid var(--gn-card-border);
    border-radius: 0.45rem;
    overflow: hidden;
}

.cgg-preset:hover {
    border-color: var(--gn-card-hover-border);
}

.cgg-preset-name {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 0.2rem 0.4rem;
    font-size: 0.75rem;
    color: #fff;
    background: rgb(0 0 0 / 0.45);
    text-align: left;
}

/* --- Small screens --------------------------------------------------- */

@media (max-width: 575.98px) {
    .cgg-preview {
        aspect-ratio: 4 / 3;
    }

    .cgg-range {
        width: 100%;
        min-width: 6rem;
    }

    .cgg-stop-label {
        width: 100%;
    }
}
