:root {
  --bg: #0f1115;
  --surface: #181b22;
  --surface-2: #20242d;
  --border: #2a2f3a;
  --text: #e8eaed;
  --text-dim: #9aa0aa;
  --primary: #ff7a18;
  --primary-600: #e85600;
  --accent: #32b643;
  --radius: 12px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

/* the hidden attribute must always win over display rules below */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  font-family: "Inter", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: radial-gradient(1200px 600px at 70% -10%, #1c2230 0%, var(--bg) 55%);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- Header ---------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 22px;
}

.brand { display: flex; align-items: center; gap: 14px; }
.header-actions { display: flex; align-items: center; gap: 10px; }

.brand-mark {
  display: grid;
  place-items: center;
  width: 46px; height: 46px;
  border-radius: 12px;
  font-size: 24px;
  background: linear-gradient(135deg, var(--primary), var(--primary-600));
  color: #fff;
  box-shadow: 0 6px 18px rgba(232, 86, 0, 0.4);
}

.app-header h1 { font-size: 20px; margin: 0; letter-spacing: -0.2px; }
.subtitle { margin: 2px 0 0; font-size: 13px; color: var(--text-dim); }

/* ---------- Workspace ---------- */
.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 22px;
  align-items: start;
}

/* ---------- Preview ---------- */
.preview-pane { display: flex; flex-direction: column; gap: 14px; }

.drop-zone {
  position: relative;
  background:
    repeating-conic-gradient(#23272f 0% 25%, #1d2128 0% 50%) 50% / 26px 26px;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  min-height: 64vh;
  display: grid;
  place-items: center;
  overflow: hidden;
  transition: border-color 0.25s ease, box-shadow 0.25s ease;
}

.drop-zone.dragover {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(50, 182, 67, 0.25) inset;
}

.empty-state { text-align: center; padding: 40px; }
.empty-icon { font-size: 54px; opacity: 0.8; }
.empty-title { font-size: 20px; font-weight: 600; margin: 14px 0 4px; }
.empty-hint { color: var(--text-dim); margin: 0 0 18px; font-size: 14px; }
.empty-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

.result-state { width: 100%; height: 100%; }
.canvas-wrap {
  position: relative;
  width: 100%;
  height: 64vh;
  display: grid;
  place-items: center;
}

.preview-img {
  position: absolute;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 6px;
}

/* Magnifier loupe */
.lens {
  position: fixed;
  width: 200px;
  height: 200px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(0, 0, 0, 0.25);
  background-color: #fff;
  background-repeat: no-repeat;
  pointer-events: none;
  z-index: 60;
  cursor: none;
}

#canvasWrap { cursor: crosshair; }

/* Loading */
.loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  gap: 12px;
  background: rgba(15, 17, 21, 0.55);
  backdrop-filter: blur(2px);
  color: var(--text);
  font-size: 14px;
  grid-auto-flow: row;
}
.spinner {
  width: 36px; height: 36px;
  border: 3px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Preview toolbar */
.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
}

/* ---------- Settings ---------- */
.settings-pane { display: flex; flex-direction: column; gap: 16px; position: sticky; top: 24px; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

.panel-title {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.2px;
  margin-bottom: 16px;
  color: var(--text);
}

.advanced summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0;
}
.advanced[open] summary { margin-bottom: 16px; }
.advanced summary::after { content: "▸"; color: var(--text-dim); transition: transform 0.2s ease; }
.advanced[open] summary::after { transform: rotate(90deg); }
.advanced summary::-webkit-details-marker { display: none; }

.control { margin-bottom: 18px; }
.control:last-child { margin-bottom: 0; }
.control.disabled { opacity: 0.4; }
.control.disabled .control-head label { color: var(--text-dim); }

.control-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 8px;
}
.control-head label { font-size: 13px; color: var(--text-dim); }
.control-head output {
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  background: var(--surface-2);
  padding: 1px 8px;
  border-radius: 6px;
}

.toggle-row { display: flex; align-items: center; justify-content: space-between; }
.toggle-row label:first-child { font-size: 13px; color: var(--text-dim); }

/* Range input */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: var(--surface-2);
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--primary);
  border: 2px solid #fff2;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}
input[type="range"]::-moz-range-thumb {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--primary);
  border: none;
  cursor: pointer;
}
input[type="range"]:disabled { opacity: 0.4; }

/* Toggle switch */
.toggle { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.toggle input { display: none; }
.toggle-track {
  width: 42px; height: 24px;
  background: var(--surface-2);
  border-radius: 999px;
  position: relative;
  transition: background 0.2s ease;
  flex: none;
}
.toggle-thumb {
  position: absolute;
  top: 3px; left: 3px;
  width: 18px; height: 18px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s ease;
}
.toggle input:checked + .toggle-track { background: var(--primary); }
.toggle input:checked + .toggle-track .toggle-thumb { transform: translateX(18px); }
.toggle-label { font-size: 13px; color: var(--text-dim); }

/* Warning */
.warning { color: var(--primary-600); font-size: 12px; margin-top: 6px; }

.download-actions { display: flex; flex-direction: column; gap: 10px; }
.download-actions .btn { width: 100%; justify-content: center; }

.tip { font-size: 12px; color: var(--text-dim); line-height: 1.5; padding: 0 2px; }
.tip strong { color: var(--text); font-weight: 600; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 9px 16px;
  cursor: pointer;
  transition: transform 0.05s ease, background 0.2s ease, opacity 0.2s ease;
}
.btn:active { transform: translateY(1px); }
.btn .ico { font-size: 15px; }

.btn-primary { background: linear-gradient(135deg, var(--primary), var(--primary-600)); color: #fff; }
.btn-primary:hover { filter: brightness(1.05); }
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; filter: none; }

.btn-ghost { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: #2a2f3a; }

.btn.full { width: 100%; justify-content: center; margin-top: 4px; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; }
  .settings-pane { position: static; }
  .drop-zone, .canvas-wrap { min-height: 48vh; height: 48vh; }
}
