:root {
  /* Dark theme (default) */
  --bg: #000000;
  --surface: #0d0d0d;
  --surface-2: #161616;
  --surface-hover: #1c1c1c;
  --border: rgba(255, 255, 255, 0.10);
  --border-strong: rgba(255, 255, 255, 0.18);
  --text: #f5f5f5;
  --text-dim: #9a9a9a;
  --text-faint: #5a5a5a;
  --accent: #4DE077;
  --accent-rgb: 77, 224, 119;
  --accent-hover: #6FE891;
  --accent-soft: rgba(77, 224, 119, 0.18);
  --accent-border: rgba(77, 224, 119, 0.65);
  --danger: #ff3b3b;
  --dot-grid: rgba(255, 255, 255, 0.045);
  --center-dot: rgba(255, 255, 255, 0.12);
  --swatch-ring: rgba(255, 255, 255, 0.32);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-pill: 999px;
}

/* Light theme — tokens flipped, accent stays mint */
[data-theme="light"] {
  --bg: #f7f7f7;
  --surface: #ffffff;
  --surface-2: #efefef;
  --surface-hover: #e7e7e7;
  --border: rgba(0, 0, 0, 0.10);
  --border-strong: rgba(0, 0, 0, 0.18);
  --text: #0a0a0a;
  --text-dim: #6a6a6a;
  --text-faint: #a0a0a0;
  --accent-soft: rgba(77, 224, 119, 0.22);
  --accent-border: rgba(77, 224, 119, 0.75);
  --dot-grid: rgba(0, 0, 0, 0.08);
  --center-dot: rgba(0, 0, 0, 0.14);
  --swatch-ring: rgba(0, 0, 0, 0.22);
  --thumb-bg: #ffffff;
  --thumb-ring: 0 0 0 2px var(--accent);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 13px;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Dotted canvas background — adapts to theme via --dot-grid */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image: radial-gradient(circle at 1px 1px, var(--dot-grid) 1px, transparent 0);
  background-size: 22px 22px;
  pointer-events: none;
  z-index: 0;
}
.app { position: relative; z-index: 1; }

.app {
  display: grid;
  grid-template-columns: 320px 1fr 340px;
  grid-template-rows: 64px 1fr 56px;
  height: 100vh;
  gap: 0;
  background: var(--bg);
}

/* HEADER */
.header {
  grid-column: 1 / -1;
  background: var(--bg);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  border-bottom: 1px solid var(--border);
}
.logo {
  font-family: "Space Grotesk", "Inter", sans-serif;
  font-weight: 500;
  font-size: 18px;
  letter-spacing: -0.01em;
  color: var(--text);
}
.logo span {
  color: var(--text);
  position: relative;
}
.logo span::after {
  content: "®";
  font-size: 9px;
  vertical-align: super;
  color: var(--text-faint);
  margin-left: 1px;
  font-weight: 400;
}
.header-spacer { flex: 1; }
.header-meta {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-faint);
  font-weight: 500;
}

/* Theme toggle — sun / moon swap based on current theme.
   Hidden for now; flip display back to inline-flex to re-enable the
   light theme picker. All theme tokens + JS handler remain in place. */
.theme-toggle {
  display: none;
  width: 36px;
  height: 36px;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 50%;
  cursor: pointer;
  padding: 0;
  margin-left: 14px;
  transition: all 0.18s ease;
}
.theme-toggle:hover {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border-strong);
}
.theme-toggle .theme-icon { display: none; }
:root .theme-toggle .moon { display: block; } /* dark theme → show moon */
[data-theme="light"] .theme-toggle .sun { display: block; }
[data-theme="light"] .theme-toggle .moon { display: none; }

/* MODE TABS — pill group, full width */
.mode-tabs {
  display: flex;
  background: var(--surface);
  border-radius: var(--radius-pill);
  padding: 4px;
  gap: 2px;
  width: 100%;
}
.mode-tab {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-dim);
  height: 40px;
  padding: 0 16px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 500;
  border-radius: var(--radius-pill);
  transition: all 0.18s ease;
  text-align: center;
}
.mode-tab:hover { color: var(--text); }
.mode-tab.active {
  background: var(--accent);
  color: #0a0a0a;
  box-shadow: 0 4px 14px rgba(var(--accent-rgb), 0.35);
}

/* WEBCAM status pill — camera lifecycle is auto-managed by tab switch */
.webcam-status {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11px;
  color: var(--text-faint);
  text-align: center;
  padding: 10px;
  border-radius: var(--radius-md);
  background: var(--surface);
}
.webcam-status.live {
  color: var(--accent);
  background: rgba(var(--accent-rgb), 0.10);
}

/* CAMERA DEVICE list — populated after permission grant */
.cam-device-list {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.cam-device-list.hidden { display: none; }
.cam-device-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  height: 40px;
  padding: 0 12px;
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  font-weight: 500;
  transition: all 0.15s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cam-device-item:hover { background: var(--surface-2); color: var(--text); }
.cam-device-item.active {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  color: var(--text);
}
.cam-device-item .cam-device-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-faint);
  flex-shrink: 0;
}
.cam-device-item.active .cam-device-dot {
  background: var(--accent);
}

/* LEFT PANEL — SOURCE */
.left {
  background: var(--bg);
  overflow-y: auto;
  padding: 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  border-right: 1px solid var(--border);
  scrollbar-gutter: stable both-edges;
}
.left > div { flex-shrink: 0; }

.section-label {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text);
  margin-bottom: 10px;
  font-weight: 500;
}

.upload-zone {
  border: 1px dashed var(--border-strong);
  padding: 22px 16px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
  background: var(--surface);
  border-radius: var(--radius-md);
}
.upload-zone:hover {
  border-color: var(--text-dim);
  background: var(--surface-2);
}
.upload-zone.drag {
  border-color: var(--accent);
  background: rgba(var(--accent-rgb), 0.08);
}
.upload-zone-title {
  font-size: 13px;
  color: var(--text);
  margin-bottom: 6px;
  font-weight: 500;
}
.upload-zone-hint {
  font-size: 12px;
  color: var(--text-faint);
  line-height: 1.5;
}

.source-preview-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  aspect-ratio: 1 / 1;
  max-height: 280px;
  position: relative;
  overflow: hidden;
  cursor: grab;
}
.source-preview-wrap:active { cursor: grabbing; }
.source-preview-wrap canvas {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
}
.crop-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.55);
  /* Outline + thirds are drawn together by .crop-thirds via a single
     background-image so all 8 lines share the same color/opacity and
     no stray pixel can fall outside via box-sizing / border math. */
}

/* Inner thirds only — no outer frame */
.crop-thirds {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    /* 2 inner vertical lines: 33.33%, 66.66% */
    linear-gradient(to right,
      transparent calc(33.33% - 0.5px),
      rgba(255,255,255,0.3) calc(33.33% - 0.5px),
      rgba(255,255,255,0.3) calc(33.33% + 0.5px),
      transparent calc(33.33% + 0.5px),
      transparent calc(66.66% - 0.5px),
      rgba(255,255,255,0.3) calc(66.66% - 0.5px),
      rgba(255,255,255,0.3) calc(66.66% + 0.5px),
      transparent calc(66.66% + 0.5px)),
    /* 2 inner horizontal lines: 33.33%, 66.66% */
    linear-gradient(to bottom,
      transparent calc(33.33% - 0.5px),
      rgba(255,255,255,0.3) calc(33.33% - 0.5px),
      rgba(255,255,255,0.3) calc(33.33% + 0.5px),
      transparent calc(33.33% + 0.5px),
      transparent calc(66.66% - 0.5px),
      rgba(255,255,255,0.3) calc(66.66% - 0.5px),
      rgba(255,255,255,0.3) calc(66.66% + 0.5px),
      transparent calc(66.66% + 0.5px));
}

/* Corner brackets — dropped (rounded crop frame reads cleaner alone) */
.crop-corner { display: none; }

.pos-controls {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}
.pos-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  height: 40px;
  padding: 0;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 500;
  border-radius: var(--radius-pill);
  transition: all 0.18s ease;
}
.pos-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

/* SLIDER ROW */
.slider-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}
.slider-row label {
  font-family: inherit;
  font-size: 12px;
  letter-spacing: 0;
  text-transform: none;
  color: var(--text-dim);
  min-width: 64px;
  font-weight: 500;
}
.slider-row input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  height: 16px;
  cursor: pointer;
}
.slider-row input[type="range"]::-webkit-slider-runnable-track {
  height: 3px;
  background: linear-gradient(to right,
    var(--accent) 0,
    var(--accent) var(--val, 0%),
    var(--border-strong) var(--val, 0%),
    var(--border-strong) 100%);
  border-radius: 999px;
}
.slider-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  background: var(--thumb-bg, var(--text));
  border-radius: 50%;
  margin-top: -6px;
  cursor: pointer;
  transition: transform 0.15s ease;
  box-shadow: var(--thumb-ring, 0 1px 4px rgba(0,0,0,0.6));
}
.slider-row input[type="range"]:hover::-webkit-slider-thumb {
  transform: scale(1.15);
}
.slider-row input[type="range"]::-moz-range-track {
  height: 3px;
  background: linear-gradient(to right,
    var(--accent) 0,
    var(--accent) var(--val, 0%),
    var(--border-strong) var(--val, 0%),
    var(--border-strong) 100%);
  border-radius: 999px;
}
.slider-row input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px;
  background: var(--thumb-bg, var(--text));
  border-radius: 50%;
  border: none;
  cursor: pointer;
  box-shadow: var(--thumb-ring, none);
}
.slider-row .val {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11px;
  color: var(--text);
  width: 56px;
  height: 34px;
  flex-shrink: 0;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 0 6px;
  border-radius: var(--radius-sm);
  outline: none;
  cursor: text;
  transition: border-color 0.15s ease;
}
.slider-row .val:hover { border-color: var(--border-strong); }
.slider-row .val:focus {
  border-color: var(--accent-border);
  background: var(--surface-2);
}

/* CENTER — OUTPUT */
.center {
  background: var(--bg);
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.output-stage {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}
#outputSvg {
  max-width: 100%;
  max-height: 100%;
  background: var(--output-bg, #000);
  border-radius: var(--radius-sm);
}
.output-meta {
  position: absolute;
  bottom: 16px;
  left: 20px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-faint);
  pointer-events: none;
}
.output-meta div { line-height: 1.8; }
.output-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.output-empty.hidden { display: none !important; }

/* Dotted grid for the idle state — bigger spacing + soft radial fade
   so the pattern feels intentional instead of edge-to-edge wallpaper */
.empty-grid {
  position: absolute;
  inset: 40px;
  pointer-events: none;
  background-image: radial-gradient(circle at 1.5px 1.5px, var(--center-dot, rgba(255, 255, 255, 0.14)) 1.5px, transparent 0);
  background-size: 40px 40px;
  background-position: 0 0;
  mask-image: radial-gradient(ellipse 70% 70% at 50% 50%, #000 50%, transparent 100%);
  -webkit-mask-image: radial-gradient(ellipse 70% 70% at 50% 50%, #000 50%, transparent 100%);
}
.empty-grid-floor,
.empty-grid-fade { display: none; }
.empty-text {
  position: relative;
  z-index: 2;
  color: var(--text-faint);
  font-size: 12px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

/* Fullscreen toggle button */
.fullscreen-btn {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 20;
  width: 36px;
  height: 36px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.18s ease;
  padding: 0;
  border-radius: 50%;
}
.fullscreen-btn:hover {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border-strong);
}
.center:fullscreen,
.center:-webkit-full-screen { background: #000; }
.center:fullscreen .output-stage,
.center:-webkit-full-screen .output-stage { padding: 40px; }
.center:fullscreen .output-meta,
.center:-webkit-full-screen .output-meta {
  bottom: 24px;
  left: 28px;
}

/* RIGHT PANEL — STYLE */
.right {
  background: var(--bg);
  overflow-y: auto;
  padding: 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  border-left: 1px solid var(--border);
  scrollbar-gutter: stable both-edges;
}

/* STYLE GRID — pill chips */
.style-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.style-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  height: 40px;
  padding: 0 16px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 500;
  border-radius: var(--radius-pill);
  transition: all 0.18s ease;
}
.style-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}
.style-btn.active {
  background: var(--accent-soft);
  color: var(--text);
  border-color: var(--accent-border);
}

/* FX preset grid — pill chips */
.fx-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.fx-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  height: 40px;
  padding: 0 16px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 500;
  border-radius: var(--radius-pill);
  transition: all 0.18s ease;
}
.fx-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}
.fx-btn.active {
  background: var(--accent-soft);
  color: var(--text);
  border-color: var(--accent-border);
}

/* Direction selector */
.dir-label {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text);
  margin-top: 16px;
  margin-bottom: 10px;
  font-weight: 500;
}
.dir-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
}
.dir-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  height: 40px;
  padding: 0;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  font-family: inherit;
  border-radius: var(--radius-md);
  transition: all 0.18s ease;
}
.dir-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}
.dir-btn.active {
  background: var(--accent-soft);
  color: var(--text);
  border-color: var(--accent-border);
}

/* INPUTS / SELECT / TEXTAREA — pill style */
select, input[type="text"], input[type="number"], textarea {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  height: 40px;
  padding: 0 14px;
  font-family: inherit;
  font-size: 13px;
  outline: none;
  border-radius: var(--radius-pill);
  transition: all 0.18s ease;
}
textarea {
  height: auto;
  padding: 12px 14px;
}
/* Select: kill native chevron, draw symmetric custom one */
select {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  padding-right: 36px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 10 10' fill='none' stroke='%239a9a9a' stroke-width='1.5'><path d='M2 4l3 3 3-3'/></svg>");
  background-repeat: no-repeat;
  background-position: right 14px center;
}
select::-ms-expand { display: none; }
textarea {
  border-radius: var(--radius-md);
}
/* background-color (not shorthand) so the custom <select> chevron
   background-image isn't cleared on hover / focus */
select:hover, input[type="text"]:hover, input[type="number"]:hover, textarea:hover {
  background-color: var(--surface-2);
}
select:focus, input:focus, textarea:focus {
  border-color: var(--border-strong);
  background-color: var(--surface-2);
}
textarea {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  resize: vertical;
  min-height: 56px;
  padding: 12px 14px;
}

/* Search-style hint with leading + */
input[type="text"]::placeholder,
textarea::placeholder {
  color: var(--text-faint);
}

.swatch-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.swatch {
  width: 24px; height: 24px;
  border: 1px solid var(--border-strong);
  cursor: pointer;
  flex-shrink: 0;
  border-radius: 50%;
  transition: transform 0.15s ease;
}
.swatch:hover { transform: scale(1.1); }
.swatch.active {
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 3px var(--accent);
}

input[type="color"] {
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  border: 1px solid var(--border);
  width: 32px;
  height: 28px;
  padding: 0;
  cursor: pointer;
  border-radius: 50%;
}
input[type="color"]::-webkit-color-swatch-wrapper { padding: 2px; }
input[type="color"]::-webkit-color-swatch { border: none; border-radius: 50%; }

/* TOGGLES */
.toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-top: 1px solid var(--border);
}
.toggle:first-child { border-top: none; }
.toggle label {
  font-size: 13px;
  color: var(--text);
}
.switch {
  width: 36px;
  height: 20px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  position: relative;
  cursor: pointer;
  transition: all 0.2s ease;
  border-radius: var(--radius-pill);
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 14px; height: 14px;
  background: var(--text-dim);
  transition: all 0.2s ease;
  border-radius: 50%;
}
.switch.on {
  background: var(--text);
  border-color: var(--text);
}
.switch.on::after {
  left: 18px;
  background: #000;
}

/* FOOTER */
.footer {
  grid-column: 1 / -1;
  background: var(--bg);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 12px;
  border-top: 1px solid var(--border);
}
.footer-meta {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11px;
  color: var(--text-faint);
}
.footer-spacer { flex: 1; }

/* RATIO — pill segmented */
.ratio-group {
  display: inline-flex;
  background: var(--surface);
  border-radius: var(--radius-pill);
  padding: 4px;
  gap: 2px;
}
.ratio-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  height: 40px;
  padding: 0 14px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 500;
  border-radius: var(--radius-pill);
  transition: all 0.18s ease;
}
.ratio-btn:hover { color: var(--text); }
.ratio-btn.active {
  background: var(--accent-soft);
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--accent-border);
}

/* EXPORT BUTTONS */
.export-group { display: flex; gap: 8px; }
.export-btn {
  background: var(--accent);
  border: none;
  color: #0a0a0a;
  height: 40px;
  padding: 0 20px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
  border-radius: var(--radius-pill);
  transition: all 0.18s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  box-shadow: 0 4px 16px rgba(var(--accent-rgb), 0.25);
}
.export-btn:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(var(--accent-rgb), 0.35);
}
.export-btn.secondary {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  box-shadow: none;
  font-weight: 500;
}
.export-btn.secondary:hover {
  background: var(--surface-2);
  transform: none;
  box-shadow: none;
}
.export-btn .caret {
  vertical-align: middle;
}

/* Download dropdown */
.export-dropdown { position: relative; }
.export-menu {
  position: absolute;
  bottom: calc(100% + 8px);
  right: 0;
  min-width: 220px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  z-index: 200;
  display: flex;
  flex-direction: column;
  padding: 6px;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.8);
}
.export-menu.hidden { display: none; }
.export-menu-item {
  background: transparent;
  border: none;
  color: var(--text);
  padding: 10px 14px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 400;
  text-align: left;
  border-radius: var(--radius-sm);
  transition: background 0.12s ease;
}
.export-menu-item:hover {
  background: var(--surface-2);
}
.export-menu-item.separator {
  border-top: 1px solid var(--border);
  margin-top: 4px;
  padding-top: 12px;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
}

/* SCROLLBARS */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 999px;
  border: 2px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

.hidden { display: none !important; }

/* TOAST */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: #000;
  padding: 12px 24px;
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--radius-pill);
  z-index: 100;
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
}
.toast.show { opacity: 1; }

/* MODAL */
.modal {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal.hidden { display: none; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.modal-panel {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 28px;
  width: 400px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: 0 20px 80px rgba(0, 0, 0, 0.8);
}
.modal-title {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 4px;
  font-weight: 500;
}
.modal-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.modal-row label {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-faint);
  font-weight: 500;
}
.modal-row select { width: 200px; }
.modal-row input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  height: 16px;
  margin: 0;
}
.modal-row input[type="range"]::-webkit-slider-runnable-track {
  height: 3px;
  background: linear-gradient(to right,
    var(--accent) 0,
    var(--accent) var(--val, 0%),
    var(--border-strong) var(--val, 0%),
    var(--border-strong) 100%);
  border-radius: 999px;
}
.modal-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  background: var(--thumb-bg, var(--text));
  border-radius: 50%;
  margin-top: -6px;
  cursor: pointer;
  box-shadow: var(--thumb-ring, none);
}
.modal-row input[type="range"]::-moz-range-track {
  height: 3px;
  background: linear-gradient(to right,
    var(--accent) 0,
    var(--accent) var(--val, 0%),
    var(--border-strong) var(--val, 0%),
    var(--border-strong) 100%);
  border-radius: 999px;
}
.modal-row input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px;
  background: var(--thumb-bg, var(--text));
  border-radius: 50%;
  border: none;
  cursor: pointer;
  box-shadow: var(--thumb-ring, none);
}
.modal-mono {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
  color: var(--text);
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}

.modal-progress {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 4px;
}
.progress-bar {
  height: 4px;
  background: var(--surface-2);
  border-radius: 999px;
  position: relative;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--text);
  width: 0%;
  border-radius: 999px;
  transition: width 0.15s linear;
}
.progress-text {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11px;
  color: var(--text-dim);
  text-align: center;
}

/* COLOR CHIP */
.color-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.color-row-label {
  font-family: inherit;
  font-size: 12px;
  letter-spacing: 0;
  text-transform: none;
  color: var(--text-dim);
  min-width: 28px;
  font-weight: 500;
}
.color-chip {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  height: 40px;
  padding: 0 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  cursor: text;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
  color: var(--text);
  text-align: left;
  border-radius: var(--radius-pill);
  transition: all 0.18s ease;
  min-width: 0;
}
.color-chip:hover { background: var(--surface-2); }
.color-chip:focus-within {
  background: var(--surface-2);
  border-color: var(--border-strong);
}
.color-chip-swatch-wrap {
  width: 22px;
  height: 22px;
  background-image: repeating-conic-gradient(#666 0% 25%, #333 0% 50%);
  background-size: 6px 6px;
  border: none;
  border-radius: 50%;
  flex-shrink: 0;
  overflow: hidden;
  padding: 0;
  cursor: pointer;
  transition: transform 0.15s ease;
  box-shadow: 0 0 0 1.5px var(--swatch-ring, rgba(255, 255, 255, 0.32));
}
.color-chip-swatch-wrap:hover { transform: scale(1.06); }
.color-chip-swatch {
  display: block;
  width: 100%;
  height: 100%;
}
input.color-chip-hex,
input.color-chip-alpha {
  background: transparent;
  border: none;
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  letter-spacing: 0.02em;
  outline: none;
  padding: 0;
  min-width: 0;
  border-radius: 0;
  height: auto;
  line-height: 1.2;
}
input.color-chip-hex {
  flex: 1 1 0;
  min-width: 0;
  width: auto;
  text-transform: uppercase;
}
input.color-chip-alpha {
  color: var(--text-dim);
  font-size: 11px;
  width: 32px;
  flex: 0 0 32px;
  text-align: right;
}
input.color-chip-hex:hover,
input.color-chip-alpha:hover,
input.color-chip-hex:focus,
input.color-chip-alpha:focus {
  background: transparent;
}
.color-chip-pct {
  color: var(--text-dim);
  font-size: 11px;
  flex-shrink: 0;
}

/* PICKER POPOVER */
.picker {
  position: fixed;
  width: 260px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.8);
  padding: 14px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.picker.hidden { display: none; }

.picker-sv {
  position: relative;
  width: 100%;
  height: 170px;
  background:
    linear-gradient(to top, #000, transparent),
    linear-gradient(to right, #fff, hsl(var(--picker-hue, 0), 100%, 50%));
  cursor: crosshair;
  user-select: none;
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.picker-sv-cursor {
  position: absolute;
  width: 12px;
  height: 12px;
  border: 2px solid #fff;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.6);
}

.picker-h {
  position: relative;
  width: 100%;
  height: 12px;
  background: linear-gradient(to right,
    #f00 0%, #ff0 17%, #0f0 33%, #0ff 50%, #00f 67%, #f0f 83%, #f00 100%);
  cursor: ew-resize;
  user-select: none;
  border-radius: 999px;
}
.picker-a {
  position: relative;
  width: 100%;
  height: 12px;
  background-image:
    linear-gradient(to right, transparent, var(--picker-solid, #fff)),
    repeating-conic-gradient(#666 0% 25%, #333 0% 50%);
  background-size: 100% 100%, 6px 6px;
  cursor: ew-resize;
  user-select: none;
  border-radius: 999px;
}
.picker-strip-cursor {
  position: absolute;
  top: -3px;
  left: 0;
  width: 4px;
  height: 18px;
  background: #fff;
  border: 1px solid rgba(0, 0, 0, 0.6);
  border-radius: 999px;
  transform: translateX(-50%);
  pointer-events: none;
}

.picker-inputs {
  display: flex;
  align-items: center;
  gap: 8px;
}
.picker-preview {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  border-radius: 50%;
  background-color: var(--picker-preview, #fff);
  background-image: repeating-conic-gradient(#666 0% 25%, #333 0% 50%);
  background-size: 6px 6px;
  position: relative;
  border: 1px solid var(--border-strong);
}
.picker-preview::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--picker-preview, #fff);
  opacity: var(--picker-preview-alpha, 1);
}
.picker-spacer { flex: 1; }
.picker-hex {
  flex: 1;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
  text-transform: uppercase;
  outline: none;
  border-radius: var(--radius-pill);
}
.picker-hex:focus { border-color: var(--border-strong); }
.picker-alpha-input {
  width: 60px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
  outline: none;
  text-align: right;
  border-radius: var(--radius-pill);
}
.picker-alpha-input:focus { border-color: var(--border-strong); }
.picker-alpha-input::-webkit-inner-spin-button,
.picker-alpha-input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.picker-alpha-suffix {
  color: var(--text-dim);
  font-size: 11px;
}

/* PRESETS MODAL */
.modal-panel-wide { width: 520px; max-width: calc(100vw - 32px); }
.presets-save {
  display: flex;
  gap: 8px;
}
.presets-save input {
  flex: 1;
}
.presets-save .export-btn { flex-shrink: 0; }
.presets-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 220px;
  overflow-y: auto;
  padding-right: 4px;
}
.presets-empty {
  color: var(--text-faint);
  font-size: 12px;
  text-align: center;
  padding: 18px 0;
}
.preset-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.preset-name {
  flex: 1;
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.preset-meta {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 10px;
  color: var(--text-faint);
}
.preset-action {
  background: var(--text);
  border: 1px solid var(--text);
  color: #000;
  height: 40px;
  padding: 0 16px;
  font-size: 12px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  border-radius: var(--radius-pill);
  transition: all 0.15s ease;
}
.preset-action:hover {
  background: #fff;
  border-color: #fff;
}
.preset-action.icon {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  width: 40px;
  height: 40px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.preset-action.icon:hover {
  color: var(--danger);
  border-color: rgba(255, 59, 59, 0.4);
  background: rgba(255, 59, 59, 0.08);
}
.preset-action.icon svg { display: block; }
.presets-section-label {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-faint);
  font-weight: 500;
}
#presetJson {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11px;
  min-height: 110px;
}

/* ============================================================
   RESPONSIVE — tablet & mobile
   ============================================================ */

/* Tablet & mobile — vertical stack */
@media (max-width: 1024px) {
  html, body {
    overflow: auto;
    height: auto;
  }
  .app {
    display: flex;
    flex-direction: column;
    height: auto;
    min-height: 100vh;
  }
  .header {
    height: 56px;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    z-index: 40;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
  }
  .center {
    order: 2;
    height: 60vh;
    min-height: 360px;
    flex-shrink: 0;
    border-bottom: 1px solid var(--border);
  }
  .left {
    order: 3;
    overflow-y: visible;
    border-bottom: 1px solid var(--border);
  }
  .right {
    order: 4;
    overflow-y: visible;
  }
  .footer {
    order: 5;
    height: 64px;
    flex-shrink: 0;
    position: sticky;
    bottom: 0;
    z-index: 40;
    background: var(--bg);
    border-top: 1px solid var(--border);
  }
  /* Source preview no longer needs forced 1:1 since space is generous */
  .source-preview-wrap {
    aspect-ratio: 16 / 9;
    max-height: 280px;
  }
}

/* Mobile — tighter spacing, full-width modals */
@media (max-width: 640px) {
  body { font-size: 14px; }
  .header {
    padding: 0 16px;
    gap: 12px;
  }
  .header-meta { display: none; }
  .left, .right {
    padding: 20px 16px;
    gap: 24px;
  }
  .footer { padding: 0 16px; }
  .center { height: 50vh; min-height: 280px; }
  .output-stage { padding: 20px; }
  .output-meta { bottom: 10px; left: 12px; font-size: 9px; }

  /* Modal goes nearly full-width */
  .modal-panel {
    width: calc(100vw - 24px);
    max-width: 420px;
    padding: 20px;
    border-radius: var(--radius-md);
  }
  .modal-row select { width: 140px; }

  /* Slider labels narrower */
  .slider-row label { min-width: 52px; font-size: 11px; }
  .slider-row { gap: 10px; }

  /* Toast above sticky footer */
  .toast { bottom: 84px; }

  /* Color picker popover sized for mobile */
  .picker { width: calc(100vw - 24px); max-width: 280px; }

  /* Position controls keep 4-col grid but smaller padding */
  .pos-btn { padding: 8px 4px; font-size: 11px; }

  /* Direction grid: 4-col stays */
  .dir-btn { padding: 8px 0; }

  /* Style/FX chips already wrap via flex-wrap */

  /* Logo a touch smaller */
  .logo { font-size: 17px; }

  /* Footer download button compact */
  .export-btn { padding: 9px 16px; font-size: 12px; }
}

/* Very narrow phones */
@media (max-width: 380px) {
  .ratio-group { flex-wrap: wrap; }
  .ratio-btn { padding: 6px 10px; font-size: 11px; }
}
