/* ========== 基础变量 ========== */
:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-hover: #f0f0f2;
  --text: #1d1d1f;
  --text-secondary: #6e6e73;
  --border: #d2d2d7;
  --accent: #0071e3;
  --accent-hover: #0077ed;
  --code-bg: #1e1e2e;
  --code-text: #cdd6f4;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.12);
  --radius: 14px;
  --transition: 0.2s ease;
  --handle-size: 18px;
  --preview-bg: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

[data-theme="dark"] {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-hover: #21262d;
  --text: #e6edf3;
  --text-secondary: #8b949e;
  --border: #30363d;
  --accent: #58a6ff;
  --accent-hover: #79c0ff;
  --code-bg: #0d1117;
  --code-text: #c9d1d9;
  --shadow: 0 2px 12px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.4);
}

/* ========== 重置 ========== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans SC", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background var(--transition), color var(--transition);
}

/* ========== 头部 ========== */
.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.icon-btn {
  background: var(--surface-hover);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  padding: 6px 10px;
  font-size: 1.1rem;
  transition: background var(--transition);
  position: relative;
  width: 40px;
  height: 36px;
}

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

.icon-btn .icon {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  transition: opacity var(--transition);
}

[data-theme="dark"] .icon.sun { opacity: 0; }
[data-theme="dark"] .icon.moon { opacity: 1; }
:not([data-theme="dark"]) .icon.sun { opacity: 1; }
:not([data-theme="dark"]) .icon.moon { opacity: 0; }

/* ========== 主布局 ========== */
.main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 24px;
  align-items: start;
}

@media (max-width: 900px) {
  .main {
    grid-template-columns: 1fr;
  }
}

/* ========== 卡片 ========== */
.preview-card,
.code-card,
.control-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: background var(--transition), border-color var(--transition);
}

.preview-card h2,
.code-card h2,
.control-card h2 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.preview-header,
.code-header,
.control-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 12px;
}

/* ========== 预览区 ========== */
.preview-area {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 20px;
  min-height: 360px;
  background:
    radial-gradient(circle at 20px 20px, var(--border) 1px, transparent 1px);
  background-size: 20px 20px;
}

.shape-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.shape-box {
  width: 100%;
  height: 100%;
  background: var(--preview-bg);
  position: relative;
  transition: border-radius 0.15s ease;
  cursor: default;
}

/* ========== 拖拽手柄 ========== */
.handle {
  position: absolute;
  width: var(--handle-size);
  height: var(--handle-size);
  border-radius: 50%;
  background: #fff;
  border: 2.5px solid var(--accent);
  cursor: pointer;
  z-index: 10;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

.handle:hover, .handle.active {
  transform: scale(1.25);
  box-shadow: 0 2px 8px rgba(0,113,227,0.4);
}

.handle-tl { top: calc(var(--handle-size) / -2); left: calc(var(--handle-size) / -2); }
.handle-tr { top: calc(var(--handle-size) / -2); right: calc(var(--handle-size) / -2); }
.handle-br { bottom: calc(var(--handle-size) / -2); right: calc(var(--handle-size) / -2); }
.handle-bl { bottom: calc(var(--handle-size) / -2); left: calc(var(--handle-size) / -2); }

/* ========== 单位切换 ========== */
.unit-toggle {
  display: flex;
  background: var(--surface-hover);
  border-radius: 8px;
  padding: 2px;
  border: 1px solid var(--border);
}

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

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

/* ========== 响应式预览 ========== */
.responsive-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px 16px;
  border-top: 1px solid var(--border);
}

.responsive-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-right: 4px;
}

.resp-btn {
  border: 1px solid var(--border);
  background: var(--surface-hover);
  border-radius: 8px;
  padding: 4px 10px;
  cursor: pointer;
  font-size: 1rem;
  transition: all var(--transition);
}

.resp-btn.active {
  border-color: var(--accent);
  background: rgba(0,113,227,0.1);
}

/* ========== 代码输出 ========== */
.code-block {
  margin: 0 20px 20px;
  padding: 16px;
  background: var(--code-bg);
  border-radius: 10px;
  overflow-x: auto;
  font-family: "SF Mono", "Fira Code", "Cascadia Code", Menlo, monospace;
  font-size: 0.85rem;
  line-height: 1.6;
  color: var(--code-text);
}

.code-block .prop { color: #89b4fa; }
.code-block .val { color: #a6e3a1; }
.code-block .punct { color: #6c7086; }

.copy-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 6px 16px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition);
}

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

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

.control-card {
  padding-bottom: 8px;
}

.control-card h2 {
  padding: 16px 20px 0;
}

.control-header h2 {
  padding: 0;
}

/* ========== 滑块 ========== */
.sliders, .morph-controls {
  padding: 8px 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.slider-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.slider-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.82rem;
}

.corner-name {
  color: var(--text-secondary);
  font-weight: 500;
}

.corner-value {
  color: var(--text);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  min-width: 32px;
  text-align: right;
}

.slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: var(--border);
  outline: none;
  transition: background var(--transition);
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
  transition: transform 0.1s;
}

.slider::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}

.slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

/* ========== 联动模式 ========== */
.link-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 0.82rem;
  color: var(--text-secondary);
  user-select: none;
}

.link-toggle input {
  display: none;
}

.link-icon {
  font-size: 1rem;
  opacity: 0.4;
  transition: opacity var(--transition);
}

.link-toggle input:checked ~ .link-icon {
  opacity: 1;
}

.link-label {
  font-weight: 500;
}

/* ========== 预设 ========== */
.presets-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  padding: 12px 20px 16px;
}

.preset-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 6px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-hover);
  cursor: pointer;
  transition: all var(--transition);
  font-size: 0.72rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.preset-btn:hover {
  border-color: var(--accent);
  background: rgba(0,113,227,0.05);
}

.preset-btn.active {
  border-color: var(--accent);
  background: rgba(0,113,227,0.1);
  color: var(--accent);
}

.preset-shape {
  width: 36px;
  height: 36px;
  background: var(--preview-bg);
  transition: border-radius 0.3s ease;
}

.preset-name {
  white-space: nowrap;
}

/* ========== 变形动画 ========== */
.morph-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 6px 16px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition);
}

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

.morph-btn.playing {
  background: #e74c3c;
}

.shape-box.morphing {
  transition: border-radius var(--morph-speed, 1s) ease-in-out;
}

/* ========== 底部 ========== */
.footer {
  text-align: center;
  padding: 24px;
  color: var(--text-secondary);
  font-size: 0.82rem;
}

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

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

/* ========== 动画 ========== */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.preview-card, .code-card, .control-card {
  animation: fadeIn 0.4s ease both;
}

.control-card:nth-child(2) { animation-delay: 0.05s; }
.control-card:nth-child(3) { animation-delay: 0.1s; }
