:root {
  --paper: #ece7e1;
  --ink: #1f1d1b;
  --ink-2: #4a4641;
  --ink-3: #7d7871;
  --hair: rgba(31, 29, 27, 0.22);
  --line: rgba(31, 29, 27, 0.55);
  --live: #3f8a5c;
  --accent: #c8641c;
  --serif: "Newsreader", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --display: "Instrument Serif", "Newsreader", Georgia, serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --pad: 48px;
  --panel-w: 284px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body { overflow: hidden; }

button, input, output { font: inherit; color: inherit; }

/* ------------------------------------------------------------ stage */
.stage {
  position: fixed;
  inset: 0;
  z-index: 0;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
.stage.over { cursor: grab; }
.stage.dragging { cursor: grabbing; }

/* the tuning banner: glows prominently for a few seconds over the jars,
   then moves aside and stays as a small mark */
.banner {
  position: absolute;
  left: var(--bx, 50%);
  top: var(--by, 50%);
  transform: translate(-50%, -50%) scale(0.92);
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
  font-family: var(--display);
  font-style: italic;
  font-size: clamp(22px, 2.3vw, 31px);
  letter-spacing: 0.01em;
  color: #4f3912;
  padding: 10px 30px 12px;
  border: 1px solid rgba(176, 132, 46, 0.75);
  outline: 1px solid rgba(176, 132, 46, 0.35);
  outline-offset: 4px;
  background: radial-gradient(ellipse at 50% 40%, rgba(255, 249, 232, 0.97), rgba(250, 236, 200, 0.92));
  box-shadow: 0 0 40px 6px rgba(244, 196, 98, 0.6), 0 0 110px 30px rgba(255, 226, 160, 0.35);
  transition: opacity 0.8s ease, transform 0.8s ease, left 1.2s ease, top 1.2s ease, font-size 1.2s ease, padding 1.2s ease, box-shadow 1.2s ease, outline-color 1.2s ease;
  z-index: 2;
}
.banner.show { opacity: 1; transform: translate(-50%, -50%) scale(1); animation: glow 1.8s ease-in-out infinite; }
.banner.mark {
  opacity: 0.92;
  left: var(--mx, 40px);
  top: var(--my, 40px);
  transform: translate(0, -50%);
  font-size: 13px;
  padding: 3px 10px 4px;
  outline-color: transparent;
  box-shadow: 0 0 10px rgba(244, 196, 98, 0.4);
}
@keyframes glow {
  0%, 100% { box-shadow: 0 0 34px 4px rgba(244, 196, 98, 0.5), 0 0 90px 24px rgba(255, 226, 160, 0.28); }
  50% { box-shadow: 0 0 52px 10px rgba(244, 196, 98, 0.75), 0 0 140px 40px rgba(255, 226, 160, 0.45); }
}

/* ------------------------------------------------------------ top bar */
.topbar {
  position: absolute;
  top: 34px;
  right: var(--pad);
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 18px;
}
.logo { display: block; line-height: 0; }
.logo img { display: block; height: 22px; width: auto; }
.badge {
  display: flex;
  align-items: center;
  gap: 7px;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.12em;
  padding: 5px 9px 4px;
  border: 1px solid var(--line);
  color: var(--ink);
  white-space: nowrap;
}
.badge .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ink-3);
  flex: none;
}
.badge.ready .dot { background: var(--live); animation: breathe 2.8s ease-in-out infinite; }
.badge.paused .dot { background: var(--ink-3); animation: none; }
@keyframes breathe {
  0%, 100% { box-shadow: 0 0 0 0 rgba(63, 138, 92, 0.35); }
  50% { box-shadow: 0 0 0 3px rgba(63, 138, 92, 0); }
}

/* --------------------------------------------------------- masthead */
.masthead {
  position: absolute;
  top: 38px;
  left: var(--pad);
  z-index: 2;
  pointer-events: none;
  display: block;
}
.kicker {
  flex-basis: 100%;
  margin: 0;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--ink-2);
}
.kicker .sep { margin: 0 0.35em; color: var(--ink-3); }
.title {
  margin: 14px 0 0 -4px;
  font-family: var(--display);
  font-style: italic;
  font-weight: 400;
  font-size: clamp(46px, min(5.3vw, 8.5vh), 86px);
  line-height: 0.95;
  letter-spacing: -0.01em;
}
.title span { display: block; }
.title .l2 { padding-left: 1.26em; }
.lede {
  display: inline-block;
  margin: 1.7em 0 0;
  font-size: 17px;
  line-height: 1.55;
  color: #3e3a35;
}

/* ------------------------------------------------------------ panel */
.panel {
  position: absolute;
  top: 78px;
  right: var(--pad);
  width: var(--panel-w);
  z-index: 3;
  border: 1px solid var(--line);
  background: rgba(236, 231, 225, 0.82);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  font-size: 13px;
}
.sheet-bar { display: none; }
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 11px 14px 10px;
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}
.panel-head em {
  font-family: var(--serif);
  font-style: italic;
  font-size: 13px;
  letter-spacing: 0;
  text-transform: none;
  color: var(--ink-2);
}
.panel section {
  border-top: 1px solid var(--hair);
  padding: 11px 14px 12px;
}
.panel h2 {
  margin: 0 0 9px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-2);
}
.panel h2 .h2note {
  font-style: italic;
  font-size: 12.5px;
  letter-spacing: 0;
  text-transform: none;
  color: var(--ink-3);
}
.panel h2 output {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0;
  text-transform: none;
  color: var(--ink);
}

.panel button {
  appearance: none;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 0;
  padding: 6px 10px 5px;
  cursor: pointer;
  font-size: 13px;
  transition: background 0.15s, color 0.15s;
}
.panel button:hover { background: rgba(31, 29, 27, 0.06); }
.panel button:focus-visible, .panel input:focus-visible { outline: 1px solid var(--ink); outline-offset: 2px; }
.panel button.on, .panel button[aria-checked="true"] {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}

.models {
  display: flex;
  flex-direction: column;
  max-height: 178px;
  overflow-y: auto;
  overscroll-behavior: contain;
  border-top: 1px solid var(--hair);
  border-bottom: 1px solid var(--hair);
  scrollbar-width: thin;
}
.panel .models button {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  flex: none;
  border: 0;
  border-bottom: 1px solid var(--hair);
  padding: 5px 8px 4px;
  text-align: left;
  line-height: 1.2;
}
.panel .models button:last-child { border-bottom: 0; }
.models .nm { font-size: 13px; }
.models .pr { font-family: var(--mono); font-size: 10.5px; color: var(--ink-3); white-space: nowrap; }
.models button[aria-checked="true"] .pr { color: rgba(236, 231, 225, 0.72); }

.ends {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
  font-size: 12px;
  color: var(--ink-3);
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 18px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track { height: 1px; background: var(--ink); }
input[type="range"]::-moz-range-track { height: 1px; background: var(--ink); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 11px;
  height: 11px;
  margin-top: -5px;
  border-radius: 50%;
  background: var(--ink);
  border: 2px solid var(--paper);
  box-shadow: 0 0 0 1px var(--ink);
}
input[type="range"]::-moz-range-thumb {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--ink);
  border: 2px solid var(--paper);
  box-shadow: 0 0 0 1px var(--ink);
}

.row3 { display: grid; grid-template-columns: 1.2fr 1fr 1fr; gap: 6px; align-items: center; }
.row3 label { display: flex; align-items: center; gap: 7px; cursor: pointer; }
.row3 input[type="checkbox"] {
  -webkit-appearance: none;
  appearance: none;
  width: 11px;
  height: 11px;
  margin: 0;
  border: 1px solid var(--ink);
  cursor: pointer;
}
.row3 input[type="checkbox"]:checked { background: var(--ink); box-shadow: inset 0 0 0 2px var(--paper); }

/* ---------------------------------------------------------- readout */
.readout {
  position: absolute;
  left: var(--pad);
  right: var(--pad);
  bottom: 26px;
  z-index: 2;
  pointer-events: none;
}
/* the summary: a row of cells between hairlines, as in a lab notebook */
.stats { display: flex; margin: 0; }
.stats > div {
  position: relative;
  padding: 0 26px;
  border-left: 1px solid var(--hair);
}
.stats > div:first-child { padding-left: 0; border-left: 0; }
.stats dt {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--ink-2);
  white-space: nowrap;
}
.stats dd {
  margin: 8px 0 0;
  font-family: var(--mono);
  font-size: 24px;
  letter-spacing: -0.01em;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.stats .pair dd small {
  margin-left: 0.6em;
  font-size: 12px;
  letter-spacing: 0;
  color: var(--ink-3);
}
.stats .pair dd small span { color: var(--ink-2); }
/* a value that changed notably flashes: a short orange wash, or dark red
   when quality drops */
.stats > div::after {
  content: "";
  position: absolute;
  inset: -4px 6px -5px 6px;
  border-radius: 2px;
  background: var(--accent);
  opacity: 0;
  pointer-events: none;
}
.stats > div:first-child::after { left: -6px; }
.stats > div.flash dd { animation: flashText 1.3s ease-out; }
.stats > div.flash::after { animation: flashBg 1.3s ease-out; }
.stats > div.dip dd { animation: dipText 1.8s ease-out; }
.stats > div.dip::after { background: #a8432a; animation: flashBg 1.8s ease-out; }
/* the router costs more than your model alone: said plainly, in red */
.stats > div.neg dd { color: #a8432a; }
/* a big jump (the tuning, a new scenario): a longer, stronger highlight */
.stats > div.jump dd { animation: jumpText 2.6s ease-out; transform-origin: left center; }
.stats > div.jump::after { animation: jumpBg 2.6s ease-out; }
@keyframes jumpText { 0% { color: var(--accent); transform: scale(1.22); } 35% { color: var(--accent); transform: scale(1.12); } 100% { color: inherit; transform: none; } }
@keyframes jumpBg { 0% { opacity: 0.3; } 40% { opacity: 0.2; } 100% { opacity: 0; } }
@keyframes flashText { 0% { color: var(--accent); } 100% { color: inherit; } }
@keyframes dipText { 0% { color: #a8432a; } 100% { color: inherit; } }
@keyframes flashBg { 0% { opacity: 0.14; } 100% { opacity: 0; } }
.foot {
  margin: 12px 0 0;
  max-width: min(640px, calc(100% - var(--panel-w) - 40px));
  font-size: 11px;
  line-height: 1.4;
  color: var(--ink-3);
}

/* ----------------------------------------------------------- inside */
.inside {
  position: absolute;
  right: var(--pad);
  bottom: 30px;
  width: var(--panel-w);
  z-index: 4;
}
.inside summary {
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 9px 0 0;
  border-top: 1px solid var(--line);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  cursor: pointer;
}
.inside summary::-webkit-details-marker { display: none; }
.inside .plus {
  font-family: var(--mono);
  font-size: 14px;
  letter-spacing: 0;
  transition: transform 0.2s;
}
.inside[open] .plus { transform: rotate(45deg); }
.inside-body {
  position: absolute;
  right: 0;
  bottom: calc(100% + 10px);
  width: min(480px, calc(100vw - var(--pad) * 2));
  max-height: calc(100vh - 150px);
  overflow: auto;
  padding: 6px 20px 16px;
  background: var(--paper);
  box-shadow: 0 18px 40px -24px rgba(31, 29, 27, 0.35);
  border: 1px solid var(--line);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink-2);
}
.inside-body h3 {
  margin: 16px 0 4px;
  font-family: var(--display);
  font-style: italic;
  font-weight: 400;
  font-size: 22px;
  color: var(--ink);
}
.inside-body p { margin: 0 0 8px; }
.inside-body .tease { margin-top: 14px; font-style: italic; color: var(--ink); }

.noscript { position: absolute; top: 50%; width: 100%; text-align: center; }

/* ------------------------------------------- the stats row, narrower */
@media (max-width: 1400px) and (min-width: 821px) {
  .stats > div { padding: 0 14px; }
  .stats dd { font-size: 18.5px; }
  .stats dt { letter-spacing: 0.15em; }
  .stats .pair dd small { font-size: 11px; margin-left: 0.5em; }
}
@media (max-width: 1100px) and (min-width: 821px) {
  .stats { flex-wrap: wrap; row-gap: 10px; }
  .stats > div { padding: 0 11px; }
  .stats dd { font-size: 16px; }
}

/* ------------------------------------------------- smaller desktops */
@media (max-width: 1180px) and (min-width: 821px) {
  :root { --pad: 32px; --panel-w: 264px; }
  .lede { font-size: 15px; }
}

/* ------------------------------------------------- short viewports */
@media (max-height: 820px) and (min-width: 821px) {
  .topbar { top: 26px; }
  .masthead { top: 26px; }
  .title { margin-top: 8px; font-size: clamp(44px, min(6vw, 8.4vh), 100px); }
  .lede { font-size: 14.5px; line-height: 1.4; }
  .panel { top: 66px; max-height: calc(100vh - 66px - 150px); overflow-y: auto; }
  .panel-head { padding: 9px 14px 8px; }
  .panel section { padding: 8px 14px 9px; }
  .panel h2 { margin-bottom: 6px; }
  .models button { padding: 3px 8px 2px; }
  .panel button { padding-top: 4px; padding-bottom: 3px; }
  .readout { bottom: 16px; }
  .foot { margin-top: 8px; max-width: 760px; }
  .inside { bottom: 20px; }
}

/* ----------------------------------------------------------- phones */
@media (max-width: 820px) {
  :root { --pad: 20px; }
  body { overflow-x: hidden; overflow-y: auto; }
  .page { display: flex; flex-direction: column; padding-bottom: 70px; }
  .topbar {
    position: static;
    order: 0;
    justify-content: space-between;
    padding: 16px var(--pad) 0;
  }
  .logo img { height: 20px; }
  .masthead {
    position: static;
    order: 1;
    display: block;
    max-width: none;
    padding: 18px var(--pad) 0;
  }
  .title { margin: 10px 0 0; font-size: clamp(34px, 9.6vw, 72px); }
  .title .l2 { padding-left: 0.6em; }
  .lede { margin-top: 14px; font-size: 15px; line-height: 1.45; }
  .stage {
    position: relative;
    order: 2;
    inset: auto;
    height: 400px;
    margin-top: 0;
  }
  .readout {
    position: static;
    order: 3;
    padding: 2px var(--pad) 0;
    max-width: none;
  }
  .stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); row-gap: 14px; }
  .stats > div { padding: 0 10px; min-width: 0; }
  .stats dt { white-space: normal; line-height: 1.25; min-height: 2.5em; }
  .stats > div:nth-child(3n + 1) { padding-left: 0; border-left: 0; }
  .stats > div:nth-child(3n + 1)::after { left: -6px; }
  .stats dt { font-size: 8.5px; letter-spacing: 0.14em; }
  .stats dd { font-size: 16px; margin-top: 2px; }
  .stats .pair dd small { display: block; margin: 1px 0 0; font-size: 10.5px; }
  .foot { max-width: none; margin-top: 16px; }
  .inside { position: static; order: 5; width: auto; margin: 28px var(--pad) 24px; }
  .inside-body { position: static; width: auto; max-height: none; margin-top: 10px; }

  /* the setup is a bottom sheet: a slim bar that opens over the page */
  .panel {
    position: fixed;
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    z-index: 10;
    border: 0;
    border-top: 1px solid var(--line);
    background: rgba(236, 231, 225, 0.94);
    box-shadow: 0 -14px 30px -22px rgba(31, 29, 27, 0.45);
  }
  .panel-head { display: none; }
  .sheet-bar {
    display: flex;
    width: 100%;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    min-height: 56px;
    padding: 8px var(--pad) 8px;
    border: 0;
    background: transparent;
    text-align: left;
    cursor: pointer;
  }
  .panel button.sheet-bar:hover { background: transparent; }
  .sb-l, .sb-r { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
  .sb-r { align-items: flex-end; flex-direction: row; gap: 12px; }
  .sb-title { font-size: 10.5px; font-weight: 500; letter-spacing: 0.22em; text-transform: uppercase; }
  .sb-sum { font-size: 13.5px; font-style: italic; color: var(--ink-2); line-height: 1.3; }
  .chev {
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border: 1px solid var(--line);
    font-family: var(--mono);
    font-size: 16px;
  }
  .chev::before { content: "+"; }
  .panel.open .chev::before { content: "\00d7"; }
  .panel-body {
    display: none;
    max-height: calc(100vh - 56px - 400px);
    min-height: 220px;
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  .panel.open .panel-body { display: block; }
  .panel section { padding: 8px var(--pad) 9px; }
  .panel h2 { margin-bottom: 6px; }
  .models { max-height: 132px; }
  .panel .models button { min-height: 38px; align-items: center; padding: 4px var(--pad) 3px 8px; }
  input[type="range"] { height: 30px; }
  input[type="range"]::-webkit-slider-thumb { width: 22px; height: 22px; margin-top: -11px; }
  .row3 { grid-template-columns: 1.2fr 1fr 1fr; }
  .row3 label { min-height: 38px; }
  .row3 button { min-height: 38px; }
  .ends { margin-top: 0; }
}

/* the small switches beside "Router on" */
.panel .row3 button.small { white-space: nowrap; padding: 5px 6px 4px; font-size: 12px; }
