:root {
  --bg: #eceae6;
  --panel: #ffffff;
  --ink: #1d2124;
  --muted: #6b7378;
  --line: #dcd8d2;
  --accent: #136f73;
  --accent-ink: #ffffff;
  --accent-soft: #e2f1f1;
  --amber: #d98a12;
  --red: #d2232a;
  --blue: #2f7fd1;
  --work: #3a3f45;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  font-size: 13px;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); }
body { display: flex; flex-direction: column; }
/* iPad: a hand on the screen mustn't zoom, bounce or select the page */
html, body { overscroll-behavior: none; touch-action: manipulation; }
.topbar, .toolbar, .optbar, .canvas-wrap, .status, .tabs { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.canvas-wrap { touch-action: none; }
button { font: inherit; cursor: pointer; }
input, select { font: inherit; }
.hidden { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  flex: none; min-height: 56px; display: flex; align-items: center; gap: 16px; padding: 0 14px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; min-width: 230px; }
.logo { height: 46px; width: auto; object-fit: contain; object-position: top; clip-path: inset(0 0 22% 0); margin-bottom: -10px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name { font-weight: 700; font-size: 15px; letter-spacing: 0.2px; }
.doc-name { color: var(--muted); font-size: 12px; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu { display: flex; align-items: center; gap: 4px; flex: 1; }
.menu button { white-space: nowrap; }
.menu button, .optbar button, .side button.btn {
  border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 6px 11px; color: var(--ink);
}
.menu button:hover, .optbar button:hover, .side button.btn:hover { background: #f5f3ef; }
button.primary, .menu button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.primary:hover, .menu button.primary:hover { background: #0f5d61; }
.sep { width: 1px; height: 24px; background: var(--line); margin: 0 6px; }
.right-controls { display: flex; gap: 10px; margin-left: auto; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; background: #fff; }
.seg button { border: 0; background: transparent; padding: 6px 11px; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent); color: #fff; }

/* ---------- layout ---------- */
.main { display: flex; flex: 1; min-height: 0; position: relative; }
.toolbar {
  width: 52px; background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: center; padding: 6px 0; gap: 2px; overflow-y: auto;
}
.toolbar .tgap { height: 8px; flex: none; }
.tool {
  width: 40px; height: 36px; flex: none; border: 0; border-radius: 7px; background: transparent; color: var(--ink);
  display: flex; align-items: center; justify-content: center; position: relative;
}
.tool svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tool:hover { background: #f1efeb; }
.tool.on { background: var(--accent); color: #fff; }

.work { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.optbar {
  height: 42px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 12px;
  background: #f8f7f4; border-bottom: 1px solid var(--line);
}
.opt-tool, .opt-toggles { display: flex; align-items: center; gap: 10px; white-space: nowrap; overflow: hidden; }
.opt-tool { flex: 1; min-width: 0; }
.opt-toggles { flex: none; }
.opt-tool .help { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.opt-tool label, .opt-toggles label { display: flex; align-items: center; gap: 4px; color: var(--muted); }
.opt-mirror.on { color: #c2185b; font-weight: 600; }
.opt-mirror select { font: inherit; font-weight: normal; }
.opt-tool input[type=number] { width: 60px; }
.opt-tool select, .opt-tool input { padding: 3px 5px; border: 1px solid var(--line); border-radius: 5px; background: #fff; }
.opt-tool .title { font-weight: 600; color: var(--ink); }
.opt-tool .help { color: var(--muted); font-size: 12px; }
.canvas-wrap { flex: 1; position: relative; background: var(--work); overflow: hidden;
  background-image: radial-gradient(rgba(255,255,255,0.06) 1px, transparent 1px); background-size: 18px 18px; }
#canvas { position: absolute; inset: 0; touch-action: none; }
.tip {
  position: absolute; pointer-events: none; max-width: 340px; background: rgba(20,22,25,0.92); color: #fff;
  padding: 7px 10px; border-radius: 6px; font-size: 12px; display: none; line-height: 1.35;
}
.tip.has-fix { pointer-events: auto; }
.tip-fixes { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 7px; }
.tip-fixes button, .fix-row button { border: 0; border-radius: 5px; padding: 4px 10px; font-size: 12px; background: var(--accent); color: #fff; cursor: pointer; }
.tip-fixes button:hover, .fix-row button:hover { filter: brightness(1.15); }
.fix-row { display: flex; flex-wrap: wrap; gap: 6px; margin: -2px 0 8px 34px; }
.measure { position: absolute; left: 12px; bottom: 10px; background: rgba(0,0,0,0.6); color: #fff; padding: 3px 8px; border-radius: 5px; font-size: 12px; display: none; }
.busy { position: absolute; right: 12px; top: 10px; background: rgba(0,0,0,0.6); color: #fff; padding: 3px 9px; border-radius: 5px; font-size: 12px; display: none; }
.status { height: 26px; display: flex; align-items: center; gap: 18px; padding: 0 12px; background: var(--panel); border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; }
.status .hint { margin-left: auto; overflow: hidden; text-overflow: ellipsis; }

/* ---------- side panel ---------- */
.side { width: 330px; background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column; }
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; border: 0; background: transparent; padding: 10px 4px; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs button.on { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
.tabs b { background: var(--red); color: #fff; border-radius: 9px; padding: 0 6px; font-size: 11px; font-weight: 600; }
.tabs b:empty { display: none; }
.tab-body { flex: 1; overflow-y: auto; padding: 12px 14px 30px; }
.sect { margin-bottom: 16px; }
.sect h3 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.8px; color: var(--muted); margin: 0 0 8px; font-weight: 600; }
.row { display: flex; align-items: center; gap: 8px; margin-bottom: 7px; }
.row > label { flex: 0 0 112px; color: var(--muted); }
.row > .ctl { flex: 1; display: flex; gap: 6px; align-items: center; min-width: 0; }
.row input[type=text], .row input[type=number], .row select {
  width: 100%; padding: 5px 7px; border: 1px solid var(--line); border-radius: 5px; background: #fff; min-width: 0;
}
.row input[type=color] { width: 40px; height: 28px; border: 1px solid var(--line); border-radius: 5px; padding: 1px; background: #fff; }
.row .unit { color: var(--muted); font-size: 12px; }
.note { color: var(--muted); font-size: 12px; line-height: 1.4; margin: 4px 0 8px; }
.calc { background: #f6f5f2; border-radius: 6px; padding: 7px 9px; font-size: 12px; line-height: 1.55; color: #444; }
.btns { display: flex; flex-wrap: wrap; gap: 6px; }
.side button.btn { padding: 5px 9px; font-size: 12px; }
.side button.btn.danger { color: var(--red); }

/* glass library */
.swatches { display: grid; grid-template-columns: repeat(6, 1fr); gap: 5px; }
.sw { aspect-ratio: 1; border-radius: 6px; border: 2px solid transparent; cursor: pointer; position: relative; box-shadow: inset 0 0 0 1px rgba(0,0,0,0.15); }
.sw.on { border-color: var(--accent); box-shadow: 0 0 0 2px #fff inset, inset 0 0 0 3px rgba(0,0,0,0.1); }
.sw .tag { position: absolute; right: 2px; bottom: 1px; font-size: 9px; font-weight: 700; color: #fff; text-shadow: 0 0 2px #000; }
.cur-glass { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; }
.cur-glass canvas { width: 64px; height: 64px; border-radius: 8px; box-shadow: inset 0 0 0 1px rgba(0,0,0,0.15); flex: none; }
.cur-glass .nm { font-weight: 600; font-size: 14px; }

/* checks */
.check { display: flex; gap: 8px; padding: 8px; border-radius: 6px; cursor: pointer; margin-bottom: 4px; line-height: 1.4; }
.check:hover { background: #f4f2ee; }
.check .dot { flex: none; width: 18px; height: 18px; border-radius: 50%; color: #fff; font-weight: 700; font-size: 11px; display: flex; align-items: center; justify-content: center; margin-top: 1px; }
.ok { padding: 12px; background: #e9f6ee; border-radius: 6px; color: #1d6b3a; }

/* bom */
table.bom { width: 100%; border-collapse: collapse; font-size: 12px; }
table.bom th { text-align: left; color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--line); padding: 4px 3px; }
table.bom td { border-bottom: 1px solid #f0eeea; padding: 5px 3px; vertical-align: top; }
.chip { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -2px; margin-right: 5px; box-shadow: inset 0 0 0 1px rgba(0,0,0,0.2); }

/* ---------- dialogs ---------- */
.modal { position: fixed; inset: 0; background: rgba(20,22,25,0.45); display: flex; align-items: center; justify-content: center; z-index: 10; }
.dialog { background: #fff; border-radius: 12px; box-shadow: 0 20px 60px rgba(0,0,0,0.35); width: min(980px, 94vw); max-height: 92vh; display: flex; flex-direction: column; }
.dialog.small { width: min(520px, 94vw); }
.dlg-head { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; }
.dlg-head h2 { margin: 0; font-size: 16px; }
.dlg-head .x { border: 0; background: transparent; font-size: 20px; color: var(--muted); }
.dlg-body { padding: 16px 18px; overflow-y: auto; display: flex; gap: 18px; }
.dlg-body .col { flex: 1; min-width: 0; }
.dlg-body .col.opts { flex: 0 0 300px; }
.dlg-foot { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.dlg-foot button { border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 7px 14px; }
.dlg-foot button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.preview { width: 100%; aspect-ratio: 4 / 3; background: #f3f1ec; border-radius: 8px; display: flex; align-items: center; justify-content: center; overflow: hidden; position: relative; }
.preview canvas { max-width: 100%; max-height: 100%; }
.preview .cap { position: absolute; left: 8px; top: 6px; font-size: 11px; color: var(--muted); background: rgba(255,255,255,0.8); padding: 1px 6px; border-radius: 4px; }
.prevs { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.radio-cards { display: grid; gap: 6px; }
.radio-cards label { display: flex; gap: 8px; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; cursor: pointer; line-height: 1.35; }
.radio-cards label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.radio-cards small { color: var(--muted); display: block; }
input[type=range] { width: 100%; accent-color: var(--accent); }
input[type=checkbox], input[type=radio] { accent-color: var(--accent); }

/* ---------- 3D projects ---------- */
.facebar { display: flex; align-items: center; gap: 6px; padding: 6px 12px; background: #f1efe9; border-bottom: 1px solid var(--line); overflow-x: auto; white-space: nowrap; flex: none; }
.facebar .fb-title { font-weight: 600; color: var(--muted); font-size: 12px; margin-right: 4px; }
.facebar .fb-gap { flex: 1; }
.facebar button { border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 4px 10px; color: var(--ink); font-size: 12px; }
.facebar button b { color: var(--accent); margin-right: 2px; }
.facebar button .qty { color: var(--muted); margin-left: 2px; }
.facebar button.on { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.facebar button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.dialog.wide { width: min(1240px, 96vw); }
.dialog button.btn { border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 5px 9px; font-size: 12px; }
.dialog button.btn:hover { background: #f5f3ef; }
canvas.view3d { display: block; width: 100%; height: 400px; border-radius: 8px; cursor: grab; touch-action: none; }
canvas.view3d.big { height: min(68vh, 640px); }
.subhead { font-weight: 600; font-size: 12px; margin: 10px 0 6px; color: var(--ink); }
.dlg-err { color: var(--red); margin-right: auto; align-self: center; font-size: 12px; }
table.notes3d { margin-top: 10px; }
table.notes3d td { line-height: 1.45; }
table.notes3d tr.pick { cursor: pointer; }
table.notes3d tr.pick:hover td { background: var(--accent-soft); }

/* ---------- colour wheel ---------- */
.cwheel { user-select: none; }
.cw-main { display: flex; gap: 12px; align-items: flex-start; }
.cw-disc { flex: none; cursor: crosshair; touch-action: none; border-radius: 50%; }
.cw-side { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.cw-now { height: 44px; border-radius: 8px; box-shadow: inset 0 0 0 1px rgba(0,0,0,0.18); }
.cw-hex { width: 100%; padding: 5px 7px; border: 1px solid var(--line); border-radius: 5px; font-family: ui-monospace, Consolas, monospace; text-transform: lowercase; }
.cw-cap { font-size: 11px; color: var(--muted); margin-top: 4px; }
.cw-harm { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
.cw-sw { aspect-ratio: 1; border: 0; border-radius: 5px; box-shadow: inset 0 0 0 1px rgba(0,0,0,0.18); padding: 0; }
.cw-sw:hover { box-shadow: inset 0 0 0 2px var(--ink); }
.cw-val { -webkit-appearance: none; appearance: none; width: 100%; height: 12px; border-radius: 6px; margin: 12px 0 6px; box-shadow: inset 0 0 0 1px rgba(0,0,0,0.15); }
.cw-val::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%; background: #fff; border: 2px solid #333; cursor: pointer; }
.cw-val::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 2px solid #333; cursor: pointer; }
.cw-nearbtn { width: 100%; text-align: left; border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 5px 8px; font-size: 12px; color: var(--ink); }
.cw-nearbtn:hover { background: #f5f3ef; }
.opt-tool .see-through { gap: 6px; }
.opt-tool input.glass-op { width: 90px; padding: 0; border: 0; background: none; }
.ring-split { display: flex; align-items: center; gap: 6px; margin: -2px 0 8px 34px; font-size: 12px; color: var(--muted); }
.ring-split input { width: 52px; padding: 4px 6px; border: 1px solid var(--line); border-radius: 5px; }
.side .ring-split button.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
#tab-project .ring-split { margin-left: 0; }

/* ---------- text tool ---------- */
.tx-text { width: 100%; font: 16px/1.3 inherit; padding: 8px; border: 1px solid var(--line); border-radius: 6px; resize: vertical; margin-bottom: 8px; }
.tx-font { font-size: 14px; }
.tx-style { display: flex; gap: 4px; }
.tx-style button { width: 32px; height: 28px; border: 1px solid var(--line); background: #fff; border-radius: 5px; }
.tx-style button.on { background: var(--accent); color: #fff; border-color: var(--accent); }
canvas.tx-prev { display: block; width: 100%; height: 320px; border-radius: 8px; box-shadow: inset 0 0 0 1px var(--line); }

/* ---------- tablets and phones ---------- */
.side-toggle { border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 5px 10px; font-size: 16px; }
body.side-collapsed .side-toggle { background: var(--accent-soft); border-color: var(--accent); }
.tabs .side-close { flex: none; padding: 10px 10px; font-size: 16px; color: var(--muted); }
/* the side panel can be hidden to give the drawing the whole width */
body.side-collapsed .side { display: none; }

/* tablets (iPad landscape and smaller laptops): the menu gets its own row so nothing is squeezed */
@media (max-width: 1400px) {
  .topbar { flex-wrap: wrap; row-gap: 6px; padding: 6px 14px; }
  .menu { order: 3; flex: 1 0 100%; flex-wrap: wrap; row-gap: 6px; }
  .menu button { padding: 7px 12px; }
}
@media (max-width: 900px) {
  .brand { min-width: 0; }
  .brand-text { display: none; }
  .menu .sep { display: none; }
  .menu button { padding: 7px 9px; }
  .topbar { gap: 8px; }
  .side { position: absolute; top: 0; right: 0; bottom: 0; z-index: 8; width: min(340px, 92vw);
    transform: translateX(100%); transition: transform 0.2s ease; box-shadow: -8px 0 30px rgba(0,0,0,0.2); }
  body.side-open .side { transform: none; }
  body.side-collapsed .side { display: flex; }
  .status .hint { display: none; }
  .dlg-body { flex-direction: column; }
  .dlg-body .col.opts { flex: none; }
}
@media (max-width: 600px) {
  .opt-toggles label { display: none; }
  .opt-toggles label.opt-mirror { display: flex; }
  .seg#viewMode button { padding: 4px 6px; font-size: 12px; }
  .toolbar { width: 44px; }
}

/* report a problem / idea */
.dialog.report { width: min(880px, 96vw); }
.rp-body .col { display: flex; flex-direction: column; gap: 10px; }
.rp-body textarea { width: 100%; box-sizing: border-box; font: inherit; padding: 8px; border: 1px solid var(--line); border-radius: 6px; resize: vertical; }
.rp-kinds { align-self: flex-start; }
.rp-kinds button { border: 0; background: transparent; padding: 6px 12px; }
.rp-check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.rp-shotcol img { width: 100%; max-height: 300px; object-fit: contain; border: 1px solid var(--line); border-radius: 6px; background: #f4f4f4; }
.rp-shotcol .btns { align-items: center; }

/* pattern library */
.dialog.patterns { width: min(1180px, 96vw); height: min(780px, 92vh); }
.dlg-body.pat { overflow: hidden; flex: 1; min-height: 0; }
.pat-list { display: flex; flex-direction: column; min-height: 0; }
.pat-search { font: inherit; padding: 7px 10px; border: 1px solid var(--line); border-radius: 6px; }
.pat-cats { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.pat-cats button { border: 1px solid var(--line); background: #fff; border-radius: 14px; padding: 4px 11px; font-size: 12px; cursor: pointer; }
.pat-cats button span { color: var(--muted); margin-left: 2px; }
.pat-cats button.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.pat-cats button.on span { color: rgba(255,255,255,0.8); }
.pat-grid { flex: 1; min-height: 0; overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; align-content: start; padding: 2px; }
.pat-card { border: 1px solid var(--line); border-radius: 8px; background: #fff; padding: 6px; text-align: left; cursor: pointer; display: flex; flex-direction: column; gap: 3px; font: inherit; }
.pat-card:hover { border-color: #b9c4c6; }
.pat-card.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.pat-card img { width: 100%; aspect-ratio: 4 / 3; object-fit: contain; background: #f3f1ec; border-radius: 6px; }
.pat-card b { font-size: 12.5px; }
.pat-card small { color: var(--muted); font-size: 11px; }
.pat-detail { overflow-y: auto; }
.pat-detail .pat-name { margin: 0 0 8px; font-size: 15px; }
.pat-detail .preview { margin-bottom: 6px; }
.pat-detail .chk { display: flex; align-items: center; gap: 6px; margin: 4px 0 10px; font-size: 12px; }
.pat-detail .btns { margin-top: 6px; }
.pat-detail button.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.pat-detail button.btn.primary:hover { background: #0f5d61; }
@media (max-width: 900px) {
  .dialog.patterns { height: 94vh; }
  .dlg-body.pat { overflow-y: auto; }
  .pat-list, .pat-detail { flex: none !important; overflow: visible; }
  .pat-grid { flex: none; max-height: 46vh; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
  .dialog.patterns .dlg-foot { flex-wrap: wrap; }
  .dialog.patterns .dlg-foot > span { display: none; }
}

/* short message over the drawing (e.g. "Undo" after a two-finger double tap) */
.toast { position: absolute; left: 50%; top: 18px; transform: translateX(-50%); background: rgba(20,22,25,0.85); color: #fff;
  padding: 7px 16px; border-radius: 18px; font-size: 14px; pointer-events: none; opacity: 0; transition: opacity 0.2s ease; }
.toast.show { opacity: 1; }
