:root {
  --bg: #0f1216; --card: #191e24; --card2: #222930; --line: #2a3139; --text: #e8edf2; --dim: #8b96a3;
  --accent: #3fb68b; --accent-d: #1d5e48; --on-accent: #06140f; --warn: #f0b429; --bad: #e5534b;
  --bed3d: #2a3038; --bin3d: #9aa7b4; --shadow: 0 1px 2px #0006, 0 8px 24px #0004;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #eef1f4; --card: #ffffff; --card2: #f1f4f7; --line: #dde3e9; --text: #15191e; --dim: #66717d;
    --accent: #23966e; --accent-d: #d7f1e7; --on-accent: #ffffff; --warn: #b7791f; --bad: #c53030;
    --bed3d: #3a4149; --bin3d: #c9d1d9; --shadow: 0 1px 2px #0001, 0 8px 24px #0000000d;
    color-scheme: light;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
body {
  margin: 0 auto; background: var(--bg); color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  padding: env(safe-area-inset-top) 0 calc(env(safe-area-inset-bottom) + 24px);
  max-width: 560px;
}
button { cursor: pointer; transition: background .15s, border-color .15s, color .15s, transform .08s; }
button:active:not(:disabled) { transform: scale(.97); }
header { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 6px; }
h1 { font-size: 22px; margin: 0; letter-spacing: -0.02em; }
h1::before { content: "🧲 "; }
.hdr-right { display: flex; gap: 8px; align-items: center; }
.pill { font-size: 13px; padding: 5px 11px; border-radius: 99px; background: var(--card); color: var(--dim); border: 1px solid var(--line); }
.pill.idle { color: var(--accent); }
.pill.busy { color: var(--warn); }
.pill.off { color: var(--bad); }
button.pill { font: inherit; font-size: 14px; }
#light.on, #camBtn.on { background: color-mix(in srgb, var(--warn) 20%, var(--card)); border-color: var(--warn); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 6px 14px; margin: 10px 0; box-shadow: var(--shadow); }
#banner, #job, #camPanel { margin: 8px 16px; }
#banner { padding: 14px; border-radius: 14px; background: color-mix(in srgb, var(--warn) 18%, var(--card)); border: 1px solid var(--warn); }
#banner b { display: block; font-size: 18px; margin-bottom: 8px; }
#job { padding: 14px; border-radius: 16px; background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow); }
#job .top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
#job b { font-size: 16px; }
#job .sub { color: var(--dim); font-size: 14px; }
#job .row { min-height: 40px; }
.cam { padding: 8px; }
.cam img, #job img { width: 100%; border-radius: 10px; display: block; background: #000; aspect-ratio: 16 / 9; object-fit: cover; }
.hint { color: var(--dim); font-size: 13px; margin: 6px 4px 2px; }
.bar { height: 8px; background: var(--card2); border-radius: 99px; margin: 10px 0; overflow: hidden; }
.bar div { height: 100%; background: var(--accent); border-radius: 99px; transition: width .6s; }
.stop { width: 100%; padding: 11px; border-radius: 12px; border: 1px solid var(--bad); background: transparent; color: var(--bad); font: inherit; font-weight: 600; }

nav { display: flex; gap: 8px; padding: 8px 16px; }
nav button, .seg button {
  flex: 1; padding: 10px; border: 1px solid var(--line); background: var(--card); color: var(--dim);
  border-radius: 12px; font: inherit;
}
nav button.on, .seg button.on { color: var(--text); border-color: var(--accent); background: var(--accent-d); }
main { padding: 0 16px; }
.row { display: flex; align-items: center; justify-content: space-between; min-height: 52px; gap: 12px; }
.card .row + .row { border-top: 1px solid var(--line); }
.row small { color: var(--dim); font-size: 13px; }
.step { display: flex; align-items: center; gap: 6px; }
.step button {
  width: 42px; height: 42px; border-radius: 12px; border: 1px solid var(--line); background: var(--card2);
  color: var(--text); font-size: 22px; line-height: 1;
}
.step input {
  width: 54px; height: 42px; text-align: center; font: inherit; font-size: 18px; color: var(--text);
  background: transparent; border: 1px solid var(--line); border-radius: 12px;
}
select { font: inherit; color: var(--text); background: var(--card2); border: 1px solid var(--line); border-radius: 12px; padding: 9px; }
.switch { appearance: none; width: 48px; height: 28px; border-radius: 99px; background: var(--card2); border: 1px solid var(--line); position: relative; cursor: pointer; transition: background .2s; flex: none; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--dim); transition: transform .2s, background .2s; }
.switch:checked { background: var(--accent-d); border-color: var(--accent); }
.switch:checked::after { transform: translateX(20px); background: var(--accent); }
.seg { display: flex; gap: 6px; }
.row .seg { width: 60%; }
#profile button { padding: 10px 2px; font-size: 15px; }
.mini { margin-left: 8px; padding: 5px 9px; border-radius: 9px; border: 1px solid var(--line); background: var(--card2); color: var(--accent); font: inherit; font-size: 13px; }

#cart { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0; scrollbar-width: none; }
.chip {
  flex: none; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--card);
  color: var(--text); font: inherit; font-size: 14px; display: flex; gap: 8px; align-items: center;
}
.chip.sel { border-color: var(--accent); background: var(--accent-d); }
.chip .x { color: var(--dim); font-size: 18px; padding-left: 4px; }
.chip.add { color: var(--accent); border-style: dashed; }

.viewer { padding: 8px; position: relative; }
#view3d { width: 100%; aspect-ratio: 4 / 3; display: block; border-radius: 12px; touch-action: none; background: radial-gradient(circle at 50% 30%, var(--card2), var(--card)); }
.viewmode { position: absolute; top: 16px; right: 16px; width: 140px; }
.viewmode button { padding: 6px; font-size: 13px; background: color-mix(in srgb, var(--card) 85%, transparent); backdrop-filter: blur(6px); }
.tabs { margin-top: 8px; }
.tabs button { padding: 7px; font-size: 14px; }

.plate-card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 12px; margin: 10px 0; transition: opacity .25s; box-shadow: var(--shadow); }
.plate-card h3 { margin: 0 0 8px; font-size: 15px; color: var(--dim); font-weight: 500; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 10px; text-align: center; }
.stats div { background: var(--card2); border-radius: 12px; padding: 9px 4px; }
.stats b { display: block; font-size: 18px; }
.stats span { font-size: 12px; color: var(--dim); }
.pending { display: inline-block; width: 52px; height: 18px; border-radius: 6px; vertical-align: middle;
  background: linear-gradient(90deg, var(--line) 25%, var(--card) 50%, var(--line) 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite linear; }
@keyframes shimmer { to { background-position: -200% 0; } }
.magnote { background: var(--card2); border-radius: 12px; padding: 10px 12px; font-size: 15px; margin-bottom: 10px; }
.magnote b { color: var(--accent); }
.go {
  width: 100%; padding: 15px; border: 0; border-radius: 14px; font: inherit; font-size: 18px; font-weight: 600;
  background: var(--accent); color: var(--on-accent);
}
.go:disabled { background: var(--card2); color: var(--dim); }
.why { font-size: 13px; color: var(--dim); text-align: center; margin-top: 6px; }
.slicing { color: var(--dim); text-align: center; padding: 24px 0; }
.err { color: var(--bad); }

svg.plate { width: 100%; height: auto; display: block; border-radius: 10px; }
svg.plate .bed { fill: var(--card2); }
svg.plate .body { fill: color-mix(in srgb, var(--accent) 22%, transparent); stroke: var(--accent); stroke-width: 1.2; }
svg.plate .div { stroke: var(--accent); stroke-width: 1; }
svg.plate .mag { fill: var(--dim); }
svg.plate text { font: 9px system-ui, sans-serif; fill: var(--text); }

.hist { display: grid; grid-template-columns: 96px 1fr; gap: 12px; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 10px; margin: 10px 0; box-shadow: var(--shadow); }
.hist svg.plate text { display: none; }
.hist .meta { font-size: 14px; color: var(--dim); min-width: 0; }
.hist .meta .title { color: var(--text); font-size: 16px; font-weight: 600; display: block; background: none; border: 0; padding: 0; text-align: left; font-family: inherit; }
.hist .meta .title::after { content: " ✎"; color: var(--dim); font-weight: 400; font-size: 13px; }
.hist .go { padding: 9px; font-size: 15px; margin-top: 8px; }
.hist .del { float: right; background: none; border: 0; color: var(--dim); font-size: 20px; padding: 0 4px; }
.status-finished { color: var(--accent); } .status-failed { color: var(--bad); } .status-magnets, .status-printing { color: var(--warn); } .status-cancelled { color: var(--dim); }
#toast { position: fixed; left: 16px; right: 16px; bottom: calc(env(safe-area-inset-bottom) + 16px); max-width: 528px; margin: auto; background: var(--text); color: var(--bg); padding: 14px; border-radius: 14px; text-align: center; box-shadow: var(--shadow); animation: pop .2s; }
@keyframes pop { from { transform: translateY(10px); opacity: 0; } }

/* Wide screens: controls on the left, 3D view, plate stats and Print on the right. */
@media (min-width: 900px) {
  body { max-width: 1180px; }
  #build:not([hidden]) { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); gap: 24px; align-items: start; }
  #build .right { position: sticky; top: 12px; }
  #build .right .viewer { margin-top: 4px; }
  nav { max-width: 42%; }
  #history:not([hidden]) { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
  #job, #banner, #camPanel { margin-inline: 16px; }
  #camPanel, #job { max-width: 620px; }
}
.stop { margin-top: 10px; }
#profName { display: block; }

/* Public site: no printer controls, no history. */
.intro { display: none; margin: 0 16px 6px; color: var(--dim); font-size: 14px; }
body.public .intro { display: block; }
body.public .hdr-right, body.public nav, body.public #banner, body.public #job, body.public #camPanel { display: none !important; }
.dl { display: block; text-align: center; margin-top: 10px; padding: 11px; border-radius: 12px; border: 1px solid var(--line); color: var(--accent); text-decoration: none; font-weight: 600; }
.dl.primary { background: var(--accent); color: var(--on-accent); border: 0; padding: 15px; font-size: 18px; }
