/* Circuit builder (experimental/circuit-builder.html; plan: docs/CIRCUIT_BUILDER_PLAN.md).
   Colours come from the site's tokens in css/style.css, so dark mode follows automatically. */
body[data-section] main.ck-main { max-width: 1400px; } /* wider than the reading width of other Experimental pages */
.ck-main > p, .ck-main > .ck-help { max-width: var(--read, 46rem); }
.ck-phone { display: none; }
@media (max-width: 699px) { .ck-phone { display: block; } }

.ck-app { margin: 16px 0; }
.ck-toolbar { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; margin-bottom: 8px; }
.ck-group { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.ck-btn { min-height: 40px; padding: 6px 12px; font: inherit; font-size: 0.95rem; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; cursor: pointer; touch-action: manipulation; }
.ck-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.ck-btn:disabled { opacity: 0.45; cursor: default; }
.ck-btn.ck-primary { background: var(--accent); color: var(--surface); border-color: var(--accent); }
.ck-btn.ck-primary:hover { color: var(--surface); }
.ck-icon-btn { min-width: 40px; font-size: 1.2rem; line-height: 1; }
.ck-check { display: inline-flex; align-items: center; gap: 6px; font-size: 0.92rem; min-height: 32px; cursor: pointer; }
.ck-check input { width: 18px; height: 18px; margin: 0; }
.ck-legend { display: inline-flex; align-items: center; gap: 6px; font-size: 0.85rem; color: var(--muted); }
.ck-legend[hidden] { display: none; }
.ck-ramp { display: inline-block; width: 64px; height: 10px; border-radius: 3px; background: linear-gradient(90deg, rgb(42, 120, 214), rgb(227, 73, 72)); }

.ck-layout { display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 700px) { .ck-layout { grid-template-columns: 132px minmax(0, 1fr); } .ck-side { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: start; } }
@media (min-width: 1150px) { .ck-layout { grid-template-columns: 132px minmax(0, 1fr) 290px; } .ck-side { grid-column: auto; display: grid; grid-template-columns: 1fr; align-content: start; } }

/* The toolbox: a column on wide screens, a scrolling strip on narrow ones. */
.ck-toolbox { display: grid; grid-template-columns: 1fr; gap: 6px; align-content: start; }
@media (max-width: 699px) { .ck-toolbox { display: flex; overflow-x: auto; padding-bottom: 4px; } .ck-toolbox .ck-tool { flex: 0 0 92px; touch-action: pan-x; } } /* a sideways swipe scrolls the strip; dragging down takes a component */
.ck-tool { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 4px 5px; font: inherit; font-size: 0.78rem; line-height: 1.15; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none; }
.ck-tool:hover { border-color: var(--accent); }
.ck-tool.ck-active { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 2px var(--accent) inset; }
.ck-tool:active { cursor: grabbing; }
.ck-icon { width: 66px; height: 36px; color: var(--text); pointer-events: none; }
.ck-tool span { pointer-events: none; text-align: center; }

/* The workspace. */
.ck-stage { min-width: 0; }
.ck-svg { display: block; width: 100%; height: clamp(420px, 64vh, 760px); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); touch-action: none; user-select: none; -webkit-user-select: none; cursor: default; }
.ck-svg:focus { outline: none; }
.ck-svg:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ck-app[data-mode="wire"] .ck-svg, .ck-app[data-mode="place"] .ck-svg { cursor: crosshair; }
.ck-hint { margin: 6px 2px 0; font-size: 0.88rem; color: var(--muted); }
.ck-griddot { fill: var(--border); }

/* Symbols and wires. */
.ck-s { stroke: var(--text); stroke-width: 2; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.ck-s.ck-body { fill: var(--surface); }
.ck-s.ck-thick { stroke-width: 4.5; stroke-linecap: butt; }
.ck-s.ck-dash { stroke-dasharray: 3 3; stroke-width: 1.5; }
.ck-s.ck-arrow { stroke-width: 1.6; marker-end: url(#ck-ah); }
.ck-s.ck-lever { stroke-width: 2.4; }
.ck-ahead { fill: var(--text); }
.ck-contact { fill: var(--surface); stroke: var(--text); stroke-width: 1.6; }
.ck-glow { fill: #ffd43b; }
.ck-halo { fill: #ffd43b; opacity: 0.35; }
.ck-pos { fill: #d32f2f; }
.ck-com { fill: var(--text); }
.ck-letter { font-size: 13px; font-weight: 700; fill: var(--text); pointer-events: none; }
.ck-comp.ck-sel .ck-s, .ck-comp.ck-hl .ck-s { stroke: var(--accent); }
.ck-comp.ck-hl .ck-s { stroke: var(--bad); }
.ck-selbox { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 1.2; stroke-dasharray: 4 3; }
.ck-comp.ck-hl .ck-selbox { fill: var(--bad-soft); stroke: var(--bad); }
.ck-wire { stroke: var(--text); stroke-width: 2.2; fill: none; stroke-linejoin: round; stroke-linecap: round; }
.ck-wire.ck-sel { stroke: var(--accent); stroke-width: 3.4; }
.ck-wire.ck-inf { stroke: var(--bad); stroke-width: 3.6; }
.ck-wire.ck-hl { stroke: var(--bad); }
.ck-dot { fill: var(--text); }
.ck-term { fill: var(--surface); stroke: var(--accent); stroke-width: 1.6; }
.ck-loose { fill: var(--surface); stroke: var(--bad); stroke-width: 2; }
.ck-label { font-size: 11.5px; fill: var(--muted); pointer-events: none; }
.ck-label .ck-name { fill: var(--text); font-weight: 600; }
.ck-reading rect { fill: #1d2a22; stroke: #4c6b57; stroke-width: 1; }
.ck-reading text { font: 600 12.5px ui-monospace, "Cascadia Mono", Consolas, monospace; fill: #b8f5a6; }
.ck-reading.ck-ol text { fill: #ff9d94; }
.ck-current { fill: var(--theme-a); }
.ck-current.ck-inf { fill: var(--bad); }
.ck-wirei { font-size: 10.5px; fill: var(--theme-a); font-weight: 600; pointer-events: none; }
.ck-handle { fill: var(--surface); stroke: var(--accent); stroke-width: 2; }
.ck-handle.ck-endh { fill: var(--accent-soft); }
.ck-selring { fill: none; stroke: var(--accent); stroke-width: 2; }
.ck-ghost { opacity: 0.5; }
.ck-insertw { fill: none; stroke: var(--accent); stroke-width: 7; stroke-opacity: 0.35; stroke-linecap: round; stroke-linejoin: round; }
.ck-preview { fill: none; stroke: var(--accent); stroke-width: 2.2; stroke-dasharray: 6 4; }
.ck-target { fill: none; stroke: var(--accent); stroke-width: 2.5; }
.ck-boxsel { fill: var(--accent-soft); fill-opacity: 0.5; stroke: var(--accent); stroke-dasharray: 4 3; }

/* The side panels. */
.ck-panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 4px 14px 12px; }
.ck-panel h3 { margin: 10px 0 8px; font-size: 1.05rem; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ck-labelin { width: 5.5em; font: inherit; font-size: 0.95rem; padding: 3px 6px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text); }
.ck-field { display: block; margin: 6px 0 8px; font-size: 0.92rem; }
.ck-flabel { display: block; color: var(--muted); margin-bottom: 2px; }
.ck-fin { display: flex; align-items: center; gap: 6px; }
.ck-fin input, .ck-field select { flex: 1; min-width: 0; min-height: 36px; font: inherit; padding: 4px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text); }
.ck-field select { width: 100%; }
.ck-fin input.ck-invalid { border-color: var(--bad); box-shadow: 0 0 0 1px var(--bad); }
.ck-unit { min-width: 1.6em; color: var(--muted); }
.ck-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.ck-slider { display: block; width: 100%; margin: 2px 0 10px; min-height: 28px; }
.ck-more { margin: 6px 0; font-size: 0.92rem; }
.ck-small { font-size: 0.85rem; color: var(--muted); margin: 4px 0 8px; }
.ck-buttons { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 2px; }
.ck-readings { margin: 10px 0 4px; padding: 8px 0 0; border-top: 1px solid var(--border); font-size: 0.92rem; }
.ck-readings:empty { display: none; }
.ck-readings div { display: flex; justify-content: space-between; gap: 10px; padding: 2px 0; }
.ck-readings dt { color: var(--muted); }
.ck-readings dd { margin: 0; font-variant-numeric: tabular-nums; text-align: right; }
.ck-lcd { font: 600 0.95rem ui-monospace, "Cascadia Mono", Consolas, monospace; background: #1d2a22; color: #b8f5a6; padding: 2px 8px; border-radius: 4px; }
.ck-lcd.ck-ol { color: #ff9d94; }
.ck-diags { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.ck-diag { font-size: 0.9rem; border-radius: 8px; }
.ck-diag button { display: block; width: 100%; text-align: left; font: inherit; color: inherit; background: none; border: 0; padding: 7px 10px; cursor: pointer; border-radius: 8px; }
.ck-diag button:hover { text-decoration: underline; }
.ck-error { background: var(--bad-soft); color: var(--bad); }
.ck-warning { background: var(--warn-soft); }
.ck-info { background: var(--bg); }
.ck-good { color: var(--good); padding: 7px 10px; }
/* Challenges: a mystery part is drawn as a closed box; read-only circuits hide the editing buttons. */
.ck-mystery { fill: var(--surface); stroke: var(--text); stroke-width: 2; stroke-dasharray: 5 3; }
.ck-mysteryq { font-size: 22px; font-weight: 700; fill: var(--text); pointer-events: none; }
.ck-app.ck-readonly .ck-toolbar .ck-group:first-child { display: none; }
.ck-tool { position: relative; }
.ck-tool small { color: var(--muted); }
.ck-tool:disabled { opacity: 0.45; cursor: default; }
.ck-left { position: absolute; top: 3px; right: 4px; font-size: 0.7rem; color: var(--muted); }

/* Modes and the challenge panel. */
.ck-tabs { display: flex; gap: 4px; margin: 16px 0 0; border-bottom: 2px solid var(--border); }
.ck-tabs button { font: inherit; font-weight: 600; padding: 8px 18px; min-height: 42px; background: none; border: 0; border-bottom: 3px solid transparent; margin-bottom: -2px; color: var(--muted); cursor: pointer; }
.ck-tabs button[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }
.ck-filebar[hidden], .ck-challenge[hidden] { display: none; }
.ck-challenge { margin: 12px 0 0; max-width: var(--read, 46rem); }
.ck-ch-title { margin: 8px 0; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ck-ch-back { margin: 0; }
.ck-ch-list { list-style: none; margin: 12px 0; padding: 0; display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.ck-challenge:has(.ck-ch-list) { max-width: none; }
.ck-ch-card { position: relative; display: flex; flex-direction: column; align-items: flex-start; gap: 6px; width: 100%; height: 100%; text-align: left; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-left: 5px solid var(--theme-b-id); border-radius: var(--radius); padding: 10px 12px; cursor: pointer; }
.ck-ch-card:hover { border-color: var(--accent); }
.ck-tick { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--good); color: var(--surface); font-size: 0.85rem; font-weight: 700; }
.ck-ch-card .ck-tick { position: absolute; top: 8px; right: 8px; }
.ck-ch-form { display: grid; gap: 4px 16px; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); margin: 8px 0; }
.ck-ch-hint { background: var(--warn-soft); border-radius: 8px; padding: 8px 12px; margin: 8px 0; }
.ck-ch-checks { list-style: none; padding: 0; margin: 6px 0; display: grid; gap: 4px; }
.ck-pass { color: var(--good); }
.ck-fail { color: var(--bad); }
.ck-ch-ok { font-weight: 600; color: var(--good); }
.ck-ch-expl { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 2px 14px 8px; margin: 10px 0; }
.ck-ch-expl h3 { font-size: 1rem; margin: 10px 0 4px; }

/* Show the working. */
.ck-steps { margin: 4px 0 8px; padding-left: 1.4em; font-size: 0.92rem; display: grid; gap: 6px; font-variant-numeric: tabular-nums; }

/* Board mode: the builder fills the screen (full screen where the browser allows it). */
html.ck-board-open { overflow: hidden; }
.ck-app.ck-board { position: fixed; inset: 0; z-index: 2000; margin: 0; padding: 12px 14px; background: var(--bg); overflow: auto; font-size: 1.12rem; }
.ck-app.ck-board .ck-svg { height: calc(100vh - 150px); min-height: 360px; }
.ck-app.ck-board .ck-describe { display: none; }
.ck-app.ck-board .ck-btn { font-size: 1.05rem; }
@media (min-width: 1150px) { .ck-app.ck-board .ck-layout { grid-template-columns: 120px minmax(0, 1fr) 320px; } }
.ck-app.ck-board .ck-label { font-size: 13px; }
.ck-app.ck-board .ck-reading text { font-size: 14px; }

/* Saving, opening and sharing. */
.ck-filebar { display: flex; flex-wrap: wrap; gap: 6px 8px; align-items: center; margin: 12px 0 0; }
.ck-filebar .ck-saved-note { font-size: 0.85rem; color: var(--muted); }
.ck-filepanel { margin: 8px 0 0; padding: 10px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.ck-filepanel[hidden] { display: none; }
.ck-filepanel h3 { margin: 4px 0 8px; font-size: 1.02rem; }
.ck-filepanel ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.ck-filepanel li { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.ck-filepanel li .ck-fname { flex: 1 1 12em; }
.ck-filepanel input[type="text"] { min-height: 38px; font: inherit; padding: 4px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text); flex: 1 1 14em; }
.ck-filepanel textarea { width: 100%; min-height: 4.5em; font: 0.85rem ui-monospace, Consolas, monospace; padding: 6px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text); }
.ck-describe, .ck-help { margin: 12px 0; }
.ck-describe summary, .ck-help summary { cursor: pointer; font-weight: 600; }
.ck-describe ul { margin: 4px 0 8px; }
