@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;600&display=swap');

:root {
    --bg-outer: #d4c5a9;
    --bg-page: #faf6ee;
    --bg-card: #fdfbf7;
    --bg-svg: #fffdf8;
    --bg-insight: #fdf8ee;
    --bg-active: #faf3e6;

    --text-primary: #362b1f;
    --text-heading: #2c2416;
    --text-h2: #3d2e1c;
    --text-h3: #4a3828;
    --text-muted: #6b5b47;
    --text-subtle: #7a6b57;
    --text-insight: #5a4630;

    --border-main: #e8dfd0;
    --border-section: #e0d5c4;
    --border-card: #ddd4c4;
    --border-input: #c4b99a;

    --accent: #8b6f47;
    --accent-hover: #6d5636;
    --accent-border: #c4a882;
    --accent-green: #5a7a5c;
    --accent-green-hover: #476248;

    --case1: #a04000;
    --case2: #5c2d82;
    --case3: #2e6b30;

    --red-node: #a02020;
    --black-node: #1a1410;

    --btn-disabled-bg: #c4b99a;
    --btn-disabled-text: #8a7d6b;

    --shadow-page: 0 1px 3px rgba(0, 0, 0, 0.08), 0 8px 24px rgba(0, 0, 0, 0.06);
    --shadow-inset: inset 0 0 80px rgba(139, 115, 85, 0.03);
    --shadow-card-active: 0 2px 8px rgba(139, 111, 71, 0.12);
    --shadow-suggestion: 0 2px 6px rgba(139, 111, 71, 0.1);

    --lines-color: rgba(139, 115, 85, 0.02);
    --gradient1: rgba(139, 115, 85, 0.08);
    --gradient2: rgba(139, 115, 85, 0.05);

    --toggle-bg: #e0d5c4;
    --toggle-knob: #8b6f47;
}

[data-theme="sepia"] {
    --bg-outer: #c8b68e;
    --bg-page: #f4e8cd;
    --bg-card: #f7ecd5;
    --bg-svg: #f5e9d0;
    --bg-insight: #f0e2c2;
    --bg-active: #eedcb8;

    --text-primary: #3d2e1a;
    --text-heading: #2a1e10;
    --text-h2: #3d2e1a;
    --text-h3: #4d3c24;
    --text-muted: #6b5535;
    --text-subtle: #7a6545;
    --text-insight: #5a4420;

    --border-main: #dcc9a0;
    --border-section: #d4be94;
    --border-card: #d4be94;
    --border-input: #b89e6e;

    --accent: #7a5c2e;
    --accent-hover: #5c4420;
    --accent-border: #b89e6e;
    --accent-green: #4a6a3a;
    --accent-green-hover: #3a5a2a;

    --case1: #944000;
    --case2: #5a2d6e;
    --case3: #2e6020;

    --red-node: #942020;
    --black-node: #2a1e10;

    --btn-disabled-bg: #b89e6e;
    --btn-disabled-text: #8a7550;

    --shadow-page: 0 1px 3px rgba(0, 0, 0, 0.1), 0 8px 24px rgba(0, 0, 0, 0.08);
    --shadow-inset: inset 0 0 80px rgba(139, 115, 85, 0.05);
    --shadow-card-active: 0 2px 8px rgba(122, 92, 46, 0.15);
    --shadow-suggestion: 0 2px 6px rgba(122, 92, 46, 0.12);

    --lines-color: rgba(139, 115, 85, 0.03);
    --gradient1: rgba(139, 115, 85, 0.1);
    --gradient2: rgba(139, 115, 85, 0.06);

    --toggle-bg: #d4be94;
    --toggle-knob: #7a5c2e;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

a {
    color: var(--accent);
    text-decoration-color: var(--accent-border);
}

a:hover {
    color: var(--accent-hover);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 0.95rem;
    line-height: 1.6;
    color: var(--text-primary);
    background: var(--bg-outer);
    background-image:
        radial-gradient(ellipse at 20% 50%, var(--gradient1) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 20%, var(--gradient2) 0%, transparent 50%);
    padding: 2.5rem;
    min-height: 100vh;
    transition: background 0.3s, color 0.3s;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

.container {
    max-width: 1300px;
    margin: 0 auto;
    background: var(--bg-page);
    padding: 2.5rem 3rem;
    border-radius: 3px;
    box-shadow: var(--shadow-page);
    border: 1px solid var(--border-main);
    position: relative;
    transition: background 0.3s, border-color 0.3s, box-shadow 0.3s;
}


/* --- Breadcrumb --- */

.breadcrumb {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
}

.breadcrumb a {
    color: var(--text-muted);
    text-decoration: none;
}

.breadcrumb a:hover {
    color: var(--accent);
}

/* --- Theme Toggle --- */

.theme-toggle {
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.25rem;
    z-index: 10;
}

.theme-btn {
    font-size: 0.72rem;
    font-family: 'JetBrains Mono', monospace;
    padding: 0.25rem 0.5rem;
    border: 1px solid var(--border-card);
    border-radius: 2px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.theme-btn:hover {
    color: var(--text-primary);
    border-color: var(--accent);
}

.theme-btn.active {
    background: var(--accent);
    color: var(--bg-page);
    border-color: var(--accent);
}


/* --- Typography --- */

h1 {
    font-size: 2.2rem;
    font-weight: 700;
    margin-bottom: 2.5rem;
    color: var(--text-heading);
    text-align: center;
    letter-spacing: -0.5px;
    border-bottom: 1px solid var(--accent-border);
    padding-bottom: 1.2rem;
    transition: color 0.3s, border-color 0.3s;
}

h2 {
    font-size: 1.4rem;
    font-weight: 600;
    margin-top: 0.5rem;
    margin-bottom: 1rem;
    color: var(--text-h2);
    letter-spacing: -0.3px;
    transition: color 0.3s;
}

h3 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-top: 0.8rem;
    margin-bottom: 0.4rem;
    color: var(--text-h3);
    transition: color 0.3s;
}

section {
    background: transparent;
    border-radius: 0;
    padding: 0.8rem 0;
    margin-bottom: 0;
    box-shadow: none;
    border-bottom: none;
}

section:last-child {
    border-bottom: none;
}

p {
    margin-bottom: 0.5rem;
}

.intro ol {
    margin: 1rem 0 1rem 2rem;
    list-style: none;
    counter-reset: rule-counter;
}

.intro li {
    margin-bottom: 0.5rem;
    counter-increment: rule-counter;
    position: relative;
    padding-left: 0.5rem;
}

.intro li::before {
    content: counter(rule-counter) ".";
    position: absolute;
    left: -1.8rem;
    color: var(--accent);
    font-weight: 600;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.9rem;
}

.key-insight {
    margin-top: 1rem;
    padding: 0.8rem 1.2rem;
    background: var(--bg-insight);
    border-left: 3px solid var(--accent-border);
    border-radius: 0;
    font-style: italic;
    color: var(--text-insight);
    transition: background 0.3s, border-color 0.3s, color 0.3s;
}

/* ============================================================
   Graph BFS page
   ============================================================ */

:root {
    --v-white: #fffdf8;
    --v-white-text: #362b1f;
    --v-gray: #9b9184;
    --v-gray-text: #ffffff;
    --v-black: #2c2416;
    --v-black-text: #fdfbf7;
    --v-stroke: #6b5b47;
    --edge: #b8ab95;
    --tree-edge: #8b6f47;
    --cur-u: #1c7ed6;
    --cur-v: #e8590c;
    --path: #7048e8;
    --tag-s: #495057;
    --wall: #5f5244;
    --code-bg: #fffdf8;
    --code-hl: rgba(28, 126, 214, 0.12);
    --code-hl2: rgba(232, 89, 12, 0.14);
    --diff-bg: rgba(139, 111, 71, 0.12);
}

[data-theme="sepia"] {
    --v-white: #fbf3e2;
    --v-gray: #9a8a70;
    --v-black: #2a1e10;
    --edge: #b8a27a;
    --tree-edge: #7a5c2e;
    --code-bg: #f9efd9;
}

code, .mono {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85em;
}

.intro ul {
    margin: 0.5rem 0 0.8rem 1.4rem;
}

.intro ul li::before {
    content: none;
}

.intro ul li {
    padding-left: 0;
    margin-bottom: 0.3rem;
}

.swatch {
    display: inline-block;
    width: 0.9em;
    height: 0.9em;
    border-radius: 50%;
    border: 1.5px solid var(--v-stroke);
    vertical-align: -0.1em;
    margin-right: 0.15em;
}

.swatch.unfound { background: var(--v-white); }
.swatch.queued { background: var(--v-gray); }
.swatch.finished { background: var(--v-black); }

/* --- toolbar --- */

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem 1rem;
    align-items: center;
    margin-bottom: 0.8rem;
}

.toolbar label {
    font-size: 0.82rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

select, .toolbar input[type="range"] {
    font-family: 'Inter', sans-serif;
    font-size: 0.85rem;
    color: var(--text-primary);
    background: var(--bg-card);
    border: 1px solid var(--border-input);
    border-radius: 2px;
    padding: 0.3rem 0.4rem;
}

.toolbar input[type="range"] {
    padding: 0;
    width: 110px;
    accent-color: var(--accent);
}

.tabs {
    display: inline-flex;
    border: 1px solid var(--accent);
    border-radius: 2px;
    overflow: hidden;
}

.tabs button {
    border: none;
    background: transparent;
    color: var(--accent);
    font: 600 0.82rem 'Inter', sans-serif;
    padding: 0.4rem 0.9rem;
    cursor: pointer;
}

.tabs button.active {
    background: var(--accent);
    color: var(--bg-page);
}

.btn {
    padding: 0.4rem 0.8rem;
    border: 1px solid var(--accent-green);
    border-radius: 2px;
    background: var(--accent-green);
    color: var(--bg-page);
    font: 600 0.82rem 'Inter', sans-serif;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}

.btn:hover { background: var(--accent-green-hover); }
.btn:active { transform: scale(0.97); }

.btn:disabled {
    background: var(--btn-disabled-bg);
    border-color: var(--btn-disabled-bg);
    color: var(--btn-disabled-text);
    cursor: not-allowed;
}

.btn.ghost {
    background: transparent;
    color: var(--accent-green);
}

.btn.ghost:hover { background: var(--bg-active); }

.btn.ghost.on {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--bg-page);
}

/* disabled: muted, no hover or press effect (also for ghost buttons) */
.btn:disabled, .btn:disabled:hover, .btn.ghost:disabled, .btn.ghost:disabled:hover {
    background: var(--btn-disabled-bg);
    border-color: var(--btn-disabled-bg);
    color: var(--btn-disabled-text);
    cursor: not-allowed;
    transform: none;
}

.step-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.45rem;
    margin-top: 0.6rem;
}

.step-count {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    color: var(--text-muted);
    min-width: 7.5em;
    text-align: center;
}

.kbd-hint {
    font-size: 0.75rem;
    color: var(--text-subtle);
    margin-top: 0.3rem;
}

/* --- workspace --- */

.ws {
    display: flex;
    gap: 1.4rem;
    align-items: flex-start;
}

.ws-main {
    flex: 1;
    min-width: 0;
}

.ws-side {
    width: 380px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.ws.compare .ws-pair {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.panel {
    background: var(--bg-card);
    border: 1px solid var(--border-section);
    border-radius: 2px;
    padding: 0.7rem 0.9rem;
    transition: background 0.3s, border-color 0.3s;
}

.panel-title {
    font: 600 0.7rem 'JetBrains Mono', monospace;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 0.4rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
}

.panel-title.plain {
    display: block;
}

.panel-title.plain code {
    text-transform: none;
    letter-spacing: 0;
    font-variant-ligatures: none;
}

.panel-title label {
    text-transform: none;
    letter-spacing: 0;
    color: var(--text-muted);
    font-family: 'Inter', sans-serif;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.3rem;
    cursor: pointer;
}

/* --- graph svg --- */

.graph-box {
    position: relative;
}

.graph-svg {
    display: block;
    width: 100%;
    height: auto;
    max-height: 62vh;
    background: var(--bg-svg);
    border: 1px solid var(--border-card);
    border-radius: 2px;
    box-shadow: inset 0 1px 4px rgba(139, 115, 85, 0.06);
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}


.graph-label {
    font: 600 0.75rem 'JetBrains Mono', monospace;
    color: var(--text-muted);
    margin-bottom: 0.3rem;
}

.edge {
    stroke: var(--edge);
    stroke-width: 2;
    fill: none;
}

.edge.tree {
    stroke: var(--tree-edge);
    stroke-width: 4;
}

.edge.exam {
    stroke: var(--cur-v);
    stroke-width: 4;
    stroke-dasharray: 7 5;
}

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

.vertex circle.body, .vertex rect.body {
    stroke: var(--v-stroke);
    stroke-width: 2;
    transition: fill 0.25s;
}

.vertex.unfound .body { fill: var(--v-white); }
.vertex.queued .body { fill: var(--v-gray); }
.vertex.finished .body { fill: var(--v-black); }

.vertex text.name {
    font: 600 22px 'JetBrains Mono', monospace;
    text-anchor: middle;
    dominant-baseline: central;
    pointer-events: none;
}

.vertex.unfound text.name { fill: var(--v-white-text); }
.vertex.queued text.name { fill: var(--v-gray-text); }
.vertex.finished text.name { fill: var(--v-black-text); }

.vertex text.dist {
    font: 600 17px 'JetBrains Mono', monospace;
    text-anchor: middle;
    fill: var(--text-muted);
    pointer-events: none;
    /* keep the label readable where an edge passes behind it */
    paint-order: stroke;
    stroke: var(--bg-svg);
    stroke-width: 4px;
    stroke-linejoin: round;
}

.vertex .halo {
    fill: none;
    stroke-width: 4;
    opacity: 0;
}

.vertex.cur-u .halo { stroke: var(--cur-u); opacity: 1; }
.vertex.cur-v .halo { stroke: var(--cur-v); opacity: 1; }
.vertex.on-path .halo { stroke: var(--path); opacity: 1; }
.vertex.src .body { stroke-width: 3.5; }

.vertex .badge circle {
    fill: var(--accent);
}

.vertex .badge text {
    font: 700 14px 'Inter', sans-serif;
    fill: var(--bg-page);
    text-anchor: middle;
    dominant-baseline: central;
}

.vertex { cursor: pointer; }

/* grid (maze) cells */
.cell-wall { fill: var(--wall); }
.vertex.cell .body { stroke-width: 1; }
.vertex.cell text.name { font-size: 12px; }
.vertex.cell .halo { stroke-width: 3; }
.cell-mark {
    font: 700 10px 'Inter', sans-serif;
    fill: var(--accent);
    pointer-events: none;
}

.ring {
    fill: none;
    stroke: var(--border-card);
    stroke-dasharray: 4 5;
}

.ring-label {
    font: 600 11px 'JetBrains Mono', monospace;
    fill: var(--text-subtle);
}

/* --- explanation --- */

.explain {
    min-height: 3.2em;
    padding: 0.6rem 0.9rem;
    background: var(--bg-insight);
    border-left: 3px solid var(--accent-green);
    color: var(--text-insight);
    font-size: 0.92rem;
    margin-top: 0.6rem;
    transition: background 0.3s, color 0.3s;
}

.explain b { color: var(--text-primary); }

.path-note {
    margin-top: 0.5rem;
    font-size: 0.88rem;
    color: var(--text-muted);
    min-height: 1.4em;
}

.path-note b { color: var(--path); }

/* --- code --- */

.code {
    font-family: 'JetBrains Mono', monospace;
    font-variant-ligatures: none;
    font-feature-settings: "liga" 0, "calt" 0;
    font-size: 0.74rem;
    line-height: 1.55;
    background: var(--code-bg);
    border: 1px solid var(--border-card);
    border-radius: 2px;
    padding: 0.4rem 0;
    overflow-x: auto;
    white-space: pre;
    transition: background 0.3s;
}

.code .ln {
    display: block;
    padding: 0 0.7rem 0 0.5rem;
    border-left: 3px solid transparent;
    min-height: 1.55em;
}

.code .ln.cmt, .code .icmt { color: var(--text-subtle); font-style: italic; font-weight: 400; }
.code .ln.hl { background: var(--code-hl); border-left-color: var(--cur-u); }
.code .kw { color: var(--case2); font-weight: 600; }

.diff {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.6rem;
}

.diff .code .ln.diffln { background: var(--diff-bg); }
.diff .code .ln.key { background: var(--code-hl2); font-weight: 600; }
.diff .code .ln.hl { background: var(--code-hl); border-left-color: var(--cur-u); }
.diff .code .ln.empty { opacity: 0.35; }

/* --- queue / stack --- */

.container-row {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    min-height: 2.6rem;
    font-size: 0.75rem;
    color: var(--text-subtle);
}

.cells {
    position: relative;
    display: flex;
    gap: 0.3rem;
    flex: 1;
    min-height: 2.3rem;
    align-items: center;
    flex-wrap: wrap;
}

.qcell {
    min-width: 2.5rem;
    height: 2.6rem;
    padding: 0 0.4rem;
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border: 1.5px solid var(--v-stroke);
    border-radius: 2px;
    background: var(--v-gray);
    color: var(--v-gray-text);
    font: 600 0.85rem 'JetBrains Mono', monospace;
    line-height: 1;
}

.qcell b { font-size: 1rem; font-weight: 700; }

.qcell.added { box-shadow: 0 0 0 3px var(--cur-v); }

.qcell small {
    font-size: 0.62rem;
    opacity: 0.85;
    margin-top: 2px;
    font-weight: 500;
}

.qcell.stale {
    background: var(--v-black);
    color: var(--v-black-text);
    opacity: 0.6;
}

.qcell.enter { animation: qenter 0.35s ease-out; }

.qcell.leave {
    position: absolute;
    animation: qleave 0.35s ease-in forwards;
    pointer-events: none;
}

@keyframes qenter {
    from { transform: translateX(24px); opacity: 0; }
}

@keyframes qleave {
    to { transform: translateX(-40px); opacity: 0; }
}

/* --- queue / stack lane --- */
.qlane { display: flex; align-items: center; gap: 0.8rem; flex-wrap: wrap; }
.qbody {
    flex: 1 1 260px;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    border: 1px solid var(--border-card);
    border-radius: 3px;
    background: var(--bg-svg);
    padding: 0.35rem 0.5rem;
}
.cells.lane { flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; min-height: 2.9rem; padding: 4px; }
.qend { display: flex; align-items: center; gap: 0.3rem; font: 600 0.78rem 'Inter', sans-serif; color: var(--text-muted); white-space: nowrap; }
.qend span:not(.qarrow) { display: flex; flex-direction: column; line-height: 1.15; }
.qend small { font-weight: 400; font-size: 0.66rem; color: var(--text-subtle); }
.qend.back { text-align: right; }
.qend.back span:not(.qarrow) { align-items: flex-end; }
.qarrow { font-size: 1.2rem; color: var(--accent); }
.qhist { display: flex; align-items: center; gap: 0.35rem; font-size: 0.7rem; color: var(--text-subtle); }
.qhist-label { white-space: nowrap; }
.qhist-cells { display: flex; gap: 0.2rem; align-items: center; }
.hcell {
    min-width: 1.6rem;
    height: 1.6rem;
    padding: 0 0.25rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 2px;
    background: var(--v-black);
    color: var(--v-black-text);
    font: 600 0.75rem 'JetBrains Mono', monospace;
}
.hcell.popped { box-shadow: 0 0 0 3px var(--cur-u); }
.hcell.enter { animation: henter 0.35s ease-out; }
@keyframes henter { from { transform: translateX(40px); opacity: 0; } }
.qhist-more { font: 600 0.7rem 'JetBrains Mono', monospace; color: var(--text-subtle); }
@media (max-width: 900px) {
    .cells.lane { flex-wrap: wrap; overflow-x: visible; }
}

.empty-note {
    font-style: italic;
    color: var(--text-subtle);
}

/* --- state table --- */

.state-table-wrap {
    max-height: 300px;
    overflow-y: auto;
}

.state-table {
    width: 100%;
    border-collapse: collapse;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.78rem;
}

.state-table th, .state-table td {
    padding: 0.2rem 0.5rem;
    border-bottom: 1px solid var(--border-card);
    text-align: left;
}

.state-table th {
    position: sticky;
    top: 0;
    background: var(--bg-card);
    color: var(--text-h3);
    font-weight: 600;
}

.state-table tr.queued td { background: var(--v-gray); color: var(--v-gray-text); }
.state-table tr.finished td { background: var(--v-black); color: var(--v-black-text); }
/* the current u / v rows keep their state colour and get an outline in the same colour as the halo */
.state-table tr.cur-u td { box-shadow: inset 0 3px 0 var(--cur-u), inset 0 -3px 0 var(--cur-u); }
.state-table tr.cur-v td { box-shadow: inset 0 3px 0 var(--cur-v), inset 0 -3px 0 var(--cur-v); }
.state-table td.changed { animation: flash 0.8s; font-weight: 700; }

@keyframes flash {
    from { background: rgba(255, 196, 0, 0.45); }
}

/* --- adjacency --- */

.adj {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.78rem;
    columns: 2;
    column-gap: 1.2rem;
}

.adj div { break-inside: avoid; }
.adj .cur { color: var(--cur-u); font-weight: 700; }

.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem 1rem;
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
}

.legend .line {
    display: inline-block;
    width: 1.6em;
    height: 0;
    border-top: 4px solid var(--tree-edge);
    vertical-align: middle;
    margin-right: 0.2em;
}

.legend .line.exam { border-top: 4px dashed var(--cur-v); }
.legend .line.path { border-top-color: var(--path); }

.legend .ring-u, .legend .ring-v {
    display: inline-block;
    width: 0.9em;
    height: 0.9em;
    border-radius: 50%;
    border: 3px solid var(--cur-u);
    vertical-align: -0.1em;
    margin-right: 0.2em;
}

.legend .ring-v { border-color: var(--cur-v); }

.summary {
    margin-top: 0.8rem;
}

.summary table {
    border-collapse: collapse;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.78rem;
    margin-top: 0.4rem;
}

.summary th, .summary td {
    border: 1px solid var(--border-card);
    padding: 0.2rem 0.55rem;
    text-align: center;
}

.summary td.longer { color: var(--path); font-weight: 700; }

details.note {
    margin-top: 0.8rem;
    border: 1px solid var(--border-card);
    border-radius: 2px;
    padding: 0.5rem 0.9rem;
    background: var(--bg-card);
}

details.note summary {
    cursor: pointer;
    font-weight: 600;
    color: var(--text-h3);
}

details.note p, details.note .code, details.note table {
    margin-top: 0.5rem;
}

.comparison-table {
    width: 100%;
    border-collapse: collapse;
    margin: 1rem 0;
    font-size: 0.9rem;
}

.comparison-table th,
.comparison-table td {
    padding: 0.45rem 0.8rem;
    border: 1px solid var(--border-card);
    text-align: left;
}

.comparison-table th {
    background: var(--bg-svg);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    color: var(--text-h3);
}

.appendix p { margin-bottom: 0.7rem; }

[hidden] { display: none !important; }

/* --- responsive --- */

@media (max-width: 900px) {
    .ws { flex-direction: column; }
    .ws-side { width: 100%; }
    .ws.compare .ws-pair { grid-template-columns: 1fr; }
    .diff { grid-template-columns: 1fr; }
}

@media (max-width: 800px) {
    body { padding: 1rem; }
    .container { padding: 2rem 1.2rem; }
    .theme-toggle { top: 1rem; right: 1rem; }
    h1 { margin-top: 1.5rem; }
}

/* long comments wrap inside the narrow code panel instead of scrolling sideways */
.code .ln.cmt {
    white-space: pre-wrap;
    padding-left: 2.2rem;
    text-indent: -1.7rem;
}

.code .icmt { white-space: pre; }

/* ============================================================
   BFS applications
   ============================================================ */

:root {
    --water: #cfe3ee;
    --sand: #e6d3a3;
    --board-light: #f1e6cf;
    --board-dark: #c9b28c;
}

.apps { margin-top: 1rem; }

.app {
    border-top: 1px solid var(--border-section);
    padding-top: 1.2rem;
    margin-top: 1.2rem;
}

.app h3 { font-size: 1.2rem; }

.app-ws {
    display: flex;
    gap: 1.2rem;
    align-items: flex-start;
    margin-top: 0.6rem;
}

.app-main { flex: 1; min-width: 0; }

.app-side {
    width: 420px;
    flex-shrink: 0;
}

.app-note {
    margin-top: 0.6rem;
    font-size: 0.86rem;
    color: var(--text-muted);
}

.app-note ol.moves { margin: 0.3rem 0 0.4rem 1.3rem; }
.app-note ol.moves li { margin-bottom: 0.15rem; }

.app-label {
    font-size: 0.82rem;
    color: var(--text-muted);
}

.player .qpanel { margin-top: 0.5rem; }
.player .cells { max-height: 7.5rem; overflow-y: auto; }

.mini-speed {
    width: 90px;
    accent-color: var(--accent);
}

.word-in {
    width: 5.5em;
    padding: 0.3rem 0.5rem;
    border: 1px solid var(--border-input);
    border-radius: 2px;
    background: var(--bg-card);
    color: var(--text-primary);
    font: 600 0.9rem 'JetBrains Mono', monospace;
    text-transform: uppercase;
}

/* word ladder layers */
.word-view {
    background: var(--bg-svg);
    border: 1px solid var(--border-card);
    border-radius: 2px;
    padding: 0.6rem 0.8rem;
    min-height: 12rem;
    max-height: 26rem;
    overflow-y: auto;
}

.layer {
    display: flex;
    gap: 0.6rem;
    align-items: flex-start;
    padding: 0.3rem 0;
    border-bottom: 1px dashed var(--border-card);
}

.layer-d {
    font: 600 0.75rem 'JetBrains Mono', monospace;
    color: var(--text-subtle);
    min-width: 3.4rem;
    padding-top: 0.25rem;
}

.chips { display: flex; flex-wrap: wrap; gap: 0.25rem; }

.chip {
    font: 600 0.74rem 'JetBrains Mono', monospace;
    padding: 0.15rem 0.4rem;
    border-radius: 2px;
    border: 1.5px solid var(--v-stroke);
}

.chip.queued { background: var(--v-gray); color: var(--v-gray-text); }
.chip.finished { background: var(--v-black); color: var(--v-black-text); }
.chip.cur { box-shadow: 0 0 0 3px var(--cur-u); }
.chip.target { border-style: dashed; }
.chip.path { box-shadow: 0 0 0 3px var(--path); }

/* knight board */
.board { max-width: 600px; }
.sq rect { stroke: none; }
.sq.light rect { fill: var(--board-light); }
.sq.dark rect { fill: var(--board-dark); }
.sq { cursor: pointer; }
.sq circle { stroke: var(--v-stroke); stroke-width: 1.5; }
.sq.queued circle { fill: var(--v-gray); }
.sq.finished circle { fill: var(--v-black); }
.sq.cur circle { stroke: var(--cur-u); stroke-width: 4; }

.sq text.knight { font-size: 19px; }
.sq.on-path circle { stroke: var(--path); stroke-width: 4; }

.sq text, .gcell text {
    font: 600 13px 'JetBrains Mono', monospace;
    text-anchor: middle;
    dominant-baseline: central;
    pointer-events: none;
}

.sq.queued text { fill: var(--v-gray-text); }
.sq.finished text { fill: var(--v-black-text); }

.coord {
    font: 600 11px 'JetBrains Mono', monospace;
    fill: var(--text-subtle);
    text-anchor: middle;
    dominant-baseline: central;
}

.jump { stroke: var(--cur-v); stroke-width: 2.5; stroke-dasharray: 5 4; pointer-events: none; }
.kpath { fill: none; stroke: var(--path); stroke-width: 3; stroke-linejoin: round; pointer-events: none; }
.target-ring { fill: none; stroke: var(--path); stroke-width: 3; stroke-dasharray: 6 4; pointer-events: none; }


/* state graph boxes */
.vertex.state text.name { font-size: 13px; }
.vertex.state .halo { stroke-width: 4; }
.vertex.state { cursor: default; }

/* grid cells (islands, multi-source) */
.grid-svg { max-height: none; }
.gcell { cursor: pointer; }
.gcell rect { stroke: transparent; stroke-width: 2.5; }
.gcell.queued rect { stroke: var(--v-gray); stroke-dasharray: 4 3; }
.gcell.cur rect { stroke: var(--cur-u); stroke-width: 4; stroke-dasharray: none; }
.gcell text { fill: var(--text-primary); }
.gcell.land.finished text, .gcell.land.queued text { fill: #ffffff; }
.gcell.src rect { stroke: var(--text-primary); stroke-width: 2.5; }
.gcell.src text { fill: #ffffff; font-size: 15px; }

/* friends */
.vertex.person text.name { font-size: 13px; }
.vertex.suggest .halo { stroke: var(--accent); opacity: 1; stroke-dasharray: 5 3; }

@media (max-width: 900px) {
    .app-ws { flex-direction: column; }
    .app-side { width: 100%; }
}
.sq:not([data-v]) { pointer-events: none; }

.vertex.person text.name { font-size: 18px; }

.notes { padding-left: 1.2em; }
.notes li { list-style: disc; margin-bottom: 0.6em; }

/* --- the BFS tree view of the main graph --- */
.vertex.placeholder .body { fill: var(--bg-svg); stroke-dasharray: 4 4; stroke-opacity: 0.45; }
.vertex.placeholder text.name { fill: var(--text-subtle); opacity: 0.6; }
.edge.ghost { stroke-dasharray: 4 5; opacity: 0.45; }
.edge.other { stroke-dasharray: 6 5; opacity: 0.45; }
.ring-label.tree-row { font-size: 15px; }
.tree-note { margin: 0.5rem 0 0; font-size: 0.88rem; color: var(--text-muted); }
.queue-panel { margin-top: 0.6rem; }
.input-code > div { padding: 0 0.8rem; border-left: 3px solid transparent; }
.input-code > div.cur { background: var(--code-hl); border-left-color: var(--cur-u); color: inherit; font-weight: 400; }
.input-code > div.plain { white-space: normal; font-family: 'Inter', sans-serif; }

.prev-arrow {
    font: 700 13px 'Inter', sans-serif;
    fill: var(--v-black-text);
    opacity: 0.9;
    text-anchor: middle;
    dominant-baseline: central;
    pointer-events: none;
}
#bfs-view .legend > span { white-space: nowrap; }
.code-note { margin: 0.6rem 0 0; font-size: 0.85rem; line-height: 1.5; color: var(--text-muted); }

/* --- "Step through it", BFS mode: code | graph, then the step line, variables, input --- */
.bfs-grid {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(0, 3fr);
    grid-template-areas:
        "means vals"
        "code graph"
        "step step";
    gap: 0.9rem 1.2rem;
    align-items: stretch;
}
.bfs-grid[hidden] { display: none; }
.bfs-grid .code-panel { grid-area: code; display: flex; flex-direction: column; }
.bfs-grid .code-panel .code { flex: 1; }
.bfs-grid .graph-panel { grid-area: graph; }
.bfs-grid .step-line { grid-area: step; }
/* the step buttons sit right under the graph box */
.bfs-grid .step-line { grid-column: 2; justify-content: center; }
@media (max-width: 900px) { .bfs-grid .step-line { grid-column: 1; justify-content: flex-start; } }
.bfs-grid .means-panel { grid-area: means; }
.bfs-grid .vals-panel { grid-area: vals; }
.graph-panel .legend { margin: 0.4rem 0 0.5rem; }
.queue-panel .panel-title { margin-bottom: 0.3rem; }

.step-line { display: flex; align-items: flex-start; gap: 1.2rem; }
.step-text { flex: 1; min-width: 0; }
.step-text .explain { margin: 0; }
.step-ctl { flex-shrink: 0; display: flex; flex-direction: column; align-items: flex-end; gap: 0.25rem; }
.step-ctl .step-row { margin: 0; }
.step-ctl .kbd-hint { margin: 0; font-size: 0.7rem; text-align: right; max-width: 30rem; }

.vars { font-family: 'JetBrains Mono', monospace; font-variant-ligatures: none; font-size: 0.85rem; }
.step-text .vars { display: flex; flex-wrap: wrap; gap: 0.3rem 1.6rem; margin-bottom: 0.35rem; }
.var { padding: 0.1rem 0.35rem; border-radius: 2px; }
.var b { color: var(--case2); }
.var.changed { background: rgba(255, 196, 0, 0.35); font-weight: 700; animation: flash 0.8s; }

@media (max-width: 900px) {
    .bfs-grid {
        grid-template-columns: minmax(0, 1fr);
        grid-template-areas: "vals" "graph" "means" "code" "step";
    }
    .step-line { flex-direction: column; }
    .step-ctl { align-items: flex-start; }
    .step-ctl .kbd-hint { text-align: left; }
}

/* --- one box: graph, legend and queue lane --- */
.graph-panel { position: relative; background: var(--bg-svg); }
.graph-panel .graph-svg { border: none; box-shadow: none; }
.lane-title { font: 600 0.72rem 'Inter', sans-serif; color: var(--text-subtle); margin-bottom: 0.3rem; text-transform: uppercase; letter-spacing: 0.05em; }
.lane-title code { text-transform: none; }
.graph-panel .qbody { background: var(--bg-card); }
.qcell.incoming, .hcell.incoming { visibility: hidden; }
.fly-token {
    position: absolute;
    left: 0;
    top: 0;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    z-index: 5;
    font: 700 1rem 'JetBrains Mono', monospace;
    border: 2px solid var(--cur-v);
    background: var(--v-gray);
    color: var(--v-gray-text);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.18);
}
.fly-token.leave-q {
    width: 38px;
    height: 38px;
    border-radius: 3px;
    border-color: var(--cur-u);
    background: var(--v-black);
    color: var(--v-black-text);
}
.vertex.pulse .halo { animation: vpulse 0.6s ease-out; }
@keyframes vpulse { 0% { stroke-width: 12; opacity: 0.2; } 100% { stroke-width: 4; } }

/* step line: the sentence takes the free space, the controls keep their natural width */
.step-text { flex: 1 1 0; }
.step-ctl { max-width: none; }
@media (min-width: 901px) { .step-ctl .step-row { flex-wrap: nowrap; } }
.step-ctl .step-row { justify-content: flex-end; padding-right: 2px; }
@media (max-width: 900px) {
    .step-text { flex: none; width: 100%; }
    .step-ctl { max-width: none; }
    .step-ctl .step-row { justify-content: flex-start; }
}

/* --- s / u / v pointer tags on the graph --- */
.ptr { pointer-events: none; }
.ptr line { stroke-width: 2; }
.ptr rect { stroke-width: 1.5; }
.ptr text { font: 700 18px 'JetBrains Mono', monospace; text-anchor: middle; dominant-baseline: central; }
.ptr-s line, .ptr-s rect { stroke: var(--tag-s); }
.ptr-s rect { fill: var(--bg-card); }
.ptr-s text { fill: var(--tag-s); }
.ptr-u line { stroke: var(--cur-u); }
.ptr-u rect { fill: var(--cur-u); stroke: var(--cur-u); }
.ptr-v line { stroke: var(--cur-v); }
.ptr-v rect { fill: var(--cur-v); stroke: var(--cur-v); }
.ptr-u text, .ptr-v text { fill: #fff; }

/* --- prev arrows and vertex tooltip --- */
.prev-head { fill: var(--tree-edge); stroke: none; pointer-events: none; }

/* input panel: g and s with short comments, then what u and v mean */
.input-code .icmt { white-space: pre; }
.input-code .cmt-line { color: var(--text-subtle); font-style: italic; }
/* small panels above the code (what each variable means) and above the graph (g and s); never scroll */
.means-panel, .vals-panel { padding: 0.5rem 0.9rem; overflow: visible; }
.bfs-grid .means-panel { align-self: start; }
.bfs-grid { row-gap: 0.7rem; }
.var-means { display: flex; flex-direction: column; }
.mean { display: grid; grid-template-columns: 2.6rem minmax(0, 1fr); font-size: 0.8rem; line-height: 1.4; }
.mean b { font: 700 0.82rem 'JetBrains Mono', monospace; color: var(--case2); }
.mean span { color: var(--text-primary); }
.var-values {
    font: 0.8rem/1.5 'JetBrains Mono', monospace;
    font-variant-ligatures: none;
    color: var(--text-primary);
    min-width: 0;
}
.var-values > div { white-space: pre-wrap; overflow-wrap: anywhere; }
.var-values .val-note { font-family: 'Inter', sans-serif; color: var(--text-muted); white-space: normal; }

/* BFS mode: narrower code column, so the code is a little smaller and the graph can grow */
.bfs-grid .code-panel .code { font-size: 0.72rem; }
.bfs-grid .graph-svg { max-height: 70vh; }
.mean { white-space: nowrap; }
@media (max-width: 1100px) { .mean { white-space: normal; } }


@media (min-width: 801px) and (max-width: 1400px) { body { padding-left: 24px; padding-right: 24px; } .container { padding-left: 2rem; padding-right: 2rem; } }

/* inline values after each executed line, like a debugger */
.code .ival { color: var(--text-subtle); white-space: pre; }
.code .ival.changed { color: var(--cur-v); font-weight: 700; }

/* vertex: name on top, distance below, inside the circle; sized close to the code font */
.vertex text.name.in { font-size: 16px; }
.vertex text.dist-in {
    font: 600 11px 'JetBrains Mono', monospace;
    font-variant-ligatures: none;
    text-anchor: middle;
    dominant-baseline: central;
    pointer-events: none;
    opacity: 0.9;
}
.vertex.unfound text.dist-in, .vertex.placeholder text.dist-in { fill: var(--v-white-text); }
.vertex.queued text.dist-in { fill: var(--v-gray-text); }
.vertex.finished text.dist-in { fill: var(--v-black-text); }
.vertex.placeholder text.dist-in { opacity: 0.5; }
.vertex.cell text.dist-in { display: none; }

/* queue and stack cells are circles, drawn like the found vertices */
.qcell.circle {
    width: 2.9rem;
    min-width: 2.9rem;
    height: 2.9rem;
    padding: 0;
    border-radius: 50%;
    border: 2px solid var(--v-stroke);
}
.qcell.circle b { font-size: 0.85rem; line-height: 1; }
.qcell.circle small { font-size: 0.55rem; margin-top: 1px; }
.cells.lane { gap: 0.45rem; }
.qcell.circle.added { box-shadow: 0 0 0 3px var(--cur-v); }
.fly-token.join { flex-direction: column; width: 2.9rem; height: 2.9rem; font-size: 0.85rem; line-height: 1; }
.fly-token.join small { font-size: 0.55rem; font-weight: 600; margin-top: 1px; }

/* the variables that have pointer tags on the graph use the tag colours */
.mean b.vn-s { color: var(--tag-s); }
.mean b.vn-u { color: var(--cur-u); }
.mean b.vn-v { color: var(--cur-v); }

/* input: the entry g[u] for the current u, and the neighbour v being checked */
.g-entry.cur { background: var(--code-hl); box-shadow: inset 3px 0 0 var(--cur-u); padding: 0 0.15rem 0 0.25rem; margin: 0 -0.15rem 0 -0.25rem; border-radius: 2px; }
.g-nb.cur { color: var(--cur-v); font-weight: 700; }
.var-values .val-muted { color: var(--text-subtle); font-family: 'Inter', sans-serif; font-size: 0.75rem; }
