:root {
  color-scheme: light;
  --paper: #f7f3fa;
  --card: #ffffff;
  --ink: #2e1a3b;
  --muted: #6e5e7a;
  --line: #e4dcea;
  --plum: #6b3fa0;
  --plum-soft: #efe6f8;
  --leaf: #4f8a2b;
  --amber: #b9731c;
  --amber-soft: #fbefdc;
  --grey-soft: #eeeaf1;
  --shadow: 0 1px 2px rgba(46, 26, 59, 0.08);
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --paper: #1b1222;
    --card: #261a30;
    --ink: #f3ecf8;
    --muted: #b6a7c2;
    --line: #3b2c47;
    --plum: #b58ae6;
    --plum-soft: #34254a;
    --leaf: #8fcf62;
    --amber: #f0b45e;
    --amber-soft: #3a2a17;
    --grey-soft: #2f2438;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: "Lexend", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 17px;
  line-height: 1.5;
  padding-bottom: calc(110px + env(safe-area-inset-bottom, 0px));
}

.wrap { max-width: 900px; margin: 0 auto; padding: 0 16px; }

header.top { padding: 32px 0 8px; }
header.top h1 {
  font-size: clamp(28px, 7vw, 40px);
  line-height: 1.1;
  font-weight: 600;
  margin: 0 0 12px;
  letter-spacing: -0.01em;
}
header.top p { margin: 0 0 8px; color: var(--muted); max-width: 60ch; }
header.top p strong { color: var(--ink); font-weight: 500; }

.tally {
  display: flex; flex-wrap: wrap; gap: 8px;
  margin: 20px 0 8px; padding: 0; list-style: none;
}
.tally a {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px; border-radius: 999px;
  background: var(--card); border: 1px solid var(--line);
  color: var(--ink); text-decoration: none; font-size: 15px;
}
.tally a b { font-weight: 600; }
.tally a.needs { background: var(--amber-soft); border-color: transparent; color: var(--amber); }

section.place { margin-top: 36px; scroll-margin-top: 16px; }
section.place > h2 {
  display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap;
  font-size: 22px; font-weight: 600; margin: 0 0 4px;
}
section.place > h2 .count { font-size: 15px; font-weight: 400; color: var(--muted); }
section.place > .addr { margin: 0 0 14px; color: var(--muted); font-size: 15px; }
section.place[data-place="unsorted"] > h2 { color: var(--amber); }
section.place[data-place="skip"] > h2 { color: var(--muted); }

.grid {
  display: grid; gap: 10px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
@media (min-width: 640px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 860px) { .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

.empty {
  border: 2px dashed var(--line); border-radius: 14px;
  padding: 18px; color: var(--muted); font-size: 15px; text-align: center;
}

.photo {
  appearance: none; border: 0; padding: 0; margin: 0;
  display: block; width: 100%; aspect-ratio: 1 / 1;
  border-radius: 14px; overflow: hidden; cursor: pointer;
  background: var(--grey-soft); box-shadow: var(--shadow);
  position: relative;
}
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo:focus-visible { outline: 3px solid var(--plum); outline-offset: 3px; }
.photo.moved { animation: moved 900ms ease-out; }
@keyframes moved {
  0% { box-shadow: 0 0 0 4px var(--leaf); }
  100% { box-shadow: 0 0 0 0 transparent; }
}

.photo.leaving { opacity: 0; transform: scale(0.9); transition: opacity 240ms ease-in, transform 240ms ease-in; }

.toast {
  position: fixed; left: 50%; z-index: 15;
  bottom: calc(90px + env(safe-area-inset-bottom, 0px));
  transform: translate(-50%, 12px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--paper);
  padding: 12px 20px; border-radius: 999px; font-weight: 500; font-size: 16px;
  transition: opacity 180ms ease-out, transform 180ms ease-out;
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Bottom sheet */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(20, 10, 28, 0.55);
  display: none; z-index: 20;
}
.sheet-backdrop.open { display: block; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21;
  background: var(--card); border-radius: 20px 20px 0 0;
  max-height: 92vh; overflow-y: auto;
  padding: 14px 16px calc(16px + env(safe-area-inset-bottom, 0px));
  transform: translateY(105%); transition: transform 220ms ease-out;
  max-width: 640px; margin: 0 auto;
}
.sheet.open { transform: translateY(0); }
.sheet .preview {
  width: 100%; max-height: 52vh; object-fit: contain;
  border-radius: 12px; background: var(--grey-soft); display: block;
}
.sheet h3 { font-size: 19px; font-weight: 600; margin: 16px 0 10px; }
.choices { display: grid; gap: 8px; }
.choice {
  appearance: none; font: inherit; color: var(--ink);
  display: flex; flex-direction: column; align-items: flex-start;
  width: 100%; text-align: left; cursor: pointer;
  padding: 14px 16px; border-radius: 14px;
  border: 2px solid var(--line); background: var(--card);
}
.choice small { color: var(--muted); font-size: 14px; }
.choice[aria-pressed="true"] { border-color: var(--plum); background: var(--plum-soft); }
.choice:focus-visible { outline: 3px solid var(--plum); outline-offset: 2px; }
.choice.skip { border-style: dashed; }
.sheet .close {
  appearance: none; font: inherit; width: 100%; margin-top: 10px;
  padding: 12px; border: 0; background: transparent; color: var(--muted); cursor: pointer;
}

/* Note + send bar */
.note { margin-top: 40px; }
.note label { display: block; font-weight: 600; font-size: 19px; margin-bottom: 4px; }
.note p { margin: 0 0 10px; color: var(--muted); font-size: 15px; }
.note textarea {
  width: 100%; min-height: 110px; font: inherit; color: var(--ink);
  padding: 12px 14px; border-radius: 14px; border: 2px solid var(--line);
  background: var(--card); resize: vertical;
}
.note textarea:focus-visible { outline: none; border-color: var(--plum); }

.bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: var(--card); border-top: 1px solid var(--line);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
}
.bar .wrap { display: flex; align-items: center; gap: 14px; padding: 0; }
.bar .status { flex: 1; font-size: 14px; color: var(--muted); min-width: 0; }
.send {
  appearance: none; font: inherit; font-weight: 600; cursor: pointer;
  padding: 14px 22px; border-radius: 999px; border: 0;
  background: var(--plum); color: #fff; white-space: nowrap;
}
@media (prefers-color-scheme: dark) { .send { color: #1b1222; } }
.send:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }
.send[disabled] { opacity: 0.6; cursor: default; }

/* Results page */
.files { margin: 10px 0 0; padding: 0; list-style: none; font-size: 14px; color: var(--muted); }
.result .photo { cursor: default; }
.result figcaption { font-size: 13px; color: var(--muted); margin-top: 4px; word-break: break-all; }
.result figure { margin: 0; }
.result a.photo { cursor: zoom-in; }
.notebox {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 14px 16px; white-space: pre-wrap; margin-top: 8px;
}
.copy {
  appearance: none; font: inherit; cursor: pointer; margin-top: 12px;
  padding: 10px 16px; border-radius: 999px; border: 2px solid var(--plum);
  background: transparent; color: var(--plum); font-weight: 500;
}

@media (prefers-reduced-motion: reduce) {
  .sheet { transition: none; }
  .photo.moved { animation: none; }
  .toast { transition: none; }
}
