/* ===========================
   Autof Pixel Art - Styles
   Glassmorphism / Liquid Glass
   =========================== */

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

:root {
  --primary: #6671cf;
  --primary-light: #8b93e0;
  --primary-dark: #505bb5;
  --accent: #83b8d7;
  --glass-bg: rgba(255, 255, 255, 0.72);
  --glass-border: rgba(255, 255, 255, 0.78);
  --glass-shadow: 0 14px 30px rgba(86, 95, 145, 0.12);
  --glass-blur: blur(18px);
  --text-primary: #171a2f;
  --text-secondary: #4a4a6a;
  --text-muted: #737891;
  --radius: 20px;
  --radius-sm: 10px;
  --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --shadow: 0 22px 60px rgba(78, 89, 140, 0.18);
  --soft-shadow: 0 14px 30px rgba(86, 95, 145, 0.12);
}

html {
  font-size: 14px;
}

body {
  font-family: Inter, "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
  color: var(--text-primary);
  min-height: 100vh;
  background:
    radial-gradient(circle at 32% 0%, rgba(255, 255, 255, 0.72), transparent 32%),
    linear-gradient(135deg, #dfe5f7 0%, #f3f6fb 58%, #e5ebf8 100%);
  background-attachment: fixed;
  overflow-x: hidden;
}

/* ===========================
   Brand Header
   =========================== */
.brand-header {
  text-align: center;
  padding: 28px 20px 18px;
  position: relative;
}

.brand-logo {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 6px;
}

.brand-name {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.5px;
}

.brand-sub {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.brand-tagline {
  font-size: 0.92rem;
  color: var(--text-muted);
}

/* ===========================
   Main Layout
   =========================== */
.app-container {
  display: grid;
  grid-template-columns: 280px 1fr 300px;
  gap: 16px;
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 16px 32px;
  min-height: calc(100vh - 140px);
}

/* ===========================
   Glass Panels
   =========================== */
.panel {
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  box-shadow: var(--soft-shadow);
  overflow: hidden;
}

.panel-inner {
  padding: 20px;
}

.panel-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(102, 113, 207, 0.12);
}

.panel-title .icon {
  width: 18px;
  height: 18px;
  color: var(--primary);
  flex-shrink: 0;
}

/* ===========================
   Upload Zone
   =========================== */
.upload-zone {
  border: 2px dashed rgba(102, 113, 207, 0.35);
  border-radius: var(--radius-sm);
  padding: 28px 16px;
  text-align: center;
  cursor: pointer;
  transition: var(--transition);
  background: rgba(102, 113, 207, 0.03);
  margin-bottom: 20px;
}

.upload-zone:hover,
.upload-zone.dragover {
  border-color: var(--primary);
  background: rgba(102, 113, 207, 0.08);
  transform: translateY(-1px);
}

.upload-zone.dragover {
  box-shadow: 0 0 0 3px rgba(102, 113, 207, 0.15);
}

.upload-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.upload-icon {
  width: 40px;
  height: 40px;
  color: var(--primary-light);
}

.upload-text {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.upload-text small {
  color: var(--text-muted);
}

.upload-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* ===========================
   Settings
   =========================== */
.setting-group {
  margin-bottom: 16px;
}

.setting-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 8px;
  cursor: pointer;
}

.setting-label input[type="checkbox"] {
  accent-color: var(--primary);
  width: 15px;
  height: 15px;
}

.platform-toggle {
  display: flex;
  gap: 6px;
}

.platform-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 8px;
  border: 1px solid rgba(102, 113, 207, 0.2);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.4);
  color: var(--text-secondary);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
}

.platform-btn .icon {
  width: 16px;
  height: 16px;
}

.platform-btn:hover {
  background: rgba(102, 113, 207, 0.08);
  border-color: var(--primary-light);
}

.platform-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  box-shadow: 0 2px 10px rgba(102, 113, 207, 0.3);
}

/* Slider */
.slider {
  width: 100%;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  background: rgba(102, 113, 207, 0.15);
  border-radius: 3px;
  outline: none;
  cursor: pointer;
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--primary);
  box-shadow: 0 2px 8px rgba(102, 113, 207, 0.35);
  cursor: pointer;
  transition: transform 0.15s ease;
}

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

.slider::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--primary);
  box-shadow: 0 2px 8px rgba(102, 113, 207, 0.35);
  border: none;
  cursor: pointer;
}

.slider-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* ===========================
   Buttons
   =========================== */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px 16px;
  border: none;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.btn .icon {
  width: 18px;
  height: 18px;
}

.btn-primary {
  background: linear-gradient(145deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: #fff;
  box-shadow: 0 12px 24px rgba(80, 91, 181, 0.28);
  margin-top: 8px;
}

.btn-primary:hover:not(:disabled) {
  transform: scale(1.03);
  box-shadow: 0 14px 28px rgba(80, 91, 181, 0.35);
}

.btn-primary:active:not(:disabled) {
  transform: scale(0.98);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-download {
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  color: var(--text-muted);
  box-shadow: var(--soft-shadow);
  margin-bottom: 8px;
  font-size: 0.82rem;
  padding: 10px 14px;
  border-radius: 999px;
}

.btn-download:hover {
  background: rgba(255, 255, 255, 0.95);
  color: var(--text-primary);
  transform: translateY(-1px);
  box-shadow: 0 14px 30px rgba(86, 95, 145, 0.16);
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid rgba(102, 113, 207, 0.2);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.5);
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
  font-size: 0.78rem;
  font-weight: 500;
}

.btn-icon .icon {
  width: 16px;
  height: 16px;
}

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

/* ===========================
   Preview / Result
   =========================== */
.panel-center {
  min-height: 0;
}

.preview-section,
.result-section {
  margin-bottom: 16px;
}

.preview-wrapper {
  position: relative;
  background: #fff;
  border-radius: var(--radius-sm);
  overflow: hidden;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.06);
}

.preview-canvas {
  width: 100%;
  max-height: 260px;
  object-fit: contain;
  display: block;
}

.image-info {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 0.72rem;
  padding: 4px 8px;
  border-radius: 6px;
  backdrop-filter: blur(8px);
}

/* Zoom Controls */
.zoom-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.zoom-level {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  min-width: 45px;
  text-align: center;
}

/* Result Canvas */
.result-wrapper {
  overflow: auto;
  max-height: calc(100vh - 360px);
  border-radius: var(--radius-sm);
  background: #fff;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.06);
}

.result-canvas-container {
  display: inline-block;
  transform-origin: top left;
  transition: transform 0.2s ease;
  position: relative;
}

.result-canvas {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.overlay-canvas {
  position: absolute;
  top: 0;
  left: 0;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* ===========================
   Loading Overlay
   =========================== */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(232, 236, 248, 0.8);
  backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.loading-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(102, 113, 207, 0.2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-text {
  margin-top: 16px;
  font-size: 0.95rem;
  color: var(--text-secondary);
  font-weight: 500;
}

/* ===========================
   Empty State
   =========================== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
}

.empty-state.hidden {
  display: none;
}

.empty-icon {
  width: 80px;
  height: 80px;
  margin-bottom: 16px;
}

.empty-state p {
  font-size: 1rem;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.empty-state small {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ===========================
   Palette Grid
   =========================== */
.palette-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(28px, 1fr));
  gap: 4px;
  margin-bottom: 20px;
  max-height: 300px;
  overflow-y: auto;
  padding-right: 4px;
}

.palette-grid::-webkit-scrollbar {
  width: 5px;
}

.palette-grid::-webkit-scrollbar-thumb {
  background: rgba(102, 113, 207, 0.2);
  border-radius: 3px;
}

.swatch {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  cursor: pointer;
  transition: var(--transition);
  position: relative;
}

.swatch:hover {
  transform: scale(1.25);
  z-index: 10;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.swatch .tooltip {
  display: none;
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(26, 26, 46, 0.9);
  color: #fff;
  font-size: 0.7rem;
  padding: 4px 8px;
  border-radius: 6px;
  white-space: nowrap;
  pointer-events: none;
  backdrop-filter: blur(8px);
}

.swatch:hover .tooltip {
  display: block;
}

/* ===========================
   Statistics
   =========================== */
.stats-container {
  max-height: 320px;
  overflow-y: auto;
  margin-bottom: 16px;
  padding-right: 4px;
}

.stats-container::-webkit-scrollbar {
  width: 5px;
}

.stats-container::-webkit-scrollbar-thumb {
  background: rgba(102, 113, 207, 0.2);
  border-radius: 3px;
}

.stats-empty {
  text-align: center;
  padding: 24px 0;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
}

.stats-table tr {
  transition: background 0.15s ease;
}

.stats-table tr:hover {
  background: rgba(102, 113, 207, 0.05);
}

.stats-table td {
  padding: 6px 8px;
  font-size: 0.78rem;
  border-bottom: 1px solid rgba(102, 113, 207, 0.08);
  vertical-align: middle;
}

.stats-swatch {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  display: inline-block;
  vertical-align: middle;
}

.stats-name {
  color: var(--text-secondary);
  font-size: 0.75rem;
}

.stats-count {
  font-weight: 600;
  color: var(--text-primary);
  text-align: right;
}

.stats-pct {
  color: var(--text-muted);
  text-align: right;
  width: 45px;
}

/* ===========================
   Download Section
   =========================== */
.download-section {
  margin-top: 4px;
}

/* ===========================
   Drawing Toolbar
   =========================== */
.draw-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(102, 113, 207, 0.15);
  border-radius: var(--radius-sm);
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.tool-group {
  display: flex;
  gap: 4px;
}

.tool-divider {
  width: 1px;
  height: 28px;
  background: rgba(102, 113, 207, 0.2);
  margin: 0 4px;
}

.tool-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  border: 1px solid rgba(102, 113, 207, 0.15);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.5);
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.tool-btn .icon {
  width: 16px;
  height: 16px;
}

.tool-btn:hover {
  background: rgba(102, 113, 207, 0.1);
  border-color: var(--primary-light);
  color: var(--text-primary);
}

.tool-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(102, 113, 207, 0.3);
}

.color-preview {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

.color-preview-swatch {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: 2px solid rgba(0, 0, 0, 0.15);
  background: #ccc;
  cursor: default;
  transition: var(--transition);
}

.color-preview-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hover-info {
  font-size: 0.72rem;
  color: var(--text-muted);
  min-width: 60px;
  text-align: right;
}

/* Canvas cursor styles */
.overlay-canvas.cursor-brush {
  cursor: crosshair;
}

.overlay-canvas.cursor-eyedropper {
  cursor: copy;
}

.overlay-canvas.cursor-eraser {
  cursor: cell;
}

/* Palette swatch selected */
.swatch.selected {
  box-shadow: 0 0 0 3px var(--primary), 0 2px 8px rgba(102, 113, 207, 0.4);
  transform: scale(1.15);
  z-index: 10;
}

/* ===========================
   Footer
   =========================== */
.app-footer {
  text-align: center;
  padding: 20px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ===========================
   Mobile Responsive
   =========================== */
@media (max-width: 1100px) {
  .app-container {
    grid-template-columns: 250px 1fr;
  }
  .panel-right {
    grid-column: 1 / -1;
  }
  .panel-right .panel-inner {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
  }
  .panel-right .panel-title {
    grid-column: 1 / -1;
  }
}

@media (max-width: 760px) {
  .app-container {
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 0 10px 24px;
  }
  .brand-header {
    padding: 18px 16px 12px;
  }
  .brand-name {
    font-size: 1.3rem;
  }
  .panel-right .panel-inner {
    grid-template-columns: 1fr;
  }
  .result-wrapper {
    max-height: 50vh;
  }
  .palette-grid {
    max-height: 160px;
  }
  .stats-container {
    max-height: 200px;
  }
  .preview-canvas {
    max-height: 200px;
  }
}
