:root {
  --bg: #fbf6ef;
  --card: #ffffff;
  --ink: #2b1d1a;
  --muted: #7d6a63;
  --line: #eadfd3;
  --rose: #9f1239;
  --rose-soft: #fce7ec;
  --gold: #b08d57;
  --danger: #b91c1c;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { margin: 0; }

body {
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 0%, #f8e1e7 0, transparent 40%),
    radial-gradient(circle at 90% 10%, #f3e6d3 0, transparent 40%),
    var(--bg);
  padding-bottom: env(safe-area-inset-bottom);
}

/* Header */
.hero { text-align: center; padding: 48px 16px 20px; }

.eyebrow {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--gold);
}

h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 400;
  font-size: clamp(34px, 9vw, 54px);
  line-height: 1.1;
  color: var(--rose);
  text-wrap: balance;
}

.flourish {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 14px 0;
  color: var(--gold);
  font-size: 14px;
}

.flourish span { width: 48px; height: 1px; background: linear-gradient(90deg, transparent, var(--gold), transparent); }

.lede {
  max-width: 34ch;
  margin: 0 auto;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.6;
}

/* Layout */
.wrap { max-width: 720px; margin: 0 auto; padding: 8px 16px 48px; display: grid; gap: 16px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 22px 20px;
  box-shadow: 0 10px 30px rgba(107, 57, 44, 0.07);
}

h2 {
  margin: 0 0 14px;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 400;
  font-size: 22px;
}

label { display: block; margin: 14px 0 6px; font-size: 13px; font-weight: 600; color: var(--muted); }

input[type="text"] {
  width: 100%;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fffdfb;
  color: var(--ink);
  font-size: 16px;
  outline: none;
}

input[type="text"]:focus { border-color: var(--rose); box-shadow: 0 0 0 3px var(--rose-soft); }

#joinCode { text-transform: uppercase; letter-spacing: 0.15em; font-family: "Courier New", monospace; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 13px 20px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
}

.btn.primary { background: var(--rose); border-color: var(--rose); color: #fff; }
.btn.wide { width: 100%; margin-top: 20px; }
.btn:disabled { opacity: 0.6; cursor: default; }

.error { margin: 12px 0 0; min-height: 18px; color: var(--danger); font-size: 14px; }
.loading { text-align: center; color: var(--muted); }

/* Uploader */
.greeting-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; }
.greeting { margin: 0; font-size: 17px; min-width: 0; overflow-wrap: anywhere; }

.logout {
  flex-shrink: 0;
  padding: 7px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.logout:hover { border-color: var(--rose); color: var(--rose); }
.greeting span { color: var(--rose); }

.pick-row { display: grid; grid-template-columns: 2fr 1fr; gap: 10px; }

.pick {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 108px;
  margin: 0;
  padding: 14px;
  border: 1.5px dashed var(--gold);
  border-radius: 16px;
  background: #fffaf3;
  color: var(--ink);
  font-size: 15px;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
}

.pick.primary { border-style: solid; border-color: var(--rose); background: var(--rose); color: #fff; }
.pick input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.pick-icon { font-size: 26px; line-height: 1; }

.note { margin: 14px 0 0; font-size: 13px; color: var(--muted); text-align: center; }

/* Upload queue */
.queue { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 8px; }
.queue:empty { display: none; }

.q-item {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fffdfb;
}

.q-thumb {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--rose-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--rose);
  font-size: 18px;
}

.q-info { min-width: 0; }
.q-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.q-status { font-size: 12px; color: var(--muted); margin-top: 2px; }
.q-item.failed .q-status { color: var(--danger); }
.q-item.done .q-status { color: #15803d; }

.q-bar { height: 5px; margin-top: 6px; border-radius: 999px; background: var(--line); overflow: hidden; }
.q-bar span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--gold), var(--rose)); transition: width 0.2s ease; }

.q-retry { padding: 6px 12px; font-size: 13px; }

/* Your uploads */
.mine-head { display: flex; justify-content: space-between; align-items: baseline; }
.count { font-size: 13px; color: var(--muted); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 6px; }

.tile {
  position: relative;
  aspect-ratio: 1;
  padding: 0;
  border: 0;
  border-radius: 10px;
  overflow: hidden;
  background: var(--rose-soft);
  cursor: pointer;
}

.tile img, .tile video { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }

.tile .badge {
  position: absolute;
  right: 6px;
  bottom: 6px;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(0,0,0,0.55);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
}

.tile .placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  color: var(--rose);
  font-size: 12px;
  font-weight: 600;
}

.empty { margin: 4px 0 0; color: var(--muted); font-size: 14px; text-align: center; }

/* Viewer */
.viewer { position: fixed; inset: 0; z-index: 50; background: rgba(20, 12, 10, 0.95); display: flex; flex-direction: column; }

.viewer-top { display: flex; align-items: center; gap: 10px; padding: 12px 14px; padding-top: max(12px, env(safe-area-inset-top)); color: #fff; }
.viewer-count { flex: 1; font-size: 14px; opacity: 0.8; }

.viewer-btn {
  padding: 8px 14px;
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 999px;
  background: rgba(255,255,255,0.08);
  color: #fff;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}

.viewer-btn.danger { border-color: rgba(252,165,165,0.5); color: #fecaca; }

.viewer-stage { flex: 1; display: flex; align-items: center; justify-content: center; padding: 8px; min-height: 0; }
.viewer-stage img, .viewer-stage video { max-width: 100%; max-height: 100%; border-radius: 8px; }
.viewer-stage .placeholder { color: #fff; text-align: center; line-height: 1.6; }

.viewer-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: rgba(255,255,255,0.12);
  color: #fff;
  font-size: 28px;
  cursor: pointer;
}

.viewer-nav.prev { left: 10px; }
.viewer-nav.next { right: 10px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translate(-50%, 160%);
  max-width: calc(100% - 32px);
  padding: 12px 18px;
  border-radius: 12px;
  background: var(--ink);
  color: #fff;
  font-size: 14px;
  transition: transform 0.25s ease;
  z-index: 60;
}

.toast.show { transform: translate(-50%, 0); }

@media (max-width: 420px) {
  .pick-row { grid-template-columns: 1fr; }
  .pick { min-height: 84px; flex-direction: row; }
}

/* Fully hidden when not showing (an empty toast used to peek above the bottom edge) */
.toast { opacity: 0; transition: transform 0.25s ease, opacity 0.2s ease; }
.toast.show { opacity: 1; }
