.app-layout {
    flex: 1 1 auto;
    display: flex;
    min-height: 0;
}
#editor-column {
    flex: 0 0 420px;
    min-width: 300px;
    max-width: 55%;
    overflow-y: auto;
    padding: 20px 12px 40px 24px;
}
#display-column {
    flex: 1 1 auto;
    min-width: 300px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 20px 24px;
    overflow-y: auto;
}
@media (max-width: 900px) {
    .app-layout { flex-direction: column; }
    #editor-column, #display-column { flex: 1 1 auto; max-width: 100%; padding: 16px; }
}

/* Segmented control (shared look across the site) */
.segmented { display: flex; border: 1px solid var(--border-strong); border-radius: 8px; overflow: hidden; min-width: 0; }
.segmented button {
    flex: 1;
    min-width: 0;
    padding: 7px 6px;
    border: none;
    background: var(--surface);
    font: inherit;
    font-size: 12.5px;
    cursor: pointer;
    border-right: 1px solid var(--border-strong);
    color: var(--text);
}
.segmented button:last-child { border-right: none; }
.segmented button.active { background: var(--primary); color: #fff; }

/* Frequency table input rows */
#freq-rows { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.freq-row { display: flex; align-items: center; gap: 8px; }
.freq-row input[type="text"] { width: 56px; text-align: center; flex: none; }
.freq-row input[type="number"] { flex: 1 1 auto; min-width: 0; }
.freq-row button { border: none; background: transparent; cursor: pointer; color: var(--muted); font-size: 14px; flex: none; }
.freq-row button:hover { color: var(--danger); }

/* Results: code table */
#codes-table table, #shannon-table { width: 100%; border-collapse: collapse; font-size: 13px; }
#codes-table th, #codes-table td, #shannon-table th, #shannon-table td {
    padding: 6px 8px;
    border-bottom: 1px solid var(--border);
    text-align: left;
}
#codes-table th, #shannon-table th { color: var(--muted); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.02em; }
#codes-table td.mono, #shannon-table td.mono { font-family: ui-monospace, monospace; }
#codes-table tr.active-row, #shannon-table tr.active-row { background: color-mix(in srgb, var(--primary) 10%, transparent); }

.stat-row { display: flex; justify-content: space-between; padding: 6px 0; font-size: 13px; border-bottom: 1px solid var(--border); }
.stat-row:last-child { border-bottom: none; }
.stat-row .stat-value { font-weight: 700; }
.stat-row .stat-value.good { color: var(--success); }
.stat-row .stat-value.bad { color: var(--danger); }
.prefix-check { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-size: 12.5px; padding: 8px 10px; border-radius: 8px; }
.prefix-check.ok { background: color-mix(in srgb, var(--success) 12%, transparent); color: var(--success); }
.prefix-check.bad { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }

/* Step nav */
#step-nav { text-align: center; max-width: 640px; }
#step-position { font-weight: 700; font-size: 14px; }
#step-description { margin: 4px 0 0 0; min-height: 20px; }

/* Tree stage */
#tree-stage { width: 100%; max-width: 820px; flex: 1 1 auto; min-height: 280px; display: flex; align-items: center; justify-content: center; }
#tree-svg { width: 100%; height: 100%; max-height: 56vh; }
.tree-edge { stroke: var(--border-strong); stroke-width: 2; transition: opacity 0.3s; }
.tree-edge-new { stroke: var(--primary); animation: edgeFadeIn 0.5s ease-out; }
.tree-edge-label-bg { fill: var(--bg); }
.tree-edge-label { font-size: 11px; text-anchor: middle; dominant-baseline: middle; fill: var(--muted); font-weight: 600; }
.tree-node circle { fill: var(--surface); stroke: var(--border-strong); stroke-width: 2; }
.tree-node-leaf circle { fill: var(--surface-2); stroke: var(--primary); }
.tree-node-new circle { animation: nodePopIn 0.4s ease-out; }
.tree-node-active circle { stroke: var(--success); stroke-width: 3; }
.tree-node-text { text-anchor: middle; dominant-baseline: middle; font-size: 13px; font-weight: 700; fill: var(--text); }
.tree-node-leaf .tree-node-text { font-size: 15px; }
.tree-node-freq { text-anchor: middle; font-size: 10px; fill: var(--muted); }
.tree-node-code-bg { fill: color-mix(in srgb, var(--primary) 12%, var(--surface)); animation: codeChipIn 0.4s ease-out; }
.tree-node-code { text-anchor: middle; dominant-baseline: middle; font-family: ui-monospace, monospace; font-size: 11px; font-weight: 700; fill: var(--primary-dark); animation: codeChipIn 0.4s ease-out; }
@keyframes codeChipIn { 0% { opacity: 0; transform: translateY(-3px); } 100% { opacity: 1; transform: translateY(0); } }
@keyframes nodePopIn { 0% { transform: scale(0.4); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
.tree-node-new circle { transform-box: fill-box; transform-origin: center; }
@keyframes edgeFadeIn { 0% { opacity: 0; } 100% { opacity: 1; } }

/* Shannon method: formulas legend + live per-step calculation + table + number line */
#shannon-stage { width: 100%; max-width: 820px; display: flex; flex-direction: column; gap: 16px; }

#shannon-formulas {
    display: flex;
    flex-direction: column;
    gap: 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r);
    padding: 12px 16px;
    font-size: 12.5px;
}
.formula-row { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.formula-name { font-family: ui-monospace, monospace; font-weight: 700; color: var(--primary-dark); min-width: 28px; }
.formula-eq { font-family: ui-monospace, monospace; font-weight: 600; }
.formula-hint { color: var(--muted); font-size: 11.5px; }

#shannon-calc {
    background: color-mix(in srgb, var(--primary) 6%, var(--surface));
    border: 1px solid color-mix(in srgb, var(--primary) 25%, var(--border));
    border-radius: var(--r);
    padding: 12px 16px;
    font-family: ui-monospace, monospace;
    font-size: 13px;
    line-height: 1.9;
    min-height: 20px;
}
#shannon-calc .calc-line b { color: var(--primary-dark); }

#shannon-table-wrap { max-height: 40vh; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--r); }
#shannon-table { margin: 0; }
#shannon-table thead th { position: sticky; top: 0; background: var(--surface); }
#shannon-numberline .nl-axis { stroke: var(--border-strong); stroke-width: 2; }
#shannon-numberline .nl-tick { stroke: var(--border-strong); stroke-width: 1; }
#shannon-numberline .nl-tick-label { font-size: 10px; fill: var(--muted); text-anchor: middle; }
#shannon-numberline .nl-segment { stroke-width: 10; }
#shannon-numberline .nl-segment.active { stroke: var(--primary); }
#shannon-numberline .nl-segment-label { font-size: 11px; text-anchor: middle; fill: var(--text); font-weight: 600; }
#shannon-numberline .nl-marker { stroke: var(--success); stroke-width: 2; }

#step-controls { display: flex; align-items: center; justify-content: center; gap: 8px; flex-wrap: wrap; }

#empty-hint { text-align: center; }
