:root {
  --bg: #0b0c10;
  --fg: #e5e7eb;
  --muted: #94a3b8;
  --accent: #7c3aed;
  --panel: #111318;
  --panel2: #0e1015;
  --border: #1f2430;
}

/* Base */
* {
  box-sizing: border-box
}

html,
body {
  height: 100%
}

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, Helvetica, Arial, 'Apple Color Emoji', 'Segoe UI Emoji';
  background: linear-gradient(180deg, var(--bg), #0f1117 40%);
  color: var(--fg);

  /* Layout: header + main fill screen */
  display: grid;
  grid-template-rows: auto 1fr;
}

header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--panel2);
}

h1 {
  margin: 0;
  font-size: 18px;
  letter-spacing: .2px
}

.muted {
  color: var(--muted);
  font-size: 12px
}

/* Two‑column app layout */
.wrap {
  display: grid;
  grid-template-columns: 420px 1fr;
  gap: 16px;
  padding: 16px;
  min-height: 0;
  /* allow children to size/scroll */
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;

  /* Make each panel fill and manage its own scroll */
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel h2 {
  margin: 0;
  font-size: 14px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-weight: 600;
  letter-spacing: .3px;

  /* Keep section title visible while content scrolls */
  position: sticky;
  top: 0;
  background: var(--panel);
  z-index: 2;
}

.panel .content {
  padding: 12px 14px;
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
}

/* Settings form pieces */
.grid {
  display: grid;
  gap: 10px
}

label {
  font-size: 12px;
  color: var(--muted);
  display: block;
  margin-bottom: 6px
}

input[type="range"] {
  width: 100%
}

input[type="number"] {
  width: 100%;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0b0d12;
  color: var(--fg);
}

select,
button {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #0b0d12;
  color: var(--fg)
}

button.primary {
  background: linear-gradient(180deg, #6d28d9, #5b21b6);
  border: none
}

button.row {
  width: auto
}

.row {
  display: flex;
  gap: 8px;
  align-items: center
}

.drop {
  border: 1px dashed #2b3242;
  border-radius: 12px;
  padding: 16px;
  text-align: center;
  background: #0b0d12;
  color: var(--muted);
  transition: border-color .2s ease, background .2s ease;
}

.drop.dragover {
  border-color: var(--accent);
  background: #0d0f16;
  color: var(--fg)
}

/* OUTPUT AREA */
.content-output {
  display: grid;
  grid-template-rows: 1fr auto;
  /* canvas area grows, caption sticks at bottom */
  gap: 10px;
  min-height: 0;
}

.stage {
  width: 100%;
  height: 100%;
  min-height: 360px;
  overflow: auto;
  display: grid;
  place-items: center;
  background: #ffffff;
  /* white behind the image */
  border-radius: 12px;
  border: 1px solid var(--border);
}

canvas {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #ffffff;
  /* also make the canvas itself white */
}

.footer {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding-top: 10px
}

.tiny {
  font-size: 11px;
  color: var(--muted)
}

.hint {
  font-size: 11px;
  color: #a78bfa
}

/* Custom palette swatches */
.swatchGrid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px
}

.swatch {
  position: relative;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border);
  cursor: pointer;
  overflow: hidden;
  transition: transform .05s ease, box-shadow .05s ease, outline-color .05s ease
}

.swatch.sel {
  outline: 3px solid var(--accent);
  outline-offset: 1px;
  box-shadow: 0 0 0 2px rgba(124, 58, 237, .35) inset
}

.swatch[aria-selected="false"] {
  opacity: .72;
  filter: saturate(.9) contrast(.92) brightness(.96)
}

.swatch .hex {
  position: absolute;
  bottom: 2px;
  right: 4px;
  font-size: 10px;
  padding: 0 4px;
  border-radius: 4px;
  background: rgba(0, 0, 0, .35);
  color: #fff
}

.swatch .check {
  position: absolute;
  top: 6px;
  left: 6px;
  width: 20px;
  height: 20px;
  border-radius: 999px;
  background: rgba(0, 0, 0, .65);
  color: #fff;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  line-height: 1
}

.swatch.sel .check {
  display: flex
}

/* Transparent swatch styling */
.swatch.transparent {
  background: linear-gradient(45deg, #ccc 25%, transparent 25%), linear-gradient(-45deg, #ccc 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #ccc 75%), linear-gradient(-45deg, transparent 75%, #ccc 75%);
  background-size: 8px 8px;
  background-position: 0 0, 0 4px, 4px -4px, -4px 0px;
}

.swatch.transparent::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 7px;
  background: rgba(255, 255, 255, .1);
}

/* Background removal controls */
#backgroundControls,
#sharpenControls {
  margin-top: 8px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(11, 13, 18, .5)
}

pre#testLog {
  background: #0b0d12;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  max-height: 160px;
  overflow: auto
}

/* Information display styles */
.info-display {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #0b0d12;
  padding: 12px
}

.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px
}

.info-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px
}

.info-item span:last-child {
  font-weight: 600;
  color: var(--fg)
}

/* Responsive: collapse to single column below ~1100px */
@media (max-width: 1100px) {
  .wrap {
    grid-template-columns: 1fr
  }

  .settings-panel {
    order: 2
  }

  .output-panel {
    order: 1
  }
}