/* 09 / LATTICE — «Матрица». Scoped to #lattice only. */

#lattice.lattice-concept {
  --lat-bg: #101813;
  --lat-bg-2: #0c120f;
  --lat-panel: #1a2721;
  --lat-panel-2: #15211b;
  --lat-paper: #e9e6d9;
  --lat-paper-2: #dfdccd;
  --lat-ink: #14201a;
  --lat-ink-soft: #3d5047;
  --lat-sage: #dbe5d6;
  --lat-body: #b9c7bb;
  --lat-muted: #92a499;
  --lat-dim: #7f9286;
  --lat-accent: #d8eda8;
  --lat-accent-strong: #e8f7c1;
  --lat-accent-dim: rgba(216, 237, 168, .16);
  --lat-line: rgba(197, 216, 199, .16);
  --lat-line-strong: rgba(197, 216, 199, .32);
  --lat-error: #9b4b3e;
  --lat-error-bg: rgba(155, 75, 62, .08);
  --lat-warn: #7a5b2e;
  --lat-warn-bg: rgba(135, 104, 58, .09);
  --lat-success: #2f654e;
  --lat-success-bg: rgba(47, 101, 78, .08);
  --split: 50%;
  height: 100vh;
  min-height: 760px;
  background: var(--lat-bg);
  color: var(--lat-sage);
  font-family: var(--sans);
  isolation: isolate;
}

#lattice *,
#lattice *::before,
#lattice *::after { box-sizing: border-box; }

#lattice ::selection { background: var(--lat-accent); color: var(--lat-ink); }

#lattice .lattice-ambient {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 52% 58% at 16% 14%, rgba(111, 143, 120, .22), transparent 68%),
    radial-gradient(ellipse 44% 52% at 87% 78%, rgba(88, 108, 129, .16), transparent 70%),
    linear-gradient(135deg, #101813 0%, #0d1511 55%, #111b16 100%);
}

#lattice .lattice-ambient::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: .5;
  background-image:
    linear-gradient(rgba(197, 216, 199, .045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(197, 216, 199, .045) 1px, transparent 1px);
  background-size: 72px 72px;
  mask-image: radial-gradient(ellipse at 42% 45%, #000 10%, transparent 78%);
  -webkit-mask-image: radial-gradient(ellipse at 42% 45%, #000 10%, transparent 78%);
}

#lattice .lattice-grain {
  position: absolute;
  inset: 0;
  z-index: 1;
  opacity: .28;
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.78' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.18'/%3E%3C/svg%3E");
  mix-blend-mode: soft-light;
}

#lattice .lattice-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- header ---------- */

#lattice .lattice-head {
  position: relative;
  z-index: 6;
  height: 64px;
  padding: 0 22px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  border-bottom: 1px solid var(--lat-line);
  background: linear-gradient(180deg, rgba(16, 24, 19, .88), rgba(16, 24, 19, .52));
  backdrop-filter: blur(12px);
}

#lattice .lattice-brand {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

#lattice .lattice-mark {
  width: 26px;
  height: 26px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 3px;
  flex: 0 0 auto;
}

#lattice .lattice-mark i {
  display: block;
  width: auto;
  height: auto;
  border-radius: 0;
  background: var(--lat-accent);
  opacity: .9;
  transition: transform .35s cubic-bezier(.2, .8, .2, 1), opacity .35s;
}

#lattice .lattice-mark i:nth-child(2) { opacity: .48; }
#lattice .lattice-mark i:nth-child(3) { opacity: .48; }
#lattice .lattice-mark i:nth-child(4) { opacity: .84; }

#lattice .lattice-brand:hover .lattice-mark i:nth-child(1) { transform: translate(2px, 2px); }
#lattice .lattice-brand:hover .lattice-mark i:nth-child(4) { transform: translate(-2px, -2px); }

#lattice .lattice-brand-text {
  display: grid;
  gap: 1px;
  min-width: 0;
}

#lattice .lattice-brand-text b {
  font: 600 10px/1 var(--display);
  letter-spacing: .02em;
  color: #eef4e9;
}

#lattice .lattice-brand-text em {
  font: 400 7px/1.2 var(--mono);
  font-style: normal;
  letter-spacing: .18em;
  color: var(--lat-muted);
}

#lattice .lattice-headline {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  font: 500 8px/1 var(--mono);
  letter-spacing: .17em;
  color: var(--lat-muted);
  white-space: nowrap;
}

#lattice .lattice-headline::before,
#lattice .lattice-headline::after {
  content: "";
  width: 26px;
  height: 1px;
  background: var(--lat-line-strong);
}

#lattice .lattice-headline b {
  margin: 0;
  font: 500 9px/1 var(--mono);
  letter-spacing: .08em;
  color: var(--lat-ink);
  background: var(--lat-accent);
  padding: 5px 7px;
  border-radius: 1px;
  font-variant-numeric: tabular-nums;
}

#lattice .lattice-presets {
  justify-self: end;
  display: flex;
  border: 1px solid var(--lat-line-strong);
  border-radius: 2px;
  overflow: hidden;
  background: rgba(13, 20, 16, .45);
}

#lattice .lattice-presets button {
  display: flex;
  align-items: center;
  gap: 7px;
  border: 0;
  border-right: 1px solid var(--lat-line);
  background: transparent;
  color: var(--lat-muted);
  padding: 8px 11px;
  font: 500 8px/1 var(--mono);
  letter-spacing: .09em;
  cursor: pointer;
  transition: background .2s, color .2s;
}

#lattice .lattice-presets button:last-child { border-right: 0; }
#lattice .lattice-presets button:hover { color: var(--lat-sage); background: rgba(216, 237, 168, .06); }
#lattice .lattice-presets button.active { color: var(--lat-ink); background: var(--lat-accent); }

#lattice .lattice-preset-glyph {
  width: 14px;
  height: 11px;
  display: flex;
  gap: 2px;
  border: 1px solid currentColor;
  padding: 2px;
  flex: 0 0 auto;
}

#lattice .lattice-preset-glyph i { display: block; flex: 1; background: currentColor; opacity: .8; }
#lattice [data-lattice-preset="theory"] .lattice-preset-glyph i:first-child { flex: 2.4; }
#lattice [data-lattice-preset="practice"] .lattice-preset-glyph i:last-child { flex: 2.4; }

/* ---------- workspace ---------- */

#lattice .lattice-space {
  position: absolute;
  z-index: 3;
  inset: 76px 22px 56px;
  display: flex;
  align-items: stretch;
  overflow: hidden;
}

#lattice .lattice-tabs { display: none; }

#lattice .lattice-theory,
#lattice .lattice-practice {
  position: relative;
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--lat-line);
}

#lattice .lattice-theory {
  width: var(--split);
  flex: 0 0 auto;
  background:
    linear-gradient(138deg, rgba(31, 46, 38, .96), rgba(20, 32, 26, .98) 58%, rgba(24, 38, 31, .96));
  transition: width .48s cubic-bezier(.22, .8, .2, 1), border-color .3s, opacity .3s;
  container-type: inline-size;
  container-name: lattice-theory;
}

#lattice .lattice-practice {
  flex: 1 1 auto;
  background:
    radial-gradient(ellipse at 82% 8%, rgba(255, 255, 255, .5), transparent 48%),
    linear-gradient(160deg, var(--lat-paper) 0%, #e7e3d5 58%, #e2dfd0 100%);
  color: var(--lat-ink);
  border-color: rgba(20, 32, 26, .24);
  transition: flex-basis .48s cubic-bezier(.22, .8, .2, 1), opacity .3s;
  container-type: inline-size;
  container-name: lattice-practice;
}

#lattice .lattice-practice::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: .32;
  background-image:
    linear-gradient(rgba(20, 32, 26, .035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(20, 32, 26, .028) 1px, transparent 1px);
  background-size: 26px 26px;
  mask-image: linear-gradient(120deg, #000, transparent 55%);
  -webkit-mask-image: linear-gradient(120deg, #000, transparent 55%);
}

#lattice .lattice-theory.is-flash,
#lattice .lattice-practice.is-flash { animation: lattice-panel-flash .7s ease; }

#lattice[data-layout="theory"] .lattice-practice,
#lattice[data-layout="practice"] .lattice-theory { display: none; }

#lattice[data-layout="theory"] .lattice-theory,
#lattice[data-layout="practice"] .lattice-practice {
  width: 100%;
  flex: 1 1 auto;
}

#lattice[data-layout="theory"] .lattice-divider,
#lattice[data-layout="practice"] .lattice-divider { display: none; }

#lattice .lattice-grid {
  position: absolute;
  inset: 46px 0 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(197, 216, 199, .07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(197, 216, 199, .07) 1px, transparent 1px);
  background-size: 46px 46px;
  mask-image: radial-gradient(260px circle at var(--mx, 50%) var(--my, 50%), #000 12%, transparent 78%);
  -webkit-mask-image: radial-gradient(260px circle at var(--mx, 50%) var(--my, 50%), #000 12%, transparent 78%);
  transition: opacity .3s;
}

/* ---------- panel label ---------- */

#lattice .lattice-label {
  position: relative;
  z-index: 3;
  height: 46px;
  padding: 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid var(--lat-line);
  font: 500 8px/1 var(--mono);
  letter-spacing: .15em;
  color: var(--lat-muted);
  opacity: 1;
}

#lattice .lattice-label > span {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#lattice .lattice-label em {
  font-style: normal;
  color: var(--lat-dim);
  letter-spacing: .12em;
}

#lattice .lattice-state-dot {
  width: 5px;
  height: 5px;
  flex: 0 0 auto;
  background: var(--lat-accent);
  box-shadow: 0 0 0 3px rgba(216, 237, 168, .1);
}

#lattice .lattice-state-dot-practice { background: var(--lat-success); box-shadow: 0 0 0 3px rgba(47, 101, 78, .1); }

#lattice .lattice-practice .lattice-label { border-bottom-color: rgba(20, 32, 26, .26); color: #56665c; }
#lattice .lattice-practice .lattice-label em { color: #56665c; }

#lattice .lattice-collapse {
  width: 27px;
  height: 27px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border: 1px solid currentColor;
  border-radius: 1px;
  background: transparent;
  color: inherit;
  font: 500 12px/1 var(--mono);
  cursor: pointer;
  transition: background .18s, color .18s, border-color .18s;
}

#lattice .lattice-collapse:hover { background: var(--lat-accent); color: var(--lat-ink); border-color: var(--lat-accent); }
#lattice .lattice-practice .lattice-collapse:hover { background: var(--lat-ink); color: var(--lat-paper); border-color: var(--lat-ink); }

/* ---------- theory ---------- */

#lattice .lattice-theory-content {
  position: relative;
  z-index: 2;
  height: calc(100% - 46px);
  padding: clamp(22px, 2.5vw, 32px);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(197, 216, 199, .22) transparent;
}

#lattice .lattice-theory-content::-webkit-scrollbar { width: 6px; }
#lattice .lattice-theory-content::-webkit-scrollbar-thumb { background: rgba(197, 216, 199, .2); }

#lattice .lattice-kicker {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  font: 500 8px/1 var(--mono);
  letter-spacing: .17em;
  color: var(--lat-muted);
}

#lattice .lattice-kicker em {
  font-style: normal;
  color: var(--lat-dim);
  white-space: nowrap;
}

#lattice .lattice-theory h1 {
  font: 500 clamp(32px, 9.6cqw, 68px)/.88 var(--serif);
  font-variation-settings: "opsz" 90;
  letter-spacing: -.045em;
  color: #f1f5ec;
  margin: clamp(16px, 2.2vw, 22px) 0 0;
  max-width: 100%;
}

#lattice .lattice-theory h1 em {
  font-style: italic;
  color: var(--lat-accent);
}

#lattice .lattice-lead {
  margin: 12px 0 0;
  max-width: 58ch;
  font: 400 clamp(11px, 1.05cqw + 7px, 13.5px)/1.62 var(--sans);
  color: var(--lat-body);
}

#lattice .lattice-workbench {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1 1 auto;
  margin-top: 10px;
  gap: 9px;
}

#lattice .lattice-refine { flex: 0 0 auto; display: block; }

#lattice .lattice-refine-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  font: 500 8px/1 var(--mono);
  letter-spacing: .15em;
  color: var(--lat-muted);
}

#lattice .lattice-refine-head span { color: var(--lat-dim); letter-spacing: .08em; }
#lattice .lattice-refine-head b { font: 500 12px/1 var(--mono); color: var(--lat-accent-strong); font-variant-numeric: tabular-nums; }

#lattice .lattice-refine input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  width: 100%;
  max-width: none;
  height: 22px;
  margin: 2px 0 0;
  background: transparent;
  cursor: pointer;
  touch-action: pan-y;
}

#lattice .lattice-refine input[type="range"]::-webkit-slider-runnable-track {
  height: 2px;
  background: linear-gradient(90deg, var(--lat-accent) 0 var(--range, 13%), rgba(216, 230, 209, .18) var(--range, 13%) 100%);
  border-radius: 2px;
}

#lattice .lattice-refine input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 13px;
  height: 13px;
  margin-top: -5.5px;
  border: 1px solid #18241e;
  border-radius: 1px;
  background: var(--lat-accent);
  box-shadow: 0 0 0 4px rgba(216, 237, 168, .12);
  transform: rotate(45deg);
  transition: box-shadow .2s, background .2s;
}

#lattice .lattice-refine input[type="range"]:hover::-webkit-slider-thumb,
#lattice .lattice-refine input[type="range"]:focus-visible::-webkit-slider-thumb {
  background: var(--lat-accent-strong);
  box-shadow: 0 0 0 6px rgba(216, 237, 168, .18);
}

#lattice .lattice-refine input[type="range"]::-moz-range-track {
  height: 2px;
  background: rgba(216, 230, 209, .18);
}

#lattice .lattice-refine input[type="range"]::-moz-range-progress {
  height: 2px;
  background: var(--lat-accent);
}

#lattice .lattice-refine input[type="range"]::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border: 1px solid #18241e;
  border-radius: 1px;
  background: var(--lat-accent);
  transform: rotate(45deg);
}

#lattice .lattice-refine-scale {
  position: relative;
  height: 8px;
  margin-top: -5px;
  font: 400 7px/1 var(--mono);
  color: var(--lat-dim);
  letter-spacing: .1em;
}

#lattice .lattice-refine-scale span { position: absolute; top: 0; transform: translateX(-50%); }
#lattice .lattice-refine-scale span:nth-child(1) { left: 0; transform: none; }
#lattice .lattice-refine-scale span:nth-child(2) { left: 13.04%; }
#lattice .lattice-refine-scale span:nth-child(3) { left: 47.83%; }
#lattice .lattice-refine-scale span:nth-child(4) { left: 100%; transform: translateX(-100%); }

#lattice .lattice-figure {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

#lattice .lattice-diagram {
  position: relative;
  flex: 1 1 auto;
  min-height: 174px;
  border: 1px solid var(--lat-line);
  border-bottom-color: var(--lat-line-strong);
  background-color: rgba(8, 14, 11, .2);
  background-image:
    linear-gradient(rgba(197, 216, 199, .055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(197, 216, 199, .055) 1px, transparent 1px);
  background-size: 42px 34px;
  overflow: hidden;
}

#lattice .lattice-diagram::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at 70% 30%, rgba(216, 237, 168, .06), transparent 62%);
}

#lattice .lattice-diagram svg {
  position: absolute;
  inset: 0 0 12px;
  width: 100%;
  height: calc(100% - 12px);
  overflow: visible;
}

#lattice .lattice-curve {
  fill: none;
  stroke: var(--lat-accent);
  stroke-width: 2.2;
  vector-effect: non-scaling-stroke;
  filter: drop-shadow(0 0 6px rgba(216, 237, 168, .34));
}

#lattice .lattice-stair {
  fill: none;
  stroke: rgba(216, 237, 168, .56);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

#lattice .lattice-fill { fill: url(#latticeFillGrad); stroke: none; }

#lattice .lattice-axis {
  fill: none;
  stroke: rgba(216, 230, 209, .4);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

#lattice #latticeRects rect {
  fill: rgba(216, 237, 168, .17);
  stroke: rgba(216, 237, 168, .42);
  stroke-width: .6;
  shape-rendering: crispEdges;
  transition: fill .12s, stroke .12s;
  pointer-events: all;
}

#lattice #latticeRects rect.is-hot {
  fill: rgba(216, 237, 168, .48);
  stroke: var(--lat-accent);
}

#lattice .lattice-probe { opacity: 0; transition: opacity .15s; pointer-events: none; }
#lattice .lattice-probe.is-active { opacity: 1; }
#lattice .lattice-probe line { stroke: rgba(216, 237, 168, .55); stroke-width: 1; stroke-dasharray: 3 4; vector-effect: non-scaling-stroke; }
#lattice .lattice-probe circle { fill: var(--lat-accent); }

#lattice .lattice-diagram-fn,
#lattice .lattice-diagram-n,
#lattice .lattice-diagram-bound,
#lattice .lattice-diagram-tag {
  position: absolute;
  z-index: 2;
  pointer-events: none;
  font: 500 8px/1 var(--mono);
  letter-spacing: .08em;
  color: var(--lat-muted);
}

#lattice .lattice-diagram-fn {
  top: 9px;
  left: 10px;
  color: var(--lat-accent);
  background: rgba(10, 17, 13, .62);
  border: 1px solid var(--lat-line);
  padding: 4px 6px;
}

#lattice .lattice-diagram-n {
  top: 9px;
  right: 10px;
  color: var(--lat-sage);
  font-variant-numeric: tabular-nums;
}

#lattice .lattice-diagram-bound { bottom: 2px; color: var(--lat-dim); }
#lattice .lattice-bound-left { left: 4.2%; }
#lattice .lattice-bound-right { right: 2.8%; }

#lattice .lattice-diagram-tag {
  right: 10px;
  bottom: 2px;
  color: var(--lat-accent);
  letter-spacing: .06em;
}

#lattice .lattice-tooltip {
  position: absolute;
  z-index: 4;
  left: 0;
  top: 0;
  transform: translate(-50%, -100%);
  margin-top: -8px;
  padding: 5px 7px;
  border: 1px solid var(--lat-line-strong);
  background: #0c1410;
  color: var(--lat-sage);
  font: 400 7.5px/1.25 var(--mono);
  letter-spacing: .05em;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity .12s;
  font-variant-numeric: tabular-nums;
}

#lattice .lattice-tooltip.is-visible { opacity: 1; }
#lattice .lattice-tooltip b { color: var(--lat-accent); font-weight: 500; }

#lattice .lattice-area-row {
  display: flex;
  align-items: baseline;
  gap: 7px;
  flex: 0 0 auto;
  min-width: 0;
}

#lattice .lattice-area-label {
  font: 500 7.5px/1 var(--mono);
  letter-spacing: .14em;
  color: var(--lat-muted);
  white-space: nowrap;
}

#lattice .lattice-area-row > b {
  font: 500 clamp(20px, 2.1cqw, 27px)/1 var(--serif);
  color: var(--lat-accent-strong);
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
}

#lattice .lattice-area-row > em {
  font: 400 8px/1 var(--mono);
  font-style: normal;
  color: var(--lat-muted);
}

#lattice .lattice-exact {
  margin-left: auto;
  font: 400 8px/1 var(--mono);
  color: var(--lat-dim);
  white-space: nowrap;
}

#lattice .lattice-exact b { color: var(--lat-sage); font-weight: 500; font-variant-numeric: tabular-nums; }

#lattice .lattice-convergence {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  font: 500 7px/1 var(--mono);
  letter-spacing: .13em;
  color: var(--lat-dim);
}

#lattice .lattice-convergence > span { white-space: nowrap; }
#lattice .lattice-convergence > i { flex: 1 1 auto; height: 2px; background: rgba(216, 230, 209, .14); overflow: hidden; }
#lattice .lattice-convergence > i b { display: block; width: 75%; height: 100%; background: var(--lat-accent); transition: width .35s cubic-bezier(.2, .8, .2, 1); }
#lattice .lattice-convergence > em { font-style: normal; color: var(--lat-muted); min-width: 28px; text-align: right; font-variant-numeric: tabular-nums; }

#lattice .lattice-theory-foot {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px 14px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--lat-line);
}

#lattice .lattice-formula {
  font: 500 clamp(20px, 3.3cqw, 38px)/1 var(--serif);
  letter-spacing: -.03em;
  color: var(--lat-sage);
  white-space: nowrap;
}

#lattice .lattice-formula b { color: var(--lat-accent); margin: 0 .28em; font-weight: 400; }

#lattice .lattice-to-practice {
  display: flex;
  align-items: center;
  gap: 14px;
  flex: 0 0 auto;
  border: 1px solid var(--lat-line-strong);
  background: transparent;
  color: var(--lat-sage);
  padding: 10px 12px;
  font: 500 8px/1 var(--mono);
  letter-spacing: .12em;
  cursor: pointer;
  transition: background .2s, color .2s, border-color .2s;
}

#lattice .lattice-to-practice b { color: var(--lat-accent); font-weight: 500; transition: transform .2s; }
#lattice .lattice-to-practice:hover { background: var(--lat-accent); color: var(--lat-ink); border-color: var(--lat-accent); }
#lattice .lattice-to-practice:hover b { color: var(--lat-ink); transform: translateX(3px); }

/* ---------- focused presets: the two rooms of the lesson ---------- */

#lattice[data-layout="theory"] .lattice-theory-content {
  display: grid;
  grid-template-columns: minmax(0, .94fr) minmax(0, 1.06fr);
  grid-template-rows: auto auto 1fr auto;
  grid-template-areas:
    "kicker workbench"
    "title workbench"
    "lead workbench"
    "foot workbench";
  column-gap: clamp(34px, 4.4vw, 74px);
  padding: clamp(30px, 3.8vw, 62px);
}

#lattice[data-layout="theory"] .lattice-kicker { grid-area: kicker; }
#lattice[data-layout="theory"] .lattice-theory h1 {
  grid-area: title;
  font-size: clamp(46px, 5cqw, 78px);
  margin-top: 16px;
}
#lattice[data-layout="theory"] .lattice-lead { grid-area: lead; max-width: 44ch; font-size: 13px; margin-top: 20px; }
#lattice[data-layout="theory"] .lattice-workbench { grid-area: workbench; margin-top: 0; }
#lattice[data-layout="theory"] .lattice-diagram { min-height: 300px; }
#lattice[data-layout="theory"] .lattice-theory-foot {
  grid-area: foot;
  margin-top: auto;
  padding-top: 20px;
  flex-direction: column;
  align-items: flex-start;
  gap: 18px;
}
#lattice[data-layout="theory"] .lattice-formula { font-size: clamp(26px, 3.4cqw, 48px); }
#lattice[data-layout="theory"] .lattice-to-practice { padding: 12px 16px; }

#lattice[data-layout="practice"] .lattice-practice-content {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(310px, .82fr);
  grid-template-rows: auto auto auto auto auto auto auto auto;
  grid-template-areas:
    "step scratch"
    "dots scratch"
    "question scratch"
    "answer scratch"
    "actions scratch"
    "hint scratch"
    "result result"
    "foot foot";
  column-gap: clamp(30px, 4.4vw, 72px);
  padding: clamp(28px, 3.4vw, 54px);
}

#lattice[data-layout="practice"] .lattice-step { grid-area: step; }
#lattice[data-layout="practice"] .lattice-progress-dots { grid-area: dots; }
#lattice[data-layout="practice"] .lattice-practice h2 { grid-area: question; font-size: clamp(40px, 4.6cqw, 68px); margin-top: 20px; max-width: 100%; }
#lattice[data-layout="practice"] .lattice-answer-zone { display: contents; }
#lattice[data-layout="practice"] .lattice-input-row { grid-area: answer; align-self: start; margin-top: 16px; }
#lattice[data-layout="practice"] .lattice-actions { grid-area: actions; margin-top: 18px; padding-top: 0; }
#lattice[data-layout="practice"] .lattice-result { grid-area: result; margin-top: 16px; max-width: 760px; }
#lattice[data-layout="practice"] .lattice-practice-foot { grid-area: foot; margin-top: 16px; }

#lattice[data-layout="practice"] .lattice-scratch {
  grid-area: scratch;
  display: flex;
  flex-direction: column;
  margin-top: 0;
  padding: 17px 19px 14px;
  border: 1px solid rgba(20, 32, 26, .18);
  background: rgba(255, 255, 255, .2);
}

#lattice[data-layout="practice"] .lattice-scratch label { font-size: 7.5px; }
#lattice[data-layout="practice"] .lattice-scratch textarea {
  flex: 1 1 auto;
  height: auto;
  min-height: 210px;
  margin-top: 8px;
}
#lattice[data-layout="practice"] .lattice-scratch-tools { margin-top: 9px; }
#lattice[data-layout="practice"] .lattice-hint-card { grid-area: hint; align-self: start; margin-top: 14px; }

#lattice[data-layout="practice"] .lattice-check-button { max-width: 380px; }
#lattice[data-layout="practice"] .lattice-actions { justify-content: flex-start; }
#lattice[data-layout="practice"] .lattice-hint-button { min-width: 170px; }

/* the lesson is assembled: let the empty paper breathe */

#lattice .lattice-practice-content.is-complete,
#lattice[data-layout="practice"] .lattice-practice-content.is-complete {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: auto auto minmax(0, 1fr) auto auto;
  grid-template-areas: none;
  align-content: stretch;
}

#lattice .lattice-practice-content.is-complete .lattice-step { grid-area: auto; grid-row: 1; grid-column: 1; }
#lattice .lattice-practice-content.is-complete .lattice-progress-dots { grid-area: auto; grid-row: 2; grid-column: 1; }
#lattice .lattice-practice-content.is-complete h2 {
  grid-area: auto;
  grid-row: 3;
  grid-column: 1;
  align-self: center;
  justify-self: center;
  margin: 0;
  font-size: clamp(52px, 7.4cqw, 92px);
  line-height: .86;
  text-align: center;
}
#lattice .lattice-practice-content.is-complete h2::before {
  content: "✓";
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  margin: 0 auto 22px;
  border: 1px solid var(--lat-success);
  border-radius: 50%;
  background: var(--lat-success-bg);
  color: var(--lat-success);
  font: 500 21px/1 var(--mono);
}
#lattice .lattice-practice-content.is-complete h2 em { color: var(--lat-success); text-decoration: none; }
#lattice .lattice-practice-content.is-complete .lattice-actions {
  grid-area: auto;
  grid-row: 4;
  grid-column: 1;
  justify-content: center;
  margin-top: 0;
  padding-top: 18px;
}
#lattice .lattice-practice-content.is-complete .lattice-result {
  grid-area: auto;
  grid-row: 5;
  grid-column: 1;
  justify-self: center;
  width: 100%;
  margin-top: 12px;
  max-width: 480px;
}
#lattice[data-layout="practice"] .lattice-practice-content.is-complete .lattice-scratch,
#lattice[data-layout="practice"] .lattice-practice-content.is-complete .lattice-hint-card { display: none; }

/* ---------- divider: the magnetic seam ---------- */

#lattice .lattice-divider {
  position: relative;
  z-index: 5;
  width: 30px;
  flex: 0 0 30px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--lat-muted);
  cursor: ew-resize;
  touch-action: none;
  outline: none;
  transition: color .2s;
}

#lattice .lattice-seam {
  width: 1px;
  flex: 1 1 auto;
  min-height: 18px;
  background: linear-gradient(180deg, transparent, var(--lat-line-strong) 14%, var(--lat-line-strong) 86%, transparent);
  transition: background .2s;
}

#lattice .lattice-divider-hint {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  writing-mode: horizontal-tb;
  font: 500 7px/1 var(--mono);
  letter-spacing: .12em;
  white-space: nowrap;
  color: var(--lat-accent);
  background: #0e1712;
  border: 1px solid var(--lat-line);
  padding: 3px 5px;
  pointer-events: none;
  transition: color .2s, border-color .2s;
}

#lattice .lattice-divider-keys {
  display: flex;
  gap: 2px;
  color: var(--lat-dim);
  transition: color .2s;
}

#lattice .lattice-divider-keys kbd {
  font: 400 6px/1 var(--mono);
  border: 1px solid var(--lat-line-strong);
  padding: 2px 3px;
  border-radius: 1px;
}

#lattice .lattice-grip {
  position: relative;
  z-index: 2;
  writing-mode: horizontal-tb;
  width: 48px;
  min-height: 72px;
  padding: 10px 5px 7px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: #16221c;
  border: 1px solid var(--lat-line-strong);
  border-radius: 2px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .22);
  transition: background .2s, border-color .2s, color .2s, box-shadow .25s, transform .2s;
}

#lattice .lattice-grip-dots {
  display: grid;
  grid-template-columns: repeat(2, 4px);
  gap: 4px;
}

#lattice .lattice-grip-dots i {
  width: 4px;
  height: 4px;
  background: var(--lat-muted);
  border-radius: 50%;
  transition: background .2s;
}

#lattice .lattice-divider-value {
  font: 500 8px/1 var(--mono);
  letter-spacing: .03em;
  color: var(--lat-sage);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  transition: color .2s;
}

#lattice .lattice-divider:hover .lattice-grip,
#lattice .lattice-divider:focus-visible .lattice-grip,
#lattice .lattice-divider.is-near .lattice-grip {
  background: #223229;
  border-color: var(--lat-accent);
  box-shadow: 0 0 0 1px rgba(216, 237, 168, .16), 0 10px 28px rgba(0, 0, 0, .3);
}

#lattice .lattice-divider:hover .lattice-grip-dots i,
#lattice .lattice-divider:focus-visible .lattice-grip-dots i,
#lattice .lattice-divider.is-near .lattice-grip-dots i { background: var(--lat-accent); }

#lattice .lattice-divider:hover .lattice-divider-hint,
#lattice .lattice-divider:focus-visible .lattice-divider-hint { color: var(--lat-accent); }

#lattice .lattice-divider.is-dragging .lattice-grip {
  background: var(--lat-accent);
  border-color: var(--lat-accent);
  color: var(--lat-ink);
}

#lattice .lattice-divider.is-dragging .lattice-grip-dots i { background: var(--lat-ink); }
#lattice .lattice-divider.is-dragging .lattice-divider-value { color: var(--lat-ink); }
#lattice .lattice-divider.is-dragging .lattice-seam { background: linear-gradient(180deg, transparent, var(--lat-accent) 10%, var(--lat-accent) 90%, transparent); }

#lattice .lattice-divider.is-pulsing .lattice-grip { animation: lattice-seam-pulse .5s cubic-bezier(.2, .8, .2, 1); }

#lattice .lattice-divider:focus-visible { outline: 2px solid var(--lat-accent-strong); outline-offset: 3px; border-radius: 2px; }

#lattice.is-dragging { user-select: none; }
#lattice.is-dragging .lattice-theory,
#lattice.is-dragging .lattice-practice { transition: none; }
#lattice.is-dragging .lattice-grid { opacity: .5; }

/* ---------- practice ---------- */

#lattice .lattice-watermark {
  position: absolute;
  z-index: 1;
  right: 18px;
  bottom: 18px;
  font: 500 clamp(66px, 9.5cqw, 132px)/.8 var(--serif);
  font-variation-settings: "opsz" 100;
  letter-spacing: -.07em;
  white-space: nowrap;
  color: rgba(20, 32, 26, .046);
  pointer-events: none;
  user-select: none;
}

#lattice .lattice-practice-content {
  position: relative;
  z-index: 2;
  height: calc(100% - 46px);
  padding: clamp(22px, 2.6vw, 38px);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(20, 32, 26, .28) transparent;
}

#lattice .lattice-practice-content::-webkit-scrollbar { width: 6px; }
#lattice .lattice-practice-content::-webkit-scrollbar-thumb { background: rgba(20, 32, 26, .24); }

#lattice .lattice-step {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  font: 500 8.5px/1 var(--mono);
  letter-spacing: .13em;
  color: #526258;
}

#lattice .lattice-step > div { display: flex; align-items: baseline; flex-wrap: wrap; gap: 5px 10px; }
#lattice .lattice-step span { color: var(--lat-ink); }

#lattice .lattice-step em {
  font-style: normal;
  color: #56665c;
  font-size: 7.5px;
  letter-spacing: .1em;
}

#lattice .lattice-step > b {
  flex: 0 0 auto;
  color: var(--lat-success);
  background: rgba(47, 101, 78, .08);
  border: 1px solid rgba(47, 101, 78, .2);
  padding: 5px 7px;
  font: 500 8px/1 var(--mono);
  letter-spacing: .06em;
  font-variant-numeric: tabular-nums;
  transition: background .2s, color .2s;
}

#lattice .lattice-step > b.is-discounted { color: var(--lat-warn); background: var(--lat-warn-bg); border-color: rgba(122, 91, 46, .3); }

#lattice .lattice-progress-dots {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
  margin: 14px 0 0;
}

#lattice .lattice-progress-step {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: baseline;
  gap: 6px;
  padding-top: 7px;
  border-top: 2px solid rgba(20, 32, 26, .18);
  color: #56665c;
  font: 500 7px/1 var(--mono);
  letter-spacing: .12em;
  transition: border-color .25s, color .25s;
}

#lattice .lattice-progress-step b { font: 500 7.5px/1 var(--mono); color: #56665c; transition: color .25s; }
#lattice .lattice-progress-step em { font-style: normal; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#lattice .lattice-progress-step.is-done { border-top-color: var(--lat-success); color: var(--lat-success); }
#lattice .lattice-progress-step.is-done b { color: var(--lat-success); }
#lattice .lattice-progress-step.is-active { border-top-color: var(--lat-ink); color: var(--lat-ink); }
#lattice .lattice-progress-step.is-active b { color: var(--lat-ink); }

#lattice .lattice-practice h2 {
  flex: 0 0 auto;
  font: 500 clamp(30px, 6.2cqw, 56px)/.95 var(--serif);
  font-variation-settings: "opsz" 90;
  letter-spacing: -.045em;
  color: var(--lat-ink);
  margin: clamp(16px, 2.6vw, 26px) 0 0;
  max-width: 15ch;
  transition: opacity .18s ease, transform .22s ease;
}

#lattice .lattice-practice h2 em {
  font-style: italic;
  color: #4c675a;
  text-decoration: underline;
  text-decoration-color: rgba(91, 120, 74, .42);
  text-decoration-thickness: 1px;
  text-underline-offset: 5px;
}

#lattice .lattice-practice h2.is-swapping { opacity: 0; transform: translateY(8px); }

#lattice .lattice-answer-zone { flex: 0 0 auto; }

#lattice .lattice-input-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  margin-top: 12px;
  border-bottom: 1px solid var(--lat-ink);
  transition: box-shadow .2s, border-color .2s;
}

#lattice .lattice-input-row:focus-within { border-bottom-color: var(--lat-ink); box-shadow: 0 1px 0 var(--lat-ink); }

#lattice .lattice-input-row input {
  width: 100%;
  min-width: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  outline: 0;
  color: var(--lat-ink);
  font: 500 clamp(56px, 10cqw, 98px)/.9 var(--serif);
  font-variation-settings: "opsz" 100;
  letter-spacing: -.02em;
  padding: 0 0 3px;
  font-variant-numeric: tabular-nums;
}

#lattice .lattice-input-row input::placeholder { color: #74837a; opacity: 1; }
#lattice .lattice-input-row input:focus-visible { outline: 2px solid #1f3a2d; outline-offset: 5px; border-radius: 2px; }

#lattice .lattice-input-row > span {
  flex: 0 0 auto;
  padding-bottom: 16px;
  font: 500 8px/1 var(--mono);
  letter-spacing: .1em;
  color: #526258;
}

#lattice .lattice-input-mark {
  width: 21px;
  height: 21px;
  flex: 0 0 auto;
  margin-bottom: 13px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(20, 32, 26, .25);
  border-radius: 50%;
  font: 500 11px/1 var(--mono);
  font-style: normal;
  color: transparent;
  transition: background .2s, border-color .2s, color .2s, transform .2s;
}

#lattice .lattice-input-row.is-correct { border-bottom-color: var(--lat-success); box-shadow: 0 1px 0 var(--lat-success); }
#lattice .lattice-input-row.is-correct .lattice-input-mark { background: var(--lat-success); border-color: var(--lat-success); color: var(--lat-paper); content: "✓"; }
#lattice .lattice-input-row.is-wrong { border-bottom-color: var(--lat-error); box-shadow: 0 1px 0 var(--lat-error); }
#lattice .lattice-input-row.is-wrong .lattice-input-mark { background: var(--lat-error); border-color: var(--lat-error); color: var(--lat-paper); }
#lattice .lattice-input-row.is-correct .lattice-input-mark::after { content: "✓"; }
#lattice .lattice-input-row.is-wrong .lattice-input-mark::after { content: "×"; }

#lattice .lattice-input-row.is-wrong { animation: lattice-shake .34s ease; }

#lattice .lattice-hint-card {
  margin-top: 13px;
  padding: 11px 13px 12px;
  background: rgba(255, 255, 255, .34);
  border: 1px solid rgba(20, 32, 26, .18);
  border-left: 3px solid var(--lat-success);
  animation: lattice-card-in .26s cubic-bezier(.2, .8, .2, 1) both;
}

#lattice .lattice-hint-card span {
  font: 500 7px/1 var(--mono);
  letter-spacing: .14em;
  color: var(--lat-success);
}

#lattice .lattice-hint-card p {
  margin: 5px 0 0;
  font: 400 11.5px/1.5 var(--sans);
  color: var(--lat-ink-soft);
}

#lattice .lattice-scratch {
  flex: 0 0 auto;
  margin-top: 16px;
  display: block;
}

#lattice .lattice-scratch label {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font: 500 7px/1 var(--mono);
  letter-spacing: .14em;
  color: #56665c;
}

#lattice .lattice-scratch label span { color: #56665c; letter-spacing: .08em; }

#lattice .lattice-scratch textarea {
  width: 100%;
  height: 58px;
  margin-top: 4px;
  padding: 2px 2px 4px;
  border: 0;
  border-bottom: 1px solid rgba(20, 32, 26, .26);
  border-radius: 0;
  background: transparent;
  background-image: repeating-linear-gradient(180deg, transparent 0 21px, rgba(20, 32, 26, .12) 21px 22px);
  resize: none;
  outline: 0;
  color: var(--lat-ink);
  font: 400 12px/22px var(--mono);
}

#lattice .lattice-scratch textarea::placeholder { color: #5a6a60; }
#lattice .lattice-scratch textarea:focus-visible { outline: 2px solid #1f3a2d; outline-offset: 3px; border-radius: 2px; border-bottom-color: var(--lat-ink); }

#lattice .lattice-scratch-tools {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 5px;
}

#lattice .lattice-scratch-tools > span {
  margin-right: 4px;
  font: 500 6.5px/1 var(--mono);
  letter-spacing: .12em;
  color: #56665c;
}

#lattice .lattice-scratch-tools button {
  min-width: 24px;
  height: 21px;
  padding: 0 5px;
  border: 1px solid rgba(20, 32, 26, .18);
  background: transparent;
  color: #526258;
  font: 500 9px/1 var(--mono);
  cursor: pointer;
  transition: background .18s, color .18s, border-color .18s;
}

#lattice .lattice-scratch-tools button:hover { background: var(--lat-ink); border-color: var(--lat-ink); color: var(--lat-paper); }
#lattice .lattice-scratch-tools .lattice-scratch-clear { margin-left: auto; color: #56665c; font-size: 6.5px; letter-spacing: .1em; }

#lattice .lattice-actions {
  flex: 0 0 auto;
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 9px;
  margin-top: 16px;
  padding-top: 0;
}

#lattice .lattice-actions button {
  border: 1px solid rgba(20, 32, 26, .34);
  background: transparent;
  color: var(--lat-ink-soft);
  padding: 12px 14px;
  font: 500 8px/1 var(--mono);
  letter-spacing: .1em;
  cursor: pointer;
  transition: background .2s, color .2s, border-color .2s, transform .15s;
}

#lattice .lattice-actions button:hover { background: rgba(20, 32, 26, .08); color: var(--lat-ink); }
#lattice .lattice-actions button:active { transform: translateY(1px); }

#lattice .lattice-hint-button span { color: #56665c; margin-left: 4px; }
#lattice .lattice-hint-button.is-open { border-color: rgba(47, 101, 78, .4); color: var(--lat-success); }

#lattice .lattice-check-button {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  background: var(--lat-ink);
  border-color: var(--lat-ink);
  color: var(--lat-paper);
  text-align: left;
}

#lattice .lattice-check-button b { font-weight: 500; font-size: 13px; line-height: 0; transition: transform .2s; }
#lattice .lattice-check-button:hover { background: #263b31; border-color: #263b31; color: #f1f3e9; }
#lattice .lattice-check-button:hover b { transform: translateX(4px); }
#lattice .lattice-check-button.is-next { background: var(--lat-success); border-color: var(--lat-success); }
#lattice .lattice-check-button:disabled { opacity: .45; cursor: default; }

#lattice .lattice-result {
  position: relative;
  flex: 0 0 auto;
  min-height: 44px;
  margin: 14px 0 0;
  padding: 8px 0 8px 20px;
  border-top: 1px solid rgba(20, 32, 26, .14);
  font: 400 11.5px/1.55 var(--sans);
  color: #526258;
  transition: color .2s, background .2s, border-color .2s, padding .2s;
}

#lattice .lattice-result::before {
  content: "→";
  position: absolute;
  left: 0;
  top: 7px;
  font: 500 10px/1.5 var(--mono);
  color: #56665c;
}

#lattice .lattice-result.ok {
  color: var(--lat-success);
  background: var(--lat-success-bg);
  border-top-color: transparent;
  border-left: 2px solid var(--lat-success);
  padding: 10px 12px 10px 30px;
}

#lattice .lattice-result.ok::before { content: "✓"; left: 11px; top: 9px; color: var(--lat-success); }

#lattice .lattice-result.bad {
  color: var(--lat-error);
  background: var(--lat-error-bg);
  border-top-color: transparent;
  border-left: 2px solid var(--lat-error);
  padding: 10px 12px 10px 30px;
}

#lattice .lattice-result.bad::before { content: "!"; left: 12px; top: 9px; color: var(--lat-error); }

#lattice .lattice-result.hint { color: var(--lat-ink-soft); }

#lattice .lattice-result b { font-weight: 700; }

#lattice .lattice-practice-foot {
  flex: 0 0 auto;
  display: flex;
  justify-content: space-between;
  gap: 14px;
  margin-top: 12px;
  padding-top: 9px;
  border-top: 1px solid rgba(20, 32, 26, .14);
  font: 400 7px/1.2 var(--mono);
  letter-spacing: .11em;
  color: #56665c;
}

#lattice .lattice-practice-foot kbd {
  font: 400 6.5px/1 var(--mono);
  border: 1px solid rgba(20, 32, 26, .25);
  border-radius: 1px;
  padding: 2px 3px;
}

#lattice .lattice-practice-foot em { font-style: normal; }

#lattice .lattice-practice-content.is-complete .lattice-answer-zone,
#lattice .lattice-practice-content.is-complete .lattice-scratch,
#lattice .lattice-practice-content.is-complete .lattice-practice-foot { display: none; }

#lattice .lattice-practice-content.is-complete .lattice-actions { justify-content: center; }
#lattice .lattice-practice-content.is-complete .lattice-hint-button { display: none; }
#lattice .lattice-practice-content.is-complete .lattice-check-button { flex: 0 0 auto; min-width: 190px; }
#lattice .lattice-practice-content.is-complete .lattice-result { margin-top: 12px; }

/* ---------- footer ---------- */

#lattice .lattice-footer {
  position: absolute;
  z-index: 6;
  left: 22px;
  right: 22px;
  bottom: 11px;
  height: 32px;
  display: flex;
  align-items: center;
  gap: 12px;
  font: 500 7px/1 var(--mono);
  letter-spacing: .13em;
  color: var(--lat-muted);
}

#lattice .lattice-footer > span { white-space: nowrap; }
#lattice .lattice-footer > span i { font-style: normal; color: var(--lat-dim); margin: 0 3px; }

#lattice .lattice-footer > b.lattice-footer-track {
  width: 170px;
  height: 3px;
  flex: 0 0 auto;
  background: rgba(197, 216, 199, .16);
  overflow: hidden;
}

#lattice .lattice-footer > b.lattice-footer-track i {
  display: block;
  width: var(--p, 0%);
  height: 100%;
  background: var(--lat-accent);
  transition: width .45s cubic-bezier(.2, .8, .2, 1);
}

#lattice .lattice-footer > em {
  font-style: normal;
  color: var(--lat-sage);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

#lattice .lattice-footer > p { margin: 0 0 0 auto; color: var(--lat-dim); white-space: nowrap; }
#lattice .lattice-footer > p b { font-weight: 500; color: var(--lat-accent); }
#lattice .lattice-footer kbd {
  font: 400 6.5px/1 var(--mono);
  border: 1px solid var(--lat-line-strong);
  padding: 2px 3px;
  border-radius: 1px;
  margin: 0 1px;
}

/* ---------- focus ---------- */

#lattice button:focus-visible,
#lattice input:focus-visible,
#lattice textarea:focus-visible,
#lattice [tabindex]:focus-visible {
  outline: 2px solid var(--lat-accent-strong);
  outline-offset: 3px;
}

#lattice .lattice-practice button:focus-visible,
#lattice .lattice-practice input:focus-visible,
#lattice .lattice-practice textarea:focus-visible {
  outline-color: #1f3a2d;
}

#lattice .lattice-presets button.active:focus-visible { outline-color: #14201a; outline-offset: 2px; }
#lattice .lattice-tabs button:focus-visible { outline-offset: -3px; }
#lattice .lattice-tabs button[aria-selected="true"]:focus-visible { outline-color: #14201a; }

/* ---------- container adaptations ---------- */

@container lattice-theory (max-width: 470px) {
  #lattice .lattice-kicker em { display: none; }
  #lattice .lattice-theory h1 { font-size: clamp(29px, 9.4cqw, 46px); }
  #lattice .lattice-lead { font-size: 11px; line-height: 1.55; }
  #lattice .lattice-theory-foot { align-items: center; }
  #lattice .lattice-formula { font-size: clamp(17px, 4.6cqw, 26px); }
  #lattice .lattice-to-practice { padding: 9px 10px; }
}

@container lattice-theory (max-width: 340px) {
  #lattice .lattice-diagram { min-height: 165px; }
  #lattice .lattice-theory-foot { margin-top: 8px; padding-top: 9px; }
}

@container lattice-practice (max-width: 490px) {
  #lattice .lattice-practice h2 { font-size: clamp(28px, 7.4cqw, 40px); }
  #lattice .lattice-input-row input { font-size: clamp(52px, 14cqw, 78px); }
  #lattice .lattice-practice-foot em { display: none; }
}

/* ---------- animation ---------- */

@keyframes lattice-seam-pulse {
  0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(216, 237, 168, .45); }
  55% { transform: scale(1.05); box-shadow: 0 0 0 8px rgba(216, 237, 168, 0); }
  100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(216, 237, 168, 0); }
}

@keyframes lattice-panel-flash {
  0% { box-shadow: inset 0 0 0 1px rgba(216, 237, 168, 0); }
  30% { box-shadow: inset 0 0 0 1px rgba(216, 237, 168, .55); }
  100% { box-shadow: inset 0 0 0 1px rgba(216, 237, 168, 0); }
}

@keyframes lattice-shake {
  0%, 100% { transform: translateX(0); }
  22% { transform: translateX(-5px); }
  44% { transform: translateX(4px); }
  66% { transform: translateX(-3px); }
  84% { transform: translateX(2px); }
}

@keyframes lattice-card-in {
  from { opacity: 0; transform: translateY(-5px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- tablet / mobile: tabs, both panels preserved ---------- */

@media (max-width: 900px) {
  #lattice.lattice-concept {
    height: calc(100vh - 64px);
    height: calc(100dvh - 64px);
    min-height: 620px;
  }

  #lattice .lattice-head {
    height: 60px;
    padding: 0 14px;
    grid-template-columns: minmax(0, 1fr) auto;
  }

  #lattice .lattice-headline {
    justify-self: end;
    display: flex;
    gap: 0;
    padding: 5px 7px;
    border: 1px solid var(--lat-line-strong);
    background: rgba(13, 20, 16, .4);
  }

  #lattice .lattice-headline::before,
  #lattice .lattice-headline::after { display: none; }
  #lattice .lattice-headline span { display: none; }
  #lattice .lattice-headline b { padding: 3px 1px; background: transparent; color: var(--lat-accent); font-size: 9px; }

  #lattice .lattice-presets { display: none; }

  #lattice .lattice-space {
    inset: 70px 10px 10px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  #lattice .lattice-tabs {
    flex: 0 0 46px;
    height: 46px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    border: 1px solid var(--lat-line);
    border-bottom: 0;
    background: rgba(10, 17, 13, .72);
  }

  #lattice .lattice-tabs button {
    position: relative;
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 8px;
    border: 0;
    border-right: 1px solid var(--lat-line);
    background: transparent;
    color: var(--lat-muted);
    padding: 0 13px;
    text-align: left;
    cursor: pointer;
    transition: background .2s, color .2s;
  }

  #lattice .lattice-tabs button:last-child { border-right: 0; }
  #lattice .lattice-tabs button span { font: 400 7px/1 var(--mono); color: var(--lat-dim); }
  #lattice .lattice-tabs button b { font: 500 8.5px/1 var(--mono); letter-spacing: .11em; }
  #lattice .lattice-tabs button em { font: 400 7px/1 var(--mono); font-style: normal; color: var(--lat-dim); justify-self: end; }

  #lattice .lattice-tabs button[aria-selected="true"] {
    color: var(--lat-ink);
    background: var(--lat-accent);
  }

  #lattice .lattice-tabs button[aria-selected="true"] span,
  #lattice .lattice-tabs button[aria-selected="true"] em { color: rgba(20, 32, 26, .74); }

  #lattice .lattice-tabs button[aria-selected="true"]::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: -1px;
    height: 1px;
    background: var(--lat-accent);
  }

  #lattice .lattice-theory,
  #lattice .lattice-practice {
    width: 100% !important;
    flex: 1 1 auto;
    min-height: 0;
    border: 1px solid var(--lat-line);
    border-top: 0;
  }

  #lattice .lattice-practice { border-color: rgba(20, 32, 26, .28); }

  #lattice .lattice-divider { display: none; }

  #lattice[data-mobile-view="theory"] .lattice-practice { display: none; }
  #lattice[data-mobile-view="practice"] .lattice-theory { display: none; }

  #lattice .lattice-theory-content,
  #lattice .lattice-practice-content {
    height: calc(100% - 44px);
    padding: 20px 16px 18px;
    overflow-y: auto;
  }

  #lattice .lattice-label { height: 44px; padding: 0 12px; }

  #lattice .lattice-theory h1 {
    font-size: clamp(34px, 9vw, 56px);
    margin-top: 18px;
    max-width: 100%;
  }

  #lattice .lattice-lead { font-size: 12px; line-height: 1.6; max-width: 46ch; }

  #lattice .lattice-diagram { flex: 1 1 auto; height: auto; min-height: 180px; }

  #lattice .lattice-theory-foot { margin-top: 14px; }

  #lattice .lattice-practice h2 { font-size: clamp(30px, 7vw, 46px); margin-top: 17px; }
  #lattice .lattice-input-row input { font-size: clamp(58px, 13vw, 90px); }
  #lattice .lattice-actions { padding-top: 14px; }
  #lattice .lattice-actions button { padding: 13px 13px; }
  #lattice .lattice-practice-foot { display: none; }

  #lattice .lattice-footer { display: none; }
}

@media (max-width: 420px) {
  #lattice .lattice-brand-text em { display: none; }
  #lattice .lattice-brand-text b { font-size: 9px; }
  #lattice .lattice-tabs button { padding: 0 10px; gap: 6px; }
  #lattice .lattice-theory-content,
  #lattice .lattice-practice-content { padding: 18px 14px 16px; }
  #lattice .lattice-theory h1 { font-size: clamp(33px, 10.4vw, 44px); }
  #lattice .lattice-step { font-size: 8px; }
  #lattice .lattice-actions { gap: 7px; }
  #lattice .lattice-actions button { font-size: 7.5px; padding: 12px 10px; }
  #lattice .lattice-check-button { gap: 10px; }
  #lattice .lattice-result { font-size: 11px; }
  #lattice .lattice-area-row > b { font-size: 22px; }
  #lattice .lattice-exact { font-size: 7.5px; }
}

/* ---------- short desktop viewports ---------- */

@media (min-width: 901px) and (max-height: 830px) {
  #lattice .lattice-head { height: 58px; }
  #lattice .lattice-space { inset: 68px 18px 48px; }
  #lattice .lattice-theory-content,
  #lattice .lattice-practice-content { padding: 22px 26px; }
  #lattice .lattice-theory h1 { font-size: clamp(31px, 8.4cqw, 56px); margin-top: 14px; }
  #lattice .lattice-lead { font-size: 11.5px; line-height: 1.55; margin-top: 11px; }
  #lattice .lattice-diagram { min-height: 150px; }
  #lattice .lattice-theory-foot { margin-top: 9px; padding-top: 9px; }
  #lattice .lattice-formula { font-size: clamp(18px, 2.8cqw, 30px); }
  #lattice .lattice-footer { bottom: 8px; height: 28px; }
  #lattice .lattice-practice h2 { margin-top: 15px; }
  #lattice .lattice-step { font-size: 8px; }
  #lattice .lattice-result { margin-top: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  #lattice *,
  #lattice *::before,
  #lattice *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}
