/* ===== 基础重置 & 变量 ===== */
:root {
  --bg: #f5f5f7;
  --bg-panel: #ffffff;
  --bg-section: #fafafa;
  --bg-input: #f0f0f2;
  --border: #e2e2e6;
  --text: #1d1d1f;
  --text-secondary: #6e6e73;
  --accent: #0071e3;
  --accent-hover: #0062cc;
  --accent-light: rgba(0, 113, 227, 0.08);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --radius: 10px;
  --radius-sm: 6px;
  --transition: 0.2s ease;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans SC", sans-serif;
  --slider-track: #d1d1d6;
  --slider-fill: var(--accent);
  --code-bg: #1e1e2e;
  --code-text: #cdd6f4;
  --layer-active: var(--accent-light);
  --danger: #ff3b30;
  --success: #34c759;
}

[data-theme="dark"] {
  --bg: #1c1c1e;
  --bg-panel: #2c2c2e;
  --bg-section: #232326;
  --bg-input: #3a3a3c;
  --border: #3a3a3c;
  --text: #f5f5f7;
  --text-secondary: #98989d;
  --accent: #0a84ff;
  --accent-hover: #409cff;
  --accent-light: rgba(10, 132, 255, 0.12);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.3);
  --slider-track: #48484a;
  --code-bg: #11111b;
  --code-text: #cdd6f4;
}

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

html {
  font-size: 14px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background var(--transition), color var(--transition);
}

/* ===== 头部 ===== */
.header {
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  height: 52px;
  display: flex;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
  transition: background var(--transition), border-color var(--transition);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 1600px;
  margin: 0 auto;
}

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

.logo-icon {
  font-size: 1.4rem;
  color: var(--accent);
}

.logo h1 {
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.icon-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  cursor: pointer;
  font-size: 1rem;
  transition: all var(--transition);
  color: var(--text);
}

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

/* ===== 主布局 ===== */
.main {
  display: flex;
  flex: 1;
  max-width: 1600px;
  margin: 0 auto;
  width: 100%;
  gap: 0;
}

.panel-controls {
  width: 380px;
  min-width: 340px;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  height: calc(100vh - 52px);
  background: var(--bg-panel);
  transition: background var(--transition), border-color var(--transition);
}

.panel-preview {
  flex: 1;
  overflow-y: auto;
  height: calc(100vh - 52px);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ===== 通用区块 ===== */
.section {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  transition: border-color var(--transition);
}

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

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

.section-header h2 {
  font-size: 0.92rem;
  font-weight: 600;
}

/* ===== 按钮 ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  font-family: var(--font);
}

.btn-sm {
  padding: 5px 12px;
  font-size: 0.8rem;
}

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

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

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

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

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

.btn-danger:hover {
  background: rgba(255, 59, 48, 0.08);
}

/* ===== 预设网格 ===== */
.presets-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.preset-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-section);
  cursor: pointer;
  transition: all var(--transition);
  font-family: var(--font);
  color: var(--text);
}

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

.preset-btn.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.preset-preview {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  background: var(--bg-panel);
  transition: background var(--transition);
}

.preset-label {
  font-size: 0.7rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* ===== 阴影层列表 ===== */
.layers-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.layer-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  border: 1px solid transparent;
  user-select: none;
}

.layer-item:hover {
  background: var(--accent-light);
}

.layer-item.active {
  background: var(--accent-light);
  border-color: var(--accent);
}

.layer-item.dragging {
  opacity: 0.4;
}

.layer-item.drag-over {
  border-top: 2px solid var(--accent);
}

.layer-drag {
  cursor: grab;
  font-size: 0.9rem;
  color: var(--text-secondary);
  padding: 0 2px;
}

.layer-drag:active {
  cursor: grabbing;
}

.layer-swatch {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.layer-name {
  flex: 1;
  font-size: 0.82rem;
  font-weight: 500;
}

.layer-actions {
  display: flex;
  gap: 2px;
}

.layer-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.85rem;
  padding: 2px 5px;
  border-radius: 3px;
  color: var(--text-secondary);
  transition: all var(--transition);
}

.layer-btn:hover {
  background: var(--accent-light);
  color: var(--text);
}

.layer-btn.off {
  opacity: 0.4;
}

.layer-btn.delete:hover {
  background: rgba(255, 59, 48, 0.08);
  color: var(--danger);
}

/* ===== 控制面板 ===== */
.controls-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.hint-text {
  color: var(--text-secondary);
  font-size: 0.85rem;
  text-align: center;
  padding: 20px 0;
}

.control-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

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

.control-value {
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* 自定义滑块 */
.slider-wrapper {
  position: relative;
  height: 28px;
  display: flex;
  align-items: center;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: var(--slider-track);
  outline: none;
  transition: background var(--transition);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 3px solid var(--bg-panel);
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

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

input[type="range"]::-webkit-slider-thumb:active {
  transform: scale(1.25);
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 3px solid var(--bg-panel);
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

/* 颜色选择行 */
.color-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

input[type="color"] {
  -webkit-appearance: none;
  appearance: none;
  width: 36px;
  height: 28px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  padding: 0;
  background: none;
}

input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 2px;
}

input[type="color"]::-webkit-color-swatch {
  border: none;
  border-radius: 3px;
}

.color-hex {
  font-size: 0.82rem;
  font-family: "SF Mono", "Fira Code", monospace;
  color: var(--text-secondary);
  flex: 1;
}

/* 内阴影切换 */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0;
}

.toggle-label {
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.toggle-switch {
  position: relative;
  width: 40px;
  height: 22px;
}

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

.toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--slider-track);
  border-radius: 22px;
  transition: all var(--transition);
}

.toggle-slider::before {
  content: "";
  position: absolute;
  height: 16px;
  width: 16px;
  left: 3px;
  bottom: 3px;
  background: #fff;
  border-radius: 50%;
  transition: all var(--transition);
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

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

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

/* ===== 预览区 ===== */
.preview-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
  transition: background var(--transition), border-color var(--transition);
}

.preview-section .section-header {
  padding: 12px 16px;
  margin-bottom: 0;
  border-bottom: 1px solid var(--border);
}

.preview-tabs {
  display: flex;
  gap: 2px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  padding: 2px;
}

.tab-btn {
  padding: 4px 12px;
  border: none;
  background: none;
  border-radius: 4px;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all var(--transition);
  font-family: var(--font);
}

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

.tab-btn.active {
  background: var(--bg-panel);
  color: var(--accent);
  box-shadow: var(--shadow-sm);
}

.preview-area {
  flex: 1;
  position: relative;
  min-height: 320px;
}

.preview-bg-toggle {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  gap: 4px;
  z-index: 10;
}

.bg-btn {
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  cursor: pointer;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}

.bg-btn:hover, .bg-btn.active {
  border-color: var(--accent);
  background: var(--accent-light);
}

.preview-stage {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  transition: background 0.3s ease;
  border-radius: 0 0 var(--radius) var(--radius);
  background: #ffffff;
  position: absolute;
  inset: 0;
}

.preview-stage.dark {
  background: #1c1c1e;
}

.preview-stage.image {
  background: url('https://images.unsplash.com/photo-1557682250-33bd709cbe85?w=800&q=80') center/cover;
}

/* 预览元素 */
.preview-box {
  width: 160px;
  height: 160px;
  border-radius: 16px;
  background: var(--bg-panel);
  transition: box-shadow 0.15s ease, background var(--transition);
}

.preview-text {
  font-size: 3rem;
  font-weight: 700;
  color: var(--text);
  transition: text-shadow 0.15s ease;
  user-select: none;
  letter-spacing: -0.02em;
}

.preview-button {
  padding: 14px 40px;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: box-shadow 0.15s ease;
}

.preview-card {
  width: 280px;
  padding: 24px;
  border-radius: 16px;
  background: var(--bg-panel);
  transition: box-shadow 0.15s ease, background var(--transition);
}

.preview-card-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 8px;
}

.preview-card-text {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

/* ===== 代码输出 ===== */
.output-section {
  background: var(--bg-panel);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  transition: background var(--transition), border-color var(--transition);
}

.output-tabs {
  display: flex;
  gap: 2px;
  margin-bottom: 12px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  padding: 2px;
}

.output-tab {
  padding: 5px 14px;
  border: none;
  background: none;
  border-radius: 4px;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all var(--transition);
  font-family: var(--font);
}

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

.output-tab.active {
  background: var(--bg-panel);
  color: var(--accent);
  box-shadow: var(--shadow-sm);
}

.code-block-wrapper {
  position: relative;
}

.code-block {
  background: var(--code-bg);
  color: var(--code-text);
  padding: 16px;
  border-radius: var(--radius-sm);
  font-family: "SF Mono", "Fira Code", "JetBrains Mono", monospace;
  font-size: 0.82rem;
  line-height: 1.6;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
  min-height: 60px;
  transition: background var(--transition);
}

.btn-copy {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 5px 12px;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.7);
  font-size: 0.75rem;
  cursor: pointer;
  transition: all var(--transition);
  font-family: var(--font);
  display: flex;
  align-items: center;
  gap: 4px;
}

.btn-copy:hover {
  background: rgba(255,255,255,0.15);
  color: #fff;
}

.btn-copy.copied {
  background: var(--success);
  color: #fff;
  border-color: var(--success);
}

/* ===== Toast 提示 ===== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 24px;
  border-radius: 24px;
  font-size: 0.85rem;
  font-weight: 500;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  z-index: 1000;
  opacity: 0;
  transition: all 0.3s ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===== 底部 ===== */
.footer {
  text-align: center;
  padding: 16px;
  font-size: 0.78rem;
  color: var(--text-secondary);
  border-top: 1px solid var(--border);
  transition: border-color var(--transition);
}

.footer a {
  color: var(--accent);
  text-decoration: none;
}

.footer a:hover {
  text-decoration: underline;
}

/* ===== 响应式 ===== */
@media (max-width: 900px) {
  .main {
    flex-direction: column;
  }

  .panel-controls {
    width: 100%;
    min-width: unset;
    height: auto;
    max-height: 55vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .panel-preview {
    height: auto;
    min-height: 60vh;
  }

  .presets-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

@media (max-width: 600px) {
  .presets-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .preview-stage {
    padding: 20px;
  }

  .preview-box {
    width: 120px;
    height: 120px;
  }

  .preview-text {
    font-size: 2rem;
  }

  .preview-card {
    width: 220px;
    padding: 16px;
  }
}

/* ===== 滚动条 ===== */
::-webkit-scrollbar {
  width: 6px;
}

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

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}
