/* =========================================================
   Z Test Calculator — "Instrument panel on lab paper"
   ========================================================= */
:root {
  --paper: #F3EDE1;
  --paper-2: #EAE2D2;
  --card: #FBF8F2;
  --ink: #141D26;
  --ink-2: #3E4954;
  --ink-3: #7A828A;
  --rule: #D9CEB9;
  --accent: #E0492B;
  --accent-soft: #F7D9CF;
  --accept: #1E6B66;
  --accept-soft: #D4E7E3;
  --gold: #E9B44C;
  --stage: #131C25;
  --stage-2: #1B2731;
  --stage-line: #2A3743;
  --cream: #F3EDE1;

  --f-display: "Instrument Sans", "Segoe UI", system-ui, sans-serif;
  --f-body: "Instrument Sans", "Segoe UI", system-ui, sans-serif;
  --f-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;

  --r: 16px;
  --ease: cubic-bezier(.2, .8, .2, 1);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.5 var(--f-body);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
/* paper grain */
body::before {
  content: "";
  position: fixed; inset: 0;
  pointer-events: none; z-index: 100;
  opacity: .35; mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.45 0 0 0 0 0.38 0 0 0 0 0.28 0 0 0 .18 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

button, input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
sup { font-size: .7em; line-height: 0; }

/* ---------- Masthead ---------- */
.masthead {
  max-width: 1480px; margin: 0 auto;
  padding: 22px 32px 18px;
  display: flex; align-items: center; justify-content: space-between; gap: 20px;
  border-bottom: 1px solid var(--rule);
}
.wordmark { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.wordmark-logo { display: block; width: 40px; height: 40px; flex: none; }
.wordmark-text { display: flex; flex-direction: column; }
.wordmark-text strong { font: 700 20px/1.1 var(--f-display); letter-spacing: -.015em; }
.masthead-actions { display: flex; gap: 10px; }
.btn-ghost, .btn-ink {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 16px; border-radius: 999px; cursor: pointer;
  font-weight: 500; font-size: 14px;
  transition: transform .2s var(--ease), background .2s, box-shadow .2s;
}
.btn-ghost svg, .btn-ink svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn-ghost { background: transparent; border: 1px solid var(--rule); }
.btn-ghost:hover { background: var(--card); }
.btn-ink { background: var(--ink); color: var(--cream); border: 1px solid var(--ink); }
.btn-ink:hover { transform: translateY(-1px); box-shadow: 0 6px 16px -6px rgba(20, 29, 38, .5); }

/* ---------- Layout ---------- */
.layout {
  max-width: 1480px; margin: 0 auto;
  grid-template-areas: none;
  padding: 28px 32px 40px;
  display: grid; grid-template-columns: 372px minmax(0, 1fr); gap: 28px;
  align-items: start;
}
.results { display: grid; gap: 22px; min-width: 0; }

.page-title {
  grid-column: 1 / -1; margin: 0 0 -6px; text-align: center;
  font: 700 clamp(30px, 3.4vw, 44px)/1.1 var(--f-display); letter-spacing: -.025em;
}

/* entrance */
.reveal { animation: rise .7s var(--ease) both; animation-delay: calc(var(--d) * 70ms); }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }

/* ---------- Controls ---------- */
.controls {
  position: sticky; top: 20px;
  display: grid; gap: 26px;
  max-height: calc(100vh - 40px); overflow: auto;
  padding-right: 6px; scrollbar-width: thin;
}
.ctl-title {
  margin: 0 0 12px;
  display: flex; align-items: baseline; gap: 10px;
  font: 600 13px/1 var(--f-body); letter-spacing: .08em; text-transform: uppercase; color: var(--ink-2);
}
.ctl-title span { font: 500 15px/1 var(--f-display); color: var(--accent); letter-spacing: 0; }

.test-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.test-card {
  position: relative; cursor: pointer;
  display: flex; flex-direction: column; gap: 6px;
  padding: 12px 14px 12px;
  border: 1px solid var(--rule); border-radius: 12px;
  background: var(--card);
  transition: border-color .2s, background .2s, transform .2s var(--ease);
}
.test-card:hover { transform: translateY(-1px); border-color: var(--ink-3); }
.test-card input { position: absolute; opacity: 0; pointer-events: none; }
.test-glyph { font: italic 500 22px/1 var(--f-display); }
.test-name { font-size: 13px; line-height: 1.25; color: var(--ink-2); }
.test-card:has(input:checked) { background: var(--ink); border-color: var(--ink); color: var(--cream); }
.test-card:has(input:checked) .test-name { color: #B9C0C6; }
.test-card:has(input:checked) .test-glyph { color: var(--gold); }
.test-card:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }

fieldset.group { border: 0; margin: 0 0 14px; padding: 0; }
fieldset.group legend {
  padding: 0; margin-bottom: 8px;
  font: 500 15px/1 var(--f-display); color: var(--ink-2);
}
.field-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.field-grid.cols-2 { grid-template-columns: 1fr 1fr; }
.field {
  display: grid; grid-template-areas: "sym label" "input input"; grid-template-columns: auto 1fr;
  align-items: baseline; column-gap: 6px;
  padding: 8px 10px 4px;
  background: var(--card); border: 1px solid var(--rule); border-radius: 10px;
  transition: border-color .2s, box-shadow .2s;
  cursor: text;
}
.field:focus-within { border-color: var(--ink); box-shadow: 0 0 0 3px rgba(20, 29, 38, .08); }
.field.is-bad { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(224, 73, 43, .12); }
.field.is-locked { background: var(--paper-2); }
.field-sym { grid-area: sym; font: italic 600 15px/1 var(--f-display); color: var(--accent); }
.field-label { grid-area: label; font-size: 11px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.field input {
  grid-area: input; width: 100%;
  border: 0; background: transparent; padding: 4px 0 4px;
  font: 500 17px/1.2 var(--f-mono); letter-spacing: -.02em;
  -moz-appearance: textfield; appearance: textfield;
}
.field input::-webkit-outer-spin-button, .field input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.field input:focus { outline: none; }
.field input[readonly] { color: var(--ink-2); }
.field--wide { grid-column: 1 / -1; }

.raw { margin-top: 8px; }
.raw summary {
  cursor: pointer; list-style: none; display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--ink-2); text-decoration: underline; text-decoration-color: var(--rule); text-underline-offset: 3px;
}
.raw summary::-webkit-details-marker { display: none; }
.raw summary::before { content: "+"; font-family: var(--f-mono); color: var(--accent); }
.raw[open] summary::before { content: "−"; }
.raw textarea {
  width: 100%; min-height: 70px; margin-top: 8px; resize: vertical;
  padding: 10px; border-radius: 10px; border: 1px dashed var(--ink-3); background: var(--card);
  font: 13px/1.5 var(--f-mono);
}
.raw-info { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 6px; font: 12px/1.4 var(--f-mono); color: var(--ink-2); }
.raw-info button {
  border: 1px solid var(--ink); background: transparent; border-radius: 999px; padding: 3px 10px; cursor: pointer; font: 500 12px var(--f-body);
}
.raw-info button:hover { background: var(--ink); color: var(--cream); }

.tail-group { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.tail-btn {
  position: relative; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 10px 6px 8px; border: 1px solid var(--rule); border-radius: 12px; background: var(--card);
  font-size: 12px; color: var(--ink-2);
  transition: border-color .2s, background .2s;
}
.tail-btn input { position: absolute; opacity: 0; pointer-events: none; }
.tail-btn svg { width: 60px; height: 26px; }
.tail-btn .t-line { fill: none; stroke: currentColor; stroke-width: 1.6; }
.tail-btn .t-fill { fill: var(--accent); }
.tail-btn small { font: italic 600 16px/1 var(--f-display); color: var(--ink); }
.tail-btn:hover { border-color: var(--ink-3); }
.tail-btn:has(input:checked) { border-color: var(--ink); background: var(--ink); color: var(--cream); }
.tail-btn:has(input:checked) small { color: var(--gold); }
.tail-btn:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }

.hypotheses {
  margin-top: 12px; padding: 12px 14px;
  border-left: 3px solid var(--ink); background: var(--paper-2); border-radius: 0 10px 10px 0;
  display: grid; gap: 6px; font: 15px/1.3 var(--f-display);
}
.hypotheses div { display: flex; align-items: center; gap: 10px; }
.hyp-tag {
  display: inline-grid; place-items: center; min-width: 30px; height: 22px; border-radius: 6px;
  font: 600 12px/1 var(--f-mono); background: var(--ink); color: var(--cream);
}
.hyp-tag--alt { background: var(--accent); }

.alpha-chips { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.alpha-chips button {
  padding: 9px 0; border-radius: 10px; border: 1px solid var(--rule); background: var(--card);
  font: 500 14px var(--f-mono); cursor: pointer; transition: background .2s, border-color .2s;
}
.alpha-chips button:hover { border-color: var(--ink-3); }
.alpha-chips button.is-on { background: var(--accent); border-color: var(--accent); color: #fff; }
.alpha-slider { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
.alpha-slider output { font: 12px/1.3 var(--f-mono); color: var(--ink-2); white-space: nowrap; min-width: 108px; text-align: right; }
input[type="range"] {
  flex: 1; -webkit-appearance: none; appearance: none; height: 4px; border-radius: 4px;
  background: linear-gradient(to right, var(--accent) var(--fill, 25%), var(--rule) var(--fill, 25%));
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 18px; height: 18px; border-radius: 50%;
  background: var(--card); border: 2px solid var(--ink); cursor: grab;
}
input[type="range"]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--card); border: 2px solid var(--ink); cursor: grab; }

/* ---------- Stage ---------- */
.stage {
  position: relative; overflow: hidden;
  background:
    radial-gradient(1200px 400px at 50% 120%, rgba(233, 180, 76, .07), transparent 60%),
    linear-gradient(180deg, var(--stage-2), var(--stage));
  color: var(--cream);
  border-radius: 22px;
  padding: 26px 28px 18px;
  box-shadow: 0 30px 60px -30px rgba(20, 29, 38, .55), inset 0 1px 0 rgba(255, 255, 255, .05);
}
.stage-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; flex-wrap: wrap; }
.eyebrow { display: block; font: 600 11px/1 var(--f-body); letter-spacing: .14em; text-transform: uppercase; color: #8C98A3; margin-bottom: 8px; }
.z-readout {
  display: flex; align-items: baseline; gap: 12px;
  font: 500 clamp(52px, 7vw, 88px)/0.9 var(--f-display);
  letter-spacing: -.03em; font-variant-numeric: tabular-nums;
}
.z-readout i { color: var(--gold); font-weight: 500; }
.z-eq { color: #56636E; font-size: .6em; }
.stage-side { display: flex; align-items: center; gap: 26px; }
.stage-p { text-align: right; }
.p-big { font: 500 30px/1 var(--f-mono); letter-spacing: -.03em; }

.stamp {
  --c: var(--accent);
  display: grid; place-items: center; text-align: center;
  min-width: 150px; padding: 10px 16px 8px;
  border: 3px double var(--c); border-radius: 8px; color: var(--c);
  font: 700 17px/1 var(--f-display); letter-spacing: .06em; text-transform: uppercase;
  transform: rotate(-5deg);
  background: color-mix(in srgb, var(--c) 8%, transparent);
}
.stamp small { margin-top: 5px; font: 500 10px/1 var(--f-mono); letter-spacing: .05em; text-transform: none; opacity: .85; }
.stamp.is-accept { --c: #6FC2B8; }
.stamp.is-idle { --c: #56636E; }
.stamp.thump { animation: thump .5s var(--ease); }
@keyframes thump {
  0% { transform: rotate(-12deg) scale(1.6); opacity: 0; }
  60% { transform: rotate(-4deg) scale(.95); opacity: 1; }
  100% { transform: rotate(-5deg) scale(1); }
}

.chart-wrap { position: relative; margin: 14px -8px 0; }
#chart { display: block; width: 100%; height: auto; touch-action: none; user-select: none; }
#chart.can-drag { cursor: ew-resize; }
#grid line { stroke: var(--stage-line); stroke-width: 1; }
#acc { fill: url(#accGrad); }
#rej { fill: var(--accent); opacity: .88; }
#parea { fill: url(#hatch); }
.hatch-line { stroke: var(--gold); stroke-width: 2.4; }
#curve { fill: none; stroke: var(--cream); stroke-width: 2.6; stroke-linejoin: round; }
#curve.draw { stroke-dasharray: 1; animation: draw 1.4s var(--ease) both .2s; }
@keyframes draw { from { stroke-dashoffset: 1; } to { stroke-dashoffset: 0; } }
#crit line { stroke: var(--accent); stroke-width: 1.5; stroke-dasharray: 5 5; }
#crit text { fill: #F08C76; font: 500 13px var(--f-mono); }
#baseline { stroke: #56636E; stroke-width: 1.2; }
#ticks line { stroke: #56636E; }
#ticks text { fill: #9AA5AE; font: 500 13px var(--f-mono); }
#ticks text.sub { fill: #66737E; font-size: 11.5px; }
.axis-title { fill: var(--gold); font: italic 600 15px var(--f-display); }
.axis-title--sub { fill: #66737E; font-size: 13px; }
#needleLine { stroke: var(--gold); stroke-width: 2.2; }
#needleDot { fill: var(--stage); stroke: var(--gold); stroke-width: 2.5; }
#needleTagBox { fill: var(--gold); }
#needleTagText { fill: var(--stage); font: 600 13px var(--f-mono); }
#needleHit { fill: transparent; }
#needleHandle { fill: var(--gold); stroke: var(--stage); stroke-width: 3; cursor: grab; outline: none; transition: r .15s; }
#needleHandle:focus-visible { stroke: var(--cream); }
#chart.dragging #needleHandle { cursor: grabbing; }
#chart:not(.can-drag) #needleHandle { cursor: default; }
#needle { filter: drop-shadow(0 0 8px rgba(233, 180, 76, .35)); }

.chart-msg {
  position: absolute; inset: 0; display: none; place-items: center; text-align: center; padding: 20px;
  font: 400 20px/1.4 var(--f-display); color: #F08C76;
  background: rgba(19, 28, 37, .72); backdrop-filter: blur(2px);
}
.stage.is-invalid .chart-msg { display: grid; }

.stage-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px 20px; flex-wrap: wrap; padding-top: 6px; border-top: 1px solid var(--stage-line); margin-top: 6px; }
.legend { list-style: none; margin: 0; padding: 8px 0 0; display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 12.5px; color: #A9B3BB; }
.legend li { display: flex; align-items: center; gap: 7px; }
.legend b { font: 500 12px var(--f-mono); color: #F08C76; }
.sw { width: 14px; height: 10px; border-radius: 2px; display: inline-block; }
.sw-rej { background: var(--accent); }
.sw-p { background: repeating-linear-gradient(45deg, var(--gold) 0 2px, transparent 2px 5px); outline: 1px solid rgba(233, 180, 76, .4); }
.sw-z { width: 3px; height: 14px; background: var(--gold); }
.sw-crit { width: 14px; height: 0; border-top: 2px dashed var(--accent); border-radius: 0; }
.hint { margin: 8px 0 0; display: flex; align-items: center; gap: 6px; font: 400 14px var(--f-display); color: #8C98A3; }
.hint svg { width: 18px; height: 18px; fill: none; stroke: var(--gold); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Readout cards ---------- */
.readouts { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.card {
  background: var(--card); border: 1px solid var(--rule); border-radius: var(--r);
  padding: 16px 16px 14px; display: flex; flex-direction: column; gap: 10px; min-width: 0;
  transition: opacity .3s;
}
.card header { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card h3 .nt { text-transform: none; letter-spacing: 0; font: italic 600 14px var(--f-display); }
.pm { font: 300 .8em var(--f-body); margin-right: 2px; vertical-align: .08em; }
.card h3 { margin: 0; font: 600 12px/1.2 var(--f-body); letter-spacing: .08em; text-transform: uppercase; color: var(--ink-2); }
.pill {
  font: 500 11px/1 var(--f-mono); padding: 4px 8px; border-radius: 999px; white-space: nowrap;
  background: var(--paper-2); color: var(--ink-2);
}
.pill.is-bad { background: var(--accent-soft); color: #A6321B; }
.pill.is-good { background: var(--accept-soft); color: var(--accept); }
.big-num { font: 500 32px/1 var(--f-display); letter-spacing: -.02em; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.big-num--sm { font-size: 22px; line-height: 1.15; padding: 6px 0 5px; }
.results.is-invalid .readouts, .results.is-invalid .working { opacity: .35; pointer-events: none; }

.gauge { position: relative; height: 12px; margin-top: 8px; border-radius: 6px; background: var(--accept-soft); }
.gauge-reject { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 6px 0 0 6px; background: var(--accent-soft); transition: width .5s var(--ease); }
.gauge-alpha { position: absolute; top: -6px; bottom: -6px; width: 2px; background: var(--accent); transition: left .5s var(--ease); }
.gauge-alpha span { position: absolute; top: -14px; left: 50%; transform: translateX(-50%); font: italic 600 12px var(--f-display); color: var(--accent); }
.gauge-dot {
  position: absolute; top: 50%; width: 16px; height: 16px; margin: -8px 0 0 -8px; border-radius: 50%;
  background: var(--ink); border: 3px solid var(--card); box-shadow: 0 0 0 1px var(--ink);
  transition: left .5s var(--ease);
}
.gauge-scale, .meter-scale, .cmp-labels { display: flex; justify-content: space-between; font: 10.5px/1 var(--f-mono); color: var(--ink-3); }

.cmp { margin-top: 8px; }
.cmp-track { position: relative; height: 12px; border-radius: 6px; background: var(--paper-2); overflow: visible; }
.cmp-fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 6px; background: var(--ink); transition: width .5s var(--ease), background .3s; }
.cmp-fill.over { background: var(--accent); }
.cmp-tick { position: absolute; top: -5px; bottom: -5px; width: 2px; background: var(--accent); transition: left .5s var(--ease); }
.cmp-labels { margin-top: 6px; }

.ci { position: relative; height: 34px; margin-top: 2px; }
.ci-track { position: absolute; left: 0; right: 0; top: 16px; height: 2px; background: var(--rule); }
.ci-span {
  position: absolute; top: 10px; height: 14px; border: 2px solid var(--ink); border-top: 0; border-bottom: 0;
  background: color-mix(in srgb, var(--ink) 12%, transparent);
  transition: left .5s var(--ease), width .5s var(--ease);
}
.ci-span.open-l { border-left: 0; border-radius: 0; -webkit-mask: linear-gradient(to right, transparent, #000 18%); mask: linear-gradient(to right, transparent, #000 18%); }
.ci-span.open-r { border-right: 0; -webkit-mask: linear-gradient(to left, transparent, #000 18%); mask: linear-gradient(to left, transparent, #000 18%); }
.ci-est { position: absolute; top: 12px; width: 10px; height: 10px; margin-left: -5px; border-radius: 50%; background: var(--ink); transition: left .5s var(--ease); }
.ci-h0 { position: absolute; top: 4px; bottom: 0; width: 2px; margin-left: -1px; background: var(--accent); transition: left .5s var(--ease); }
.ci-h0 span { position: absolute; top: 28px; left: 50%; transform: translateX(-50%); font: 600 10px/1 var(--f-mono); color: var(--accent); white-space: nowrap; }

.meter { position: relative; display: grid; grid-template-columns: 2fr 3fr 3fr 4fr; gap: 3px; height: 12px; margin-top: 8px; }
.meter span { border-radius: 3px; background: var(--paper-2); }
.meter span:nth-child(2) { background: #EED9B0; }
.meter span:nth-child(3) { background: #E9B44C; }
.meter span:nth-child(4) { background: var(--accent); }
.meter i {
  position: absolute; top: -6px; width: 4px; height: 24px; margin-left: -2px; border-radius: 2px;
  background: var(--ink); box-shadow: 0 0 0 2px var(--card); transition: left .5s var(--ease);
}
.meter-scale span:nth-child(2) { margin-left: -10%; }

/* ---------- Working ---------- */
.working {
  display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 0;
  background: var(--card); border: 1px solid var(--rule); border-radius: var(--r);
  transition: opacity .3s;
}
.working-main { padding: 22px 24px; border-right: 1px solid var(--rule); }
.working-side { padding: 22px 24px; display: grid; gap: 22px; align-content: start; }
.section-title { margin: 0 0 14px; font: 600 19px/1.2 var(--f-display); letter-spacing: -.01em; }
.steps { list-style: none; margin: 0; padding: 0; counter-reset: s; display: grid; gap: 4px; }
.steps li {
  counter-increment: s; position: relative;
  display: grid; grid-template-columns: 28px 1fr; gap: 0 12px; align-items: start;
  padding: 10px 0; border-top: 1px dashed var(--rule);
}
.steps li:first-child { border-top: 0; }
.steps li::before {
  content: counter(s); grid-row: span 2;
  display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%;
  border: 1px solid var(--ink); font: 500 12px var(--f-mono);
}
.step-k { font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3); font-weight: 600; }
.step-f {
  font: 17px/2.3 var(--f-display); display: block;
  font-variant-numeric: tabular-nums;
}
.step-f b { font-family: var(--f-mono); font-weight: 500; font-size: 15px; background: var(--paper-2); padding: 1px 7px; border-radius: 6px; }
.step-f .res { background: var(--ink); color: var(--cream); }
.step-f .res.rej { background: var(--accent); color: #fff; }
.step-f .res.acc { background: var(--accept); color: #fff; }
.frac { margin: 0 2px; display: inline-flex; flex-direction: column; align-items: center; vertical-align: middle; line-height: 1.25; font-size: .92em; }
.frac > span:first-child { border-bottom: 1.3px solid currentColor; padding: 0 4px 1px; }
.frac > span:last-child { padding: 1px 4px 0; }
.sqrt { display: inline-flex; align-items: stretch; vertical-align: middle; }
.sqrt::before { content: "√"; font-size: 1.15em; margin-right: 1px; }
.sqrt > span { border-top: 1.3px solid currentColor; padding: 2px 3px 0; display: inline-flex; align-items: center; gap: 4px; }
.mono { font-family: var(--f-mono); font-size: .88em; }

.interpret p { margin: 0; font: 16px/1.6 var(--f-display); color: var(--ink-2); }
.interpret p strong { color: var(--ink); font-weight: 600; }
.assume ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.assume li { display: grid; grid-template-columns: 22px 1fr; gap: 10px; font-size: 13.5px; line-height: 1.4; color: var(--ink-2); }
.assume li::before {
  content: "✓"; display: grid; place-items: center; width: 20px; height: 20px; border-radius: 50%;
  font-size: 11px; font-weight: 700; background: var(--accept-soft); color: var(--accept);
}
.assume li.warn::before { content: "!"; background: var(--accent-soft); color: var(--accent); }
.assume li.info::before { content: "i"; font-family: var(--f-display); font-style: italic; background: var(--paper-2); color: var(--ink-2); }

/* ---------- Footer & toast ---------- */
.footer { max-width: 1480px; margin: 0 auto; padding: 0 32px 40px; }
.footer p { margin: 0; max-width: 760px; font: 14px/1.5 var(--f-display); color: var(--ink-3); }
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px); opacity: 0; z-index: 200;
  padding: 10px 18px; border-radius: 999px; background: var(--ink); color: var(--cream); font-size: 14px;
  transition: opacity .25s, transform .25s var(--ease); pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Responsive ---------- */
@media (max-width: 1280px) {
  .readouts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 1020px) {
  .layout { grid-template-columns: 1fr; }
  .controls { position: static; max-height: none; overflow: visible; padding: 0; }
  .working { grid-template-columns: 1fr; }
  .working-main { border-right: 0; border-bottom: 1px solid var(--rule); }
}
@media (max-width: 640px) {
  .masthead, .layout, .footer { padding-left: 16px; padding-right: 16px; }
  .masthead { flex-wrap: wrap; }
  .wordmark-logo { width: 36px; height: 36px; }
  .stage { padding: 20px 16px 14px; border-radius: 18px; }
  .stage-side { width: 100%; justify-content: space-between; }
  .stage-p { text-align: left; }
  .readouts { grid-template-columns: 1fr; }
  .field-grid { grid-template-columns: 1fr 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
.footer { border-top: 1px solid var(--rule); padding-top: 22px; }
.footer .copyright { max-width: none; text-align: center; font-size: 14px; color: var(--ink-3); }

/* ---------- Header menu ---------- */
.masthead { position: relative; z-index: 50; padding-top: 16px; padding-bottom: 14px; }
.site-nav { display: flex; align-items: center; }
.nav-menu { list-style: none; margin: 0; padding: 0; display: flex; align-items: center; gap: 2px; }
.nav-item { position: relative; }
.nav-top {
  display: inline-flex; align-items: center; gap: 4px; padding: 9px 12px; border: 0; border-radius: 10px; background: none;
  font: 500 14.5px/1 var(--f-body); color: var(--ink-2); text-decoration: none; cursor: pointer; white-space: nowrap;
  transition: background .15s, color .15s;
}
.nav-top:hover, .nav-top[aria-expanded="true"] { background: var(--paper-2); color: var(--ink); }
.nav-item.is-current > .nav-top, .nav-top[aria-current="page"] { color: var(--ink); box-shadow: inset 0 -2px 0 var(--accent); border-radius: 10px 10px 0 0; }
.nav-chev { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; transition: transform .2s; }
.nav-top[aria-expanded="true"] .nav-chev { transform: rotate(180deg); }
.nav-panel {
  position: absolute; top: calc(100% + 8px); left: 0; z-index: 60; min-width: 300px; padding: 8px;
  background: var(--card); border: 1px solid var(--rule); border-radius: 14px;
  box-shadow: 0 18px 40px -18px rgba(20, 29, 38, .35);
  opacity: 0; visibility: hidden; transform: translateY(-4px); transition: opacity .15s, transform .15s, visibility .15s;
}
.nav-item:nth-last-child(-n+4) .nav-panel { left: auto; right: 0; }
.nav-panel::before { content: ""; position: absolute; left: 0; right: 0; top: -10px; height: 10px; }
.nav-panel ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 1px; }
.nav-panel a { display: grid; gap: 1px; padding: 8px 12px; border-radius: 9px; text-decoration: none; color: var(--ink); }
.nav-panel a strong { font: 600 14px/1.3 var(--f-body); }
.nav-panel a span { font-size: 12.5px; line-height: 1.3; color: var(--ink-3); }
.nav-panel a:hover, .nav-panel a:focus-visible { background: var(--paper-2); }
.nav-panel a[aria-current="page"] { background: var(--ink); color: var(--cream); }
.nav-panel a[aria-current="page"] span { color: #B9C0C6; }
.nav-top[aria-expanded="true"] + .nav-panel { opacity: 1; visibility: visible; transform: none; }
@media (hover: hover) and (min-width: 1101px) {
  .has-sub:hover > .nav-panel { opacity: 1; visibility: visible; transform: none; }
}
.nav-toggle {
  display: none; align-items: center; gap: 8px; padding: 9px 14px; border: 1px solid var(--rule); border-radius: 999px;
  background: var(--card); font: 500 14px var(--f-body); color: var(--ink); cursor: pointer;
}
.nav-toggle svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
@media (max-width: 1100px) {
  .masthead { flex-wrap: wrap; }
  .nav-toggle { display: inline-flex; }
  .site-nav { position: static; }
  .nav-menu {
    display: none; position: absolute; left: 16px; right: 16px; top: 100%; z-index: 60; flex-direction: column; align-items: stretch; gap: 0;
    max-height: calc(100vh - 90px); overflow: auto; padding: 8px; background: var(--card); border: 1px solid var(--rule); border-radius: 14px;
    box-shadow: 0 18px 40px -18px rgba(20, 29, 38, .35);
  }
  .site-nav.is-open .nav-menu { display: flex; }
  .nav-top { width: 100%; justify-content: space-between; padding: 12px; }
  .nav-item.is-current > .nav-top, .nav-top[aria-current="page"] { box-shadow: inset 3px 0 0 var(--accent); border-radius: 10px; }
  .nav-panel { position: static; display: none; min-width: 0; opacity: 1; visibility: visible; transform: none; box-shadow: none; border: 0; padding: 0 0 6px 8px; background: none; }
  .nav-top[aria-expanded="true"] + .nav-panel { display: block; }
}
@media (max-width: 640px) {
  .masthead { flex-wrap: nowrap; }
}

/* ---------- Language switcher ---------- */
.lang-switch { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: center; gap: 6px 10px; margin: 0 auto 12px; max-width: 980px; }
.lang-label { font: 600 12px/1 var(--f-body); letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); }
.lang-switch ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 14px; }
.lang-switch a { font-size: 13.5px; color: var(--ink-3); text-decoration: none; }
.lang-switch a:hover { color: var(--ink); text-decoration: underline; text-underline-offset: 3px; }
.lang-switch a[aria-current="true"] { color: var(--ink); font-weight: 600; }

/* ---------- Right-to-left (Arabic) ----------
   Text and layout flip; charts, number scales, formulas and numeric controls stay left-to-right
   so axes, signs (−1.96) and equations read the same as in every other language. */
[dir="rtl"] .nav-panel { left: auto; right: 0; }
[dir="rtl"] .nav-item:nth-last-child(-n+4) .nav-panel { right: auto; left: 0; }
[dir="rtl"] svg,
[dir="rtl"] .stage-head, [dir="rtl"] .chart-wrap, [dir="rtl"] .z-readout,
[dir="rtl"] .big-num, [dir="rtl"] .p-big,
[dir="rtl"] .gauge, [dir="rtl"] .gauge-scale, [dir="rtl"] .meter, [dir="rtl"] .meter-scale,
[dir="rtl"] .cmp, [dir="rtl"] .cmp-labels, [dir="rtl"] .ci,
[dir="rtl"] .alpha-chips, [dir="rtl"] .alpha-slider, [dir="rtl"] .tail-group,
[dir="rtl"] .hypotheses, [dir="rtl"] .step-f,
[dir="rtl"] .formula-main, [dir="rtl"] .example-steps div,
[dir="rtl"] input[type="number"], [dir="rtl"] input[type="range"] { direction: ltr; }
[dir="rtl"] .stage-p, [dir="rtl"] .stamp { direction: rtl; }
[dir="rtl"] .big-num, [dir="rtl"] .hypotheses { text-align: right; }
[dir="rtl"] .alpha-slider output { text-align: left; }
[dir="rtl"] .data-table td, [dir="rtl"] .data-table th { text-align: right; }
