/* ============================================================
   Delus Journal — style.css
   Structural skeleton only. Design values (fonts, colours,
   spacing, animations) to be filled in once Figma is final.
   ============================================================ */

/* --- Reset ------------------------------------------------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* --- Web fonts --------------------------------------------- */
@font-face {
  font-family: "Styrene B";
  src: url("assets/fonts/StyreneB-Regular.otf") format("opentype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Styrene B";
  src: url("assets/fonts/StyreneB-Medium.otf") format("opentype");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Louize";
  src: url("assets/fonts/Louize-Regular.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Louize";
  src: url("assets/fonts/Louize-Italic.ttf") format("truetype");
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}

/* --- Root variables (TODO: update with real design tokens) - */
:root {
  /* Typography */
  --font-sans:  "Styrene B", system-ui, -apple-system, sans-serif;
  --font-serif: "Louize", Georgia, "Times New Roman", serif;
  --font-size-base: clamp(1.2rem, 1.15rem + 0.3vw, 1.75rem);
  --font-size-ui: clamp(0.8rem, 0.8rem + 0.2vw, 1.2rem);
  --line-height-base: 1.4;
  --transition-view: 900ms ease-in-out;

  /* Colours */
  --color-bg: #E2E2DD;
  --color-text: #111111;            /* TODO */
  --color-muted: #888888;           /* TODO */

  /* Layout */
  --max-width-page: 1400px;
  --spacing-section: 4rem;
  --spacing-page: 2rem;
  --spacing-columns: 4rem;
  --spacing-header-gap: calc(var(--spacing-section) * 1.5); /* gap below header; absorbed by the footer absorber on tall viewports, triggers scroll on short ones */
}

/* --- Base -------------------------------------------------- */
html {
  font-size: 16px;
  scrollbar-gutter: stable;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  font-size: var(--font-size-base);
  line-height: var(--line-height-base);
  background-color: var(--color-bg);
  color: var(--color-text);
}

a {
  color: inherit;
  text-decoration: underline;
}


p + p {
  margin-top: 1em;
}

strong {
  font-weight: 500;
}

/* --- Page wrapper ------------------------------------------ */
.weather-bg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%; /* 100% of body, not 100vw — avoids overshooting by the scrollbar width */
  height: 50vh; /* fallback until JS sizes to h1.bottom + extra */
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.page {
  position: relative;
  z-index: 1;
  /* min-height (not height) + no overflow clip = layout fills the viewport when
     the window is tall, but grows and lets the body scroll when the viewport is
     shorter than the content (short laptops, zoomed-in displays, etc.). */
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 3fr;
  /* Row 1: header (content-sized).
     Row 2: main + service (content-sized — does not stretch to fill).
     Row 3: flexible absorber — eats any leftover viewport space so the footer
            pins to the bottom on tall windows. Shrinks to 0 when content fills
            the viewport; once it hits 0, body scroll kicks in naturally.
     Row 4: footer (content-sized). */
  grid-template-rows: auto auto minmax(2rem, 1fr) auto;
  column-gap: var(--spacing-columns);
  align-items: first baseline;
  max-width: var(--max-width-page);
  margin-inline: auto;
  padding: var(--spacing-page);
}

/* --- Header ------------------------------------------------ */
.site-header {
  grid-column: 1 / -1;
  padding-bottom: var(--spacing-header-gap);
  font-size: var(--font-size-ui);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.site-nav,
.site-nav-back {
  transition: opacity var(--transition-view);
}

.header--fading .site-nav,
.header--fading .site-nav-back {
  opacity: 0;
  pointer-events: none;
}

/* --- Masthead ---------------------------------------------- */
.masthead {
  display: flex;
  flex-direction: row;
  align-items: baseline;
  gap: 1.5rem; /* TODO: tune */
}
.masthead__title,
.masthead__subtitle {
  font-weight: 400;
}

/* --- Nav --------------------------------------------------- */
.site-nav {
  display: flex;
  gap: 1.5rem; /* TODO: tune */
}

.site-nav-back {
  display: none;
  text-decoration: none;
}

.site-nav-back::before {
  content: '←\00a0\00a0';
  font-size: 0.85em;
  opacity: 0;
  transition: opacity 150ms ease;
}

.site-nav-back:hover::before {
  opacity: 1;
}
.site-nav a { font-weight: 400; text-decoration: none; }
.site-nav a[aria-current="page"] { text-decoration: none; }
.masthead[data-view] { cursor: pointer; }
.mobile-only { display: none; }

/* --- Main -------------------------------------------------- */
.site-main {
  grid-column: 2;
  grid-row: 2;
  min-height: 0;
}

/* --- Service sidebar --------------------------------------- */
.site-service {
  grid-column: 1;
  grid-row: 2;
  min-height: 0;
  font-size: var(--font-size-ui);
}

/* --- Views (SPA swap) -------------------------------------- */
.site-main,
.site-service { display: grid; }

.view {
  grid-area: 1 / 1;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-view);
}

.view--active {
  opacity: 1;
  pointer-events: auto;
}

/* Collapsed views are pulled OUT OF FLOW (not just height:0) so they don't
   contribute to the grid cell's size OR its first-baseline calculation.
   Without position:absolute, the DOM-first collapsed view (home) would still
   expose a baseline at y=0, breaking `align-items: first baseline` on the
   page grid — the main column would then sit lower than the service column
   on about/donate views.
   JS toggles this class AFTER the fade-out completes (and removes it BEFORE
   the fade-in starts), so the opacity transition plays at full height — no
   snap-collapse mid-fade. */
.view--collapsed {
  position: absolute;
  height: 0;
  overflow: hidden;
  pointer-events: none;
}

/* --- Footnote tooltip -------------------------------------- */
.footnote {
  font-weight: 500;
  font-style: normal;   /* override italic from blockquote parent */
  font-size: 0.6em;
  line-height: 0;       /* prevent superscript from stretching parent line-height */
  cursor: default;
  padding: 0.4em 0.3em; /* larger hit area */
}

.tooltip {
  position: fixed;
  pointer-events: none;
  z-index: 100;
  background-color: var(--color-bg);
  border: 1px solid currentColor;
  border-radius: 4px;
  padding: 0.5rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 400;
  line-height: 1.3;
  max-width: 20rem;
}

/* Align first body paragraph with the home blockquote — same spacing as blockquote margin-top */
.site-main .view[data-view="about"] h1 + p,
.site-main .view[data-view="donate"] h1 + p {
  margin-top: 1.5rem;
}


/* --- Image tooltip (issue covers) -------------------------- */
.image-tooltip {
  position: fixed;
  z-index: 100;
}

@keyframes image-tooltip-in {
  from { opacity: 0; translate: 0 6px; }
  to   { opacity: 1; translate: 0 0; }
}

.image-tooltip img {
  display: block;
  width: 240px;
  height: auto;
  filter: drop-shadow(0 8px 24px rgba(0, 0, 0, 0.15));
  animation: image-tooltip-in 300ms ease-out both;
}

.image-tooltip__buy {
  display: block;
  margin: 0.5rem 4px 0;
  animation: image-tooltip-in 300ms ease-out 200ms both;
  padding: 0.6rem 1.75rem;
  background: var(--color-bg);
  border: 1px solid currentColor;
  border-radius: 999px;
  font-size: var(--font-size-header-mobile, var(--font-size-ui));
  font-weight: 400;
  text-align: center;
  text-decoration: none;
  color: var(--color-text);
  white-space: nowrap;
}

.image-tooltip__buy::after {
  content: '\00a0\00a0↗';
  font-size: 0.85em;
}

/* --- Main column text styles ------------------------------- */
.site-main h1         { font-family: var(--font-serif); font-weight: 400; font-size: 1.5em; }
.site-main blockquote {
  font-family: var(--font-serif);
  font-weight: 400;
  font-style: italic;
  font-size: 1.125em;                    /* slight bump over body */
  padding-left: 1.25rem;
  margin: 2rem 0;                      /* breathing room above and below */
}
.site-main p          { font-family: var(--font-serif); font-weight: 400; }
/* .site-main em inherits family/weight; italic handled by the em tag's default font-style and Louize-Italic @font-face */

/* --- Service column text styles ---------------------------- */
/* ------------------------------------------------------------------
   Zero-height baseline anchor for .site-service.

   Why this exists:
   .page uses `align-items: first baseline` so the service column and the
   main column line up on their first text baseline. The service column's
   h1 is `position: absolute`, which takes it out of flow — meaning the
   column has NO in-flow first baseline, and the grid falls back to
   aligning on the top of the column's box. Result: the main column's
   prose visibly drops below where the service h1 sits.

   How the fix works:
   This ::before is an in-flow pseudo-element carrying a zero-width space
   (\200B is required — an empty `content: ''` would not generate a box,
   so there would be no baseline to anchor to). Its font-size and
   line-height mirror the h1, so its first baseline lands at the same y
   the h1's baseline would have had in flow. `height: 0` + `overflow:
   visible` means it contributes a baseline but no layout height, so the
   row still sizes to the (absolute) h1's visual box. `visibility:
   hidden` is belt-and-braces — the ZWSP renders nothing anyway.

   If you "clean this up": the main/service columns will drift out of
   vertical alignment on desktop. The mobile override below disables
   this (display: none) because mobile is single-column and doesn't use
   baseline alignment.
   ------------------------------------------------------------------ */
.site-service::before {
  content: '\200B';
  grid-area: 1 / 1;
  align-self: start;
  font-size: var(--font-size-ui);
  line-height: var(--line-height-base);
  height: 0;
  overflow: visible;
  visibility: hidden;
  pointer-events: none;
}

.site-service h1 a { text-decoration: none; }

.site-service .view:not([data-view="home"]) h1::before {
  content: '←';
  position: absolute;
  right: 100%;
  top: 0;
  padding-right: 0.4em;
  opacity: 0;
  transition: opacity 200ms ease;
}

.site-service .view:not([data-view="home"]) h1:hover::before {
  opacity: 1;
}
.site-service h1 {
  font-size: inherit;
  font-weight: 500;
  text-transform: uppercase;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  margin: 0;
}

.site-service .view {
  position: relative;
  padding-top: calc(var(--line-height-base) * 2 * var(--font-size-base) - 0.6rem);
}
.site-service p  { font-weight: 400; margin-top: 1em; }
.credit { font-size: 0.85rem; line-height: 1.25; margin-top: 2em; }
.credit p { margin: 0; }
.credit a { text-decoration: none; transition: opacity 150ms ease; }
.credit a:hover { opacity: 0.6; }
.credit--mobile { display: none; }

.site-service strong {
  /* TODO: sub-title treatment (block-level, weight, spacing) */
  display: block;
}

.site-service ul {
  list-style: "– ";
  padding-left: 1em;
  margin: 0;
}


/* --- Sections ---------------------------------------------- */
.section {
  margin-bottom: var(--spacing-section);
}

/* CTA */
.site-cta { display: none; }

/* Mobile open-call floating pill */
.mobile-open-call-pill { display: none; }

.section--cta p {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.section--cta a {
  display: inline-block;
  font-family: var(--font-sans);
  font-size: var(--font-size-ui);
  font-weight: 400;
  text-transform: uppercase;
  text-decoration: none;
}

.desktop-cta a::after {
  content: '\00a0\00a0↗';
  font-size: 0.85em;
  opacity: 0;
  transition: opacity 150ms ease;
}

.desktop-cta a:hover::after {
  opacity: 1;
}

/* --- Footer ------------------------------------------------ */
.site-footer {
  grid-column: 1 / -1;
  grid-row: 4; /* sits below the absorber row (mobile override resets this) */
  /* No fixed padding-top — the 1fr absorber row above is the only spacer
     between content and footer. Keeps the gap fully dynamic: expands on tall
     viewports, shrinks to 0 on short ones before any scroll kicks in. */
  color: var(--color-muted);
  font-size: 0.85rem;
  transition: opacity var(--transition-view);
}

.footer--fading {
  opacity: 0;
  pointer-events: none;
}
.site-footer a { text-decoration: none; }

/* --- Responsive -------------------------------------------- */
@media (max-width: 768px) {
  html { scroll-behavior: smooth; }

  #open-call-section { scroll-margin-top: 3rem; }

  :root {
    --spacing-section: 2.5rem;
    --spacing-page: 1.25rem;
    --font-size-header-mobile: calc(var(--font-size-ui) * 1.2);
    --transition-view: 400ms ease-in-out;
  }

  .page {
    grid-template-columns: 1fr;
    grid-template-rows: none;
    column-gap: 0;
  }

  .site-header  {
    order: 1; grid-column: 1; grid-row: auto;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 3rem;
    padding-top: 2rem;
    padding-bottom: 4rem;
  }
  .masthead { flex-direction: column; align-items: center; gap: 0.15rem; }
  .mobile-only { display: inline; }
  .site-header { font-size: var(--font-size-header-mobile); }
  .site-nav { justify-content: center; }
  .page:not([data-current-view="home"]) .site-nav { display: none; }
  .page:not([data-current-view="home"]) .site-nav-back { display: block; }
  .site-nav-back::before { content: none; }
  .site-service .view[data-view="home"] h1 { text-align: center; }
  .site-service .view[data-view="about"] h1,
  .site-service .view[data-view="donate"] h1 { display: none; }
  .site-service .view { padding-top: 0; position: static; }
  .site-service h1 { position: static; margin-bottom: 4em; }
  .site-service { margin-top: 2rem; }
  .site-service::before { display: none; }
  .site-main    { order: 2; grid-column: 1; grid-row: auto; }
  .site-service { order: 3; grid-column: 1; grid-row: auto; }
  .site-cta     { order: 4; grid-column: 1; grid-row: auto; display: grid; text-align: center; padding-top: 3rem; }
  .site-cta .section--cta p { padding-inline: 6rem; }
  .site-cta .section--cta a {
    border: 1px solid currentColor;
    border-radius: 999px;
    padding: 0.6rem 1.75rem;
  }
  .credit--desktop { display: none; }
  .credit--mobile  { display: block; order: 5; grid-column: 1; grid-row: auto; margin-top: 8rem; }
  .site-footer  { order: 6; grid-column: 1; grid-row: auto; padding-top: 2rem; }
  .page[data-current-view="about"] .site-cta    { padding-top: 5rem; }
  .page[data-current-view="donate"] .site-cta   { padding-top: 2rem; }
  .page[data-current-view="about"] .credit--mobile,
  .page[data-current-view="donate"] .credit--mobile { display: none; }
  .desktop-cta  { display: none; }

  .page[data-current-view="home"] .mobile-open-call-pill {
    display: block;
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 50;
    border: 1px solid currentColor;
    border-radius: 999px;
    padding: 0.6rem 1.75rem;
    font-size: var(--font-size-header-mobile, var(--font-size-ui));
    font-weight: 400;
    text-decoration: none;
    color: var(--color-text);
    background: var(--color-bg);
    white-space: nowrap;
    transition: opacity 300ms ease;
  }

  .mobile-open-call-pill.is-hidden {
    opacity: 0;
    pointer-events: none;
  }
}
