/* Vector: colour tokens (light, then dark), the gallery, the editor (top bar, tool bar, stage, panel), the
   picker, dialogs and menus, then phones. */

:root {
    --bg: #ffffff;
    --bg-2: #f4f4f2;
    --bg-3: #ebebe8;
    --ink: #2b2a27;
    --ink-2: #6f6e69;
    --ink-3: #a5a49f;
    --line: #e4e3df;
    --hover: rgba(0, 0, 0, 0.05);
    --accent: #3b63fb;
    --accent-ink: #ffffff;
    --accent-soft: rgba(59, 99, 251, 0.12);
    --danger: #e03e3e;
    --pasteboard: #d9d9dc;
    --shadow: 0 10px 32px rgba(0, 0, 0, 0.16), 0 1px 3px rgba(0, 0, 0, 0.12);
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #232325;
        --bg-2: #1b1b1d;
        --bg-3: #2c2c2f;
        --ink: #ededeb;
        --ink-2: #a9a8a4;
        --ink-3: #75746f;
        --line: #38383b;
        --hover: rgba(255, 255, 255, 0.07);
        --accent: #6d8cff;
        --accent-soft: rgba(109, 140, 255, 0.18);
        --pasteboard: #3a3a3e;
        --shadow: 0 10px 32px rgba(0, 0, 0, 0.5), 0 1px 3px rgba(0, 0, 0, 0.4);
        color-scheme: dark;
    }
}

:root[data-theme="dark"] {
    --bg: #232325;
    --bg-2: #1b1b1d;
    --bg-3: #2c2c2f;
    --ink: #ededeb;
    --ink-2: #a9a8a4;
    --ink-3: #75746f;
    --line: #38383b;
    --hover: rgba(255, 255, 255, 0.07);
    --accent: #6d8cff;
    --accent-soft: rgba(109, 140, 255, 0.18);
    --pasteboard: #3a3a3e;
    --shadow: 0 10px 32px rgba(0, 0, 0, 0.5), 0 1px 3px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    background: var(--bg);
    color: var(--ink);
    font: 14px/1.4 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

body { overflow: hidden; }

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
button:disabled { opacity: 0.35; cursor: default; }
select option { background: var(--bg); color: var(--ink); }
input[type=number], input[type=text], select {
    background: var(--bg-2);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 4px 6px;
    min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.ic { display: block; flex: none; }
.screen[hidden], [hidden] { display: none !important; }


/* ---------- Gallery ---------- */

#gallery { height: 100%; overflow: auto; background: var(--bg-2); }
.g-head {
    position: sticky; top: 0; z-index: 2;
    display: flex; align-items: center; gap: 16px;
    padding: 14px 24px; background: var(--bg); border-bottom: 1px solid var(--line);
}
.g-head h1 { margin: 0; font-size: 20px; font-weight: 650; }
.g-home { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); text-decoration: none; font-weight: 600; }
.logo { display: block; width: 24px; height: 24px; border-radius: 6px; flex: none; }
.g-actions { margin-left: auto; display: flex; gap: 8px; }
.g-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    height: 36px; padding: 0 14px; border-radius: 18px; border: 1px solid var(--line);
    background: var(--bg); color: var(--ink); text-decoration: none; font-weight: 600;
}
.g-btn:hover { background: var(--hover); }
.g-new { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.g-new:hover { background: var(--accent); filter: brightness(1.08); }
.g-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 20px;
    padding: 24px; max-width: 1400px; margin: 0 auto;
}
.g-card { position: relative; background: var(--bg); border-radius: 12px; border: 1px solid var(--line); overflow: hidden; }
.g-thumb { display: flex; align-items: center; justify-content: center; width: 100%; aspect-ratio: 4 / 3; background: var(--bg-3); }
.g-thumb img { max-width: 86%; max-height: 86%; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18); background: #fff; }
.g-meta { padding: 10px 40px 12px 12px; }
.g-meta b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.g-meta small { color: var(--ink-2); }
.g-more { position: absolute; right: 6px; bottom: 12px; }
.g-empty { text-align: center; padding: 80px 24px; color: var(--ink-2); }
.g-empty h2 { color: var(--ink); margin: 16px 0 6px; }
.g-empty-art { display: inline-flex; padding: 22px; border-radius: 24px; background: var(--accent-soft); color: var(--accent); }
.g-empty-btns { display: flex; gap: 10px; justify-content: center; margin-top: 18px; }


/* ---------- Editor ---------- */

#editor { display: flex; flex-direction: column; height: 100%; height: 100dvh; }
#topbar {
    flex: none; display: flex; align-items: center; gap: 4px;
    height: 44px; padding: 0 8px; border-bottom: 1px solid var(--line); background: var(--bg);
}
.tb { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-width: 34px; height: 32px; padding: 0 6px; border-radius: 7px; color: var(--ink); }
.tb:hover:not(:disabled) { background: var(--hover); }
.tb.primary { background: var(--accent); color: var(--accent-ink); padding: 0 12px; font-weight: 600; }
.tb.primary:hover { background: var(--accent); filter: brightness(1.08); }
.tb.zoom { font-variant-numeric: tabular-nums; font-size: 13px; color: var(--ink-2); min-width: 52px; }
.tb-home { display: inline-flex; align-items: center; gap: 7px; color: var(--ink-2); text-decoration: none; font-weight: 650; padding: 0 6px; }
.name-wrap { position: relative; display: flex; align-items: center; }
#doc-name { width: 170px; border-color: transparent; background: none; font-weight: 600; }
#doc-name:hover, #doc-name:focus { border-color: var(--line); background: var(--bg-2); }
#saved { position: absolute; right: -2px; width: 6px; height: 6px; border-radius: 50%; background: var(--ink-3); opacity: 0.6; }
#saved.on { background: #30a46c; }
#menubar { display: flex; gap: 0; margin-left: 6px; }
#menubar button { height: 30px; padding: 0 9px; border-radius: 6px; color: var(--ink); }
#menubar button:hover, #menubar button.on { background: var(--hover); }
.grow { flex: 1; }
.phone-only { display: none !important; }

#main { flex: 1; display: flex; min-height: 0; position: relative; }

/* the tool bar */
#tools {
    flex: none; width: 52px; padding: 6px 5px; overflow-y: auto; overflow-x: hidden;
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    border-right: 1px solid var(--line); background: var(--bg); scrollbar-width: none;
}
.tool { position: relative; display: flex; align-items: center; justify-content: center; width: 40px; height: 36px; border-radius: 8px; color: var(--ink); flex: none; }
.tool:hover { background: var(--hover); }
.tool.on { background: var(--accent-soft); color: var(--accent); }
.tool.more::after { content: ''; position: absolute; right: 3px; bottom: 3px; border: 3px solid transparent; border-right-color: currentColor; border-bottom-color: currentColor; opacity: 0.6; }
.tool .tname { display: none; }
.paint-chips { position: relative; width: 44px; height: 64px; margin-top: 8px; flex: none; }
.pc { position: absolute; width: 26px; height: 26px; border-radius: 5px; border: 1px solid var(--ink-3); background: #fff; overflow: hidden; }
.pc span { position: absolute; inset: 0; }
.pc.fill { left: 2px; top: 2px; z-index: 1; }
.pc.stroke { left: 15px; top: 15px; }
.pc.stroke span { inset: 0; }
.pc.stroke::after { content: ''; position: absolute; inset: 6px; background: var(--bg); border: 1px solid var(--ink-3); }
.pc.front { z-index: 2; box-shadow: 0 0 0 2px var(--accent); }
.pc.none span, .chip.none span, .swatch.none { background: #fff linear-gradient(to top right, transparent calc(50% - 1px), var(--danger) calc(50% - 1px), var(--danger) calc(50% + 1px), transparent calc(50% + 1px)) !important; }
.pc-mini { position: absolute; width: 14px; height: 14px; font-size: 11px; line-height: 14px; color: var(--ink-2); }
.pc-mini.swap { right: 0; top: 0; }
.pc-mini.dflt { left: 2px; bottom: 2px; }
.pc-mini.dflt::before, .pc-mini.dflt::after { content: ''; position: absolute; width: 8px; height: 8px; border: 1px solid var(--ink-2); }
.pc-mini.dflt::before { left: 0; top: 0; background: #fff; z-index: 1; }
.pc-mini.dflt::after { left: 4px; top: 4px; background: #000; }
.pc-mini.nonep { right: 0; bottom: 2px; border: 1px solid var(--ink-3); background: #fff linear-gradient(to top right, transparent 45%, var(--danger) 45%, var(--danger) 55%, transparent 55%); width: 12px; height: 12px; }

/* the stage */
#stage { flex: 1; position: relative; min-width: 0; overflow: hidden; background: var(--pasteboard); touch-action: none; }
#canvas { position: absolute; left: 20px; top: 20px; width: calc(100% - 20px); height: calc(100% - 20px); display: block; touch-action: none; user-select: none; -webkit-user-select: none; }
#stage.no-rulers #canvas { left: 0; top: 0; width: 100%; height: 100%; }
#rul-x { position: absolute; left: 20px; top: 0; height: 20px; width: calc(100% - 20px); cursor: ns-resize; }
#rul-y { position: absolute; left: 0; top: 20px; width: 20px; height: calc(100% - 20px); cursor: ew-resize; }
.rul-corner { position: absolute; left: 0; top: 0; width: 20px; height: 20px; background: var(--bg); border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
#stage.no-rulers #rul-x, #stage.no-rulers #rul-y, #stage.no-rulers .rul-corner { display: none; }

#canvas[data-tool=pen], #canvas[data-tool=curvature], #canvas[data-tool=pencil], #canvas[data-tool=rect], #canvas[data-tool=rrect],
#canvas[data-tool=ellipse], #canvas[data-tool=polygon], #canvas[data-tool=star], #canvas[data-tool=line], #canvas[data-tool=arc],
#canvas[data-tool=spiral], #canvas[data-tool=width], #canvas[data-tool=gradient], #canvas[data-tool=artboard], #canvas[data-tool=blend], #canvas[data-tool=eraser], #canvas[data-tool=shapebuilder] { cursor: crosshair; }
#canvas[data-tool=type] { cursor: text; }
#canvas[data-tool=scissors], #canvas[data-tool=addpoint], #canvas[data-tool=delpoint], #canvas[data-tool=convert], #canvas[data-tool=eyedropper] { cursor: crosshair; }
#canvas[data-tool=hand], #canvas.space { cursor: grab; }
#canvas.panning { cursor: grabbing !important; }
#canvas[data-tool=zoom] { cursor: zoom-in; }

.board { fill: #fff; filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.25)); }
#art .hit { fill: none; stroke: transparent; stroke-width: 10px; vector-effect: non-scaling-stroke; pointer-events: stroke; }
#art .hit.hit-fill { fill: transparent; pointer-events: all; }
#art .clipper .hit { pointer-events: stroke; }
#art .outl, #canvas.outline #art path:not(.hit) { fill: none !important; stroke: #333 !important; stroke-width: 1px !important; vector-effect: non-scaling-stroke; filter: none; }
#canvas.outline #art text { fill: none; stroke: #333; stroke-width: 0.5px; vector-effect: non-scaling-stroke; }
#outlines, #ui, #preview { pointer-events: none; }
.sel-line, .hover-line { fill: none; stroke-width: 1px; vector-effect: non-scaling-stroke; }
.hover-line { stroke-width: 2px; }
.sel-box { fill: none; stroke-width: 1px; shape-rendering: crispEdges; }
.handle { fill: #fff; stroke-width: 1px; }
.rot-stem { stroke-width: 1px; }
.anchor { fill: #fff; stroke: #4f8cff; stroke-width: 1px; }
.anchor.on { fill: #4f8cff; }
.hline { stroke: #4f8cff; stroke-width: 1px; }
.hdot { fill: #fff; stroke: #4f8cff; stroke-width: 1px; }
.rubber { fill: none; stroke: #4f8cff; stroke-width: 1px; stroke-dasharray: 4 3; }
.guide { stroke: #00b8d4; stroke-width: 1px; }
.smart { stroke: #ff3ea5; stroke-width: 1px; }
.snap-pt { fill: none; stroke: #ff3ea5; stroke-width: 1.5px; }
.marquee { fill: rgba(79, 140, 255, 0.08); stroke: #4f8cff; stroke-width: 1px; stroke-dasharray: 3 3; }
.lasso-line { fill: rgba(79, 140, 255, 0.08); stroke: #4f8cff; stroke-width: 1px; stroke-dasharray: 3 3; }
.blob-trail { fill: none; stroke-linecap: round; stroke-linejoin: round; opacity: 0.55; }
.brushes { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin-top: 6px; }
.brush-row { display: flex; flex-direction: column; align-items: stretch; gap: 1px; padding: 4px; border-radius: 6px; border: 1px solid var(--line); background: var(--bg); font-size: 11px; color: var(--ink-2); text-align: left; }
.brush-row img { width: 100%; height: 28px; object-fit: contain; background: #fff; border-radius: 4px; }
.brush-row span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brush-row:hover { background: var(--hover); }
.brush-row.on { border-color: var(--accent); color: var(--ink); }
.swatch.global { position: relative; }
.swatch.global::after { content: ''; position: absolute; right: 0; bottom: 0; border: 5px solid transparent; border-right-color: #fff; border-bottom-color: #fff; }
.mesh-line { fill: none; stroke: #4f8cff; stroke-width: 1px; }
.mesh-pt { fill: #fff; stroke: #4f8cff; stroke-width: 1px; }
.thread-line { stroke: #4f8cff; stroke-width: 1px; stroke-dasharray: 4 3; }
.measure-line { stroke: #ff3ea5; stroke-width: 1.5px; }
#gridlines { pointer-events: none; }
.grid-minor { fill: none; stroke: rgba(79, 140, 255, 0.16); stroke-width: 1px; vector-effect: non-scaling-stroke; }
.grid-major { fill: none; stroke: rgba(79, 140, 255, 0.34); stroke-width: 1px; vector-effect: non-scaling-stroke; }
.glyphs { display: grid; grid-template-columns: repeat(auto-fill, minmax(34px, 1fr)); gap: 2px; max-height: 50vh; overflow-y: auto; font-size: 20px; }
.glyphs button { height: 36px; border-radius: 5px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); }
.glyphs button:hover { background: var(--hover); }
.knife-line { fill: none; stroke: #e03e3e; stroke-width: 1.5px; }
.key-line { fill: none; stroke-width: 3px; vector-effect: non-scaling-stroke; }
#art .iso-dim { filter: opacity(0.3); }
#isobar {
    position: absolute; left: 50%; top: 30px; transform: translateX(-50%); max-width: calc(100% - 60px); display: flex; align-items: center; gap: 2px;
    padding: 3px 6px; border-radius: 8px; background: var(--bg); color: var(--ink); box-shadow: var(--shadow); font-size: 12px; white-space: nowrap; overflow: hidden;
}
#isobar button { padding: 3px 6px; border-radius: 5px; color: var(--ink-2); display: flex; align-items: center; }
#isobar button:hover { background: var(--hover); }
#isobar button.on { color: var(--ink); font-weight: 600; }
#isobar span { color: var(--ink-3); }
.pivot { fill: none; stroke: #4f8cff; stroke-width: 1.5px; }
.grad-line { stroke: #fff; stroke-width: 2px; fill: none; filter: drop-shadow(0 0 1px rgba(0, 0, 0, 0.8)); }
.grad-stop { stroke: #fff; stroke-width: 2px; filter: drop-shadow(0 0 1px rgba(0, 0, 0, 0.8)); }
.grad-end { fill: #fff; stroke: #333; stroke-width: 1px; }
.board-name { font-size: 12px; fill: var(--ink-2); font-family: inherit; }
.board-name.on { fill: var(--accent); font-weight: 600; }
.size-label rect { fill: #4f8cff; }
.size-label text { fill: #fff; font-size: 11px; font-family: inherit; font-variant-numeric: tabular-nums; }

#hint {
    position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); max-width: calc(100% - 24px);
    padding: 5px 12px; border-radius: 14px; background: rgba(20, 20, 22, 0.78); color: #fff; font-size: 12px;
    pointer-events: none; opacity: 0; transition: opacity 0.2s; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#hint.show { opacity: 1; }

/* the panel */
#panel { flex: none; width: 280px; display: flex; flex-direction: column; border-left: 1px solid var(--line); background: var(--bg); min-height: 0; }
#panel-tabs { flex: none; display: flex; gap: 2px; padding: 6px 8px 0; border-bottom: 1px solid var(--line); }
#panel-tabs [data-tab] { padding: 6px 10px 8px; color: var(--ink-2); font-weight: 600; border-bottom: 2px solid transparent; }
#panel-tabs [data-tab].on { color: var(--ink); border-bottom-color: var(--accent); }
#panel-body { flex: 1; overflow-y: auto; padding: 4px 12px 40px; overscroll-behavior: contain; }
.kind { padding: 10px 0 2px; font-weight: 650; }
.ps { border-bottom: 1px solid var(--line); padding: 8px 0 10px; }
.ps:last-child { border-bottom: 0; }
.ps h3 { display: flex; align-items: center; justify-content: space-between; margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-2); }
.ps h3[data-fold] { cursor: pointer; }
.ps.shut .ps-body { display: none; }
.ps-body > * + * { margin-top: 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 8px; }
.grid3 { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 8px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.row { display: flex; align-items: center; gap: 6px; }
.row.tight { gap: 2px; }
.nf { display: flex; align-items: center; gap: 6px; min-width: 0; }
.nf > span { color: var(--ink-2); font-size: 12px; min-width: 12px; display: flex; }
.nf input { width: 100%; }
.nf.sw { width: 76px; flex: none; }
.nf.sw input { width: 52px; }
.grid4 .nf { flex-direction: column; align-items: stretch; gap: 2px; }
.sf { display: flex; flex-direction: column; gap: 3px; }
.sf > span { color: var(--ink-2); font-size: 12px; }
.sf.grow { flex: 1; }
.rf { display: grid; grid-template-columns: 74px 1fr 46px; align-items: center; gap: 6px; }
.rf > span { color: var(--ink-2); font-size: 12px; }
.rf output { font-size: 12px; text-align: right; font-variant-numeric: tabular-nums; color: var(--ink-2); }
.row .rf { flex: 1; grid-template-columns: 56px 1fr 34px; }
input[type=range] { width: 100%; accent-color: var(--accent); }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.check input { accent-color: var(--accent); margin: 0; }
.check .nf { display: inline-flex; }
input.inline { width: 54px; }
.ib { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; border-radius: 6px; color: var(--ink); flex: none; }
.ib:hover { background: var(--hover); }
.ib.on { background: var(--accent-soft); color: var(--accent); }
.btns { display: flex; flex-wrap: wrap; gap: 6px; }
.btns + .btns { margin-top: 8px; }
.btn-s { display: inline-flex; align-items: center; gap: 5px; height: 30px; padding: 0 10px; border-radius: 15px; border: 1px solid var(--line); font-size: 13px; }
.btn-s:hover { background: var(--hover); }
.btn-s.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.link { color: var(--accent); font-size: 13px; }
.fold-btn { display: flex; align-items: center; gap: 4px; color: var(--ink-2); font-size: 13px; padding: 2px 0; }
.lbl, .lbl-row { color: var(--ink-2); font-size: 12px; }
.seg { display: flex; background: var(--bg-2); border: 1px solid var(--line); border-radius: 8px; padding: 2px; }
.seg button { flex: 1; height: 26px; border-radius: 6px; font-size: 12px; color: var(--ink-2); }
.seg button.on { background: var(--bg); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15); }
.seg.wide button { height: 32px; font-size: 13px; }
.look-row { display: flex; align-items: center; gap: 6px; }
.chip { position: relative; width: 28px; height: 28px; border-radius: 6px; border: 1px solid var(--ink-3); overflow: hidden; flex: none; background: #fff linear-gradient(45deg, #ddd 25%, transparent 25%, transparent 75%, #ddd 75%) 0 0 / 8px 8px; }
.chip span { position: absolute; inset: 0; }
.stroke-chip::after { content: ''; position: absolute; inset: 7px; border-radius: 2px; background: var(--bg); border: 1px solid var(--ink-3); }
.stroke-opts { padding: 4px 0 2px; display: flex; flex-direction: column; gap: 6px; }
.look-list { margin-top: 6px; display: flex; flex-direction: column; gap: 4px; }
.look-item { display: flex; align-items: center; gap: 4px; font-size: 13px; }
.look-item span { flex: 1; }
.look-item.off { opacity: 0.5; }
.look-sub { padding-left: 36px; }
.fx { border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; display: flex; flex-direction: column; gap: 6px; }
.fx.off { opacity: 0.55; }
.fx-head { display: flex; align-items: center; gap: 4px; }
.fx-head b { flex: 1; font-size: 13px; }
.board-chip { display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font-weight: 600; }
.board-chip small { color: var(--ink-2); font-weight: 400; flex: 1; text-align: left; }
.board-list { display: flex; flex-direction: column; gap: 2px; }
.board-list button { display: flex; justify-content: space-between; padding: 6px 8px; border-radius: 6px; text-align: left; }
.board-list button.on { background: var(--accent-soft); }
.board-list small { color: var(--ink-2); }
.hint { color: var(--ink-2); font-size: 12px; margin: 0; }

/* layers */
.layers-bar { display: flex; align-items: center; gap: 6px; padding: 8px 0; }
.layer-tree { display: flex; flex-direction: column; user-select: none; -webkit-user-select: none; }
.lrow {
    display: flex; align-items: center; gap: 2px; height: 32px; padding-left: calc(var(--d, 0) * 14px);
    border-radius: 6px; position: relative; touch-action: pan-y;
}
.lrow:hover { background: var(--hover); }
.lrow.on { background: var(--accent-soft); }
.lrow.layer { font-weight: 650; border-left: 3px solid var(--lc); }
.lrow.layer.cur { background: var(--bg-2); }
.lrow.hid .lname, .lrow.hid .thumb { opacity: 0.45; }
.lrow .ib { width: 26px; height: 26px; color: var(--ink-2); }
.twisty { width: 18px; height: 26px; display: inline-flex; align-items: center; justify-content: center; color: var(--ink-2); flex: none; }
.thumb { width: 26px; height: 26px; flex: none; display: inline-flex; align-items: center; justify-content: center; border-radius: 4px; background: var(--bg-2); color: var(--ink-2); }
.lname { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: default; padding: 4px 2px; font-size: 13px; }
.lc { width: 8px; height: 8px; background: var(--lc); flex: none; margin-right: 6px; }
.lrow.dragging { opacity: 0.4; }
.lrow.drop-above { box-shadow: inset 0 2px 0 var(--accent); }
.lrow.drop-below { box-shadow: inset 0 -2px 0 var(--accent); }

/* swatches */
.swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(24px, 1fr)); gap: 5px; }
.swatches.small { grid-template-columns: repeat(12, 1fr); gap: 3px; margin-top: 8px; }
.swatch { aspect-ratio: 1; border-radius: 5px; border: 1px solid rgba(0, 0, 0, 0.15); }
.swatch:hover { transform: scale(1.1); }
.swatch.add { display: flex; align-items: center; justify-content: center; border-style: dashed; color: var(--ink-2); background: none; }
.swatches.grads { grid-template-columns: repeat(4, 1fr); }
.swatches.grads .swatch { aspect-ratio: 2; }

/* the colour picker */
.picker {
    position: fixed; z-index: 40; width: 248px; padding: 10px; border-radius: 12px;
    background: var(--bg); border: 1px solid var(--line); box-shadow: var(--shadow);
    display: flex; flex-direction: column; gap: 8px;
}
.pk-head { display: flex; align-items: center; justify-content: space-between; }
.pk-sv { position: relative; height: 150px; border-radius: 6px; cursor: crosshair; touch-action: none; }
.pk-sv-w, .pk-sv-b { position: absolute; inset: 0; border-radius: 6px; }
.pk-sv-w { background: linear-gradient(90deg, #fff, rgba(255, 255, 255, 0)); }
.pk-sv-b { background: linear-gradient(0deg, #000, rgba(0, 0, 0, 0)); }
.pk-sv i, .pk-hue i, .pk-stop { position: absolute; width: 14px; height: 14px; margin: -7px 0 0 -7px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.4); pointer-events: none; }
.pk-hue { position: relative; height: 14px; border-radius: 7px; cursor: pointer; touch-action: none; background: linear-gradient(90deg, #f00, #ff0, #0f0, #0ff, #00f, #f0f, #f00); }
.pk-hue i { top: 7px; }
.pk-row { display: flex; align-items: center; gap: 6px; }
.pk-row .nf { flex: 1; }
.pk-row .nf span { font-size: 11px; }
.pk-now { width: 26px; height: 26px; border-radius: 6px; border: 1px solid var(--line); flex: none; }
.pk-hex { flex: 1; font-family: ui-monospace, monospace; }
.pk-none { color: var(--ink-2); text-align: center; margin: 14px 0; }
.pk-grad { position: relative; height: 26px; margin: 4px 7px 0; }
.pk-bar { position: absolute; left: -7px; right: -7px; top: 3px; height: 20px; border-radius: 4px; border: 1px solid var(--line); cursor: copy; touch-action: none; }
.pk-stop { top: 13px; pointer-events: auto; cursor: ew-resize; width: 16px; height: 16px; margin: -8px 0 0 -8px; touch-action: none; }
.pk-stop.on { box-shadow: 0 0 0 2px var(--accent); }

/* dialogs */
.dialog { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; background: rgba(0, 0, 0, 0.35); padding: 16px; }
.dlg-box { width: 100%; max-width: 420px; max-height: calc(100dvh - 32px); overflow: auto; margin: auto; padding: 18px 20px; border-radius: 14px; background: var(--bg); box-shadow: var(--shadow); }
.dlg-box h2 { margin: 0 0 14px; font-size: 18px; }
.dlg-body { display: flex; flex-direction: column; gap: 12px; }
.dlg-btns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.btn { height: 36px; padding: 0 16px; border-radius: 18px; border: 1px solid var(--line); font-weight: 600; }
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.presets { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; max-height: 300px; overflow: auto; }
.preset { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 6px; border: 1px solid var(--line); border-radius: 10px; }
.preset.on, .preset:hover { border-color: var(--accent); background: var(--accent-soft); }
.preset i { display: block; height: 40px; max-width: 60px; border: 1.5px solid var(--ink-2); border-radius: 3px; }
.preset b { font-size: 12px; text-align: center; }
.preset small { color: var(--ink-2); font-size: 11px; }
.hist { display: flex; flex-direction: column; max-height: 50vh; overflow: auto; }
.hist button { text-align: left; padding: 6px 10px; border-radius: 6px; }
.hist button.on { background: var(--accent-soft); font-weight: 600; }
.hist button.later { color: var(--ink-3); }

/* menus */
.menu.pop {
    position: fixed; z-index: 45; min-width: 210px; max-height: calc(100dvh - 16px); overflow: auto; padding: 5px;
    background: var(--bg); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow);
}
.menu.pop button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 6px 10px; border-radius: 6px; text-align: left; white-space: nowrap; }
.menu.pop button:hover:not(:disabled) { background: var(--hover); }
.menu.pop button.on { color: var(--accent); }
.menu.pop button.danger { color: var(--danger); }
.menu.pop button span { flex: 1; }
.menu.pop kbd { font: 11px ui-monospace, monospace; color: var(--ink-3); }
.menu.pop hr { border: 0; border-top: 1px solid var(--line); margin: 4px 6px; }
.menu.pop .mh { padding: 8px 10px 2px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-3); }
.ic-space { width: 16px; flex: none; }
#scrim { position: fixed; inset: 0; z-index: 44; background: rgba(0, 0, 0, 0.3); }

#toast {
    position: fixed; left: 50%; bottom: 64px; z-index: 60; transform: translate(-50%, 20px); opacity: 0;
    padding: 8px 16px; border-radius: 18px; background: #222; color: #fff; font-size: 13px; pointer-events: none;
    transition: opacity 0.2s, transform 0.2s; max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

#selbar { position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); display: flex; gap: 2px; padding: 4px; border-radius: 14px; background: var(--bg); box-shadow: var(--shadow); }
#selbar button { display: flex; flex-direction: column; align-items: center; gap: 1px; min-width: 50px; padding: 4px 2px; border-radius: 10px; font-size: 10px; color: var(--ink-2); }
#selbar button:active { background: var(--hover); }

#editor.bare #tools, #editor.bare #panel { display: none; }


/* ---------- Phones ---------- */

@media (max-width: 767px) {
    .wide-only { display: none !important; }
    .phone-only { display: inline-flex !important; }
    .g-head { padding: 10px 14px; gap: 10px; }
    .g-home-t { display: none; }
    .g-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; padding: 14px; }
    #topbar { height: 50px; padding: 0 4px; gap: 2px; }
    .tb-home, #redo { display: none; }
    .tb { min-width: 40px; height: 40px; }
    .tb.primary { min-width: 40px; padding: 0; }
    .name-wrap { flex: 1; min-width: 0; }
    #topbar .grow { display: none; }
    #doc-name { width: 100%; }
    #main { flex-direction: column-reverse; }
    #tools {
        width: auto; height: 62px; flex-direction: row; overflow-x: auto; overflow-y: hidden; padding: 4px 6px;
        border-right: 0; border-top: 1px solid var(--line); padding-bottom: max(4px, env(safe-area-inset-bottom));
        box-sizing: content-box;
    }
    .tool { flex-direction: column; width: 48px; height: 54px; gap: 2px; }
    .tool .tname { display: block; font-size: 10px; color: var(--ink-2); white-space: nowrap; }
    .tool.on .tname { color: var(--accent); }
    .tool.more::after { right: 4px; bottom: 4px; border-width: 4px; opacity: 0.75; }
    /* the colour chips first and always in sight */
    .paint-chips { order: -1; position: sticky; left: -6px; z-index: 1; margin: 0 2px 0 -6px; padding-left: 6px; width: 50px; height: 54px; background: var(--bg); box-sizing: content-box; }
    .all-tools { position: sticky; right: -6px; z-index: 1; background: var(--bg); }
    .pc { width: 30px; height: 30px; }
    .pc.fill { left: 6px; top: 2px; }
    .pc.stroke { left: 22px; top: 20px; }
    .pc-mini { display: none; }
    .tstrip { display: flex; gap: 2px; min-width: 0; max-width: calc(100% - 16px); overflow-x: auto; padding: 4px; border-radius: 14px; }
    .tstrip button { flex-direction: column; gap: 2px; width: 60px; padding: 6px 2px; justify-content: center; font-size: 10px; color: var(--ink-2); }
    .tstrip button span { flex: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; text-align: center; }
    .tstrip button.on { background: var(--accent-soft); color: var(--accent); }
    .tsheet .tgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 2px; padding: 0 2px 6px; }
    .menu.pop.sheet.tsheet .tgrid button { flex-direction: column; gap: 4px; padding: 10px 2px; white-space: normal; text-align: center; font-size: 11px; line-height: 1.2; color: var(--ink-2); }
    .tsheet .tgrid button.on { background: var(--accent-soft); color: var(--accent); }
    .menu.pop.sheet kbd { display: none; }
    .menu.pop.sheet button.back { color: var(--ink-2); }
    #modkey {
        position: absolute; left: 10px; bottom: 96px; z-index: 6; width: 48px; height: 48px; border-radius: 50%; align-items: center; justify-content: center;
        background: var(--bg); box-shadow: var(--shadow); color: var(--ink-2); touch-action: none; user-select: none; -webkit-user-select: none;
        font-size: 18px;
    }
    #modkey i { display: none; font-style: normal; font-size: 13px; font-weight: 650; }
    #modkey.shift, #modkey.lock { background: var(--accent); color: var(--accent-ink); }
    #modkey.alt { background: var(--accent); color: var(--accent-ink); box-shadow: 0 0 0 10px var(--accent-soft), var(--shadow); }
    #modkey.alt b { display: none; }
    #modkey.alt i { display: block; }
    #editor.sheet-open #modkey { display: none !important; }
    body:has(.tstrip) #selbar { visibility: hidden; }
    #zoom-pill {
        position: absolute; right: 10px; top: 10px; z-index: 6; height: 32px; min-width: 56px; padding: 0 10px; border-radius: 16px; align-items: center; justify-content: center;
        background: var(--bg); box-shadow: var(--shadow); font-size: 12px; font-variant-numeric: tabular-nums; color: var(--ink-2);
    }
    #selbar { max-width: calc(100% - 16px); overflow-x: auto; scrollbar-width: none; }
    #selbar button { flex: none; min-width: 52px; }
    #rul-x, #rul-y, .rul-corner { display: none; }
    #canvas { left: 0; top: 0; width: 100%; height: 100%; }
    #panel {
        position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; width: auto; height: var(--sheet-h, 56dvh);
        border: 0; border-radius: 16px 16px 0 0; box-shadow: var(--shadow); transform: translateY(105%); transition: transform 0.22s;
        padding-bottom: env(safe-area-inset-bottom);
    }
    #editor.sheet-open #panel { transform: none; }
    #panel.sizing { transition: none; }
    #sheet-grip { justify-content: center; align-items: center; height: 18px; flex: none; touch-action: none; cursor: ns-resize; }
    #sheet-grip i { width: 40px; height: 5px; border-radius: 3px; background: var(--ink-3); opacity: 0.6; }
    #panel-tabs { padding-top: 0; }
    #panel-tabs { align-items: center; }
    #sheet-close { margin-left: auto; }
    #panel-body { padding: 4px 16px 40px; }
    #hint { bottom: auto; top: 8px; white-space: normal; text-align: center; font-size: 11px; max-width: calc(100% - 150px); }
    #hint.show { animation: hint-out 5s forwards; }
    @keyframes hint-out { 0%, 80% { opacity: 1; } 100% { opacity: 0; } }
    .picker.sheet { left: 0 !important; right: 0; top: auto !important; bottom: 0; width: auto; border-radius: 16px 16px 0 0; padding-bottom: max(14px, env(safe-area-inset-bottom)); }
    .menu.pop.sheet { left: 0; right: 0; bottom: 0; top: auto; max-height: 70dvh; border-radius: 16px 16px 0 0; padding-bottom: max(8px, env(safe-area-inset-bottom)); }
    .menu.pop.sheet button { padding: 10px 12px; }
    .dialog { align-items: flex-end; padding: 0; }
    .dlg-box { max-width: none; border-radius: 16px 16px 0 0; padding-bottom: max(18px, env(safe-area-inset-bottom)); }
    input[type=number], input[type=text], select { font-size: 16px; padding: 6px 8px; }
    .ib { width: 40px; height: 40px; }
    .lrow { height: 44px; }
    .lrow .ib { width: 34px; height: 34px; }
    .ps h3[data-fold] { min-height: 32px; margin-bottom: 4px; }
    .grid3 { grid-template-columns: 1fr 1fr; }
    .grid3 > .sf:first-child { grid-column: 1 / -1; }
    .presets { grid-template-columns: repeat(2, 1fr); max-height: 38dvh; }
}

/* Shape Builder and Eraser */
.sb-hover { fill: rgba(79, 140, 255, 0.18); stroke: #4f8cff; stroke-width: 1px; stroke-dasharray: 4 3; }
.sb-picked { fill: rgba(255, 62, 165, 0.22); stroke: #ff3ea5; stroke-width: 1.5px; }
.eraser-trail { fill: none; stroke: rgba(224, 62, 62, 0.35); stroke-linecap: round; stroke-linejoin: round; }
.eraser-ring { fill: none; stroke: var(--ink-2); stroke-width: 1px; }

/* typing in place */
.text-edit {
    position: absolute; z-index: 5; margin: 0; padding: 0; border: 0; outline: 1px dashed #4f8cff; outline-offset: 2px;
    background: transparent; resize: none; overflow: hidden; white-space: pre; caret-color: #4f8cff; min-width: 20px;
}
.text-edit.plain { background: var(--bg); color: var(--ink); padding: 6px 8px; border-radius: 8px; white-space: pre-wrap; box-shadow: var(--shadow); outline: 0; }

/* symbols, recolour */
.symbols { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 8px; }
.sym { position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--ink-2); min-width: 0; }
.sym span { max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sym-thumb { width: 100%; aspect-ratio: 1; border: 1px solid var(--line); border-radius: 8px; background: #fff; display: flex; align-items: center; justify-content: center; padding: 6px; }
.sym-thumb img { max-width: 100%; max-height: 100%; }
.sym .ib { position: absolute; right: 0; top: 0; width: 24px; height: 24px; }
.rc-list { display: flex; flex-direction: column; gap: 4px; max-height: 240px; overflow: auto; }
.rc-row { display: flex; align-items: center; gap: 8px; }
.rc-old, .rc-new { width: 30px; height: 30px; border-radius: 6px; border: 1px solid var(--line); flex: none; }
.rc-row code { font-size: 12px; color: var(--ink-2); }

/* Gradient mesh, freeform gradients, Colour Guide, swatch libraries (mesh.js) */
.mesh-pt.on { stroke: #fff; stroke-width: 2px; filter: drop-shadow(0 0 1.5px rgba(0, 0, 0, 0.9)); }
.grad-stop.on { stroke-width: 3px; }
.pk-kind { flex-wrap: wrap; }
.pk-kind button { flex: 1 0 30%; }
.pk-note { margin: 6px 0 0; }
.cg-base { display: inline-block; width: 12px; height: 12px; border-radius: 3px; border: 1px solid var(--line); vertical-align: -2px; }
.cg-row { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 2px 6px; margin-top: 8px; }
.cg-row > span { grid-column: 1 / -1; font-size: 12px; color: var(--ink-2); }
.cg-row .swatches { grid-template-columns: repeat(7, 1fr); }
.lib-names { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
.lib-names .btn-s.on { background: var(--ink); color: var(--bg); }

/* Shaper, Join, Puppet Warp, corner widgets, Free Transform (reshape.js) */
.shaper-trail { fill: none; stroke: #4f8cff; stroke-width: 2px; stroke-linecap: round; stroke-linejoin: round; opacity: 0.8; }
.open-end { fill: #fff; stroke: #e5484d; stroke-width: 1.5px; }
.pin { fill: rgba(255, 178, 36, 0.35); stroke: #f76b15; stroke-width: 1.5px; }
.pin-dot { fill: #f76b15; }
.corner-w { fill: #fff; stroke: #4f8cff; stroke-width: 1.5px; cursor: pointer; }
.ft-side { fill: #fff; stroke: #4f8cff; stroke-width: 1px; }

/* 3D, perspective grid (depth.js) */
.cube3d { display: flex; align-items: center; gap: 10px; margin: 8px 0; padding: 4px 8px; border: 1px solid var(--line); border-radius: 8px; cursor: grab; touch-action: none; user-select: none; }
.cube3d:active { cursor: grabbing; }
.cube3d svg line { stroke: var(--ink-3); stroke-width: 1.2px; }
.cube3d svg line.front { stroke: var(--accent); stroke-width: 1.8px; }
.cube3d span { font-size: 12px; color: var(--ink-2); }
#perspgrid { pointer-events: none; }
#perspgrid path { fill: none; stroke-width: 1px; vector-effect: non-scaling-stroke; }
#perspgrid .pg-left { stroke: rgba(48, 164, 108, 0.45); }
#perspgrid .pg-right { stroke: rgba(229, 72, 77, 0.45); }
#perspgrid .pg-floor { stroke: rgba(79, 140, 255, 0.45); }
#perspgrid path.on { stroke-width: 1.6px; }
#perspgrid .pg-horizon { stroke: rgba(120, 120, 120, 0.6); stroke-dasharray: 6 4; }
.pg-handle { fill: #fff; stroke: #4f8cff; stroke-width: 1.5px; }
.pg-handle.vp { fill: #4f8cff; }

/* Touch Type (typeset.js) */
.touch-box { fill: none; stroke: #4f8cff; stroke-width: 1px; }
.touch-h { fill: #fff; stroke: #4f8cff; stroke-width: 1.5px; }

/* Graphs, actions, versions, crop, document info (graphs.js, workflow.js) */
.graph-data { width: 100%; font: 13px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); tab-size: 12; resize: vertical; }
.row.wrap { flex-wrap: wrap; }
.act-row { display: flex; align-items: center; gap: 6px; padding: 2px 0; }
.act-row span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.act-row small { color: var(--ink-3); }
.rec-on { padding: 8px; border: 1px solid var(--danger); border-radius: 8px; margin: 6px 0; font-size: 13px; }
.rec-on .ic { color: var(--danger); vertical-align: -3px; }
.rec-steps { margin: 6px 0; padding-left: 20px; font-size: 12px; color: var(--ink-2); }
.ver-list { display: flex; flex-direction: column; gap: 6px; max-height: 50vh; overflow: auto; margin-top: 10px; }
.ver-row { display: flex; align-items: center; gap: 10px; }
.ver-row img, .ver-row > i { width: 64px; height: 44px; object-fit: contain; border: 1px solid var(--line); border-radius: 6px; background: #fff; flex: none; }
.ver-row span { flex: 1; min-width: 0; display: flex; flex-direction: column; font-size: 13px; }
.ver-row small { color: var(--ink-2); }
.crop-shade { fill: rgba(0, 0, 0, 0.45); fill-rule: evenodd; }
.crop-line { fill: none; stroke: #fff; stroke-width: 1.5px; }
.crop-h { fill: #fff; stroke: #4f8cff; stroke-width: 1.5px; }
table.di { border-collapse: collapse; font-size: 13px; width: 100%; }
table.di th { text-align: left; font-weight: 500; color: var(--ink-2); padding: 4px 12px 4px 0; vertical-align: top; white-space: nowrap; }
table.di td { padding: 4px 0; }
.di-sw i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; border: 1px solid var(--line); margin: 0 2px -2px 0; }

/* Short screens (a laptop's 768 px and less): the tools in two columns, so the colour chips stay in sight */
@media (min-width: 768px) and (max-height: 840px) {
    #tools { width: 94px; flex-direction: row; flex-wrap: wrap; align-content: flex-start; justify-content: flex-start; }
    #tools .paint-chips { margin: 8px calc(50% - 22px) 0; }
}
