:root {
    --paper: #f3eee3;
    --paper-2: #fffbf4;
    --ink: #1b1712;
    --ink-soft: #5c564c;
    --line: #d9d0c0;
    --teal: #0f6b56;
    --teal-2: #148067;
    --amber: #e09a12;
    --amber-ink: #6a4700;
    --blue: #215ea8;
    --blue-soft: #d7e6f8;
    --gray: #8d877c;
    --rose: #b44538;
    --rose-soft: #f6d9d4;
    --path: #0f6b56;
    --shadow: 0 18px 40px rgba(40, 28, 8, 0.08);
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
    background:
        radial-gradient(1200px 500px at 10% -10%, #efe4c8 0%, transparent 55%),
        var(--paper);
    color: var(--ink);
    font-family: Outfit, "Segoe UI", sans-serif;
    font-size: 16px;
    line-height: 1.45;
}

.page {
    max-width: 1180px;
    margin: 0 auto;
    padding: 32px 22px 64px;
}

.crumb {
    margin: 0 0 18px;
}

.crumb ol {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 0;
    list-style: none;
    margin: 0;
    padding: 0;
    font-family: "IBM Plex Mono", ui-monospace, monospace;
    font-size: 12px;
    line-height: 1.4;
}

.crumb li {
    display: inline-flex;
    align-items: center;
    color: var(--ink);
}

.crumb li:not(:last-child)::after {
    content: "/";
    margin: 0 8px;
    color: var(--gray);
}

.crumb a {
    color: var(--teal);
    text-decoration: none;
}

.crumb a:hover {
    color: var(--teal-2);
}

.crumb [aria-current="page"] {
    color: var(--ink-soft);
}

.hero h1,
.board-head h2,
.panel h3 {
    font-family: Fraunces, Georgia, serif;
    font-optical-sizing: auto;
    margin: 0;
}

.eyebrow {
    margin: 0 0 8px;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    font-size: 11px;
    font-weight: 560;
    color: var(--teal);
}

.hero h1 {
    font-size: clamp(28px, 4vw, 42px);
    font-weight: 620;
    letter-spacing: -0.03em;
    line-height: 1.12;
    max-width: 18ch;
}

.lede {
    max-width: 62ch;
    color: var(--ink-soft);
    margin: 12px 0 0;
}

.lede strong,
.primer strong {
    color: var(--ink);
}

.primer {
    margin-top: 22px;
    padding: 14px 16px 12px;
    background: #efe6d4;
    border: 1px solid var(--line);
}

.primer-label {
    font-size: 11px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--teal);
    font-weight: 560;
    margin-bottom: 4px;
}

.primer p {
    margin: 6px 0;
    color: var(--ink-soft);
    font-size: 14.5px;
}

.mono {
    font-family: "IBM Plex Mono", ui-monospace, monospace;
    font-size: 0.92em;
    background: #efe6d4;
    padding: 0 5px;
    border-radius: 4px;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

.tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 22px 0 16px;
}

.tabs button {
    appearance: none;
    border: 1px solid var(--line);
    background: var(--paper-2);
    color: var(--ink-soft);
    font: 560 13px Outfit, sans-serif;
    padding: 8px 12px;
    border-radius: 999px;
    cursor: pointer;
}

.tabs button:hover {
    border-color: #b9ae9a;
    color: var(--ink);
}

.tabs button[aria-selected="true"] {
    background: var(--ink);
    border-color: var(--ink);
    color: #f7f1e6;
}

.stage {
    display: grid;
    grid-template-columns: minmax(0, 1.35fr) minmax(300px, 0.95fr);
    gap: 18px;
    align-items: start;
}

.board,
.panel {
    background: var(--paper-2);
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
}

.board {
    padding: 16px 16px 14px;
}

.board-head {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: flex-start;
    margin-bottom: 8px;
}

.board-head h2 {
    font-size: 24px;
    font-weight: 620;
}

.formula {
    margin: 4px 0 0;
    font-family: "IBM Plex Mono", ui-monospace, monospace;
    font-size: 13px;
    color: var(--teal);
}

.status {
    flex: none;
    font-size: 12px;
    font-weight: 560;
    padding: 5px 10px;
    border-radius: 999px;
    background: #efe6d4;
    color: var(--ink-soft);
}

.status.is-run {
    background: #f8e4b0;
    color: var(--amber-ink);
}

.status.is-ok {
    background: #d7efe6;
    color: var(--teal);
}

.status.is-stuck {
    background: var(--rose-soft);
    color: var(--rose);
}

#graph {
    width: 100%;
    height: auto;
    display: block;
    background: linear-gradient(#faf6ee, #f4ecdc);
    border: 1px solid #eadfcb;
    border-radius: 10px;
}

.node circle {
    fill: #fffdf8;
    stroke: #c9beab;
    stroke-width: 2;
}

.node.start circle {
    stroke: var(--teal);
    stroke-width: 2.6;
}

.node.goal circle {
    fill: #fff6dd;
    stroke: #7c5a00;
    stroke-width: 3;
}

.node.goal .id {
    fill: #4a3400;
}

.node .id {
    font-family: Fraunces, Georgia, serif;
    font-size: 16px;
    font-weight: 700;
    fill: var(--ink);
    text-anchor: middle;
    dominant-baseline: central;
}

.node .meta {
    font-family: "IBM Plex Mono", ui-monospace, monospace;
    font-size: 10px;
    fill: var(--ink-soft);
    text-anchor: middle;
}

.edge {
    fill: none;
    stroke: #cbbfa8;
    stroke-width: 2;
}

.edge-label {
    font-family: "IBM Plex Mono", ui-monospace, monospace;
    font-size: 11px;
    fill: #6d665b;
    text-anchor: middle;
    dominant-baseline: middle;
}

.node.is-expanded circle {
    fill: #ece7dc;
    stroke: #b5ad9e;
}

.node.is-expanded .id {
    fill: #6a645a;
}

.node.is-frontier circle {
    fill: var(--blue-soft);
    stroke: var(--blue);
}

.node.is-current circle {
    fill: #f6d889;
    stroke: var(--amber);
    stroke-width: 3;
}

.node.is-path circle {
    fill: #cdeadf;
    stroke: var(--path);
}

.node.is-path.is-current circle,
.node.is-frontier.is-current circle {
    fill: #f6d889;
    stroke: var(--amber);
}

.node.is-drop circle {
    fill: var(--rose-soft);
    stroke: var(--rose);
}

.edge.is-path {
    stroke: var(--path);
    stroke-width: 3.2;
}

.edge.is-current {
    stroke: var(--amber);
    stroke-width: 3.4;
}

.edge.is-drop {
    stroke: var(--rose);
    stroke-dasharray: 5 4;
}

.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 12px 16px;
    list-style: none;
    padding: 10px 2px 0;
    margin: 0;
    color: var(--ink-soft);
    font-size: 13px;
}

.swatch {
    display: inline-block;
    width: 11px;
    height: 11px;
    border-radius: 99px;
    margin-right: 5px;
    vertical-align: -1px;
    border: 1px solid rgba(0, 0, 0, 0.12);
}

.swatch-current {
    background: #f6d889;
    border-color: var(--amber);
}
.swatch-frontier {
    background: var(--blue-soft);
    border-color: var(--blue);
}
.swatch-expanded {
    background: #ece7dc;
    border-color: #b5ad9e;
}
.swatch-path {
    background: #cdeadf;
    border-color: var(--path);
}
.swatch-goal {
    background: #fff6dd;
    border-color: #7c5a00;
    border-width: 2px;
}
.swatch-drop {
    background: var(--rose-soft);
    border-color: var(--rose);
}

.transport {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px 16px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--line);
}

.transport-btns {
    display: flex;
    gap: 8px;
}

@media (prefers-reduced-motion: no-preference) {
    .transport button,
    .tabs button {
        transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
    }
}

.transport button {
    appearance: none;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--ink);
    font: 560 13px Outfit, sans-serif;
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
}

.transport button.primary {
    background: var(--teal);
    border-color: var(--teal);
    color: #f4fff9;
}

.transport button:hover:not(:disabled) {
    filter: brightness(1.05);
}

.transport button:disabled {
    opacity: 0.45;
    cursor: default;
}

.speed {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--ink-soft);
}

.speed input {
    width: 110px;
    accent-color: var(--teal);
}

.step-count {
    margin: 0 0 0 auto;
    font-family: "IBM Plex Mono", ui-monospace, monospace;
    font-size: 12px;
    color: var(--ink-soft);
}

.panel {
    padding: 16px 16px 18px;
    position: sticky;
    top: 12px;
}

.panel h3 {
    font-size: 13px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    font-weight: 620;
    color: var(--ink-soft);
    margin-bottom: 6px;
}

.panel section + section {
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--line);
}

.idea,
.why,
.narration {
    margin: 0;
    font-size: 14.5px;
}

.why {
    color: var(--ink-soft);
}

.narration {
    background: #f7f0e2;
    border-radius: 8px;
    padding: 10px 11px;
    min-height: 8.5em;
    white-space: pre-wrap;
}

.row-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
}

.hint {
    font-size: 11px;
    color: var(--gray);
    font-family: "IBM Plex Mono", ui-monospace, monospace;
}

.ds {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    min-height: 38px;
}

.ds-mark {
    font-size: 10px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--gray);
}

.chip {
    display: inline-flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 1px;
    padding: 5px 8px;
    border-radius: 8px;
    background: var(--blue-soft);
    color: #163a6b;
    font-family: "IBM Plex Mono", ui-monospace, monospace;
    font-size: 12px;
    line-height: 1.25;
    border: 1px solid #b9d0ee;
}

.chip b {
    font-weight: 500;
    font-size: 13px;
}

.chip small {
    color: #3d5f8a;
    font-size: 10px;
}

.chip.is-next {
    background: #f6d889;
    border-color: #e0b34a;
    color: var(--amber-ink);
}

.chip.is-next small {
    color: var(--amber-ink);
}

.chip.is-drop {
    background: var(--rose-soft);
    border-color: #e3b0a8;
    color: var(--rose);
    text-decoration: line-through;
}

.chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    min-height: 1.6em;
}

.chip-row .chip {
    background: #ece7dc;
    border-color: #d4cbb8;
    color: #5a564c;
}

.chip-row .chip small {
    color: #7a7468;
}

.empty {
    color: var(--gray);
    font-size: 13px;
}

.analysis {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.analysis ul {
    margin: 0;
    padding-left: 16px;
    color: var(--ink-soft);
    font-size: 13px;
}

.analysis li + li {
    margin-top: 4px;
}

.code-panel {
    margin-top: 18px;
    background: #1c1915;
    border: 1px solid #3a342c;
    box-shadow: var(--shadow);
    padding: 14px 14px 12px;
    border-radius: 2px;
}

.code-panel .row-head {
    margin-bottom: 10px;
}

.code-panel h3 {
    font-family: Fraunces, Georgia, serif;
    font-size: 13px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    font-weight: 620;
    color: #d9cbb3;
    margin: 0;
}

.code-panel .hint {
    color: #9a9082;
}

.copy-btn {
    appearance: none;
    margin-left: auto;
    border: 1px solid #5a5348;
    background: #2a2520;
    color: #f0e6d4;
    font: 560 12px Outfit, sans-serif;
    padding: 5px 10px;
    border-radius: 6px;
    cursor: pointer;
}

.copy-btn:hover {
    background: #3a342c;
}

.code-block {
    margin: 0;
    max-height: 420px;
    overflow: auto;
    font-family: "IBM Plex Mono", ui-monospace, monospace;
    font-size: 12.5px;
    line-height: 1.55;
    color: #e8ddcc;
}

.code-line {
    display: grid;
    grid-template-columns: 36px 1fr;
    gap: 10px;
    padding: 0 8px;
    border-radius: 4px;
}

.code-line .ln {
    color: #6f675c;
    text-align: right;
    user-select: none;
}

.code-line .lx {
    white-space: pre;
}

.code-line.is-on {
    background: #5a4314;
    box-shadow: inset 3px 0 0 #e09a12;
}

.code-line.is-on .lx {
    color: #ffe7a8;
}

.code-line.is-on .ln {
    color: #e09a12;
    font-weight: 500;
}

@media (max-width: 960px) {
    .stage {
        grid-template-columns: 1fr;
    }

    .panel {
        position: static;
    }

    .step-count {
        margin-left: 0;
    }
}

@media (max-width: 640px) {
    .primer {
        padding: 12px;
    }

    .board-head {
        flex-direction: column;
    }

    .status {
        align-self: flex-start;
    }

    .transport {
        flex-direction: column;
        align-items: stretch;
    }

    .transport-btns {
        flex-wrap: wrap;
    }

    .speed {
        justify-content: space-between;
    }

    .speed input {
        flex: 1;
        min-width: 0;
        width: auto;
    }

    .step-count {
        margin-left: 0;
    }

    .analysis {
        grid-template-columns: 1fr;
    }

    .code-line {
        grid-template-columns: 28px 1fr;
        gap: 6px;
    }

    .code-line .lx {
        overflow-x: auto;
    }
}
