:root {
  --bg: #faf6f1;
  --paper: #fffdfa;
  --ink: #2d2723;
  --muted: #8a7f76;
  --line: #ece4da;
  --accent: #d9604c;
  --accent-soft: #fbe7e2;
  --taken: #4f9a7a;
  --radius: 18px;
  --shadow: 0 1px 2px rgb(60 40 20 / 6%), 0 6px 20px rgb(60 40 20 / 6%);
  --shadow-hover: 0 2px 4px rgb(60 40 20 / 8%), 0 14px 32px rgb(60 40 20 / 12%);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1200px 500px at 10% -10%, #fde9df 0%, transparent 60%),
    radial-gradient(900px 500px at 110% 0%, #e9f1ea 0%, transparent 55%),
    var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--sans);
}

button { font: inherit; color: inherit; cursor: pointer; }

.top {
  max-width: 1080px;
  margin: 0 auto;
  padding: 56px 24px 24px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
}

h1 {
  margin: 0;
  font: 600 clamp(2.2rem, 5vw, 3.2rem)/1.1 var(--serif);
  letter-spacing: -0.01em;
}

.subtitle { margin: 8px 0 0; color: var(--muted); }
.subtitle:empty { display: none; }

.legend {
  margin: 14px 0 0;
  display: flex;
  align-items: baseline;
  gap: 8px;
  color: var(--muted);
  font-size: 0.85rem;
}
.legend-hearts { color: var(--accent); letter-spacing: 1px; white-space: nowrap; }
.legend-hearts span:last-child { color: var(--line); }

.top-controls { display: flex; align-items: center; gap: 12px; }

.languages {
  display: flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  box-shadow: var(--shadow);
}
.languages button {
  padding: 6px 12px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
}
.languages button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }

.whoami {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px 6px 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  box-shadow: var(--shadow);
  white-space: nowrap;
}
.whoami[hidden] { display: none; }

.badge {
  display: inline-grid;
  place-items: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--taken);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
}

.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  flex: none;
  display: block;
}
.avatar-slot { display: contents; }

main { max-width: 1080px; margin: 0 auto; padding: 8px 24px 64px; }

.items {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 18px;
}

.items + .group, .group + .group { margin-top: 28px; }

.group summary {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.group summary::-webkit-details-marker { display: none; }
.group summary::before {
  content: "";
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg);
  transition: transform 0.15s ease;
}
.group[open] summary::before { transform: rotate(45deg); }
.group:not([open]) summary { margin-bottom: 0; }
.group-label { margin: 0; font: 600 1.45rem/1.2 var(--serif); }
.group-count {
  padding: 1px 9px;
  border-radius: 999px;
  background: var(--line);
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
}

.card {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 20px 20px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: var(--shadow);
  text-align: left;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.card:hover, .card:focus-visible {
  transform: translateY(-2px);
  box-shadow: var(--shadow-hover);
  outline: none;
}
.card.mine { border-color: var(--accent); }

.label { margin: 0; font: 600 1.25rem/1.25 var(--serif); }

.want { display: flex; gap: 2px; font-size: 0.95rem; line-height: 1; }
.heart { color: var(--line); }
.heart.on { color: var(--accent); }

.description { margin: 0; color: var(--muted); font-size: 0.95rem; }

.card-footer {
  margin-top: auto;
  padding-top: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 38px;
}
.count { font-size: 0.85rem; color: var(--taken); font-weight: 600; }
.count.free { color: var(--muted); font-weight: 400; }

.stack { display: flex; }
.stack .avatar { border: 2px solid var(--paper); box-sizing: content-box; }
.stack > * + * { margin-left: -8px; }
.more {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--line);
  font-size: 0.75rem;
  border: 2px solid var(--paper);
  margin-left: -8px;
}

dialog {
  border: none;
  border-radius: 22px;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 30px 80px rgb(40 20 10 / 25%);
  width: min(520px, calc(100vw - 32px));
}
dialog::backdrop { background: rgb(45 39 35 / 35%); backdrop-filter: blur(3px); }
dialog[open] { animation: pop 0.18s ease-out; }
@keyframes pop {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
}

.dialog-body, .name-dialog form { position: relative; padding: 28px; }
.dialog-close { position: absolute; top: 12px; right: 12px; margin: 0; }
.dialog-close button {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: transparent;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--muted);
}
.dialog-close button:hover { background: var(--bg); }

.dialog-label { margin: 0 40px 10px 0; font: 600 1.7rem/1.2 var(--serif); }
.card-dialog .want { font-size: 1.15rem; }
.dialog-description { white-space: pre-line; margin: 16px 0 0; }
.dialog-description:empty { display: none; }

.givers-section { margin: 22px 0; padding-top: 18px; border-top: 1px solid var(--line); }
.givers-section h3 {
  margin: 0 0 10px;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.givers { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.giver {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px 4px 4px;
  border-radius: 999px;
  background: var(--bg);
}
.giver.me { background: var(--accent-soft); }
.no-givers { margin: 0; color: var(--muted); }
.no-givers[hidden] { display: none; }

.pledge, .actions button {
  padding: 12px 20px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  font-weight: 600;
  transition: filter 0.15s ease;
}
.pledge { width: 100%; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { filter: brightness(1.06); }
button:disabled { opacity: 0.6; cursor: progress; }

.name-dialog h2 { margin: 0; font: 600 1.5rem/1.2 var(--serif); }
.hint { margin: 6px 0 18px; color: var(--muted); }
.name-row { display: flex; align-items: center; gap: 12px; }
.name-row .avatar { width: 44px; height: 44px; }
#name-input {
  flex: 1;
  min-width: 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  font: inherit;
  background: #fff;
}
#name-input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.actions .quiet { margin-right: auto; border-color: transparent; color: var(--muted); }
.field-error { margin: 10px 0 0; color: #a8392a; font-size: 0.9rem; }
.field-error[hidden] { display: none; }

.google-section[hidden] { display: none; }
.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 22px 0 16px;
  color: var(--muted);
  font-size: 0.85rem;
}
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--line); }
.google-button { display: flex; justify-content: center; min-height: 44px; }
.hint.small { margin: 12px 0 0; font-size: 0.85rem; }

.error {
  margin-top: 24px;
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: #8a2b1c;
}

@media (max-width: 560px) {
  .top { padding-top: 32px; flex-direction: column; align-items: flex-start; }
  .top-controls { flex-direction: row-reverse; }
}
