/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: #0f1115;
  color: #e5e7eb;
  height: 100vh;
  overflow: hidden;
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; font-size: inherit; color: inherit; }
input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* ===== Layout ===== */
.topbar {
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: #161922;
  border-bottom: 1px solid #262a36;
  flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-icon { color: #818cf8; }
.brand h1 { font-size: 16px; font-weight: 600; margin: 0; letter-spacing: 0.2px; }
.subtitle { font-size: 12px; color: #6b7280; padding-left: 6px; border-left: 1px solid #2a2f3d; margin-left: 4px; }
.topbar-actions { display: flex; gap: 8px; }

.layout {
  display: grid;
  grid-template-columns: 320px 1fr 280px;
  height: calc(100vh - 52px - 64px);
}

/* ===== Panel ===== */
.panel {
  background: #14171f;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #2a2f3d transparent;
}
.panel::-webkit-scrollbar { width: 6px; }
.panel::-webkit-scrollbar-thumb { background: #2a2f3d; border-radius: 3px; }
.panel-left { border-right: 1px solid #262a36; }
.panel-right { border-left: 1px solid #262a36; transition: transform 0.25s ease; }
.panel-right.collapsed { transform: translateX(100%); position: absolute; right: 0; }

.panel-section { padding: 16px 18px; border-bottom: 1px solid #1f2330; }
.section-title { font-size: 11px; text-transform: uppercase; letter-spacing: 1.2px; color: #6b7280; margin: 0 0 12px; font-weight: 600; }

/* ===== Field ===== */
.field { margin-bottom: 12px; }
.field:last-child { margin-bottom: 0; }
.field-label { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: #9ca3af; margin-bottom: 6px; }
.hint { font-size: 11px; color: #6b7280; font-weight: normal; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 12px;
  border: 1px solid #2a2f3d;
  background: #1c2030;
  color: #e5e7eb;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  transition: all 0.15s ease;
  white-space: nowrap;
}
.btn:hover { background: #252a3a; border-color: #3a4054; }
.btn:active { transform: translateY(1px); }
.btn-sm { padding: 4px 8px; font-size: 11px; }
.btn-icon { width: 28px; height: 28px; padding: 0; font-size: 14px; }
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: #1c2030; }
.btn-primary { background: linear-gradient(180deg, #6366f1, #4f46e5); border-color: #4f46e5; }
.btn-primary:hover { background: linear-gradient(180deg, #7376f3, #5d54ea); border-color: #5d54ea; }
.btn-secondary { background: #1c2030; }
.btn-danger { background: #2a1a1f; color: #f87171; border-color: #4a1f25; }
.btn-danger:hover { background: #3a1f24; color: #fca5a5; }

/* ===== Color Picker ===== */
.color-row { display: flex; gap: 6px; align-items: center; }
.color-row input[type=color] {
  width: 36px; height: 32px;
  border: 1px solid #2a2f3d;
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
  padding: 2px;
}
.color-row input[type=text] {
  flex: 1;
  padding: 6px 8px;
  background: #0f1218;
  border: 1px solid #2a2f3d;
  border-radius: 6px;
  font-family: 'SF Mono', Monaco, monospace;
  font-size: 12px;
  text-transform: uppercase;
}
.color-row input[type=text]:focus { outline: none; border-color: #6366f1; }

/* ===== Range ===== */
input[type=range] {
  -webkit-appearance: none;
  width: 100%;
  height: 4px;
  background: #2a2f3d;
  border-radius: 2px;
  outline: none;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  background: #6366f1;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(99,102,241,0.4);
}
input[type=range]::-moz-range-thumb {
  width: 16px; height: 16px;
  background: #6366f1;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid #fff;
}
.range-row { display: flex; flex-direction: column; gap: 8px; }

/* ===== Chips ===== */
.radius-presets, .size-presets, .canvas-bg-toggles { display: flex; gap: 4px; flex-wrap: wrap; }
.chip {
  padding: 4px 10px;
  background: #1c2030;
  border: 1px solid #2a2f3d;
  border-radius: 14px;
  color: #9ca3af;
  font-size: 11px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.chip:hover { color: #e5e7eb; border-color: #3a4054; }
.chip.active { background: #6366f1; color: #fff; border-color: #6366f1; }

/* ===== Border & Shadow ===== */
.border-row, .shadow-row { display: flex; gap: 6px; align-items: center; }
.border-row input[type=color], .shadow-row input[type=color] {
  width: 32px; height: 28px;
  border: 1px solid #2a2f3d;
  border-radius: 4px;
  background: transparent;
  cursor: pointer;
  padding: 2px;
}
.border-row input[type=number], .shadow-row select {
  padding: 5px 6px;
  background: #0f1218;
  border: 1px solid #2a2f3d;
  border-radius: 4px;
  font-size: 12px;
  flex: 1;
}
.border-row input[type=checkbox], .shadow-row input[type=checkbox] { width: 16px; height: 16px; accent-color: #6366f1; }
.unit { color: #6b7280; font-size: 11px; }

/* ===== Size Input ===== */
.size-input-row { display: flex; gap: 6px; align-items: center; }
.size-input-row input {
  flex: 1;
  padding: 6px 8px;
  background: #0f1218;
  border: 1px solid #2a2f3d;
  border-radius: 6px;
  font-size: 12px;
  text-align: center;
}
.size-input-row input:focus { outline: none; border-color: #6366f1; }
.size-input-row .unit { padding: 0 2px; }

/* ===== Tabs ===== */
.tabs { display: flex; gap: 2px; background: #0f1218; border-radius: 6px; padding: 3px; margin-bottom: 12px; }
.tab {
  flex: 1;
  padding: 6px 8px;
  background: transparent;
  border: none;
  color: #6b7280;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  transition: all 0.15s ease;
}
.tab:hover { color: #e5e7eb; }
.tab.active { background: #1c2030; color: #fff; }

.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ===== Emoji ===== */
.emoji-input { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.emoji-input input {
  flex: 1;
  padding: 8px 10px;
  background: #0f1218;
  border: 1px solid #2a2f3d;
  border-radius: 6px;
  font-size: 18px;
  text-align: center;
}
.emoji-input input:focus { outline: none; border-color: #6366f1; }
.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  max-height: 180px;
  overflow-y: auto;
  padding: 4px;
  background: #0f1218;
  border-radius: 6px;
  scrollbar-width: thin;
  scrollbar-color: #2a2f3d transparent;
}
.emoji-grid::-webkit-scrollbar { width: 4px; }
.emoji-grid::-webkit-scrollbar-thumb { background: #2a2f3d; border-radius: 2px; }
.emoji-item {
  width: 100%;
  aspect-ratio: 1;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.1s ease;
}
.emoji-item:hover { background: #1c2030; border-color: #3a4054; }
.emoji-item.active { background: #6366f1; border-color: #6366f1; }

/* ===== Image Upload ===== */
.upload-area {
  position: relative;
  border: 2px dashed #2a2f3d;
  border-radius: 8px;
  background: #0f1218;
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 10px;
  cursor: pointer;
  transition: all 0.15s ease;
  overflow: hidden;
}
.upload-area:hover, .upload-area.dragover { border-color: #6366f1; background: #1a1d2a; }
.upload-inner { text-align: center; color: #6b7280; }
.upload-inner p { margin: 6px 0 2px; color: #9ca3af; font-size: 12px; }
.upload-inner svg { color: #4b5263; }
.image-preview {
  display: none;
  max-width: 100%;
  max-height: 140px;
  border-radius: 4px;
}
.upload-area.has-image .upload-inner { display: none; }
.upload-area.has-image .image-preview { display: block; }

/* ===== Form ===== */
textarea, input[type=text], input[type=number], select {
  width: 100%;
  padding: 6px 8px;
  background: #0f1218;
  border: 1px solid #2a2f3d;
  border-radius: 6px;
  font-size: 12px;
  color: #e5e7eb;
  transition: border-color 0.15s ease;
}
textarea { font-family: 'SF Mono', Monaco, monospace; resize: vertical; }
textarea:focus, input[type=text]:focus, input[type=number]:focus, select:focus { outline: none; border-color: #6366f1; }
select { cursor: pointer; }

/* ===== Canvas Stage ===== */
.canvas-wrap {
  display: flex;
  flex-direction: column;
  background: #0f1115;
  min-width: 0;
}
.canvas-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  background: #14171f;
  border-bottom: 1px solid #262a36;
  flex-shrink: 0;
}
.zoom-controls { display: flex; align-items: center; gap: 6px; }
.zoom-controls span { font-size: 12px; color: #9ca3af; min-width: 40px; text-align: center; }

.canvas-stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  padding: 30px;
}
.canvas-bg {
  position: absolute;
  inset: 0;
  background-color: #0a0c12;
}
.canvas-bg.bg-checker {
  background-image:
    linear-gradient(45deg, #1a1d2a 25%, transparent 25%),
    linear-gradient(-45deg, #1a1d2a 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #1a1d2a 75%),
    linear-gradient(-45deg, transparent 75%, #1a1d2a 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
}
.canvas-bg.bg-light { background-color: #f3f4f6; }
.canvas-bg.bg-dark { background-color: #0a0c12; }
.canvas-bg.bg-white { background-color: #ffffff; }

.icon-render {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.canvas-info {
  padding: 8px 16px;
  text-align: center;
  font-size: 11px;
  color: #6b7280;
  background: #14171f;
  border-top: 1px solid #262a36;
  flex-shrink: 0;
}

/* ===== History ===== */
.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px 8px;
}
.history-header .section-title { margin: 0; }
.history-list { padding: 0 12px 12px; }
.history-empty {
  text-align: center;
  color: #4b5263;
  font-size: 12px;
  padding: 40px 20px;
}
.history-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  background: #1c2030;
  border: 1px solid #2a2f3d;
  border-radius: 6px;
  margin-bottom: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.history-item:hover { border-color: #6366f1; }
.history-thumb {
  width: 40px;
  height: 40px;
  border-radius: 6px;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
}
.history-thumb img { width: 100%; height: 100%; object-fit: contain; }
.history-meta { flex: 1; min-width: 0; }
.history-title {
  font-size: 12px;
  color: #e5e7eb;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.history-time { font-size: 10px; color: #6b7280; margin-top: 2px; }
.history-delete {
  background: transparent;
  border: none;
  color: #6b7280;
  width: 24px;
  height: 24px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.history-delete:hover { background: #2a1a1f; color: #f87171; }

/* ===== Export Bar ===== */
.export-bar {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: #161922;
  border-top: 1px solid #262a36;
  padding: 0 20px;
  flex-shrink: 0;
}

.export-scale {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  background: #0f1218;
  border: 1px solid #2a2f3d;
  border-radius: 6px;
  height: 32px;
}
.export-scale .hint {
  font-size: 10px;
  color: #6b7280;
  margin-right: 2px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.scale-btn {
  background: transparent;
  border: 1px solid transparent;
  color: #9ca3af;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}
.scale-btn:hover { color: #e5e7eb; background: #1c2030; }
.scale-btn.active { background: #6366f1; color: #fff; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #1c2030;
  color: #e5e7eb;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 13px;
  border: 1px solid #2a2f3d;
  box-shadow: 0 10px 30px rgba(0,0,0,0.3);
  opacity: 0;
  transition: all 0.25s ease;
  pointer-events: none;
  z-index: 100;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.success { border-color: #10b981; }
.toast.error { border-color: #ef4444; }

/* ===== Responsive ===== */
@media (max-width: 1100px) {
  .layout { grid-template-columns: 280px 1fr 240px; }
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 260px 1fr; }
  .panel-right { display: none; }
}

/* ===== Icon rendering helpers ===== */
.icon-render .icon-content {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  line-height: 1;
  user-select: none;
}
.icon-render img,
.icon-render svg {
  max-width: 100%;
  max-height: 100%;
  display: block;
}
