:root {
  --spruce: #0f3b2e;
  --spruce-deep: #0a2a20;
  --spruce-dot: #154a3a;
  --holly: #b3122e;
  --holly-deep: #8c0d23;
  --kraft: #e2c393;
  --kraft-edge: #c9a56d;
  --gold: #d9ad3c;
  --snow: #fbfaf7;
  --frost: #eef1ec;
  --ink: #1c1a17;
  --muted: #5d5a52;
  --line: #d9dcd4;

  --display: 'Grenze Gotisch', 'UnifrakturMaguntia', Georgia, serif;
  --body: 'Figtree', system-ui, -apple-system, 'Segoe UI', sans-serif;

  --radius: 4px;
  --gutter: 16px;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--body);
  font-size: 17px;
  line-height: 1.55;
  color: var(--ink);
  /* Wrapping-paper polka dots on spruce */
  background-color: var(--spruce);
  background-image:
    radial-gradient(var(--spruce-dot) 2px, transparent 2.5px),
    radial-gradient(var(--spruce-dot) 2px, transparent 2.5px);
  background-size: 28px 28px;
  background-position: 0 0, 14px 14px;
}

/* ---------- masthead ---------- */

.ribbon {
  height: 14px;
  background: repeating-linear-gradient(135deg, var(--holly) 0 14px, var(--snow) 14px 28px);
}

.masthead {
  max-width: 760px;
  margin: 0 auto;
  padding: 22px var(--gutter) 10px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
}

.wordmark {
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(2.4rem, 8vw, 3.4rem);
  line-height: 1;
  color: var(--gold);
  text-decoration: none;
  letter-spacing: 0.01em;
  text-shadow: 0 2px 0 var(--spruce-deep);
}

.masthead-nav {
  display: flex;
  align-items: baseline;
  gap: 16px;
  color: var(--frost);
  font-size: 0.95rem;
}

.nav-note {
  color: var(--kraft);
}

/* ---------- page + sheets ---------- */

.page {
  max-width: 760px;
  margin: 0 auto;
  padding: 8px var(--gutter) 64px;
  outline: none;
}

.sheet {
  background: var(--snow);
  border-radius: var(--radius);
  padding: 26px 28px 28px;
  margin-top: 22px;
  box-shadow: 0 1px 0 var(--spruce-deep), 0 10px 24px rgba(4, 22, 16, 0.35);
}

.sheet-narrow {
  max-width: 460px;
  margin-left: auto;
  margin-right: auto;
}

.sheet-quiet {
  background: var(--frost);
  box-shadow: none;
}

h1,
h2 {
  font-family: var(--body);
  font-weight: 700;
  line-height: 1.2;
  margin: 0 0 6px;
  color: var(--spruce);
}

h1 {
  font-size: 1.6rem;
}

h2 {
  font-size: 1.25rem;
}

.page-title {
  font-family: var(--display);
  font-weight: 500;
  font-size: 2rem;
  color: var(--snow);
  margin: 10px 0 0;
}

.lede {
  color: var(--muted);
  margin: 0 0 18px;
}

.empty {
  color: var(--muted);
  font-style: italic;
  margin: 8px 0 0;
}

.warn {
  background: #fdf0d5;
  border-left: 4px solid var(--gold);
  padding: 10px 14px;
  border-radius: 0 var(--radius) var(--radius) 0;
}

.loading {
  color: var(--frost);
  font-style: italic;
  margin-top: 40px;
}

.footnote {
  text-align: center;
  margin-top: 20px;
}

.footnote a {
  color: var(--kraft);
}

.greeting {
  color: var(--frost);
  font-size: 1.1rem;
  margin: 8px 0 0;
}

/* ---------- the gift tag ---------- */

.tag-hang {
  display: flex;
  justify-content: center;
  padding: 34px 0 8px;
  /* On the wrapper: clip-path on .tag would clip its own shadow */
  filter: drop-shadow(0 10px 14px rgba(4, 22, 16, 0.45));
}

.tag {
  --notch: 34px;
  position: relative;
  min-width: min(100%, 440px);
  max-width: 100%;
  padding: 30px 40px 34px calc(var(--notch) + 44px);
  background: var(--kraft);
  color: var(--ink);
  clip-path: polygon(var(--notch) 0, 100% 0, 100% 100%, var(--notch) 100%, 0 50%);
  transform: rotate(-2.5deg);
  transform-origin: 20% 50%;
  display: flex;
  flex-direction: column;
  gap: 2px;
  animation: tag-swing 1.6s cubic-bezier(0.3, 0.7, 0.3, 1) both;
}

/* Reinforced string hole */
.tag::before {
  content: '';
  position: absolute;
  left: calc(var(--notch) - 4px);
  top: 50%;
  width: 20px;
  height: 20px;
  margin-top: -10px;
  border-radius: 50%;
  background: var(--spruce);
  box-shadow: 0 0 0 5px var(--kraft-edge);
}

/* Faint inset border, like a printed tag */
.tag::after {
  content: '';
  position: absolute;
  inset: 8px 8px 8px calc(var(--notch) + 6px);
  border: 1.5px dashed rgba(28, 26, 23, 0.25);
  pointer-events: none;
}

.tag-to {
  font-size: 0.95rem;
  font-weight: 600;
  color: #6b5532;
}

.tag-name {
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(2.6rem, 11vw, 4.2rem);
  line-height: 1;
  color: var(--holly-deep);
  overflow-wrap: anywhere;
}

.tag-blank .tag-name {
  color: #8a7350;
}

@keyframes tag-swing {
  0% {
    transform: rotate(-9deg);
    opacity: 0;
  }
  35% {
    opacity: 1;
  }
  60% {
    transform: rotate(1deg);
  }
  100% {
    transform: rotate(-2.5deg);
  }
}

/* ---------- wish lists ---------- */

.wishlist {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
}

.wishlist li {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 14px;
  padding: 12px 0 12px 26px;
  border-top: 1px solid var(--line);
  position: relative;
}

.wishlist li:first-child {
  border-top: 0;
}

/* Little holly berry bullet */
.wishlist li::before {
  content: '';
  position: absolute;
  left: 4px;
  top: 1.15em;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--holly);
  box-shadow: 6px -4px 0 -1px var(--holly-deep);
}

.wish-text {
  flex: 1 1 220px;
}

.wish-link {
  color: var(--spruce);
  font-size: 0.92rem;
  font-weight: 600;
}

.add-item {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 2px dotted var(--line);
}

.optional {
  font-weight: 400;
  color: var(--muted);
}

/* ---------- rules (rendered markdown) ---------- */

.md h1,
.md h2,
.md h3 {
  font-size: 1.05rem;
  margin: 20px 0 4px;
}

.md > :first-child {
  margin-top: 0;
}

.md ul,
.md ol {
  padding-left: 1.3em;
}

.md li + li {
  margin-top: 4px;
}

.md a {
  color: var(--holly);
}

.md blockquote {
  margin: 12px 0;
  padding: 4px 16px;
  border-left: 4px solid var(--kraft);
  color: var(--muted);
}

code {
  font-size: 0.9em;
  background: var(--frost);
  padding: 1px 5px;
  border-radius: 3px;
}

.rules-editor {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.rules-editor textarea {
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: 0.9rem;
  min-height: 260px;
  resize: vertical;
}

.preview-label {
  display: block;
  font-weight: 600;
  font-size: 0.95rem;
  margin-bottom: 6px;
}

.rules-preview {
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 12px 16px;
  min-height: 260px;
  max-height: 420px;
  overflow: auto;
  background: #fff;
}

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

form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-weight: 600;
  font-size: 0.95rem;
}

input,
textarea {
  font: inherit;
  font-weight: 400;
  color: var(--ink);
  background: #fff;
  border: 1.5px solid #c4c8bf;
  border-radius: var(--radius);
  padding: 10px 12px;
  width: 100%;
}

input:focus-visible,
textarea:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 1px;
  border-color: var(--spruce);
}

.code-input {
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: 1.6rem;
  letter-spacing: 0.4em;
  text-align: center;
  padding: 10px;
}

.check {
  flex-direction: row;
  align-items: center;
  gap: 10px;
  font-weight: 500;
}

.check input {
  width: 18px;
  height: 18px;
  accent-color: var(--holly);
}

.hint,
.aside {
  margin: -6px 0 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.aside {
  margin-top: 0;
}

.form-error:empty {
  display: none;
}

.form-error {
  margin: 0;
  color: var(--holly);
  font-weight: 600;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.inline-form {
  margin-top: 12px;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: flex-end;
}

.inline-form label {
  flex: 1 1 240px;
}

.inline-form .form-error {
  flex-basis: 100%;
}

.invite-form {
  flex-direction: row;
  flex-wrap: wrap;
  align-items: flex-end;
  margin: 14px 0 6px;
}

.invite-form label {
  flex: 1 1 180px;
}

.invite-form .form-error {
  flex-basis: 100%;
}

.draw-form {
  margin-top: 14px;
}

/* ---------- buttons + links ---------- */

.btn {
  font: inherit;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 11px 20px;
  border-radius: var(--radius);
  border: 0;
  cursor: pointer;
  text-decoration: none;
  align-self: flex-start;
}

.btn:focus-visible,
.link:focus-visible,
a:focus-visible,
[role='tab']:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-holly {
  background: var(--holly);
  color: var(--snow);
  box-shadow: inset 0 -3px 0 var(--holly-deep);
}

.btn-holly:hover:not(:disabled) {
  background: var(--holly-deep);
}

.btn-quiet {
  background: transparent;
  color: var(--spruce);
  box-shadow: inset 0 0 0 1.5px var(--spruce);
}

.btn-quiet:hover {
  background: var(--frost);
}

.link {
  font: inherit;
  background: none;
  border: 0;
  padding: 0;
  color: var(--spruce);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.link-light {
  color: var(--frost);
}

.link-danger {
  color: var(--holly);
}

.link:disabled {
  opacity: 0.5;
}

/* Segmented sign-in method switch */
.switch {
  display: flex;
  background: var(--frost);
  border-radius: var(--radius);
  padding: 4px;
  margin-bottom: 18px;
}

.switch [role='tab'] {
  flex: 1;
  font: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  border: 0;
  background: transparent;
  padding: 8px;
  border-radius: 3px;
  color: var(--muted);
  cursor: pointer;
}

.switch [aria-selected='true'] {
  background: #fff;
  color: var(--spruce);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

/* ---------- people table ---------- */

.people {
  width: 100%;
  border-collapse: collapse;
  margin-top: 16px;
  font-size: 0.95rem;
}

.people th {
  text-align: left;
  font-weight: 600;
  color: var(--muted);
  padding: 6px 8px 6px 0;
  border-bottom: 2px solid var(--line);
}

.people td {
  padding: 12px 8px 12px 0;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.person-name {
  display: block;
  font-weight: 600;
}

.person-email {
  display: block;
  color: var(--muted);
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

.status {
  color: var(--muted);
  font-size: 0.9rem;
}

.actions {
  text-align: right;
  white-space: nowrap;
}

.actions .link + .link {
  margin-left: 14px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 20px);
  max-width: calc(100% - 32px);
  background: var(--ink);
  color: var(--snow);
  padding: 12px 18px;
  border-radius: var(--radius);
  border-left: 5px solid var(--gold);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}

.toast[data-kind='error'] {
  border-left-color: var(--holly);
}

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

/* ---------- small screens ---------- */

@media (max-width: 640px) {
  body {
    font-size: 16px;
  }

  .sheet {
    padding: 20px 18px 22px;
  }

  .tag {
    --notch: 26px;
    padding: 24px 22px 26px calc(var(--notch) + 34px);
    min-width: 0;
    width: 100%;
  }

  .rules-editor {
    grid-template-columns: 1fr;
  }

  .people thead {
    display: none;
  }

  .people tr {
    display: grid;
    grid-template-columns: 1fr;
    border-bottom: 1px solid var(--line);
    padding: 10px 0;
  }

  .people td {
    border: 0;
    padding: 2px 0;
  }

  .actions {
    text-align: left;
    padding-top: 6px !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  .tag {
    animation: none;
  }

  .toast {
    transition: none;
  }
}
