/* ==========================================================================
   Tokens
   ========================================================================== */

:root {
    color-scheme: dark;

    --bg: #0e0f11;
    --panel: #16171a;
    --panel-2: #1e2024;
    --border: #2a2c31;
    --border-strong: #3a3d44;
    --text: #ececee;
    --muted: #9a9da5;
    --accent: #f4f4f5;
    --accent-text: #111214;
    --focus: #7aa7ff;
    --shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
    --checker-a: #1a1b1f;
    --checker-b: #202126;

    --radius: 14px;
    --radius-sm: 10px;

    /* Replaced at runtime with a gradient sampled from the current line. */
    --live: linear-gradient(90deg, #ff6b6b, #feca57, #1dd1a1, #48dbfb, #5f27cd);
}

@media (prefers-color-scheme: light) {
    :root {
        color-scheme: light;

        --bg: #f3f3f1;
        --panel: #ffffff;
        --panel-2: #f4f4f2;
        --border: #e3e3df;
        --border-strong: #cfcfca;
        --text: #18181b;
        --muted: #6b6d74;
        --accent: #18181b;
        --accent-text: #ffffff;
        --shadow: 0 12px 32px rgba(20, 20, 30, 0.14);
        --checker-a: #ededea;
        --checker-b: #f6f6f4;
    }
}

/* ==========================================================================
   Base
   ========================================================================== */

*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
}

body {
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    -webkit-font-smoothing: antialiased;
}

body::before {
    content: "";
    display: block;
    height: 3px;
    background: var(--live);
}

[hidden] {
    display: none !important;
}

:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: 2px;
}

svg {
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

kbd {
    display: inline-block;
    min-width: 1.6em;
    padding: 0 0.35em;
    border: 1px solid var(--border);
    border-bottom-width: 2px;
    border-radius: 5px;
    background: var(--panel-2);
    font: inherit;
    font-size: 11px;
    line-height: 1.5;
    text-align: center;
}

kbd + kbd {
    margin-left: 2px;
}

/* ==========================================================================
   Top bar
   ========================================================================== */

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    max-width: 1440px;
    margin: 0 auto;
    padding: 16px 20px;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: inherit;
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.02em;
    text-decoration: none;
}

.brand-mark {
    width: 24px;
    height: 24px;
    border-radius: 7px;
    background: var(--live);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.14);
}

.topbar-actions {
    display: flex;
    gap: 8px;
}

/* ==========================================================================
   Buttons & form controls
   ========================================================================== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 36px;
    padding: 0 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--panel-2);
    color: var(--text);
    font: inherit;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
    transition: border-color 0.15s, background-color 0.15s, transform 0.05s;
}

.btn:hover:not(:disabled) {
    border-color: var(--border-strong);
}

.btn:active:not(:disabled) {
    transform: translateY(1px);
}

.btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.btn svg {
    width: 16px;
    height: 16px;
    flex: none;
}

.btn-primary {
    border-color: transparent;
    background: var(--accent);
    color: var(--accent-text);
}

.btn-primary:hover:not(:disabled) {
    border-color: transparent;
    opacity: 0.9;
}

.link-btn {
    padding: 0;
    border: 0;
    background: none;
    color: var(--muted);
    font: inherit;
    font-size: 13px;
    cursor: pointer;
}

.link-btn:hover {
    color: var(--text);
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 28px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--panel-2);
    color: var(--muted);
    font: inherit;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}

.chip svg {
    width: 14px;
    height: 14px;
}

.chip .icon-locked,
.chip[aria-pressed="true"] .icon-unlocked {
    display: none;
}

.chip[aria-pressed="true"] .icon-locked {
    display: block;
}

.chip[aria-pressed="true"] {
    border-color: transparent;
    background: var(--accent);
    color: var(--accent-text);
}

.segmented {
    display: grid;
    grid-auto-columns: 1fr;
    grid-auto-flow: column;
    padding: 3px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--panel-2);
}

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

.segmented label {
    padding: 6px 10px;
    border-radius: 7px;
    color: var(--muted);
    font-weight: 600;
    text-align: center;
    cursor: pointer;
    transition: color 0.15s, background-color 0.15s;
}

.segmented label:hover {
    color: var(--text);
}

.segmented input:checked + label {
    background: var(--panel);
    box-shadow: inset 0 0 0 1px var(--border), 0 1px 2px rgba(0, 0, 0, 0.25);
    color: var(--text);
}

.segmented input:focus-visible + label {
    outline: 2px solid var(--focus);
    outline-offset: 1px;
}

input[type="range"] {
    width: 100%;
    height: 22px;
    margin: 0;
    background: transparent;
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track {
    height: 6px;
    border-radius: 999px;
    background: var(--panel-2);
    box-shadow: inset 0 0 0 1px var(--border);
}

input[type="range"]::-moz-range-track {
    height: 6px;
    border-radius: 999px;
    background: var(--panel-2);
    box-shadow: inset 0 0 0 1px var(--border);
}

input[type="range"]::-webkit-slider-thumb {
    width: 18px;
    height: 18px;
    margin-top: -6px;
    border: 3px solid var(--panel);
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 0 1px var(--border-strong);
    -webkit-appearance: none;
    appearance: none;
}

input[type="range"]::-moz-range-thumb {
    width: 12px;
    height: 12px;
    border: 3px solid var(--panel);
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 0 1px var(--border-strong);
}

input[type="range"]:focus-visible {
    outline: none;
}

input[type="range"]:focus-visible::-webkit-slider-thumb {
    box-shadow: 0 0 0 2px var(--focus);
}

input[type="range"]:focus-visible::-moz-range-thumb {
    box-shadow: 0 0 0 2px var(--focus);
}

.select {
    position: relative;
}

.select::after {
    content: "";
    position: absolute;
    top: 50%;
    right: 14px;
    width: 7px;
    height: 7px;
    border-right: 1.5px solid var(--muted);
    border-bottom: 1.5px solid var(--muted);
    transform: translateY(-70%) rotate(45deg);
    pointer-events: none;
}

.select select {
    width: 100%;
    height: 36px;
    padding: 0 34px 0 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--panel-2);
    color: var(--text);
    font: inherit;
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
}

/* ==========================================================================
   Layout & panels
   ========================================================================== */

.layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px;
    align-items: start;
    gap: 20px;
    max-width: 1440px;
    margin: 0 auto;
    padding: 0 20px 20px;
}

.panel {
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--panel);
}

.panel-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px 12px;
    min-height: 28px;
    margin-bottom: 12px;
}

.panel-head h2 {
    margin: 0;
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.output-panel {
    position: sticky;
    top: 20px;
}

/* ==========================================================================
   Source
   ========================================================================== */

.readout {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 13px;
    font-variant-numeric: tabular-nums;
}

.readout-colour {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12px;
}

.readout-colour .dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    box-shadow: inset 0 0 0 1px rgba(127, 127, 127, 0.4);
}

.readout-position {
    color: var(--muted);
}

.stage {
    position: relative;
    display: grid;
    place-items: center;
    padding: 16px;
    border-radius: var(--radius-sm);
    background: repeating-conic-gradient(var(--checker-a) 0 25%, var(--checker-b) 0 50%) 0 0 / 20px 20px;
    overflow: hidden;
}

.stage-inner {
    position: relative;
    border-radius: 6px;
    box-shadow: var(--shadow);
    line-height: 0;
    overflow: hidden;
}

#source {
    display: block;
    cursor: crosshair;
    touch-action: none;
}

#source:focus-visible {
    outline: none;
}

.stage-inner:has(#source:focus-visible) {
    outline: 2px solid var(--focus);
    outline-offset: 3px;
}

.sample-band {
    position: absolute;
    box-shadow:
        0 0 0 1px rgba(255, 255, 255, 0.95),
        0 0 0 2px rgba(0, 0, 0, 0.35),
        0 0 0 100vmax rgba(0, 0, 0, 0.18);
    pointer-events: none;
    transition: box-shadow 0.2s;
}

.sample-band[data-direction="row"] {
    left: 0;
    right: 0;
    min-height: 1px;
}

.sample-band[data-direction="column"] {
    top: 0;
    bottom: 0;
    min-width: 1px;
}

.sample-band.is-locked {
    box-shadow:
        0 0 0 1px #fff,
        0 0 0 2px rgba(0, 0, 0, 0.45),
        0 0 0 100vmax rgba(0, 0, 0, 0.4);
}

/* Grab handles at both ends of a locked line */
.sample-band.is-locked::before,
.sample-band.is-locked::after {
    content: "";
    position: absolute;
    border-radius: 999px;
    background: #fff;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
}

.sample-band[data-direction="row"].is-locked::before,
.sample-band[data-direction="row"].is-locked::after {
    top: 50%;
    width: 8px;
    height: 20px;
    transform: translateY(-50%);
}

.sample-band[data-direction="row"].is-locked::before { left: 8px; }
.sample-band[data-direction="row"].is-locked::after { right: 8px; }

.sample-band[data-direction="column"].is-locked::before,
.sample-band[data-direction="column"].is-locked::after {
    left: 50%;
    width: 20px;
    height: 8px;
    transform: translateX(-50%);
}

.sample-band[data-direction="column"].is-locked::before { top: 8px; }
.sample-band[data-direction="column"].is-locked::after { bottom: 8px; }

/* --------------------------------------------------------------------------
   Crop
   -------------------------------------------------------------------------- */

.crop-stage {
    position: relative;
    line-height: 0;
    box-shadow: var(--shadow);
    cursor: crosshair;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

.crop-stage:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: 3px;
}

#cropCanvas {
    display: block;
}

/* The shade is clipped to the image; the box isn't, so its handles can
   overhang the edges. */
.crop-shade {
    position: absolute;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
}

.crop-hole {
    position: absolute;
    box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.58);
}

.crop-box {
    position: absolute;
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.95), 0 0 0 2px rgba(0, 0, 0, 0.3);
    cursor: move;
}

.crop-grid {
    position: absolute;
    inset: 0;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s;
}

.crop-grid::before,
.crop-grid::after {
    content: "";
    position: absolute;
    border: 0 solid rgba(255, 255, 255, 0.5);
}

.crop-grid::before {
    top: 0;
    bottom: 0;
    left: 33.333%;
    width: 33.333%;
    border-left-width: 1px;
    border-right-width: 1px;
}

.crop-grid::after {
    left: 0;
    right: 0;
    top: 33.333%;
    height: 33.333%;
    border-top-width: 1px;
    border-bottom-width: 1px;
}

.crop-stage.is-dragging .crop-grid {
    opacity: 1;
}

.crop-handle {
    position: absolute;
    width: 14px;
    height: 14px;
    margin: -7px 0 0 -7px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
}

/* Bigger hit area than the visible handle */
.crop-handle::before {
    content: "";
    position: absolute;
    inset: -10px;
}

.crop-handle[data-handle="nw"] { left: 0; top: 0; cursor: nwse-resize; }
.crop-handle[data-handle="ne"] { left: 100%; top: 0; cursor: nesw-resize; }
.crop-handle[data-handle="se"] { left: 100%; top: 100%; cursor: nwse-resize; }
.crop-handle[data-handle="sw"] { left: 0; top: 100%; cursor: nesw-resize; }

.crop-handle[data-handle="n"],
.crop-handle[data-handle="s"] {
    left: 50%;
    width: 24px;
    height: 8px;
    margin: -4px 0 0 -12px;
    border-radius: 999px;
    cursor: ns-resize;
}

.crop-handle[data-handle="n"] { top: 0; }
.crop-handle[data-handle="s"] { top: 100%; }

.crop-handle[data-handle="e"],
.crop-handle[data-handle="w"] {
    top: 50%;
    width: 8px;
    height: 24px;
    margin: -12px 0 0 -4px;
    border-radius: 999px;
    cursor: ew-resize;
}

.crop-handle[data-handle="e"] { left: 100%; }
.crop-handle[data-handle="w"] { left: 0; }

.crop-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    margin-top: 12px;
}

.crop-ratios {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.crop-dims {
    margin-left: auto;
    color: var(--muted);
    font-size: 12px;
    font-variant-numeric: tabular-nums;
}

.crop-actions {
    display: flex;
    gap: 8px;
}

.empty {
    display: grid;
    align-content: center;
    justify-items: center;
    gap: 6px;
    min-height: 320px;
    padding: 32px 16px;
    text-align: center;
}

.empty-art {
    display: flex;
    width: 88px;
    height: 64px;
    margin-bottom: 14px;
    border-radius: 12px;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.empty-art span {
    flex: 1;
}

.empty-art span:nth-child(1) { background: #ff6b6b; }
.empty-art span:nth-child(2) { background: #feca57; }
.empty-art span:nth-child(3) { background: #1dd1a1; }
.empty-art span:nth-child(4) { background: #48dbfb; }
.empty-art span:nth-child(5) { background: #5f27cd; }

.empty-title {
    margin: 0;
    font-size: 17px;
    font-weight: 650;
}

.empty-sub {
    max-width: 36ch;
    margin: 0 0 12px;
    color: var(--muted);
}

/* Credit, session origin and hint lines under the source */
.source-meta {
    display: grid;
    gap: 4px;
    margin-top: 12px;
}

.credit {
    margin: 0;
    color: var(--muted);
    font-size: 12px;
    overflow-wrap: anywhere;
}

.credit a {
    color: var(--text);
    text-underline-offset: 3px;
}

.credit a::after {
    content: " ↗";
}

.session-origin {
    margin: 0;
    color: var(--muted);
    font-size: 12px;
    overflow-wrap: anywhere;
}

.session-origin span {
    color: var(--text);
}

.session-origin .link-btn,
.share-details {
    color: var(--text);
    text-decoration: underline;
    text-underline-offset: 3px;
}

.session-origin .link-btn {
    font-size: inherit;
}

.hint {
    margin: 0;
    color: var(--muted);
    font-size: 12px;
    line-height: 2;
}

.hint .sep {
    margin: 0 4px;
    opacity: 0.5;
}

.hint-touch {
    display: none;
}

@media (hover: none) {
    .hint-pointer { display: none; }
    .hint-touch { display: inline; }
}

/* ==========================================================================
   Output
   ========================================================================== */

.dims {
    color: var(--muted);
    font-size: 12px;
    font-variant-numeric: tabular-nums;
}

.preview-frame {
    display: grid;
    place-items: center;
    min-height: 160px;
    padding: 14px;
    border-radius: var(--radius-sm);
    background: repeating-conic-gradient(var(--checker-a) 0 25%, var(--checker-b) 0 50%) 0 0 / 20px 20px;
}

.preview-placeholder {
    margin: 0;
    color: var(--muted);
    font-size: 13px;
}

#preview {
    display: block;
    border-radius: 6px;
    box-shadow: var(--shadow);
}

.palette {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 6px;
    margin-top: 12px;
}

.swatch {
    position: relative;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    height: 48px;
    padding: 0 0 5px;
    border: 0;
    border-radius: 8px;
    box-shadow: inset 0 0 0 1px rgba(127, 127, 127, 0.25);
    font: 600 9.5px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    letter-spacing: -0.02em;
    cursor: copy;
    transition: transform 0.12s;
}

.swatch:hover {
    transform: translateY(-2px);
}

.swatch.is-light { color: rgba(0, 0, 0, 0.72); }
.swatch.is-dark { color: rgba(255, 255, 255, 0.86); }

.controls {
    display: grid;
    gap: 16px;
    margin-top: 20px;
}

.field {
    display: grid;
    gap: 8px;
}

.label {
    display: flex;
    justify-content: space-between;
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
}

.label output {
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

.actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

/* ==========================================================================
   Print dialog
   ========================================================================== */

.dialog {
    width: min(560px, calc(100vw - 32px));
    max-height: calc(100vh - 32px);
    padding: 0;
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--panel);
    box-shadow: var(--shadow);
    color: var(--text);
}

.dialog::backdrop {
    background: rgba(10, 10, 12, 0.55);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
}

.dialog[open] {
    animation: pop-in 0.2s ease-out;
}

.dialog-sheet {
    display: grid;
    gap: 16px;
    padding: 20px;
}

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

.dialog-head h2 {
    margin: 0;
    font-size: 17px;
    font-weight: 650;
}

.dialog-intro {
    margin: -8px 0 0;
    color: var(--muted);
}

.print-products {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

@media (max-width: 560px) {
    .dialog-sheet {
        padding: 16px;
    }

    .print-products {
        grid-template-columns: repeat(2, 1fr);
    }
}

.print-product {
    position: relative;
    display: grid;
    justify-items: center;
    gap: 2px;
    padding: 12px 10px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--panel-2);
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.print-product:hover {
    border-color: var(--border-strong);
}

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

.print-product:has(input:checked) {
    border-color: var(--accent);
    box-shadow: inset 0 0 0 1px var(--accent);
}

.print-product:has(input:focus-visible) {
    outline: 2px solid var(--focus);
    outline-offset: 2px;
}

.print-frame {
    display: grid;
    place-items: center;
    width: 100%;
    height: 88px;
    margin-bottom: 6px;
}

.print-thumb {
    display: block;
    border-radius: 3px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.print-name {
    font-weight: 600;
}

.print-size {
    color: var(--muted);
    font-size: 12px;
    font-variant-numeric: tabular-nums;
}

.print-disclosure {
    margin: -6px 0 0;
    color: var(--muted);
    font-size: 12px;
}

.print-demo {
    padding: 10px 12px;
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-sm);
    color: var(--muted);
    font-size: 13px;
}

.print-demo strong {
    color: var(--text);
}

.print-mockup {
    justify-self: center;
    width: min(256px, 100%);
    aspect-ratio: 1;
    border-radius: var(--radius-sm);
    background: var(--panel-2);
}

.print-status:empty {
    display: none;
}

.print-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-variant-numeric: tabular-nums;
}

.print-status[data-kind="busy"]::before {
    content: "";
    width: 14px;
    height: 14px;
    border: 2px solid var(--border-strong);
    border-top-color: var(--text);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.print-status[data-kind="error"] {
    color: #e5484d;
}

.print-link {
    display: grid;
    gap: 4px;
}

.print-link .label {
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
}

.print-link code {
    display: block;
    max-height: 84px;
    padding: 8px 10px;
    border-radius: 8px;
    background: var(--panel-2);
    font: 11.5px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    overflow: auto;
    word-break: break-all;
    user-select: all;
}

.print-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
}

.print-actions a.btn {
    text-decoration: none;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ==========================================================================
   Wallpapers dialog: print cards, but several can be ticked
   ========================================================================== */

/* Status and buttons stay in view while the list scrolls on small screens. */
.wallpapers-foot {
    position: sticky;
    bottom: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px 16px;
    margin: 0 -20px -20px;
    padding: 14px 20px 20px;
    border-top: 1px solid var(--border);
    background: var(--panel);
}

.wallpapers-foot .print-actions {
    margin-left: auto;
}

@media (max-width: 560px) {
    .wallpapers-foot {
        margin: 0 -16px -16px;
        padding: 12px 16px 16px;
    }
}

.wallpaper-device::before {
    content: "";
    position: absolute;
    top: 7px;
    right: 7px;
    width: 16px;
    height: 16px;
    box-sizing: border-box;
    border: 1.5px solid var(--border-strong);
    border-radius: 50%;
}

.wallpaper-device:has(input:checked)::before {
    border-color: var(--accent);
    background: var(--accent);
}

.wallpaper-device:has(input:checked)::after {
    content: "";
    position: absolute;
    top: 10px;
    right: 13px;
    width: 4px;
    height: 7px;
    border: solid var(--panel);
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

/* ==========================================================================
   Share dialog
   ========================================================================== */

.share-dialog {
    width: min(480px, calc(100vw - 32px));
}

.share-options {
    display: grid;
    gap: 10px;
}

.share-option {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--panel-2);
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
    transition: border-color 0.15s;
}

.share-option:hover:not(:disabled) {
    border-color: var(--border-strong);
}

.share-option:disabled {
    opacity: 0.55;
    cursor: progress;
}

.share-icon {
    display: grid;
    flex: none;
    place-items: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--accent);
    color: var(--accent-text);
}

.share-icon svg {
    width: 18px;
    height: 18px;
}

.share-text {
    display: grid;
    gap: 2px;
}

.share-name {
    font-weight: 600;
}

.share-desc {
    color: var(--muted);
    font-size: 13px;
}

.share-details {
    justify-self: start;
}

.share-details:disabled {
    opacity: 0.5;
    cursor: progress;
}

.share-note {
    margin: 0;
    color: var(--muted);
    font-size: 12px;
}

/* ==========================================================================
   Session details
   ========================================================================== */

.details-dialog {
    width: min(520px, calc(100vw - 32px));
}

.details-list {
    display: grid;
    grid-template-columns: max-content 1fr;
    margin: 0;
}

.details-list dt,
.details-list dd {
    margin: 0;
    padding: 8px 0;
    border-top: 1px solid var(--border);
}

.details-list dt {
    padding-right: 16px;
    color: var(--muted);
    font-size: 13px;
}

.details-list dd {
    overflow-wrap: anywhere;
}

.details-list a {
    color: var(--text);
    text-underline-offset: 3px;
}

.details-note {
    margin: 0;
    color: var(--muted);
    font-size: 12px;
}

.details-raw summary {
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

.details-raw pre {
    max-height: 240px;
    margin: 8px 0;
    padding: 10px 12px;
    border-radius: 8px;
    background: var(--panel-2);
    font: 11.5px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    white-space: pre-wrap;
    overflow: auto;
    overflow-wrap: anywhere;
}

/* ==========================================================================
   Samples gallery
   ========================================================================== */

.samples-dialog {
    width: min(880px, calc(100vw - 32px));
}

.samples-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.samples-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.samples-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 18px 14px;
}

@media (max-width: 560px) {
    .samples-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 14px 10px;
    }

    .sample-title {
        font-size: 13px;
    }
}

.sample-card {
    display: grid;
    gap: 4px;
    padding: 0;
    border: 0;
    background: none;
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.sample-thumb {
    position: relative;
    display: block;
    border-radius: var(--radius-sm);
    overflow: hidden;
    box-shadow: inset 0 0 0 1px var(--border);
}

.sample-thumb img {
    display: block;
    width: 100%;
    aspect-ratio: 4 / 3;
    object-fit: cover;
    transition: transform 0.25s;
}

.sample-card:hover .sample-thumb img {
    transform: scale(1.04);
}

.sample-card[aria-current="true"] .sample-thumb {
    box-shadow: 0 0 0 2px var(--accent);
}

.sample-card[aria-current="true"] .sample-thumb::after {
    content: "Open";
    position: absolute;
    top: 8px;
    left: 8px;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--accent);
    color: var(--accent-text);
    font-size: 11px;
    font-weight: 600;
}

.sample-palette {
    display: flex;
    height: 8px;
    margin: 4px 0 2px;
    border-radius: 999px;
    overflow: hidden;
}

.sample-palette span {
    flex: 1;
}

.sample-title {
    font-weight: 600;
    line-height: 1.3;
}

.sample-byline {
    color: var(--muted);
    font-size: 12px;
}

/* ==========================================================================
   Snapshots
   ========================================================================== */

.snapshots {
    max-width: 1440px;
    margin: 0 auto;
    padding: 0 20px 24px;
}

.snapshot-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 24px 20px;
    margin: 0;
    padding: 0;
    list-style: none;
}

/* minmax(0, 1fr) keeps a long label from widening the card past its column. */
.snapshot {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
    animation: pop-in 0.25s ease-out;
}

.snapshot-thumb {
    display: block;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: inset 0 0 0 1px var(--border);
}

.snapshot-thumb img {
    display: block;
    width: 100%;
    aspect-ratio: 16 / 10;
    object-fit: cover;
    transition: transform 0.2s;
}

.snapshot-thumb:hover img {
    transform: scale(1.03);
}

.snapshot-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-size: 12px;
}

.snapshot-restore {
    min-width: 0;
    padding: 0;
    border: 0;
    background: none;
    color: var(--muted);
    font: inherit;
    font-variant-numeric: tabular-nums;
    text-align: left;
    text-overflow: ellipsis;
    white-space: nowrap;
    overflow: hidden;
    cursor: pointer;
}

.snapshot-restore:hover {
    color: var(--text);
    text-decoration: underline;
    text-underline-offset: 3px;
}

.snapshot-meta .icons {
    flex: none;
    display: flex;
    gap: 2px;
}

.icon-btn {
    display: inline-grid;
    place-items: center;
    width: 26px;
    height: 26px;
    padding: 0;
    border: 0;
    border-radius: 6px;
    background: none;
    color: var(--muted);
    cursor: pointer;
}

.icon-btn:hover {
    background: var(--panel-2);
    color: var(--text);
}

.icon-btn svg {
    width: 15px;
    height: 15px;
}

@keyframes pop-in {
    from { opacity: 0; transform: scale(0.96); }
}

/* ==========================================================================
   Overlays
   ========================================================================== */

.drop-overlay {
    position: fixed;
    inset: 0;
    z-index: 10;
    display: grid;
    padding: 16px;
    background: rgba(10, 10, 12, 0.55);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s;
}

.drop-overlay-inner {
    display: grid;
    place-items: center;
    border: 2px dashed rgba(255, 255, 255, 0.7);
    border-radius: 20px;
    color: #fff;
    font-size: 22px;
    font-weight: 650;
}

body.is-dragging .drop-overlay {
    opacity: 1;
}

.toast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    z-index: 20;
    padding: 10px 16px;
    border-radius: 999px;
    background: var(--accent);
    box-shadow: var(--shadow);
    color: var(--accent-text);
    font-weight: 600;
    opacity: 0;
    transform: translate(-50%, 12px);
    transition: opacity 0.2s, transform 0.2s;
    pointer-events: none;
}

.toast.is-visible {
    opacity: 1;
    transform: translate(-50%, 0);
}

/* ==========================================================================
   Small screens
   ========================================================================== */

@media (max-width: 920px) {
    .layout {
        grid-template-columns: minmax(0, 1fr);
    }

    .output-panel {
        position: static;
    }
}

@media (max-width: 560px) {
    .topbar,
    .layout,
    .snapshots {
        padding-left: 12px;
        padding-right: 12px;
    }

    .topbar-actions .btn span {
        display: none;
    }

    .topbar-actions .btn {
        width: 36px;
        padding: 0;
    }

    .panel {
        padding: 12px;
    }

    .stage {
        padding: 10px;
    }

    .readout-position {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation: none !important;
        transition: none !important;
    }
}
