/* Family Secret Santa — design system */
:root {
  color-scheme: light;

  /* Color */
  --paper: #FCFAF6;
  --linen: #F2EDE3;
  --sage: #E7EEE7;
  --kraft: #D8B88E;
  --kraft-deep: #B8905C;
  --brass: #B9892C;
  --brass-ink: #7A5612;
  --spruce: #16352B;
  --spruce-mid: #2C5A48;
  --ink-soft: #4E615A;
  --ink-placeholder: #5C6B64;
  --hairline: rgba(22, 53, 43, 0.16);
  --hairline-strong: rgba(22, 53, 43, 0.32);
  --berry: #9B2C3A;
  --on-dark: #FCFAF6;

  /* Type */
  --font-display: "Fraunces", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --font-text: "Atkinson Hyperlegible", "Helvetica Neue", Arial, system-ui, sans-serif;
  --font-mono: ui-monospace, Menlo, Consolas, monospace;

  --text-display: 2.25rem;
  --text-title: 1.75rem;
  --text-heading: 1.25rem;
  --text-body: 1.0625rem;
  --text-button: 1.0625rem;
  --text-small: 0.9375rem;
  --text-admin-small: 0.875rem;

  --leading-display: 1.1;
  --leading-title: 1.15;
  --leading-heading: 1.3;
  --leading-body: 1.5;
  --leading-small: 1.45;

  /* Spacing */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --space-8: 64px;

  --gutter: var(--space-5);
  --measure: 34rem;
  --measure-admin: 56rem;

  /* Radius: tag > button > input */
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 18px;
  --radius-card: 24px;

  /* Shadow */
  --shadow-tag: 0 10px 28px -14px rgba(22, 53, 43, 0.45), 0 1px 2px rgba(22, 53, 43, 0.12);
  --shadow-card: 0 24px 60px -30px rgba(0, 0, 0, 0.5);

  /* Motion */
  --ease-out: cubic-bezier(0.2, 0.7, 0.2, 1);
  --dur-fast: 160ms;
  --dur-base: 280ms;
  --dur-reveal: 600ms;

  /* Controls */
  --tap-min: 44px;
  --control-h: 52px;
  --input-h: 48px;
  --header-h: 56px;
}

@media (prefers-reduced-motion: reduce) {
  :root {
    --dur-fast: 1ms;
    --dur-base: 1ms;
    --dur-reveal: 1ms;
  }
}

/* ---- Base ---- */
*, *::before, *::after { box-sizing: border-box; }
html { font-size: 100%; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--spruce);
  font-family: var(--font-text);
  font-size: var(--text-body);
  line-height: var(--leading-body);
  letter-spacing: 0;
}

h1, h2, h3 { margin: 0; font-family: var(--font-display); font-weight: 600; letter-spacing: 0; }
h1 { font-size: var(--text-title); line-height: var(--leading-title); font-variation-settings: "opsz" 144; }
h2 { font-size: var(--text-heading); line-height: var(--leading-heading); font-weight: 500; }
p  { margin: 0 0 var(--space-3); }
.small { font-size: var(--text-small); line-height: var(--leading-small); color: var(--ink-soft); }
.error { color: var(--berry); }
.strong { font-weight: 700; }

a { color: var(--spruce); text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1.5px; }
a:hover { color: var(--spruce-mid); }

:focus-visible {
  outline: 3px solid var(--spruce);
  outline-offset: 3px;
  box-shadow: 0 0 0 2px var(--paper);
}

/* ---- Layout: the page is the card ---- */
.page {
  position: relative;
  max-width: var(--measure);
  margin: 0 auto;
  padding: 0 var(--gutter) calc(var(--space-7) + env(safe-area-inset-bottom));
}
.header {
  position: relative;
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  min-height: var(--header-h);
  border-bottom: 1px solid var(--hairline);
  margin-bottom: var(--space-6);
}
.wordmark {
  font-weight: 700;
  font-size: var(--text-small);
  text-decoration: none;
  color: var(--spruce);
  padding: 10px 0;
  min-height: var(--tap-min);
  display: inline-flex;
  align-items: center;
}
.section { margin-top: var(--space-7); }
.section > h2 { margin-bottom: var(--space-3); }
.centered { text-align: center; padding-top: var(--space-6); }
.centered .wordmark-center { font-weight: 700; font-size: var(--text-small); color: var(--spruce); margin-bottom: var(--space-5); }
.centered .tag-mark { display: block; width: 48px; height: 48px; margin: 0 auto var(--space-5); }
.centered h1 { margin-bottom: var(--space-3); }
.centered .lead-body { max-width: 24rem; margin: 0 auto var(--space-5); }
.centered .sub-note { margin-top: var(--space-4); }
.gate-form { text-align: left; max-width: 24rem; margin: var(--space-5) auto 0; }

.footer-line {
  margin-top: var(--space-7);
  padding-top: var(--space-4);
  border-top: 1px solid var(--hairline);
  font-size: var(--text-small);
  color: var(--ink-soft);
}
.inline-form { display: inline; }
.inline-link-btn {
  display: inline;
  padding: 10px 2px;
  min-height: var(--tap-min);
  background: none;
  border: 0;
  color: var(--spruce);
  font: 400 var(--text-small) / var(--leading-small) var(--font-text);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1.5px;
  cursor: pointer;
}
.inline-link-btn:hover { color: var(--spruce-mid); }

@media (min-width: 720px) {
  body { background: var(--spruce); }
  .page {
    --gutter: var(--space-6);
    background: var(--paper);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-card);
    margin: var(--space-7) auto;
    padding-top: var(--space-2);
  }
  body.admin { background: var(--linen); }
  body.admin .page {
    max-width: var(--measure-admin);
    box-shadow: none;
    border: 1px solid var(--hairline);
  }
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 100%;
  min-height: var(--control-h);
  padding: 12px var(--space-5);
  border-radius: var(--radius-md);
  border: 1.5px solid transparent;
  font: 700 var(--text-button) / 1.2 var(--font-text);
  text-decoration: none;
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out);
}
.btn-primary { background: var(--spruce); color: var(--on-dark); }
.btn-primary:hover { background: var(--spruce-mid); color: var(--on-dark); }
.btn-primary:active { background: var(--spruce-mid); transform: scale(0.985); }
.btn-secondary { background: var(--paper); color: var(--spruce); border-color: var(--hairline-strong); }
.btn-secondary:hover { background: var(--linen); color: var(--spruce); }
.btn-secondary:active { background: var(--linen); }
.btn-danger { background: var(--paper); color: var(--berry); border-color: var(--berry); }
.btn-danger:hover { background: var(--linen); color: var(--berry); }
.btn-danger-filled { background: var(--berry); color: var(--on-dark); }
.btn-danger-filled:hover { opacity: 0.92; }
.btn:disabled { background: var(--linen); color: var(--ink-soft); border-color: transparent; transform: none; cursor: default; }
.btn-auto { width: auto; }

.btn-text {
  display: inline-flex; align-items: center;
  min-height: var(--tap-min); padding: 10px 6px;
  background: none; border: 0; color: var(--spruce);
  font: 700 var(--text-button) / 1.2 var(--font-text);
  text-decoration: none;
  cursor: pointer;
}
.btn-text:hover { color: var(--spruce-mid); }
.btn-text.danger { color: var(--berry); }
.btn-text.small-action { font-size: var(--text-small); }

/* ---- Inputs ---- */
label { display: block; font-weight: 700; margin-bottom: var(--space-2); }
.help { font-size: var(--text-small); color: var(--ink-soft); margin: calc(-1 * var(--space-1)) 0 var(--space-2); }
input[type="text"], input[type="password"], input[type="tel"], input[type="email"], input[type="date"], textarea, select {
  width: 100%;
  min-height: var(--input-h);
  padding: 12px 14px;
  border: 1.5px solid var(--hairline-strong);
  border-radius: var(--radius-sm);
  background: var(--paper);
  color: var(--spruce);
  font: 400 var(--text-body) / var(--leading-body) var(--font-text);
}
textarea { resize: vertical; min-height: calc(5 * 1.5 * var(--text-body) + 24px); field-sizing: content; }
textarea.short { min-height: calc(3 * 1.5 * var(--text-body) + 24px); }
::placeholder { color: var(--ink-placeholder); opacity: 1; }
input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: none; border-color: var(--spruce); box-shadow: inset 0 0 0 1px var(--spruce);
}
.field { margin-bottom: var(--space-4); }
.field-error { color: var(--berry); font-size: var(--text-small); margin-top: var(--space-2); }

/* ---- Info block, flash banner, empty state ---- */
.info { background: var(--sage); border-radius: var(--radius-lg); padding: var(--space-4) var(--space-5); margin: var(--space-4) 0; }
.info p:last-child { margin-bottom: 0; }
.flash {
  background: var(--sage);
  color: var(--spruce);
  border-radius: var(--radius-lg);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-5);
  font-weight: 700;
  font-size: var(--text-small);
}
.flash.error-flash {
  background: var(--paper);
  border: 2px solid var(--berry);
  color: var(--berry);
}
.empty { color: var(--ink-soft); }

/* ---- List rows ---- */
.rows { list-style: none; margin: 0; padding: 0; }
.row {
  display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-4); align-items: center;
  min-height: 56px; padding: 12px 0; border-bottom: 1px solid var(--hairline);
}
.row-main { flex: 1 1 200px; }
.row-sub { display: block; font-size: var(--text-small); color: var(--ink-soft); }
.row-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }
.row-panel {
  flex: 1 0 100%;
  margin-top: var(--space-2);
  padding: var(--space-4);
  background: var(--linen);
  border-radius: var(--radius-sm);
}

/* ---- Name chip + sheet ---- */
.chip-wrap { position: relative; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: var(--tap-min); padding: 8px 12px;
  background: var(--linen); color: var(--spruce); border: 0; border-radius: var(--radius-sm);
  font: 700 var(--text-small) / 1 var(--font-text); cursor: pointer;
}
.chip:hover { background: var(--sage); }
.sheet {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 20;
  background: var(--paper); border: 1px solid var(--hairline); border-radius: var(--radius-sm);
  min-width: 220px; padding: var(--space-2) 0;
}
.sheet[hidden] { display: none; }
.sheet .btn-text { display: flex; width: 100%; text-align: left; padding: 12px var(--space-4); }
.sheet .who { padding: 8px var(--space-4) 12px; border-bottom: 1px solid var(--hairline); font-size: var(--text-small); color: var(--ink-soft); }

/* ---- The gift tag (reveal control) ----
   Front face is a <form> holding the reveal <button>; back face is a plain panel with its own
   Hide <button>. No button is ever nested in another. Faces share one grid cell. */
.tag-wrap { perspective: 1200px; margin: var(--space-5) 0; }
.tag {
  position: relative; display: grid; width: 100%; min-height: 186px;
  background: var(--kraft); color: var(--spruce);
  border: 1.5px solid var(--kraft-deep); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-tag);
  transform: rotate(-1.5deg);
  transform-style: preserve-3d;
  transition: transform var(--dur-reveal) var(--ease-out);
}
.tag:has(.reveal:active) { transform: rotate(0) scale(0.98); transition-duration: var(--dur-fast); }
.tag[data-open="true"] { transform: rotate(0) rotateY(180deg); }
.tag .face {
  grid-area: 1 / 1; min-height: 186px; padding: var(--space-5);
  display: flex; flex-direction: column; justify-content: center;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
}
.tag .face.back { transform: rotateY(180deg); justify-content: flex-start; padding-top: 40px; }
.tag .face.front { margin: 0; padding: 0; }   /* the <form>; the button fills it */
.tag .reveal {
  appearance: none; -webkit-appearance: none;
  display: flex; flex-direction: column; justify-content: center; align-items: center;
  width: 100%; min-height: 186px; margin: 0; padding: var(--space-5);
  background: none; border: 0; border-radius: var(--radius-lg); color: inherit;
  font: 700 var(--text-body) / var(--leading-body) var(--font-text); cursor: pointer;
}
.tag .reveal:focus-visible { outline: 3px solid var(--spruce); outline-offset: 3px; box-shadow: 0 0 0 2px var(--paper); }
.tag .hole {
  position: absolute; top: 14px; left: 18px; width: 14px; height: 14px;
  border-radius: 50%; background: var(--paper); border: 2px solid var(--kraft-deep);
  pointer-events: none;
}
.tag .twine {
  position: absolute; top: 10px; left: 30px; width: 64px; height: 22px;
  stroke: var(--brass); stroke-width: 2; fill: none; pointer-events: none;
}
.tag .prompt { text-align: center; margin-top: var(--space-3); }
.tag .note { font-weight: 400; font-size: var(--text-small); text-align: center; margin-top: var(--space-2); }
.tag .lead { font-weight: 400; font-size: var(--text-body); }
.tag .name {
  display: block;
  font: 600 var(--text-display) / var(--leading-display) var(--font-display);
  font-optical-sizing: auto;
  margin: var(--space-2) 0 var(--space-3);
  overflow-wrap: anywhere;
}
.tag .hide { align-self: flex-end; margin-top: auto; text-decoration: none; }
.tag[data-open="false"] .face.back { visibility: hidden; }   /* keeps hidden face out of tab order */
.tag[data-open="true"] .face.front { visibility: hidden; }

/* Static open state for no-JS POST /me/reveal */
.tag-static-open {
  position: relative; display: flex; flex-direction: column; width: 100%; min-height: 186px;
  padding: 40px var(--space-5) var(--space-5);
  background: var(--kraft); color: var(--spruce);
  border: 1.5px solid var(--kraft-deep); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-tag);
}
.tag-static-open .hole {
  position: absolute; top: 14px; left: 18px; width: 14px; height: 14px;
  border-radius: 50%; background: var(--paper); border: 2px solid var(--kraft-deep);
}
.tag-static-open .twine {
  position: absolute; top: 10px; left: 30px; width: 64px; height: 22px;
  stroke: var(--brass); stroke-width: 2; fill: none;
}
.tag-static-open .lead { font-weight: 400; }
.tag-static-open .name {
  font: 600 var(--text-display) / var(--leading-display) var(--font-display);
  font-variation-settings: "opsz" 144;
  margin: var(--space-2) 0 var(--space-3);
}
.tag-static-open .hide-action { align-self: flex-end; margin-top: auto; }

.recipient-box {
  margin-top: var(--space-5);
  padding-top: var(--space-4);
  border-top: 1px solid var(--hairline);
  animation: reveal-in var(--dur-base) var(--ease-out);
}
.recipient-box[hidden] { display: none; }
.recipient-text { white-space: pre-wrap; margin-bottom: var(--space-4); }
@keyframes reveal-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

@media (prefers-reduced-motion: reduce) {
  .tag, .tag:has(.reveal:active), .tag[data-open="true"] { transform: none; transition: none; }
  .tag .face, .tag .face.back { transform: none; backface-visibility: visible; -webkit-backface-visibility: visible; }
  .recipient-box { animation: none; }
}

/* ---- Chat ---- */
.chat-page { display: flex; flex-direction: column; min-height: 100dvh; }
.chat-log { flex: 1; display: flex; flex-direction: column; gap: var(--space-2); padding-bottom: var(--space-4); }
.bubble { max-width: 85%; padding: 12px 14px; border-radius: var(--radius-sm); white-space: pre-wrap; }
.bubble.helper { align-self: flex-start; background: var(--sage); color: var(--spruce); margin-left: 20px; position: relative; }
.bubble.helper::before { content: ""; position: absolute; left: -20px; top: 16px; width: 10px; height: 10px; border-radius: 50%; background: var(--spruce-mid); }
.bubble.me { align-self: flex-end; background: var(--spruce); color: var(--on-dark); }
.bubble.helper + .bubble.me, .bubble.me + .bubble.helper { margin-top: var(--space-2); }
.bubble.helper.arrive { animation: bubble-in var(--dur-base) var(--ease-out); }
@keyframes bubble-in { from { opacity: 0; } to { opacity: 1; } }
.composer-wrap {
  position: sticky; bottom: 0;
  padding: var(--space-3) 0 calc(var(--space-3) + env(safe-area-inset-bottom));
  background: var(--paper); border-top: 1px solid var(--hairline);
}
.composer { display: flex; gap: var(--space-2); }
.composer input { flex: 1; }
.composer .btn { width: auto; padding: 0 var(--space-4); min-height: var(--input-h); }
@media (min-width: 720px) {
  .chat-page { min-height: 0; }
  .chat-log { max-height: min(70vh, 640px); overflow-y: auto; padding-right: var(--space-2); }
}

/* ---- Toast ---- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--space-5) + env(safe-area-inset-bottom));
  transform: translateX(-50%); z-index: 50;
  max-width: 90%; padding: 12px 16px;
  background: var(--spruce); color: var(--on-dark);
  border-radius: var(--radius-lg);
  font: 700 var(--text-small) / 1.3 var(--font-text);
  animation: toast-in var(--dur-base) var(--ease-out);
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---- Admin ---- */
body.admin { --gutter: var(--space-4); }
body.admin .section { margin-top: var(--space-6); }
body.admin .row { font-size: var(--text-small); }
body.admin .row-sub { font-size: var(--text-admin-small); }
body.admin h2 { font-family: var(--font-text); font-weight: 700; font-size: var(--text-body); }
.admin-grid { display: grid; gap: var(--space-3); grid-template-columns: 1fr; }
@media (min-width: 600px) {
  .admin-grid.two { grid-template-columns: 1fr 1fr; }
  .admin-grid.three { grid-template-columns: 1fr 1fr 1fr; }
}
.url-row { display: flex; gap: var(--space-2); align-items: stretch; margin: var(--space-2) 0; }
.urlfield { font-family: var(--font-mono); font-size: var(--text-small); flex: 1; }
.copy-btn { width: auto; min-height: var(--input-h); padding: 0 var(--space-4); }
.confirm-box {
  margin-top: var(--space-3);
  padding: var(--space-4);
  background: var(--linen);
  border-radius: var(--radius-sm);
}
.confirm-actions { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center; margin-top: var(--space-3); }
.testing { margin-top: var(--space-7); padding-top: var(--space-5); border-top: 3px double var(--hairline); }
details.inline-disclosure > summary {
  list-style: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  min-height: var(--tap-min);
  padding: 10px 6px;
  font-weight: 700;
  color: var(--spruce);
}
details.inline-disclosure > summary::-webkit-details-marker { display: none; }
details.inline-disclosure.danger > summary { color: var(--berry); }

/* ---- Utilities ---- */
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.stack > * + * { margin-top: var(--space-4); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mt-5 { margin-top: var(--space-5); }
