:root {
  color-scheme: dark;
  --bg: #050505;
  --paper: #101014;
  --ink: #e8e8e8;
  --muted: #8e8e8e;
  --line: #27242e;
  --slate: #bbb;
  --slate-dark: #e8e8e8;
  --accent: #a17dee;
  --accent-soft: #21192f;
  --accent-line: #51406e;
  --primary: linear-gradient(135deg, #7555cc, #8e6cda);
  --light: #151219;
  --success: #82cba3;
  --radius: 6px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 280px;
  min-height: 100vh;
  background-color: var(--bg);
  background-image:
    radial-gradient(ellipse at 50% 0, #7555cc1f, transparent 60%),
    linear-gradient(#ffffff04 1px, transparent 1px),
    linear-gradient(90deg, #ffffff04 1px, transparent 1px);
  background-size: 100% 780px, 64px 64px, 64px 64px;
  background-repeat: no-repeat, repeat, repeat;
  color: var(--ink);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

button,
input {
  font: inherit;
}

button,
a,
input {
  -webkit-tap-highlight-color: transparent;
}

button {
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
summary:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

h1,
h2,
p {
  margin: 0;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 56px;
  padding: 8px 28px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--ink);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0;
  text-decoration: none;
}

.brand img,
.brand-logo {
  display: block;
  flex-shrink: 0;
  width: 25px;
  height: 28px;
  object-fit: contain;
}

.brand-name {
  color: #fff;
  font-size: 20px;
  font-weight: 500;
  letter-spacing: 0;
  white-space: nowrap;
}

.brand-divider {
  flex-shrink: 0;
  width: 1px;
  height: 20px;
  margin: 0 5px;
  background: var(--line);
}

.brand-product {
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 0;
  white-space: nowrap;
}

.brand-icon {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 4px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 21px;
}

.header-meta {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0;
}

.header-meta span {
  margin: 0 12px;
  color: var(--muted);
}

.text-button {
  padding: 8px;
  border: 0;
  background: transparent;
  color: var(--slate);
  font-size: 12px;
  font-weight: 600;
}

.site-header .text-button {
  flex-shrink: 0;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  font-weight: 500;
}

.site-header .text-button:hover:not(:disabled) {
  border-color: var(--accent-line);
}

.text-button:hover:not(:disabled) {
  background: var(--light);
  color: var(--slate-dark);
}

.text-button span {
  margin-left: 8px;
}

main {
  max-width: 1600px;
  margin: 0 auto;
  padding: 0 28px;
}

.intro {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 22px 0 18px;
}

.eyebrow {
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.9px;
}

.intro .eyebrow {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--accent);
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
}

h1 {
  margin: 5px 0 7px;
  font-size: clamp(24px, 2.4vw, 32px);
  font-weight: 650;
  line-height: 1.25;
  letter-spacing: -0.7px;
}

h1 > span {
  color: var(--accent);
}

.intro p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.intro-note {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-left: 20px;
  border-left: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

.intro-note strong {
  color: var(--ink);
  font-weight: 600;
}

.note-symbol {
  color: var(--accent);
  font: 36px Georgia, serif;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  align-items: start;
  gap: 16px;
}

.lab-card,
.control-card,
.steps-card,
.principle-card,
.observations-card {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
}

.card-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

h2 {
  margin-top: 3px;
  font-size: 18px;
  font-weight: 650;
  line-height: 1.35;
  letter-spacing: -0.3px;
}

.pill {
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--light);
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.pill.on {
  border-color: var(--accent-line);
  background: var(--accent-soft);
  color: var(--accent);
}

/* Keep the bench readable without changing the SVG's instrument presentation. */
.apparatus-wrap {
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  background: var(--paper);
  scrollbar-color: var(--accent-line) var(--paper);
  scrollbar-width: thin;
}

#apparatus {
  display: block;
  width: 100%;
  height: auto;
}

.bench-caption {
  margin: 0;
  padding: 8px 18px;
  border-top: 1px solid var(--line);
  background: var(--light);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

/* Legacy labels remain available for dynamically generated ruler markings. */
.svg-caption {
  fill: #536477;
  font: 10px system-ui, sans-serif;
  letter-spacing: 0.7px;
}

.svg-resistance {
  fill: #263445;
  font: 600 16px system-ui, sans-serif;
}

.svg-small {
  fill: #4b5b6b;
  font: 11px system-ui, sans-serif;
}

.svg-node {
  fill: #344e68;
  font: 600 13px system-ui, sans-serif;
}

.jockey {
  cursor: ew-resize;
  touch-action: none;
}

#needle {
  transition: transform 0.16s ease-out;
}

.wire-controls {
  padding: 15px 18px;
  border-top: 1px solid var(--line);
}

.control-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  font-size: 12px;
  font-weight: 600;
}

.control-label label span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 400;
}

.control-label output {
  font-size: 17px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.control-label output small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
}

input[type="range"] {
  display: block;
  width: 100%;
  height: 6px;
  margin: 16px 0 12px;
  appearance: none;
  border-radius: 3px;
  background: #302a3c;
  accent-color: var(--accent);
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  width: 18px;
  height: 18px;
  appearance: none;
  border: 2px solid var(--paper);
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 1px var(--accent-line);
}

input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border: 2px solid var(--paper);
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 1px var(--accent-line);
}

.range-labels {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 11px;
}

.fine-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 12px;
}

.fine-controls > span {
  color: var(--muted);
  font-size: 11px;
}

.small-button {
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--paper);
  color: var(--ink);
  font-size: 12px;
}

.small-button:hover:not(:disabled) {
  border-color: var(--accent-line);
  background: var(--light);
}

.readout-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 12px 18px;
  border-top: 1px solid var(--line);
  background: var(--light);
}

.readout-strip strong,
.results-bar strong {
  display: block;
  margin-top: 3px;
  font-family: ui-monospace, "Cascadia Mono", monospace;
  font-size: 23px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.readout-strip strong small,
.results-bar strong small {
  color: var(--muted);
  font-family: system-ui, sans-serif;
  font-size: 13px;
  font-weight: 400;
}

.balance-message {
  max-width: 270px;
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}

.balance-message.balanced {
  color: var(--success);
  font-weight: 700;
}

.control-card {
  padding: 0 16px;
}

.control-card .card-heading {
  margin-bottom: 14px;
  padding: 14px 0;
}

.control-icon {
  color: var(--muted);
  font-size: 22px;
}

.mode-switch {
  display: flex;
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--light);
}

.mode-switch button {
  flex: 1;
  padding: 8px 4px;
  border: 1px solid transparent;
  border-radius: 3px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
}

.mode-switch button.selected {
  border-color: var(--accent-line);
  background: var(--accent-soft);
  color: var(--ink);
  font-weight: 700;
}

.mode-switch button:hover:not(.selected) {
  background: #211d29;
}

.mode-switch span {
  margin-left: 5px;
  color: var(--accent);
}

.mode-description {
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

.control-section {
  margin-top: 14px;
  padding: 15px 0;
  border-top: 1px solid var(--line);
}

.control-section output {
  font-size: 14px;
}

.unknown-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid var(--accent-line);
  border-radius: 4px;
  background: var(--light);
}

.unknown-box .eyebrow {
  font-size: 9px;
  letter-spacing: 0.5px;
}

.unknown-box strong {
  display: block;
  margin-top: 4px;
  font-size: 22px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.icon-button {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--paper);
  color: var(--slate);
  font-size: 21px;
}

.icon-button:hover {
  background: var(--light);
}

.primary-button,
.secondary-button {
  display: block;
  width: 100%;
  padding: 11px 10px;
  border: 1px solid var(--accent-line);
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
}

.primary-button {
  background: var(--primary);
  color: #fff;
}

.primary-button:hover:not(:disabled) {
  border-color: var(--accent);
  background: linear-gradient(135deg, #8060d6, #9977e4);
}

#power-button[aria-pressed="true"] {
  border-color: var(--accent-line);
  background: var(--accent-soft);
  color: var(--ink);
}

#power-button[aria-pressed="true"]:hover:not(:disabled) {
  border-color: var(--accent);
  background: #30233f;
}

.power-icon {
  margin-right: 6px;
  font-size: 15px;
}

.secondary-button {
  margin-top: 9px;
  border-color: var(--line);
  background: var(--paper);
  color: var(--slate);
}

.secondary-button:hover:not(:disabled) {
  background: var(--light);
}

.button-hint {
  margin: 8px 0 12px;
  color: var(--muted);
  font-size: 11px;
  text-align: center;
}

.secondary-controls {
  display: flex;
  justify-content: space-between;
  gap: 4px;
  padding-top: 5px;
  border-top: 1px solid var(--line);
}

.secondary-controls .text-button {
  font-size: 11px;
}

.tip-card {
  display: flex;
  gap: 9px;
  margin: 12px 0 16px;
  padding: 11px;
  border-left: 3px solid var(--accent);
  border-radius: 3px;
  background: var(--accent-soft);
}

.tip-card > span {
  color: var(--accent);
  font-size: 17px;
}

.tip-card strong {
  font-size: 12px;
  font-weight: 600;
}

.tip-card p {
  margin-top: 4px;
  color: var(--slate);
  font-size: 11px;
  line-height: 1.6;
}

.learning-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 16px;
}

.steps-card,
.principle-card {
  padding: 18px;
}

.steps-card h2,
.principle-card h2 {
  margin: 4px 0 12px;
}

.steps-card ol {
  margin: 0;
  padding: 0;
  list-style: none;
}

.steps-card li {
  display: flex;
  gap: 12px;
  margin-top: 14px;
}

.steps-card li > span {
  display: grid;
  flex-shrink: 0;
  place-items: center;
  width: 26px;
  height: 26px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--light);
  color: var(--slate);
  font-size: 11px;
  font-weight: 600;
}

.steps-card li strong {
  font-size: 13px;
  font-weight: 600;
}

.steps-card li p,
.principle-card p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.65;
}

.principle-card {
  background: var(--light);
}

.formula {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 17px 0 12px;
  font: italic 27px Georgia, serif;
}

.fraction {
  display: inline-flex;
  flex-direction: column;
  gap: 4px;
  font-size: 21px;
  text-align: center;
}

.fraction > span:first-child {
  padding: 0 10px 4px;
  border-bottom: 1px solid var(--muted);
}

.principle-card #formula-caption {
  font-size: 11px;
  text-align: center;
}

.live-calculation {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  font-size: 13px;
}

.live-calculation span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

details {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

summary {
  color: var(--slate);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

details p {
  font-size: 11px;
}

.observations-card {
  margin-top: 16px;
}

.observation-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 15px 18px;
}

.observation-heading h2 span {
  display: inline-block;
  margin-left: 8px;
  padding: 3px 7px;
  border-radius: 4px;
  background: var(--light);
  color: var(--muted);
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0;
  vertical-align: middle;
}

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

.table-scroll {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  white-space: nowrap;
}

th {
  padding: 11px 18px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: var(--light);
  color: var(--muted);
  font-size: 10px;
  font-weight: 650;
  letter-spacing: 0.4px;
}

td {
  padding: 11px 18px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

tbody tr:hover {
  background: var(--light);
}

td:last-child {
  width: 42px;
  padding: 5px;
}

.delete-reading {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 3px;
  background: transparent;
  color: var(--muted);
  font-size: 20px;
}

.delete-reading:hover {
  background: #321c26;
  color: #f29ca9;
}

.empty-state {
  padding: 22px 18px;
  text-align: center;
}

.empty-state > span {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 24px;
}

.empty-state strong {
  font-size: 13px;
  font-weight: 600;
}

.empty-state p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}

.results-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 14px 18px;
  border-top: 1px solid var(--line);
  background: var(--light);
}

.results-bar p {
  max-width: 470px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

.answer-form {
  padding: 18px;
  border-top: 1px solid var(--line);
}

.answer-form label {
  font-size: 13px;
  font-weight: 600;
}

.answer-form > div {
  display: flex;
  gap: 10px;
  margin: 10px 0;
}

.answer-form input {
  min-width: 0;
  max-width: 250px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--paper);
  color: var(--ink);
}

.answer-form button {
  width: auto;
  padding: 10px 18px;
}

.answer-form p {
  color: var(--muted);
  font-size: 12px;
}

footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 0;
  color: var(--muted);
  font-size: 11px;
}

footer .brand {
  font-size: 10px;
  letter-spacing: 0.6px;
}

footer > span:last-child {
  font-size: 10px;
  letter-spacing: 0.5px;
}

dialog {
  width: calc(100% - 32px);
  max-width: 560px;
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 18px 70px #0009;
}

dialog::backdrop {
  background: #000b;
}

.dialog-close {
  position: absolute;
  top: 12px;
  right: 12px;
}

dialog > .eyebrow {
  display: block;
  padding-right: 28px;
}

dialog h2 {
  margin: 12px 0;
  padding-right: 20px;
}

dialog p,
dialog li {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.75;
}

dialog ol {
  padding-left: 22px;
}

dialog li {
  padding: 4px 0;
}

.help-note {
  margin: 14px 0;
  padding: 12px;
  border-left: 3px solid var(--accent);
  border-radius: 3px;
  background: var(--accent-soft);
}

.toast {
  position: fixed;
  z-index: 10;
  bottom: 22px;
  left: 50%;
  max-width: calc(100% - 32px);
  padding: 12px 18px;
  transform: translate(-50%, 12px);
  border: 1px solid var(--accent-line);
  border-radius: 5px;
  background: var(--light);
  color: var(--ink);
  font-size: 12px;
  box-shadow: 0 4px 18px #0006;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}

.toast.visible {
  transform: translate(-50%, 0);
  opacity: 1;
}

[hidden] {
  display: none !important;
}

@media (max-width: 1150px) {
  main {
    padding: 0 18px;
  }

  .site-header {
    padding-right: 18px;
    padding-left: 18px;
  }

  #apparatus {
    min-width: 780px;
  }

  .intro-note {
    display: none;
  }

  .control-label label span {
    display: none;
  }
}

@media (max-width: 850px) {
  .workspace,
  .learning-row {
    grid-template-columns: minmax(0, 1fr);
  }

  .control-card {
    padding: 0 18px;
  }

  .mode-description {
    margin-bottom: 12px;
  }

  .bench-caption {
    border-left: 3px solid var(--accent);
    background: var(--accent-soft);
    color: var(--slate);
  }
}

@media (max-width: 540px) {
  main {
    padding: 0 12px;
  }

  .site-header {
    gap: 8px;
    min-height: 52px;
    padding: 8px 12px;
  }

  .brand {
    gap: 7px;
    font-size: 10px;
    letter-spacing: 0.5px;
  }

  .header-meta,
  .brand-product,
  .brand-divider {
    display: none;
  }

  .site-header .text-button {
    font-size: 11px;
  }

  .intro {
    padding: 16px 0;
  }

  .intro .eyebrow {
    font-size: 9px;
    letter-spacing: 0.5px;
  }

  .desktop-break {
    display: none;
  }

  .card-heading,
  .wire-controls,
  .readout-strip,
  .observation-heading,
  .results-bar,
  .answer-form {
    padding-right: 14px;
    padding-left: 14px;
  }

  .readout-strip {
    align-items: flex-start;
    gap: 12px;
  }

  .readout-strip .eyebrow {
    font-size: 9px;
    letter-spacing: 0.4px;
  }

  .readout-strip strong {
    font-size: 21px;
  }

  .balance-message {
    max-width: 46%;
    font-size: 11px;
  }

  .fine-controls {
    gap: 8px;
  }

  .fine-controls > span {
    font-size: 10px;
  }

  .steps-card,
  .principle-card {
    padding: 16px;
  }

  .observation-heading {
    flex-wrap: wrap;
  }

  .table-actions {
    margin-left: auto;
  }

  .results-bar {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }

  .answer-form > div {
    flex-wrap: wrap;
  }

  .answer-form input {
    flex: 1 1 150px;
  }

  footer {
    flex-wrap: wrap;
    gap: 8px;
    padding: 18px 0;
  }

  footer > span:last-child {
    display: none;
  }

  dialog {
    padding: 24px 20px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}

/* Embedded in an existing EDZA page: retain the experiment, omit duplicate chrome. */
body.embedded { background: var(--bg); }
.embedded .site-header,
.embedded footer { display: none; }
.embedded main { max-width: none; padding: 0 16px; }
.embedded .intro { padding-top: 16px; }
