/**
 * CSS Design System for Geometric Wallpaper Generator
 * Features Outfit/Inter fonts, high-end dark mode, glassmorphic floating panels,
 * customized input ranges, neon highlights, and beautiful micro-animations.
 */

@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&family=Inter:wght@300;400;500;600&display=swap');

/* --- INTERFACE THEME SYSTEM ---
   :root holds the default "Midnight Gold" theme. Every other preset overrides the same
   variable set via [data-theme="..."] on <html> (set by app.js / persisted to
   localStorage). Only chrome tokens are themed here — the canvas/artwork background
   (#030303 etc.) intentionally stays fixed regardless of UI theme, since it's the
   generated wallpaper's own stage, not app chrome. */
:root {
  --bg-dark: #070709;
  --bg-panel: rgba(13, 13, 17, 0.7);
  --bg-panel-solid: #0d0d11;
  --bg-active: rgba(255, 255, 255, 0.1);
  --border-glass: rgba(255, 255, 255, 0.08);
  --border-active: rgba(255, 255, 255, 0.2);
  --text-primary: #f3f3f5;
  --text-secondary: #a1a1aa;
  --accent: #c5a059; /* Luxury warm gold highlight */
  --accent-glow: rgba(197, 160, 89, 0.4);
  --glow-teal: #66fcf1;
  --glow-pink: #f72585;

  /* Recessed/"sunken" card surfaces (pattern cards, palette items, tab nav, etc.) */
  --surface-sunken: rgba(0, 0, 0, 0.2);
  --surface-sunken-strong: rgba(0, 0, 0, 0.3);
  /* Hover/interactive surface tint — lightens on dark themes, darkens on light ones */
  --surface-hover: rgba(255, 255, 255, 0.06);
  --surface-hover-strong: rgba(255, 255, 255, 0.14);
  --handle-pill: rgba(255, 255, 255, 0.35);
  --trigger-bg: #16161c;
  --trigger-bg-hover: #1f1f27;

  --sidebar-width: 380px;
  --radius-lg: 16px;
  --radius-md: 10px;
  --radius-sm: 6px;
  --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --shadow-panel: 0 20px 40px rgba(0, 0, 0, 0.5), 0 0 0 1px var(--border-glass);
}

[data-theme="cyberpunk"] {
  --bg-dark: #05070c;
  --bg-panel: rgba(8, 14, 22, 0.72);
  --bg-panel-solid: #080e16;
  --bg-active: rgba(102, 252, 241, 0.12);
  --border-glass: rgba(102, 252, 241, 0.14);
  --border-active: rgba(102, 252, 241, 0.35);
  --text-primary: #eafffe;
  --text-secondary: #85a8a5;
  --accent: #66fcf1;
  --accent-glow: rgba(102, 252, 241, 0.4);
  --surface-sunken: rgba(0, 0, 0, 0.25);
  --surface-sunken-strong: rgba(0, 0, 0, 0.35);
  --surface-hover: rgba(102, 252, 241, 0.06);
  --surface-hover-strong: rgba(102, 252, 241, 0.14);
  --handle-pill: rgba(102, 252, 241, 0.4);
  --trigger-bg: #0a1216;
  --trigger-bg-hover: #0f1b20;
}

[data-theme="ocean"] {
  --bg-dark: #060c12;
  --bg-panel: rgba(10, 20, 30, 0.72);
  --bg-panel-solid: #0a141e;
  --bg-active: rgba(79, 176, 216, 0.12);
  --border-glass: rgba(120, 180, 210, 0.12);
  --border-active: rgba(120, 180, 210, 0.3);
  --text-primary: #eef6fa;
  --text-secondary: #8fa8b5;
  --accent: #4fb0d8;
  --accent-glow: rgba(79, 176, 216, 0.4);
  --surface-sunken: rgba(0, 0, 0, 0.22);
  --surface-sunken-strong: rgba(0, 0, 0, 0.32);
  --surface-hover: rgba(255, 255, 255, 0.06);
  --surface-hover-strong: rgba(255, 255, 255, 0.14);
  --handle-pill: rgba(255, 255, 255, 0.35);
  --trigger-bg: #0a141c;
  --trigger-bg-hover: #101e28;
}

[data-theme="light"] {
  --bg-dark: #f2f2f4;
  --bg-panel: rgba(255, 255, 255, 0.78);
  --bg-panel-solid: #ffffff;
  --bg-active: rgba(0, 0, 0, 0.06);
  --border-glass: rgba(0, 0, 0, 0.09);
  --border-active: rgba(0, 0, 0, 0.2);
  --text-primary: #17171a;
  --text-secondary: #65656d;
  --accent: #a8763a;
  --accent-glow: rgba(168, 118, 58, 0.35);
  --surface-sunken: rgba(0, 0, 0, 0.04);
  --surface-sunken-strong: rgba(0, 0, 0, 0.07);
  --surface-hover: rgba(0, 0, 0, 0.045);
  --surface-hover-strong: rgba(0, 0, 0, 0.08);
  --handle-pill: rgba(0, 0, 0, 0.22);
  --trigger-bg: #ffffff;
  --trigger-bg-hover: #f0f0f0;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: 'Inter', sans-serif;
  background-color: var(--bg-dark);
  color: var(--text-primary);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

h1, h2, h3, h4 {
  font-family: 'Outfit', sans-serif;
  font-weight: 600;
  letter-spacing: -0.02em;
}

/* --- APP LAYOUT --- */
.app-container {
  display: flex;
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* Canvas Viewport */
.canvas-viewport {
  flex: 1;
  min-width: 0; /* allow the flex item to shrink below its content size next to the sidebar */
  position: relative;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #030303;
  z-index: 1;
}

#mainCanvas {
  max-width: 100%;
  max-height: 100%;
  box-shadow: 0 15px 50px rgba(0, 0, 0, 0.7);
  transition: transform 0.3s ease;
  touch-action: none;
  background-color: #050505;
}

/* Sidebar Dashboard — a real flex sibling of .canvas-viewport (not an absolutely
   positioned overlay), so the canvas never renders underneath it. Previously this was
   `position: absolute`, which left the canvas at full width behind the (semi-transparent,
   blurred) panel — visible artwork bleeding through the glass. */
.sidebar-dashboard {
  position: relative;
  flex: 0 0 var(--sidebar-width);
  width: var(--sidebar-width);
  margin: 20px 20px 20px 0;
  background: var(--bg-panel);
  backdrop-filter: blur(20px) saturate(160%);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-panel);
  z-index: 10;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: var(--transition-smooth);
}

.sidebar-dashboard.collapsed {
  flex-basis: 0;
  width: 0;
  margin-left: 0;
  margin-right: 0;
  border-width: 0;
  opacity: 0;
  pointer-events: none;
}

/* Sidebar Toggle Controls */
.ui-toggle-btn {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: var(--bg-panel);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border-glass);
  color: var(--text-primary);
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  z-index: 11;
  box-shadow: var(--shadow-panel);
  transition: var(--transition-smooth);
}

.ui-toggle-btn:hover {
  background: var(--surface-hover-strong);
  border-color: var(--border-active);
  transform: scale(1.05);
}

/* --- SIDEBAR COMPONENTS --- */
/* Dashboard Header */
.sidebar-header {
  padding: 24px;
  border-bottom: 1px solid var(--border-glass);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar-header h1 {
  font-size: 24px;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-header h1 span {
  background: linear-gradient(135deg, var(--accent) 0%, color-mix(in srgb, var(--accent) 55%, white) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.sidebar-header p {
  font-size: 13px;
  color: var(--text-secondary);
}

/* Interface theme presets */
.theme-swatch-row {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.theme-swatch {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  padding: 0;
  cursor: pointer;
  border: 2px solid transparent;
  background: linear-gradient(135deg, var(--swatch-a) 50%, var(--swatch-b) 50%);
  transition: var(--transition-smooth);
}

.theme-swatch:hover {
  transform: scale(1.1);
}

.theme-swatch.active {
  border-color: var(--text-primary);
  box-shadow: 0 0 0 2px var(--bg-panel-solid), 0 0 8px var(--accent-glow);
}

/* Credits Footer */
.sidebar-footer {
  flex-shrink: 0;
  padding: 12px 20px;
  border-top: 1px solid var(--border-glass);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-secondary);
}

.sidebar-footer strong {
  color: var(--text-primary);
  font-weight: 600;
}

.sidebar-footer a {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: 4px;
  color: var(--text-secondary);
  text-decoration: none;
  transition: var(--transition-smooth);
}

.sidebar-footer a:hover {
  color: var(--accent);
}

.sidebar-footer a svg {
  fill: currentColor;
}

/* Tab Navigation */
.tab-navigation {
  display: flex;
  border-bottom: 1px solid var(--border-glass);
  background: var(--surface-sunken);
}

.tab-btn {
  flex: 1;
  padding: 14px 0;
  font-family: 'Outfit', sans-serif;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: var(--transition-smooth);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.tab-btn svg {
  width: 18px;
  height: 18px;
  stroke: var(--text-secondary);
  transition: var(--transition-smooth);
}

.tab-btn:hover {
  color: var(--text-primary);
}

.tab-btn:hover svg {
  stroke: var(--text-primary);
}

.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab-btn.active svg {
  stroke: var(--accent);
}

/* Tab Panels Content Scroll */
.tab-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.tab-panel {
  display: none;
  flex-direction: column;
  gap: 20px;
}

.tab-panel.active {
  display: flex;
}

/* Custom Scrollbar for Sidebar Panel */
.tab-content::-webkit-scrollbar {
  width: 6px;
}
.tab-content::-webkit-scrollbar-track {
  background: var(--surface-sunken);
}
.tab-content::-webkit-scrollbar-thumb {
  background: var(--surface-hover-strong);
  border-radius: var(--radius-sm);
}
.tab-content::-webkit-scrollbar-thumb:hover {
  background: var(--border-active);
}

/* --- CONTROL MODULES --- */
.control-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.control-group label {
  font-family: 'Outfit', sans-serif;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.control-group label .val-display {
  color: var(--accent);
  font-weight: 600;
}

/* Grid Selections (Pattern Engines) */
.pattern-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.pattern-card {
  background: var(--surface-sunken);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-md);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: var(--transition-smooth);
  text-align: center;
}

.pattern-card svg {
  width: 24px;
  height: 24px;
  stroke: var(--text-secondary);
  transition: var(--transition-smooth);
}

.pattern-card span {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  transition: var(--transition-smooth);
}

.pattern-card:hover {
  background: var(--surface-hover);
  border-color: var(--border-active);
}

.pattern-card.active {
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  border-color: var(--accent);
  box-shadow: 0 0 15px color-mix(in srgb, var(--accent) 15%, transparent);
}

.pattern-card.active svg {
  stroke: var(--accent);
}

.pattern-card.active span {
  color: var(--text-primary);
  font-weight: 600;
}

/* Range Inputs */
input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: var(--surface-hover-strong);
  outline: none;
  transition: var(--transition-smooth);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text-primary);
  border: 2px solid var(--accent);
  cursor: pointer;
  box-shadow: 0 0 10px var(--accent-glow);
  transition: var(--transition-smooth);
}

input[type="range"]::-webkit-slider-thumb:hover {
  background: var(--accent);
  transform: scale(1.15);
}

/* Select Dropdown */
select {
  background: var(--surface-sunken-strong);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
  outline: none;
  cursor: pointer;
  transition: var(--transition-smooth);
  width: 100%;
}

select:hover {
  border-color: var(--border-active);
}

select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 10px var(--accent-glow);
}

/* Switch & Toggles */
.toggle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
}

.toggle-row span {
  font-size: 13px;
  color: var(--text-secondary);
}

.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 22px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--surface-hover-strong);
  transition: .4s;
  border-radius: 22px;
  border: 1px solid var(--border-glass);
}

.slider:before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 3px;
  bottom: 3px;
  background-color: var(--text-secondary);
  transition: .4s;
  border-radius: 50%;
}

input:checked + .slider {
  background-color: color-mix(in srgb, var(--accent) 20%, transparent);
  border-color: var(--accent);
}

input:checked + .slider:before {
  transform: translateX(22px);
  background-color: var(--accent);
}

/* --- PALETTE SYSTEM CONTROLS --- */
.palette-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.palette-item {
  background: var(--surface-sunken);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-md);
  padding: 12px;
  cursor: pointer;
  transition: var(--transition-smooth);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.palette-item:hover {
  border-color: var(--border-active);
  background: var(--surface-hover);
}

.palette-item.active {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 5%, transparent);
}

.palette-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.palette-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
}

.palette-swatches {
  display: flex;
  border-radius: var(--radius-sm);
  overflow: hidden;
  height: 24px;
  width: 100%;
}

.swatch {
  flex: 1;
  height: 100%;
}

/* Edit-in-place swatch color pickers (Customize Active Colors) */
.custom-swatch-editor {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.custom-swatch-editor .picker-wrapper {
  width: 32px;
  height: 32px;
}

/* Color Harmonizer and Picker Box */
.harmony-editor {
  background: var(--surface-sunken);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.picker-row {
  display: flex;
  gap: 12px;
  align-items: center;
}

.picker-wrapper {
  position: relative;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border-glass);
}

.picker-wrapper input[type="color"] {
  position: absolute;
  top: -10px;
  left: -10px;
  width: 64px;
  height: 64px;
  border: none;
  cursor: pointer;
}

.harmony-select-wrapper {
  flex: 1;
}

/* Custom Action Buttons */
.btn {
  background: var(--text-primary);
  color: var(--bg-dark);
  font-family: 'Outfit', sans-serif;
  font-size: 13px;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-md);
  padding: 12px 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: var(--transition-smooth);
}

.btn svg {
  width: 16px;
  height: 16px;
  stroke: var(--bg-dark);
}

.btn:hover {
  background: var(--accent);
  box-shadow: 0 5px 15px var(--accent-glow);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--surface-hover);
  color: var(--text-primary);
  border: 1px solid var(--border-glass);
}

.btn-secondary svg {
  stroke: var(--text-primary);
}

.btn-secondary:hover {
  background: var(--surface-hover-strong);
  border-color: var(--border-active);
  box-shadow: none;
}

.btn-danger {
  background: rgba(230, 57, 70, 0.15);
  color: #ff4d6d;
  border: 1px solid rgba(230, 57, 70, 0.3);
}

.btn-danger svg {
  stroke: #ff4d6d;
}

.btn-danger:hover {
  background: #e63946;
  color: #ffffff;
  box-shadow: 0 5px 15px rgba(230, 57, 70, 0.3);
}

.buttons-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.buttons-row .btn {
  padding: 10px;
}

/* --- EXPORT PANEL DETAILS --- */
.export-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.ratio-card {
  background: var(--surface-sunken);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-md);
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: var(--transition-smooth);
}

.ratio-icon {
  width: 24px;
  height: 28px;
  border: 2px solid var(--text-secondary);
  border-radius: 3px;
  transition: var(--transition-smooth);
}

.ratio-icon.square { width: 24px; height: 24px; }
.ratio-icon.mobile { width: 16px; height: 28px; }
.ratio-icon.tablet { width: 22px; height: 28px; }

.ratio-card:hover {
  background: var(--surface-hover);
}

.ratio-card.active {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}

.ratio-card.active .ratio-icon {
  border-color: var(--accent);
}

.ratio-card span {
  font-size: 11px;
  color: var(--text-secondary);
}

.ratio-card.active span {
  color: var(--text-primary);
  font-weight: 500;
}

.ratio-card .res {
  font-size: 10px;
  opacity: 0.6;
}

/* --- HISTORY & GALLERY PANELS --- */
.gallery-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  max-height: 250px;
  overflow-y: auto;
  padding-right: 4px;
}

.gallery-card {
  background: var(--surface-sunken-strong);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-md);
  aspect-ratio: 16/10;
  position: relative;
  overflow: hidden;
  cursor: pointer;
  transition: var(--transition-smooth);
}

.gallery-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.gallery-card:hover {
  border-color: var(--border-active);
  transform: translateY(-2px);
}

.gallery-card .card-actions {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  opacity: 0;
  transition: var(--transition-smooth);
}

.gallery-card:hover .card-actions {
  opacity: 1;
}

.action-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.2);
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  transition: var(--transition-smooth);
}

.action-icon svg {
  width: 14px;
  height: 14px;
  stroke: #ffffff;
}

.action-icon:hover {
  background: var(--accent);
  border-color: var(--accent);
}

.action-icon:hover svg {
  stroke: var(--bg-dark);
}

.action-icon.del-btn:hover {
  background: #e63946;
  border-color: #e63946;
}

.action-icon.del-btn:hover svg {
  stroke: #ffffff;
}

/* Empty gallery prompt */
.gallery-empty {
  grid-column: span 2;
  text-align: center;
  padding: 30px 10px;
  font-size: 12px;
  color: var(--text-secondary);
  border: 1px dashed var(--border-glass);
  border-radius: var(--radius-md);
}

/* --- QUICK WORKSPACE UTILITIES --- */
.workspace-controls {
  position: absolute;
  left: 20px;
  bottom: 20px;
  display: flex;
  gap: 10px;
  z-index: 10;
}

.control-circle {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--bg-panel);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border-glass);
  color: var(--text-primary);
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  box-shadow: var(--shadow-panel);
  transition: var(--transition-smooth);
}

.control-circle svg {
  width: 18px;
  height: 18px;
  stroke: var(--text-primary);
}

.control-circle:hover {
  background: var(--surface-hover-strong);
  border-color: var(--border-active);
  transform: scale(1.05);
}

.control-circle.disabled {
  opacity: 0.4;
  pointer-events: none;
}

/* --- COLLAPSE BUTTON INTEGRATED ON SIDEBAR --- */
/* Positioned relative to .app-container (not .sidebar-dashboard) and placed after it
   in the DOM, so it stays visible and clickable even while the sidebar itself is faded
   out / pointer-events:none in its collapsed state — otherwise there'd be no way to
   bring the panel back once collapsed. */
.sidebar-collapse-trigger {
  position: absolute;
  top: 50%;
  right: calc(var(--sidebar-width) + 20px);
  transform: translateY(-50%);
  width: 24px;
  height: 60px;
  /* Solid (not the sidebar's translucent glass) + an accent-tinted border so this stays
     legible against the near-black canvas backdrop it sits on top of. */
  background: var(--trigger-bg);
  border: 1px solid var(--accent);
  border-right: none;
  border-radius: var(--radius-md) 0 0 var(--radius-md);
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  box-shadow: -6px 0 20px rgba(0, 0, 0, 0.5), 0 0 10px var(--accent-glow);
  transition: var(--transition-smooth);
  z-index: 15;
}

.sidebar-collapse-trigger:hover {
  background: var(--trigger-bg-hover);
  box-shadow: -6px 0 20px rgba(0, 0, 0, 0.5), 0 0 16px var(--accent-glow);
}

/* Slide the tab to the screen edge to match the sidebar sliding away */
#sidebar.collapsed ~ .sidebar-collapse-trigger {
  right: 0;
}

.sidebar-collapse-trigger svg {
  width: 13px;
  height: 13px;
  stroke: var(--accent);
  transition: var(--transition-smooth);
}

.sidebar-collapse-trigger:hover svg {
  stroke: var(--text-primary);
}

/* --- MOBILE BOTTOM-SHEET HANDLE --- */
.sheet-handle {
  display: none; /* hidden on desktop, shown via media query */
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 4px;
  padding: 8px 0 6px;
  cursor: pointer;
  flex-shrink: 0;
  /* "none" (not "manipulation") so the browser never hijacks the vertical drag as a
     page pan mid-gesture — that hijack fires pointercancel instead of pointerup and
     breaks both tap-to-toggle and drag-to-resize on touch devices. */
  touch-action: none;
  border-bottom: 1px solid var(--border-glass);
  background: var(--surface-hover);
}

.sheet-handle-pill {
  width: 44px;
  height: 5px;
  background: var(--handle-pill);
  border-radius: 3px;
  transition: background 0.2s ease;
}

.sheet-handle-label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-family: 'Outfit', sans-serif;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--accent);
  text-transform: uppercase;
}

.sheet-handle-label svg {
  width: 14px;
  height: 14px;
  stroke: var(--accent);
  transition: transform 0.3s ease;
}

.sheet-handle:active .sheet-handle-pill {
  background: var(--accent);
}

/* Responsive sidebars */
@media(max-width: 900px) {
  .app-container {
    flex-direction: column;
  }

  .canvas-viewport {
    /* Canvas takes whatever height the bottom sheet leaves */
    flex: 1 1 0;
    min-height: 0;
    height: auto;
    width: 100%;
    padding: 10px;
  }

  #mainCanvas {
    max-width: 100%;
    max-height: 100%;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
  }

  .sheet-handle {
    display: flex;
  }

  /* .collapsed is the desktop side-panel state; it must not hide the mobile sheet */
  .sidebar-dashboard,
  .sidebar-dashboard.collapsed {
    position: relative;
    top: auto;
    right: auto;
    bottom: auto;
    left: auto;
    width: 100%;
    flex: 0 0 auto;
    height: 48vh;
    height: 48dvh;
    min-height: 0;
    margin: 0;
    opacity: 1;
    pointer-events: auto;
    border-width: 1px 1px 0;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    overflow: hidden;
    /* Nothing renders behind the sheet, so the blur only costs frames */
    backdrop-filter: none;
    transition: height 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  }

  /* Disable transitions while the user is actively dragging the handle */
  .app-container.dragging .sidebar-dashboard {
    transition: none;
  }

  /* --- MINIMIZED STATE (class toggled on .app-container by JS) --- */

  /* Panel shrinks to just show the handle bar.
     JS also drives height via inline styles (applyHeights); these are CSS fallbacks. */
  .app-container.panel-collapsed .sidebar-dashboard {
    flex: 0 0 58px;
    height: 58px;
    min-height: 58px;
    max-height: 58px;
    overflow: hidden;
  }

  /* Flip the chevron + swap label when collapsed */
  .app-container.panel-collapsed .sheet-handle-label svg {
    transform: rotate(180deg);
  }

  .sidebar-collapse-trigger {
    display: none;
  }

  /* Move workspace buttons to top-left so they don't overlap canvas */
  .workspace-controls {
    top: 10px;
    bottom: auto;
    left: 10px;
  }

  .control-circle {
    width: 36px;
    height: 36px;
  }

  .control-circle svg {
    width: 15px;
    height: 15px;
  }
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Screen reader only utility to visually hide elements while keeping them accessible */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* --- KEYBOARD FOCUS VISIBILITY --- */
/* Cards/icons are plain divs made keyboard-operable via role="button"+tabindex; give
   them the same glow language already used for select:focus so Tab-navigation is visible. */
.pattern-card:focus-visible,
.ratio-card:focus-visible,
.palette-item:focus-visible,
.action-icon:focus-visible,
.tab-btn:focus-visible,
.control-circle:focus-visible,
.btn:focus-visible,
.theme-swatch:focus-visible,
.sidebar-footer a:focus-visible,
#mainCanvas:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  box-shadow: 0 0 10px var(--accent-glow);
}

/* --- KEYBOARD SHORTCUTS LEGEND MODAL --- */
.shortcuts-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.shortcuts-modal-backdrop.hidden {
  display: none;
}

.shortcuts-modal {
  background: var(--bg-panel-solid);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-panel);
  padding: 24px;
  width: min(420px, 90vw);
  max-height: 80vh;
  overflow-y: auto;
}

.shortcuts-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.shortcuts-modal-header h2 {
  font-family: 'Outfit', sans-serif;
  font-size: 18px;
  font-weight: 600;
}

.shortcuts-modal-header .control-circle {
  position: static;
  width: 32px;
  height: 32px;
}

.shortcuts-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.shortcuts-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
}

.shortcuts-list li span {
  margin-left: auto;
  text-align: right;
  color: var(--text-primary);
}

.shortcuts-list kbd {
  background: var(--bg-active);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-sm);
  padding: 2px 7px;
  font-family: 'Inter', monospace;
  font-size: 12px;
  color: var(--text-primary);
}

