/* ===== CSS Variables ===== */
:root {
  --bg-primary: #0f0f1a;
  --bg-secondary: #16213e;
  --bg-tertiary: #1a1a2e;
  --bg-card: #1c2541;
  --bg-input: #0f3460;
  --text-primary: #e8e8e8;
  --text-secondary: #a0a0b8;
  --text-muted: #6b6b80;
  --accent: #4cc9f0;
  --accent-hover: #3ab5db;
  --accent-glow: rgba(76, 201, 240, 0.25);
  --border: rgba(255, 255, 255, 0.08);
  --border-focus: rgba(76, 201, 240, 0.5);
  --danger: #ff6b6b;
  --success: #51cf66;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.4);
  --transition: 0.2s ease;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: 'Segoe UI', 'Microsoft YaHei', sans-serif;
  font-size: 13px;
  color: var(--text-primary);
  background: var(--bg-primary);
  -webkit-font-smoothing: antialiased;
}

/* ===== Title Bar ===== */
.titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 38px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  -webkit-app-region: drag;
  user-select: none;
  flex-shrink: 0;
}

.titlebar-drag {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-left: 14px;
  height: 100%;
}

.app-icon {
  font-size: 16px;
  color: var(--accent);
}

.lang-toggle {
  width: 28px;
  height: 24px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 10px;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-app-region: no-drag;
  margin-left: 4px;
}

.lang-toggle:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(76, 201, 240, 0.08);
}

.about-btn {
  width: 28px;
  height: 24px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-app-region: no-drag;
}

.about-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(76, 201, 240, 0.08);
}

/* ===== About Modal ===== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.modal-overlay.active {
  display: flex;
}

.modal-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px 32px;
  min-width: 320px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
  text-align: center;
}

.modal-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 20px;
}

.modal-body {
  margin-bottom: 24px;
}

.modal-line {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.modal-label {
  color: var(--text-muted);
  margin-right: 8px;
}

.modal-close {
  padding: 8px 32px;
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  background: rgba(76, 201, 240, 0.1);
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}

.modal-close:hover {
  background: var(--accent);
  color: var(--bg-primary);
}

.app-title {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
}

.titlebar-buttons {
  display: flex;
  height: 100%;
  -webkit-app-region: no-drag;
}

.titlebar-btn {
  width: 46px;
  height: 100%;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 14px;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}

.titlebar-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
}

.titlebar-btn#btn-close:hover {
  background: var(--danger);
  color: white;
}

/* ===== Layout ===== */
.layout {
  display: flex;
  height: calc(100vh - 38px);
}

/* ===== Sidebar ===== */
.sidebar {
  width: 340px;
  min-width: 280px;
  max-width: 420px;
  background: var(--bg-tertiary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: width var(--transition), min-width var(--transition), opacity var(--transition);
  overflow: hidden;
}

.sidebar.collapsed {
  width: 0;
  min-width: 0;
  border-right: none;
}

/* Sidebar toggle button (shown when sidebar is collapsed, lives in toolbar-left) */
.sidebar-toggle {
  display: none;
  color: var(--accent);
  font-size: 14px;
  min-width: 36px;
  padding: 6px 10px;
}

.sidebar-toggle:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(76, 201, 240, 0.1);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-header h2 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
}

.collapse-btn {
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 11px;
  transition: all var(--transition);
  flex-shrink: 0;
}

.collapse-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px 24px;
}

.sidebar-content::-webkit-scrollbar {
  width: 6px;
}

.sidebar-content::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar-content::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 3px;
}

.sidebar-content::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* ===== Control Groups ===== */
.control-group {
  margin-bottom: 16px;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: 14px;
  border: 1px solid var(--border);
  transition: border-color var(--transition);
}

.control-group:hover {
  border-color: rgba(255, 255, 255, 0.12);
}

.control-group h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--accent);
  margin-bottom: 12px;
  font-weight: 600;
}

/* ===== Controls ===== */
.control-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.control-row:last-child {
  margin-bottom: 0;
}

.control-row label {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.control-row input[type="range"] {
  width: 130px;
}

/* Textarea */
textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 8px 10px;
  font-size: 12px;
  font-family: inherit;
  resize: vertical;
  outline: none;
  transition: border-color var(--transition);
}

textarea:focus {
  border-color: var(--border-focus);
}

/* Select */
select {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 6px 10px;
  font-size: 12px;
  font-family: inherit;
  outline: none;
  cursor: pointer;
  transition: border-color var(--transition);
  appearance: auto;
}

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

/* Range Slider */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  background: var(--bg-input);
  border-radius: 3px;
  outline: none;
  cursor: pointer;
  transition: background var(--transition);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 0 6px var(--accent-glow);
  transition: transform var(--transition), box-shadow var(--transition);
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.15);
  box-shadow: 0 0 10px var(--accent-glow);
}

input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: none;
  box-shadow: 0 0 6px var(--accent-glow);
}

/* Checkbox */
input[type="checkbox"] {
  accent-color: var(--accent);
  width: 14px;
  height: 14px;
  cursor: pointer;
}

/* Color Picker */
.color-picker-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
}

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

input[type="color"]:hover {
  border-color: var(--accent);
}

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

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

.color-hex {
  font-size: 11px;
  font-family: 'Consolas', 'Courier New', monospace;
  color: var(--text-muted);
  min-width: 60px;
}

/* ===== Canvas Area ===== */
.canvas-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
  min-width: 0;
}

/* Toolbar */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.toolbar-left, .toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.toolbar-center {
  flex: 1;
  text-align: center;
}

.tool-btn {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  transition: all var(--transition);
  font-family: inherit;
}

.tool-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(76, 201, 240, 0.08);
}

.image-info {
  font-size: 12px;
  color: var(--text-muted);
  font-family: 'Consolas', 'Courier New', monospace;
}

.zoom-level {
  font-size: 12px;
  color: var(--text-secondary);
  min-width: 48px;
  text-align: center;
  font-family: 'Consolas', monospace;
}

/* Canvas Container */
.canvas-container {
  flex: 1;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  position: relative;
  background:
    radial-gradient(circle at center, rgba(76, 201, 240, 0.03) 0%, transparent 70%),
    repeating-conic-gradient(rgba(255,255,255,0.02) 0% 25%, transparent 0% 50%) 0 0 / 20px 20px;
}

#preview-canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  transition: transform var(--transition);
}

/* Empty State */
.empty-state {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  color: var(--text-muted);
  pointer-events: none;
}

.empty-icon {
  font-size: 56px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-state p {
  font-size: 15px;
  color: var(--text-secondary);
}

.empty-state strong {
  color: var(--accent);
}

.empty-sub {
  font-size: 12px;
  margin-top: 6px;
  color: var(--text-muted);
}

/* Export Bar */
.export-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.export-btn {
  padding: 10px 28px;
  border: none;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  font-family: inherit;
  letter-spacing: 0.3px;
}

.export-png {
  background: linear-gradient(135deg, var(--accent), #3a8fbf);
  color: white;
  box-shadow: 0 2px 12px rgba(76, 201, 240, 0.3);
}

.export-png:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 20px rgba(76, 201, 240, 0.4);
}

.export-jpg {
  background: linear-gradient(135deg, #51cf66, #3da54d);
  color: white;
  box-shadow: 0 2px 12px rgba(81, 207, 102, 0.3);
}

.export-jpg:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 20px rgba(81, 207, 102, 0.4);
}

/* Drag overlay */
.drag-overlay {
  position: absolute;
  inset: 0;
  background: rgba(76, 201, 240, 0.1);
  border: 3px dashed var(--accent);
  border-radius: var(--radius-lg);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  pointer-events: none;
}

.drag-overlay.active {
  display: flex;
}

.drag-overlay span {
  font-size: 20px;
  font-weight: 600;
  color: var(--accent);
  background: var(--bg-primary);
  padding: 12px 28px;
  border-radius: var(--radius-md);
}
