:root {
  --bg: #0d1113;
  --surface: #171c20;
  --surface-2: #20262c;
  --line: #364049;
  --text: #f5f7f8;
  --muted: #aeb8c1;
  --green: #5ee0a0;
  --blue: #68b9ff;
  --yellow: #ffd166;
  --red: #ff7474;
  --ink: #0d1113;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  line-height: 1.6;
}

a { color: var(--blue); }

button,
input,
select { font: inherit; }

button:focus-visible,
input:focus-visible,
select:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(104, 185, 255, .42);
  outline-offset: 3px;
}

.page {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 22px 20px 58px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 54px;
  margin-bottom: 26px;
  border-bottom: 1px solid var(--line);
}

.topbar a {
  color: var(--text);
  font-weight: 850;
  text-decoration: none;
}

.topbar span { color: var(--muted); }

.lesson-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 24px;
  align-items: end;
  padding-bottom: 28px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--green);
  font-size: .78rem;
  font-weight: 900;
  text-transform: uppercase;
}

h1,
h2,
h3,
p { margin-top: 0; }

h1 {
  max-width: 820px;
  margin-bottom: 10px;
  font-size: clamp(2rem, 4vw, 3.5rem);
  line-height: 1.04;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 14px;
  font-size: 1.45rem;
  letter-spacing: 0;
}

h3 {
  margin-bottom: 8px;
  font-size: 1rem;
  letter-spacing: 0;
}

p { color: var(--muted); }

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  font-weight: 800;
  white-space: nowrap;
}

.band {
  min-width: 0;
  padding: 28px 0;
  border-top: 1px solid var(--line);
}

.two-col {
  display: grid;
  grid-template-columns: minmax(0, 1.02fr) minmax(320px, .98fr);
  gap: 30px;
  align-items: start;
}

.lead {
  max-width: 820px;
  color: #d5dce2;
  font-size: 1.04rem;
}

.concept-list,
.sources {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.concept-list li {
  padding: 11px 0 11px 16px;
  border-left: 3px solid var(--blue);
  color: var(--muted);
}

.concept-list strong { color: var(--text); }

.source-figure {
  margin: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.source-figure img {
  display: block;
  width: 100%;
  max-height: 520px;
  object-fit: contain;
}

.source-figure figcaption {
  padding: 11px 14px;
  border-top: 1px solid #d7dde2;
  background: #eef2f5;
  color: #3f4b55;
  font-size: .8rem;
}

.formula {
  margin: 14px 0;
  padding: 13px 16px;
  overflow-x: auto;
  border-left: 3px solid var(--yellow);
  background: #211f17;
  color: #f7e8ad;
  font: 800 .98rem/1.65 Consolas, "Courier New", monospace;
}

.fact-check {
  padding: 14px 16px;
  border: 1px solid #456a5a;
  border-radius: 7px;
  background: #15251e;
  color: var(--muted);
}

.fact-check strong { color: var(--green); }

.warning {
  padding: 14px 16px;
  border-left: 3px solid var(--red);
  background: #2a1d20;
  color: var(--muted);
}

.geometry-lab {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.lab-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 15px 17px;
  border-bottom: 1px solid var(--line);
}

.lab-head h2 { margin: 0; font-size: 1.08rem; }

.lab-result {
  color: var(--yellow);
  font-family: Consolas, "Courier New", monospace;
  font-weight: 900;
}

.lab-result.ok { color: var(--green); }
.lab-result.no { color: var(--red); }

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}

.field {
  display: grid;
  gap: 4px;
  min-width: 96px;
}

.field span {
  color: var(--muted);
  font-size: .72rem;
  font-weight: 800;
}

.field input,
.field select,
.controls select {
  width: 112px;
  min-height: 42px;
  padding: 7px 9px;
  border: 1px solid #56616d;
  border-radius: 6px;
  background: #111519;
  color: var(--text);
}

.field.wide { min-width: 220px; flex: 1 1 260px; }
.field.wide select { width: 100%; }

.controls button {
  min-width: 42px;
  min-height: 42px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #2b333a;
  color: var(--text);
  cursor: pointer;
  font-weight: 850;
}

.controls button:hover { border-color: var(--blue); }
.controls button.primary { border-color: var(--green); background: var(--green); color: var(--ink); }

.geometry-stage {
  position: relative;
  min-height: 360px;
  padding: 18px;
  overflow: hidden;
  background-color: #11171b;
  background-image:
    linear-gradient(#242d33 1px, transparent 1px),
    linear-gradient(90deg, #242d33 1px, transparent 1px);
  background-size: 28px 28px;
}

.geometry-stage svg {
  display: block;
  width: 100%;
  height: 360px;
}

.geometry-stage circle,
.geometry-stage line,
.geometry-stage path,
.geometry-stage rect { vector-effect: non-scaling-stroke; }

.shape-primary { fill: rgba(104, 185, 255, .15); stroke: var(--blue); stroke-width: 3; }
.shape-secondary { fill: rgba(255, 209, 102, .15); stroke: var(--yellow); stroke-width: 3; }
.shape-secondary.ok { fill: rgba(94, 224, 160, .18); stroke: var(--green); }
.shape-secondary.no { fill: rgba(255, 116, 116, .18); stroke: var(--red); }
.guide { fill: none; stroke: #d7e3ed; stroke-width: 2; stroke-dasharray: 7 6; }
.measure { fill: none; stroke: var(--yellow); stroke-width: 4; }
.geometry-label { fill: #f5f7f8; font: 800 16px Inter, Arial, sans-serif; paint-order: stroke; stroke: #11171b; stroke-width: 5px; }

.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border-top: 1px solid var(--line);
}

.metric {
  min-width: 0;
  padding: 13px 15px;
}

.metric + .metric { border-left: 1px solid var(--line); }
.metric span { display: block; color: var(--muted); font-size: .71rem; font-weight: 800; text-transform: uppercase; }
.metric strong { display: block; overflow-wrap: anywhere; color: var(--text); font-family: Consolas, "Courier New", monospace; }
.metric strong.ok { color: var(--green); }
.metric strong.no { color: var(--red); }

.check-list {
  display: grid;
  gap: 8px;
  padding: 14px 16px;
  border-top: 1px solid var(--line);
}

.check-row {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  color: var(--muted);
}

.check-icon {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--muted);
  font-size: .72rem;
  font-weight: 900;
}

.check-row.ok .check-icon { border-color: var(--green); color: var(--green); }
.check-row.no .check-icon { border-color: var(--red); color: var(--red); }
.check-row code { color: var(--text); }

.point { fill: #dce7ef; stroke: #11171b; stroke-width: 3; }
.point.selected { fill: var(--yellow); }
.point.on-circle { fill: var(--green); }
.candidate-circle { fill: rgba(104, 185, 255, .08); stroke: var(--blue); stroke-width: 3; }
.segment { stroke: #9aacba; stroke-width: 6; stroke-linecap: round; }
.segment.active { stroke: var(--green); }
.segment.related { stroke: var(--blue); }
.wall { stroke: #dce7ef; stroke-width: 5; }
.projection { fill: var(--yellow); stroke: #11171b; stroke-width: 2; }

.area-strip {
  display: flex;
  width: min(760px, 100%);
  min-height: 140px;
  margin: 70px auto 0;
  overflow: hidden;
  border: 2px solid #dce7ef;
}

.area-part {
  display: grid;
  place-items: center;
  min-width: 56px;
  padding: 10px;
  color: #101417;
  font-weight: 900;
  text-align: center;
  transition: width .25s ease;
}

.area-part small { display: block; color: #243039; }
.area-1 { background: #68b9ff; }
.area-2 { background: #ffd166; }
.area-3 { background: #5ee0a0; }

.range-field {
  display: grid;
  grid-template-columns: auto minmax(170px, 1fr) 92px;
  gap: 10px;
  align-items: center;
  flex: 1 1 340px;
}

.range-field span { color: var(--muted); font-size: .76rem; font-weight: 800; }
.range-field input[type="range"] { width: 100%; accent-color: var(--green); }
.range-field input[type="number"] {
  min-height: 42px;
  padding: 7px 9px;
  border: 1px solid #56616d;
  border-radius: 6px;
  background: #111519;
  color: var(--text);
}

.code-panel {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0a0d0f;
}

.code-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: .82rem;
  font-weight: 800;
}

.code-title a { text-decoration: none; }

pre {
  margin: 0;
  padding: 18px;
  overflow: auto;
  color: #dce9f8;
  font: .9rem/1.65 Consolas, "Courier New", monospace;
}

.complexity {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.complexity > div {
  padding: 14px 0 14px 15px;
  border-left: 3px solid var(--green);
}

.complexity strong { display: block; }
.complexity span { color: var(--muted); }

.sources li {
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
}

.sources li:last-child { border-bottom: 0; }
.sources a { font-weight: 800; text-decoration: none; }

.lesson-nav {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding-top: 26px;
  border-top: 1px solid var(--line);
}

.lesson-nav a {
  padding: 9px 13px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  font-weight: 800;
  text-decoration: none;
}

.lesson-nav a:hover { border-color: var(--green); }

@media (max-width: 780px) {
  .page { padding-inline: 14px; overflow-x: clip; }
  .lesson-header,
  .two-col { grid-template-columns: 1fr; }
  .lesson-header { align-items: start; }
  .source-figure img { max-height: 380px; }
  .geometry-stage { min-height: 310px; padding: 8px; }
  .geometry-stage svg { height: 310px; }
  .metric-grid { grid-template-columns: 1fr; }
  .metric + .metric { border-top: 1px solid var(--line); border-left: 0; }
  .controls button { flex: 1 1 120px; }
  .field { flex: 1 1 90px; }
  .field input { width: 100%; }
  .check-row { grid-template-columns: 24px minmax(0, 1fr); }
  .check-row code { grid-column: 2; }
  .range-field { grid-template-columns: 1fr; }
  .area-strip { margin-top: 45px; min-height: 180px; }
  .area-part { padding: 6px; writing-mode: vertical-rl; }
  .area-part small { display: none; }
  .complexity { grid-template-columns: 1fr; }
  .lesson-nav { flex-direction: column; }
  .lesson-nav a { text-align: center; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
