:root {
  color-scheme: light;
  --bg: #f7f3ea;
  --panel: #fffaf0;
  --panel-strong: #f0e5d0;
  --ink: #1f2528;
  --muted: #66706f;
  --line: #d8cdb9;
  --accent: #8f4f2f;
  --accent-2: #2f6470;
  --good: #2f6f4e;
  --warn: #a25e13;
  --bad: #943734;
  --code: #efe3ce;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    linear-gradient(90deg, rgba(31, 37, 40, 0.035) 1px, transparent 1px),
    linear-gradient(rgba(31, 37, 40, 0.035) 1px, transparent 1px),
    var(--bg);
  background-size: 34px 34px;
  color: var(--ink);
}

main,
.hero,
footer {
  width: min(1440px, calc(100vw - 40px));
  margin: 0 auto;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(280px, 0.8fr);
  gap: 28px;
  align-items: end;
  padding: 48px 0 24px;
}

.eyebrow,
.section-kicker {
  color: var(--accent);
  font-size: 0.74rem;
  font-weight: 760;
  letter-spacing: 0.12em;
  margin: 0 0 10px;
  text-transform: uppercase;
}

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

h1 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2.2rem, 5vw, 5.2rem);
  line-height: 0.98;
  max-width: 980px;
  margin-bottom: 20px;
}

h2 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.35rem, 2vw, 2rem);
  line-height: 1.08;
  margin-bottom: 14px;
}

.lede {
  color: var(--muted);
  font-size: clamp(1.04rem, 1.5vw, 1.3rem);
  line-height: 1.55;
  max-width: 900px;
}

.lede-link a {
  color: var(--accent);
  font-weight: 760;
}

.hero-panel,
.paper-section,
.control-panel,
.visual-card {
  background: rgba(255, 250, 240, 0.92);
  border: 1px solid var(--line);
}

.hero-panel {
  padding: 22px;
}

.hero-stat {
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0;
}

.hero-stat:last-child {
  border-bottom: 0;
}

.hero-stat strong {
  font-size: 1.35rem;
}

.paper-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(300px, 0.7fr);
  gap: 20px;
  margin: 12px 0 20px;
}

.paper-section {
  padding: 24px;
}

.paper-section.wide p:last-child {
  color: var(--muted);
  line-height: 1.7;
  margin: 18px 0 0;
}

.equation-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.equation-card {
  background: var(--panel-strong);
  border: 1px solid var(--line);
  padding: 14px;
}

.equation-card span {
  color: var(--muted);
  display: block;
  font-size: 0.82rem;
  margin-bottom: 8px;
}

code,
pre {
  background: var(--code);
  border-radius: 3px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.92em;
  padding: 0.08rem 0.24rem;
}

pre {
  border: 1px solid var(--line);
  line-height: 1.5;
  margin: 0;
  overflow: auto;
  padding: 14px;
}

.control-panel {
  align-items: end;
  display: grid;
  grid-template-columns: repeat(5, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
  padding: 16px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.control {
  display: grid;
  gap: 7px;
}

label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

select,
input[type="range"] {
  accent-color: var(--accent);
}

select {
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--ink);
  font: inherit;
  padding: 9px 10px;
}

.dashboard {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
}

.gallery-section {
  background: rgba(255, 250, 240, 0.92);
  border: 1px solid var(--line);
  margin-top: 20px;
  padding: 22px;
}

.gallery-heading {
  align-items: start;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(180px, 240px);
  gap: 20px;
  margin-bottom: 18px;
}

.compact-control {
  background: var(--panel-strong);
  border: 1px solid var(--line);
  padding: 12px;
}

.energy-gallery {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
}

.heatmap-card {
  background: #fffdf7;
  border: 1px solid var(--line);
  padding: 10px;
}

.heatmap-card h3 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1rem;
  line-height: 1.15;
  margin: 0 0 6px;
}

.heatmap-meta {
  color: var(--muted);
  display: flex;
  font-size: 0.72rem;
  justify-content: space-between;
  margin-bottom: 8px;
  gap: 8px;
}

.heatmap-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
}

.heatmap-cell {
  aspect-ratio: 1;
  border: 1px solid rgba(31, 37, 40, 0.08);
  min-width: 0;
}

.heatmap-legend {
  align-items: center;
  color: var(--muted);
  display: grid;
  font-size: 0.72rem;
  gap: 5px;
  grid-template-columns: auto 1fr auto;
  margin-top: 8px;
}

.heatmap-note {
  font-size: 0.76rem;
  margin: 8px 0 0;
}

.legend-ramp {
  background: linear-gradient(90deg, rgba(239, 227, 206, 1), rgba(143, 79, 47, 1));
  height: 7px;
}

.visual-card {
  min-width: 0;
  padding: 20px;
}

.square-card {
  display: flex;
  flex-direction: column;
}

.card-heading {
  align-items: start;
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

.badge {
  border: 1px solid currentColor;
  color: var(--good);
  font-size: 0.76rem;
  font-weight: 750;
  letter-spacing: 0.08em;
  padding: 5px 8px;
  text-transform: uppercase;
}

.badge.invalid {
  color: var(--bad);
}

.square-grid {
  display: grid;
  gap: 6px;
  margin: 4px 0 16px;
  width: min(100%, 440px);
}

.cell {
  align-items: center;
  aspect-ratio: 1;
  background: var(--panel-strong);
  border: 1px solid var(--line);
  display: flex;
  font-weight: 760;
  justify-content: center;
  position: relative;
}

.cell::after {
  background: var(--accent-2);
  bottom: 0;
  content: "";
  left: 0;
  opacity: 0.2;
  position: absolute;
  right: 0;
}

.cell.negative::after {
  background: var(--accent);
}

canvas {
  background: #fffdf7;
  border: 1px solid var(--line);
  display: block;
  height: auto;
  max-width: 100%;
  width: 100%;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.stat {
  background: var(--panel-strong);
  border: 1px solid var(--line);
  padding: 14px;
}

.stat span {
  color: var(--muted);
  display: block;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
  text-transform: uppercase;
}

.stat strong {
  font-size: 1.25rem;
}

.muted {
  color: var(--muted);
  line-height: 1.55;
}

footer {
  color: var(--muted);
  padding: 28px 0 44px;
}

@media (max-width: 980px) {
  .hero,
  .paper-grid,
  .dashboard,
  .control-panel,
  .gallery-heading {
    grid-template-columns: 1fr;
  }

  .control-panel {
    position: static;
  }

  .equation-grid,
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .energy-gallery {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 620px) {
  .energy-gallery {
    grid-template-columns: 1fr;
  }
}
