/* ==========================================================================
   SIAM SIR ICT - LOGIC CIRCUIT LAB
   Full-screen workbench. Uses the tokens from style.css. Only hue-coded parts
   carry a chapter colour: amber for 3.2 and violet for 3.1.
   ========================================================================== */
.ll-body {
  --sig-on: #FFD23F;
  --sig-off: #4B5C8C;
  --sig-x: #4E8DFF;
  --board: #0A1128;
  --board-dot: #24315C;
  --part: #16224A;
  --part-line: #AEB9D6;
  --ease: var(--ease-out);
  --c32: var(--ch-4);
  --c31: var(--ch-3);
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto 1fr;
  overscroll-behavior: none;
}

[data-theme="light"] .ll-body {
  --sig-on: #C2410C;
  --sig-off: #A6B0C8;
  --sig-x: #2448D8;
  --board: #F5F6F8;
  --board-dot: #CBD3E2;
  --part: #FFFFFF;
  --part-line: #33405F;
}

.ll-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

:where(.ll-body) button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
.ll-body button:focus-visible,
.ll-body a:focus-visible,
.ll-body input:focus-visible,
.ll-body select:focus-visible,
.ll-body .cp:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ---- Top bar ---------------------------------------------------------- */
.ll-top {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 52px;
  padding: 0 12px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  min-width: 0;
}

.ll-back {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex: none;
  height: 36px;
  padding: 0 12px 0 6px;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
  background: var(--bg-elevated);
  transition: color var(--t-fast) var(--ease);
}
.ll-back:hover { color: var(--text-main); }

.ll-top svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

.ll-title {
  flex: none;
  font-size: 1.12rem;
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
  margin: 0 6px 0 2px;
}

.ll-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1 1 auto;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.ll-actions::-webkit-scrollbar { display: none; }

.ll-tool {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: none;
  height: 36px;
  min-width: 36px;
  justify-content: center;
  padding: 0 8px;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 600;
  white-space: nowrap;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.ll-tool:hover:not(:disabled) { background: var(--bg-elevated); color: var(--text-main); }
.ll-tool:disabled { opacity: 0.35; cursor: default; }
.ll-tool[aria-expanded="true"] { background: var(--bg-elevated); color: var(--text-main); }

.ll-sep { flex: none; width: 1px; height: 20px; margin: 0 4px; background: var(--border-color); }

.ll-site { display: flex; align-items: center; gap: 4px; flex: none; }
.ll-lang, .ll-theme {
  height: 36px;
  padding: 0 10px;
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
}
.ll-lang:hover, .ll-theme:hover { color: var(--text-main); }

/* ---- Work area -------------------------------------------------------- */
.ll-work {
  display: grid;
  grid-template-columns: 216px minmax(0, 1fr) 300px;
  min-height: 0;
}

.ll-left, .ll-right {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg-surface);
}
.ll-left { border-right: 1px solid var(--border-color); }
.ll-right { border-left: 1px solid var(--border-color); }

.ll-switcher {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  padding: 8px;
  flex: none;
}
.ll-switcher button {
  height: 34px;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 700;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.ll-switcher button:hover { color: var(--text-main); }
.ll-switcher button.on { background: var(--bg-elevated); color: var(--text-main); }

.ll-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 0 8px 16px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-color) transparent;
}
.ll-scroll[hidden] { display: none; }

/* ---- Parts ------------------------------------------------------------ */
.ll-group { margin-top: 12px; }
.ll-group:first-child { margin-top: 2px; }
.ll-group-title {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-dim);
  margin: 0 4px 4px;
  line-height: 1.4;
}
[data-lang="en"] .ll-group-title { font-family: var(--font-mono); letter-spacing: 0.02em; }
.ll-group-title { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.ll-group-title em { flex: none; font-style: normal; color: var(--h, var(--text-dim)); font-family: var(--font-mono); }

.ll-parts { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }

.ll-part {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 62px;
  padding: 6px 4px;
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  color: var(--text-main);
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
  transition: transform var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
  cursor: grab;
}
.ll-part:hover { transform: translateY(-1px); }
.ll-part:active { cursor: grabbing; }
.ll-part svg { width: 46px; height: 28px; overflow: visible; }
.ll-part .pi-body { fill: none; stroke: var(--text-main); stroke-width: 3; }
.ll-part .pi-line { fill: none; stroke: var(--text-main); stroke-width: 2.5; }
.ll-part-code {
  display: flex;
  align-items: center;
  height: 28px;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.92rem;
  color: var(--h, var(--text-main));
}
.ll-part-name { font-size: 0.72rem; font-weight: 600; line-height: 1.15; text-align: center; color: var(--text-muted); }

.ll-ghost {
  position: fixed;
  z-index: 60;
  pointer-events: none;
  transform: translate(-50%, -50%);
  padding: 6px 10px;
  border-radius: var(--radius-md);
  background: var(--cobalt);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
  white-space: nowrap;
}

/* ---- Examples --------------------------------------------------------- */
.ll-ex {
  display: block;
  width: 100%;
  padding: 7px 8px;
  border-radius: var(--radius-sm);
  text-align: left;
  font-size: 0.84rem;
  font-weight: 500;
  line-height: 1.3;
  color: var(--text-muted);
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.ll-ex:hover { background: var(--bg-elevated); color: var(--text-main); }
.ll-ex.on { background: var(--bg-elevated); color: var(--text-main); box-shadow: inset 3px 0 0 var(--h); }

/* ---- Equation strip --------------------------------------------------- */
.ll-center { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; min-width: 0; min-height: 0; }

.ll-eq {
  padding: 8px 12px 6px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  min-width: 0;
}

.ll-eq-row { display: flex; align-items: center; gap: 8px; min-width: 0; }

.ll-eq-label { flex: none; font-size: 0.82rem; font-weight: 700; color: var(--text-muted); }

.ll-eq-input {
  flex: 1 1 200px;
  min-width: 120px;
  height: 38px;
  padding: 0 12px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  background: var(--bg-elevated);
  color: var(--text-main);
  font-family: var(--font-mono);
  font-size: 0.98rem;
  transition: border-color var(--t-fast) var(--ease);
}
.ll-eq-input.bad { border-color: var(--danger); }
.ll-eq-input::placeholder { color: var(--text-dim); }

.ll-modes {
  display: flex;
  flex: none;
  gap: 2px;
  padding: 3px;
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
}
.ll-mode {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  height: 32px;
  padding: 0 9px;
  line-height: 32px;
  border-radius: 7px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.ll-mode b { font-family: var(--font-mono); font-size: 0.78rem; font-weight: 700; color: var(--text-dim); }
.ll-mode:hover:not(:disabled) { color: var(--text-main); }
.ll-mode:disabled { opacity: 0.4; cursor: not-allowed; }
.ll-mode[aria-checked="true"] { background: var(--bg-card); color: var(--text-main); }
[data-theme="light"] .ll-mode[aria-checked="true"] { box-shadow: 0 1px 2px rgba(11, 21, 51, 0.12); }
.ll-mode[aria-checked="true"] b { color: var(--marker); }
[data-theme="light"] .ll-mode[aria-checked="true"] b { color: var(--cobalt); }

.ll-build {
  flex: none;
  height: 38px;
  padding: 0 16px;
  border-radius: var(--radius-md);
  background: var(--cobalt);
  color: #fff;
  font-size: 0.86rem;
  font-weight: 700;
  white-space: nowrap;
  transition: background var(--t-fast) var(--ease);
}
.ll-build:hover:not(:disabled) { background: var(--cobalt-hover); }
.ll-build:disabled { opacity: 0.5; cursor: not-allowed; }

.ll-eq-read {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 18px;
  min-height: 34px;
  padding-top: 6px;
  font-size: 0.8rem;
  color: var(--text-dim);
  line-height: 1.5;
}
.ll-eq-out {
  font-family: var(--font-display);
  font-size: 1.28rem;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.35;
  white-space: nowrap;
}
.ll-eq-err { color: var(--danger); font-size: 0.86rem; font-weight: 600; }
.ll-eq-err mark { background: var(--danger-tint); color: var(--danger); border-radius: 3px; padding: 0 2px; font-family: var(--font-mono); }
.ll-eq-tip code { font-family: var(--font-mono); color: var(--text-muted); background: none; padding: 0; font-size: 0.8rem; }

/* Overbars stack, so a bar over a bar stays readable. */
.ov {
  display: inline-block;
  border-top: 2px solid currentColor;
  margin-top: 3px;
  padding-top: 1px;
  line-height: 1.15;
}
.xo { font-family: var(--font-sans); font-size: 0.82em; font-weight: 600; }
.ll-eq-out .ov { border-top-color: var(--marker); }
[data-theme="light"] .ll-eq-out .ov { border-top-color: var(--cobalt); }

/* ---- Board ------------------------------------------------------------ */
.ll-stage { position: relative; min-height: 0; min-width: 0; overflow: hidden; background: var(--board); }

.ll-board {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: default;
}
.ll-board.panning { cursor: grabbing; }
.ll-dot { fill: var(--board-dot); }

.wire, .wire-hit { fill: none; stroke-linejoin: round; stroke-linecap: round; }
.wire { stroke: var(--sig-off); stroke-width: 2.4; pointer-events: none; transition: stroke 120ms linear; }
.wire-hit { stroke: transparent; stroke-width: 14; cursor: crosshair; }
.net[data-s="1"] .wire { stroke: var(--sig-on); stroke-width: 3; }
.net[data-s="2"] .wire { stroke: var(--sig-x); }
.net .jn { fill: var(--sig-off); pointer-events: none; transition: fill 120ms linear; }
.net[data-s="1"] .jn { fill: var(--sig-on); }
.net[data-s="2"] .jn { fill: var(--sig-x); }
.wire-sel { fill: none; stroke: var(--primary); stroke-width: 7; stroke-opacity: 0.45; stroke-linejoin: round; stroke-linecap: round; pointer-events: none; }
.rubber { fill: none; stroke: var(--primary); stroke-width: 2.4; stroke-dasharray: 6 5; pointer-events: none; }
.rubber.hit { stroke: var(--marker); stroke-dasharray: none; }
[data-theme="light"] .rubber.hit { stroke: var(--cobalt); }
.marquee { fill: var(--primary-glow); stroke: var(--primary); stroke-width: 1; pointer-events: none; }

.cp { cursor: move; }
.cp .hit { fill: transparent; stroke: none; }
.cp .hl { fill: none; stroke: none; pointer-events: none; }
.cp.sel .hl { stroke: var(--primary); stroke-width: 1.6; stroke-dasharray: 5 4; }
.cp.tidy { transition: transform 320ms var(--ease); }

.stub { fill: none; stroke: var(--sig-off); stroke-width: 2.4; pointer-events: none; transition: stroke 120ms linear; }
.stub[data-s="1"] { stroke: var(--sig-on); stroke-width: 3; }
.stub[data-s="2"] { stroke: var(--sig-x); }

.pin { fill: var(--sig-off); pointer-events: none; transition: r 120ms var(--ease); }
.pin[data-s="1"] { fill: var(--sig-on); }
.pin[data-s="2"] { fill: var(--board); stroke: var(--sig-x); stroke-width: 1.8; }
.pin.can { fill: var(--primary); stroke: none; }
.pin.hot { r: 7px; fill: var(--marker); stroke: none; }
[data-theme="light"] .pin.hot { fill: var(--cobalt); }

.g-body { fill: var(--part); stroke: var(--part-line); stroke-width: 2; stroke-linejoin: round; }
.g-line { fill: none; stroke: var(--part-line); stroke-width: 2; }
.g-name {
  fill: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 8.5px;
  font-weight: 700;
  text-anchor: middle;
  pointer-events: none;
}

.chip { --h: var(--c32); }
.chip.c31 { --h: var(--c31); }
.chip-body { fill: var(--part); stroke: var(--h); stroke-width: 2; }
.chip-title {
  fill: var(--h);
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 700;
  pointer-events: none;
}
.chip-pin { fill: var(--text-muted); font-family: var(--font-mono); font-size: 9.5px; font-weight: 500; pointer-events: none; }
.chip-pin.r { text-anchor: end; }
.chip-clk { fill: none; stroke: var(--text-muted); stroke-width: 1.4; }
.chip-state {
  fill: var(--text-main);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  text-anchor: end;
  pointer-events: none;
}
.chip-state.bad { fill: var(--danger); }

.sw-body { fill: var(--part); stroke: var(--part-line); stroke-width: 2; }
.sw-label, .lamp-label {
  fill: var(--text-main);
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 700;
  pointer-events: none;
}
.lamp-label { font-size: 12px; }
.sw-key { fill: var(--bg-elevated); transition: fill 120ms linear; }
.sw-val {
  fill: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 700;
  text-anchor: middle;
  pointer-events: none;
}
.cp[data-on="1"] .sw-key { fill: var(--sig-on); }
.cp[data-on="1"] .sw-val { fill: #0B1533; }
[data-theme="light"] .cp[data-on="1"] .sw-val { fill: #fff; }
.cp.poke { cursor: pointer; }

.lamp { fill: var(--part); stroke: var(--part-line); stroke-width: 2; transition: fill 120ms linear; }
.lamp-val {
  fill: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  text-anchor: middle;
  pointer-events: none;
}
.cp[data-on="1"] .lamp { fill: var(--sig-on); stroke: var(--sig-on); filter: drop-shadow(0 0 7px var(--sig-on)); }
.cp[data-on="1"] .lamp-val { fill: #0B1533; }
[data-theme="light"] .cp[data-on="1"] .lamp-val { fill: #fff; }
.cp[data-on="2"] .lamp { stroke: var(--sig-x); stroke-dasharray: 4 3; }

.const-body { fill: var(--bg-elevated); stroke: none; }

.num-body { fill: var(--part); stroke: var(--c31); stroke-width: 2; }
.num-title { fill: var(--c31); font-family: var(--font-mono); font-size: 9px; font-weight: 700; pointer-events: none; }
.num-big { fill: var(--text-main); font-family: var(--font-display); font-size: 25px; font-weight: 800; text-anchor: middle; pointer-events: none; }
.num-bin { fill: var(--text-muted); font-family: var(--font-mono); font-size: 9.5px; text-anchor: middle; pointer-events: none; }
.num-key { fill: var(--bg-elevated); cursor: pointer; }
.num-key:hover { fill: var(--primary); }
.num-arrow { fill: var(--text-main); pointer-events: none; }
.num-k { fill: var(--text-dim); font-family: var(--font-mono); font-size: 9.5px; font-weight: 700; pointer-events: none; }
.num-v { fill: var(--text-main); font-family: var(--font-mono); font-size: 11px; font-weight: 700; text-anchor: end; pointer-events: none; }

.seg-body { fill: #070D22; stroke: var(--c31); stroke-width: 2; }
.seg { fill: #1B2852; transition: fill 120ms linear; }
.seg[data-s="1"] { fill: #FFD23F; }

/* One assembly when a circuit is built. Nothing moves at rest. */
.enter { animation: ll-rise 320ms var(--ease) both; animation-delay: var(--d, 0ms); }
.wire.enter { stroke-dasharray: 1; animation: ll-draw 360ms var(--ease) both; animation-delay: var(--d, 0ms); }
.jn.enter { animation: ll-fade 200ms linear both; animation-delay: var(--d, 0ms); }
@keyframes ll-rise { from { opacity: 0; } to { opacity: 1; } }
@keyframes ll-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes ll-draw { from { stroke-dashoffset: 1; } to { stroke-dashoffset: 0; } }

/* ---- Floating controls ------------------------------------------------ */
.ll-empty {
  position: absolute;
  top: 28px;
  left: 28px;
  max-width: min(460px, calc(100% - 56px));
  pointer-events: none;
}
.ll-empty[hidden] { display: none; }
.ll-empty h2 { font-size: 1.5rem; font-weight: 800; line-height: 1.2; margin-bottom: 6px; }
.ll-empty p { font-size: 0.95rem; line-height: 1.55; color: var(--text-muted); }

.ll-note {
  position: absolute;
  top: 10px;
  left: 10px;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  max-width: min(520px, calc(100% - 20px));
  padding: 8px 6px 8px 12px;
  border-radius: var(--radius-md);
  background: var(--bg-card);
  box-shadow: 0 10px 24px -14px rgba(0, 0, 0, 0.55);
  font-size: 0.84rem;
  line-height: 1.45;
  color: var(--text-muted);
}
[data-theme="light"] .ll-note { box-shadow: 0 8px 20px -14px rgba(11, 21, 51, 0.4); }
.ll-note[hidden] { display: none; }
.ll-note strong { display: block; color: var(--text-main); font-weight: 700; }
.ll-note button { flex: none; width: 24px; height: 24px; border-radius: 6px; font-size: 1.05rem; line-height: 1; color: var(--text-dim); }
.ll-note button:hover { color: var(--text-main); }

.ll-clock {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border-radius: var(--radius-md);
  background: var(--bg-card);
  box-shadow: 0 10px 24px -14px rgba(0, 0, 0, 0.55);
}
.ll-clock[hidden] { display: none; }
.ll-chipbtn {
  height: 32px;
  padding: 0 10px;
  border-radius: 7px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  white-space: nowrap;
}
.ll-chipbtn:hover { background: var(--bg-elevated); color: var(--text-main); }
.ll-chipbtn.primary { background: var(--cobalt); color: #fff; }
.ll-chipbtn.primary:hover { background: var(--cobalt-hover); color: #fff; }
.ll-speed select {
  height: 32px;
  padding: 0 4px;
  border: 0;
  border-radius: 7px;
  background: var(--bg-elevated);
  color: var(--text-main);
  font-family: var(--font-mono);
  font-size: 0.78rem;
}

.ll-inspector {
  position: absolute;
  left: 10px;
  bottom: 10px;
  width: 300px;
  max-width: calc(100% - 76px);
  padding: 10px 12px;
  border-radius: var(--radius-md);
  background: var(--bg-card);
  box-shadow: 0 10px 24px -14px rgba(0, 0, 0, 0.55);
}
[data-theme="light"] .ll-inspector,
[data-theme="light"] .ll-clock { box-shadow: 0 8px 20px -14px rgba(11, 21, 51, 0.4); }
.ll-inspector[hidden] { display: none; }
.ll-in-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.ll-in-name { font-family: var(--font-display); font-size: 1rem; font-weight: 700; line-height: 1.2; }
.ll-in-desc { font-size: 0.8rem; line-height: 1.4; color: var(--text-muted); margin-top: 2px; }
.ll-in-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 0.8rem; font-weight: 600; color: var(--text-muted); }
.ll-in-row input {
  flex: 1;
  min-width: 0;
  height: 30px;
  padding: 0 8px;
  border: 0;
  border-radius: 6px;
  background: var(--bg-elevated);
  color: var(--text-main);
  font-family: var(--font-mono);
  font-size: 0.86rem;
}
.ll-step { display: inline-flex; align-items: center; gap: 2px; margin-left: auto; }
.ll-step button { width: 30px; height: 30px; border-radius: 6px; background: var(--bg-elevated); font-weight: 700; color: var(--text-main); }
.ll-step button:disabled { opacity: 0.35; cursor: default; }
.ll-step span { min-width: 22px; text-align: center; font-family: var(--font-mono); font-weight: 700; color: var(--text-main); }
.ll-del {
  flex: none;
  height: 28px;
  padding: 0 10px;
  border-radius: 6px;
  background: var(--danger-tint);
  color: var(--danger);
  font-size: 0.78rem;
  font-weight: 700;
}

.ll-zoom {
  position: absolute;
  right: 10px;
  bottom: 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 3px;
  border-radius: var(--radius-md);
  background: var(--bg-card);
  box-shadow: 0 10px 24px -14px rgba(0, 0, 0, 0.55);
}
.ll-zoom button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 7px;
  color: var(--text-muted);
  font-size: 1.15rem;
  font-weight: 600;
}
.ll-zoom button:hover { background: var(--bg-elevated); color: var(--text-main); }
.ll-zoom svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.ll-help {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 5;
  width: 340px;
  max-width: calc(100% - 20px);
  max-height: calc(100% - 20px);
  overflow-y: auto;
  padding: 14px 16px;
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  box-shadow: 0 24px 48px -24px rgba(0, 0, 0, 0.6);
}
.ll-help[hidden] { display: none; }
.ll-help h2 { font-size: 1.05rem; margin-bottom: 6px; }
.ll-help dt { font-size: 0.8rem; font-weight: 700; color: var(--text-main); margin-top: 8px; }
.ll-help dd { font-size: 0.82rem; line-height: 1.45; color: var(--text-muted); }
.ll-legend { display: flex; align-items: center; gap: 6px; }
.ll-legend span:not([data-i18n-en]) { width: 22px; height: 3px; border-radius: 2px; margin-left: 6px; }
.ll-legend .s1 { background: var(--sig-on); margin-left: 0 !important; }
.ll-legend .s0 { background: var(--sig-off); }
.ll-legend .sx { background: var(--sig-x); }

/* ---- Status line ------------------------------------------------------ */
.ll-status {
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 28px;
  padding: 0 12px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-color);
  font-size: 0.78rem;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
}
.ll-st-hint { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; color: var(--text-muted); }
.ll-st-warn { flex: none; font-weight: 700; color: var(--danger); }
.ll-st-warn.soft { color: var(--sig-x); }
.ll-st-count { flex: none; font-family: var(--font-mono); font-size: 0.74rem; }

/* ---- Truth table ------------------------------------------------------ */
.ll-exprs { margin: 2px 2px 10px; }
.ll-expr { font-size: 1.02rem; font-family: var(--font-display); font-weight: 700; line-height: 1.4; overflow-wrap: anywhere; color: var(--text-main); }
.ll-expr-note { font-size: 0.74rem; font-weight: 600; color: var(--text-dim); margin-top: 6px; line-height: 1.3; }
.ll-expr + .ll-expr-note { margin-top: 2px; }
.ll-msg { font-size: 0.84rem; line-height: 1.5; color: var(--text-muted); padding: 2px 4px; }

.ll-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-family: var(--font-mono);
  font-size: 0.82rem;
}
.ll-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 5px 4px;
  background: var(--bg-elevated);
  color: var(--text-main);
  font-weight: 700;
  font-size: 0.76rem;
  line-height: 1.15;
  text-align: center;
  overflow-wrap: anywhere;
}
.ll-table td { padding: 3px 4px; text-align: center; color: var(--text-muted); border-bottom: 1px solid var(--border-color); }
.ll-table .o { background: var(--primary-glow); }
.ll-table td.o { color: var(--text-main); font-weight: 700; }
.ll-table td.o[data-v="1"] { color: var(--sig-on); }
.ll-table td.o[data-v="2"] { color: var(--sig-x); }
.ll-table th.o { color: var(--text-main); }
.ll-table tbody tr { cursor: pointer; }
.ll-table tbody tr:hover td { background: var(--bg-elevated); }
.ll-table tr.now td { background: var(--marker) !important; color: #0B1533 !important; font-weight: 700; }

.ll-make-row { display: flex; align-items: center; gap: 8px; margin: 2px 2px 8px; font-size: 0.82rem; font-weight: 600; color: var(--text-muted); }
.ll-table td.flip { cursor: pointer; }
.ll-table td.flip:hover { background: var(--primary) !important; color: #fff; }
.ll-table td.flip[data-v="1"] { color: var(--sig-on); }
.ll-make-outs { margin: 10px 2px; }
.ll-make-build { width: 100%; margin-top: 4px; }

/* ---- Bottom bar (phones) ---------------------------------------------- */
.ll-bar { display: none; }

@media (max-width: 1280px) {
  .ll-tool.has-text span { display: none; }
  .ll-work { grid-template-columns: 196px minmax(0, 1fr) 270px; }
}

/* Below this width the row cannot hold everything, so the modes drop to a second line. */
@media (max-width: 1240px) {
  .ll-eq-row { flex-wrap: wrap; }
  .ll-eq-input { flex: 1 1 calc(100% - 90px); }
  .ll-build { margin-left: auto; }
}

@media (max-width: 900px) {
  .ll-body { grid-template-rows: auto minmax(0, 1fr) auto; padding-bottom: env(safe-area-inset-bottom); }
  .ll-top { height: 48px; padding: 0 8px; gap: 6px; }
  .ll-title, .ll-hide-narrow { display: none; }
  .ll-back { padding: 0 8px 0 6px; }
  .ll-lang { width: 36px; padding: 0 0 0 9px; overflow: hidden; text-align: left; white-space: nowrap; letter-spacing: 24px; }
  .ll-theme .hide-mobile { display: none; }

  .ll-work { display: block; position: relative; }
  .ll-center { height: 100%; grid-template-rows: minmax(0, 1fr) auto; }

  .ll-left, .ll-right, .ll-eq {
    position: fixed;
    left: 0;
    right: 0;
    bottom: calc(46px + env(safe-area-inset-bottom));
    z-index: 30;
    height: 58vh;
    height: 58dvh;
    border: 0;
    border-top: 1px solid var(--border-color);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    box-shadow: 0 -18px 40px -24px rgba(0, 0, 0, 0.6);
    transform: translateY(calc(100% + 60px));
    visibility: hidden;
    transition: transform 240ms var(--ease), visibility 240ms;
  }
  .ll-eq { height: auto; padding: 12px; }
  [data-sheet="parts"] .ll-left,
  [data-sheet="examples"] .ll-left,
  [data-sheet="equation"] .ll-eq,
  [data-sheet="table"] .ll-right { transform: none; visibility: visible; }
  .ll-left .ll-switcher { display: none; }
  .ll-parts { grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); }

  .ll-eq-row { gap: 6px; }
  .ll-eq-label { width: 100%; }
  .ll-eq-input { flex-basis: 100%; font-size: 16px; height: 44px; }
  .ll-modes { width: 100%; overflow-x: auto; }
  .ll-mode { flex: 1 0 auto; justify-content: center; }
  .ll-build { width: 100%; margin: 2px 0 0; height: 42px; }
  .ll-eq-read { min-height: 0; }

  .ll-status { min-height: 24px; font-size: 0.72rem; padding: 0 8px; }
  .ll-st-count { display: none; }

  .ll-note { font-size: 0.78rem; padding: 6px 4px 6px 10px; top: 6px; left: 6px; max-width: calc(100% - 12px); }
  .ll-clock { top: auto; bottom: 8px; left: 8px; right: 56px; width: fit-content; max-width: calc(100% - 64px); overflow-x: auto; }
  .ll-inspector { left: 6px; bottom: 6px; width: auto; right: 56px; max-width: none; padding: 8px 10px; z-index: 3; }
  .ll-zoom { right: 6px; bottom: 6px; }
  .ll-zoom button { width: 38px; height: 38px; }

  .ll-bar {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    position: relative;
    z-index: 31;
    height: 46px;
    background: var(--bg-surface);
    border-top: 1px solid var(--border-color);
  }
  .ll-bar button { font-size: 0.82rem; font-weight: 700; color: var(--text-muted); }
  .ll-bar button.on { color: var(--text-main); box-shadow: inset 0 2px 0 var(--marker); }
}

@media (prefers-reduced-motion: reduce) {
  .ll-body *, .ll-body *::before { transition: none !important; animation: none !important; }
}
