/* ===== WobbleTone FX — styles ===== */
:root {
  --bg: #0a0a0f;
  --bg-elev: #14141c;
  --bg-elev-2: #1c1c28;
  --border: #2a2a3a;
  --border-soft: #222230;
  --text: #e8e8f0;
  --text-dim: #9090a8;
  --text-faint: #5a5a70;
  --accent: #7c5cff;
  --accent-glow: rgba(124, 92, 255, 0.4);
  --accent-2: #ff5c8a;
  --good: #4ade80;
  --radius: 12px;
  --radius-sm: 8px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body {
  display: flex;
  width: 100%;
  min-width: 0;
  min-height: 100dvh;
  flex-direction: column;
  overflow-x: hidden;
}

/* ===== Header ===== */
.app-header {
  display: flex;
  width: 100%;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  padding: calc(var(--safe-top) + 10px) 16px 10px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 8px; }
.brand-mark { font-size: 22px; color: var(--accent); filter: drop-shadow(0 0 6px var(--accent-glow)); }
.brand h1 { font-size: 17px; font-weight: 700; letter-spacing: -0.02em; }

.info-button {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: rgba(255,255,255,0.03);
  color: var(--text);
  font: 700 15px/1 Georgia, serif;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.15s;
}
.info-button:hover { border-color: var(--accent); background: rgba(124,92,255,0.12); }
.info-button:active { transform: scale(0.94); }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  background: var(--bg-elev-2);
  color: var(--text);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); background: #232333; }
.btn:active { transform: scale(0.96); }
.btn-ghost { background: transparent; }
.btn-small { padding: 6px 10px; font-size: 12px; }
.btn-add {
  width: 100%;
  justify-content: center;
  padding: 12px;
  margin-top: 12px;
  border-style: dashed;
  color: var(--text-dim);
}

/* ===== Main layout ===== */
.app-main {
  flex: 1;
  display: flex;
  width: 100%;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  overflow: hidden;
}

/* ===== Stage ===== */
.stage-section {
  width: 100%;
  min-width: 0;
  flex-shrink: 0;
  padding: 12px 16px 8px;
  border-bottom: 1px solid var(--border);
}

.stage {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background:
    repeating-conic-gradient(#1a1a24 0% 25%, #14141c 0% 50%) 50% / 24px 24px;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
}

.upload-prompt {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s;
}
.upload-prompt:hover { background: rgba(124, 92, 255, 0.08); }
.upload-inner { text-align: center; padding: 24px; }
.upload-icon { font-size: 42px; margin-bottom: 8px; opacity: 0.7; }
.upload-title { font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.upload-sub { font-size: 12px; color: var(--text-faint); }

.preview-wrap {
  position: absolute;
  inset: 0;
  overflow: hidden;
  cursor: zoom-in;
  touch-action: manipulation;
}
.preview-wrap.is-zoomed { cursor: zoom-out; }

.layer-container {
  position: absolute;
  top: 0;
  left: 0;
  display: block;
  line-height: 0;
  transform-origin: 0 0;
  transition: transform 0.22s cubic-bezier(.2,.8,.2,1);
  will-change: transform;
}
.layer-container.no-transition { transition: none; }

.base-image,
.preview-canvas {
  display: block;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
}

.stage-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 2px 8px;
}
.image-status {
  min-width: 0;
  overflow: hidden;
  color: var(--text-faint);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.image-status.is-rendering { color: var(--accent-2); }

.command-dock {
  margin: 0 -16px -8px;
  overflow: hidden;
  border-top: 1px solid var(--border-soft);
  background: linear-gradient(180deg, rgba(28,28,40,0.55), rgba(10,10,15,0.94));
}
.command-track {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 10px 16px calc(10px + var(--safe-bottom));
  scroll-padding-inline: 16px;
  scroll-snap-type: x proximity;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.command-track::-webkit-scrollbar { display: none; }
/* Right-edge fade while more actions sit offscreen — toggled by JS.
   With equal-width items this only triggers below ~330px viewports. */
.command-track.has-more {
  mask-image: linear-gradient(to right, #000 calc(100% - 44px), transparent 100%);
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 44px), transparent 100%);
}
.command-item {
  display: flex;
  flex: 1 1 0;
  min-width: 56px;
  max-width: 120px;
  min-height: 52px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 7px 10px;
  scroll-snap-align: start;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: rgba(28,28,40,0.78);
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 650;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s, color 0.15s, background 0.15s;
}
.command-item:hover { border-color: #484861; color: var(--text); }
.command-item:active { transform: scale(0.95); }
.command-item.is-primary {
  border-color: var(--accent);
  background: linear-gradient(145deg, rgba(124,92,255,0.3), rgba(255,92,138,0.12));
  color: #fff;
  box-shadow: 0 0 0 1px rgba(124,92,255,0.12), 0 8px 22px rgba(0,0,0,0.22);
}
.command-icon { font-size: 17px; font-weight: 400; line-height: 1; }

.toggle-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
}
.toggle-row input { accent-color: var(--accent); width: 16px; height: 16px; }

/* ===== Compare switch (compact) ===== */
.compare-switch {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
  flex-shrink: 0;
}
.compare-switch input { display: none; }
.compare-track {
  position: relative;
  width: 32px;
  height: 18px;
  background: var(--border);
  border-radius: 9px;
  transition: background 0.2s;
}
.compare-thumb {
  position: absolute;
  top: 2px; left: 2px;
  width: 14px; height: 14px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
}
.compare-switch input:checked + .compare-track { background: var(--accent); }
.compare-switch input:checked + .compare-track .compare-thumb { transform: translateX(14px); }
.compare-label {
  font-size: 11px;
  color: var(--text-dim);
  font-weight: 600;
}

/* ===== Preset cards ===== */
.library-actions {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  margin: -2px -4px 14px;
  padding: 2px 4px 8px;
  scrollbar-width: none;
}
.library-actions::-webkit-scrollbar { display: none; }
.preset-list { display: flex; flex-direction: column; gap: 10px; }
.preset-card {
  padding: 13px;
  background: linear-gradient(145deg, rgba(35,35,51,0.96), rgba(24,24,35,0.96));
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.preset-card-head { display: flex; align-items: flex-start; gap: 10px; }
.preset-thumb-btn {
  flex: none;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #101018;
  cursor: pointer;
  line-height: 0;
}
.preset-thumb-btn:hover, .preset-thumb-btn:focus-visible { border-color: var(--accent); }
.preset-thumb {
  display: block;
  width: 56px;
  height: 56px;
  border-radius: 7px;
}
.preset-info { flex: 1; min-width: 0; }
.preset-name { font-size: 14px; font-weight: 700; margin-bottom: 3px; }
.preset-delete {
  flex: none;
  align-self: flex-start;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: none;
  color: var(--text-faint);
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
}
.preset-delete:hover, .preset-delete:focus-visible { color: #ff6b81; border-color: rgba(255,107,129,0.55); }
.preset-effects {
  margin-top: 3px;
  font-size: 11px;
  color: var(--text-faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.preset-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 11px; }
.preset-actions .btn { padding: 5px 8px; font-size: 11px; }
.preset-actions .preset-load { border-color: rgba(124,92,255,0.65); color: #fff; }
.preset-empty {
  padding: 34px 18px;
  text-align: center;
  color: var(--text-faint);
  font-size: 13px;
  line-height: 1.5;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}
.btn-danger { color: var(--accent-2); }
.btn-danger:hover { border-color: var(--accent-2); background: rgba(255, 92, 138, 0.1); }

/* ===== Controls ===== */
.controls-section {
  flex: 1;
  display: flex;
  width: 100%;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  padding-bottom: var(--safe-bottom);
}

.controls-tabs {
  display: flex;
  gap: 4px;
  padding: 8px 16px 0;
  flex-shrink: 0;
}
.tab-btn {
  flex: 1;
  padding: 10px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}
.tab-btn.active { color: var(--text); border-bottom-color: var(--accent); }

.tab-panel {
  display: none;
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px 20px;
  -webkit-overflow-scrolling: touch;
}
.tab-panel.active { display: block; }

/* ===== Effect cards ===== */
.effects-list { display: flex; flex-direction: column; gap: 10px; }

.effect-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.15s;
}
.effect-card.disabled { opacity: 0.5; }
.effect-card.dragging { border-color: var(--accent); opacity: 0.75; position: relative; z-index: 2; }

.effect-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  cursor: pointer;
  user-select: none;
}
.effect-grip {
  color: var(--text-faint);
  cursor: grab;
  font-size: 14px;
  padding: 2px 4px;
  touch-action: none;
  user-select: none;
}
.effect-grip:active { cursor: grabbing; }
.effect-name { flex: 1; min-width: 0; overflow: hidden; font-size: 14px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.effect-badge {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--bg-elev-2);
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.effect-toggle {
  position: relative;
  width: 38px;
  height: 22px;
  background: var(--border);
  border-radius: 11px;
  cursor: pointer;
  transition: background 0.2s;
  flex-shrink: 0;
}
.effect-toggle::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 18px; height: 18px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
}
.effect-toggle.on { background: var(--accent); }
.effect-toggle.on::after { transform: translateX(16px); }

.effect-card-body {
  padding: 4px 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.effect-card-body.hidden { display: none; }

/* ===== Sliders ===== */
.control-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.control-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--text-dim);
}
.control-value {
  font-variant-numeric: tabular-nums;
  color: var(--text);
  font-weight: 600;
  font-size: 12px;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  /* Vertical drags scroll the sheet instead of being captured by the
     slider; horizontal drags still move the thumb. */
  touch-action: pan-y;
}
/* Touch screens: indent the track so the left gutter is a dead zone a
   finger can rest on to scroll past a stack of sliders. */
@media (pointer: coarse) {
  input[type="range"] { width: 80%; margin-left: 20%; }
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px; height: 18px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 0 0 0 var(--accent-glow);
  transition: box-shadow 0.15s;
}
input[type="range"]::-webkit-slider-thumb:hover { box-shadow: 0 0 0 6px var(--accent-glow); }
input[type="range"]::-moz-range-thumb {
  width: 18px; height: 18px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  border: none;
}

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

select {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}

.color-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.color-row input[type="color"] { flex: 1; }
.color-hex {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
  min-width: 70px;
  text-align: right;
}

.effect-remove {
  align-self: flex-start;
  background: transparent;
  border: none;
  color: var(--text-faint);
  font-size: 12px;
  cursor: pointer;
  padding: 4px 0;
}
.effect-remove:hover { color: var(--accent-2); }

.effect-note {
  font-size: 11px;
  color: var(--text-faint);
  line-height: 1.4;
  padding: 6px 8px;
  background: rgba(124, 92, 255, 0.06);
  border-left: 2px solid var(--accent);
  border-radius: 0 4px 4px 0;
}

/* ===== Code panel ===== */
.code-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.code-label { font-size: 13px; color: var(--text); font-weight: 700; }
.code-meta { margin-top: 3px; color: var(--text-faint); font-size: 11px; }
.code-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 5px; }
.code-warning {
  margin-bottom: 10px;
  padding: 9px 10px;
  border: 1px solid rgba(255,184,77,0.28);
  border-radius: var(--radius-sm);
  background: rgba(255,184,77,0.07);
  color: #e8c58f;
  font-size: 11px;
  line-height: 1.45;
}

.code-block {
  background: #0d0d14;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  overflow-x: auto;
  font-family: "SF Mono", "Fira Code", "Cascadia Code", Consolas, monospace;
  font-size: 12px;
  line-height: 1.6;
  white-space: pre;
  color: #c8c8e0;
  max-height: 50dvh;
}
.code-hint {
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-faint);
  line-height: 1.5;
}

/* ===== Modal ===== */
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: flex-end; justify-content: center; padding: 16px; }
.modal[hidden] { display: none; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(3,3,8,0.72);
  backdrop-filter: blur(10px) saturate(0.75);
  -webkit-backdrop-filter: blur(10px) saturate(0.75);
  animation: fadeIn 0.18s ease;
}
.modal-content {
  position: relative;
  width: min(100%, 560px);
  max-height: 80dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  overscroll-behavior: contain;
  background: rgba(20,20,28,0.96);
  border: 1px solid rgba(255,255,255,0.11);
  border-radius: 22px;
  padding: 18px 18px calc(var(--safe-bottom) + 18px);
  box-shadow: 0 26px 80px rgba(0,0,0,0.58), inset 0 1px 0 rgba(255,255,255,0.05);
  animation: modalIn 0.22s cubic-bezier(.2,.8,.2,1);
}
@keyframes fadeIn { from { opacity: 0; } }
@keyframes modalIn { from { opacity: 0; transform: translateY(18px) scale(0.98); } }

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.modal-kicker {
  display: block;
  margin-bottom: 4px;
  color: var(--accent-2);
  font-size: 10px;
  font-weight: 750;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.export-label {
  display: block;
  margin-bottom: 6px;
  color: var(--text-faint);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.export-filename {
  width: 100%;
  box-sizing: border-box;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255,255,255,0.04);
  color: var(--text);
  font: inherit;
}
.export-filename:focus { border-color: var(--accent); outline: none; }
.export-status {
  margin-top: 10px;
  color: var(--accent-2);
  font-size: 12px;
}
.export-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 16px;
}
/* Name-entry modals sit high on touch screens so the open keyboard
   doesn't cover them. */
@media (pointer: coarse) {
  #export-modal, #preset-name-modal {
    align-items: flex-start;
    padding-top: max(28px, calc(var(--safe-top, 0px) + 16px));
  }
}
.modal-header h2 { font-size: 20px; font-weight: 750; letter-spacing: -0.02em; }
.modal-close {
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: rgba(255,255,255,0.04);
  color: var(--text);
  font-size: 17px;
  cursor: pointer;
}
.modal-close:hover { border-color: var(--accent-2); background: rgba(255,92,138,0.1); }
.info-panel { max-width: 520px; }
.info-content { color: var(--text-dim); font-size: 13px; line-height: 1.58; }
.info-content p + h3 { margin-top: 18px; }
.info-content h3 { margin-bottom: 5px; color: var(--text); font-size: 13px; }
.info-content a { color: var(--accent); }
body.modal-open { overflow: hidden; }

.effect-options {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}
.effect-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 16px 10px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s;
  text-align: center;
}
.effect-option:hover { border-color: var(--accent); transform: translateY(-2px); }
.effect-option-icon { font-size: 28px; }
.effect-option-name { font-size: 13px; font-weight: 600; }
.effect-option-desc { font-size: 11px; color: var(--text-faint); line-height: 1.3; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: calc(var(--safe-bottom) + 20px);
  left: 50%;
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: min(320px, calc(100vw - 32px));
  transform: translateX(-50%);
  background: rgba(28,28,40,0.97);
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 10px 12px 10px 16px;
  border-radius: 24px;
  font-size: 13px;
  font-weight: 600;
  z-index: 200;
  box-shadow: 0 10px 34px rgba(0,0,0,0.5);
  animation: toastIn 0.2s ease;
}
.toast-message { flex: 1; }
.toast-action {
  border: 0;
  border-radius: 16px;
  background: rgba(124,92,255,0.2);
  color: #fff;
  padding: 6px 10px;
  font: inherit;
  cursor: pointer;
}
.toast[hidden] { display: none; }
@keyframes toastIn { from { opacity: 0; transform: translateX(-50%) translateY(10px); } }

/* ===== Desktop / wider screens ===== */
@media (min-width: 900px) {
  .app-main { flex-direction: row; }
  .stage-section {
    width: auto;
    flex: 1;
    border-bottom: none;
    border-right: 1px solid var(--border);
    padding: 20px;
    display: flex;
    flex-direction: column;
    justify-content: center;
  }
  .stage { aspect-ratio: auto; flex: 1; min-height: 0; }
  .controls-section { width: 420px; flex-shrink: 0; }
  .command-dock { margin-inline: 0; border: 1px solid var(--border-soft); border-radius: 16px; }
  .command-track { justify-content: center; padding: 10px; }
  .modal { align-items: center; }
  .modal-content { max-width: 600px; }
  .info-panel { max-width: 520px; }
  .btn span { display: inline; }
}

@media (max-width: 520px) {
  .code-header { flex-direction: column; }
  .code-actions { justify-content: flex-start; }
}

@media (max-width: 380px) {
  .brand h1 { font-size: 15px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}
