:root {
  --panel-w: 320px;
  --anode: #d4b9ff;
  --cathode: #75d8fb;
}
#app button {
  min-height: 42px;
  padding: 6px 13px;
  border: 1px solid #39465a;
  border-radius: 8px;
  background: #141c29;
  color: var(--accent);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
#app button:hover { border-color: var(--accent); }
#app :focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
#stage {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  justify-items: center;
  padding: 20px 24px 16px;
  background: radial-gradient(ellipse at 50% 53%, #0e1a27 0%, #05070d 72%);
}
.experiment-head, .experiment-foot, .stage-actions { width: min(100%, 760px); }
.experiment-title, .experiment-bar, .stage-status {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.experiment-title { margin-bottom: 10px; }
.experiment-title h1 { margin: 0; font-size: 18px; color: var(--accent); }
.experiment-title a { color: #bac9dc; font-size: 12px; text-decoration: none; padding: 8px 0; }
.experiment-title a:hover { color: var(--accent); }
.presets, .stage-actions { display: flex; gap: 6px; }
#app button[aria-pressed="true"]:not(.apparatus-control) {
  background: var(--accent);
  color: #171309;
  border-color: var(--accent);
  font-weight: 650;
}
#energy { color: #bac9dc; font-size: 13px; }
.experiment-body {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  justify-items: center;
  width: 100%;
  min-height: 0;
}
.apparatus-slot {
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 0;
  container-type: size;
}
.apparatus {
  position: relative;
  width: min(100cqw, 100cqh * 640 / 410, 850px);
  aspect-ratio: 640 / 410;
}
#canvas { width: 100%; height: 100%; }
#app .apparatus-control {
  position: absolute;
  min-width: 44px;
  min-height: 44px;
  transform: translate(-50%, -50%);
  padding: 0;
  border-color: transparent;
  background: transparent;
  touch-action: manipulation;
}
#app .apparatus-control:hover, #app .apparatus-control:focus-visible {
  border-color: #ffc94a99;
  background: #ffc94a0c;
}
#wireControl { left: 29.7%; top: 15.6%; width: 14%; height: 15%; }
#bridgeControl { left: 50%; top: 39%; width: 25%; height: 18%; }
.reaction-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.reaction-pair > div {
  display: grid;
  justify-items: center;
  gap: 2px;
  padding: 8px 4px;
  border: 1px solid #2f384e;
  border-radius: 8px;
  background: #101724;
}
.reaction-pair strong { font-size: 13px; color: var(--anode); }
.reaction-pair > :last-child strong { color: var(--cathode); }
.reaction-pair span { font-size: 15px; white-space: nowrap; }
.stage-status { min-height: 36px; color: #b9c8da; font-size: 13px; }
#status::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-right: 6px;
  background: #91a2b8;
}
#status[data-state="running"]::before { background: #78dfb0; }
#status[data-state="blocked"]::before { background: var(--accent); }
.stage-charge { white-space: nowrap; font-variant-numeric: tabular-nums; }
#app #play { min-width: 70px; background: #312719; border-color: #8c6b2d; }
#app #panelToggle, #app #panelClose { display: none; }
#panel { padding: 18px 16px 24px; background: #0f1520; }
.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
#panel #panelTitle { margin: 0; font-size: 15px; }
#panel .measurement { padding: 12px; border: 1px solid #304055; border-radius: 10px; background: #161f2d; margin-bottom: 12px; }
.primary-reading { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; }
.primary-reading > span { font-size: 13px; color: #c0ccdb; }
.primary-reading strong { color: #f4b987; font-size: 22px; }
.measurement dl { grid-template-columns: 1fr auto; }
.measurement dd { text-align: right; }
.measurement dd, .primary-reading strong { font-variant-numeric: tabular-nums; }
#panel .slider { min-height: 39px; margin: 0; grid-template-columns: 56px minmax(0, 1fr) 54px; font-size: 13px; }
.slider output { color: #d4dfeb; }
.slider input { margin: 0; min-height: 32px; }
#panel .checks { gap: 0 6px; }
#panel .switch { min-height: 44px; font-size: 13px; gap: 6px; }
#panel .switch input { width: 15px; height: 15px; margin: 0; }
#bridgeRow[hidden], #bridgeControl[hidden] { display: none; }
.model-notes { border-top: 1px solid var(--line); padding: 0 0 8px; font-size: 13px; }
.model-notes summary { color: var(--accent); cursor: pointer; padding: 12px 0; }
.model-notes p { margin: 0 0 6px; }
#shareStatus { overflow-wrap: anywhere; }
#shareStatus:empty { display: none; }
@media (max-width: 760px) {
  #stage { padding: 8px 12px 10px; }
  .experiment-title { margin-bottom: 5px; }
  .experiment-title h1 { font-size: 16px; }
  .experiment-title a { padding: 5px 0; }
  #energy { font-size: 12px; }
  #app button { min-height: 44px; padding-inline: 10px; }
  .experiment-body { grid-template-rows: minmax(0, auto) auto; align-content: center; }
  .apparatus-slot { height: min(calc((100vw - 24px) * 410 / 640), 46dvh); }
  .stage-actions { padding-bottom: env(safe-area-inset-bottom, 0px); }
  .reaction-pair > div { padding: 5px 3px; }
  .reaction-pair span { font-size: clamp(11px, 3.6vw, 14px); }
  .stage-status { font-size: 12px; min-height: 32px; }
  #app #panelToggle, #app #panelClose { display: block; position: static; z-index: auto; }
  #app #panelToggle { margin-left: auto; border-radius: 8px; }
  #panel { height: 46%; max-height: none; padding-top: 10px; }
  #app:has(#panel:not(.collapsed)) #stage { bottom: 46%; }
  #app:has(#panel:not(.collapsed)) .experiment-body { grid-template-rows: minmax(0, 1fr) auto; align-content: stretch; }
  #app:has(#panel:not(.collapsed)) .apparatus-slot { height: auto; }
  #panel.collapsed { visibility: hidden; }
  .panel-head { margin-bottom: 6px; }
}
@media (max-width: 370px) {
  #energy { font-size: 11px; }
  #app .presets button { padding-inline: 7px; }
}
@media (prefers-reduced-motion: reduce) {
  #panel { transition: none; }
}
#stageCopper { display: none; }
@media (max-width: 760px) {
  #stageCopper { display: inline; margin-left: 8px; color: #f4b987; }
}
