:root {
  --paper: #EDF0F5;
  --surface: #FFFFFF;
  --ink: #17202E;
  --muted: #5B687B;
  --line: #C3CCDA;
  --cobalt: #2B55DF;
  --cobalt-soft: rgba(43, 85, 223, .08);
  --ok: #1B7F55;
  --err: #BE3434;
  --radius-s: 4px;
  --radius-m: 10px;
  --display: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #121822;
    --surface: #1A2230;
    --ink: #E6EAF1;
    --muted: #97A3B6;
    --line: #34405399;
    --cobalt: #7C9BFF;
    --cobalt-soft: rgba(124, 155, 255, .10);
    --ok: #4CC08D;
    --err: #FF7B7B;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.55 var(--body);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--cobalt); }
:focus-visible { outline: 2px solid var(--cobalt); outline-offset: 3px; }

.wrap { width: min(760px, 100% - 32px); margin: 0 auto; }

header.top { padding: 22px 0; }
header.top .wrap { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.brand {
  font: 700 20px/1 var(--display);
  color: var(--ink);
  text-decoration: none;
  letter-spacing: -.01em;
}

main { flex: 1; }

h1 {
  font: 700 clamp(34px, 6vw, 52px)/1.05 var(--display);
  letter-spacing: -.025em;
  margin: 28px 0 10px;
}
.lede { color: var(--muted); margin: 0 0 32px; max-width: 52ch; }

/* ---- Drop zone: selection rectangle with corner handles ---- */
.zone {
  position: relative;
  display: grid;
  place-items: center;
  text-align: center;
  min-height: 280px;
  padding: 32px 24px;
  background: var(--surface);
  cursor: pointer;
  border-radius: var(--radius-s);
  --dash: var(--cobalt);
  background-image:
    linear-gradient(90deg, var(--dash) 50%, transparent 50%),
    linear-gradient(90deg, var(--dash) 50%, transparent 50%),
    linear-gradient(0deg, var(--dash) 50%, transparent 50%),
    linear-gradient(0deg, var(--dash) 50%, transparent 50%);
  background-repeat: repeat-x, repeat-x, repeat-y, repeat-y;
  background-size: 14px 1.5px, 14px 1.5px, 1.5px 14px, 1.5px 14px;
  background-position: 0 0, 0 100%, 0 0, 100% 0;
  background-color: var(--surface);
}
.zone .h {
  position: absolute;
  width: 11px; height: 11px;
  background: var(--surface);
  border: 1.5px solid var(--cobalt);
}
.zone .h.tl { top: -5px; left: -5px; }
.zone .h.tr { top: -5px; right: -5px; }
.zone .h.bl { bottom: -5px; left: -5px; }
.zone .h.br { bottom: -5px; right: -5px; }
.zone .size-tag {
  position: absolute;
  top: -30px; left: 0;
  font: 600 12px/1 var(--body);
  background: var(--cobalt);
  color: #fff;
  padding: 6px 8px;
  border-radius: var(--radius-s);
}
.zone strong { display: block; font: 600 22px/1.2 var(--display); margin-bottom: 6px; }
.zone p { margin: 0; color: var(--muted); }
.zone kbd {
  font: 600 13px/1 var(--body);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: var(--radius-s);
  padding: 3px 6px;
  color: var(--ink);
}
.zone input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.zone.over { background-color: var(--cobalt-soft); animation: ants .6s linear infinite; }
@keyframes ants {
  to { background-position: 14px 0, -14px 100%, 0 -14px, 100% 14px; }
}
@media (prefers-reduced-motion: reduce) { .zone.over { animation: none; } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: 600 14px/1 var(--body);
  padding: 11px 16px;
  border-radius: var(--radius-m);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn.primary { background: var(--cobalt); border-color: var(--cobalt); color: #fff; }
.zone .btn { margin-top: 20px; }

/* ---- Results ---- */
.results { list-style: none; padding: 0; margin: 36px 0 0; display: grid; gap: 14px; }
.item {
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 14px;
  align-items: center;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
}
.item .thumb {
  width: 64px; height: 64px;
  border-radius: var(--radius-s);
  object-fit: cover;
  background: var(--paper);
}
.item .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .status { color: var(--muted); font-size: 14px; }
.item .status.err { color: var(--err); }
.bar { height: 4px; background: var(--paper); border-radius: 2px; margin-top: 8px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--cobalt); transition: width .15s linear; }
.linkrow { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.linkrow input {
  flex: 1 1 220px;
  min-width: 0;
  font: 500 14px/1 var(--body);
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
  background: var(--paper);
  color: var(--ink);
}

footer { padding: 40px 0 28px; color: var(--muted); font-size: 13px; }

/* ---- View page ---- */
.view-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.stage {
  width: min(1200px, 100% - 32px);
  margin: 8px auto 0;
  display: grid;
  place-items: center;
  padding: 20px;
  border-radius: var(--radius-m);
  background-color: var(--surface);
  background-image:
    linear-gradient(45deg, var(--paper) 25%, transparent 25%, transparent 75%, var(--paper) 75%),
    linear-gradient(45deg, var(--paper) 25%, transparent 25%, transparent 75%, var(--paper) 75%);
  background-size: 20px 20px;
  background-position: 0 0, 10px 10px;
}
.stage img { max-width: 100%; height: auto; display: block; box-shadow: 0 1px 0 var(--line), 0 12px 30px -18px rgba(0,0,0,.45); }
.meta {
  width: min(1200px, 100% - 32px);
  margin: 14px auto 0;
  display: flex; flex-wrap: wrap; gap: 6px 22px;
  color: var(--muted); font-size: 14px;
}
.meta b { color: var(--ink); font-weight: 600; }
.noshow { padding: 60px 20px; text-align: center; color: var(--muted); }
.noshow[hidden] { display: none; }
.center-msg { text-align: center; padding: 80px 0; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--ink); color: var(--paper);
  padding: 10px 16px; border-radius: var(--radius-m);
  font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s;
}
.toast.show { opacity: 1; }
