:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --line: #e2e6ea;
  --ink: #1c2430;
  --ink2: #5a6675;
  --ink3: #8b96a5;
  --brand: #0f6e56;
  --brand-soft: #e1f5ee;
  --warn: #8a5a08;
  --warn-bg: #faeeda;
  --bad: #a32d2d;
  --bad-bg: #fcebeb;
  --ok: #0f6e56;
  --ok-bg: #e1f5ee;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 13px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
.app { display: flex; height: 100vh; overflow: hidden; }
aside {
  width: 352px;
  min-width: 352px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  padding: 0 0 40px;
}
.topbar {
  position: sticky;
  top: 0;
  z-index: 6;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 9px 18px;
}
.topbar a { font-size: 11.5px; font-weight: 600; color: var(--brand); text-decoration: none; }
.topbar a:hover { text-decoration: underline; }
.brand { padding: 16px 18px 12px; border-bottom: 1px solid var(--line); }
.brand h1 { margin: 0; font-size: 15px; font-weight: 600; letter-spacing: .2px; }
.brand p { margin: 3px 0 0; font-size: 11.5px; color: var(--ink3); }
section { border-bottom: 1px solid var(--line); padding: 14px 18px; }
section h2 {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink2);
  text-transform: uppercase;
  letter-spacing: .6px;
  display: flex;
  gap: 7px;
  align-items: center;
}
section h2 i {
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: var(--brand-soft);
  color: var(--brand);
  font-style: normal;
  font-size: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
}
label { display: block; font-size: 11.5px; color: var(--ink2); margin: 9px 0 4px; }
.row { display: flex; gap: 8px; align-items: center; }
.row > * { flex: 1; }
input[type=text], input[type=email], input[type=number], select, textarea {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-size: 12.5px;
  font-family: inherit;
}
textarea { resize: vertical; min-height: 56px; }
input[type=range] { width: 100%; accent-color: var(--brand); margin: 2px 0; }
.val { float: right; color: var(--ink); font-variant-numeric: tabular-nums; }
.hint { font-size: 11px; color: var(--ink3); margin: 3px 0 0; }
button {
  font-family: inherit;
  font-size: 12.5px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 7px 11px;
  cursor: pointer;
}
button:hover { border-color: #c7cdd4; }
button.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
button.primary:hover { background: #0c5a47; }
button:disabled { opacity: .45; cursor: default; }
.posrow { display: flex; gap: 8px; align-items: center; }
.posrow input[type=range] { flex: 1; margin: 0; }
.posax { width: 13px; flex: none; text-align: center; font-size: 12px; color: var(--ink3); line-height: 1; }
.posbtns { display: flex; gap: 6px; margin-top: 7px; }
.posbtns button { flex: 1; padding: 6px 8px; font-size: 12px; }
.posbtns button.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.swatches { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 2px; }
.sw { width: 26px; height: 26px; border-radius: 5px; border: 1px solid rgba(0,0,0,.14); cursor: pointer; padding: 0; }
.sw.on { outline: 2px solid var(--brand); outline-offset: 1px; }
.checks { display: flex; flex-direction: column; gap: 6px; }
.chk { border-radius: 7px; padding: 7px 9px; font-size: 11.5px; line-height: 1.45; border: 1px solid transparent; }
.chk b { display: block; font-size: 11.5px; font-weight: 600; margin-bottom: 1px; }
.chk.ok { background: var(--ok-bg); color: #0b4a3a; }
.chk.warn { background: var(--warn-bg); color: #6b4705; }
.chk.bad { background: var(--bad-bg); color: #7d1f1f; }
.cksum { display: flex; align-items: center; gap: 7px; font-size: 11.5px; color: var(--ink2); line-height: 1.4; }
.cksum i { width: 7px; height: 7px; border-radius: 50%; flex: none; background: var(--ok); }
.cksum.warn i { background: #c98a12; }
.cksum.bad i { background: var(--bad); }
.cksum b { font-weight: 600; color: var(--ink); }
#q-body { display: block; }
main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.viewport { flex: 1; position: relative; background: linear-gradient(180deg, #fbfcfd 0%, #eceff3 100%); }
canvas#gl { display: block; width: 100%; height: 100%; }
.tools { position: absolute; top: 12px; right: 12px; display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; max-width: calc(100% - 24px); }
.tools button { background: rgba(255,255,255,.92); backdrop-filter: blur(4px); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.vpnote { position: absolute; left: 14px; bottom: 12px; font-size: 11px; color: var(--ink3); }
.plan { height: 230px; border-top: 1px solid var(--line); background: #fff; position: relative; }
canvas#plan { display: block; width: 100%; height: 100%; }
.plantag { position: absolute; left: 12px; top: 9px; font-size: 11px; color: var(--ink3); text-transform: uppercase; letter-spacing: .6px; }
.cad-btns { position: absolute; right: 12px; top: 7px; display: flex; gap: 5px; z-index: 2; }
.cad-btns button { padding: 3px 8px; font-size: 11px; background: rgba(255,255,255,.92); }
.boot { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--ink3); font-size: 13px; }
.modal { position: fixed; inset: 0; background: rgba(20,26,34,.45); display: none; align-items: center; justify-content: center; z-index: 20; }
.modal.on { display: flex; }
.card { background: #fff; border-radius: 12px; max-width: 560px; width: 90%; padding: 20px; }
.card h3 { margin: 0 0 8px; font-size: 15px; }
.card pre { background: #f6f8fa; border: 1px solid var(--line); border-radius: 6px; padding: 10px; font-size: 11px; overflow: auto; max-height: 260px; }
.foot { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; }
.sep { height: 1px; background: var(--line); margin: 12px 0; }
.toggle { display: flex; align-items: center; gap: 7px; margin: 9px 0; font-size: 12px; color: var(--ink2); cursor: pointer; }
.toggle input { accent-color: var(--brand); }

/* ---- two entry paths: ready-made model vs. own shape ---- */
.mode { display: flex; gap: 6px; margin: 0 0 11px; }
.mode button { flex: 1; padding: 7px 5px; font-size: 12px; line-height: 1.25; border-radius: 7px; background: #fff; text-align: center; }
.mode button b { display: block; font-size: 12px; font-weight: 600; }
.mode button small { display: block; font-size: 10px; color: var(--ink3); margin-top: 1px; }
.mode button.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.mode button.on small { color: rgba(255,255,255,.8); }

/* ---- category filter tabs ---- */
.cat-tabs { display: flex; gap: 4px; margin: 0 0 8px; flex-wrap: wrap; }
.cat-tabs button {
  padding: 3px 8px;
  font-size: 11px;
  border-radius: 99px;
  background: #f6f8fa;
  border: 1px solid var(--line);
  color: var(--ink2);
}
.cat-tabs button.on {
  background: var(--brand-soft);
  border-color: var(--brand);
  color: var(--brand);
  font-weight: 600;
}

.tplgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; max-height: 300px; overflow-y: auto; padding: 2px 2px 6px; }
.tc { border: 1px solid var(--line); border-radius: 8px; background: #fff; padding: 0; overflow: hidden; cursor: pointer; text-align: left; display: block; }
.tc:hover { border-color: #c7cdd4; }
.tc.on { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand-soft); }
.tc img { display: block; width: 100%; height: 64px; object-fit: contain; background: #fff; }
.tc span { display: block; font-size: 10px; line-height: 1.35; padding: 3px 5px 4px; color: var(--ink3); }
.tc span b { display: block; font-size: 10.5px; font-weight: 600; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fixedrow { background: #f6f8fa; border-radius: 7px; padding: 8px 10px; font-size: 11.5px; color: var(--ink2); margin: 2px 0 6px; line-height: 1.6; }
.fixedrow b { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.ld { font-size: 11px; color: var(--ink3); padding: 5px 0; }

/* ---- multi-print-zone switcher ---- */
.zone-tabs { display: flex; gap: 5px; margin: 4px 0 8px; flex-wrap: wrap; }
.zone-tabs button { flex: 1; padding: 5px 7px; font-size: 11.5px; }
.zone-tabs button.on { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); font-weight: 600; }

/* ---- custom mask preview & brush editor ---- */
.mask-box {
  margin: 8px 0 6px;
  padding: 8px;
  background: #f6f8fa;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.mask-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: var(--ink2);
  margin-bottom: 6px;
}
canvas#maskCv {
  display: block;
  width: 100%;
  max-height: 150px;
  object-fit: contain;
  background: repeating-conic-gradient(#e9edf2 0% 25%, #ffffff 0% 50%) 50% / 12px 12px;
  border: 1px solid var(--line);
  border-radius: 5px;
  cursor: crosshair;
  touch-action: none;
}
.mask-tools {
  display: flex;
  gap: 5px;
  margin-top: 6px;
  flex-wrap: wrap;
}
.mask-tools button {
  flex: 1;
  padding: 4px 6px;
  font-size: 11px;
}
.mask-tools button.on {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.filebox { display: flex; align-items: center; gap: 8px; margin: 6px 0 3px; }
.filebox input[type=file] { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.fbtn { display: inline-block; padding: 7px 12px; border: 1px solid var(--line); border-radius: 7px; background: #fff; color: var(--ink); font-size: 12px; font-weight: 600; line-height: 1.2; cursor: pointer; white-space: nowrap; }
.fbtn:hover { border-color: var(--brand); color: var(--brand); }
.filebox input[type=file]:focus-visible + .fbtn { outline: 2px solid var(--brand); outline-offset: 2px; }
.fname { font-size: 11.5px; color: var(--ink3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 168px; }
.fname.has { color: var(--ink2); font-weight: 500; }

/* ---- responsive mobile / narrow tablet layout ---- */
@media (max-width: 860px) {
  .app { flex-direction: column-reverse; height: auto; min-height: 100vh; overflow: visible; }
  aside { width: 100%; min-width: 0; border-right: none; border-top: 1px solid var(--line); overflow-y: visible; }
  main { position: sticky; top: 0; z-index: 10; height: 48vh; min-height: 300px; border-bottom: 1px solid var(--line); }
  .plan { height: 130px; }
}
