@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;
}

[data-theme="dark"] {
    --bg-outer: #1a1a1a;
    --bg-page: #252220;
    --bg-card: #2d2a27;
    --bg-svg: #2a2725;
    --bg-insight: #302b24;
    --bg-active: #3a3228;

    --text-primary: #e0d5c4;
    --text-heading: #f0e8dc;
    --text-h2: #e8dfd0;
    --text-h3: #d4c5a9;
    --text-muted: #a89880;
    --text-subtle: #9a8b74;
    --text-insight: #c4b99a;

    --border-main: #3d3530;
    --border-section: #4a4038;
    --border-card: #4a4038;
    --border-input: #5a4e42;

    --accent: #c4a882;
    --accent-hover: #d4b892;
    --accent-border: #8b6f47;
    --accent-green: #7aa87c;
    --accent-green-hover: #8dba8f;

    --case1: #e07030;
    --case2: #b080e0;
    --case3: #60b060;

    --red-node: #e05050;
    --black-node: #f0e8dc;

    --btn-disabled-bg: #3d3530;
    --btn-disabled-text: #6b5b47;

    --shadow-page: 0 1px 3px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.4);
    --shadow-inset: inset 0 0 80px rgba(0, 0, 0, 0.1);
    --shadow-card-active: 0 2px 8px rgba(196, 168, 130, 0.15);
    --shadow-suggestion: 0 2px 6px rgba(196, 168, 130, 0.1);

    --lines-color: rgba(255, 255, 255, 0.015);
    --gradient1: rgba(255, 255, 255, 0.02);
    --gradient2: rgba(255, 255, 255, 0.01);

    --toggle-bg: #4a4038;
    --toggle-knob: #c4a882;
}

[data-theme="hacker"] {
    --bg-outer: #000000;
    --bg-page: #0a0a0a;
    --bg-card: #111111;
    --bg-svg: #0d0d0d;
    --bg-insight: #0a1a0a;
    --bg-active: #0a200a;

    --text-primary: #33ff33;
    --text-heading: #44ff44;
    --text-h2: #33ee33;
    --text-h3: #22cc22;
    --text-muted: #1a991a;
    --text-subtle: #158015;
    --text-insight: #22aa22;

    --border-main: #1a331a;
    --border-section: #1a3a1a;
    --border-card: #1a331a;
    --border-input: #2a552a;

    --accent: #33ff33;
    --accent-hover: #66ff66;
    --accent-border: #1a661a;
    --accent-green: #33ff33;
    --accent-green-hover: #66ff66;

    --case1: #ff6633;
    --case2: #cc66ff;
    --case3: #33ff99;

    --red-node: #ff3333;
    --black-node: #33ff33;

    --btn-disabled-bg: #1a331a;
    --btn-disabled-text: #0d4d0d;

    --shadow-page: 0 0 20px rgba(0, 255, 0, 0.05), 0 0 60px rgba(0, 255, 0, 0.02);
    --shadow-inset: inset 0 0 80px rgba(0, 255, 0, 0.02);
    --shadow-card-active: 0 0 12px rgba(51, 255, 51, 0.15);
    --shadow-suggestion: 0 0 8px rgba(51, 255, 51, 0.1);

    --lines-color: rgba(0, 255, 0, 0.02);
    --gradient1: rgba(0, 255, 0, 0.03);
    --gradient2: rgba(0, 255, 0, 0.01);

    --toggle-bg: #1a331a;
    --toggle-knob: #33ff33;
}

[data-theme="hacker"] .container {
    border-color: #1a3a1a;
    box-shadow: 0 0 30px rgba(0, 255, 0, 0.04), inset 0 0 60px rgba(0, 255, 0, 0.01);
}

* {
    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: 1100px;
    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: #5a7a5c;
    --cur-v: #a04000;
    --path: #c0392b;
    --wall: #5f5244;
    --code-bg: #fffdf8;
    --code-hl: rgba(90, 122, 92, 0.18);
    --code-hl2: rgba(160, 64, 0, 0.16);
    --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;
}

[data-theme="dark"] {
    --v-white: #e8dfd0;
    --v-white-text: #252220;
    --v-gray: #7d7368;
    --v-black: #141210;
    --v-black-text: #f0e8dc;
    --v-stroke: #c4a882;
    --edge: #5a4e42;
    --tree-edge: #c4a882;
    --cur-u: #7aa87c;
    --cur-v: #e07030;
    --path: #ff6b5b;
    --wall: #4a4038;
    --code-bg: #2a2725;
    --code-hl: rgba(122, 168, 124, 0.22);
    --code-hl2: rgba(224, 112, 48, 0.2);
    --diff-bg: rgba(196, 168, 130, 0.12);
}

[data-theme="hacker"] {
    --v-white: #0d0d0d;
    --v-white-text: #33ff33;
    --v-gray: #1a661a;
    --v-gray-text: #ccffcc;
    --v-black: #33ff33;
    --v-black-text: #000000;
    --v-stroke: #33ff33;
    --edge: #1a4d1a;
    --tree-edge: #66ff66;
    --cur-u: #33ff99;
    --cur-v: #ff6633;
    --path: #ff3333;
    --wall: #1a331a;
    --code-bg: #0d0d0d;
    --code-hl: rgba(51, 255, 51, 0.15);
    --code-hl2: rgba(255, 102, 51, 0.18);
    --diff-bg: rgba(51, 255, 51, 0.07);
}

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.white { background: var(--v-white); }
.swatch.gray { background: var(--v-gray); }
.swatch.black { 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);
}

.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.white .body { fill: var(--v-white); }
.vertex.gray .body { fill: var(--v-gray); }
.vertex.black .body { fill: var(--v-black); }

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

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

.vertex text.dist {
    font: 600 12px '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 10px '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.2rem;
    height: 2.2rem;
    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 small {
    font-size: 0.58rem;
    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: translateY(-18px); opacity: 0; }
}

.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.cur-u td { background: var(--code-hl); }
.state-table tr.cur-v td { background: var(--code-hl2); }
.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;
}

[data-theme="dark"] {
    --water: #2c3e4a;
    --sand: #6b5a3a;
    --board-light: #4a4038;
    --board-dark: #2d2a27;
}

[data-theme="hacker"] {
    --water: #0a1f2a;
    --sand: #1a331a;
    --board-light: #112211;
    --board-dark: #0a140a;
}

.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: 360px;
    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.gray { background: var(--v-gray); color: var(--v-gray-text); }
.chip.black { 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: 460px; }
.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.gray circle { fill: var(--v-gray); }
.sq.black 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.gray text { fill: var(--v-gray-text); }
.sq.black 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.gray 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.black text, .gcell.land.gray 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; }
