/*
 * Public gift list.
 *
 * Self-contained on purpose: the farm's stylesheet is for the farm. Warm and
 * quiet — cream paper, sage, dusty rose and soft gold — and mobile first, since
 * most relatives open the link from a phone.
 */

:root {
  --bg:          #faf6ef;
  --bg-deep:     #f2eadf;
  --paper:       #fffdf9;
  --ink:         #3b3431;
  --ink-soft:    #665b55;
  --ink-faint:   #8f847c;
  --line:        #ebe2d6;
  --line-strong: #d8cab8;

  --sage:        #7c9a7e;
  --sage-deep:   #4f6d52;
  --sage-darker: #43603f;
  --sage-soft:   #e7efe5;
  --rose:        #d49a98;
  --rose-deep:   #8e4c51;
  --rose-darker: #7a3f44;
  --rose-soft:   #f8e8e5;
  --gold:        #dcb35c;
  --gold-deep:   #7a5a12;
  --gold-soft:   #faf0d9;
  --blue-deep:   #4d6480;
  --blue-soft:   #e7edf3;
  --sand-deep:   #6e6152;
  --sand-soft:   #f1ebe2;
  --muted-deep:  #6f645e;
  --muted-soft:  #eee8e3;

  --focus:       #3d5f8a;

  --shadow-sm: 0 1px 2px rgb(59 52 49 / 5%), 0 2px 10px rgb(59 52 49 / 5%);
  --shadow-md: 0 2px 6px rgb(59 52 49 / 7%), 0 14px 34px rgb(59 52 49 / 9%);
  --shadow-lg: 0 10px 30px rgb(59 52 49 / 16%), 0 30px 80px rgb(59 52 49 / 18%);

  --radius-lg: 22px;
  --radius:    16px;
  --radius-sm: 12px;

  --font: "Nunito", ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto,
          "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Roboto Mono", "Liberation Mono", monospace;

  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html.has-dialog, html.has-dialog body { overflow: hidden; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 1.0625rem;
  line-height: 1.55;
  overflow-x: hidden;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  -webkit-font-smoothing: antialiased;
}

img { max-width: 100%; display: block; }

h1, h2, h3 { margin: 0 0 .5em; line-height: 1.2; font-weight: 800; letter-spacing: -.005em; }
p { margin: 0 0 .9em; }

a { color: var(--sage-deep); text-underline-offset: 3px; }

:where(a, button, input, textarea, select, summary):focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

[tabindex="-1"]:focus { outline: none; }

[hidden] { display: none !important; }

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%);
  white-space: nowrap;
}

.shell {
  width: min(100% - 2rem, 1120px);
  margin-inline: auto;
}

.muted { color: var(--ink-soft); }
.small { font-size: .9rem; }

.icon {
  width: 1.2em; height: 1.2em;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon--star { fill: currentColor; stroke-width: 1.4; }

/* --- loading ------------------------------------------------------------ */

.loading {
  min-height: 70vh;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .9rem;
  color: var(--ink-soft);
}

.spinner {
  width: 2.25rem; height: 2.25rem;
  border-radius: 50%;
  border: 3px solid var(--sage-soft);
  border-top-color: var(--sage-deep);
  animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.noscript { max-width: 32rem; margin: 3rem auto; padding: 0 1rem; text-align: center; }

/* --- buttons ------------------------------------------------------------ */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  min-height: 2.75rem;
  padding: .6rem 1.2rem;
  border: 1.5px solid transparent;
  border-radius: 999px;
  font: inherit; font-size: 1rem; font-weight: 700; line-height: 1.2;
  text-align: center; text-decoration: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color .15s ease, border-color .15s ease, color .15s ease, box-shadow .15s ease;
}
.btn:disabled { cursor: default; opacity: .6; }

.btn--primary {
  background: var(--sage-deep); color: #fff;
  box-shadow: 0 1px 2px rgb(59 52 49 / 12%), 0 4px 14px rgb(79 109 82 / 22%);
}
.btn--primary:hover:not(:disabled) { background: var(--sage-darker); }

.btn--secondary { background: var(--paper); color: var(--ink); border-color: var(--line-strong); }
.btn--secondary:hover:not(:disabled) { background: var(--bg-deep); border-color: var(--ink-faint); }

.btn--ghost { background: transparent; color: var(--ink-soft); }
.btn--ghost:hover:not(:disabled) { background: rgb(59 52 49 / 6%); color: var(--ink); }

.btn--danger { background: var(--rose-deep); color: #fff; }
.btn--danger:hover:not(:disabled) { background: var(--rose-darker); }

.btn--quiet { background: transparent; color: var(--rose-deep); }
.btn--quiet:hover:not(:disabled) { background: var(--rose-soft); }

.btn--small { min-height: 2.35rem; padding: .35rem .9rem; font-size: .92rem; }
.btn--block { width: 100%; }

.btn.is-busy { opacity: .8; }
.btn.is-busy .icon { display: none; }
.btn.is-busy::before {
  content: "";
  width: 1em; height: 1em;
  border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: spin .7s linear infinite;
}

.icon-btn {
  display: inline-grid; place-items: center;
  width: 2.75rem; height: 2.75rem;
  flex: none;
  padding: 0;
  border: 0; border-radius: 50%;
  background: transparent; color: var(--ink-soft);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:hover:not(:disabled) { background: rgb(59 52 49 / 7%); color: var(--ink); }
.icon-btn .icon { width: 1.35rem; height: 1.35rem; }

/* --- forms -------------------------------------------------------------- */

.stack { display: grid; gap: 1rem; }

.field { display: grid; gap: .35rem; min-width: 0; }
.field__label { font-weight: 700; font-size: .98rem; }
.field__optional { font-weight: 400; color: var(--ink-soft); }
.field__hint { margin: 0; font-size: .9rem; color: var(--ink-soft); }

.input, .textarea, .select {
  width: 100%;
  min-height: 2.9rem;
  padding: .65rem .95rem;
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--paper);
  color: var(--ink);
  /* Below 16px iOS zooms the whole page in when a field is focused. */
  font: inherit; font-size: max(1rem, 16px);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.input::placeholder, .textarea::placeholder { color: var(--ink-faint); opacity: 1; }
.input:focus, .textarea:focus, .select:focus {
  border-color: var(--sage-deep);
  box-shadow: 0 0 0 3px rgb(79 109 82 / 18%);
  outline: none;
}
.input:focus-visible, .textarea:focus-visible, .select:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; }
.input:disabled, .textarea:disabled { background: var(--bg-deep); color: var(--ink-soft); }

.textarea { min-height: 7rem; resize: vertical; line-height: 1.5; }

.select {
  appearance: none;
  padding-right: 2.5rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23665b55' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right .8rem center;
  background-size: 1.1rem;
  cursor: pointer;
}
.select--compact { width: auto; min-height: 2.5rem; padding-block: .4rem; border-radius: 999px; font-weight: 600; }

.input--code {
  font-family: var(--mono);
  font-size: 1.15rem;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.input--code::placeholder { text-transform: none; letter-spacing: normal; font-family: var(--font); font-size: 1rem; }

.input-wrap { position: relative; }
.input--with-toggle { padding-right: 5.25rem; }
.input-toggle {
  position: absolute; top: 50%; right: .35rem;
  transform: translateY(-50%);
  min-height: 2.3rem;
  padding: .3rem .8rem;
  border: 0; border-radius: 999px;
  background: var(--bg-deep); color: var(--ink-soft);
  font: inherit; font-size: .88rem; font-weight: 700;
  cursor: pointer;
}
.input-toggle[aria-pressed="true"] { background: var(--sage-soft); color: var(--sage-deep); }

.form-error {
  display: flex; gap: .55rem; align-items: flex-start;
  margin: 0;
  padding: .7rem .9rem;
  border-radius: var(--radius-sm);
  background: var(--rose-soft); color: var(--rose-darker);
  font-weight: 600; font-size: .95rem;
}
/* Kept in the accessibility tree while empty, so a screen reader announces it when it fills. */
.form-error:empty { position: absolute; padding: 0; }
.form-error .icon { margin-top: .12em; }
/* Scrolled to in the gift form, where the sticky save bar would otherwise cover it. */
.gift-form .form-error { scroll-margin-bottom: 6rem; }

.notice {
  display: flex; gap: .65rem; align-items: flex-start;
  margin: 0 0 1rem;
  padding: .8rem 1rem;
  border-radius: var(--radius-sm);
  font-size: .95rem;
}
.notice p { margin: 0; }
.notice .icon { margin-top: .15em; }
.notice--info { background: var(--blue-soft); color: var(--blue-deep); }
.notice--warn { background: var(--gold-soft); color: var(--gold-deep); }

.divider {
  display: flex; align-items: center; gap: .9rem;
  margin: 1.25rem 0;
  color: var(--ink-faint); font-size: .9rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em;
}
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* --- centred screens (password, code, closed) -------------------------- */

.center {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid; place-items: center;
  padding: max(2rem, env(safe-area-inset-top)) 1rem max(2rem, env(safe-area-inset-bottom));
  background:
    radial-gradient(circle at 12% 12%, rgb(212 154 152 / 24%), transparent 42%),
    radial-gradient(circle at 92% 8%, rgb(220 179 92 / 20%), transparent 38%),
    radial-gradient(circle at 80% 96%, rgb(124 154 126 / 22%), transparent 44%),
    var(--bg);
}

.center__card {
  width: min(100%, 28rem);
  padding: 2rem 1.35rem 1.75rem;
  border-radius: 28px;
  background: var(--paper);
  box-shadow: var(--shadow-md);
}
@media (min-width: 30em) {
  .center__card { padding: 2.5rem 2.25rem 2.25rem; }
}

.center__card > .eyebrow, .center__title { text-align: center; }
.center__title { font-size: clamp(1.7rem, 1.35rem + 1.6vw, 2.2rem); }
.center__card .lead { color: var(--ink-soft); }
.center__note { margin-top: .75rem; text-align: center; }
.center__lead { text-align: center; }

/* The first-timer's way in: big enough that nobody has to look for it. */
.btn--hero {
  min-height: 5.25rem;
  margin-top: .5rem;
  padding: 1rem 1.5rem;
  border-radius: 22px;
}
.btn--hero .icon { width: 1.6rem; height: 1.6rem; flex: none; }
.btn--hero__label { display: grid; gap: .1rem; text-align: left; }
.btn--hero__lead { font-size: 1rem; font-weight: 600; opacity: .92; }
.btn--hero__action { font-size: 1.45rem; font-weight: 800; line-height: 1.15; }

.returning { display: grid; gap: .75rem; }
.returning__title { margin: 0; font-size: 1.1rem; text-align: center; }
.returning__text { margin: 0; text-align: center; }

.emblem {
  display: grid; place-items: center;
  width: 3.75rem; height: 3.75rem;
  margin: 0 auto 1rem;
  border-radius: 50%;
  background: var(--gold-soft); color: var(--gold-deep);
}
.emblem .icon { width: 1.75rem; height: 1.75rem; }
.emblem--small { width: 3.1rem; height: 3.1rem; margin-bottom: .75rem; }
.emblem--small .icon { width: 1.45rem; height: 1.45rem; }

.eyebrow {
  margin: 0 0 .35rem;
  color: var(--rose-deep);
  font-size: .82rem; font-weight: 800; letter-spacing: .1em; text-transform: uppercase;
}

/* --- gallery header ----------------------------------------------------- */

.hero {
  padding: calc(2rem + env(safe-area-inset-top)) 0 2rem;
  background:
    radial-gradient(circle at 8% 20%, rgb(212 154 152 / 22%), transparent 40%),
    radial-gradient(circle at 95% 0%, rgb(220 179 92 / 20%), transparent 36%),
    radial-gradient(circle at 70% 120%, rgb(124 154 126 / 22%), transparent 45%),
    var(--bg);
  border-bottom: 1px solid var(--line);
}

.hero__inner { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 1rem 2rem; }
.hero__title {
  margin: 0;
  font-size: clamp(2.1rem, 1.6rem + 2.6vw, 3.3rem);
  line-height: 1.05;
  overflow-wrap: anywhere;
}

.codebar {
  display: flex; flex-wrap: wrap; align-items: center; gap: .35rem .75rem;
  padding: .45rem .5rem .45rem 1.1rem;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgb(255 253 249 / 85%);
  box-shadow: var(--shadow-sm);
}
.codebar__info { margin: 0; font-size: .95rem; }
.codebar__info--muted { color: var(--ink-soft); }
.codebar__label { color: var(--ink-soft); font-weight: 600; }

.code {
  font-family: var(--mono);
  font-weight: 700;
  letter-spacing: .06em;
  white-space: nowrap;
}

/* --- main --------------------------------------------------------------- */

.main { padding-block: 1.5rem 3rem; }

.help {
  margin-bottom: 1.5rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--paper);
  box-shadow: var(--shadow-sm);
}
.help__summary {
  display: flex; align-items: center; gap: .65rem;
  min-height: 3.25rem;
  padding: .7rem 1.1rem;
  border-radius: var(--radius-lg);
  color: var(--sage-deep);
  font-weight: 800; font-size: 1.05rem;
  list-style: none;
  cursor: pointer;
}
.help__summary::-webkit-details-marker { display: none; }
.help__heading { flex: 1; color: var(--ink); }
.help__chevron { transition: transform .2s ease; color: var(--ink-soft); }
.help[open] .help__chevron { transform: rotate(180deg); }

.help__body { padding: 0 1.1rem 1.25rem; max-width: 46rem; }
@media (min-width: 36em) {
  .help__summary { padding-inline: 1.5rem; }
  .help__body { padding: 0 1.5rem 1.6rem 3.35rem; }
}
.help__body h3 { margin: 1.35rem 0 .4rem; font-size: 1.05rem; }
.help__body p { color: var(--ink-soft); }

.legend { list-style: none; margin: .5rem 0 0; padding: 0; display: grid; gap: .6rem; }
.legend__row { display: grid; gap: .25rem; }
.legend__row .badge { justify-self: start; }
@media (min-width: 36em) {
  .legend__row { grid-template-columns: 19.5rem 1fr; align-items: center; gap: 1rem; }
}
.legend__text { color: var(--ink-soft); font-size: .95rem; }

/* toolbar */

.toolbar { display: grid; gap: 1rem; margin-bottom: 1.1rem; }
.toolbar__row { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; }
.toolbar__add { flex: 1 1 100%; }
@media (min-width: 40em) {
  .toolbar__add { flex: 0 0 auto; }
}

.search { position: relative; flex: 1 1 16rem; margin: 0; }
.search__icon {
  position: absolute; left: .95rem; top: 50%;
  transform: translateY(-50%);
  color: var(--ink-faint);
  pointer-events: none;
}
.search__input { padding-left: 2.75rem; border-radius: 999px; }

/* On a phone the chips scroll sideways instead of stacking into rows above the list. */
.chips {
  display: flex; gap: .5rem;
  margin-inline: -1rem;
  padding: .15rem 1rem .4rem;
  overflow-x: auto;
  scrollbar-width: none;
  scroll-padding-inline: 1rem;
  -webkit-overflow-scrolling: touch;
}
.chips::-webkit-scrollbar { display: none; }
@media (min-width: 48em) {
  .chips { flex-wrap: wrap; margin-inline: 0; padding-inline: 0; overflow: visible; }
}

.chip {
  display: inline-flex; align-items: center; gap: .4rem;
  flex: none;
  min-height: 2.5rem;
  padding: .35rem .6rem .35rem .9rem;
  border: 1.5px solid var(--line-strong);
  border-radius: 999px;
  background: var(--paper); color: var(--ink);
  font: inherit; font-size: .93rem; font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color .15s ease, border-color .15s ease, color .15s ease;
}
.chip .icon { width: 1.05em; height: 1.05em; color: var(--ink-soft); }
.chip:hover { border-color: var(--ink-faint); }
.chip__count {
  min-width: 1.6rem;
  padding: .05rem .45rem;
  border-radius: 999px;
  background: var(--bg-deep); color: var(--ink-soft);
  font-size: .82rem; text-align: center;
}
.chip__count:empty { display: none; }
.chip[aria-pressed="true"] { background: var(--sage-deep); border-color: var(--sage-deep); color: #fff; }
.chip[aria-pressed="true"] .icon { color: #fff; }
.chip[aria-pressed="true"] .chip__count { background: rgb(255 255 255 / 22%); color: #fff; }

/* results */

.results__bar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem 1rem;
  margin-bottom: .9rem;
}
.results__count { margin: 0; color: var(--ink-soft); font-weight: 600; font-size: .95rem; }
.sort { display: flex; align-items: center; gap: .5rem; }
.sort__label { color: var(--ink-soft); font-size: .92rem; font-weight: 600; }

/* --- cards -------------------------------------------------------------- */

.grid {
  list-style: none; margin: 0; padding: 0;
  display: grid; gap: .85rem;
  grid-template-columns: 1fr;
}

/* Phones: a compact row per item, so a long list stays scannable. */
.card {
  position: relative;
  display: grid;
  grid-template-columns: 6.25rem minmax(0, 1fr);
  grid-template-areas: "media body" "actions actions";
  gap: .75rem .9rem;
  padding: .75rem;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--paper);
  box-shadow: var(--shadow-sm);
  transition: box-shadow .18s ease, transform .18s ease, border-color .18s ease;
}

.card__media {
  grid-area: media;
  position: relative;
  align-self: start;
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: 14px;
}
.card__img { width: 100%; height: 100%; object-fit: cover; }
.card__placeholder { position: absolute; inset: 0; display: grid; place-items: center; }
.card__placeholder .icon { width: 2.1rem; height: 2.1rem; opacity: .55; }
.card__count {
  position: absolute; right: .35rem; bottom: .35rem;
  display: inline-flex; align-items: center; gap: .2rem;
  padding: .05rem .45rem;
  border-radius: 999px;
  background: rgb(59 52 49 / 68%); color: #fff;
  font-size: .75rem; font-weight: 700;
}
.card__count .icon { width: .95em; height: .95em; }

.media--gold  { background: var(--gold-soft);  color: var(--gold-deep); }
.media--blue  { background: var(--blue-soft);  color: var(--blue-deep); }
.media--rose  { background: var(--rose-soft);  color: var(--rose-deep); }
.media--sage  { background: var(--sage-soft);  color: var(--sage-deep); }
.media--sand  { background: var(--sand-soft);  color: var(--sand-deep); }
.media--muted { background: var(--muted-soft); color: var(--muted-deep); }

.card__body { grid-area: body; min-width: 0; }
.card__title { margin: 0 0 .4rem; font-size: 1.05rem; font-weight: 800; line-height: 1.25; }

.card__open {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  padding: 0; border: 0;
  background: none; color: inherit;
  font: inherit; text-align: left;
  overflow-wrap: anywhere;
  cursor: pointer;
}
/* The whole card opens the details; the action buttons sit above this layer. */
.card__open::after { content: ""; position: absolute; inset: 0; z-index: 1; }
.card__open:focus-visible { outline: none; }
.card__open:focus-visible::after { border-radius: 20px; box-shadow: inset 0 0 0 3px var(--focus); }

.card__excerpt {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  margin: .45rem 0 0;
  color: var(--ink-soft);
  font-size: .92rem;
  line-height: 1.45;
}

.card__actions {
  grid-area: actions;
  position: relative; z-index: 2;
  display: flex; flex-wrap: wrap; gap: .5rem;
}
.card__actions .btn { flex: 1 1 auto; }

@media (hover: hover) {
  .card:hover { box-shadow: var(--shadow-md); border-color: var(--line-strong); }
}

@media (min-width: 36em) {
  /* Wide enough that "Lupaudun hankkimaan tämän" stays on one line. */
  .grid { grid-template-columns: repeat(auto-fill, minmax(18rem, 1fr)); gap: 1.25rem; }

  .card {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto 1fr auto;
    grid-template-areas: "media" "body" "actions";
    gap: 0;
    padding: 0;
    overflow: hidden;
  }
  .card__media { aspect-ratio: 4 / 3; border-radius: 0; }
  .card__placeholder .icon { width: 2.75rem; height: 2.75rem; }
  .card__body { padding: .95rem 1.1rem .5rem; }
  .card__excerpt { -webkit-line-clamp: 3; }
  .card__actions { padding: .5rem 1.1rem 1.1rem; }
  .card__actions .btn { flex: 1 1 auto; }
}

@media (hover: hover) and (min-width: 36em) and (prefers-reduced-motion: no-preference) {
  .card:hover { transform: translateY(-2px); }
}

/* skeleton */

.card--skeleton { box-shadow: none; }
.sk {
  border-radius: 8px;
  background: linear-gradient(90deg, var(--bg-deep) 0%, #f8f2e9 50%, var(--bg-deep) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}
.card__media.sk { border-radius: 14px; }
.sk--title { height: 1.1rem; width: 70%; margin-bottom: .6rem; }
.sk--badge { height: 1.5rem; width: 45%; margin-bottom: .6rem; border-radius: 999px; }
.sk--line  { height: .85rem; width: 90%; }
@media (min-width: 36em) {
  .card__media.sk { border-radius: 0; }
  .card--skeleton .card__body { padding-bottom: 1.25rem; }
}

@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

/* badges */

.badges { display: flex; flex-wrap: wrap; gap: .35rem; }
.badge {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .2rem .65rem .2rem .45rem;
  border-radius: 999px;
  font-size: .8rem; font-weight: 800; line-height: 1.3;
}
.badge .icon { width: 1.05em; height: 1.05em; }
.badge--gold  { background: var(--gold-soft);  color: var(--gold-deep); }
.badge--blue  { background: var(--blue-soft);  color: var(--blue-deep); }
.badge--rose  { background: var(--rose-soft);  color: var(--rose-deep); }
.badge--sage  { background: var(--sage-soft);  color: var(--sage-deep); }
.badge--sand  { background: var(--sand-soft);  color: var(--sand-deep); }
.badge--muted { background: var(--muted-soft); color: var(--muted-deep); }
.badge--gold .icon { color: #b8872a; }

/* empty */

.empty {
  padding: 2.5rem 1.25rem;
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--radius-lg);
  text-align: center;
}
.empty__title { margin-bottom: .35rem; font-weight: 800; font-size: 1.1rem; }
.empty .btn { margin-top: .5rem; }

/* footer */

.footer { padding: 0 0 calc(2.5rem + env(safe-area-inset-bottom)); color: var(--ink-soft); }
.footer__inner {
  display: flex; align-items: center; justify-content: center; gap: .5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--line);
}
.footer__inner p { margin: 0; font-weight: 600; }
.footer .icon { color: var(--rose); fill: currentColor; stroke: none; }

/* --- dialogs ------------------------------------------------------------ */

.dialog {
  --pad: 1.25rem;
  width: min(100% - 1.5rem, 34rem);
  max-width: none;
  max-height: calc(100% - 1.5rem);
  max-height: calc(100dvh - 1.5rem);
  padding: 0;
  border: 0;
  border-radius: 24px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--shadow-lg);
  overflow: auto;
  overscroll-behavior: contain;
}
.dialog::backdrop { background: rgb(59 52 49 / 48%); }
@media (min-width: 36em) {
  .dialog { --pad: 1.9rem; }
}

.dialog--small  { width: min(100% - 1.5rem, 29rem); }
.dialog--form   { width: min(100% - 1.5rem, 40rem); }
.dialog--detail { width: min(100% - 1.5rem, 48rem); }

.dialog__box { padding: var(--pad); }
.dialog__box > :last-child { margin-bottom: 0; }

.dialog__head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: .75rem;
  margin-bottom: .9rem;
}
.dialog__title { margin: .35rem 0 0; font-size: 1.4rem; overflow-wrap: anywhere; }
.dialog__close { margin: -.35rem -.6rem 0 0; }
.dialog__intro { color: var(--ink-soft); }

.dialog__actions {
  display: flex; flex-wrap: wrap-reverse; justify-content: flex-end; gap: .6rem;
  margin-top: 1.4rem;
}
@media (max-width: 29.99em) {
  .dialog__actions .btn { flex: 1 1 auto; }
}

/* Big dialogs keep their title and close button in reach while scrolling. */
.dialog--sheet .dialog__head {
  position: sticky; top: 0; z-index: 5;
  margin: calc(-1 * var(--pad)) calc(-1 * var(--pad)) 1rem;
  padding: calc(var(--pad) - .35rem) var(--pad) .6rem;
  background: rgb(255 253 249 / 94%);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.dialog__footer {
  position: sticky; bottom: 0; z-index: 5;
  display: flex; flex-wrap: wrap-reverse; justify-content: flex-end; gap: .6rem;
  margin: 1.25rem calc(-1 * var(--pad)) calc(-1 * var(--pad));
  padding: .85rem var(--pad) calc(.85rem + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--paper);
}
@media (max-width: 29.99em) {
  .dialog__footer .btn { flex: 1 1 auto; }
}

/* Phones: detail and form fill the screen like a page of their own. */
@media (max-width: 35.99em) {
  .dialog--sheet {
    width: 100%;
    height: 100%;
    height: 100dvh;
    max-height: none;
    margin: 0;
    border-radius: 0;
  }
  .dialog--sheet .dialog__box {
    min-height: 100%;
    padding-top: calc(var(--pad) + env(safe-area-inset-top));
  }
  .dialog--sheet .dialog__head { padding-top: calc(var(--pad) - .35rem + env(safe-area-inset-top)); margin-top: calc(-1 * (var(--pad) + env(safe-area-inset-top))); }
}

.dialog--fallback {
  position: fixed; inset: 0; z-index: 1000;
  margin: auto;
  height: fit-content;
  box-shadow: 0 0 0 100vmax rgb(59 52 49 / 48%);
}

@media (prefers-reduced-motion: no-preference) {
  .dialog[open] { animation: dialog-in .22s ease-out; }
  .dialog[open]::backdrop { animation: fade-in .22s ease-out; }
}
@keyframes dialog-in { from { opacity: 0; transform: translateY(12px) scale(.98); } }
@keyframes fade-in { from { opacity: 0; } }

.reveal__save { margin-top: 1rem; }
.dialog--reveal .emblem { background: var(--sage-soft); color: var(--sage-deep); margin-inline: 0; }

.codebox {
  display: grid; gap: .75rem; justify-items: center;
  margin: 1rem 0;
  padding: 1.1rem 1rem 1rem;
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--radius);
  background: var(--bg);
}
.code--big {
  margin: 0;
  font-size: clamp(1.75rem, 1.3rem + 2.4vw, 2.3rem);
  letter-spacing: .12em;
  color: var(--ink);
  user-select: all;
  -webkit-user-select: all;
}
.codebox__actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: .5rem .75rem; }
.codebox__status { color: var(--sage-deep); font-weight: 700; font-size: .92rem; }

.copy-helper { position: fixed; top: 0; left: 0; width: 1px; height: 1px; opacity: 0; }

.choice { display: grid; gap: .6rem; }
.choice__title { margin: .25rem 0 0; font-size: 1.05rem; }

.confirm__item {
  padding: .7rem 1rem;
  border-radius: var(--radius-sm);
  background: var(--bg);
  font-weight: 800;
  overflow-wrap: anywhere;
}

/* --- detail ------------------------------------------------------------- */

.viewer { margin-bottom: 1.1rem; }
@media (max-width: 35.99em) {
  .viewer { margin-inline: calc(-1 * var(--pad)); }
  .viewer__stage { border-radius: 0; }
}

.viewer__stage {
  position: relative;
  aspect-ratio: 4 / 3;
  max-height: 65vh;
  width: 100%;
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--bg-deep);
}
.viewer__img { width: 100%; height: 100%; object-fit: contain; }

.viewer__nav, .viewer__full {
  position: absolute;
  display: grid; place-items: center;
  width: 2.75rem; height: 2.75rem;
  padding: 0; border: 0; border-radius: 50%;
  background: rgb(255 253 249 / 90%); color: var(--ink);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
}
.viewer__nav { top: 50%; transform: translateY(-50%); }
.viewer__nav--prev { left: .6rem; }
.viewer__nav--next { right: .6rem; }
.viewer__nav:hover, .viewer__full:hover { background: #fff; }
.viewer__full { top: .6rem; right: .6rem; width: 2.4rem; height: 2.4rem; }
.viewer__full .icon { width: 1.1rem; height: 1.1rem; }

.viewer__counter {
  position: absolute; left: 50%; bottom: .6rem;
  transform: translateX(-50%);
  padding: .1rem .65rem;
  border-radius: 999px;
  background: rgb(59 52 49 / 68%); color: #fff;
  font-size: .82rem; font-weight: 700;
}

.viewer__thumbs {
  display: flex; gap: .5rem;
  padding: .65rem .15rem .2rem;
  overflow-x: auto;
  scrollbar-width: thin;
}
@media (max-width: 35.99em) {
  .viewer__thumbs { padding-inline: var(--pad); }
}
.viewer__thumb {
  flex: none;
  width: 4.25rem; aspect-ratio: 1;
  padding: 0;
  overflow: hidden;
  border: 2px solid transparent;
  border-radius: 12px;
  background: var(--bg-deep);
  opacity: .7;
  cursor: pointer;
}
.viewer__thumb img { width: 100%; height: 100%; object-fit: cover; }
.viewer__thumb[aria-current="true"] { border-color: var(--sage-deep); opacity: 1; }
.viewer__thumb:hover { opacity: 1; }

.detail__status { margin-bottom: 1rem; }
.detail__note { margin: .6rem 0 0; color: var(--ink-soft); }
.detail__description { white-space: pre-line; overflow-wrap: anywhere; }
.detail__subtitle { margin: 1.2rem 0 .5rem; font-size: 1rem; }

.links { list-style: none; margin: 0; padding: 0; display: grid; gap: .45rem; }
.link {
  display: flex; align-items: center; gap: .6rem;
  min-height: 2.9rem;
  padding: .55rem .9rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--ink);
  font-weight: 700;
  text-decoration: none;
}
.link:hover { border-color: var(--line-strong); background: var(--bg-deep); }
.link .icon { color: var(--sage-deep); }
.link__text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.link__external { color: var(--ink-faint) !important; width: 1rem; height: 1rem; }

.detail__actions {
  display: flex; flex-wrap: wrap; gap: .6rem;
  margin-top: 1.5rem;
  padding-top: 1.1rem;
  border-top: 1px solid var(--line);
}
@media (max-width: 29.99em) {
  .detail__actions .btn { flex: 1 1 auto; }
}

/* --- gift form ---------------------------------------------------------- */

.gift-form { display: grid; gap: 1rem; }
.form-fields { display: grid; gap: 1.25rem; min-width: 0; margin: 0; padding: 0; border: 0; }

.group { display: grid; gap: .6rem; min-width: 0; margin: 0; padding: 1rem; border: 1px solid var(--line); border-radius: var(--radius); }
.group__legend { padding: 0 .35rem; font-weight: 700; }
.group__actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.group > .btn { justify-self: start; }

.link-rows { display: grid; gap: .75rem; }
.link-rows:empty { display: none; }
.link-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: "url remove" "label remove";
  gap: .5rem .35rem;
  align-items: end;
  padding-bottom: .75rem;
  border-bottom: 1px dashed var(--line);
}
.link-row:last-child { padding-bottom: 0; border-bottom: 0; }
.link-row__url { grid-area: url; }
.link-row__label { grid-area: label; }
.link-row__remove { grid-area: remove; align-self: center; color: var(--rose-deep); }
.link-row__remove:hover { background: var(--rose-soft) !important; color: var(--rose-darker) !important; }
@media (min-width: 36em) {
  .link-row { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr) auto; grid-template-areas: "url label remove"; }
  .link-row__remove { align-self: end; }
}

.similar:not(:empty) {
  margin-top: .35rem;
  padding: .75rem .9rem;
  border-radius: var(--radius-sm);
  background: var(--gold-soft);
  color: var(--gold-deep);
}
.similar__title { display: flex; align-items: center; gap: .45rem; margin: 0 0 .45rem; font-weight: 800; font-size: .95rem; }
.similar__list { list-style: none; margin: 0; padding: 0; display: grid; gap: .35rem; }
.similar__item {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .35rem .75rem;
  width: 100%;
  padding: .5rem .7rem;
  border: 0;
  border-radius: 10px;
  background: rgb(255 253 249 / 80%); color: var(--ink);
  font: inherit; font-size: .95rem; font-weight: 700; text-align: left;
  cursor: pointer;
}
.similar__item:hover { background: var(--paper); }
.similar__name { min-width: 0; overflow-wrap: anywhere; }
.similar__hint { margin: .55rem 0 0; font-size: .9rem; }

.image-edit {
  list-style: none; margin: 0; padding: 0;
  display: grid; gap: .6rem;
  grid-template-columns: repeat(auto-fill, minmax(6rem, 1fr));
}
.image-edit__item {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: 12px;
  background: var(--bg-deep);
}
.image-edit__item img { position: relative; width: 100%; height: 100%; object-fit: cover; }
.image-edit__fallback { position: absolute; top: 50%; left: 50%; width: 1.75rem; height: 1.75rem; margin: -.875rem 0 0 -.875rem; color: var(--ink-faint); }
.image-edit__remove {
  position: absolute; top: .3rem; right: .3rem; z-index: 2;
  display: grid; place-items: center;
  width: 2.25rem; height: 2.25rem;
  padding: 0; border: 0; border-radius: 50%;
  background: rgb(255 253 249 / 92%); color: var(--rose-deep);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
}
.image-edit__remove:hover { background: #fff; }
.image-edit__remove:disabled { opacity: .5; cursor: default; }
.image-edit__remove .icon { width: 1.1rem; height: 1.1rem; }
.image-edit__state {
  position: absolute; left: .3rem; right: .3rem; bottom: .3rem; z-index: 2;
  padding: .1rem .4rem;
  border-radius: 999px;
  background: rgb(59 52 49 / 70%); color: #fff;
  font-size: .72rem; font-weight: 700; text-align: center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.image-edit__item--uploading img { opacity: .55; }
.image-edit__item--failed { box-shadow: inset 0 0 0 2px var(--rose-deep); }
.image-edit__item--failed .image-edit__state { background: var(--rose-deep); }

.progress { display: grid; gap: .4rem; }
.progress__text { font-weight: 700; font-size: .95rem; color: var(--sage-deep); }
.progress__bar {
  width: 100%; height: .5rem;
  appearance: none;
  border: 0; border-radius: 999px;
  background: var(--sage-soft);
  overflow: hidden;
}
.progress__bar::-webkit-progress-bar { background: var(--sage-soft); border-radius: 999px; }
.progress__bar::-webkit-progress-value { background: var(--sage-deep); border-radius: 999px; transition: width .25s ease; }
.progress__bar::-moz-progress-bar { background: var(--sage-deep); border-radius: 999px; }

/* --- toasts ------------------------------------------------------------- */

.toasts {
  position: fixed; left: 50%; bottom: calc(1rem + env(safe-area-inset-bottom)); z-index: 2000;
  transform: translateX(-50%);
  display: grid; gap: .5rem;
  width: min(100% - 1.5rem, 30rem);
  pointer-events: none;
}
.toast {
  display: flex; align-items: flex-start; gap: .65rem;
  padding: .7rem .5rem .7rem 1rem;
  border-radius: 18px;
  background: var(--ink); color: #fff;
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
}
.toast > .icon { margin-top: .15em; color: #cfe0cb; }
.toast--error { background: var(--rose-darker); }
.toast--error > .icon { color: #fff; }
.toast__text { flex: 1; margin: .05rem 0 0; font-weight: 600; font-size: .96rem; }
.toast__close {
  display: grid; place-items: center;
  width: 2.25rem; height: 2.25rem; flex: none;
  margin: -.3rem 0;
  padding: 0; border: 0; border-radius: 50%;
  background: transparent; color: rgb(255 255 255 / 80%);
  cursor: pointer;
}
.toast__close:hover { background: rgb(255 255 255 / 12%); color: #fff; }
.toast__close:focus-visible { outline-color: #fff; }
.toast__close .icon { width: 1.1rem; height: 1.1rem; }

/* In the gift form, keep clear of the sticky save button. */
.dialog--form .toasts { bottom: calc(5.5rem + env(safe-area-inset-bottom)); }

@media (prefers-reduced-motion: no-preference) {
  .toast { animation: toast-in .22s ease-out; }
  .toast.is-leaving { opacity: 0; transform: translateY(6px); transition: opacity .2s ease, transform .2s ease; }
}
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }

/* --- reduced motion ----------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
  /* A spinner that stops looks like a page that froze; a slow one does not. */
  .spinner, .btn.is-busy::before {
    animation-duration: 2s !important;
    animation-iteration-count: infinite !important;
  }
}
