:root {
  --bg: #090b10;
  --panel: rgba(13, 16, 24, 0.85);
  --panel-solid: #11141f;
  --border: rgba(255, 255, 255, 0.08);
  --border-focus: rgba(59, 130, 246, 0.5);
  --border-hover: rgba(255, 255, 255, 0.16);
  --surface: rgba(255, 255, 255, 0.035);
  --surface-hover: rgba(255, 255, 255, 0.07);
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --accent: #2563eb;
  --accent-light: #3b82f6;
  --accent-glow: rgba(37, 99, 235, 0.25);
  --danger: #ef4444;
  --shadow: 0 20px 48px rgba(0, 0, 0, 0.55), 0 1px 0 rgba(255, 255, 255, 0.08) inset;
  --radius: 12px;
  --radius-sm: 7px;
}

* {
  box-sizing: border-box;
}

/* Scrollbars */
*::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}
*::-webkit-scrollbar-track {
  background: transparent;
}
*::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 999px;
}
*::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.25);
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background:
    radial-gradient(circle at 10% 15%, rgba(37, 99, 235, 0.12), transparent 40%),
    radial-gradient(circle at 90% 85%, rgba(14, 165, 233, 0.08), transparent 35%),
    var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 12px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

/* ==========================================================================
   Icon System (Zero-latency, 100% vector aligned)
   ========================================================================== */
[data-icon] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  line-height: 1;
  vertical-align: middle;
}

.icon {
  width: 14px;
  height: 14px;
  display: block;
  flex-shrink: 0;
  pointer-events: none;
}

input[type="file"] {
  display: none;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
}

/* ==========================================================================
   Canvas & Viewport
   ========================================================================== */
#renderWrap {
  position: absolute;
  inset: 0;
  --transparency-base: #e5e7eb;
}

#renderWrap.show-transparency-grid {
  background-color: var(--transparency-base);
  background-image:
    linear-gradient(45deg, rgba(0, 0, 0, 0.08) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(0, 0, 0, 0.08) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(0, 0, 0, 0.08) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(0, 0, 0, 0.08) 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
}

#renderWrap canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

/* ==========================================================================
   Controls Sidebar Panel
   ========================================================================== */
.controls {
  position: absolute;
  top: 14px;
  right: 14px;
  bottom: 14px;
  width: 324px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 30;
  background: var(--panel);
  backdrop-filter: blur(28px) saturate(160%);
  -webkit-backdrop-filter: blur(28px) saturate(160%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: opacity 0.2s ease, transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

body.controls-collapsed .controls {
  opacity: 0;
  pointer-events: none;
  transform: translateX(20px);
}

/* Header */
.controls-header {
  flex: 0 0 auto;
  padding: 10px 10px 8px;
  border-bottom: 1px solid var(--border);
  display: grid;
  gap: 8px;
  background: rgba(255, 255, 255, 0.015);
}

.brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-icon {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.4);
}
.brand-icon .icon {
  width: 15px;
  height: 15px;
}

.brand-text h1 {
  margin: 0;
  font-size: 13.5px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: #ffffff;
  line-height: 1.1;
}

.brand-tag {
  font-size: 10px;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

.header-tools {
  display: flex;
  align-items: center;
  gap: 2px;
}

/* Toolbar */
.toolbar {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 6px;
  align-items: center;
}

/* Body */
.controls-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px;
  display: grid;
  align-content: start;
  gap: 6px;
}

/* Footer */
.controls-footer {
  flex: 0 0 auto;
  padding: 8px 10px;
  border-top: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.015);
}

.footer-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.status-bar {
  min-height: 14px;
  margin-top: 5px;
  font-size: 10.5px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
}
.status-bar:empty {
  display: none;
}

/* ==========================================================================
   Buttons (Refined, perfectly aligned, coherent hierarchy)
   ========================================================================== */
button,
.btn {
  font-family: inherit;
  cursor: pointer;
  border: 0;
  padding: 0;
  background: none;
  color: inherit;
}

.btn {
  height: 30px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  font-size: 11.5px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  line-height: 1;
  white-space: nowrap;
  user-select: none;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
  border: 1px solid transparent;
}

.btn:active,
.icon-btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--accent);
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.12);
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.35);
}
.btn-primary:hover {
  background: var(--accent-light);
  border-color: rgba(255, 255, 255, 0.25);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover {
  background: var(--surface-hover);
  border-color: var(--border-hover);
}

.btn-sm {
  height: 26px;
  font-size: 11px;
  padding: 0 8px;
}

.icon-btn {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  border: 1px solid transparent;
  transition: all 0.15s ease;
}
.icon-btn:hover {
  color: var(--text);
  background: var(--surface-hover);
  border-color: var(--border);
}

.btn-danger-subtle {
  width: 30px;
  height: 30px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.btn-danger-subtle:hover {
  color: var(--danger);
  background: rgba(239, 68, 68, 0.12);
  border-color: rgba(239, 68, 68, 0.3);
}

/* Focus styles */
button:focus-visible,
.btn:focus-visible,
select:focus-visible,
input[type="range"]:focus-visible {
  outline: 2px solid var(--accent-light);
  outline-offset: 1px;
}

/* Loading animation for random sample */
@keyframes spin-icon {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}
.btn.loading .icon {
  animation: spin-icon 0.8s linear infinite;
}

/* Bypass / Compare Toggle Button & Canvas Badge */
#toggleEffectBtn.active {
  color: #fb923c;
  background: rgba(249, 115, 22, 0.15);
  border-color: rgba(249, 115, 22, 0.45);
  box-shadow: 0 0 10px rgba(249, 115, 22, 0.3);
}

.bypass-badge {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%) translateY(-24px);
  z-index: 25;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 28px;
  padding: 0 12px;
  border-radius: 999px;
  background: rgba(234, 88, 12, 0.92);
  color: #ffffff;
  font-size: 11.5px;
  font-weight: 600;
  border: 1px solid rgba(255, 255, 255, 0.25);
  box-shadow: 0 4px 16px rgba(234, 88, 12, 0.45);
  opacity: 0;
  pointer-events: none;
  cursor: pointer;
  transition: transform 0.22s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.2s ease, background 0.15s ease;
  user-select: none;
}
.bypass-badge .icon {
  width: 14px;
  height: 14px;
}
.bypass-badge.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}
.bypass-badge:hover {
  background: #ea580c;
  transform: translateX(-50%) translateY(1px);
}

/* ==========================================================================
   Presets Card & Ribbon
   ========================================================================== */
.presets-card {
  border-radius: 9px;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 7px 8px 6px;
  display: grid;
  gap: 6px;
}

.presets-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.presets-title {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  line-height: 1;
}
.presets-title .icon {
  width: 13px;
  height: 13px;
  color: var(--accent-light);
}

.select-wrapper {
  position: relative;
  flex: 1;
  max-width: 180px;
}

.select-wrapper select {
  width: 100%;
  height: 26px;
  padding: 0 24px 0 8px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: inherit;
  font-size: 11px;
  font-weight: 500;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  line-height: 24px;
}
.select-wrapper select:hover {
  border-color: var(--border-hover);
}
.select-wrapper select option {
  background: var(--panel-solid);
  color: var(--text);
}

.select-arrow {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}
.select-arrow .icon {
  width: 12px;
  height: 12px;
}

/* Horizontal pill carousel */
.preset-strip {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 2px;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.preset-strip::-webkit-scrollbar {
  display: none;
}

.preset-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 10.5px;
  font-weight: 500;
  white-space: nowrap;
  flex-shrink: 0;
  cursor: pointer;
  transition: all 0.15s ease;
}
.preset-chip:hover {
  color: var(--text);
  background: var(--surface-hover);
  border-color: var(--border-hover);
}
.preset-chip.active {
  color: #ffffff;
  background: rgba(37, 99, 235, 0.22);
  border-color: rgba(59, 130, 246, 0.6);
  box-shadow: 0 0 8px rgba(37, 99, 235, 0.25);
}

.preset-dot {
  width: 6.5px;
  height: 6.5px;
  border-radius: 50%;
  background: var(--dot, #3b82f6);
  box-shadow: 0 0 5px var(--dot, #3b82f6);
  flex-shrink: 0;
}

/* ==========================================================================
   Accordion Groups
   ========================================================================== */
.group {
  border-radius: 9px;
  background: var(--surface);
  border: 1px solid var(--border);
  overflow: hidden;
  transition: border-color 0.15s ease;
}
.group:hover {
  border-color: rgba(255, 255, 255, 0.12);
}

.group-header {
  width: 100%;
  height: 32px;
  padding: 0 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 0;
  background: transparent;
  cursor: pointer;
  text-align: left;
  user-select: none;
}
.group-header:hover {
  background: var(--surface-hover);
}

.group-title {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text);
}

.group-icon {
  color: var(--accent-light);
}
.group-icon .icon {
  width: 13.5px;
  height: 13.5px;
}

.chev {
  color: var(--text-dim);
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  transform-origin: 50% 50%;
}
.chev .icon {
  width: 13px;
  height: 13px;
}
.group.open .chev {
  transform: rotate(90deg);
}

.group-body {
  display: none;
  padding: 2px 10px 8px;
  gap: 6px;
}
.group.open .group-body {
  display: grid;
}

/* ==========================================================================
   Controls & Sliders (Sleek, uncluttered, clean alignment)
   ========================================================================== */
.control {
  min-width: 0;
}

.control-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2px;
  line-height: 1;
}

.label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
}

.value-badge {
  font-size: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.04);
  padding: 1px 4px;
  border-radius: 4px;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.header-inline-tools {
  display: flex;
  align-items: center;
  gap: 4px;
}

.inline-reset-btn {
  width: 16px;
  height: 16px;
  border-radius: 3px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  opacity: 0.6;
  transition: all 0.15s ease;
}
.inline-reset-btn .icon {
  width: 10px;
  height: 10px;
}
.inline-reset-btn:hover {
  opacity: 1;
  color: var(--text);
  background: var(--surface-hover);
}

/* 2-Column Pair Row */
.pair-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.action-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 2px;
}

/* Range input styling */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 14px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  transition: background 0.15s ease;
}
input[type="range"]::-moz-range-track {
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  margin-top: -4px;
  border-radius: 50%;
  background: #ffffff;
  border: 1px solid rgba(0, 0, 0, 0.2);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
input[type="range"]::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #ffffff;
  border: 1px solid rgba(0, 0, 0, 0.2);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

input[type="range"]:hover::-webkit-slider-thumb {
  transform: scale(1.15);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.35), 0 2px 6px rgba(0, 0, 0, 0.4);
}

/* ==========================================================================
   Toggles & Swatches
   ========================================================================== */
.toggle-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.toggle-tile {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  height: 27px;
  padding: 0 8px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  transition: all 0.15s ease;
}
.toggle-tile.full {
  width: 100%;
}
.toggle-tile.flex-1 {
  flex: 1;
}

.toggle-tile input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.toggle-tile .toggle-icon .icon {
  width: 12.5px;
  height: 12.5px;
  color: var(--text-dim);
  transition: color 0.15s ease;
}

.toggle-tile:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.toggle-tile:has(input:checked) {
  color: #ffffff;
  background: rgba(37, 99, 235, 0.16);
  border-color: rgba(59, 130, 246, 0.45);
}
.toggle-tile:has(input:checked) .toggle-icon .icon {
  color: var(--accent-light);
}

.toggle-tile:has(input:focus-visible) {
  outline: 2px solid var(--accent-light);
  outline-offset: 1px;
}

.toggle-line {
  display: flex;
}

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

.color-well {
  position: relative;
  width: 32px;
  height: 27px;
  flex-shrink: 0;
  border-radius: 6px;
  border: 1px solid var(--border);
  overflow: hidden;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.04);
  transition: border-color 0.15s ease;
}
.color-well:hover {
  border-color: var(--border-hover);
}

.color-preview {
  position: absolute;
  inset: 3px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  pointer-events: none;
}

.color-well input[type="color"] {
  position: absolute;
  inset: -8px;
  width: calc(100% + 16px);
  height: calc(100% + 16px);
  opacity: 0;
  cursor: pointer;
}

/* ==========================================================================
   Floating Panel Show Button
   ========================================================================== */
.panel-show-btn {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 40;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--panel);
  border: 1px solid var(--border);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  color: var(--text);
  box-shadow: var(--shadow);
  display: grid;
  place-items: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, background 0.15s ease;
}
.panel-show-btn .icon {
  width: 16px;
  height: 16px;
}
.panel-show-btn:hover {
  background: var(--panel-solid);
}
body.controls-collapsed .panel-show-btn {
  opacity: 1;
  pointer-events: auto;
}

/* ==========================================================================
   Drag & Drop Overlay
   ========================================================================== */
.drop-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(5, 7, 12, 0.6);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
  z-index: 50;
}
body.dragging .drop-overlay {
  opacity: 1;
  pointer-events: auto;
}

.drop-card {
  width: min(400px, calc(100vw - 32px));
  padding: 24px 20px;
  text-align: center;
  border-radius: 16px;
  background: rgba(13, 16, 24, 0.92);
  border: 1.5px dashed rgba(59, 130, 246, 0.6);
  box-shadow: var(--shadow);
}
.drop-icon {
  margin-bottom: 8px;
  color: var(--accent-light);
}
.drop-icon .icon {
  width: 32px;
  height: 32px;
  margin: 0 auto;
}
.drop-card h3 {
  margin: 0 0 4px;
  font-size: 16px;
  font-weight: 600;
  color: #ffffff;
}
.drop-card p {
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
}

/* ==========================================================================
   Help Modal
   ========================================================================== */
.help-modal {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(5, 7, 12, 0.65);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 60;
  padding: 16px;
}
.help-modal.open {
  display: flex;
}

.help-card {
  width: min(440px, calc(100vw - 32px));
  border-radius: 14px;
  background: rgba(13, 16, 24, 0.96);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 16px 18px 14px;
}

.help-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.help-card-title {
  display: flex;
  align-items: center;
  gap: 7px;
  color: #ffffff;
}
.help-card-title .icon {
  width: 16px;
  height: 16px;
  color: var(--accent-light);
}
.help-card-title h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.help-card-content p {
  margin: 0 0 8px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-muted);
}
.help-card-content strong {
  color: var(--text);
}
.help-card-content em {
  color: var(--accent-light);
  font-style: normal;
}

.help-card-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 14px;
}

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 860px) {
  .controls {
    left: 10px;
    right: 10px;
    bottom: 10px;
    top: auto;
    width: auto;
    height: min(60vh, 580px);
  }
  body.controls-collapsed .controls {
    transform: translateY(20px);
  }
}
