@font-face { font-family: "Fredoka"; src: url("../fonts/fredoka-600.woff2") format("woff2"); font-weight: 500 700; font-display: swap; }
@font-face { font-family: "Nunito"; src: url("../fonts/nunito-700.woff2") format("woff2"); font-weight: 400 800; font-display: swap; }

:root, :root[data-theme="dark"] {
  --bg: #11131d; --bg2: #171a28; --panel: #1e2133; --panel2: #282c43; --line: #363c5c; --text: #f4f5fc; --muted: #a9aecb;
  --primary: #7c5cff; --primary2: #a08aff; --pink: #ff5fc8; --yellow: #ffc531; --teal: #16c7a6; --danger: #ff4d6d;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35); --glass: rgba(24, 27, 42, .78);
  --cx: #ff6b81; --cy: #3ddc84; --cz: #4ea3ff;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #e9edf7; --bg2: #dfe4f2; --panel: #ffffff; --panel2: #f1f3fa; --line: #d9deec; --text: #1b1e2e; --muted: #5d6482;
  --primary: #6b48ff; --primary2: #8a6dff; --shadow: 0 10px 30px rgba(40, 50, 90, .14); --glass: rgba(255, 255, 255, .82);
  --cx: #e8364f; --cy: #12a35a; --cz: #1f74e0;
  color-scheme: light;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text);
  font: 600 14px/1.3 "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overscroll-behavior: none; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
button:disabled { opacity: .4; cursor: default; }
:focus-visible { outline: 3px solid var(--yellow); outline-offset: 2px; }
.ic { width: 22px; height: 22px; flex: none; }

#app { position: fixed; inset: 0; display: grid; gap: 8px; padding: 8px;
  grid-template-columns: 92px minmax(0, 1fr) 316px; grid-template-rows: 60px minmax(0, 1fr);
  grid-template-areas: "top top top" "tools view panel"; }

/* ---------------- top bar */
#top { grid-area: top; display: flex; align-items: center; gap: 8px; padding: 0 8px 0 10px; background: var(--panel);
  border-radius: 18px; box-shadow: var(--shadow); min-width: 0; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; margin-right: 8px; flex: none; }
.logo { width: 40px; height: 40px; }
.bt { display: flex; flex-direction: column; line-height: 1; font-family: "Fredoka", sans-serif; }
.bt small { font-size: 12px; color: var(--muted); letter-spacing: .08em; text-transform: uppercase; }
.bt b { font-size: 21px; font-weight: 700; white-space: nowrap; }
.bt i { font-style: normal; background: linear-gradient(90deg, var(--pink), var(--yellow)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.tgroup { display: flex; align-items: center; gap: 6px; }
.tspace { flex: 1; }
.b { display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 42px; padding: 0 14px; border-radius: 13px;
  background: var(--panel2); font-family: "Fredoka", sans-serif; font-weight: 600; font-size: 15px; white-space: nowrap; transition: transform .08s, background .15s; }
.b:active:not(:disabled) { transform: scale(.96); }
.b:hover:not(:disabled) { background: color-mix(in srgb, var(--panel2) 70%, var(--primary)); }
.b.ghost { background: transparent; }
.b.ghost:hover:not(:disabled) { background: var(--panel2); }
.b.iconly { width: 42px; padding: 0; }
.b.iconly .lbl { display: none; }
.b.on { color: var(--yellow); }
.b.primary { background: linear-gradient(135deg, var(--primary), var(--pink)); color: #fff; box-shadow: 0 4px 14px rgba(124, 92, 255, .35); }
.b.primary:hover:not(:disabled) { background: linear-gradient(135deg, var(--primary2), var(--pink)); }
.b.exit { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); border: 2px solid color-mix(in srgb, var(--danger) 55%, transparent); }
.b.exit:hover { background: var(--danger) !important; color: #fff; }
.b.small { height: 34px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.b.big { height: 50px; font-size: 16px; border-radius: 14px; }
.b.full { width: 100%; }
.b.danger { color: var(--danger); }
.langb .lbl { font-size: 13px; }
.phone-only { display: none !important; }

/* ---------------- toolbar */
#tools { grid-area: tools; display: flex; flex-direction: column; gap: 6px; padding: 8px; background: var(--panel); border-radius: 18px;
  box-shadow: var(--shadow); overflow-y: auto; scrollbar-width: none; }
#tools::-webkit-scrollbar { display: none; }
.tool { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; min-height: 68px; padding: 8px 4px; border-radius: 14px;
  font-size: 12px; line-height: 1.1; text-align: center; color: var(--text); transition: background .15s, transform .08s; }
.tool .ic { width: 30px; height: 30px; }
.tool:hover { background: var(--panel2); }
.tool:active { transform: scale(.95); }
.tool.on { background: linear-gradient(135deg, var(--primary), #a35cff); color: #fff; box-shadow: 0 4px 14px rgba(124, 92, 255, .4); }
.t-shapes .ic { color: #22b8f0; } .t-draw .ic { color: #ffc531; } .t-push .ic { color: #3ddc84; } .t-revolve .ic { color: #16c7a6; }
.t-edit .ic { color: #3d7bff; } .t-move .ic { color: #ff5fc8; } .t-select .ic { color: var(--text); }
.t-measure .ic { color: #ff8a3d; } .t-combine .ic { color: #ff5fc8; } .t-templates .ic { color: #ffc531; } .t-library .ic { color: #ff4d6d; }
.t-library:not(.on) { background: color-mix(in srgb, #ff4d6d 9%, transparent); }
.tool.on .ic { color: #fff; }

/* ---------------- 3D view */
#view { grid-area: view; position: relative; border-radius: 18px; overflow: hidden; box-shadow: var(--shadow); background: var(--bg2); min-height: 0; touch-action: none; }
#gl { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }
#labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.dim { position: absolute; left: 0; top: 0; padding: 3px 8px; border-radius: 999px; background: var(--yellow); color: #1b1e2e; font: 700 12px "Nunito", sans-serif;
  white-space: nowrap; box-shadow: 0 2px 8px rgba(0, 0, 0, .25); }
.dim[data-ax="x"] { border: 2px solid var(--cx); } .dim[data-ax="y"] { border: 2px solid var(--cy); } .dim[data-ax="z"] { border: 2px solid var(--cz); }
.dim.ruler { background: #fff; font-size: 14px; border: 2px solid var(--yellow); }
#viewbtns { position: absolute; top: 10px; right: 10px; display: flex; flex-direction: column; gap: 6px; z-index: 2; }
.vb { display: flex; flex-direction: column; align-items: center; gap: 2px; width: 56px; padding: 7px 2px 5px; border-radius: 13px; background: var(--glass);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); font-size: 11px; box-shadow: 0 2px 10px rgba(0, 0, 0, .15); }
.vb:hover { color: var(--yellow); }
#status { position: absolute; left: 10px; right: 76px; bottom: 10px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; z-index: 2; pointer-events: none; }
#status > * { pointer-events: auto; }
#hint { padding: 9px 14px; border-radius: 13px; background: var(--glass); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); font-size: 13.5px; max-width: 100%;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .15); flex: 0 1 auto; }
#live { padding: 8px 12px; border-radius: 12px; background: var(--yellow); color: #1b1e2e; font-weight: 800; }
#vcb { display: flex; align-items: center; gap: 6px; padding: 5px 5px 5px 12px; border-radius: 13px; background: var(--glass); backdrop-filter: blur(8px); box-shadow: 0 2px 10px rgba(0, 0, 0, .15); }
#vcb[hidden], #finish[hidden], #live[hidden] { display: none; }
#vcb label { font-size: 12.5px; color: var(--muted); }
#vcbIn { width: 92px; height: 34px; border-radius: 9px; border: 2px solid var(--primary); background: var(--panel); text-align: center; font-weight: 800; font-size: 15px; }
.chip { display: inline-flex; align-items: center; gap: 5px; height: 36px; padding: 0 12px; border-radius: 12px; background: var(--glass); backdrop-filter: blur(8px); font-size: 13px; margin-left: auto; box-shadow: 0 2px 10px rgba(0, 0, 0, .15); }
.chip .ic { width: 18px; height: 18px; color: var(--danger); }
.chip.off .ic { color: var(--muted); }
#tip { position: absolute; left: 0; top: 0; z-index: 3; pointer-events: none; padding: 4px 10px; border-radius: 10px; background: var(--panel); color: var(--text);
  font: 800 13px "Nunito", sans-serif; white-space: nowrap; border: 2px solid var(--primary); box-shadow: 0 3px 12px rgba(0, 0, 0, .18); }
#tip[hidden], #marq[hidden], #dragH[hidden] { display: none; }
#marq { position: absolute; z-index: 3; pointer-events: none; border: 1.5px dashed #1a73ff; background: rgba(26, 115, 255, .08); border-radius: 3px; }
#dragH { position: absolute; left: 0; top: 0; z-index: 3; width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; touch-action: none;
  background: #1a73ff; color: #fff; box-shadow: 0 0 0 4px rgba(255, 255, 255, .85), 0 6px 18px rgba(26, 115, 255, .5); }
#dragH svg { width: 28px; height: 28px; }
#dragH.on { transform-origin: center; filter: brightness(1.15); }
.axc { display: inline-flex; gap: 3px; }
.axc[hidden] { display: none; }
.axc button { width: 30px; height: 30px; border-radius: 8px; font-weight: 800; font-size: 13px; background: var(--panel2); border: 2px solid transparent; }
.axc .ax-x { color: var(--cx); } .axc .ax-y { color: var(--cy); } .axc .ax-z { color: var(--cz); }
.axc button.on { background: currentColor; } .axc button.on { color: #fff; }
.axc .ax-x.on { background: var(--cx); } .axc .ax-y.on { background: var(--cy); } .axc .ax-z.on { background: var(--cz); }
.editb { background: color-mix(in srgb, #3d7bff 14%, var(--panel2)); color: var(--text); }
.editb .ic { color: #3d7bff; }
#loading { position: absolute; inset: 0; display: grid; place-items: center; background: var(--bg2); z-index: 5; transition: opacity .3s; }
body.ready #tip { position: absolute; left: 0; top: 0; z-index: 3; pointer-events: none; padding: 4px 10px; border-radius: 10px; background: var(--panel); color: var(--text);
  font: 800 13px "Nunito", sans-serif; white-space: nowrap; border: 2px solid var(--primary); box-shadow: 0 3px 12px rgba(0, 0, 0, .18); }
#tip[hidden], #marq[hidden], #dragH[hidden] { display: none; }
#marq { position: absolute; z-index: 3; pointer-events: none; border: 1.5px dashed #1a73ff; background: rgba(26, 115, 255, .08); border-radius: 3px; }
#dragH { position: absolute; left: 0; top: 0; z-index: 3; width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; touch-action: none;
  background: #1a73ff; color: #fff; box-shadow: 0 0 0 4px rgba(255, 255, 255, .85), 0 6px 18px rgba(26, 115, 255, .5); }
#dragH svg { width: 28px; height: 28px; }
#dragH.on { transform-origin: center; filter: brightness(1.15); }
.axc { display: inline-flex; gap: 3px; }
.axc[hidden] { display: none; }
.axc button { width: 30px; height: 30px; border-radius: 8px; font-weight: 800; font-size: 13px; background: var(--panel2); border: 2px solid transparent; }
.axc .ax-x { color: var(--cx); } .axc .ax-y { color: var(--cy); } .axc .ax-z { color: var(--cz); }
.axc button.on { background: currentColor; } .axc button.on { color: #fff; }
.axc .ax-x.on { background: var(--cx); } .axc .ax-y.on { background: var(--cy); } .axc .ax-z.on { background: var(--cz); }
.editb { background: color-mix(in srgb, #3d7bff 14%, var(--panel2)); color: var(--text); }
.editb .ic { color: #3d7bff; }
#loading { opacity: 0; pointer-events: none; }
.spin { width: 46px; height: 46px; border-radius: 50%; border: 5px solid var(--panel2); border-top-color: var(--primary); animation: sp 0.8s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }

/* ---------------- panel */
#panel { grid-area: panel; background: var(--panel); border-radius: 18px; box-shadow: var(--shadow); display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
#panel .grab { display: none; }
#panelBody { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.phead { display: flex; align-items: center; gap: 10px; padding: 14px 14px 10px; }
.phead .dot { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: var(--panel2); color: #fff; flex: none; box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .15); }
.phead .dot:not([style*="background"]) { color: var(--primary2); }
.phead .pt { display: flex; flex-direction: column; min-width: 0; }
.phead b { font: 700 18px "Fredoka", sans-serif; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.phead small { color: var(--muted); font-size: 12.5px; }
.phead .chev { display: none; margin-left: auto; }
.pscroll { overflow-y: auto; padding: 0 14px 14px; flex: 1; min-height: 0; }
section { padding: 10px 0; border-top: 1px solid var(--line); }
section:first-child { border-top: 0; }
h4 { margin: 0 0 8px; font: 600 13px "Fredoka", sans-serif; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; display: flex; align-items: center; gap: 8px; }
.seg { display: flex; gap: 4px; padding: 4px; background: var(--panel2); border-radius: 14px; margin-bottom: 4px; }
.seg button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 7px 2px; border-radius: 11px; font-size: 12px; }
.seg button.on { background: var(--primary); color: #fff; }
.seg.small button { flex-direction: row; justify-content: center; padding: 9px 8px; font-size: 13.5px; }
.sw { display: grid; grid-template-columns: repeat(7, 1fr); gap: 7px; }
.swc { aspect-ratio: 1; border-radius: 50%; box-shadow: inset 0 0 0 2px rgba(0, 0, 0, .12); position: relative; transition: transform .1s; }
.swc:hover { transform: scale(1.12); }
.swc.on { box-shadow: 0 0 0 3px var(--panel), 0 0 0 5px var(--text); }
.swc.custom { display: grid; place-items: center; background: conic-gradient(#ff4d6d, #ffc531, #3ddc84, #22b8f0, #7c5cff, #ff5fc8, #ff4d6d); cursor: pointer; overflow: hidden; }
.swc.custom input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; }
.swc.custom span { color: #fff; font-weight: 800; font-size: 16px; text-shadow: 0 1px 3px rgba(0, 0, 0, .5); pointer-events: none; }
.row3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 8px 0 12px; }
.row2 .b { flex-direction: column; height: auto; padding: 12px 6px; white-space: normal; text-align: center; }
.fld { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.fld span { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fld.cx span { color: var(--cx); } .fld.cy span { color: var(--cy); } .fld.cz span { color: var(--cz); }
.fld input { width: 100%; height: 40px; border-radius: 11px; border: 2px solid var(--line); background: var(--panel2); text-align: center; font-weight: 800; font-size: 15px; min-width: 0; }
.fld input:focus { border-color: var(--primary); outline: none; }
.fld.wide { margin: 6px 0; }
.fld.wide input { text-align: left; padding: 0 12px; }
.sel { display: flex; flex-direction: column; gap: 4px; margin: 8px 0; font-size: 12.5px; color: var(--muted); }
.sel select { height: 42px; border-radius: 11px; border: 2px solid var(--line); background: var(--panel2); padding: 0 10px; color: var(--text); font-weight: 700; }
.chk { display: flex; align-items: center; gap: 8px; margin: 10px 0 4px; cursor: pointer; font-size: 14px; }
.chk input { width: 20px; height: 20px; accent-color: var(--primary); }
.chk .ic { color: var(--primary2); }
.rng { display: flex; flex-direction: column; gap: 4px; margin: 6px 0; font-size: 12.5px; color: var(--muted); }
.rng b { color: var(--text); }
.rng input { width: 100%; accent-color: var(--primary); height: 26px; }
.lockb { margin-left: auto; display: inline-flex; align-items: center; gap: 4px; font: 600 11.5px "Nunito", sans-serif; text-transform: none; letter-spacing: 0; color: var(--muted); padding: 4px 8px; border-radius: 9px; background: var(--panel2); }
.lockb .ic { width: 16px; height: 16px; }
.lockb.on { color: var(--yellow); }
.acts { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.acts.three { grid-template-columns: repeat(3, 1fr); }
.b.act { flex-direction: column; height: auto; padding: 9px 2px; gap: 3px; font-size: 11.5px; white-space: normal; text-align: center; line-height: 1.1; }
.mirror { display: flex; align-items: center; gap: 6px; margin-top: 8px; }
.mirror > span { display: flex; align-items: center; gap: 6px; flex: 1; font-size: 13px; color: var(--muted); }
.mirror .b { width: 44px; }
.phelp { font-size: 12.5px; color: var(--muted); margin: 8px 0; font-weight: 600; }
.empty { font-size: 15px; margin: 4px 0 0; }

/* ---------------- popover, modal, toast, tour */
#pop { position: fixed; z-index: 50; display: none; background: var(--panel); border-radius: 18px; box-shadow: 0 16px 50px rgba(0, 0, 0, .45); padding: 10px; min-width: 220px;
  border: 1px solid var(--line); max-height: calc(100vh - 20px); overflow: auto; }
#pop.show { display: block; animation: pin .14s ease-out; }
@keyframes pin { from { opacity: 0; transform: translateY(6px) scale(.98); } }
.ptitle { display: flex; align-items: center; gap: 8px; font: 600 14px "Fredoka", sans-serif; color: var(--muted); padding: 4px 6px 8px; }
#pop hr { border: 0; border-top: 1px solid var(--line); margin: 6px 0; }
.mi { display: flex; align-items: center; gap: 12px; width: 100%; padding: 11px 12px; border-radius: 12px; text-align: left; font-size: 15px; }
.mi:hover { background: var(--panel2); }
.mi.sel { background: color-mix(in srgb, var(--primary) 22%, transparent); color: var(--text); }
.mi .ic { color: var(--primary2); }
.flag { display: inline-grid; place-items: center; width: 30px; height: 22px; border-radius: 6px; background: var(--panel2); font-size: 11px; font-weight: 800; }
.vol { display: flex; flex-direction: column; gap: 4px; padding: 8px 12px; font-size: 12.5px; color: var(--muted); }
.vol input { accent-color: var(--primary); }
.grid { display: grid; grid-template-columns: repeat(3, 92px); gap: 6px; }
.gi { display: flex; flex-direction: column; align-items: center; gap: 5px; padding: 12px 4px 10px; border-radius: 14px; font-size: 12.5px; background: var(--panel2); text-align: center; line-height: 1.1; }
.gi .ic { width: 34px; height: 34px; color: var(--primary2); }
.gi:hover:not(:disabled) { background: color-mix(in srgb, var(--panel2) 65%, var(--primary)); }
.gi.sel { outline: 2px solid var(--yellow); }
.s-box .ic { color: #3d7bff; } .s-cylinder .ic { color: #ff8a3d; } .s-sphere .ic { color: #ffc531; } .s-cone .ic { color: #3ddc84; } .s-pyramid .ic { color: #ff4d6d; }
.s-torus .ic { color: #b45cff; } .s-wedge .ic { color: #16c7a6; } .s-tube .ic { color: #22b8f0; } .s-text .ic { color: #ff5fc8; }
#pop.wide .phelp { max-width: 288px; }
#modal { position: fixed; inset: 0; z-index: 60; display: none; }
#modal.show { display: grid; place-items: center; }
.mback { position: absolute; inset: 0; background: rgba(8, 10, 22, .6); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
.mbox { position: relative; width: min(560px, calc(100vw - 20px)); max-height: calc(100vh - 20px); overflow: auto; background: var(--panel); border-radius: 22px; padding: 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .5); animation: pin .16s ease-out; }
.mbox h2 { margin: 0 0 14px; font: 700 22px "Fredoka", sans-serif; display: flex; align-items: center; gap: 10px; }
.mbox h2 .ic { width: 28px; height: 28px; color: var(--primary2); }
.mclose { position: absolute; top: 12px; right: 12px; }
.fmts { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; margin-bottom: 12px; }
.fmt { position: relative; display: flex; flex-direction: column; gap: 3px; padding: 12px; border-radius: 14px; background: var(--panel2); border: 2px solid transparent; cursor: pointer; }
.fmt input { position: absolute; opacity: 0; }
.fmt b { font: 700 20px "Fredoka", sans-serif; }
.fmt span { font-size: 12.5px; color: var(--muted); }
.fmt em { position: absolute; top: 10px; right: 10px; font-style: normal; font-size: 10.5px; background: var(--teal); color: #05241f; padding: 2px 7px; border-radius: 99px; font-weight: 800; }
.fmt.on { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 16%, var(--panel2)); }
.dlrow { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: end; margin-bottom: 12px; }
.dlrow .seg { margin: 0; }
.msg { white-space: pre-line; padding: 12px 14px; border-radius: 14px; background: var(--panel2); margin-bottom: 12px; font-size: 14px; }
.msg.good { background: color-mix(in srgb, var(--teal) 22%, var(--panel2)); }
.msg.warn { background: color-mix(in srgb, var(--yellow) 25%, var(--panel2)); }
.tpls { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 12px; }
.tpl { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 18px 6px 14px; border-radius: 18px; background: var(--panel2); font: 600 14px "Fredoka", sans-serif; text-align: center;
  border: 2px solid transparent; transition: transform .1s, border-color .15s; }
.tpl .ic { width: 46px; height: 46px; color: var(--c); }
.tpl:hover { border-color: var(--c); transform: translateY(-2px); }
.tpl.busy { opacity: .5; pointer-events: none; }
.helpl { list-style: none; padding: 0; margin: 0 0 12px; display: grid; gap: 10px; }
.helpl li { display: flex; gap: 12px; align-items: flex-start; }
.helpl .ic { width: 30px; height: 30px; color: var(--primary2); flex: none; margin-top: 2px; }
.helpl b { display: block; font: 600 15px "Fredoka", sans-serif; }
.helpl span { font-size: 13.5px; color: var(--muted); font-weight: 600; }
.keys { font-size: 13px; color: var(--muted); margin: 0 0 14px; }
.mbox h4 { margin-top: 6px; }
#toast { position: fixed; left: 50%; top: 78px; transform: translate(-50%, -20px); z-index: 70; background: var(--text); color: var(--bg); padding: 11px 18px; border-radius: 14px;
  font-weight: 700; opacity: 0; pointer-events: none; transition: .2s; max-width: calc(100vw - 24px); text-align: center; box-shadow: var(--shadow); }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#tour { position: fixed; inset: 0; z-index: 80; display: none; }
#tour.show { display: block; }
#tour .ring { position: absolute; border-radius: 16px; border: 3px solid var(--yellow); box-shadow: 0 0 0 9999px rgba(8, 10, 22, .62); transition: all .25s; pointer-events: none; }
#tour .ring.round { border-radius: 50%; }
#tour .bubble { position: absolute; background: var(--panel); border-radius: 18px; padding: 16px; box-shadow: 0 16px 50px rgba(0, 0, 0, .45); border: 2px solid var(--primary); }
#tour .bubble b { font: 700 19px "Fredoka", sans-serif; display: block; margin: 2px 0 6px; }
#tour .bubble p { margin: 0 0 12px; font-size: 14.5px; }
#tour .step { font-size: 12px; color: var(--muted); }
#tour .row { display: flex; justify-content: space-between; gap: 8px; }

/* ---------------- tablet */
@media (max-width: 1100px) and (min-width: 761px) {
  #app { grid-template-columns: 84px minmax(0, 1fr) 280px; }
  .bt small { display: none; }
  .b .lbl { display: none; }
  .b { padding: 0 10px; }
  .b.primary .lbl, .b.exit .lbl { display: inline; }
}

/* ---------------- phone */
@media (max-width: 760px) {
  #app { padding: 6px; gap: 6px; grid-template-columns: minmax(0, 1fr); grid-template-rows: 54px minmax(0, 1fr) 76px;
    grid-template-areas: "top" "view" "tools"; padding-bottom: max(6px, env(safe-area-inset-bottom)); }
  #top { padding: 0 6px; gap: 4px; border-radius: 16px; }
  .brand { margin-right: 0; gap: 6px; }
  .logo { width: 34px; height: 34px; }
  .bt small { display: none; }
  .bt b { font-size: 16px; }
  .wide-only { display: none !important; }
  .phone-only { display: inline-flex !important; }
  .b { height: 40px; padding: 0 10px; font-size: 14px; }
  .b.iconly { width: 38px; }
  .tgroup { gap: 2px; }
  #tools { flex-direction: row; padding: 6px; gap: 4px; overflow-x: auto; overflow-y: hidden; scroll-snap-type: x proximity; border-radius: 16px; }
  .tool { min-width: 70px; min-height: 0; padding: 5px 3px; font-size: 11px; scroll-snap-align: start; }
  .tool .ic { width: 26px; height: 26px; }
  #view { border-radius: 16px; }
  #viewbtns { top: 60px; right: 8px; gap: 5px; }
  .vb { width: 48px; padding: 6px 2px 4px; font-size: 10px; }
  .vb .ic { width: 20px; height: 20px; }
  #status { top: 8px; bottom: auto; left: 8px; right: 8px; }
  #hint { font-size: 12.5px; padding: 7px 11px; flex: 1 1 100%; }
  .chip { position: absolute; right: 0; top: auto; display: none; }
  #panel { position: fixed; left: 6px; right: 6px; bottom: calc(76px + 12px + env(safe-area-inset-bottom)); z-index: 20; max-height: 64px; border-radius: 18px;
    transition: max-height .25s ease; box-shadow: 0 -6px 30px rgba(0, 0, 0, .35); border: 1px solid var(--line); }
  #panel.open { max-height: min(62vh, 560px); }
  #panel .grab { display: block; width: 40px; height: 4px; border-radius: 4px; background: var(--line); margin: 6px auto 0; flex: none; }
  .phead { padding: 4px 12px 8px; cursor: pointer; }
  .phead .dot { width: 36px; height: 36px; }
  .phead .chev { display: block; color: var(--muted); transition: transform .2s; }
  #panel.open .phead .chev { transform: rotate(180deg); }
  .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  #pop { min-width: 0; }
  #pop.wide .phelp { max-width: none; }
  .tpls { grid-template-columns: repeat(2, 1fr); }
  .dlrow { grid-template-columns: 1fr; }
  #toast { top: 66px; }
  #view #labels .dim { font-size: 11px; }
}
@media (max-width: 520px) { .bt { display: none; } .b.primary, .b.exit { padding: 0 10px; gap: 5px; } }
@media (max-width: 340px) { .b.exit .lbl { display: none; } .b.exit { width: 40px; padding: 0; } }

/* ---------------- cover render mode */
body.cover #top, body.cover #tools, body.cover #panel, body.cover #status, body.cover #viewbtns, body.cover #labels, body.cover #tip { position: absolute; left: 0; top: 0; z-index: 3; pointer-events: none; padding: 4px 10px; border-radius: 10px; background: var(--panel); color: var(--text);
  font: 800 13px "Nunito", sans-serif; white-space: nowrap; border: 2px solid var(--primary); box-shadow: 0 3px 12px rgba(0, 0, 0, .18); }
#tip[hidden], #marq[hidden], #dragH[hidden] { display: none; }
#marq { position: absolute; z-index: 3; pointer-events: none; border: 1.5px dashed #1a73ff; background: rgba(26, 115, 255, .08); border-radius: 3px; }
#dragH { position: absolute; left: 0; top: 0; z-index: 3; width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; touch-action: none;
  background: #1a73ff; color: #fff; box-shadow: 0 0 0 4px rgba(255, 255, 255, .85), 0 6px 18px rgba(26, 115, 255, .5); }
#dragH svg { width: 28px; height: 28px; }
#dragH.on { transform-origin: center; filter: brightness(1.15); }
.axc { display: inline-flex; gap: 3px; }
.axc[hidden] { display: none; }
.axc button { width: 30px; height: 30px; border-radius: 8px; font-weight: 800; font-size: 13px; background: var(--panel2); border: 2px solid transparent; }
.axc .ax-x { color: var(--cx); } .axc .ax-y { color: var(--cy); } .axc .ax-z { color: var(--cz); }
.axc button.on { background: currentColor; } .axc button.on { color: #fff; }
.axc .ax-x.on { background: var(--cx); } .axc .ax-y.on { background: var(--cy); } .axc .ax-z.on { background: var(--cz); }
.editb { background: color-mix(in srgb, #3d7bff 14%, var(--panel2)); color: var(--text); }
.editb .ic { color: #3d7bff; }
#loading { display: none !important; }
body.cover #app { padding: 0; grid-template: "view" 1fr / 1fr; }
body.cover #view { border-radius: 0; box-shadow: none; background: transparent; }
body.cover { background: radial-gradient(120% 90% at 70% 20%, #3a2f8f 0%, #1d1a4a 45%, #0f1027 100%); }

/* ---------------- ready-made parts library */
.mbox.libm { width: min(1040px, calc(100vw - 24px)); height: min(820px, calc(100vh - 24px)); padding: 0; overflow: hidden; display: flex; }
.lib { display: flex; flex-direction: column; flex: 1; min-width: 0; min-height: 0; }
.libh { display: flex; align-items: center; gap: 14px; padding: 16px 64px 10px 20px; flex-wrap: wrap; }
.libh h2 { margin: 0; white-space: nowrap; }
.libh h2 .ic { color: #ff4d6d !important; }
.libq { flex: 1 1 260px; display: flex; align-items: center; gap: 8px; height: 46px; padding: 0 14px; border-radius: 14px; background: var(--panel2); border: 2px solid var(--line); }
.libq:focus-within { border-color: var(--primary); }
.libq .ic { width: 20px; height: 20px; color: var(--muted); flex: none; }
.libq input { flex: 1; min-width: 0; border: 0; background: none; font-size: 16px; font-weight: 700; color: var(--text); outline: none; }
.libc { display: flex; gap: 6px; padding: 2px 20px 10px; overflow-x: auto; scrollbar-width: thin; flex: none; }
.libc[hidden] { display: none; }
.lcat { display: inline-flex; align-items: center; gap: 7px; height: 40px; padding: 0 14px; border-radius: 99px; background: var(--panel2); font: 600 14px "Fredoka", sans-serif; white-space: nowrap; flex: none; transition: background .15s; }
.lcat .ic { width: 20px; height: 20px; color: var(--primary2); }
.lcat:hover { background: color-mix(in srgb, var(--panel2) 70%, var(--primary)); }
.lcat.on { background: linear-gradient(135deg, var(--primary), #a35cff); color: #fff; }
.lcat.on .ic { color: #fff; }
.libb { flex: 1; min-height: 0; overflow-y: auto; padding: 4px 20px 22px; border-top: 1px solid var(--line); }
.libb[hidden] { display: none; }
.lgh { display: flex; align-items: center; gap: 8px; margin: 16px 2px 10px; font: 600 17px "Fredoka", sans-serif; }
.lgh .ic { width: 22px; height: 22px; color: var(--primary2); }
.lgh small { margin-left: auto; font: 700 12px "Nunito", sans-serif; color: var(--muted); }
.pgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(138px, 1fr)); gap: 10px; }
.pc { display: flex; flex-direction: column; align-items: stretch; gap: 0; border-radius: 16px; background: var(--panel2); border: 2px solid transparent; overflow: hidden; text-align: center;
  transition: transform .1s, border-color .15s, box-shadow .15s; }
.pc:hover { border-color: var(--c); transform: translateY(-2px); box-shadow: 0 8px 20px rgba(40, 50, 90, .14); }
.pc .th { position: relative; aspect-ratio: 128 / 104; display: grid; place-items: center;
  background: radial-gradient(circle at 50% 38%, #fff 0, color-mix(in srgb, var(--c) 10%, #eef1f7) 70%); }
:root[data-theme="dark"] .pc .th { background: radial-gradient(circle at 50% 38%, #e9ecf4 0, color-mix(in srgb, var(--c) 18%, #c9cfdd) 75%); }
.pc .th img { width: 100%; height: 100%; object-fit: contain; opacity: 0; transition: opacity .25s; }
.pc .th.ok img { opacity: 1; }
.pc .th .ph { position: absolute; width: 38px; height: 38px; color: var(--c); opacity: .55; }
.pc .th.ok .ph { display: none; }
.pc .nm { padding: 8px 6px 10px; font: 600 13.5px "Fredoka", sans-serif; line-height: 1.15; min-height: 2.6em; display: grid; place-items: center; }
.pc.tpl .th .ic { width: 52px; height: 52px; color: var(--c); }
.pc.busy { opacity: .5; pointer-events: none; }
.libhint { color: var(--muted); font-weight: 700; margin: 14px 2px 4px; }
.tplt { max-width: 340px; margin-bottom: 14px !important; }
.libnone { display: flex; align-items: center; gap: 10px; color: var(--muted); font-weight: 700; margin: 30px 4px; }
.libnone .ic { width: 26px; height: 26px; }
.libd { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); border-top: 1px solid var(--line); }
.libd[hidden] { display: none; }
.ldp { padding: 14px 20px 20px; display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.ldp h3 { margin: 0; font: 700 24px "Fredoka", sans-serif; display: flex; align-items: center; gap: 10px; }
.ldp h3::before { content: ""; width: 14px; height: 14px; border-radius: 5px; background: var(--c); box-shadow: inset 0 0 0 2px rgba(0, 0, 0, .12); }
.lback { align-self: flex-start; padding-left: 8px; }
.prev { position: relative; flex: 1; min-height: 200px; border-radius: 20px; display: grid; place-items: center; overflow: hidden;
  background: radial-gradient(circle at 50% 40%, #fff 0, #e6eaf3 75%); }
:root[data-theme="dark"] .prev { background: radial-gradient(circle at 50% 40%, #eef0f6 0, #c4cad8 80%); }
.prev img { max-width: 100%; max-height: 100%; object-fit: contain; }
.prev .sz { position: absolute; left: 12px; bottom: 12px; padding: 5px 12px; border-radius: 99px; background: var(--yellow); color: #1b1e2e; font: 800 13px "Nunito", sans-serif; }
.ldf { padding: 16px 20px 20px; overflow-y: auto; border-left: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.pfields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 10px; }
.pf { display: flex; flex-direction: column; gap: 4px; min-width: 0; font-size: 12.5px; color: var(--muted); font-weight: 700; }
.pf > span:first-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pf.wide { grid-column: 1 / -1; }
.pf.wide input { height: 44px; border-radius: 12px; border: 2px solid var(--line); background: var(--panel2); padding: 0 12px; font-size: 16px; font-weight: 800; color: var(--text); }
.pf select { height: 44px; border-radius: 12px; border: 2px solid var(--line); background: var(--panel2); padding: 0 10px; color: var(--text); font-weight: 700; font-size: 15px; }
.pf.chk { flex-direction: row; align-items: center; gap: 8px; margin: 0; font-size: 14px; color: var(--text); grid-column: 1 / -1; }
.pf.chk input { width: 20px; height: 20px; accent-color: var(--primary); }
.stp { display: flex; align-items: stretch; height: 44px; border-radius: 12px; border: 2px solid var(--line); background: var(--panel2); overflow: hidden; }
.stp:focus-within { border-color: var(--primary); }
.stp input { flex: 1; min-width: 0; width: 100%; border: 0; background: none; text-align: center; font-weight: 800; font-size: 16px; color: var(--text); outline: none; }
.stp .sb { width: 38px; flex: none; font-size: 20px; font-weight: 800; color: var(--primary2); }
.stp .sb:hover { background: color-mix(in srgb, var(--primary) 14%, transparent); }
.stp .sb:active { background: color-mix(in srgb, var(--primary) 26%, transparent); }
.ldf .phelp { margin: 2px 0; }
.ldf .b.big { margin-top: auto; }
.partsec .pfields { gap: 8px; }
.partsec .stp, .partsec .pf select, .partsec .pf.wide input { height: 40px; }
@media (max-width: 760px) {
  #modal.show:has(.libm) { place-items: stretch; }
  .mbox.libm { width: 100vw; height: 100%; max-height: none; border-radius: 0; }
  .libh { padding: 12px 56px 8px 14px; gap: 10px; }
  .libh h2 { font-size: 20px; }
  .libq { flex-basis: 100%; height: 44px; }
  .libc { padding: 2px 14px 8px; }
  .lcat { height: 38px; padding: 0 12px; font-size: 13.5px; }
  .libb { padding: 4px 12px 22px; }
  .pgrid { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
  .pc .nm { font-size: 12.5px; padding: 6px 4px 8px; }
  .libd { grid-template-columns: 1fr; overflow-y: auto; align-content: start; }
  .ldp { padding: 10px 14px 6px; }
  .ldp h3 { font-size: 20px; }
  .prev { min-height: 190px; flex: none; height: 200px; }
  .ldf { border-left: 0; padding: 8px 14px calc(18px + env(safe-area-inset-bottom)); overflow: visible; }
  .ldf .b.big { position: sticky; bottom: 8px; margin-top: 8px; }
}
