/* ==========================================================================
   Sean Shoots — styles
   1. Tokens          4. Site header     7. Details panel
   2. Base            5. Gallery         8. About dialog
   3. Shared pieces   6. Photo viewer    9. Motion preferences

   Class naming: block, block__element, block--variant. State is expressed with
   is-* classes or ARIA attributes, both set from JavaScript.
   ========================================================================== */

/* 1. Tokens --------------------------------------------------------------- */

@font-face {
  font-family: "Architect Hand";
  src: url("fonts/architect-hand.ttf") format("truetype");
  font-display: swap;
}

:root {
  /* Two colours per theme, nothing else. Tints are mixed from these two. */
  --color-ink: #8b5760;
  --color-paper: #edd8bd;

  --color-veil: color-mix(in srgb, var(--color-paper) 68%, transparent);      /* behind text over photos */
  --color-ink-faint: color-mix(in srgb, var(--color-ink) 10%, transparent);
  --color-ink-soft: color-mix(in srgb, var(--color-ink) 38%, transparent);

  --font-family: "Architect Hand", ui-rounded, system-ui, sans-serif;
  --font-size: 1.05rem;
  --tracking-caps: 0.04em;
  --tracking-prose: 0.01em;

  --gap: 6px;                 /* the one gap: between tiles, rows and the page edge */
  --page-inset: 16px;         /* text inset from the page edge */
  --header-height: 60px;
  --header-solid: calc(50% + 4px); /* how far down the header stays fully opaque */
  --blur: 14px;
  --hover-border: 5px;

  --ease-out: cubic-bezier(0.2, 0.7, 0.2, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-ink: #f0f6f0;
    --color-paper: #222323;
  }
}

@media (max-width: 600px) {
  :root {
    --gap: 4px;
    --page-inset: 10px;
    --header-height: 52px;
  }
}

/* 2. Base ----------------------------------------------------------------- */

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

html {
  color-scheme: light dark;
  background: var(--color-paper);
}

body {
  margin: 0;
  background: var(--color-paper);
  color: var(--color-ink);
  font-family: var(--font-family);
  font-size: var(--font-size);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase; /* everything is caps except .prose and the details panel */
  -webkit-font-smoothing: antialiased;
}

/* Lock the page behind an open dialog */
body:has(dialog[open]) {
  overflow: hidden;
}

h1,
h2 {
  margin: 0;
  font: inherit;
}

dialog {
  padding: 0;
  border: 0;
  color: var(--color-ink);
}

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

/* 3. Shared pieces -------------------------------------------------------- */

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Text-only control, used for every button and link */
.text-button {
  margin: 0;
  padding: 8px 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  letter-spacing: inherit;
  text-transform: uppercase;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* Selected / expanded: embolden with a stroke so the text width never changes */
.text-button[aria-pressed="true"],
.text-button[aria-expanded="true"] {
  -webkit-text-stroke: 0.9px currentColor;
}

@media (hover: hover) {
  .text-button:hover {
    text-decoration: underline;
    text-underline-offset: 0.25em;
  }
}

/* Mixed-case text: the about content and the photo details */
.prose {
  letter-spacing: var(--tracking-prose);
  text-transform: none;
  line-height: 1.5;
}

/* 4. Site header ---------------------------------------------------------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  height: var(--header-height);
  padding: 6px max(var(--page-inset), env(safe-area-inset-right)) 0 max(var(--page-inset), env(safe-area-inset-left));
}

/* Backing layer: solid paper at the top, thinning to pure blur, and the blur
   itself is masked out towards the bottom edge so there is no visible border. */
.site-header::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: linear-gradient(to bottom, var(--color-paper) 0 var(--header-solid), transparent 100%);
  -webkit-backdrop-filter: blur(var(--blur));
  backdrop-filter: blur(var(--blur));
  -webkit-mask-image: linear-gradient(to bottom, #000 0 62%, transparent 100%);
  mask-image: linear-gradient(to bottom, #000 0 62%, transparent 100%);
}

.filters {
  display: flex;
  gap: clamp(10px, 2.4vw, 28px);
  min-width: 0;
}

@media (max-width: 600px) {
  .site-header {
    gap: 10px;
    padding-top: 5px;
    font-size: min(0.8rem, 3.5vw);
    letter-spacing: 0.01em;
  }

  /* Falls back to sideways scrolling on very narrow screens */
  .filters {
    gap: 9px;
    padding-inline: 2px;
    overflow-x: auto;
    scrollbar-width: none;
  }
}

/* 5. Gallery --------------------------------------------------------------
   Rows and tile widths are computed in js/layout.js; CSS only supplies the gap. */

.gallery {
  padding: var(--gap);
}

.gallery__row {
  display: flex;
  gap: var(--gap);
  margin-bottom: var(--gap);
}

.gallery__row:last-child {
  margin-bottom: 0;
}

.gallery-status {
  margin: 0;
  padding: 20vh var(--page-inset);
  text-align: center;
}

.gallery-status[hidden] {
  display: none;
}

.tile {
  position: relative;
  display: block;
  min-width: 0;
  height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  overflow: hidden;
  font: inherit;
  letter-spacing: inherit;
}

/* Photo tile */
.tile--photo {
  background: var(--color-ink-soft);
  cursor: pointer;
  /* Placeholder: pulses until the thumbnail has loaded */
  animation: tile-pulse 1.8s ease-in-out infinite alternate;
}

.tile--photo.is-loaded,
.tile--photo.is-broken {
  animation: none;
}

@keyframes tile-pulse {
  from { background: var(--color-ink-faint); }
  to { background: var(--color-ink-soft); }
}

.tile__image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.35s;
}

.tile--photo.is-loaded .tile__image {
  opacity: 1;
}

/* Hover / focus: an ink border tweens in over the photo; the photo never moves */
.tile--photo::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow: inset 0 0 0 0 var(--color-ink);
  transition: box-shadow 0.22s ease-out;
}

.tile--photo:focus-visible {
  outline: 0;
}

.tile--photo:focus-visible::after {
  box-shadow: inset 0 0 0 var(--hover-border) var(--color-ink);
}

@media (hover: hover) {
  .tile--photo:hover::after {
    box-shadow: inset 0 0 0 var(--hover-border) var(--color-ink);
  }
}

/* Date tile: same footprint as a photo, inverted palette. Text scales with the tile. */
.tile--date {
  container-type: size;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--color-ink);
  color: var(--color-paper);
  line-height: 1;
  text-transform: uppercase;
}

.tile__day {
  font-size: 21cqmin;
}

.tile__year {
  margin-top: 7cqmin;
  font-size: 13cqmin;
}

/* 6. Photo viewer ---------------------------------------------------------
   The dialog is the scroll container. The stage is pinned to the viewport and
   the details panel follows it in the flow, so scrolling pulls the panel up. */

.viewer {
  width: 100vw;
  max-width: none;
  height: 100dvh;
  max-height: none;
  margin: 0;
  overflow: hidden auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
  background: var(--color-paper); /* the letterbox colour */
}

.viewer:focus {
  outline: 0;
}

.viewer[open] {
  animation: viewer-fade-in 0.18s ease-out;
}

@keyframes viewer-fade-in {
  from { opacity: 0; }
}

.viewer__stage {
  position: sticky;
  top: 0;
  height: 100dvh;
  cursor: pointer;
}

.viewer__image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain; /* never stretch or crop: letterbox as little as possible */
}

/* Chrome = the close button and details panel. Hidden until the photo is clicked. */
.viewer__chrome {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.3s var(--ease-out);
}

.viewer.is-chrome-visible .viewer__chrome {
  opacity: 1;
  pointer-events: auto;
  transform: none;
}

/* Just an X, haloed in the paper colour so it reads over any photo */
.viewer__close {
  position: fixed;
  top: max(4px, env(safe-area-inset-top));
  right: max(6px, env(safe-area-inset-right));
  padding: 8px 14px;
  font-size: 1.6em;
  line-height: 1;
  -webkit-text-stroke: 5px var(--color-paper);
  paint-order: stroke fill;
}

@media (hover: hover) {
  .viewer__close:hover {
    text-decoration: none;
  }
}

/* 7. Details panel -------------------------------------------------------- */

.details {
  position: relative;
  /* Pulled up by exactly the header's height (measured in js/viewer.js) so only
     the header overlaps the photo until the viewer is scrolled. */
  margin-top: calc(-1 * var(--details-header-height, 48px));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--color-veil);
  -webkit-backdrop-filter: blur(var(--blur));
  backdrop-filter: blur(var(--blur));
  transform: translateY(16px);
}

.details__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 48px;
  padding: 8px var(--page-inset);
}

.details__summary {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 14px;
  min-width: 0;
  letter-spacing: var(--tracking-prose);
  text-transform: none;
}

.details__title {
  font-size: 1.15em;
}

.details__controls {
  display: flex;
  flex: none;
  gap: clamp(12px, 2.4vw, 28px);
}

.details__list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(220px, 42vw), 1fr));
  gap: 14px 28px;
  margin: 0;
  padding: 10px var(--page-inset) 28px;
  letter-spacing: var(--tracking-prose);
  text-transform: none;
}

.details__item {
  min-width: 0;
}

.details__label {
  margin-bottom: 3px;
  font-size: 0.72em;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.details__value {
  margin: 0;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

/* 8. About dialog --------------------------------------------------------- */

.about {
  width: min(560px, calc(100vw - 32px));
  min-height: 280px;
  background: var(--color-paper);
  box-shadow: 0 0 0 2px var(--color-ink);
}

.about::backdrop {
  background: var(--color-veil);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}

.about__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
}

.about__body {
  padding: 4px 16px 20px;
}

/* 9. Motion preferences --------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
