: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; }

[hidden] {
  display: none !important;
}

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;
  flex-wrap: wrap;
}

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 strong {
  display: block;
  margin-bottom: 4px;
}

.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; }
}

select {
  width: 100%;
  border: 1px solid #bdd0eb;
  border-radius: 8px;
  padding: 12px 13px;
  font: inherit;
  font-weight: 800;
  color: var(--ink);
  background: #fff;
}

.phase-map {
  position: relative;
  min-height: 330px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(36, 72, 189, 0.06) 1px, transparent 1px) 0 0 / 56px 56px,
    linear-gradient(180deg, rgba(36, 72, 189, 0.06) 1px, transparent 1px) 0 0 / 56px 56px,
    #fff;
  margin-top: 14px;
  overflow: hidden;
}

.phase {
  position: absolute;
  width: 150px;
  height: 92px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  text-align: center;
  font-weight: 950;
  border: 2px solid var(--line);
  color: var(--ink);
  background: #f8fbff;
}

.phase.solid { left: 8%; top: 48px; background: #eef3ff; }
.phase.liquid { left: 50%; top: 48px; transform: translateX(-50%); background: #eefcff; }
.phase.gas { right: 8%; top: 48px; background: #fff8e8; }

.transition {
  position: absolute;
  min-width: 138px;
  white-space: nowrap;
  padding: 9px 12px;
  font-size: 0.95rem;
  background: #fff;
}

.transition.selected {
  background: var(--blue);
  color: #fff;
}

.t-melt { left: 24%; top: 42px; }
.t-freeze { left: 24%; top: 104px; }
.t-vapor { right: 23%; top: 42px; }
.t-condense { right: 23%; top: 104px; }
.t-sublime { left: 22%; bottom: 54px; }
.t-resublime { right: 22%; bottom: 54px; }

.map-answer strong {
  color: var(--blue);
}

.data-table {
  display: grid;
  gap: 8px;
}

.data-table > div,
.data-table button {
  display: grid;
  grid-template-columns: 1fr 90px 90px;
  gap: 10px;
  align-items: center;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  text-align: left;
}

.data-table > div {
  background: #f6f9fd;
  color: var(--muted);
  font-weight: 900;
}

.data-table button {
  background: #fff;
}

.data-table button:hover {
  border-color: #9db7ef;
  background: #f8fbff;
}

.heating-area {
  display: grid;
  grid-template-columns: 230px 1fr;
  grid-template-rows: minmax(240px, 1fr) auto;
  gap: 18px;
  align-items: stretch;
  min-height: 350px;
}

.beaker {
  position: relative;
  grid-column: 1;
  grid-row: 1;
  min-height: 260px;
  border: 4px solid #172033;
  border-top: 0;
  border-radius: 0 0 26px 26px;
  background: linear-gradient(180deg, rgba(237, 244, 255, 0.3), rgba(237, 244, 255, 0.9));
  overflow: hidden;
}

.beaker::before {
  content: "";
  position: absolute;
  left: -4px;
  right: -4px;
  top: 0;
  height: 4px;
  background: #172033;
}

.beaker span {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 14px;
  border-radius: 8px;
  padding: 10px;
  background: rgba(255,255,255,0.86);
  text-align: center;
  font-weight: 950;
  color: var(--blue);
}

.particles {
  position: absolute;
  inset: 10px;
}

.particles i {
  position: absolute;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 5px 12px rgba(0, 143, 156, 0.2);
}

.particles.solid i {
  animation: vibrate 700ms infinite alternate ease-in-out;
}

.particles.melting i,
.particles.liquid i {
  animation: drift 1800ms infinite alternate ease-in-out;
}

.particles.boiling i,
.particles.gas i {
  background: #f97316;
  animation: floaty 1200ms infinite alternate ease-in-out;
}

@keyframes vibrate {
  from { transform: translate(-1px, 0); }
  to { transform: translate(1px, 1px); }
}

@keyframes drift {
  from { transform: translate(calc(var(--dx, 6px) * -0.45), calc(var(--dy, 6px) * 0.25)); }
  to { transform: translate(calc(var(--dx, 6px) * 0.45), calc(var(--dy, 6px) * -0.35)); }
}

@keyframes floaty {
  from { transform: translate(calc(var(--dx, 14px) * -0.9), calc(var(--dy, 18px) * 0.9)); opacity: 0.66; }
  to { transform: translate(calc(var(--dx, 14px) * 0.9), calc(var(--dy, 18px) * -0.9)); opacity: 1; }
}

.particles.boiling i {
  box-shadow: 0 0 0 5px rgba(249, 115, 22, 0.12), 0 8px 18px rgba(249, 115, 22, 0.18);
}

.particles.gas i {
  box-shadow: 0 0 0 7px rgba(249, 115, 22, 0.10), 0 10px 22px rgba(249, 115, 22, 0.16);
}

.particle-note {
  grid-column: 1;
  grid-row: 2;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fbff;
  padding: 14px;
  color: var(--muted);
  line-height: 1.45;
}

.heating-area canvas {
  grid-column: 2;
  grid-row: 1 / span 2;
  align-self: stretch;
}

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

.pressure-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.pressure-row button.selected {
  background: var(--blue);
  color: #fff;
}

.phase-equation {
  white-space: nowrap;
  font-size: clamp(1.9rem, 3.4vw, 3rem);
}

.expansion-spotlight {
  background: #173f7a;
}

.expansion-spotlight .math-display {
  font-size: clamp(1.85rem, 3.3vw, 2.85rem);
  line-height: 1.12;
}

.expansion-layout {
  grid-template-columns: 300px 1fr;
}

.expansion-stage {
  min-height: 350px;
  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, #f9fcff, #eef7ff);
  padding: 28px;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.rail-model,
.vessel-model,
.gas-model {
  width: min(560px, 100%);
}

.rail-model {
  position: relative;
  min-height: 170px;
  display: grid;
  align-items: center;
}

.rail-model::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 8px;
  border-radius: 99px;
  background: #172033;
}

.fixed-mark {
  position: absolute;
  left: 0;
  top: calc(50% + 18px);
  font-weight: 900;
  color: var(--muted);
}

.rod {
  position: relative;
  z-index: 1;
  height: 42px;
  width: 62%;
  border-radius: 8px;
  background: linear-gradient(90deg, #64748b, #94a3b8, #475569);
  box-shadow: 0 14px 24px rgba(71, 85, 105, 0.26);
  transition: width 220ms ease;
}

.gap {
  position: absolute;
  right: 5%;
  top: calc(50% + 22px);
  border-top: 4px solid var(--amber);
  padding-top: 8px;
  font-weight: 900;
  color: var(--amber);
}

.gap.tight {
  color: var(--red);
  border-color: var(--red);
}

.vessel-model {
  display: grid;
  place-items: center;
}

.vessel {
  position: relative;
  width: 190px;
  height: 292px;
  border: 4px solid #172033;
  border-top: 0;
  border-radius: 0 0 28px 28px;
  overflow: hidden;
  background: rgba(255,255,255,0.7);
}

.vessel::before {
  content: "";
  position: absolute;
  left: -4px;
  right: -4px;
  top: 0;
  height: 4px;
  background: #172033;
}

.liquid-fill {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 45%;
  background: linear-gradient(180deg, #67e8f9, #0891b2);
  transition: height 220ms ease;
}

.vessel span {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 14px;
  padding: 10px;
  border-radius: 8px;
  background: rgba(255,255,255,0.84);
  color: var(--blue);
  font-weight: 950;
  text-align: center;
}

.gas-box {
  position: relative;
  min-height: 300px;
  display: grid;
  place-items: center;
}

.gas-balloon {
  width: 185px;
  height: 185px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fed7aa, #f97316 58%, #c2410c);
  box-shadow: 0 20px 38px rgba(249, 115, 22, 0.28);
  transition: transform 220ms ease;
}

.gas-dots {
  position: absolute;
  inset: 0;
}

.gas-dots i {
  position: absolute;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #fff7ed;
  box-shadow: 0 0 0 5px rgba(255, 247, 237, 0.4);
  animation: gas-jitter 900ms infinite alternate ease-in-out;
}

@keyframes gas-jitter {
  from { transform: translate(-10px, 7px); }
  to { transform: translate(12px, -9px); }
}

.delta-line {
  display: block;
  margin-top: 12px;
  color: var(--blue);
  font-weight: 950;
}

.thermometer-wrap {
  margin-top: 22px;
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 18px;
  align-items: center;
  min-height: 260px;
}

.thermometer {
  position: relative;
  width: 82px;
  height: 246px;
  margin-inline: auto;
}

.thermo-tube {
  position: absolute;
  left: 31px;
  top: 0;
  width: 20px;
  height: 195px;
  border: 4px solid #172033;
  border-radius: 99px;
  background: #fff;
  overflow: hidden;
}

.thermo-fill {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 36%;
  background: linear-gradient(180deg, #fb7185, #dc2626);
  transition: height 220ms ease;
}

.thermo-bulb {
  position: absolute;
  left: 16px;
  bottom: 0;
  width: 50px;
  height: 50px;
  border: 4px solid #172033;
  border-radius: 50%;
  background: #dc2626;
}

.thermo-scale {
  display: grid;
  gap: 62px;
  color: var(--muted);
  font-weight: 900;
}

.lake-layout {
  display: grid;
  gap: 16px;
}

.lake-scene {
  position: relative;
  min-height: 300px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: linear-gradient(180deg, #e0f2fe 0 10%, #38bdf8 10% 52%, #0f5f9a 100%);
  display: grid;
  grid-template-rows: 54px 72px 92px 1fr;
  color: #fff;
  font-weight: 950;
}

.ice-layer {
  display: grid;
  place-items: center;
  background: linear-gradient(180deg, #f8fafc, #dbeafe);
  color: #2448bd;
  border-bottom: 4px solid rgba(255,255,255,0.74);
  opacity: 0;
}

.ice-layer.visible {
  opacity: 1;
}

.water-layer {
  display: grid;
  place-items: center;
  text-shadow: 0 2px 8px rgba(15, 32, 51, 0.22);
}

.water-layer.top {
  background: rgba(125, 211, 252, 0.58);
}

.water-layer.middle {
  background: rgba(14, 165, 233, 0.46);
}

.water-layer.bottom {
  background: rgba(2, 132, 199, 0.76);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 16px;
}

.fish {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  padding: 8px 14px;
  border-radius: 8px;
  background: rgba(255,255,255,0.9);
  color: #075985;
  font-weight: 950;
}

.matter-spotlight {
  background: #1b3f5f;
}

.matter-spotlight .math-display {
  font-size: clamp(1.75rem, 3.2vw, 2.75rem);
  line-height: 1.12;
}

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

.molecule-stage,
.particle-box,
.diffusion-box,
.brown-box {
  position: relative;
  min-height: 330px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(36, 72, 189, 0.08) 1px, transparent 1px) 0 0 / 56px 56px,
    linear-gradient(180deg, #f9fcff, #eef7ff);
}

.molecule-stage {
  min-height: 300px;
}

.atom {
  position: absolute;
  display: grid;
  place-items: center;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  color: #fff;
  font-weight: 950;
  box-shadow: 0 14px 28px rgba(23, 32, 51, 0.18);
  z-index: 2;
}

.atom-o { background: #ef4444; }
.atom-h { background: #38bdf8; }
.atom-c { background: #475569; }
.atom-n { background: #2563eb; }
.atom-he { background: #9333ea; }

.molecule-bonds {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  pointer-events: none;
}

.molecule-bonds line {
  stroke: #172033;
  stroke-width: 2.4;
  stroke-linecap: round;
}

.particle-box {
  margin: 16px 0;
}

.particle-box i,
.diffusion-box i,
.brown-box i {
  position: absolute;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
}

.particle-box i {
  background: var(--cyan);
  box-shadow: 0 4px 12px rgba(0, 143, 156, 0.24);
}

.particle-box.solid i {
  animation: matter-vibrate 620ms infinite alternate ease-in-out;
}

.particle-box.liquid i {
  animation: matter-drift 1250ms infinite alternate ease-in-out;
}

.particle-box.gas i {
  background: #f97316;
  box-shadow: 0 0 0 7px rgba(249, 115, 22, 0.11), 0 10px 20px rgba(249, 115, 22, 0.16);
  animation: matter-float 520ms infinite alternate ease-in-out;
}

@keyframes matter-vibrate {
  from { transform: translate(-52%, -50%); }
  to { transform: translate(-48%, -47%); }
}

@keyframes matter-drift {
  from { transform: translate(calc(-50% + var(--dx, 8px) * -0.35), calc(-50% + var(--dy, 8px) * 0.28)); }
  to { transform: translate(calc(-50% + var(--dx, 8px) * 0.35), calc(-50% + var(--dy, 8px) * -0.32)); }
}

@keyframes matter-float {
  from { transform: translate(calc(-50% + var(--dx, 16px) * -0.9), calc(-50% + var(--dy, 16px) * 0.9)); }
  to { transform: translate(calc(-50% + var(--dx, 16px) * 0.9), calc(-50% + var(--dy, 16px) * -0.9)); }
}

.diffusion-controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin: 12px 0 16px;
}

.diffusion-controls button.selected {
  background: var(--blue);
  color: #fff;
}

.diffusion-box {
  margin: 16px 0;
}

.diffusion-box::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 50%;
  width: 2px;
  background: rgba(23, 32, 51, 0.16);
}

.diffusion-box.gas {
  background:
    linear-gradient(90deg, rgba(36, 72, 189, 0.08) 1px, transparent 1px) 0 0 / 56px 56px,
    linear-gradient(180deg, #fbfdff, #eef7ff);
}

.diffusion-box.liquid {
  background:
    linear-gradient(90deg, rgba(36, 72, 189, 0.08) 1px, transparent 1px) 0 0 / 56px 56px,
    linear-gradient(180deg, #dff7ff, #8dd7f7);
}

.diffusion-box i.blue {
  background: #2563eb;
  box-shadow: 0 0 0 6px rgba(37, 99, 235, 0.12);
}

.diffusion-box i.red {
  background: #ef4444;
  box-shadow: 0 0 0 6px rgba(239, 68, 68, 0.12);
}

.brown-box {
  margin-top: 18px;
  min-height: 250px;
}

.brown-box i {
  width: 11px;
  height: 11px;
  background: rgba(37, 99, 235, 0.45);
  animation: brown-dot 900ms infinite alternate ease-in-out;
}

.brown-grain {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #f97316;
  box-shadow: 0 0 0 9px rgba(249, 115, 22, 0.14);
  animation: brown-grain 1300ms infinite alternate ease-in-out;
  z-index: 2;
}

@keyframes brown-dot {
  from { transform: translate(-7px, 5px); }
  to { transform: translate(8px, -6px); }
}

@keyframes brown-grain {
  0% { transform: translate(-50%, -50%); }
  35% { transform: translate(calc(-50% + 18px), calc(-50% - 12px)); }
  70% { transform: translate(calc(-50% - 14px), calc(-50% + 15px)); }
  100% { transform: translate(calc(-50% + 8px), calc(-50% + 4px)); }
}

@media (max-width: 900px) {
  .phase-map {
    min-height: 560px;
  }

  .phase {
    left: 50% !important;
    right: auto !important;
    transform: translateX(-50%) !important;
  }

  .phase.solid { top: 24px; }
  .phase.liquid { top: 190px; }
  .phase.gas { top: 356px; }

  .transition {
    left: 50% !important;
    right: auto !important;
    transform: translateX(-50%);
  }

  .t-melt { top: 126px; }
  .t-freeze { top: 158px; }
  .t-vapor { top: 292px; }
  .t-condense { top: 324px; }
  .t-sublime { bottom: 62px; }
  .t-resublime { bottom: 22px; }

  .heating-area {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
  }

  .expansion-layout,
  .lake-layout,
  .molecule-layout {
    grid-template-columns: 1fr;
  }

  .beaker,
  .particle-note,
  .heating-area canvas {
    grid-column: 1;
    grid-row: auto;
  }
}

@media (max-width: 560px) {
  .phase-equation {
    white-space: normal;
    font-size: clamp(1.8rem, 10vw, 2.45rem);
  }

  .data-table > div,
  .data-table button {
    grid-template-columns: 1fr;
  }

  .thermometer-wrap {
    grid-template-columns: 1fr;
  }

  .thermo-scale {
    display: flex;
    justify-content: space-between;
  }

  .expansion-stage,
  .lake-scene,
  .molecule-stage,
  .particle-box,
  .diffusion-box {
    min-height: 320px;
  }

  .panel-title-row {
    display: grid;
    gap: 8px;
  }
}
