/* Secret Santa Hat: festive but restrained. Mobile first, light/dark aware. */

:root {
  color-scheme: light dark;
  --bg: #f8f3ea;
  --bg-dot: rgba(120, 80, 40, .06);
  --surface: #fffdf9;
  --surface-2: #f3ece1;
  --text: #221b17;
  --muted: #6c6158;
  --border: #e5dacb;
  --red: #b3261e;
  --red-strong: #8f1d17;
  --red-soft: #fbe4e1;
  --btn: #b3261e;
  --btn-hover: #8f1d17;
  --green: #1d6b47;
  --green-soft: #def1e6;
  --gold: #d6a23a;
  --on-accent: #fff;
  --focus: #1d6b47;
  --error: #b3261e;
  --shadow: 0 1px 2px rgba(60, 30, 10, .06), 0 6px 20px rgba(60, 30, 10, .06);
  --radius: 16px;
  --ad-bg: rgba(0, 0, 0, .03);
  --ad-border: rgba(0, 0, 0, .14);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16110f;
    --bg-dot: rgba(255, 230, 200, .035);
    --surface: #211a17;
    --surface-2: #2b2320;
    --text: #f4ece4;
    --muted: #b3a79c;
    --border: #3a302b;
    --red: #e0574d;
    --red-strong: #c4382e;
    --red-soft: #3b1d1a;
    --btn: #c0352b;
    --btn-hover: #a32a22;
    --green: #5cc493;
    --green-soft: #183326;
    --gold: #e9b754;
    --on-accent: #fff;
    --focus: #7ad8ab;
    --error: #ff8a80;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    --ad-bg: rgba(255, 255, 255, .03);
    --ad-border: rgba(255, 255, 255, .16);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  font: 16px/1.5 var(--font);
  color: var(--text);
  background-color: var(--bg);
  background-image: radial-gradient(var(--bg-dot) 1px, transparent 1.2px);
  background-size: 14px 14px;
  min-height: 100vh;
}

a { color: var(--green); }
a:hover { text-decoration-thickness: 2px; }
h1, h2, h3 { line-height: 1.2; }
kbd {
  font: inherit; font-size: .85em; padding: 1px 6px; border-radius: 6px;
  border: 1px solid var(--border); border-bottom-width: 2px; background: var(--surface);
}
code { font-size: .9em; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
.muted { color: var(--muted); font-weight: 400; }
.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
[hidden] { display: none !important; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 8px; }

.skip-link {
  position: absolute; left: 8px; top: -60px; z-index: 50; padding: 8px 14px;
  background: var(--surface); color: var(--text); border-radius: 10px; box-shadow: var(--shadow);
}
.skip-link:focus { top: 8px; }
.noscript { margin: 16px; padding: 12px 16px; background: var(--red-soft); border-radius: 12px; }

/* ---------- Buttons ---------- */
.btn {
  -webkit-appearance: none; appearance: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 8px 16px;
  font: inherit; font-weight: 600; color: var(--text);
  background: var(--surface); border: 1.5px solid var(--border); border-radius: 12px;
  cursor: pointer; transition: background .15s, border-color .15s, transform .1s;
  text-decoration: none;
}
.btn:hover { border-color: var(--muted); }
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--btn); border-color: var(--btn); color: var(--on-accent); }
.btn--primary:hover { background: var(--btn-hover); border-color: var(--btn-hover); }
.btn--quiet { border-color: transparent; background: transparent; color: var(--muted); font-weight: 500; min-height: 40px; padding: 6px 10px; }
.btn--quiet:hover { color: var(--text); background: var(--surface-2); border-color: transparent; }
.btn--huge { width: 100%; min-height: 60px; font-size: 1.25rem; border-radius: 16px; box-shadow: 0 6px 18px rgba(179, 38, 30, .25); }
.btn[aria-disabled="true"] { opacity: .55; box-shadow: none; }
.btn.is-done { background: var(--green-soft); border-color: var(--green); color: var(--green); }

/* ---------- Header / layout ---------- */
.site-header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  max-width: 1120px; margin: 0 auto; padding: 12px 16px;
}
.brand { display: inline-flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; font-weight: 800; }
.brand__logo { width: 34px; height: 34px; }
.brand__name { font-family: var(--font-display); font-size: 1.15rem; letter-spacing: -.01em; }
.site-header__nav { display: flex; gap: 14px; font-size: .95rem; }
.site-header__nav a { color: var(--muted); text-decoration: none; }
.site-header__nav a:hover { color: var(--text); }

.layout {
  max-width: 1120px; margin: 0 auto; padding: 0 16px 24px;
  display: grid; grid-template-columns: minmax(0, 1fr); gap: 24px; align-items: start;
}
.tool { max-width: 680px; width: 100%; margin: 0 auto; display: grid; gap: 16px; }
@media (min-width: 1000px) {
  .layout { grid-template-columns: minmax(0, 1fr) 300px; }
  .tool { margin: 0; justify-self: end; }
  .sidebar { position: sticky; top: 16px; }
}
@media (max-width: 999px) { .sidebar { display: none; } }

.intro h1 { font-family: var(--font-display); font-size: clamp(1.7rem, 5vw, 2.3rem); margin: 8px 0 4px; letter-spacing: -.02em; }
.intro__lead { margin: 0; color: var(--muted); font-size: 1.05rem; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px;
}
@media (min-width: 600px) { .card { padding: 20px 22px; } }
.card__head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.card__head h2 { font-size: 1.12rem; margin: 0; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.card__foot { display: flex; justify-content: space-between; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.step {
  display: inline-grid; place-items: center; width: 28px; height: 28px; flex: none;
  border-radius: 50%; background: var(--btn); color: var(--on-accent); font-size: .9rem; font-weight: 800;
}
.step--done { background: var(--green); }
.opt { font-size: .8rem; font-weight: 500; color: var(--muted); background: var(--surface-2); padding: 2px 8px; border-radius: 99px; }
.count { color: var(--muted); font-size: .92rem; white-space: nowrap; }
.help { color: var(--muted); font-size: .92rem; margin: 8px 0 0; }

/* ---------- People list ---------- */
.people { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.person { display: grid; grid-template-columns: 28px minmax(0, 1fr) 44px; align-items: center; gap: 4px; }
.person__num { color: var(--muted); font-size: .85rem; text-align: right; padding-right: 6px; font-variant-numeric: tabular-nums; }
.person__input {
  width: 100%; min-height: 46px; padding: 8px 12px;
  font: inherit; font-size: 1.05rem; color: var(--text);
  background: transparent; border: 1.5px solid transparent; border-radius: 10px;
  transition: border-color .12s, background .12s;
}
.person__input:hover { background: var(--surface-2); }
.person__input:focus { outline: none; border-color: var(--green); background: var(--surface); box-shadow: 0 0 0 3px color-mix(in srgb, var(--green) 20%, transparent); }
.person.is-blank .person__input { border: 1.5px dashed var(--border); }
.person.is-blank .person__input:focus { border-style: solid; border-color: var(--green); }
.person__input::placeholder { color: var(--muted); opacity: .8; }
.person__input[aria-invalid="true"] { border-color: var(--error); background: var(--red-soft); }
.person__del {
  width: 40px; height: 40px; border: 0; border-radius: 10px; background: transparent;
  color: var(--muted); font-size: 1.4rem; line-height: 1; cursor: pointer;
}
.person__del:hover { background: var(--red-soft); color: var(--error); }
.person.is-blank .person__del { visibility: hidden; }
.person__err { grid-column: 2 / 4; margin: 0 0 4px 12px; color: var(--error); font-size: .88rem; }
.person__err:empty { display: none; }

/* ---------- Toggles ---------- */
.toggle { display: flex; align-items: center; gap: 10px; margin: 12px 0 4px; cursor: pointer; min-height: 44px; }
.toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.toggle__track {
  flex: none; width: 44px; height: 26px; border-radius: 99px; background: var(--border); position: relative; transition: background .15s;
}
.toggle__track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .15s;
}
.toggle input:checked + .toggle__track { background: var(--green); }
.toggle input:checked + .toggle__track::after { transform: translateX(18px); }
.toggle input:focus-visible + .toggle__track { outline: 3px solid var(--focus); outline-offset: 2px; }
.toggle--small { font-size: .93rem; }

/* ---------- Exclusion picker ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.chip {
  min-height: 40px; padding: 6px 14px; border-radius: 99px; font: inherit; font-weight: 500;
  color: var(--text); background: var(--surface-2); border: 1.5px solid var(--border); cursor: pointer;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chip:hover { border-color: var(--muted); }
.chip[aria-pressed="true"] { background: var(--btn); border-color: var(--btn); color: var(--on-accent); }
.chip.is-linked { border-style: dashed; color: var(--muted); }
.pick-hint { min-height: 1.5em; margin: 8px 0 4px; font-size: .93rem; color: var(--muted); }
.pick-hint.is-active { color: var(--red); font-weight: 600; }
.rules { list-style: none; margin: 4px 0 0; padding: 0; display: grid; gap: 6px; }
.rule {
  display: flex; align-items: center; gap: 6px; padding: 4px 4px 4px 12px;
  background: var(--green-soft); border-radius: 12px;
}
.rule__text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.rule__dir, .rule__del {
  flex: none; min-width: 40px; height: 40px; border: 0; border-radius: 10px; background: transparent;
  color: var(--text); font: inherit; cursor: pointer;
}
.rule__dir { font-size: .85rem; padding: 0 10px; color: var(--green); font-weight: 600; }
.rule__del { font-size: 1.3rem; color: var(--muted); }
.rule__dir:hover, .rule__del:hover { background: var(--surface); }

/* ---------- Details ---------- */
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { display: grid; gap: 4px; min-width: 0; }
.field--wide { grid-column: 1 / -1; }
.field label { font-weight: 600; font-size: .92rem; }
.field input, .field textarea, .hint-list input, .org-link input {
  width: 100%; min-height: 44px; padding: 8px 12px; font: inherit; color: var(--text);
  background: var(--surface); border: 1.5px solid var(--border); border-radius: 10px;
}
.field textarea { resize: vertical; min-height: 64px; }
.field input:focus, .field textarea:focus, .hint-list input:focus, .org-link input:focus {
  outline: none; border-color: var(--green); box-shadow: 0 0 0 3px color-mix(in srgb, var(--green) 20%, transparent);
}
.wishes { margin-top: 14px; border-top: 1px solid var(--border); padding-top: 10px; }
.wishes summary { cursor: pointer; font-weight: 600; min-height: 36px; display: list-item; }
.hint-list { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 8px; }
.hint-list li { display: grid; grid-template-columns: minmax(70px, 30%) 1fr; align-items: center; gap: 10px; }
.hint-list label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }

/* ---------- Draw ---------- */
.draw { display: grid; gap: 10px; position: sticky; bottom: 8px; z-index: 5; }
.draw::before {
  content: ""; position: absolute; inset: -12px -8px -8px; z-index: -1; border-radius: 20px;
  background: linear-gradient(to bottom, transparent, var(--bg) 30%);
}
.problems:empty { display: none; }
.problems { display: grid; gap: 6px; }
.problem { margin: 0; padding: 10px 14px; border-radius: 12px; font-size: .95rem; background: var(--surface); border: 1px solid var(--border); }
.problem--error { background: var(--red-soft); border-color: color-mix(in srgb, var(--error) 40%, transparent); color: var(--text); }
.problem--error::before { content: "⚠ "; color: var(--error); font-weight: 700; }
.problem--info::before { content: "ℹ "; color: var(--green); font-weight: 700; }
.problems.is-flash .problem--error { animation: flash .6s; }
@keyframes flash { 30% { transform: translateX(-4px); } 60% { transform: translateX(4px); } }

/* ---------- Results ---------- */
.card--results { border: 2px solid var(--green); }
.card--results:focus { outline: none; }
.results-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.links { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.link-row {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 8px;
  padding: 8px 8px 8px 14px; border-radius: 12px; background: var(--surface-2);
}
.link-row__who { min-width: 0; }
.link-row__name { font-weight: 600; overflow-wrap: anywhere; }
.link-row__meta { display: block; font-size: .85rem; color: var(--muted); }
.link-row__meta.is-sent { color: var(--green); }
.link-row__btns { display: flex; gap: 6px; }
.link-row__btns .btn { min-height: 40px; padding: 6px 12px; font-size: .93rem; }
.org-link { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }
.org-link label { font-weight: 600; font-size: .92rem; }
.org-link__row { display: flex; gap: 8px; margin-top: 4px; }
.org-link__row input { font-size: .85rem; color: var(--muted); min-width: 0; }

.recent summary { cursor: pointer; font-weight: 600; }
.recent ul { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 4px; }
.recent li { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.recent a { overflow-wrap: anywhere; }

/* ---------- Ads (reserved sizes: no layout shift) ---------- */
.ad-slot {
  position: relative; display: grid; place-items: center; margin: 0 auto;
  border: 1.5px dashed var(--ad-border); border-radius: 12px; background: var(--ad-bg);
  overflow: hidden; contain: layout paint;
}
.ad-slot__label { font-size: .7rem; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.ad-slot--leaderboard { width: 320px; max-width: calc(100% - 32px); height: 50px; margin-bottom: 8px; }
.ad-slot--rect { width: 300px; max-width: 100%; height: 250px; }
.ad-slot--inline { width: 320px; max-width: 100%; height: 100px; margin: 8px auto; }
@media (min-width: 760px) {
  .ad-slot--leaderboard { width: 728px; height: 90px; }
  .ad-slot--inline { width: 468px; height: 60px; }
}
@media (min-width: 1000px) { .content .ad-slot--inline { width: 728px; height: 90px; } }

/* ---------- SEO content ---------- */
.content { max-width: 760px; margin: 24px auto 0; padding: 0 16px; }
.content section { margin: 0 0 32px; }
.content h2 { font-family: var(--font-display); font-size: 1.4rem; margin: 0 0 12px; }
.content h3 { margin: 0 0 6px; font-size: 1.05rem; }
.how { padding-left: 1.3em; display: grid; gap: 8px; }
.ideas { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.ideas > div { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px; }
.ideas ul { margin: 0; padding-left: 1.2em; }
#faq details { border-bottom: 1px solid var(--border); padding: 4px 0; }
#faq summary { cursor: pointer; font-weight: 600; padding: 10px 0; min-height: 44px; }
#faq details p { margin: 0 0 12px; color: var(--muted); }

.site-footer { max-width: 760px; margin: 0 auto; padding: 16px 16px 40px; border-top: 1px solid var(--border); font-size: .92rem; }
.site-footer__row { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 100;
  display: flex; align-items: center; gap: 12px; max-width: calc(100% - 32px); width: max-content;
  padding: 10px 12px 10px 16px; border-radius: 14px; background: #2a211d; color: #fff;
  box-shadow: 0 10px 30px rgba(0,0,0,.3); font-size: .95rem;
}
.toast__undo { flex: none; min-height: 36px; padding: 4px 12px; border: 0; border-radius: 10px; background: var(--gold); color: #2a211d; font: inherit; font-weight: 700; cursor: pointer; }

/* ---------- Embed mode ---------- */
.embed-credit { display: none; }
html.embed .chrome { display: none !important; }
html.embed body { background-image: none; }
html.embed .layout { padding-top: 12px; grid-template-columns: minmax(0, 1fr); }
html.embed .tool { justify-self: center; margin: 0 auto; }
html.embed .intro h1 { font-size: 1.4rem; margin-top: 0; }
html.embed .embed-credit { display: block; text-align: center; font-size: .85rem; margin: 4px 0 16px; }

/* ---------- Reveal view ---------- */
html.is-reveal .organiser { display: none; }
.reveal {
  min-height: 100vh; padding: 16px 16px 32px;
  background:
    radial-gradient(1200px 500px at 50% -10%, color-mix(in srgb, var(--red) 18%, transparent), transparent 70%),
    radial-gradient(var(--bg-dot) 1px, transparent 1.2px) 0 0 / 14px 14px,
    var(--bg);
}
.reveal__main { max-width: 520px; margin: 0 auto; text-align: center; }
.reveal__stage {
  position: relative; margin-top: 4vh; padding: 28px 20px 22px; border-radius: 24px;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); overflow: hidden;
}
.reveal__stage::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 8px;
  background: repeating-linear-gradient(-45deg, var(--red) 0 12px, #fff 12px 24px, var(--green) 24px 36px, #fff 36px 48px);
  opacity: .9;
}
.reveal__event { margin: 4px 0 0; color: var(--muted); font-weight: 600; letter-spacing: .02em; }
.reveal__hi { font-family: var(--font-display); font-size: clamp(1.8rem, 7vw, 2.4rem); margin: 4px 0 2px; overflow-wrap: anywhere; }
.reveal__lead { margin: 0 0 8px; color: var(--muted); }
.reveal__secret { margin: 18px 0 0; font-size: .9rem; color: var(--muted); }

.gift {
  display: block; margin: 8px auto 0; padding: 0; width: min(240px, 70vw); aspect-ratio: 200 / 190;
  border: 0; background: none; cursor: pointer; border-radius: 20px;
}
.gift svg { width: 100%; height: 100%; overflow: visible; }
.gift__shadow { fill: rgba(0, 0, 0, .12); }
.gift__paper { fill: var(--red); }
.gift__paper--lid { fill: var(--red-strong); }
.gift__ribbon, .gift__bow, .gift__knot { fill: var(--gold); }
.gift__fold { stroke: rgba(0, 0, 0, .1); stroke-width: 2; }
.gift__lid, .gift__box { transform-box: fill-box; transform-origin: 50% 100%; transition: transform .7s cubic-bezier(.2, .8, .2, 1.2), opacity .5s; }
@media (prefers-reduced-motion: no-preference) {
  .gift:not(.is-open) svg { animation: wiggle 3.2s ease-in-out infinite; transform-origin: 50% 90%; }
  .gift:hover:not(.is-open) .gift__lid { transform: translateY(-6px); }
}
@keyframes wiggle {
  0%, 70%, 100% { transform: rotate(0); }
  75% { transform: rotate(-4deg); } 80% { transform: rotate(4deg); } 85% { transform: rotate(-3deg); } 90% { transform: rotate(2deg); }
}
.gift.is-open .gift__lid { transform: translate(40px, -90px) rotate(28deg); opacity: 0; }
.gift.is-open .gift__box { transform: scale(.9) translateY(8px); opacity: 0; transition-delay: .25s; }
.gift.is-open { pointer-events: none; height: 0; aspect-ratio: auto; transition: height .4s .55s; }

.reveal__card { margin-top: 6px; }
.reveal__card:not([hidden]) { animation: pop .6s cubic-bezier(.2, .9, .3, 1.3) both .35s; }
@keyframes pop { from { opacity: 0; transform: translateY(16px) scale(.92); } to { opacity: 1; transform: none; } }
.reveal__label { margin: 0; color: var(--muted); font-weight: 600; }
.reveal__name {
  font-family: var(--font-display); font-size: clamp(2.2rem, 11vw, 3.4rem); margin: 4px 0 14px;
  color: var(--red); overflow-wrap: anywhere; letter-spacing: -.02em;
}
.reveal__name:focus { outline: none; }
.reveal__details { margin: 0 auto; display: grid; gap: 8px; text-align: left; max-width: 400px; }
.reveal__details > div { padding: 10px 14px; background: var(--surface-2); border-radius: 12px; }
.reveal__details dt { font-size: .8rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.reveal__details dd { margin: 2px 0 0; overflow-wrap: anywhere; white-space: pre-line; }
.reveal__actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 16px; }
.reveal__error { margin-top: 10vh; padding: 24px; background: var(--surface); border-radius: 20px; border: 1px solid var(--border); }
.reveal__cta { margin: 24px 0 0; font-weight: 600; }
/* Keep the ad well away from the reveal moment. */
.reveal__ad-gap { height: 40vh; }

.confetti { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.confetti i {
  position: absolute; top: 34%; left: 50%; width: 8px; height: 12px; border-radius: 2px; opacity: 0;
  background: var(--c); animation: burst 1.4s cubic-bezier(.15, .7, .3, 1) forwards; animation-delay: var(--d);
}
@keyframes burst {
  0% { opacity: 1; transform: translate(-50%, 0) rotate(0); }
  100% { opacity: 0; transform: translate(calc(-50% + var(--x)), var(--y)) rotate(var(--r)); }
}
@media (prefers-reduced-motion: reduce) {
  .gift__lid, .gift__box, .gift.is-open { transition: none; }
  .reveal__card:not([hidden]) { animation: none; }
  .confetti { display: none; }
  .problems.is-flash .problem--error { animation: none; }
}

@media print {
  .chrome, .ad-slot, .draw, .toast { display: none !important; }
}
