/* Flat yarn colours: navy, cranberry and mustard plus wool white (see
   DESIGN.md). Mustard fill is reserved for primary actions; mustard as *text*
   uses --color-gold, darkened for AA contrast on light grounds. */
@font-face {
  font-family: "Archivo";
  src: url("fonts/Archivo.woff2") format("woff2");
  font-weight: 600 900;
  font-display: swap;
}

:root {
  --navy: #1e2a47;
  --navy-deep: #141d33;
  --cranberry: #a3263a;
  --cranberry-deep: #86182b;
  --mustard: #e3a92a;
  --mustard-bright: #f0bf52;
  --wool: #f5f0e7;
  --badge-draft-bg: #ece6d8;
  --badge-draft-text: #6b5a1f;
  --badge-pending-bg: #eee5cf;
  --badge-pending-text: #7a5b00;
  --redact: var(--navy);

  --color-bg: var(--wool);
  --color-surface: #fffdf9;
  --color-border: #e1d7c6;
  --color-text: var(--navy);
  --color-text-muted: #59607a;
  --color-primary: var(--navy);
  --color-primary-dark: var(--navy-deep);
  --color-primary-contrast: var(--wool);
  --color-accent: var(--cranberry);
  --color-accent-contrast: #ffffff;
  --color-gold: #8a6100;
  --color-success-bg: #e6f2ea;
  --color-success-text: #1d4d33;
  --color-error-bg: #fbe7ea;
  --color-error-text: #8a1c2c;
  --color-warning-bg: #fbf0d4;
  --color-warning-text: #6b4e00;
  --radius: 12px;
  --focus-ring: 3px solid var(--navy);
  --scroll-thumb: var(--navy);
  --font-display: "Archivo", system-ui, sans-serif;

  /* The Fair Isle band: the one knitted thing, sewn under the header. */
  --fair-isle: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='46' height='46'%3E%3Crect width='46' height='46' fill='%231e2a47'/%3E%3Crect width='46' height='6' fill='%23e3a92a'/%3E%3Crect y='40' width='46' height='6' fill='%23e3a92a'/%3E%3Cpath d='M23 11 L33 23 L23 35 L13 23Z' fill='%23f5f0e7'/%3E%3Cpath d='M23 17 L28 23 L23 29 L18 23Z' fill='%23a3263a'/%3E%3Ccircle cx='3' cy='23' r='3' fill='%23f5f0e7'/%3E%3Ccircle cx='43' cy='23' r='3' fill='%23f5f0e7'/%3E%3C/svg%3E");
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #121a2d;
    --color-surface: #1b2540;
    --color-border: #2f3b5c;
    --color-text: #f1ece2;
    --color-text-muted: #b3b8ca;
    --color-primary: var(--mustard);
    --color-primary-dark: var(--mustard-bright);
    --color-primary-contrast: var(--navy-deep);
    --color-accent: #e06a7c;
    --color-accent-contrast: #1a0508;
    --color-gold: #ecc15a;
    --color-success-bg: #163324;
    --color-success-text: #b6e3c6;
    --color-error-bg: #3a1720;
    --color-error-text: #f4b6c0;
    --color-warning-bg: #3a2f12;
    --color-warning-text: #f2d58a;
    --focus-ring: 3px solid var(--mustard);
    --scroll-thumb: var(--mustard);
    --badge-draft-bg: #2f3b5c;
    --badge-draft-text: #e6dcc4;
    --badge-pending-bg: #3a2f12;
    --badge-pending-text: #f2d58a;
    /* Blacked out stays black at night - a cream bar reads as an empty field. */
    --redact: #05080f;
  }
}

* { box-sizing: border-box; }

html {
  color-scheme: light dark;
  background: var(--color-bg);
  scrollbar-color: var(--scroll-thumb) var(--color-bg);
  accent-color: var(--color-accent);
  caret-color: var(--color-accent);
}
/* The navy header always needs the mustard ring, whatever the theme. */
.site-header :focus-visible { outline-color: var(--mustard); }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.55;
}

a { color: var(--color-primary); text-underline-offset: 0.15em; }
::selection { background: var(--color-primary); color: var(--color-primary-contrast); }
a:hover { color: var(--color-primary-dark); }

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--color-primary);
  color: var(--color-primary-contrast);
  padding: 0.75rem 1rem;
  z-index: 100;
  border-radius: 0 0 var(--radius) 0;
}
.skip-link:focus {
  left: 0;
}

:focus-visible {
  outline: var(--focus-ring);
  outline-offset: 2px;
}

/* Navy header with a Fair Isle band beneath it - fixed yarn colours in both
   themes. The band is the only knitted detail on the site; used anywhere
   else it turns into fancy dress. */
.site-header {
  background-color: var(--navy);
  color: var(--wool);
  border-bottom: 34px solid transparent;
  border-image: var(--fair-isle) 0 0 46 0 / 0 0 34px 0 round;
}
.site-header .wrap {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.brand {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.25rem;
  letter-spacing: -0.01em;
  color: var(--wool);
  text-decoration: none;
}
.brand:hover { color: var(--wool); opacity: 0.9; }
.brand { display: inline-flex; align-items: center; gap: 0.5rem; }
.main-nav ul {
  list-style: none;
  display: flex;
  gap: 1.25rem;
  margin: 0;
  padding: 0;
  flex-wrap: wrap;
}
.main-nav a {
  color: var(--wool);
  text-decoration: none;
  font-weight: 500;
}
.main-nav a:hover { text-decoration: underline; }
.main-nav a[aria-current="page"] { text-decoration: underline; text-underline-offset: 3px; }

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem 1.25rem 4rem;
}

.narrow { max-width: 640px; }

h1, h2, h3 { line-height: 1.2; }
h1 { font-family: var(--font-display); font-weight: 800; font-size: clamp(1.9rem, 1.5rem + 1.6vw, 2.75rem); letter-spacing: -0.015em; }

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}
/* The card's padding is the spacing - a heading's own top margin on top of it
   left a tall empty band above every card title. */
.card > :first-child { margin-top: 0; }
.card > :last-child { margin-bottom: 0; }

.grid { display: grid; gap: 1.5rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
/* Three across at full width (never 4 + 2), one column on phones. */
.grid-features { grid-template-columns: repeat(auto-fit, minmax(min(100%, 18rem), 1fr)); margin-bottom: 1.5rem; }
.grid-features .card { margin-bottom: 0; }

.btn {
  display: inline-block;
  font: inherit;
  font-weight: 600;
  padding: 0.65rem 1.25rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
}
.btn-primary { background: var(--color-primary); color: var(--color-primary-contrast); }
.btn-primary:hover { background: var(--color-primary-dark); color: var(--color-primary-contrast); }
.btn-accent { background: var(--color-accent); color: var(--color-accent-contrast); }
.btn-secondary { background: transparent; color: var(--color-primary); border-color: var(--color-primary); }
.btn-secondary:hover { background: var(--color-bg); }
.btn-danger { background: transparent; color: var(--color-error-text); border-color: var(--color-error-text); }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.875rem; }
.btn[disabled] { opacity: 0.6; cursor: not-allowed; }

label { display: block; font-weight: 600; margin-bottom: 0.3rem; }
.field { margin-bottom: 1.1rem; }
.hint { color: var(--color-text-muted); font-size: 0.875rem; margin-top: 0.3rem; }
input:not([type]), input[type="text"], input[type="email"], input[type="password"], input[type="tel"],
input[type="number"], input[type="date"], input[type="datetime-local"], select, textarea {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-surface);
  color: var(--color-text);
  font: inherit;
}
textarea { min-height: 6rem; }
fieldset { border: 1px solid var(--color-border); border-radius: var(--radius); padding: 1rem; margin: 0 0 1.1rem; }
legend { font-weight: 700; padding: 0 0.4rem; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--color-border); }
th { color: var(--color-text-muted); font-size: 0.875rem; text-transform: uppercase; letter-spacing: 0.03em; }
.table-scroll { overflow-x: auto; }

.flash {
  padding: 0.9rem 1.1rem;
  border-radius: var(--radius);
  margin-bottom: 1.5rem;
  font-weight: 600;
}
.flash-success { background: var(--color-success-bg); color: var(--color-success-text); }
.flash-error { background: var(--color-error-bg); color: var(--color-error-text); }

.badge {
  display: inline-block;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
}
.badge-draft { background: var(--badge-draft-bg); color: var(--badge-draft-text); }
.badge-scheduled, .badge-cancelled { background: var(--badge-pending-bg); color: var(--badge-pending-text); }
.badge-sent { background: var(--color-success-bg); color: var(--color-success-text); }
.badge-delivered { background: var(--color-success-bg); color: var(--color-success-text); }
.badge-failed { background: var(--color-error-bg); color: var(--color-error-text); }
.badge-pending { background: var(--badge-pending-bg); color: var(--badge-pending-text); }

.price { font-weight: 700; color: var(--color-gold); font-variant-numeric: tabular-nums; }
/* Price lists: the price sits beside its description, and drops beneath it
   (right-aligned) when there isn't room - rather than squeezing the
   description into a narrow column on phones. */
.price-table tr { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 0.15rem 1.5rem; padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--color-border); }
.price-table td { padding: 0; border: 0; }
.price-table td:first-child { flex: 1 1 0; min-width: 0; }
.price-table td.price { flex: 0 0 auto; margin-left: auto; white-space: nowrap; }
.price-lg { font-size: 1.5rem; }

.cta { text-align: center; }

.stat {
  text-align: center;
}
.stat .n { display: block; font-size: 1.5rem; font-weight: 800; color: var(--color-primary); }
.stat .l { color: var(--color-text-muted); font-size: 0.875rem; }

.trend-chart {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 90px;
  border-bottom: 1px solid var(--color-border);
}
.trend-chart .bar {
  flex: 1;
  background: var(--color-accent);
  border-radius: 2px 2px 0 0;
  min-height: 1px;
}

.countdown {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.countdown .unit {
  background: var(--navy);
  color: var(--wool);
  border-radius: var(--radius);
  padding: 0.6rem 0.9rem;
  min-width: 4.5rem;
  text-align: center;
}
.countdown .unit .n { display: block; font-size: 1.5rem; font-weight: 800; }
.countdown .unit .l { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; }

.site-footer {
  border-top: 1px solid var(--color-border);
  padding: 2rem 1.25rem;
  color: var(--color-text-muted);
  font-size: 0.875rem;
}
.site-footer .wrap { max-width: 1100px; margin: 0 auto; display: flex; justify-content: space-between; flex-wrap: wrap; gap: 1rem; }
.site-footer a { color: var(--color-text-muted); }
.site-footer .legal { flex-basis: 100%; margin: 0; font-size: 0.75rem; }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

@media (max-width: 640px) {
  .main-nav ul { gap: 0.85rem; }
}

.rule-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.4rem 0; border-bottom: 1px solid var(--color-border); }
.rule-row form { margin: 0; }
.check-list { display: flex; flex-wrap: wrap; gap: 0.25rem 1.25rem; margin-bottom: 0.75rem; }
.pair-rule { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.75rem; }
.pair-rule select { width: auto; flex: 1 1 8rem; }
.disclosure { margin: 0 0 1.1rem; }
.disclosure summary { cursor: pointer; color: var(--color-text-muted); }
.disclosure[open] summary { margin-bottom: 0.75rem; }
.code-input { text-transform: uppercase; }
.draw-details { margin: 0.5rem 0 1rem; }
.draw-details summary { cursor: pointer; color: var(--color-text-muted); }
.draw-details form { margin-top: 0.75rem; max-width: 28rem; }
/* Buttons that wrap on narrow screens keep a gap between rows, not just columns. */
.btn-row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem; }
.btn-row-center { justify-content: center; }
.btn-row-tight { gap: 0.4rem; }

/* A table that becomes one block per row on phones, so nothing - least of
   all a row's actions - ends up off the edge of the card. */
@media (max-width: 640px) {
  .stack-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .stack-table, .stack-table tbody, .stack-table tr, .stack-table td { display: block; }
  .stack-table tr { padding: 0.9rem 0; border-bottom: 1px solid var(--color-border); }
  .stack-table tr:last-child { border-bottom: 0; }
  .stack-table td { border: 0; padding: 0.15rem 0; }
  .stack-table .stack-title { font-weight: 700; font-size: 1.15rem; }
  .stack-table td[data-label]::before { content: attr(data-label) ": "; color: var(--color-text-muted); }
  .stack-table td:last-child { padding-top: 0.6rem; }
}

/* Flash messages after an in-place update (see initAjaxPage in app.js). */
.toast { position: fixed; left: 50%; bottom: 1.25rem; transform: translateX(-50%); z-index: 100; max-width: min(32rem, calc(100% - 2rem)); box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18); }
form[aria-busy="true"] { opacity: 0.6; }

.flash-warning, .badge-warning { background: var(--color-warning-bg); color: var(--color-warning-text); }
.hint-warning { color: var(--color-warning-text); font-weight: 600; }

/* Scheduling a draw sits under its "Send draw now" button. */
.schedule-form { margin-top: 1.25rem; padding-top: 1.25rem; border-top: 1px solid var(--color-border); }
.schedule-form input[type="datetime-local"] { width: auto; flex: 1 1 14rem; }
.scheduled-at { font-family: var(--font-display); font-weight: 800; font-size: 1.5rem; margin: 0 0 0.75rem; }

/* ---- Long-form pages (pricing, scrooge rules, support) -------------------
   Read like a page, not a dashboard: one column at a reading width, sections
   divided by a hairline, never a grid of cards. */
.doc { max-width: 44rem; }
.doc h1 { font-size: clamp(2.4rem, 1.6rem + 3vw, 3.5rem); line-height: 1; margin: 0.5rem 0 1rem; }
.doc-lede { font-size: 1.25rem; line-height: 1.5; margin: 0 0 2rem; }
.doc section { border-top: 1px solid var(--color-border); padding: 1.75rem 0; }
.doc section h2 { font-family: var(--font-display); font-weight: 800; font-size: 1.5rem; letter-spacing: -0.015em; line-height: 1.15; margin: 0 0 0.6rem; }
.doc section p { margin: 0 0 0.75rem; }
.doc section > :last-child { margin-bottom: 0; }
.doc .example { color: var(--color-text-muted); }
.doc .example strong { color: var(--color-text); }
.doc .price-table { margin-bottom: 1rem; }
.doc .price-table tr { padding-inline: 0; }
.examples { margin: 0; }
.examples dt { font-weight: 700; margin-top: 1rem; }
.examples dt:first-child { margin-top: 0; }
.examples dd { margin: 0.2rem 0 0; font-variant-numeric: tabular-nums; }
.doc-end { padding-top: 2rem; }

/* ---- Home page -------------------------------------------------------- */
/* The hero breaks out of <main>'s column to full width; its side padding puts
   the content back on the same column as everything else. */
body { overflow-x: clip; }
.hero, .santa {
  margin-inline: calc(50% - 50vw);
  padding: 3.5rem max(1.25rem, calc(50vw - 550px + 1.25rem));
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 0.75fr);
  gap: 3.5rem;
  align-items: center;
}
.hero { margin-top: -2rem; background: var(--cranberry); color: var(--wool); }
.hero h1 { font-size: clamp(2.6rem, 1.6rem + 3.6vw, 4.5rem); line-height: 0.98; letter-spacing: -0.025em; margin: 0 0 1.25rem; color: inherit; text-wrap: balance; }
.hero .lede { font-size: 1.25rem; line-height: 1.5; max-width: 33rem; margin: 0 0 2rem; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 1rem 1.5rem; }
.hero-price { font-size: 0.875rem; margin: 0.5rem 0 0; opacity: 0.9; }
.hero :focus-visible, .santa :focus-visible { outline-color: var(--mustard); }

.btn-yarn { background: var(--mustard); color: var(--navy); font-size: 1rem; padding: 0.8rem 1.4rem; }
.btn-yarn:hover { background: var(--mustard-bright); color: var(--navy); }
.btn-wool { background: var(--wool); color: var(--navy); font-size: 1rem; padding: 0.8rem 1.4rem; }
.btn-wool:hover { background: #ffffff; color: var(--navy); }

/* A messages-app thread from "Santa" (templates/_sms.twig). */
.thread { margin: 0; background: var(--color-surface); color: var(--color-text); border-radius: 18px; padding: 0 0 0.9rem; box-shadow: 0 10px 28px rgba(20, 8, 12, 0.25); max-width: 24rem; justify-self: end; width: 100%; }
.thread-head { text-align: center; font-weight: 700; padding: 0.8rem 1.1rem; border-bottom: 1px solid var(--color-border); }
.thread-noreply { font-size: 0.75rem; color: var(--color-text-muted); text-align: center; margin: 1.1rem 1.1rem 0; padding-top: 0.8rem; border-top: 1px solid var(--color-border); }
.thread-messages { list-style: none; margin: 0; padding: 0.4rem 1.1rem 0; }
.thread-messages time { display: block; text-align: center; font-size: 0.75rem; color: var(--color-text-muted); margin: 0.9rem 0 0.45rem; }
.sms-bubble { margin: 0; background: var(--color-bg); color: var(--color-text); border-radius: 1.1rem 1.1rem 1.1rem 0.3rem; padding: 0.7rem 0.95rem; max-width: 88%; white-space: pre-line; }
.thread figcaption { font-size: 0.75rem; color: var(--color-text-muted); text-align: center; margin-top: 0.4rem; }
/* The texts arrive one after another when the thread scrolls into view
   (initArrivingTexts in app.js). Without JS, or with reduced motion, they're just there. */
@media (prefers-reduced-motion: no-preference) {
  .js .thread:not(.is-arriving) .thread-messages li { opacity: 0; }
  .thread.is-arriving .thread-messages li { animation: text-arrives 0.6s cubic-bezier(0.16, 1, 0.3, 1) backwards; }
  .thread.is-arriving .thread-messages li:nth-child(1) { animation-delay: 0.25s; }
  .thread.is-arriving .thread-messages li:nth-child(2) { animation-delay: 1.1s; }
}
@keyframes text-arrives { from { opacity: 0; transform: translateY(10px); } }

.secret { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 3.5rem; align-items: center; padding: 4.5rem 0 3.5rem; border-bottom: 1px solid var(--color-border); }
.secret h2, .how h2, .santa h2 { font-family: var(--font-display); font-weight: 800; font-size: clamp(1.9rem, 1.4rem + 2vw, 2.75rem); letter-spacing: -0.02em; line-height: 1.05; margin: 0 0 1rem; text-wrap: balance; }
.secret-copy .hint { font-size: 1rem; max-width: 30rem; }
.pairings { list-style: none; margin: 0; padding: 0; font-size: 1.15rem; }
.pairings li { display: flex; align-items: center; gap: 0.9rem; padding: 0.85rem 0; border-bottom: 1px solid var(--color-border); }
.pairings li:first-child { border-top: 1px solid var(--color-border); }
.pairings li > span:first-child { font-weight: 700; min-width: 4rem; }
.pairings li > span:nth-child(2) { color: var(--color-text-muted); }
/* The secret: a blacked-out name, like a redacted document. */
.redacted { display: inline-block; width: var(--w, 4rem); height: 1.1em; border-radius: 2px; background: var(--redact); box-shadow: inset 0 0 0 1px var(--color-border); }

.how { padding: 3.5rem 0 4.5rem; max-width: 44rem; }
.how p { font-size: 1.15rem; line-height: 1.6; margin: 0 0 1.5rem; }

.santa { background: var(--navy); color: var(--wool); grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr); margin-bottom: -4rem; }
.santa h2 { color: inherit; }
.santa p { font-size: 1.15rem; max-width: 32rem; }
.santa .hero-price { font-size: 0.875rem; }
.santa .hero-price a { color: inherit; }
/* Christmas morning, as the phone shows it: the time, then Santa's message. */
.lockscreen { text-align: center; padding: 1rem 0; margin: 0; }
.santa .lock-time { max-width: none; font-family: var(--font-display); font-weight: 600; font-size: clamp(4rem, 2.5rem + 6vw, 7rem); line-height: 1; letter-spacing: -0.03em; margin: 0; }
.santa .lock-date { max-width: none; margin: 0.4rem 0 1.75rem; font-size: 1rem; opacity: 0.85; }
.lock-note { text-align: left; background: var(--wool); color: var(--navy); border-radius: 18px; padding: 0.9rem 1.1rem; max-width: 22rem; margin: 0 auto; box-shadow: 0 10px 28px rgba(5, 8, 15, 0.35); }
.santa .lock-note p { margin: 0; font-size: 1rem; }
.santa .lock-note .lock-note-head { display: flex; justify-content: space-between; margin-bottom: 0.2rem; font-size: 0.875rem; }
.lock-note-head span { color: var(--color-text-muted); }
.santa .lock-caption { font-size: 0.75rem; opacity: 0.75; margin-top: 0.75rem; }

@media (max-width: 860px) {
  .hero, .santa { grid-template-columns: 1fr; gap: 2.5rem; padding-block: 2.75rem; }
  .thread { justify-self: start; }
  .secret { grid-template-columns: 1fr; gap: 2rem; }
  .santa { grid-template-columns: 1fr; }
}
