/*
 * Pip's Studio themes.
 *   Workbench (dark, default): warm neutral charcoal, so colors on the canvas look true.
 *   Sketchbook (light): paper and ink, for daylight drawing.
 * Pip orange stays the accent in both. Picked with the theme button; set on <html data-theme>.
 */
:root {
  --surround: #3a3734;      /* around the canvas */
  --base: #232120;          /* inputs, cards */
  --raised: #2c2a28;        /* panels */
  --hover: #3a3734;
  --line: #4c4843;          /* borders, slider tracks */
  --panel: rgba(44, 42, 40, .94);
  --panel-border: rgba(255, 255, 255, .08);
  --text: #ece6dc;
  --muted: #a9a196;
  --strong: #f6f0e6;        /* names, values */
  --highlight: #ffb547;     /* headings, selected outlines */
  --scrim: rgba(15, 13, 12, .6);
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --orange: #f2792b;
  --orange-shadow: #b9541a;
  --accent-hover: #ff9147;
  --on-accent: #1f1a16;     /* text on orange, both themes */
  --teal: #3cc8d6;
  --font-pixel: "Pixelify Sans", system-ui, sans-serif;
  --font-display: "Space Grotesk", system-ui, sans-serif;
  --font-body: "Nunito", system-ui, sans-serif;
  color-scheme: dark;
}

:root[data-theme="sketchbook"] {
  --surround: #d6d1c8;
  --base: #fbf8f2;
  --raised: #f4efe6;
  --hover: #e8e1d5;
  --line: #d3cabc;
  --panel: rgba(244, 239, 230, .95);
  --panel-border: rgba(60, 45, 30, .12);
  --text: #3b342c;
  --muted: #7a6f62;
  --strong: #2b241d;
  --highlight: #b84a22;
  --scrim: rgba(60, 50, 40, .35);
  --shadow: 0 8px 24px rgba(60, 45, 30, .18);
  color-scheme: light;
}

:root[data-theme="sketchbook"] .badge { color: #1d7f8a; border-color: rgba(29, 127, 138, .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, .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(--orange);
  text-decoration: none;
  white-space: nowrap;
}
.brand span { color: var(--highlight); }

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

.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: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(--orange);
  color: var(--on-accent);
  box-shadow: 0 3px 0 var(--orange-shadow);
}

.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(--teal); 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); }

/* 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(--orange); 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(--teal); }
.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-pixel); 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(--orange);
  border-radius: 0;
  background: var(--base);
}

/* 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-pixel); 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(--orange); }
.wl-actions { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }

/* 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(--teal); }
.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: 120px;
  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-pixel); color: var(--highlight); }
.ly-count { flex: 1; font: 600 .72rem var(--font-display); color: var(--muted); }
.ly-list { flex: 1; min-height: 60px; overflow-y: auto; margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 4px; }
.ly-row {
  display: grid;
  grid-template-columns: 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(--orange); }
.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: 1; }
.ly-name { grid-column: 2; 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: 2; grid-row: 2; font-size: .72rem; color: var(--muted); }
.ly-icon[data-lock] { grid-column: 3; }
.ly-icon[data-eye] { grid-column: 4; }
.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); }
.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-pixel); 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(--teal); }

/* 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-pixel); 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(--orange); 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(--teal); 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(--teal); }
.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(--teal); }
.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-pixel); 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(--orange); }

.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: #2c2a28; 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; }

@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(--orange);
  color: var(--on-accent);
  font: 600 .95rem var(--font-display);
  box-shadow: 0 3px 0 var(--orange-shadow);
  cursor: pointer;
}
.btn:hover { background: var(--accent-hover); }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--orange-shadow); }

/* 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(--orange); box-shadow: 0 0 0 1px var(--orange); }
.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(--teal); 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-pixel); 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(--teal); 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(--orange); }
.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(--orange);
  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; }
}
