:root {
  --green-deep: #173a2a;
  --green: #1f5a3d;
  --cream: #fff8ee;
  --card: #fffdf8;
  --ink: #2b2118;
  --muted: #6d5d4b;
  --red: #b3261e;
  --red-dark: #8e1b14;
  --gold: #e0b050;
  --line: #eadfcb;
  --radius: 16px;
  --shadow: 0 6px 22px rgba(23, 58, 42, .18);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --cream: #142a20;
    --card: #1d3a2c;
    --ink: #f6eedf;
    --muted: #c9bfa9;
    --line: #2f5443;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 1rem;
  line-height: 1.5;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 0%, rgba(224, 176, 80, .18), transparent 40%),
    linear-gradient(180deg, var(--green-deep), var(--green) 60%, var(--cream) 60%);
  background-color: var(--green-deep);
  min-height: 100vh;
  overflow-x: hidden;
}

a { color: var(--red); }
h1, h2, h3 { line-height: 1.2; margin: .3rem 0 .6rem; }
h1 { font-size: clamp(1.6rem, 4vw, 2.2rem); }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.05rem; }
code { background: var(--line); padding: .1rem .35rem; border-radius: 6px; }

.top {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: .5rem 1rem; padding: .9rem 16px; color: #fff;
}
.brand { color: #fff; font-weight: 700; text-decoration: none; font-size: 1.1rem; }
.nav { display: flex; flex-wrap: wrap; gap: .4rem .9rem; align-items: center; }
.nav a, .nav .link { color: #fff; text-decoration: none; opacity: .92; }
.nav a:hover, .nav .link:hover { text-decoration: underline; opacity: 1; }

.wrap {
  max-width: 980px; margin: 0 auto; padding: 8px 16px 24px;
  display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  color: var(--ink);
}
.card.narrow { max-width: 440px; margin: 16px auto; }
.hero { text-align: center; }
.lead { color: var(--muted); margin: .2rem 0 1rem; }
.hint { color: var(--muted); font-size: .85rem; font-weight: 400; }
.budget {
  display: inline-block; background: #fff1cf; color: #5a4300;
  padding: .35rem .8rem; border-radius: 999px; font-weight: 600; margin: .2rem 0 .8rem;
}
.section-title { margin-top: 10px; }
.result { font-size: 1.15rem; margin: .8rem 0 0; }
.notice { background: #e4f4e8; color: #144d2a; padding: .6rem .9rem; border-radius: 12px; }
.alert { background: #fde6e3; color: #7d1510; padding: .6rem .9rem; border-radius: 12px; }

label { display: grid; gap: .3rem; font-weight: 600; }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--cream);
  border: 1px solid var(--line); border-radius: 10px; padding: .6rem .75rem; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 3px solid var(--gold); outline-offset: 1px; }
.stack { display: grid; gap: 12px; }
.row-form { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; margin-top: 14px; }
.row-form label { flex: 1 1 180px; }
.row-form .btn { flex: 0 0 auto; }

.btn {
  display: inline-block; cursor: pointer; border: 0; border-radius: 999px;
  background: var(--red); color: #fff; font: inherit; font-weight: 700;
  padding: .7rem 1.4rem; text-decoration: none; text-align: center;
  box-shadow: 0 3px 0 var(--red-dark);
  transition: transform .08s ease, box-shadow .08s ease;
}
.btn:hover { background: #c4302a; }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--red-dark); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.small { padding: .45rem .9rem; font-size: .9rem; }

button.link {
  background: none; border: 0; padding: 0; cursor: pointer;
  color: var(--red); font: inherit; text-decoration: underline;
}
.nav button.link { color: #fff; }
button.link.danger { color: var(--red); }
.inline { display: inline; margin: 0; }
.hidden-form { display: none; }

.table { width: 100%; border-collapse: collapse; margin-top: 8px; }
.table th, .table td { text-align: left; padding: .55rem .4rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { font-size: .85rem; color: var(--muted); }
.actions { text-align: right; white-space: nowrap; }
.actions form + form { margin-left: .8rem; }
.badge {
  background: var(--gold); color: #3a2a00; font-size: .72rem; font-weight: 700;
  padding: .1rem .45rem; border-radius: 999px; vertical-align: middle;
}
.creds dl { display: grid; grid-template-columns: max-content 1fr; gap: .4rem 1rem; margin: .4rem 0 0; }
.creds dt { color: var(--muted); }
.creds dd { margin: 0; font-size: 1.1rem; }
.creds code { font-size: 1.1rem; }

.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.wish { display: flex; flex-direction: column; gap: 6px; padding: 14px; }
.wish img {
  width: 100%; height: auto; aspect-ratio: 4 / 3; object-fit: cover;
  border-radius: 12px; background: var(--line);
}
.wish h3 { margin: 4px 0 0; }
.price { font-weight: 700; color: var(--muted); margin: 0; }
.link-out { margin-top: auto; }
.danger { color: var(--red) !important; }

/* Wheel */
.reveal { display: grid; justify-items: center; gap: 12px; margin-top: 12px; }
.wheel-wrap { position: relative; width: min(340px, 86vw); aspect-ratio: 1; }
.wheel-wrap.small { width: min(260px, 80vw); margin: 8px auto; }
.wheel {
  width: 100%; height: 100%; border-radius: 50%;
  box-shadow: 0 0 0 8px var(--gold), var(--shadow);
  background: #fff;
}
.pointer {
  position: absolute; left: 50%; top: -6px; transform: translateX(-50%);
  width: 0; height: 0;
  border-left: 16px solid transparent; border-right: 16px solid transparent;
  border-top: 30px solid var(--red-dark);
  filter: drop-shadow(0 2px 2px rgba(0,0,0,.3));
  z-index: 2;
}

/* Meadow with animals */
.meadow {
  position: relative; background: var(--cream);
  padding: 16px 16px 0; margin-top: 24px;
  display: flex; justify-content: center; align-items: flex-end; gap: 10px;
  height: 150px; overflow: hidden;
}
.meadow::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 22px;
  background: radial-gradient(circle at 10px 22px, var(--cream) 14px, transparent 15px) 0 0 / 40px 22px repeat-x;
  transform: translateY(-21px);
}
.pet { height: auto; fill-rule: nonzero; }
.pet.dog { width: 130px; animation: bob 3.2s ease-in-out infinite; }
.pet.cat.big { width: 96px; animation: bob 2.6s ease-in-out infinite .4s; }
.pet.cat.small { width: 70px; animation: bob 2.9s ease-in-out infinite .9s; }
.pet.dog .tail { transform-origin: 120px 142px; animation: wag 1.2s ease-in-out infinite; }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }
@keyframes wag { 0%, 100% { transform: rotate(-8deg); } 50% { transform: rotate(10deg); } }

@media (max-width: 560px) {
  .pet.dog { width: 96px; }
  .pet.cat.big { width: 70px; }
  .pet.cat.small { width: 52px; }
  .meadow { height: 120px; }
  .top { justify-content: center; text-align: center; }
  .nav { justify-content: center; }
  .card { padding: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .pet, .pet .tail { animation: none; }
  .btn { transition: none; }
}

/* Matrix: who may give to whom */
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.legend { display: flex; flex-wrap: wrap; gap: .4rem 1rem; align-items: center; color: var(--muted); font-size: .9rem; margin: .4rem 0 .8rem; }
.sw { display: inline-block; width: 14px; height: 14px; border-radius: 4px; margin-right: .3rem; vertical-align: -2px; }
.sw.free { background: #d9ecd9; }
.sw.excluded { background: #f2b8b2; }
.sw.assigned { background: var(--gold); }
.matrix-wrap { overflow: auto; max-width: 100%; border-radius: 12px; border: 1px solid var(--line); -webkit-overflow-scrolling: touch; }
.matrix { border-collapse: separate; border-spacing: 0; font-size: .9rem; }
.matrix th, .matrix td { border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); }
.matrix .corner { position: sticky; left: 0; top: 0; z-index: 3; background: var(--card); padding: .4rem .6rem; font-size: .75rem; color: var(--muted); white-space: nowrap; text-align: left; }
.matrix th.col { position: sticky; top: 0; z-index: 2; background: var(--card); padding: .4rem .2rem; height: 9.5rem; vertical-align: bottom; }
.matrix th.col span { display: inline-block; writing-mode: vertical-rl; transform: rotate(180deg); white-space: nowrap; font-weight: 600; font-size: .85rem; }
.matrix th.row { position: sticky; left: 0; z-index: 1; background: var(--card); text-align: right; padding: .3rem .7rem; white-space: nowrap; font-weight: 600; min-width: 7rem; max-width: 12rem; overflow: hidden; text-overflow: ellipsis; }
.matrix td.cell { width: 2.6rem; min-width: 2.6rem; height: 2.6rem; text-align: center; padding: 0; background: #d9ecd9; font-size: 1rem; }
.matrix td.cell.diag { background: repeating-linear-gradient(45deg, transparent 0 6px, var(--line) 6px 7px); color: var(--muted); }
.matrix td.cell.excluded { background: #f2b8b2; color: #7d1510; font-weight: 700; }
.matrix td.cell.assigned { background: var(--gold); }
.matrix td.cell:has(input:checked) { background: #f2b8b2; }
.matrix td.cell:has(input:checked) .tick { opacity: 1; }
.tick { display: flex; width: 100%; height: 100%; align-items: center; justify-content: center; cursor: pointer; }
.matrix input[type="checkbox"] { width: 1.25rem; height: 1.25rem; margin: 0; accent-color: var(--red); cursor: pointer; }
.matrix-form .row-form { margin-top: 12px; }
.results { columns: 2 14rem; padding-left: 1.1rem; margin: .4rem 0 0; }
.results li { break-inside: avoid; margin-bottom: .2rem; }

.table-wrap { overflow-x: auto; max-width: 100%; }
.matrix td.cell.assigned { color: #3a2a00; }

/* Falling snow and stars (decorative) */
.snow { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }
main, header, footer { position: relative; z-index: 1; }
.flake, .star { position: absolute; top: -20px; will-change: transform; }
.flake { background: #fff; border-radius: 50%; opacity: .85; animation: fall linear infinite; }
.star {
  background: var(--gold);
  clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
  opacity: .9; animation: fall-spin linear infinite;
}
@keyframes fall { to { transform: translateY(110vh); } }
@keyframes fall-spin { to { transform: translateY(110vh) rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .snow { display: none; } }
