:root {
  --bg: #15171c; --panel: #1d2027; --panel2: #262a33; --line: #333844; --text: #e8eaf0; --muted: #98a0b0;
  --accent: #6c5cff; --accent2: #8f83ff; --ok: #2fbf71; --warn: #f2b134; --err: #ef5350;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 13px/1.4 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); display: flex; flex-direction: column; overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 5px 10px; cursor: pointer; }
button:hover { border-color: var(--accent2); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.ghost { background: transparent; }
button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
:focus-visible { outline: 2px solid var(--accent2); outline-offset: 1px; }
input, select, textarea { background: var(--bg); border: 1px solid var(--line); border-radius: 5px; padding: 4px 6px; min-width: 0; }
input[type=color] { padding: 0; width: 30px; height: 26px; cursor: pointer; }
input[type=range] { padding: 0; accent-color: var(--accent); }

#topbar { display: flex; align-items: center; gap: 10px; padding: 7px 12px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; font-size: 15px; display: flex; gap: 7px; align-items: center; }
.logo { width: 24px; height: 24px; border-radius: 6px; background: linear-gradient(135deg, var(--accent), #e0468f); display: grid; place-items: center; color: #fff; }
#docName { background: transparent; border-color: transparent; width: 200px; }
#docName:hover, #docName:focus { border-color: var(--line); }
.group { display: flex; gap: 3px; }
.seg button { border-radius: 0; }
.seg button:first-child { border-radius: 6px 0 0 6px; }
.seg button:last-child { border-radius: 0 6px 6px 0; }
.spacer { flex: 1; }

#workspace { flex: 1; display: flex; min-height: 0; }
#tools { width: 46px; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 4px; padding: 8px 6px; align-items: center; }
#tools button { width: 34px; height: 34px; padding: 0; font-size: 15px; }
#left, #right { background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
#left { width: 268px; border-right: 1px solid var(--line); }
#right { width: 272px; border-left: 1px solid var(--line); }
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; background: none; border: 0; border-bottom: 2px solid transparent; border-radius: 0; padding: 9px 4px; color: var(--muted); }
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); background: none; }
.panel { flex: 1; overflow: auto; padding: 10px; }
.panel h3 { font-size: 11px; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); margin: 14px 0 6px; }
.panel h3:first-child { margin-top: 2px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; }
.field { display: flex; flex-direction: column; gap: 2px; color: var(--muted); font-size: 11px; }
.field input, .field select { color: var(--text); font-size: 13px; width: 100%; }
.row { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; }
.row .grow { flex: 1; }
.card { display: block; width: 100%; text-align: left; background: var(--panel2); border: 1px solid var(--line); border-radius: 7px; padding: 7px 9px; margin-bottom: 5px; }
.card small { color: var(--muted); display: block; }
.card.on { border-color: var(--accent); }
.swatches { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.swatches button { width: 20px; height: 20px; padding: 0; border-radius: 4px; }
.note { color: var(--muted); font-size: 12px; margin: 6px 0; }
.empty { color: var(--muted); text-align: center; padding: 26px 8px; }
.tabs .pill { margin-left: 4px; }
.pill { background: var(--accent); color: #fff; border-radius: 9px; padding: 0 6px; font-size: 10px; font-weight: 700; }

.layer { display: flex; align-items: center; gap: 5px; padding: 4px 6px; border-radius: 5px; cursor: pointer; }
.layer:hover { background: var(--panel2); }
.layer.on { background: #3a3560; }
.layer .nm { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.layer button { padding: 0 4px; background: none; border: 0; color: var(--muted); }

.issue { display: block; width: 100%; text-align: left; background: var(--panel2); border: 0; border-left: 3px solid var(--muted); border-radius: 4px; padding: 6px 8px; margin-bottom: 5px; }
.issue.error { border-left-color: var(--err); }
.issue.warn { border-left-color: var(--warn); }
.preflight-ok { color: var(--ok); font-weight: 600; }

#stageWrap { flex: 1; position: relative; min-width: 0; background: #2a2d35; overflow: hidden; }
#stage { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; user-select: none; }
#stage.t-hand { cursor: grab; }
#stage.t-draw { cursor: crosshair; }
.ruler { position: absolute; z-index: 2; background: #1d2027; cursor: grab; }
.no-rulers .ruler { display: none; }
#rulerX { top: 0; left: 18px; right: 0; height: 18px; width: calc(100% - 18px); }
#rulerY { top: 18px; left: 0; bottom: 0; width: 18px; height: calc(100% - 18px); }
#textEdit { position: absolute; z-index: 3; background: #fff; color: #000; border: 1px solid var(--accent); padding: 0; resize: none; overflow: hidden; line-height: 1.2; white-space: pre; }
#status { position: absolute; left: 26px; bottom: 7px; color: var(--muted); font-size: 11px; pointer-events: none; }

dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 18px; width: min(560px, 94vw); max-height: 90vh; }
dialog.wide { width: min(980px, 96vw); }
dialog::backdrop { background: rgba(0, 0, 0, .55); }
dialog h2 { margin: 0 0 4px; font-size: 18px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.plans { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 10px; }
.plan { border: 1px solid var(--line); border-radius: 9px; padding: 11px; display: flex; flex-direction: column; }
.plan.on { border-color: var(--accent); }
.plan b { font-size: 15px; }
.plan .price { font-size: 19px; font-weight: 700; margin: 3px 0; }
.plan ul { padding-left: 16px; margin: 7px 0; flex: 1; color: var(--muted); }
.formats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 5px; margin: 8px 0; }
.formats button { padding: 7px 2px; font-weight: 600; }
.formats .pill { display: block; margin-top: 2px; }
.view3d { display: grid; grid-template-columns: 1fr 240px; gap: 12px; }
#view3dCanvas, model-viewer { width: 100%; height: 58vh; background: #eceef2; border-radius: 8px; display: block; }
.wide { width: 100%; }
.top8 { margin-top: 8px; }
.search { width: 100%; margin-bottom: 8px; }
#left { width: 288px; }
.panel .card { margin-bottom: 0; padding: 6px 8px; font-size: 12px; min-width: 0; overflow: hidden; }
.panel .card small { font-size: 10px; }
.die-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; margin-top: 8px; }
.die { padding: 4px; display: flex; flex-direction: column; gap: 3px; align-items: stretch; min-width: 0; }
.die svg { width: 100%; height: 62px; background: #fff; border-radius: 3px; display: block; }
.die span { font-size: 10px; line-height: 1.2; height: 24px; overflow: hidden; color: var(--muted); }
.die.on { border-color: var(--accent); background: #3a3560; }
.die-form { background: var(--panel2); border: 1px solid var(--accent); border-radius: 8px; padding: 9px; margin: 8px 0; display: flex; flex-direction: column; gap: 8px; }
.die-form .row { margin: 0; }
.slide { display: grid; grid-template-columns: 92px 1fr; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
details { border-top: 1px solid var(--line); padding: 5px 0; }
summary { cursor: pointer; padding: 2px 0; margin-bottom: 4px; }
.callout { background: #2b2850; border: 1px solid #4b44a0; border-radius: 7px; padding: 8px 10px; margin: 10px 0; font-size: 12px; }
.warn { color: var(--warn); font-size: 12px; margin: 6px 0; }
.checks { display: flex; flex-direction: column; gap: 4px; margin: 10px 0; }
.check { display: flex; gap: 7px; align-items: center; }
.check input { width: auto; }
body:not(.expert) .x-only { display: none; }
#toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: #000; color: #fff; padding: 8px 14px; border-radius: 7px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 99; max-width: 80vw; }
#toast.show { opacity: 1; }
.phone-share { margin-top: 12px; }
.qr { width: 220px; margin: 8px auto; background: #fff; border-radius: 8px; overflow: hidden; }
.qr svg { display: block; width: 100%; height: auto; }
.phone-share a { display: block; word-break: break-all; }
.template-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.template { padding: 4px; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.template svg { display: block; width: 100%; height: 118px; background: var(--panel); border-radius: 3px; }
.template span { font-size: 10px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.palette { margin-top: 8px; }
.palette small { color: var(--muted); }
.palette .row { margin: 0; }
.palette .row button { font-size: 11px; padding: 3px 7px; }
.palette .swatches button { width: 26px; height: 22px; }
.row input[type=color] { flex: none; width: 34px; height: 30px; padding: 0; }
.tabs button { font-size: 11.5px; padding-left: 1px; padding-right: 1px; min-width: 0; white-space: nowrap; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
.chips button { padding: 4px 9px; font-size: 11px; border-radius: 999px; }
.chips button.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.elem-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
.elem { padding: 6px; min-width: 0; background: #f4f5f8; }
.elem svg { display: block; width: 100%; height: 62px; }
.icon-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
.icon-grid button { padding: 7px; min-width: 0; }
.icon-grid svg { display: block; width: 100%; height: auto; }
.photo-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; margin-top: 8px; }
.photo-grid button { padding: 0; overflow: hidden; height: 92px; min-width: 0; }
.photo-grid img { display: block; width: 100%; height: 100%; object-fit: cover; }
.chart-form { display: grid; grid-template-columns: 280px 1fr; gap: 14px; align-items: start; }
.chart-preview svg { display: block; width: 100%; border-radius: 6px; }
.mock-big { display: block; width: 100%; max-height: 58vh; object-fit: contain; border-radius: 6px; background: var(--panel2); }
.mock-list { display: grid; grid-template-columns: repeat(5, 1fr); gap: 5px; margin-top: 8px; }
.die-layer { border-left: 3px solid #ff0a54; }
#boards { position: absolute; left: 50%; bottom: 8px; transform: translateX(-50%); display: flex; gap: 4px; padding: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; z-index: 2; }
#boards button { padding: 3px 9px; font-size: 11px; min-width: 26px; }
#boards button.on { background: var(--accent); color: #fff; border-color: var(--accent); }
#left { width: 330px; }
#leftTabs button { flex: 1 1 auto; font-size: 11px; padding-left: 2px; padding-right: 2px; }
#rulerBtn.on { color: var(--text); border-color: var(--accent); }
#status { left: 28px; }
.template img { display: block; width: 100%; height: 118px; object-fit: contain; background: #eceef2; border-radius: 3px; }
.layer-head { gap: 2px; background: var(--panel2); font-weight: 600; margin-top: 4px; }
.layer-head.active { box-shadow: inset 2px 0 0 var(--accent); }
.layer-head button { padding: 1px 4px; min-width: 0; font-size: 11px; }
.layer-name { flex: 1; min-width: 0; background: none; border: 0; color: inherit; font: inherit; padding: 2px; }
.layer-head small { color: var(--muted); padding: 0 3px; }
.layer:not(.layer-head) { margin-left: 12px; }
.die-layer { margin-left: 0 !important; }
.font-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
.font-card { padding: 7px 5px; min-width: 0; display: flex; flex-direction: column; gap: 2px; align-items: center; }
.font-card b { font-size: 21px; font-weight: 400; line-height: 1.5; white-space: nowrap; overflow: hidden; max-width: 100%; }
.font-card small { font-size: 9.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.font-card.on { border-color: var(--accent); }
.style-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
.style-card { padding: 7px; background: #f4f5f8; min-width: 0; }
.style-card svg { display: block; width: 100%; height: 66px; }
.brand-kit { border: 1px solid var(--line); border-radius: 8px; padding: 8px; margin-bottom: 8px; }
.brand-logo { max-width: 100%; max-height: 60px; display: block; margin-top: 6px; background: #fff; border-radius: 4px; }
