/* ========================================= */
/* === Dynamic programming (/dp)         === */
/* ========================================= */

.dp-container {
    max-width: 900px;
}

.ed-words {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 16px;
}

.ed-words label {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1 1 200px;
}

.ed-words input {
    flex: 1;
}

.ed-explain {
    min-height: 2.8em;
    margin: 12px 0 8px;
}

.ed-table-wrap {
    overflow-x: auto;
}

.ed-table {
    border-collapse: collapse;
    margin: 0 auto;
    font-family: Consolas, Menlo, monospace;
}

.ed-table th,
.ed-table td {
    width: 32px;
    height: 32px;
    padding: 0;
    border: 1px solid var(--border);
    text-align: center;
    transition: background-color 0.15s ease;
}

.ed-table th {
    background-color: var(--th-bg);
    color: var(--text-muted);
    font-weight: bold;
}

.ed-table td.base {
    color: var(--text-muted);
    background-color: var(--surface-2);
}

/* The cell being computed, its three neighbours, and the one it took its value from */
.ed-table td.neighbour {
    background-color: rgba(36, 113, 163, 0.16);
}

.ed-table td.chosen {
    background-color: rgba(56, 150, 220, 0.38);
    font-weight: bold;
}

.ed-table td.current {
    background-color: #ffc107;
    color: #222;
    font-weight: bold;
}

/* The way back, coloured by the change made at each step */
.ed-table td.path {
    font-weight: bold;
    box-shadow: inset 0 0 0 2px var(--text);
}

.ed-table td.path.keep { background-color: #e9ecef; color: #222; }
.ed-table td.path.substitute { background-color: #ffe08a; color: #222; }
.ed-table td.path.delete { background-color: #f5c2c7; color: #222; }
.ed-table td.path.insert { background-color: #badbcc; color: #222; }

.ed-ops {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    font-family: Consolas, Menlo, monospace;
}

.ed-op {
    padding: 3px 8px;
    border-radius: 4px;
    background-color: #e9ecef;
    color: #222;
}

.ed-op.substitute { background-color: #ffe08a; }
.ed-op.delete { background-color: #f5c2c7; }
.ed-op.insert { background-color: #badbcc; }

@media (max-width: 600px) {
    .ed-table th,
    .ed-table td {
        width: 24px;
        height: 24px;
        font-size: 0.8rem;
    }
}

/* === Optimal binary search tree (/dp#obst) === */
.obst-table th,
.obst-table td {
    width: auto;
    min-width: 44px;
    height: 40px;
    padding: 0 4px;
    font-size: 0.85rem;
}

.obst-table td span {
    display: block;
    font-weight: bold;
}

.obst-table td small {
    display: block;
    font-size: 0.7rem;
    color: var(--text-muted);
}

.obst-table td.none {
    background-color: var(--surface-2);
    border-color: transparent;
}

.obst-table td.chosen {
    background-color: rgba(56, 150, 220, 0.38);
}

.obst-table td.current,
.obst-table td.current small {
    background-color: #ffc107;
    color: #222;
}

.obst-table td.answer {
    box-shadow: inset 0 0 0 2px var(--text);
    background-color: #badbcc;
    color: #222;
}

.obst-table td.answer small {
    color: #222;
}

.obst-candidates {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    min-height: 1.6em;
    font-family: Consolas, Menlo, monospace;
    font-size: 0.85rem;
}

.obst-chip {
    padding: 2px 8px;
    border-radius: 4px;
    background-color: var(--surface-2);
    border: 1px solid var(--border);
}

.obst-chip.best {
    background-color: #ffc107;
    border-color: #d39e00;
    color: #222;
    font-weight: bold;
}

.obst-trees {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 14px;
    margin-top: 16px;
}

.obst-panel {
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background-color: var(--card-bg);
}

.obst-panel h3 {
    margin: 0;
}

.obst-cost {
    margin: 2px 0 8px;
    color: var(--text-muted);
}

.obst-svg {
    display: block;
    width: 100%;
    height: auto;
}

.obst-edge {
    stroke: var(--border);
    stroke-width: 1.5;
}

/* stroke-width is set per node: wider for words that are searched more */
.obst-node {
    fill: var(--surface-2);
    stroke: #2471a3;
}

.obst-key {
    fill: var(--text);
    font: bold 11px Consolas, Menlo, monospace;
    text-anchor: middle;
}

.obst-weight {
    fill: var(--text-muted);
    font-size: 9px;
    text-anchor: middle;
}

.obst-candidates:empty {
    min-height: 0;
    margin: 0;
}
