:root {
  /* Colors and fonts come from the shared design system (/assets/design.css);
     these names keep the rest of this stylesheet unchanged. Scene, particle and
     field colors carry meaning and stay as they were. */
  --brand-accent: var(--accent);
  --brand-accent-strong: var(--accent-hover);
  --bg-color: var(--bg);
  --bg-pattern: var(--bg-grid);
  --text-main: var(--ink);
  --text-secondary: var(--ink-2);
  --brand-primary: var(--accent);
  --scene-accent: #0D9488;
  --scene-accent-strong: #0F766E;
  --card-bg: var(--surface);
  --card-border: var(--line);
  --card-shadow: var(--shadow-1);
  --soft-shadow: var(--shadow-1);
  --muted-bg: var(--surface-3);
  --input-border: var(--line-strong);
  --nav-bg: var(--surface);
  --nav-border: var(--line);
  --viewer-bg: var(--surface-3);
  --overlay-bg: var(--surface);
  --focus: var(--accent);
  /* Physics colors shared by the 3D scene, legend and graphs. */
  --north: #D45132;
  --south: #1675BB;
  --field: #0D9488;
  --e-field: #7C3AED;
  --current: #E07A10;
  --force: #B5179E;
  --velocity: #2F6FDB;
  --copper: #B8733D;
  --steel: #8E99A4;
  --carbon: #4A5360;
  --gun: #4A5360;
  --gun-tip: #8E99A4;
  --positive: #D45132;
  --negative: #1675BB;
  --negative-ink: #fff;
  --positive-ink: #04101F;
  --alpha-ink: #04101F;
  --e-field-ink: #fff;
  --field-ink: #04101F;
  --neutral: #657481;
  --alpha: #3F8A55;
  --phase1: #E07A10;
  --phase2: #0D9488;
  --phase3: #7C3AED;
  --correct-border: #3F7A55;
  --retry-border: #9E6B27;
}

[data-theme="dark"] {
  --scene-accent: #5EEAD4;
  --scene-accent-strong: #2DD4BF;
  --north: #EF6A48;
  --south: #4BA3E3;
  --field: #2DD4BF;
  --e-field: #A78BFA;
  --current: #FBA43C;
  --force: #E879F9;
  --velocity: #6EA8FF;
  --copper: #D08A50;
  --steel: #9AA5B0;
  --carbon: #5B6573;
  --gun: #AEB8C4;
  --gun-tip: #E2E8EE;
  --positive: #EF6A48;
  --negative: #4BA3E3;
  --negative-ink: #04101F;
  --e-field-ink: #04101F;
  --neutral: #8C9AA6;
  --alpha: #4ADE80;
  --phase1: #FBA43C;
  --phase2: #2DD4BF;
  --phase3: #A78BFA;
  --correct-border: #4ADE80;
  --retry-border: #F0A64A;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background-color: var(--bg-color);
  background-image: radial-gradient(var(--bg-pattern) 1px, transparent 1px);
  background-size: 30px 30px;
  color: var(--text-main);
  font: 16px/1.65 var(--font-body);
}
button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; cursor: pointer; color: inherit; }
a { color: inherit; text-underline-offset: 4px; }
button:focus-visible, a:focus-visible, #viewer:focus-visible, select:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
.mono { font-family: var(--font-mono); }

/* Floating banner */
.banner {
  position: sticky;
  top: var(--standalone-top);
  z-index: 20;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 6px max(20px, env(safe-area-inset-right)) 6px max(20px, env(safe-area-inset-left));
  background: var(--nav-bg);
  border-bottom: 1px solid var(--nav-border);
  box-shadow: var(--soft-shadow);
}

/* Apps keep a plain title; one thin spectrum line under the banner marks the app as PanPhy. */
.banner::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  background: var(--spectrum);
  opacity: 0.85;
  pointer-events: none;
}
.banner-logo { justify-self: start; display: flex; align-items: center; min-height: 48px; line-height: 0; }
.banner-logo img { display: block; width: 38px; height: 38px; object-fit: contain; }
.banner-title {
  justify-self: center;
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.03em;
  color: var(--ink);
}
.banner-actions { justify-self: end; display: flex; gap: 8px; align-items: center; }
#theme-button { --panphy-theme-button-size: 48px; }

main, footer { width: calc(100% - 48px); max-width: 1320px; margin: auto; }
.eyebrow { margin: 0; font-family: var(--font-mono); font-size: .76rem; letter-spacing: .12em; font-weight: 600; color: var(--brand-primary); }
.intro { display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 30px 0 24px; }
.intro p { margin: 0; }
.intro > p { color: var(--text-secondary); border-left: 3px solid var(--card-border); padding-left: 22px; }
h1, h2 { font-family: var(--font-display); font-weight: 600; letter-spacing: -0.02em; }
h1 { font-size: clamp(1.8rem, 3.2vw, 3rem); letter-spacing: -.03em; line-height: 1.1; margin: 10px 0 0; }
h1 span { color: var(--brand-primary); }

/* Mode chooser */
.models { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 20px; }
.models button {
  display: grid;
  grid-template-rows: auto auto 1fr;
  align-content: start;
  gap: 2px;
  min-height: 100px;
  padding: 14px 18px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  box-shadow: var(--card-shadow);
  text-align: left;
  transition: border-color .15s, background .15s, transform .15s;
}
.models button > span { font-family: var(--font-mono); font-size: .74rem; letter-spacing: .08em; font-weight: 600; color: var(--text-secondary); }
.models strong { font-size: 1.15rem; line-height: 1.25; }
.models small { color: var(--text-secondary); font-size: .85rem; }
.models button:hover { border-color: var(--brand-accent); transform: translateY(-1px); }
.models button[aria-pressed=true] { border-color: var(--brand-accent-strong); background: var(--brand-accent-strong); color: var(--accent-ink); }
[data-theme="dark"] .models button[aria-pressed=true] { background: var(--brand-accent); border-color: var(--brand-accent); color: var(--accent-ink); }
.models button[aria-pressed=true] > span, .models button[aria-pressed=true] small { color: inherit; opacity: .85; }

.lab-strip { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 12px; color: var(--text-secondary); font-size: .8rem; }
.lab-strip b { margin-left: 12px; color: var(--text-main); }

/* Workspace: the 3D view and its controls side by side, the explanation underneath. */
.workspace {
  scroll-margin-top: 72px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(330px, 380px);
  grid-template-areas: "viewer console" "guide guide";
  border: 1px solid var(--card-border);
  border-radius: 20px;
  overflow: hidden;
  background: var(--card-bg);
  box-shadow: var(--card-shadow);
}
.viewer-panel { grid-area: viewer; display: flex; flex-direction: column; min-width: 0; padding: 20px; background: var(--viewer-bg); }
.viewer-heading { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; font-family: var(--font-mono); font-size: .76rem; font-weight: 600; letter-spacing: .08em; }
#scene-title { margin-right: auto; }
.scale { color: var(--text-secondary); font-size: .68rem; border: 1px solid var(--input-border); border-radius: 999px; padding: 4px 10px; }
#fullscreen { --panphy-fs-size: 48px; }
body.viewer-expanded { overflow: hidden; }
.workspace.is-fullscreen { position: fixed; inset: 0; z-index: 1000; width: 100%; height: 100%; height: 100dvh; display: block; border: 0; border-radius: 0; box-shadow: none; background: var(--viewer-bg); }
.workspace.is-fullscreen aside { display: none; }
.workspace.is-fullscreen .console { border: 0; padding: 16px 0 0; background: none; }
.workspace.is-fullscreen .viewer-panel { height: 100%; overflow: auto; padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
.workspace.is-fullscreen .viewer-panel > :not(#viewer) { flex-shrink: 0; }
.workspace.is-fullscreen .viewer-heading { position: sticky; top: 0; z-index: 3; background: var(--viewer-bg); padding-bottom: 8px; }
.workspace.is-fullscreen #viewer { flex: 1 0 260px; height: 0; min-height: 260px; }
/* Wide screens: the controls and the explanation share a right-hand column beside the 3D view. */
@media (min-width: 900px) {
  .workspace.is-fullscreen { display: grid; grid-template-columns: minmax(0, 1fr) clamp(320px, 30vw, 440px); grid-template-areas: "viewer guide"; }
  .workspace.is-fullscreen aside { display: block; min-height: 0; overflow: auto; border: 0; border-left: 1px solid var(--card-border); padding: max(20px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) 20px; }
  .workspace.is-fullscreen aside .console { padding: 0 0 20px; margin-bottom: 20px; border-bottom: 1px solid var(--card-border); }
}

/* contain: size keeps the canvas pixel size from feeding back into the viewer height. */
/* The 3D view grows with the screen, so it fills most of a laptop or projector screen when the sim is scrolled into view. */
#viewer { position: relative; display: flex; flex-direction: column; flex: 1; min-height: clamp(620px, calc(100vh - 260px), 820px); contain: size; margin: 8px 0 12px; border-radius: 14px; touch-action: none; overflow: hidden; }
#viewer.is-hovering { cursor: pointer; }
#viewer > canvas { display: block; width: 100%; height: 0; flex: 1; min-height: 0; align-self: stretch; }
#load-status { position: absolute; inset: 30% 10%; margin: 0; text-align: center; color: var(--text-secondary); }

.overlay { position: absolute; z-index: 2; pointer-events: none; font-size: .74rem; }
.legend { left: 10px; bottom: 10px; right: 10px; display: flex; flex-wrap: wrap; gap: 6px; }
.legend > span { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px 3px 4px; border-radius: 999px; background: var(--overlay-bg); border: 1px solid var(--card-border); }
.legend i { font-style: normal; display: inline-grid; place-items: center; border-radius: 50%; width: 18px; height: 18px; font-size: .72rem; font-weight: 800; color: #fff; }
.legend > span.is-off { opacity: .5; text-decoration: line-through; }
.legend > span.speed-key { padding: 3px 10px; }
.legend i.speed-pill { width: 72px; height: 10px; border-radius: 999px; }
.gesture { position: static; order: -1; margin: 0 2px 4px; color: var(--text-secondary); }

/* Live readouts: an equation card and a graph side by side above the 3D view, so they never cover a track.
   Each folds away to a tab, and both start folded so the 3D view gets the room. */
.stack { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; gap: 8px; margin: 8px 0 0; }
.info-box { min-width: 0; border: 1px solid var(--card-border); border-radius: 12px; background: var(--overlay-bg); }
.info-box summary { display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 12px; cursor: pointer; font-family: var(--font-mono); font-size: .7rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; list-style: none; }
.info-box summary::-webkit-details-marker { display: none; }
.info-box summary::before { content: ''; width: 6px; height: 6px; border: solid currentColor; border-width: 0 2px 2px 0; transform: rotate(-45deg); transition: transform .18s ease; }
.info-box[open] summary::before { transform: translateY(-2px) rotate(45deg); }
.info-box summary:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
.equation { padding: 0 12px 10px; font-family: var(--font-mono); font-size: .78rem; line-height: 1.5; }
.equation .row { display: flex; justify-content: space-between; gap: 10px; }
.equation .row span:first-child { color: var(--text-secondary); }
.equation .formula { font-size: .9rem; font-weight: 600; margin-bottom: 2px; }
.equation .sub { color: var(--text-secondary); font-size: .72rem; }
.equation b { font-weight: 600; color: var(--brand-primary); }
.equation .status { margin-top: 4px; font-size: .72rem; font-weight: 600; }
.equation .status.good { color: var(--correct-border); }
.equation .status.warn { color: var(--retry-border); }
.graph { padding: 0 6px 6px; }
.graph canvas { display: block; width: 100%; height: 150px; flex: none; min-height: 0; }

/* Playback bar under the 3D view */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; }
.toolbar button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 8px 14px;
  border: 1px solid var(--input-border);
  border-radius: 12px;
  background: var(--card-bg);
  font-size: .85rem;
  font-weight: 700;
  transition: border-color .15s, background .15s;
}
.toolbar button:hover { border-color: var(--brand-accent); background: var(--muted-bg); }
.toolbar svg { width: 18px; height: 18px; flex: none; fill: currentColor; }
.toolbar svg .stroke, .fire svg { fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
#motion { min-width: 150px; }
#motion[aria-pressed=false] { border-color: var(--brand-accent-strong); color: var(--brand-accent-strong); }
/* Labels that change keep the width of their widest label, so the bar does not jump. */
[data-reserve] { display: inline-grid; justify-items: center; align-content: center; }
[data-reserve]::after { content: attr(data-reserve); height: 0; overflow: hidden; visibility: hidden; }
button:disabled { cursor: default; opacity: 0.9; }

/* Control column: the main action first, then what it shows, then the settings. */
.console { grid-area: console; display: flex; flex-direction: column; gap: 12px; min-width: 0; padding: 20px; border-left: 1px solid var(--card-border); background: var(--card-bg); }
.fire {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; min-height: 56px; padding: 10px 18px;
  border: 0; border-radius: 14px;
  background: var(--brand-primary); color: var(--accent-ink);
  font-size: 1.02rem; font-weight: 800;
  box-shadow: 0 6px 16px color-mix(in srgb, var(--brand-primary), transparent 72%);
  transition: filter .15s, transform .1s;
}
.fire:hover { filter: brightness(1.07); }
.fire:active { transform: translateY(1px); }
.fire svg { width: 20px; height: 20px; }
.fire[aria-pressed=true] { background: var(--text-main); color: var(--bg-color); box-shadow: none; }
.fire[aria-pressed=true] svg { fill: currentColor; }
/* One message says what the model shows and what to try next. Room for five lines, so a longer message does not push the settings around. */
.particle-readout { margin: 0; min-height: calc(7.75em + 20px); padding: 10px 14px; border-radius: 12px; border-left: 3px solid var(--brand-accent); background: var(--muted-bg); color: var(--text-main); font-size: .84rem; line-height: 1.55; }

.sample-controls { display: flex; flex-direction: column; gap: 16px; }
.section { display: flex; flex-direction: column; gap: 8px; }
.section-title { font-family: var(--font-mono); font-size: .7rem; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--text-secondary); }
.choice-row { display: flex; flex-wrap: wrap; gap: 8px; }
.choice-row .chip { display: inline-grid; place-items: center; width: 20px; height: 20px; margin-right: 6px; border-radius: 50%; font-size: .72rem; font-style: normal; color: #fff; flex: none; }
.stepper button, .choice-row button {
  min-width: 48px; min-height: 48px; padding: 8px 12px;
  border: 1px solid var(--input-border); border-radius: 12px; background: var(--card-bg);
  font: 700 1.1rem var(--font-body); color: var(--text-main); touch-action: manipulation;
}
.choice-row button { display: inline-flex; align-items: center; justify-content: center; font-size: .85rem; }
.stepper button:hover:not(:disabled), .choice-row button:hover:not(:disabled):not([aria-pressed=true]) { border-color: var(--brand-accent); background: var(--muted-bg); }
/* The particle chooser is one segmented control: exactly one choice is lit. */
.segmented { display: grid; grid-auto-columns: 1fr; grid-auto-flow: column; gap: 4px; padding: 4px; border-radius: 14px; background: var(--muted-bg); }
.segmented button { border-color: transparent; background: none; padding: 6px 4px; line-height: 1.2; }
.segmented button[aria-pressed=true] { background: var(--brand-accent-strong); border-color: var(--brand-accent-strong); color: #fff; }
[data-theme="dark"] .segmented button[aria-pressed=true] { background: var(--brand-accent); border-color: var(--brand-accent); color: var(--accent-ink); }
.segmented button[aria-pressed=true] .chip { box-shadow: 0 0 0 2px #fff; }

/* Each setting is one row: its name on the left, exact stepping on the right. */
.setting { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 4px 4px 4px 0; border-radius: 12px; }
.setting-label { font-size: .88rem; font-weight: 600; line-height: 1.3; }
.setting.is-changed { animation: changed 1.6s ease-out; }
@keyframes changed { 0%, 30% { background: color-mix(in srgb, var(--brand-accent), transparent 78%); box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand-accent), transparent 78%); } 100% { background: transparent; box-shadow: 0 0 0 4px transparent; } }
.stepper { display: inline-flex; align-items: center; gap: 4px; flex: none; }
.stepper input {
  width: 78px; min-height: 48px; padding: 0 6px;
  border: 1px solid var(--input-border); border-radius: 12px; background: var(--card-bg);
  color: var(--text-main); text-align: center; font: 600 1rem var(--font-mono); letter-spacing: 0;
  -moz-appearance: textfield; appearance: textfield;
}
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.stepper input:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }

/* On/off settings look like switches, so their state is never confused with an action. */
.switch-list { display: flex; flex-direction: column; gap: 6px; }
.switch {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%; min-height: 48px; padding: 6px 10px 6px 14px;
  border: 1px solid var(--input-border); border-radius: 12px; background: var(--card-bg);
  font-size: .88rem; font-weight: 600; text-align: left; touch-action: manipulation;
}
.switch:hover { border-color: var(--brand-accent); }
.switch-label { display: inline-flex; align-items: center; }
.switch-label .chip { display: inline-grid; place-items: center; width: 20px; height: 20px; margin-right: 8px; border-radius: 50%; font-size: .72rem; font-style: normal; font-weight: 800; color: #fff; }
.switch-track { position: relative; flex: none; width: 44px; height: 26px; border-radius: 999px; background: var(--input-border); transition: background .15s; }
.switch-track::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: transform .15s; }
.switch[aria-pressed=true] .switch-track { background: var(--brand-accent-strong); }
.switch[aria-pressed=true] .switch-track::after { transform: translateX(18px); }

aside { grid-area: guide; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 40px; border-top: 1px solid var(--card-border); padding: 26px; background: var(--card-bg); }
aside h2 { font-size: 1.35rem; line-height: 1.15; margin: 10px 0 14px; }
aside p { color: var(--text-secondary); font-size: .92rem; margin: 8px 0 20px; }
h3 { font-size: .88rem; margin: 0; }
.icon { width: 1.15em; height: 1.15em; vertical-align: -0.2em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.idea h3 .icon { color: var(--brand-accent-strong); }
.idea { border-left: 3px solid var(--brand-accent); border-radius: 0 12px 12px 0; padding: 13px 16px; margin: 20px 0; background: var(--muted-bg); }
.idea p { margin: 6px 0 0; }
.level { display: inline-block; margin: 0 0 12px; padding: 2px 10px; border-radius: 999px; border: 1px solid var(--input-border); font-family: var(--font-mono); font-size: .7rem; letter-spacing: .06em; color: var(--text-secondary); }
.deeper { border: 1px dashed var(--input-border); border-radius: 12px; padding: 12px 16px; margin: 0 0 20px; }
.deeper p { margin: 6px 0 0; font-size: .88rem; }
.deeper h3 { color: var(--brand-primary); }

.reality { display: flex; gap: 24px; padding: 28px 0; max-width: 1030px; }
.reality > span { font-size: 2rem; color: var(--brand-primary); }
.reality h2 { font-size: 1rem; margin: 0 0 8px; }
.reality p { color: var(--text-secondary); font-size: .9rem; margin: 6px 0; }
footer { display: flex; justify-content: space-between; gap: 20px; border-top: 1px solid var(--card-border); padding: 22px 0 max(30px, env(safe-area-inset-bottom)); color: var(--text-secondary); font-size: .78rem; }
.no-script { padding: 24px; }

@media (max-width: 1100px) {
  .workspace { grid-template-columns: minmax(0, 1fr) 330px; }
  .models strong { font-size: 1.05rem; }
}
/* Narrower screens stack the view, its controls and the explanation. */
@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; grid-template-areas: "viewer" "console" "guide"; }
  .console { border-left: 0; border-top: 1px solid var(--card-border); }
  aside { display: block; }
}
@media (min-width: 640px) and (max-width: 900px) {
  .workspace:not(.is-fullscreen) .sample-controls { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 24px; align-items: start; }
}
@media (max-width: 760px) {
  main, footer { width: calc(100% - 28px); }
  .banner { padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
  .banner-title { font-size: 0.95rem; }
  .intro { display: block; padding: 22px 0 18px; }
  .intro > p { margin-top: 16px; font-size: .9rem; }
  .intro h1 { font-size: 1.7rem; }
  .models { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .models button { min-height: 84px; padding: 12px; border-radius: 14px; }
  .models strong { font-size: .98rem; }
  .models small { font-size: .76rem; }
  .lab-strip { flex-direction: column; align-items: flex-start; gap: 0; }
  .viewer-panel { padding: 12px; }
  /* On phones the readouts stack in one column above the 3D view. */
  #viewer { flex: none; height: 520px; min-height: 520px; }
  .workspace.is-fullscreen #viewer { flex: 1 0 520px; min-height: 520px; }
  .viewer-heading { font-size: .68rem; }
  .gesture { display: none; }
  .stack { grid-template-columns: 1fr; gap: 6px; }
  .console { padding: 16px 12px; }
  .particle-readout { min-height: 72px; }
  .toolbar { gap: 6px; }
  .toolbar button { flex: 1 1 auto; gap: 6px; padding: 8px 10px; white-space: nowrap; font-size: .82rem; }
  #motion { min-width: 0; }
  aside { padding: 20px; }
  .reality { gap: 12px; }
  footer { flex-direction: column; gap: 8px; }
}
@media (prefers-reduced-motion: reduce) {
  .models button, .toolbar button, .fire, .switch-track, .switch-track::after, .info-box summary::before { transition: none; }
  .setting.is-changed { animation: none; }
  .models button:hover { transform: none; }
}
