:root {
  --bg: #f4f2ee;
  --panel: #ffffff;
  --line: #dedad3;
  --text: #24221f;
  --muted: #77726a;
  --accent: #0f8a7e;
  --accent-soft: #dff3f0;
  --danger: #c4372f;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: grid; grid-template-rows: auto 1fr auto; overflow: hidden;
  -webkit-user-select: none; user-select: none; overscroll-behavior: none;
}
button, select, input, textarea { font: inherit; color: inherit; }
button {
  min-height: 40px; padding: 6px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--panel); cursor: pointer; white-space: nowrap;
}
button.on { background: var(--accent-soft); border-color: var(--accent); }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
button.small { min-height: 32px; padding: 3px 10px; font-size: 13px; }
select, input[type=number], input:not([type]) {
  min-height: 40px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 10px; background: #fff;
  -webkit-user-select: text; user-select: text;
}
.group, .row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.hint { color: var(--muted); font-size: 13px; margin: 0; }
.check { display: flex; gap: 6px; align-items: center; cursor: pointer; font-size: 14px; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.slider { display: flex; gap: 6px; align-items: center; color: var(--muted); font-size: 13px; }
.slider input[type=range] { width: 100px; accent-color: var(--accent); }
.slider input[type=number] { width: 64px; }
.slider.wide input[type=range] { flex: 1; width: auto; }
.slider span { min-width: 2.2em; text-align: right; }

#toolbar {
  display: flex; gap: 8px 10px; align-items: center; flex-wrap: wrap;
  padding: 6px 10px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.tools { gap: 3px; }
.tool { display: grid; justify-items: center; gap: 0; min-width: 54px; padding: 3px 4px; font-size: 11px; line-height: 1.1; color: var(--muted); }
.tool i { font-style: normal; font-size: 20px; line-height: 1.2; }
.tool.on { color: var(--text); }
#brushBtn { display: flex; gap: 8px; align-items: center; min-width: 140px; text-align: left;
  border-color: var(--accent); background: var(--accent-soft); }
#brushBtn .stack { display: grid; line-height: 1.15; }
#brushBtn small { font-size: 12px; color: var(--muted); max-width: 110px; overflow: hidden; text-overflow: ellipsis; }
#brushBtn i { font-style: normal; font-size: 20px; }
/* Brush library: categories on the left, the category's brushes with sample strokes on the right */
#brushPop { width: min(680px, calc(100vw - 24px)); height: min(620px, calc(100vh - 90px));
  grid-template-columns: 150px 1fr; gap: 10px; padding: 10px; }
.libCats { display: flex; flex-direction: column; gap: 4px; overflow-y: auto; }
.libCats button { flex: none; text-align: left; white-space: normal; font-weight: 600; }
.libList { overflow-y: auto; overscroll-behavior: contain; display: flex; flex-direction: column; gap: 6px; padding-right: 2px; }
.libRow { flex: none; display: grid; grid-template-columns: 1fr; gap: 4px; justify-items: stretch; text-align: left;
  padding: 8px 10px; min-height: 0; color: var(--text); font-size: 14px; }
.libName { display: grid; grid-template-columns: auto 1fr; column-gap: 8px; align-items: center; }
.libName i { font-style: normal; font-size: 18px; grid-row: span 2; }
.libName small { color: var(--muted); font-size: 12px; white-space: normal; line-height: 1.25; }
.libRow img { width: 100%; height: 66px; object-fit: contain; object-position: left center; }
@media (max-width: 600px) { #brushPop { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .libCats { flex-direction: row; overflow-x: auto; } .libCats button { white-space: nowrap; } }
#swatches { gap: 4px; }
#swatches button { min-height: 28px; width: 28px; padding: 0; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line); }
#swatches button.on { box-shadow: 0 0 0 2px var(--accent); }
#colorBtn { width: 44px; padding: 4px; }
#colorNow { display: block; width: 100%; height: 28px; border-radius: 6px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.15); }

.menu { position: relative; }
.menu summary { list-style: none; cursor: pointer; padding: 9px 14px; border: 1px solid var(--line); border-radius: 10px; }
.menu summary::-webkit-details-marker { display: none; }
.menuBody {
  /* Placed by placeMenu() in app.js so it always stays on screen; scrolls inside when tall. */
  position: fixed; z-index: 20; width: min(340px, calc(100vw - 24px));
  overflow-y: auto; overscroll-behavior: contain;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 10px 14px 14px;
  box-shadow: 0 12px 30px rgba(0,0,0,.12); display: grid; gap: 8px;
}
.menuBody .brand { display: flex; align-items: center; gap: 10px; padding-bottom: 6px; border-bottom: 1px solid var(--line); }
.menuBody .brand img:first-child { height: 64px; }
.menuBody .brand img:last-child { height: 44px; min-width: 0; flex: 1; object-fit: contain; object-position: left center; }
.menuBody h4 { margin: 6px 0 0; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.menuBody .row > * { flex: 1; }
.menuBody .row > .small { flex: none; }

main { display: grid; grid-template-columns: 1fr 300px; min-height: 0; }
main.wide { grid-template-columns: 1fr 0; }
main.wide #side { display: none; }
#stageWrap { position: relative; overflow: hidden; min-height: 0; touch-action: none; }
#stage {
  position: absolute; left: 0; top: 0; transform-origin: 0 0;
  background: #fff; box-shadow: 0 2px 14px rgba(0,0,0,.12);
  /* checkerboard-free white paper; exports stay see-through */
}
#stage canvas, #layersView, .layer { position: absolute; inset: 0; width: 100%; height: 100%; }
.layer { isolation: isolate; }
#stencilView, #paperOver { pointer-events: none; }
#paperOver { mix-blend-mode: multiply; }
.floating {
  position: absolute; z-index: 5; display: flex; gap: 6px; align-items: center;
  background: rgba(255,255,255,.92); border: 1px solid var(--line); border-radius: 12px; padding: 4px;
  box-shadow: 0 4px 14px rgba(0,0,0,.08);
}
#zoomCtl { right: 10px; bottom: 10px; }
#zoomCtl button { min-width: 44px; padding: 4px 8px; }
#moveBar { left: 50%; top: 10px; transform: translateX(-50%); padding: 4px 4px 4px 14px; max-width: calc(100% - 20px); }
#moveBar span { font-size: 14px; }

#side {
  background: var(--panel); border-left: 1px solid var(--line); padding: 4px 12px 16px;
  overflow-y: auto; overscroll-behavior: contain;
}
#side details { border-bottom: 1px solid var(--line); padding: 8px 0 12px; }
#side details > * + *, #stencilCtl > * + *, #traceCtl > * + * { margin-top: 8px; }
#side label.field, #side label.slider, #side label.check { margin-top: 8px; }
#side summary { font-weight: 650; cursor: pointer; padding: 4px 0; list-style-position: inside; }
#side .row > button { flex: 1; padding: 6px 4px; min-width: 0; }
.field { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }

#layerList { display: grid; gap: 4px; max-height: 300px; overflow-y: auto; }
.layerRow {
  display: grid; grid-template-columns: 38px 52px 1fr auto; gap: 6px; align-items: center;
  padding: 4px; border: 1px solid var(--line); border-radius: 10px; background: #fff; text-align: left; min-height: 50px;
}
.layerRow.on { border-color: var(--accent); background: var(--accent-soft); }
.layerRow .eye { min-height: 36px; width: 36px; padding: 0; font-size: 16px; }
.layerRow .eye.off { opacity: .35; }
.layerRow canvas { width: 52px; height: 40px; object-fit: contain; border-radius: 4px; border: 1px solid var(--line);
  background: repeating-conic-gradient(#eeebe5 0% 25%, #fff 0% 50%) 50% / 10px 10px; }
.layerRow .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.layerRow .tags { font-size: 12px; color: var(--muted); }

.shapes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; }
.shapes button { padding: 4px; font-size: 18px; min-height: 44px; }
.shapes button[data-shape="layer"] { grid-column: span 2; font-size: 14px; }
.seg { display: flex; }
.seg button { flex: 1; border-radius: 0; }
.seg button:first-child { border-radius: 10px 0 0 10px; }
.seg button:last-child { border-radius: 0 10px 10px 0; }

#framesBar {
  display: flex; gap: 12px; align-items: center; padding: 6px 10px;
  background: var(--panel); border-top: 1px solid var(--line);
}
#strip { flex: 1; display: flex; gap: 8px; overflow-x: auto; padding: 2px; }
.thumb { position: relative; padding: 3px; min-height: 0; background: #fff; flex: none; }
.thumb canvas { display: block; height: 54px; width: auto; }
.thumb span { position: absolute; left: 5px; bottom: 3px; font-size: 11px; color: var(--muted); }

.pop {
  position: fixed; z-index: 30; background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 12px; box-shadow: 0 12px 30px rgba(0,0,0,.16); display: grid; gap: 10px; width: 286px;
}
#wheel { width: 280px; height: 280px; justify-self: center; touch-action: none; cursor: crosshair; }
#bright { width: 100%; height: 22px; -webkit-appearance: none; appearance: none; border-radius: 11px; background: linear-gradient(90deg, #000, #fff); }
#bright::-webkit-slider-thumb { -webkit-appearance: none; width: 26px; height: 26px; border-radius: 50%; background: #fff; border: 2px solid #555; }
#colorPreview { width: 40px; height: 40px; border-radius: 8px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.15); }
#hex { flex: 1; min-width: 0; font-family: ui-monospace, monospace; }
#colorPop { width: 320px; max-height: calc(100vh - 80px); overflow-y: auto; overscroll-behavior: contain; }
#colorPop select { width: 100%; }
#palette { display: grid; grid-template-columns: repeat(10, 1fr); gap: 3px; }
#palette button { min-height: 0; aspect-ratio: 1; padding: 0; border-radius: 5px; border: none; box-shadow: inset 0 0 0 1px rgba(0,0,0,.1); }
#palette button.named { aspect-ratio: auto; height: 34px; grid-column: span 2; font-size: 10px; line-height: 1.1;
  white-space: normal; text-align: left; padding: 2px 4px; display: flex; align-items: flex-end; }
#mine button, #recent button { min-height: 28px; width: 28px; padding: 0; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line); }

/* folding the frames bar, and focus mode (only the paper and the zoom buttons) */
body.barsLow #framesBar { padding: 2px 10px; }
body.barsLow #framesBar > :not(#barToggle) { display: none; }
body.barsLow #barToggle::after { content: " Frames"; }
body.focus #toolbar, body.focus #framesBar, body.focus #side { display: none !important; }
body.focus main { grid-template-columns: 1fr !important; grid-template-rows: 1fr !important; }
#unfocus { left: 10px; top: 10px; padding: 6px 14px; font-weight: 600; }
#sideGrip { display: none; }

#penPop { width: min(560px, calc(100vw - 24px)); }
#penPop h4 { margin: 0; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.meter { height: 10px; border-radius: 5px; background: var(--line); overflow: hidden; }
.meter span { display: block; height: 100%; width: 0; background: var(--accent); }
#penTest { width: 100%; height: 120px; border: 1px dashed var(--line); border-radius: 10px; background: #fff; touch-action: none; }

#toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); z-index: 40;
  background: #2b2925; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s; max-width: 90vw;
}
#toast.show { opacity: 1; }
#toast.err { background: var(--danger); }

/* website only: home button and the Wall of Fame dialog */
#homeBtn { display: grid; place-items: center; flex: none; }
#homeBtn img { width: 40px; height: 40px; object-fit: contain; }
#fameDlg {
  border: 1px solid var(--line); border-radius: 16px; padding: 18px; width: min(420px, calc(100vw - 32px));
  background: var(--panel); color: var(--text); box-shadow: 0 16px 40px rgba(0,0,0,.2);
}
#fameDlg::backdrop { background: rgba(30,28,25,.45); }
#fameForm { display: grid; gap: 12px; }
#fameForm h3 { margin: 0; }
#famePreview { width: 100%; max-height: 40vh; object-fit: contain; border-radius: 10px; border: 1px solid var(--line); background: #fff; }
#fameForm .field { display: grid; gap: 4px; font-size: 14px; color: var(--muted); }
#fameForm input { width: 100%; color: var(--text); }

@media (max-width: 900px) {
  main { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  main.wide { grid-template-columns: 1fr; grid-template-rows: 1fr 0; }
  #side { border-left: none; border-top: 1px solid var(--line); height: var(--sideH, 34vh); max-height: 75vh; padding-top: 0; }
  #sideGrip { display: grid; place-items: center; position: sticky; top: 0; z-index: 2; height: 26px;
    margin: 0 -12px; background: var(--panel); touch-action: none; cursor: ns-resize; }
  #sideGrip span { width: 56px; height: 5px; border-radius: 3px; background: #c9c3b9; }
  #framesBar { flex-wrap: wrap; }
}
