/*
 * Candid Cavanaugh — site styles.
 *
 * Every colour, font, size and spacing decision that is meant to be changed
 * comes from the custom properties written into each page from
 * content/site.json (see src/site/render.ts → tokensCss). This file should
 * only need editing for structural changes.
 *
 * Tokens: --font-body --font-display --display-weight
 *         --color-bg --color-text --color-muted --color-accent --color-rule
 *         --content-width --gallery-gap --gallery-row --radius --nav-height
 *         --step--1 … --step-3 (type scale)
 */

:root {
  --gutter: clamp(16px, 3.2vw, 40px);
  --space-1: 0.5rem;
  --space-2: 1rem;
  --space-3: 1.5rem;
  --space-4: 2.5rem;
  --space-5: 4rem;
  --ease: cubic-bezier(.2, .7, .2, 1);
}

*, *::before, *::after { box-sizing: border-box; }

html {
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: var(--step-0);
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
  text-rendering: optimizeLegibility;
}

body {
  margin: 0;
  background: var(--color-bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

main { flex: 1; }

img { display: block; max-width: 100%; height: auto; }

a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: 0.2em; }
a:hover { color: var(--color-accent); }

:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 3px; }

h1, h2, h3 { font-weight: var(--display-weight); margin: 0; }

.wrap {
  width: 100%;
  max-width: var(--content-width);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

.skip {
  position: absolute; left: -9999px; top: 0;
  background: var(--color-text); color: var(--color-bg); padding: var(--space-1) var(--space-2);
}
.skip:focus { left: var(--space-2); z-index: 10; }

/* Small, quiet supporting text: dates, counts, captions. */
.meta {
  color: var(--color-muted);
  font-size: var(--step--1);
  letter-spacing: 0.01em;
  font-variant-numeric: tabular-nums;
}

.label {
  font-family: var(--font-body);
  font-size: var(--step--1);
  font-weight: 400;
  color: var(--color-muted);
  letter-spacing: 0.02em;
}

/* ------------------------------------------------------------ masthead */

.masthead { height: var(--nav-height); }

.masthead-inner {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.brand {
  font-family: var(--font-display);
  font-weight: var(--display-weight);
  font-size: var(--step-1);
  text-decoration: none;
  letter-spacing: 0.005em;
  white-space: nowrap;
}

.masthead nav { display: flex; gap: var(--space-3); }

.masthead nav a {
  text-decoration: none;
  color: var(--color-muted);
  font-size: var(--step--1);
  padding-block: 12px; /* 44px tap target with the line height */
}
.masthead nav a:hover, .masthead nav a[aria-current="page"] { color: var(--color-text); }

/* --------------------------------------------------------------- home */

.lead { margin: 0 auto; width: fit-content; max-width: 100%; }

.lead-img {
  width: 100%;
  max-height: calc(100svh - var(--nav-height) - 3.5rem);
  object-fit: contain;
  margin-inline: auto;
  width: auto;
}

.lead a { display: block; }

.lead-caption {
  padding-inline: 0;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--space-2);
  padding-top: var(--space-1);
  font-size: var(--step--1);
}
.lead-caption a { text-decoration: none; }

.intro {
  padding-block: var(--space-5) var(--space-4);
  font-family: var(--font-display);
  font-size: var(--step-1);
  line-height: 1.4;
}
.intro p { margin: 0; max-width: 34ch; }
.intro p + p { margin-top: var(--space-2); }

.section { padding-block: var(--space-4) var(--space-5); }

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  border-bottom: 1px solid var(--color-rule);
  padding-bottom: var(--space-1);
  margin-bottom: var(--space-4);
}

.label-link { font-size: var(--step--1); color: var(--color-muted); text-decoration: none; }

.page-title {
  font-family: var(--font-display);
  font-size: var(--step-3);
  line-height: 1.1;
  letter-spacing: -0.005em;
}

.section > .page-title { margin-bottom: var(--space-4); }

.empty { padding-block: var(--space-5); }

/* ------------------------------------------------------ gallery index
 * An editorial index: each gallery is one row — the cover at its own aspect
 * ratio beside its title — rather than a grid of cropped cards.
 */

.index { list-style: none; margin: 0; padding: 0; }

.entry + .entry { margin-top: var(--space-5); }

.entry-link {
  display: grid;
  grid-template-columns: minmax(0, 8fr) minmax(0, 4fr);
  gap: var(--space-2) var(--space-4);
  align-items: end;
  text-decoration: none;
}

.entry.is-portrait .entry-link { grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); }

.entry-media img {
  width: 100%;
  max-height: 78vh;
  object-fit: contain;
  object-position: left bottom;
  border-radius: var(--radius);
}

.entry-text { display: flex; flex-direction: column; gap: 0.35rem; padding-bottom: 0.2rem; }

.entry-title {
  font-family: var(--font-display);
  font-weight: var(--display-weight);
  font-size: var(--step-2);
  line-height: 1.15;
}

.entry-desc { color: var(--color-muted); max-width: 42ch; margin-top: 0.25rem; }

.entry-link:hover .entry-title { color: var(--color-accent); }
.entry-link img { transition: opacity .25s var(--ease); }
.entry-link:hover img { opacity: .92; }

/* ------------------------------------------------------------ gallery */

.album-head {
  padding-block: var(--space-4) var(--space-3);
  display: grid;
  gap: 0.4rem;
}
.album-desc { margin: 0.4rem 0 0; max-width: 60ch; color: var(--color-muted); }

.wrap-wide { max-width: calc(var(--content-width) + 240px); padding-bottom: var(--space-5); }

/*
 * Justified rows without JavaScript: each frame grows in proportion to its
 * aspect ratio, so every photograph in a row ends up the same height and none
 * is cropped. The trailing pseudo-element stops the last row from stretching.
 */
.justified {
  display: flex;
  flex-wrap: wrap;
  gap: var(--gallery-gap);
}
.justified::after { content: ""; flex-grow: 1000000; }

.frame {
  --row: var(--gallery-row);
  flex-grow: calc(var(--ar) * 100);
  flex-basis: calc(var(--ar) * var(--row));
  aspect-ratio: var(--ar);
  display: block;
  position: relative;
  overflow: hidden;
  border-radius: var(--radius);
  cursor: zoom-in;
  /* A very wide last row item must not grow into a giant. */
  max-width: calc(var(--ar) * var(--row) * 1.8);
}
.frame img { width: 100%; height: 100%; object-fit: cover; }
.frame:focus-visible { outline-offset: 2px; }

@media (max-width: 900px) { .frame { --row: calc(var(--gallery-row) * .7); } }
@media (max-width: 560px) { .frame { --row: calc(var(--gallery-row) * .42); } }

/* ------------------------------------------------------------- unlock */

.unlock { padding-block: var(--space-5); max-width: 36rem; margin-inline: auto; }
.unlock .meta { margin: 0.5rem 0 var(--space-4); }
.unlock-form label { display: block; font-size: var(--step--1); color: var(--color-muted); margin-bottom: 0.4rem; }
.unlock-row { display: flex; gap: var(--space-1); }

input[type="text"], input[type="password"] {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  padding: 0.55rem 0.75rem;
  background: transparent;
  color: var(--color-text);
  border: 1px solid var(--color-rule);
  border-radius: var(--radius);
  font: inherit;
}
input:focus-visible { outline: none; border-color: var(--color-accent); }

button, .button {
  min-height: 44px;
  padding: 0.55rem 1.1rem;
  font: inherit;
  font-size: var(--step--1);
  background: var(--color-text);
  color: var(--color-bg);
  border: 0;
  border-radius: var(--radius);
  cursor: pointer;
}
button:hover { background: var(--color-accent); }

.error { color: #e3a58f; font-size: var(--step--1); margin-top: var(--space-1); }

/* -------------------------------------------------------------- about */

.about { display: grid; gap: var(--space-4); }
.about.has-photo { grid-template-columns: minmax(0, 6fr) minmax(0, 5fr); align-items: start; }
.about .page-title { margin-bottom: var(--space-3); }
.prose { max-width: 60ch; }
.prose p { margin: 0 0 1em; }
.about-photo { margin: 0; }
.about-photo img { border-radius: var(--radius); max-height: 80vh; width: auto; }

.contact { margin: var(--space-4) 0 0; display: grid; gap: 0.6rem; font-size: var(--step--1); }
.contact div { display: grid; grid-template-columns: 7rem 1fr; gap: var(--space-2); border-top: 1px solid var(--color-rule); padding-top: 0.6rem; }
.contact dt { color: var(--color-muted); }
.contact dd { margin: 0; overflow-wrap: anywhere; }

/* ------------------------------------------------------------ footer */

.colophon { border-top: 1px solid var(--color-rule); margin-top: var(--space-4); }
.colophon-inner {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-3);
  padding-block: var(--space-3);
  font-size: var(--step--1);
  color: var(--color-muted);
}
.colophon p { margin: 0; }
.colophon-links { display: flex; flex-wrap: wrap; gap: var(--space-3); }
.colophon a { text-decoration: none; }

/* ----------------------------------------------------------- lightbox */

.lightbox {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: color-mix(in srgb, var(--color-bg) 97%, black);
  color: var(--color-text);
  overflow: hidden;
}
.lightbox::backdrop { background: var(--color-bg); }
.lightbox[open] { display: grid; grid-template-rows: auto 1fr auto; }

.lb-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: max(8px, env(safe-area-inset-top)) var(--gutter) 8px;
  font-size: var(--step--1);
  color: var(--color-muted);
  min-height: 56px;
}
.lb-actions { display: flex; align-items: center; gap: var(--space-1); }

.lb-btn {
  background: transparent;
  color: var(--color-muted);
  min-width: 44px;
  min-height: 44px;
  padding: 0 0.6rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  font-size: var(--step--1);
}
.lb-btn:hover { background: transparent; color: var(--color-text); }
.lb-btn svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.5; }

.lb-stage {
  position: relative;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 var(--gutter);
  touch-action: pan-y pinch-zoom;
  user-select: none;
}
.lb-stage img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  transition: opacity .18s var(--ease), transform .18s var(--ease);
}
.lb-stage img.is-loading { opacity: .35; }

.lb-prev, .lb-next {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 18%;
  max-width: 160px;
  min-width: 56px;
  background: transparent;
  color: var(--color-muted);
  display: flex;
  align-items: center;
  padding: 0 var(--gutter);
}
.lb-prev { left: 0; justify-content: flex-start; }
.lb-next { right: 0; justify-content: flex-end; }
.lb-prev:hover, .lb-next:hover { background: transparent; color: var(--color-text); }
.lb-prev svg, .lb-next svg { width: 28px; height: 28px; stroke: currentColor; fill: none; stroke-width: 1.25; }
.lb-prev[hidden], .lb-next[hidden] { display: none; }

.lb-foot { min-height: max(12px, env(safe-area-inset-bottom)); }

/* On touch screens the side zones would sit over the photograph; swipe instead. */
@media (hover: none) and (pointer: coarse) {
  .lb-prev, .lb-next { display: none; }
  .lb-stage { padding: 0; }
}

/* ------------------------------------------------------------ narrow */

@media (max-width: 760px) {
  .entry-link, .entry.is-portrait .entry-link { grid-template-columns: 1fr; gap: var(--space-2); }
  .entry-media img { max-height: none; }
  .entry + .entry { margin-top: var(--space-4); }
  .page-title { font-size: var(--step-2); }
  .intro { padding-block: var(--space-4) var(--space-3); }
  .about.has-photo { grid-template-columns: 1fr; }
  .about-photo { order: -1; }
  .contact div { grid-template-columns: 5.5rem 1fr; }
  .lead-img { max-height: 75svh; }
  .lead-caption { padding-inline: var(--gutter); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
