:root {
  color-scheme: light dark;
  --bg: #faf7f2;
  --surface: #ffffff;
  --text: #24201b;
  --muted: #6d655b;
  --line: #e4ddd2;
  --accent: #c2410c;
  --accent-text: #ffffff;
  --good: #15803d;
  --bad: #b91c1c;
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17140f;
    --surface: #221e18;
    --text: #f3eee6;
    --muted: #aaa194;
    --line: #3a342b;
    --accent: #f97316;
    --accent-text: #1c1006;
    --good: #4ade80;
    --bad: #f87171;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

main {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 16px 64px;
}

h1 { font-size: clamp(1.7rem, 6vw, 2.5rem); line-height: 1.15; margin: 0 0 4px; overflow-wrap: anywhere; }
h2 { font-size: 1.2rem; margin: 32px 0 12px; }
p { margin: 0 0 12px; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.error { color: var(--bad); }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 8px 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

button.primary, .button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

button.danger { color: var(--bad); }
button:disabled { opacity: .55; cursor: default; }

.dates {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
  gap: 0 16px;
}

input[type="text"], input[type="password"], input[type="datetime-local"] {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-size: 16px; /* Below 16px, iPhones zoom the page when the field is tapped. */
}

label.field { display: block; font-weight: 600; margin-bottom: 12px; }
label.field input { margin-top: 4px; font-weight: 400; }
label.check { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 12px; }
label.check input { width: 20px; height: 20px; margin: 2px 0 0; flex: none; }

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

/* Guest upload */
.dropzone {
  position: relative;
  display: block;
  padding: 32px 16px;
  margin: 16px 0;
  border: 2px dashed var(--accent);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: center;
  cursor: pointer;
}
.dropzone.over { background: color-mix(in srgb, var(--accent) 14%, var(--surface)); }
.dropzone strong { display: block; font-size: 1.25rem; color: var(--accent); }
.dropzone input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}
.dropzone:focus-within { outline: 3px solid var(--accent); outline-offset: 2px; }

.overall { margin-bottom: 8px; font-weight: 600; }

progress {
  display: block;
  width: 100%;
  height: 8px;
  accent-color: var(--accent);
}

.queue { list-style: none; margin: 0; padding: 0; }
.queue li {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) auto;
  gap: 4px 12px;
  align-items: center;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}
.queue li:first-child { border-top: 0; }
.queue img, .queue .noimg {
  grid-row: span 2;
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 8px;
  background: var(--line);
}
.queue .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.queue .state { font-size: .875rem; color: var(--muted); white-space: nowrap; }
.queue .state.done { color: var(--good); }
.queue .state.failed { color: var(--bad); white-space: normal; }
.queue progress { grid-column: 2 / 4; }
.queue .retry { grid-column: 2 / 4; justify-self: start; min-height: 36px; padding: 4px 12px; }

/* Gallery */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(30%, 150px), 1fr));
  gap: 6px;
}
.tile {
  position: relative;
  display: block;
  width: 100%;
  min-height: 0;
  aspect-ratio: 1;
  padding: 0;
  border: 0;
  border-radius: 8px;
  overflow: hidden;
  background: var(--line);
}
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .placeholder {
  display: flex;
  height: 100%;
  align-items: center;
  justify-content: center;
  padding: 6px;
  font-size: .75rem;
  font-weight: 400;
  color: var(--muted);
  overflow-wrap: anywhere;
}
.tile .badge {
  position: absolute;
  left: 6px;
  bottom: 6px;
  padding: 1px 6px;
  border-radius: 6px;
  background: rgba(0, 0, 0, .7);
  color: #fff;
  font-size: .7rem;
  font-weight: 600;
}

dialog.viewer {
  width: 100vw;
  max-width: 100vw;
  height: 100dvh;
  max-height: 100dvh;
  margin: 0;
  padding: 0;
  border: 0;
  background: #000;
  color: #fff;
}
dialog.viewer[open] { display: flex; flex-direction: column; }
dialog.viewer .stage {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
dialog.viewer .stage img, dialog.viewer .stage video { max-width: 100%; max-height: 100%; }
dialog.viewer .bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  background: #111;
}
dialog.viewer .bar .caption { flex: 1 1 100%; font-size: .875rem; overflow-wrap: anywhere; }
dialog.viewer .note { padding: 16px; text-align: center; }
dialog.viewer a, dialog.viewer button { background: #222; border-color: #444; color: #fff; }

/* Organizer */
.event-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  align-items: center;
  justify-content: space-between;
}
.event-row .name { font-weight: 700; overflow-wrap: anywhere; }
.qr-block { display: flex; flex-wrap: wrap; gap: 16px; }
.qr-block img { width: 180px; height: 180px; background: #fff; border-radius: 8px; padding: 6px; }
.qr-block .details { flex: 1 1 240px; min-width: 0; }
.link { overflow-wrap: anywhere; font-weight: 600; }

/* Poster */
.poster { text-align: center; padding: 32px 16px; }
.poster h1 { font-size: clamp(2rem, 8vw, 3.5rem); margin-bottom: 16px; }
.poster .lead { font-size: clamp(1.2rem, 4vw, 1.75rem); margin-bottom: 24px; }
.poster img { width: min(80vw, 420px); height: auto; background: #fff; padding: 12px; border-radius: 12px; }
.poster .link { margin-top: 20px; font-size: 1.1rem; }

@media print {
  :root { --bg: #fff; --text: #000; --muted: #444; }
  body { background: #fff; color: #000; }
  .noprint { display: none !important; }
  .poster img { width: 11cm; }
}

/* Brand line */
.brand {
  margin-top: 40px;
  text-align: center;
  font-size: .875rem;
  font-weight: 600;
  color: var(--muted);
}

/* Site banner */
.banner {
  padding: 12px 16px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: .02em;
  text-align: center;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

/* Hover menus on tiles */
.tile { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: var(--line); }
.tile-open {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
}
.tile-open img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile-open .placeholder {
  display: flex;
  height: 100%;
  align-items: center;
  justify-content: center;
  padding: 6px;
  font-size: .75rem;
  font-weight: 400;
  color: var(--muted);
  overflow-wrap: anywhere;
}
.tile-open .badge {
  position: absolute;
  left: 6px;
  bottom: 6px;
  padding: 1px 6px;
  border-radius: 6px;
  background: rgba(0, 0, 0, .7);
  color: #fff;
  font-size: .7rem;
  font-weight: 600;
}
.tile-open .star {
  position: absolute;
  right: 6px;
  bottom: 4px;
  color: #facc15;
  font-size: 1.25rem;
  text-shadow: 0 1px 3px rgba(0, 0, 0, .8);
}
.tile-menu {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 6px;
  background: linear-gradient(rgba(0, 0, 0, .65), rgba(0, 0, 0, 0));
  opacity: 0;
  pointer-events: none;
  transition: opacity .12s;
}
.tile:hover .tile-menu, .tile:focus-within .tile-menu { opacity: 1; pointer-events: auto; }
.tile-menu button {
  min-width: 32px;
  min-height: 32px;
  padding: 2px 4px;
  border: 0;
  border-radius: 6px;
  background: rgba(255, 255, 255, .92);
  color: #111;
  font-size: .95rem;
  line-height: 1;
}
.tile-menu button:hover { background: #fff; }
.tile-menu button.danger { color: #b91c1c; }
/* Touch screens can't hover: tapping a photo opens the viewer, which has the same actions with full labels. */
@media (hover: none) {
  .tile-menu { display: none; }
}

select {
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
label.field select { display: block; width: 100%; margin-top: 4px; font-weight: 400; }

/* Manage page */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 16px 0;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}
button.active, .tabs button.active { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.filters { margin-bottom: 12px; }
#personForm input { flex: 1 1 200px; width: auto; }
.card > .row { margin-top: 12px; }
.name { font-weight: 700; overflow-wrap: anywhere; }

dialog.picker {
  width: min(92vw, 440px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}
dialog.picker h2 { margin-top: 0; overflow-wrap: anywhere; }
dialog.picker form input { flex: 1 1 160px; width: auto; }
dialog::backdrop { background: rgba(0, 0, 0, .5); }

.book-items { list-style: none; margin: 16px 0 0; padding: 0; }
.book-items li {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}
.book-items img, .book-items .noimg { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; background: var(--line); flex: none; }
.book-items input { flex: 1 1 180px; width: auto; }
.book-items button { min-width: 40px; padding: 4px 8px; }

/* Choosing photos for a scrapbook */
.pick-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
  margin-top: 12px;
}
.pick-tile { min-width: 0; }
.pick-tile input { display: block; width: 100%; margin-top: 6px; }
.pick-tile input[hidden] { display: none; }
.pick-open {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 1;
  padding: 0;
  overflow: hidden;
  border: 3px solid transparent;
  border-radius: 10px;
  background: var(--line);
  cursor: pointer;
}
.pick-open img { display: block; width: 100%; height: 100%; object-fit: cover; opacity: .8; }
.pick-open:hover img { opacity: 1; }
.pick-open .placeholder {
  display: flex;
  height: 100%;
  align-items: center;
  justify-content: center;
  padding: 8px;
  font-size: .8rem;
  overflow-wrap: anywhere;
}
.pick-open .badge {
  position: absolute;
  left: 6px;
  bottom: 6px;
  padding: 1px 6px;
  border-radius: 6px;
  background: rgba(0, 0, 0, .65);
  color: #fff;
  font-size: .75rem;
}
.pick-mark {
  position: absolute;
  top: 6px;
  right: 6px;
  display: none;
  width: 26px;
  height: 26px;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 700;
}
.pick-tile.chosen .pick-open { border-color: var(--accent); }
.pick-tile.chosen .pick-open img { opacity: 1; }
.pick-tile.chosen .pick-mark { display: flex; }

/* Scrapbook */
.book-head { text-align: center; margin-bottom: 24px; }
.book-grid { columns: 3 260px; column-gap: 14px; }
.book-grid figure {
  margin: 0 0 14px;
  padding: 10px 10px 12px;
  break-inside: avoid;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
}
.book-grid img, .book-grid video { display: block; width: 100%; height: auto; border-radius: 3px; }
.book-grid figcaption { margin-top: 8px; text-align: center; font-size: .95rem; overflow-wrap: anywhere; }

/* Upload notice */
.notice h2 { margin-top: 0; }
.notice ul { margin: 0 0 12px; padding-left: 20px; font-size: .9rem; }
.notice li { margin-bottom: 6px; }
.notice .agree { margin: 0; padding-top: 12px; border-top: 1px solid var(--line); font-weight: 600; }
.dropzone.locked { border-color: var(--line); cursor: not-allowed; opacity: .65; }
.dropzone.locked strong { color: var(--muted); }

/* Faces to name */
.face-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.face-row img { width: 72px; height: 72px; object-fit: cover; border-radius: 50%; background: var(--line); }
#faceGroups form input { flex: 1 1 180px; width: auto; }
#faceGroups .card > p:last-child { margin: 8px 0 0; }
