:root {
  color-scheme: light dark;
  --accent: #2456e6;
  --accent-text: #1f4bd1;
  --line: #8884;
}
@media (prefers-color-scheme: dark) { :root { --accent-text: #9bb4ff; } }
* { box-sizing: border-box; }
body {
  margin: 0;
  font: 17px/1.6 system-ui, sans-serif;
}
header, main, footer {
  max-width: 44rem;
  margin: 0 auto;
  padding: 16px 20px;
}
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}
.brand, header nav a { display: inline-block; min-height: 44px; line-height: 44px; }
.brand { font-weight: 700; text-decoration: none; color: inherit; }
a { color: var(--accent-text); }
/* Long URLs and code never push the page sideways on a narrow phone. */
main p, main li, main td, main a, main code { overflow-wrap: anywhere; }
h1 { font-size: clamp(1.7rem, 5vw, 2.4rem); line-height: 1.15; margin: 12px 0; text-wrap: balance; }
h2 { margin-top: 2.2rem; }
h3 { margin-bottom: 0; font-size: 1rem; }
.lede { font-size: 1.1rem; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }
.actions button { min-height: 44px; padding: 8px 16px; border-radius: 8px; border: 0; background: var(--accent); color: #fff; font: inherit; font-weight: 600; cursor: pointer; }
/* The ad slot keeps its height whatever fills it, so the page never shifts. It is only rendered
   when the build has something to put in it (src/pages.mjs). */
.ad-slot { height: 250px; overflow: hidden; contain: strict; margin: 36px 0; padding: 12px; border-radius: 12px; }
.ads-off .ad-slot { display: none; }
.ad-label { display: block; opacity: .65; font-size: .75rem; margin-bottom: 8px; }
.house-card { display: block; padding: 14px 16px; border-radius: 10px; background: #2456e612; color: inherit; text-decoration: none; }
.house-card strong { display: block; color: var(--accent-text); }
.house-card span { display: block; margin-top: 4px; font-size: .95rem; }
.consent { position: fixed; inset: auto 12px 12px 12px; max-width: 44rem; margin: 0 auto; padding: 14px 16px; border-radius: 12px; background: Canvas; color: CanvasText; border: 1px solid var(--line); box-shadow: 0 6px 24px #0004; z-index: 10; }
.consent div { display: flex; gap: 10px; flex-wrap: wrap; }
.consent button { flex: 1; min-height: 44px; padding: 10px 14px; border-radius: 8px; border: 1px solid var(--accent); background: transparent; color: inherit; font: inherit; cursor: pointer; }
footer { margin-top: 40px; opacity: .7; font-size: .9rem; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* Keep the canvas and its overlays within the viewport grid cell. */
.tool > *, #output > *, .rail > * { min-width: 0; }
.rail > * { flex-shrink: 0; }
#status:not(.busy) { min-height: 0; }
#output { display: grid; gap: var(--s4); }
#explode-slot:empty { display: none; }
.drop { position: relative; }
.drop-hint .nowrap { white-space: nowrap; }
.drop > #picker {
  min-inline-size: 44px;
  max-inline-size: 100%;
  min-block-size: var(--s7);
}
.stage { isolation: isolate; overflow: hidden; }
.stage:has(#keys[hidden]) canvas { visibility: hidden; }
#stage-empty { background: inherit; }
.stage.over canvas { opacity: 0.85; }
.stage-busy { width: min(90%, 32rem); min-width: 0; pointer-events: none; z-index: 1; }
.hud { flex-wrap: wrap; }
.hud-dim { margin-inline-start: auto; min-width: min(220px, 100%); max-width: 100%; }
.dim { margin-block: 0; }
.measure-result .dim { margin: 0; }
.dim .value { min-width: 0; overflow-wrap: anywhere; white-space: normal; }
.stage-tag, #cut-readout { overflow-wrap: anywhere; }
.stage-tag { margin: 0; max-width: calc(100% - 2 * var(--s3)); }
#output .file-meta { font-family: var(--mono); }
#busy-actions { justify-content: start; }
fieldset.group > legend { float: left; }
#measure-group > [aria-live] { display: flex; flex-direction: column; gap: var(--s2); }
#parts input { width: 24px; height: 24px; scroll-margin-block: 24px; }
@media (width > 760px) {
  .tool { align-items: stretch; }
}
@media (max-width: 760px) {
  .stage:has(#stage-empty:not([hidden])) { aspect-ratio: auto; height: 220px; }
  #stage-empty svg { width: 72px; height: 72px; }
  .stage canvas { position: absolute; inset: 0; }
  .range-row { gap: var(--s2); }
  .stage-msg { gap: var(--s2); padding: var(--s3); }
}
