:root {
  --bg: #0d0f14;
  --panel: #171a22;
  --panel-2: #11141b;
  --text: #f3f5f8;
  --muted: #9da6b8;
  --line: #2a303d;
  --red: #e9344f;
  --red-2: #ff5b70;
  --good: #3ee28f;
  --shadow: 0 18px 50px rgba(0,0,0,.35);
  --radius: 18px;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(233, 52, 79, .22), transparent 34rem),
    linear-gradient(135deg, #0b0d12, #11151d 50%, #0c0e13);
  color: var(--text);
}

code {
  color: #ffd1d8;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.08);
  padding: .1rem .32rem;
  border-radius: 7px;
}

.shell { width: min(1240px, calc(100% - 32px)); margin: 0 auto; padding: 34px 0; }
.hero {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-end;
  margin-bottom: 24px;
}
.eyebrow { color: var(--red-2); font-weight: 800; letter-spacing: .12em; text-transform: uppercase; font-size: 12px; }
h1 { margin: 5px 0 8px; font-size: clamp(34px, 5vw, 58px); line-height: .95; letter-spacing: -.04em; }
p { margin: 0; color: var(--muted); max-width: 720px; }
.status-card {
  min-width: 270px;
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(23,26,34,.72);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 16px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}
.status-card small { display: block; color: var(--muted); margin-top: 2px; }
.dot { width: 10px; height: 10px; border-radius: 99px; background: var(--good); box-shadow: 0 0 16px var(--good); }
.dot.warn { background: #ffbf47; box-shadow: 0 0 16px #ffbf47; }
.dot.bad { background: var(--red); box-shadow: 0 0 16px var(--red); }

.grid { display: grid; grid-template-columns: 410px 1fr; gap: 20px; align-items: start; }
.panel {
  background: linear-gradient(180deg, rgba(23,26,34,.96), rgba(15,18,25,.96));
  border: 1px solid rgba(255,255,255,.08);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 18px 18px 0;
}
h2 { margin: 0; font-size: 20px; letter-spacing: -.02em; }

.dropzone {
  margin: 18px;
  min-height: 245px;
  border: 1.5px dashed rgba(255,255,255,.18);
  background: linear-gradient(180deg, rgba(255,255,255,.055), rgba(255,255,255,.025));
  border-radius: 18px;
  display: grid;
  place-items: center;
  text-align: center;
  cursor: pointer;
  transition: .18s ease;
  position: relative;
}
.dropzone:hover, .dropzone.dragover { border-color: rgba(233,52,79,.75); background: rgba(233,52,79,.08); transform: translateY(-1px); }
.dropzone input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.dropzone strong, .dropzone small, .drop-icon { display: block; }
.dropzone small { color: var(--muted); margin-top: 4px; }
.drop-icon {
  width: 54px;
  height: 54px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  margin-bottom: 14px;
  background: rgba(233,52,79,.14);
  color: #fff;
  font-size: 26px;
}

.preview-row {
  margin: -4px 18px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 14px;
  background: rgba(255,255,255,.04);
}
.preview-row img {
  width: 76px;
  height: 76px;
  object-fit: contain;
  image-rendering: pixelated;
  background: repeating-conic-gradient(#20242e 0% 25%, #171b24 0% 50%) 50% / 14px 14px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,.08);
}
.preview-row strong { display: block; overflow-wrap: anywhere; }
.preview-row small { color: var(--muted); }
.hidden { display: none !important; }

.controls {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 12px;
  padding: 0 18px 18px;
}
label { color: var(--muted); font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; }
select {
  width: 100%;
  margin-top: 7px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 12px;
  padding: 12px;
  outline: 0;
}
button {
  border: 0;
  border-radius: 12px;
  color: #fff;
  cursor: pointer;
  font-weight: 800;
  transition: .16s ease;
}
button:disabled { opacity: .45; cursor: not-allowed; }
.primary-btn {
  background: linear-gradient(135deg, var(--red), #b5142c);
  box-shadow: 0 10px 25px rgba(233,52,79,.24);
  align-self: end;
  min-height: 43px;
  padding: 0 16px;
}
.primary-btn:not(:disabled):hover, .ghost-btn:hover { transform: translateY(-1px); filter: brightness(1.05); }
.ghost-btn {
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.10);
  color: var(--text);
  min-height: 36px;
  padding: 0 12px;
}
.hint-box {
  border-top: 1px solid rgba(255,255,255,.08);
  padding: 16px 18px 18px;
  color: var(--muted);
  font-size: 13px;
}
.hint-box strong { color: var(--text); display: block; margin-bottom: 7px; }
.hint-box p { margin-top: 8px; font-size: 13px; }

.results-panel { min-height: 560px; }
.pill {
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 999px;
  color: var(--muted);
  padding: 7px 10px;
  font-size: 12px;
  white-space: nowrap;
}
.loading { display: flex; align-items: center; gap: 12px; padding: 24px 18px; color: var(--muted); }
.spinner {
  width: 20px;
  height: 20px;
  border: 3px solid rgba(255,255,255,.12);
  border-top-color: var(--red-2);
  border-radius: 999px;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.results { padding: 16px 18px 18px; display: grid; gap: 12px; }
.results.empty { min-height: 460px; place-items: center; }
.empty-state {
  text-align: center;
  color: var(--muted);
  border: 1px dashed rgba(255,255,255,.12);
  border-radius: 16px;
  padding: 34px;
  max-width: 460px;
}
.empty-state strong { color: var(--text); display: block; font-size: 18px; margin-bottom: 8px; }
.empty-state span { display: block; line-height: 1.5; }
.result-card {
  display: grid;
  grid-template-columns: 42px 76px 1fr 82px;
  align-items: center;
  gap: 14px;
  padding: 12px;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 16px;
  background: rgba(255,255,255,.035);
}
.result-card.best { border-color: rgba(233,52,79,.65); background: linear-gradient(135deg, rgba(233,52,79,.16), rgba(255,255,255,.035)); }
.rank {
  width: 34px;
  height: 34px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: rgba(255,255,255,.07);
  color: var(--muted);
  font-weight: 900;
}
.best .rank { background: var(--red); color: #fff; }
.sprite-wrap {
  width: 76px;
  height: 76px;
  display: grid;
  place-items: center;
  background: repeating-conic-gradient(#20242e 0% 25%, #171b24 0% 50%) 50% / 14px 14px;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 14px;
}
.sprite {
  max-width: 70px;
  max-height: 70px;
  image-rendering: pixelated;
}
.result-title { font-weight: 900; letter-spacing: -.01em; overflow-wrap: anywhere; }
.result-sub { color: var(--muted); margin-top: 4px; font-size: 13px; overflow-wrap: anywhere; }
.result-meta { color: #758096; margin-top: 6px; font-size: 12px; overflow-wrap: anywhere; }
.score {
  justify-self: end;
  font-weight: 950;
  font-size: 20px;
  color: var(--red-2);
}

@media (max-width: 900px) {
  .hero { align-items: stretch; flex-direction: column; }
  .status-card { min-width: 0; }
  .grid { grid-template-columns: 1fr; }
  .result-card { grid-template-columns: 34px 66px 1fr; }
  .score { grid-column: 3; justify-self: start; font-size: 17px; }
  .sprite-wrap { width: 66px; height: 66px; }
  .sprite { max-width: 60px; max-height: 60px; }
}

.mode-box {
  margin: 0 18px 18px;
  padding: 14px;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 16px;
  background: rgba(255,255,255,.035);
}
.mode-title { display: block; margin-bottom: 10px; }
.mode-toggle { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.mode-btn {
  min-height: 39px;
  padding: 0 12px;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.10);
  color: var(--text);
}
.mode-btn.active {
  border-color: rgba(233,52,79,.78);
  background: linear-gradient(135deg, rgba(233,52,79,.30), rgba(255,255,255,.06));
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.04), 0 10px 22px rgba(233,52,79,.12);
}
.mode-box p {
  margin-top: 10px;
  font-size: 13px;
  line-height: 1.35;
}

.wand-panel {
  margin: -4px 18px 18px;
  padding: 14px;
  border: 1px solid rgba(233,52,79,.24);
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(233,52,79,.08), rgba(255,255,255,.035));
}
.wand-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.wand-head strong { display: block; }
.wand-head small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  line-height: 1.35;
}
.wand-stage-wrap {
  border: 1px solid rgba(255,255,255,.10);
  border-radius: 14px;
  overflow: hidden;
  background: repeating-conic-gradient(#20242e 0% 25%, #171b24 0% 50%) 50% / 14px 14px;
}
.wand-stage {
  position: relative;
  width: 100%;
  min-height: 160px;
  cursor: crosshair;
}
.wand-stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}
#wandMaskCanvas { mix-blend-mode: normal; }
.wand-controls {
  display: grid;
  grid-template-columns: 1fr 82px 82px;
  gap: 8px;
  align-items: end;
  margin-top: 12px;
}
.wand-controls label { display: grid; grid-template-columns: 1fr auto; gap: 7px 9px; align-items: center; }
.wand-controls input[type="range"] { grid-column: 1 / -1; width: 100%; accent-color: var(--red); }
.wand-controls .ghost-btn { min-height: 40px; }

@media (max-width: 900px) {
  .mode-toggle { grid-template-columns: 1fr; }
  .wand-controls { grid-template-columns: 1fr; }
}
