:root {
  --bg: #fdf6ec;
  --card: #ffffff;
  --ink: #4a3728;
  --butter: #f7c948;
  --butter-dark: #e0a800;
  --open: #fff3d6;
  --open-border: #ecd9a8;
  --selected: #6aa84f;
  --taken-bg: #f3d9dc;
  --taken-border: #ddb2b8;
  --taken-ink: #8c555d;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

.wrap {
  max-width: 880px;
  margin: 0 auto;
  padding: 1.5rem 1rem 5rem;
}

header h1 { margin: 0.25rem 0; font-size: 1.9rem; }
.tagline, .prize { margin: 0.25rem 0; }
.prize strong { color: var(--butter-dark); }
.back { color: var(--ink); opacity: 0.7; text-decoration: none; font-size: 0.9rem; }
.back:hover { opacity: 1; }

.notice {
  margin: 1rem 0 0;
  padding: 0.75rem 1rem;
  border-radius: 10px;
  background: #ffe9e9;
  border: 1px solid #f0b9b9;
  font-weight: 600;
}

.notice.success { background: #e6f4e0; border-color: #b7dcae; }

.muted { opacity: 0.7; }

.badge {
  display: inline-block;
  font-size: 0.62rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 99px;
  background: #efe7d6;
  border: 1px solid #d8cdb4;
  vertical-align: middle;
}

.gallery { margin-top: 1.25rem; }

.gallery-main {
  display: block;
  width: 100%;
  max-height: 400px;
  object-fit: contain;
  background: var(--card);
  border-radius: 14px;
  border: 1px solid var(--open-border);
  cursor: zoom-in;
}

.thumbs {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.thumb-btn {
  width: 72px;
  height: 54px;
  padding: 0;
  border-radius: 8px;
  overflow: hidden;
  border: 2px solid var(--open-border);
  background: none;
  cursor: pointer;
  opacity: 0.75;
}

.thumb-btn img { width: 100%; height: 100%; object-fit: cover; display: block; }

.thumb-btn.active, .thumb-btn:hover { opacity: 1; }

.thumb-btn.active { border-color: var(--butter-dark); }

.tile.locked {
  background: #efeae2;
  border-color: #d8d2c6;
  color: #9b9184;
  cursor: not-allowed;
}

.cards {
  margin-top: 1.5rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 1rem;
}

.card {
  display: flex;
  flex-direction: column;
  background: var(--card);
  border-radius: 14px;
  overflow: hidden;
  text-decoration: none;
  color: var(--ink);
  border: 1px solid var(--open-border);
  box-shadow: 0 2px 8px rgba(74, 55, 40, 0.07);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 20px rgba(74, 55, 40, 0.15);
}

.thumb {
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  background: var(--open);
}

.thumb.placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
}

.card-body { padding: 0.85rem 1rem 1rem; }

.card-body h2 { margin: 0 0 0.35rem; font-size: 1.15rem; }

.desc { margin: 0 0 0.35rem; font-size: 0.88rem; opacity: 0.85; }

.prize { font-size: 0.85rem; color: var(--butter-dark); font-weight: 600; }

.meta { font-size: 0.88rem; margin: 0.4rem 0 0.55rem; }

.progress {
  height: 8px;
  border-radius: 99px;
  background: var(--open);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--butter), var(--selected));
  transition: width 0.4s ease;
}

.taken-line { font-size: 0.8rem; margin: 0.45rem 0 0; opacity: 0.85; }

.controls {
  margin: 1.5rem 0 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.controls input {
  padding: 0.65rem 0.85rem;
  font-size: 1rem;
  border-radius: 10px;
  border: 2px solid var(--open-border);
  background: var(--card);
  color: var(--ink);
}

.controls input:focus { outline: none; border-color: var(--butter-dark); }

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

.tile {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 12px;
  border: 2px solid var(--open-border);
  background: var(--open);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font: inherit;
  color: var(--ink);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}

.tile .num { font-size: 1.15rem; font-weight: 700; }

.tile .who {
  font-size: 0.62rem;
  line-height: 1.05;
  text-align: center;
  padding: 0 4px;
  overflow-wrap: anywhere;
}

.tile.open:hover { transform: translateY(-2px); box-shadow: 0 3px 8px rgba(74, 55, 40, 0.18); }

.tile.selected { background: var(--selected); border-color: #4e7d38; color: #fff; }

.tile.taken {
  background: var(--taken-bg);
  border-color: var(--taken-border);
  color: var(--taken-ink);
  cursor: not-allowed;
}

.legend {
  margin-top: 1rem;
  display: flex;
  gap: 1.25rem;
  font-size: 0.85rem;
}

.legend span { display: inline-flex; align-items: center; gap: 0.4rem; }

.dot { width: 14px; height: 14px; border-radius: 4px; display: inline-block; }
.dot.open { background: var(--open); border: 1px solid var(--open-border); }
.dot.selected { background: var(--selected); }
.dot.taken { background: var(--taken-bg); border: 1px solid var(--taken-border); }

.bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  background: var(--card);
  border-top: 2px solid var(--open-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.8rem max(1rem, calc((100vw - 880px) / 2));
}

.bar button,
button.primary,
button.secondary,
button.danger,
form button[type="submit"] {
  font-size: 1rem;
  font-weight: 700;
  padding: 0.65rem 1.4rem;
  border-radius: 10px;
  border: none;
  cursor: pointer;
}

.bar button, form button[type="submit"] { background: var(--butter); color: var(--ink); }

.bar button:disabled, form button[type="submit"]:disabled { opacity: 0.45; cursor: not-allowed; }

.bar button:not(:disabled):hover,
form button[type="submit"]:not(:disabled):hover,
button.primary:hover:not(:disabled) { background: var(--butter-dark); }

button.primary { background: var(--butter); color: var(--ink); }

button.secondary {
  background: transparent;
  border: 2px solid var(--open-border);
  color: var(--ink);
}

button.danger { background: #d64545; color: #fff; }
button.danger:hover:not(:disabled) { background: #b93a3a; }

dialog {
  border: none;
  border-radius: 16px;
  padding: 1.5rem 1.75rem;
  max-width: 420px;
  width: calc(100% - 2rem);
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.25);
}

dialog::backdrop { background: rgba(74, 55, 40, 0.45); }

dialog h2 { margin-top: 0; }

#checkoutSpots { font-size: 0.95rem; }

.owed-label { margin-bottom: 0.15rem; font-weight: 600; }

.owed { margin: 0; font-size: 2.2rem; font-weight: 800; color: var(--butter-dark); }

.pay-note { font-size: 0.82rem; opacity: 0.8; }

.pay-list { display: flex; flex-direction: column; gap: 0.6rem; margin-top: 1rem; }

.pay-opt {
  width: 100%;
  padding: 0.7rem 1rem;
  font-size: 1rem;
  font-weight: 700;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  background: var(--butter);
  color: var(--ink);
}

.pay-opt:hover:not(:disabled) { background: var(--butter-dark); }

.pay-opt:disabled { opacity: 0.5; cursor: wait; }

.dialog-buttons { display: flex; gap: 0.75rem; margin-top: 0.9rem; }

.dialog-buttons button { flex: 1; padding: 0.7rem 1rem; font-size: 1rem; font-weight: 700; }
