:root {
  --page: #F5F6F8; --card: #FFFFFF; --raised: #ECEFF3; --line: #D6DBE3; --ink: #242830; --ink2: #566070;
  --accent: #0B6B80; --accent-dk: #095A6C; --neon: #04D9C4; --need: #8A5A00; --need-bg: #FFF4DC; --need-line: #E6CF9C; --bad: #BC3030;
  --r-btn: 10px; --r-card: 16px; --side: 300px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { background: var(--page); color: var(--ink); font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; min-height: 100dvh; display: grid; grid-template-rows: auto 1fr auto; gap: 12px; padding: 10px 16px 14px; }
button, input { font: inherit; color: inherit; }
a:focus-visible, button:focus-visible, input:focus-visible, canvas:focus-visible, .thumb:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--card); padding: 12px 16px; border-radius: var(--r-btn); z-index: 20; }
.skip:focus { left: 8px; }
.ico { width: 24px; height: 24px; flex: none; fill: currentColor; color: var(--accent); }

.top { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px; min-height: 48px; }
.brand { white-space: nowrap; display: flex; align-items: center; gap: 10px; min-height: 44px; font-weight: 700; font-size: 18px; color: var(--ink); text-decoration: none; margin-right: auto; }
.steps { display: flex; gap: 8px; list-style: none; margin: 0; padding: 0; }
.step { display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 14px; border: 1px solid var(--line); border-radius: var(--r-btn); background: var(--card); color: var(--ink2); font-size: 14px; }
.step .n { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 7px; background: var(--raised); font-weight: 700; }
.step em { font-style: normal; border-left: 1px solid var(--line); padding-left: 8px; }
.step.is-now { color: #fff; background: var(--accent); border-color: var(--accent); font-weight: 600; box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--neon); }
.step.is-now .n { background: #fff; color: var(--accent); }
.chip { margin: 0; display: flex; align-items: center; min-height: 44px; padding: 0 14px; background: var(--card); border: 1px solid var(--line); border-radius: var(--r-btn); font-size: 14px; color: var(--ink2); }
.chip b { color: var(--ink); font-weight: 700; margin-right: 6px; }
.chip.dev { border-color: var(--need-line); background: var(--need-bg); color: var(--need); font-weight: 700; }

.layout { display: grid; grid-template-columns: var(--side) minmax(0, 1fr) var(--side); gap: 14px; min-height: 0; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-card); padding: 14px 16px; }
h2 { margin: 0 0 4px; font-size: 20px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
h3 { margin: 0 0 6px; font-size: 16px; }
.help { margin: 4px 0 10px; color: var(--ink2); font-size: 14px; }
.soon { font-style: normal; font-size: 14px; font-weight: 700; color: var(--need); background: var(--need-bg); border: 1px solid var(--need-line); border-radius: 8px; padding: 2px 10px; }

/* parts tray */
.tray { overflow: auto; min-height: 0; }
.tray h3.fam { font-size: 14px; letter-spacing: 0.02em; text-transform: uppercase; color: var(--ink2); margin: 12px 0 8px; }
.parts { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 10px; list-style: none; margin: 0; padding: 0; }
.part { display: flex; flex-direction: column; border: 1px solid var(--line); border-top: 3px solid var(--neon); border-radius: 12px; background: var(--card); overflow: hidden; }
.part .thumb { aspect-ratio: 4 / 3; background: #D9DCE1; cursor: grab; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.part .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; -webkit-user-drag: none; }
.part .meta { padding: 8px 10px 4px; flex: 1; }
.part b { display: block; font-size: 14px; line-height: 1.25; }
.part span.sub { font-size: 14px; color: var(--ink2); }
.part .btn { margin: 6px 10px 10px; min-height: 44px; }
.emptytray { border: 1px dashed var(--line); border-radius: 12px; padding: 16px; color: var(--ink2); }
.emptytray b { display: block; color: var(--ink); margin-bottom: 6px; }

/* buttons */
.btn, .tb { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; min-width: 44px; padding: 6px 12px; font-weight: 600; font-size: 14px; line-height: 1.2; color: var(--ink); background: var(--card); border: 2px solid var(--line); border-radius: var(--r-btn); cursor: pointer; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; }
.btn:hover, .tb:hover { background: var(--raised); }
.btn.main { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.main:hover { background: var(--accent-dk); }
.btn[disabled], .tb[disabled] { color: var(--ink2); background: var(--raised); border-color: var(--line); cursor: not-allowed; opacity: 0.7; }
.btn.seg[aria-pressed="true"], .tb[aria-pressed="true"] { background: #E3F1F5; border-color: var(--accent); }

/* the 3D view */
.stage { display: flex; flex-direction: column; padding: 0; overflow: hidden; min-height: 0; }
.view { position: relative; flex: 1 1 auto; min-height: 320px; background: #E9EDF2; }
.view canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.view canvas:focus-visible { outline-offset: -4px; }
.empty { position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%); margin: 0; padding: 14px 18px; max-width: min(420px, 80%); text-align: center; background: var(--card); border: 1px solid var(--line); border-radius: 12px; color: var(--ink2); pointer-events: none; }
.empty b { display: block; color: var(--ink); font-size: 18px; margin-bottom: 4px; }
.loading { position: absolute; inset: 0; margin: 0; display: grid; place-items: center; background: var(--card); text-align: center; padding: 24px; }
.status { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; padding: 8px 14px; border-top: 1px solid var(--line); min-height: 48px; }
.status p { margin: 0; font-size: 14px; flex: 1 1 220px; }
.status p.bad { color: var(--bad); font-weight: 600; }
.warns { display: flex; flex-wrap: wrap; gap: 6px; list-style: none; margin: 0; padding: 0; }
.warns li { display: flex; align-items: center; gap: 6px; font-size: 14px; background: var(--need-bg); border: 1px solid var(--need-line); color: var(--need); border-radius: 8px; padding: 6px 10px; }
.warns .ico { width: 20px; height: 20px; color: var(--need); }
.toolbar { display: flex; flex-direction: column; gap: 6px; padding: 8px 10px 10px; border-top: 1px solid var(--line); background: var(--card); }
.tg { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.tb { flex: 1 1 56px; max-width: 120px; flex-direction: column; gap: 2px; padding: 4px 8px; font-size: 14px; font-weight: 500; }
.tb .ico { width: 22px; height: 22px; }
.tb[data-view="perspective"] { flex-basis: 96px; }

/* view cube: real buttons on the faces of a CSS 3D cube (shared/view-cube.js) */
#cube { position: absolute; right: 18px; top: 18px; width: 60px; height: 60px; perspective: 420px; z-index: 2; }
.vc-cube { position: relative; width: 60px; height: 60px; transform-style: preserve-3d; }
.vc-face { position: absolute; left: 0; top: 0; width: 60px; height: 60px; display: grid; place-items: center; padding: 0; font-size: 14px; font-weight: 600; color: var(--ink); background: #FFFFFF; border: 1px solid var(--line); border-radius: 4px; cursor: pointer; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.vc-face:hover { background: var(--raised); }
.vc-face.is-now { background: #E3F1F5; border-color: var(--accent); color: var(--accent); }

/* right column */
.side { display: flex; flex-direction: column; gap: 14px; min-height: 0; overflow: auto; }
.field { display: block; font-size: 14px; font-weight: 600; margin: 6px 0 4px; }
#name { width: 100%; min-height: 44px; padding: 0 12px; border: 2px solid var(--line); border-radius: var(--r-btn); background: var(--card); }
.list { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 6px; }
.list button { width: 100%; min-height: 44px; display: flex; align-items: center; gap: 8px; text-align: left; padding: 4px 10px; font-size: 14px; background: var(--card); border: 2px solid var(--line); border-radius: var(--r-btn); cursor: pointer; }
.list button:hover { background: var(--raised); }
.list button[aria-pressed="true"] { border-color: var(--accent); background: #E3F1F5; font-weight: 700; }
.list i { width: 14px; height: 14px; border-radius: 4px; border: 1px solid rgba(0,0,0,.25); flex: none; }
.list small { margin-left: auto; color: var(--ink2); font-size: 14px; }
#devbox { margin-top: 10px; display: grid; gap: 6px; }
.sel { margin: 12px 0 4px; padding: 12px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); display: grid; gap: 10px; }
.sel h3 { margin: 0; }
.steprow { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 14px; }
.steprow span { margin-right: 4px; }
.pad { display: grid; gap: 6px; grid-template-columns: repeat(3, 1fr); grid-template-areas: ". f u" "l . r" ". b d"; }
.pad .btn { min-width: 0; padding: 4px; }
#b-print { width: 100%; margin-top: 10px; }
.turnrow { display: grid; gap: 6px; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
.sel .help { margin: 0; }

.ghost { position: fixed; left: 0; top: 0; width: 112px; height: 84px; z-index: 50; pointer-events: none; border: 2px solid var(--accent); border-radius: 10px; overflow: hidden; background: #D9DCE1; opacity: .92; }
.ghost img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tabs { display: none; }

/* desktop: the page is one screen, panels scroll inside */
@media (min-width: 901px) {
  body { height: 100dvh; overflow: hidden; }
  .layout > * { min-height: 0; }
}
@media (min-width: 901px) and (max-width: 1500px) { :root { --side: 268px; } }
@media (min-width: 901px) and (max-width: 1250px) { :root { --side: 248px; } .step em { display: none; } }
@media (min-width: 901px) and (max-width: 1100px) { :root { --side: 224px; } .brand span { font-size: 16px; } .tb { padding: 4px 2px; } }
@media (min-width: 901px) and (max-height: 700px) { .view { min-height: 200px; } .toolbar { padding: 4px 8px 6px; } .tb { min-height: 44px; } }

/* phone and small tablet: view first, then the panels one at a time */
@media (max-width: 900px) {
  body { grid-template-rows: auto auto auto; padding: 8px 10px 16px; gap: 10px; }
  .layout { grid-template-columns: 1fr; gap: 10px; }
  .stage { order: 1; }
  .tray, .side { order: 3; }
  .view { flex: none; height: clamp(280px, 48vh, 520px); min-height: 0; }
  .tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; order: 2; position: static; }
  .tabs button { min-height: 48px; font-weight: 700; font-size: 15px; background: var(--card); border: 2px solid var(--line); border-radius: var(--r-btn); cursor: pointer; }
  .tabs button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
  main.layout { display: contents; }
  body { display: flex; flex-direction: column; }
  body > .top { order: 0; } body > .layout { order: 1; }
  body[data-tab="parts"] #p-mine, body[data-tab="parts"] #p-bo,
  body[data-tab="mine"] #p-parts, body[data-tab="mine"] #p-bo,
  body[data-tab="bo"] #p-parts, body[data-tab="bo"] #p-mine { display: none; }
  .steps { order: 3; width: 100%; } .step { flex: 1; flex-wrap: wrap; justify-content: center; align-content: center; gap: 0 6px; padding: 2px 6px; }
  .step em { flex-basis: 100%; text-align: center; border: 0; padding: 0; line-height: 1.1; }
  .brand { margin-right: 0; flex: 0 0 auto; white-space: nowrap; }
  .chip.dev { flex: 1 1 auto; justify-content: center; }
  .tray { overflow: visible; }
  .side { overflow: visible; }
  .toolbar { padding: 6px; }
}
@media (max-width: 420px) {
  .parts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #cube { right: 10px; top: 10px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
