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

:root {
    --paper: #eceef4;
    --surface: #ffffff;
    --ink: #15172b;
    --muted: #565b76;
    --line: #cdd1e1;
    --accent: #3350ff;
    --list-w: 23rem;
    --button: #225c45;
    --button-text: #cecece;
    --fg: #0a0a0a;
    --border: #e5e5e5;

    color-scheme: light dark;

    @media (prefers-color-scheme: dark) {
        --paper: #000e10;
        --surface: #1e1e1e;
        --ink: #eceefa;
        --muted: #9aa0bd;
        --line: #2b2f47;
        --accent: #8497ff;
        --button: #22ae45;
        --button-text: #242424;
        --fg: #fafafa;
        --border: #2e2e2e;
    }
}

html {
    height: 100%;
}

body {
    margin: 0;
    min-height: 100%;
    background: var(--paper);
    color: var(--ink);
    font-family:
        "Bricolage Grotesque",
        system-ui,
        -apple-system,
        "Segoe UI",
        sans-serif;
    font-optical-sizing: auto;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

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

/* Layout: index on the left, live preview fills the rest */
.lab {
    display: grid;
    grid-template-columns: var(--list-w) minmax(0, 1fr);
    grid-template-rows: auto 1fr;
    column-gap: clamp(1rem, 2.5vw, 2rem);
    height: 100dvh;
    padding: clamp(1rem, 2.5vw, 2rem);

    @media (max-width: 900px) {
        display: flex;
        flex-direction: column;
        height: auto;
        min-height: 100dvh;
    }
}

.intro {
    grid-column: 1;
    grid-row: 1;
    padding-bottom: 1.5rem;

    @media (max-width: 900px) {
        padding-bottom: 1rem;
    }

    h1 {
        margin: 0 0 0.6rem;
        font-size: clamp(2.4rem, 4.4vw, 3.5rem);
        font-weight: 750;
        font-stretch: 80%;
        line-height: 0.95;
        letter-spacing: -0.025em;
        padding-left: 0.85em;

        .lab {
            writing-mode: vertical-lr;
            font-size: clamp(1rem, 2.3vw, 2.1rem);
        }
    }

    p {
        color: var(--muted);
        transform: translateX(7em);
        padding-left: 0.85em;
    }

    span {
        writing-mode: vertical-lr;
        font-size: clamp(1rem, 1.74vw, 2.1rem);
        transform: rotateX(180deg) rotateY(180deg) translateY(-0.5em);
    }
}

.index {
    grid-column: 1;
    grid-row: 2;
    min-height: 0;
    overflow-y: auto;

    @media (max-width: 900px) {
        overflow: visible;
    }

    ul {
        margin: 0;
        padding: 0;
        list-style: none;
        border-top: 1px solid var(--line);
    }

    li {
        border-bottom: 1px solid var(--line);
    }

    .empty {
        padding: 1.25rem 0.25rem;
        color: var(--muted);

        code {
            display: block;
            margin-top: 0.5rem;
            padding: 0.6rem 0.75rem;
            border-radius: 8px;
            background: var(--surface);
            color: var(--ink);
            font-size: 0.85rem;
        }
    }
}

.item {
    position: relative;
    display: block;
    padding: 0.9rem 0.75rem 0.9rem 1rem;
    color: inherit;
    text-decoration: none;

    &::before {
        content: "";
        position: absolute;
        left: 0;
        top: 0.7rem;
        bottom: 0.7rem;
        width: 3px;
        border-radius: 2px;
        background: var(--accent);
        transform: scaleY(0);
        transition: transform 0.18s ease;

        @media (prefers-reduced-motion: reduce) {
            transition: none;
        }
    }

    &:hover {
        background: color-mix(in srgb, var(--surface) 65%, transparent);
    }

    &[aria-current="true"] {
        background: var(--surface);

        &::before {
            transform: scaleY(1);
        }
    }

    .item-title {
        display: block;
        font-size: 1.05rem;
        font-weight: 650;
        letter-spacing: -0.005em;
    }

    .item-desc {
        display: block;
        margin-top: 0.15rem;
        color: var(--muted);
        font-size: 0.92rem;
    }

    .item-meta {
        display: flex;
        justify-content: space-between;
        gap: 1rem;
        margin-top: 0.5rem;
        color: var(--muted);
        font-size: 0.8rem;
    }
}

.stage {
    grid-column: 2;
    grid-row: 1 / span 2;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 14px;

    @media (max-width: 900px) {
        height: 80dvh;
        min-height: 30rem;
        margin-top: 1.25rem;
    }
}

.stage-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem 1.5rem;
    padding: 0.9rem 1.1rem;
    border-bottom: 1px solid var(--line);
}

.stage-title {
    h2 {
        margin: 0;
        font-size: 1.1rem;
        font-weight: 650;
    }

    p {
        margin: 0;
        color: var(--muted);
        font-size: 0.9rem;
    }
}

.stage-tools {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.sizes {
    display: inline-flex;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 8px;

    @media (max-width: 900px) {
        display: none;
    }

    button {
        padding: 0.4rem 0.8rem;
        border: 0;
        background: transparent;
        color: var(--muted);
        font: inherit;
        font-size: 0.85rem;
        cursor: pointer;

        & + button {
            border-left: 1px solid var(--line);
        }

        &[aria-pressed="true"] {
            background: var(--ink);
            color: var(--paper);
        }
    }
}

.editor {
    display: inline-block;
    text-decoration: none;
    font-size: clamp(1.1rem, 1.2vw, 2rem);
    font-weight: 600;
    background-color: var(--button);
    color: var(--button-text);
    border: 2px solid var(--button);
    border-radius: 5px;
    padding: 0.5rem 0.75rem;
    line-height: 1.2;
    text-transform: uppercase;
}

.frame-wrap {
    flex: 1;
    min-height: 0;
    display: flex;
    justify-content: center;
    background: var(--paper);
}

#frame {
    width: var(--frame-w, 100%);
    max-width: 100%;
    height: 100%;
    border: 0;
    background: #fff;
    transition: width 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);

    @media (prefers-reduced-motion: reduce) {
        transition: none;
    }
}

#open {
    text-decoration: none;
    display: flex;
    align-items: center;
    min-height: 36px;
    padding: 0 12px;
    background: transparent;
    color: var(--fg);
    font: inherit;
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;

    &:hover {
        border-color: var(--muted);
    }
}
