/* CSS Reset & Variables */
:root {
  --bg-dark: #07090e;
  --bg-card: rgba(18, 24, 38, 0.75);
  --bg-card-hover: rgba(26, 35, 56, 0.85);
  --border-color: rgba(255, 255, 255, 0.08);
  --border-highlight: rgba(139, 92, 246, 0.3);
  
  --accent-primary: #8b5cf6;
  --accent-secondary: #06b6d4;
  --accent-gradient: linear-gradient(135deg, #8b5cf6 0%, #06b6d4 100%);
  --accent-gradient-hover: linear-gradient(135deg, #a78bfa 0%, #22d3ee 100%);
  
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  
  --radius-lg: 16px;
  --radius-md: 10px;
  --radius-sm: 6px;
  
  --shadow-main: 0 20px 40px -15px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 25px rgba(139, 92, 246, 0.35);
  
  --font-family: 'Noto Sans Arabic', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

[dir="ltr"] {
  --font-family: 'Inter', 'Noto Sans Arabic', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-dark);
  color: var(--text-main);
  min-height: 100vh;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
}

/* App Container */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-height: 100vh;
  overflow: hidden;
  position: relative;
}

/* Header Navbar */
.app-header {
  height: 70px;
  background: rgba(11, 15, 25, 0.9);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-color);
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 100;
  flex-shrink: 0;
}

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

.brand-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  background: var(--accent-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  color: #fff;
  box-shadow: var(--shadow-glow);
}

.spin-slow {
  animation: spin 12s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.brand-text h1 {
  font-size: 1.25rem;
  font-weight: 800;
  line-height: 1.2;
}

.brand-text p {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Header Canvas Size Dropdown */
.size-select-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.select-icon {
  position: absolute;
  inset-inline-start: 12px;
  color: var(--accent-secondary);
  pointer-events: none;
  font-size: 0.85rem;
}

.custom-select {
  font-family: inherit;
  font-size: 0.84rem;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 9px 14px 9px 34px;
  border-radius: var(--radius-md);
  cursor: pointer;
  outline: none;
  transition: all 0.25s ease;
  appearance: none;
  -webkit-appearance: none;
}

[dir="rtl"] .custom-select {
  padding: 9px 34px 9px 14px;
}

.custom-select:hover {
  background: rgba(255, 255, 255, 0.16);
  border-color: rgba(255, 255, 255, 0.25);
}

.custom-select option {
  background: #0f172a;
  color: #fff;
  padding: 8px;
}

/* Mobile Quick Header Actions (Hidden on Desktop) */
.mobile-header-actions {
  display: none;
}

.mobile-settings-menu {
  display: none;
}

.btn-header-icon {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-header-icon:hover {
  background: rgba(255, 255, 255, 0.16);
  transform: translateY(-1px);
}

.btn-header-primary {
  background: var(--accent-gradient);
  border: none;
  color: #fff;
  box-shadow: 0 2px 10px rgba(139, 92, 246, 0.4);
}

/* Buttons */
.btn {
  font-family: inherit;
  font-weight: 700;
  font-size: 0.88rem;
  padding: 9px 18px;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: all 0.25s ease;
}

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

.btn-primary:hover {
  background: var(--accent-gradient-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-glow);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-color);
  color: var(--text-main);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.16);
  border-color: rgba(255, 255, 255, 0.25);
}

.glow-btn {
  box-shadow: 0 4px 15px rgba(139, 92, 246, 0.4);
}

.glow-btn-subtle {
  box-shadow: 0 2px 10px rgba(6, 182, 212, 0.2);
}

.btn-full-width {
  width: 100%;
  justify-content: center;
  font-size: 0.84rem;
  padding: 10px 12px;
}

/* Powered by uaenawaf.com Credits Styling */
.mobile-credits-item, .sidebar-credits-wrapper {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--border-color);
  text-align: center;
}

.powered-by-text {
  font-size: 0.82rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex-wrap: wrap;
}

.credits-link {
  color: var(--accent-secondary);
  font-weight: 700;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: var(--radius-sm);
  background: rgba(6, 182, 212, 0.12);
  border: 1px solid rgba(6, 182, 212, 0.3);
  transition: all 0.2s ease;
  direction: ltr !important;
}

.credits-link:hover {
  background: rgba(6, 182, 212, 0.25);
  color: #fff;
  border-color: var(--accent-secondary);
  transform: translateY(-1px);
  box-shadow: 0 0 12px rgba(6, 182, 212, 0.4);
}

.credits-link i {
  color: #f59e0b;
  font-size: 0.82rem;
}

/* Source Image Resizing Controls */
.source-resizing-wrapper {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px dashed var(--border-color);
}

.margin-top-sm {
  margin-top: 10px;
}

.margin-top-xs {
  margin-top: 6px;
}

.source-presets-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-top: 8px;
  direction: ltr !important;
}

.preset-btn {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  padding: 6px 4px;
  font-family: inherit;
  font-weight: 600;
  font-size: 0.72rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.preset-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: var(--text-main);
}

/* Pro Pattern Card Panel Highlight */
.card-panel.highlight-panel {
  border: 1px solid rgba(6, 182, 212, 0.4);
  background: linear-gradient(180deg, rgba(6, 182, 212, 0.08) 0%, rgba(18, 24, 38, 0.85) 100%);
  box-shadow: 0 4px 20px rgba(6, 182, 212, 0.1);
}

.pattern-type-picker {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-top: 6px;
  direction: ltr !important;
}

.pattern-type-btn {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  padding: 8px 4px;
  font-family: inherit;
  font-weight: 700;
  font-size: 0.76rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: all 0.2s ease;
}

.pattern-type-btn i {
  font-size: 1rem;
}

.pattern-type-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: var(--text-main);
}

.pattern-type-btn.active {
  background: linear-gradient(135deg, #06b6d4 0%, #3b82f6 100%);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 2px 10px rgba(6, 182, 212, 0.4);
}

/* Google Material Symbols Play/Pause Action Button */
.btn-play-pause {
  width: 100%;
  padding: 10px 16px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  border-radius: var(--radius-md);
  font-family: inherit;
  font-weight: 700;
  font-size: 0.88rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.25s ease;
  margin-top: 6px;
}

.btn-play-pause:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.25);
  transform: translateY(-1px);
}

.btn-play-pause.playing {
  background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 4px 15px rgba(239, 68, 68, 0.4);
}

.btn-play-pause.playing:hover {
  background: linear-gradient(135deg, #f87171 0%, #ef4444 100%);
}

.material-symbols-outlined {
  font-size: 1.35rem !important;
  vertical-align: middle;
  line-height: 1;
}

/* Main Workspace Split Layout */
.workspace {
  display: grid;
  grid-template-columns: 380px 1fr;
  flex: 1;
  overflow: hidden;
  height: calc(100vh - 70px);
}

[dir="rtl"] .sidebar {
  border-left: 1px solid var(--border-color);
  border-right: none;
}

[dir="ltr"] .sidebar {
  border-right: 1px solid var(--border-color);
  border-left: none;
}

/* Mobile Drawer Header Handle (Hidden on Desktop) */
.mobile-drawer-header {
  display: none;
}

/* Sidebar Panel */
.sidebar {
  background: rgba(15, 21, 35, 0.75);
  backdrop-filter: blur(12px);
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.sidebar::-webkit-scrollbar {
  width: 6px;
}
.sidebar::-webkit-scrollbar-track {
  background: transparent;
}
.sidebar::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 4px;
}
.sidebar::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* Card Panels */
.card-panel {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  transition: border-color 0.25s ease;
}

.card-panel:hover {
  border-color: rgba(255, 255, 255, 0.15);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.panel-header h3 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-header h3 i {
  color: var(--accent-secondary);
}

.value-badge {
  background: rgba(139, 92, 246, 0.2);
  color: #a78bfa;
  border: 1px solid rgba(139, 92, 246, 0.3);
  font-size: 0.8rem;
  font-weight: 700;
  padding: 2px 10px;
  border-radius: 20px;
}

/* Upload Zone */
.upload-zone {
  border: 2px dashed rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-md);
  padding: 20px 14px;
  text-align: center;
  cursor: pointer;
  transition: all 0.25s ease;
  background: rgba(0, 0, 0, 0.2);
}

.upload-zone:hover, .upload-zone.dragover {
  border-color: var(--accent-primary);
  background: rgba(139, 92, 246, 0.08);
}

.upload-icon {
  font-size: 2rem;
  color: var(--accent-primary);
  margin-bottom: 8px;
}

.upload-content p {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.upload-content p span.highlight {
  color: var(--accent-secondary);
  font-weight: 600;
  text-decoration: underline;
}

.upload-content small {
  display: block;
  margin-top: 4px;
  font-size: 0.72rem;
  color: var(--text-dim);
}

/* Sample Thumbnails */
.samples-wrapper {
  margin-top: 14px;
}

.sub-label {
  font-size: 0.78rem;
  color: var(--text-dim);
  display: block;
  margin-bottom: 8px;
}

.sample-thumbs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  direction: ltr !important;
}

.sample-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 8px;
  font-size: 1.3rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.sample-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  transform: scale(1.05);
}

.sample-btn.active {
  border-color: var(--accent-primary);
  background: rgba(139, 92, 246, 0.25);
  box-shadow: 0 0 10px rgba(139, 92, 246, 0.4);
}

/* Mirrors Selector Picker - Left to Right Numbers Order (Up to 32) */
.mirror-picker {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(42px, 1fr));
  gap: 6px;
  margin-bottom: 12px;
  direction: ltr !important;
}

.mirror-btn {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  padding: 7px 0;
  font-family: inherit;
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.mirror-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-main);
}

.mirror-btn.active {
  background: var(--accent-gradient);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 2px 8px rgba(139, 92, 246, 0.4);
}

/* Control Groups & Sliders */
.control-group {
  margin-bottom: 14px;
}

.control-group:last-child {
  margin-bottom: 0;
}

.label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
  font-size: 0.84rem;
  color: var(--text-muted);
}

.val-txt {
  font-weight: 700;
  color: var(--accent-secondary);
  font-size: 0.82rem;
  direction: ltr !important;
}

/* Sliders always grow to RIGHT and shrink to LEFT in all languages */
.custom-slider {
  -webkit-appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.1);
  outline: none;
  transition: background 0.2s ease;
  direction: ltr !important;
}

.custom-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent-gradient);
  cursor: pointer;
  box-shadow: 0 0 10px rgba(139, 92, 246, 0.5);
  transition: transform 0.15s ease;
}

.custom-slider::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

/* Interactive Circular Rotation Dial Knob Widget */
.dials-compact-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.dial-wrapper {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 6px;
  background: rgba(0, 0, 0, 0.25);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  direction: ltr !important;
  touch-action: none !important;
}

.dial-wheel {
  position: relative;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(30, 41, 59, 0.9) 0%, rgba(15, 23, 42, 0.9) 100%);
  border: 2px solid var(--border-highlight);
  box-shadow: 0 0 15px rgba(139, 92, 246, 0.2), inset 0 0 10px rgba(0, 0, 0, 0.5);
  cursor: grab;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  touch-action: none !important;
}

.dial-wheel:active {
  cursor: grabbing;
  border-color: var(--accent-secondary);
  box-shadow: 0 0 20px rgba(6, 182, 212, 0.5);
}

.dial-ring {
  position: absolute;
  inset: 4px;
  border-radius: 50%;
  border: 1px dashed rgba(255, 255, 255, 0.2);
  pointer-events: none;
}

.dial-pointer {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 28px;
  height: 4px;
  margin-top: -2px;
  transform-origin: left center;
  pointer-events: none;
  transition: transform 0.05s linear;
}

.dial-pointer::after {
  content: '';
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-secondary);
  box-shadow: 0 0 8px var(--accent-secondary);
}

.dial-center-badge {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-main);
  z-index: 2;
  pointer-events: none;
  background: rgba(15, 23, 42, 0.8);
  padding: 1px 4px;
  border-radius: 4px;
}

.dial-slider-container {
  flex: 1;
}

/* Toggle Switches */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.toggle-row label {
  font-size: 0.84rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
  direction: ltr !important;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider-toggle {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: rgba(255, 255, 255, 0.15);
  transition: .3s ease;
  border-radius: 24px;
}

.slider-toggle:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: .3s ease;
  border-radius: 50%;
}

input:checked + .slider-toggle {
  background: var(--accent-gradient);
}

input:checked + .slider-toggle:before {
  transform: translateX(20px);
}

/* Icon Buttons */
.btn-icon {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.btn-icon:hover {
  background: rgba(255, 255, 255, 0.15);
  color: var(--text-main);
}

.btn-icon-lg {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  transition: all 0.2s ease;
}

.btn-icon-lg:hover {
  background: rgba(239, 68, 68, 0.2);
  border-color: rgba(239, 68, 68, 0.4);
  color: #fca5a5;
}

.hint-text {
  font-size: 0.74rem;
  color: var(--text-dim);
  margin-top: 10px;
  line-height: 1.4;
}

/* Background Mode Picker */
.bg-mode-picker {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 8px;
  direction: ltr !important;
}

.bg-btn {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.bg-btn span {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.bg-btn.active {
  border-color: var(--accent-primary);
  background: rgba(139, 92, 246, 0.15);
}

.bg-demo {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.transparent-grid {
  background-image: repeating-conic-gradient(#334155 0% 25%, #0f172a 0% 50%);
  background-size: 10px 10px;
}

.dark-fill { background: #0b0f19; }
.light-fill { background: #f8fafc; }
.color-fill { background: #0f172a; }

.color-picker-group input[type="color"] {
  -webkit-appearance: none;
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  cursor: pointer;
  background: none;
}

/* Main Preview Stage Area */
.canvas-stage-wrapper {
  background: #090d16;
  display: flex;
  flex-direction: column;
  height: 100%;
  position: relative;
  overflow: hidden;
}

.stage-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.stage-tag {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.fps-badge {
  background: rgba(6, 182, 212, 0.15);
  color: var(--accent-secondary);
  border: 1px solid rgba(6, 182, 212, 0.3);
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 12px;
  font-weight: 600;
  direction: ltr !important;
}

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

.btn-stage {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-stage:hover {
  background: rgba(255, 255, 255, 0.12);
  color: var(--text-main);
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.2);
  border-color: rgba(239, 68, 68, 0.4);
  color: #fca5a5;
}

/* Canvas Viewport */
.canvas-viewport {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  position: relative;
  overflow: hidden;
  user-select: none;
}

.canvas-holder {
  position: relative;
  max-width: 92%;
  max-height: 92%;
  aspect-ratio: 1 / 1;
  border-radius: 16px;
  box-shadow: 0 25px 60px -15px rgba(0, 0, 0, 0.8), 0 0 30px rgba(139, 92, 246, 0.15);
  border: 1px solid var(--border-color);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none !important; /* CRITICAL FOR MOBILE CANVAS DRAGGING */
}

/* Transparent Checkerboard Pattern */
.transparent-checker {
  background-image: 
    linear-gradient(45deg, #182234 25%, transparent 25%), 
    linear-gradient(-45deg, #182234 25%, transparent 25%), 
    linear-gradient(45deg, transparent 75%, #182234 75%), 
    linear-gradient(-45deg, transparent 75%, #182234 75%);
  background-size: 24px 24px;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0px;
  background-color: #0d131f;
}

/* Canvas element styling */
#main-canvas {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

/* Canvas Overlay & Interactive Crosshair */
.canvas-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  cursor: grab;
  z-index: 10;
  touch-action: none !important; /* CRITICAL: Prevent touch page scroll on drag */
}

.canvas-overlay:active {
  cursor: grabbing;
}

.center-crosshair {
  position: absolute;
  width: 24px;
  height: 24px;
  border: 2px solid var(--accent-secondary);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  box-shadow: 0 0 12px var(--accent-secondary);
  opacity: 0.6;
  transition: opacity 0.2s ease;
}

.canvas-holder:hover .center-crosshair {
  opacity: 1;
}

.center-crosshair::after {
  content: '';
  position: absolute;
  top: 50%; left: 50%;
  width: 6px; height: 6px;
  background: var(--accent-secondary);
  border-radius: 50%;
  transform: translate(-50%, -50%);
}

.stage-footer {
  height: 38px;
  background: rgba(15, 21, 35, 0.7);
  border-top: 1px solid var(--border-color);
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.stage-footer p {
  font-size: 0.78rem;
  color: var(--text-dim);
}

/* Fullscreen Pattern Test Preview Modal */
.pattern-modal {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 15, 0.92);
  backdrop-filter: blur(16px);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 30px;
  transition: all 0.3s ease;
}

.pattern-modal.hidden {
  opacity: 0;
  pointer-events: none;
}

.pattern-modal-content {
  width: 90vw;
  height: 85vh;
  background: var(--bg-dark);
  border: 1px solid var(--border-highlight);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.8), 0 0 40px rgba(6, 182, 212, 0.3);
}

.pattern-modal-header {
  height: 60px;
  padding: 0 24px;
  background: rgba(15, 23, 42, 0.9);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.pattern-modal-header h3 {
  font-size: 1.05rem;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 10px;
}

.pattern-modal-header h3 i {
  color: var(--accent-secondary);
}

.pattern-modal-body {
  flex: 1;
  width: 100%;
  height: 100%;
  background-repeat: repeat;
  background-position: center;
  background-size: auto;
  box-shadow: inset 0 0 100px rgba(0, 0, 0, 0.8);
}

/* Toast Notifications */
.toast {
  position: fixed;
  bottom: 24px;
  inset-inline-start: 24px;
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid var(--accent-secondary);
  color: #fff;
  padding: 12px 24px;
  border-radius: var(--radius-md);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5), 0 0 15px rgba(6, 182, 212, 0.4);
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.88rem;
  font-weight: 600;
  z-index: 3000;
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.toast.hidden {
  opacity: 0;
  transform: translateY(30px) scale(0.9);
  pointer-events: none;
}

.toast i {
  color: var(--accent-secondary);
  font-size: 1.1rem;
}

/* Mobile & Tablet Bottom Dock Bar (Hidden on Desktop) */
.mobile-bottom-dock {
  display: none;
}

/* ==========================================================================
   MOBILE & TABLET RESPONSIVE ENGINE
   ========================================================================== */
@media (max-width: 1024px) {
  .app-container {
    height: 100vh;
    overflow: hidden;
  }

  .app-header {
    height: 60px;
    padding: 0 14px;
  }

  .brand-icon {
    width: 36px;
    height: 36px;
    font-size: 1.1rem;
  }

  .brand-text h1 {
    font-size: 0.95rem;
  }

  .brand-text p {
    display: none;
  }

  .desktop-only-btn {
    display: none !important;
  }

  .mobile-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
  }

  /* Top Slide-Down Settings Menu */
  .mobile-settings-menu {
    display: block;
    position: absolute;
    top: 60px;
    left: 0;
    right: 0;
    background: rgba(11, 15, 25, 0.97);
    backdrop-filter: blur(24px);
    border-bottom: 1px solid var(--border-highlight);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.85);
    z-index: 600;
    padding: 16px;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.25s ease;
    transform: translateY(0);
    opacity: 1;
  }

  .mobile-settings-menu.hidden {
    transform: translateY(-120%);
    pointer-events: none;
    opacity: 0;
  }

  .mobile-menu-content {
    display: flex;
    flex-direction: column;
    gap: 12px;
  }

  .mobile-menu-item label {
    font-size: 0.82rem;
    color: var(--text-muted);
    font-weight: 700;
    display: block;
    margin-bottom: 6px;
  }

  .full-width-select {
    width: 100%;
  }

  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
    height: calc(100vh - 60px - 64px);
    position: relative;
  }

  /* Canvas Stage on Mobile/Tablet */
  .canvas-stage-wrapper {
    height: 100%;
    width: 100%;
  }

  .canvas-viewport {
    padding: 10px;
  }

  .canvas-holder {
    max-width: 96%;
    max-height: 96%;
  }

  .stage-footer {
    display: none;
  }

  /* Mobile Bottom Navigation Dock Bar */
  .mobile-bottom-dock {
    display: flex;
    align-items: center;
    justify-content: space-around;
    height: 64px;
    background: rgba(11, 15, 25, 0.95);
    backdrop-filter: blur(20px);
    border-top: 1px solid var(--border-color);
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 500;
    direction: ltr !important;
  }

  .dock-tab {
    background: transparent;
    border: none;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    font-family: inherit;
    font-size: 0.7rem;
    font-weight: 700;
    cursor: pointer;
    flex: 1;
    padding: 8px 0;
    transition: all 0.2s ease;
  }

  .dock-tab i {
    font-size: 1.25rem;
  }

  .dock-tab.active {
    color: var(--accent-secondary);
    transform: translateY(-2px);
  }

  .dock-tab.active i {
    color: var(--accent-primary);
    filter: drop-shadow(0 0 8px rgba(139, 92, 246, 0.6));
  }

  /* Mobile Floating Drawer Panel for Sidebar Controls */
  .sidebar {
    position: absolute;
    bottom: 64px;
    left: 0;
    right: 0;
    max-height: 62vh;
    background: rgba(11, 15, 25, 0.96);
    backdrop-filter: blur(24px);
    border-top: 1px solid var(--border-highlight);
    border-radius: 20px 20px 0 0;
    padding: 14px;
    z-index: 400;
    box-shadow: 0 -15px 40px rgba(0, 0, 0, 0.7);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    transform: translateY(0);
    display: flex;
    flex-direction: column;
    gap: 10px;
  }

  .sidebar.collapsed {
    transform: translateY(120%);
  }

  .mobile-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border-color);
  }

  .drawer-handle-bar {
    width: 44px;
    height: 5px;
    background: rgba(255, 255, 255, 0.25);
    border-radius: 3px;
    margin: 0 auto;
  }

  /* Mobile Active Section Filter */
  .mobile-panel-section {
    display: none;
  }

  .mobile-panel-section.active-mobile-tab {
    display: block;
  }

  /* 60% COMPACT HEIGHT FOR ROTATION SECTION ON MOBILE & TABLET */
  #panel-tab-direction {
    padding: 10px 12px;
  }

  .dials-compact-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 6px;
  }

  .dial-compact-item {
    margin-bottom: 0;
  }

  .dial-compact-item .label-row {
    margin-bottom: 2px;
    font-size: 0.75rem;
  }

  .dial-wrapper {
    padding: 4px 6px;
    gap: 6px;
    margin-top: 2px;
  }

  .dial-wheel {
    width: 42px;
    height: 42px;
  }

  .dial-center-badge {
    font-size: 0.65rem;
    padding: 0 2px;
  }

  .dial-pointer {
    width: 18px;
  }

  .control-group.margin-top-xs {
    margin-top: 6px;
    margin-bottom: 8px;
  }

  .btn-play-pause {
    padding: 8px 12px;
    font-size: 0.8rem;
    margin-top: 4px;
  }
}

@media (max-width: 600px) {
  .header-actions {
    gap: 6px;
  }

  .custom-select {
    padding: 6px 8px 6px 20px;
    font-size: 0.74rem;
  }

  [dir="rtl"] .custom-select {
    padding: 6px 20px 6px 8px;
  }

  .btn {
    padding: 7px 10px;
    font-size: 0.76rem;
  }

  .stage-tag {
    font-size: 0.72rem;
  }
}
