*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0e0e0f;
  --surface: #161617;
  --surface-2: #1e1e20;
  --surface-3: #252528;
  --border: rgba(255, 255, 255, 0.07);
  --border-mid: rgba(255, 255, 255, 0.1);
  --text: #e8e8e6;
  --text-muted: #5e5e62;
  --text-dim: #8a8a8f;
  --accent: #1a9e75;
  --accent-dim: rgba(26, 158, 117, 0.15);
  --accent-h: #17b882;
  --danger: #e05252;
  --panel-w: 292px;
  --header-h: 48px;
  --radius: 8px;
  --radius-sm: 5px;
}

body {
  font-family:
    'DM Sans',
    -apple-system,
    sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
}

/* ── Header ──────────────────────────────────────────────── */
.app-header {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 12px;
  flex-shrink: 0;
  gap: 12px;
}

.logo {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.4px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 7px;
  justify-content: center;
}

.logo em {
  font-style: normal;
  color: var(--accent);
}

.logo-icon {
  width: 28px;
  height: 28px;
  background: var(--accent-dim);
  border: 1px solid rgba(26, 158, 117, 0.25);
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
}

.header-export {
  display: flex;
  align-items: center;
  gap: 6px;
}

.header-select {
  width: auto;
  max-width: max-content;
  padding: 6px 8px;
  font-size: 12px;
}

.header-actions {
  display: flex;
  gap: 5px;
  flex-shrink: 0;
  justify-content: flex-end;
}

/* ── Workspace layout ─────────────────────────────────────── */
.workspace {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Viewport ─────────────────────────────────────────────── */
.viewport {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
  overflow: hidden;
  position: relative;
  background: var(--bg);
  background-image: radial-gradient(
    ellipse at 50% 50%,
    rgba(26, 158, 117, 0.03) 0%,
    transparent 70%
  );
}

/* ── Drop zone ────────────────────────────────────────────── */
.drop-zone {
  position: absolute;
  inset: 32px;
  border: 1.5px dashed var(--border-mid);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.drop-zone:hover,
.drop-zone.drag-over {
  border-color: var(--accent);
  background: var(--accent-dim);
}

.drop-zone.drag-over .drop-icon {
  transform: scale(1.1) translateY(-4px);
}

.drop-zone-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
  pointer-events: none;
}

.drop-icon {
  width: 56px;
  height: 56px;
  background: var(--surface-2);
  border: 1px solid var(--border-mid);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  transition: transform 0.2s ease;
  margin-bottom: 4px;
}

.drop-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-dim);
}

.drop-sub {
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.5px;
}

/* ── Canvas stage ─────────────────────────────────────────── */
.canvas-stage {
  display: none;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

.loaded .drop-zone {
  display: none;
}

.loaded .canvas-stage {
  display: flex;
}

.canvas-wrap {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.06),
    0 8px 40px rgba(0, 0, 0, 0.5),
    0 2px 8px rgba(0, 0, 0, 0.3);
  flex-shrink: 0;
  cursor: crosshair;
}

#preview-canvas {
  display: block;
}

/* ── Grid overlay ─────────────────────────────────────────── */
#grid-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: none;
}

#grid-overlay.visible {
  display: block;
}

#grid-overlay svg {
  width: 100%;
  height: 100%;
}

/* ── Checker pattern (transparent BG) ────────────────────── */
.checker {
  background-image:
    linear-gradient(45deg, #2a2a2e 25%, transparent 25%),
    linear-gradient(-45deg, #2a2a2e 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #2a2a2e 75%),
    linear-gradient(-45deg, transparent 75%, #2a2a2e 75%);
  background-size: 16px 16px;
  background-position:
    0 0,
    0 8px,
    8px -8px,
    -8px 0;
  background-color: #1e1e20;
}

/* ── Panel ────────────────────────────────────────────────── */
.panel {
  width: var(--panel-w);
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  flex-shrink: 0;
  scrollbar-width: thin;
  scrollbar-color: var(--surface-3) transparent;
}

.panel::-webkit-scrollbar {
  width: 4px;
}

.panel::-webkit-scrollbar-track {
  background: transparent;
}

.panel::-webkit-scrollbar-thumb {
  background: var(--surface-3);
  border-radius: 4px;
}

.panel-section {
  padding: 14px 14px;
  border-bottom: 1px solid var(--border);
}

.section-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.13s;
  font-family: 'DM Sans', sans-serif;
  white-space: nowrap;
  flex-shrink: 0;
}

.btn:hover {
  background: var(--surface-3);
  color: var(--text);
  border-color: var(--border-mid);
}

.btn:active {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  transform: none;
  pointer-events: none;
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
}

.btn-ghost:hover {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text);
}

.btn-primary {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
  font-weight: 600;
}

.btn-primary:hover {
  background: var(--accent-h);
  color: #fff;
}

.btn-outline {
  background: transparent;
  border-color: var(--border-mid);
  color: var(--text-dim);
}

.btn-outline:hover {
  background: var(--surface-2);
  color: var(--text);
}

.btn-block {
  width: 100%;
}

/* ── Action stack ─────────────────────────────────────────── */
.action-stack {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

/* ── Progress ─────────────────────────────────────────────── */
.progress-track {
  height: 2px;
  background: var(--surface-3);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 10px;
  display: none;
}

.progress-track.show {
  display: block;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.35s ease;
  width: 0;
  position: relative;
}

.progress-fill::after {
  content: '';
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 24px;
  background: linear-gradient(to right, transparent, rgba(255, 255, 255, 0.4));
  border-radius: 2px;
}

.status-text {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 7px;
  min-height: 14px;
  line-height: 1.5;
  font-family: 'DM Mono', monospace;
}

/* ── BG swatches ──────────────────────────────────────────── */
.swatch-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 5px;
  margin-bottom: 9px;
}

.swatch {
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
  cursor: pointer;
  transition: all 0.13s;
  outline: none;
  position: relative;
}

.swatch:hover,
.swatch.active {
  border-color: var(--accent);
  transform: scale(1.1);
}

.swatch-transparent {
  background-image:
    linear-gradient(45deg, #3a3a3e 25%, transparent 25%),
    linear-gradient(-45deg, #3a3a3e 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #3a3a3e 75%),
    linear-gradient(-45deg, transparent 75%, #3a3a3e 75%);
  background-size: 8px 8px;
  background-position:
    0 0,
    0 4px,
    4px -4px,
    -4px 0;
  background-color: #222;
}

.color-row {
  display: flex;
  align-items: center;
  gap: 7px;
}

input[type='color'] {
  width: 32px;
  height: 32px;
  border: 1px solid var(--border-mid);
  border-radius: var(--radius-sm);
  padding: 2px;
  cursor: pointer;
  background: var(--surface-2);
}

/* ── Ratio grid ───────────────────────────────────────────── */
.ratio-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}

.ratio-btn {
  padding: 8px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  cursor: pointer;
  text-align: center;
  transition: all 0.13s;
  font-family: 'DM Sans', sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}

.ratio-btn:hover {
  background: var(--surface-2);
  border-color: var(--border-mid);
}

.ratio-btn.active {
  border-color: var(--accent);
  background: var(--accent-dim);
}

.ratio-value {
  font-size: 12px;
  font-weight: 600;
  font-family: 'DM Mono', monospace;
  color: var(--text-dim);
  display: block;
}

.ratio-label {
  font-size: 10px;
  color: var(--text-muted);
  display: block;
}

.ratio-btn.active .ratio-value,
.ratio-btn.active .ratio-label {
  color: var(--accent);
}

/* ── Controls ─────────────────────────────────────────────── */
.control-rows {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.control-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.control-row label {
  font-size: 12px;
  color: var(--text-dim);
  flex: 1;
}

.input-suffix {
  display: flex;
  align-items: center;
  gap: 4px;
}

.input-suffix span {
  font-size: 11px;
  color: var(--text-muted);
  font-family: 'DM Mono', monospace;
}

.hint-text {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 9px;
  line-height: 1.5;
}

.hint-text strong {
  color: var(--accent);
  font-weight: 500;
}

/* ── Toggle ───────────────────────────────────────────────── */
.toggle {
  width: 32px;
  height: 18px;
  background: var(--surface-3);
  border: 1px solid var(--border-mid);
  border-radius: 10px;
  position: relative;
  cursor: pointer;
  transition: all 0.18s;
  flex-shrink: 0;
}

.toggle::after {
  content: '';
  position: absolute;
  width: 12px;
  height: 12px;
  background: var(--text-muted);
  border-radius: 50%;
  top: 2px;
  left: 2px;
  transition: all 0.18s;
}

.toggle.on {
  background: var(--accent);
  border-color: transparent;
}

.toggle.on::after {
  background: #fff;
  transform: translateX(14px);
}

/* ── Inputs ───────────────────────────────────────────────── */
.num-input {
  width: 70px;
  padding: 5px 7px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-family: 'DM Mono', monospace;
  background: var(--surface-2);
  color: var(--text);
  text-align: center;
  transition: border-color 0.13s;
}

.num-input:focus {
  outline: none;
  border-color: var(--accent);
}

.mono-input,
.text-input {
  width: 100%;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px;
  background: var(--surface-2);
  color: var(--text);
  transition: border-color 0.13s;
}

.mono-input {
  font-family: 'DM Mono', monospace;
}

.mono-input:focus,
.text-input:focus {
  outline: none;
  border-color: var(--accent);
}

::placeholder {
  color: var(--text-muted);
}

/* ── Shadow controls ──────────────────────────────────────── */
.shadow-controls {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.slider-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.slider-header {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
}

.slider-value {
  font-family: 'DM Mono', monospace;
}

input[type='range'] {
  width: 100%;
  height: 3px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ── Filename ─────────────────────────────────────────────── */
.filename-preview {
  margin-top: 8px;
  font-size: 11px;
  font-family: 'DM Mono', monospace;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 9px;
  word-break: break-all;
  line-height: 1.5;
}

.filename-preview .suffix {
  color: var(--accent);
  font-weight: 500;
}

/* ── Export ───────────────────────────────────────────────── */
.export-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.select-input {
  flex: 1;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  font-family: 'DM Sans', sans-serif;
}

.select-input:focus {
  outline: none;
  border-color: var(--accent);
}

/* ── Badge ────────────────────────────────────────────────── */
.badge {
  font-size: 9px;
  font-weight: 700;
  padding: 2px 5px;
  border-radius: 4px;
  background: var(--accent-dim);
  color: var(--accent);
  letter-spacing: 0.5px;
  border: 1px solid rgba(26, 158, 117, 0.2);
}

/* ── File input hidden ────────────────────────────────────── */
#file-input {
  display: none;
}

/* ── Scrollbar ────────────────────────────────────────────── */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--surface-3) transparent;
}

/* ── History panel (left) ─────────────────────────────────── */
.history-panel {
  width: 200px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
}

.history-header {
  padding: 12px 14px 10px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.history-count {
  font-size: 10px;
  font-family: 'DM Mono', monospace;
  background: var(--surface-3);
  color: var(--text-muted);
  padding: 2px 7px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.history-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.history-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text-muted);
  text-align: center;
  padding: 20px;
  font-size: 11px;
  line-height: 1.6;
}

.history-empty svg {
  opacity: 0.3;
}

.history-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  cursor: pointer;
  transition: all 0.15s;
  position: relative;
  display: flex;
  flex-direction: column;
}

.history-item:hover {
  border-color: var(--border-mid);
  background: var(--surface-3);
}

.history-item.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent-dim);
}

.history-thumb {
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
  display: block;
  background-image:
    linear-gradient(45deg, #2a2a2e 25%, transparent 25%),
    linear-gradient(-45deg, #2a2a2e 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #2a2a2e 75%),
    linear-gradient(-45deg, transparent 75%, #2a2a2e 75%);
  background-size: 10px 10px;
  background-position:
    0 0,
    0 5px,
    5px -5px,
    -5px 0;
  background-color: #1e1e20;
  padding: 6px;
  box-sizing: border-box;
}

.history-meta {
  padding: 6px 8px 4px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.history-label {
  font-size: 11px;
  color: var(--text-dim);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-time {
  font-size: 10px;
  font-family: 'DM Mono', monospace;
  color: var(--text-muted);
}

.history-item-actions {
  display: flex;
  gap: 3px;
  padding: 0 6px 6px;
}

.history-use-btn,
.history-del-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 5px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.13s;
  font-size: 11px;
}

.history-use-btn:hover {
  background: var(--accent-dim);
  border-color: rgba(26, 158, 117, 0.3);
  color: var(--accent);
}

.history-del-btn:hover {
  background: rgba(224, 82, 82, 0.12);
  border-color: rgba(224, 82, 82, 0.3);
  color: var(--danger);
}

/* ── Floating action buttons ──────────────────────────────── */
.floating-actions {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: none;
  gap: 8px;
  z-index: 10;
}

.loaded .floating-actions {
  display: flex;
}

.fab-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 100px;
  font-size: 12px;
  font-weight: 600;
  font-family: 'DM Sans', sans-serif;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  backdrop-filter: blur(12px);
  box-shadow:
    0 4px 16px rgba(0, 0, 0, 0.4),
    0 1px 4px rgba(0, 0, 0, 0.3);
}

.fab-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  pointer-events: none;
}

.fab-btn:active:not(:disabled) {
  transform: scale(0.96);
}

.fab-primary {
  background: var(--accent);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #fff;
}

.fab-primary:hover:not(:disabled) {
  background: var(--accent-h);
  box-shadow:
    0 4px 20px rgba(26, 158, 117, 0.35),
    0 1px 4px rgba(0, 0, 0, 0.3);
}

.fab-outline {
  background: rgba(22, 22, 23, 0.85);
  border: 1px solid var(--border-mid);
  color: var(--text-dim);
}

.fab-outline:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border-mid);
}

/* FAB progress pill */
.fab-progress {
  position: relative;
  height: 36px;
  min-width: 200px;
  max-width: 280px;
  background: rgba(22, 22, 23, 0.88);
  border: 1px solid var(--border-mid);
  border-radius: 100px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(12px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

.fab-progress-bar {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-dim), rgba(26, 158, 117, 0.25));
  border-radius: 100px;
  transition: width 0.35s ease;
}

.fab-progress-text {
  position: relative;
  font-size: 12px;
  font-weight: 500;
  font-family: 'DM Mono', monospace;
  color: var(--text-dim);
  padding: 0 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 260px;
}

/* FAB done badge */
.fab-done {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 9px 18px;
  border-radius: 100px;
  background: rgba(26, 158, 117, 0.15);
  border: 1px solid rgba(26, 158, 117, 0.35);
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  font-family: 'DM Sans', sans-serif;
  backdrop-filter: blur(12px);
  box-shadow: 0 4px 16px rgba(26, 158, 117, 0.15);
  animation: fab-done-in 0.3s ease;
}

@keyframes fab-done-in {
  from {
    opacity: 0;
    transform: scale(0.9) translateY(4px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}
