@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

*, *::before, *::after { box-sizing: border-box; }

/* ── Design tokens ───────────────────────────────────────────────────────────  */
:root {
  --glass-bg:     rgba(255, 255, 255, 0.10);
  --glass-border: rgba(255, 255, 255, 0.72);
  --glass-blur:   24px;

  --text:         #1c2a5e;
  --text-muted:   #6f82c8;
  --accent:       #4a5c88;
  --accent-2:     #33415f;
  --accent-fg:    #ffffff;

  --sidebar-w:    228px;
  --header-h:     54px;

  /* Safe-area insets (notch / home indicator on iPhone & iPad) */
  --safe-top:     env(safe-area-inset-top, 0px);
  --safe-bottom:  env(safe-area-inset-bottom, 0px);
  --safe-left:    env(safe-area-inset-left, 0px);
  --safe-right:   env(safe-area-inset-right, 0px);

  --r-pill:       999px;
  --r-card:       20px;
  --r-sm:         12px;

  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

  /* Liquid glass rim — the thick specular edge that defines the look */
  --rim:
    inset 0 2px 6px  rgba(255, 255, 255, 0.95),
    inset 0 -2px 4px rgba(200, 210, 255, 0.22),
    inset 3px 0 5px  rgba(255, 255, 255, 0.40),
    inset -1px 0 3px rgba(200, 210, 255, 0.12);

  --outer-glow:
    0 8px 32px rgba(140, 155, 220, 0.18),
    0 2px  8px rgba(140, 155, 220, 0.12);
}

/* ── Background ──────────────────────────────────────────────────────────────  */
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;          /* no rubber-band / pull-to-refresh */
  font-family: var(--font);
  font-size: 12px;
  color: var(--text);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;        /* no long-press image/callout menu */
  -webkit-tap-highlight-color: transparent;
}

body {
  background: #ffffff;
}

/* ── Liquid glass mixin ──────────────────────────────────────────────────────  */
/* The "water rim" look: nearly transparent body, thick bright border, deep inset shadows */
.glass {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur)) saturate(140%);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(140%);
  border: 2px solid var(--glass-border);
  box-shadow: var(--rim), var(--outer-glow);
}

/* ── Header ──────────────────────────────────────────────────────────────────  */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  height: calc(var(--header-h) + var(--safe-top));
  padding: var(--safe-top) calc(20px + var(--safe-right)) 0 calc(20px + var(--safe-left));
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 20;
  background: transparent;
  border-bottom: none;
}

/* ── Mobile drawer toggle buttons (hidden on desktop) ─────────────────────────  */
.drawer-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  padding: 0;
  border-radius: 12px;
  cursor: pointer;
  color: var(--text);
  background: rgba(255, 255, 255, 0.22);
  backdrop-filter: blur(20px) saturate(140%);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  border: 1.5px solid rgba(255, 255, 255, 0.70);
  box-shadow:
    inset 0 1px 3px rgba(255, 255, 255, 0.90),
    0 4px 14px rgba(130, 145, 210, 0.18);
  transition: background 0.15s, transform 0.12s, color 0.15s;
}
.drawer-toggle:active { transform: scale(0.94); }
.drawer-toggle.active {
  background: rgba(74, 92, 136, 0.14);
  border-color: rgba(74, 92, 136, 0.40);
  color: var(--accent);
}

.btn-load-short { display: none; }

.logo {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: 8px;
}
.logo::before {
  content: '+';
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  background: rgba(74, 92, 136, 0.08);
  border: 1.5px solid rgba(74, 92, 136, 0.28);
  border-radius: 7px;
  font-size: 15px;
  font-weight: 300;
  line-height: 1;
}

.header-actions { display: flex; gap: 8px; }

/* ── Buttons ─────────────────────────────────────────────────────────────────  */
.btn {
  border: none;
  border-radius: var(--r-pill);
  padding: 9px 20px;
  font: 600 11px/1 var(--font);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.15s, opacity 0.15s;
  position: relative;
  overflow: hidden;
}
.btn:hover:not(:disabled) { transform: translateY(-1px); }
.btn:active:not(:disabled) { transform: scale(0.97) translateY(0); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Specular sweep on all buttons */
.btn::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 52%;
  background: linear-gradient(180deg,
    rgba(255,255,255,0.60) 0%,
    rgba(255,255,255,0.00) 100%
  );
  border-radius: var(--r-pill) var(--r-pill) 0 0;
  pointer-events: none;
}

/* Ghost = liquid glass button (like "Cancel" in reference) */
.btn-ghost {
  background: rgba(255, 255, 255, 0.14);
  backdrop-filter: blur(20px) saturate(130%);
  -webkit-backdrop-filter: blur(20px) saturate(130%);
  border: 2px solid rgba(255, 255, 255, 0.72);
  color: var(--text);
  box-shadow:
    inset 0 2px 5px rgba(255, 255, 255, 0.90),
    inset 0 -1px 3px rgba(180, 190, 255, 0.18),
    0 4px 16px rgba(140, 155, 220, 0.16);
}
.btn-ghost:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.24);
  box-shadow:
    inset 0 2px 6px rgba(255, 255, 255, 0.95),
    0 6px 22px rgba(140, 155, 220, 0.22);
}

/* Export = polished silver chrome */
.btn-export {
  background: linear-gradient(180deg, #fcfdff 0%, #e8ecf4 46%, #ccd4e2 54%, #eef2f8 100%);
  color: #2b3a5e;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.75);
  border: 1.5px solid rgba(150, 162, 190, 0.70);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.95),
    inset 0 -2px 3px rgba(120, 132, 165, 0.30),
    0 5px 16px rgba(90, 105, 150, 0.28);
}
.btn-export:hover:not(:disabled) {
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 1),
    0 7px 22px rgba(90, 105, 150, 0.42);
}
.btn-export:disabled {
  background: linear-gradient(180deg, #f2f3f7 0%, #dde0e8 100%);
  color: #9aa3b8; text-shadow: none;
}

.btn-full { width: 100%; text-align: center; }

/* ── Workspace ───────────────────────────────────────────────────────────────  */
.workspace {
  /* Grid removed — everything is position:fixed now */
  position: relative;
  height: calc(100vh - var(--header-h));
}

/* ── Sidebars ────────────────────────────────────────────────────────────────  */
.sidebar {
  position: fixed;
  top: 0;                        /* start from top so blur merges with header */
  bottom: 0;
  width: var(--sidebar-w);
  z-index: 10;
  background: rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(15px) saturate(150%);
  -webkit-backdrop-filter: blur(15px) saturate(150%);
  border: none;
  box-shadow: none;
  /* push content below the header (+ notch) */
  padding: calc(var(--header-h) + var(--safe-top) + 14px) 12px calc(14px + var(--safe-bottom));
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}
.sidebar-left  { left: 0;  padding-left:  calc(12px + var(--safe-left)); }
.sidebar-right { right: 0; padding-right: calc(12px + var(--safe-right)); }

/* Scrim behind an open mobile drawer */
.scrim {
  display: block;
  position: fixed;
  inset: 0;
  z-index: 35;
  background: rgba(28, 38, 88, 0.20);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}
.scrim[hidden] { display: none; }

/* Scrollbar */
.sidebar::-webkit-scrollbar { width: 3px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(140,155,220,0.28); border-radius: 99px; }

.panel-title {
  margin: 0 0 10px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.panel-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.panel-title-row .panel-title { margin-bottom: 0; }

/* ── Layer list ──────────────────────────────────────────────────────────────  */
.layer-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* ── Layer card — the core liquid glass element ──────────────────────────────  */
.layer {
  display: grid;
  grid-template-columns: 46px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: var(--r-card);
  cursor: pointer;
  user-select: none;

  /* Nearly transparent — the "water" look comes from the rim, not the fill */
  background: rgba(255, 255, 255, 0.14);
  backdrop-filter: blur(16px) saturate(130%);
  -webkit-backdrop-filter: blur(16px) saturate(130%);
  border: 2px solid rgba(255, 255, 255, 0.72);

  box-shadow:
    /* Top bright rim — the defining liquid glass trait */
    inset 0 2px 5px  rgba(255, 255, 255, 0.95),
    /* Left rim */
    inset 3px 0 5px  rgba(255, 255, 255, 0.42),
    /* Bottom rim (slight cool tint for depth) */
    inset 0 -2px 4px rgba(190, 200, 255, 0.20),
    /* Outer soft shadow */
    0 6px 24px rgba(130, 145, 210, 0.16),
    0 2px  6px rgba(130, 145, 210, 0.10);

  transition: all 0.18s;
  position: relative;
  overflow: hidden;
}

/* Specular sweep across the top surface */
.layer::after {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 42%;
  background: linear-gradient(180deg,
    rgba(255,255,255,0.70) 0%,
    rgba(255,255,255,0.00) 100%
  );
  border-radius: var(--r-card) var(--r-card) 50% 50%;
  pointer-events: none;
}

.layer:hover {
  background: rgba(255, 255, 255, 0.24);
  box-shadow:
    inset 0 2px 6px  rgba(255, 255, 255, 1.0),
    inset 3px 0 5px  rgba(255, 255, 255, 0.50),
    inset 0 -2px 4px rgba(190, 200, 255, 0.22),
    0 8px 28px rgba(130, 145, 210, 0.22),
    0 3px  8px rgba(130, 145, 210, 0.14);
  transform: translateY(-1px);
}

.layer-active {
  background: rgba(74, 92, 136, 0.10) !important;
  border: 2px solid rgba(100, 140, 255, 0.50) !important;
  box-shadow:
    inset 0 2px 5px rgba(180, 200, 255, 0.70),
    inset 3px 0 5px rgba(180, 200, 255, 0.30),
    0 6px 24px rgba(74, 92, 136, 0.18) !important;
}

.layer-stack {
  background: transparent !important;
  backdrop-filter: none !important;
  border: none !important;
  box-shadow: none !important;
  margin-top: 4px;
  padding-top: 8px;
  border-top: 1px solid rgba(140, 155, 220, 0.25) !important;
}
.layer-stack::after { display: none; }
.layer-stack:hover { transform: none; }

.layer-thumb {
  padding: 0;
  border: 1.5px solid rgba(255, 255, 255, 0.60);
  border-radius: 10px;
  background: rgba(10, 12, 25, 0.78);
  cursor: pointer;
  overflow: hidden;
  width: 46px;
  height: 46px;
  transition: border-color 0.15s;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.20),
    0 2px 8px rgba(0,0,0,0.22);
  position: relative;
  z-index: 1;
}
.layer-thumb:hover:not(:disabled) { border-color: rgba(100, 140, 255, 0.60); }
.layer-thumb:disabled { cursor: default; opacity: 0.5; }

.layer-thumb-canvas { display: block; width: 100%; height: 100%; object-fit: cover; }

.layer-name {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text);
  position: relative;
  z-index: 1;
}

.layer-actions {
  display: flex;
  flex-direction: row;
  gap: 6px;
  align-items: center;
  position: relative;
  z-index: 1;
}


.layer-stack-badge {
  font-size: 9px;
  font-weight: 700;
  color: var(--accent);
  background: rgba(74, 92, 136, 0.10);
  border: 1.5px solid rgba(74, 92, 136, 0.28);
  border-radius: var(--r-pill);
  padding: 2px 7px;
  position: relative;
  z-index: 1;
}

.hint {
  margin-top: 14px;
  color: var(--text-muted);
  font-size: 10px;
  line-height: 1.6;
  letter-spacing: 0;
  text-transform: none;
}

/* ── Canvas area ─────────────────────────────────────────────────────────────  */
.canvas-area {
  position: fixed;
  inset: 0;
  z-index: 0;
  background: #ffffff;
  overflow: hidden;
  touch-action: none;   /* we handle pan / pinch ourselves via pointer events */
}
.canvas-area.drag-over {
  outline: 2px dashed rgba(100, 140, 255, 0.5);
  outline-offset: -8px;
}

.canvas-wrap {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: visible;
}
.canvas-wrap.bg-checker {
  background-image:
    linear-gradient(45deg, #e0e0e0 25%, transparent 25%),
    linear-gradient(-45deg, #e0e0e0 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e0e0e0 75%),
    linear-gradient(-45deg, transparent 75%, #e0e0e0 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-color: #ffffff;
}
.canvas-wrap.bg-black { background: #000; }
.canvas-wrap.bg-white { background: #fff; }

.preview-canvas {
  display: none; /* hidden until image loads */
  image-rendering: auto;
  border-radius: 4px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.65);
}
.preview-canvas.hidden { display: none; }
/* Show only once empty-state is hidden (i.e. image is loaded) */
.canvas-wrap:has(.empty-state.hidden) .preview-canvas:not(.hidden) { display: block; }

.empty-state {
  text-align: center;
  color: rgba(140, 155, 210, 0.60);
  pointer-events: none;
}
.empty-state.hidden { display: none; }
.empty-state p:first-child { font-size: 14px; font-weight: 500; }
.empty-sub { font-size: 11px; margin-top: 8px; opacity: 0.7; text-transform: none; letter-spacing: 0; }

/* ── Bottom toolbar — floating liquid glass pill ─────────────────────────────  */
.canvas-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  background: rgba(255, 255, 255, 0.22);
  backdrop-filter: blur(28px) saturate(140%);
  -webkit-backdrop-filter: blur(28px) saturate(140%);
  border: 2px solid rgba(255, 255, 255, 0.75);
  border-radius: var(--r-pill);
  box-shadow:
    inset 0 2px 6px rgba(255, 255, 255, 0.95),
    inset 0 -1px 3px rgba(180, 190, 255, 0.18),
    0 10px 40px rgba(130, 145, 210, 0.20),
    0 3px  10px rgba(130, 145, 210, 0.14);
  position: fixed;
  bottom: calc(18px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100vw - 24px);
  z-index: 20;
  overflow: hidden;
  touch-action: auto;   /* allow the selects / export button to be tapped */
}

/* Specular sweep on toolbar pill */
.canvas-toolbar::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 52%;
  background: linear-gradient(180deg,
    rgba(255,255,255,0.65) 0%,
    rgba(255,255,255,0.00) 100%
  );
  border-radius: var(--r-pill) var(--r-pill) 0 0;
  pointer-events: none;
}

.toolbar-select {
  background: rgba(255, 255, 255, 0.30);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1.5px solid rgba(255, 255, 255, 0.68);
  color: var(--text);
  border-radius: var(--r-pill);
  padding: 5px 12px;
  font: 500 11px var(--font);
  cursor: pointer;
  outline: none;
  box-shadow: inset 0 1px 3px rgba(255,255,255,0.80);
  position: relative;
  z-index: 1;
}

.toolbar-format {
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 0 4px;
  position: relative;
  z-index: 1;
}

/* ── Right panel controls ────────────────────────────────────────────────────  */
.ctrl-panel.hidden { display: none; }
.control { margin-bottom: 18px; }

.control label,
.control-label {
  display: block;
  margin-bottom: 7px;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* Glass slider */
.control input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: calc(100% - 34px);
  height: 6px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.55);
  box-shadow:
    inset 0 1px 3px rgba(180, 190, 255, 0.20),
    inset 0 1px 0 rgba(255,255,255,0.80);
  outline: none;
  vertical-align: middle;
  cursor: pointer;
  border: 1px solid rgba(255,255,255,0.70);
}
.control input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 32%, #ffffff 0%, #eef1f7 55%, #ccd4e4 100%);
  border: 2px solid rgba(255, 255, 255, 0.90);
  box-shadow:
    0 2px 8px rgba(90, 105, 150, 0.40),
    inset 0 1px 0 rgba(255, 255, 255, 0.55);
  cursor: pointer;
}
.control input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 32%, #ffffff 0%, #eef1f7 55%, #ccd4e4 100%);
  border: 2px solid rgba(255, 255, 255, 0.90);
  cursor: pointer;
}

.control-value {
  display: inline-block;
  width: 26px;
  text-align: right;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: 11px;
}

/* ── Toggle groups ───────────────────────────────────────────────────────────  */
.control-toggle .toggle-group { display: flex; gap: 4px; }

/* Toggle = liquid glass chip (like tab bar in reference) */
.toggle {
  flex: 1;
  background: rgba(255, 255, 255, 0.18);
  backdrop-filter: blur(12px) saturate(130%);
  -webkit-backdrop-filter: blur(12px) saturate(130%);
  border: 2px solid rgba(255, 255, 255, 0.68);
  color: var(--text-muted);
  border-radius: var(--r-pill);
  padding: 7px 8px;
  font: 600 10px/1 var(--font);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.15s;
  box-shadow:
    inset 0 2px 4px rgba(255,255,255,0.90),
    inset 0 -1px 2px rgba(180,190,255,0.15),
    0 3px 10px rgba(130,145,210,0.12);
  position: relative;
  overflow: hidden;
}
.toggle::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 50%;
  background: linear-gradient(180deg, rgba(255,255,255,0.55) 0%, transparent 100%);
  border-radius: var(--r-pill) var(--r-pill) 0 0;
  pointer-events: none;
}
.toggle:hover {
  background: rgba(255, 255, 255, 0.32);
  color: var(--text);
  box-shadow:
    inset 0 2px 5px rgba(255,255,255,0.95),
    0 4px 14px rgba(130,145,210,0.18);
}
.toggle.active {
  background: linear-gradient(180deg, #fbfcff 0%, #e6eaf2 50%, #cdd5e3 100%);
  color: #2b3a5e;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.7);
  border-color: rgba(150, 162, 190, 0.6);
  box-shadow:
    inset 0 2px 4px rgba(255,255,255,0.30),
    0 4px 18px rgba(74, 92, 136, 0.40);
}

/* ── Lock button ─────────────────────────────────────────────────────────────  */
.lock-btn {
  background: rgba(255, 255, 255, 0.20);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1.5px solid rgba(255, 255, 255, 0.68);
  border-radius: var(--r-sm);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 12px;
  padding: 3px 6px;
  line-height: 1;
  transition: all 0.15s;
  box-shadow:
    inset 0 1px 3px rgba(255,255,255,0.90),
    0 2px 8px rgba(130,145,210,0.12);
}
.lock-btn:hover { background: rgba(255,255,255,0.35); color: var(--text); }
.lock-btn.locked {
  background: rgba(74, 92, 136, 0.10);
  border-color: rgba(74, 92, 136, 0.38);
  color: var(--accent);
}

/* ── Locked state ────────────────────────────────────────────────────────────  */
.ctrl-panel.locked input[type="range"],
.ctrl-panel.locked .toggle,
.ctrl-panel.locked .btn:not(.lock-btn) {
  opacity: 0.35;
  pointer-events: none;
}
.ctrl-panel.locked .hint { opacity: 0.4; }

/* ── Responsive: phones & iPad portrait become slide-in drawers ───────────────  */
@media (max-width: 860px) {
  /* Header swaps to icon toggles + compact load button */
  .drawer-toggle  { display: inline-flex; }
  .btn-load-full  { display: none; }
  .btn-load-short { display: inline; font-size: 16px; }
  .logo           { font-size: 12px; letter-spacing: 0.08em; }

  /* Sidebars slide in from the edges over the canvas — same light glass as desktop */
  .sidebar {
    width: min(320px, 86vw);
    z-index: 40;
    box-shadow: 0 14px 50px rgba(55, 70, 150, 0.16);
    transition: transform 0.32s cubic-bezier(0.22, 1, 0.36, 1);
    will-change: transform;
  }
  .sidebar-left  { transform: translateX(-103%); }
  .sidebar-right { transform: translateX(103%); }
  .sidebar-left.open,
  .sidebar-right.open { transform: translateX(0); }

  /* Bigger, finger-friendly hit targets */
  .layer { padding: 10px 9px; }
  .toggle { padding: 11px 8px; font-size: 11px; }
  .lock-btn { font-size: 15px; padding: 6px 9px; }
  .control { margin-bottom: 20px; }
  .control input[type="range"] { height: 9px; }
  .control input[type="range"]::-webkit-slider-thumb { width: 24px; height: 24px; }
  .control input[type="range"]::-moz-range-thumb     { width: 24px; height: 24px; }
  .toolbar-select { padding: 8px 12px; font-size: 12px; }
  .canvas-toolbar { gap: 6px; padding: 8px 12px; }
}

/* Coarse-pointer (touch) tweaks regardless of width — bigger toolbar targets */
@media (pointer: coarse) {
  .btn { padding: 11px 20px; }
}

/* Narrow phones: drop the format label so the EXPORT button isn't clipped */
@media (max-width: 430px) {
  .toolbar-format { display: none; }
  .canvas-toolbar { gap: 5px; padding: 8px 10px; }
}

/* ── Mobile knob rail — live edge controls ───────────────────────────────────  */
.knob-rail   { display: none; }
.knob-bubble { display: none; }

@media (max-width: 860px) {
  /* Knobs replace the slider rows inside the panel drawer on mobile */
  .sidebar-right .control:has(input[type="range"]) { display: none; }

  .knob-rail {
    position: fixed;
    right: 0;
    top:    calc(var(--header-h) + var(--safe-top) + 10px);
    bottom: calc(92px + var(--safe-bottom));
    width: 104px;
    z-index: 25;
    display: none;                       /* shown via .show when layer has knobs */
    flex-direction: column;
    align-items: center;
    gap: 14px;
    padding: 18px 0;
    overflow-y: auto;
    overflow-x: hidden;
    touch-action: none;
    /* frosted glass strip behind the knobs */
    background: rgba(255, 255, 255, 0.10);
    backdrop-filter: blur(16px) saturate(150%);
    -webkit-backdrop-filter: blur(16px) saturate(150%);
    border-left: 1px solid rgba(255, 255, 255, 0.55);
    border-radius: 22px 0 0 22px;
    box-shadow: -10px 0 30px rgba(40, 60, 150, 0.16);
  }
  .knob-rail.show { display: flex; }
  .knob-rail::-webkit-scrollbar { width: 0; }

  /* The rail is the full edit surface on mobile → no settings drawer toggle */
  .drawer-toggle-right { display: none; }
}

.knob-control { display: flex; flex-direction: column; align-items: center; gap: 4px; flex: 0 0 auto; }

.knob {
  width: 58px; height: 58px;
  position: relative;
  cursor: ns-resize;
  touch-action: none;
  border-radius: 50%;          /* clip the PNG's square soft-glow corners */
  /* designed knob asset (dimpled disc with baked-in shading) */
  background: url('../assets/knob.png') center / cover no-repeat;
  transition: transform 0.1s ease, filter 0.12s ease;
}
.knob::before, .knob::after { content: none; display: none; }
.knob.active { transform: scale(1.08); }

.knob-cap {
  font-size: 8.5px; font-weight: 700; letter-spacing: 0.04em;
  text-transform: uppercase; color: var(--text-muted);
}
.knob-num {
  font-size: 11px; font-weight: 700; line-height: 1;
  color: var(--text); font-variant-numeric: tabular-nums;
}

/* Floating value readout while dragging a knob */
.knob-bubble {
  position: fixed; z-index: 60;
  transform: translateY(-50%);
  background: linear-gradient(160deg, #525f7f, #313c58);
  color: #fff;
  font: 700 16px/1 var(--font); font-variant-numeric: tabular-nums;
  padding: 9px 14px; border-radius: 13px;
  box-shadow: 0 6px 22px rgba(35, 45, 75, 0.45);
  pointer-events: none;
}
.knob-bubble[hidden] { display: none; }

/* ── Rail extras: lock chip, toggles, action buttons ─────────────────────────  */
.rail-lock {
  width: 36px; height: 36px; flex: 0 0 auto;
  border: 1.5px solid rgba(255, 255, 255, 0.6);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.45);
  color: var(--text-muted);
  font-size: 14px; line-height: 1; cursor: pointer;
  box-shadow: inset 0 1px 2px rgba(255,255,255,0.85), 0 2px 7px rgba(40,60,150,0.16);
}
.rail-lock.on { background: rgba(74, 92, 136, 0.18); border-color: rgba(74, 92, 136, 0.45); color: var(--accent); }

/* Fixed-width centered column so nothing reaches the rail edges */
.rail-seg-group { display: flex; flex-direction: column; align-items: center; gap: 5px; width: 84px; flex: 0 0 auto; }
.rail-seg-label {
  font-size: 8px; font-weight: 700; letter-spacing: 0.05em;
  text-transform: uppercase; color: var(--text-muted);
}
.rail-seg { display: flex; flex-direction: column; gap: 4px; width: 100%; }

/* Shared liquid-glass treatment to match the EXPORT / toggle language */
.rail-seg-btn, .rail-btn {
  position: relative; overflow: hidden;
  flex: 0 0 auto;
  border: 1.5px solid rgba(255, 255, 255, 0.72);
  background: rgba(255, 255, 255, 0.20);
  color: var(--text-muted);
  font: 700 9px/1 var(--font); letter-spacing: 0.04em; text-transform: uppercase;
  cursor: pointer;
  box-shadow:
    inset 0 2px 4px rgba(255, 255, 255, 0.90),
    inset 0 -1px 2px rgba(180, 190, 255, 0.16),
    0 3px 10px rgba(130, 145, 210, 0.14);
  transition: background 0.12s, color 0.12s;
}
.rail-seg-btn::before, .rail-btn::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 50%;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.55), transparent);
  pointer-events: none;
}
.rail-seg-btn { width: 100%; border-radius: 999px; padding: 8px 4px; }
.rail-seg-btn::before { border-radius: 999px 999px 0 0; }
.rail-seg-btn.active {
  background: linear-gradient(180deg, #fbfcff 0%, #e6eaf2 50%, #cdd5e3 100%);
  color: #2b3a5e; border-color: rgba(150, 162, 190, 0.6);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.7);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.95),
    inset 0 -2px 3px rgba(120, 132, 165, 0.25),
    0 4px 14px rgba(90, 105, 150, 0.25);
}

.rail-btn {
  width: 84px; border-radius: 13px; padding: 10px 4px;
  color: #2b3a5e; text-align: center; text-shadow: 0 1px 0 rgba(255, 255, 255, 0.7);
  background: linear-gradient(180deg, #fbfcff 0%, #e6eaf2 50%, #cfd6e4 100%);
  border-color: rgba(150, 162, 190, 0.65);
}
.rail-btn::before { border-radius: 13px 13px 0 0; }
.rail-btn:active { background: rgba(255, 255, 255, 0.34); }

/* Liquid-glass sliding switch (translucent glassy track + glossy thumb) */
.rail-switch {
  position: relative; flex: 0 0 auto;
  width: 50px; height: 28px; padding: 0;
  border-radius: 999px;
  border: 1.5px solid rgba(255, 255, 255, 0.60);
  /* glass base + built-in top sheen (no overflow clip needed) */
  background:
    linear-gradient(180deg, rgba(255,255,255,0.5), rgba(255,255,255,0) 50%),
    linear-gradient(180deg, #b6bfd0, #8a93a9);
  -webkit-backdrop-filter: blur(8px) saturate(140%);
  backdrop-filter: blur(8px) saturate(140%);
  cursor: pointer;
  box-shadow:
    inset 0 1px 2px rgba(255, 255, 255, 0.65),
    inset 0 -2px 4px rgba(110, 125, 175, 0.30),
    0 2px 7px rgba(40, 60, 150, 0.14);
  transition: background 0.4s ease, border-color 0.4s ease, box-shadow 0.4s ease;
}
.rail-switch.on {
  background:
    linear-gradient(180deg, rgba(255,255,255,0.42), rgba(255,255,255,0) 52%),
    linear-gradient(180deg, #8da0c6 0%, #586c9a 100%);
  border-color: rgba(120, 138, 178, 0.65);
  box-shadow:
    inset 0 1px 2px rgba(255, 255, 255, 0.50),
    inset 0 -2px 5px rgba(50, 65, 110, 0.35),
    0 3px 11px rgba(70, 90, 140, 0.35);
}
/* glossy liquid bead */
.rail-switch-thumb {
  position: absolute; top: 2px; left: 2px;
  width: 22px; height: 22px; border-radius: 50%;
  background: radial-gradient(circle at 50% 32%, #ffffff 0%, #f2f4f9 50%, #d3dae8 100%);
  box-shadow:
    0 2px 6px rgba(18, 40, 120, 0.45),
    inset 0 1px 1px rgba(255, 255, 255, 0.95),
    inset 0 -2px 3px rgba(150, 165, 210, 0.45);
  /* springy, overshooting slide for the liquid feel */
  transition: transform 0.36s cubic-bezier(0.34, 1.56, 0.45, 1);
}
.rail-switch.on .rail-switch-thumb { transform: translateX(22px); }
.rail-switch:active .rail-switch-thumb {
  box-shadow: 0 1px 4px rgba(18, 40, 120, 0.5), inset 0 1px 1px rgba(255, 255, 255, 0.95);
}
.rail-switch-val {
  font-size: 8.5px; font-weight: 700; letter-spacing: 0.04em;
  text-transform: uppercase; color: var(--text-muted);
}

/* Locked layer → dim + freeze everything except the lock chip */
.knob-rail.locked .knob-control,
.knob-rail.locked .rail-seg-group,
.knob-rail.locked .rail-btn { opacity: 0.4; pointer-events: none; }

/* ── Ko-fi support toast ─────────────────────────────────────────────────────*/
.kofi-toast {
  position: fixed;
  bottom: calc(24px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(120%);
  z-index: 120;
  width: min(340px, calc(100vw - 32px));
  padding: 18px 20px 16px;
  border-radius: 18px;
  background: linear-gradient(160deg, rgba(255,255,255,0.18) 0%, rgba(255,255,255,0.08) 100%);
  backdrop-filter: blur(28px) saturate(160%);
  -webkit-backdrop-filter: blur(28px) saturate(160%);
  border: 1px solid rgba(255,255,255,0.30);
  box-shadow: 0 8px 40px rgba(30,40,80,0.28), inset 0 1px 0 rgba(255,255,255,0.55);
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: transform 0.42s cubic-bezier(0.34, 1.4, 0.55, 1), opacity 0.3s ease;
  opacity: 0;
}
.kofi-toast:not([hidden]) {
  display: flex;
}
.kofi-toast[hidden] {
  display: none;
}
.kofi-toast.visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}
.kofi-close {
  position: absolute;
  top: 10px; right: 12px;
  background: none; border: none; padding: 4px 6px;
  font-size: 11px; color: var(--text-muted);
  cursor: pointer; line-height: 1;
  opacity: 0.7;
  transition: opacity 0.15s;
}
.kofi-close:hover { opacity: 1; }
.kofi-msg {
  margin: 0;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  line-height: 1.4;
  padding-right: 20px;
}
.kofi-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 20px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-decoration: none;
  color: #fff;
  background: linear-gradient(180deg, #ff7b54 0%, #ff5722 100%);
  box-shadow: 0 3px 12px rgba(255,87,34,0.40), inset 0 1px 0 rgba(255,255,255,0.28);
  border: 1px solid rgba(200,60,0,0.25);
  transition: filter 0.15s, transform 0.12s;
  align-self: flex-start;
}
.kofi-btn:hover  { filter: brightness(1.08); transform: translateY(-1px); }
.kofi-btn:active { filter: brightness(0.96); transform: translateY(0); }

/* ── Processing overlay ──────────────────────────────────────────────────────*/
.process-overlay {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(12, 16, 30, 0.55);
  backdrop-filter: blur(6px) saturate(120%);
  -webkit-backdrop-filter: blur(6px) saturate(120%);
  border-radius: inherit;
  animation: overlay-in 0.18s ease forwards;
}
.process-overlay[hidden] { display: none; }
@keyframes overlay-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.process-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 28px 36px;
  border-radius: 20px;
  background: linear-gradient(160deg, rgba(255,255,255,0.14) 0%, rgba(255,255,255,0.06) 100%);
  border: 1px solid rgba(255,255,255,0.22);
  box-shadow: 0 8px 40px rgba(10,15,40,0.45), inset 0 1px 0 rgba(255,255,255,0.4);
  backdrop-filter: blur(20px) saturate(150%);
  -webkit-backdrop-filter: blur(20px) saturate(150%);
  animation: card-in 0.22s cubic-bezier(0.34,1.4,0.55,1) forwards;
}
@keyframes card-in {
  from { transform: scale(0.88); opacity: 0; }
  to   { transform: scale(1);    opacity: 1; }
}
.process-spinner {
  width: 36px; height: 36px;
  border: 3px solid rgba(255,255,255,0.15);
  border-top-color: rgba(200,215,255,0.90);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
.process-label {
  margin: 0;
  font-size: 13px; font-weight: 700;
  letter-spacing: 0.06em; text-transform: uppercase;
  color: rgba(220,228,255,0.92);
}
.process-sub {
  margin: 0;
  font-size: 11px; font-weight: 500;
  color: rgba(180,196,240,0.65);
  letter-spacing: 0.03em;
}

/* ── Ko-fi donation modal ────────────────────────────────────────────────────*/
.kofi-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 14, 28, 0.60);
  backdrop-filter: blur(10px) saturate(130%);
  -webkit-backdrop-filter: blur(10px) saturate(130%);
  animation: overlay-in 0.2s ease forwards;
}
.kofi-modal[hidden] { display: none; }
.kofi-modal-card {
  position: relative;
  width: min(480px, calc(100vw - 32px));
  height: min(620px, calc(100dvh - 60px));
  border-radius: 22px;
  background: linear-gradient(160deg, rgba(255,255,255,0.16) 0%, rgba(255,255,255,0.07) 100%);
  border: 1px solid rgba(255,255,255,0.25);
  box-shadow: 0 16px 64px rgba(10,15,40,0.55), inset 0 1px 0 rgba(255,255,255,0.5);
  backdrop-filter: blur(24px) saturate(160%);
  -webkit-backdrop-filter: blur(24px) saturate(160%);
  overflow: hidden;
  animation: card-in 0.26s cubic-bezier(0.34,1.3,0.55,1) forwards;
}
.kofi-modal-close {
  position: absolute;
  top: 12px; right: 14px;
  z-index: 1;
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.20);
  border-radius: 50%;
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; color: rgba(220,228,255,0.80);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.kofi-modal-close:hover {
  background: rgba(255,255,255,0.22);
  color: #fff;
}
#kofi-iframe {
  width: 100%; height: 100%;
  border: none;
  border-radius: 22px;
}

/* ── Spotlight tour ───────────────────────────────────────────────────────────*/
.tour-scrim {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(6, 10, 22, 0.75);
  pointer-events: none;
  animation: overlay-in 0.25s ease forwards;
}
.tour-scrim[hidden] { display: none; }

.tour-ring {
  position: fixed;
  z-index: 302;
  border-radius: 12px;
  border: 2.5px solid #ff3b30;
  box-shadow: 0 0 0 4px rgba(255,59,48,0.20), 0 0 20px rgba(255,59,48,0.35);
  pointer-events: none;
  transition: top 0.3s cubic-bezier(0.4,0,0.2,1),
              left 0.3s cubic-bezier(0.4,0,0.2,1),
              width 0.3s cubic-bezier(0.4,0,0.2,1),
              height 0.3s cubic-bezier(0.4,0,0.2,1);
  animation: ring-pulse 1.8s ease-in-out infinite;
}
.tour-ring[hidden] { display: none; }
@keyframes ring-pulse {
  0%, 100% { box-shadow: 0 0 0 4px rgba(255,59,48,0.20), 0 0 20px rgba(255,59,48,0.35); }
  50%       { box-shadow: 0 0 0 8px rgba(255,59,48,0.10), 0 0 32px rgba(255,59,48,0.50); }
}

.tour-tip {
  position: fixed;
  z-index: 303;
  width: min(300px, calc(100vw - 32px));
  padding: 16px 18px 14px;
  border-radius: 16px;
  background: linear-gradient(160deg, rgba(22,26,44,0.96) 0%, rgba(14,18,34,0.98) 100%);
  border: 1px solid rgba(255,255,255,0.14);
  box-shadow: 0 12px 40px rgba(0,0,0,0.55), inset 0 1px 0 rgba(255,255,255,0.10);
  display: flex; flex-direction: column; gap: 8px;
  transition: top 0.3s cubic-bezier(0.4,0,0.2,1),
              left 0.3s cubic-bezier(0.4,0,0.2,1);
  animation: card-in 0.22s cubic-bezier(0.34,1.3,0.55,1) forwards;
}
.tour-tip[hidden] { display: none; }

.tour-tip-header {
  display: flex; align-items: center; justify-content: space-between;
}
.tour-step-label {
  font-size: 10px; font-weight: 700; letter-spacing: 0.10em;
  text-transform: uppercase; color: #ff3b30;
}
.tour-skip {
  background: none; border: none; padding: 0;
  font-size: 11px; color: rgba(180,196,240,0.50);
  cursor: pointer; transition: color 0.15s;
}
.tour-skip:hover { color: rgba(200,216,255,0.80); }
.tour-tip-title {
  margin: 0;
  font-size: 14px; font-weight: 700;
  color: rgba(228,236,255,0.95);
  line-height: 1.3;
}
.tour-tip-body {
  margin: 0;
  font-size: 12px; line-height: 1.55;
  color: rgba(170,188,240,0.72);
}
.tour-tip-footer { display: flex; justify-content: flex-end; padding-top: 2px; }
.tour-next {
  padding: 7px 18px;
  border-radius: 999px;
  border: none;
  font-size: 12px; font-weight: 700; letter-spacing: 0.04em;
  color: #fff;
  background: #ff3b30;
  box-shadow: 0 3px 10px rgba(255,59,48,0.40);
  cursor: pointer;
  transition: filter 0.15s, transform 0.12s;
}
.tour-next:hover  { filter: brightness(1.10); transform: translateY(-1px); }
.tour-next:active { filter: brightness(0.95); transform: translateY(0); }

/* ── Stack slide switches (layer list) ───────────────────────────────────────*/
.stack-switch {
  position: relative;
  flex: 0 0 auto;
  width: 34px; height: 19px;
  padding: 0; border-radius: 999px;
  border: 1.5px solid rgba(255,255,255,0.50);
  background: linear-gradient(180deg, rgba(255,255,255,0.4), rgba(255,255,255,0) 50%),
              linear-gradient(180deg, #9aa3b8, #6e7890);
  backdrop-filter: blur(6px) saturate(130%);
  cursor: pointer;
  transition: background 0.35s ease, border-color 0.35s ease, box-shadow 0.35s ease;
}
.stack-switch.on {
  background: linear-gradient(180deg, rgba(255,255,255,0.38), rgba(255,255,255,0) 52%),
              linear-gradient(180deg, #7a94be 0%, #4a6490 100%);
  border-color: rgba(100,130,180,0.65);
  box-shadow: 0 0 6px rgba(80,120,200,0.30);
}
.stack-switch-thumb {
  position: absolute;
  top: 1.5px; left: 1.5px;
  width: 13px; height: 13px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 30%, #ffffff 0%, #f0f3f9 55%, #d0d8e8 100%);
  box-shadow: 0 1px 3px rgba(0,0,0,0.25);
  transition: transform 0.32s cubic-bezier(0.34, 1.56, 0.45, 1);
  pointer-events: none;
}
.stack-switch.on .stack-switch-thumb {
  transform: translateX(15px);
}
