:root {
	--bg: #161618;
	--panel: #202023;
	--panel-2: #2a2a2e;
	--line: #34343a;
	--text: #e6e6e9;
	--muted: #9a9aa2;
	--accent: #3b82f6;
	--button: #2563eb; /* filled buttons: white text on --accent was 3.7:1, on this 5.2:1 */
	--part: #e8731a;
	--mark: #1e90ff;
	--paper: #f5f2ea;
	--ink: #1f2430;
	color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
/* Phones and tablets: no font inflation when turned sideways, and no double-tap zoom on buttons
   (two quick taps on Undo would zoom the page). */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; touch-action: manipulation; }

body {
	margin: 0;
	background: var(--bg);
	color: var(--text);
	font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, sans-serif;
}

/* --gutter: the page's side margin, kept clear of an iPhone's notch when turned sideways. */
:root { --gutter-l: max(20px, env(safe-area-inset-left)); --gutter-r: max(20px, env(safe-area-inset-right)); }
header {
	display: flex;
	align-items: center;
	gap: 16px;
	padding: calc(12px + env(safe-area-inset-top)) var(--gutter-r) 12px var(--gutter-l);
	border-bottom: 1px solid var(--line);
}

.brand { font-weight: 600; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.logo { width: 30px; height: 30px; }
.icon { width: 16px; height: 16px; flex-shrink: 0; }
button.primary .icon { width: 17px; height: 17px; }
.muted { color: var(--muted); font-weight: 400; }
.small { font-size: 12px; }
.account { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.account button { white-space: nowrap; }
button.balance { font-size: 13px; color: #c9c9cf; background: none; padding: 4px 10px; border: 1px solid var(--line); border-radius: 999px; white-space: nowrap; }
button.balance.low { color: #f3d38a; border-color: #5c4718; }
.parts-menu, .credit-menu { position: relative; }
.parts-panel, .credit-panel {
	position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; width: min(320px, 85vw); max-height: 60vh; overflow: auto;
	background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 6px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}
#parts-list { list-style: none; margin: 0; padding: 0; }
#parts-list button { width: 100%; display: flex; align-items: center; gap: 10px; border: none; background: none; padding: 6px 10px; text-align: left; }
#parts-list .thumb { width: 48px; height: 48px; flex-shrink: 0; border-radius: 6px; background: var(--panel-2); overflow: hidden; }
#parts-list .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
#parts-list .part-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
#parts-list button:hover { background: var(--panel-2); }
#parts-list .when { color: var(--muted); font-size: 12px; }
#parts-list .empty-note { color: var(--muted); padding: 8px 10px; font-size: 13px; }
.parts-foot { border-top: 1px solid var(--line); margin-top: 6px; padding: 8px 10px 4px; display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); }
.credit-panel { width: min(300px, 85vw); padding: 12px; font-size: 13px; color: var(--muted); }
.credit-panel p { margin: 0 0 10px; }
.credit-panel .credit-thanks { color: #9be3b0; font-weight: 600; }
.credit-packs { display: flex; gap: 8px; margin-bottom: 10px; }
.credit-packs button { flex: 1; flex-direction: column; gap: 2px; padding: 10px 8px; }
.credit-packs b { font-size: 15px; color: var(--text); }
.credit-packs span { font-size: 11px; color: var(--muted); }
.credit-panel .credit-foot { margin: 0; font-size: 12px; }
.credit-panel .credit-foot.failed { color: #ffb4b4; }
.credit-panel .credit-thanks.plain { color: var(--text); font-weight: 400; }
.credit-panel .credit-head { font-size: 12px; }
.credit-panel .credit-under { text-align: center; margin-top: -4px; }
/* The other ways to parts, as options: an icon, a title with one small line, a button. Your
   own AI (app.js, Connect my AI) is web-only, never in the iOS app. */
.credit-ways { margin: 12px 0 8px; border-top: 1px solid var(--line); }
.credit-way { display: flex; align-items: center; gap: 10px; padding: 10px 0 0; }
.credit-way > .icon { flex-shrink: 0; color: var(--text); }
.credit-way .way-text { flex: 1; display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.credit-way b { color: var(--text); font-weight: 600; }
.credit-way small { font-size: 12px; }
.credit-way button { flex-shrink: 0; padding: 5px 10px; font-size: 12px; }
/* On a phone the menus hang from the header's right edge instead of their own button (My
   parts has the parts pill to its right, so a 320 px panel ran off the left edge), and are
   never wider than the screen between the page's margins. */
@media (max-width: 640px) {
	.account { position: relative; }
	.parts-menu, .credit-menu { position: static; }
	.parts-panel { width: min(320px, calc(100vw - var(--gutter-l) - var(--gutter-r))); }
	.credit-panel { width: min(300px, calc(100vw - var(--gutter-l) - var(--gutter-r))); }
}
.signin-card .invite-note { color: #9be3b0; font-weight: 600; }
button.link { background: none; border: none; padding: 0; text-decoration: underline; text-underline-offset: 2px; color: var(--muted); font-size: 12px; align-self: flex-start; }
button.link.danger { color: #f08a8a; }
.signin { display: flex; justify-content: center; align-items: center; padding: 32px max(16px, env(safe-area-inset-right)) calc(32px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); flex: 1; }
.signin-card { max-width: 760px; width: 100%; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.signin-card h1 { font-size: 24px; line-height: 1.3; margin: 4px 0 0; }
.signin-card p { margin: 0; }
.signin-card button.primary { align-self: center; margin-top: 6px; }
/* Google's button is a light-scheme frame; matching it stops the browser painting a white box behind it on our dark page. */
.google-button { min-height: 44px; margin-top: 6px; display: flex; justify-content: center; color-scheme: light; }
.highlights { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 14px; }
.signin-card .highlight {
	display: flex; gap: 10px; align-items: flex-start; margin: 0; padding: 12px 14px; flex: 1 1 260px; max-width: 360px; text-align: left;
	background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
	font-size: 13px; line-height: 1.45; color: var(--muted);
}
.highlight .icon { width: 20px; height: 20px; color: var(--accent); margin-top: 1px; }
.highlight b { display: block; color: var(--text); font-weight: 600; margin-bottom: 2px; }
.google-button:empty { display: none; }
/* Apple's button, drawn by its script at the same size as Google's. */
.apple-button { width: 260px; height: 40px; }
.apple-button:empty { display: none; }
.logo-big { width: 44px; height: 44px; margin-top: 8px; }

/* The signed-out demo: a miniature of the real app (720 x 405, scaled to fit by intro.js)
   playing sketch -> Make it -> v1 -> red mark + note -> Update -> v2. */
.intro { width: 100%; position: relative; overflow: hidden; border-radius: 12px; }
.mini {
	width: 720px; height: 405px; transform-origin: 0 0; position: absolute; left: 0; top: 0; text-align: left;
	background: var(--bg); border: 1px solid var(--line); border-radius: 12px; display: flex; flex-direction: column;
}
.mini-head { display: flex; align-items: center; gap: 8px; padding: 9px 14px; border-bottom: 1px solid var(--line); font-weight: 600; font-size: 14px; }
.mini-head img { width: 22px; height: 22px; }
.mini-body { flex: 1; display: grid; grid-template-columns: 300px 1fr; gap: 10px; padding: 10px; min-height: 0; }
.mini-panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 9px; display: flex; flex-direction: column; gap: 7px; min-height: 0; }
.mini-title { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; }
.mini-step { display: inline-grid; place-items: center; width: 16px; height: 16px; border-radius: 50%; background: var(--panel-2); color: var(--muted); font-size: 10px; }
.mini-muted { color: var(--muted); font-weight: 400; }
.mini-tools { display: flex; gap: 4px; }
.mini-tools i { width: 26px; height: 18px; border-radius: 5px; background: var(--panel-2); border: 1px solid var(--line); }
.mini-tools i.on { background: #1e3a66; border-color: var(--accent); }
.mini-paper {
	flex: 1; min-height: 0; border-radius: 8px; background: var(--paper);
	background-image: linear-gradient(rgba(31, 36, 48, 0.06) 1px, transparent 1px), linear-gradient(90deg, rgba(31, 36, 48, 0.06) 1px, transparent 1px);
	background-size: 16px 16px;
}
#intro-sketch { width: 100%; height: 100%; transition: opacity 0.4s; }
#intro-sketch.fading { opacity: 0; }
.mini-text {
	min-height: 26px; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px;
	font-size: 12px; color: var(--text); flex: 1;
}
.mini-button {
	align-self: flex-end; background: var(--accent); color: white; border-radius: 7px; padding: 6px 12px; font-size: 12px; font-weight: 600;
	transition: transform 0.15s, box-shadow 0.3s;
}
.mini-button.pressed { transform: scale(0.9); box-shadow: 0 0 0 6px rgba(59, 130, 246, 0.3); }
.mini-viewer { position: relative; height: 214px; border-radius: 8px; overflow: hidden; background: radial-gradient(ellipse at 50% 60%, #2a2a2f 0%, #18181b 75%); }
.mini-viewer canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
#intro-marks { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 1; }
.mini-left .mini-text { flex: none; }
.mini-change { display: flex; gap: 8px; align-items: stretch; }
.mini-change .mini-button { align-self: center; }
.mini-chips { margin-left: auto; display: flex; gap: 4px; }
.mini-chips span { font-size: 10px; padding: 1px 7px; border: 1px solid var(--line); border-radius: 6px; color: var(--muted); }
.mini-chips span.current { border-color: var(--part); color: #ffd2b0; }
.reveal { fill: none; stroke: #fff; stroke-linecap: round; stroke-linejoin: round; }
.mark { fill: none; stroke-linecap: round; stroke-linejoin: round; }
@media (max-width: 640px) {
	.signin-card { gap: 10px; }
	.signin-card h1 { font-size: 20px; margin-top: 14px; }
	.signin-card .logo-big { display: none; }}
.banner {
	background: #3a2d12; color: #f3d38a; border: 1px solid #5c4718;
	padding: 4px 10px; border-radius: 6px; font-size: 13px;
}
/* Local mode (platform.js): green while the person's own AI answers, amber when it doesn't. */
.banner.local { background: #12301f; color: #9fe0b8; border-color: #1f5236; min-width: 0; }
.banner.local.off { background: #3a2d12; color: #f3d38a; border-color: #5c4718; }
.banner.local button.link { color: inherit; font-size: inherit; margin-left: 6px; }
/* A kept pairing whose AI started while this page is the plain website (app.js watchPairedAi). */
.banner.ai-ready { cursor: pointer; font: inherit; font-size: 13px; white-space: nowrap; }
.ai-dialog { max-width: 460px; }
.ai-dialog ol { padding-left: 20px; }
.ai-dialog li { margin: 6px 0; }
.ai-status { padding: 8px 10px; border-radius: 6px; background: var(--panel-2); }

main {
	display: grid;
	grid-template-columns: minmax(360px, 5fr) minmax(420px, 7fr);
	gap: 16px;
	padding: 16px var(--gutter-r) calc(24px + env(safe-area-inset-bottom)) var(--gutter-l);
	max-width: 1700px;
	margin: 0 auto;
}

.panel {
	background: var(--panel);
	border: 1px solid var(--line);
	border-radius: 12px;
	padding: 14px;
	display: flex;
	flex-direction: column;
	gap: 10px;
	min-width: 0;
}

h2 { margin: 2px 0 2px; font-size: 15px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.step {
	display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%;
	background: var(--panel-2); color: var(--muted); font-size: 12px;
}

button, .button {
	appearance: none; border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
	padding: 6px 12px; border-radius: 7px; font: inherit; cursor: pointer; text-decoration: none;
	display: inline-flex; align-items: center; gap: 6px;
}
button:hover, .button:hover { border-color: #4a4a52; }
button.active { background: #1e3a66; border-color: var(--accent); }
button.primary {
	background: var(--button); border-color: var(--button); color: white; font-weight: 600;
	padding: 9px 18px; align-self: flex-end;
}
button.primary:disabled { opacity: 0.5; cursor: default; }

.tools { display: flex; gap: 6px; flex-wrap: wrap; }

/* The pad is a desk; the sheet on it (zoomed and moved by sketch.applyView) is the paper. */
.paper {
	position: relative;
	aspect-ratio: 4 / 3;
	border-radius: 10px;
	overflow: hidden;
	background: #2c2c31;
	-webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.sheet {
	position: absolute; inset: 0;
	background: var(--paper);
	background-image:
		linear-gradient(rgba(31, 36, 48, 0.06) 1px, transparent 1px),
		linear-gradient(90deg, rgba(31, 36, 48, 0.06) 1px, transparent 1px);
	background-size: 24px 24px;
}
#sketch { position: relative; width: 100%; height: 100%; display: block; touch-action: none; cursor: crosshair; }
.paper-fit { position: absolute; right: 8px; bottom: 8px; z-index: 2; background: rgba(22, 22, 24, 0.85); }
.paper-toast {
	position: absolute; left: 50%; top: 10px; transform: translateX(-50%); z-index: 3; width: max-content; max-width: calc(100% - 24px);
	background: rgba(22, 22, 24, 0.88); color: #e6e6e9; font-size: 13px; text-align: center;
	padding: 6px 12px; border-radius: 999px; pointer-events: none;
}
.paper-hint {
	position: absolute; inset: 0; display: grid; place-items: center; text-align: center;
	color: rgba(31, 36, 48, 0.66); font-size: 15px; line-height: 1.6; pointer-events: none;
	transition: opacity 0.3s;
}
.paper-hint.gone { opacity: 0; }
/* Once a part exists, its drawing is locked: a version always comes from the drawing it was
   made with, so changes go through step 3, and a new drawing means a New part. */
.draw-lock { display: inline-flex; color: var(--muted); cursor: help; }
.draw-lock .icon { width: 15px; height: 15px; }
#sketch-panel.locked .paper { filter: grayscale(0.5) brightness(0.88); }
#sketch-panel.locked #sketch { cursor: not-allowed; }
#sketch-panel.locked .tools button:disabled { opacity: 0.45; cursor: default; border-color: var(--line); }
#sketch-panel.locked #request-text { opacity: 0.7; }
.lock-hint { margin: -2px 0 0; font-size: 12px; color: var(--muted); }
/* A photo is being dragged over the Draw it panel. */
/* The number box that pops up in the middle of a new dimension line. */
.dim-input {
	position: absolute; transform: translate(-50%, -50%); width: 76px; z-index: 2; text-align: center;
	font: 600 15px -apple-system, "Segoe UI", sans-serif; color: #2563eb; background: #fff;
	border: 2px solid #2563eb; border-radius: 7px; padding: 4px 6px; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}
.dim-input:focus { outline: none; }

textarea {
	width: 100%; resize: vertical; background: var(--bg); color: var(--text);
	border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; font: inherit;
}
textarea:focus { outline: none; border-color: var(--accent); }

.viewer {
	position: relative;
	aspect-ratio: 4 / 3;
	border-radius: 10px;
	overflow: hidden;
	background: radial-gradient(ellipse at 50% 60%, #2a2a2f 0%, #18181b 75%);
}
.viewer > canvas.three { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#markup { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 2; pointer-events: none; touch-action: none; }
.viewer.marking #markup { pointer-events: auto; cursor: crosshair; }
.viewer-tools { position: absolute; top: 10px; left: 10px; z-index: 3; display: flex; gap: 6px; }
.viewer-tools button { background: rgba(22, 22, 24, 0.85); }
/* Turn / Draw switch and the hint line; hidden until there is a part to look at. */
.viewer-tools.right { left: auto; right: 10px; }
/* Wraps before the right tools: their measured width (app.js), the two 10 px edges and a gap. */
.viewer-tools:not(.right) {
	flex-wrap: wrap;
	max-width: calc(100% - var(--right-tools, 90px) - 30px - env(safe-area-inset-left) - env(safe-area-inset-right));
}
.segmented { display: flex; }
.segmented button { border-radius: 0; }
.segmented button:first-child { border-radius: 7px 0 0 7px; }
.segmented button:last-child { border-radius: 0 7px 7px 0; border-left: none; }
.segmented button.active { background: #2f3440; border-color: #5b6475; }
#mode-draw.active { background: #123a66; border-color: var(--mark); }
.swatches { display: flex; gap: 4px; padding: 3px; background: rgba(22, 22, 24, 0.85); border: 1px solid var(--line); border-radius: 8px; }
.swatches button { padding: 4px; border: 2px solid transparent; background: none; border-radius: 6px; }
.swatches button span { display: block; width: 16px; height: 16px; border-radius: 50%; box-shadow: 0 0 0 2px #fff; }
.swatches button.active { border-color: #e6e6e9; }
.viewer-hint {
	position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%); z-index: 3;
	background: rgba(22, 22, 24, 0.75); color: var(--muted); font-size: 12px;
	padding: 3px 10px; border-radius: 999px; pointer-events: none; white-space: nowrap;
}
.viewer.marking .swatches { display: flex; gap: 4px; padding: 3px; background: rgba(22, 22, 24, 0.85); border: 1px solid var(--line); border-radius: 8px; }
.swatches button { padding: 4px; border: 2px solid transparent; background: none; border-radius: 6px; }
.swatches button span { display: block; width: 16px; height: 16px; border-radius: 50%; box-shadow: 0 0 0 2px #fff; }
.swatches button.active { border-color: #e6e6e9; }
.viewer-hint { color: #cfe6ff; }
.viewer:not(.has-part) .viewer-tools, .viewer:not(.has-part) .swatches { display: flex; gap: 4px; padding: 3px; background: rgba(22, 22, 24, 0.85); border: 1px solid var(--line); border-radius: 8px; }
.swatches button { padding: 4px; border: 2px solid transparent; background: none; border-radius: 6px; }
.swatches button span { display: block; width: 16px; height: 16px; border-radius: 50%; box-shadow: 0 0 0 2px #fff; }
.swatches button.active { border-color: #e6e6e9; }
.viewer-hint { display: none; }
.empty {
	position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); z-index: 1;
	text-align: center; line-height: 1.7; padding: 20px;
}
.busy {
	position: absolute; inset: 0; z-index: 4; background: rgba(14, 14, 16, 0.78);
	display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 24px;
}
#busy-title { font-weight: 600; }
/* The AI's test build behind the progress: faded and soft, so it reads as a draft. Screen
   blending drops the picture's dark background into the overlay. */
.busy-draft {
	position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; z-index: -1;
	opacity: 0.5; filter: blur(1.5px); mix-blend-mode: screen; pointer-events: none;
}
.busy-draft-label { position: absolute; bottom: 12px; left: 0; right: 0; text-align: center; font-size: 12px; color: var(--muted); }
#busy-step { max-width: 80%; text-align: center; color: #d6d6dc; min-height: 1.45em; }
/* Local mode, no AI listening: copies what to say in the AI chat (app.js busy.wake). */
.busy-wake { font-size: 13px; }
.viewer:has(.busy:not([hidden])) .empty { visibility: hidden; }
.spinner {
	width: 28px; height: 28px; border-radius: 50%; border: 3px solid #3a3a40; border-top-color: var(--part);
	animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.result { display: flex; flex-direction: column; gap: 4px; }
.result-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 12px; align-items: center; }
.result-name { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; min-width: 0; flex: 1 1 180px; }
.title { font-size: 15px; font-weight: 600; }
.downloads { display: flex; flex-wrap: wrap; gap: 8px 10px; align-items: center; }
.download-main { border-color: var(--part); color: #ffd2b0; }
.download-main:hover { border-color: #ff9a4d; }
/* A button with a little arrow beside it for the other choices (the slicers). */
.split { position: relative; display: flex; }
.split > button:has(+ .split-toggle:not([hidden])) { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.split-toggle { border-top-left-radius: 0; border-bottom-left-radius: 0; margin-left: -1px; padding: 6px 7px; }
.split-toggle[aria-expanded="true"] .icon { transform: rotate(180deg); }
.split > button:hover { position: relative; } /* the hovered border shows on both sides of the seam */
.slicers-panel {
	position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; min-width: 100%; white-space: nowrap;
	background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 6px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}
.slicers-panel .menu-item { border-radius: 6px; }
a.link { color: var(--muted); text-decoration: underline; text-underline-offset: 2px; }
#result-asked { color: var(--text); }
.result p { margin: 0; color: #c9c9cf; }
/* The main sizes: edit a number, then Rebuild (no AI, free). */
.sizes { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px 12px; margin: 2px 0; }
.sizes-grid { display: flex; flex-wrap: wrap; gap: 8px 12px; }
.size { display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: var(--muted); }
.size-input { display: flex; align-items: center; gap: 4px; color: var(--muted); }
.size input {
	width: 70px; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 6px;
	padding: 4px 6px; font: inherit; font-size: 13px;
}
.size input:focus { outline: none; border-color: var(--accent); }
.size input.changed { border-color: var(--part); }
#sizes-apply { padding: 4px 10px; font-size: 13px; border-color: var(--part); color: #ffd2b0; }
details summary { cursor: pointer; color: var(--muted); }
#assumptions { margin: 4px 0 0; padding-left: 20px; color: #c9c9cf; }

.revise { display: flex; flex-direction: column; gap: 8px; border-top: 1px solid var(--line); padding-top: 10px; }
.revise-row { display: flex; align-items: stretch; gap: 10px; }
.revise-row textarea { flex: 1; resize: none; }
.revise-row button.primary { align-self: stretch; }
.versions { display: flex; gap: 6px; flex-wrap: wrap; margin-left: auto; }
.versions button { padding: 2px 9px; font-size: 12px; }
.versions button.current { border-color: var(--part); color: #ffd2b0; }

.error { background: #3a1616; border: 1px solid #6b2424; color: #ffb4b4; padding: 8px 10px; border-radius: 8px; }

/* On a laptop or desktop the whole loop (draw, check, change) fits on one screen:
   the panels take the window height and the sketch pad and 3D view absorb the slack. */
@media (min-width: 901px) {
	body { height: 100vh; height: 100dvh; display: flex; flex-direction: column; }
	main { flex: 1; min-height: 0; width: 100%; }
	.panel { min-height: 0; overflow: auto; }
	.paper, .viewer { aspect-ratio: auto; flex: 1 1 0; min-height: 240px; }
	/* Placed, so the other panel stays put while one of them is full screen. */
	#sketch-panel { grid-area: 1 / 1; }
	#model-panel { grid-area: 1 / 2; }
}

/* One column: the drawing, then the 3D view and the change box. A pad or view no taller than
   the screen (a phone on its side), so the whole of it can be seen while drawing. */
@media (max-width: 900px) {
	:root { --gutter-l: max(12px, env(safe-area-inset-left)); --gutter-r: max(12px, env(safe-area-inset-right)); }
	main { grid-template-columns: 1fr; padding: 10px var(--gutter-r) calc(16px + env(safe-area-inset-bottom)) var(--gutter-l); gap: 12px; }
	.panel { padding: 12px; }
	.paper, .viewer { width: min(100%, calc((100dvh - 96px) * 4 / 3)); align-self: center; }
}

/* Phones: drawing tools as a row of icons with small names under them, and the pad is
   squarer to give the finger more room. */
@media (min-width: 521px) { .phone-only { display: none !important; } }
@media (max-width: 520px) {
	.wide-only { display: none !important; }
	.account .label, .viewer-tools .label { display: none; }
	.paper { aspect-ratio: 1 / 1; width: min(100%, calc(100dvh - 96px)); }
	header { padding: calc(10px + env(safe-area-inset-top)) var(--gutter-r) 10px var(--gutter-l); gap: 10px; }
	.banner { font-size: 12px; }
	/* The local mode banner takes its own row under the logo and the buttons. */
	header:has(.banner.local:not([hidden])) { flex-wrap: wrap; row-gap: 8px; }
	.banner.local { order: 3; flex-basis: 100%; }
}
@media (max-width: 520px), (orientation: landscape) and (max-height: 500px) {
	.tools { flex-wrap: nowrap; gap: 4px; }
	.tools button {
		flex: 1 1 0; min-width: 0; flex-direction: column; justify-content: center; gap: 3px;
		padding: 6px 0 5px; font-size: 11px; line-height: 1.1; white-space: nowrap;
	}
	.tools .icon { width: 20px; height: 20px; }
	.tools .full-toggle { margin-left: 0; }
}

/* ---------- Full screen (app.js setFull) ---------- */
html.full-open, html.full-open body { overflow: hidden; overscroll-behavior: none; }
.full-toggle { margin-left: auto; }
button.full-toggle.done { background: var(--button); border-color: var(--button); color: white; font-weight: 600; }
#sketch-panel.full {
	position: fixed; inset: 0; z-index: 50; border: none; border-radius: 0; background: var(--bg);
	overflow: hidden; touch-action: none; gap: 8px;
	padding: calc(8px + env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
}
#sketch-panel.full > :not(.tools, .paper) { display: none; }
#sketch-panel.full .paper { flex: 1 1 0; min-height: 0; width: auto; aspect-ratio: auto; align-self: stretch; border-radius: 8px; }
/* A phone on its side: the tools go down the left edge, leaving the height for the paper. */
@media (orientation: landscape) and (max-height: 500px) {
	#sketch-panel.full { flex-direction: row; }
	#sketch-panel.full .tools { flex-direction: column; width: 64px; }
	#sketch-panel.full .tools button { flex: 1 1 0; min-height: 0; }
}
.viewer.full { position: fixed; inset: 0; z-index: 50; border-radius: 0; aspect-ratio: auto; width: auto; align-self: stretch; }
.viewer.full .viewer-tools { top: calc(10px + env(safe-area-inset-top)); left: max(10px, env(safe-area-inset-left)); }
.viewer.full .viewer-tools.right { left: auto; right: max(10px, env(safe-area-inset-right)); }
.viewer.full .viewer-tools:not(.right) { max-width: calc(100% - 220px); } /* room for Fit and Done */
.viewer-tools .full-toggle { margin-left: 0; }
/* An icon, except under the phone's drawing tools, where every tool has its name. */
.full-toggle:not(.done) .label { display: none; }
.full-toggle.done .label { display: inline; }
@media (max-width: 520px), (orientation: landscape) and (max-height: 500px) {
	.tools .full-toggle .label { display: inline; }
}

/* ---------- Fingers: everything to tap at least 44 px, and text boxes at 16 px (smaller
   makes iPhone Safari zoom the page in when one is tapped) ---------- */
@media (pointer: coarse) {
	button, .button { min-height: 44px; }
	button.link { min-height: 0; }
	header button.link { min-height: 44px; }
	textarea, input { font-size: 16px; }
	.dim-input { font-size: 17px; width: 90px; padding: 7px 6px; }
	.size input { width: 84px; padding: 8px; }
	.versions button { min-width: 44px; justify-content: center; }
	.swatches button { width: 40px; height: 40px; min-height: 0; justify-content: center; }
	.split-toggle { min-width: 44px; justify-content: center; }
	.examples { grid-template-columns: 44px minmax(0, 1fr) 44px; }
	.carousel-arrow { width: 44px; height: 44px; }
	.carousel-dots button { width: 30px; height: 44px; min-height: 0; }
	.menu-item { min-height: 48px; }
}
.nowrap { white-space: nowrap; }

/* /terms and /privacy */
a.brand { color: inherit; text-decoration: none; }
.legal { display: block; max-width: 720px; margin: 0 auto; padding: 24px 16px 64px; font-size: 15px; line-height: 1.6; }
.legal h1 { font-size: 26px; line-height: 1.3; }
.legal h2 { font-size: 18px; margin-top: 28px; }
.legal a { color: var(--accent); }
.legal table { width: 100%; border-collapse: collapse; font-size: 14px; }
.legal th, .legal td { border: 1px solid var(--line); padding: 8px; text-align: left; vertical-align: top; }
.legal th { background: var(--panel); }
/* Code to copy (the /ai setup steps): wrapped, with a Copy button in the corner (legal.js). */
.legal pre { position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px 74px 12px 12px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 13px; line-height: 1.5; }
.legal pre .copy { position: absolute; top: 8px; right: 8px; padding: 4px 10px; font-size: 12px; }
.legal code { font-size: 13px; }
@media (max-width: 600px) { .legal table { display: block; overflow-x: auto; } }

/* Example parts: a real drawing, the part made from it (turnable), the text typed with it and
   what it shows. On the signed-out page and, signed in, in a window (examples.js). */
.examples-section { width: 100%; margin-top: 28px; display: flex; flex-direction: column; gap: 6px; }
.examples-section h2 { justify-content: center; font-size: 18px; }
/* The carousel: arrows at the sides and dots below; on a phone, arrows and dots above the page. */
.examples { display: grid; grid-template-columns: 36px minmax(0, 1fr) 36px; grid-template-areas: "prev pages next" ". dots ."; gap: 10px 8px; align-items: center; width: 100%; margin-top: 8px; text-align: left; }
.carousel-pages { grid-area: pages; min-width: 0; }
.carousel-page:not([hidden]) { animation: page-in 0.25s ease-out; }
@keyframes page-in { from { opacity: 0; transform: translateX(var(--from, 0)); } }
@media (prefers-reduced-motion: reduce) { .carousel-page:not([hidden]) { animation: none; } }
/* Reduce Motion: fades and the intro's button press happen at once. The spinner keeps turning:
   it says the part is being made. */
@media (prefers-reduced-motion: reduce) {
	#intro-sketch, .mini-button, .paper-hint { transition: none; }
}
.carousel-arrow { grid-area: prev; width: 36px; height: 36px; padding: 0; border-radius: 50%; display: grid; place-items: center; background: var(--panel-2); border: 1px solid var(--line); color: var(--text); }
.carousel-arrow.next { grid-area: next; }
.carousel-arrow:hover { background: var(--line); }
.carousel-arrow svg { width: 18px; height: 18px; }
.carousel-dots { grid-area: dots; display: flex; justify-content: center; gap: 4px; }
.carousel-dots button { width: 22px; height: 22px; padding: 0; border: none; background: none; display: grid; place-items: center; }
.carousel-dots button::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.carousel-dots button[aria-current]::before { background: var(--accent); }
.examples-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr)); gap: 12px; }
.example { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px; display: flex; flex-direction: column; gap: 6px; }
.example-pair { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; position: relative; }
.example-pair img, .example-model { width: 100%; aspect-ratio: 1; border-radius: 8px; display: block; }
.example-pair img { height: auto; background: var(--paper); object-fit: contain; }
.example-model { position: relative; background: radial-gradient(ellipse at 50% 60%, #2a2a2f 0%, #18181b 75%); }
.example-model canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; touch-action: pan-y; }
.example-model canvas:active { cursor: grabbing; }
/* A small arrow from the drawing to the part. */
.example-pair::after {
	content: "→"; position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 1; pointer-events: none;
	width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
	background: var(--accent); color: white; font-size: 15px; line-height: 1; box-shadow: 0 0 0 3px var(--panel);
}
.example h3 { margin: 4px 0 0; font-size: 14px; font-weight: 600; }
.example p { margin: 0; }
.example-text { font-size: 12px; color: #c9c9cf; font-style: italic; }
.example-point { font-size: 12px; color: var(--muted); }
.example-story { font-size: 13px; color: #d6d6dc; line-height: 1.45; }
/* A story: drawing, part and photos of it at home, wrapping into rows where every tile has the
   same height (each grows in proportion to its width at --h tall). */
.story { min-width: 0; --h: 180px; }
.story-tiles { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.story .example-pair { flex: 2 1 calc(2 * var(--h) + 8px); min-width: 0; }
.story-photo { flex: var(--r) 1 calc(var(--r) * var(--h)); min-width: 0; height: auto; aspect-ratio: var(--r); object-fit: cover; border-radius: 8px; display: block; background: var(--panel-2); }
.story-words { flex: 1 1 240px; display: flex; flex-direction: column; gap: 6px; padding: 2px 4px; }

.menu-item { width: 100%; border: none; background: none; padding: 8px 10px; text-align: left; color: var(--text); }
.menu-item:hover { background: var(--panel-2); }
.parts-panel .menu-item { border-bottom: 1px solid var(--line); border-radius: 6px 6px 0 0; margin-bottom: 4px; }
.empty button.link { font-size: inherit; color: #60a5fa; } /* --accent was 4.4:1 on the 3D view */

.examples-dialog {
	width: min(820px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); padding: 0;
	background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 12px;
}
.examples-dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
.examples-inner { padding: 14px; display: flex; flex-direction: column; gap: 4px; }
.examples-head { display: flex; align-items: center; justify-content: space-between; }
.examples-head h2 { font-size: 17px; }
@media (max-width: 640px) {
	.examples { grid-template-areas: "prev dots next" "pages pages pages"; }
	.examples-grid { grid-template-columns: 1fr; }
	.story { --h: 140px; }
	.examples-inner { padding: 12px; }
}

/* ---------- The iPhone and iPad app (mobile/; platform.js sets html.app) ---------- */
/* Apple allows no buying outside the App Store in an app, and Google's and Apple's web sign-in
   buttons don't work in its web view. */
html.app .web-only { display: none !important; }
/* The app's own wording where the website's names its prices (Apple allows no pointing to them). */
html:not(.app) .app-only { display: none !important; }
/* An app doesn't stretch past its ends, flash grey on taps, or offer "Open link" menus on a
   long press. */
html.app, html.app body { overscroll-behavior: none; }
html.app { -webkit-tap-highlight-color: transparent; }
html.app a, html.app img { -webkit-touch-callout: none; }
/* A long press on a button selects nothing (no Copy / Look Up menu over the parts count). */
html.app button, html.app .button { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
/* The clock and battery sit over the page; a strip in the page's colour keeps them readable
   while it scrolls (full screen covers it and keeps its own margin). */
html.app body::before {
	content: ""; position: fixed; z-index: 40; top: 0; left: 0; right: 0;
	height: env(safe-area-inset-top); background: var(--bg); pointer-events: none;
}
/* The Examples window stays clear of the clock and the Dynamic Island. */
html.app .examples-dialog {
	margin-top: calc(12px + env(safe-area-inset-top));
	max-height: calc(100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
}
/* The app's own Sign in with Apple and Google buttons (account.js showNativeButtons), the
   size and shape of the website's: white with each one's logo, as Apple and Google ask for on a
   dark page. */
.native-sign-in {
	width: 260px; height: 40px; min-height: 40px; border: none; border-radius: 999px; justify-content: center; gap: 8px;
	background: #fff; color: #000; font: 500 15px/1 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
.native-sign-in svg { width: 17px; height: 17px; }
.native-sign-in.apple svg { margin-top: -3px; }
.native-sign-in.google { color: #1f1f1f; }
#apple-native { margin-top: 6px; }

/* ---------- Loading placeholders ---------- */
/* Grey shapes where something is coming, pulsing slowly. They show only after 0.3 s, so a quick
   load shows nothing at all, and under Reduce Motion they stay still. The pulse moves the
   background colour only, so a thumbnail inside one doesn't flicker. */
.skel { background-color: var(--panel-2); border-radius: 8px; animation: skel-in 0s 0.3s both, skel-pulse 1.6s ease-in-out 0.3s infinite; }
@keyframes skel-in { from { visibility: hidden; } }
@keyframes skel-pulse { 50% { background-color: #232327; } }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* The first screen while the page starts and checks the sign-in: the app's two panels as shapes
   (before any script runs, so also while the libraries load). Gone once the app or the sign-in
   screen shows. */
.boot { display: none; }
body:has(#app[hidden]):has(#signin[hidden]) .boot { display: grid; }
.boot .panel { gap: 12px; }
.skel-title { height: 18px; width: 40%; }
.skel-tools { height: 36px; }
.skel-area { aspect-ratio: 4 / 3; border-radius: 10px; }
.skel-box { height: 88px; }
@media (min-width: 901px) { .skel-area { aspect-ratio: auto; flex: 1 1 0; min-height: 240px; } }

/* My parts while the list and its thumbnails load. */
#parts-list .part-skel { display: flex; align-items: center; gap: 10px; padding: 6px 10px; }
#parts-list .part-skel .part-text { flex: 1; gap: 6px; }
.skel-line { display: block; height: 12px; width: 70%; }
.skel-line.short { width: 40%; }
#parts-list .thumb:not(:has(img.loaded, img[hidden])) { animation: skel-pulse 1.6s ease-in-out 0.3s infinite; }

/* The parts panel's pack and the parts count while they load. */
.skel-pack { flex: 1; min-height: 54px; }
button.balance.skel { min-width: 92px; border-color: transparent; color: transparent; }

/* Opening a saved part, or another version: the pad and the 3D view wait quietly instead of
   saying "draw here" and "your part appears here". */
.opening .paper-hint, .opening .viewer .empty { visibility: hidden; }
.opening .paper::after, .opening .viewer::after, .viewer.loading::after {
	content: ""; position: absolute; inset: 0; z-index: 5; pointer-events: none; background: #fff; opacity: 0;
	animation: skel-in 0s 0.3s both, overlay-pulse 1.6s ease-in-out 0.3s infinite;
}
.opening .paper::after { background: #000; }
@keyframes overlay-pulse { 50% { opacity: 0.06; } }

/* A button that started something over the network (platform.js whileBusy): it can't be pressed
   twice, and dims and pulses after 0.3 s. */
[aria-busy="true"] { pointer-events: none; animation: busy-pulse 1.6s ease-in-out 0.3s infinite; }
@keyframes busy-pulse { 50% { opacity: 0.55; } }

@media (prefers-reduced-motion: reduce) {
	.skel { animation: skel-in 0s 0.3s both; }
	#parts-list .thumb:not(:has(img.loaded, img[hidden])) { animation: none; }
	.opening .paper::after, .opening .viewer::after, .viewer.loading::after { animation: skel-in 0s 0.3s both; opacity: 0.04; }
	[aria-busy="true"] { animation: busy-dim 0s 0.3s both; }
	@keyframes busy-dim { to { opacity: 0.6; } }
}
