:root {
  --paper: #f7f1e5;
  --card: #fffdf8;
  --ink: #1f2a22;
  --muted: #5f6b61;
  --line: #e2d8c4;
  --pine: #1e5b38;
  --pine-dark: #133d25;
  --berry: #b3262e;
  --berry-dark: #8c1b22;
  --gold: #e0a526;
  --snow: #ffffff;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(31, 42, 34, .06), 0 6px 18px rgba(31, 42, 34, .08);
  --display: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --body: ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI", system-ui, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--body);
  color: var(--ink);
  background: var(--paper);
  line-height: 1.5;
  min-height: 100vh;
}
a { color: var(--pine); }
h1, h2, h3 { font-family: var(--display); line-height: 1.15; margin: 0 0 .5rem; }
h1 { font-size: clamp(1.7rem, 4vw, 2.3rem); }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.hidden { display: none !important; }

/* ---------- Layout ---------- */
.topbar {
  background: var(--pine-dark);
  color: #fff;
  padding: .75rem 1rem;
  border-bottom: 4px solid var(--berry);
  background-image: repeating-linear-gradient(-45deg, transparent 0 14px, rgba(255,255,255,.04) 14px 28px);
}
.topbar .inner { max-width: 960px; margin: 0 auto; display: flex; align-items: center; gap: 1rem; }
.brand { font-family: var(--display); font-size: 1.3rem; color: #fff; text-decoration: none; font-weight: 700; }
.topbar .spacer { flex: 1; }
.topbar button.link { color: #fff; }
main { max-width: 960px; margin: 0 auto; padding: 1.5rem 1rem 4rem; }
.stack > * + * { margin-top: 1rem; }
.row { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1rem; }

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
}
.panel > h2 { display: flex; align-items: center; gap: .5rem; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; flex-wrap: wrap; margin-bottom: .75rem; }
.panel-head h2 { margin: 0; }

/* ---------- Forms ---------- */
label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .25rem; }
label .opt { font-weight: 400; color: var(--muted); }
label.check { display: flex; gap: .5rem; align-items: flex-start; font-weight: 400; margin: 0 0 1rem; }
label.check input { margin-top: .2rem; flex: none; }
input, select, textarea {
  width: 100%;
  font: inherit;
  padding: .6rem .75rem;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(30, 91, 56, .25); border-color: var(--pine); }
textarea { min-height: 6rem; resize: vertical; }
.field { margin-bottom: .9rem; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .75rem; }
.hint { font-size: .8rem; color: var(--muted); margin-top: .25rem; }

button, .button {
  font: inherit;
  font-weight: 700;
  border: 0;
  border-radius: 10px;
  padding: .6rem 1rem;
  cursor: pointer;
  background: var(--pine);
  color: #fff;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  line-height: 1.2;
}
button:hover, .button:hover { background: var(--pine-dark); }
button:disabled { opacity: .55; cursor: not-allowed; }
button.berry, .button.berry { background: var(--berry); }
button.berry:hover, .button.berry:hover { background: var(--berry-dark); }
button.ghost, .button.ghost { background: transparent; color: var(--pine); border: 1.5px solid var(--line); }
button.ghost:hover, .button.ghost:hover { background: #f0eadc; }
button.link { background: none; padding: 0; color: var(--pine); font-weight: 600; text-decoration: underline; }
button.small, .button.small { padding: .35rem .65rem; font-size: .85rem; }
button.danger { background: transparent; color: var(--berry); border: 1.5px solid #ecc7c9; }
button.danger:hover { background: #fbeeee; }

.segmented { display: inline-flex; border: 1.5px solid var(--line); border-radius: 10px; overflow: hidden; }
.segmented button { border-radius: 0; background: #fff; color: var(--ink); font-weight: 600; }
.segmented button[aria-pressed="true"] { background: var(--pine); color: #fff; }

.alert { padding: .7rem .9rem; border-radius: 10px; margin-bottom: 1rem; font-weight: 600; }
.alert.error { background: #fbeaea; color: var(--berry-dark); border: 1px solid #efc9cb; }
.alert.ok { background: #e7f3ea; color: var(--pine-dark); border: 1px solid #c3e0cb; }
.alert.info { background: #fff6dc; color: #6b4e00; border: 1px solid #f1dd9f; }

.badge { display: inline-block; font-size: .75rem; font-weight: 700; padding: .1rem .5rem; border-radius: 999px; background: #efe8d8; color: var(--muted); }
.badge.green { background: #e1f0e5; color: var(--pine-dark); }
.badge.red { background: #f8e2e3; color: var(--berry-dark); }
.badge.gold { background: #fbefcf; color: #7a5600; }

.code-chip {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-weight: 700; letter-spacing: .12em;
  background: #fff; border: 1.5px dashed var(--berry); color: var(--berry-dark);
  padding: .15rem .5rem; border-radius: 8px;
}

/* ---------- Lists ---------- */
.people { list-style: none; margin: 0; padding: 0; }
.people li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: .25rem 1rem;
  align-items: center;
  padding: .75rem 0;
  border-top: 1px solid var(--line);
}
.people li:first-child { border-top: 0; }
.people .who { font-weight: 700; font-size: 1.05rem; }
.people .meta { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; font-size: .85rem; color: var(--muted); }
.people .pin { font-size: 1.05rem; letter-spacing: .1em; }
.people .actions { display: flex; gap: .4rem; }

.event-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 1rem; }
.event-card { display: block; text-decoration: none; color: inherit; position: relative; overflow: hidden; }
.event-card:hover { border-color: var(--pine); }
.event-card::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 6px; background: repeating-linear-gradient(90deg, var(--berry) 0 16px, var(--snow) 16px 24px, var(--pine) 24px 40px, var(--snow) 40px 48px); }

.empty { text-align: center; padding: 2rem 1rem; color: var(--muted); }
.empty .big { font-size: 2.5rem; }

/* ---------- Dialog ---------- */
dialog {
  border: 0; border-radius: var(--radius); padding: 0; width: min(520px, calc(100vw - 2rem));
  box-shadow: 0 20px 60px rgba(0,0,0,.25); background: var(--card); color: var(--ink);
}
dialog::backdrop { background: rgba(19, 30, 22, .45); }
dialog .dialog-body { padding: 1.25rem; }
dialog .dialog-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1rem; }

/* ---------- Keypad ---------- */
.pin-dots { display: flex; justify-content: center; gap: .6rem; margin: .5rem 0 1rem; }
.pin-dots span {
  width: 3.2rem; height: 3.2rem; border-radius: 12px; border: 2px dashed var(--line);
  display: grid; place-items: center; font-size: 1.8rem; background: #fff;
}
.pin-dots span.filled { border-style: solid; border-color: var(--pine); }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; max-width: 320px; margin: 0 auto; }
.keypad.emoji { grid-template-columns: repeat(4, 1fr); max-width: 360px; }
.keypad button {
  background: #fff; color: var(--ink); border: 2px solid var(--line);
  font-size: 1.7rem; padding: .7rem 0; justify-content: center; border-radius: 14px;
  box-shadow: 0 3px 0 var(--line);
  transition: transform .06s ease;
}
.keypad button:hover { background: #fbf6ea; }
.keypad button:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--line); }
.keypad button.util { font-size: 1rem; font-weight: 700; color: var(--muted); }
.keypad.compact button { font-size: 1.25rem; padding: .4rem 0; }
.pin-dots.compact span { width: 2.4rem; height: 2.4rem; font-size: 1.3rem; }

/* ---------- Printable cards ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }
.login-card {
  background: #fff;
  border: 2px dashed var(--berry);
  border-radius: var(--radius);
  padding: 1rem;
  text-align: center;
  break-inside: avoid;
  page-break-inside: avoid;
}
.login-card .name { font-family: var(--display); font-size: 1.6rem; font-weight: 700; margin: 0; }
.login-card .event { font-size: .8rem; color: var(--muted); margin-bottom: .5rem; }
.login-card img { width: 180px; height: 180px; display: block; margin: .25rem auto .5rem; }
.login-card .pin-label { font-size: .75rem; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.login-card .pin { font-size: 1.8rem; letter-spacing: .15em; }
.login-card .scan { font-size: .85rem; font-weight: 700; color: var(--pine); margin-top: .25rem; }
.login-card .url { font-size: .7rem; color: var(--muted); word-break: break-all; margin-top: .4rem; }

@media print {
  body { background: #fff; }
  .topbar, .no-print { display: none !important; }
  main { padding: 0; max-width: none; }
  .cards { grid-template-columns: repeat(2, 1fr); gap: .5in; }
}

/* ---------- Kid app ---------- */
html:has(body.kid) { background: #0f3520; }
body.kid {
  background-color: #0f3520;
  background-image: radial-gradient(1200px 600px at 50% -10%, #2b7a4b 0%, #174d2e 55%, #0f3520 100%);
  background-attachment: fixed;
  color: var(--ink);
}
.kid main { max-width: 560px; padding-top: 1rem; position: relative; z-index: 1; }
.kid-title { text-align: center; color: #fff; margin: 1rem 0 1.25rem; }
.kid-title h1 { font-size: clamp(1.8rem, 7vw, 2.6rem); text-shadow: 0 2px 0 rgba(0,0,0,.2); }
.kid-title p { color: #d9eadf; margin: 0; }
.kid .panel { border: 0; border-radius: 22px; padding: 1.5rem; }

.name-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: .75rem; }
.name-grid button {
  background: #fff; color: var(--ink); border: 2px solid var(--line);
  font-size: 1.3rem; padding: 1rem .5rem; justify-content: center; border-radius: 16px;
  box-shadow: 0 4px 0 var(--line); font-family: var(--display);
}
.name-grid button:hover { border-color: var(--pine); background: #f7fbf8; }

.gift-stage { text-align: center; padding: 1rem 0; }
.gift {
  width: 180px; height: 170px; margin: 1rem auto; position: relative; cursor: pointer;
  border: 0; background: none; padding: 0; display: block;
}
.gift:hover { background: none; }
.gift .box { position: absolute; bottom: 0; left: 10px; width: 160px; height: 120px; background: var(--berry); border-radius: 10px; }
.gift .lid { position: absolute; top: 20px; left: 0; width: 180px; height: 38px; background: #c9333b; border-radius: 10px; transition: transform .6s cubic-bezier(.3,1.6,.5,1), opacity .6s; z-index: 2; }
.gift .ribbon-v { position: absolute; bottom: 0; left: 78px; width: 24px; height: 150px; background: var(--gold); z-index: 3; }
.gift .lid::after { content: ""; position: absolute; left: 78px; top: 0; width: 24px; height: 38px; background: var(--gold); }
.gift .bow { position: absolute; top: -6px; left: 60px; font-size: 3.2rem; line-height: 1; z-index: 4; transition: transform .6s, opacity .6s; }
.gift.wiggle { animation: wiggle 2.2s ease-in-out infinite; }
.gift.open .lid { transform: translate(40px, -90px) rotate(25deg); opacity: 0; }
.gift.open .bow { transform: translate(-40px, -110px) rotate(-30deg); opacity: 0; }
@keyframes wiggle { 0%, 70%, 100% { transform: rotate(0); } 75% { transform: rotate(-4deg); } 80% { transform: rotate(4deg); } 85% { transform: rotate(-3deg); } 90% { transform: rotate(2deg); } }

.reveal { text-align: center; animation: pop .5s ease-out both; }
.reveal .for { font-size: 1rem; color: var(--muted); margin-bottom: .25rem; }
.reveal .receiver { font-family: var(--display); font-size: clamp(2.4rem, 12vw, 3.6rem); color: var(--berry); font-weight: 800; line-height: 1.05; }
.wish { background: #fbf6ea; border-radius: 12px; padding: .9rem 1rem; text-align: left; white-space: pre-wrap; }
@keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.snow { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }
.snow i { position: absolute; top: -10px; width: 6px; height: 6px; background: #fff; border-radius: 50%; opacity: .7; animation: fall linear infinite; }
@keyframes fall { to { transform: translate3d(var(--drift, 20px), 105vh, 0); } }
@media (prefers-reduced-motion: reduce) {
  .snow, .gift.wiggle { animation: none; }
  .snow i { display: none; }
  .gift .lid, .gift .bow, .reveal { transition: none; animation: none; }
}

@media (max-width: 560px) {
  .people li { grid-template-columns: 1fr; }
  .panel { padding: 1rem; }
}

/* ---------- Wish lists ---------- */
.wish-list { list-style: none; margin: 0 0 1rem; padding: 0; }
.wish-item {
  display: flex; gap: .75rem; align-items: flex-start; justify-content: space-between;
  padding: .7rem .85rem; margin-bottom: .5rem;
  background: #fbf6ea; border: 1px solid var(--line); border-radius: 12px;
}
.wish-item.editing { display: block; background: #fff; }
.wish-main { min-width: 0; }
.wish-title { font-weight: 700; overflow-wrap: anywhere; }
.wish-title a { color: var(--pine); }
.wish-host { font-weight: 600; font-size: .78rem; color: var(--muted); white-space: nowrap; }
.wish-notes { font-size: .88rem; color: var(--muted); margin-top: .15rem; white-space: pre-wrap; }
.wish-item .actions { display: flex; gap: .35rem; flex-shrink: 0; }
.wish-add { border-top: 1px dashed var(--line); padding-top: 1rem; }
.wish-copy { margin-top: .75rem; }
.wish-copy summary { cursor: pointer; color: var(--pine); font-weight: 600; }
.reveal .wish-list { text-align: left; }

/* ---------- Account dashboard ---------- */
.section-title { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin: 1.75rem 0 .75rem; }
.section-title h2 { margin: 0; }
.kid-chips { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .5rem; }
.match-hidden { text-align: center; padding: .5rem 0; }
.match-name { font-family: var(--display); font-size: clamp(2rem, 8vw, 2.8rem); color: var(--berry); font-weight: 800; line-height: 1.1; margin: .25rem 0 1rem; }
.mini-card { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; }
.mini-card img { width: 140px; height: 140px; border: 2px dashed var(--berry); border-radius: 10px; padding: 4px; background: #fff; }
