﻿/* Calm classroom: quiet panels and soft borders, with the playful parts (Bit, the bars, the stage objects) doing the talking.
   Pixel type is kept for the wordmark only.
   Layout: header on top, lesson list on the left (it can fold to a thin rail), main area on the right. */
:root {
    --bg: #f7f6fc;
    --panel: #ffffff;
    --panel2: #efecfa;
    --ink: #1f1d3d;
    --muted: #625f84;
    --line: #dcd8ee;
    --outline: #1f1d3d;
    --violet: #6a4cff;
    --sun: #ffc933;
    --coral: #ff6b6b;
    --mint: #25c2a0;
    --sky: #4b8bff;
    --code-bg: #1f1d3d;
    --code-fg: #eceaff;
    --code-dim: #8e8bbd;
    --code-hl: rgba(255, 201, 51, 0.2);
    --c-kw: #ff8fb1;
    --c-str: #8be9b8;
    --c-num: #ffd166;
    --c-fn: #8ab4ff;
    --c-cm: #7f7cb0;
    --font-wordmark: 'Pixelify Sans', 'DM Sans', system-ui, sans-serif;
    --font-display: 'DM Sans', system-ui, sans-serif;
    --font-body: 'DM Sans', system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;
    --shadow: 0 1px 2px rgba(31, 29, 61, 0.06), 0 6px 18px rgba(31, 29, 61, 0.06);
    --radius: 14px;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #14122b;
        --panel: #1d1a40;
        --panel2: #2a2663;
        --ink: #efedff;
        --muted: #a8a5d8;
        --line: #322e66;
        --outline: #0a0919;
        --code-bg: #0d0b24;
        --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 18px rgba(0, 0, 0, 0.25);
        color-scheme: dark;
    }
}

:root[data-theme="dark"] {
    --bg: #14122b;
    --panel: #1d1a40;
    --panel2: #2a2663;
    --ink: #efedff;
    --muted: #a8a5d8;
    --line: #322e66;
    --outline: #0a0919;
    --code-bg: #0d0b24;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 18px rgba(0, 0, 0, 0.25);
    color-scheme: dark;
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

body {
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font-body);
    font-size: 15px;
    line-height: 1.6;
    padding-left: max(16px, env(safe-area-inset-left, 0px));
    padding-right: max(16px, env(safe-area-inset-right, 0px));
    padding-block: 20px 56px;
}

h1, h2, h3, h4 {
    font-family: var(--font-display);
    margin: 0;
    text-wrap: balance;
}

.app {
    max-width: 1200px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: 264px minmax(0, 1fr);
    gap: 28px 36px;
    align-items: start;
    transition: grid-template-columns 0.2s ease;
}

/* ---------- header ---------- */
.top {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px 20px;
    flex-wrap: wrap;
    padding-bottom: 18px;
    border-bottom: 1px solid var(--line);
}

.brand {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
}

.brand-mascot svg {
    width: 48px;
    height: 48px;
    display: block;
    flex: none;
}

.brand h1 {
    font-family: var(--font-wordmark);
    font-weight: 700;
    font-size: clamp(1.4rem, 4vw, 1.85rem);
    line-height: 1.1;
    letter-spacing: 0.01em;
}

.brand p {
    margin: 3px 0 0;
    color: var(--muted);
    font-size: 0.92rem;
}

.top-actions {
    display: flex;
    gap: 10px;
}

#topicsBtn {
    display: none;
}

/* ---------- buttons ---------- */
.btn {
    font: inherit;
    font-weight: 600;
    color: var(--ink);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 7px 16px;
    cursor: pointer;
}

    .btn:hover {
        background: var(--panel2);
    }

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

    .btn.primary {
        background: var(--sun);
        color: #1f1d3d;
        border-color: #e3ae0d;
        min-width: 92px;
    }

        .btn.primary:hover {
            background: #ffd44f;
        }

    .btn:disabled {
        opacity: 0.45;
        cursor: default;
    }

    .btn:focus-visible, input:focus-visible, select:focus-visible, .tlink:focus-visible, summary:focus-visible, .side-toggle:focus-visible, .ln:focus-visible {
        outline: 3px solid var(--violet);
        outline-offset: 2px;
    }

/* ---------- lesson list ---------- */
.side {
    position: sticky;
    top: 16px;
    max-height: calc(100vh - 32px);
    overflow-y: auto;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

.side-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 10px 10px 16px;
    border-bottom: 1px solid var(--line);
}

.side-title {
    font-size: 0.74rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--muted);
}

.side-toggle {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    padding: 0;
    color: var(--muted);
    background: none;
    border: 1px solid var(--line);
    border-radius: 8px;
    cursor: pointer;
}

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

    .side-toggle svg {
        width: 16px;
        height: 16px;
    }

.side-body {
    padding: 8px 8px 14px;
}

.tlink {
    display: block;
    width: 100%;
    text-align: left;
    font: inherit;
    font-size: 0.94rem;
    font-weight: 500;
    line-height: 1.3;
    color: var(--ink);
    background: none;
    border: 0;
    border-radius: 8px;
    padding: 8px 12px;
    cursor: pointer;
}

    .tlink:hover {
        background: var(--panel2);
    }

    .tlink.on {
        background: var(--violet);
        color: #fff;
        font-weight: 600;
    }

    .tlink.soon {
        color: var(--muted);
    }

    .tlink.home {
        margin-bottom: 6px;
    }

.group {
    margin-top: 4px;
}

    .group summary {
        display: flex;
        align-items: center;
        gap: 8px;
        padding: 9px 12px 7px;
        list-style: none;
        cursor: pointer;
        border-radius: 8px;
        font-size: 0.74rem;
        font-weight: 700;
        letter-spacing: 0.08em;
        text-transform: uppercase;
        color: var(--muted);
        user-select: none;
    }

        .group summary::-webkit-details-marker {
            display: none;
        }

        .group summary:hover {
            background: var(--panel2);
        }

        .group summary::before {
            content: "";
            flex: none;
            width: 6px;
            height: 6px;
            border-right: 2px solid currentColor;
            border-bottom: 2px solid currentColor;
            transform: rotate(-45deg);
            transition: transform 0.15s ease;
        }

    .group[open] summary::before {
        transform: rotate(45deg);
    }

.gname {
    flex: 1;
    min-width: 0;
}

.gcount {
    font-size: 0.7rem;
    letter-spacing: 0;
    background: var(--panel2);
    border-radius: 999px;
    padding: 0 8px;
}

.glist {
    display: grid;
    gap: 2px;
    padding: 2px 0 6px 14px;
}

/* the folded rail (wide screens only) */
@media (min-width: 861px) {
    .app.min {
        grid-template-columns: 56px minmax(0, 1fr);
    }

        .app.min .side {
            overflow: hidden;
        }

        .app.min .side-body {
            display: none;
        }

        .app.min .side-head {
            flex-direction: column;
            align-items: center;
            gap: 14px;
            padding: 10px 0 16px;
            border-bottom: 0;
        }

        .app.min .side-title {
            writing-mode: vertical-rl;
            letter-spacing: 0.14em;
        }

        .app.min .side-toggle {
            order: -1;
        }

            .app.min .side-toggle svg {
                transform: rotate(180deg);
            }
}

/* ---------- home page ---------- */
.home {
    display: grid;
    gap: 44px;
}

.hero {
    display: flex;
    align-items: center;
    gap: 28px;
    flex-wrap: wrap;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 32px;
}

.hero-art svg {
    width: 120px;
    height: 120px;
    display: block;
    animation: bob 2.8s steps(4, end) infinite;
}

.hero-copy {
    flex: 1 1 300px;
    min-width: 0;
}

.px-bubble {
    display: inline-block;
    margin: 0 0 16px;
    padding: 6px 14px;
    background: var(--sun);
    color: #1f1d3d;
    border-radius: 999px;
    font-weight: 700;
    font-size: 0.95rem;
}

.hero h2 {
    font-weight: 800;
    font-size: clamp(1.7rem, 4vw, 2.4rem);
    line-height: 1.15;
}

.lead {
    margin: 14px 0 0;
    max-width: 58ch;
    font-size: 1.05rem;
    color: var(--muted);
}

.sec {
    font-size: 1.3rem;
    font-weight: 700;
}

.why {
    margin: 10px 0 20px;
    max-width: 66ch;
    color: var(--muted);
}

.reasons {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 16px;
}

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

    .reason h4 {
        font-size: 1.05rem;
        font-weight: 700;
        margin-bottom: 6px;
    }

    .reason p {
        margin: 0;
        color: var(--muted);
    }

.steps {
    list-style: none;
    margin: 16px 0 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 16px;
}

    .steps li {
        display: flex;
        gap: 12px;
        align-items: flex-start;
    }

    .steps p {
        margin: 3px 0 0;
    }

.num {
    flex: none;
    width: 32px;
    height: 32px;
    display: grid;
    place-items: center;
    background: var(--sun);
    color: #1f1d3d;
    border-radius: 8px;
    font-weight: 800;
    font-size: 0.9rem;
}

.start {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 16px;
}

.more {
    margin: 16px 0 0;
    color: var(--muted);
}

/* ---------- lesson title ---------- */
.main {
    min-width: 0;
}

.title-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px 16px;
}

    .title-row h2 {
        font-size: clamp(1.6rem, 4vw, 2.1rem);
        font-weight: 800;
    }

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

.pill {
    font-family: var(--font-mono);
    font-size: 0.74rem;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 1px 10px;
    white-space: nowrap;
}

    .pill b {
        font-family: var(--font-body);
        font-weight: 700;
        color: var(--muted);
        margin-right: 4px;
    }

.blurb {
    margin: 8px 0 20px;
    max-width: 68ch;
    color: var(--muted);
}

/* ---------- stage ---------- */
.stage {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.coach {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 16px;
    background: var(--panel2);
}

.coach-mascot {
    flex: none;
}

    .coach-mascot svg {
        width: 48px;
        height: 48px;
        display: block;
        animation: bob 2.8s steps(4, end) infinite;
    }

.bubble {
    flex: 1;
    min-width: 0;
    min-height: 44px;
    display: flex;
    align-items: center;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 6px 14px;
    font-weight: 500;
    position: relative;
}

    .bubble::before {
        content: "";
        position: absolute;
        left: -6px;
        top: 50%;
        width: 10px;
        height: 10px;
        background: var(--panel);
        border-left: 1px solid var(--line);
        border-bottom: 1px solid var(--line);
        transform: translateY(-50%) rotate(45deg);
    }

.canvas {
    position: relative;
    height: 280px;
    overflow: hidden;
}

.edges {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

    .edges line {
        stroke: var(--muted);
        stroke-width: 3;
        stroke-linecap: round;
        opacity: 0.55;
        transition: stroke 0.3s, stroke-width 0.3s, opacity 0.3s;
    }

        .edges line.hot {
            stroke: var(--sun);
            stroke-width: 6;
            opacity: 1;
        }

        .edges line.tree {
            stroke: var(--mint);
            stroke-width: 5;
            opacity: 1;
        }

@keyframes bob {
    50% {
        transform: translateY(-4px);
    }
}

@keyframes pop {
    from {
        opacity: 0;
        scale: 0.6;
    }
}

@keyframes shake {
    25% {
        translate: -5px 0;
    }

    75% {
        translate: 5px 0;
    }
}

.item {
    position: absolute;
    left: 0;
    top: 0;
    transition: transform 0.45s cubic-bezier(0.3, 1.35, 0.5, 1), height 0.3s, background-color 0.25s, opacity 0.25s;
    animation: pop 0.3s ease-out;
    will-change: transform;
}

.bar, .cell, .node {
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-mono);
    font-weight: 600;
    background: var(--violet);
    color: #fff;
    border: 2px solid var(--outline);
}

.bar {
    align-items: flex-start;
    padding-top: 5px;
    border-radius: 10px 10px 4px 4px;
    font-size: 0.95rem;
}

.cell {
    border-radius: 8px;
}

.node {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--panel);
    color: var(--ink);
    font-size: 1rem;
}

.item.compare, .item.mid, .item.current, .item.peek {
    background: var(--sun);
    color: #1f1d3d;
}

.item.swap, .item.out {
    background: var(--coral);
    color: #fff;
}

.item.sorted, .item.found, .item.done {
    background: var(--mint);
    color: #06352b;
}

.item.key, .item.queued {
    background: var(--sky);
    color: #fff;
}

.item.dim {
    opacity: 0.28;
}

.item.out {
    opacity: 0.85;
}

.tag {
    display: flex;
    justify-content: center;
    font-family: var(--font-mono);
    font-size: 0.74rem;
    font-weight: 600;
    text-align: center;
    color: var(--bg);
    background: var(--ink);
    border-radius: 7px;
    padding: 1px 6px;
    white-space: nowrap;
}

.cap {
    font-family: var(--font-mono);
    font-size: 0.82rem;
    color: var(--muted);
    white-space: nowrap;
}

    .cap.banner {
        font-weight: 600;
        color: var(--ink);
    }

.floor {
    height: 3px;
    background: var(--muted);
    opacity: 0.4;
    border-radius: 2px;
}

.jar {
    border: 3px solid var(--ink);
    border-top: 0;
    border-radius: 0 0 14px 14px;
}

    .jar.shake {
        animation: shake 0.35s ease-in-out;
    }

.pipe {
    border-top: 3px solid var(--ink);
    border-bottom: 3px solid var(--ink);
}

/* ---------- controls ---------- */
.controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-top: 20px;
}

.speed {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--muted);
}

    .speed input {
        width: 110px;
    }

.scrub {
    width: 100%;
    margin: 14px 0 0;
    accent-color: var(--violet);
}

input[type=range] {
    accent-color: var(--violet);
}

.inputs {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 10px 16px;
    margin-top: 14px;
}

    .inputs label {
        display: flex;
        flex-direction: column;
        gap: 4px;
        font-size: 0.8rem;
        font-weight: 600;
        color: var(--muted);
        min-width: 0;
    }

    .inputs input[type=text], .inputs input[type=number], .inputs select {
        font: inherit;
        font-family: var(--font-mono);
        font-size: 0.9rem;
        color: var(--ink);
        background: var(--panel);
        border: 1px solid var(--line);
        border-radius: 10px;
        padding: 7px 10px;
        max-width: 100%;
    }

    .inputs .grow {
        flex: 1 1 260px;
    }

        .inputs .grow input {
            width: 100%;
        }

    .inputs input[type=number] {
        width: 84px;
    }

.msg {
    min-height: 1.4em;
    margin-top: 6px;
    font-size: 0.85rem;
    color: var(--coral);
    font-weight: 600;
}

/* ---------- code ---------- */
.code {
    margin-top: 16px;
    background: var(--code-bg);
    color: var(--code-fg);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
}

.code-head {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 16px;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--code-dim);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.code-body {
    position: relative;
    max-height: 380px;
    overflow: auto;
    padding: 8px 0;
    font-family: var(--font-mono);
    font-size: 0.86rem;
    line-height: 1.75;
}

.ln {
    display: flex;
    white-space: pre;
    border-left: 4px solid transparent;
    padding-right: 16px;
    cursor: pointer;
    min-width: max-content;
}

    .ln:hover {
        background: rgba(255, 255, 255, 0.05);
    }

    .ln .n {
        flex: none;
        width: 3em;
        padding-right: 14px;
        text-align: right;
        color: var(--code-dim);
        user-select: none;
    }

    .ln.on {
        background: var(--code-hl);
        border-left-color: var(--sun);
    }

        .ln.on .n {
            color: var(--sun);
        }

    .ln.skip {
        cursor: default;
    }

        .ln.skip:hover {
            background: none;
        }

.k {
    color: var(--c-kw);
}

.s {
    color: var(--c-str);
}

.d {
    color: var(--c-num);
}

.f {
    color: var(--c-fn);
}

.c {
    color: var(--c-cm);
    font-style: italic;
}

.vars {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 8px;
    padding: 10px 16px 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    min-height: 50px;
    font-family: var(--font-mono);
    font-size: 0.78rem;
    align-items: center;
}

    .vars .chip {
        background: rgba(255, 255, 255, 0.1);
        border-radius: 8px;
        padding: 2px 10px;
    }

        .vars .chip b {
            color: var(--c-fn);
            font-weight: 600;
            margin-right: 6px;
        }

    .vars .none {
        color: var(--code-dim);
    }

.hint {
    margin: 10px 2px 0;
    font-size: 0.82rem;
    color: var(--muted);
}

/* ---------- coming soon ---------- */
.soon-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 24px;
    display: flex;
    gap: 18px;
    align-items: center;
    flex-wrap: wrap;
}

    .soon-card svg {
        width: 84px;
        height: 84px;
        flex: none;
    }

    .soon-card h3 {
        margin: 0 0 4px;
        font-size: 1.3rem;
    }

    .soon-card p {
        margin: 0;
        color: var(--muted);
        max-width: 52ch;
    }

/* ---------- narrow screens ---------- */
@media (max-width: 860px) {
    .app {
        grid-template-columns: minmax(0, 1fr);
    }

    #topicsBtn {
        display: inline-block;
    }

    .side {
        display: none;
        position: static;
        max-height: 60vh;
    }

        .side.open {
            display: block;
        }

    .side-toggle {
        display: none;
    }

    .speed {
        margin-left: 0;
    }

    .canvas {
        height: 250px;
    }

    .hero {
        padding: 22px;
    }

    .hero-art svg {
        width: 96px;
        height: 96px;
    }
}

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

    .app {
        transition: none;
    }

    .coach-mascot svg, .hero-art svg {
        animation: none;
    }

    .jar.shake {
        animation: none;
    }
}
