/* ============================================
   CodeSnap — Main Styles
   ============================================ */

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

:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #12121a;
  --bg-tertiary: #1a1a2e;
  --text-primary: #e4e4e7;
  --text-secondary: #a1a1aa;
  --text-muted: #71717a;
  --border-color: #27272a;
  --accent: #8b5cf6;
  --accent-hover: #7c3aed;
  --radius: 8px;
  --radius-lg: 12px;
  --transition: 150ms ease;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ============================================
   Header
   ============================================ */

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-secondary);
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.logo svg {
  color: var(--accent);
}

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

/* ============================================
   Buttons
   ============================================ */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: white;
  flex: 1;
}

.btn-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(139, 92, 246, 0.4);
}

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

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

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}

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

/* ============================================
   Main Layout
   ============================================ */

.main {
  display: flex;
  min-height: calc(100vh - 57px);
}

/* ============================================
   Controls Panel
   ============================================ */

.controls-panel {
  width: 340px;
  min-width: 340px;
  height: calc(100vh - 57px);
  position: sticky;
  top: 57px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  padding: 24px 24px;
  overflow-y: auto;
  scrollbar-width: none;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.controls-panel::-webkit-scrollbar {
  display: none;
}

.panel-title {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.control-label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.control-select {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 8px 12px;
  font-family: inherit;
  font-size: 0.8125rem;
  cursor: pointer;
  outline: none;
  transition: border-color var(--transition);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2371717a' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

.control-select:hover {
  border-color: var(--text-muted);
}

.control-select:focus {
  border-color: var(--accent);
}

.control-input {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 8px 12px;
  font-family: inherit;
  font-size: 0.8125rem;
  outline: none;
  transition: border-color var(--transition);
}

.control-input:focus {
  border-color: var(--accent);
}

.control-input::placeholder {
  color: var(--text-muted);
}

/* Gradient Presets */

.gradient-presets {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.gradient-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}

.gradient-btn:hover {
  transform: scale(1.1);
}

.gradient-btn.active {
  border-color: white;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.2);
}

#custom-gradient-btn {
  background: conic-gradient(red, yellow, lime, aqua, blue, magenta, red);
}

.hidden-color-input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  width: 0;
  height: 0;
}

/* Button Group */

.btn-group {
  display: flex;
  gap: 4px;
  background: var(--bg-primary);
  padding: 3px;
  border-radius: var(--radius);
}

.btn-option {
  flex: 1;
  padding: 6px 8px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-option:hover {
  color: var(--text-secondary);
}

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

/* Range Slider */

.control-range {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: var(--bg-primary);
  border-radius: 2px;
  outline: none;
}

.control-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid var(--bg-secondary);
  transition: transform var(--transition);
}

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

.control-range::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid var(--bg-secondary);
}

.range-value {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* Toggle Switch */

.toggle {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
}

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

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-primary);
  border-radius: 10px;
  transition: var(--transition);
}

.toggle-slider::before {
  content: '';
  position: absolute;
  height: 14px;
  width: 14px;
  left: 3px;
  bottom: 3px;
  background: var(--text-muted);
  border-radius: 50%;
  transition: var(--transition);
}

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

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

/* Export Actions */

.export-actions {
  display: flex;
  gap: 8px;
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--border-color);
}

.export-actions .btn {
  font-size: 0.8rem;
  padding: 8px 12px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ============================================
   Preview Area
   ============================================ */

.preview-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.preview-area *::-webkit-scrollbar { display: none; }
.preview-area * { scrollbar-width: none; }

.preview-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  overflow: auto;
  background: var(--bg-primary);
  background-image:
    radial-gradient(circle at 1px 1px, rgba(255,255,255,0.03) 1px, transparent 0);
  background-size: 24px 24px;
}

/* ============================================
   Code Card (Exportable)
   ============================================ */

.code-card {
  display: inline-block;
}

.code-card-bg {
  padding: 32px;
  background: linear-gradient(135deg, #f97316, #ec4899);
  border-radius: 12px;
}

.code-window {
  background: #282c34;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 20px 68px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255,255,255,0.05);
  min-width: 400px;
  max-width: 600px;
}

.window-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  background: rgba(0, 0, 0, 0.15);
}

.window-dots {
  display: flex;
  gap: 8px;
}

.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.dot-red { background: #ff5f57; }
.dot-yellow { background: #febc2e; }
.dot-green { background: #28c840; }

.window-dots.hidden {
  visibility: hidden;
}

.window-title {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.4);
  font-family: 'Inter', sans-serif;
}

.code-body {
  padding: 20px;
  overflow-x: auto;
}

.code-body pre {
  margin: 0;
  padding: 0;
}

.code-body code {
  font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: 13px;
  line-height: 1.5;
  tab-size: 2;
  counter-reset: line;
  display: block;
  background: transparent !important;
  padding: 0 !important;
}

/* Line Numbers */

.code-body code.show-line-numbers .code-line {
  display: flex;
}

.code-body code.show-line-numbers .code-line::before {
  counter-increment: line;
  content: counter(line);
  display: inline-block;
  width: 2.5em;
  margin-right: 1.5em;
  text-align: right;
  color: rgba(255, 255, 255, 0.2);
  flex-shrink: 0;
  user-select: none;
}

/* ============================================
   Input Area
   ============================================ */

.input-area {
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  padding: 16px 24px;
}

.input-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

#code-input {
  width: 100%;
  min-height: 140px;
  max-height: 300px;
  resize: vertical;
  background: var(--bg-primary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 16px;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 0.8125rem;
  line-height: 1.6;
  outline: none;
  tab-size: 2;
  transition: border-color var(--transition);
}

#code-input:focus {
  border-color: var(--accent);
}

#code-input::placeholder {
  color: var(--text-muted);
}

/* ============================================
   Toast Notification
   ============================================ */

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  border: 1px solid var(--border-color);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  transform: translateY(100px);
  opacity: 0;
  transition: all 300ms ease;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 8px;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.toast.success {
  border-color: #22c55e;
}

/* ============================================
   Responsive
   ============================================ */

@media (max-width: 900px) {
  .main {
    flex-direction: column;
  }

  .controls-panel {
    width: 100%;
    min-width: unset;
    height: auto;
    position: static;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
    flex-direction: row;
    flex-wrap: wrap;
    gap: 12px;
    padding: 16px;
  }

  .panel-title {
    width: 100%;
  }

  .control-group {
    min-width: 140px;
    flex: 1;
  }

  .export-actions {
    width: 100%;
    margin-top: 0;
    padding-top: 0;
    border-top: none;
  }

  .preview-container {
    padding: 20px;
  }

  .code-window {
    min-width: unset;
    max-width: 100%;
  }
}
