/* Secret Santa — warm, festive, mobile-first. No external fonts or assets. */

:root {
  --bg: #FBF6EE;
  --surface: #FFFFFF;
  --surface-2: #F3EBDF;
  --line: #E8DDCD;
  --ink: #1D2A23;
  --ink-2: #56645C;
  --ink-3: #7D8A82;
  --green: #1F5A3D;
  --green-soft: #E2EEE6;
  --red: #A8282F;
  --red-soft: #F8E3E2;
  --gold: #8A6418;
  --gold-soft: #F7ECD3;
  --pine-soft: #E3ECEE;
  --pine: #2C5560;
  --berry-soft: #F3E3EC;
  --berry: #7E2E57;
  --primary: var(--green);
  --on-primary: #FFFFFF;
  --danger: #A8282F;
  --focus: #A8282F;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(40, 50, 30, .05), 0 6px 18px rgba(40, 50, 30, .06);
  --shadow-lg: 0 10px 40px rgba(20, 30, 20, .2);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: ui-serif, "New York", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --nav-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111A15;
    --surface: #1A251F;
    --surface-2: #233129;
    --line: #304037;
    --ink: #F4EFE6;
    --ink-2: #C4CCC6;
    --ink-3: #9AA69F;
    --green: #8CD3A9;
    --green-soft: #1F3A2B;
    --red: #F2A3A3;
    --red-soft: #432225;
    --gold: #EAC57A;
    --gold-soft: #3E3220;
    --pine-soft: #1F3338;
    --pine: #9FCCD6;
    --berry-soft: #3D2232;
    --berry: #EDB3D0;
    --primary: #8CD3A9;
    --on-primary: #0E1F15;
    --danger: #F2A3A3;
    --focus: #F2A3A3;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-lg: 0 10px 40px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html.sheet-open, html.sheet-open body { overflow: hidden; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
a { color: var(--green); text-underline-offset: 2px; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 8px; }
[hidden] { display: none !important; }
.icon { flex: none; }
.muted { color: var(--ink-2); }
.small { font-size: 14px; }
.center { text-align: center; }
.right { text-align: right; }
.over-text { color: var(--red); font-weight: 600; }

/* ---------- Boot ---------- */
.boot { min-height: 100vh; display: grid; place-content: center; justify-items: center; gap: 12px; color: var(--ink-2); font-family: var(--serif); font-size: 22px; }
.boot-mark { width: 56px; height: 56px; border-radius: 16px; background: var(--red); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .5; transform: scale(.94); } }
.boot-error { padding: 32px 20px; max-width: 520px; margin: 0 auto; }

/* ---------- Shell ---------- */
#view {
  max-width: 680px;
  margin: 0 auto;
  padding: calc(var(--safe-t) + 8px) 16px calc(var(--nav-h) + var(--safe-b) + 100px);
  outline: none;
}
body.bare #view { padding-bottom: calc(var(--safe-b) + 32px); }
body.bare .tabbar, body.bare .fab { display: none; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--nav-h) + var(--safe-b));
  padding: 4px max(4px, env(safe-area-inset-left)) var(--safe-b) max(4px, env(safe-area-inset-right));
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(18px);
  backdrop-filter: saturate(1.4) blur(18px);
  border-top: 1px solid var(--line);
}
.tab {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border: 0; background: none; color: var(--ink-2); font-size: 11.5px; font-weight: 500; padding: 4px 0; min-height: 48px; min-width: 0;
}
.tab.active { color: var(--red); }
.tab.active .icon { stroke-width: 2.1; }
.tab-label { white-space: nowrap; letter-spacing: -.01em; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.tab-badge {
  position: absolute; top: 2px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--red); color: var(--bg); font-size: 11px; font-weight: 700; line-height: 18px; text-align: center;
}

.fab {
  position: fixed; z-index: 31; right: max(16px, env(safe-area-inset-right)); bottom: calc(var(--nav-h) + var(--safe-b) + 16px);
  width: 60px; height: 60px; border-radius: 30px; border: 0; display: grid; place-items: center;
  background: var(--red); color: #fff; box-shadow: 0 6px 20px rgba(120, 20, 30, .28);
  transition: transform .12s ease;
}
@media (prefers-color-scheme: dark) { .fab { color: #2A0F12; } }
.fab:active { transform: scale(.94); }
@media (min-width: 720px) { .fab { right: calc(50% - 340px + 16px); } }

/* ---------- Page ---------- */
.page { display: flex; flex-direction: column; gap: 14px; padding-top: 8px; }
.page-header { display: flex; align-items: center; gap: 8px; min-height: 52px; }
.page-heading { flex: 1; min-width: 0; }
.page-title { margin: 0; font: 600 30px/1.15 var(--serif); letter-spacing: -.01em; overflow-wrap: anywhere; }
.page-subtitle { margin: 2px 0 0; color: var(--ink-2); font-size: 15px; }
.back-btn { margin-left: -10px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; margin-top: 10px; }
.section-title { margin: 0; font-size: 13px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-2); }
.link { font-size: 15px; font-weight: 600; text-decoration: none; min-height: 44px; display: inline-flex; align-items: center; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin: 0; }
.card > p { margin: 0 0 8px; }
.card > p:last-child { margin-bottom: 0; }

/* ---------- Hero ---------- */
.hero {
  position: relative; overflow: hidden; border-radius: 22px; padding: 22px 20px 20px; color: #FFF8EC;
  background:
    radial-gradient(circle at 88% 12%, rgba(255, 255, 255, .16) 0 2px, transparent 3px),
    radial-gradient(circle at 70% 40%, rgba(255, 255, 255, .14) 0 1.5px, transparent 2.5px),
    radial-gradient(circle at 94% 64%, rgba(255, 255, 255, .12) 0 2px, transparent 3px),
    radial-gradient(circle at 58% 18%, rgba(255, 255, 255, .12) 0 1.5px, transparent 2.5px),
    linear-gradient(140deg, #1F5A3D, #173F2C);
}
.hero-greeting { margin: 0; font-size: 15px; opacity: .85; }
.hero-title { color: inherit; margin-top: 2px; }
.countdown { display: flex; align-items: baseline; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.countdown-num { font: 700 46px/1 var(--serif); color: #F6D58A; }
.countdown-label { font-size: 16px; }

.notice {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: 14px; text-decoration: none;
  background: var(--gold-soft); color: var(--gold); font-size: 15px; font-weight: 500; min-height: 48px;
}
.notice-warn { background: var(--red-soft); color: var(--red); }

/* ---------- Stats & bars ---------- */
.budget-top { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.stat-label { margin: 0; font-size: 13px; color: var(--ink-2); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.stat-value { margin: 2px 0 0; font: 600 26px/1.15 var(--serif); }
.bar { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; margin: 6px 0 8px; }
.bar-fill { display: block; height: 100%; border-radius: 4px; background: var(--green); transition: width .3s ease; }
.bar.over .bar-fill { background: var(--red); }

/* ---------- To do ---------- */
.todo-list, .card-list, .gift-list, .person-strip, .past-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.todo {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; min-height: 52px; border-radius: 14px; text-decoration: none;
  color: var(--ink); background: var(--surface); border: 1px solid var(--line);
}
.todo > span { flex: 1; }
.todo > .icon:first-child { color: var(--red); }
.todo > .icon:last-child { color: var(--ink-3); }

.person-strip { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.person-chip {
  display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 14px; text-decoration: none; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); min-height: 60px;
}
.person-chip-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.person-chip-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.person-chip > .icon { color: var(--green); }
.quick-row { display: flex; gap: 10px; margin-top: 4px; }
.quick-row > .btn { flex: 1; }

/* ---------- Avatars ---------- */
.avatar { flex: none; display: grid; place-items: center; border-radius: 50%; font-weight: 700; letter-spacing: .02em; }
.tone-green { background: var(--green-soft); color: var(--green); }
.tone-red { background: var(--red-soft); color: var(--red); }
.tone-gold { background: var(--gold-soft); color: var(--gold); }
.tone-pine { background: var(--pine-soft); color: var(--pine); }
.tone-berry { background: var(--berry-soft); color: var(--berry); }

/* ---------- People ---------- */
.person-card {
  display: flex; align-items: center; gap: 12px; padding: 14px; border-radius: var(--radius); text-decoration: none; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow);
}
.person-card-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.person-card-text .bar { margin: 6px 0 0; height: 6px; }
.person-name { font-weight: 600; font-size: 17px; overflow-wrap: anywhere; }
.person-card > .icon { color: var(--ink-3); }
.done-badge { display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; border-radius: 999px; background: var(--green-soft); color: var(--green); font-size: 13px; font-weight: 700; }
.notes { margin: 8px 0 0; white-space: pre-wrap; color: var(--ink-2); font-size: 15px; }
.past-list li { display: flex; gap: 12px; padding: 12px 14px; border-radius: 14px; background: var(--surface-2); font-size: 15px; }
.past-year { font-weight: 700; color: var(--ink-2); flex: none; }

/* ---------- Gifts ---------- */
.gift-row {
  display: flex; align-items: center; gap: 6px; padding: 6px 8px 6px 4px; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--line);
}
.gift-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; border: 0; background: none; text-align: left; padding: 6px 4px 6px 8px; min-height: 52px; }
.status-dot { flex: none; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; }
.status-idea .status-dot { background: var(--gold-soft); color: var(--gold); }
.status-bought .status-dot { background: var(--pine-soft); color: var(--pine); }
.status-wrapped .status-dot { background: var(--red-soft); color: var(--red); }
.status-given .status-dot { background: var(--green-soft); color: var(--green); }
.gift-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.gift-name { font-weight: 600; overflow-wrap: anywhere; }
.status-given .gift-name { color: var(--ink-2); }
.gift-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 13.5px; color: var(--ink-2); }
.pill { padding: 1px 8px; border-radius: 999px; background: var(--surface-2); font-size: 12px; font-weight: 600; }
.gift-price { flex: none; font-weight: 600; font-variant-numeric: tabular-nums; font-size: 15px; }
.advance {
  flex: none; min-height: 44px; padding: 0 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--green-soft); color: var(--green); font-size: 14px; font-weight: 700; white-space: nowrap;
}
.advance:active { transform: scale(.97); }
.done-mark { flex: none; display: inline-flex; align-items: center; gap: 4px; padding: 0 10px; color: var(--green); font-size: 14px; font-weight: 700; }
@media (max-width: 380px) {
  .gift-row { flex-wrap: wrap; }
  .gift-main { flex-basis: 100%; }
  .advance, .done-mark { margin-left: auto; }
}

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 4px; margin: 0 -16px; padding-left: 16px; padding-right: 16px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-size: 15px; font-weight: 600;
}
.chip[aria-selected="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chip-count { font-size: 12.5px; opacity: .7; }
.group { display: flex; flex-direction: column; gap: 8px; }
.group-head { display: flex; align-items: center; gap: 4px; text-decoration: none; color: var(--ink); min-height: 44px; margin-top: 6px; }
.group-title { margin: 0; font: 600 19px/1.2 var(--serif); }

/* ---------- Thank-yous ---------- */
.thank-row { display: flex; align-items: center; gap: 4px; padding: 4px 8px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); }
.check {
  flex: none; width: 44px; height: 44px; display: grid; place-items: center; border: 0; background: none; padding: 0;
}
.check::before { content: ""; grid-area: 1 / 1; width: 26px; height: 26px; border-radius: 8px; border: 2px solid var(--ink-3); }
.check .icon { grid-area: 1 / 1; color: var(--on-primary); }
.check[aria-checked="true"]::before { background: var(--green); border-color: var(--green); }
.thank-main { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; border: 0; background: none; text-align: left; padding: 8px 4px; min-height: 52px; }
.thanked .gift-name { color: var(--ink-2); text-decoration: line-through; }

/* ---------- Empty ---------- */
.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; padding: 36px 16px; color: var(--ink-2); }
.empty > .icon { color: var(--green); }
.empty-title { margin: 4px 0 0; font: 600 21px/1.25 var(--serif); color: var(--ink); }
.empty-text { margin: 0 0 8px; max-width: 34ch; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 18px;
  border-radius: 14px; border: 1px solid transparent; font-weight: 600; font-size: 16px; text-decoration: none;
  transition: transform .1s ease;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn-danger { background: var(--danger); color: #fff; }
@media (prefers-color-scheme: dark) { .btn-danger { color: #2A0F12; } }
.btn-ghost-danger { background: transparent; color: var(--danger); }
.btn-link { background: none; color: var(--green); }
.btn-lg { min-height: 54px; font-size: 17px; }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1 1 auto; }
.btn-col { display: flex; flex-direction: column; gap: 10px; }
.card .btn-row, .card .btn-col { margin-top: 12px; }
.card.btn-col { margin-top: 0; }
.icon-btn {
  flex: none; width: 44px; height: 44px; display: grid; place-items: center; border: 0; border-radius: 12px; background: none; color: var(--ink-2);
}
.link-btn { color: var(--ink-2); }

/* ---------- Forms ---------- */
.form { display: flex; flex-direction: column; gap: 14px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-label { font-size: 14px; font-weight: 600; color: var(--ink-2); }
.field-hint { font-size: 13.5px; color: var(--ink-3); }
.field-hint:empty { display: none; }
.field-inline { margin-top: 4px; }
input[type="text"], input[type="url"], select, textarea {
  width: 100%; min-height: 48px; padding: 11px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); color: var(--ink); font-size: 17px; appearance: none; -webkit-appearance: none;
}
.field-inline input { width: 100%; }
select {
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-2) 50%), linear-gradient(135deg, var(--ink-2) 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 15px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 36px;
}
textarea { resize: vertical; min-height: 72px; line-height: 1.4; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 3px color-mix(in srgb, var(--green) 25%, transparent); }
.segmented { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; padding: 4px; border-radius: 14px; background: var(--surface-2); }
.seg { min-height: 44px; border: 0; border-radius: 10px; background: none; font-size: 14.5px; font-weight: 600; color: var(--ink-2); padding: 0 4px; }
.seg[aria-checked="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

/* ---------- Welcome ---------- */
.welcome { padding-top: calc(var(--safe-t) + 28px); max-width: 460px; margin: 0 auto; }
.welcome-mark { width: 84px; height: 84px; border-radius: 24px; display: grid; place-items: center; background: var(--red); color: #fff; margin: 0 auto; box-shadow: var(--shadow-lg); }
.welcome-title { text-align: center; font-size: 36px; }
.welcome-lead { margin: 0; text-align: center; color: var(--ink-2); }
.about { margin-top: 16px; }

/* ---------- Sheets ---------- */
.sheet-layer { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(10, 20, 15, .4); opacity: 0; transition: opacity .2s ease; }
.sheet {
  position: relative; width: 100%; max-width: 560px; max-height: 92vh; display: flex; flex-direction: column;
  background: var(--bg); border-radius: 22px 22px 0 0; box-shadow: var(--shadow-lg); outline: none;
  transform: translateY(100%); transition: transform .24s cubic-bezier(.2, .8, .2, 1);
}
.sheet-layer.open .sheet-backdrop { opacity: 1; }
.sheet-layer.open .sheet { transform: none; }
@media (prefers-reduced-motion: reduce) { .sheet, .sheet-backdrop { transition: none !important; } }
@media (min-width: 720px) {
  .sheet-layer { align-items: center; }
  .sheet { border-radius: 22px; max-height: 88vh; }
}
.sheet-header { display: flex; align-items: center; gap: 8px; padding: 14px 8px 8px 20px; flex: none; }
.sheet-title { flex: 1; margin: 0; font: 600 21px/1.25 var(--serif); }
.sheet-body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 6px 20px 20px; overscroll-behavior: contain; }
.sheet-footer { flex: none; padding: 10px 16px calc(12px + var(--safe-b)); border-top: 1px solid var(--line); }
.dialog-message { margin: 0; color: var(--ink-2); }

/* ---------- Toasts ---------- */
#toasts { position: fixed; z-index: 60; left: 0; right: 0; bottom: calc(var(--nav-h) + var(--safe-b) + 88px); display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 16px; }
.sheet-open #toasts { bottom: calc(var(--safe-b) + 90px); }
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 12px; max-width: 480px; width: 100%;
  padding: 10px 12px 10px 16px; border-radius: 14px; background: var(--ink); color: var(--bg); font-size: 15px; box-shadow: var(--shadow-lg);
  opacity: 0; transform: translateY(8px); transition: opacity .2s ease, transform .2s ease;
}
.toast.show { opacity: 1; transform: none; }
.toast-error { background: var(--danger); color: #fff; }
.toast-msg { flex: 1; }
.toast-action { border: 0; background: none; color: #F6D58A; font-weight: 700; padding: 6px 4px; min-height: 36px; white-space: nowrap; }
@media (prefers-color-scheme: dark) { .toast-action { color: #A8282F; } .toast-error { color: #2A0F12; } }
