/* Light Theme (Default) */
:root {
  --bg-primary: #ffffff;
  --bg-secondary: #f8f9fa;
  --bg-tertiary: #f1f3f5;
  --border-primary: #e9ecef;
  --border-secondary: #dee2e6;
  --segment-hover-bg: #e2e6ea;
  --text-primary: #212529;
  --text-secondary: #495057;
  --text-tertiary: #868e96;
  --accent-primary: #4263eb;
  --accent-hover: #364fc7;
  --accent-light: #edf2ff;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.08);
}

/* Dark Theme */
[data-theme="dark"] {
  --bg-primary: #1a1b1e;
  --bg-secondary: #25262b;
  --bg-tertiary: #2c2e33;
  --border-primary: #373a40;
  --border-secondary: #2c2e33;
  --segment-hover-bg: #3e4148;
  --text-primary: #e9ecef;
  --text-secondary: #c1c2c5;
  --text-tertiary: #909296;
  --accent-primary: #5c7cfa;
  --accent-hover: #748ffc;
  --accent-light: #2b3a67;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
}

/* Loading Screen */
.loading-screen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: var(--bg-primary);
  transition: opacity 350ms ease;
}

.loading-screen.fade-out {
  opacity: 0;
  pointer-events: none;
}

.loading-spinner {
  width: 28px;
  height: 28px;
  border: 2.5px solid var(--border-primary);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: loading-spin 0.75s linear infinite;
}

.loading-text {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-tertiary);
  letter-spacing: 0.02em;
}

@keyframes loading-spin {
  to { transform: rotate(360deg); }
}

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

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: var(--text-primary);
  background: var(--bg-secondary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.app {
  display: grid;
  grid-template-columns: 320px 1fr;
  height: 100vh;
  overflow: hidden;
}

/* Top Right Controls Container */
.top-right-controls {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Theme Toggle - Top Right */
body>.theme-toggle {
  box-shadow: var(--shadow-md);
}

/* Sidebar */
.sidebar {
  background: var(--bg-primary);
  border-right: 1px solid var(--border-primary);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

.sidebar::-webkit-scrollbar {
  width: 8px;
}

.sidebar::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
  background: var(--border-secondary);
  border-radius: 4px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
  background: var(--text-tertiary);
}

.sidebar-header {
  padding: 24px 24px 20px;
  border-bottom: 1px solid var(--border-primary);
  display: flex;
  align-items: center;
  gap: 12px;
}

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

.app-title {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
  margin: 0;
}

.app-title:hover {
  color: var(--accent-primary);
}

.info-btn {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: var(--text-tertiary);
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  margin-left: auto;
}

.info-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.version-badge {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-tertiary);
  background: var(--bg-tertiary);
  padding: 2px 7px;
  border-radius: 10px;
  transition: all 0.2s ease;
  user-select: none;
  opacity: 0;
  transform: translateY(-2px);
}

.title-wrapper:hover .version-badge {
  opacity: 1;
  background: var(--accent-light);
  color: var(--accent-primary);
  transform: translateY(-2px) scale(1.05);
}

/* App Icon */
.app-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  flex-shrink: 0;
  text-decoration: none;
  box-shadow: 0 2px 8px rgba(66, 99, 235, 0.15);
}

.app-icon:hover {
  transform: scale(1.08);
  box-shadow: 0 4px 16px rgba(66, 99, 235, 0.25);
  filter: brightness(1.1);
}

.app-icon:active {
  transform: scale(0.95);
  transition-duration: 0.1s;
}

.app-icon:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-light), 0 4px 16px rgba(66, 99, 235, 0.25);
}

.app-icon svg {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 8px;
}

/* Dark theme adjustments */
[data-theme="dark"] .app-icon {
  box-shadow: 0 2px 8px rgba(92, 124, 250, 0.2);
}

[data-theme="dark"] .app-icon:hover {
  box-shadow: 0 4px 16px rgba(92, 124, 250, 0.35);
}

.app-icon-small {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 7px;
}

.app-icon-small svg {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 7px;
}

.theme-toggle {
  width: 36px;
  height: 36px;
  border: none;
  background: white;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: all 0.2s ease;
}

.theme-toggle:hover {
  background: var(--border-secondary);
  color: var(--text-primary);
}

.theme-toggle .moon-icon {
  display: none;
}

[data-theme="dark"] .theme-toggle {
  background: var(--bg-tertiary);
}

[data-theme="dark"] .theme-toggle .sun-icon {
  display: none;
}

[data-theme="dark"] .theme-toggle .moon-icon {
  display: block;
}

/* Dark mode: fix invisible hover states caused by --border-secondary === --bg-tertiary */
[data-theme="dark"] .theme-toggle:hover,
[data-theme="dark"] .info-btn:hover,
[data-theme="dark"] .section-toggle:hover,
[data-theme="dark"] .mode-btn:hover,
[data-theme="dark"] .zoom-btn:hover,
[data-theme="dark"] .btn-secondary:hover,
[data-theme="dark"] .modal-close:hover,
[data-theme="dark"] .feedback-btn:hover,
[data-theme="dark"] .app-toggle:hover {
  background: #3e4148;
}

/* Sections */
.section {
  border-bottom: 1px solid var(--border-primary);
}

.section:last-child {
  border-bottom: none;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 24px 0;
  margin-bottom: 16px;
}

.section-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-tertiary);
  margin: 0;
}

.section-header-end {
  display: flex;
  align-items: center;
  gap: 4px;
}

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

#randomizeTilingParams.spinning svg {
  animation: spin-once 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.randomize-params-btn {
  width: 100%;
  margin-bottom: 16px;
  justify-content: center;
}

.section-toggle {
  width: 24px;
  height: 24px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: all 0.2s ease;
}

.section-toggle:hover {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
}

.section-toggle .chevron {
  transition: transform 0.25s ease;
}

.section-toggle[aria-expanded="false"] .chevron {
  transform: rotate(-90deg);
}

.mode-selector {
  display: flex;
  gap: 8px;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-primary);
}

.mode-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 12px;
  border: 1px solid var(--border-primary);
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.mode-btn svg {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

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

.mode-btn.active {
  background: var(--accent-primary);
  color: white;
  border-color: var(--accent-primary);
}

.section-content {
  padding: 0 24px 24px;
  overflow: hidden;
  transition: max-height 0.4s ease-in-out, opacity 0.3s ease, padding 0.3s ease;
}

.section-content.collapsed {
  max-height: 0 !important;
  opacity: 0;
  padding-top: 0;
  padding-bottom: 0;
}

/* Dropzone */
.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 32px 16px;
  background: var(--bg-tertiary);
  border: 2px dashed var(--border-secondary);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s ease;
  color: var(--text-secondary);
  position: relative;
}

.dropzone:hover {
  background: var(--border-secondary);
  border-color: var(--text-tertiary);
}

.dropzone.drag-over {
  background: var(--accent-light);
  border-color: var(--accent-primary);
  color: var(--accent-primary);
}

.dropzone svg {
  flex-shrink: 0;
}

.dropzone-text {
  font-size: 14px;
  font-weight: 500;
  text-align: center;
}

.file-name {
  margin-top: 12px;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  background: var(--accent-light);
  border: 1px solid var(--accent-primary);
  border-radius: 8px;
  word-break: break-all;
  line-height: 1.5;
  transition: all 0.2s ease;
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.file-name.visible {
  display: flex;
  animation: fadeInSlide 0.3s ease;
}

.remove-image-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: 4px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.remove-image-btn:hover {
  background: rgba(0, 0, 0, 0.05);
  color: var(--text-primary);
}

.remove-image-btn:active {
  transform: scale(0.95);
}

@keyframes fadeInSlide {
  from {
    opacity: 0;
    transform: translateY(-5px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Controls */
.control {
  margin-bottom: 20px;
}

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

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

.control label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.value {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent-primary);
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: all 0.2s ease;
  user-select: none;
  min-width: 40px;
  text-align: right;
}

.value:hover {
  background: var(--accent-light);
  color: var(--accent-hover);
}

.value.editing {
  cursor: text;
  user-select: text;
}

.value-input {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent-primary);
  font-variant-numeric: tabular-nums;
  background: var(--bg-primary);
  border: 2px solid var(--accent-primary);
  border-radius: 6px;
  padding: 4px 8px;
  width: 60px;
  text-align: right;
  outline: none;
  font-family: inherit;
  box-shadow: 0 0 0 3px var(--accent-light);
}

.value-input::selection {
  background: var(--accent-primary);
  color: white;
}

.value-input::-moz-selection {
  background: var(--accent-primary);
  color: white;
}

/* Select Input */
.select-input {
  width: 100%;
  height: 36px;
  padding: 0 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-secondary);
  border-radius: 6px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  outline: none;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 14px;
  transition: all 0.2s ease;
}

.select-input:hover {
  border-color: var(--border-primary);
}

.select-input:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 2px var(--accent-light);
}

[data-theme="dark"] .select-input {
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23e9ecef' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
}

/* Range Inputs */
input[type="range"] {
  width: 100%;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--bg-tertiary);
  border-radius: 3px;
  outline: none;
  transition: background 0.2s ease;
  position: relative;
}

input[type="range"]:hover {
  background: var(--border-secondary);
}

/* WebKit (Chrome, Safari, Edge) */
input[type="range"]::-webkit-slider-runnable-track {
  width: 100%;
  height: 6px;
  background: transparent;
  border-radius: 3px;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  background: var(--accent-primary);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: all 0.2s ease;
  position: relative;
  z-index: 2;
  margin-top: -6px;
}

input[type="range"]::-webkit-slider-thumb:hover {
  background: var(--accent-hover);
  transform: scale(1.1);
}

/* Firefox */
input[type="range"]::-moz-range-track {
  width: 100%;
  height: 6px;
  background: transparent;
  border-radius: 3px;
}

input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  background: var(--accent-primary);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: all 0.2s ease;
  position: relative;
  z-index: 2;
}

input[type="range"]::-moz-range-thumb:hover {
  background: var(--accent-hover);
  transform: scale(1.1);
}

/* Firefox progress fill */
input[type="range"]::-moz-range-progress {
  height: 6px;
  background: var(--accent-primary);
  opacity: 0.3;
  border-radius: 3px;
}

/* Boundary Controls */
.boundary-controls,
.mask-controls {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border-primary);
  animation: slideDown 0.3s ease;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Color Picker */
.color-picker-wrapper {
  display: flex;
  align-items: center;
  gap: 12px;
}

.color-swatch {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  border: 2px solid var(--border-secondary);
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  flex-shrink: 0;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1);
}

.color-swatch:hover {
  transform: scale(1.05);
  border-color: var(--accent-primary);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15), inset 0 1px 3px rgba(0, 0, 0, 0.1);
}

.color-swatch:active {
  transform: scale(0.95);
}

.color-swatch.dragging {
  opacity: 0.5;
  transform: scale(1.05);
}

.color-swatch.drag-over {
  border: 2px solid var(--accent-primary);
  transform: scale(1.1);
}

.color-swatch:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-light), 0 4px 12px rgba(0, 0, 0, 0.15);
  border-color: var(--accent-primary);
}

.hex-input {
  flex: 1;
  padding: 10px 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-primary);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 500;
  font-family: 'Monaco', 'Menlo', 'Courier New', monospace;
  text-transform: uppercase;
  transition: all 0.2s ease;
}

.hex-input:hover {
  border-color: var(--border-secondary);
}

.hex-input:focus {
  outline: none;
  border-color: var(--accent-primary);
  background: var(--bg-primary);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.hex-input::placeholder {
  color: var(--text-tertiary);
  text-transform: uppercase;
}

/* Gradient Stops UI */
.grad-stops-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
  max-height: 220px;
  overflow-y: auto;
  overflow-x: hidden;
}

.grad-stop-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.grad-stop-swatch {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 2px solid var(--border-secondary);
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.2s ease;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1);
}

.grad-stop-swatch:hover {
  border-color: var(--accent-primary);
  transform: scale(1.05);
}

.grad-stop-swatch.dragging {
  opacity: 0.5;
  transform: scale(1.05);
}

.grad-stop-swatch.drag-over {
  border: 2px solid var(--accent-primary);
  transform: scale(1.1);
}

.grad-stop-hex {
  flex: 1;
  min-width: 0;
}


.grad-stop-delete {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border-primary);
  border-radius: 8px;
  background: var(--bg-tertiary);
  color: var(--text-tertiary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s ease;
  font-size: 18px;
  line-height: 1;
}

.grad-stop-delete:hover {
  background: var(--accent-light);
  color: var(--accent-primary);
  border-color: var(--accent-primary);
}

.grad-stop-delete:disabled {
  opacity: 0.25;
  cursor: not-allowed;
  pointer-events: none;
}

.grad-add-stop {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px dashed var(--border-secondary);
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  font-weight: 500;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.grad-add-stop:hover {
  border-color: var(--accent-primary);
  color: var(--accent-primary);
  background: var(--accent-light);
}

.grad-stops-actions {
  display: flex;
  gap: 8px;
}

.grad-stops-actions .grad-add-stop {
  flex: 1;
}

/* Checkboxes */
.checkbox {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  padding: 12px 0;
  user-select: none;
}

.checkbox input[type="checkbox"] {
  width: 20px;
  height: 20px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--bg-tertiary);
  border: 2px solid var(--border-secondary);
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.checkbox input[type="checkbox"]:hover {
  border-color: var(--accent-primary);
}

.checkbox input[type="checkbox"]:checked {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
}

.checkbox input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 5px;
  top: 2px;
  width: 5px;
  height: 9px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.checkbox-label {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
}

/* Segmented Control */
.segmented-control {
  display: flex;
  margin: 4px 0 8px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border-primary);
}

.segment-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 12px;
  border: none;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
}

.segment-btn:not(:last-child) {
  border-right: 1px solid var(--border-primary);
}

.segment-btn:not(.active):hover {
  filter: brightness(1.4);
  color: var(--text-primary);
}

.segment-btn.active {
  background: var(--accent-primary);
  color: white;
}

/* Dimension Inputs */
.dimension-inputs {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 12px;
  margin-bottom: 16px;
  align-items: end;
}

.dimension-input {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.dimension-input label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.link-button {
  width: 42px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--border-primary);
  background: var(--bg-tertiary);
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-tertiary);
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.link-button svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.feedback-btn svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.link-button:hover {
  background: var(--border-secondary);
  border-color: var(--border-secondary);
  color: var(--text-secondary);
}

.link-button.linked {
  background: var(--accent-light);
  border-color: var(--accent-primary);
  color: var(--accent-primary);
}

.link-button.linked:hover {
  background: var(--accent-primary);
  color: white;
}

.link-button .unlink-icon {
  display: none;
}

.link-button.linked .link-icon {
  display: block;
}

.link-button.linked .unlink-icon {
  display: none;
}

.link-button:not(.linked) .link-icon {
  display: none;
}

.link-button:not(.linked) .unlink-icon {
  display: block;
}

input[type="number"] {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-primary);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  transition: all 0.2s ease;
}

input[type="number"]::selection {
  background: var(--accent-primary);
  color: white;
}

input[type="number"]::-moz-selection {
  background: var(--accent-primary);
  color: white;
}

input[type="number"]:hover {
  border-color: var(--border-secondary);
}

input[type="number"]:focus {
  outline: none;
  border-color: var(--accent-primary);
  background: var(--bg-primary);
}

/* Buttons */
.action-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}

.action-button-row {
  display: flex;
  gap: 8px;
}

.action-button-row .btn:first-child {
  flex: 1;
}

.btn-icon {
  width: 44px;
  height: 44px;
  padding: 0;
  flex-shrink: 0;
}

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 16px;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

#exportTileSvg,
#exportTilePng {
  padding: 8px 14px;
}

.btn svg {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
}

.btn-primary {
  background: var(--accent-primary);
  color: white;
  box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
  background: var(--accent-hover);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

/* Modal Footer Credit */
.modal-footer-credit {
  margin-top: 32px;
  padding-top: 24px;
  padding-bottom: 24px;
  text-align: center;
  border-top: 1px solid var(--border-primary);
  position: relative;
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border: 1px solid var(--border-primary);
}

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

#exportTileSvg:hover svg,
#exportTilePng:hover svg {
  color: var(--accent-primary);
  stroke: var(--accent-primary);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-primary:disabled {
  background: var(--bg-tertiary);
  color: var(--text-tertiary);
  box-shadow: none;
}

.btn-secondary:disabled {
  background: var(--bg-tertiary);
  color: var(--text-tertiary);
  border-color: var(--border-primary);
}

/* Hint */
.hint {
  font-size: 12px;
  color: var(--text-tertiary);
  line-height: 1.5;
  margin-bottom: 8px;
}

/* ════════════════════════════════════════
   PRESETS SECTION
   ════════════════════════════════════════ */

.preset-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-primary);
  border-radius: 8px;
  margin-bottom: 6px;
}

.preset-thumb {
  width: 40px;
  height: 40px;
  border-radius: 6px;
  object-fit: cover;
  flex-shrink: 0;
  border: 1px solid var(--border-primary);
}

.preset-thumb-empty {
  background: var(--bg-secondary);
}

.preset-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.preset-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.preset-date {
  font-size: 11px;
  color: var(--text-tertiary);
}

.preset-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.preset-rename-input {
  padding: 2px 6px;
  font-size: 13px;
  font-weight: 500;
  height: auto;
  margin: 0;
  min-width: 0;
  flex: 1;
}

.preset-save-form {
  display: none;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}

.preset-name-input {
  width: 100%;
  box-sizing: border-box;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1.5px solid var(--border-primary);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s ease;
}

.preset-name-input:focus {
  border-color: var(--accent-primary);
}

.preset-save-actions {
  display: flex;
  gap: 6px;
}

.btn-sm {
  padding: 5px 12px;
  font-size: 13px;
  height: auto;
  border-radius: 8px;
}

/* Play/Pause Button */
.play-pause-btn {
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  background: var(--accent-primary);
  color: white;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}

.play-pause-btn:hover {
  background: var(--accent-hover);
  transform: scale(1.05);
}

.play-pause-btn:active {
  transform: scale(0.95);
}

.play-pause-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-light), var(--shadow-sm);
}

.play-pause-btn svg {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
}

/* Main Canvas Area */
.main {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  background: var(--bg-secondary);
  overflow: hidden;
  position: relative;
}

.main.drag-over::before {
  content: '';
  position: absolute;
  inset: 20px;
  border: 3px dashed var(--accent-primary);
  border-radius: 12px;
  background: var(--accent-light);
  pointer-events: none;
  z-index: 10;
}

.canvas-container {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  padding: 0;
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
  max-width: calc(100vw - 400px);
  max-height: calc(100vh - 120px);
}

.canvas-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  /* Prevents blank space from showing during pan */
  width: 100%;
  height: 100%;
  cursor: default;
  z-index: 1;
}

.canvas-wrapper.panning {
  cursor: grabbing !important;
}

.canvas-wrapper.pannable {
  cursor: grab;
}

canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  height: auto;
  border-radius: 8px;
  transform-origin: center center;
  position: relative;
  z-index: 2;
  will-change: transform;
  /* Optimize transform performance */
}

/* Empty State (Canvas) */
.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 14px;
  background: color-mix(in oklab, var(--bg-tertiary) 70%, transparent);
  border: 1px solid var(--border-primary);
  border-radius: 10px;
  color: var(--text-secondary);
  pointer-events: none;
  opacity: 1;
  transition: opacity 160ms ease-in-out;
  z-index: 5;
}

.empty-state.hidden {
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
}

.empty-icon svg {
  width: 88px;
  height: 88px;
  color: var(--text-tertiary);
  opacity: 0.7;
}

@media (prefers-reduced-motion: no-preference) {
  @keyframes emptyIconPulse {

    0%,
    100% {
      transform: scale(1);
      opacity: 0.7;
    }

    50% {
      transform: scale(1.03);
      opacity: 0.8;
    }
  }

  .empty-icon svg {
    animation: emptyIconPulse 3000ms ease-in-out infinite;
  }
}

.empty-title {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}

.empty-desc {
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-secondary);
}

.empty-import-btn {
  pointer-events: auto;
  /* re-enable for button */
  padding: 12px 18px;
  margin-top: 16px;
}

.empty-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 32px;
}

.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 10px;
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--bg-tertiary);
  border: 1px solid var(--border-primary);
  border-radius: 999px;
}

.empty-footnote {
  font-size: 12px;
  color: var(--text-tertiary);
}

/* Preview Toggle Button (hidden, functionality moved to zoom toolbar) */
.toggle-switch {
  display: none !important;
}

/* See Also Tab Styles */
.apps-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.app-item {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-primary);
  border-radius: 12px;
  overflow: hidden;
  transition: all 0.2s ease;
}

.app-item:hover {
  border-color: var(--accent-primary);
  box-shadow: var(--shadow-sm);
  background: var(--bg-primary);
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  cursor: pointer;
  user-select: none;
}

.app-link {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: var(--text-primary);
  flex: 1;
  transition: opacity 0.2s ease;
}

.app-link:hover {
  opacity: 0.8;
}

.app-icon-img {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  object-fit: contain;
  background: var(--bg-primary);
  padding: 2px;
  border: 1px solid var(--border-primary);
}

.app-name {
  font-weight: 600;
  font-size: 15px;
}

.app-toggle {
  background: transparent;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.app-toggle:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.app-toggle .chevron-icon {
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.app-item.expanded .app-toggle .chevron-icon {
  transform: rotate(180deg);
}

.app-description {
  height: 0;
  overflow: hidden;
  transition: height 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  background: var(--bg-primary);
  border-top: 1px solid transparent;
}

.app-item.expanded .app-description {
  border-top-color: var(--border-primary);
}

.app-description p {
  padding: 16px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-secondary);
  margin: 0;
}

.toggle-btn {
  display: none;
}

/* Zoom Controls */
.zoom-toolbar {
  position: absolute;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  display: none;
  /* Hidden by default until image is loaded */
  align-items: center;
  gap: 8px;
  background: var(--bg-primary);
  border: 1px solid var(--border-primary);
  border-radius: 12px;
  padding: 8px;
  box-shadow: var(--shadow-lg);
  z-index: 200;
  transition: all 0.2s ease;
}

.zoom-btn {
  width: 36px;
  height: 36px;
  padding: 0;
  border: none;
  background: transparent;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: all 0.2s ease;
}

.zoom-btn svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.zoom-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.zoom-btn:active {
  transform: scale(0.95);
}

.zoom-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.zoom-btn:disabled:hover {
  background: transparent;
  color: var(--text-secondary);
}

/* Preview Toggle Button */
.preview-toggle-btn {
  position: relative;
}

.preview-toggle-btn .eye-off-icon {
  display: none;
}

.preview-toggle-btn.showing-original .eye-icon {
  display: none;
}

.preview-toggle-btn.showing-original .eye-off-icon {
  display: block;
}

.preview-toggle-btn.showing-original {
  background: var(--accent-light);
  color: var(--accent-primary);
}

.preview-toggle-btn.showing-original:hover {
  background: var(--accent-primary);
  color: white;
}

/* Geo Animation Toggle Button */
.geo-anim-toggle-btn.is-playing {
  background: var(--accent-light);
  color: var(--accent-primary);
}

.geo-anim-toggle-btn.is-playing:hover {
  background: var(--accent-primary);
  color: white;
}

.zoom-indicator {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 8px;
  min-width: 70px;
  justify-content: center;
}

.zoom-input {
  width: 42px;
  padding: 6px 4px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  text-align: right;
  transition: all 0.2s ease;
  font-variant-numeric: tabular-nums;
}

.zoom-input:hover {
  background: var(--bg-tertiary);
  border-color: var(--border-primary);
}

.zoom-input:focus {
  outline: none;
  background: var(--bg-tertiary);
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.zoom-percent {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  user-select: none;
}

.zoom-divider {
  width: 1px;
  height: 24px;
  background: var(--border-primary);
  margin: 0 4px;
}

.zoom-reset {
  color: var(--accent-primary);
}

.zoom-reset:hover {
  background: var(--accent-light);
  color: var(--accent-hover);
}

/* Focus states for accessibility */
.btn:focus-visible,
.link-button:focus-visible,
input[type="number"]:focus-visible,
input[type="range"]:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent-primary) 25%, transparent);
}

/* Sidebar Footer */
.sidebar-footer {
  margin-top: auto;
  padding: 24px;
  text-align: center;
  border-top: 1px solid var(--border-primary);
  position: relative;
}

.footer-text {
  font-size: 12px;
  color: var(--text-tertiary);
  margin: 0;
  position: relative;
}

.footer-link {
  color: inherit;
  text-decoration: none;
  position: relative;
  display: inline-block;
  transition: color 0.25s ease;
}

.footer-link::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 50%;
  width: 0;
  height: 1px;
  background: var(--accent-primary);
  transform: translateX(-50%);
  transition: width 0.3s ease;
}

.footer-link:hover {
  color: var(--accent-primary);
}

.footer-link:hover::after {
  width: 100%;
}

/* Animated underline */
.footer-link::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 50%;
  width: 0;
  height: 1px;
  background: var(--accent-primary);
  transform: translateX(-50%);
  transition: width 0.3s ease;
}

/* Tooltip */
.footer-link::before {
  content: 'Discover more design tools';
  position: absolute;
  bottom: calc(100% + 12px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-primary);
  color: var(--text-primary);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-primary);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  z-index: 100;
}

/* Show tooltip after delay */
@keyframes tooltipFadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

.footer-link:hover::before {
  animation: tooltipFadeIn 0.25s ease forwards;
  animation-delay: 1.2s;
}

/* Dark theme tooltip */
[data-theme="dark"] .footer-link::before {
  background: var(--bg-tertiary);
  border-color: var(--border-secondary);
}

/* Responsive */
@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .sidebar {
    max-height: 50vh;
    border-right: none;
    border-bottom: 1px solid var(--border-primary);
  }

  .main {
    padding: 20px;
  }

  .canvas-container {
    padding: 0;
    max-width: calc(100vw - 40px);
  }

  .zoom-toolbar {
    bottom: 20px;
  }
}

@media (max-width: 600px) {
  .sidebar-header {
    padding: 20px 16px 16px;
  }

  .section {
    padding: 20px 16px;
  }

  .main {
    padding: 16px;
  }

  .action-buttons {
    flex-direction: column;
  }

  .canvas-container {
    max-width: calc(100vw - 32px);
  }

  .zoom-toolbar {
    bottom: 16px;
    padding: 6px;
    gap: 6px;
  }

  .zoom-btn {
    width: 32px;
    height: 32px;
  }

  .zoom-indicator {
    padding: 0 4px;
    min-width: 60px;
  }

  .zoom-input {
    width: 38px;
    font-size: 13px;
  }
}

/* Flat Pattern Preview */
.geo-flat-preview {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  border: 1px solid var(--border-primary);
  border-radius: 8px;
}

/* Tile Shape Editor */
.tile-editor-canvas {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  border: 1px solid var(--border-primary);
  border-radius: 8px;
  cursor: crosshair;
  touch-action: none;
  /* SVG theme tokens */
  --te-bg:           var(--bg-tertiary);
  --te-tile-fill:    rgba(66, 99, 235, 0.12);
  --te-tile-stroke:  #4263eb;
  --te-edge-vtx:     #212529;
  --te-fixed-vtx:    #e03131;
  --te-immobile:     #e03131;
  --te-mobile:       #b0b5bb;
  --te-sym-vtx:      #339af0;
  /* Connected-edge colour palette — one shade per unique edge ID.
     Shades span dark→light so adjacent slots are clearly distinguishable. */
  --te-edge-color-0: #1864ab;
  --te-edge-color-1: #4263eb;
  --te-edge-color-2: #74c0fc;
  --te-edge-color-3: #1c7ed6;
  --te-edge-color-4: #748ffc;
  /* Bezier handle colours */
  --te-handle-line:  rgba(134, 142, 150, 0.7);
  --te-handle-dot:   #868e96;
  /* Snap indicator colour */
  --te-snap-color:   #f08c00;
}
[data-theme="dark"] .tile-editor-canvas {
  --te-tile-fill:    rgba(92, 124, 250, 0.20);
  --te-tile-stroke:  #5c7cfa;
  --te-edge-vtx:     #e9ecef;
  --te-fixed-vtx:    #e03131;
  --te-immobile:     #e03131;
  --te-mobile:       #6e7278;
  --te-sym-vtx:      #74c0fc;
  /* Connected-edge colour palette — one shade per unique edge ID.
     Shades span light→medium so adjacent slots are clearly distinguishable. */
  --te-edge-color-0: #a5d8ff;
  --te-edge-color-1: #5c7cfa;
  --te-edge-color-2: #74c0fc;
  --te-edge-color-3: #4263eb;
  --te-edge-color-4: #91a7ff;
  /* Bezier handle colours */
  --te-handle-line:  rgba(134, 142, 150, 0.4);
  --te-handle-dot:   #6e7278;
  /* Snap indicator colour */
  --te-snap-color:   #fd7e14;
}

.tile-editor-canvas .te-vtx-hover {
  pointer-events: none;
}

.tile-editor-canvas .te-vtx-selected {
  pointer-events: none;
}

.tile-editor-canvas .te-vtx-drag {
  cursor: grab;
  transform-box: fill-box;
  transform-origin: center;
  transition: transform 0.12s ease;
}

.tile-editor-canvas .te-vtx-drag:hover {
  transform: scale(1.6);
}

.tile-editor-canvas .te-vtx-handle {
  cursor: crosshair;
  transition: transform 0.12s ease;
  transform-box: fill-box;
  transform-origin: center;
}

.tile-editor-canvas .te-vtx-handle:hover {
  transform: scale(1.5);
}

.tile-editor-hint {
  font-size: 11px;
  color: var(--text-tertiary);
  line-height: 1.5;
  margin-bottom: 10px;
}

.tile-editor-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 10px;
}

.tile-editor-btn {
  flex: 1 1 0;
  min-width: 0;
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  text-align: center;
  justify-content: center;
}

/* Snap toggle — active (on) state */
.tile-editor-snap.is-active {
  color: var(--accent-primary);
  border-color: rgba(66, 99, 235, 0.45);
  background: var(--accent-light);
}

.tile-editor-snap.is-active:hover {
  background: var(--accent-light);
  border-color: var(--accent-primary);
  opacity: 0.85;
}

[data-theme="dark"] .tile-editor-snap.is-active {
  color: var(--accent-primary);
  border-color: rgba(92, 124, 250, 0.45);
  background: rgba(43, 58, 103, 0.6);
}

/* Smooth toggle — active (smooth) state */
.tile-editor-smooth.is-smooth {
  color: var(--accent-primary);
  border-color: rgba(66, 99, 235, 0.45);
  background: var(--accent-light);
}

.tile-editor-smooth.is-smooth:hover {
  background: var(--accent-light);
  border-color: var(--accent-primary);
  opacity: 0.85;
}

[data-theme="dark"] .tile-editor-smooth.is-smooth {
  color: var(--accent-primary);
  border-color: rgba(92, 124, 250, 0.45);
  background: rgba(43, 58, 103, 0.6);
}

[data-theme="dark"] .tile-editor-smooth.is-smooth:hover {
  background: rgba(43, 58, 103, 0.6);
  border-color: var(--accent-primary);
  opacity: 0.85;
}

[data-theme="dark"] .tile-editor-snap.is-active:hover {
  background: rgba(43, 58, 103, 0.6);
  border-color: var(--accent-primary);
  opacity: 0.85;
}

.tile-editor-remove:not(:disabled) {
  color: #e03131;
  border-color: rgba(224, 49, 49, 0.35);
}

.tile-editor-remove:not(:disabled):hover {
  background: rgba(224, 49, 49, 0.08);
  border-color: #e03131;
  color: #e03131;
}

[data-theme="dark"] .tile-editor-remove:not(:disabled) {
  color: #ff6b6b;
  border-color: rgba(255, 107, 107, 0.35);
}

[data-theme="dark"] .tile-editor-remove:not(:disabled):hover {
  background: rgba(255, 107, 107, 0.12);
  border-color: #ff6b6b;
  color: #ff6b6b;
}

/* Modal Dialog */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 20px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal-dialog {
  background: var(--bg-primary);
  border-radius: 16px;
  box-shadow: var(--shadow-lg), 0 20px 60px rgba(0, 0, 0, 0.3);
  width: 90%;
  max-width: 700px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  transform: scale(0.95);
  opacity: 0;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease;
}

.modal-overlay.active .modal-dialog {
  transform: scale(1);
  opacity: 1;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 28px;
  border-bottom: 1px solid var(--border-primary);
  flex-shrink: 0;
}

.modal-title-wrapper {
  display: flex;
  align-items: center;
  gap: 12px;
}

.modal-title {
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  margin: 0;
}

.modal-version {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-tertiary);
  background: var(--bg-tertiary);
  padding: 4px 10px;
  border-radius: 12px;
}

.modal-close {
  width: 36px;
  height: 36px;
  padding: 0;
  border: none;
  background: transparent;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-tertiary);
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.modal-close:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  transform: rotate(90deg);
}

.modal-close:active {
  transform: rotate(90deg) scale(0.95);
}

/* Modal Tabs */
.modal-tabs {
  display: flex;
  border-bottom: 1px solid var(--border-primary);
  background: var(--bg-primary); /* Match modal bg */
  padding: 0 28px;
  flex-shrink: 0; /* Don't shrink */
}

.modal-tab {
  padding: 16px 4px;
  margin-right: 24px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
}

.modal-tab:hover {
  color: var(--text-primary);
}

.modal-tab.active {
  color: var(--accent-primary);
  border-bottom-color: var(--accent-primary);
}

.tab-content {
  display: none;
  animation: fadeIn 0.2s ease;
}

.tab-content.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.modal-content {
  padding: 28px;
  overflow-y: auto;
  flex: 1;
}

.modal-content::-webkit-scrollbar {
  width: 8px;
}

.modal-content::-webkit-scrollbar-track {
  background: transparent;
}

.modal-content::-webkit-scrollbar-thumb {
  background: var(--border-secondary);
  border-radius: 4px;
}

.modal-content::-webkit-scrollbar-thumb:hover {
  background: var(--text-tertiary);
}

.modal-description {
  margin-bottom: 28px;
}

.modal-description p {
  font-size: 15px;
  line-height: 1.7;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

.modal-description p:last-child {
  margin-bottom: 0;
}

/* How-to Tab */
.howto-content h3 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 16px;
}

.howto-content h4 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  margin-top: 24px;
  margin-bottom: 12px;
}

.howto-content h4:first-of-type {
  margin-top: 0;
}

.howto-content p {
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.howto-content ul {
  list-style: none;
  padding: 0;
  margin-bottom: 16px;
}

.howto-content li {
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-secondary);
  margin-bottom: 8px;
  padding-left: 16px;
  position: relative;
}

.howto-content li::before {
  content: "•";
  position: absolute;
  left: 0;
  color: var(--accent-primary);
  font-weight: bold;
}

/* Shortcuts Tab Styles */
.shortcuts-container {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.5rem 2rem;
  align-items: start;
}

@media (max-width: 600px) {
  .shortcuts-container {
    grid-template-columns: 1fr;
    gap: 1.5rem;
  }
}

.shortcut-group {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.shortcut-category {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0 0 0.25rem 0;
  border-bottom: 1px solid var(--border-primary);
  padding-bottom: 0.5rem;
}

.shortcut-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.25rem 0;
}

.shortcut-desc {
  color: var(--text-secondary);
  font-size: 0.95rem;
}

.shortcut-keys {
  display: flex;
  gap: 0.35rem;
  align-items: center;
}

.kbd-key {
  font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Fira Mono', 'Droid Sans Mono', 'Source Code Pro', monospace;
  font-size: 0.85rem;
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-secondary);
  border-radius: 4px;
  padding: 0.15rem 0.45rem;
  color: var(--text-primary);
  box-shadow: 0 1px 0 var(--border-secondary);
  min-width: 1.4rem;
  text-align: center;
  display: inline-block;
  line-height: 1.2;
}

.kbd-key.key-modifier {
  font-weight: 500;
}


.modal-actions {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
}

.discover-more-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 14px 20px;
  background: var(--accent-primary);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: var(--shadow-sm);
  flex: 1;
}

.feedback-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 14px 20px;
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-primary);
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
  flex: 1;
}

.feedback-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border-color: var(--border-secondary);
}

.discover-more-btn:hover {
  background: var(--accent-hover);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.discover-more-btn:active {
  transform: translateY(0);
}

.discover-more-btn svg {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
}

.eula-text {
  /* padding removed as it is inside modal-content */
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-secondary);
}

.eula-text p {
  margin-bottom: 12px;
}

.eula-text h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-top: 20px;
  margin-bottom: 8px;
}

.eula-text h3:first-of-type {
  margin-top: 0;
}

.eula-text a {
  color: var(--accent-primary);
  text-decoration: none;
  transition: color 0.2s ease;
}

.eula-text a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

.eula-footer {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border-primary);
  font-style: italic;
  color: var(--text-tertiary);
}

/* Modal responsive */
@media (max-width: 600px) {
  .modal-overlay {
    padding: 16px;
  }

  .modal-dialog {
    width: 95%;
    max-height: 85vh;
  }

  .modal-header {
    padding: 20px;
  }

  .modal-title {
    font-size: 20px;
  }

  .modal-content {
    padding: 20px;
  }

  .modal-description p {
    font-size: 14px;
  }

  .discover-more-btn {
    padding: 12px 16px;
    font-size: 14px;
  }

  .modal-close {
    width: 32px;
    height: 32px;
  }
}

/* See Also Tab Styles */
.apps-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.app-item {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-primary);
  border-radius: 12px;
  overflow: hidden;
  transition: all 0.2s ease;
}

.app-item:hover {
  border-color: var(--accent-primary);
  box-shadow: var(--shadow-sm);
  background: var(--bg-primary);
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  cursor: pointer;
  user-select: none;
}

.app-link {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: var(--text-primary);
  flex: 1;
  transition: opacity 0.2s ease;
}

.app-link:hover {
  opacity: 0.8;
}

.app-icon-img {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  object-fit: contain;
  background: var(--bg-primary);
  padding: 2px;
  border: 1px solid var(--border-primary);
}

.app-name {
  font-weight: 600;
  font-size: 15px;
}

.app-toggle {
  background: transparent;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.app-toggle:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.app-toggle .chevron-icon {
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.app-item.expanded .app-toggle .chevron-icon {
  transform: rotate(180deg);
}

.app-description {
  height: 0;
  overflow: hidden;
  transition: height 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  background: var(--bg-primary);
  border-top: 1px solid transparent;
}

.app-item.expanded .app-description {
  border-top-color: var(--border-primary);
}

.app-description p {
  padding: 16px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-secondary);
  margin: 0;
}

/* =========================================================
   LICENSE SYSTEM
   ========================================================= */

/* License Status Badge */
.license-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 12px;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  border: none;
  font-family: inherit;
  transition: all 0.2s ease;
  white-space: nowrap;
  flex-shrink: 0;
  box-shadow: var(--shadow-md);
  text-transform: uppercase;
}

.license-badge svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.license-badge span {
  display: inline;
}

.license-badge.trial {
  background: var(--bg-primary);
  color: var(--text-secondary);
  border: 1px solid var(--border-primary);
}

.license-badge.trial:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.license-badge.pro {
  background: var(--bg-primary);
  color: var(--accent-primary);
  border: 1px solid var(--border-primary);
}

.license-badge.pro svg {
  color: var(--accent-primary);
}

.license-badge.pro span {
  color: var(--accent-primary);
}

.license-badge.pro:hover {
  background: var(--bg-tertiary);
  color: var(--accent-primary);
}

[data-theme="dark"] .license-badge.pro {
  box-shadow: var(--shadow-md);
}

/* Pro lock badge on buttons */
.btn.pro-locked {
  position: relative;
}

/* Prevent lock icon color change on hover for pro-locked buttons */
.btn.pro-locked:hover .pro-lock-badge svg {
  color: white;
}

.pro-lock-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 18px;
  height: 18px;
  background: linear-gradient(135deg, #f59f00, #e67700);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 4px rgba(0,0,0,0.25);
  pointer-events: none;
  z-index: 1;
}

.pro-lock-badge svg {
  width: 10px;
  height: 10px;
  color: white;
}

/* Paywall Overlay */
.paywall-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.paywall-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.paywall-dialog {
  background: var(--bg-primary);
  border-radius: 16px;
  box-shadow: var(--shadow-lg), 0 0 0 1px var(--border-primary);
  width: 100%;
  max-width: 480px;
  overflow: hidden;
  transform: translateY(10px) scale(0.97);
  transition: transform 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.paywall-overlay.active .paywall-dialog {
  transform: translateY(0) scale(1);
}

.paywall-header {
  padding: 24px 24px 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.paywall-icon-wrap {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(66, 99, 235, 0.3);
}

.paywall-icon-wrap svg {
  display: block;
}

.paywall-header-text {
  flex: 1;
  padding-top: 2px;
}

.paywall-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 4px;
  letter-spacing: -0.02em;
}

.paywall-subtitle {
  font-size: 12.5px;
  color: var(--text-tertiary);
  margin: 0;
  line-height: 1.5;
}

.paywall-close {
  width: 30px;
  height: 30px;
  border: none;
  background: transparent;
  color: var(--text-tertiary);
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
  margin-top: -2px;
}

.paywall-close:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.paywall-features {
  padding: 24px 24px 0;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 7px 12px;
  margin-bottom: 20px;
}

.paywall-feature {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}

.paywall-feature svg {
  color: var(--accent-primary);
  flex-shrink: 0;
}

.paywall-body {
  padding: 18px 24px 24px;
}

.paywall-input-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 7px;
  display: block;
}

.paywall-key-input {
  width: 100%;
  height: 42px;
  padding: 0 14px;
  background: var(--bg-tertiary);
  border: 1.5px solid var(--border-secondary);
  border-radius: 10px;
  color: var(--text-primary);
  font-family: 'SF Mono', 'Fira Mono', 'Consolas', monospace;
  font-size: 13px;
  font-weight: 500;
  outline: none;
  transition: all 0.2s ease;
  letter-spacing: 0.04em;
}

.paywall-key-input:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.paywall-key-input::placeholder {
  color: var(--text-tertiary);
  font-family: 'SF Mono', 'Fira Mono', 'Consolas', monospace;
  letter-spacing: 0.04em;
}

.paywall-message {
  margin-top: 9px;
  font-size: 12.5px;
  font-weight: 500;
  min-height: 18px;
  display: flex;
  align-items: center;
  gap: 6px;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.paywall-message.visible { opacity: 1; }
.paywall-message.error   { color: #e03131; }
.paywall-message.success { color: #2f9e44; }

[data-theme="dark"] .paywall-message.error   { color: #ff6b6b; }
[data-theme="dark"] .paywall-message.success { color: #69db7c; }

.paywall-actions {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.paywall-btn-validate {
  width: 100%;
  height: 42px;
  background: linear-gradient(135deg, #4263eb, #7048e8);
  color: white;
  border: none;
  border-radius: 10px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 2px 8px rgba(66, 99, 235, 0.25);
}

.paywall-btn-validate:hover:not(:disabled) {
  box-shadow: 0 4px 16px rgba(66, 99, 235, 0.4);
  transform: translateY(-1px);
}

.paywall-btn-validate:active:not(:disabled) { transform: translateY(0); }

.paywall-btn-validate:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.paywall-btn-purchase {
  width: 100%;
  height: 42px;
  background: transparent;
  color: var(--text-secondary);
  border: 1.5px solid var(--border-secondary);
  border-radius: 10px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.paywall-btn-purchase:hover {
  border-color: var(--accent-primary);
  color: var(--accent-primary);
  background: var(--accent-light);
}

.paywall-divider {
  margin: 4px 0;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-tertiary);
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.paywall-divider::before,
.paywall-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border-primary);
}

/* Pro active view */
.paywall-pro-view {
  display: flex;
  flex-direction: column;
}

.paywall-pro-info {
  padding: 24px 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.paywall-pro-info-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.paywall-pro-info-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.paywall-pro-info-value {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  font-family: 'SF Mono', 'Fira Mono', 'Consolas', monospace;
  letter-spacing: 0.02em;
}

.paywall-pro-actions {
  padding: 0 24px 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.paywall-btn-feature-request {
  width: 100%;
  height: 42px;
  background: transparent;
  color: var(--text-secondary);
  border: 1.5px solid var(--border-secondary);
  border-radius: 10px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
}

.paywall-btn-feature-request:hover {
  background: var(--bg-tertiary);
  border-color: var(--border-primary);
  color: var(--text-primary);
}

.paywall-btn-deactivate {
  width: 100%;
  height: 42px;
  background: transparent;
  color: var(--text-tertiary);
  border: 1.5px solid var(--border-secondary);
  border-radius: 10px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.paywall-btn-deactivate:hover {
  background: #fef2f2;
  border-color: #fecaca;
  color: #dc2626;
}

[data-theme="dark"] .paywall-btn-deactivate:hover {
  background: #450a0a;
  border-color: #7f1d1d;
  color: #fca5a5;
}

/* Spinner */
@keyframes paywall-spin {
  to { transform: rotate(360deg); }
}

.paywall-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,0.35);
  border-top-color: white;
  border-radius: 50%;
  animation: paywall-spin 0.65s linear infinite;
  flex-shrink: 0;
}

/* Success pop */
@keyframes license-pop {
  0%   { transform: scale(0.5); opacity: 0; }
  65%  { transform: scale(1.2); opacity: 1; }
  100% { transform: scale(1);   opacity: 1; }
}

.license-pop-anim {
  animation: license-pop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

/* Toast */
.license-toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: var(--bg-primary);
  border: 1px solid var(--border-primary);
  border-radius: 10px;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  box-shadow: var(--shadow-lg);
  z-index: 20000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  white-space: nowrap;
}

.license-toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

.license-toast-icon {
  color: #f59f00;
  flex-shrink: 0;
  display: flex;
}

.license-toast-cta {
  color: var(--accent-primary);
  font-weight: 600;
  cursor: pointer;
  background: none;
  border: none;
  font-family: inherit;
  font-size: 13px;
  padding: 0;
  margin-left: 4px;
}

.license-toast-cta:hover { text-decoration: underline; }
