/* Layout: one-screen workbench. Library rail | 3D stage with overlaid stepper | plan & materials panel.
   Deliberately dark-only ("night build" look): deepslate neutrals, torchlight amber accent,
   blueprint cyan for planning aids (plan grid, ghost layers). */
:root {
  --ink-0: #0a0d12;
  --ink-1: #10141b;
  --ink-2: #161b24;
  --ink-3: #1d2430;
  --line: #242c39;
  --line-2: #313b4b;
  --text: #e8ecf2;
  --muted: #8a95a7;
  --faint: #5c6677;
  --torch: #ffb547;
  --torch-2: #ffd27a;
  --torch-ink: #2a1803;
  --prism: #6fd3ff;
  --easy: #6fd08c;
  --mid: #f0c050;
  --hard: #ff7a6b;
  --epic: #c59bff;
  --scene: radial-gradient(120% 90% at 50% 18%, #233046 0%, #151c28 48%, #0b0f15 100%);
  --glass: rgba(12, 16, 22, 0.74);

  --display: 'Pixelify Sans', 'Silkscreen', ui-monospace, monospace;
  --body: 'Figtree', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;

  --r-lg: 16px;
  --r-md: 11px;
  --r-sm: 8px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
/* No page pinch-zoom or double-tap zoom; the 3D viewer handles its own pinch. */
html { touch-action: pan-x pan-y; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--ink-0);
  color: var(--text);
  font: 15px/1.5 var(--body);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; background: none; border: 0; }
button:disabled { cursor: default; opacity: 0.35; }
:focus-visible { outline: 2px solid var(--torch); outline-offset: 2px; }
h1, h2, h3 { margin: 0; line-height: 1.1; text-wrap: balance; }
[hidden] { display: none !important; }

/* ---------- shell ---------- */
.app {
  height: 100vh; height: 100dvh;
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) 384px;
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas: 'bar bar bar' 'lib stage panel';
  gap: 12px;
  padding-block: 12px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}

.bar { grid-area: bar; display: flex; align-items: center; gap: 14px; min-height: 40px; }
.brand { display: flex; align-items: center; gap: 10px; font: 700 22px/1 var(--display); letter-spacing: 0.02em; }
.logo {
  width: 24px; height: 24px; flex: none;
  background:
    linear-gradient(var(--torch-2), var(--torch-2)) 6px 6px / 12px 12px no-repeat,
    var(--torch);
  box-shadow: 0 0 18px rgba(255, 181, 71, 0.45);
}
.tagline { color: var(--muted); font-size: 13px; }
.bar-spacer { flex: 1; }
.lib-toggle {
  display: none; align-items: center; gap: 8px;
  padding: 8px 12px; border-radius: var(--r-sm); border: 1px solid var(--line-2); background: var(--ink-2);
  font-weight: 600; font-size: 14px;
}

/* ---------- library ---------- */
.library {
  grid-area: lib; min-height: 0;
  display: flex; flex-direction: column;
  background: var(--ink-1); border: 1px solid var(--line); border-radius: var(--r-lg);
  overflow: hidden;
}
.lib-head { padding: 14px 14px 10px; display: flex; flex-direction: column; gap: 10px; border-bottom: 1px solid var(--line); }
.lib-title { display: flex; align-items: baseline; justify-content: space-between; }
.lib-title h2 { font: 600 12px/1 var(--body); text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted); }
.lib-title span { font: 500 12px/1 var(--mono); color: var(--faint); }
.search {
  width: 100%; background: var(--ink-0); border: 1px solid var(--line); border-radius: var(--r-sm);
  color: var(--text); font: inherit; font-size: 14px; padding: 8px 11px;
}
.search::placeholder { color: var(--faint); }
select.search { appearance: none; cursor: pointer; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
.chips { display: flex; gap: 4px; padding: 3px; background: var(--ink-0); border: 1px solid var(--line); border-radius: var(--r-sm); }
.chip { flex: 1; padding: 5px 0; border-radius: 6px; font-size: 12px; font-weight: 600; color: var(--muted); }
.chip:hover { color: var(--text); }
.chip.active { background: var(--ink-3); color: var(--text); box-shadow: inset 0 0 0 1px var(--line-2); }

.lib-list { flex: 1; min-height: 0; overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 4px; }
.lib-item {
  display: grid; grid-template-columns: 76px minmax(0, 1fr); gap: 12px; align-items: center; position: relative;
  padding: 7px; border-radius: var(--r-md); border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s;
}
.lib-item:hover { background: var(--ink-2); }
.lib-item.active { background: var(--ink-2); border-color: var(--line-2); box-shadow: inset 3px 0 0 var(--torch); }
.lib-thumb {
  width: 76px; height: 58px; border-radius: var(--r-sm); overflow: hidden; position: relative;
  background: var(--scene); max-width: 100%;
}
.lib-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.lib-info { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.lib-name { padding-right: 24px; font-weight: 650; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lib-meta { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.lib-meta .mono { font-family: var(--mono); font-size: 11.5px; color: var(--faint); }
.lib-progress { height: 3px; border-radius: 3px; background: var(--line); overflow: hidden; }
.lib-progress i { display: block; height: 100%; background: var(--torch); }
.lib-fav {
  position: absolute; top: 5px; right: 5px;
  width: 26px; height: 26px; display: grid; place-items: center; border-radius: 7px;
  font-size: 17px; line-height: 1; color: var(--faint); opacity: 0; transition: opacity 0.15s, color 0.15s, background 0.15s;
}
.lib-item:hover .lib-fav, .lib-fav:focus-visible, .lib-fav.on { opacity: 1; }
.lib-fav:hover { background: var(--ink-3); color: var(--torch); }
.lib-fav.on { color: var(--torch); }
@media (hover: none) { .lib-fav { opacity: 0.6; } .lib-fav.on { opacity: 1; } }
.lib-done { color: var(--easy); font-weight: 700; font-size: 12px; }
.lib-empty { color: var(--muted); padding: 12px; font-size: 14px; }

.diff { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; }
.diff::before { content: ''; width: 7px; height: 7px; border-radius: 2px; background: currentColor; }
.diff-beginner { color: var(--easy); }
.diff-intermediate { color: var(--mid); }
.diff-advanced { color: var(--hard); }
.diff-expert { color: var(--epic); }

.loading { position: absolute; inset: 0; background: linear-gradient(100deg, transparent 30%, rgba(255,255,255,0.08), transparent 70%) 0 0 / 200% 100%; animation: shimmer 1.3s infinite linear; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- stage ---------- */
.stage {
  grid-area: stage; position: relative; min-height: 0; min-width: 0;
  border-radius: var(--r-lg); overflow: hidden;
  background: var(--scene); border: 1px solid var(--line);
}
.viewer { position: absolute; inset: 0; touch-action: none; }
.viewer canvas { display: block; width: 100%; height: 100%; cursor: grab; }
.viewer canvas:active { cursor: grabbing; }

.stage-head {
  position: absolute; top: 18px; left: 20px; right: 380px; pointer-events: none;
  display: flex; flex-direction: column; gap: 6px;
}
.title-row h1 { display: inline; }
.fav-btn {
  pointer-events: auto; display: inline-block; vertical-align: 0.35em; margin-left: 12px; padding: 6px 11px; border-radius: 999px; font-size: 13px; font-weight: 700;
  background: var(--glass); border: 1px solid var(--line-2); color: var(--text); backdrop-filter: blur(8px);
}
.fav-btn:hover { border-color: var(--torch); }
.fav-btn.on { color: var(--torch-ink); background: var(--torch); border-color: var(--torch); }
.stage-head h1 { font: 700 clamp(24px, 2.6vw, 36px)/1.05 var(--display); letter-spacing: 0.01em; text-shadow: 0 2px 18px rgba(0, 0, 0, 0.6); }
.stage-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; font-size: 13px; color: var(--muted); }
.stage-meta .mono { font-family: var(--mono); font-size: 12px; color: var(--text); opacity: 0.8; }

.tools {
  position: absolute; top: 16px; right: 16px; z-index: 6; display: flex; gap: 2px; padding: 3px;
  background: var(--glass); border: 1px solid rgba(255, 255, 255, 0.08); border-radius: var(--r-md);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.tool { padding: 7px 11px; border-radius: var(--r-sm); font-size: 13px; font-weight: 600; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.tool:hover { color: var(--text); background: rgba(255, 255, 255, 0.05); }
.tool.active { color: var(--torch-ink); background: var(--torch); }
.tool svg { width: 15px; height: 15px; }
/* Icon-only buttons keep the toolbar compact; Tour keeps its label as the main call to action. */
.tools .tool span { display: none; }
.tools #tour span { display: inline; }
.tool { min-width: 34px; justify-content: center; }
/* Display settings sit inline on wide screens and fold into a View menu on phones. */
.tool-group { display: contents; }
.view-toggle { display: none; }

.stepper {
  position: absolute; left: 16px; right: 16px; bottom: 16px;
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; align-items: center; gap: 14px;
  padding: 10px 12px;
  background: var(--glass); border: 1px solid rgba(255, 255, 255, 0.08); border-radius: var(--r-lg);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  max-width: 820px; margin: 0 auto;
}
.step-btn {
  width: 48px; height: 48px; border-radius: var(--r-md);
  display: grid; place-items: center;
  background: var(--torch); color: var(--torch-ink);
  box-shadow: 0 0 0 1px rgba(255, 210, 122, 0.5) inset, 0 6px 20px rgba(255, 181, 71, 0.22);
  transition: transform 0.1s, filter 0.15s;
}
.step-btn svg { width: 18px; height: 18px; }
.step-btn:not(:disabled):hover { filter: brightness(1.08); }
.step-btn:not(:disabled):active { transform: translateY(1px); }
.step-btn:disabled { background: var(--ink-3); color: var(--muted); box-shadow: none; opacity: 1; }
.step-mid { min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.step-label { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.step-label strong { font: 700 20px/1 var(--display); white-space: nowrap; }
.step-label strong em { font-style: normal; color: var(--muted); font-size: 15px; }
.step-label span { font: 500 12px/1 var(--mono); color: var(--muted); white-space: nowrap; }

.range { -webkit-appearance: none; appearance: none; width: 100%; height: 18px; background: transparent; margin: 0; cursor: pointer; }
.range:disabled { cursor: default; opacity: 0.4; }
.range::-webkit-slider-runnable-track {
  height: 6px; border-radius: 3px;
  background:
    linear-gradient(var(--torch), var(--torch)) 0 0 / var(--fill, 0%) 100% no-repeat,
    var(--line-2);
}
.range::-moz-range-track { height: 6px; border-radius: 3px; background: var(--line-2); }
.range::-moz-range-progress { height: 6px; border-radius: 3px; background: var(--torch); }
.range::-webkit-slider-thumb {
  -webkit-appearance: none; width: 16px; height: 16px; margin-top: -5px; border-radius: 4px;
  background: var(--torch-2); border: 2px solid var(--ink-0); box-shadow: 0 0 0 1px var(--torch);
}
.range::-moz-range-thumb { width: 14px; height: 14px; border-radius: 4px; background: var(--torch-2); border: 2px solid var(--ink-0); }

.hint {
  position: absolute; right: 18px; bottom: 96px; font-size: 12px; color: var(--faint); pointer-events: none;
  text-align: right;
}

/* ---------- tour ---------- */
.app.touring .stepper, .app.touring .hint, .app.touring .tools { display: none; }
.app.touring .viewer canvas { cursor: default; }
.tour-ui { position: absolute; inset: 0; pointer-events: none; }
.tour-caption {
  position: absolute; left: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 4px;
  padding: 10px 14px; border-radius: var(--r-md); background: var(--glass); border: 1px solid rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); max-width: calc(100% - 200px);
}
.tour-eyebrow { font: 600 11px/1 var(--body); text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted); }
.tour-caption strong { font: 700 20px/1.15 var(--display); color: var(--torch-2); }
.tour-actions { position: absolute; right: 16px; bottom: 16px; display: flex; gap: 8px; pointer-events: auto; }
.tour-stop { padding: 9px 14px; border-radius: var(--r-sm); background: var(--torch); color: var(--torch-ink); font-weight: 700; font-size: 13px; }
.tour-all {
  display: flex; align-items: center; justify-content: center; gap: 8px; padding: 8px 10px; border-radius: var(--r-sm);
  background: rgba(255, 181, 71, 0.12); color: var(--torch-2); border: 1px solid rgba(255, 181, 71, 0.35); font-weight: 600; font-size: 13.5px;
}
.tour-all:hover { background: rgba(255, 181, 71, 0.2); }
.tour-all svg { width: 16px; height: 16px; }

/* ---------- explore ---------- */
.app.exploring .stepper, .app.exploring .hint, .app.exploring .stage-head, .app.exploring .tools { display: none; }
.app.exploring .viewer canvas { cursor: crosshair; }
.explore-ui { position: absolute; inset: 0; pointer-events: none; }
.explore-hint {
  position: absolute; left: 16px; top: 16px; right: 150px; width: fit-content;
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  padding: 8px 14px; border-radius: var(--r-md); background: var(--glass); border: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 12.5px; color: var(--muted); max-width: calc(100% - 32px);
}
.explore-hint strong { font: 700 15px/1.2 var(--display); color: var(--torch); }
.explore-hint .touch { display: none; }
.joystick {
  position: absolute; left: 22px; bottom: 22px; width: 120px; height: 120px; border-radius: 50%;
  background: var(--glass); border: 1px solid rgba(255, 255, 255, 0.12); pointer-events: auto; touch-action: none;
  display: none; place-items: center;
}
.knob { width: 50px; height: 50px; border-radius: 50%; background: var(--torch); box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4); }
.lift { position: absolute; right: 22px; bottom: 22px; display: none; flex-direction: column; gap: 8px; pointer-events: auto; }
.lift-btn {
  width: 54px; height: 54px; border-radius: var(--r-md); background: var(--glass); border: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 18px; color: var(--text); touch-action: none;
}
.lift-btn:active { background: var(--torch); color: var(--torch-ink); }
.exit-explore {
  position: absolute; right: 16px; top: 16px; pointer-events: auto;
  padding: 8px 12px; border-radius: var(--r-sm); background: var(--torch); color: var(--torch-ink); font-weight: 700; font-size: 13px;
}
@media (pointer: coarse) {
  .joystick { display: grid; }
  .lift { display: flex; }
  .explore-hint .desk { display: none; }
  .explore-hint .touch { display: inline; }
}

/* ---------- panel ---------- */
.panel {
  grid-area: panel; min-height: 0;
  display: flex; flex-direction: column;
  background: var(--ink-1); border: 1px solid var(--line); border-radius: var(--r-lg);
  overflow: hidden;
}
.tabs { display: flex; gap: 2px; padding: 6px; border-bottom: 1px solid var(--line); }
.tabs button {
  flex: 1; padding: 8px 6px; border-radius: var(--r-sm);
  font-weight: 600; font-size: 13.5px; color: var(--muted);
}
.tabs button:hover { color: var(--text); }
.tabs button[aria-selected='true'] { color: var(--text); background: var(--ink-3); box-shadow: inset 0 0 0 1px var(--line-2); }
.tab-body { flex: 1; min-height: 0; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; }

.section-label { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.section-label h3 { font: 600 12px/1 var(--body); text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted); }
.section-label span { font: 500 12px/1 var(--mono); color: var(--faint); }

.plan-frame {
  position: relative; display: flex; justify-content: center;
  padding: 10px; border-radius: var(--r-md);
  background: #0c1522; border: 1px solid #1c2b40;
  background-image: radial-gradient(rgba(111, 211, 255, 0.07) 1px, transparent 1px);
  background-size: 12px 12px;
}
.plan-frame canvas { display: block; cursor: crosshair; max-width: 100%; }
.plan-legend { color: var(--muted); font-size: 12.5px; margin: 0; }
.tooltip {
  position: absolute; z-index: 5; pointer-events: none; max-width: 240px;
  background: var(--ink-0); border: 1px solid var(--line-2); border-radius: var(--r-sm);
  padding: 6px 9px; font-size: 12.5px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

.materials { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.materials li { border-bottom: 1px solid var(--line); }
.m-row {
  width: 100%; text-align: left;
  display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; column-gap: 12px; align-items: center;
  padding: 8px 6px; margin: 0 -6px; width: calc(100% + 12px); border-radius: var(--r-sm);
  transition: background 0.15s;
}
.m-row:hover { background: var(--ink-2); }
.m-row:hover .m-count::after { content: ' ⇄'; color: var(--muted); }
.l-row { grid-template-columns: 22px 28px minmax(0, 1fr) auto; }
.l-row:hover .m-count::after { content: none; }
.l-row.on { background: rgba(255, 181, 71, 0.12); box-shadow: inset 0 0 0 1px rgba(255, 181, 71, 0.55); }
.l-key { font: 700 12px/22px var(--mono); text-align: center; border-radius: 6px; background: var(--ink-0); color: inherit; box-shadow: inset 0 0 0 1px var(--line-2); }
.l-row.on .l-key { background: var(--torch); color: var(--torch-ink); box-shadow: none; }
.m-was { color: var(--prism); font-size: 11.5px; }
.m-note { color: var(--muted); font-size: 11.5px; line-height: 1.35; }
.mat-actions { display: flex; gap: 6px; }
.switch-row { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: var(--r-md); background: var(--ink-2); border: 1px solid var(--line); cursor: pointer; }
.switch-row input { position: absolute; opacity: 0; pointer-events: none; }
.switch { flex: none; width: 36px; height: 20px; border-radius: 999px; background: var(--line-2); position: relative; transition: background 0.15s; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: var(--text); transition: transform 0.15s; }
.switch-row input:checked + .switch { background: var(--torch); }
.switch-row input:checked + .switch::after { transform: translateX(16px); background: var(--torch-ink); }
.switch-row input:focus-visible + .switch { outline: 2px solid var(--torch); outline-offset: 2px; }
.switch-row span:last-child { display: flex; flex-direction: column; font-size: 13.5px; }
.switch-row em { font-style: normal; color: var(--muted); font-size: 12px; }

.picker {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center;
  background: rgba(4, 6, 10, 0.62); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  padding: max(16px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) max(16px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
}
.picker-card {
  width: min(560px, 100%); max-height: min(640px, 100%); min-height: 0; display: flex; flex-direction: column; gap: 12px;
  background: var(--ink-1); border: 1px solid var(--line-2); border-radius: var(--r-lg); padding: 16px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}
.picker-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.picker-eyebrow { font: 600 11px/1 var(--body); text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted); }
.picker-head h3 { font: 700 20px/1.2 var(--display); margin-top: 6px; }
.picker-close { width: 32px; height: 32px; border-radius: var(--r-sm); color: var(--muted); }
.picker-close:hover { background: var(--ink-3); color: var(--text); }
.picker-grid {
  flex: 1; min-height: 0; overflow-y: auto;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; align-content: start;
}
.pick {
  display: flex; align-items: center; gap: 9px; padding: 7px; border-radius: var(--r-sm);
  border: 1px solid var(--line); background: var(--ink-2); font-size: 13px; text-align: left;
}
.pick:hover { border-color: var(--line-2); background: var(--ink-3); }
.pick.current { border-color: var(--torch); box-shadow: inset 0 0 0 1px var(--torch); }
.pick.original span::after { content: ' (original)'; color: var(--muted); }
.pick .swatch { width: 26px; height: 26px; flex: none; }
.picker-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; color: var(--muted); font-size: 12.5px; }
.materials li:last-child { border-bottom: 0; }
.swatch { width: 28px; height: 28px; image-rendering: pixelated; border-radius: 5px; background: var(--ink-0); box-shadow: inset 0 0 0 1px rgba(255,255,255,0.06); }
.m-text { min-width: 0; display: flex; flex-direction: column; }
.m-name { font-weight: 550; font-size: 14px; }
.m-stacks { color: var(--faint); font: 500 11.5px/1.3 var(--mono); }
.m-count { font: 600 14px/1 var(--mono); font-variant-numeric: tabular-nums; color: var(--torch-2); }
.empty { color: var(--muted); margin: 0; font-size: 14px; }

.small-btn { padding: 6px 10px; border-radius: var(--r-sm); border: 1px solid var(--line-2); background: var(--ink-2); font-size: 12.5px; font-weight: 600; }
.small-btn:hover { background: var(--ink-3); }
.total { margin: 0; color: var(--muted); font-size: 13.5px; }
.total strong { color: var(--text); font-family: var(--mono); }

.desc { margin: 0; font-size: 15px; line-height: 1.6; color: #cfd6e0; }
.tips { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 10px; counter-reset: tip; }
.tips li { display: grid; grid-template-columns: 22px 1fr; gap: 10px; font-size: 14px; color: #cfd6e0; counter-increment: tip; }
.tips li::before {
  content: counter(tip); width: 22px; height: 22px; display: grid; place-items: center; border-radius: 6px;
  background: var(--ink-3); color: var(--torch); font: 700 12px/1 var(--mono);
}
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 0; }
.facts div { background: var(--ink-2); border: 1px solid var(--line); border-radius: var(--r-md); padding: 10px 12px; }
.facts dt { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.1em; }
.facts dd { margin: 4px 0 0; font: 600 16px/1.2 var(--mono); }
.big-btn { padding: 12px; border-radius: var(--r-md); background: var(--torch); color: var(--torch-ink); font-weight: 700; }
.big-btn.is-done { background: rgba(111, 208, 140, 0.14); color: var(--easy); box-shadow: inset 0 0 0 1px rgba(111, 208, 140, 0.4); }

.scrim { display: none; }

/* ---------- medium: library becomes a drawer ---------- */
@media (max-width: 1180px) {
  .app { grid-template-columns: minmax(0, 1fr) 360px; grid-template-areas: 'bar bar' 'stage panel'; }
  .lib-toggle { display: inline-flex; }
  .library {
    position: fixed; z-index: 30; top: 0; bottom: 0; left: 0; width: min(330px, 88vw);
    border-radius: 0 var(--r-lg) var(--r-lg) 0;
    padding-top: env(safe-area-inset-top, 0px);
    padding-left: env(safe-area-inset-left, 0px);
    transform: translateX(-102%); transition: transform 0.25s ease;
    box-shadow: 20px 0 60px rgba(0, 0, 0, 0.5);
  }
  .app.lib-open .library { transform: none; }
  .scrim { display: block; position: fixed; inset: 0; z-index: 25; background: rgba(0, 0, 0, 0.5); opacity: 0; pointer-events: none; transition: opacity 0.25s; }
  .app.lib-open .scrim { opacity: 1; pointer-events: auto; }
}

/* ---------- small: stack and let the page scroll ---------- */
@media (max-width: 860px) {
  body { overflow: auto; }
  .app { height: auto; min-height: 100%; grid-template-columns: minmax(0, 1fr); grid-template-areas: 'bar' 'stage' 'panel'; }
  .stage { height: 62vh; min-height: 380px; }
  .panel { overflow: visible; }
  .tab-body { overflow: visible; }
  .tagline, .hint { display: none; }
  .stage-head { right: 16px; top: 64px; left: 16px; }
  .stage-head h1 { font-size: 24px; }
  .stepper { left: 10px; right: 10px; bottom: 10px; gap: 10px; padding: 8px; }
  .search { font-size: 16px; }
  .step-btn { width: 44px; height: 44px; }
  #layer-info { display: none; }
  .tools { left: 12px; right: auto; top: 12px; }
}
@media (max-width: 640px) {
  .view-toggle { display: flex; }
  .tools #tour span { display: none; }
  .tools .view-toggle span { display: inline; }
  .tool-group {
    display: none; position: absolute; top: calc(100% + 6px); right: 0; z-index: 20; min-width: 190px;
    flex-direction: column; gap: 2px; padding: 5px;
    background: var(--ink-1); border: 1px solid var(--line-2); border-radius: var(--r-md);
    box-shadow: 0 14px 34px rgba(0, 0, 0, 0.5); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  }
  .tool-group.open { display: flex; }
  .tool-group .tool { justify-content: flex-start; padding: 10px 12px; font-size: 14px; }
  .tools .tool-group .tool span { display: inline; }
}
/* Phones: the block picker becomes a bottom sheet. */
@media (max-width: 560px) {
  .picker { align-items: flex-end; padding: 0; }
  .picker-card {
    width: 100%; max-height: 82%; border-radius: var(--r-lg) var(--r-lg) 0 0; border-bottom: 0;
    padding-bottom: max(16px, env(safe-area-inset-bottom, 0px));
    padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  }
  .picker-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pick span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---------- step-by-step instructions (full screen) ---------- */
.guide-btn {
  display: flex; align-items: center; gap: 6px; height: 48px; padding: 0 14px; flex: none;
  border-radius: var(--r-md); border: 1px solid var(--line-2); background: var(--ink-2);
  font-weight: 700; font-size: 13px; color: var(--text);
}
.guide-btn:hover { background: var(--ink-3); border-color: var(--torch); }
.guide-btn svg, .expand-btn svg { width: 14px; height: 14px; }
.expand-btn { display: inline-flex; align-items: center; gap: 6px; margin-left: auto; }
.section-label .expand-btn + * { margin-left: 0; }

.guide {
  position: fixed; inset: 0; z-index: 60; background: var(--ink-0); color: var(--text);
  display: grid; grid-template-columns: minmax(0, 1fr) 360px; grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas: 'head head' 'stage side';
}
.guide[hidden] { display: none; }
.g-head {
  grid-area: head; display: flex; align-items: center; gap: 14px; padding: 10px 16px;
  border-bottom: 1px solid var(--line); background: var(--ink-1); position: relative;
}
.g-close { width: 38px; height: 38px; border-radius: var(--r-sm); background: var(--ink-2); border: 1px solid var(--line-2); font-size: 16px; flex: none; }
.g-close:hover { background: var(--ink-3); }
.g-titles { display: flex; flex-direction: column; min-width: 0; }
.g-titles strong { font: 700 20px/1.15 var(--display); }
.g-titles strong em { font-style: normal; color: var(--muted); font-size: 15px; }
.g-eyebrow { color: var(--torch); font: 700 11px/1.3 var(--mono); text-transform: uppercase; letter-spacing: 0.06em; }
.g-layerbar { position: absolute; left: 0; right: 0; bottom: -1px; height: 3px; background: transparent; }
.g-layerbar i { display: block; height: 100%; background: var(--torch); transition: width 0.25s; }
.g-stage { grid-area: stage; position: relative; min-height: 0; overflow: hidden; touch-action: none; }
.g-stage canvas { display: block; cursor: grab; touch-action: none; }
.g-stage canvas:active { cursor: grabbing; }
.g-stage .tooltip { max-width: 260px; }
.g-zoom {
  position: absolute; right: 14px; bottom: 14px; display: flex; flex-direction: column; gap: 6px;
}
.g-zoom button {
  width: 44px; height: 44px; border-radius: var(--r-sm); background: var(--glass); border: 1px solid var(--line-2);
  font: 700 20px/1 var(--body); backdrop-filter: blur(8px);
}
.g-zoom #g-fit { font-size: 12px; }
.g-zoom button:hover { border-color: var(--torch); }
.g-side {
  grid-area: side; border-left: 1px solid var(--line); background: var(--ink-1);
  display: flex; flex-direction: column; gap: 12px; padding: 16px; overflow-y: auto; min-height: 0;
}
.g-card { background: var(--ink-2); border: 1px solid var(--line-2); border-radius: var(--r-md); padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.g-card h2 { margin: 0; font: 700 21px/1.2 var(--body); }
.g-big { display: grid; grid-template-columns: auto auto minmax(0, 1fr); gap: 12px; align-items: center; }
.g-key { width: 34px; height: 34px; border-radius: 9px; background: var(--torch); color: var(--torch-ink); font: 800 18px/34px var(--mono); text-align: center; }
.g-icon { width: 48px; height: 48px; image-rendering: pixelated; border-radius: 7px; box-shadow: 0 0 0 2px var(--torch); }
.g-hint { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.45; }
.g-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.g-chip { display: inline-flex; align-items: center; gap: 5px; padding: 4px 8px 4px 4px; border-radius: 8px; background: var(--ink-0); border: 1px solid var(--line); font: 600 12.5px/1 var(--mono); }
.g-chip b { width: 20px; height: 20px; border-radius: 5px; background: var(--ink-3); text-align: center; line-height: 20px; font-size: 11px; }
.g-chip img { width: 18px; height: 18px; image-rendering: pixelated; border-radius: 3px; }
.g-nav { display: grid; grid-template-columns: 1fr 2fr; gap: 8px; }
.g-nav button { height: 52px; border-radius: var(--r-md); display: flex; align-items: center; justify-content: center; gap: 8px; font-weight: 700; font-size: 15px; }
.g-nav svg { width: 16px; height: 16px; }
.g-back { background: var(--ink-2); border: 1px solid var(--line-2); }
.g-next { background: var(--torch); color: var(--torch-ink); box-shadow: 0 6px 18px rgba(255, 181, 71, 0.22); }
.g-nav button:disabled { opacity: 0.4; box-shadow: none; }
.g-list { display: flex; flex-direction: column; gap: 4px; }
.g-row {
  display: grid; grid-template-columns: 22px 10px 26px minmax(0, 1fr) auto; gap: 10px; align-items: center;
  padding: 7px 8px; border-radius: var(--r-sm); text-align: left; font-size: 13.5px;
}
.g-row[data-part="-1"] { grid-template-columns: 22px minmax(0, 1fr) auto; }
.g-row:hover { background: var(--ink-2); }
.g-row.on { background: rgba(255, 181, 71, 0.12); box-shadow: inset 0 0 0 1px rgba(255, 181, 71, 0.55); }
.g-row.on .l-key { background: var(--torch); color: var(--torch-ink); box-shadow: none; }
.g-row .swatch { width: 26px; height: 26px; }
.g-rname { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.g-rcount { font: 600 12.5px/1 var(--mono); color: var(--muted); }
.g-row.done .g-rcount { color: #5ee39a; }
.g-row.done .g-rname { color: var(--muted); }
.g-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.g-tip { margin: 0; color: var(--faint); font-size: 12px; line-height: 1.45; }
.app.guiding .stage, .app.guiding .panel { visibility: hidden; }

@media (max-width: 860px) {
  .guide { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr) auto; grid-template-areas: 'head' 'stage' 'side'; }
  .g-side { border-left: 0; border-top: 1px solid var(--line); max-height: 42vh; padding: 12px; gap: 10px; }
  .g-titles strong { font-size: 17px; }
  .g-card h2 { font-size: 17px; }
  .g-icon { width: 38px; height: 38px; }
  .g-tip, .g-big .g-hint { display: none; }
  .g-side { max-height: 38vh; }
  .g-nav button { height: 46px; }
  .guide-btn span { display: none; }
  .guide-btn { padding: 0 12px; height: 44px; }
}

/* ---------- downloads for Minecraft ---------- */
.tools #ar-btn span { display: inline; }
.dl-list { display: flex; flex-direction: column; gap: 6px; }
.dl {
  display: grid; grid-template-columns: 18px minmax(0, 1fr); gap: 10px; align-items: start; text-align: left;
  padding: 10px 12px; border-radius: var(--r-md); background: var(--ink-2); border: 1px solid var(--line);
}
.dl:hover { border-color: var(--torch); }
.dl:disabled { opacity: 0.6; }
.dl svg { width: 16px; height: 16px; margin-top: 2px; color: var(--torch); }
.dl strong { display: block; font-size: 14px; }
.dl em { display: block; font-style: normal; color: var(--muted); font-size: 12.5px; line-height: 1.4; }
.dl-help { font-size: 13px; color: var(--muted); line-height: 1.5; }
.dl-help summary { cursor: pointer; color: var(--text); font-weight: 600; padding: 4px 0; }
.dl-help p { margin: 8px 0; }
.dl-help code, .dl-help kbd { font: 500 12px var(--mono); background: var(--ink-0); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; color: var(--text); }

/* ---------- AR dialog ---------- */
.ar { position: fixed; inset: 0; z-index: 70; background: rgba(4, 6, 10, 0.72); display: grid; place-items: center; padding: 16px; backdrop-filter: blur(6px); }
.ar[hidden] { display: none; }
.ar-card {
  width: min(560px, 100%); max-height: 100%; overflow-y: auto; display: flex; flex-direction: column; gap: 12px;
  background: var(--ink-1); border: 1px solid var(--line-2); border-radius: var(--r-lg); padding: 16px; box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}
.ar-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.ar-head h3 { margin: 2px 0 0; font: 700 20px/1.2 var(--display); }
.ar-stage { position: relative; height: min(48vh, 380px); border-radius: var(--r-md); overflow: hidden; background: var(--scene); }
.ar-stage model-viewer { width: 100%; height: 100%; --poster-color: transparent; }
.ar-loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 14px; z-index: 1; background: var(--scene); }
.ar-loading[hidden] { display: none; }
.ar-opts { display: flex; flex-wrap: wrap; gap: 8px; }
.seg { display: flex; gap: 3px; padding: 3px; background: var(--ink-0); border: 1px solid var(--line); border-radius: var(--r-sm); flex: 1 1 200px; }
.seg button { flex: 1; padding: 7px 8px; border-radius: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--ink-3); color: var(--text); box-shadow: inset 0 0 0 1px var(--line-2); }
.ar-go {
  height: 50px; border-radius: var(--r-md); background: var(--torch); color: var(--torch-ink); font-weight: 700; font-size: 15px;
  display: flex; align-items: center; justify-content: center; gap: 8px; box-shadow: 0 6px 18px rgba(255, 181, 71, 0.22);
}
.ar-go svg { width: 18px; height: 18px; }
.ar-go:disabled { opacity: 0.45; box-shadow: none; }
.ar-note { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.45; }

.g-marker { width: 10px; height: 10px; border-radius: 3px; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.25); }
#g-bedrock { display: inline-flex; align-items: center; gap: 6px; }
#g-bedrock svg { width: 13px; height: 13px; }

/* ---------- page content under the app (build guides for readers and search engines) ---------- */
.seo { max-width: 920px; margin: 0 auto; padding: 56px 20px 96px; color: #cfd6e0; font-size: 16px; line-height: 1.65; }
.seo a { color: var(--torch-2); }
.seo a:hover { text-decoration: underline; }
.seo h1 { font: 700 clamp(28px, 4vw, 40px)/1.15 var(--display); color: var(--text); margin: 8px 0 14px; }
.seo h2 { font: 700 22px/1.25 var(--body); color: var(--text); margin: 40px 0 12px; }
.seo h2 a { color: inherit; }
.seo .lede { font-size: 18px; color: var(--text); }
.seo .crumbs { font-size: 13px; color: var(--muted); }
.seo .crumbs a { color: var(--muted); }
.seo .facts { list-style: none; padding: 0; margin: 20px 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; }
.seo .facts li { background: var(--ink-1); border: 1px solid var(--line); border-radius: var(--r-md); padding: 10px 12px; color: var(--text); }
.seo .facts b { display: block; font: 600 11px/1.4 var(--mono); text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.seo .mats { width: 100%; border-collapse: collapse; font-size: 14.5px; }
.seo .mats th, .seo .mats td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); }
.seo .mats th { font: 600 11px var(--mono); text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.seo .mats td:nth-child(2) { font-family: var(--mono); color: var(--torch-2); }
.seo .mats td:nth-child(3) { font-family: var(--mono); color: var(--muted); font-size: 13px; }
.seo .tips-list li, .seo .steps li { margin: 6px 0; }
.seo .steps { font-size: 14.5px; columns: 2 320px; column-gap: 32px; }
.seo .steps li { break-inside: avoid; }
.seo .steps b { color: var(--text); margin-right: 6px; }
.seo .cards { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
.seo .cards a { display: flex; flex-direction: column; gap: 2px; height: 100%; padding: 12px 14px; border-radius: var(--r-md); background: var(--ink-1); border: 1px solid var(--line); color: var(--text); text-decoration: none; }
.seo .cards a:hover { border-color: var(--torch); }
.seo .cards span { font-size: 13px; color: var(--muted); }
.seo .cards em { font-style: normal; font-size: 13.5px; color: #b7c0cc; margin-top: 4px; }
.seo .cards-wide { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.seo .tags { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.seo .tags a { display: inline-block; padding: 6px 12px; border-radius: 999px; background: var(--ink-1); border: 1px solid var(--line-2); color: var(--text); font-size: 14px; text-decoration: none; }
.seo .tags span { color: var(--muted); font-family: var(--mono); font-size: 12px; margin-left: 4px; }
