:root {
  color-scheme: light dark;
  --bg: #F3F0FF;
  --panel: #FFFFFF;
  --border: #E5DBFF;
  --text: #2B2540;
  --muted: #6B6480;
  --accent: #6741D9;
  --accent-deep: #5F3DC4;
  --accent-soft: #E5DBFF;
  --lilac: #B197FC;
  --mint: #63E6BE;
  --mint-ink: #0B4A3A;
  --coral: #FFA8A8;
  --danger: #E2555A;
  --radius: 16px;
  --radius-pill: 999px;
  --shadow: 0 4px 14px rgba(43, 37, 64, 0.10);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1A1523;
    --panel: #241C30;
    --border: #3A2F4D;
    --text: #F1ECFF;
    --muted: #A99CC4;
    --accent: #8B6CF0;
    --accent-deep: #B197FC;
    --accent-soft: #33295A;
    --shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Poppins', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}
#app { max-width: 760px; margin: 0 auto; padding: 24px 16px 96px; }
h1 { font-size: 22px; font-weight: 800; margin: 0 0 16px; }
h2 { font-size: 15px; font-weight: 600; margin: 0 0 12px; }
.panel {
  background: var(--panel);
  border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--border);
  padding: 20px;
  margin-bottom: 16px;
}
input[type=text], input[type=password], input[type=file], select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 12px; background: var(--panel); font-family: inherit;
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 14px;
}
button {
  padding: 10px 16px;
  border-radius: var(--radius-pill); font-weight: 600; font-family: inherit;
  border: none;
  background: var(--accent);
  color: white;
  font-size: 14px;
  cursor: pointer;
}
button.secondary { background: transparent; border: 1px solid var(--border); color: var(--text); }
button.danger { background: var(--danger); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
.row { display: flex; gap: 8px; align-items: center; }
.album-list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.album-list-item:last-child { border-bottom: none; }
.album-list-item a { color: var(--text); text-decoration: none; font-weight: 600; }
.muted { color: var(--muted); font-size: 13px; }
.dropzone {
  border: 2px dashed var(--border);
  border-radius: 12px;
  padding: 40px 16px;
  text-align: center;
  color: var(--muted);
  cursor: pointer;
}
.dropzone.drag { border-color: var(--accent); color: var(--accent); }
.file-grid {
  margin-top: 16px;
}
.thumb-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 8px;
}
.file-item {
  aspect-ratio: 1;
  border-radius: 8px;
  overflow: hidden;
  background: var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  padding: 4px;
  position: relative;
}
.file-item img, .file-item video { width: 100%; height: 100%; object-fit: cover; }
.file-thumb-inner { display: contents; }
.file-item.selected { outline: 2px solid var(--accent); outline-offset: -2px; }
.file-select { position: absolute; top: 4px; left: 4px; z-index: 1; }
.file-select input { width: 18px; height: 18px; cursor: pointer; }
.thumb-spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid var(--border); border-top-color: var(--accent);
  animation: pd-spin 0.8s linear infinite;
}
@keyframes pd-spin { to { transform: rotate(360deg); } }
.upload-rows { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; }
.upload-row { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.upload-row-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-bar { flex: 0 0 72px; height: 6px; border-radius: 3px; background: var(--border); overflow: hidden; }
.upload-bar-fill { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.15s linear; }
.upload-row-state { flex: 0 0 auto; max-width: 45%; font-size: 12px; color: var(--muted); text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-row.is-rejected .upload-bar-fill, .upload-row.is-error .upload-bar-fill { background: var(--danger); }
.upload-row.is-rejected .upload-row-state, .upload-row.is-error .upload-row-state { color: var(--danger); }
.upload-row.is-duplicate .upload-bar-fill, .upload-row.is-client-duplicate .upload-bar-fill { background: var(--muted); }
.upload-row-actions button { padding: 4px 10px; font-size: 12px; }

.upload-workspace { margin-top: 14px; }
.upload-tabs { display: none; gap: 8px; margin-bottom: 10px; }
.upload-tab { padding: 6px 14px; border-radius: 999px; border: 1px solid var(--border); background: transparent; color: var(--muted); font-size: 13px; cursor: pointer; }
.upload-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.upload-split { display: flex; gap: 16px; align-items: flex-start; }
.upload-pane { flex: 1 1 0; min-width: 0; max-height: 420px; overflow-y: auto; }
.upload-pane[hidden] { display: block; }

.upload-stats { display: flex; gap: 10px; flex-wrap: wrap; }
.stat-tile { display: flex; flex-direction: column; gap: 2px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; min-width: 84px; }
.stat-value { font-size: 15px; font-weight: 600; }
.stat-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
.upload-stats-breakdown { margin-top: 8px; }
.upload-group + .upload-group { margin-top: 10px; }
.upload-group:empty { display: none; }

.local-preview-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(70px, 1fr)); gap: 6px; }
.local-preview-cell {
  aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; color: var(--muted); text-align: center; padding: 4px;
}
.local-preview-cell img { width: 100%; height: 100%; object-fit: cover; }
.local-preview-cell.more-tile { font-weight: 600; }

@media (max-width: 700px) {
  .upload-tabs { display: flex; }
  .upload-split { display: block; }
  .upload-pane[hidden] { display: none; }
}

a.back { color: var(--muted); font-size: 13px; text-decoration: none; display: inline-block; margin-bottom: 16px; }
.lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,0.9);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
.lightbox img, .lightbox video { max-width: 90vw; max-height: 80vh; object-fit: contain; }
.lightbox-caption { position: absolute; bottom: 24px; left: 0; right: 0; text-align: center; color: #fff; font-size: 13px; }
.lightbox-close, .lightbox-prev, .lightbox-next {
  position: absolute; background: rgba(255,255,255,0.1); border: none; color: #fff;
  font-size: 20px; padding: 10px 14px; border-radius: 8px; cursor: pointer;
}
.lightbox-close { top: 16px; right: 16px; }
.lightbox-prev { left: 16px; top: 50%; transform: translateY(-50%); }
.lightbox-next { right: 16px; top: 50%; transform: translateY(-50%); }
.folder-section-title { font-size: 13px; color: var(--muted); margin: 16px 0 6px; text-transform: uppercase; letter-spacing: 0.04em; }

/* ---------- SnapPile components ---------- */
.wordmark { font-weight: 800; color: var(--accent); font-size: 15px; margin: 0; text-decoration: none; display: inline-block; }
.wordmark--lg { font-size: 18px; }
.center { text-align: center; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }

.pill { border-radius: var(--radius-pill); padding: 10px 18px; font-weight: 600; background: var(--accent); color: #fff; border: 0; cursor: pointer; font-family: inherit; font-size: 14px; text-decoration: none; display: inline-block; }
.pill-soft { background: var(--accent-soft); color: var(--accent-deep); }
.pill-mint { background: var(--mint); color: var(--mint-ink); }
.pill-danger { background: var(--danger); color: #fff; }
.pill-sm { padding: 6px 12px; font-size: 13px; }
.pill:disabled { opacity: 0.5; cursor: not-allowed; }

/* guest */
.g-head { margin-bottom: 12px; }
.g-head h1 { margin: 4px 0 2px; }
.drop { border: 2px dashed var(--lilac); border-radius: 20px; background: var(--panel); min-height: 170px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; cursor: pointer; padding: 16px; box-shadow: var(--shadow); }
.drop--over { border-style: solid; border-color: var(--accent); background: var(--accent-soft); }
.drop-emoji { font-size: 40px; line-height: 1; }
.drop-title { font-weight: 700; font-size: 16px; margin-top: 8px; }
.drop-sub { color: var(--muted); font-size: 13px; }
.g-actions { display: flex; gap: 8px; justify-content: center; margin: 12px 0; }
details.extras { margin: 4px 0 8px; }
details.extras summary { color: var(--accent-deep); font-size: 13px; cursor: pointer; }
details.extras .row { margin-top: 8px; }
.pile { position: relative; height: 96px; margin: 16px 0 4px; }
.pile-thumb { position: absolute; top: 12px; width: 64px; height: 64px; border-radius: 12px; object-fit: cover; border: 2px solid var(--panel); box-shadow: var(--shadow); background: var(--accent-soft); }
.pile-thumb--uploading { opacity: .45; }
@keyframes land { from { transform: scale(1.15); } to { transform: scale(1); } }
.pile-thumb--land { animation: land 250ms ease-out; }
.sheet { position: fixed; left: 0; right: 0; bottom: 64px; height: 56px; background: var(--panel); border-radius: 20px 20px 0 0; box-shadow: 0 -6px 18px rgba(0,0,0,.12); transition: height 220ms ease; overflow: hidden; z-index: 4; }
.sheet--open { height: 92vh; overflow-y: auto; }
.sheet-handle { width: 100%; height: 56px; background: transparent; border: 0; font-weight: 600; color: var(--accent-deep); cursor: pointer; font-family: inherit; font-size: 14px; border-radius: 0; }
.sheet-body { padding: 0 16px 24px; }
.sheet-small { height: auto; bottom: 0; padding: 16px; z-index: 6; }
.fixed-bottom { position: fixed; left: 16px; right: 16px; bottom: 12px; z-index: 5; text-align: center; }
#toasts { position: fixed; top: 12px; left: 0; right: 0; display: flex; flex-direction: column; align-items: center; gap: 6px; z-index: 20; pointer-events: none; }
.toast { border-radius: var(--radius-pill); padding: 8px 14px; font-size: 13px; font-weight: 600; box-shadow: var(--shadow); }
.toast--ok { background: var(--mint); color: var(--mint-ink); }
.toast--warn { background: var(--accent-soft); color: var(--accent-deep); }
.toast--error { background: var(--coral); color: #5a1f1f; }
.banner { background: var(--accent-soft); color: var(--accent-deep); border-radius: 12px; padding: 8px 12px; font-size: 13px; margin-bottom: 12px; }
.banner a { color: inherit; font-weight: 600; }

/* owner */
.o-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.o-head h1 { margin: 0; flex: 1; }
.meter-wrap { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; flex: 1; min-width: 160px; }
.meter { flex: 1; max-width: 200px; height: 8px; border-radius: var(--radius-pill); background: var(--panel); border: 1px solid var(--border); overflow: hidden; }
.meter i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--mint), var(--accent)); }
.piles { display: grid; grid-template-columns: 1fr; gap: 20px; }
@media (min-width: 600px) { .piles { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 900px) { .piles { grid-template-columns: repeat(3, 1fr); } }
.pile-card { position: relative; padding-top: 14px; }
.pile-back { position: absolute; left: 10px; right: 10px; top: 0; height: 100px; border-radius: 14px; }
.pile-back--1 { background: var(--lilac); transform: rotate(-4deg) translateY(10px); }
.pile-back--2 { background: var(--accent-soft); transform: rotate(3deg) translateY(5px); }
.pile-face { position: relative; background: var(--panel); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; }
.cover { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 2px; height: 110px; }
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover-empty { background: var(--accent-soft); }
.pile-body { padding: 10px 12px 12px; }
.pile-name { font-weight: 800; font-size: 15px; }
.pile-stats { color: var(--muted); font-size: 13px; margin-top: 2px; }
.tag { display: inline-block; border-radius: var(--radius-pill); padding: 2px 8px; font-size: 12px; font-weight: 600; margin-top: 6px; }
.tag--live { background: #E3FCF3; color: #0B7A5A; }
.tag--done { background: var(--accent-soft); color: var(--accent-deep); }
.tag--empty { background: #FFE8E8; color: #B03A3A; }
.pile-actions { display: flex; gap: 6px; margin-top: 10px; }
.two-col { display: grid; grid-template-columns: 1fr; gap: 16px; }
@media (min-width: 800px) { .two-col { grid-template-columns: 1fr 280px; } }
.face { width: 44px; height: 44px; border-radius: 50%; overflow: hidden; border: 0; padding: 0; background: var(--lilac); cursor: pointer; }
.face img { width: 100%; height: 100%; object-fit: cover; display: block; }
.face--on { outline: 3px solid var(--mint); }
.faces { display: flex; gap: 8px; flex-wrap: wrap; }
.popover { position: absolute; width: 280px; background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; z-index: 10; }
.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--accent-soft); color: var(--accent-deep); border-radius: 6px; padding: 2px 6px; font-weight: 700; }
.qr { display: block; margin: 8px 0; border-radius: 8px; background: #fff; }
details.adv summary { cursor: pointer; font-weight: 600; color: var(--accent-deep); }
details.adv .row { margin-top: 10px; flex-wrap: wrap; }
.g-page { max-width: 520px; margin: 0 auto; }


/* code gate: shared by the guest "pile needs a code" page and the owner sign-in.
   Same family as the landing (tile stack, lowercase headline, pill), but built on the app's
   theme vars so it follows light/dark like the rest of the app. */
.gate { min-height: calc(100vh - 120px); min-height: calc(100svh - 120px); display: grid; place-items: center; padding: 24px 0; }
.gate-card { width: 100%; max-width: 420px; text-align: center; }
.gate-stack { position: relative; height: 84px; width: 160px; margin: 0 auto 22px; }
.gate-stack i {
  position: absolute; left: 50%; top: 50%; width: 62px; height: 62px; margin: -31px 0 0 -31px;
  border-radius: 14px; background: var(--panel); padding: 4px; box-shadow: var(--shadow);
  animation: gate-in 700ms cubic-bezier(.2, .8, .2, 1) both;
}
.gate-stack i::before { content: ""; position: absolute; inset: 4px; border-radius: 10px; background: var(--g); }
.gate-stack i:nth-child(1) { --g: linear-gradient(135deg, #B197FC, #8B6CF0); transform: translate(-44px, 6px) rotate(-12deg); animation-delay: 0ms; }
.gate-stack i:nth-child(2) { --g: linear-gradient(135deg, #63E6BE, #38D9A9); transform: translate(0, -4px) rotate(3deg); animation-delay: 80ms; z-index: 1; }
.gate-stack i:nth-child(3) { --g: linear-gradient(135deg, #FFD8A8, #FFB868); transform: translate(44px, 8px) rotate(11deg); animation-delay: 160ms; }
@keyframes gate-in { from { opacity: 0; translate: 0 18px; } to { opacity: 1; translate: 0 0; } }
.gate-wm { display: block; margin: 0 0 18px; font-size: 15px; }
.gate-h { margin: 0; font-size: clamp(26px, 6vw, 34px); font-weight: 800; letter-spacing: -.02em; line-height: 1.05; color: var(--text); text-wrap: balance; }
.gate-h em { font-style: normal; color: var(--accent); }
.gate-p { margin: 10px 0 22px; color: var(--muted); font-size: 14px; }
.gate-form { display: flex; gap: 8px; align-items: stretch; }
.gate-form input[type=password], .gate-form input[type=text] {
  flex: 1; text-align: center; font-size: 18px; font-weight: 600; letter-spacing: .18em; padding: 14px 16px;
  border-radius: var(--radius-pill); border: 2px solid var(--border);
}
.gate-form input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.gate-form .pill { padding: 0 22px; font-size: 15px; }
.gate-err { min-height: 20px; margin: 12px 0 0; font-size: 13px; font-weight: 600; color: var(--danger); }
.gate-foot { margin-top: 28px; font-size: 13px; color: var(--muted); }
.gate-foot a { color: var(--accent-deep); font-weight: 600; text-decoration: none; }
.gate-foot a:hover { text-decoration: underline; }
@media (max-width: 420px) { .gate-form { flex-direction: column; } .gate-form .pill { padding: 12px 22px; } }
