:root { --ink: #0d0f12; --panel: #161a20; --panel2: #1c2129; --line: #262c35; --accent: #ff6a13; --text: #e9edf2; --muted: #8a94a3; --bad: #ff7b7b; }
[hidden] { display: none !important; }
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--ink); color: var(--text); font: 14px/1.4 system-ui, "Segoe UI", sans-serif; display: grid; grid-template-rows: auto 1fr auto; overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
.btn { background: var(--accent); color: #111; border: 0; border-radius: 9px; padding: 7px 14px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); font-weight: 500; }
.btn.ghost:not(:disabled):hover { border-color: var(--accent); }
.btn.small { padding: 3px 10px; font-size: 12px; }
.btn.icon { padding: 5px 10px; font-size: 16px; line-height: 1; }
.muted { color: var(--muted); }
.bad { color: var(--bad); min-height: 1em; margin: 4px 0 0; }

/* top bar */
.top { display: flex; align-items: center; gap: 14px; padding: 8px 14px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { color: var(--text); text-decoration: none; font-weight: 700; font-size: 16px; white-space: nowrap; }
.brand span { color: var(--accent); margin-left: 3px; }
.brand em { font-style: normal; font-weight: 500; color: var(--muted); margin-left: 6px; }
.name { background: transparent; border: 1px solid transparent; border-radius: 8px; padding: 5px 8px; min-width: 120px; max-width: 280px; }
.name:hover, .name:focus { border-color: var(--line); outline: none; }
.actions { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }
.account { max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.menu { position: relative; }
.menu-list { position: absolute; right: 0; top: calc(100% + 6px); width: 300px; background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 6px; z-index: 20; box-shadow: 0 10px 30px #0008; }
.menu-list button { display: grid; width: 100%; text-align: left; background: none; border: 0; padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.menu-list button:hover { background: #ffffff0d; }
.menu-list small { color: var(--muted); }
.menu-list .opt { display: grid; gap: 4px; padding: 8px 10px; color: var(--muted); font-size: 12px; border-top: 1px solid var(--line); margin-top: 4px; }

/* layout */
.work { display: grid; grid-template-columns: 64px 1fr 300px; min-height: 0; }
.rail { display: flex; flex-direction: column; gap: 4px; padding: 8px 6px; background: var(--panel); border-right: 1px solid var(--line); }
.tool { display: grid; justify-items: center; gap: 2px; background: none; border: 1px solid transparent; border-radius: 10px; padding: 7px 0; font-size: 11px; color: var(--muted); cursor: pointer; }
.tool span { font-size: 18px; color: var(--text); }
.tool:hover { border-color: var(--line); }
.tool.active { background: #ff6a1322; border-color: var(--accent); color: var(--text); }
.grow { flex: 1; }
.stage { position: relative; min-width: 0; min-height: 0; overflow: hidden; }
.stage canvas { display: block; }
.stage.dragover::after { content: "Drop to open"; position: absolute; inset: 10px; border: 2px dashed var(--accent); border-radius: 16px; display: grid; place-items: center; font-size: 20px; background: #0d0f12aa; }
.panel { background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; padding: 8px; display: grid; gap: 8px; align-content: start; }
.box { background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.box summary { cursor: pointer; font-weight: 600; list-style: none; }
.box summary::-webkit-details-marker { display: none; }
.box summary::after { content: "›"; float: right; color: var(--muted); transition: transform .15s; }
.box[open] summary { margin-bottom: 8px; }
.box[open] summary::after { transform: rotate(90deg); }
.box h4 { margin: 0 0 6px; font-size: 13px; }
.row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.lbl { color: var(--muted); font-size: 12px; margin-right: 4px; }
.check { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.info { font-size: 12px; line-height: 1.6; }
.size { display: flex; gap: 6px; align-items: center; margin-top: 8px; }
.size label { display: flex; align-items: center; gap: 4px; color: var(--muted); font-size: 12px; }
.size input, select, .panel input[type=number] { width: 100%; background: var(--ink); border: 1px solid var(--line); border-radius: 7px; padding: 4px 6px; }
.size input { width: 64px; }
.unit { color: var(--muted); font-size: 12px; }
.slider { display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; align-items: center; font-size: 12px; color: var(--muted); margin-top: 6px; }
.slider input { grid-column: 1 / -1; width: 100%; accent-color: var(--accent); }
.tip { font-size: 12px; color: var(--muted); margin: 6px 0 0; }

/* palette */
.pal { display: grid; gap: 4px; }
.pal .item { display: grid; grid-template-columns: 22px 1fr auto auto; gap: 8px; align-items: center; padding: 4px 6px; border-radius: 8px; cursor: pointer; border: 1px solid transparent; }
.pal .item:hover { background: #ffffff08; }
.pal .item.on { border-color: var(--accent); }
.pal .sw { width: 22px; height: 22px; border-radius: 6px; border: 1px solid #ffffff30; }
.pal .meta { min-width: 0; }
.pal .meta b { display: block; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pal .meta small { color: var(--muted); }
.pal .ctl { display: flex; gap: 2px; }
.pal .ctl button { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 2px 4px; border-radius: 5px; }
.pal .ctl button:hover { color: var(--text); background: #ffffff10; }
.pal .key { color: var(--muted); font-size: 11px; }
.swap select { flex: 1; min-width: 0; }

/* dock */
.dock { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); display: flex; gap: 6px; padding: 6px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 6px 20px #0006; max-width: calc(100% - 28px); overflow-x: auto; }
.chips { display: flex; gap: 6px; }
.chip { position: relative; width: 40px; height: 40px; border-radius: 10px; border: 2px solid #ffffff22; cursor: pointer; flex: none; }
.chip.on { border-color: #fff; box-shadow: 0 0 0 2px var(--accent); }
.chip i { position: absolute; left: 3px; top: 1px; font-style: normal; font-size: 10px; font-weight: 700; text-shadow: 0 0 3px #000, 0 0 3px #000; color: #fff; }
.chip.add { background: transparent; border: 2px dashed var(--line); color: var(--muted); font-size: 22px; }
.chip.erase { background: repeating-linear-gradient(45deg, #c9cdd2 0 6px, #9aa0a6 6px 12px); }

.hint { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 6px 12px; font-size: 12px; color: var(--muted); pointer-events: none; }
.hint b { color: var(--text); }
.drop { position: absolute; inset: 0; display: grid; place-items: center; z-index: 2; background: radial-gradient(circle at 50% 40%, #1c2129, var(--ink)); }
.drop[hidden] { display: none; }
.drop-card { text-align: center; max-width: 460px; padding: 28px; border: 1px dashed var(--line); border-radius: 18px; background: var(--panel); display: grid; gap: 10px; justify-items: center; }
.drop-card h2 { margin: 0; }
.drop-card p { margin: 0 0 6px; color: var(--muted); }
.recent { width: 100%; display: grid; gap: 4px; margin-top: 8px; }
.recent:empty { display: none; }
.recent h4 { margin: 6px 0 2px; color: var(--muted); font-weight: 500; text-align: left; }
/* "Working" card across the middle of the window. The spinner turns on the GPU (transform only), so it keeps
   moving even while the page is busy number-crunching. */
.busy { position: fixed; inset: 0; display: grid; place-items: center; background: #0d0f12b0; z-index: 50; backdrop-filter: blur(2px); }
.busy[hidden] { display: none; }
.busy-card { display: grid; justify-items: center; gap: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 28px 36px; width: min(520px, 86vw); text-align: center; line-height: 1.45; box-shadow: 0 20px 60px #000a; }
.busy-title { font-size: 20px; }
.busy-sub { color: var(--muted); font-size: 14px; min-height: 1.4em; }
.spinner { width: 56px; height: 56px; border-radius: 50%; border: 5px solid #ffffff1a; border-top-color: var(--accent);
  animation: spin 0.9s linear infinite; will-change: transform; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }
.orient-bar { position: absolute; top: 12px; right: 12px; display: flex; align-items: center; gap: 4px; padding: 4px 6px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 6px 20px #0006; z-index: 3; }
.orient-bar[hidden] { display: none; }
.orient-bar .lbl { font-size: 12px; color: var(--muted); margin: 0 4px; }
.orient-bar button { background: transparent; color: var(--text); border: 1px solid transparent; border-radius: 7px; padding: 4px 8px; font: inherit; font-size: 12px; cursor: pointer; }
.orient-bar button:hover { background: #ffffff10; border-color: var(--line); }
.orient-bar button.on { background: var(--accent); color: #fff; }

/* projects + history */
.projects { display: grid; gap: 4px; }
.proj { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; align-items: center; padding: 6px; border-radius: 8px; cursor: pointer; }
.proj:hover { background: #ffffff08; }
.proj small { color: var(--muted); grid-column: 1; }
.proj .strip { display: flex; gap: 2px; grid-column: 1; }
.proj .strip i { width: 12px; height: 6px; border-radius: 2px; }
.proj button { grid-row: 1 / span 3; grid-column: 2; }
.history { margin: 0; padding: 0 0 0 4px; list-style: none; max-height: 260px; overflow-y: auto; font-size: 12px; display: grid; gap: 1px; }
.history li { padding: 3px 6px; border-radius: 6px; cursor: pointer; }
.history li:hover { background: #ffffff0d; }
.history li.undone { color: var(--muted); text-decoration: line-through; opacity: .6; }
.history li.now { border-left: 2px solid var(--accent); }

/* status */
.status { display: flex; gap: 12px; padding: 5px 14px; background: var(--panel); border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.status .right { margin-left: auto; }
#status.bad { color: var(--bad); }

/* dialogs */
.dlg { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 16px; padding: 18px; width: min(520px, 92vw); }
.dlg::backdrop { background: #000a; }
.dlg h3 { margin: 0 0 12px; }
.dlg label { display: grid; gap: 4px; color: var(--muted); font-size: 12px; margin-bottom: 10px; }
.dlg input:not([type=color]):not([type=checkbox]) { background: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; width: 100%; }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.tabs { display: flex; gap: 4px; margin-bottom: 10px; }
.tabs button { background: none; border: 1px solid var(--line); border-radius: 8px; padding: 5px 12px; cursor: pointer; color: var(--muted); }
.tabs button.on { border-color: var(--accent); color: var(--text); }
.search { width: 100%; margin-bottom: 8px; }
.fil-list { max-height: 50vh; overflow-y: auto; display: grid; gap: 2px; }
.fil { display: grid; grid-template-columns: 26px 1fr auto; gap: 10px; align-items: center; padding: 6px; border-radius: 8px; cursor: pointer; background: none; border: 0; text-align: left; }
.fil:hover { background: #ffffff0d; }
.fil .sw { width: 26px; height: 26px; border-radius: 7px; border: 1px solid #ffffff30; }
.fil small { color: var(--muted); display: block; }
.fil .left { color: var(--muted); font-size: 12px; text-align: right; }
.fil .ams { color: var(--accent); }
.custom { display: grid; grid-template-columns: 70px 1fr 90px auto; gap: 8px; align-items: end; }
.custom label { margin: 0; }
.custom input[type=color] { width: 100%; height: 36px; padding: 2px; background: var(--ink); border: 1px solid var(--line); border-radius: 8px; }

/* phase 2 */
.rail { overflow-y: auto; }
.tool { padding: 5px 0; }
.tool span { font-size: 16px; }
.overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 1; }
.ring { position: absolute; border: 2px solid #fff; box-shadow: 0 0 0 1px #000a, inset 0 0 0 1px #000a; border-radius: 50%; pointer-events: none; z-index: 1; transform: translate(-50%, -50%); }
.ring.mark { border-color: #ff4fd8; }
.ring.erase { border-style: dashed; }
.ctx-menu { position: absolute; z-index: 30; background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 4px; min-width: 220px; box-shadow: 0 10px 30px #0008; }
.ctx-menu button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 7px 10px; border-radius: 7px; cursor: pointer; }
.ctx-menu button:hover { background: #ffffff10; }
.ctx-menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
.pill { font-size: 11px; font-weight: 600; color: #111; background: var(--accent); border-radius: 20px; padding: 1px 7px; margin-left: 6px; }
.pill:empty { display: none; }
.seg { gap: 0; }
.seg button { flex: 1; background: var(--ink); border: 1px solid var(--line); color: var(--muted); padding: 4px 6px; font-size: 12px; cursor: pointer; }
.seg button + button { border-left: 0; }
.seg button:first-child { border-radius: 7px 0 0 7px; }
.seg button:last-child { border-radius: 0 7px 7px 0; }
.seg button.on { color: var(--text); background: #ff6a1326; border-color: var(--accent); }
.opts { display: grid; gap: 6px; margin-top: 8px; }
.opts .inline { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.opts .inline input[type=number] { width: 64px; }
.opts select, .opts input[type=text] { background: var(--ink); border: 1px solid var(--line); border-radius: 7px; padding: 4px 6px; width: 100%; }
.actions-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.warn { color: #ffcf5c; font-size: 12px; margin: 6px 0 0; }
.decal-colors { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 6px; }
.decal-colors i { width: 18px; height: 18px; border-radius: 5px; border: 1px solid #ffffff30; }

/* Phase 3: clean-up, parts and palette tools */
.panel .box hr { border: 0; border-top: 1px solid var(--line); margin: 10px 0; }
.panel input.num { width: 56px; }
.panel .row .muted { font-size: 12px; }
.menu-list label.check { display: flex; gap: 6px; align-items: center; }

/* Phase 4: print plan */
.plan-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; font-size: 12px; margin-bottom: 8px; }
.plan-grid label { display: flex; align-items: center; gap: 4px; justify-content: space-between; }
.plan-grid input.num { width: 52px; }
.plan-result table { width: 100%; border-collapse: collapse; font-size: 12px; margin: 6px 0; }
.plan-result td, .plan-result th { padding: 3px 4px; text-align: right; border-bottom: 1px solid var(--line); }
.plan-result td:first-child, .plan-result th:first-child { text-align: left; }
.plan-result .sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; vertical-align: -1px; margin-right: 4px; border: 1px solid rgba(0,0,0,.2); }
.plan-result .ok { color: #2fae5c; } .plan-result .short { color: #e5484d; font-weight: 600; }
.plan-result .sum { font-size: 12px; line-height: 1.5; }
.swap-strip { width: 100%; height: 28px; border-radius: 6px; display: block; margin: 6px 0; background: var(--line); }
.orient-row { display: flex; align-items: center; gap: 8px; font-size: 12px; margin: 4px 0; }
.orient-row span { flex: 1; }

/* guided export + reference image */
.ref-img { position: absolute; left: 50%; top: 50%; max-width: 100%; max-height: 100%; pointer-events: none; z-index: 1; transform: translate(-50%, -50%) scale(.8); opacity: .4; }
.guide { width: min(600px, 94vw); }
.guide h4 { margin: 14px 0 6px; font-size: 13px; }
.guide .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.guide select { background: var(--ink); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; }
.g-checks { display: grid; gap: 6px; }
.g-row { display: flex; align-items: center; gap: 8px; padding: 7px 9px; border-radius: 8px; background: var(--ink); font-size: 13px; }
.g-row > span:nth-child(2) { flex: 1; }
.g-ico { width: 18px; text-align: center; font-weight: 700; }
.g-row.ok .g-ico { color: #2fae5c; } .g-row.warn .g-ico { color: #f5a400; } .g-row.bad .g-ico { color: #e5484d; }
.g-steps { margin: 0; padding-left: 20px; font-size: 13px; color: var(--muted); display: grid; gap: 4px; }
.send-load { display: grid; gap: 6px; margin: 8px 0; font-size: 13px; }
.send-load table.load { width: 100%; border-collapse: collapse; }
.send-load table.load td, .send-load table.load th { text-align: left; padding: 4px 6px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.send-load .bad { color: #e5484d; margin: 0; } .send-load .ok { color: #2fae5c; }
.send-load .warn { color: #f5a400; }
.send-load .sw, .guide .sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; border: 1px solid #fff3; }
.dlg label.check { display: inline-flex; align-items: center; gap: 6px; margin: 0 14px 0 0; }

/* buying */
.buy { display: grid; gap: 8px; margin: 12px 0 4px; }
.buy h4 { margin: 4px 0 0; font-size: 13px; }
.buy-item { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; align-items: center; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; }
.buy-item.best { border-color: var(--accent); }
.buy-item small { color: var(--muted); grid-column: 1; }
.buy-item .btn { grid-row: 1 / span 2; grid-column: 2; }
.buy p.small { margin: 0; font-size: 12px; }
.buy .tag { display: inline-block; margin-left: 6px; padding: 1px 7px; border-radius: 999px; font-size: 11px; font-weight: 600; background: var(--accent); color: #fff; vertical-align: 1px; }
.credits-big b { font-size: 18px; color: var(--accent); }
#exportCost { margin: 6px 0 2px; font-size: 12px; line-height: 1.35; white-space: normal; }

/* AI */
.ai-thumb { width: 40px; height: 40px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); }
#aiRun { align-items: center; } #aiRun .muted { flex: 1; }

/* help */
.help-bubble { position: fixed; z-index: 1000; max-width: 300px; background: #0b0d10; color: var(--text); border: 1px solid var(--line); border-radius: 9px; padding: 8px 11px; font-size: 12.5px; line-height: 1.45; box-shadow: 0 8px 24px #000a; pointer-events: none; }
.help-bubble[hidden] { display: none; }
.help-q { display: inline-grid; place-items: center; width: 17px; height: 17px; margin-left: 6px; border-radius: 50%; border: 1px solid var(--line); color: var(--muted); font-size: 11px; font-weight: 600; cursor: help; vertical-align: 1px; }
.help-q:hover { color: var(--text); border-color: var(--muted); }
.help-dlg { width: min(860px, 94vw); }
.help-wrap { display: grid; grid-template-columns: 190px 1fr; gap: 18px; min-height: 420px; max-height: 70vh; }
.help-nav { display: grid; align-content: start; gap: 2px; border-right: 1px solid var(--line); padding-right: 10px; }
.help-nav button { text-align: left; background: none; border: 0; color: var(--muted); padding: 7px 10px; border-radius: 7px; font: inherit; cursor: pointer; }
.help-nav button:hover { color: var(--text); background: #ffffff08; }
.help-nav button.on { color: var(--text); background: #ffffff12; }
.help-body { overflow: auto; padding-right: 6px; line-height: 1.55; }
.help-body h3 { margin-top: 0; }
.help-body dt { font-weight: 600; margin-top: 10px; }
.help-body dd { margin: 2px 0 0; color: var(--muted); }
.help-body li { margin: 6px 0; }
.help-body .keys td { padding: 4px 12px 4px 0; vertical-align: top; }
.help-body .keys td:first-child { font-family: ui-monospace, monospace; white-space: nowrap; color: var(--accent); }
@media (max-width: 640px) { .help-wrap { grid-template-columns: 1fr; } .help-nav { border-right: 0; grid-auto-flow: column; overflow-x: auto; } }

/* narrow windows: the header never pushes the page wider than the window */
body { grid-template-columns: minmax(0, 1fr); }
.top { min-width: 0; }
.name { flex: 0 1 auto; min-width: 60px; }
.actions { min-width: 0; flex-shrink: 1; }
@media (max-width: 1200px) {
  .brand em { display: none; }
  .top { gap: 8px; padding: 8px 10px; }
  .actions { gap: 4px; }
  .actions .btn { padding-left: 9px; padding-right: 9px; }
  .account { max-width: 130px; }
  .actions .sep { display: none; }
}
@media (max-width: 1000px) {
  .work { grid-template-columns: 56px 1fr 270px; }
  #downloadBtn { display: none; }
}

/* account dialog: sign in / create account, terms, delete */
#authMode { display: flex; margin: 8px 0 10px; }
.dlg label.check.terms { display: flex; align-items: flex-start; margin: 6px 0; font-size: 13px; line-height: 1.4; }
.dlg label.check.terms input { margin-top: 2px; }
.legal-links { margin: 12px 0 0; }
.legal-links a { color: var(--muted); }
details.danger { margin-top: 14px; border: 1px solid #c0392b55; border-radius: 10px; padding: 8px 12px; }
details.danger summary { cursor: pointer; color: #e57373; font-size: 13px; }
details.danger label { display: block; margin: 8px 0; font-size: 13px; }
.btn.danger-btn { background: #c0392b; border-color: #c0392b; color: #fff; }
.btn.danger-btn:disabled { opacity: 0.5; cursor: not-allowed; }
#signInMsg.ok { color: #2fae5c; }
