/* app.css — dark drafting-room chrome, sized for fingers and Apple Pencil.
   Two rules drive most of this file: nothing may scroll or bounce (the canvas
   owns every gesture), and every control is at least 44px so it can be hit
   without looking. */

:root {
  --bg: #14161b;
  --bg-2: #1b1e25;
  --panel: rgba(28, 31, 38, 0.86);
  --panel-solid: #1c1f26;
  --line: rgba(255, 255, 255, 0.11);
  --line-strong: rgba(255, 255, 255, 0.2);
  --ink: #e9edf4;
  --ink-2: #a6b0c0;
  --ink-3: #6b7484;
  --accent: #4fc3f7;
  --accent-ink: #062330;
  --warm: #ffb74d;
  --good: #7cffb2;
  --danger: #ff6b6b;
  --sym: #ba68c8;

  --r-sm: 8px;
  --r: 12px;
  --r-lg: 18px;
  --tap: 44px;
  --shadow: 0 10px 34px rgba(0, 0, 0, 0.5);

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }

/* Author `display` rules beat the UA stylesheet's [hidden] rule, and almost
   every panel below sets one. Without this, nothing can actually hide. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  position: fixed;
  inset: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, system-ui, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

/* Text inputs are the one place selection must work. */
input, textarea {
  -webkit-user-select: text;
  user-select: text;
  touch-action: auto;
}

.app { position: fixed; inset: 0; }

/* ----------------------------------------------------------- canvas stack */

.stage { position: absolute; inset: 0; touch-action: none; }
.board, .live {
  position: absolute;
  top: 0; left: 0;
  touch-action: none;
  display: block;
}
.live { pointer-events: none; }

/* ----------------------------------------------------------- chrome shell */

.app[data-ui="off"] .bar,
.app[data-ui="off"] .groupbar,
.app[data-ui="off"] .rail,
.app[data-ui="off"] .dock,
.app[data-ui="off"] .status,
.app[data-ui="off"] .selbar,
.app[data-ui="off"] .panel { opacity: 0; pointer-events: none; transform: translateY(6px); }

.bar, .rail, .dock, .status, .selbar, .panel, .groupbar {
  transition: opacity .18s ease, transform .18s ease;
}

.bar {
  position: absolute;
  left: calc(var(--safe-l) + 8px);
  right: calc(var(--safe-r) + 8px);
  top: calc(var(--safe-t) + 8px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  pointer-events: none;
  z-index: 20;
}
.cluster {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  background: var(--panel);
  backdrop-filter: blur(18px) saturate(1.3);
  -webkit-backdrop-filter: blur(18px) saturate(1.3);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  pointer-events: auto;
}
.cluster-centre { background: none; border: none; box-shadow: none; backdrop-filter: none; -webkit-backdrop-filter: none; }

.btn {
  appearance: none;
  min-width: var(--tap);
  height: var(--tap);
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: transparent;
  border: 0;
  border-radius: var(--r-sm);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { background: rgba(255, 255, 255, 0.1); }
.btn[disabled] { opacity: .32; pointer-events: none; }
.btn[aria-pressed="true"], .btn.on { background: var(--accent); color: var(--accent-ink); }
.btn.on .ic { stroke: var(--accent-ink); }
.btn-danger:active { background: rgba(255, 107, 107, .22); }
.btn-name { max-width: 34vw; }
.btn-name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.ic {
  width: 22px; height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}
.ic-sm { width: 15px; height: 15px; stroke-width: 1.9; }

.save-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--ink-3);
  transition: background .25s ease, box-shadow .25s ease;
}
.save-dot[data-state="dirty"] { background: var(--warm); }
.save-dot[data-state="saving"] { background: var(--accent); box-shadow: 0 0 0 4px rgba(79, 195, 247, .18); }
.save-dot[data-state="saved"] { background: var(--good); }
.save-dot[data-state="error"] { background: var(--danger); box-shadow: 0 0 0 4px rgba(255, 107, 107, .2); }

/* ----------------------------------------------------------- tool rails */

.rail {
  position: absolute;
  left: calc(var(--safe-l) + 8px);
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 5px;
  background: var(--panel);
  backdrop-filter: blur(18px) saturate(1.3);
  -webkit-backdrop-filter: blur(18px) saturate(1.3);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  z-index: 18;
}
.rail-right { left: auto; right: calc(var(--safe-r) + 8px); }
.app[data-ui="off"] .rail { transform: translateY(-50%) translateX(-8px); }
.app[data-ui="off"] .rail-right { transform: translateY(-50%) translateX(8px); }

.rail-btn {
  appearance: none;
  width: var(--tap);
  height: var(--tap);
  display: grid;
  place-items: center;
  background: transparent;
  border: 0;
  border-radius: var(--r-sm);
  color: var(--ink-2);
  cursor: pointer;
  position: relative;
}
.rail-btn:active { background: rgba(255, 255, 255, .1); }
.rail-btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.rail-btn.armed { color: var(--warm); }
.rail-btn.armed::after {
  content: '';
  position: absolute;
  right: 5px; top: 5px;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--warm);
}
.rail-gap { height: 10px; border-top: 1px solid var(--line); margin: 4px 6px 0; }

/* ----------------------------------------------------------- pen dock */

.dock {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--safe-b) + 46px);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px;
  background: var(--panel);
  backdrop-filter: blur(18px) saturate(1.3);
  -webkit-backdrop-filter: blur(18px) saturate(1.3);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  z-index: 18;
  max-width: calc(100vw - 2 * (var(--tap) + 30px));
}
.app[data-ui="off"] .dock { transform: translateX(-50%) translateY(10px); }

.pens { display: flex; gap: 3px; }
.pen {
  appearance: none;
  width: 46px; height: var(--tap);
  padding: 0;
  background: rgba(255, 255, 255, .04);
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  cursor: pointer;
  display: grid;
  place-items: center;
  position: relative;
  overflow: hidden;
}
.pen canvas { display: block; width: 44px; height: 30px; }
.pen[aria-selected="true"] {
  background: rgba(79, 195, 247, .16);
  border-color: var(--accent);
}
.pen-size {
  position: absolute;
  bottom: 1px; right: 3px;
  font: 600 9px/1 ui-monospace, monospace;
  color: var(--ink-3);
}
.pen[aria-selected="true"] .pen-size { color: var(--accent); }

.swatch-big {
  appearance: none;
  width: var(--tap); height: var(--tap);
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .5);
  cursor: pointer;
  padding: 0;
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, .35);
}
.btn-scalepen { font-size: 12px; padding: 0 10px; }
.btn-scalepen span { display: none; }
@media (min-width: 860px) { .btn-scalepen span { display: inline; } }

/* ----------------------------------------------------------- status */

.status {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--safe-b) + 6px);
  display: flex;
  align-items: center;
  gap: 5px;
  z-index: 17;
  max-width: calc(100vw - 24px);
}
.chip {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 32px;
  padding: 0 11px;
  background: var(--panel);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--line);
  border-radius: 16px;
  color: var(--ink-2);
  font: 500 12px/1 ui-monospace, "SF Mono", monospace;
  cursor: pointer;
  white-space: nowrap;
}
.chip-flat { pointer-events: none; }
.chip-live { color: var(--accent); border-color: rgba(79, 195, 247, .4); font-variant-numeric: tabular-nums; }
.chip-action { background: var(--good); color: #05301b; border-color: transparent; font-weight: 700; }

/* ----------------------------------------------------------- group strip */

.groupbar {
  position: absolute;
  left: calc(var(--safe-l) + 8px);
  top: calc(var(--safe-t) + 72px);
  right: calc(var(--safe-r) + 62px);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  background: var(--panel);
  backdrop-filter: blur(18px) saturate(1.3);
  -webkit-backdrop-filter: blur(18px) saturate(1.3);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  z-index: 17;
  max-width: max-content;
}
.groupbar-label {
  font: 600 10px/1 inherit;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--ink-3);
  flex: none;
}
.groupbar-chips {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  touch-action: pan-x;
  scrollbar-width: none;
}
.groupbar-chips::-webkit-scrollbar { display: none; }
.gchip {
  appearance: none;
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 11px;
  background: rgba(255, 255, 255, .05);
  border: 1px solid var(--line);
  border-radius: 17px;
  color: var(--ink-2);
  font: 500 13px/1 inherit;
  cursor: pointer;
  white-space: nowrap;
  max-width: 190px;
}
.gchip span {
  overflow: hidden;
  text-overflow: ellipsis;
}
.gchip-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  flex: none;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .35);
}
.gchip[aria-pressed="true"] { background: rgba(255, 255, 255, .14); color: var(--ink); }
.gchip[data-off="true"] { opacity: .42; }
.gchip[data-off="true"] .gchip-dot { background: transparent !important; box-shadow: inset 0 0 0 2px currentColor; }
.gchip[data-solo="true"] {
  border-color: var(--good);
  color: var(--good);
  background: rgba(124, 255, 178, .12);
}
.groupbar-clear {
  appearance: none;
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 32px;
  padding: 0 10px;
  border-radius: 16px;
  border: 1px solid var(--good);
  background: rgba(124, 255, 178, .12);
  color: var(--good);
  font: 600 12px/1 inherit;
  cursor: pointer;
  white-space: nowrap;
}

/* ----------------------------------------------------------- group rows */

.grow {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 6px;
  margin: 8px 0 3px;
  border-radius: var(--r-sm);
  background: rgba(255, 255, 255, .05);
  border-left: 3px solid var(--accent);
}
.grow:first-child { margin-top: 0; }
.grow-name {
  flex: 1;
  min-width: 0;
  background: none;
  border: 0;
  color: var(--ink);
  font: 600 13px/1.2 inherit;
  padding: 3px 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.grow-meta { font: 11px/1 ui-monospace, monospace; color: var(--ink-3); flex: none; padding-right: 2px; }
.grow-caret { transition: transform .15s ease; }
.grow[data-collapsed="true"] .grow-caret { transform: rotate(0deg); }
.grow[data-collapsed="false"] .grow-caret { transform: rotate(90deg); }
.layer-nested { margin-left: 12px; border-left: 2px solid var(--line); padding-left: 6px; }
.layer[data-hidden-by-group="true"] { opacity: .45; }
.layer-solo, .grow-solo { color: var(--ink-3); }
.layer-solo[aria-pressed="true"], .grow-solo[aria-pressed="true"] { color: var(--good); }

/* ----------------------------------------------------------- selection bar */

.selbar {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  /* Sits below the group strip, so the two stack instead of colliding. */
  top: calc(var(--safe-t) + 126px);
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px;
  background: var(--panel);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  z-index: 19;
}
.selbar-count {
  min-width: 30px;
  padding: 0 8px;
  font: 600 12px/1 ui-monospace, monospace;
  color: var(--accent);
  text-align: center;
}

/* ----------------------------------------------------------- panels */

.panel {
  position: absolute;
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  z-index: 25;
  overflow: hidden;
}
.panel-right {
  right: calc(var(--safe-r) + 62px);
  top: calc(var(--safe-t) + 62px);
  bottom: calc(var(--safe-b) + 46px);
  width: min(364px, 82vw);
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 10px 10px 16px;
  border-bottom: 1px solid var(--line);
  flex: none;
}
.panel-head h2 { margin: 0; font-size: 15px; font-weight: 600; }
.panel-head-actions { display: flex; gap: 2px; }
.panel-body {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  padding: 10px;
}
.panel-foot {
  flex: none;
  padding: 8px 10px;
  border-top: 1px solid var(--line);
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}

/* ----------------------------------------------------------- layer rows */

.layer {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  margin-bottom: 4px;
}
.layer[aria-current="true"] { background: rgba(79, 195, 247, .12); border-color: rgba(79, 195, 247, .45); }
.layer-thumb {
  width: 44px; height: 34px;
  border-radius: 5px;
  background: #fff;
  flex: none;
  object-fit: contain;
  border: 1px solid var(--line);
}
.layer-main { flex: 1; min-width: 0; }
.layer-name {
  font-size: 13px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: none;
  border: 0;
  color: var(--ink);
  padding: 2px 0;
  width: 100%;
  font-family: inherit;
}
.layer-meta {
  font: 11px/1.2 ui-monospace, monospace;
  color: var(--ink-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.layer-btns { display: flex; gap: 0; }
.icon-btn {
  appearance: none;
  width: 34px; height: 34px;
  display: grid; place-items: center;
  background: none; border: 0; border-radius: 6px;
  color: var(--ink-2); cursor: pointer;
}
.icon-btn:active { background: rgba(255, 255, 255, .1); }
.icon-btn[aria-pressed="true"] { color: var(--accent); }
.icon-btn.off { color: var(--ink-3); opacity: .55; }

/* ----------------------------------------------------------- modal + pop */

.sheetmodal {
  position: absolute;
  inset: 0;
  background: rgba(8, 9, 12, .6);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  display: grid;
  place-items: center;
  z-index: 40;
  padding: calc(var(--safe-t) + 12px) 12px calc(var(--safe-b) + 12px);
}
.sheetmodal-card {
  width: min(620px, 100%);
  max-height: 100%;
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sheetmodal-card.wide { width: min(940px, 100%); }

.pop {
  position: absolute;
  inset: 0;
  z-index: 35;
}
.pop-card {
  position: absolute;
  background: var(--panel-solid);
  border: 1px solid var(--line-strong);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  padding: 10px;
  max-width: min(400px, calc(100vw - 24px));
  max-height: min(70vh, 560px);
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
}

/* ----------------------------------------------------------- form bits */

.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
.field > label,
.field-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-bottom: 6px;
}
.field-row { display: flex; align-items: center; gap: 8px; }
.field-hint { font-size: 12px; color: var(--ink-3); margin-top: 5px; line-height: 1.35; }

.seg { display: flex; gap: 2px; padding: 3px; background: rgba(0, 0, 0, .3); border-radius: 10px; flex-wrap: wrap; }
.seg button {
  appearance: none;
  flex: 1 1 auto;
  min-height: 36px;
  padding: 0 11px;
  background: none;
  border: 0;
  border-radius: 7px;
  color: var(--ink-2);
  font: 500 13px/1 inherit;
  cursor: pointer;
  white-space: nowrap;
}
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); font-weight: 600; }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 32px;
  background: none;
  margin: 0;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 5px;
  border-radius: 3px;
  background: rgba(255, 255, 255, .16);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 26px; height: 26px;
  margin-top: -11px;
  border-radius: 50%;
  background: var(--ink);
  border: 2px solid var(--bg-2);
  box-shadow: 0 2px 8px rgba(0, 0, 0, .5);
}
input[type="range"]::-moz-range-track { height: 5px; border-radius: 3px; background: rgba(255,255,255,.16); }
input[type="range"]::-moz-range-thumb { width: 22px; height: 22px; border-radius: 50%; background: var(--ink); border: 2px solid var(--bg-2); }

input[type="text"], input[type="number"], textarea, select {
  width: 100%;
  min-height: 42px;
  padding: 9px 11px;
  background: rgba(0, 0, 0, .3);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  color: var(--ink);
  font: inherit;
}
textarea { min-height: 96px; resize: vertical; line-height: 1.45; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.val { font: 600 12px/1 ui-monospace, monospace; color: var(--ink-2); min-width: 54px; text-align: right; }

.row-btn {
  appearance: none;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: var(--tap);
  padding: 8px 10px;
  background: none;
  border: 0;
  border-radius: var(--r-sm);
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.row-btn:active { background: rgba(255, 255, 255, .08); }
.row-btn .ic { color: var(--ink-2); }
.row-btn small { display: block; color: var(--ink-3); font-size: 12px; margin-top: 1px; }
.row-btn-main { flex: 1; min-width: 0; }
.row-sep { height: 1px; background: var(--line); margin: 6px 4px; }

.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: var(--tap); }
.toggle-txt { flex: 1; }
.toggle-txt small { display: block; color: var(--ink-3); font-size: 12px; margin-top: 2px; line-height: 1.35; }
.switch {
  appearance: none;
  position: relative;
  width: 50px; height: 30px;
  flex: none;
  background: rgba(255, 255, 255, .16);
  border: 0;
  border-radius: 15px;
  cursor: pointer;
  transition: background .18s ease;
}
.switch::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: #fff;
  transition: transform .18s ease;
}
.switch[aria-pressed="true"] { background: var(--accent); }
.switch[aria-pressed="true"]::after { transform: translateX(20px); }

/* ----------------------------------------------------------- swatches */

.swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 6px; }
.swatch {
  appearance: none;
  aspect-ratio: 1;
  min-height: 40px;
  border-radius: 9px;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .14);
}
.swatch[aria-pressed="true"] { border-color: var(--accent); }

.wheel-wrap { display: grid; place-items: center; gap: 10px; }
.wheel { touch-action: none; border-radius: 50%; cursor: crosshair; }

/* ----------------------------------------------------------- stencils */

.sten-groups { display: flex; gap: 4px; overflow-x: auto; padding-bottom: 8px; touch-action: pan-x; }
.sten-groups button {
  appearance: none;
  flex: none;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 17px;
  border: 1px solid var(--line);
  background: none;
  color: var(--ink-2);
  font: 500 13px/1 inherit;
  cursor: pointer;
  white-space: nowrap;
}
.sten-groups button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.sten-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 6px; }
.sten {
  appearance: none;
  padding: 8px 4px 7px;
  background: rgba(255, 255, 255, .04);
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  cursor: pointer;
  display: grid;
  grid-template-rows: auto auto;
  gap: 7px;
  justify-items: center;
}
.sten[aria-pressed="true"] { background: rgba(79, 195, 247, .16); border-color: var(--accent); }
.sten svg { width: 52px; height: 52px; stroke: var(--ink); fill: none; stroke-width: 2.4; stroke-linejoin: round; stroke-linecap: round; }
.sten img { width: 52px; height: 52px; object-fit: contain; filter: invert(1) brightness(1.6); }
.sten span { font-size: 10px; color: var(--ink-3); text-align: center; line-height: 1.2; }

/* ----------------------------------------------------------- gallery */

.gal { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 10px; }
.gal-card {
  border: 1px solid var(--line);
  border-radius: var(--r);
  overflow: hidden;
  background: rgba(255, 255, 255, .03);
  display: flex;
  flex-direction: column;
}
.gal-open { appearance: none; background: none; border: 0; padding: 0; cursor: pointer; display: block; }
.gal-thumb { width: 100%; aspect-ratio: 4/3; object-fit: contain; background: #fff; display: block; }
.gal-thumb-empty { width: 100%; aspect-ratio: 4/3; display: grid; place-items: center; background: #fff; color: #b9c2cf; font-size: 12px; }
.gal-meta { padding: 8px 10px; }
.gal-name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gal-sub { font: 11px/1.3 ui-monospace, monospace; color: var(--ink-3); margin-top: 2px; }
.gal-acts { display: flex; border-top: 1px solid var(--line); }
.gal-acts button { flex: 1; min-height: 40px; background: none; border: 0; color: var(--ink-2); cursor: pointer; display: grid; place-items: center; }
.gal-acts button:active { background: rgba(255, 255, 255, .08); }
.gal-acts button + button { border-left: 1px solid var(--line); }

/* ----------------------------------------------------------- toasts */

.toasts {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--safe-b) + 106px);
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  z-index: 50;
  pointer-events: none;
}
.toast {
  padding: 9px 15px;
  background: rgba(20, 22, 27, .95);
  border: 1px solid var(--line-strong);
  border-radius: 20px;
  font-size: 13px;
  box-shadow: var(--shadow);
  animation: pop .2s ease;
  max-width: min(420px, 88vw);
  text-align: center;
}
.toast[data-kind="ok"] { border-color: rgba(124, 255, 178, .5); }
.toast[data-kind="warn"] { border-color: rgba(255, 183, 77, .6); }
.toast[data-kind="error"] { border-color: rgba(255, 107, 107, .6); }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.97); } }

.busy { position: absolute; inset: 0; display: grid; place-items: center; z-index: 60; pointer-events: all; background: rgba(8,9,12,.25); }
.spinner {
  width: 34px; height: 34px;
  border: 3px solid rgba(255, 255, 255, .18);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.hint-tap {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  padding: 14px 22px;
  background: rgba(20, 22, 27, .94);
  border: 1px solid var(--line-strong);
  border-radius: var(--r);
  font-size: 15px;
  font-weight: 600;
  z-index: 55;
  pointer-events: none;
  animation: pop .15s ease;
}

/* ----------------------------------------------------------- misc */

.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13px; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; font-family: ui-monospace, monospace; }

.empty { text-align: center; padding: 34px 18px; color: var(--ink-3); }
.empty h3 { color: var(--ink-2); margin: 0 0 6px; font-size: 15px; }
.empty p { margin: 0 0 14px; font-size: 13px; line-height: 1.5; }

.btn-wide {
  width: 100%;
  min-height: var(--tap);
  border-radius: var(--r-sm);
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, .06);
  color: var(--ink);
  font: 600 14px/1 inherit;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn-wide:active { background: rgba(255, 255, 255, .13); }
.btn-wide.primary { background: var(--accent); border-color: transparent; color: var(--accent-ink); }
.btn-wide.danger { color: var(--danger); border-color: rgba(255, 107, 107, .4); }

.chips-wrap { display: flex; flex-wrap: wrap; gap: 5px; }
.chips-wrap button {
  appearance: none;
  min-height: 36px;
  padding: 0 12px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: none;
  color: var(--ink-2);
  font: 500 13px/1 inherit;
  cursor: pointer;
  white-space: nowrap;
}
.chips-wrap button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }

/* Landscape phones and short windows: shrink the dock so it still fits. */
@media (max-height: 460px) {
  .dock { bottom: calc(var(--safe-b) + 40px); padding: 3px; }
  .pen { width: 38px; height: 38px; }
  .pen canvas { width: 36px; height: 26px; }
  .rail-btn, .btn { height: 38px; min-width: 38px; }
  .rail { gap: 0; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
