:root {
  --bg: #f4f7fb;
  --panel: #ffffff;
  --ink: #172033;
  --muted: #55647c;
  --line: #d6dfed;
  --blue: #2448bd;
  --green: #198754;
  --red: #dc3b3b;
  --amber: #b7791f;
  --cyan: #008f9c;
  --soft-blue: #edf4ff;
  --soft-green: #effaf3;
  --soft-red: #fff2f2;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

.site-header {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 18px;
  align-items: center;
  padding: 16px min(4vw, 48px);
  background: #fff;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand, nav a {
  color: #163ea8;
  text-decoration: none;
  font-weight: 850;
}

nav {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

nav a {
  color: var(--ink);
  padding: 10px 12px;
  border-radius: 8px;
}

nav a.active, nav a:hover {
  color: var(--blue);
  background: var(--soft-blue);
  outline: 1px solid #bad0f7;
}

.home-grid, .lesson-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 28px auto 56px;
}

.home-grid {
  display: grid;
  grid-template-columns: 0.95fr 1.05fr;
  gap: 28px;
}

.intro-panel, .lesson-card, .panel, .hero {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 18px 34px rgba(23, 32, 51, 0.06);
}

.intro-panel, .hero {
  padding: clamp(26px, 5vw, 50px);
  border-left: 7px solid var(--cyan);
}

.lesson-picker {
  display: grid;
  gap: 14px;
}

.lesson-card {
  padding: 26px;
  display: grid;
  grid-template-columns: 76px 1fr auto;
  gap: 18px;
  align-items: center;
  text-decoration: none;
  color: inherit;
}

.lesson-card:hover {
  border-color: #a9bfeb;
  transform: translateY(-1px);
}

.card-icon {
  width: 62px;
  height: 62px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #eefcff;
  color: var(--cyan);
  font-size: 1.45rem;
  font-weight: 900;
}

.card-action {
  color: var(--blue);
  font-weight: 900;
}

h1, h2, h3, p { margin: 0; }
h1 { font-size: clamp(2.3rem, 5vw, 4.1rem); line-height: 1.04; }
h2 { font-size: clamp(1.55rem, 3vw, 2rem); line-height: 1.1; }
p { color: var(--muted); line-height: 1.6; }

.small-label {
  color: #00988f;
  text-transform: uppercase;
  font-weight: 900;
  margin-bottom: 18px;
}

.intro-panel p:not(.small-label), .hero p:not(.small-label) {
  margin-top: 22px;
  max-width: 780px;
}

.unit-line {
  margin-top: 10px;
  font-weight: 700;
}

.lesson-shell {
  display: grid;
  gap: 22px;
}

.hero {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 28px;
  align-items: center;
}

.formula-spotlight {
  background: #1f328f;
  color: #fff;
  border-radius: 8px;
  padding: 28px;
}

.math-display {
  display: block;
  font-size: clamp(2rem, 4vw, 3.2rem);
  font-weight: 950;
}

.formula-spotlight small {
  display: block;
  margin-top: 10px;
  font-weight: 850;
}

.content-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.panel {
  padding: 24px;
}

.wide {
  grid-column: 1 / -1;
}

.panel h2 {
  margin-bottom: 14px;
}

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

.fact-grid div {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fbff;
  padding: 14px;
  display: grid;
  gap: 7px;
}

.fact-grid strong {
  color: var(--blue);
  font-size: 1.35rem;
}

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

.fact-grid b {
  color: var(--ink);
}

.hint {
  margin-top: 14px;
  border-left: 4px solid var(--amber);
  background: #fff8e8;
  border-radius: 8px;
  padding: 12px 14px;
}

.target-buttons, .button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 14px 0;
}

button {
  border: 1px solid #bad0f7;
  border-radius: 8px;
  padding: 11px 14px;
  font: inherit;
  font-weight: 850;
  cursor: pointer;
  color: var(--ink);
  background: #fff;
}

button.selected, .primary {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
}

.secondary {
  background: #edf4ff;
}

.steps {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #f9fbff;
}

.step {
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 10px;
  align-items: start;
}

.step-number {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #dff7f3;
  color: #007f75;
  font-weight: 900;
}

.panel-title-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: baseline;
}

output {
  color: var(--blue);
  font-weight: 900;
}

.sim-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 20px;
}

.controls {
  display: grid;
  gap: 18px;
  align-content: start;
}

.control label {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-weight: 850;
  margin-bottom: 8px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--blue);
}

input[type="number"] {
  width: 100%;
  border: 1px solid #bdd0eb;
  border-radius: 8px;
  padding: 12px 13px;
  font: inherit;
  font-weight: 750;
}

.scale-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #f9fbff;
  color: var(--muted);
}

.scale-card strong {
  display: block;
  color: var(--ink);
  margin-bottom: 6px;
}

.thermo-area {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 20px;
  min-height: 360px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(36, 72, 189, 0.08) 1px, transparent 1px) 0 0 / 58px 58px,
    linear-gradient(180deg, rgba(36, 72, 189, 0.08) 1px, transparent 1px) 0 0 / 58px 58px,
    #fff;
  padding: 20px;
}

.thermometer {
  position: relative;
  height: 320px;
  display: grid;
  justify-items: center;
}

.tube {
  position: relative;
  width: 34px;
  height: 260px;
  border: 4px solid #172033;
  border-radius: 999px;
  background: #f5fbff;
  overflow: hidden;
  align-self: start;
}

.mercury {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 40%;
  background: linear-gradient(180deg, #ff8a52, #dc3b3b);
  border-radius: 999px 999px 0 0;
  transition: height 180ms ease;
}

.bulb {
  position: absolute;
  bottom: 12px;
  width: 72px;
  height: 72px;
  border: 4px solid #172033;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #ffb38a, #dc3b3b 65%);
}

.ticks {
  position: absolute;
  left: 96px;
  top: 0;
  height: 260px;
  width: 70px;
}

.tick {
  position: absolute;
  left: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-weight: 800;
  transform: translateY(50%);
}

.tick::before {
  content: "";
  width: 18px;
  height: 2px;
  background: #172033;
}

.reading-panel {
  display: grid;
  gap: 12px;
  align-content: start;
}

.reading-panel > div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #f9fbff;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.reading-panel span {
  color: var(--muted);
  font-weight: 750;
}

.reading-panel strong {
  font-size: 1.6rem;
  color: var(--blue);
}

canvas {
  width: 100%;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.calc-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 14px;
}

.calc-grid label {
  display: grid;
  gap: 7px;
  font-weight: 850;
  color: var(--muted);
}

.answer {
  margin-top: 14px;
  padding: 14px;
  min-height: 52px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fbff;
  line-height: 1.55;
}

.answer.good {
  border-color: #a5d8b7;
  background: var(--soft-green);
  color: var(--green);
}

.answer.bad {
  border-color: #f0b5b5;
  background: var(--soft-red);
  color: var(--red);
}

.practice-row {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 10px;
  align-items: center;
  margin-top: 14px;
}

#taskUnit {
  font-weight: 900;
}

@media (max-width: 900px) {
  .site-header, .home-grid, .hero, .content-grid, .sim-layout, .thermo-area {
    grid-template-columns: 1fr;
  }

  .fact-grid, .calc-grid {
    grid-template-columns: 1fr;
  }

  .thermometer {
    justify-self: center;
    width: 180px;
  }
}

@media (max-width: 520px) {
  .home-grid, .lesson-shell { width: min(100% - 24px, 1180px); }
  .lesson-card { grid-template-columns: 1fr; }
  .practice-row { grid-template-columns: 1fr; }
  .panel, .hero, .intro-panel { padding: 22px; }
  h1 { font-size: 2.2rem; }
}
