/* ==========================================================================
   PixKit — minimal monochrome design
   Tokens: black/grey dark theme (default) + white theme.
   Components ported from 21st.dev: joyco/file-dropzone, campsite/theme-toggle.
   ========================================================================== */

:root,
:root[data-theme="dark"] {
  --bg: #09090b;
  --surface: #111113;
  --surface-2: #17171a;
  --surface-3: #1d1d21;
  --border: #262629;
  --border-str: #3a3a3f;
  --text: #fafafa;
  --text-dim: #a1a1aa;
  --text-dim-2: #71717a;
  --checker-a: #2e2e33;
  --checker-b: #232327;
  --btn-bg: #fafafa;
  --btn-fg: #09090b;
  --danger: #ef6b6b;
  --ok: #6bbf8b;
  --ring: rgba(250, 250, 250, .1);
  --shadow: 0 16px 40px rgba(0, 0, 0, .45);
  --scrim: rgba(4, 4, 5, .8);
}

:root[data-theme="light"] {
  --bg: #fafafa;
  --surface: #ffffff;
  --surface-2: #f4f4f5;
  --surface-3: #ececee;
  --border: #e4e4e7;
  --border-str: #d4d4d8;
  --text: #0a0a0a;
  --text-dim: #6b6b74;
  --text-dim-2: #8e8e96;
  --checker-a: #e9e9eb;
  --checker-b: #f8f8fa;
  --btn-bg: #0a0a0a;
  --btn-fg: #fafafa;
  --danger: #d24a4a;
  --ok: #3f8d64;
  --ring: rgba(10, 10, 10, .06);
  --shadow: 0 16px 40px rgba(0, 0, 0, .08);
  --scrim: rgba(20, 20, 22, .45);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background .18s ease, color .18s ease;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

a { color: var(--text); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }

::selection { background: var(--text); color: var(--bg); }
:focus-visible { outline: 2px solid var(--text-dim); outline-offset: 2px; }

/* ============ header ============ */
.site-header {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px clamp(16px, 5vw, 56px);
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: inline-flex; align-items: center; gap: 10px;
  font-size: 17px; font-weight: 700; letter-spacing: -.02em;
  color: var(--text);
}
.brand:hover { text-decoration: none; }

.brand-mark {
  display: grid; place-items: center;
  width: 32px; height: 32px; border-radius: 9px;
  background: var(--btn-bg); color: var(--btn-fg);
}
.brand-mark svg { width: 18px; height: 18px; }

/* ---- theme toggle (port of campsite's picker, compact variant) ---- */
.theme-toggle {
  position: relative;
  display: inline-flex; gap: 2px;
  padding: 3px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface);
}
.tt-btn {
  position: relative; z-index: 1;
  display: grid; place-items: center;
  width: 34px; height: 30px; border-radius: 7px;
  background: transparent; border: none; cursor: pointer;
  color: var(--text-dim); transition: color .15s;
}
.tt-btn svg { width: 16px; height: 16px; }
.tt-btn:hover { color: var(--text); }
.tt-btn[aria-checked="true"] { color: var(--btn-fg); }
.tt-thumb {
  position: absolute; top: 3px; left: 3px; z-index: 0;
  width: 34px; height: 30px; border-radius: 7px;
  background: var(--btn-bg);
  transition: transform .22s cubic-bezier(.4, 0, .2, 1), width .22s cubic-bezier(.4, 0, .2, 1);
}
.tt-thumb.pos-1 { transform: translateX(35px); }
.tt-thumb.pos-2 { transform: translateX(70px); }
.tt-thumb.invert { background: var(--text); }

/* ============ layout ============ */
main { max-width: 1160px; margin: 0 auto; padding: 0 clamp(16px, 5vw, 32px); }

/* ============ hero ============ */
.hero { text-align: center; padding: clamp(44px, 8vw, 88px) 0 28px; }

h1 {
  font-size: clamp(30px, 5vw, 50px);
  font-weight: 800; letter-spacing: -.03em; line-height: 1.1;
}
.muted { color: var(--text-dim); font-weight: 700; }

.hero-sub { margin-top: 16px; color: var(--text-dim); font-size: clamp(14.5px, 2vw, 16.5px); line-height: 1.6; }

/* ---- dropzone (port of joyco/FileDropzone, multiple mode) ---- */
.dropzone {
  margin: 36px auto 0; max-width: 560px;
  min-height: 240px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 36px 24px;
  border: 1px dashed var(--border-str); border-radius: 14px;
  background: transparent;
  cursor: pointer; outline: none;
  text-align: center;
  transition: border-color .18s, background .18s, box-shadow .18s;
}
.dropzone:hover,
.dropzone:focus-visible { border-color: var(--text-dim-2); background: color-mix(in srgb, var(--surface) 60%, transparent); }
.dropzone.dragging {
  border-color: var(--text);
  background: color-mix(in srgb, var(--surface-2) 85%, transparent);
  box-shadow: 0 0 0 3px var(--ring);
}

.dz-icon {
  width: 46px; height: 46px; margin-bottom: 12px;
  border-radius: 50%;
  display: grid; place-items: center;
  border: 1px solid var(--border-str);
  background: var(--surface);
  color: var(--text-dim);
}
.dz-icon svg { width: 19px; height: 19px; }

.dz-title { font-size: 15px; font-weight: 550; }
.dz-sub { margin-top: 5px; color: var(--text-dim); font-size: 12.5px; }
kbd {
  background: var(--surface-2); border: 1px solid var(--border); border-bottom-width: 2px;
  border-radius: 5px; padding: 0 5px; font-size: 11px; font-family: inherit;
}

/* ---- buttons (shadcn-like outline / solid) ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 16px; border-radius: 9px; cursor: pointer;
  font-size: 13.5px; font-weight: 550; font-family: inherit;
  border: 1px solid transparent;
  transition: background .15s, border-color .15s, color .15s, transform .1s;
}
.btn svg { width: 15px; height: 15px; }
.btn:active { transform: scale(.98); }
.btn.solid { background: var(--btn-bg); color: var(--btn-fg); }
.btn.solid:hover { background: var(--btn-bg); opacity: .88; }
.btn.outline { border-color: var(--border-str); background: transparent; color: var(--text); }
.btn.outline:hover { background: var(--surface-2); }
.dz-select { margin-top: 18px; }
.dz-select svg { opacity: .7; }

/* ---- engine progress ---- */
.engine-status {
  max-width: 560px; margin: 22px auto 0;
  padding: 15px 17px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--border);
  text-align: left; font-size: 13px;
}
.st-row { display: flex; justify-content: space-between; margin-bottom: 9px; }
.st-row span:first-child { color: var(--text-dim); }
.bar { height: 6px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.bar-fill {
  height: 100%; width: 0%;
  background: var(--text); border-radius: 99px;
  transition: width .25s ease;
}

/* ============ toolbar ============ */
.editor { padding-top: 26px; }

.toolbar {
  display: flex; flex-wrap: wrap; gap: 18px 30px;
  padding: 18px 20px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px;
  align-items: flex-start;
}

.tool-group { display: flex; flex-direction: column; gap: 9px; }
.tool-label {
  font-size: 11px; font-weight: 600; letter-spacing: .1em;
  text-transform: uppercase; color: var(--text-dim-2);
}

.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch {
  width: 30px; height: 30px; border-radius: 8px;
  border: 1px solid var(--border-str); cursor: pointer;
  transition: transform .12s, box-shadow .12s;
  display: grid; place-items: center; padding: 0; position: relative;
  background: var(--surface-2); color: var(--text-dim);
}
.swatch:hover { transform: translateY(-2px); }
.swatch.active { border-color: var(--text); box-shadow: inset 0 0 0 1px var(--text); }
.swatch svg { width: 16px; height: 16px; }

.swatch.bg-transparent::after {
  content: "";
  position: absolute; inset: 0; border-radius: 7px;
  background:
    linear-gradient(45deg, var(--checker-a) 25%, transparent 25%, transparent 75%, var(--checker-a) 75%),
    linear-gradient(45deg, var(--checker-a) 25%, transparent 25%, transparent 75%, var(--checker-a) 75%);
  background-size: 10px 10px; background-position: 0 0, 5px 5px;
  background-color: var(--checker-b);
}
.swatch-custom { overflow: hidden; }
.swatch-custom input[type="color"] {
  position: absolute; inset: -6px; width: 44px; height: 44px; border: none; cursor: pointer; padding: 0;
  background: conic-gradient(#5a5a60, #8a8a90, #c9c9cd, #8a8a90, #5a5a60);
}
.swatch-custom input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.swatch-custom input[type="color"]::-webkit-color-swatch { border: none; }

.select {
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border-str); border-radius: 9px;
  padding: 8px 34px 8px 12px; font-size: 13px; cursor: pointer; min-width: 190px;
  appearance: none; font-family: inherit;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-dim) 50%), linear-gradient(135deg, var(--text-dim) 50%, transparent 50%);
  background-position: calc(100% - 17px) 55%, calc(100% - 12px) 55%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
.select:hover { border-color: var(--text-dim-2); }

.export-row { display: inline-flex; align-items: center; gap: 10px; }
.export-row .select { min-width: 82px; }
input[type="range"].quality { accent-color: var(--text); width: 108px; cursor: pointer; }

/* ============ results ============ */
.results-head {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 12px;
  margin: 34px 0 16px;
}
.results-head h2 { font-size: 18px; font-weight: 650; letter-spacing: -.01em; }

.count-badge {
  display: inline-block; vertical-align: 2px;
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text-dim); font-size: 11.5px; font-weight: 600;
  border-radius: 99px; padding: 2px 9px; margin-left: 6px;
}

.results-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.results-actions .btn { padding: 8px 14px; font-size: 13px; }

/* ---- grid ---- */
.grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(236px, 1fr));
  padding-bottom: 30px;
}

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; overflow: hidden;
  display: flex; flex-direction: column;
  transition: border-color .18s;
}
.card:hover { border-color: var(--border-str); }

.thumb {
  position: relative; aspect-ratio: 1 / 1;
  background: var(--surface-2);
  overflow: hidden; cursor: zoom-in;
}
.fg {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: contain; z-index: 2; display: none;
}

.card.processing .thumb::after {
  content: "";
  position: absolute; inset: 0; z-index: 3;
  background: linear-gradient(110deg, transparent 32%, var(--ring) 50%, transparent 68%);
  background-size: 220% 100%;
  animation: shimmer 1.2s linear infinite;
}
@keyframes shimmer { to { background-position: -220% 0; } }

/* background layer used by the card + compare modal */
.bg-layer {
  position: absolute; inset: 0; z-index: 1;
  background: var(--surface-2);
}
.bg-layer.blur-bg {
  background-size: cover; background-position: center;
  filter: blur(14px) brightness(.95);
  inset: -24px;
}
.bg-layer.transparent-bg,
.checker {
  background:
    linear-gradient(45deg, var(--checker-a) 25%, transparent 25%, transparent 75%, var(--checker-a) 75%),
    linear-gradient(45deg, var(--checker-a) 25%, transparent 25%, transparent 75%, var(--checker-a) 75%);
  background-size: 18px 18px; background-position: 0 0, 9px 9px;
  background-color: var(--checker-b);
}

.illus {
  position: absolute; inset: 0; z-index: 1;
  display: grid; place-items: center; align-content: center; gap: 10px;
  color: var(--text-dim); font-size: 12.5px; text-align: center; padding: 10px;
}
.illus .big { font-size: 26px; opacity: .6; }
.illus .err { color: var(--danger); }

.card-info { display: flex; flex-direction: column; gap: 3px; padding: 12px 14px 10px; }
.card-info .name {
  font-size: 13px; font-weight: 550;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.card-info .status { font-size: 12px; color: var(--text-dim-2); }
.card.processing .status { color: var(--text-dim); }
.card.done .status { color: var(--ok); }
.card.error .status { color: var(--danger); }

.card-actions { display: flex; gap: 6px; padding: 0 10px 12px; }
.icon-btn {
  flex: 1 1 0; min-width: 0;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 8px 0; border-radius: 8px; cursor: pointer;
  background: transparent; border: 1px solid var(--border);
  color: var(--text-dim);
  aspect-ratio: 1.6 / 1;
  transition: color .15s, border-color .15s, background .15s;
}
.icon-btn { font-size: 12px; font-family: inherit; }
.icon-btn:hover { color: var(--text); border-color: var(--border-str); background: var(--surface-2); }
.icon-btn:disabled { opacity: .3; cursor: not-allowed; }
.icon-btn svg { width: 14px; height: 14px; }
.icon-btn.danger:hover { color: var(--danger); border-color: var(--danger); background: transparent; }

.icon-x {
  display: grid; place-items: center;
  width: 32px; height: 32px; border-radius: 8px;
  background: transparent; border: 1px solid var(--border);
  color: var(--text-dim); font-size: 13px; cursor: pointer;
}
.icon-x:hover { color: var(--text); background: var(--surface-2); }

/* ============ features ============ */
.features {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  margin: 44px 0 64px;
}
.feature {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 20px;
}
.feature h3 { font-size: 14px; font-weight: 600; margin-bottom: 8px; }
.feature p { color: var(--text-dim); font-size: 13px; line-height: 1.6; }

.site-footer {
  border-top: 1px solid var(--border);
  padding: 24px; text-align: center;
  color: var(--text-dim-2); font-size: 12.5px;
}

/* ============ compare modal ============ */
.modal { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; }
.modal-backdrop { position: absolute; inset: 0; background: var(--scrim); backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px); }
.modal-body {
  position: relative; z-index: 1;
  width: min(92vw, 960px); max-height: 92vh; overflow: auto;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 20px;
  box-shadow: var(--shadow);
}
.modal-close { position: absolute; top: 12px; right: 14px; z-index: 5; }

.compare-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; padding-right: 44px; }
.compare-head .filename {
  font-size: 13px; color: var(--text-dim); flex: 1;
  text-align: center; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chip {
  font-size: 11px; font-weight: 650; letter-spacing: .08em; text-transform: uppercase;
  padding: 5px 11px; border-radius: 99px;
  border: 1px solid var(--border); color: var(--text-dim);
}
.chip-invert { background: var(--btn-bg); color: var(--btn-fg); border-color: transparent; }

.viewer {
  position: relative; margin: 0 auto;
  /* width/height are set by fitBox() so image aspect is preserved exactly */
  border-radius: 10px; overflow: hidden;
  touch-action: none;
  background: var(--surface-2);
  cursor: ew-resize;
}
.layer { position: absolute; inset: 0; display: grid; place-items: center; }
.layer img {
  width: 100%; height: 100%; object-fit: contain; display: block;
  pointer-events: none; user-select: none; -webkit-user-drag: none;
}
.layer-result { z-index: 2; }
#cmp-original { z-index: 3; }
.divider {
  position: absolute; top: 0; bottom: 0; z-index: 4;
  width: 2px; background: var(--text); pointer-events: none;
}
.divider::after {
  content: "";
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--btn-bg);
  box-shadow: 0 2px 10px rgba(0, 0, 0, .3);
}
.compare-range { width: 100%; margin-top: 14px; accent-color: var(--text); cursor: pointer; }
.compare-hint { text-align: center; color: var(--text-dim-2); font-size: 12px; margin-top: 8px; }

/* ---- manual editor (eraser / restore brushes) ---- */
.edit-head {
  display: flex; align-items: center; gap: 12px;
  flex-wrap: wrap; margin-bottom: 14px; padding-right: 44px;
}
.edit-head h2 { font-size: 16px; font-weight: 650; letter-spacing: -.01em; }
.edit-tools { display: flex; align-items: center; gap: 10px; flex: 1; flex-wrap: wrap; }

.toolseg {
  display: inline-flex; gap: 2px; padding: 3px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-2);
}
.toolseg button {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 7px; border: none; cursor: pointer;
  background: transparent; color: var(--text-dim);
  font-size: 12.5px; font-weight: 550; font-family: inherit;
  transition: color .15s, background .15s;
}
.toolseg button svg { width: 14px; height: 14px; }
.toolseg button.active { background: var(--btn-bg); color: var(--btn-fg); }

#brush-size { width: 110px; accent-color: var(--text); cursor: pointer; }
.brush-size-val {
  font-size: 11.5px; color: var(--text-dim-2);
  min-width: 44px; font-variant-numeric: tabular-nums;
}
.btn.sm { padding: 7px 12px; font-size: 12.5px; border-radius: 8px; }
.btn.sm svg { width: 14px; height: 14px; }

.editor-canvas-wrap {
  position: relative; margin: 0 auto;
  /* width/height are set by fitBox() so image aspect is preserved exactly */
  border-radius: 10px; overflow: hidden;
  cursor: none; touch-action: none;
  box-shadow: inset 0 0 0 1px var(--border);
}
.editor-canvas-wrap canvas { display: block; width: 100%; height: 100%; }
.editor-canvas-wrap.preloading { opacity: .4; pointer-events: none; transition: opacity .15s; }

.brush-cursor {
  position: absolute; z-index: 5;
  border-radius: 50%;
  border: 1.5px solid #000;
  outline: 1.5px solid #fff;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.6);
  pointer-events: none;
  display: none;
  transform: translate(-50%, -50%);
  mix-blend-mode: normal;
}

.edit-foot {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-top: 14px; flex-wrap: wrap;
}
.edit-hint { color: var(--text-dim-2); font-size: 12px; }

/* ============ faq ============ */
.faq { max-width: 680px; margin: 40px auto 0; }
.faq h2 { font-size: 17px; font-weight: 650; letter-spacing: -.01em; margin-bottom: 14px; }
.faq details {
  border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 16px; margin-bottom: 8px;
  background: var(--surface);
}
.faq summary {
  cursor: pointer; font-size: 13.5px; font-weight: 550;
  list-style: none; display: flex; justify-content: space-between; gap: 10px;
}
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after { content: "+"; color: var(--text-dim-2); font-weight: 400; }
.faq details[open] summary::after { content: "–"; }
.faq details p { margin: 10px 0 2px; color: var(--text-dim); font-size: 13px; line-height: 1.55; }

/* ============ toasts ============ */
.toasts {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  z-index: 200; display: flex; flex-direction: column; gap: 10px; align-items: center;
}
.toast {
  background: var(--surface); border: 1px solid var(--border-str);
  color: var(--text); font-size: 13px;
  padding: 12px 18px; border-radius: 10px;
  box-shadow: var(--shadow);
  animation: toast-in .22s ease;
  max-width: min(90vw, 540px);
}
.toast.error { border-color: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ============ responsive ============ */
@media (max-width: 640px) {
  .toolbar { gap: 14px; padding: 16px; }
  .tool-group { width: 100%; }
  .select { min-width: 0; width: 100%; }
  .results-actions .btn { flex: 1; }
}
