* {
  box-sizing: border-box;
}

:root {
  --bg: #f7f7f5;
  --card: #fff;
  --ink: #111;
  --muted: #646464;
  --line: #d9d9d4;
  --soft-line: #ececea;
  --panel-bg: #fafaf8;
  /* functional colors (match canvas drawing) */
  --field: #d2473b;
  --electron: #2576d6;
  --nucleus: #c24a5a;
  --current: #14936f;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
}

button,
input {
  font: inherit;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  width: min(1280px, calc(100% - 48px));
  margin: 0 auto;
  padding: 24px 0 18px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 10px;
  font-size: clamp(26px, 3vw, 34px);
  line-height: 1.12;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.lede {
  max-width: 780px;
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.6;
  font-size: 14px;
}

.home-link {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 100;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 1px solid #d8d2c0;
  border-radius: 50%;
  color: #2f5d4f;
  background: #faf8f1;
  box-shadow: 0 1px 2px rgba(28,43,37,.05), 0 12px 32px -16px rgba(28,43,37,.28);
  text-decoration: none;
  transition: transform .2s ease, border-color .2s ease;
}
.home-link:hover,
.home-link:focus-visible {
  border-color: #8a9a5b;
  color: #3f7060;
  transform: translateY(-2px);
  outline: none;
}
.home-link svg { display: block; }

.app {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  gap: 18px;
  width: min(1280px, calc(100% - 48px));
  margin: 0 auto;
  padding: 0 0 36px;
}

.panel,
.stage-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
}

.controls-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 16px;
}

.mode-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-bg);
}

.mode-button {
  min-height: 40px;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  font-weight: 700;
  cursor: pointer;
}

.mode-button.active {
  color: #ffffff;
  background: var(--ink);
}

.control-block {
  display: grid;
  gap: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-bg);
}

.block-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.block-heading h2,
.stage-header h2,
.explanation-panel h2 {
  margin: 0;
  font-size: 17px;
  line-height: 1.25;
  font-weight: 700;
}

.status-pill {
  flex: 0 0 auto;
  padding: 5px 9px;
  border-radius: 999px;
  color: #ffffff;
  background: #7f8793;
  font-size: 12px;
  font-weight: 700;
}

.status-pill.on {
  background: var(--current);
}

.status-pill.neutral {
  color: var(--ink);
  background: var(--soft-line);
}

.field-switch,
.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: #ffffff;
  font-weight: 700;
  cursor: pointer;
}

.secondary-button:hover {
  background: var(--soft-line);
}

.field-switch.active {
  color: #ffffff;
  border-color: var(--ink);
  background: var(--ink);
}

.switch-track {
  position: relative;
  width: 38px;
  height: 20px;
  border-radius: 999px;
  background: #c8d0da;
}

.switch-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #ffffff;
  transition: transform 0.18s ease;
}

.field-switch.active .switch-track {
  background: rgba(255, 255, 255, 0.35);
}

.field-switch.active .switch-thumb {
  transform: translateX(18px);
}

.slider-row {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr) 64px;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
}

.slider-row strong {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

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

.metrics {
  display: grid;
  gap: 10px;
}

.metric {
  display: grid;
  gap: 4px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-bg);
}

.metric span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.metric strong {
  font-size: 16px;
  line-height: 1.25;
}

.stage-panel {
  min-width: 0;
  overflow: hidden;
}

.stage-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--soft-line);
}

.stage-header p {
  max-width: 760px;
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px 14px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
}

.legend-dot.nucleus {
  background: var(--nucleus);
}

.legend-dot.electron {
  background: var(--electron);
}

.legend-line {
  width: 22px;
  height: 3px;
  border-radius: 999px;
  background: var(--current);
}

canvas {
  display: block;
  width: 100%;
  height: min(62vh, 640px);
  min-height: 420px;
  background: #fff;
}

.readout-strip {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 18px;
  border-top: 1px solid var(--soft-line);
  color: var(--muted);
  background: #ffffff;
  font-size: 13px;
  font-weight: 600;
}

.explanation-panel {
  grid-column: 1 / -1;
  padding: 18px;
}

.concept-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-top: 14px;
}

.concept-grid > div {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-bg);
}

.concept-grid h3 {
  margin-bottom: 8px;
  font-size: 15px;
  font-weight: 700;
}

.concept-grid p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.55;
}

@media (max-width: 900px) {
  .topbar,
  .stage-header,
  .readout-strip {
    flex-direction: column;
  }

  .topbar {
    align-items: flex-start;
  }

  .app {
    grid-template-columns: 1fr;
    width: calc(100% - 28px);
  }

  .concept-grid {
    grid-template-columns: 1fr;
  }

  .legend {
    justify-content: flex-start;
  }

  canvas {
    height: 520px;
  }
}

@media (max-width: 520px) {
  .slider-row {
    grid-template-columns: 1fr 62px;
  }

  .slider-row span {
    grid-column: 1 / -1;
  }

  canvas {
    min-height: 380px;
    height: 460px;
  }
}
