:root {
  --rose: #b76e79;
  --rose-dark: #9a5561;
  --bg: #faf6f4;
  --card: #ffffff;
  --ink: #2a2320;
  --muted: #8a7d76;
  --line: #efe7e3;
  --green: #3f9d6b;
  --blue: #4a7bb7;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.05);
}

/* touch-action: manipulation disables the browser's double-tap-to-zoom (and the
   ~300ms tap delay) so the double-tap-to-claim gesture never zooms the page,
   while normal scrolling and pinch-zoom still work. */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
html, body { margin: 0; }
body {
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  padding-bottom: env(safe-area-inset-bottom);
  /* No pull-to-refresh: it was reloading the page on a downward swipe. The board
     is live, so a manual refresh is never needed. */
  overscroll-behavior-y: none;
}
button { font: inherit; cursor: pointer; }
img { max-width: 100%; }

/* ---------------- Login ---------------- */
.login {
  min-height: 100dvh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px; text-align: center;
}
.login h1 { font-size: 30px; font-weight: 700; margin: 0 0 6px; letter-spacing: -.01em; }
.login p.motto { color: var(--rose); font-weight: 600; font-size: 15px; margin: -2px 0 4px; }
.login p.tag { color: var(--muted); margin: 0 0 28px; }
.card-box {
  width: 100%; max-width: 360px; background: var(--card); border-radius: 18px;
  box-shadow: var(--shadow); padding: 22px;
}
.role-toggle { display: flex; gap: 8px; margin-bottom: 18px; }
.role-toggle button {
  flex: 1; padding: 10px; border-radius: 10px; border: 1.5px solid var(--line);
  background: #fff; color: var(--muted); font-weight: 600;
}
.role-toggle button.active { border-color: var(--rose); color: var(--rose); background: #fdf2f3; }
label.fld { display: block; text-align: left; font-size: 13px; color: var(--muted); margin: 0 0 6px; font-weight: 600; }
input, select, textarea {
  width: 100%; padding: 12px 14px; border: 1.5px solid var(--line); border-radius: 10px;
  font: inherit; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--rose); }
.btn-primary {
  width: 100%; margin-top: 16px; padding: 13px; border: none; border-radius: 10px;
  background: var(--rose); color: #fff; font-weight: 700; font-size: 16px;
}
.btn-primary:disabled { opacity: .5; }
.btn-primary:active { background: var(--rose-dark); }
/* Home page: sales to join + start-a-sale */
.card-box.sale-list { padding: 4px 0; }
.sale-row {
  display: grid; grid-template-columns: 1fr auto; grid-template-areas: "host go" "meta go";
  align-items: center; gap: 2px 12px; padding: 13px 18px; text-align: left;
  text-decoration: none; color: var(--ink); border-bottom: 1px solid var(--line);
}
.sale-row:last-child { border-bottom: none; }
.sale-row:active { background: #faf3f1; }
.sale-host { grid-area: host; font-weight: 700; }
.sale-meta { grid-area: meta; font-size: 13px; color: var(--muted); }
.sale-go { grid-area: go; color: var(--rose); font-weight: 700; font-size: 14px; }
.sale-empty { color: var(--muted); font-size: 14px; line-height: 1.5; margin: 14px 18px; text-align: center; }
.text-link { margin-top: 14px; color: var(--rose-dark); font-weight: 600; font-size: 14px; text-decoration: none; }
.btn-secondary {
  width: 100%; max-width: 360px; margin-top: 14px; padding: 13px; border-radius: 10px;
  border: 1.5px solid var(--rose); background: #fff; color: var(--rose-dark); font-weight: 700; font-size: 16px;
}
.btn-secondary:active { background: #faf3f1; }
.card-box.new-sale { margin-top: 14px; }
.check-row { display: flex; align-items: center; gap: 8px; margin-top: 14px; font-size: 14px; color: var(--ink); text-align: left; cursor: pointer; }
.check-row input { width: 18px; height: 18px; padding: 0; margin: 0; accent-color: var(--rose); }
.login-err { color: #b1443f; font-size: 13px; margin: 12px 0 0; min-height: 1em; text-align: center; }

/* ---------------- Header ---------------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; padding-top: calc(12px + env(safe-area-inset-top));
  background: rgba(250,246,244,.92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar .title { font-weight: 700; font-size: 17px; }
.topbar .who { color: var(--muted); font-size: 13px; margin-left: auto; }
.topbar .who b { color: var(--rose); }
.post-btn {
  border: none; background: var(--rose); color: #fff; font-weight: 700;
  padding: 9px 15px; border-radius: 999px; margin-left: 8px;
}
.end-btn {
  border: 1.5px solid var(--rose); background: #fff; color: var(--rose-dark); font-weight: 700;
  padding: 8px 13px; border-radius: 999px; font-size: 13px; margin-left: 8px;
}
.end-btn:disabled { opacity: .5; }
.bell {
  position: relative; border: none; background: transparent; font-size: 20px; line-height: 1;
  padding: 6px; margin-left: 4px; cursor: pointer;
}
.bell-badge {
  position: absolute; top: -1px; right: -1px; min-width: 18px; height: 18px; padding: 0 4px;
  border-radius: 999px; background: #d64545; color: #fff; font-size: 11px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; box-sizing: border-box;
}
.notif-sheet { max-width: 440px; }
.notif-list { display: flex; flex-direction: column; }
.notif-row {
  display: flex; gap: 10px; align-items: flex-start; text-align: left; width: 100%;
  border: none; background: transparent; padding: 12px 4px; border-bottom: 1px solid var(--line);
  font: inherit; color: var(--ink); cursor: pointer;
}
.notif-row:active { background: #faf3f1; }
.notif-ico { font-size: 20px; line-height: 1.3; flex: 0 0 auto; }
.notif-txt { flex: 1; font-size: 14px; line-height: 1.4; }
.notif-time { display: block; color: var(--muted); font-size: 11px; margin-top: 2px; }
.notif-empty { color: var(--muted); text-align: center; padding: 30px 12px; line-height: 1.5; }
.notif-open {
  flex: 1; display: flex; text-align: left; border: none; background: transparent;
  font: inherit; color: var(--ink); cursor: pointer; padding: 0;
}
.notif-ack {
  flex: 0 0 auto; align-self: center; border: none; background: var(--green); color: #fff;
  font-weight: 700; font-size: 13px; padding: 8px 12px; border-radius: 999px; white-space: nowrap;
}
.notif-ack.done { background: #eaf5ee; color: var(--green); }

/* ---------------- Confirm dialog ---------------- */
.confirm-sheet { max-width: 400px; }
.confirm-row { display: flex; gap: 10px; }
.confirm-row button { flex: 1; padding: 13px; border-radius: 11px; font-weight: 700; font-size: 15px; border: none; }
.confirm-cancel { background: #fff; color: var(--ink); border: 1.5px solid var(--line) !important; }
.confirm-end { background: var(--rose); color: #fff; }
.confirm-end:disabled { opacity: .7; }

/* ---------------- Grid ---------------- */
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; padding: 14px; }
@media (min-width: 560px) { .grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 820px) { .grid { grid-template-columns: repeat(4, 1fr); } }

.item {
  background: var(--card); border-radius: 14px; overflow: hidden; box-shadow: var(--shadow);
  position: relative; user-select: none; -webkit-user-select: none;
}
.item .imgwrap { position: relative; aspect-ratio: 3/4; background: #eee5e1; }
.item .imgwrap img { width: 100%; height: 100%; object-fit: cover; display: block; }
.item .heart {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 72px; opacity: 0; pointer-events: none;
}
.item .heart.pop { animation: pop .6s ease; }
@keyframes pop { 0%{opacity:0;transform:scale(.4)} 30%{opacity:1;transform:scale(1.1)} 100%{opacity:0;transform:scale(1)} }

.badge {
  position: absolute; top: 8px; left: 8px; font-size: 11px; font-weight: 700;
  padding: 4px 8px; border-radius: 999px; background: rgba(255,255,255,.92); color: var(--ink);
  box-shadow: 0 1px 2px rgba(0,0,0,.12);
}
.badge.mine { background: var(--rose); color: #fff; }
.badge.claimed { background: #fff; color: var(--rose-dark); }
.badge.queued { background: var(--blue); color: #fff; }
.badge.available { background: var(--green); color: #fff; }
.badge.unavail { background: #6b615b; color: #fff; }
.imgwrap.dimmed img { opacity: .45; }
.wait-pill {
  position: absolute; top: 8px; right: 8px; font-size: 11px; font-weight: 700;
  padding: 4px 7px; border-radius: 999px; background: rgba(42,35,32,.72); color: #fff;
}
.count-pill {
  position: absolute; bottom: 8px; right: 8px; font-size: 11px; font-weight: 700;
  padding: 4px 7px; border-radius: 999px; background: rgba(42,35,32,.72); color: #fff;
}
.item .meta { padding: 8px 10px 10px; }
.item .cap { font-size: 13px; line-height: 1.35; max-height: 2.7em; overflow: hidden; }
.item .sub { font-size: 11px; color: var(--muted); margin-top: 3px; display: flex; gap: 8px; }

.empty { text-align: center; color: var(--muted); padding: 60px 24px; }

/* ---------------- Modal ---------------- */
.overlay {
  position: fixed; inset: 0; z-index: 40; background: rgba(30,22,20,.55);
  display: flex; align-items: flex-end; justify-content: center;
}
@media (min-width: 560px) { .overlay { align-items: center; } }
.sheet {
  background: var(--card); width: 100%; max-width: 480px; max-height: 92dvh;
  border-radius: 18px 18px 0 0; overflow-y: auto; box-shadow: var(--shadow);
  overscroll-behavior: contain;
}
.sheet-grab {
  position: absolute; top: 8px; left: 50%; transform: translateX(-50%); z-index: 3;
  width: 40px; height: 5px; border-radius: 999px; background: rgba(255,255,255,.6);
}
@media (min-width: 560px) { .sheet { border-radius: 18px; } }
.gallery {
  display: flex; overflow-x: auto; scroll-snap-type: x mandatory; background: #1c1512;
  -webkit-overflow-scrolling: touch;
}
.gallery img {
  flex: 0 0 100%; width: 100%; max-height: 52dvh; object-fit: contain; scroll-snap-align: center; display: block;
}
.swipe-hint { text-align: center; font-size: 12px; color: var(--muted); padding: 6px 0 0; }
.sheet .pad { padding: 16px; }
.sheet h2 { margin: 0 0 4px; font-size: 18px; }
.sheet .poster { color: var(--muted); font-size: 13px; margin: 0 0 14px; }
.status-line { font-weight: 600; margin: 0 0 12px; }
.status-line.available { color: var(--green); }
.status-line.mine { color: var(--rose); }
.status-line.claimed { color: var(--rose-dark); }
.status-line.queued { color: var(--blue); }
.status-line.unavail { color: var(--muted); }
.waitlist { font-size: 13px; color: var(--muted); margin: -6px 0 14px; }
.action-row { display: flex; gap: 10px; margin-bottom: 18px; }
.action-row button { flex: 1; padding: 13px; border-radius: 11px; border: none; font-weight: 700; }
.act-claim { background: var(--rose); color: #fff; }
.act-queue { background: var(--blue); color: #fff; }
.act-release { background: #fff; color: var(--rose-dark); border: 1.5px solid var(--rose) !important; }
.act-force { background: #fff; color: var(--rose-dark); border: 1.5px solid var(--rose) !important; }
.act-confirm { background: var(--green); color: #fff; }
#grace-count { font-weight: 700; opacity: .9; }
.lock-note { font-size: 13px; color: var(--muted); margin: -4px 0 16px; }
.seen-note { font-size: 13px; color: var(--green); font-weight: 600; margin: -4px 0 14px; }

.comments { border-top: 1px solid var(--line); padding-top: 14px; }
.comments h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 10px; }
.cmt { margin-bottom: 10px; font-size: 14px; }
.cmt b { color: var(--rose-dark); }
.cmt .t { color: var(--muted); font-size: 11px; margin-left: 6px; }
.cmt-form { display: flex; gap: 8px; margin-top: 12px; }
.cmt-form input { flex: 1; }
.cmt-form button { border: none; background: var(--rose); color: #fff; border-radius: 10px; padding: 0 16px; font-weight: 700; }
.size-chip {
  border: 1.5px solid var(--line); background: #fff; color: var(--ink); font-weight: 700;
  padding: 8px 12px; border-radius: 999px; font-size: 14px; min-width: 46px;
}
.size-chip:active { background: #fdf2f3; border-color: var(--rose); color: var(--rose-dark); }
.size-chip.on { background: var(--rose); border-color: var(--rose); color: #fff; }
/* Sizes: tag on the card, filter bar on the board, picker/line on the item */
.size-pill {
  position: absolute; bottom: 8px; left: 8px; font-size: 11px; font-weight: 800;
  padding: 4px 8px; border-radius: 999px; background: #fff; color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.15);
}
.size-bar { display: flex; gap: 8px; overflow-x: auto; padding: 12px 14px 0; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.size-bar::-webkit-scrollbar { display: none; }
.size-bar:empty { display: none; }
.size-bar .size-chip, .size-row .size-chip { flex: 0 0 auto; padding: 6px 12px; font-size: 13px; min-width: 0; }
.size-row { display: flex; align-items: center; gap: 8px; overflow-x: auto; margin: 0 0 14px; padding-bottom: 2px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.size-row::-webkit-scrollbar { display: none; }
.size-row-label { flex: 0 0 auto; font-size: 12px; font-weight: 700; color: var(--muted); }
.size-line { margin: 0 0 10px; font-size: 15px; }
.cam-sizes { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 12px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.cam-sizes::-webkit-scrollbar { display: none; }
.cam-size {
  flex: 0 0 auto; border: 1.5px solid rgba(255,255,255,.7); background: rgba(0,0,0,.35); color: #fff;
  font-weight: 700; font-size: 13px; padding: 6px 11px; border-radius: 999px;
}
.cam-size.on { background: #fff; color: var(--ink); border-color: #fff; }
.close-x {
  position: absolute; top: 10px; right: 10px; z-index: 2; width: 34px; height: 34px; border-radius: 999px;
  border: none; background: rgba(0,0,0,.5); color: #fff; font-size: 20px; line-height: 1;
}

/* ---------------- Post form ---------------- */
.post-preview { width: 100%; aspect-ratio: 3/4; object-fit: cover; border-radius: 12px; background: #eee5e1; margin-bottom: 12px; }
.file-drop {
  display: flex; align-items: center; justify-content: center; text-align: center;
  aspect-ratio: 3/4; border: 2px dashed var(--line); border-radius: 12px; color: var(--muted);
  margin-bottom: 12px; padding: 20px;
}

/* ---------------- Floating post button ---------------- */
.fab {
  position: fixed; right: 16px; z-index: 30;
  bottom: calc(18px + env(safe-area-inset-bottom));
  border: none; background: var(--rose); color: #fff; font-weight: 800; font-size: 16px;
  padding: 15px 22px; border-radius: 999px; box-shadow: 0 6px 20px rgba(183,110,121,.5);
}
.fab:disabled { opacity: .8; }
.fab:active { background: var(--rose-dark); }

/* ---------------- In-app camera ---------------- */
.cam { position: fixed; inset: 0; z-index: 50; background: #000; overflow: hidden; }
.cam video {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000;
}
.cam-flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
.cam-flash.on { animation: camflash .3s ease; }
@keyframes camflash { 0% { opacity: 0; } 12% { opacity: .9; } 100% { opacity: 0; } }

.cam-x {
  position: absolute; z-index: 2; top: calc(12px + env(safe-area-inset-top)); left: 12px;
  width: 40px; height: 40px; border-radius: 999px; border: none;
  background: rgba(0,0,0,.45); color: #fff; font-size: 24px; line-height: 1;
}
.cam-bar {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 2;
  padding: 14px 16px calc(18px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, rgba(0,0,0,.65), rgba(0,0,0,0));
}
.cam-strip { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 12px; -webkit-overflow-scrolling: touch; }
.cam-strip:empty { display: none; }
.cam-thumb { position: relative; flex: 0 0 auto; }
.cam-thumb img {
  width: 52px; height: 52px; object-fit: cover; border-radius: 8px;
  border: 2px solid rgba(255,255,255,.9); display: block;
}
.cam-thumb-x {
  position: absolute; top: -7px; right: -7px; width: 20px; height: 20px; border-radius: 999px;
  border: none; background: rgba(0,0,0,.85); color: #fff; font-size: 13px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
}
.cam-controls { display: flex; align-items: center; gap: 12px; }
.cam-count {
  flex: 1; color: #fff; font-size: 13px; font-weight: 600; text-align: left;
  text-shadow: 0 1px 3px rgba(0,0,0,.6);
}
.cam-shutter {
  flex: 0 0 auto; width: 74px; height: 74px; border-radius: 999px;
  background: #fff; border: 4px solid rgba(255,255,255,.55); box-shadow: 0 0 0 2px rgba(0,0,0,.25);
}
.cam-shutter:active { transform: scale(.93); }
.cam-post {
  flex: 1; text-align: right; border: none; background: transparent; color: #fff;
  font-weight: 800; font-size: 16px; padding: 10px 2px; text-shadow: 0 1px 3px rgba(0,0,0,.6);
}
.cam-post:disabled { opacity: .45; }

.remove-post {
  display: block; width: 100%; margin-top: 16px; padding: 12px; border-radius: 10px;
  border: 1.5px solid var(--line); background: #fff; color: #b1443f; font-weight: 600;
}

/* ---------------- Toast ---------------- */
#toast-wrap { position: fixed; left: 0; right: 0; bottom: 18px; z-index: 60; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast {
  background: #2a2320; color: #fff; padding: 11px 16px; border-radius: 999px; font-size: 14px;
  box-shadow: var(--shadow); max-width: 90vw; animation: rise .3s ease;
}
@keyframes rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
.toast-tappable { pointer-events: auto; cursor: pointer; }
.toast-hint { display: block; font-size: 11px; opacity: .75; margin-top: 2px; font-weight: 600; }
.toast.done { background: #2f7d54; }
.hidden { display: none !important; }
