/* Physics Atlas — base elements, prose typography, buttons. */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-padding-top: calc(var(--topbar) + 56px); }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 400 var(--fs-1)/1.5 var(--font-ui);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
img, svg, canvas, video { max-width: 100%; }
img { height: auto; }
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--accent-2); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
[hidden] { display: none !important; }
.sr-only { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
::selection { background: color-mix(in srgb, var(--accent) 25%, transparent); }

h1, h2, h3, h4 { font-family: var(--font-ui); color: var(--ink); line-height: 1.2; letter-spacing: -0.01em; text-wrap: balance; }
h1 { font-size: var(--fs-5); font-weight: 700; margin: 0 0 var(--sp-3); }
h2 { font-size: var(--fs-4); font-weight: 650; margin: var(--sp-7) 0 var(--sp-4); }
h3 { font-size: var(--fs-3); font-weight: 650; margin: var(--sp-6) 0 var(--sp-3); }
h4 { font-size: var(--fs-1); font-weight: 700; margin: var(--sp-4) 0 var(--sp-2); text-transform: uppercase; letter-spacing: .06em; color: var(--ink-2); }
h4:has(.katex, .math) { text-transform: none; letter-spacing: .01em; }   /* upper-casing would change symbols (m → M) */
code { font-family: var(--font-mono); font-size: .9em; background: var(--sunken); padding: .1em .35em; border-radius: 4px; }

/* ---- prose: section text ---- */
.prose { font-family: var(--font-prose); font-size: var(--fs-2); line-height: var(--lh-prose); color: var(--ink); }
.prose p, .prose ul, .prose ol, .prose dl, .prose blockquote, .prose table { margin: 0 0 1em; max-width: var(--measure); }
.prose li { margin: .25em 0; }
.prose li::marker { color: var(--muted); }
.prose strong { font-weight: 700; }
.prose em { font-style: italic; }
.prose figure { margin: var(--sp-5) 0; }
.prose figcaption { font: var(--fs-0)/1.45 var(--font-ui); color: var(--muted); margin-top: var(--sp-2); }
.prose table { border-collapse: collapse; font: var(--fs-1)/1.4 var(--font-ui); }
.prose th, .prose td { padding: .45em .7em; border-bottom: 1px solid var(--line); text-align: left; }
.prose th { color: var(--ink-2); font-weight: 650; }
.prose blockquote { border-left: 3px solid var(--line-strong); padding-left: var(--sp-4); color: var(--ink-2); }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: var(--sp-6) 0; }
.prose details { max-width: var(--measure); margin: 0 0 1em; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.prose details > summary { cursor: pointer; padding: var(--sp-3) var(--sp-4); font: 600 var(--fs-1)/1.4 var(--font-ui); color: var(--ink-2); list-style-position: inside; }
.prose details[open] > summary { border-bottom: 1px solid var(--line); }
.prose details > :not(summary) { margin-left: var(--sp-4); margin-right: var(--sp-4); }
.prose details > :last-child { margin-bottom: var(--sp-4); }
.prose details > summary + * { margin-top: var(--sp-3); }
.prose .lead { font-size: 1.15em; color: var(--ink-2); }

/* math */
.katex { font-size: 1.08em; }
.math-display { display: block; overflow-x: auto; overflow-y: hidden; padding: .2em 0; max-width: var(--measure); }
.math-display .katex-display { margin: .4em 0; }
.math-error { color: var(--bad); font-family: var(--font-mono); border-bottom: 1px dashed var(--bad); }

/* ---- buttons ---- */
.btn {
  display: inline-flex; align-items: center; gap: .4em; min-height: 40px; padding: 0 16px;
  font: 600 var(--fs-1)/1 var(--font-ui); color: var(--ink); background: var(--raised);
  border: 1px solid var(--line-strong); border-radius: 999px; cursor: pointer;
  transition: background .15s, border-color .15s, transform .1s;
}
.btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover:not(:disabled) { background: var(--accent-2); border-color: var(--accent-2); color: var(--on-accent); }
.btn-quiet { background: transparent; border-color: transparent; color: var(--accent); padding: 0 10px; }
.btn-quiet:hover:not(:disabled) { background: var(--accent-soft); border-color: transparent; }
.btn-nudge { animation: nudge 1.6s var(--ease) 2; background: var(--accent-soft); }
@keyframes nudge { 0%, 100% { transform: none; } 50% { transform: translateY(-2px); } }

.icon-btn { width: 40px; height: 40px; display: inline-grid; place-items: center; border: 1px solid transparent; background: transparent; color: var(--ink-2); border-radius: 10px; cursor: pointer; }
.icon-btn:hover { background: var(--sunken); color: var(--ink); }

.tag-hl {
  display: inline-block; font: 700 10px/1 var(--font-ui); letter-spacing: .06em; padding: 3px 5px; border-radius: 4px;
  color: var(--unit-E); background: var(--unit-E-soft); border: 1px solid color-mix(in srgb, var(--unit-E) 35%, transparent); vertical-align: middle;
}
.meta-chip { display: inline-flex; align-items: center; gap: 6px; font: 500 var(--fs-0)/1 var(--font-ui); color: var(--muted); padding: 6px 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; }

/* progress ring */
.ring { flex: none; }
.ring-bg { fill: none; stroke: var(--line); stroke-width: 2.5; }
.ring-fg { fill: none; stroke: var(--unit, var(--accent)); stroke-width: 2.5; stroke-linecap: round; transition: stroke-dasharray .4s var(--ease); }
.ring-full .ring-fg { stroke: var(--good); }

/* inputs */
input[type="text"], input[type="number"], select, textarea {
  font: 500 var(--fs-1)/1.3 var(--font-ui); color: var(--ink); background: var(--raised);
  border: 1px solid var(--line-strong); border-radius: 8px; padding: 8px 10px; min-height: 40px;
}
input[type="text"]:focus, select:focus, textarea:focus { border-color: var(--accent); outline: 2px solid color-mix(in srgb, var(--accent) 35%, transparent); outline-offset: 0; }
textarea { width: 100%; resize: vertical; font-family: var(--font-ui); }

input[type="range"] { -webkit-appearance: none; appearance: none; width: 100%; height: 28px; background: transparent; cursor: pointer; margin: 0; touch-action: pan-y; }
input[type="range"]::-webkit-slider-runnable-track { height: 4px; background: var(--line-strong); border-radius: 4px; }
input[type="range"]::-moz-range-track { height: 4px; background: var(--line-strong); border-radius: 4px; }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 20px; height: 20px; margin-top: -8px; border-radius: 50%; background: var(--raised); border: 2px solid var(--accent); box-shadow: var(--shadow-1); }
input[type="range"]::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: var(--raised); border: 2px solid var(--accent); }
input[type="range"]:disabled { opacity: .5; cursor: default; }
input[type="range"]:focus-visible { outline: none; }
input[type="range"]:focus-visible::-webkit-slider-thumb { outline: 3px solid var(--focus); outline-offset: 2px; }
input[type="range"]:focus-visible::-moz-range-thumb { outline: 3px solid var(--focus); outline-offset: 2px; }

/* celebrate (reduced motion: none) */
.celebrate { animation: celebrate .7s var(--ease); }
@keyframes celebrate { 0% { transform: scale(.98); box-shadow: 0 0 0 0 color-mix(in srgb, var(--good) 45%, transparent); } 60% { transform: scale(1.01); box-shadow: 0 0 0 10px transparent; } 100% { transform: none; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
}

.author-error { font: 600 13px/1.4 var(--font-mono); color: var(--bad); background: var(--bad-soft); border: 1px dashed var(--bad); padding: 8px 10px; border-radius: 6px; margin: 6px 0; }
