:root {
  --bg: #1d1e21;
  --panel: #27282c;
  --panel2: #313237;
  --text: #e7e7e9;
  --muted: #9b9da4;
  --accent: #2b8cff;
  /* the accent behind white text: dark enough to read (contrast 4.9 : 1) */
  --accent-fill: #1a6fd6;
  --border: #3c3e44;
  --warn: #ffd166;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
/* safe areas: inside Discord on a phone its own controls cover the edges of the Activity (Discord gives the
   insets as --discord-safe-area-inset-*); elsewhere the device's (notches) – usually none */
:root {
  --sait: var(--discord-safe-area-inset-top, env(safe-area-inset-top, 0px));
  --sair: var(--discord-safe-area-inset-right, env(safe-area-inset-right, 0px));
  --saib: var(--discord-safe-area-inset-bottom, env(safe-area-inset-bottom, 0px));
  --sail: var(--discord-safe-area-inset-left, env(safe-area-inset-left, 0px));
}
body { padding: var(--sait) var(--sair) var(--saib) var(--sail); }
body {
  display: flex; flex-direction: column;
  background: var(--bg); color: var(--text);
  font: 13px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  user-select: none;
}

button {
  background: var(--panel2); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 4px 10px; font: inherit; cursor: pointer;
}
button:hover { border-color: #60636c; }
button:disabled { opacity: .4; cursor: default; }
button.primary { background: var(--accent-fill); border-color: var(--accent); color: #fff; }
input[type=text], input[type=number] {
  background: #1b1c1f; color: var(--text);
  border: 1px solid var(--border); border-radius: 5px;
  padding: 4px 6px; font: inherit; min-width: 0;
}
input[type=number] { width: 64px; }
input[type=color] { width: 36px; height: 24px; padding: 0; border: 1px solid var(--border); background: none; vertical-align: middle; }
input:focus { outline: 1px solid var(--accent); }
kbd { font: 11px ui-monospace, monospace; padding: 0 4px; border: 1px solid var(--border); border-radius: 3px; color: var(--muted); }

#topbar {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 10px; background: var(--panel); border-bottom: 1px solid var(--border);
  /* too many buttons for the window: the bar scrolls, not the page */
  overflow-x: auto; scrollbar-width: thin;
}
#topbar .brand { font-weight: 600; margin-right: 10px; letter-spacing: .02em; }
#topbar > * { flex: none; }
#topbar .sep { width: 1px; height: 20px; background: var(--border); margin: 0 4px; }
#zoom-label { min-width: 48px; text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; }

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

#tools {
  width: 50px; flex: none; display: flex; flex-direction: column; gap: 5px;
  padding: 7px; background: var(--panel); border-right: 1px solid var(--border);
  /* a short window: the tools scroll (they were cut off under the status bar) */
  min-height: 0; overflow-y: auto; scrollbar-width: none;
}
#tools button { flex: none; width: 36px; height: 36px; padding: 0; display: grid; place-items: center; }
#tools svg { width: 20px; height: 20px; fill: currentColor; }
#tools svg .st { fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linejoin: round; }
#tools button.active { background: var(--accent-fill); border-color: var(--accent); color: #fff; }
/* the vector app's Simple mode (for children): bigger tools with a word under each, bigger color swatches */
body:not([data-mode=simple]) .simple-only { display: none !important; }
/* hand-laid lines (handlaid.ts): the even lines hide under their tapered pieces (still there to edit) */
#mz-shapes.hand :not(.mz-fill):not(g) { stroke-opacity: 0; }
#tools #btn-hand { margin-top: 6px; position: relative; }
#tools #btn-hand::before { content: ''; position: absolute; left: 4px; right: 4px; top: -6px; border-top: 1px solid var(--border); }
#tools #btn-hand svg { fill: currentColor; }
body.in-discord .app-switch.expert { display: inline-flex !important; }
#tools .tl { display: none; }
body.app-vector[data-mode=simple] #tools { width: 74px; }
body.app-vector[data-mode=simple] #tools button { width: 60px; height: 54px; grid-template-rows: auto auto; gap: 2px; align-content: center; }
body.app-vector[data-mode=simple] #tools svg { width: 24px; height: 24px; }
body.app-vector[data-mode=simple] #tools .tl { display: block; font-size: 11px; line-height: 1; }
body.app-vector[data-mode=simple] #palette { grid-template-columns: repeat(auto-fill, minmax(46px, 1fr)); gap: 8px; }
body.app-vector[data-mode=simple] .active-colors .acbox { width: 46px; height: 46px; }
/* children don't remove colors by accident (the small × on touch screens) */
body.app-vector[data-mode=simple] .swatch .del { display: none !important; }
/* phones and tablets: the colors along the bottom of the drawing too (kid-colors.ts) */
#kid-colors { display: none; }
@media (max-width: 900px) {
  body.app-vector[data-mode=simple] #kid-colors {
    display: flex; gap: 8px; position: absolute; left: 0; right: 0; bottom: 0; z-index: 3; padding: 8px; overflow-x: auto;
    background: rgba(39,40,44,.94); border-top: 1px solid var(--border); scrollbar-width: none;
  }
}
#kid-colors .kc { flex: none; width: 44px; height: 44px; padding: 0; border-radius: 10px; border: 2px solid rgba(255,255,255,.25); }
#kid-colors .kc.none { background: repeating-linear-gradient(135deg, #f4f4f4 0 9px, #f4f4f4 9px, #e23 9px 11px, #f4f4f4 11px 20px); }
#kid-colors .kc.active { border-color: #fff; box-shadow: 0 0 0 2px var(--accent); }

#stage { flex: 1; position: relative; overflow: hidden; background: #3b3c41; }
.canvas-layer { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#overlay { pointer-events: none; will-change: transform; }
/* the app does its own hit testing; letting the browser hit-test thousands of shapes on every move is slow */
#mz-doc, #mz-ref, #mz-page, #mz-gridrect { pointer-events: none; }
#stage[data-tool=line] #canvas, #stage[data-tool=ngon] #canvas { cursor: crosshair; }
#stage[data-tool=bucket] #canvas { cursor: cell; }
#stage[data-tool=pan] #canvas, #stage.space #canvas { cursor: grab; }
#stage.panning #canvas { cursor: grabbing; }
#stage.drop { outline: 3px dashed var(--accent); outline-offset: -6px; }
/* raster app: one canvas shows the image; the brush outline is drawn on it */
#stage[data-tool] #view { cursor: crosshair; }
#stage[data-tool=bucket] #view { cursor: cell; }
#stage[data-tool=pan] #view, #stage.space #view { cursor: grab; }
#stage.panning #view { cursor: grabbing; }

#mz-page { stroke: rgba(0,0,0,.45); stroke-width: 1; vector-effect: non-scaling-stroke; filter: drop-shadow(0 2px 10px rgba(0,0,0,.45)); }
.sel-outline { fill: none; stroke: #2b8cff; stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.handle { fill: #fff; stroke: #2b8cff; stroke-width: 1.2; vector-effect: non-scaling-stroke; }
.handle.ngon { fill: #ffd166; }
.sel-ctrl { fill: none; stroke: #2b8cff; stroke-width: 1; stroke-dasharray: 3 3; opacity: .7; vector-effect: non-scaling-stroke; }
.snap-mark { fill: none; stroke: #ff2d78; stroke-width: 1.6; vector-effect: non-scaling-stroke; }
.snap-label { fill: #ff2d78; font-family: system-ui, sans-serif; }
.preview { opacity: .85; }
.preview-ghost { fill: none; stroke: #2b8cff; stroke-width: 1; stroke-dasharray: 4 3; vector-effect: non-scaling-stroke; }
.marquee { fill: rgba(43,140,255,.08); stroke: #2b8cff; stroke-width: 1; stroke-dasharray: 4 3; vector-effect: non-scaling-stroke; }

#panel {
  width: 300px; flex: none; overflow-y: auto;
  background: var(--panel); border-left: 1px solid var(--border);
}
#panel section { padding: 10px 12px; border-bottom: 1px solid var(--border); }
#panel h3 { margin: 0 0 8px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }
#panel h3 span:not(.expert):not(.simple-only) { text-transform: none; letter-spacing: 0; font-weight: 400; }
.row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.row.small button { padding: 3px 8px; font-size: 12px; }
.note { margin: 8px 0 0; font-size: 11.5px; color: var(--muted); }
label.chk { display: flex; align-items: center; gap: 6px; margin: 4px 0; }
.seg label { display: flex; align-items: center; gap: 4px; }
.quick { display: inline-flex; gap: 3px; }
.quick button { padding: 2px 7px; font-size: 12px; }
.quick button.active { border-color: var(--accent); color: #fff; background: #23477a; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.grid3 label { display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: var(--muted); }
.grid3 input { width: 100%; }
.btns button { flex: 1; padding: 4px 4px; font-size: 12px; }

.active-colors { display: flex; align-items: flex-end; gap: 10px; margin-bottom: 10px; }
.ac { display: flex; flex-direction: column; gap: 2px; font-size: 11px; color: var(--muted); }
.acbox { width: 34px; height: 26px; border-radius: 5px; border: 1px solid rgba(255,255,255,.25); }
.acbox.none, .swatch.none {
  background: linear-gradient(to top right, transparent calc(50% - 1.5px), #e5484d calc(50% - 1.5px), #e5484d calc(50% + 1.5px), transparent calc(50% + 1.5px)), #f2f2f2;
}
#btn-swap { padding: 2px 7px; margin-bottom: 2px; }
.sw-w { margin-left: auto; display: flex; flex-direction: column; font-size: 11px; color: var(--muted); }
.sw-w input { width: 60px; }

#palette { display: grid; grid-template-columns: repeat(auto-fill, minmax(34px, 1fr)); gap: 6px; }
.swatch {
  position: relative; aspect-ratio: 1; border-radius: 6px; cursor: pointer;
  border: 1px solid rgba(255,255,255,.18);
}
.swatch.is-fill { outline: 2px solid #fff; outline-offset: 2px; }
.swatch.is-stroke::before {
  content: ''; position: absolute; inset: 4px; border-radius: 3px;
  border: 2px dashed #fff; mix-blend-mode: difference;
}
.swatch .count {
  position: absolute; left: 2px; bottom: 2px; padding: 0 3px; border-radius: 3px;
  background: rgba(0,0,0,.6); color: #fff; font-size: 9.5px; line-height: 13px;
}
.swatch .del {
  display: none; position: absolute; top: -7px; right: -7px;
  width: 17px; height: 17px; padding: 0; border-radius: 50%;
  font-size: 12px; line-height: 14px; background: #44464d;
}
.swatch:hover .del { display: block; }
.add-row input { flex: 1; }
.mini { width: 22px; height: 22px; border-radius: 4px; border: 1px solid var(--border); flex: none; }

details summary { cursor: pointer; color: var(--muted); }
.keys { margin-top: 8px; border-collapse: collapse; font-size: 12px; }
.keys td { padding: 2px 6px 2px 0; vertical-align: top; }
.keys td:first-child { color: var(--muted); white-space: nowrap; font-family: ui-monospace, monospace; font-size: 11px; }

#status {
  display: flex; gap: 18px; align-items: center; padding: 4px 10px;
  background: var(--panel); border-top: 1px solid var(--border);
  font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden;
}
#st-pos { min-width: 130px; font-variant-numeric: tabular-nums; }
#st-hint { overflow: hidden; text-overflow: ellipsis; }
#st-msg { margin-left: auto; color: var(--warn); }
#st-version { padding: 0 6px; border: 0; background: none; color: var(--muted); font-size: 11px; }
#st-version.new { color: #fff; background: var(--accent-fill); border-radius: 4px; }
#dlg-whats-new { width: min(560px, 96vw); }
#dlg-whats-new h3 { margin: 14px 0 4px; font-size: 14px; }
#dlg-whats-new ul { margin: 0; padding-left: 18px; line-height: 1.5; }

/* ---- modes ---- */
[hidden] { display: none !important; }
body[data-mode=simple] .expert { display: none !important; }
.seg-btns { display: inline-flex; flex-wrap: wrap; max-width: 100%; border: 1px solid var(--border); border-radius: 7px; overflow: hidden; }
.seg-btns button { flex: 1 0 auto; border: 0; border-radius: 0; padding: 4px 11px; background: transparent; color: var(--muted); }
.seg-btns button.active { background: var(--accent-fill); color: #fff; }
.seg-btns a { padding: 4px 11px; color: var(--muted); text-decoration: none; }
.seg-btns a:hover { color: var(--text); }
.seg-btns a[aria-current] { background: var(--accent-fill); color: #fff; }
select {
  background: #1b1c1f; color: var(--text); border: 1px solid var(--border);
  border-radius: 5px; padding: 3px 5px; font: inherit; max-width: 100%;
}
input[type=range] { accent-color: var(--accent); vertical-align: middle; }
label.grow { display: flex; align-items: center; gap: 8px; flex: 1; }
label.grow input { flex: 1; }
.pal-row select { flex: 1; min-width: 0; }
.pal-row button { padding: 3px 8px; }
button.active { border-color: var(--accent); }

/* ---- canvas extras ---- */
.sym-guide { stroke: #c24dff; stroke-width: 1; stroke-dasharray: 6 4; vector-effect: non-scaling-stroke; opacity: .7; }
.sym-center { fill: none; stroke: #c24dff; stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.gap-mark { fill: rgba(229,72,77,.15); stroke: #e5484d; stroke-width: 2; vector-effect: non-scaling-stroke; animation: pulse 0.8s ease-in-out infinite alternate; }
@keyframes pulse { from { opacity: 1; } to { opacity: .35; } }
.measure { fill: #fff; paint-order: stroke; stroke: rgba(0,0,0,.75); stroke-width: 3px; font-family: system-ui, sans-serif; vector-effect: non-scaling-stroke; }
#mz-shapes.grout :not(.mz-fill):not(g) { stroke: var(--grout-color) !important; stroke-width: var(--grout-width) !important; stroke-linecap: round; }

#stage.with-rulers .canvas-layer { inset: 20px 0 0 20px; width: calc(100% - 20px); height: calc(100% - 20px); }
.ruler { position: absolute; z-index: 2; display: block; }
#ruler-x { left: 20px; top: 0; right: 0; height: 20px; width: calc(100% - 20px); border-bottom: 1px solid var(--border); }
#ruler-y { left: 0; top: 20px; bottom: 0; width: 20px; height: calc(100% - 20px); border-right: 1px solid var(--border); }
#ruler-corner {
  position: absolute; left: 0; top: 0; width: 20px; height: 20px; z-index: 2;
  background: var(--panel); color: var(--muted); font-size: 9px; display: grid; place-items: center;
  border-right: 1px solid var(--border); border-bottom: 1px solid var(--border);
}
#stage-actions {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); z-index: 3;
  display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; padding: 6px; border-radius: 10px; max-width: calc(100% - 16px); box-sizing: border-box;
  background: rgba(39,40,44,.92); border: 1px solid var(--border); box-shadow: 0 4px 16px rgba(0,0,0,.4);
}
#stage-actions[hidden], #stage-actions [hidden] { display: none; }
/* by the selection (select.ts places it) */
#stage-actions.follow { bottom: auto; transform: none; padding: 4px; gap: 4px; }
#stage-actions .icon { min-width: 36px; min-height: 34px; padding: 4px; }

/* ---- panels ---- */
table.layers { border-collapse: collapse; width: 100%; }
table.layers td { padding: 3px 0; }
table.layers td:not(:first-child) { width: 36px; text-align: center; }
table.layers button { width: 30px; padding: 2px 0; }
table.layers button.off { opacity: .55; }

/* ---- dialogs ---- */
dialog {
  background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px 18px 16px; width: min(760px, calc(100vw - 24px)); max-height: calc(100vh - 40px);
  box-shadow: 0 12px 40px rgba(0,0,0,.5);
}
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog h2 { margin: 0; font-size: 16px; }
.dlg-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.dlg-head button { padding: 2px 9px; }
.dlg-foot { justify-content: flex-end; margin-top: 12px; }
.dlg-foot .note { margin: 0 auto 0 0; }
.table-wrap { max-height: 55vh; overflow: auto; margin-top: 10px; border: 1px solid var(--border); border-radius: 8px; }
#rep-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
#rep-table th { position: sticky; top: 0; background: var(--panel2); text-align: left; font-weight: 600; color: var(--muted); }
#rep-table th, #rep-table td { padding: 5px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
#rep-table td .mini { display: inline-block; width: 20px; height: 16px; vertical-align: middle; }
#rep-table select { max-width: 150px; }
#rep-tw, #rep-th, #rep-waste { width: 56px; }
#hist-list { margin-top: 10px; max-height: 60vh; overflow: auto; display: flex; flex-direction: column; gap: 6px; }
.hist-row { display: flex; align-items: center; gap: 12px; padding: 6px; border: 1px solid var(--border); border-radius: 8px; }
.hist-row img { width: 64px; height: 64px; object-fit: contain; background: #fff; border-radius: 4px; flex: none; }
.hist-info { flex: 1; display: flex; flex-direction: column; font-size: 12.5px; min-width: 0; }
.hist-info span { color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.hist-row.pinned { border-color: var(--accent); }
.hist-row button { flex: none; }
.hist-pin { color: var(--muted); }
.hist-pin[aria-pressed="true"] { color: #e9a400; }

/* ---- phones & tablets ---- */
#btn-panel { display: none; }
@media (max-width: 900px) {
  #topbar { overflow-x: auto; scrollbar-width: none; }
  #topbar .brand, #zoom-label, #btn-zoomin, #btn-zoomout { display: none; }
  #topbar button { flex: none; }
  #btn-panel { display: inline-block; margin-left: auto; }
  #panel {
    position: fixed; z-index: 20; top: calc(var(--topbar-h, 42px) + var(--sait)); right: var(--sair); bottom: var(--saib); width: min(340px, 88vw);
    transform: translateX(100%); transition: transform .2s ease; box-shadow: -8px 0 24px rgba(0,0,0,.45);
  }
  body.panel-open #panel { transform: none; }
  #st-hint { display: none; }
}
@media (pointer: coarse) {
  #tools button { width: 44px; height: 44px; }
  #tools { width: 58px; }
  button { padding: 6px 12px; }
  .swatch .del { display: block; }
}

dialog hr { border: 0; border-top: 1px solid var(--border); margin: 10px 0; }
.note.warn { color: var(--warn); }
#am-count { width: 52px; }

/* ---- color mix ---- */
.mix-box { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border); }
.mix-chips { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0; }
.mix-chip { width: 22px; height: 22px; border-radius: 4px; border: 1px solid rgba(255,255,255,.3); cursor: pointer; }
.swatch.in-mix::after { content: ''; position: absolute; right: 3px; top: 3px; width: 7px; height: 7px; border-radius: 50%; background: #fff; box-shadow: 0 0 0 1.5px #000; }

/* ---- vision checks ---- */
.contrast-mark { fill: rgba(255,45,120,.22); stroke: #ff2d78; stroke-width: 2; vector-effect: non-scaling-stroke; }
#rep-alike ul { margin: 6px 0 0; padding-left: 18px; font-size: 12.5px; }
#rep-alike li { margin: 3px 0; }
#rep-alike .mini { display: inline-block; width: 16px; height: 14px; vertical-align: middle; }
#rep-alike h3 { margin: 12px 0 0; font-size: 13px; color: var(--warn); }
#view-filter { max-width: 150px; }
#lang-select { max-width: 92px; }

/* ---- pages ---- */
#pagebar {
  display: flex; align-items: center; gap: 4px; padding: 3px 8px 0 58px;
  background: var(--bg); border-top: 1px solid var(--border); overflow-x: auto; scrollbar-width: thin;
}
#page-tabs { display: flex; gap: 2px; }
.page-tab { display: flex; flex: none; border: 1px solid var(--border); border-bottom: 0; border-radius: 6px 6px 0 0; background: var(--panel); }
.page-tab button { border: 0; background: none; border-radius: 6px 6px 0 0; padding: 3px 10px; font-size: 12px; color: var(--muted); }
.page-tab.active { background: var(--panel2); border-color: #55585f; }
.page-tab.active button { color: var(--text); }
.page-tab .page-more { padding: 3px 6px; }
#page-add { flex: none; padding: 2px 8px; font-size: 12px; background: none; border-style: dashed; }
#page-menu {
  position: fixed; z-index: 50; display: flex; flex-direction: column; min-width: 140px; padding: 4px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.45);
}
#page-menu button { border: 0; text-align: left; background: none; padding: 5px 10px; }
#page-menu button:hover:not(:disabled) { background: var(--panel2); }

/* ---- motifs ---- */
.motif-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 6px; }
.motif { position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px; cursor: pointer;
  border: 1px solid var(--border); border-radius: 6px; background: var(--panel2); }
.motif:hover, .motif.active { border-color: var(--accent); }
.motif img { width: 100%; height: 56px; object-fit: contain; background: #fff; border-radius: 3px; }
.motif span { font-size: 11px; color: var(--muted); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.motif .del { display: none; position: absolute; top: -6px; right: -6px; width: 17px; height: 17px; padding: 0; border-radius: 50%; font-size: 12px; line-height: 14px; }
.motif:hover .del { display: block; }

/* ---- laying plan ---- */
.panel-rect { fill: none; stroke: #ff8c1a; stroke-width: 2; stroke-dasharray: 8 5; vector-effect: non-scaling-stroke; }
.panel-label { fill: rgba(255,140,26,.75); font-family: system-ui, sans-serif; font-weight: 700; text-anchor: middle; dominant-baseline: central; }
#lp-w, #lp-h { width: 64px; }

/* ---- shared mosaics (read-only viewer) ---- */
.grow-input { flex: 1; font-family: ui-monospace, monospace; font-size: 11px; }
#viewer-bar { display: none; }
body.viewer #viewer-bar {
  display: flex; align-items: center; gap: 8px; position: absolute; z-index: 4; left: 50%; top: 12px; transform: translateX(-50%);
  padding: 8px 12px; border-radius: 10px; background: rgba(39,40,44,.95); border: 1px solid var(--border); box-shadow: 0 4px 16px rgba(0,0,0,.4);
}
body.viewer #tools, body.viewer #panel, body.viewer #page-add, body.viewer .page-more,
body.viewer #topbar > button:not(#btn-fit):not(#btn-zoomin):not(#btn-zoomout):not(#btn-report),
body.viewer #mode-switch, body.viewer #btn-panel { display: none !important; }

/* 3D print dialog (both apps) */
#dlg-3d { width: min(720px, 96vw); }
.m3-body { display: flex; gap: 14px; margin-top: 10px; align-items: flex-start; flex-wrap: wrap; }
.m3-view { display: flex; flex-direction: column; gap: 6px; }
.m3-tabs { align-self: flex-start; }
.m3-mode { margin: 4px 0 2px; flex-wrap: wrap; }
.m3-finish { margin-top: 6px; }
.m3-finish summary { cursor: pointer; color: var(--muted); font-size: 13px; }
#m3-3d { width: 300px; height: 300px; border-radius: 6px; cursor: grab; }
#m3-preview { max-width: 300px; max-height: 300px; background: repeating-conic-gradient(#d9d9d9 0 25%, #fff 0 50%) 0 0 / 16px 16px; border-radius: 6px; image-rendering: pixelated; }
.m3-side { flex: 1; min-width: 260px; }
#m3-order { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; max-height: 260px; overflow: auto; }
.m3-row { display: flex; align-items: center; gap: 6px; font-size: 12.5px; }
.m3-row .note { margin: 0 auto 0 0; }
.m3-row button { padding: 1px 7px; }
.m3-row code { font-size: 12px; }
.m3-row .tag { font-size: 11px; padding: 0 5px; border: 1px solid var(--border); border-radius: 4px; color: var(--muted); background: none; }
.m3-row .tag.on { color: #fff; background: var(--accent-fill); border-color: var(--accent); }

body.working, body.working * { cursor: progress !important; }

/* examples and the newcomers' guide */
#dlg-examples { width: min(560px, 96vw); }
.ex-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; margin-top: 10px; }
.ex-card { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; padding: 10px; text-align: left; white-space: normal; height: auto; }
.ex-card img { width: 100%; height: 120px; object-fit: contain; image-rendering: pixelated; background: repeating-conic-gradient(#d9d9d9 0 25%, #fff 0 50%) 0 0 / 16px 16px; border-radius: 6px; }
.ex-card .note { margin: 0; }
#guide { position: fixed; inset: auto 16px 44px auto; margin: 0; width: min(340px, calc(100vw - 32px)); z-index: 50; box-shadow: 0 8px 30px rgba(0, 0, 0, .25); }
#guide h2 { font-size: 16px; }
#guide .guide-text { margin: 8px 0 4px; line-height: 1.45; }
.guide-target { outline: 3px solid var(--accent) !important; outline-offset: 2px; border-radius: 6px; }
#btn-guide { font-weight: 700; min-width: 30px; }

/* the G-code check in the 3D dialog */
.m3-check { margin: 8px 0 0; padding: 8px 10px; border-radius: 6px; border: 1px solid var(--border); font-size: 13px; }
.m3-check ul { margin: 6px 0 0; padding-left: 4px; list-style: none; }
.m3-check li.ok { color: var(--muted); }
.m3-check li.bad { font-weight: 600; }
.m3-check.bad { border-color: #d9822b; }

/* keyboard focus is always visible; less motion when the system asks for it */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* inside Discord (the Activity): no installing or share links – the post button instead */
.in-discord #btn-install, .in-discord #btn-share { display: none !important; }

/* questions asked in the page (dialogs.ts) and the color chooser (color-picker.ts) */
#dlg-ask { width: min(420px, 94vw); }
#dlg-ask .ask-msg { white-space: pre-line; margin: 0 0 10px; }
#dlg-ask .ask-input { width: 100%; }
#dlg-color { width: min(340px, 94vw); }
/* setting up the palette from pasted colors (palette-setup.ts) */
#dlg-palsetup { width: min(520px, 94vw); }
#dlg-palsetup .ps-text { width: 100%; box-sizing: border-box; font: 12px/1.4 ui-monospace, monospace; resize: vertical; margin: 6px 0; }
#dlg-palsetup .ps-found { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 10px; max-height: 180px; overflow: auto; }
#dlg-palsetup .ps-swatch { width: 34px; height: 34px; padding: 0; border-radius: 6px; border: 2px solid rgba(255,255,255,.35); }
#dlg-palsetup .ps-swatch.off { opacity: .25; border-style: dashed; }
.cp-sv { position: relative; height: 180px; border-radius: 6px; cursor: crosshair; touch-action: none;
  background-image: linear-gradient(to top, #000, transparent), linear-gradient(to right, #fff, transparent); }
.cp-knob { 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, .6); pointer-events: none; }
.cp-hue { width: 100%; margin: 10px 0 6px; -webkit-appearance: none; appearance: none; height: 14px; border-radius: 7px;
  background: linear-gradient(to right, #f00, #ff0, #0f0, #0ff, #00f, #f0f, #f00); }
.cp-row { align-items: center; gap: 6px; }
.cp-old, .cp-new { width: 34px; height: 26px; border-radius: 5px; border: 1px solid rgba(255, 255, 255, .25); }
.cp-hex { flex: 1; min-width: 0; font-family: ui-monospace, monospace; }
.acbox[role=button] { cursor: pointer; }

/* the quick menu (quick-menu.ts): double-tap the drawing with a finger; it grows out of the finger */
#quick-menu { position: fixed; inset: 0; z-index: 70; background: rgba(0, 0, 0, .12); touch-action: none; }
#quick-menu[hidden] { display: none; }
#quick-menu::before {
  /* a ring where the finger tapped */
  content: ""; position: absolute; left: var(--qx); top: var(--qy); width: 56px; height: 56px; margin: -28px 0 0 -28px;
  border-radius: 50%; border: 2px solid var(--accent); opacity: 0; pointer-events: none;
}
#quick-menu.ripple::before { animation: qm-ripple .45s ease-out; }
@keyframes qm-ripple { from { transform: scale(.3); opacity: .9; } to { transform: scale(1.5); opacity: 0; } }
.qm-card {
  position: absolute; width: min(296px, calc(100vw - 20px)); padding: 8px; display: flex; flex-direction: column; gap: 8px;
  background: rgba(39, 40, 44, .94); border: 1px solid var(--border); border-radius: 20px;
  box-shadow: 0 14px 44px rgba(0, 0, 0, .5), 0 0 0 1px rgba(255, 255, 255, .03) inset;
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  opacity: 0; transform: scale(.35);
  transition: transform .26s cubic-bezier(.2, 1.15, .35, 1), opacity .16s ease-out;
}
.qm-card.in { opacity: 1; transform: none; }
/* the rows follow the card in, one after another */
.qm-card > * { opacity: 0; transform: translateY(6px); transition: opacity .2s ease-out, transform .24s cubic-bezier(.2, 1.1, .35, 1); }
.qm-card.in > * { opacity: 1; transform: none; }
.qm-card.in > :nth-child(2) { transition-delay: .03s; }
.qm-card.in > :nth-child(3) { transition-delay: .06s; }
.qm-card.in > :nth-child(4) { transition-delay: .09s; }
.qm-card.in > :nth-child(5) { transition-delay: .12s; }
.qm-row { display: flex; align-items: center; gap: 6px; }
.qm-grow { flex: 1; }
.qm-card button { border: none; -webkit-tap-highlight-color: transparent; transition: transform .1s, background-color .15s; }
.qm-card button:active:not(:disabled) { transform: scale(.92); }
.qm-icon { width: 40px; height: 40px; padding: 0; border-radius: 12px; background: transparent; font-size: 19px; display: grid; place-items: center; }
.qm-icon svg { width: 20px; height: 20px; }
.qm-card svg .st { fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linejoin: round; stroke-linecap: round; }
.qm-head { border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.qm-tools { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.qm-tool { height: 50px; padding: 0; border-radius: 14px; background: var(--panel2); display: grid; place-items: center; }
.qm-tool svg { width: 24px; height: 24px; fill: currentColor; }
.qm-tool.active { background: var(--accent-fill); color: #fff; box-shadow: 0 4px 14px rgba(43, 140, 255, .35); }
.qm-target { flex: 1; height: 42px; padding: 0 10px; border-radius: 14px; background: var(--panel2); display: flex; align-items: center; gap: 8px;
  box-shadow: 0 0 0 2px transparent inset; }
.qm-target.active { box-shadow: 0 0 0 2px var(--accent) inset; }
.qm-chip { width: 24px; height: 24px; border-radius: 50%; flex: none; border: 2px solid rgba(255, 255, 255, .25); }
.qm-chip.none { background: repeating-conic-gradient(#888 0 25%, #ddd 0 50%) 0 0 / 8px 8px !important; }
.qm-tname { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qm-swatches { display: grid; grid-template-columns: repeat(var(--qm-cols, 7), minmax(36px, 1fr)); justify-items: center; gap: 7px; padding: 3px; }
.qm-swatches.scroll { grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: 36px; grid-template-rows: repeat(var(--qm-rows, 1), 36px);
  justify-content: start; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; }
.qm-swatches::-webkit-scrollbar { display: none; }
.qm-swatch { width: 36px; height: 36px; padding: 0; border-radius: 50%; scroll-snap-align: start; box-shadow: 0 0 0 1px rgba(255, 255, 255, .18) inset; }
.qm-swatch.active { box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--accent); }
.qm-empty { color: var(--muted); padding: 6px 4px; grid-column: 1 / -1; white-space: normal; width: 260px; }
.qm-size { padding: 0 4px 2px; }
.qm-size input { flex: 1; accent-color: var(--accent); min-width: 0; height: 28px; }
.qm-size output { min-width: 58px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
@media (prefers-reduced-motion: reduce) {
  .qm-card, .qm-card > * { transition: opacity .12s; transform: none; }
  #quick-menu.ripple::before { animation: none; }
}
#quick-menu.closing { pointer-events: none; background: transparent; transition: background-color .15s; }
#quick-menu.closing .qm-card { transition-duration: .15s; transition-timing-function: ease-in; }

/* sheets: dialogs along the bottom that leave the picture visible above them (adjust-ui.ts) */
dialog.sheet { margin: auto auto 0; width: min(640px, 100vw); max-height: 44vh; overflow: auto; border-radius: 16px 16px 0 0;
  padding-bottom: calc(12px + var(--saib)); }
dialog.sheet::backdrop { background: transparent; }
.adj-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 4px 18px; }
.adj-row { display: grid; grid-template-columns: 7.5em 1fr 3em; align-items: center; gap: 8px; min-height: 34px; }
.adj-row input { width: 100%; accent-color: var(--accent); }
.adj-row output { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.adj-busy { margin-left: auto; }

/* the Text tool's sheet (text.ts) */
#dlg-text .tx-text { width: 100%; font: 16px/1.3 system-ui, sans-serif; background: #1b1c1f; color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 8px; resize: vertical; margin-bottom: 6px; }
#dlg-text .row.wrap { flex-wrap: wrap; gap: 8px 12px; margin-bottom: 6px; }
#dlg-text .seg-btns button { min-width: 36px; }
/* a sheet's buttons stay in reach while its settings scroll */
dialog.sheet .dlg-foot { position: sticky; bottom: calc(-12px - var(--saib)); background: var(--panel); margin: 0 -18px calc(-12px - var(--saib)); padding: 8px 18px calc(10px + var(--saib)); border-top: 1px solid var(--border); z-index: 1; }

/* add-ons (addons.ts): the list in the side panel, the download dialog */
.addon-row { display: flex; gap: 10px; align-items: flex-start; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--border); }
.addon-row .note { font-size: 12px; }
.addon-row button { flex: none; }
#dlg-addon { width: min(460px, 94vw); }
.addon-progress { display: flex; align-items: center; gap: 10px; margin: 10px 0; }
.addon-progress progress { flex: 1; height: 10px; accent-color: var(--accent); }
#dlg-ocr .ocr-text { width: 100%; font: 14px/1.4 ui-monospace, monospace; background: #1b1c1f; color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 8px; }
#dlg-relief .rl-preview { display: block; max-width: 100%; max-height: 40vh; margin: 8px auto; border: 1px solid var(--border); image-rendering: auto; }
#dlg-relief .row.wrap, #dlg-bg .row.wrap { flex-wrap: wrap; gap: 6px 14px; }

/* layers (raster, layers.ts) */
#layer-list { list-style: none; margin: 0 0 6px; padding: 0; border: 1px solid var(--border); border-radius: 8px; max-height: 240px; overflow: auto; }
#layer-list li { display: flex; align-items: center; gap: 8px; padding: 4px 6px; cursor: pointer; border-bottom: 1px solid var(--border); }
#layer-list li:last-child { border-bottom: 0; }
#layer-list li.active { background: rgba(43, 140, 255, .18); box-shadow: inset 3px 0 0 var(--accent); }
#layer-list .layer-eye { width: 30px; height: 30px; padding: 0; flex: none; background: transparent; border: 0; font-size: 16px; }
#layer-list .layer-eye[aria-pressed=false] { color: var(--muted); }
#layer-list .layer-thumb { flex: none; width: 48px; height: 36px; border-radius: 4px; background: repeating-conic-gradient(#666 0 25%, #888 0 50%) 0 0 / 8px 8px; }
#layer-list .layer-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* choosing a frame of a GIF or a video (frames.ts) */
#dlg-frame { width: min(640px, 96vw); }
#dlg-frame .fr-stage { display: grid; place-items: center; background: repeating-conic-gradient(#555 0 25%, #666 0 50%) 0 0 / 16px 16px; border-radius: 8px; overflow: hidden; }
#dlg-frame .fr-canvas, #dlg-frame .fr-video { display: block; width: 100%; height: auto; max-height: 50vh; object-fit: contain; }
#dlg-frame .fr-canvas { image-rendering: pixelated; }
#dlg-frame .fr-canvas[hidden], #dlg-frame .fr-video[hidden] { display: none; }
#dlg-frame .fr-slider { width: 100%; margin: 12px 0 4px; accent-color: var(--accent); height: 28px; }
#dlg-frame .fr-controls button { min-width: 44px; min-height: 40px; }

/* icons (icons.ts): outlines in the text color */
svg.ic { width: 18px; height: 18px; display: block; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
svg.ic .dot, svg.ic .knob { fill: currentColor; }
svg.ic .knob { stroke: var(--panel2); stroke-width: 1.2; }
button.icon { padding: 4px 7px; display: inline-grid; place-items: center; min-width: 32px; min-height: 28px; }
.qm-icon svg.ic { width: 21px; height: 21px; }
@media (max-width: 760px) { button.icon { min-width: 40px; min-height: 36px; } svg.ic { width: 20px; height: 20px; } }
#dlg-adjust .adj-group { margin: 10px 0 2px; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
button.icon-text { display: inline-flex; align-items: center; gap: 5px; }
button.icon-text svg.ic { width: 16px; height: 16px; }
.qm-extra { display: contents; }
/* a long message wraps instead of running off the screen; on a phone it takes the tool hint's place */
#st-msg { white-space: normal; text-align: right; min-width: 0; overflow-wrap: anywhere; }
@media (max-width: 760px) {
  #status:has(#st-msg:not(:empty)) #st-hint, #status:has(#st-msg:not(:empty)) #st-pos { display: none; }
  #st-msg { margin-left: 0; text-align: left; }
}
