/* huffman-trees: SICP 2.3.4 Huffman-encoding-trees trace explorer. Reuses
   the site's :root tokens (--bg, --bg-content, --text, --text-secondary,
   --accent, --accent-light, --border, --code-bg) from style.css. The site
   has no dark mode -- this file does not invent one. */

#tool-root { font-size: 15px; }
#tool-root button, #tool-root input, #tool-root select { font: inherit; }

.ht-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    margin: 1rem 0;
    padding: 1rem 0;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}
.ht-field { margin-bottom: 12px; }
.ht-field label { display: block; font-weight: 600; margin-bottom: 6px; }
.ht-tin { width: 100%; font-family: monospace; font-size: 14px; padding: 6px 9px; border: 1px solid var(--border); border-radius: 4px; background: var(--bg-content); color: var(--text); }
.ht-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.ht-chip { display: inline-flex; align-items: baseline; gap: 6px; border: 1px solid var(--border); border-radius: 4px; padding: 2px 8px; background: var(--bg-content); font: 13px monospace; }
.ht-chip b { font-weight: 600; }
.ht-scrub { color: var(--accent); border-bottom: 1.5px dotted var(--accent); cursor: ew-resize; user-select: none; touch-action: none; min-width: 2ch; text-align: right; display: inline-block; }
.ht-presets { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.ht-preset, .ht-smallbtn { border: 1px solid var(--border); background: transparent; border-radius: 14px; padding: 2px 10px; font-size: 13px; cursor: pointer; }
.ht-preset:hover, .ht-smallbtn:hover { border-color: var(--accent); }
.ht-hint { color: var(--text-secondary); font-size: 13px; margin-top: 6px; }
.ht-err { color: #c2413b; font-size: 13px; margin-top: 6px; }
.ht-err[hidden] { display: none; }

.ht-seg { display: inline-flex; border: 1px solid var(--border); border-radius: 5px; overflow: hidden; background: var(--bg-content); }
.ht-seg label { position: relative; }
.ht-seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.ht-seg span { display: block; padding: 5px 12px; font-size: 13.5px; border-right: 1px solid var(--border); cursor: pointer; }
.ht-seg label:last-child span { border-right: 0; }
.ht-seg input:checked + span { background: var(--accent); color: #fff; }
.ht-opt { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 14px; margin-top: 10px; }
.ht-opt > span:first-child { min-width: 6.5em; color: var(--text-secondary); }

.ht-result { padding: 0.5rem 0; }
.ht-answer { font-size: 20px; line-height: 1.4; }
.ht-answer code { font: 600 17px monospace; }
.ht-compare { color: var(--text-secondary); margin-top: 6px; }
table.ht-cost { border-collapse: collapse; margin-top: 12px; font-size: 13.5px; }
table.ht-cost th { font-weight: 600; color: var(--text-secondary); text-align: right; padding: 4px 12px; border-bottom: 1px solid var(--border); }
table.ht-cost th:first-child, table.ht-cost td:first-child { text-align: left; }
table.ht-cost td { padding: 4px 12px; text-align: right; font-family: monospace; font-size: 13px; border-bottom: 1px solid var(--border); }
table.ht-cost tr.ht-sel td { background: var(--accent-light); }
table.ht-cost tr.ht-bound td { color: var(--text-secondary); }

.ht-transport { position: sticky; top: 0; z-index: 2; background: var(--bg); padding: 10px 0; border-bottom: 1px solid var(--border); margin-top: 14px; }
.ht-tbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.ht-tbar button { min-width: 34px; height: 30px; border: 1px solid var(--border); background: var(--bg-content); border-radius: 4px; cursor: pointer; padding: 0 8px; }
.ht-tbar button:hover { border-color: var(--accent); }
.ht-tbar .ht-play { min-width: 60px; background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.ht-tbar .ht-txt { font-size: 13px; }
#ht-step-range { flex: 1; min-width: 160px; accent-color: var(--accent); }
.ht-steplabel { font: 13px monospace; color: var(--text-secondary); min-width: 13ch; text-align: right; }
.ht-speed { font-size: 13px; color: var(--text-secondary); display: inline-flex; align-items: center; gap: 6px; }
#ht-strip { display: block; width: 100%; height: 48px; margin-top: 10px; cursor: crosshair; border-radius: 3px; }
.ht-caption { color: var(--text-secondary); font-size: 13px; margin-top: 4px; }

.ht-work { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 16px; margin-top: 16px; }
.ht-panel { background: var(--bg-content); border: 1px solid var(--border); border-radius: 6px; padding: 14px 16px; min-width: 0; }
.ht-panel h2 { font-size: 14px; margin: 0 0 10px; }
.ht-side { display: grid; gap: 16px; align-content: start; min-width: 0; }
.ht-forest { overflow: auto; max-height: 460px; border-top: 1px solid var(--border); margin: 8px -16px 0; padding-top: 8px; }
.ht-forest svg { display: block; }
.ht-forest .e { stroke: var(--border); stroke-width: 1.5; }
.ht-forest .e.path { stroke: var(--accent); stroke-width: 3; }
.ht-forest .el { font: 10.5px monospace; fill: var(--text-secondary); text-anchor: middle; }
.ht-forest .el.path { fill: var(--accent); font-weight: 600; }
.ht-forest .n circle { fill: var(--bg-content); stroke: var(--text-secondary); stroke-width: 1.5; }
.ht-forest .n.leaf circle { fill: var(--accent-light); stroke: var(--accent-light); }
.ht-forest .n text.s { font: 600 12px monospace; text-anchor: middle; fill: var(--text); }
.ht-forest .n text.w { font: 10.5px monospace; text-anchor: middle; fill: var(--text-secondary); }
.ht-forest .n.path circle { stroke: var(--accent); stroke-width: 2.5; }
.ht-forest .n.cur circle { stroke: var(--accent); stroke-width: 4; }
.ht-forest .n.new circle { stroke: #c27d0e; stroke-width: 3.5; }
.ht-forest .n.hit circle { stroke: #178577; stroke-width: 3.5; }
.ht-forest .tag { font: 600 11.5px sans-serif; fill: #c27d0e; text-anchor: middle; }
.ht-wl { display: flex; flex-wrap: wrap; gap: 4px 0; align-items: center; font: 12.5px monospace; margin-top: 10px; }
.ht-wl .ht-cell { padding: 3px 7px; border: 1.5px solid var(--border); border-radius: 3px; }
.ht-wl .ht-cell i { font-style: normal; color: var(--text-secondary); margin-left: 6px; }
.ht-wl .ht-cell.cur { border-color: var(--accent); background: var(--accent-light); }
.ht-wl .ht-cell.new { border-color: #c27d0e; }
.ht-wl .ht-arrow { color: var(--border); padding: 0 3px; }

.ht-code { font: 12.5px/1.65 monospace; margin: 0; background: var(--code-bg); padding: 8px; border-radius: 4px; overflow-x: auto; }
.ht-code .ht-ln { display: block; padding: 0 6px; border-left: 3px solid transparent; white-space: pre; }
.ht-code .ht-ln.ht-hl { background: var(--accent-light); border-left-color: var(--accent); }
.ht-event { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border); min-height: 4.5em; font-size: 13.5px; }
.ht-phase { font-size: 13px; color: var(--text-secondary); margin-top: 6px; }

.ht-bottom { display: grid; grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr); gap: 16px; margin-top: 16px; }
table.ht-codes { border-collapse: collapse; width: 100%; font-size: 13px; }
table.ht-codes th { font-weight: 600; color: var(--text-secondary); text-align: right; padding: 3px 8px; border-bottom: 1px solid var(--border); }
table.ht-codes th:first-child, table.ht-codes td:first-child, table.ht-codes td.ht-codecol { text-align: left; }
table.ht-codes td { padding: 3px 8px; text-align: right; font-family: monospace; border-bottom: 1px solid var(--border); }
table.ht-codes tr.cur td { background: var(--accent-light); }
.ht-stream { font: 14px/1.9 monospace; overflow-wrap: anywhere; }
.ht-stream span { padding: 1px 1px; border-radius: 2px; }
.ht-stream .ht-done { color: var(--text); }
.ht-stream .ht-todo { color: var(--border); }
.ht-stream .ht-cur { background: var(--accent-light); box-shadow: 0 0 0 1.5px var(--accent); }
.ht-stream .ht-errc { background: #c2413b; color: #fff; }
.ht-stream .ht-sep { color: var(--border); }
.ht-streamblock { margin-top: 12px; }

@media (max-width: 920px) {
    .ht-controls, .ht-work, .ht-bottom { grid-template-columns: 1fr; }
}
