:root {
  --ink: #26334b;
  --muted: #65738b;
  --purple: #7544c3;
  --teal: #008a95;
  --orange: #d56822;
  --border: #dfe5ef;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(ellipse at top left, #eee7fb 0, transparent 45%),
    #f3f6fa;
  font-family: system-ui, sans-serif;
  line-height: 1.4;
}

.app {
  max-width: 1800px;
  margin: auto;
  padding: 14px 20px;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 12px;
}

.eyebrow {
  color: var(--purple);
  font-size: .66rem;
  font-weight: 800;
  letter-spacing: .18em;
}

h1 {
  margin: 2px 0 0;
  font-size: clamp(1.25rem, 2vw, 1.85rem);
  line-height: 1.2;
}

.page-header p {
  color: var(--muted);
  font-size: .85rem;
}

h2, p {
  margin: 0;
}

button, input {
  font: inherit;
}

button {
  padding: 8px 12px;
  color: white;
  background: var(--purple);
  border: 1px solid var(--purple);
  border-radius: 9px;
  font-size: .8rem;
  font-weight: 700;
  cursor: pointer;
}

button.secondary {
  color: var(--purple);
  background: #f4effb;
  border-color: #dfd3ef;
}

button:hover {
  filter: brightness(.96);
}

button:focus-visible,
summary:focus-visible,
input:focus-visible {
  outline: 3px solid #b59bdd;
  outline-offset: 3px;
}

.control-bar {
  display: grid;
  grid-template-columns: auto repeat(3, minmax(0, 1fr));
  align-items: center;
  gap: 22px;
  padding: 12px 16px;
  margin-bottom: 12px;
  background: #ffffffed;
  border: 1px solid var(--border);
  border-radius: 14px;
}

.play-controls {
  display: flex;
  gap: 8px;
}

label {
  display: block;
  font-size: .78rem;
  font-weight: 650;
}

output {
  float: right;
  margin-left: 8px;
  color: var(--purple);
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  display: block;
  width: 100%;
  height: 16px;
  margin: 7px 0 0;
  accent-color: var(--purple);
  cursor: pointer;
}

input[type="checkbox"] {
  accent-color: var(--purple);
}

/* The left panel spans both rows. */
.dashboard {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
  grid-template-rows: auto auto;
  gap: 12px;
  align-items: stretch;
}

.panel {
  min-width: 0;
  overflow: hidden;
  background: white;
  border: 1px solid var(--border);
  border-radius: 15px;
  box-shadow: 0 4px 15px #29314b05;
}

.experiment-panel {
  grid-column: 1;
  grid-row: 1 / 3;
  display: flex;
  flex-direction: column;
}

.zoom-panel {
  grid-column: 2;
  grid-row: 1;
}

.graph-panel {
  grid-column: 2;
  grid-row: 2;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid #edf0f6;
}

.experiment-panel .panel-heading {
  background: #f3effb;
}

.zoom-panel .panel-heading {
  background: #edf8f8;
}

.graph-panel .panel-heading {
  background: #fff5ec;
}

.panel-heading > div {
  display: flex;
  align-items: center;
  gap: 9px;
}

.panel-heading h2 {
  font-size: .92rem;
}

.step {
  display: inline-grid;
  place-items: center;
  width: 25px;
  height: 25px;
  border-radius: 8px;
  background: white;
  color: var(--purple);
  font-size: .7rem;
  font-weight: 800;
}

.badge {
  color: var(--muted);
  font-size: .68rem;
}

.options, .legend {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 16px;
  padding: 8px 14px;
}

.options label, .legend {
  font-size: .74rem;
}

.legend {
  color: var(--muted);
}

.s1 {
  color: var(--teal);
}

.s2 {
  color: var(--orange);
}

.purple {
  color: var(--purple);
}

.main-stage {
  flex: 1;
  display: flex;
  align-items: center;
}

/* Preserve the aspect ratio: circles remain circular. */
canvas {
  display: block;
  width: 100%;
  height: auto;
}

#experiment {
  touch-action: none;
}

.position-controls {
  padding: 10px 14px;
  background: #faf9fd;
  border-top: 1px solid #eee8f6;
}

.preset-buttons, .arrival-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.preset-buttons {
  margin-top: 9px;
}

.arrival-buttons {
  padding: 0 14px 10px;
}

.arrival-buttons button {
  flex: 1;
}

#notice {
  color: var(--purple);
  font-size: .75rem;
}

#notice:not(:empty) {
  margin-top: 8px;
}

.phase-controls {
  padding: 0 14px 10px;
}

#instant {
  margin-top: 5px;
  color: var(--muted);
  font-size: .7rem;
  font-variant-numeric: tabular-nums;
}

.result-strip {
  display: grid;
  grid-template-columns: minmax(0, 2.3fr) repeat(3, minmax(0, 1fr));
  align-items: center;
  gap: 16px;
  margin-top: 12px;
  padding: 12px 16px;
  background: white;
  border: 1px solid var(--border);
  border-radius: 14px;
}

.result-summary h2 {
  margin-bottom: 6px;
  color: var(--purple);
  font-size: .9rem;
}

.meter {
  height: 8px;
  overflow: hidden;
  background: #17202d;
  border-radius: 20px;
}

#brightnessBar {
  width: 100%;
  height: 100%;
  background: #ffd166;
}

#brightnessText {
  margin-top: 4px;
  color: var(--muted);
  font-size: .68rem;
}

.measurement {
  padding-left: 16px;
  border-left: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}

.measurement span {
  display: block;
  color: var(--muted);
  font-size: .7rem;
}

.measurement strong {
  display: block;
  font-size: .87rem;
}

.explanation {
  margin-top: 10px;
  color: var(--muted);
  font-size: .83rem;
}

.explanation summary {
  width: fit-content;
  padding: 5px 0;
  color: var(--purple);
  font-weight: 650;
  cursor: pointer;
}

.explanation-content {
  max-width: 950px;
  padding: 10px 0;
}

.explanation-content p + p {
  margin-top: 10px;
}

/* Presentation mode keeps the exit button accessible. */
body.presenting .page-header,
body.presenting .explanation {
  display: none;
}

body.presenting .app {
  padding-top: 10px;
}

/* Short laptop displays: tighten spacing, retain all controls. */
@media (min-width: 1051px) and (max-height: 800px) {
  .app {
    padding: 8px 14px;
  }

  .page-header {
    margin-bottom: 8px;
  }

  .page-header p, .eyebrow {
    display: none;
  }

  .control-bar {
    padding: 8px 12px;
    margin-bottom: 8px;
  }

  .dashboard {
    gap: 8px;
  }

  .panel-heading {
    padding: 6px 12px;
  }

  .legend, .options {
    padding-top: 5px;
    padding-bottom: 5px;
  }

  button {
    padding: 6px 10px;
  }

  .result-strip {
    padding: 8px 12px;
    margin-top: 8px;
  }
}

@media (max-width: 1050px) {
  .control-bar {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
  }

  .play-controls {
    grid-column: 1 / -1;
  }

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

  .experiment-panel {
    grid-column: 1 / -1;
    grid-row: 1;
  }

  .zoom-panel {
    grid-column: 1;
    grid-row: 2;
  }

  .graph-panel {
    grid-column: 2;
    grid-row: 2;
  }

  .page-header p {
    display: none;
  }
}

@media (max-width: 650px) {
  .app {
    padding: 10px;
  }

  .control-bar, .dashboard {
    display: flex;
    flex-direction: column;
    align-items: stretch;
  }

  .control-bar {
    gap: 14px;
  }

  .result-strip {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
  }

  .result-summary {
    grid-column: 1 / -1;
  }

  .measurement {
    padding-left: 8px;
  }

  .badge {
    display: none;
  }
}