/* ========================================= */
/* === Sökning i rutnät (/graphs)        === */
/* ========================================= */

.graphs-container {
    max-width: 1000px;
}

/* Rutstorleken anpassas efter skärmen: 41 kolumner ska få plats. */
.grid {
    --cols: 41;
    --cell: min(22px, calc((100vw - 90px) / var(--cols)));
    display: grid;
    grid-template-columns: repeat(var(--cols), var(--cell));
    grid-auto-rows: var(--cell);
    gap: 1px;
    background: var(--border);
    border: 1px solid var(--border);
    width: max-content;
    margin: 16px auto;
    user-select: none;
    touch-action: none; /* rita med fingret utan att sidan scrollar */
}

.cell {
    background: var(--card-bg);
    transition: background-color 0.15s ease;
}

.cell.wall { background: #2f3640; }
.cell.mud { background: #a0784c; }
.cell.visited { background: #9fd3f5; animation: pop 0.25s ease; }
.cell.mud.visited { background: #7aa7c4; }
.cell.path { background: #ffd43b; animation: pop 0.3s ease; }
.cell.start { background: #2b9348; cursor: grab; }
.cell.goal { background: #d62828; cursor: grab; }

@keyframes pop {
    from { transform: scale(0.6); }
    to { transform: scale(1); }
}

.graph-controls,
.graph-actions,
.draw-modes {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 16px;
}

.graph-controls { margin: 12px 0; }
.graph-actions { margin: 8px 0 12px; gap: 8px; }
.draw-modes { gap: 6px; }

.graph-controls label { display: flex; align-items: center; gap: 6px; }

.graph-actions button,
.mode-btn {
    padding: 7px 12px;
    border: 1px solid var(--border);
    border-radius: 5px;
    background: var(--secondary-bg);
    color: var(--text);
    cursor: pointer;
    font-weight: bold;
}

.graph-actions button:hover,
.mode-btn:hover { border-color: var(--accent); }

.graph-actions button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.graph-actions button:disabled { opacity: 0.5; cursor: wait; }

.mode-btn.active { background: #2f3640; border-color: #2f3640; color: #fff; }
.mode-btn[data-mode="mud"].active { background: #a0784c; border-color: #a0784c; }
.mode-btn[data-mode="erase"].active { background: #6c757d; border-color: #6c757d; }

.algorithm-info { color: var(--text-muted); min-height: 2.6em; margin: 4px 0; }

.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 16px;
    list-style: none;
    padding: 0;
    margin: 0;
    font-size: 0.9rem;
}

.legend li { display: flex; align-items: center; gap: 6px; }
.swatch { width: 14px; height: 14px; border-radius: 3px; border: 1px solid var(--border); }
.swatch.start { background: #2b9348; }
.swatch.goal { background: #d62828; }
.swatch.wall { background: #2f3640; }
.swatch.mud { background: #a0784c; }
.swatch.visited { background: #9fd3f5; }
.swatch.path { background: #ffd43b; }

.graph-message { min-height: 1.4em; text-align: center; font-weight: bold; color: var(--error); }

.graph-stats {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px 32px;
    margin: 8px 0 0;
}

.graph-stats div { text-align: center; }
.graph-stats dt { font-size: 0.85rem; color: var(--text-muted); }
.graph-stats dd { margin: 2px 0 0; font-size: 1.4rem; font-weight: bold; }

.compare-result { margin-top: 16px; }
.compare-result .hint { color: var(--text-muted); font-size: 0.9rem; }
.compare-result table { width: 100%; border-collapse: collapse; }
.compare-result th,
.compare-result td { padding: 6px 10px; border-bottom: 1px solid var(--border); text-align: right; }
.compare-result th:first-child,
.compare-result td:first-child { text-align: left; }
.compare-result tr.best td { font-weight: bold; color: #2b9348; }

/* Mörkt läge: väggarna ljusa i stället för mörka, så att de syns mot den mörka bakgrunden */
:root.dark .cell.wall,
:root.dark .swatch.wall { background: #94a3b8; }
:root.dark .mode-btn.active { background: #94a3b8; border-color: #94a3b8; color: #0f172a; }

/* Labyrinter: väljaren bredvid knappen, och rutan som grävs just nu */
.maze-pick {
    display: inline-flex;
    gap: 4px;
    align-items: center;
}

.maze-pick select {
    width: auto;
    padding: 6px;
}

.cell.maze-head {
    background: #d63384 !important;
}

/* === Minsta uppspännande träd === */
.mst-svg {
    display: block;
    width: 100%;
    margin-top: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-2);
}

.mst-edge {
    stroke: var(--text-muted);
    stroke-width: 2;
    opacity: 0.45;
}

.mst-edge.taken {
    stroke: #4caf50;
    stroke-width: 6;
    opacity: 1;
}

.mst-edge.skipped {
    stroke: #b02a37;
    stroke-dasharray: 6 6;
    opacity: 0.35;
}

.mst-edge.current {
    stroke: #ffc107;
    stroke-width: 7;
    opacity: 1;
}

.mst-weight {
    fill: var(--text-muted);
    font: 15px Consolas, Menlo, monospace;
    text-anchor: middle;
}

.mst-weight.taken {
    fill: var(--text);
    font-weight: bold;
}

.mst-weight.skipped {
    opacity: 0.45;
    text-decoration: line-through;
}

.mst-node {
    stroke: var(--card-bg);
    stroke-width: 3;
}

.mst-edges {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 0;
    margin: 6px 0 0;
    list-style: none;
}

.mst-edges li {
    min-width: 28px;
    padding: 2px 6px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--card-bg);
    font-family: Consolas, Menlo, monospace;
    text-align: center;
}

.mst-edges li.taken { background: #4caf50; border-color: #4caf50; color: #fff; }
.mst-edges li.skipped { color: var(--text-muted); text-decoration: line-through; }
.mst-edges li.current { box-shadow: 0 0 0 2px #ffc107; }
