/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0e0e11;
  --bg-elev: #17171c;
  --bg-elev2: #1f1f27;
  --bg-hover: #26262f;
  --border: #2a2a35;
  --border-strong: #3a3a48;
  --text: #e8e8ed;
  --text-dim: #9a9aaa;
  --text-faint: #6a6a78;
  --accent: #6c5ce7;
  --accent-hover: #7c6cf7;
  --accent-soft: rgba(108, 92, 231, 0.15);
  --success: #22c55e;
  --danger: #ef4444;
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 14px;
  --shadow: 0 4px 24px rgba(0,0,0,0.3);
  --transition: 150ms ease;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

button { cursor: pointer; border: none; background: none; color: inherit; font: inherit; }
input { font: inherit; color: inherit; }

/* ===== App layout ===== */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ===== Header ===== */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 60px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
  flex-shrink: 0;
}

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

.logo-icon {
  width: 28px;
  height: 28px;
  color: var(--accent);
}
.logo-icon svg { width: 100%; height: 100%; }

.header h1 {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

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

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  transition: all var(--transition);
  white-space: nowrap;
}
.btn svg { width: 16px; height: 16px; flex-shrink: 0; }

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

.btn-secondary {
  background: var(--bg-elev2);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--bg-hover); border-color: var(--border-strong); }

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

.btn-full { width: 100%; justify-content: center; }

/* ===== Dropdown ===== */
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 180px;
  background: var(--bg-elev2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 4px;
  z-index: 100;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition: all var(--transition);
}
.dropdown.open .dropdown-menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}
.dropdown-menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-dim);
  transition: all var(--transition);
}
.dropdown-menu button:hover {
  background: var(--bg-hover);
  color: var(--text);
}

/* ===== Main ===== */
.main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ===== Panels ===== */
.panel {
  background: var(--bg);
}

.editor-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  min-width: 0;
}

.side-panel {
  width: 340px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  background: var(--bg-elev);
}

/* ===== Preview ===== */
.preview-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  min-height: 300px;
  background:
    linear-gradient(45deg, #1a1a22 25%, transparent 25%),
    linear-gradient(-45deg, #1a1a22 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #1a1a22 75%),
    linear-gradient(-45deg, transparent 75%, #1a1a22 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  background-color: #141418;
}

.preview-wrapper {
  position: relative;
  width: 100%;
  max-width: 600px;
  aspect-ratio: 16 / 10;
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.preview-canvas {
  width: 100%;
  height: 100%;
  transition: background var(--transition);
}

.preview-controls {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  gap: 4px;
}

.preview-toggle {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.5);
  border-radius: var(--radius-sm);
  color: #fff;
  transition: all var(--transition);
  backdrop-filter: blur(4px);
}
.preview-toggle svg { width: 16px; height: 16px; }
.preview-toggle:hover { background: rgba(0,0,0,0.7); }
.preview-toggle.active { background: var(--accent); }

/* ===== Controls area ===== */
.controls-area {
  padding: 20px 24px 24px;
  border-top: 1px solid var(--border);
  background: var(--bg-elev);
}

/* ===== Tabs ===== */
.tabs {
  display: flex;
  gap: 2px;
  background: var(--bg-elev2);
  border-radius: var(--radius);
  padding: 3px;
  margin-bottom: 16px;
}

.tab {
  flex: 1;
  padding: 8px 12px;
  border-radius: calc(var(--radius) - 2px);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-dim);
  transition: all var(--transition);
}
.tab:hover { color: var(--text); }
.tab.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 8px rgba(108, 92, 231, 0.3);
}

/* ===== Type options ===== */
.type-options { margin-bottom: 16px; }
.option-group { display: none; }
.option-group.active { display: block; }

.option-label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-dim);
  margin-bottom: 8px;
  margin-top: 12px;
}
.option-label:first-child { margin-top: 0; }

/* Angle control */
.angle-control {
  display: flex;
  align-items: center;
  gap: 12px;
}

.angle-wheel {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--bg-elev2);
  border: 2px solid var(--border);
  position: relative;
  cursor: pointer;
  flex-shrink: 0;
  transition: border-color var(--transition);
}
.angle-wheel:hover { border-color: var(--accent); }

.angle-pointer {
  position: absolute;
  top: 4px;
  left: 50%;
  width: 2px;
  height: calc(50% - 4px);
  background: var(--accent);
  transform-origin: bottom center;
  border-radius: 1px;
  pointer-events: none;
}

.angle-center-dot {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 6px;
  height: 6px;
  background: var(--accent);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.input-number {
  width: 64px;
  padding: 6px 8px;
  background: var(--bg-elev2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  text-align: center;
  font-size: 14px;
  font-weight: 500;
  outline: none;
  transition: border-color var(--transition);
}
.input-number:focus { border-color: var(--accent); }

.angle-unit {
  font-size: 14px;
  color: var(--text-dim);
  font-weight: 500;
}

/* Shape picker */
.shape-picker {
  display: flex;
  gap: 8px;
}

.shape-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: var(--bg-elev2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 13px;
  transition: all var(--transition);
}
.shape-btn svg { width: 18px; height: 18px; }
.shape-btn:hover { border-color: var(--border-strong); color: var(--text); }
.shape-btn.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

/* Position grid */
.position-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  max-width: 120px;
}

.position-grid button {
  width: 36px;
  height: 36px;
  background: var(--bg-elev2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}
.position-grid button:hover {
  border-color: var(--border-strong);
  background: var(--bg-hover);
}
.position-grid button.active {
  background: var(--accent);
  border-color: var(--accent);
}

/* ===== Gradient bar ===== */
.gradient-bar-section { margin-bottom: 16px; }

.gradient-bar {
  position: relative;
  height: 32px;
  border-radius: var(--radius);
  cursor: crosshair;
  user-select: none;
  overflow: visible;
}

.gradient-bar-preview {
  width: 100%;
  height: 100%;
  border-radius: var(--radius);
  border: 2px solid var(--border);
  pointer-events: none;
}

/* Color stop handles */
.stop-handle {
  position: absolute;
  top: 50%;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 3px solid #fff;
  transform: translate(-50%, -50%);
  cursor: grab;
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
  z-index: 1;
}
.stop-handle:hover {
  transform: translate(-50%, -50%) scale(1.15);
  box-shadow: 0 2px 10px rgba(0,0,0,0.5);
}
.stop-handle.active {
  border-color: var(--accent);
  transform: translate(-50%, -50%) scale(1.2);
  z-index: 2;
}
.stop-handle.dragging { cursor: grabbing; }

.stops-hint {
  font-size: 11px;
  color: var(--text-faint);
  margin-top: 8px;
  text-align: center;
}

/* ===== Stops list ===== */
.stops-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.stop-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px 4px 4px;
  background: var(--bg-elev2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: all var(--transition);
}
.stop-item.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.stop-color-wrap {
  position: relative;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  cursor: pointer;
}
.stop-color-wrap input[type="color"] {
  position: absolute;
  top: -4px;
  left: -4px;
  width: calc(100% + 8px);
  height: calc(100% + 8px);
  border: none;
  cursor: pointer;
  opacity: 0;
}

.stop-pos {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-dim);
  min-width: 32px;
  text-align: right;
}

.stop-remove {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-faint);
  font-size: 14px;
  transition: all var(--transition);
}
.stop-remove:hover {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
}

/* ===== Side panel ===== */
.side-section {
  padding: 20px;
  border-bottom: 1px solid var(--border);
}

.side-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 14px;
}

/* Presets grid */
.presets-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  max-height: 340px;
  overflow-y: auto;
  padding-right: 4px;
}

.preset-item {
  aspect-ratio: 16 / 9;
  border-radius: var(--radius);
  cursor: pointer;
  border: 2px solid transparent;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}
.preset-item:hover {
  border-color: var(--border-strong);
  transform: scale(1.02);
}
.preset-item.active {
  border-color: var(--accent);
}

.preset-label {
  position: absolute;
  bottom: 4px;
  left: 4px;
  right: 4px;
  font-size: 10px;
  font-weight: 500;
  color: rgba(255,255,255,0.85);
  text-shadow: 0 1px 3px rgba(0,0,0,0.5);
  text-align: center;
}

/* Code section */
.code-section { flex: 1; display: flex; flex-direction: column; }

.code-output {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  overflow: auto;
  margin-bottom: 12px;
  min-height: 80px;
}

.code-output pre {
  margin: 0;
  font-family: "SF Mono", "Fira Code", "JetBrains Mono", monospace;
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-dim);
  white-space: pre-wrap;
  word-break: break-all;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  padding: 10px 20px;
  background: var(--bg-elev2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  box-shadow: var(--shadow);
  opacity: 0;
  visibility: hidden;
  transition: all 0.25s ease;
  z-index: 1000;
  pointer-events: none;
}
.toast.show {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

/* ===== Responsive ===== */
@media (max-width: 900px) {
  .main { flex-direction: column; }
  .editor-panel { border-right: none; border-bottom: 1px solid var(--border); }
  .side-panel { width: 100%; }
  .preview-area { min-height: 200px; padding: 16px; }
}
