  /* ============================================================
     OnSketch — light, professional, utilitarian.
     ============================================================ */
  :root {
    --bg:            #eef1f4;
    --panel:         #f6f7f9;
    --panel-2:       #ffffff;
    --panel-3:       #fbfcfd;
    --border:        #cfd5dd;
    --border-soft:   #e4e8ee;
    --text:          #1b2028;
    --text-soft:     #58616d;
    --text-muted:    #858f9b;
    --accent:        #2563a5;
    --accent-strong: #174f87;
    --accent-soft:   #dce9f7;
    --accent-softer: #edf5fd;
    --selected:      #ff8a1e;
    --hover:         #eef4fa;
    --construction:  #c44b8a;
    --underc:        #1f7ad6;
    --fullyc:        #111418;
    --overc:         #d63a3a;
    --grid-fine:     #e6e9ee;
    --grid-major:    #c8ced6;
    --canvas-a:      #fbfcfd;
    --canvas-b:      #e3e8ef;
    --shadow-soft:   0 1px 2px rgba(18, 25, 38, 0.06);
    --field:         #ffffff;
    --panel-head:    linear-gradient(#fff, #fafbfc);
    --canvas-mid:    #f5f8fb;
    --accent-border: #bfd6ee;
    --inset:         rgba(255,255,255,0.55);
    color-scheme: light;
  }
  :root[data-theme="dark"] {
    --bg:            #15191f;
    --panel:         #1b2027;
    --panel-2:       #20262e;
    --panel-3:       #1e242b;
    --border:        #333b46;
    --border-soft:   #2a313b;
    --text:          #e3e7ec;
    --text-soft:     #a9b2bd;
    --text-muted:    #7d8793;
    --accent:        #5aa9ff;
    --accent-strong: #84bfff;
    --accent-soft:   #1e3a5a;
    --accent-softer: #1a2b3f;
    --selected:      #ff9a3c;
    --hover:         #262d36;
    --construction:  #e27bb4;
    --underc:        #5aa9ff;
    --fullyc:        #e6e9ee;
    --overc:         #ff6464;
    --grid-fine:     #252b34;
    --grid-major:    #343c48;
    --canvas-a:      #1d232b;
    --canvas-mid:    #191e25;
    --canvas-b:      #13171c;
    --shadow-soft:   0 1px 2px rgba(0, 0, 0, 0.4);
    --field:         #161a20;
    --panel-head:    linear-gradient(#232a33, #20262e);
    --accent-border: #2f5378;
    --inset:         rgba(255,255,255,0.03);
    color-scheme: dark;
  }
  * { box-sizing: border-box; }
  html, body { height: 100%; margin: 0; }
  body {
    font: 13px/1.4 -apple-system, "Segoe UI", "Inter", system-ui, sans-serif;
    color: var(--text);
    background: var(--bg);
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
  }
  button, input, select, textarea { font: inherit; color: inherit; }

  #app {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 46px 40px minmax(0, 1fr) 28px;
    grid-template-areas: "menubar" "optbar" "workspace" "statusbar";
    height: 100vh;
  }

  /* ---------- Menu bar ---------- */
  #menubar {
    grid-area: menubar;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    background: var(--panel-2);
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    overflow-y: hidden;
    box-shadow: var(--shadow-soft);
  }
  #menubar .group {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0 10px 0 0;
    border-right: 1px solid var(--border-soft);
    height: 38px;
    flex: 0 0 auto;
  }
  #menubar .group:last-child { border-right: 0; }
  #menubar .label {
    font-size: 9px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin: 0 2px 0 0;
    min-width: 36px;
  }
  .tbtn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 32px;
    min-width: 32px;
    padding: 0 9px;
    border: 1px solid transparent;
    background: transparent;
    border-radius: 6px;
    cursor: pointer;
    color: var(--text);
    gap: 6px;
    font-size: 12px;
    white-space: nowrap;
  }
  .tbtn:hover { background: var(--hover); border-color: var(--border-soft); }
  .tbtn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
    box-shadow: 0 1px 2px rgba(37, 99, 165, 0.22);
  }
  .tbtn.toggle.on {
    background: var(--accent-soft);
    color: var(--accent);
    border-color: var(--accent-border);
  }
  .tbtn.tool {
    width: 34px;
    padding: 0;
  }
  .tbtn svg, .ui-icon { width: 16px; height: 16px; flex: 0 0 auto; }
  .tbtn .btn-label { line-height: 1; }
  .tbtn:focus-visible,
  .icon-btn:focus-visible,
  .rel-btn:focus-visible,
  .context-menu-item:focus-visible,
  input:focus-visible,
  textarea:focus-visible {
    outline: 2px solid color-mix(in srgb, var(--accent) 55%, white);
    outline-offset: 1px;
  }
  .sep { width: 1px; height: 22px; background: var(--border-soft); margin: 0 4px; }

  .panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 11px;
    font-size: 11px;
    text-transform: uppercase;
    color: var(--text-soft);
    letter-spacing: 0.08em;
    border-bottom: 1px solid var(--border-soft);
    background: var(--panel-head);
    flex: 0 0 auto;
    font-weight: 700;
  }
  .panel-header .actions { display: flex; gap: 2px; }
  .panel-header .badge {
    text-transform: none;
    letter-spacing: 0;
    background: var(--panel);
    border: 1px solid var(--border-soft);
    border-radius: 999px;
    padding: 0 6px;
    font-size: 10px;
    color: var(--text-soft);
  }
  .icon-btn {
    width: 24px; height: 24px;
    display: inline-flex; align-items: center; justify-content: center;
    border: 1px solid transparent;
    background: transparent;
    border-radius: 5px;
    cursor: pointer;
    color: var(--text-soft);
    font-size: 12px;
  }
  .icon-btn:hover { background: var(--hover); color: var(--text); }
  .icon-btn svg { width: 14px; height: 14px; }

  /* Selection / relations panel body */
  .sb-body {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 10px 11px 12px;
    min-height: 0;
  }
  .sb-subhead {
    font-size: 10px;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.06em;
    margin: 12px 0 6px;
    font-weight: 600;
  }
  .sb-subhead:first-child { margin-top: 0; }
  .muted { color: var(--text-muted); }
  .empty {
    color: var(--text-muted);
    padding: 6px 0;
    font-size: 11px;
  }

  /* Selection list */
  .sel-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 6px;
    font-size: 12px;
    color: var(--text);
    border-radius: 6px;
    border: 1px solid transparent;
    min-width: 0;
  }
  .sel-item:hover { background: var(--hover); border-color: var(--border-soft); }
  .sel-item.active {
    background: var(--accent-softer);
    border-color: var(--accent-border);
    color: var(--accent-strong);
  }
  .sel-item .glyph {
    width: 14px;
    flex: 0 0 14px;
    text-align: center;
    color: var(--text-soft);
    font-weight: 600;
  }
  .sel-item > span:not(.glyph):not(.layer-tag) {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
  }
  .sel-item .layer-tag {
    margin-left: auto;
    font-size: 10px;
    color: var(--text-muted);
    padding: 0 4px;
    border: 1px solid var(--border-soft);
    border-radius: 999px;
    flex: 0 0 auto;
  }

  /* Relation buttons grid */
  .rel-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    margin: 4px 0;
  }
  .rel-btn {
    min-height: 32px;
    padding: 6px 8px;
    border: 1px solid var(--border);
    background: var(--field);
    border-radius: 6px;
    cursor: pointer;
    font-size: 11px;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text);
    min-width: 0;
  }
  .rel-btn:hover {
    background: var(--accent-softer);
    border-color: var(--accent);
    color: var(--accent);
  }
  .rel-btn.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
    justify-content: center;
  }
  .rel-btn.primary:hover { background: var(--accent-strong); color: white; }
  .rel-btn.danger:hover {
    background: color-mix(in srgb, var(--overc) 10%, var(--field));
    border-color: var(--overc);
    color: var(--overc);
  }
  .rel-btn.full { grid-column: 1 / -1; justify-content: center; }
  .rel-btn:disabled {
    background: var(--panel);
    color: var(--text-muted);
    cursor: not-allowed;
    border-color: var(--border-soft);
  }
  .rel-btn .glyph {
    width: 14px;
    text-align: center;
    flex: 0 0 14px;
    color: var(--text-soft);
    font-weight: 600;
  }
  .rel-btn:hover .glyph { color: var(--accent); }
  .rel-btn.primary .glyph,
  .rel-btn.primary:hover .glyph { color: white; }

  .tool-summary {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    margin-bottom: 8px;
  }
  .tool-metric {
    border: 1px solid var(--border-soft);
    border-radius: 6px;
    background: var(--field);
    padding: 7px 8px;
    min-width: 0;
  }
  .tool-metric strong {
    display: block;
    font-size: 16px;
    line-height: 1;
    color: var(--text);
    margin-bottom: 2px;
  }
  .tool-metric span {
    color: var(--text-muted);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
  }
  .choice-row {
    width: 100%;
    display: grid;
    grid-template-columns: 24px minmax(0, 1fr);
    gap: 7px;
    align-items: center;
    padding: 8px;
    border: 1px solid var(--border-soft);
    border-radius: 6px;
    background: var(--field);
    cursor: pointer;
    margin-bottom: 6px;
    text-align: left;
  }
  .choice-row:hover {
    border-color: var(--accent-border);
    background: var(--accent-softer);
  }
  .choice-row.active {
    border-color: var(--accent);
    background: var(--accent-softer);
    box-shadow: inset 3px 0 0 var(--accent);
  }
  .choice-row .glyph {
    width: 24px;
    height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 5px;
    background: var(--panel);
    color: var(--accent);
    font-weight: 700;
  }
  .choice-row strong {
    display: block;
    font-size: 12px;
    font-weight: 700;
    color: var(--text);
  }
  .choice-row.active strong { color: var(--accent-strong); }
  .choice-row span:not(.glyph) {
    display: block;
    color: var(--text-muted);
    font-size: 11px;
    line-height: 1.3;
    margin-top: 1px;
  }
  .stack-list {
    display: grid;
    gap: 3px;
  }
  .tool-note {
    border-left: 3px solid var(--border);
    padding: 6px 7px;
    margin: 6px 0;
    background: var(--panel);
    color: var(--text-soft);
    font-size: 11px;
    border-radius: 0 5px 5px 0;
  }
  .tool-note.warn {
    border-left-color: #d28a18;
    background: color-mix(in srgb, #d28a18 12%, var(--field));
    color: color-mix(in srgb, #d28a18 60%, var(--text));
  }
  .op-actions { margin-top: 10px; }

  /* Existing constraint pills */
  .constraint-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 6px;
    background: var(--panel);
    border: 1px solid var(--border-soft);
    border-radius: 999px;
    font-size: 11px;
    margin: 2px 2px 2px 0;
    color: var(--text-soft);
  }
  .constraint-pill .x {
    cursor: pointer; color: var(--text-muted);
    font-size: 14px; line-height: 1;
  }
  .constraint-pill .x:hover { color: var(--overc); }

  /* Property rows */
  .prop-row {
    display: grid;
    grid-template-columns: 82px minmax(0, 1fr);
    align-items: center;
    gap: 6px;
    padding: 4px 0;
    font-size: 12px;
  }
  .prop-row label {
    color: var(--text-soft);
    font-size: 11px;
    text-transform: capitalize;
  }
  .prop-row input[type=number],
  .prop-row input[type=text] {
    flex: 1;
    padding: 5px 7px;
    border: 1px solid var(--border);
    border-radius: 5px;
    background: var(--field);
    min-width: 0;
  }
  .prop-row input:focus {
    outline: 1px solid var(--accent);
    border-color: var(--accent);
  }
  .prop-row .rel-btn { width: 100%; justify-content: center; }
  .prop-row select { padding: 4px 6px; border: 1px solid var(--border); border-radius: 5px; background: var(--field); color: var(--text); min-width: 0; }
  .prop-row input.bad, .dim-val.bad { border-color: var(--overc); box-shadow: 0 0 0 2px color-mix(in srgb, var(--overc) 25%, transparent); }

  /* ---- Properties window: header, toggles, relation and dimension rows ---- */
  .ps-empty { display: grid; gap: 4px; padding: 6px 2px; font-size: 11.5px; color: var(--text-muted); line-height: 1.4; }
  .ps-empty strong { color: var(--text-soft); font-size: 12px; }
  .ps-head, .ps-multi > summary {
    display: flex; align-items: center; gap: 8px;
    padding: 7px 8px; margin-bottom: 4px;
    border: 1px solid var(--border-soft); border-radius: 8px; background: var(--field);
    min-width: 0;
  }
  .ps-glyph {
    width: 24px; height: 24px; flex: 0 0 24px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 6px; background: var(--accent-softer); color: var(--accent);
    font-weight: 700; font-size: 12px;
  }
  .ps-title { display: flex; align-items: baseline; gap: 6px; min-width: 0; flex: 1; font-size: 12.5px; }
  .ps-title strong { font-weight: 650; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .ps-id { color: var(--text-muted); font-size: 10.5px; font-variant-numeric: tabular-nums; }
  .ps-tag {
    font-size: 10px; color: var(--text-soft); padding: 1px 6px;
    border: 1px solid var(--border-soft); border-radius: 999px; flex: 0 0 auto;
  }
  .ps-tag.on { color: var(--accent); border-color: var(--accent-border); background: var(--accent-softer); }
  .ps-head .layer-tag { font-size: 10px; color: var(--text-muted); padding: 0 5px; border: 1px solid var(--border-soft); border-radius: 999px; }
  .ps-multi > summary { cursor: pointer; list-style: none; font-size: 12px; }
  .ps-multi > summary::-webkit-details-marker { display: none; }
  .ps-multi > summary::after { content: '▸'; margin-left: auto; color: var(--text-muted); font-size: 10px; }
  .ps-multi[open] > summary::after { content: '▾'; }
  .ps-multi > summary strong { font-weight: 600; }
  button.sel-item { width: 100%; background: none; font: inherit; text-align: left; cursor: pointer; }

  /* Relation toggles: lit = already applied (click removes) */
  .rel-btn .rel-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .rel-btn .rel-check { font-size: 11px; font-weight: 700; }
  .rel-btn.on {
    background: var(--accent-softer); border-color: var(--accent-border);
    color: var(--accent-strong); box-shadow: inset 3px 0 0 var(--accent);
  }
  .rel-btn.on .glyph { color: var(--accent); }
  .rel-btn.on:hover {
    background: color-mix(in srgb, var(--overc) 8%, var(--field));
    border-color: var(--overc); color: var(--overc); box-shadow: inset 3px 0 0 var(--overc);
  }
  .rel-btn.on:hover .glyph { color: var(--overc); }
  .rel-btn.on:hover .rel-check::before { content: '✕'; }
  .rel-btn.on:hover .rel-check { font-size: 0; }
  .rel-btn.on:hover .rel-check::before { font-size: 11px; }
  .rel-btn.partial { border-style: dashed; border-color: var(--accent-border); }

  .rel-list, .dim-list { display: grid; gap: 2px; margin-top: 6px; }
  .rel-row, .dim-row {
    display: flex; align-items: center; gap: 6px;
    padding: 4px 4px 4px 6px; border-radius: 6px; border: 1px solid transparent;
    font-size: 11.5px; color: var(--text); min-width: 0; cursor: pointer;
  }
  .rel-row:hover, .dim-row:hover { background: var(--hover); border-color: var(--border-soft); }
  .rel-row .glyph, .dim-row .glyph { width: 14px; flex: 0 0 14px; text-align: center; color: var(--accent); font-weight: 600; }
  .rel-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .layer-tag.cross { flex: none; font-size: 10px; color: var(--accent); padding: 0 5px; margin-left: 4px; border: 1px dashed var(--accent-border); border-radius: 999px; white-space: nowrap; }
  .rel-with { color: var(--text-muted); margin-left: 5px; }
  .rel-del {
    width: 20px; height: 20px; flex: 0 0 20px; border: 0; background: none; border-radius: 4px;
    color: var(--text-muted); font-size: 14px; line-height: 1; cursor: pointer; opacity: 0.55;
  }
  .rel-row:hover .rel-del, .dim-row:hover .rel-del, .rel-del:focus-visible { opacity: 1; }
  .rel-del:hover { color: var(--overc); background: color-mix(in srgb, var(--overc) 10%, transparent); }
  .dim-row { cursor: default; padding: 2px 4px 2px 6px; }
  .dim-name { flex: 0 1 auto; min-width: 46px; max-width: 46%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-soft); font-size: 11px; }
  .dim-val {
    flex: 1; min-width: 0; padding: 4px 6px; font: inherit; font-variant-numeric: tabular-nums;
    border: 1px solid var(--border); border-radius: 5px; background: var(--field); color: var(--text);
  }
  .dim-val:focus { outline: 1px solid var(--accent); border-color: var(--accent); }
  .dim-val.driven { border-style: dashed; color: var(--text-muted); background: transparent; }
  .dim-unit { font-size: 11px; color: var(--text-soft); flex: 0 0 auto; min-width: 16px; }
  .dim-add { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
  .dim-add .mini-btn { display: inline-flex; align-items: center; gap: 4px; padding: 4px 8px; border-style: dashed; }
  .dim-add .mini-btn .glyph { color: var(--accent); font-weight: 600; }
  .ps-delete { margin-top: 14px; width: 100%; justify-content: center; }

  /* On/off switch (a styled checkbox) */
  .switch { position: relative; display: inline-flex; width: 30px; height: 17px; cursor: pointer; text-transform: none; }
  .switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
  .switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--border); transition: background .12s; pointer-events: none; }
  .switch span::after {
    content: ''; position: absolute; top: 2px; left: 2px; width: 13px; height: 13px; border-radius: 50%;
    background: white; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .12s;
  }
  .switch input:checked + span { background: var(--accent); }
  .switch input:checked + span::after { transform: translateX(13px); }
  .switch input:indeterminate + span { background: var(--accent-border); }
  .switch input:indeterminate + span::after { transform: translateX(6.5px); }
  .switch input:focus-visible + span { outline: 2px solid color-mix(in srgb, var(--accent) 55%, white); outline-offset: 1px; }

  /* ---------- Workspace / canvas ---------- */
  #workspace {
    grid-area: workspace;
    position: relative;
    overflow: hidden;
    background: radial-gradient(circle at 50% 35%, var(--canvas-a) 0%, var(--canvas-mid) 38%, var(--canvas-b) 100%);
  }
  #canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    /* Touch: the editor handles drags, pans and pinches itself (touch.js);
       no effect on mouse input. */
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
  }
  #loupe {
    position: absolute; z-index: 25; pointer-events: none;
    border-radius: 50%; border: 2px solid var(--panel-2);
    box-shadow: 0 0 0 1px var(--border), 0 8px 24px rgba(0, 0, 0, 0.28);
    background: var(--panel-2);
  }
  #loupe[hidden] { display: none; }

  /* ---------- Status bar ---------- */
  #statusbar {
    grid-area: statusbar;
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 10px;
    background: var(--panel-2);
    border-top: 1px solid var(--border);
    color: var(--text-soft);
    font-size: 11px;
    font-variant-numeric: tabular-nums;
    min-width: 0;
  }
  #statusbar .spacer { flex: 1; }
  #statusbar .pill {
    padding: 1px 7px;
    border: 1px solid var(--border-soft);
    border-radius: 999px;
    background: var(--panel);
  }
  #status-hint {
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 160px;
  }
  #statusbar .pill.ok    { border-color: #cbe1cc; background: #ecf6ed; color: #2c6b34; }
  #statusbar .pill.warn  { border-color: #f0d9b5; background: #fbf2e2; color: #8a5a16; }
  #statusbar .pill.error { border-color: #efc4c4; background: #fbeaea; color: #8a2a2a; }

  /* Report a problem: a quiet link at the end of the status bar */
  .report-link {
    flex: 0 0 auto; border: 0; background: none; padding: 0 2px; cursor: pointer;
    font-size: 11px; color: var(--text-muted);
  }
  .report-link:hover { color: var(--text-soft); text-decoration: underline; }
  .modal.report .body { display: grid; gap: 6px; }
  .modal.report label { font-weight: 600; font-size: 12px; }
  .modal.report .check { display: flex; align-items: center; gap: 6px; font-weight: 400; margin-top: 4px; }
  .modal.report textarea {
    min-height: 120px; font: 13px/1.45 -apple-system, "Segoe UI", "Inter", system-ui, sans-serif; margin-bottom: 6px;
  }
  .modal.report input[type=email] {
    padding: 6px 8px; border: 1px solid var(--border); border-radius: 3px; background: var(--field); margin-bottom: 4px;
  }
  .modal.report .muted { color: var(--text-muted); font-weight: 400; font-size: 11.5px; margin: 0; }
  .report-status { margin-right: auto; align-self: center; font-size: 12px; color: var(--text-soft); }
  .report-status.ok { color: #2c6b34; }
  .report-status.error { color: var(--overc); }
  .btn:disabled { opacity: 0.55; cursor: default; }

  /* ---------- App dialogs and notices (src/ui/dialogs.js) ---------- */
  .btn.danger { background: var(--overc); border-color: var(--overc); color: #fff; }
  .btn.danger:hover { background: #b92f2f; border-color: #b92f2f; }
  .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
  .modal-backdrop.app-dialog { z-index: 1200; animation: dialog-fade .12s ease-out; }
  .modal.app-dialog-box { width: 420px; animation: dialog-pop .14s ease-out; }
  .modal.app-dialog-box .body p { margin: 0; line-height: 1.5; color: var(--text-soft); }
  .modal.app-dialog-box .body { display: grid; gap: 8px; }
  .modal.app-dialog-box textarea { min-height: 90px; font: inherit; font-size: 13px; }
  .modal.app-dialog-box .footer { flex-wrap: wrap; }
  @keyframes dialog-fade { from { opacity: 0; } }
  @keyframes dialog-pop { from { opacity: 0; transform: translateY(6px) scale(.98); } }
  #app-notice {
    position: fixed; left: 50%; bottom: 44px; z-index: 1300; max-width: min(520px, calc(100vw - 32px));
    padding: 9px 14px; border-radius: 8px; background: #1b2028; color: #fff; font-size: 13px; line-height: 1.4;
    box-shadow: 0 8px 24px rgba(0,0,0,.22); pointer-events: none;
    opacity: 0; transform: translate(-50%, 8px); transition: opacity .18s, transform .18s;
  }
  #app-notice.show { opacity: 1; transform: translate(-50%, 0); }
  #app-notice[data-kind="error"] { background: #8f2424; }
  :root[data-theme="dark"] #app-notice { background: #e3e7ec; color: #15191f; }
  :root[data-theme="dark"] #app-notice[data-kind="error"] { background: #ff9c9c; color: #2c1717; }
  .compact #app-notice { bottom: calc(96px + env(safe-area-inset-bottom, 0px)); }
  @media (prefers-reduced-motion: reduce) {
    .modal-backdrop.app-dialog, .modal.app-dialog-box { animation: none; }
    #app-notice { transition: none; }
  }

  /* ---------- Start-up (html.booting until main.js has built the UI) ---------- */
  html.booting #menubar > :not(.brand),
  html.booting #optbar > *,
  html.booting #statusbar > *,
  html.booting .fwin,
  html.booting #mobilebar,
  html.booting #fab-delete { visibility: hidden; }
  #boot { display: none; }
  html.booting #boot {
    position: fixed; inset: 0; z-index: 5; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 12px; color: var(--text-muted); font-size: 13px; pointer-events: none;
    opacity: 0; animation: boot-in .25s ease-out .4s forwards;      /* only shows when loading is slow */
  }
  html.boot-slow #boot { pointer-events: auto; animation-delay: 0s; }
  #boot svg { width: 40px; height: 40px; animation: boot-pulse 1.4s ease-in-out infinite; }
  #boot a { color: var(--accent); }
  @keyframes boot-in { to { opacity: 1; } }
  @keyframes boot-pulse { 50% { opacity: .45; } }
  @keyframes ui-in { from { opacity: 0; } }
  html.ui-in #menubar > :not(.brand), html.ui-in #optbar > *, html.ui-in #statusbar > *, html.ui-in .fwin { animation: ui-in .2s ease-out; }
  @media (prefers-reduced-motion: reduce) {
    #boot svg { animation: none; }
    html.ui-in #menubar > :not(.brand), html.ui-in #optbar > *, html.ui-in #statusbar > *, html.ui-in .fwin { animation: none; }
  }

  /* ---------- Modal ---------- */
  .modal-backdrop {
    position: fixed; inset: 0;
    background: rgba(20,25,32,0.32);
    display: none;
    align-items: center; justify-content: center;
    z-index: 1000;
  }
  .modal-backdrop.show { display: flex; }
  .modal {
    background: var(--field);
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.18);
    width: 460px;
    max-width: 90vw;
    overflow: hidden;
    border: 1px solid var(--border);
  }
  .modal h3 {
    margin: 0; padding: 12px 16px;
    border-bottom: 1px solid var(--border-soft);
    font-size: 14px;
  }
  .modal .body { padding: 14px 16px; }
  .modal .footer {
    padding: 10px 16px;
    border-top: 1px solid var(--border-soft);
    display: flex; gap: 6px; justify-content: flex-end;
    background: var(--panel);
  }
  .modal textarea {
    width: 100%; min-height: 220px;
    font: 12px/1.4 ui-monospace, Menlo, Consolas, monospace;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 3px;
    resize: vertical;
  }
  .btn {
    padding: 6px 14px;
    border: 1px solid var(--border);
    background: var(--field);
    border-radius: 6px;
    cursor: pointer;
  }
  .btn:hover { background: var(--hover); }
  .btn.primary {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
  }
  .btn.primary:hover { background: #1d527f; }

  /* ---------- Account and cloud projects (cloud-ui.js) ---------- */
  #account-btn { gap: 6px; margin-left: 4px; }
  #account-btn[hidden] { display: none; }
  #account-btn .avatar {
    width: 24px; height: 24px; border-radius: 50%; flex: 0 0 auto;
    background: var(--accent); color: #fff; font-size: 12px; font-weight: 700;
    display: inline-flex; align-items: center; justify-content: center; object-fit: cover;
  }
  #account-btn .cloud-status { font-size: 11px; color: var(--text-muted); }
  #account-btn[data-status="offline"] .cloud-status,
  #account-btn[data-status="conflict"] .cloud-status { color: var(--overc); }
  .compact #account-btn { display: none; }
  /* Account menu (avatar ▾, cloud-ui.js) */
  #account-btn .am-caret { font-size: 10px; color: var(--text-muted); margin-left: -2px; }
  .account-menu {
    position: fixed; z-index: 1100; width: 260px; padding: 6px; display: flex; flex-direction: column;
    background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,0.18);
  }
  .account-menu[hidden] { display: none; }
  .am-head { display: flex; align-items: center; gap: 10px; padding: 8px 8px 6px; }
  .am-head .avatar {
    width: 34px; height: 34px; flex: 0 0 auto; border-radius: 50%; background: var(--accent); color: #fff; font-weight: 700;
    display: inline-flex; align-items: center; justify-content: center; object-fit: cover;
  }
  .am-who { display: flex; flex-direction: column; min-width: 0; }
  .am-who b, .am-who span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .am-who span { font-size: 12px; }
  .am-plan { font-size: 12px; padding: 0 8px 6px; border-bottom: 1px solid var(--border-soft); margin-bottom: 4px; }
  .am-plan:empty { display: none; }
  .am-item {
    display: block; width: 100%; text-align: left; padding: 7px 10px; border: 0; border-radius: 6px; background: none;
    color: var(--text); font: inherit; font-size: 13px; text-decoration: none; cursor: pointer;
  }
  .am-item:hover, .am-item:focus-visible { background: var(--hover); outline: none; }
  .account-menu .am-pro { color: var(--accent); font-weight: 600; }
  .am-sep { height: 1px; background: var(--border-soft); margin: 4px 2px; }
  /* Profile dialog */
  .username-row { display: flex; align-items: center; border: 1px solid var(--border); border-radius: 6px; background: var(--field); }
  .username-row:focus-within { outline: 2px solid var(--accent-border); border-color: var(--accent); }
  .username-row .at { padding: 0 2px 0 9px; color: var(--text-muted); }
  .modal.account .username-row input[type=text], .modal.account .username-row input[type=text]:focus { border: 0; outline: none; box-shadow: none; flex: 1; min-width: 0; background: transparent; padding-left: 2px; }
  .username-hint { font-size: 12px; min-height: 1.2em; }
  .username-hint[data-state="good"] { color: #2c8a3a; }
  .username-hint[data-state="bad"] { color: var(--overc); }
  .picture-opt img { width: 22px; height: 22px; border-radius: 50%; object-fit: cover; }
  /* File group: New / Open / Save with their text, and the save status */
  #menubar .file-btn { gap: 6px; padding: 0 10px; }
  #menubar .file-btn[hidden] { display: none; }
  #menubar .file-btn .btn-label { display: inline !important; font-size: 12.5px; }
  .save-state { font-size: 11.5px; color: var(--text-muted); white-space: nowrap; min-width: 0; padding: 0 2px 0 4px; }
  .save-state:empty { display: none; }
  .save-state[data-state="saved"]::before { content: "✓ "; color: #2c8a3a; }
  .save-state[data-state="unsaved"] { color: var(--text-soft); }
  .save-state[data-state="offline"], .save-state[data-state="conflict"] { color: var(--overc); }
  @media (max-width: 900px) { #menubar .file-btn .btn-label { display: none !important; } }
  .modal.account .footer .spacer { flex: 1; }
  .modal.account .footer .link { align-self: center; margin-right: 10px; font-size: 12.5px; }
  .open-list { list-style: none; margin: 0; padding: 0; max-height: min(60vh, 440px); overflow: auto; display: grid; gap: 4px; }
  .open-item {
    width: 100%; display: flex; align-items: center; gap: 10px; padding: 6px; text-align: left; cursor: pointer;
    border: 1px solid transparent; border-radius: 8px; background: none; color: inherit; font: inherit;
  }
  .open-item:hover, .open-item:focus-visible { background: var(--hover); border-color: var(--border-soft); outline: none; }
  .open-item.current { background: var(--accent-softer); border-color: var(--accent-border); }
  .open-thumb { flex: 0 0 auto; width: 88px; height: 55px; border-radius: 6px; border: 1px solid var(--border-soft); background: #fff; overflow: hidden; }
  .open-thumb img { width: 100%; height: 100%; object-fit: contain; display: block; }
  .open-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
  .open-text b { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .open-text .muted { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .open-when { flex: 0 0 auto; font-size: 11px; }
  .open-empty { padding: 18px 8px; text-align: center; }
  .modal.account .body { display: grid; gap: 8px; }
  .modal.account p { margin: 0; }
  .modal.account label { font-weight: 600; font-size: 12px; }
  .modal.account input[type=email], .modal.account input[type=text] {
    padding: 7px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--field); color: inherit; font-size: 13px;
  }
  .modal.account .muted { color: var(--text-muted); font-size: 12px; }
  .modal.account .btn.oauth { display: flex; align-items: center; justify-content: center; gap: 8px; }
  .modal.account .or { display: flex; align-items: center; gap: 8px; color: var(--text-muted); font-size: 11px; }
  .modal.account .or::before, .modal.account .or::after { content: ""; flex: 1; border-top: 1px solid var(--border-soft); }
  .modal.account .link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font-size: 12px; justify-self: start; }
  .modal.account .link:hover { text-decoration: underline; }
  .account-msg { min-height: 1em; font-size: 12px; color: var(--text-soft); }
  .account-msg.error, .project-list .error { color: var(--overc); }
  .account-who { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12px; }
  .account-current { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px; border-radius: 6px; background: var(--panel); }
  .project-list { list-style: none; margin: 0; padding: 0; max-height: min(50vh, 360px); overflow: auto; border: 1px solid var(--border-soft); border-radius: 6px; }
  .project-list li { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-top: 1px solid var(--border-soft); }
  .project-list li:first-child { border-top: 0; }
  .project-list li.current { background: var(--hover); }
  .project-list .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
  .project-list .when { font-size: 11px; color: var(--text-muted); white-space: nowrap; }
  .project-list .btn { padding: 4px 10px; }
  .project-list .btn.icon { padding: 4px 8px; }
  .modal.account .footer { flex-wrap: wrap; }
  .account-plan { font-size: 12px; }
  .account-plan b { color: var(--text); }
  .modal.account .account-page { text-align: center; text-decoration: none; }
  .modal.account textarea {
    min-height: 74px; font: inherit; font-size: 13px; padding: 7px 8px;
    border: 1px solid var(--border); border-radius: 6px; background: var(--field); color: inherit; resize: vertical;
  }
  .modal.account .check { display: flex; align-items: center; gap: 6px; font-weight: 400; }
  .modal.details .counter { float: right; font-weight: 400; color: var(--text-muted); }
  .modal.details .counter.short { color: var(--overc); }
  .details-preview { border: 1px solid var(--border-soft); border-radius: 8px; overflow: hidden; background: #fff; aspect-ratio: 16 / 10; }
  .details-preview canvas, .details-preview img { display: block; width: 100%; height: 100%; object-fit: contain; }
  .details-note b { color: var(--text-soft); }

  /* ---------- My sketches page (app/projects/) ---------- */
  body.page { height: auto; min-height: 100%; overflow: auto; background: var(--bg); color: var(--text); font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif; }
  .page-bar {
    position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 12px;
    padding: 10px max(16px, calc((100% - 1120px) / 2)); background: var(--panel-2); border-bottom: 1px solid var(--border);
  }
  .page-bar .brand { font-weight: 800; font-size: 17px; color: var(--text); text-decoration: none; }
  .page-bar .brand b { color: var(--accent); }
  .page-bar h1 { margin: 0; font-size: 15px; font-weight: 600; color: var(--text-soft); padding-left: 12px; border-left: 1px solid var(--border); }
  .page-bar .spacer { flex: 1; }
  .page-bar .btn { text-decoration: none; color: var(--text); white-space: nowrap; }
  .page-account { display: flex; align-items: center; gap: 8px; font-size: 13px; }
  .page-account .avatar {
    width: 28px; height: 28px; border-radius: 50%; background: var(--accent); color: #fff; font-weight: 700; font-size: 13px;
    display: inline-flex; align-items: center; justify-content: center; object-fit: cover;
  }
  .page-account .who { color: var(--text-soft); max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .page .link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font: inherit; }
  .page .link:hover { text-decoration: underline; }
  .page-main { max-width: 1120px; margin: 0 auto; padding: 22px 16px 48px; }
  .page-msg { color: var(--text-soft); }
  .page-msg[hidden] { display: none; }
  .usage {
    display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; padding: 10px 14px;
    background: var(--panel-2); border: 1px solid var(--border-soft); border-radius: 10px; color: var(--text-soft);
  }
  .usage b { color: var(--text); }
  .meter { flex: 0 1 220px; height: 8px; border-radius: 4px; background: var(--border-soft); overflow: hidden; }
  .meter > span { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
  .meter.full > span { background: var(--selected); }
  .sketches { list-style: none; margin: 0; padding: 0; display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
  .sketch-card {
    display: flex; flex-direction: column; min-width: 0; background: var(--panel-2); border: 1px solid var(--border-soft);
    border-radius: 12px; box-shadow: var(--shadow-soft); transition: border-color .15s, box-shadow .15s;
  }
  .sketch-card[data-id]:hover { border-color: var(--accent-border); box-shadow: 0 4px 14px rgba(18, 25, 38, 0.08); }
  .sketch-card .thumb { position: relative; display: block; aspect-ratio: 16 / 10; background: #fff; border-bottom: 1px solid var(--border-soft); border-radius: 12px 12px 0 0; overflow: hidden; }
  .sketch-card .thumb img { display: block; width: 100%; height: 100%; object-fit: contain; }
  .thumb-empty { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; color: #b4bcc6; font-size: 12px; }
  .thumb-empty svg { width: 42px; height: 42px; }
  .sketch-card .card-body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
  .card-title-row { position: relative; display: flex; align-items: center; gap: 6px; }
  .card-title { flex: 1; min-width: 0; margin: 0; font-size: 15px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .card-title a { color: var(--text); text-decoration: none; }
  .card-title a:hover { color: var(--accent); }
  .menu-btn { width: 30px; height: 28px; border: 1px solid transparent; border-radius: 6px; background: none; color: var(--text-soft); font-size: 18px; line-height: 1; cursor: pointer; }
  .menu-btn:hover { background: var(--hover); border-color: var(--border-soft); }
  .card-desc { margin: 0; color: var(--text-soft); font-size: 13px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 2.9em; }
  .card-desc .missing { color: var(--text-muted); font-style: italic; }
  .card-meta { margin-top: auto; padding-top: 6px; display: flex; align-items: center; justify-content: space-between; font-size: 12px; color: var(--text-muted); }
  .tag { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; border: 1px solid var(--border-soft); }
  .tag.public { color: #2c6b34; background: #eaf6ec; border-color: #cfe8d3; }
  .tag.private { color: var(--text-soft); background: var(--panel); }
  .tag.open { position: absolute; left: 8px; top: 8px; color: #fff; background: var(--accent); border-color: var(--accent); }
  :root[data-theme="dark"] .tag.public { color: #8fd49a; background: #18291c; border-color: #2c5a35; }
  .card-menu {
    position: absolute; right: 0; top: 32px; z-index: 5; min-width: 160px; padding: 4px; display: flex; flex-direction: column;
    background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,0.16);
  }
  .card-menu button { text-align: left; padding: 7px 10px; border: 0; border-radius: 5px; background: none; color: var(--text); font: inherit; cursor: pointer; }
  .card-menu button:hover, .card-menu button:focus-visible { background: var(--hover); outline: none; }
  .card-menu .danger { color: var(--overc); }
  .sketch-card.new { border-style: dashed; background: transparent; box-shadow: none; min-height: 220px; }
  .sketch-card.new a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; color: var(--text-soft); text-decoration: none; border-radius: 12px; }
  .sketch-card.new a:hover { color: var(--accent); background: var(--accent-softer); }
  .sketch-card.new .plus { font-size: 34px; line-height: 1; font-weight: 300; }
  .sketch-card.new .muted { font-size: 12px; color: var(--text-muted); }
  .sketch-card.upsell { padding: 18px; justify-content: center; gap: 8px; min-height: 220px; background: var(--accent-softer); border-color: var(--accent-border); }
  .sketch-card.upsell h2 { margin: 0; font-size: 16px; }
  .sketch-card.upsell p { margin: 0; color: var(--text-soft); font-size: 13px; }
  .sketch-card.upsell .btn { align-self: flex-start; }
  .empty-state { text-align: center; padding: 40px 16px; color: var(--text-soft); }
  .empty-state.wide { grid-column: 1 / -1; padding: 18px 16px 6px; }
  .empty-state h2 { margin: 0 0 6px; font-size: 19px; color: var(--text); }
  .empty-state p { margin: 0 0 14px; }
  .empty-state .btn { text-decoration: none; display: inline-block; }
  .empty-mark { width: 54px; height: 54px; margin: 0 auto 12px; color: var(--accent); }
  /* ---------- Library page (library/) ---------- */
  .lib-intro { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px 24px; flex-wrap: wrap; margin-bottom: 20px; }
  .lib-intro h2 { margin: 0 0 4px; font-size: 24px; letter-spacing: -0.3px; }
  .lib-intro p { margin: 0; max-width: 560px; color: var(--text-soft); }
  .lib-search { display: flex; gap: 8px; flex: 0 1 420px; }
  .lib-search input, .lib-search select {
    padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--field); color: inherit; font: inherit;
  }
  .lib-search input { flex: 1; min-width: 0; }
  .lib-search input:focus, .lib-search select:focus { outline: 2px solid var(--accent-border); border-color: var(--accent); }
  .lib-card { cursor: pointer; }
  .lib-card .card-title { white-space: normal; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; }
  .author { display: inline-flex; align-items: center; gap: 6px; min-width: 0; color: var(--text-muted); font-size: 12px; }
  .author .author-name { color: var(--text-soft); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 140px; }
  .author .avatar {
    width: 20px; height: 20px; flex: 0 0 auto; border-radius: 50%; background: var(--accent); color: #fff; font-size: 10px; font-weight: 700;
    display: inline-flex; align-items: center; justify-content: center; object-fit: cover;
  }
  .author.big { font-size: 13px; }
  .author.big .avatar { width: 28px; height: 28px; font-size: 13px; }
  .author.big .author-name { max-width: 260px; font-size: 14px; }
  .like-btn {
    display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border: 1px solid var(--border-soft); border-radius: 999px;
    background: var(--field); color: var(--text-soft); font: inherit; font-size: 12px; font-weight: 600; cursor: pointer; flex: 0 0 auto;
  }
  .like-btn svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; }
  .like-btn:hover:not(:disabled) { border-color: var(--accent-border); color: var(--accent); }
  .like-btn.on { color: var(--accent); border-color: var(--accent-border); background: var(--accent-softer); }
  .like-btn.on svg { fill: currentColor; fill-opacity: 0.18; }
  .like-btn:disabled { cursor: default; opacity: 0.7; }
  .lib-detail-by { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 2px 0 4px; }
  .lib-card .card-meta { gap: 8px; }
  .usage-name { margin-left: auto; font-size: 13px; }
  .usage-name a { color: var(--accent); }
  .card-tags { display: inline-flex; align-items: center; gap: 6px; }
  .likes-pill { font-size: 11px; font-weight: 600; color: var(--text-soft); }
  /* Profile mode of the library (/library/?u=<username>) */
  .lib-profile { margin-bottom: 22px; }
  .lib-profile[hidden] { display: none; }
  .lp-back { display: inline-block; margin-bottom: 10px; color: var(--text-soft); font-size: 13px; text-decoration: none; }
  .lp-back:hover { color: var(--accent); }
  .lp-card { display: flex; align-items: flex-start; gap: 18px; padding: 20px; border: 1px solid var(--border-soft); border-radius: 14px; background: var(--panel-2); }
  .lp-avatar { width: 72px; height: 72px; flex: 0 0 auto; border-radius: 50%; object-fit: cover; background: #2563a5; color: #fff;
    font-size: 30px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }
  .lp-main { flex: 1; min-width: 0; }
  .lp-main h2 { margin: 2px 0 6px; font-size: 22px; letter-spacing: -0.3px; overflow-wrap: anywhere; }
  .lp-bio { margin: 0 0 8px; color: var(--text-soft); line-height: 1.5; white-space: pre-line; overflow-wrap: anywhere; }
  .lp-facts { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 0; font-size: 13px; color: var(--text-muted); }
  .lp-facts a { color: var(--accent); overflow-wrap: anywhere; }
  .lp-stats { display: flex; gap: 18px; flex: 0 0 auto; }
  .lp-stats div { display: flex; flex-direction: column; align-items: center; min-width: 64px; }
  .lp-stats b { font-size: 22px; }
  .lp-stats span { font-size: 12px; color: var(--text-muted); }
  .lp-mine { margin: 10px 2px 0; font-size: 13px; }
  .lp-mine a { color: var(--accent); }
  .lp-empty { text-align: center; padding: 40px 16px; }
  .lp-empty h2 { margin: 0 0 6px; }
  .lp-empty a { color: var(--accent); }
  a.author-name { text-decoration: none; }
  a.author-name:hover { color: var(--accent); text-decoration: underline; }
  @media (max-width: 640px) {
    .lp-card { flex-wrap: wrap; gap: 14px; padding: 16px; }
    .lp-avatar { width: 56px; height: 56px; font-size: 24px; }
    .lp-stats { width: 100%; justify-content: flex-start; border-top: 1px solid var(--border-soft); padding-top: 10px; }
  }
  /* Profile dialog: country + website side by side */
  .profile-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  .profile-row > div { display: grid; gap: 6px; min-width: 0; }
  .modal.account select, .modal.account input[type=url] {
    padding: 7px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--field); color: inherit; font: inherit; font-size: 13px; min-width: 0; width: 100%;
  }
  .modal.profile .counter { float: right; font-weight: 400; color: var(--text-muted); }
  .profile-public-note { font-size: 12px; margin: 0; }
  .modal.profile .footer .profile-view { align-self: center; font-size: 12.5px; }
  @media (max-width: 480px) { .profile-row { grid-template-columns: 1fr; } }
  .lib-more { display: flex; justify-content: center; margin-top: 22px; }
  .lib-more .btn[hidden] { display: none; }
  .page-foot { max-width: 1120px; margin: 0 auto; padding: 8px 16px 40px; font-size: 12px; color: var(--text-muted); }
  .page-foot a { color: inherit; }
  .modal.lib-detail { width: 720px; max-height: calc(100vh - 32px); overflow: auto; }
  .lib-detail-thumb { position: relative; aspect-ratio: 16 / 10; background: #fff; border-bottom: 1px solid var(--border-soft); }
  .lib-detail-thumb img { display: block; width: 100%; height: 100%; object-fit: contain; }
  .modal.lib-detail h3 { padding: 0; border: 0; margin: 0 0 6px; font-size: 20px; }
  .modal.lib-detail .body { display: grid; gap: 6px; }
  .modal.lib-detail .body p { margin: 0; }
  .lib-detail-desc { color: var(--text-soft); white-space: pre-line; font-size: 14px; }
  .modal.lib-detail .footer { align-items: center; flex-wrap: wrap; }
  .modal.lib-detail .footer .btn { text-decoration: none; color: inherit; }
  .modal.lib-detail .footer .btn.primary { color: #fff; }
  .lib-report { margin-right: auto; font-size: 12px; color: var(--text-muted) !important; }
  .lib-detail .account-msg { min-height: 1em; font-size: 12px; color: var(--text-soft); }
  /* ---------- Pricing page (pricing/) ---------- */
  .pricing { max-width: 920px; }
  .pr-intro { text-align: center; margin: 12px auto 26px; max-width: 640px; }
  .pr-intro h2 { margin: 0 0 8px; font-size: 28px; letter-spacing: -0.4px; }
  .pr-intro p { margin: 0 0 18px; color: var(--text-soft); font-size: 15px; }
  .pr-toggle { display: inline-flex; padding: 3px; border: 1px solid var(--border); border-radius: 999px; background: var(--panel-2); }
  .pr-toggle button { border: 0; background: none; padding: 7px 16px; border-radius: 999px; font: inherit; font-weight: 600; color: var(--text-soft); cursor: pointer; }
  .pr-toggle button[aria-checked="true"] { background: var(--accent); color: #fff; }
  .pr-save { font-size: 11px; font-weight: 700; padding: 1px 6px; margin-left: 4px; border-radius: 999px; background: #e3f4e6; color: #2c6b34; }
  .pr-plans { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: stretch; }
  .pr-card { position: relative; display: flex; flex-direction: column; padding: 24px; border: 1px solid var(--border-soft); border-radius: 14px; background: var(--panel-2); }
  .pr-card.pro { border: 2px solid var(--accent); box-shadow: 0 10px 30px rgba(37, 99, 165, 0.12); }
  .pr-badge { position: absolute; top: -12px; left: 24px; padding: 2px 10px; border-radius: 999px; background: var(--accent); color: #fff; font-size: 12px; font-weight: 700; }
  .pr-card h3 { margin: 0 0 8px; font-size: 18px; }
  .pr-price { display: flex; align-items: baseline; gap: 8px; }
  .pr-price b { font-size: 38px; letter-spacing: -1px; }
  .pr-price span { color: var(--text-muted); }
  .pr-sub, .pr-lead { margin: 4px 0 14px; color: var(--text-soft); font-size: 13px; min-height: 1.4em; }
  .pr-list { list-style: none; margin: 0 0 20px; padding: 0; display: grid; gap: 9px; flex: 1; }
  .pr-list li { position: relative; padding-left: 24px; color: var(--text-soft); font-size: 14px; line-height: 1.45; }
  .pr-list li::before { content: "✓"; position: absolute; left: 2px; color: var(--accent); font-weight: 700; }
  .pr-list b { color: var(--text); }
  .pr-cta .btn { display: block; width: 100%; text-align: center; padding: 10px 14px; font-weight: 600; text-decoration: none; }
  .pr-cta a.btn:not(.primary) { color: var(--text); }
  .pr-cta .btn:disabled { opacity: .7; }
  .pr-current { display: block; text-align: center; padding: 10px; font-weight: 700; color: #2c8a3a; }
  .pr-note { margin: 8px 0 0; text-align: center; font-size: 12px; color: var(--text-muted); }
  .pr-banner { margin: 0 0 18px; padding: 12px 16px; border-radius: 10px; background: var(--accent-softer); border: 1px solid var(--accent-border); }
  .pr-banner.ok { background: #e9f6ec; border-color: #c4e5cb; color: #1f5a2a; }
  .pr-banner.warn { background: #fff4e0; border-color: #f0d49a; color: #6a4a10; }
  .pr-banner[hidden] { display: none; }
  :root[data-theme="dark"] .pr-banner.ok { background: #18291c; border-color: #2c5a35; color: #8fd49a; }
  :root[data-theme="dark"] .pr-banner.warn { background: #2a2214; border-color: #6a5121; color: #f0c56f; }
  :root[data-theme="dark"] .pr-save { background: #18291c; color: #8fd49a; }
  .pr-faq { margin: 40px auto 0; max-width: 680px; }
  .pr-faq h2 { font-size: 20px; margin: 0 0 10px; }
  .pr-faq details { border-top: 1px solid var(--border-soft); padding: 12px 2px; }
  .pr-faq details:last-child { border-bottom: 1px solid var(--border-soft); }
  .pr-faq summary { cursor: pointer; font-weight: 600; }
  .pr-faq p { margin: 8px 0 0; color: var(--text-soft); line-height: 1.55; }
  @media (max-width: 720px) { .pr-plans { grid-template-columns: 1fr; gap: 26px; } .pr-intro h2 { font-size: 23px; } }
  @media (max-width: 640px) {
    .page-bar { gap: 8px; flex-wrap: wrap; }
    .page-bar h1 { display: none; }
    .page-account .who { display: none; }
    .sketches { grid-template-columns: 1fr; }
    .lib-search { flex: 1 1 100%; }
    .page-bar .hide-sm { display: none; }
    .modal.lib-detail { max-width: calc(100vw - 16px); }
  }

  /* Cursor hint */
  #cursor-hint {
    position: absolute;
    pointer-events: none;
    background: rgba(28,32,38,0.86);
    color: white;
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 3px;
    white-space: nowrap;
    transform: translate(12px, 14px);
    z-index: 20;
    display: none;
  }

  #context-menu {
    position: fixed;
    min-width: 170px;
    max-width: 260px;
    max-height: 260px;
    overflow-y: auto;
    padding: 5px;
    background: var(--field);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 10px 28px rgba(15, 23, 42, 0.18);
    z-index: 40;
  }
  .context-menu-item {
    width: 100%;
    border: 0;
    background: transparent;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 7px 8px;
    border-radius: 6px;
    font: 12px ui-sans-serif, system-ui, -apple-system, Segoe UI, sans-serif;
    text-align: left;
    cursor: pointer;
  }
  .unit-row { display: flex; align-items: center; gap: 6px; min-width: 0; }
  .unit-row input { flex: 1; min-width: 0; }
  .unit-row span { font-size: 11px; color: var(--text-soft); }
  .context-menu-head { padding: 4px 8px 2px; font-size: 10.5px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-muted); }
  .context-menu-sep { height: 1px; margin: 4px 2px; background: var(--border-soft); }
  .context-menu-item.action .glyph { font-weight: 400; }
  .context-menu-item:hover {
    background: var(--accent-softer);
    color: var(--accent);
  }
  .context-menu-item .glyph {
    width: 16px;
    flex: 0 0 16px;
    color: var(--text-soft);
    text-align: center;
    font-weight: 700;
  }
  .context-menu-item:hover .glyph { color: var(--accent); }
  .context-menu-item .meta {
    margin-left: auto;
    color: var(--text-muted);
    font-size: 10px;
  }

  /* ---------- Dark theme overrides for literal accent tints ---------- */
  :root[data-theme="dark"] .rel-btn:hover,
  :root[data-theme="dark"] .tbtn:hover { border-color: var(--accent-border); }
  :root[data-theme="dark"] #statusbar .pill.ok    { border-color: #2c5a35; background: #18291c; color: #8fd49a; }
  :root[data-theme="dark"] #statusbar .pill.warn  { border-color: #6a5121; background: #2a2214; color: #f0c56f; }
  :root[data-theme="dark"] #statusbar .pill.error { border-color: #6b2e2e; background: #2c1717; color: #ff9c9c; }

  #layer-list { flex: 1; overflow-y: auto; padding: 4px 0; }
  .lyr-row {
    display: grid;
    grid-template-columns: 24px minmax(0, 1fr) auto;
    align-items: center;
    gap: 3px;
    padding: 3px 8px 3px 4px;
    margin: 2px 6px;
    border-radius: 6px;
    border: 1px solid transparent;
    cursor: pointer;
  }
  .lyr-row:hover { background: var(--hover); border-color: var(--border-soft); }
  .lyr-row.active { background: var(--accent-softer); border-color: var(--accent-border); }
  .lyr-row.hidden-layer .name, .lyr-row.hidden-layer .count { opacity: 0.5; }
  .lyr-row .icon-btn.on { color: var(--accent); }
  .lyr-row .name {
    font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    padding: 3px 2px; min-width: 0;
  }
  .lyr-row .name[contenteditable="true"] {
    background: var(--field); border: 1px solid var(--accent); border-radius: 4px; outline: none;
  }
  .lyr-row .count { font-size: 10px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
  .lyr-swatch {
    position: relative;
    width: 18px; height: 18px;
    border-radius: 4px;
    background: var(--sw);
    border: 1px solid color-mix(in srgb, var(--text) 25%, transparent);
    cursor: pointer;
    overflow: hidden;
  }
  .lyr-swatch input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; border: 0; padding: 0; }
  .lyr-fill {
    position: absolute; right: 0; bottom: 0; width: 8px; height: 8px;
    background: var(--fl); border-top-left-radius: 3px;
    border-left: 1px solid var(--panel); border-top: 1px solid var(--panel);
    pointer-events: none;
  }

  .swatches {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 4px;
    margin-bottom: 4px;
  }
  .swatches .sw {
    position: relative;
    aspect-ratio: 1;
    min-width: 0;
    padding: 0;
    border-radius: 5px;
    border: 1px solid color-mix(in srgb, var(--text) 22%, transparent);
    background: var(--sw);
    cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
  }
  .swatches .sw:hover { transform: scale(1.08); }
  .swatches .sw.on { outline: 2px solid var(--accent); outline-offset: 1px; }
  .swatches .sw-none { background: var(--field); color: var(--text-muted); }
  .swatches .sw-none svg { width: 14px; height: 14px; }
  .swatches .sw-custom {
    background: conic-gradient(from 0deg, #e53935, #fdd835, #43a047, #1e88e5, #8e24aa, #e53935);
    overflow: hidden;
  }
  .swatches .sw-custom.on::after {
    content: ""; position: absolute; inset: 4px; border-radius: 3px; background: var(--sw);
    border: 1px solid var(--panel);
  }
  .swatches .sw-custom input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; border: 0; padding: 0; }

  .fwin select, #optbar select {
    width: 100%;
    padding: 4px 6px;
    border: 1px solid var(--border);
    border-radius: 5px;
    background: var(--field);
    min-width: 0;
  }
  .range-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
  .range-row input[type=range] { flex: 1; min-width: 0; accent-color: var(--accent); }
  .range-row span { font-size: 11px; color: var(--text-soft); width: 34px; text-align: right; font-variant-numeric: tabular-nums; }
  .link-btn {
    border: 0; background: none; padding: 0 0 0 4px;
    color: var(--accent); font-size: 10px; text-transform: none; letter-spacing: 0;
    cursor: pointer; text-decoration: underline; font-weight: 500;
  }


  .sb-section[hidden] { display: none; }

  #layer-props { padding: 2px 12px 8px; border-top: 1px solid var(--border-soft); }
  .check-row { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-soft); padding: 6px 0 2px; cursor: pointer; }
  .check-row input { accent-color: var(--accent); }
  .sw-dot {
    display: inline-block; width: 14px; height: 14px; border-radius: 4px; background: var(--sw);
    border: 1px solid color-mix(in srgb, var(--text) 25%, transparent);
  }

  /* ---------- Menu bar ---------- */
  #menubar .brand {
    font-weight: 600; letter-spacing: -0.01em; font-size: 15px;
    padding: 0 10px 0 4px; color: var(--text); flex: 0 0 auto;
  }
  #menubar .brand b { color: var(--accent); font-weight: 700; }
  #menubar .group { height: 34px; padding-right: 8px; }
  #menubar .spacer { flex: 1; }
  #menubar .tbtn svg, #optbar .tbtn svg { width: 18px; height: 18px; flex: 0 0 auto; }
  #project-name {
    width: 180px; flex: 0 1 180px; min-width: 90px;
    padding: 5px 8px; border: 1px solid var(--border-soft); border-radius: 6px;
    background: var(--field); font-size: 12px;
  }
  #project-name:focus { outline: 1px solid var(--accent); border-color: var(--accent); }
  #menubar .units { font-size: 11px; color: var(--text-muted); margin-left: -2px; }

  /* ---------- Tool options bar ---------- */
  #optbar {
    grid-area: optbar;
    display: flex; align-items: center; gap: 10px;
    padding: 0 12px;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    font-size: 12px; color: var(--text-soft);
    overflow-x: auto; overflow-y: hidden; white-space: nowrap;
  }
  #optbar .tbtn { height: 28px; }
  .opt-tool { display: inline-flex; align-items: center; gap: 7px; color: var(--text); min-width: 150px; }
  .opt-tool svg { width: 18px; height: 18px; color: var(--accent); }
  .opt-sep { width: 1px; height: 20px; background: var(--border-soft); flex: 0 0 auto; }
  .opt { display: inline-flex; align-items: center; gap: 6px; }
  .opt select, .opt input[type=number] {
    padding: 3px 6px; border: 1px solid var(--border); border-radius: 5px; background: var(--field);
  }
  .opt input[type=number] { width: 58px; }
  .opt-sw, .pc-legend i {
    display: inline-block; width: 16px; height: 16px; border-radius: 4px; background: var(--sw);
    border: 1px solid color-mix(in srgb, var(--text) 25%, transparent);
  }
  .opt-hint { color: var(--text-muted); }
  .opt-hint b { color: var(--accent); }
  .seg { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
  .seg button { border: 0; background: var(--field); padding: 4px 10px; cursor: pointer; font-size: 12px; }
  .seg button + button { border-left: 1px solid var(--border); }
  .seg button.on { background: var(--accent); color: #fff; }

  /* ---------- Floating windows ---------- */
  .fwin {
    position: absolute;
    z-index: 10;
    display: flex; flex-direction: column;
    background: color-mix(in srgb, var(--panel) 96%, transparent);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(15, 20, 30, 0.18), 0 1px 3px rgba(15, 20, 30, 0.12);
    backdrop-filter: blur(6px);
    overflow: hidden;
    max-height: calc(100% - 16px);
  }
  .fwin[hidden] { display: none; }
  .fwin.dragging { opacity: 0.92; box-shadow: 0 16px 40px rgba(15, 20, 30, 0.28); }
  .fwin-head {
    display: flex; align-items: center; gap: 6px;
    padding: 5px 6px 5px 10px;
    font-size: 10px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
    color: var(--text-soft);
    background: var(--panel-head);
    border-bottom: 1px solid var(--border-soft);
    cursor: grab; user-select: none; touch-action: none;
  }
  .fwin.dragging .fwin-head { cursor: grabbing; }
  .fwin-head > span:first-child { flex: 1; }
  .fwin-head .badge {
    text-transform: none; letter-spacing: 0; font-weight: 500;
    border: 1px solid var(--border-soft); border-radius: 999px; padding: 0 6px; font-size: 10px;
  }
  .fwin-actions { display: inline-flex; gap: 1px; }
  .fwin-actions .icon-btn { width: 22px; height: 22px; }
  .fwin-x {
    width: 22px; height: 22px; border: 0; background: transparent; border-radius: 5px;
    color: var(--text-muted); font-size: 16px; line-height: 1; cursor: pointer;
  }
  .fwin-x:hover { background: var(--hover); color: var(--text); }
  .fwin-body { padding: 8px; min-height: 0; }
  .fwin-scroll { overflow-y: auto; }
  .fwin[data-win="tools"]  { width: 132px; }
  .fwin[data-win="colors"] { width: 212px; }
  .fwin[data-win="layers"] { width: 240px; }
  .fwin[data-win="props"]  { width: 280px; max-height: calc(100% - 228px); }
  .fwin[data-win="layers"] .fwin-body { padding: 4px 0 0; }
  #layer-list { max-height: 220px; }

  /* Tools window */
  .tool-grid { display: grid; grid-template-columns: repeat(3, 36px); gap: 4px; justify-content: center; }
  .tool-sep { height: 1px; background: var(--border-soft); margin: 7px 2px; }
  .tool-btn {
    width: 36px; height: 34px; padding: 0;
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    border: 1px solid transparent; border-radius: 7px; background: transparent;
    color: var(--text); cursor: pointer;
  }
  .tool-btn svg { width: 19px; height: 19px; }
  .tool-btn:hover { background: var(--hover); border-color: var(--border-soft); }
  .tool-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
  .tool-wide { width: 100%; justify-content: flex-start; padding: 0 8px; font-size: 12px; font-weight: 600; }
  .tool-dim { border-color: var(--accent-border); background: var(--accent-softer); color: var(--accent); height: 38px; justify-content: center; }

  /* Colors window: primary / secondary chips like Paint.NET */
  .pc-wrap { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
  .pc { position: relative; width: 64px; height: 56px; flex: 0 0 auto; }
  .pc-sw {
    position: absolute; width: 38px; height: 38px; border-radius: 7px;
    background: var(--sw); border: 2px solid var(--panel);
    box-shadow: 0 0 0 1px color-mix(in srgb, var(--text) 30%, transparent);
    cursor: pointer; overflow: hidden;
  }
  .pc-sw input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; border: 0; padding: 0; }
  .pc-primary { left: 0; top: 0; z-index: 2; }
  .pc-secondary { left: 22px; top: 16px; z-index: 1; }
  .pc-swap {
    position: absolute; right: -4px; top: -4px; width: 18px; height: 18px; padding: 0;
    border: 0; background: none; color: var(--text-soft); cursor: pointer; font-size: 12px;
  }
  .pc-legend { display: grid; gap: 4px; font-size: 11px; color: var(--text-soft); }
  .pc-legend span { display: inline-flex; align-items: center; gap: 6px; }
  .palette { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; margin-bottom: 6px; }
  .palette .sw {
    aspect-ratio: 1; padding: 0; border-radius: 5px; cursor: pointer; background: var(--sw);
    border: 1px solid color-mix(in srgb, var(--text) 22%, transparent);
  }
  .palette .sw:hover { transform: scale(1.08); }
  /* Sketch window: Fill, Pen, Marker, Arrow, Text, Eraser in one row */
  .fwin[data-win="sketch"] .fwin-body { width: 260px; }
  .sketch-grid { grid-template-columns: repeat(6, 36px); }
  .image-import-btn { display: flex; align-items: center; justify-content: center; gap: 6px; width: 100%; margin-top: 6px; padding: 5px 8px; font-size: 12px; }
  .image-import-btn svg { flex: none; }
  .arrow-seg button, #sketch-body .seg.arrow-seg button { padding: 3px 6px; line-height: 0; }
  .arrow-seg svg { display: block; }
  /* Text settings in the Sketch window: narrow label column, segments fit */
  #sketch-body .prop-row { grid-template-columns: 62px minmax(0, 1fr); }
  #sketch-body .seg button { padding: 4px 8px; }
  .prop-row .seg { justify-self: start; max-width: 100%; }
  /* Colors window: the highlighted chip is what the palette sets */
  .pc-sw.pc-one { position: relative; width: 44px; height: 44px; flex: 0 0 auto; }
  .pc-legend span.on { color: var(--text); }
  .pc-legend b { font-weight: 600; min-width: 26px; display: inline-block; }
  .palette .sw.on { outline: 2px solid var(--accent); outline-offset: 1px; }
  #optbar input[type=range] { width: 110px; accent-color: var(--accent); vertical-align: middle; }
  .opt-val { display: inline-block; min-width: 40px; font-size: 11px; color: var(--text-soft); font-variant-numeric: tabular-nums; }
  .hint { font-size: 10.5px; color: var(--text-muted); line-height: 1.35; margin-top: 4px; }

  /* Properties window */
  .fwin[data-win="props"] .sb-tool-options {
    border-left: 3px solid var(--accent); padding-left: 8px; margin-bottom: 10px;
  }

  @media (max-width: 1400px) {
    #menubar [data-action="grid"] .btn-label,
    #menubar [data-action="snap"] .btn-label,
    #menubar [data-action="color-mode"] .btn-label { display: none; }
    #project-name { width: 130px; flex-basis: 130px; }
  }
  @media (max-width: 1100px) {
    #menubar .btn-label { display: none; }
    #menubar .units { display: none; }
  }

  /* ---------- Dimension value input + Equations window ---------- */
  .dim-input {
    position: absolute; z-index: 30; transform: translate(-50%, -50%);
    padding: 3px 6px; border: 1.5px solid var(--accent); border-radius: 4px;
    background: var(--field); color: var(--text); caret-color: var(--accent);
    font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; text-align: right; outline: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  }
  /* Text tool: the inline editor sits exactly where the text is drawn */
  .text-edit {
    position: absolute; z-index: 30; margin: 0; padding: 0;
    border: 0; outline: 1.5px dashed var(--accent); outline-offset: 3px; border-radius: 1px;
    background: transparent; resize: none; overflow: hidden; white-space: pre;
    line-height: 1.25; caret-color: var(--accent); min-width: 6px;
  }
  /* Text box colours: paper (canvas colour) + light tints + any colour */
  .box-swatches { display: inline-flex; align-items: center; gap: 3px; flex-wrap: wrap; vertical-align: middle; }
  .bsw {
    position: relative; width: 18px; height: 18px; padding: 0; border-radius: 4px; cursor: pointer;
    background: var(--sw); border: 1px solid color-mix(in srgb, var(--text) 25%, transparent); overflow: hidden;
  }
  .bsw.paper::after { content: ''; position: absolute; inset: 4px; border: 1px dashed color-mix(in srgb, var(--text) 35%, transparent); border-radius: 2px; }
  .bsw.custom { background: conic-gradient(#d63a3a, #c9a400, #14946b, #1f7ad6, #8a4fd1, #d63a3a); }
  .bsw.custom.on { background: var(--sw); }
  .bsw.custom input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; border: 0; padding: 0; cursor: pointer; }
  .bsw.on { outline: 2px solid var(--accent); outline-offset: 1px; }
  /* Ink properties: text box, group and link rows */
  .prop-row.prop-text { align-items: start; }
  .prop-row textarea {
    min-width: 0; resize: vertical; padding: 5px 7px; font: inherit; font-size: 12px;
    border: 1px solid var(--border); border-radius: 5px; background: var(--field); color: var(--text);
  }
  .prop-val { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; color: var(--text-soft); font-size: 11.5px; }
  .mini-btn {
    padding: 2px 8px; font-size: 11px; border-radius: 5px; cursor: pointer;
    border: 1px solid var(--border); background: var(--field); color: var(--text);
  }
  .mini-btn:hover { border-color: var(--accent); color: var(--accent); }
  .dim-input.bad, .eq-grid input.bad { border-color: var(--overc); box-shadow: 0 0 0 2px color-mix(in srgb, var(--overc) 25%, transparent); }
  .fwin[data-win="equations"] { width: 380px; max-height: 70%; }
  .eq-head {
    display: flex; align-items: center; justify-content: space-between;
    font-size: 10px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
    color: var(--text-muted); margin: 6px 0 6px;
  }
  .eq-head:first-child { margin-top: 0; }
  .eq-grid { display: grid; grid-template-columns: 74px minmax(0, 1fr) 66px 22px; gap: 4px; align-items: center; margin-bottom: 8px; }
  .eq-grid input {
    min-width: 0; padding: 4px 6px; border: 1px solid var(--border); border-radius: 5px;
    background: var(--field); font: 12px ui-monospace, SFMono-Regular, Menlo, monospace;
  }
  .eq-grid input:disabled { opacity: 0.55; }
  .eq-grid .eq-name { font-weight: 600; }
  .eq-val.scrub { cursor: ew-resize; border-radius: 3px; padding: 1px 3px; }
  .eq-val.scrub:hover { background: var(--accent-softer); color: var(--accent); }
  .eq-val.scrubbing { background: var(--accent); color: #fff; }
  body.scrubbing, body.scrubbing * { cursor: ew-resize !important; user-select: none; }
  .eq-val { font-size: 11px; text-align: right; color: var(--text-soft); font-variant-numeric: tabular-nums; }
  .hint code { font-size: 10.5px; }

  /* ---------- Active layer (the only editable one) ---------- */
  .lyr-row.active {
    background: var(--accent-softer);
    border-color: var(--accent-border);
    box-shadow: inset 3px 0 0 var(--accent);
  }
  .lyr-row.active .name { font-weight: 600; color: var(--accent-strong); }
  .lyr-row:not(.active) .name { color: var(--text-soft); }

  #statusbar > span { white-space: nowrap; flex: 0 0 auto; }
  #statusbar > #status-hint { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }

  /* Colors window: single fill chip */
  .pc-sw.pc-fill { position: relative; left: auto; top: auto; width: 44px; height: 44px; flex: 0 0 auto; }
  .pc-legend b { font-size: 12px; color: var(--text); }
  .pc-legend span { font: 11px ui-monospace, monospace; color: var(--text-muted); }
  .palette .sw.on { outline: 2px solid var(--accent); outline-offset: 1px; }


  /* ============================================================
     TOUCH + PHONE LAYOUT
     Nothing below applies to a mouse on a desktop: the phone shell is
     under `.compact` (touch screen, narrow or short; compact.js), touch
     controls under `.touch-ui` (set after the first touch or pen input).
     ============================================================ */
  #more-btn, #mobilebar, #more-menu, #mb-flyout { display: none; }

  /* Touch controls in the options bar */
  .nudge { display: inline-flex; align-items: center; gap: 2px; }
  .nudge .tbtn { min-width: 32px; justify-content: center; }
  .touch-ui #optbar .tbtn { height: 34px; min-width: 34px; }
  .touch-ui #optbar > *, .compact #optbar > * { flex-shrink: 0; }   /* scroll, never overlap */
  .touch-ui .context-menu-item { min-height: 40px; }

  /* Floating Delete button (touch-ui.js), touch devices only */
  #fab-delete { display: none; }
  .touch-ui #fab-delete:not([hidden]) {
    display: inline-flex; align-items: center; gap: 8px;
    position: absolute; right: 12px; bottom: 12px; z-index: 20;
    height: 46px; padding: 0 18px 0 16px; border-radius: 23px;
    border: 0; background: var(--overc); color: #fff;
    font: 600 15px -apple-system, "Segoe UI", system-ui, sans-serif;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25); cursor: pointer;
  }
  .touch-ui #fab-delete:active { filter: brightness(0.92); }
  .context-menu-title { padding: 6px 10px 4px; font-size: 11px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-muted); }

  /* Dimension keypad (touch-ui.js) */
  #dimpad {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 1200;
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
    background: var(--panel); border-top: 1px solid var(--border);
    box-shadow: 0 -8px 24px rgba(15, 20, 30, 0.18);
    display: grid; gap: 6px; max-width: 520px; margin: 0 auto;
    user-select: none; -webkit-user-select: none; touch-action: manipulation;
  }
  #dimpad button {
    min-height: 42px; border: 1px solid var(--border); border-radius: 8px;
    background: var(--panel-2); color: var(--text); font: 600 16px ui-monospace, Menlo, monospace; cursor: pointer;
  }
  #dimpad button:active { background: var(--accent-soft); }
  #dimpad .op { color: var(--accent); }
  #dimpad .go { background: var(--accent); border-color: var(--accent); color: #fff; }
  #dimpad .pad-keys { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
  #dimpad .pad-units, #dimpad .pad-names, #dimpad .pad-foot { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
  #dimpad .pad-units button, #dimpad .pad-names button { flex: 0 0 auto; min-width: 52px; min-height: 36px; font-size: 14px; }
  #dimpad .pad-names .name { color: var(--accent); }
  #dimpad .pad-foot button { flex: 1; min-height: 36px; font: 600 13px -apple-system, "Segoe UI", system-ui, sans-serif; }
  #dimpad .pad-hint { font-size: 12px; color: var(--text-muted); padding: 8px 2px; }

  /* ---------- Phone shell ---------- */
  .compact body { overscroll-behavior: none; }
  .compact #app {
    height: 100dvh;
    grid-template-rows: calc(44px + env(safe-area-inset-top)) minmax(0, 1fr) auto calc(58px + env(safe-area-inset-bottom));
    grid-template-areas: "menubar" "workspace" "optbar" "mobilebar";
  }
  .compact #menubar {
    padding: env(safe-area-inset-top) 8px 0; gap: 4px; overflow: hidden;
  }
  .compact #menubar .group:not([aria-label="Edit"]),
  .compact #menubar [data-action="solve"],
  .compact #menubar .units { display: none; }
  .compact #menubar .brand { font-size: 14px; padding: 0 4px 0 0; }
  .compact #menubar .tbtn { width: 40px; height: 40px; justify-content: center; }
  .compact #project-name { flex: 1 1 auto; width: auto; min-width: 60px; }
  .compact #more-btn { display: inline-flex; font-size: 20px; line-height: 1; }

  .compact #optbar {
    border-bottom: 0; border-top: 1px solid var(--border);
    padding: 5px 8px; min-height: 44px; gap: 6px; scrollbar-width: none;
  }
  .compact #optbar::-webkit-scrollbar { display: none; }
  .compact #optbar .opt-hint { display: none; }
  .compact #optbar .opt-tool { min-width: 0; }
  .compact #optbar .opt-tool b { display: none; }
  .compact #optbar .opt { flex: 0 0 auto; }

  /* Status: a pill on the canvas */
  .compact #statusbar {
    grid-area: workspace; align-self: start; justify-self: start;
    z-index: 15; margin: 8px; padding: 0; height: auto;
    background: none; border: 0; overflow: hidden; pointer-events: none; gap: 4px;
  }
  .compact #statusbar > :not(#status-state):not(#status-dof) { display: none; }

  /* Bottom bar */
  .compact #mobilebar {
    grid-area: mobilebar; display: flex; align-items: stretch;
    padding: 0 4px env(safe-area-inset-bottom);
    background: var(--panel-2); border-top: 1px solid var(--border);
    box-shadow: 0 -1px 2px rgba(15, 20, 30, 0.05);
  }
  .mb-slot {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    border: 0; background: none; color: var(--text-soft); font-size: 10.5px; cursor: pointer; border-radius: 10px; margin: 4px 2px;
  }
  .mb-slot svg { width: 22px; height: 22px; }
  .mb-slot.on { color: var(--accent); background: var(--accent-softer); }
  .compact #mb-flyout:not([hidden]), .compact #more-menu:not([hidden]) {
    display: grid; position: fixed; z-index: 1100;
    background: var(--panel-2); border: 1px solid var(--border); border-radius: 12px;
    box-shadow: 0 12px 32px rgba(15, 20, 30, 0.22); padding: 6px;
  }
  .compact #mb-flyout { grid-template-columns: repeat(3, 92px); gap: 4px; }
  .fly-item {
    display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 4px;
    border: 0; border-radius: 9px; background: none; color: var(--text); font-size: 11px; cursor: pointer; text-align: center;
  }
  .fly-item svg { width: 22px; height: 22px; }
  .fly-item.on { background: var(--accent); color: #fff; }
  .compact #more-menu { top: calc(46px + env(safe-area-inset-top)); right: 8px; min-width: 230px; max-height: 75dvh; overflow-y: auto; }
  .more-item {
    display: flex; align-items: center; gap: 10px; min-height: 42px; padding: 0 10px;
    border: 0; border-radius: 8px; background: none; color: var(--text); font-size: 14px; text-align: left; cursor: pointer;
  }
  .more-item:active { background: var(--hover); }
  .more-item svg { width: 18px; height: 18px; color: var(--text-soft); }
  .more-item .chk { margin-left: auto; color: var(--accent); font-weight: 700; }
  .more-sep { height: 1px; margin: 4px 6px; background: var(--border-soft); }

  /* Windows as bottom sheets */
  .compact .fwin {
    position: fixed; left: 0 !important; right: 0; top: auto !important;
    bottom: calc(58px + 44px + env(safe-area-inset-bottom));
    width: auto !important; max-height: 52dvh; z-index: 900 !important;
    border-radius: 14px 14px 0 0; border-left: 0; border-right: 0;
  }
  .compact .fwin .fwin-head { position: relative; padding-top: 14px; touch-action: none; }
  .compact .fwin .fwin-head::before {
    content: ""; position: absolute; top: 5px; left: 50%; width: 36px; height: 4px; margin-left: -18px;
    border-radius: 2px; background: var(--border);
  }
  .compact .fwin .fwin-body { width: auto !important; overflow-y: auto; }
  .compact .fwin-x { width: 36px; height: 36px; font-size: 20px; }
  .compact .fwin[data-win="equations"] { width: auto; }
  .compact .fwin[data-win="tools"], .compact .fwin[data-win="sketch"] { display: none; }
  .compact .context-menu-item { min-height: 44px; font-size: 14px; }
  .compact .dim-input { font-size: 16px; padding: 6px 8px; }
  .compact.keypad-open .dim-input { top: 30% !important; }
  .compact #dimpad { bottom: 0; }

  /* Phone on its side: tools as a rail on the right, sheets on the right */
  .compact-land #app {
    grid-template-columns: minmax(0, 1fr) calc(64px + env(safe-area-inset-right));
    grid-template-rows: calc(40px + env(safe-area-inset-top)) minmax(0, 1fr) auto;
    grid-template-areas: "menubar menubar" "workspace mobilebar" "optbar mobilebar";
  }
  .compact-land #mobilebar {
    flex-direction: column; padding: 4px env(safe-area-inset-right) 4px 0; border-top: 0; border-left: 1px solid var(--border);
  }
  .compact-land #optbar { min-height: 40px; padding: 3px 8px; }
  .compact-land .fwin {
    left: auto !important; right: calc(64px + env(safe-area-inset-right)); top: calc(40px + env(safe-area-inset-top)) !important;
    bottom: 0; width: min(340px, 60vw) !important; max-height: none; border-radius: 12px 0 0 0; border-left: 1px solid var(--border);
  }
  .compact-land .fwin .fwin-head::before { display: none; }
  .compact-land #mb-flyout { grid-template-columns: repeat(3, 84px); }

/* Snap button while Alt is held: snapping is off for now. */
#menubar .tbtn[data-action="snap"].held-off { opacity: 0.45; text-decoration: line-through; }

.opt-hint kbd {
  font: inherit; font-size: 10.5px; padding: 0 4px; margin-right: 2px;
  border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; background: var(--field); color: var(--text);
}
