:root {
  color-scheme: dark;
  --bg: #16130f;
  --line: #0a0a0a;
  --text: #eee7db;
  --muted: #c0b2a2;
  --lcd: #b9d7dd;
  --lcd-text: #243c45;
  --lamp: #ffd78a;
  --wood-width: clamp(22px, calc(22px + (100vw - 980px) * 0.1522), 92px);
  --content-gutter: calc(var(--wood-width) * 2 + 24px);
}

* {
  box-sizing: border-box;
}

body {
  position: relative;
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(90deg, #6b3b1d 0 var(--wood-width), transparent var(--wood-width) calc(100% - var(--wood-width)), #6b3b1d calc(100% - var(--wood-width))),
    linear-gradient(90deg, rgba(255, 210, 142, 0.12) 0 var(--wood-width), transparent var(--wood-width) calc(100% - var(--wood-width)), rgba(255, 210, 142, 0.12) calc(100% - var(--wood-width))),
    radial-gradient(circle at 12% 0%, rgba(255, 255, 255, 0.08), transparent 32%),
    var(--bg);
  color: var(--text);
  font-family: "Arial Narrow", "Helvetica Neue", Arial, sans-serif;
}

body::before,
body::after {
  content: "";
  position: fixed;
  top: 0;
  bottom: 0;
  z-index: 0;
  width: var(--wood-width);
  pointer-events: none;
  background:
    radial-gradient(ellipse at 35% 22%, rgba(255, 204, 137, 0.22), transparent 18%),
    radial-gradient(ellipse at 68% 72%, rgba(45, 21, 9, 0.24), transparent 22%),
    repeating-linear-gradient(86deg, rgba(95, 45, 20, 0.34) 0 3px, rgba(142, 82, 41, 0.24) 3px 8px, rgba(72, 32, 14, 0.3) 8px 13px),
    linear-gradient(90deg, rgba(255, 218, 154, 0.14), transparent 42%, rgba(37, 16, 7, 0.22));
}

body::before {
  left: 0;
}

body::after {
  right: 0;
  transform: scaleX(-1);
}

.app {
  position: relative;
  z-index: 1;
  width: min(1220px, calc(100vw - var(--content-gutter)));
  margin: 0 auto;
  padding: 20px 0 28px;
}

.topbar,
.equation-stage,
.control-grid {
  margin-bottom: 10px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 2px solid var(--line);
  border-radius: 8px 8px 4px 4px;
  padding: 12px 14px;
  background: linear-gradient(#252525, #111);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.15), 0 3px 10px rgba(0, 0, 0, 0.45);
}

h1,
p {
  margin: 0;
}

h1 {
  font-family: "Avenir Next Condensed", "DIN Condensed", "Helvetica Neue", Arial, sans-serif;
  font-size: clamp(25px, 3vw, 40px);
  line-height: 1;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
  text-shadow: 0 1px 0 #000;
}

.transport {
  display: flex;
  align-items: center;
  gap: 8px;
}

.build-id {
  color: var(--muted);
  font-family: "Courier New", monospace;
  font-size: 12px;
  font-weight: 700;
}

button,
select,
input {
  font: inherit;
}

.lamp-button,
.equation-buttons button {
  border: 1px solid #090909;
  border-radius: 4px;
  background: linear-gradient(#3c3c3c, #171717);
  color: #f3e7d2;
  font-weight: 900;
  text-transform: uppercase;
  text-shadow: 0 1px 0 #000;
  box-shadow:
    0 3px 0 #050505,
    inset 0 1px 0 rgba(255, 255, 255, 0.18);
  cursor: pointer;
}

.lamp-button {
  min-width: 86px;
  min-height: 34px;
  padding: 7px 12px;
}

.lamp-button[aria-pressed="true"],
.equation-buttons button.is-selected {
  color: #1f1204;
  background: linear-gradient(#ffd98c, #f18b35);
}

.equation-stage {
  display: grid;
  grid-template-columns: minmax(280px, 0.9fr) minmax(360px, 1.5fr);
  gap: 10px;
}

.equation-card,
.scope-panel,
fieldset {
  border: 2px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.08), transparent 26%),
    linear-gradient(#4a423a, #2d2925);
  box-shadow:
    inset 0 2px 1px rgba(255, 255, 255, 0.16),
    inset 0 -3px 8px rgba(0, 0, 0, 0.38),
    0 2px 5px rgba(0, 0, 0, 0.45);
}

.equation-card {
  min-height: 270px;
  padding: 12px;
}

.equation-heading,
.scope-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 34px;
  margin-bottom: 8px;
  padding: 6px 8px;
  border-radius: 5px;
  background: #1c3444;
  color: #c9e8f2;
  font-size: 13px;
  font-weight: 900;
  text-transform: uppercase;
}

.equation-heading span:last-child,
.scope-toolbar span:last-child {
  color: rgba(238, 231, 219, 0.72);
  font-family: "Courier New", monospace;
  font-size: 11px;
  text-transform: none;
}

.equation-display {
  display: grid;
  align-content: center;
  min-height: 148px;
  padding: 14px;
  border: 2px solid #050505;
  border-radius: 6px;
  background:
    radial-gradient(circle at 50% 0%, rgba(140, 160, 255, 0.1), transparent 38%),
    #090909;
  color: #f3efff;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(19px, 2.2vw, 32px);
  line-height: 1.25;
  text-align: center;
  text-shadow: 0 0 12px rgba(130, 105, 255, 0.55);
}

.equation-line {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.28em;
}

.sigma {
  position: relative;
  display: inline-grid;
  place-items: center;
  margin: 0 0.24em;
  font-size: 2.2em;
  line-height: 0.82;
}

.sigma sup,
.sigma sub {
  position: absolute;
  font-family: "Times New Roman", serif;
  font-size: 0.28em;
  line-height: 1;
}

.sigma sup {
  top: -0.74em;
}

.sigma sub {
  bottom: -0.86em;
}

.frac {
  display: inline-grid;
  grid-template-rows: auto 1px auto;
  align-items: center;
  min-width: 1.8em;
  vertical-align: middle;
}

.frac::before {
  content: "";
  grid-row: 2;
  height: 1px;
  background: currentColor;
}

.frac span {
  display: block;
  padding: 0 0.08em;
}

.frac span:first-child {
  grid-row: 1;
}

.frac span:last-child {
  grid-row: 3;
}

.equation-note {
  margin-top: 10px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.35;
}

canvas {
  display: block;
  width: 100%;
  height: 220px;
  border: 3px solid #8b908a;
  border-radius: 6px;
  background:
    linear-gradient(rgba(100, 190, 122, 0.13) 1px, transparent 1px) 0 0 / 100% 20px,
    linear-gradient(90deg, rgba(100, 190, 122, 0.1) 1px, transparent 1px) 0 0 / 28px 100%,
    linear-gradient(rgba(100, 190, 122, 0.2) 1px, transparent 1px) 0 50% / 100% 50%,
    #03160c;
  box-shadow:
    0 0 0 2px #050505,
    inset 0 0 22px rgba(0, 0, 0, 0.86),
    inset 0 0 42px rgba(30, 118, 56, 0.2);
}

.control-grid {
  display: grid;
  grid-template-columns: minmax(300px, 1.25fr) minmax(300px, 0.75fr);
  gap: 10px;
}

fieldset {
  position: relative;
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 42px 10px 10px;
}

legend {
  position: absolute;
  top: 8px;
  left: 8px;
  right: 8px;
  padding: 4px 8px;
  border-radius: 5px;
  background: #22331f;
  color: #d9f0b9;
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-align: center;
  text-transform: uppercase;
  text-shadow: 0 1px 0 #000;
}

.module-equations legend {
  background: #1c3444;
  color: #c9e8f2;
}

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

.equation-buttons button {
  min-height: 42px;
  padding: 7px 8px;
  font-size: 11px;
  line-height: 1.1;
}

label {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr) 82px;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 7px;
  border: 1px solid rgba(0, 0, 0, 0.55);
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.18);
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
  text-transform: uppercase;
}

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

select,
output {
  min-width: 0;
  border: 1px solid #080808;
  border-radius: 4px;
  padding: 6px;
  background: linear-gradient(#cce5eb, var(--lcd));
  color: var(--lcd-text);
  font-family: "Courier New", monospace;
  font-size: 11px;
  font-weight: 800;
  text-align: center;
}

select {
  width: 100%;
}

@media (max-width: 820px) {
  .app {
    width: min(100% - 18px, 760px);
  }

  .topbar,
  .equation-stage,
  .control-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .transport {
    justify-content: space-between;
  }

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

  label {
    grid-template-columns: 62px minmax(0, 1fr) 76px;
  }
}

@media (max-width: 420px) {
  .equation-buttons {
    grid-template-columns: 1fr;
  }

  label {
    grid-template-columns: 1fr;
  }
}
