/*
 * Pip's Studio themes, in the site's Botanical Press palette.
 *   Workbench (dark, default): deep forest charcoal, kept low in color so the canvas looks true.
 *   Sketchbook (light): sage paper, the same look as pipandpixel.net.
 * Terracotta clay is the accent in both. Picked with the theme button; set on <html data-theme>.
 */
:root {
  --surround: #343a37;      /* around the canvas */
  --base: #1e2321;          /* inputs, cards */
  --raised: #272d2a;        /* panels */
  --hover: #343a37;
  --line: #46504b;          /* borders, slider tracks */
  --panel: rgba(39, 45, 42, .94);
  --panel-border: rgba(255, 255, 255, .08);
  --text: #e7ece8;
  --muted: #a5b0aa;
  --strong: #f6f8f5;        /* names, values */
  --highlight: #a3c4ad;     /* headings, selected outlines: light sage */
  --scrim: rgba(12, 16, 14, .6);
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --clay: #d48162;
  --clay-dark: #a6573b;
  --accent-hover: #e0957a;
  --on-accent: #ffffff;     /* text on clay, both themes */
  --robin: #8fb8c2;
  --font-pixel: "Pixelify Sans", system-ui, sans-serif;   /* logo only */
  --font-serif: "Lora", Georgia, serif;                   /* headings */
  --font-display: "Space Grotesk", system-ui, sans-serif;
  --font-body: "Nunito", system-ui, sans-serif;
  color-scheme: dark;
}

:root[data-theme="sketchbook"] {
  --surround: #dfe6e0;
  --base: #ffffff;
  --raised: #f4f6f4;
  --hover: #eaefea;
  --line: #c5d1c7;
  --panel: rgba(255, 255, 255, .94);
  --panel-border: rgba(35, 48, 43, .1);
  --text: #23302b;
  --muted: #52635c;
  --strong: #1b2621;
  --highlight: #5b7e68;
  --accent-hover: #c77252;
  --robin: #588591;
  --scrim: rgba(35, 48, 43, .3);
  --shadow: 0 8px 24px rgba(35, 48, 43, .12);
  color-scheme: light;
}

:root[data-theme="sketchbook"] .badge { color: var(--robin); border-color: rgba(88, 133, 145, .45); }

/* Imported tip shapes are white; show them dark on light panels */
:root[data-theme="sketchbook"] .tip-icon { filter: brightness(0) opacity(.75); }

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--base);
  color: var(--text);
  font-family: var(--font-body);
  /* No text selection, callouts or tap flashes while drawing */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
/*
 * The studio is a fixed app screen, not a scrolling page: pin both the page and the body
 * so iPad Safari can't rubber-band them, and only let real scroll areas pan (below).
 */
html { position: fixed; inset: 0; }
body { position: fixed; inset: 0; touch-action: none; }

/* Places that are meant to scroll: they scroll, and stop at their ends instead of dragging the page */
.ly-list, .ly-props, .help-body, .gl-grid, .gl-new, .ws-list, .ws-settings, .view-menu {
  touch-action: pan-y;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.help-nav, .brushes { touch-action: pan-x; overscroll-behavior: contain; }
input, textarea, select { touch-action: manipulation; }

#view {
  position: fixed;
  left: 0;
  top: 0;
  display: block;
  touch-action: none; /* the canvas handles every touch itself */
  cursor: crosshair;
}
#view.pan-ready { cursor: grab; }
#view.panning { cursor: grabbing; }

button { font: inherit; color: inherit; touch-action: manipulation; }

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}

/* Top bars */
.bar {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px;
}
.bar-left { left: max(12px, env(safe-area-inset-left)); padding: 10px 16px; }
.bar-right { right: max(12px, env(safe-area-inset-right)); }

.brand {
  font-family: var(--font-pixel);
  font-weight: 700;
  font-size: 1.35rem;
  line-height: 1;
  color: var(--strong);
  text-decoration: none;
  white-space: nowrap;
}
.brand span { color: var(--clay); }

.badge {
  margin-left: .6rem;
  padding: .15rem .55rem;
  border: 1px solid rgba(143, 184, 194, .4);
  border-radius: 999px;
  font: 600 .68rem var(--font-display);
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--robin);
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.icon-btn[hidden] { display: none; }
.icon-btn:hover { background: var(--hover); }
.icon-btn:disabled { opacity: .35; cursor: default; background: transparent; }
.icon-btn[aria-pressed="true"] { background: var(--line); color: var(--highlight); }
.icon-btn svg, .brush svg { width: 22px; height: 22px; }

/* Bottom dock */
.dock {
  position: fixed;
  left: 50%;
  bottom: max(12px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px 18px;
  width: max-content;
  max-width: calc(100vw - 24px);
  padding: 10px 14px;
}

.brushes { display: flex; gap: 4px; }
.brush {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  width: 54px;
  height: 56px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font: 600 .68rem var(--font-display);
  cursor: pointer;
}
.brush > span { max-width: 50px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brush:hover { background: var(--hover); color: var(--text); }
.brush[aria-checked="true"] {
  background: var(--clay);
  color: var(--on-accent);
  box-shadow: 0 3px 0 var(--clay-dark);
}

.sliders { display: flex; gap: 14px; }
.slider {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 130px;
  font: 600 .75rem var(--font-display);
  color: var(--muted);
}
.slider > span, .slider small { display: flex; justify-content: space-between; }
.slider small { font: 600 .68rem var(--font-body); }
output { color: var(--strong); font-variant-numeric: tabular-nums; }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 28px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track { height: 6px; border-radius: 999px; background: var(--line); }
input[type="range"]::-moz-range-track { height: 6px; border-radius: 999px; background: var(--line); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  margin-top: -8px;
  border: 3px solid var(--base);
  border-radius: 50%;
  background: var(--highlight);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .2);
}
input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border: 3px solid var(--base);
  border-radius: 50%;
  background: var(--highlight);
}
input[type="range"]:focus-visible { outline: 2px solid var(--robin); outline-offset: 2px; border-radius: 6px; }

.colors { display: flex; align-items: center; gap: 12px; }
.swatches { display: grid; grid-template-columns: repeat(6, 24px); gap: 6px; }
.swatch {
  width: 24px;
  height: 24px;
  padding: 0;
  border: 2px solid rgba(128, 118, 106, .35);
  border-radius: 7px;
  cursor: pointer;
}
.swatch[aria-checked="true"] { outline: 2px solid var(--highlight); outline-offset: 2px; }

.custom-color {
  position: relative;
  display: block;
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: conic-gradient(#f44, #fd4, #4e6, #4de, #46f, #d4f, #f44);
  cursor: pointer;
}
.custom-color input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.custom-color .current {
  position: absolute;
  inset: 5px;
  border: 3px solid var(--raised);
  border-radius: 10px;
  pointer-events: none;
}

/* More menu: on narrow screens (phones), the less-used top buttons live here */
.more-only { display: none; }
@media (max-width: 699px) {
  .bar-right .secondary { display: none; }
  .bar-right .more-only { display: grid; }
}
.more-menu {
  position: fixed;
  top: calc(max(12px, env(safe-area-inset-top)) + 62px);
  right: max(12px, env(safe-area-inset-right));
  z-index: 9;
  display: flex;
  flex-direction: column;
  min-width: 220px;
  padding: 6px;
}
.more-menu button {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  padding: 0 12px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  font: 600 .92rem var(--font-display);
  text-align: left;
  cursor: pointer;
}
.more-menu button:hover { background: var(--hover); }
.more-menu svg { width: 20px; height: 20px; flex: none; color: var(--muted); }

/* Long-press / right-click menu */
/* Move & resize bar: under the top bars, centered */
.xf-bar {
  position: fixed;
  top: calc(max(12px, env(safe-area-inset-top)) + 66px);
  left: 0;
  right: 0;
  width: fit-content;
  margin: 0 auto; /* centered, and free to use the full width on phones */
  z-index: 8;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px 12px;
  max-width: calc(100vw - 24px);
  padding: 8px 10px;
}
.xf-bar[hidden] { display: none; }
.xf-title { font: 600 .8rem var(--font-display); color: var(--muted); white-space: nowrap; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.xf-title strong { color: var(--strong); }
.xf-btns { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.xf-btns .ws-btn { padding: .4rem .75rem; font-size: .78rem; }
.ws-btn.primary { background: var(--clay); border-color: var(--clay); color: var(--on-accent); }
.ws-btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
#view.transforming { cursor: move; }
@media (max-width: 520px) { .sel-bar:not(.compact) #selHint { display: none; } } /* phones: a shorter Select bar */
/* with a brush and a selection: just the note and Deselect */
.sel-bar.compact .seg,
.sel-bar.compact [data-sel]:not([data-sel="none"]) { display: none; }

/* "Paste here" box */
.paste-box {
  position: fixed;
  top: 28%;
  left: 0;
  right: 0;
  width: min(320px, calc(100vw - 32px));
  margin: 0 auto;
  z-index: 25;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
}
.paste-box[hidden] { display: none; }
.paste-title { font: 700 1rem var(--font-serif); color: var(--highlight); }
.paste-how { margin: 0; font-size: .85rem; color: var(--text); }
.paste-target {
  min-height: 90px;
  display: grid;
  place-items: center;
  border: 2px dashed var(--clay);
  border-radius: 12px;
  background: var(--base);
  color: var(--muted);
  font: 600 .9rem var(--font-display);
  outline: none;
  caret-color: transparent;
  /* the page turns off selection and the iOS callout; this box needs both for Paste */
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
  touch-action: manipulation;
}
.paste-target:empty::before { content: attr(data-placeholder); }
.paste-target:focus { border-style: solid; }
.paste-box .ws-btn { align-self: flex-end; }

.ctx-menu {
  position: fixed;
  z-index: 30;
  display: flex;
  flex-direction: column;
  min-width: 200px;
  max-width: calc(100vw - 16px);
  padding: 6px;
}
.ctx-title {
  padding: 6px 12px 4px;
  font: 600 .72rem var(--font-display);
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ctx-menu button {
  min-height: 40px;
  padding: 0 12px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--text);
  font: 600 .9rem var(--font-display);
  text-align: left;
  cursor: pointer;
}
.ctx-menu button:hover:not(:disabled) { background: var(--hover); }
.ctx-menu button:disabled { opacity: .4; cursor: default; }
.ctx-menu button.danger { color: #e5484d; }
.ctx-sep { width: 100%; margin: 4px 0; border: 0; border-top: 1px solid var(--panel-border); }

/* View menu (theme + table) */
.view-menu {
  position: fixed;
  z-index: 8;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 250px;
  padding: 12px 14px;
}
.vm-group { display: flex; flex-direction: column; gap: 4px; }
.vm-label { font: 600 .75rem var(--font-display); color: var(--muted); }
.vm-note { font-size: .72rem; color: var(--muted); }
.seg { display: flex; padding: 3px; gap: 3px; border-radius: 12px; background: var(--base); border: 1px solid var(--line); }
.seg button {
  flex: 1;
  padding: .45rem .7rem;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--text);
  font: 600 .85rem var(--font-display);
  cursor: pointer;
}
.seg button:hover { background: var(--hover); }
.seg-4 button { padding: .45rem .35rem; font-size: .8rem; }
.seg .dot { display: inline-block; width: 9px; height: 9px; margin-right: 5px; border-radius: 3px; vertical-align: 0; }
.vm-grid { padding-top: 10px; border-top: 1px solid var(--panel-border); }
.vm-label small { font-weight: 400; opacity: .8; }
.vm-grid-opts { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.view-menu { min-width: 300px; max-height: calc(100vh - 100px); overflow-y: auto; }
.seg button[aria-pressed="true"] { background: var(--clay); color: var(--on-accent); }

/* Help */
.help-wrap {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  background: var(--scrim);
}
.help-panel {
  display: flex;
  flex-direction: column;
  width: min(760px, 100%);
  height: min(820px, 100%);
  overflow: hidden;
  background: var(--raised);
}
.help-ref {
  margin-left: auto;
  margin-right: 8px;
  font: 600 .82rem var(--font-display);
  color: var(--highlight);
  text-decoration: none;
}
.help-ref:hover { text-decoration: underline; }
.help-body a { color: var(--highlight); }
.help-nav {
  display: flex;
  gap: 6px;
  padding: 10px 16px;
  overflow-x: auto;
  border-bottom: 1px solid var(--panel-border);
  scrollbar-width: none;
}
.help-nav a {
  flex: none;
  padding: .35rem .75rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--base);
  color: var(--text);
  font: 600 .78rem var(--font-display);
  text-decoration: none;
}
.help-nav a:hover { border-color: var(--robin); }
.help-body {
  flex: 1;
  overflow-y: auto;
  padding: 6px 22px 28px;
  font-size: .95rem;
  line-height: 1.55;
  -webkit-user-select: text;
  user-select: text;
}
.help-body section { padding-top: 14px; scroll-margin-top: 8px; }
.help-body h3 { margin: 0 0 6px; font: 700 1.15rem var(--font-serif); color: var(--highlight); }
.help-body p { margin: 0 0 10px; }
.help-body ul { margin: 0 0 10px; padding-left: 1.2rem; }
.help-body li { margin-bottom: 4px; }
.help-body strong { color: var(--strong); }
.help-body code { font-size: .85em; padding: .05em .35em; border-radius: 5px; background: var(--base); }
.help-body table { width: 100%; border-collapse: collapse; margin: 4px 0 12px; font-size: .88rem; }
.help-body th, .help-body td { padding: 6px 8px; text-align: left; border-bottom: 1px solid var(--panel-border); vertical-align: top; }
.help-body th { font: 600 .75rem var(--font-display); color: var(--muted); }
.help-note {
  padding: 10px 12px;
  border-left: 3px solid var(--clay);
  border-radius: 0;
  background: var(--base);
}

/* Ko-fi support button (a plain link, no third-party script) */
.kofi {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: .45rem .9rem .45rem .7rem;
  border-radius: 999px;
  background: #2f4a3b;
  color: #fff;
  font: 700 .85rem var(--font-display);
  text-decoration: none;
  white-space: nowrap;
  box-shadow: 0 2px 0 rgba(0, 0, 0, .25);
}
.kofi:hover { filter: brightness(1.15); }
.kofi svg { width: 20px; height: 20px; flex: none; }
.kofi-small { padding: .3rem .7rem .3rem .55rem; font-size: .78rem; }
.kofi-small svg { width: 16px; height: 16px; }
.wl-support { margin: 14px 0 0; font-size: .82rem; color: var(--muted); }

/* Welcome pop-up */
.welcome-wrap {
  position: fixed;
  inset: 0;
  z-index: 25;
  display: grid;
  place-items: center;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: var(--scrim);
}
.welcome {
  width: min(460px, 100%);
  max-height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  padding: 24px 24px 20px;
  background: var(--raised);
  text-align: center;
}
.wl-icon { display: block; margin: 0 auto 10px; border-radius: 16px; }
.welcome h2 { margin: 0 0 6px; font: 700 1.5rem var(--font-serif); color: var(--highlight); }
.welcome p { margin: 0 0 14px; color: var(--muted); }
.wl-tips { margin: 0 0 16px; padding: 0; list-style: none; text-align: left; display: flex; flex-direction: column; gap: 8px; }
.wl-tips li {
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--base);
  font-size: .92rem;
  line-height: 1.45;
}
.wl-tips strong { color: var(--strong); }
.wl-dont { display: inline-flex; align-items: center; gap: 8px; margin-bottom: 14px; font: 600 .85rem var(--font-display); color: var(--muted); cursor: pointer; }
.wl-dont input { width: 18px; height: 18px; accent-color: var(--clay); }
.wl-actions { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }
.wl-actions a.btn { display: inline-flex; align-items: center; text-decoration: none; }
#moved .wl-tips li:first-child { background: transparent; padding: 0 2px 2px; }

/* Color panel */
.custom-color { border: 0; padding: 0; }
.custom-color[aria-expanded="true"] { box-shadow: 0 0 0 2px var(--highlight); }
.color-panel {
  position: fixed;
  right: max(12px, env(safe-area-inset-right));
  z-index: 8;
  width: min(380px, calc(100vw - 24px));
  max-height: calc(100vh - 160px);
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.cp-top { display: flex; gap: 14px; align-items: center; }
#cpWheel { flex: none; touch-action: none; cursor: crosshair; }
.cp-side { display: flex; flex-direction: column; gap: 10px; min-width: 0; flex: 1; }
.cp-now { height: 56px; border-radius: 12px; border: 1px solid var(--line); }
.cp-hex { display: flex; flex-direction: column; gap: 2px; font: 600 .75rem var(--font-display); color: var(--muted); }
.cp-hex input {
  width: 100%;
  padding: .45rem .6rem;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: var(--base);
  color: var(--text);
  font: 600 .95rem ui-monospace, Menlo, Consolas, monospace;
  -webkit-user-select: text;
  user-select: text;
}
.cp-hex input:focus { outline: none; border-color: var(--robin); }
.cp-section { display: flex; flex-direction: column; gap: 6px; padding-top: 10px; border-top: 1px solid var(--panel-border); }
.cp-row, .cp-grid { display: flex; flex-wrap: wrap; gap: 6px; }
.cp-row .swatch, .cp-grid .swatch { width: 30px; height: 30px; }
.cp-empty { color: var(--muted); font-size: .75rem; }
.cp-pal-pick { display: flex; align-items: center; gap: 8px; }
.cp-pal-pick select {
  flex: 1;
  min-width: 0;
  padding: .4rem .5rem;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: var(--base);
  color: var(--text);
  font: 600 .85rem var(--font-display);
}
.cp-actions .ws-btn { padding: .35rem .65rem; font-size: .75rem; }
.swatch.removable { position: relative; }
.swatch.removable::after {
  content: "×";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: 5px;
  background: rgba(20, 17, 14, .55);
  color: #fff;
  font: 700 1rem var(--font-display);
}
@media (max-width: 420px) {
  .cp-top { flex-direction: column; align-items: stretch; }
  #cpWheel { align-self: center; }
  .cp-side { flex-direction: row; align-items: flex-end; flex-wrap: wrap; }
  .cp-now { flex: 1 0 60px; height: 40px; }
}

/* Layers panel */
.layers {
  position: fixed;
  top: calc(max(12px, env(safe-area-inset-top)) + 66px);
  right: max(12px, env(safe-area-inset-right));
  bottom: calc(var(--dock-top, 108px) + 12px); /* stops above the dock, whatever its height */
  z-index: 5;
  display: flex;
  flex-direction: column;
  width: 290px;
  max-height: 640px;
  padding: 10px;
}
.ly-head { display: flex; align-items: center; gap: 8px; padding: 0 2px 6px 6px; }
.ly-head h2 { margin: 0; font: 700 1.05rem var(--font-serif); color: var(--highlight); }
.ly-count { flex: 1; font: 600 .72rem var(--font-display); color: var(--muted); }
.ly-list { flex: 1; min-height: 110px; overflow-y: auto; margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 4px; }
.ly-row {
  display: grid;
  grid-template-columns: 22px 56px 1fr auto auto;
  grid-template-rows: auto auto;
  column-gap: 8px;
  align-items: center;
  padding: 6px;
  border: 2px solid transparent;
  border-radius: 12px;
  background: var(--base);
  cursor: pointer;
}
.ly-row:hover { background: var(--hover); }
.ly-row.active { border-color: var(--clay); }
.ly-row.hidden-layer .ly-thumb, .ly-row.hidden-layer .ly-name { opacity: .45; }
.ly-thumb {
  grid-row: 1 / 3;
  width: 56px;
  height: 42px;
  border-radius: 5px;
  background: repeating-conic-gradient(#e3e7ef 0 25%, #fff 0 50%) 0 0 / 10px 10px;
}
.ly-thumb { grid-column: 2; }
.ly-name { grid-column: 3; grid-row: 1; font: 600 .9rem var(--font-display); color: var(--strong); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.ly-meta { grid-column: 3; grid-row: 2; font-size: .72rem; color: var(--muted); }
.ly-icon[data-lock] { grid-column: 4; }
.ly-icon[data-eye] { grid-column: 5; }
/* drag handle: claims its touches so dragging it moves the layer, not the list */
.ly-grip {
  grid-column: 1;
  grid-row: 1 / 3;
  align-self: stretch;
  display: grid;
  place-items: center;
  margin: -6px 0 -6px -6px;
  padding-left: 4px;
  color: var(--muted);
  cursor: grab;
  touch-action: none;
}
.ly-grip svg { width: 12px; height: 24px; }
.ly-row.dragging { position: relative; z-index: 2; box-shadow: 0 6px 18px rgba(0, 0, 0, .3); opacity: .92; cursor: grabbing; }
.ly-row.dragging .ly-grip { cursor: grabbing; }
.ly-row.drop-before { box-shadow: 0 -3px 0 var(--clay); }
.ly-row.drop-after { box-shadow: 0 3px 0 var(--clay); }
.ly-icon {
  grid-row: 1 / 3;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.ly-icon svg { width: 18px; height: 18px; }
.ly-icon:hover { background: var(--hover); color: var(--text); }
.ly-icon[data-lock][aria-pressed="true"] { color: var(--highlight); }
.ly-icon[data-eye][aria-pressed="true"] { color: var(--muted); opacity: .7; }
.ly-props { display: flex; flex-direction: column; gap: 8px; padding-top: 10px; margin-top: 8px; border-top: 1px solid var(--panel-border); flex: 0 1 auto; min-height: 0; overflow-y: auto; }
.ly-active-label { font-size: .78rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ly-active-label strong { color: var(--strong); }
.ly-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.ly-actions .ws-btn { padding: .35rem .65rem; font-size: .75rem; }

/* Pen readout */
.hud {
  position: fixed;
  top: calc(max(12px, env(safe-area-inset-top)) + 66px);
  left: max(12px, env(safe-area-inset-left)); /* left, so it doesn't cover the Layers panel */
  z-index: 5;
  width: 260px;
  padding: 14px 16px;
  font-size: .85rem;
}
.hud h2 { margin: 0 0 8px; font: 700 1.05rem var(--font-serif); color: var(--highlight); }
.hud dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0 0 10px; }
.hud dt { color: var(--muted); }
.hud dd { margin: 0; text-align: right; color: var(--strong); font-variant-numeric: tabular-nums; white-space: nowrap; }
.meter {
  display: inline-block;
  width: 64px;
  height: 6px;
  margin-right: 6px;
  overflow: hidden;
  vertical-align: middle;
  border-radius: 999px;
  background: var(--line);
}
.meter span { display: block; width: 0; height: 100%; background: var(--robin); }

/* Dock brush icons from imported tips (white shapes) */
.tip-icon { width: 24px; height: 24px; object-fit: contain; }
.brush[aria-checked="true"] .tip-icon { filter: brightness(0); }
.brushes { max-width: min(560px, calc(100vw - 48px)); overflow-x: auto; scrollbar-width: none; }

/* Brush Workshop */
.workshop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  background: var(--scrim);
}
.ws-panel {
  display: flex;
  flex-direction: column;
  width: min(1180px, 100%);
  height: min(820px, 100%);
  overflow: hidden;
  background: var(--raised);
}
.ws-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px 10px 20px;
  border-bottom: 1px solid var(--panel-border);
}
.ws-head h2 { margin: 0; font: 700 1.35rem var(--font-serif); color: var(--highlight); }

.ws-body {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr) 320px;
}
.ws-side {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--panel-border);
}
.ws-list { flex: 1; overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 2px; }
.ws-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  font: 600 .9rem var(--font-display);
  text-align: left;
  cursor: pointer;
}
.ws-item svg, .ws-item .tip-icon { flex: none; width: 22px; height: 22px; }
.ws-item:hover { background: var(--hover); }
.ws-item[aria-pressed="true"] { background: var(--clay); color: var(--on-accent); }
.ws-item[aria-pressed="true"] .tip-icon { filter: brightness(0); }
.ws-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ws-tag { font: 600 .62rem var(--font-display); text-transform: uppercase; letter-spacing: .06em; opacity: .7; }
.ws-dot { width: 8px; height: 8px; border-radius: 2px; background: var(--robin); flex: none; }
.ws-actions { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px; border-top: 1px solid var(--panel-border); }
.ws-files { padding-top: 8px; }

.ws-btn {
  padding: .45rem .8rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--base);
  color: var(--text);
  font: 600 .8rem var(--font-display);
  cursor: pointer;
}
.ws-btn:hover { border-color: var(--robin); }
.ws-btn:disabled { opacity: .35; cursor: default; border-color: var(--line); }
.ws-btn[aria-pressed="true"] { background: var(--line); border-color: var(--highlight); color: var(--highlight); }
.ws-btn.danger:not(:disabled):hover { border-color: #e5484d; color: #ff8a8d; }
.ws-row { display: flex; flex-wrap: wrap; gap: 6px; }

.ws-padwrap { display: flex; flex-direction: column; min-width: 0; min-height: 0; padding: 12px; gap: 8px; }
.ws-pad {
  flex: 1;
  width: 100%;
  min-height: 200px;
  border-radius: 12px;
  background: #fff;
  touch-action: none;
  cursor: crosshair;
}
.ws-padbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: .82rem; color: var(--muted); }

.ws-settings {
  overflow-y: auto;
  padding: 12px 16px 20px;
  border-left: 1px solid var(--panel-border);
  -webkit-user-select: none;
}
.ws-field { display: flex; flex-direction: column; gap: 2px; margin-bottom: 8px; min-width: 0; }
.ws-namefield { font: 600 .75rem var(--font-display); color: var(--muted); }
.ws-namefield input {
  padding: .5rem .7rem;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: var(--base);
  color: var(--text);
  font: 600 1rem var(--font-body);
  -webkit-user-select: text;
  user-select: text;
}
.ws-namefield input:focus { outline: none; border-color: var(--robin); }
.ws-group { margin: 12px 0 0; padding: 10px 0 0; border: 0; border-top: 1px solid var(--panel-border); }
.ws-group legend { padding: 0; font: 700 .95rem var(--font-serif); color: var(--highlight); }
.ws-toggle { display: flex; align-items: center; gap: 10px; margin: 6px 0 10px; font: 600 .8rem var(--font-display); color: var(--text); cursor: pointer; }
.ws-toggle input { width: 20px; height: 20px; accent-color: var(--clay); }

.ws-tip { display: flex; gap: 12px; align-items: flex-start; margin: 6px 0 12px; }
.ws-tip-preview { flex: none; width: 72px; height: 72px; border-radius: 12px; background: #272d2a; border: 1px solid var(--line); } /* dark in both themes: tips are white shapes */
.ws-tip-buttons { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.ws-tip-title { font: 600 .75rem var(--font-display); color: var(--muted); }
.ws-tip-buttons small { color: var(--muted); font-size: .72rem; line-height: 1.35; }
.ws-from { margin: -2px 0 8px; font-size: .75rem; color: var(--muted); }
.ws-more { display: inline-flex; align-items: center; text-decoration: none; color: var(--highlight); }

/* Export pack dialog (sits over the Workshop) */
.ws-pack { z-index: 3; }
.ws-pack-quick { margin-bottom: 8px; }
.ws-pack-quick .ws-btn { padding: .3rem .6rem; font-size: .75rem; }
.ws-pack-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 4px;
  max-height: 40vh;
  overflow-y: auto;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--base);
}
.ws-pack-item { display: flex; align-items: center; gap: 8px; padding: 5px 6px; border-radius: 8px; font: 600 .82rem var(--font-display); cursor: pointer; min-width: 0; }
.ws-pack-item:hover { background: var(--hover); }
.ws-pack-item input { flex: none; width: 18px; height: 18px; accent-color: var(--clay); }
.ws-pack-item svg, .ws-pack-item .tip-icon { flex: none; width: 20px; height: 20px; }
#wsPackCount { font-weight: 400; }

@media (max-width: 980px) {
  .ws-body { grid-template-columns: 170px minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) minmax(0, 1fr); }
  .ws-side { grid-row: 1 / 3; }
  .ws-settings { border-left: 0; border-top: 1px solid var(--panel-border); }
}
@media (max-width: 640px) {
  .ws-body { grid-template-columns: 1fr; grid-template-rows: auto minmax(220px, 1fr) minmax(0, 1fr); }
  .ws-side { grid-row: auto; border-right: 0; border-bottom: 1px solid var(--panel-border); }
  .ws-list { flex-direction: row; overflow-x: auto; overflow-y: hidden; }
  .ws-item { width: auto; flex: none; }
  .ws-actions { padding: 6px 8px; }
  .ws-padbar > span:first-child { display: none; }
}

/* Drawing name in the top bar */
.bar-left { gap: 8px; padding: 6px 8px 6px 16px; }
.bar-left .badge { margin-left: 2px; }
.drawing-name {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font: 600 .85rem var(--font-display);
  color: var(--muted);
  padding-right: 8px;
}

.btn {
  padding: .5rem 1.3rem;
  border: 0;
  border-radius: 999px;
  background: var(--clay);
  color: var(--on-accent);
  font: 600 .95rem var(--font-display);
  box-shadow: 0 3px 0 var(--clay-dark);
  cursor: pointer;
}
.btn:hover { background: var(--accent-hover); }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--clay-dark); }

/* Gallery */
.gallery {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  background: var(--scrim);
}
.gl-panel {
  display: flex;
  flex-direction: column;
  width: min(1180px, 100%);
  height: min(820px, 100%);
  overflow: hidden;
  background: var(--raised);
}
.gl-grid {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr));
  align-content: start;
  gap: 16px;
  padding: 16px;
}
.gl-card {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  background: var(--base);
}
.gl-card.current { border-color: var(--clay); box-shadow: 0 0 0 1px var(--clay); }
.gl-thumb {
  display: grid;
  place-items: center;
  aspect-ratio: 4 / 3;
  padding: 10px;
  border: 0;
  background:
    linear-gradient(rgba(255,255,255,.03) 1px, transparent 1px) 0 0 / 16px 16px,
    linear-gradient(90deg, rgba(255,255,255,.03) 1px, transparent 1px) 0 0 / 16px 16px,
    var(--hover);
  cursor: pointer;
}
.gl-thumb img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 4px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .4);
  background: repeating-conic-gradient(#e3e7ef 0 25%, #fff 0 50%) 0 0 / 12px 12px;
}
.gl-info { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px 4px; min-width: 0; }
.gl-name { font: 700 1rem var(--font-display); color: var(--strong); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gl-meta { font-size: .78rem; color: var(--muted); }
.gl-actions { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 12px 12px; }
.gl-actions .ws-btn { padding: .35rem .65rem; font-size: .75rem; }

.gl-add {
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 220px;
  border: 2px dashed var(--line);
  color: var(--muted);
  font: 600 1rem var(--font-display);
  cursor: pointer;
}
.gl-add:hover { border-color: var(--robin); color: var(--text); }
.gl-plus { font: 700 2.6rem var(--font-pixel); color: var(--highlight); line-height: 1; }

.gl-new {
  position: absolute;
  z-index: 2;
  width: min(520px, calc(100% - 24px));
  max-height: calc(100% - 24px);
  overflow-y: auto;
  padding: 18px 20px;
  background: var(--raised);
}
.gl-new h3 { margin: 0 0 12px; font: 700 1.2rem var(--font-serif); color: var(--highlight); }
.gl-fieldset { margin: 10px 0 0; padding: 0; border: 0; }
.gl-fieldset legend { margin-bottom: 6px; font: 600 .75rem var(--font-display); color: var(--muted); }
.gl-presets { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.gl-preset { display: block; cursor: pointer; }
.gl-preset input { position: absolute; opacity: 0; }
.gl-preset span {
  display: flex;
  flex-direction: column;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--base);
}
.gl-preset strong { font: 600 .85rem var(--font-display); color: var(--text); }
.gl-preset small { font-size: .72rem; color: var(--muted); }
.gl-preset input:checked + span { border-color: var(--highlight); box-shadow: 0 0 0 1px var(--highlight); }
.gl-preset input:focus-visible + span { outline: 2px solid var(--robin); outline-offset: 2px; }
.gl-custom { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 10px; font: 600 .8rem var(--font-display); color: var(--muted); }
.gl-custom input {
  width: 90px;
  margin-left: 4px;
  padding: .4rem .5rem;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--base);
  color: var(--text);
  font: 600 .9rem var(--font-body);
  -webkit-user-select: text;
  user-select: text;
}
.gl-custom small { flex-basis: 100%; font-weight: 400; }
.gl-paper { display: inline-flex; align-items: center; gap: 6px; margin-right: 10px; font: 600 .85rem var(--font-display); cursor: pointer; }
.gl-paper input { accent-color: var(--clay); }
.gl-paper .sw { width: 18px; height: 18px; border-radius: 5px; border: 1px solid var(--line); }
.gl-paper .sw-clear { background: repeating-conic-gradient(#c9cfdb 0 25%, #fff 0 50%) 0 0 / 8px 8px; }
.gl-new-actions { justify-content: flex-end; margin-top: 16px; }

/* Keep the two top bars from running into each other on narrower screens */
@media (max-width: 1000px) {
  .drawing-name { display: none; }
}
@media (max-width: 860px) {
  .bar-left .badge { display: none; }
  .bar-right .icon-btn { width: 40px; height: 40px; }
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  top: calc(max(12px, env(safe-area-inset-top)) + 70px);
  z-index: 30;
  padding: .55rem 1.3rem;
  border-radius: 999px;
  background: var(--clay);
  color: var(--on-accent);
  font: 700 .9rem var(--font-display);
  box-shadow: 0 4px 15px rgba(0, 0, 0, .4);
  opacity: 0;
  transform: translate(-50%, -10px);
  transition: opacity .2s, transform .2s;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 600px) {
  .badge { display: none; }
  .brand { font-size: 1.1rem; }
  .bar-left { padding: 8px 12px; }
  .icon-btn { width: 38px; height: 38px; }
  .brush { width: 46px; }
  .slider { min-width: 110px; }
  .hud { width: calc(100vw - 24px); }
}

/* Phones: tools as icons only, so the whole row fits (names stay as tooltips / screen-reader labels) */
@media (max-width: 430px) {
  .dock { padding: 8px 10px; gap: 8px 12px; }
  .brushes { gap: 2px; max-width: calc(100vw - 44px); }
  .brush { width: 42px; height: 44px; }
  .brush > span { display: none; }
  .brush svg, .brush .tip-icon { width: 24px; height: 24px; }
}

@media (prefers-reduced-motion: reduce) {
  .toast { transition: none; }
}

/* ===================================================================
 * Greenhouse look (Papergrove, Nov 2026): airy sage-glass panels, thin
 * outlines, softly rounded corners, and a quiet sage "selected" state with a
 * small clay dot instead of solid clay blocks. Same Botanical Press colors.
 * Kept in one block at the end so it's easy to tune.
 * =================================================================== */
:root {
  --panel: rgba(40, 52, 45, .84);
  --panel-border: rgba(163, 196, 173, .22);
  --hover: rgba(163, 196, 173, .12);
  --sel-bg: #3d5245;        /* selected tool / toggled button */
  --sel-text: #eef5ef;
  --shadow: 0 8px 24px rgba(0, 0, 0, .25);
}
:root[data-theme="sketchbook"] {
  --panel: rgba(246, 250, 246, .86);
  --panel-border: #b9cdbd;
  --hover: #e6efe7;
  --sel-bg: #d6e6d9;
  --sel-text: #24382c;
  --shadow: 0 6px 18px rgba(35, 48, 43, .08);
}

.panel {
  border-radius: 20px;
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
}
.bar { gap: 6px; padding: 7px 8px; }
.bar-left { padding: 10px 18px; }
.dock { border-radius: 22px; padding: 10px 16px; gap: 10px 20px; }

.icon-btn { border-radius: 14px; }
.icon-btn[aria-pressed="true"] { background: var(--sel-bg); color: var(--sel-text); }

/* selected tool: a soft sage pill with a small clay dot */
.brush { border-radius: 14px; position: relative; }
.brush[aria-checked="true"] {
  background: var(--sel-bg);
  color: var(--sel-text);
  box-shadow: none;
}
.brush[aria-checked="true"]::after {
  content: "";
  position: absolute;
  bottom: 3px;
  left: 50%;
  width: 5px;
  height: 5px;
  margin-left: -2.5px;
  border-radius: 50%;
  background: var(--clay);
}
.brush[aria-checked="true"] .tip-icon { filter: none; }
:root[data-theme="sketchbook"] .brush[aria-checked="true"] .tip-icon { filter: brightness(0) opacity(.8); }

.seg button[aria-pressed="true"] { background: var(--sel-bg); color: var(--sel-text); }
.ws-item[aria-pressed="true"] { background: var(--sel-bg); color: var(--sel-text); }
.ws-item[aria-pressed="true"] .tip-icon { filter: none; }
:root[data-theme="sketchbook"] .ws-item[aria-pressed="true"] .tip-icon { filter: brightness(0) opacity(.8); }
.ws-btn[aria-pressed="true"] { background: var(--sel-bg); border-color: var(--highlight); color: var(--sel-text); }

.ly-row { border-radius: 14px; }
.ly-row.active { border-color: var(--highlight); background: var(--sel-bg); }
.ly-row.active .ly-name { color: var(--sel-text); }

/* main buttons: still clay, without the hard ledge underneath */
.btn { box-shadow: none; }
.btn:active { box-shadow: none; transform: translateY(1px); }
/* phones: the extra breathing room doesn't fit two top bars side by side */
@media (max-width: 520px) {
  .bar { gap: 2px; padding: 5px; }
  .bar-left { padding: 8px 12px; }
}
