/*
  Founder's Table Grant Planner — visual direction (brief §8.5): a working document,
  not a course player. Two voices (display serif for numbering/titles, quiet sans
  for reading/writing), generous worksheet-style fields, one bold element (the
  progress bar), everything else restrained. No CDN fonts — robust system stacks.
*/

*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --font-display: Georgia, 'Iowan Old Style', 'Palatino Linotype', 'Book Antiqua', serif;
  --font-body: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;

  /* Modular type scale, ratio ~1.25 */
  --step--1: 0.85rem;
  --step-0: 1rem;
  --step-1: 1.25rem;
  --step-2: 1.563rem;
  --step-3: 1.953rem;
  --step-4: 2.441rem;
  --step-5: 3.052rem;

  --color-paper: #faf7f1;
  --color-paper-raised: #ffffff;
  --color-ink: #232019;
  --color-ink-muted: #5c5548;
  --color-border: #d9d0c1;
  --color-border-strong: #b9ac95;
  --color-accent: #a3402a;
  --color-accent-dark: #7c2f1f;
  --color-accent-contrast: #fff8f2;
  --color-success: #3f6b4a;
  --color-error: #a12626;
  --color-error-bg: #fbebe9;
  --color-focus: #1f5f7a;

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 3rem;
  --space-8: 4rem;

  --radius: 6px;
  --radius-lg: 10px;
  --measure: 38em;
  --transition-fast: 150ms ease;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--color-paper);
  color: var(--color-ink);
  font-family: var(--font-body);
  font-size: var(--step-0);
  line-height: 1.6;
  overflow-x: hidden;
}

/* Space reserved so the sticky progress bar can never cover the last field
   (acceptance criterion: bar never covers the last question at 360px). The bar's
   real height varies a little with text wrap, so this is deliberately generous
   rather than measured — a little extra whitespace is a fine trade for certainty. */
body.has-progressbar {
  padding-bottom: calc(150px + env(safe-area-inset-bottom));
}

@media (max-width: 480px) {
  body.has-progressbar {
    padding-bottom: calc(190px + env(safe-area-inset-bottom));
  }
}

img {
  max-width: 100%;
  display: block;
}

a {
  color: var(--color-accent-dark);
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--color-ink);
  color: #fff;
  padding: var(--space-2) var(--space-4);
  z-index: 1000;
}

.skip-link:focus {
  left: var(--space-3);
  top: var(--space-3);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

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

/* ---------- Layout shell ---------- */

.site-header {
  border-bottom: 1px solid var(--color-border);
  background: var(--color-paper-raised);
}

.site-header__inner,
.site-footer__inner {
  max-width: 46rem;
  margin: 0 auto;
  padding: var(--space-4) var(--space-5);
}

.site-header__brand {
  font-family: var(--font-display);
  font-size: var(--step-1);
  font-weight: 700;
  text-decoration: none;
  color: var(--color-ink);
}

.site-header__brand span {
  color: var(--color-accent);
}

.site-main {
  max-width: 46rem;
  margin: 0 auto;
  padding: var(--space-6) var(--space-5) var(--space-8);
}

.site-footer {
  border-top: 1px solid var(--color-border);
  color: var(--color-ink-muted);
  font-size: var(--step--1);
}

.site-footer a {
  color: var(--color-ink-muted);
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 44px;
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-lg);
  border: 1px solid transparent;
  font-family: var(--font-body);
  font-size: var(--step-0);
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background-color var(--transition-fast), border-color var(--transition-fast), transform var(--transition-fast);
}

.btn--primary {
  background: var(--color-accent);
  color: var(--color-accent-contrast);
}

.btn--primary:hover {
  background: var(--color-accent-dark);
}

.btn--secondary {
  background: transparent;
  border-color: var(--color-border-strong);
  color: var(--color-ink);
}

.btn--secondary:hover {
  border-color: var(--color-accent);
  color: var(--color-accent-dark);
}

@media (prefers-reduced-motion: no-preference) {
  .btn--primary:active {
    transform: translateY(1px);
  }
}

/* ---------- Chapter header ---------- */

.chapter__header-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
}

.chapter__eyebrow {
  font-family: var(--font-display);
  font-size: var(--step-1);
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--color-accent-dark);
  margin: 0;
}

.chapter__title {
  font-family: var(--font-display);
  font-size: var(--step-4);
  line-height: 1.15;
  margin: var(--space-2) 0 var(--space-3);
}

.chapter__summary {
  font-size: var(--step-1);
  color: var(--color-ink-muted);
  max-width: var(--measure);
  margin: 0 0 var(--space-2);
}

.chapter__meta {
  color: var(--color-ink-muted);
  font-size: var(--step--1);
  margin: 0 0 var(--space-6);
}

.chapter__body {
  max-width: var(--measure);
  font-size: var(--step-0);
  margin-bottom: var(--space-6);
}

/* ---------- Video ---------- */

.video-embed {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #14110d;
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: var(--space-6);
}

.video-embed__facade {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  padding: 0;
  margin: 0;
  cursor: pointer;
  background: #14110d;
}

.video-embed__poster {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.85;
}

.video-embed__play {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--color-accent-contrast);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
}

.video-embed__play::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 55%;
  transform: translate(-50%, -50%);
  border-style: solid;
  border-width: 12px 0 12px 20px;
  border-color: transparent transparent transparent var(--color-accent-dark);
}

.video-embed__iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

.video-embed__unsupported {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  padding: var(--space-4);
  text-align: center;
}

.video-embed__transcript {
  margin: calc(-1 * var(--space-4)) 0 var(--space-6);
  font-size: var(--step--1);
}

/* ---------- Resources ---------- */

.resources {
  margin-bottom: var(--space-7);
}

.resources__heading {
  font-family: var(--font-display);
  font-size: var(--step-1);
  margin: 0 0 var(--space-4);
}

.resources__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.resources__item {
  border-left: 3px solid var(--color-border-strong);
  background: var(--color-paper-raised);
  border-radius: 0 var(--radius) var(--radius) 0;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.resources__item:has(.resources__link:hover) {
  background: var(--color-paper);
  border-left-color: var(--color-accent);
}

/* The whole box is one link (label, type badge, and description) — clicking
   anywhere in it opens the resource, not just the label text. */
.resources__link {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  text-decoration: none;
  padding: var(--space-2) var(--space-4);
  min-height: 44px;
}

.resources__link-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
}

.resources__link:hover .resources__label {
  color: var(--color-accent-dark);
  text-decoration: underline;
}

.resources__label {
  color: var(--color-ink);
  font-weight: 600;
}

.resources__type {
  flex-shrink: 0;
  font-size: var(--step--1);
  letter-spacing: 0.04em;
  color: var(--color-ink-muted);
}

.resources__desc {
  margin: 0;
  color: var(--color-ink-muted);
  font-size: var(--step--1);
  max-width: var(--measure);
}

/* ---------- Response form / worksheet fields ---------- */

.response-section__heading {
  font-family: var(--font-display);
  font-size: var(--step-2);
  margin: 0 0 var(--space-5);
}

.response-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}

.field {
  max-width: var(--measure);
}

.field__label {
  display: block;
  font-weight: 700;
  font-size: var(--step-0);
  margin-bottom: var(--space-2);
  padding: 0;
}

.field__required {
  color: var(--color-accent-dark);
}

.field__optional {
  font-weight: 400;
  color: var(--color-ink-muted);
}

.field__help {
  margin: 0 0 var(--space-2);
  color: var(--color-ink-muted);
  font-size: var(--step--1);
}

.field__error {
  margin: 0 0 var(--space-2);
  color: var(--color-error);
  background: var(--color-error-bg);
  border: 1px solid var(--color-error);
  border-radius: var(--radius);
  padding: var(--space-2) var(--space-3);
  font-size: var(--step--1);
  font-weight: 600;
}

.field--invalid .field__control,
.field--invalid .field__fieldset {
  border-color: var(--color-error);
}

.field__control {
  width: 100%;
  font-family: var(--font-body);
  font-size: var(--step-0);
  line-height: 1.6;
  color: var(--color-ink);
  background: var(--color-paper-raised);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
  min-height: 44px;
}

.field__control:focus-visible {
  border-color: var(--color-focus);
}

.field__control--textarea {
  resize: vertical;
  min-height: 8rem;
}

.field__counter {
  margin: var(--space-1) 0 0;
  text-align: right;
  font-size: var(--step--1);
  color: var(--color-ink-muted);
}

.field__counter[data-counter-met="true"] {
  color: var(--color-success);
}

.field__fieldset {
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius);
  padding: var(--space-4);
  margin: 0;
}

.field__fieldset legend.field__label {
  padding: 0 var(--space-1);
  margin-left: calc(-1 * var(--space-1));
}

.field__options--stacked {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.field__options--scale {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.field__option {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 44px;
  padding: var(--space-2) var(--space-2);
  cursor: pointer;
  border-radius: var(--radius);
}

.field__options--scale .field__option {
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  text-align: center;
  min-width: 4.5rem;
}

.field__option:hover {
  background: var(--color-paper);
}

.field__option input {
  width: 22px;
  height: 22px;
  accent-color: var(--color-accent);
  flex-shrink: 0;
}

.field__option-label {
  font-size: var(--step-0);
}

.field__options--scale .field__option-label {
  font-size: var(--step--1);
  color: var(--color-ink-muted);
}

.response-form__actions {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  flex-wrap: wrap;
}

/* ---------- Invitation block (preview mode) ---------- */

.invite-block {
  max-width: var(--measure);
  background: var(--color-paper-raised);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
}

.invite-block h2 {
  font-family: var(--font-display);
  font-size: var(--step-2);
  margin-top: 0;
}

/* ---------- Share sheet ---------- */

.share {
  position: relative;
}

.share__trigger {
  background: transparent;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-lg);
  padding: var(--space-2) var(--space-4);
  min-height: 44px;
  font-family: var(--font-body);
  font-weight: 600;
  cursor: pointer;
}

.share__trigger:hover {
  border-color: var(--color-accent);
  color: var(--color-accent-dark);
}

.share__sheet {
  position: absolute;
  right: 0;
  top: calc(100% + var(--space-2));
  z-index: 20;
  width: min(320px, 90vw);
  background: var(--color-paper-raised);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

/* The `display: flex` above wins over the browser's default [hidden] {
   display: none } (author rules always beat user-agent rules regardless of
   specificity), so without this the sheet never actually hides — the X
   button's `sheet.hidden = true` had no visible effect. */
.share__sheet[hidden] {
  display: none;
}

.share__close {
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  font-size: var(--step-1);
  cursor: pointer;
  color: var(--color-ink-muted);
}

.share__title {
  font-family: var(--font-display);
  font-size: var(--step-1);
  margin: 0 0 var(--space-1);
}

.share__option {
  display: block;
  width: 100%;
  text-align: left;
  min-height: 44px;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-paper);
  font-family: var(--font-body);
  font-size: var(--step-0);
  cursor: pointer;
  text-decoration: none;
  color: var(--color-ink);
}

.share__option:hover {
  border-color: var(--color-accent);
}

.share__option[data-copied="true"] {
  border-color: var(--color-success);
  color: var(--color-success);
}

.share__email-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  border-top: 1px solid var(--color-border);
  padding-top: var(--space-3);
}

.share__email-title {
  margin: 0;
  font-weight: 700;
  font-size: var(--step--1);
}

.share__email-label {
  font-size: var(--step--1);
  color: var(--color-ink-muted);
}

.share__email-form input {
  min-height: 44px;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: var(--step-0);
}

.share__email-status {
  margin: 0;
  font-size: var(--step--1);
  color: var(--color-ink-muted);
  min-height: 1.2em;
}

/* ---------- Start page ---------- */

.start {
  max-width: var(--measure);
}

.start__eyebrow {
  font-family: var(--font-display);
  color: var(--color-accent-dark);
  font-weight: 700;
  margin: 0;
}

.start__title {
  font-family: var(--font-display);
  font-size: var(--step-4);
  line-height: 1.2;
  margin: var(--space-2) 0 var(--space-4);
}

.start__lede {
  font-size: var(--step-1);
  color: var(--color-ink-muted);
  margin-bottom: var(--space-6);
}

.start__form {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

.start__consent {
  font-size: var(--step--1);
  color: var(--color-ink-muted);
  margin: 0;
}

/* ---------- Summary page ---------- */

.summary__eyebrow {
  font-family: var(--font-display);
  color: var(--color-accent-dark);
  font-weight: 700;
  margin: 0;
}

.summary__title {
  font-family: var(--font-display);
  font-size: var(--step-4);
  margin: var(--space-2) 0 var(--space-3);
}

.summary__lede {
  color: var(--color-ink-muted);
  max-width: var(--measure);
  margin-bottom: var(--space-7);
}

.summary__chapter {
  border-top: 1px solid var(--color-border);
  padding: var(--space-5) 0;
}

.summary__chapter-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
  margin-bottom: var(--space-4);
}

.summary__chapter-eyebrow {
  font-family: var(--font-display);
  font-size: var(--step--1);
  color: var(--color-accent-dark);
  font-weight: 700;
  margin: 0;
}

.summary__chapter-title {
  font-family: var(--font-display);
  font-size: var(--step-2);
  margin: var(--space-1) 0 0;
}

.summary__edit-link {
  font-size: var(--step--1);
  font-weight: 600;
  white-space: nowrap;
}

.summary__qa {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  max-width: var(--measure);
}

.summary__qa-item {
  margin: 0;
}

.summary__question {
  font-weight: 700;
  margin-bottom: var(--space-1);
}

.summary__answer {
  margin: 0;
  color: var(--color-ink);
}

.summary__answer--empty {
  color: var(--color-ink-muted);
  font-style: italic;
}

.summary__submit-form {
  margin-top: var(--space-7);
  padding-top: var(--space-6);
  border-top: 2px solid var(--color-border-strong);
}

.summary__submit-note {
  max-width: var(--measure);
  color: var(--color-ink-muted);
  margin-bottom: var(--space-4);
}

.summary__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-5);
  flex-wrap: wrap;
  margin-bottom: var(--space-7);
}

.summary__print-btn {
  flex: none;
  white-space: nowrap;
}

.summary__print-heading {
  display: none;
}

/* ---------- Print / "Download as PDF" ----------
   .summary__print-btn triggers window.print() (planner.js); this is the whole
   "download as PDF" mechanism — no server-side PDF generation, the browser's
   own print-to-PDF does the work. These rules strip everything but the report
   itself out of that output. */
.print-only {
  display: none;
}

@media print {
  .no-print {
    display: none !important;
  }

  .print-only {
    display: block;
  }

  body {
    background: #fff;
  }

  .site-header,
  .site-footer,
  .progressbar {
    display: none !important;
  }

  .summary {
    max-width: none;
    padding: 0;
  }

  .summary__chapter {
    break-inside: avoid;
    border-top-color: #000;
  }

  .summary__answer {
    color: #000;
  }
}

/* ---------- Progress bar (the signature element) ---------- */

.progressbar {
  position: sticky;
  bottom: 0;
  z-index: 30;
  background: var(--color-paper-raised);
  border-top: 2px solid var(--color-ink);
  box-shadow: 0 -6px 20px rgba(0, 0, 0, 0.08);
  padding: var(--space-4) var(--space-5) calc(var(--space-3) + env(safe-area-inset-bottom));
}

.progressbar__track {
  position: relative;
  height: 40px;
  margin-bottom: var(--space-2);
}

/* Static full-width base line, painted first so the fill (next in the cascade)
   and the pips (later in the DOM) naturally layer on top — no z-index needed. */
.progressbar__track::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  transform: translateY(-50%);
  height: 6px;
  background: var(--color-border);
  border-radius: 999px;
}

.progressbar__fill {
  position: absolute;
  top: 50%;
  left: 0;
  transform: translateY(-50%);
  height: 6px;
  background: var(--color-accent);
  border-radius: 999px;
  transition: width var(--transition-fast);
}

.progressbar__pips {
  position: relative;
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 100%;
}

.progressbar__pip {
  display: flex;
  align-items: center;
  justify-content: center;
}

.progressbar__pip-link {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
}

.progressbar__pip-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 3px solid var(--color-border-strong);
  background: var(--color-paper-raised);
  transition: background-color var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.progressbar__pip--completed .progressbar__pip-dot {
  background: var(--color-accent);
  border-color: var(--color-accent);
}

.progressbar__pip--current .progressbar__pip-dot {
  background: var(--color-paper-raised);
  border-color: var(--color-accent);
  box-shadow: 0 0 0 4px rgba(163, 64, 42, 0.18);
}

.progressbar__pip--locked .progressbar__pip-dot {
  background: var(--color-paper-raised);
  border-color: var(--color-border);
}

.progressbar__pip-link:focus-visible {
  outline: 3px solid var(--color-focus);
  outline-offset: 3px;
}

.progressbar__status {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.progressbar__label {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--step-0);
}

.progressbar__save-state {
  font-size: var(--step--1);
  color: var(--color-ink-muted);
  text-align: right;
}

@media (max-width: 480px) {
  .progressbar__pip-link,
  .progressbar__pip {
    width: 28px;
    height: 28px;
  }

  .progressbar__status {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-1);
  }

  .progressbar__save-state {
    text-align: left;
  }
}

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  * {
    transition-duration: 0.001ms !important;
    animation-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
