/* SchoolCAD — guided modelling mode.
 * Part-studio layout: tools across the top, feature tree and parts on the left,
 * the model in the middle, and the guided steps on the right like a worksheet. */
:root {
  --sk-free: #2463d9;      /* under-defined sketch geometry (blue, as in Onshape/SolidWorks) */
  --sk-sel: #0f7bff;
  --sk-hi: #e08a00;
  --sk-ref: #d27a2c;       /* projected model edges */
  --sk-origin: #c0362b;
  --sk-grid: rgba(60, 70, 90, 0.08);
  --sk-axis: rgba(60, 70, 90, 0.35);
  --sk-dim: #4f5b70;
  --sk-region: rgba(15, 123, 255, 0.16);
  --sk-passive: #6a7a96;
  --sk-plane: #5b8be6;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --sk-free: #6fa3ff; --sk-sel: #4fa2ff; --sk-hi: #ffb340; --sk-ref: #f0a060; --sk-origin: #ff7a6b;
    --sk-grid: rgba(200, 210, 230, 0.07); --sk-axis: rgba(200, 210, 230, 0.32); --sk-dim: #a7b2c6;
    --sk-region: rgba(79, 162, 255, 0.2); --sk-passive: #8fa0bf; --sk-plane: #7d9dff;
  }
}
:root[data-theme="dark"] {
  --sk-free: #6fa3ff; --sk-sel: #4fa2ff; --sk-hi: #ffb340; --sk-ref: #f0a060; --sk-origin: #ff7a6b;
  --sk-grid: rgba(200, 210, 230, 0.07); --sk-axis: rgba(200, 210, 230, 0.32); --sk-dim: #a7b2c6;
  --sk-region: rgba(79, 162, 255, 0.2); --sk-passive: #8fa0bf; --sk-plane: #7d9dff;
}

body.cad-app { grid-template-rows: auto auto minmax(0, 1fr) auto; }

/* ---------- toolbar ---------- */
.toolbar {
  display: flex; align-items: stretch; gap: 4px; padding: 4px 10px; background: var(--panel); border-bottom: 1px solid var(--line);
  overflow-x: auto; scrollbar-width: thin; min-height: 52px;
}
.tgroup { display: flex; align-items: stretch; gap: 2px; padding-right: 6px; margin-right: 4px; border-right: 1px solid var(--line); }
.tgroup:last-child, .tgroup.end { border-right: 0; }
.tgroup.end { margin-left: auto; align-items: center; gap: 6px; padding-left: 8px; }
.tool {
  display: grid; justify-items: center; align-content: center; gap: 1px; min-width: 52px; padding: 4px 6px; border: 1px solid transparent; border-radius: 6px;
  background: none; cursor: pointer; color: var(--ink);
}
.tool:hover:not(:disabled) { background: var(--panel-2); border-color: var(--line); }
.tool[aria-pressed="true"] { background: var(--accent-weak); border-color: var(--accent); }
.tool:disabled { opacity: 0.38; cursor: default; }
.tool .ti { width: 22px; height: 22px; display: grid; place-items: center; }
.tool .ti svg { width: 22px; height: 22px; }
.tool .tl { font-size: 11px; color: var(--muted); white-space: nowrap; }
.tool[aria-pressed="true"] .tl { color: var(--ink); }
.tool.con { min-width: 40px; }
.tool .cg { width: 22px; height: 22px; display: grid; place-items: center; font: 700 14px var(--font-ui); border: 1px solid var(--line-strong); border-radius: 5px; background: var(--panel-2); }
.toolbar.sketching { background: color-mix(in srgb, var(--accent-weak) 45%, var(--panel)); }
.ok-btn { background: var(--ok); color: #fff; border-color: var(--ok); font-weight: 600; }
.ok-btn:hover { background: var(--ok); filter: brightness(1.08); }
.tb-hint { align-self: center; color: var(--muted); font-size: 13px; padding-left: 6px; }
.hint-group { border-right: 0; }

/* lesson highlight */
.pulse { position: relative; animation: pulse 1.6s ease-in-out infinite; border-color: var(--sk-hi) !important; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--sk-hi) 55%, transparent); } 50% { box-shadow: 0 0 0 5px color-mix(in srgb, var(--sk-hi) 0%, transparent); } }
@media (prefers-reduced-motion: reduce) { .pulse { animation: none; box-shadow: 0 0 0 2px var(--sk-hi); } }

/* ---------- layout ---------- */
.cad { display: grid; grid-template-columns: 240px minmax(0, 1fr) 330px; min-height: 0; }
.ftree { background: var(--panel); border-right: 1px solid var(--line); overflow: auto; display: flex; flex-direction: column; min-height: 0; }
.tree-sec { padding: 8px 0; }
.tree-sec + .tree-sec { border-top: 1px solid var(--line); }
.tree-sec h2 { margin: 0 12px 4px; font: 600 11px var(--font-ui); text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.tree-sec h2 span { font-weight: 400; letter-spacing: 0; }
.features, .parts { list-style: none; margin: 0; padding: 0; }
.features li, .parts li { display: flex; align-items: center; gap: 7px; padding: 4px 12px; font-size: 13px; cursor: default; user-select: none; min-height: 28px; }
.features li .ti, .parts .ti { width: 18px; height: 18px; flex: none; color: var(--muted); }
.features li .ti svg { width: 18px; height: 18px; }
.features li.fixed { color: var(--muted); cursor: pointer; }
.features li.fixed:hover, .features li.feat:hover, .parts li:hover { background: var(--panel-2); }
.features li.sel, .parts li.sel { background: var(--accent-weak); }
.features li.editing { background: var(--accent-weak); box-shadow: inset 3px 0 0 var(--accent); font-weight: 600; }
.features li.feat { cursor: pointer; }
.features li.rolled { opacity: 0.45; }
.features li.supp .fname { text-decoration: line-through; color: var(--muted); }
.features li.err .fname { color: var(--err); }
.features li.warn .fname { color: var(--warn); }
.features li .fname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.features li .badge { font: 700 12px var(--font-mono); color: var(--sk-free); }
.features li .st { font-weight: 700; font-size: 12px; width: 16px; height: 16px; display: grid; place-items: center; border-radius: 50%; }
.features li .st.err { background: var(--err); color: #fff; }
.features li .st.warn { color: var(--warn); }
.features li.drop { box-shadow: inset 0 -2px 0 var(--accent); }
.features li.rollback { padding: 0 8px; min-height: 12px; cursor: grab; position: relative; }
.features li.rollback::before { content: ""; flex: 1; height: 4px; border-radius: 2px; background: var(--accent); opacity: 0.75; }
.features li.rollback:hover::before { opacity: 1; height: 5px; }
.features input.rename, .parts input.rename { flex: 1; min-width: 0; font-size: 13px; padding: 2px 5px; border: 1px solid var(--accent); border-radius: 4px; background: var(--panel); }
.parts li { gap: 6px; padding-left: 6px; cursor: pointer; }
.parts li.empty { color: var(--muted); cursor: default; padding-left: 12px; }
.parts .eye { width: 24px; height: 24px; padding: 3px; border: 0; background: none; color: var(--muted); cursor: pointer; border-radius: 4px; flex: none; }
.parts .eye:hover { background: var(--line); color: var(--ink); }
.parts .eye svg { width: 18px; height: 18px; }
.pswatch { width: 10px; height: 10px; border-radius: 2px; flex: none; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.18); }
.parts .pname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.parts .psize { font: 11px var(--font-mono); color: var(--muted); white-space: nowrap; }

/* ---------- viewport ---------- */
.viewport { position: relative; background: radial-gradient(ellipse at 50% 35%, color-mix(in srgb, var(--panel) 70%, var(--stage)), var(--stage)); min-height: 0; overflow: hidden; }
.viewport canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#ov { outline: none; touch-action: none; }
.viewcube { position: absolute; top: 10px; right: 10px; display: flex; gap: 2px; padding: 3px; background: color-mix(in srgb, var(--panel) 92%, transparent); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); }
.viewcube button { border: 0; background: none; padding: 4px 8px; border-radius: 5px; font-size: 12px; cursor: pointer; }
.viewcube button:hover { background: var(--accent-weak); }
.explode { position: absolute; right: 10px; bottom: 10px; padding: 5px 8px; background: color-mix(in srgb, var(--panel) 92%, transparent); border: 1px solid var(--line); border-radius: 8px; }
.nav-hint { position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); font-size: 12px; color: var(--muted); background: color-mix(in srgb, var(--panel) 88%, transparent); padding: 4px 10px; border-radius: 999px; pointer-events: none; transition: opacity 1s; }
.nav-hint.fade { opacity: 0; }
.vstatus { position: absolute; left: 50%; top: 10px; transform: translateX(-50%); font-size: 13px; padding: 5px 12px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow); max-width: calc(100% - 260px); text-align: center; }
.vstatus.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 50%, var(--line)); }
.vstatus.warn { color: var(--sk-free); }
.vstatus.err { color: var(--err); border-color: var(--err); }

/* feature dialog (top-left of the view, like Onshape) */
.fdialog { position: absolute; left: 10px; top: 10px; width: 290px; max-height: calc(100% - 20px); overflow: auto; background: var(--panel); border: 1px solid var(--line-strong); border-radius: 8px; box-shadow: var(--shadow); z-index: 5; }
.fd-head { display: flex; align-items: center; gap: 6px; padding: 6px 6px 6px 10px; border-bottom: 1px solid var(--line); background: var(--panel-2); border-radius: 8px 8px 0 0; }
.fd-head .ti { width: 20px; height: 20px; color: var(--accent); flex: none; }
.fd-head .ti svg { width: 20px; height: 20px; }
.fd-name { flex: 1; min-width: 0; border: 1px solid transparent; background: none; font-weight: 600; padding: 3px 4px; border-radius: 4px; }
.fd-name:hover, .fd-name:focus { border-color: var(--line); background: var(--panel); }
.fd-ok, .fd-cancel { width: 30px; height: 30px; border-radius: 6px; border: 1px solid var(--line); cursor: pointer; font-weight: 700; font-size: 15px; flex: none; }
.fd-ok { background: var(--ok); color: #fff; border-color: var(--ok); }
.fd-cancel { background: var(--panel); color: var(--err); }
.fd-body { padding: 10px; display: grid; gap: 9px; }
.fd-body .seg { width: 100%; }
.fd-body .seg button { flex: 1; }
.fd-row { display: grid; grid-template-columns: 86px minmax(0, 1fr); align-items: center; gap: 8px; }
.fd-row > label { font-size: 12.5px; color: var(--muted); }
.fd-ctl { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.fd-ctl select, .fd-ctl input[type=text] { flex: 1; min-width: 0; padding: 5px 7px; border: 1px solid var(--line); border-radius: var(--r); background: var(--panel-2); }
.fd-num { flex: 1; min-width: 0; padding: 5px 7px; border: 1px solid var(--line); border-radius: var(--r); background: var(--panel-2); font: 13px var(--font-mono); }
.fd-num.bad { border-color: var(--err); }
.fd-ctl .unit { font-size: 12px; color: var(--muted); }
.fd-sub { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; margin-top: 2px; }
.fd-parts { display: grid; gap: 3px; max-height: 160px; overflow: auto; }
.chk { display: flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; }
.chk input { accent-color: var(--accent); }
.fd-error { margin: 0; color: var(--err); font-size: 12.5px; background: color-mix(in srgb, var(--err) 9%, var(--panel)); border-radius: 6px; padding: 6px 8px; }
.help.small { font-size: 12px; }
.btn.small { padding: 4px 8px; font-size: 12.5px; }

/* inline dimension value */
.val-edit { position: absolute; z-index: 8; display: grid; grid-template-columns: auto 90px 30px; gap: 4px 6px; align-items: center; padding: 6px 8px; background: var(--panel); border: 1px solid var(--accent); border-radius: 8px; box-shadow: var(--shadow); }
.val-edit label { font-size: 12px; color: var(--muted); }
.val-edit input { width: 90px; padding: 4px 6px; border: 1px solid var(--line); border-radius: 5px; font: 14px var(--font-mono); background: var(--panel-2); }
.val-edit .ok { height: 28px; border: 0; border-radius: 5px; background: var(--ok); color: #fff; font-weight: 700; cursor: pointer; }
.val-edit .err { grid-column: 1 / -1; color: var(--err); font-size: 12px; max-width: 230px; }
.val-edit .err:empty { display: none; }

.ctx-menu { position: fixed; z-index: 40; min-width: 190px; padding: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); }
.ctx-menu button { display: block; width: 100%; text-align: left; padding: 6px 10px; border: 0; background: none; border-radius: 5px; cursor: pointer; font-size: 13px; white-space: pre; }
.ctx-menu button:hover { background: var(--accent-weak); }
.ctx-menu button.danger { color: var(--err); }
.ctx-menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }

/* ---------- lesson ---------- */
.lesson { background: var(--panel); border-left: 1px solid var(--line); overflow: auto; padding: 0 14px 18px; display: flex; flex-direction: column; gap: 10px; }
.lesson-head { position: sticky; top: 0; background: var(--panel); display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 0 8px; border-bottom: 1px solid var(--line); z-index: 1; }
.lesson-head b { display: block; font-family: var(--font-display); font-size: 15px; }
.lesson-head small { color: var(--muted); font-size: 12px; }
.lesson-prog { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px; }
.lesson-prog button { width: 24px; height: 24px; border-radius: 50%; border: 1px solid var(--line-strong); background: var(--panel); font: 600 11px var(--font-ui); cursor: pointer; color: var(--muted); padding: 0; }
.lesson-prog li.done button { background: var(--ok); color: #fff; border-color: var(--ok); }
.lesson-prog li.cur button { box-shadow: 0 0 0 2px var(--accent); color: var(--ink); }
.lesson-title { margin: 4px 0 0; font: 600 17px var(--font-display); }
.lesson-title span { color: var(--muted); }
.lesson-intro { margin: 0; font-size: 13.5px; }
.lesson-steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.lesson-steps li { display: grid; grid-template-columns: 24px minmax(0, 1fr); gap: 8px; padding: 8px; border-radius: 8px; border: 1px solid transparent; font-size: 13px; }
.lesson-steps li.cur { border-color: var(--accent); background: color-mix(in srgb, var(--accent-weak) 55%, var(--panel)); }
.lesson-steps li.ok { color: var(--muted); }
.lesson-steps li.ok b { text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--ok) 70%, transparent); }
.lesson-steps .mark { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font: 600 11px var(--font-ui); border: 1px solid var(--line-strong); background: var(--panel); }
.lesson-steps li.ok .mark { background: var(--ok); border-color: var(--ok); color: #fff; }
.lesson-steps li.cur .mark { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.lesson-steps .how { margin-top: 4px; color: var(--ink); line-height: 1.5; }
.lesson-steps .how ul { margin: 4px 0 0; padding-left: 18px; }
.lesson-steps .how li { display: list-item; padding: 0; border: 0; font-size: 13px; }
.nudge { margin: 6px 0 0; color: var(--warn); font-size: 12.5px; }
.lesson-done { border-radius: 8px; padding: 10px 12px; background: color-mix(in srgb, var(--ok) 12%, var(--panel)); border: 1px solid color-mix(in srgb, var(--ok) 45%, var(--line)); font-size: 13px; }
.lesson-done b { color: var(--ok); }
.lesson-done p { margin: 4px 0 0; }
.lesson-bar { display: flex; gap: 6px; margin-top: auto; padding-top: 8px; position: sticky; bottom: -18px; background: var(--panel); padding-bottom: 6px; }
.lesson-bar .btn:last-child { margin-left: auto; }
table.cut { border-collapse: collapse; margin-top: 6px; font-size: 12.5px; width: 100%; }
table.cut th, table.cut td { border-bottom: 1px solid var(--line); padding: 3px 4px; text-align: left; }
table.cut td:last-child { font-family: var(--font-mono); white-space: nowrap; }
.lesson.collapsed { gap: 0; }
.cad:has(.lesson.collapsed) { grid-template-columns: 240px minmax(0, 1fr) 190px; }

/* ---------- small screens ---------- */
@media (max-width: 1180px) { .cad { grid-template-columns: 210px minmax(0, 1fr) 290px; } .who input { width: 110px; } }
@media (max-width: 900px) {
  body.cad-app { overflow: auto; height: auto; display: block; }
  .cad { display: flex; flex-direction: column; }
  .viewport { height: 62vh; min-height: 360px; order: 1; }
  .lesson { order: 2; border-left: 0; border-top: 1px solid var(--line); max-height: none; }
  .ftree { order: 3; border-right: 0; border-top: 1px solid var(--line); }
  .modes { order: 3; }
  .tool .tl { display: none; }
  .tool { min-width: 40px; }
  .vstatus { max-width: calc(100% - 20px); top: 52px; }
  .fdialog { width: min(290px, calc(100% - 20px)); }
  .nav-hint { display: none; }
}

/* measure & section panels */
.vpanel { position: absolute; z-index: 4; background: color-mix(in srgb, var(--panel) 95%, transparent); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); font-size: 13px; }
.section-panel { right: 10px; bottom: 56px; display: flex; align-items: center; gap: 8px; padding: 6px 8px; }
.section-panel input[type=range] { width: 160px; accent-color: var(--accent); }
.section-panel output { font: 12px var(--font-mono); min-width: 64px; }
.measure-panel { left: 10px; bottom: 10px; width: 250px; max-height: 50%; overflow: auto; padding: 8px 10px; display: grid; gap: 3px; }
.measure-panel .mp-head { display: flex; justify-content: space-between; align-items: center; }
.measure-panel .msub { margin-top: 6px; font-weight: 600; color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.05em; }
.measure-panel .mrow { display: flex; justify-content: space-between; gap: 10px; }
.measure-panel .mrow b { font: 600 12.5px var(--font-mono); text-align: right; }
.parts li.totals { cursor: default; font-weight: 600; border-top: 1px solid var(--line); margin-top: 4px; padding-left: 12px; }
.parts li.totals span:first-child { flex: 1; }

/* parameters */
.tree-add { float: right; border: 0; background: none; color: var(--accent); font: 600 11px var(--font-ui); cursor: pointer; text-transform: none; letter-spacing: 0; padding: 0; }
.params { list-style: none; margin: 0; padding: 0; }
.params li { display: flex; align-items: center; gap: 4px; padding: 2px 8px 2px 12px; font-size: 12.5px; }
.params li.empty { color: var(--muted); font-size: 12px; }
.params input { min-width: 0; border: 1px solid transparent; background: none; border-radius: 4px; padding: 2px 4px; font: 12.5px var(--font-mono); }
.params input:hover, .params input:focus { border-color: var(--line); background: var(--panel); }
.params .pname-in { width: 64px; font-weight: 600; }
.params .pexpr-in { flex: 1; }
.params .pexpr-in.bad { border-color: var(--err); }
.params .eq, .params .pval { color: var(--muted); font: 11.5px var(--font-mono); }
.params li.err .pval { color: var(--err); font-weight: 700; }
.params .pdel { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 14px; padding: 0 2px; }
.params .pdel:hover { color: var(--err); }

.lesson.collapsed .lesson-head { flex-direction: column; align-items: flex-start; }

/* drawing dialog */
dialog.wide { width: min(1100px, calc(100vw - 32px)); }
.drawing-dlg .dr-grid { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 16px; align-items: start; }
.drawing-dlg .dr-opts { display: grid; gap: 9px; }
.drawing-dlg .fd-row { display: grid; grid-template-columns: 78px minmax(0, 1fr); align-items: center; gap: 8px; font-size: 13px; }
.drawing-dlg .fd-row > span { color: var(--muted); }
.drawing-dlg input[type=text], .drawing-dlg select { padding: 5px 7px; border: 1px solid var(--line); border-radius: var(--r); background: var(--panel-2); min-width: 0; width: 100%; }
.drawing-dlg .seg { width: 100%; }
.drawing-dlg .seg button { flex: 1; }
.drawing-dlg .dr-preview { background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 6px; }
.drawing-dlg .dr-preview img { width: 100%; height: auto; display: block; aspect-ratio: 1.414; }
@media (max-width: 800px) { .drawing-dlg .dr-grid { grid-template-columns: 1fr; } }
