/* =========================================================================
   Pixel Art Editor — stylesheet
   Token system: color/type/spacing are all defined once on :root and its
   dark-mode counterparts, then consumed everywhere else. Change the tokens,
   not the components, to retheme.
   ========================================================================= */

/* ---- Design tokens: light (default) ---- */
:root {
  --bg: #eef0f4;
  --surface: #ffffff;
  --surface-alt: #eceef3;
  --surface-sunken: #e2e5ec;
  --border: #d5d9e2;
  --text: #20222b;
  --text-dim: #6b6e7a;
  --accent: #d9611b;
  --accent-strong: #b84f12;
  --accent-2: #2789a3;
  --danger: #cc3b3b;
  --focus-ring: #2789a3;
  --checker-a: #d9dce3;
  --checker-b: #eef0f4;
  --shadow: 0 4px 16px rgba(30, 32, 40, 0.14);

  --font-ui: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'SFMono-Regular', Consolas, monospace;

  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #1c1d24;
    --surface: #23252e;
    --surface-alt: #2b2d38;
    --surface-sunken: #17181e;
    --border: #3a3d4a;
    --text: #e9e9ee;
    --text-dim: #9a9ca8;
    --accent: #ff8a3d;
    --accent-strong: #ffa564;
    --accent-2: #5ec8dd;
    --danger: #f0605f;
    --focus-ring: #5ec8dd;
    --checker-a: #2b2d38;
    --checker-b: #23252e;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.45);
  }
}

:root[data-theme='dark'] {
  --bg: #1c1d24;
  --surface: #23252e;
  --surface-alt: #2b2d38;
  --surface-sunken: #17181e;
  --border: #3a3d4a;
  --text: #e9e9ee;
  --text-dim: #9a9ca8;
  --accent: #ff8a3d;
  --accent-strong: #ffa564;
  --accent-2: #5ec8dd;
  --danger: #f0605f;
  --focus-ring: #5ec8dd;
  --checker-a: #2b2d38;
  --checker-b: #23252e;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.45);
}

/* ---- Reset & base ---- */
* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

button {
  font-family: inherit;
  color: inherit;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 1px;
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}

/* =========================================================================
   Menu bar
   ========================================================================= */

#menu-bar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 6px 10px;
  padding-top: calc(6px + env(safe-area-inset-top, 0px));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex: none;
  position: relative;
  z-index: 30;
}

#menu-bar .brand {
  font-weight: 700;
  letter-spacing: 0.01em;
  margin-right: 12px;
  color: var(--accent-strong);
  white-space: nowrap;
}

.menu {
  position: relative;
}

.menu-trigger {
  background: none;
  border: none;
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}

.menu-trigger:hover,
.menu.open .menu-trigger {
  background: var(--surface-alt);
}

.menu-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 200px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 6px;
  display: none;
  flex-direction: column;
  gap: 1px;
  z-index: 40;
}

.menu.open .menu-dropdown {
  display: flex;
}

.menu-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 7px 10px;
  border-radius: 5px;
  font-size: 13px;
  cursor: pointer;
}

.menu-item:hover:not(:disabled) {
  background: var(--surface-alt);
}

.menu-item:disabled {
  color: var(--text-dim);
  cursor: default;
}

.menu-item .shortcut {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
}

.menu-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 2px;
}

.menu-placeholder {
  padding: 10px;
  font-size: 12px;
  color: var(--text-dim);
  font-style: italic;
}

/* =========================================================================
   Overall layout: toolbar strip, then sidebar + canvas, then status bar
   ========================================================================= */

#app-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#toolbar {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  padding: 8px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex: none;
}

.tool-group {
  display: flex;
  gap: 4px;
}

.tool-btn {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 7px;
  border: 1px solid transparent;
  background: var(--surface-alt);
  cursor: pointer;
  font-size: 16px;
}

.tool-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent-strong);
}

.opacity-control {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-dim);
}

.opacity-control input[type='range'] {
  width: 120px;
}

/* Per-tool option panels (Shape's Fill toggle, Blender's Radius/Strength) —
   same visual family as .opacity-control, but only one is ever shown at a
   time, toggled via [hidden] by ui.js's initToolOptions. Author rules beat
   the UA stylesheet's [hidden] rule regardless of specificity (see the
   .ref-pane[hidden] comment below for why), so this override is required,
   not decorative. */
.tool-options {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-dim);
}

.tool-options[hidden] {
  display: none;
}

.tool-options input[type='range'] {
  width: 70px;
}

.shape-fill-label {
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
}

.shape-fill-label input[type='checkbox'] {
  cursor: pointer;
}

/* Small 2/3-way toggle used by Pen Size (1/2/3) and Mirror Pen's axis
   (X/Y) — same visual family as .ref-target-group, just reused inside a
   .tool-options strip instead of the reference bar. */
.segmented-group {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  flex: none;
}

.segmented-btn {
  background: var(--surface-alt);
  border: none;
  border-right: 1px solid var(--border);
  color: var(--text-dim);
  padding: 4px 9px;
  font-size: 11px;
  font-family: var(--font-mono);
  cursor: pointer;
}

.segmented-btn:last-child {
  border-right: none;
}

.segmented-btn.active {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

/* Pixel Selection's Copy/Cut/Paste/…-to-New-Layer buttons sit directly in
   the toolbar strip — snug them up a bit smaller than the sidebar's .btn. */
#select-options .btn {
  flex: none;
  padding: 5px 9px;
  font-size: 11px;
}

#opacity-value {
  font-family: var(--font-mono);
  width: 3.2em;
  color: var(--text);
}

.toolbar-spacer {
  flex: 1;
}

.zoom-control {
  display: flex;
  align-items: center;
  gap: 4px;
  font-family: var(--font-mono);
  font-size: 12px;
}

.icon-btn {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

#status-zoom {
  min-width: 3.6em;
  text-align: center;
  color: var(--text-dim);
}

/* ---- Reference bar: the three-way onion-skin switch ---- */

#reference-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  padding: 8px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex: none;
}

.reference-bar-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
}

.ref-mode-group {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 7px;
  overflow: hidden;
}

.ref-mode-btn {
  background: var(--surface-alt);
  border: none;
  border-right: 1px solid var(--border);
  color: var(--text-dim);
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
}

.ref-mode-btn:last-child {
  border-right: none;
}

.ref-mode-btn.active {
  background: var(--accent-2);
  color: #06202a;
  font-weight: 600;
}

#ref-opacity-row {
  color: var(--text-dim);
}

/* Overlay-only: which single frame ("what it was" vs "what it's becoming")
   gets onion-skinned. Same visual family as .ref-mode-group, one size down,
   since it's a sub-choice that only matters once Overlay is already active. */
.ref-target-group {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  flex: none;
}

.ref-target-btn {
  background: var(--surface-alt);
  border: none;
  border-right: 1px solid var(--border);
  color: var(--text-dim);
  padding: 5px 10px;
  font-size: 11px;
  cursor: pointer;
}

.ref-target-btn:last-child {
  border-right: none;
}

.ref-target-btn.active {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

#ref-opacity-row input[type='range'] {
  width: 100px;
}

#ref-opacity-value {
  font-family: var(--font-mono);
  width: 3.2em;
}

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

/* ---- Sidebar: palettes ---- */

#sidebar {
  width: 240px;
  flex: none;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.sidebar-section {
  padding: 12px;
  border-bottom: 1px solid var(--border);
}

.sidebar-section h2 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin: 0 0 10px;
}

/* Used where a section's heading shares its row with a small action button
   (e.g. History's "Clear") instead of the button going on its own line. */
.sidebar-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.sidebar-section-header h2 {
  margin: 0;
}

.history-clear-btn {
  background: none;
  border: none;
  padding: 0;
  color: var(--text-dim);
  font-size: 11px;
  cursor: pointer;
  text-decoration: underline;
}

.history-clear-btn:hover {
  color: var(--accent);
}

#palette-select {
  width: 100%;
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  font-size: 13px;
  margin-bottom: 8px;
}

.palette-actions {
  display: flex;
  gap: 6px;
}

.btn {
  flex: 1;
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  cursor: pointer;
  font-size: 12px;
  white-space: nowrap;
}

.btn:hover {
  border-color: var(--accent);
}

.btn.danger:hover {
  border-color: var(--danger);
  color: var(--danger);
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent-strong);
  color: #fff;
}

.btn.primary:hover {
  background: var(--accent-strong);
}

#swatch-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  margin-bottom: 10px;
}

.swatch {
  position: relative;
  aspect-ratio: 1;
  border-radius: 6px;
  border: 2px solid var(--border);
  cursor: pointer;
  padding: 0;
}

.swatch-delete {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  line-height: 16px;
  text-align: center;
  opacity: 0;
}

.swatch:hover .swatch-delete {
  opacity: 1;
}

/* A mix set's swatch is a 4-way conic-gradient preview of its Top/Right/
   Bottom/Left modifiers (set inline via JS, since it's per-entry) — this
   small diamond marker is the only static styling needed to tell it apart
   from an ordinary solid-color swatch at a glance. */
.swatch-mixset::before {
  content: '\25C6';
  position: absolute;
  bottom: 1px;
  right: 3px;
  font-size: 8px;
  line-height: 1;
  color: #fff;
  text-shadow: 0 0 2px rgba(0, 0, 0, 0.9), 0 0 1px rgba(0, 0, 0, 0.9);
  pointer-events: none;
}

.add-color-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

#color-picker {
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: none;
  flex: none;
}

#hex-input {
  flex: 1;
  min-width: 0;
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12px;
}

/* ---- Current Color: the one place the active color is shown ---- */

.current-color-display {
  display: flex;
  align-items: center;
  gap: 10px;
}

.current-color-swatch-lg {
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: 8px;
  border: 1px solid var(--border);
  /* Palette colors are always fully opaque (#rrggbb, no alpha) — a solid
     fill is all this ever needs to show; its actual color comes from the
     inline background-color set in ui.js's renderCurrentColor(). */
}

.current-color-hex-lg {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text);
  flex: 1;
}

/* Sits right next to the Current Color swatch — see App.activateEyedropper
   for what a click actually does (real screen-wide sampling when the
   browser supports it, canvas-only sampling as the fallback). */
.eyedropper-btn {
  margin-left: auto;
}

.eyedropper-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* Only ever set while the rare canvas-only fallback tool is engaged. */
.eyedropper-btn.active {
  background: var(--accent);
  border-color: var(--accent-strong);
  color: #fff;
}

/* ---- History: most-recently-used colors ---- */

.color-history-track {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.history-swatch {
  width: 22px;
  height: 22px;
  padding: 0;
  border-radius: 5px;
  border: 1px solid var(--border);
  cursor: pointer;
}

.history-swatch:hover {
  border-color: var(--accent);
}

/* ---- Mix: 3x3 grid centered on a base color, 4 editable modifiers ---- */

.mixer-frame {
  display: grid;
  grid-template-columns: 26px 1fr 26px;
  grid-template-rows: 26px 1fr 26px;
  gap: 5px;
  align-items: center;
  justify-items: center;
  margin-bottom: 12px;
}

.mixer-corner {
  width: 100%;
  height: 100%;
}

.mixer-modifier {
  width: 26px;
  height: 26px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: none;
  cursor: pointer;
}

.mixer-3x3 {
  display: grid;
  grid-template-columns: repeat(3, 34px);
  grid-template-rows: repeat(3, 34px);
  gap: 3px;
}

.mixer-cell {
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 5px;
  border: 1px solid var(--border);
  cursor: pointer;
}

.mixer-cell:hover {
  border-color: var(--accent);
}

.mixer-cell-center {
  border-width: 2px;
  border-color: var(--accent-2);
  border-radius: 6px;
  cursor: default;
}

.mixer-slider-row {
  margin-top: 6px;
}

.mixer-slider-row input[type='range'] {
  flex: 1;
}

.mixer-save-btn {
  width: 100%;
  margin-top: 10px;
}

/* ---- Layers: per-frame compositing stack ---- */

.layers-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.layer-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 6px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  cursor: pointer;
}

.layer-row.active {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 1px var(--focus-ring);
}

.layer-visibility-btn {
  flex: none;
  width: 20px;
  height: 20px;
  border: none;
  background: none;
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}

.layer-row.active .layer-visibility-btn {
  color: var(--accent-2);
}

.layer-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}

.layer-move-btn {
  flex: none;
  width: 18px;
  height: 18px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  font-size: 10px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}

.layer-move-btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.layer-move-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.layer-delete-btn {
  flex: none;
  width: 18px;
  height: 18px;
  border-radius: 4px;
  border: none;
  background: none;
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}

.layer-delete-btn:hover {
  color: var(--danger);
}

/* ---- Canvas viewport ---- */

#canvas-viewport {
  flex: 1;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
  min-width: 0;
}

#canvas-stage {
  display: flex;
  align-items: center;
  gap: 24px;
}

/* Shared "transparent area" checkerboard for every STANDALONE canvas (the
   main canvas, and the side-by-side reference panels). Deliberately NOT
   applied to .ref-overlay-canvas below — those sit on top of #canvas and
   must stay truly transparent so #canvas's own checkerboard shows through
   wherever neither layer has drawn a pixel yet. */
#canvas,
.ref-pane canvas {
  background-image: linear-gradient(45deg, var(--checker-a) 25%, transparent 25%),
    linear-gradient(-45deg, var(--checker-a) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--checker-a) 75%),
    linear-gradient(-45deg, transparent 75%, var(--checker-a) 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0px;
  background-color: var(--checker-b);
}

#canvas {
  /* Pixel-perfect scaling: never smooth/anti-alias when the browser scales
     the backing bitmap up to its CSS size. */
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
  cursor: crosshair;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  max-width: 100%;
}

/* ---- Reference views: prev/next frame, look-only ---- */

.canvas-stack {
  position: relative;
  display: flex;
}

/* Onion-skin overlays sit exactly on top of the main canvas. pointer-events
   is the belt-and-suspenders guarantee that they're never interactive —
   even though this app never attaches mouse listeners to them either. */
.ref-overlay-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
}

.ref-pane {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  opacity: 0.55;
}

/* Author rules always beat the browser's own [hidden]{display:none} rule,
   REGARDLESS of selector specificity (it's a lower-precedence stylesheet
   origin, not a specificity contest) — so the unconditional `display: flex`
   above silently defeats `.hidden = true` in JS unless we re-assert it
   here. Without this, the side-by-side panels never actually disappear in
   Normal mode. */
.ref-pane[hidden] {
  display: none;
}

.ref-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
}

.ref-pane canvas {
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
  pointer-events: none;
  border: 1px solid var(--border);
  max-width: 140px;
  max-height: 140px;
}

.ref-placeholder {
  font-size: 11px;
  color: var(--text-dim);
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 24px 14px;
  text-align: center;
  max-width: 120px;
}

/* =========================================================================
   Filmstrip: numbered frame thumbnails + hover-to-insert gaps
   ========================================================================= */

#filmstrip {
  flex: none;
  background: var(--surface);
  border-top: 1px solid var(--border);
  overflow-x: auto;
}

#filmstrip-track {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  min-height: 76px;
}

.filmstrip-tile {
  position: relative;
  flex: none;
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-sunken);
  border: 2px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  padding: 0;
}

.filmstrip-tile.active {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 2px var(--focus-ring);
}

.filmstrip-thumb-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  overflow: hidden;
  background-image: linear-gradient(45deg, var(--checker-a) 25%, transparent 25%),
    linear-gradient(-45deg, var(--checker-a) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--checker-a) 75%),
    linear-gradient(-45deg, transparent 75%, var(--checker-a) 75%);
  background-size: 10px 10px;
  background-position: 0 0, 0 5px, 5px -5px, -5px 0px;
  background-color: var(--checker-b);
  border-radius: 3px;
}

.filmstrip-thumb {
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
  pointer-events: none;
}

.filmstrip-number {
  position: absolute;
  bottom: -2px;
  right: -2px;
  min-width: 16px;
  padding: 0 3px;
  height: 16px;
  border-radius: 5px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 10px;
  line-height: 14px;
  text-align: center;
}

.filmstrip-tile.active .filmstrip-number {
  background: var(--accent-2);
  color: #06202a;
  border-color: var(--accent-2);
  font-weight: 600;
}

.filmstrip-delete {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  line-height: 16px;
  text-align: center;
  opacity: 0;
}

.filmstrip-tile:hover .filmstrip-delete {
  opacity: 1;
}

/* The hoverable seam between frames. Fixed-width (rather than expanding on
   hover) so hovering along the strip never shifts other tiles around —
   wide enough to fit both buttons side by side even though they're only
   visible on hover. */
.filmstrip-gap {
  flex: none;
  width: 40px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

.gap-btn {
  width: 18px;
  height: 18px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text-dim);
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
}

.filmstrip-gap:hover .gap-btn,
.filmstrip-gap:focus-within .gap-btn {
  opacity: 1;
  pointer-events: auto;
}

.gap-btn:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent-strong);
}

.gap-btn-duplicate:hover {
  background: var(--accent-2);
  border-color: var(--accent-2);
  color: #06202a;
}

/* =========================================================================
   Status bar
   ========================================================================= */

#status-bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 6px 12px;
  padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px));
  background: var(--surface);
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-dim);
  font-family: var(--font-mono);
}

.status-color-chip {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  border: 1px solid var(--border);
  flex: none;
}

.status-item {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

#status-bar .status-spacer {
  flex: 1;
}

/* =========================================================================
   Dialogs
   ========================================================================= */

dialog {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  padding: 18px;
  width: min(320px, 90vw);
}

dialog::backdrop {
  background: rgba(10, 10, 14, 0.45);
}

dialog h2 {
  margin: 0 0 14px;
  font-size: 15px;
}

.field-row {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
}

.field {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field label {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.field input {
  padding: 7px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  font-family: var(--font-mono);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* Export dialog: a couple of stacked `.field`s (not side-by-side in a
   `.field-row`, unlike New Image's Width/Height), so give each its own
   bottom margin instead of relying on a row's `gap`. */
#export-dialog .field {
  margin-bottom: 14px;
}

.export-format-field .segmented-group {
  margin-top: 2px;
}

#import-spritesheet-dialog {
  width: min(360px, 92vw);
}

.import-sheet-preview-wrap {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 14px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-alt);
}

#import-sheet-preview-canvas {
  max-width: 100%;
  image-rendering: pixelated;
  border: 1px solid var(--border);
}

.import-sheet-hint {
  margin: -4px 0 14px;
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.4;
}

.export-hint {
  margin: -4px 0 14px;
  font-size: 11px;
  color: var(--text-dim);
  font-style: italic;
}

/* ---- V Brush pipeline dialog ---- */

/* Wider than the default dialog — it holds a variable-length list of node
   cards, each with several numeric fields, not just a couple of inputs.
   The `display: flex` below is only safe scoped to `[open]`: an unscoped
   `#vbrush-pipeline-dialog { display: flex }` would (like the `.ref-pane`
   bug elsewhere in this file) override the browser's own
   `dialog:not([open]) { display: none }` default and make the dialog show
   — and block clicks on the page underneath it — even while closed. */
#vbrush-pipeline-dialog {
  width: min(560px, 92vw);
  max-height: 85vh;
}

#vbrush-pipeline-dialog[open] {
  display: flex;
  flex-direction: column;
}

#vbrush-pipeline-dialog .dialog-actions {
  justify-content: space-between;
}

.vbrush-pipeline-hint {
  margin: 0 0 12px;
  font-size: 12px;
  color: var(--text-dim);
  font-style: italic;
}

.vbrush-node-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
  overflow-y: auto;
  max-height: 46vh;
}

.vbrush-node-row {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-alt);
  padding: 8px 10px;
}

.vbrush-node-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

.vbrush-node-title {
  flex: 1;
  font-size: 12px;
  font-weight: 600;
}

.vbrush-node-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
}

.vbrush-field {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 10px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.vbrush-field input,
.vbrush-field select {
  padding: 4px 6px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12px;
  width: 84px;
}

.vbrush-field select {
  width: auto;
}

.vbrush-field-row {
  display: flex;
  align-items: center;
  gap: 4px;
}

.vbrush-field-row input {
  width: 84px;
}

.vbrush-node-note {
  font-size: 11px;
  color: var(--text-dim);
  font-style: italic;
  align-self: center;
}

.vbrush-reroll-btn {
  flex: none;
  width: 24px;
  height: 24px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-size: 12px;
}

.vbrush-reroll-btn:hover {
  border-color: var(--accent);
}

.vbrush-add-row {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.vbrush-add-row select {
  flex: 1;
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  font-size: 12px;
}

/* Presets row — same layout language as .vbrush-add-row (a select plus
   buttons in one line) but with a small leading label, since "Preset"
   isn't as self-explanatory as the node-type dropdown next to "Add Node". */
.vbrush-preset-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}

.vbrush-preset-label {
  flex: none;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.vbrush-preset-row select {
  flex: 1;
  min-width: 0;
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  font-size: 12px;
}

/* Range sliders inside a node card (Perlin Noise's params, Brick/Wood
   texture params, Color Ramp's stop positions) — wider than the plain
   number fields since a slider needs room to be draggable, with a small
   read-only readout beside it instead of a typed/steppered number. */
.vbrush-field-row input[type='range'] {
  width: 96px;
  accent-color: var(--accent);
}

.vbrush-range-value {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text);
  min-width: 2.4em;
  text-align: right;
}

/* Color-picker swatches (Color Clamp's Min/Max, Color Ramp's stops) —
   small squares rather than the browser's default wide color input. */
.vbrush-color-swatch {
  width: 28px;
  height: 24px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: none;
  cursor: pointer;
  flex: none;
}

.vbrush-clamp-controls {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  align-items: flex-start;
}

.vbrush-clamp-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 100px;
}

.vbrush-clamp-group-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.vbrush-clamp-swatch-row {
  display: flex;
}

.vbrush-ramp-stops {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
}

.vbrush-ramp-stop {
  display: flex;
  align-items: center;
  gap: 8px;
}

.vbrush-ramp-stop .vbrush-field {
  flex: 1;
}

.vbrush-add-stop-btn {
  align-self: flex-start;
  padding: 4px 10px;
  font-size: 11px;
}

/* Brick Texture's "Seamless Tiling" checkbox — same row, checkbox first. */
.vbrush-checkbox-field {
  flex-direction: row !important;
  align-items: center;
  gap: 6px;
  text-transform: none;
  font-size: 12px;
  color: var(--text);
  width: 100%;
}

.vbrush-checkbox-field input[type='checkbox'] {
  width: auto;
  accent-color: var(--accent);
  cursor: pointer;
}

/* A full-width label breaking a node's controls into sub-groups (e.g.
   Brick Texture's "Variation" cluster of corner-radius/waviness/etc). */
.vbrush-node-subheading {
  flex-basis: 100%;
  font-size: 10px;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-top: 1px solid var(--border);
  padding-top: 8px;
  margin-top: 2px;
}

/* Live preview — shows what the brush will actually paint (same hash +
   pipeline math as VBrushTool._dab), refreshed after every add/remove/
   reorder/param edit via renderPreview(). */
.vbrush-preview {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-alt);
}

#vbrush-preview-canvas {
  width: 96px;
  height: 96px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: #808080;
  image-rendering: pixelated;
  flex: none;
}

.vbrush-preview-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.vbrush-preview-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text);
}

.vbrush-preview-caption {
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.4;
}

/* =========================================================================
   Responsive: phones — stack sidebar under canvas, wrap the toolbar
   ========================================================================= */

@media (max-width: 640px) {
  #main-area {
    flex-direction: column;
    overflow-y: auto;
  }

  #sidebar {
    width: 100%;
    max-height: 40vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  #canvas-viewport {
    padding: 16px;
  }

  #menu-bar .brand {
    display: none;
  }

  /* Side-by-side reference panes stack above/below the canvas instead of
     eating horizontal space that's already tight on a phone. */
  #canvas-stage {
    flex-direction: column;
    gap: 12px;
  }

  .ref-pane canvas,
  .ref-placeholder {
    max-width: 96px;
    max-height: 96px;
  }

  #reference-bar {
    gap: 8px;
  }

  .filmstrip-tile {
    width: 44px;
    height: 44px;
  }

  .filmstrip-thumb-wrap {
    width: 34px;
    height: 34px;
  }

  .filmstrip-gap {
    height: 44px;
    width: 34px;
  }

  .gap-btn {
    width: 15px;
    height: 15px;
    font-size: 9px;
  }
}
