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

:root {
  --bg: #252220;
  --bg-raised: #332f2c;
  --bg-sunken: #1a1816;
  --border: #504b47;
  --border-active: #d4a366;
  --accent: #d4a366;
  --accent-light: #ffd591;
  --text: #f7f7f5;
  --text-muted: #a8a39e;
  --green: #95de64;
  --red: #ff4d4f;
}

html, body {
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Courier New', Courier, monospace;
  font-size: 14px;
  line-height: 1.5;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

#bg-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

header {
  width: 100%;
  padding: 12px 12px 4px;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-shrink: 0;
}


#title-canvas {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  max-width: min(100%, 720px);
  height: auto;
  display: block;
}

main {
  width: 100%;
  max-width: 1100px;
  padding: 12px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}

/* Drop zone */
#drop-zone {
  border: 3px dashed var(--border);
  background: var(--bg-sunken);
  padding: 48px 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.1s, background 0.1s;
  user-select: none;
  width: min(100%, 480px);
  box-shadow: inset 3px 3px 0 rgba(0,0,0,0.4), inset -3px -3px 0 rgba(255,255,255,0.04);
}

#drop-zone.compact {
  padding: 12px 24px;
}

#drop-zone.compact .drop-secondary {
  display: none;
}

#drop-zone:hover,
#drop-zone.drag-over {
  border-color: var(--accent);
  background: #2a2522;
}

#drop-zone .drop-primary {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

#drop-zone .drop-secondary {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

#file-input {
  display: none;
}

/* Controls */
#controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 10px 14px;
  background: var(--bg-raised);
  border: 2px solid var(--border);
  box-shadow: 3px 3px 0 rgba(0,0,0,0.5);
  width: min(100%, 480px);
}

#controls label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

#controls .control-group {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}


#width-slider {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  min-width: 0;
  height: 8px;
  background: var(--bg-sunken);
  border: 2px solid var(--border);
  outline: none;
  cursor: pointer;
}

#width-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 0;
  background: var(--accent);
  border: 2px solid var(--bg-sunken);
  cursor: pointer;
  box-shadow: 2px 2px 0 rgba(0,0,0,0.5);
}

#width-slider::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 0;
  background: var(--accent);
  border: 2px solid var(--bg-sunken);
  cursor: pointer;
  box-shadow: 2px 2px 0 rgba(0,0,0,0.5);
}

#width-slider::-webkit-slider-thumb:hover {
  background: var(--accent-light);
}


.btn {
  padding: 10px 18px;
  border: 2px solid var(--border-active);
  background: transparent;
  color: var(--accent);
  font-family: 'Courier New', Courier, monospace;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: background 0.1s, color 0.1s;
  white-space: nowrap;
  box-shadow: 3px 3px 0 rgba(0,0,0,0.5);
}

.btn:hover {
  background: var(--accent);
  color: var(--bg);
}

.btn:active {
  box-shadow: 1px 1px 0 rgba(0,0,0,0.5);
  transform: translate(2px, 2px);
}

.btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  box-shadow: none;
}

.btn-primary {
  background: var(--accent);
  color: var(--bg);
}

.btn-primary:hover {
  background: var(--accent-light);
}

/* Status */
#status {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  min-height: 1em;
}

#status.loading { color: var(--accent); }
#status.done    { color: var(--green); }
#status.error   { color: var(--red); }

/* Preview area */
#preview-area {
  display: none;
  gap: 12px;
  flex-direction: column;
  width: 100%;
  align-items: center;
}

#preview-area.visible {
  display: flex;
  align-items: center;
}

/* ── Compare widget ─────────────────────────────────────────────────────────── */

#compare-wrap {
  position: relative;
  display: inline-block;
  max-width: min(100%, 800px);
  margin: 0 auto;
  cursor: col-resize;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  -webkit-touch-callout: none;
}

/* Canvas container clips the images but not the handle */
#compare-canvases {
  display: grid;
  border: 2px solid var(--border);
  box-shadow: 4px 4px 0 rgba(0,0,0,0.6);
  overflow: hidden;
  background: var(--bg-sunken);
  position: relative;
}

#block-count-overlay {
  position: absolute;
  bottom: 6px;
  right: 6px;
  font-size: 11px;
  font-weight: 700;
  font-family: 'Courier New', Courier, monospace;
  letter-spacing: 0.04em;
  color: #f7f7f5;
  background: rgba(0,0,0,0.6);
  padding: 3px 6px;
  pointer-events: none;
  z-index: 5;
  line-height: 1;
}

/* Both canvases share the same grid cell — they stack pixel-perfectly */
#compare-bg,
#compare-fg {
  grid-area: 1 / 1;
  display: block;
  max-width: 100%;
  height: auto;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

#compare-fg {
  clip-path: inset(0 0 0 50%);
}

/* ── Divider handle ─────────────────────────────────────────────────────────── */

#compare-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  z-index: 10;
  cursor: col-resize;
}

.handle-line {
  flex: 1;
  width: 3px;
  background: var(--accent);
}

.handle-knob {
  width: 32px;
  height: 32px;
  background: var(--accent);
  border: 3px solid var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--bg);
  flex-shrink: 0;
  box-shadow: 3px 3px 0 rgba(0,0,0,0.6);
  transition: background 0.1s;
}

#compare-handle:hover .handle-knob,
#compare-handle:active .handle-knob {
  background: var(--accent-light);
}


/* ── Actions ────────────────────────────────────────────────────────────────── */

#output-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

#loupe-hint {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  background: rgba(0,0,0,0.7);
  padding: 3px 8px;
  pointer-events: none;
  z-index: 15;
  white-space: nowrap;
  display: none;
}

#btn-loupe.active {
  background: #7a5c30;
  color: var(--accent-light);
  border-color: #7a5c30;
}

#btn-loupe.active:hover {
  background: #8f6c38;
  color: var(--accent-light);
  border-color: #8f6c38;
}

/* ── Loupe ──────────────────────────────────────────────────────────────────── */

#loupe {
  position: fixed;
  width: 160px;
  height: 160px;
  border-radius: 50%;
  border: 3px solid var(--accent);
  box-shadow: 0 0 0 2px var(--bg), 4px 4px 0 rgba(0,0,0,0.7);
  pointer-events: none;
  display: none;
  z-index: 50;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* Tooltip */
#tooltip {
  position: fixed;
  background: var(--bg-raised);
  border: 2px solid var(--border-active);
  padding: 6px 10px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text);
  pointer-events: none;
  display: none;
  z-index: 100;
  white-space: nowrap;
  box-shadow: 3px 3px 0 rgba(0,0,0,0.5);
}



/* Loading spinner */
@keyframes spin {
  to { transform: rotate(360deg); }
}

.spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 0;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}
