/* ---------- Tokens ---------- */
:root {
  color-scheme: light;

  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-soft: #f3f6fa;
  --ink: #050a16;
  --muted: #2e3644;
  --accent: #0b3fb3;
  --accent-soft: rgba(11, 63, 179, 0.07);
  --accent-line: rgba(11, 63, 179, 0.45);
  --border: rgba(5, 10, 22, 0.16);
  --shadow: 0 20px 44px rgba(11, 30, 80, 0.12);
  --shadow-soft: 0 10px 24px rgba(11, 30, 80, 0.07);
  --backdrop: rgba(5, 10, 22, 0.4);
  --nuiteq: #483c68;

  --radius-lg: 16px;
  --radius-sm: 10px;
  --space-1: 8px;
  --space-2: 16px;
  --space-3: 24px;
  --space-4: 36px;
  --space-6: 72px;
  --content-font: "Sora", "Helvetica Neue", sans-serif;
  --mono-font: "SFMono-Regular", "JetBrains Mono", "Fira Mono", "Menlo", "Consolas", "Liberation Mono", monospace;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

/* ---------- Base ---------- */
* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  font-family: var(--content-font);
  background: var(--bg);
  color: var(--ink);
  margin: 0;
  padding: 48px 20px 96px;
  line-height: 1.65;
  min-height: 100dvh;
}

.shell {
  width: min(960px, 100%);
  margin: 0 auto;
}

.section {
  margin: var(--space-6) 0;
}

.hero {
  margin-top: var(--space-2);
}

.hero p {
  font-size: 1.05rem;
  max-width: 60ch;
}

h1 {
  font-family: var(--content-font);
  font-weight: 600;
  letter-spacing: -0.01em;
  font-size: clamp(2.8rem, 6vw, 4.6rem);
  line-height: 1.05;
  margin: 0 0 var(--space-2);
}

h3 {
  font-size: 0.85rem;
  color: var(--muted);
  padding-top: var(--space-2);
  margin: 0 0 var(--space-2);
  border-top: 1px solid var(--border);
}

h4 {
  font-size: clamp(1.2rem, 2.2vw, 1.6rem);
  line-height: 1.3;
  margin: var(--space-3) 0 var(--space-1);
  color: var(--ink);
}

.section > h4:first-of-type {
  margin-top: 0;
  margin-bottom: var(--space-2);
}

p {
  font-size: 1rem;
  color: var(--muted);
  margin: 0 0 var(--space-2);
  max-width: 70ch;
}

ul {
  margin: 0 0 var(--space-3);
  padding-left: 1.2rem;
  color: var(--muted);
}

li {
  margin-bottom: 10px;
}

a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid var(--accent-line);
  transition: color 0.2s ease, border-color 0.2s ease;
}

a:hover {
  color: var(--ink);
  border-bottom-color: var(--ink);
}

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

[data-type="name"] {
  color: var(--accent);
}

.reset-m {
  margin: 0;
}

/* ---------- Gratitude button + dialog ---------- */
.gratitude-button {
  position: fixed;
  top: 20px;
  right: 20px;
  width: 44px;
  height: 44px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-soft);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 5;
  transition: border-color 0.2s ease, transform 0.2s var(--ease-out);
}

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

.gratitude-button:active {
  transform: scale(0.96);
}

.gratitude-button svg {
  width: 20px;
  height: 20px;
  fill: var(--accent);
}

button[name="close"] {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  width: 36px;
  height: 36px;
  border-radius: 999px;
  position: absolute;
  top: 18px;
  right: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

button[name="close"]:hover {
  border-color: var(--accent);
}

button[name="close"] svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  fill: none;
}

dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  padding-right: calc(var(--space-4) + 36px);
  width: min(640px, 90vw);
  box-shadow: var(--shadow);
  background: var(--surface);
  color: var(--ink);
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

dialog::backdrop {
  background: var(--backdrop);
  backdrop-filter: blur(6px);
}

/* ---------- Remaining funds ---------- */
.fund-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-3) var(--space-4);
  display: inline-flex;
  align-items: center;
  box-shadow: var(--shadow);
}

.fund-card + p {
  margin-top: var(--space-3);
}

.fund-card h1 {
  font-size: clamp(2rem, 4vw, 3rem);
  letter-spacing: 0.02em;
  margin: 0;
}

.funds {
  font-family: var(--mono-font);
  font-variant-numeric: tabular-nums;
}

/* ---------- Previous years ---------- */
.year-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--space-2);
}

.year-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-2);
  background: var(--surface);
  display: block;
  color: inherit;
  transition: transform 0.25s var(--ease-out), box-shadow 0.25s var(--ease-out), border-color 0.2s ease;
}

.year-card h3 {
  border-top: 0;
  padding-top: 0;
  margin-bottom: var(--space-1);
  color: var(--ink);
  font-size: 1.4rem;
}

/* Shared year number: hug the text so the morph scales evenly,
   and use the same weight/tracking on both pages. */
.year-title {
  width: fit-content;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.year-card:hover {
  color: inherit;
  transform: translateY(-3px);
  border-color: var(--accent-line);
  box-shadow: var(--shadow-soft);
}

.year-card:active {
  transform: translateY(-1px);
}

.know-more {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--muted);
  margin: 0;
  font-variant-numeric: tabular-nums;
}

/* A year inside running text that morphs into the year page heading.
   inline-block keeps it one box (a line-wrapped inline can't be captured). */
.year-inline {
  display: inline-block;
}

/* ---------- Eligible causes ---------- */
.cause-list {
  list-style: none;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr;
  column-gap: var(--space-4);
}

.cause-list li {
  margin: 0;
  padding: 12px 0;
  border-top: 1px solid var(--border);
}

@media (min-width: 720px) {
  .cause-list {
    grid-template-columns: 1fr 1fr;
  }
}

/* ---------- Year pages ---------- */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 16px;
  color: var(--ink);
  font-size: 0.9rem;
  letter-spacing: 0.02em;
  margin-bottom: 0.75rem;
}

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

.year-totals {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: var(--space-2);
  margin: 0 0 var(--space-4);
}

.year-total-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-2);
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

.year-total-card h4 {
  margin: 0 0 6px;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--muted);
}

.year-total-amount {
  margin: 0;
  color: var(--ink);
  font-size: clamp(1.2rem, 3vw, 1.9rem);
  line-height: 1.3;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.year-total-card--accent {
  border-color: var(--accent-line);
  background: linear-gradient(155deg, var(--accent-soft), var(--surface) 70%);
}

.year-total-card--accent .year-total-amount {
  color: var(--accent);
}

.nuiteq-mark {
  color: var(--nuiteq);
  font-family: "Montserrat", "Sora", "Helvetica Neue", sans-serif;
}

.table-wrap {
  margin: 0 0 var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow-x: auto;
  background: var(--surface);
}

.initiative-table {
  width: 100%;
  border-collapse: collapse;
  color: var(--muted);
  font-size: 0.96rem;
}

.initiative-table th,
.initiative-table td {
  padding: 12px 16px;
  text-align: left;
  vertical-align: top;
}

.initiative-table tbody tr + tr td {
  border-top: 1px solid var(--border);
}

.initiative-table tbody tr:hover td {
  background: var(--accent-soft);
}

.initiative-table th {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink);
  background: var(--surface-soft);
  border-bottom: 1px solid var(--border);
}

.initiative-table th:last-child,
.initiative-table .amount {
  text-align: right;
}

.initiative-table .amount {
  width: 1%;
  white-space: nowrap;
  color: var(--ink);
  font-family: var(--mono-font);
  font-variant-numeric: tabular-nums;
}

/* ---------- Motion (only when the user allows it) ---------- */
@media (prefers-reduced-motion: no-preference) {
  .section {
    opacity: 0;
    transform: translateY(14px);
    animation: rise 0.7s var(--ease-out) forwards;
  }

  main > .section:nth-of-type(1) { animation-delay: 0.04s; }
  main > .section:nth-of-type(2) { animation-delay: 0.1s; }
  main > .section:nth-of-type(3) { animation-delay: 0.16s; }
  main > .section:nth-of-type(4) { animation-delay: 0.22s; }
  main > .section:nth-of-type(n+5) { animation-delay: 0.28s; }
}

@media (prefers-reduced-motion: reduce) {
  .year-card,
  .gratitude-button {
    transition: none;
  }

  .year-card:hover {
    transform: none;
  }
}

/* ---------- Page transitions (home <-> year pages) ----------
   Cross-document View Transitions. The year number in a home card
   and the big year heading on its page share a view-transition-name
   (set inline in the HTML), so it morphs between the two pages.
   Browsers without support just navigate normally. */
@media (prefers-reduced-motion: no-preference) {
  @view-transition {
    navigation: auto;
  }

  ::view-transition-group(*) {
    animation-duration: 0.45s;
    animation-timing-function: var(--ease-out);
  }

  /* Fade-through instead of a crossfade, so the two pages
     never sit on top of each other at full strength. */
  ::view-transition-old(root) {
    animation: vt-fade-out 0.16s ease-in both;
  }

  ::view-transition-new(root) {
    animation: vt-fade-in 0.3s var(--ease-out) 0.12s both;
  }
}

@keyframes vt-fade-out {
  to { opacity: 0; }
}

@keyframes vt-fade-in {
  from { opacity: 0; transform: translateY(8px); }
}

/* A page reached through a view transition skips the load-in rise,
   so the two animations do not stack. Class is set in <head>. */
.vt-arrived .section {
  animation: none;
  opacity: 1;
  transform: none;
}

@keyframes rise {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ---------- Small screens ---------- */
@media (max-width: 720px) {
  body {
    padding: 36px 16px 72px;
  }

  h1 {
    font-size: clamp(2.4rem, 9vw, 3.4rem);
    line-height: 1;
  }

  .hero h1 {
    padding-right: 52px;
  }

  .fund-card {
    width: 100%;
    justify-content: center;
  }

  .initiative-table {
    font-size: 0.9rem;
  }

  .initiative-table th,
  .initiative-table td {
    padding: 10px 12px;
  }
}
