/* harelphotos (DESIGN.md 11).
 *
 * One stylesheet, no build step, no framework. Written with CSS *logical*
 * properties throughout (margin-inline, padding-block, text-align: start)
 * rather than left/right. That costs nothing today and is the difference
 * between a future Hebrew interface being one `dir="rtl"` and being a rewrite.
 */

:root {
  --bg: #ffffff;
  --fg: #1a1a1a;
  --dim: #6b6b6b;
  --line: #e2e2e2;
  --card: #f6f6f6;
  --accent: #2d6cdf;
  --gap: 4px;
  --radius: 6px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121212;
    --fg: #ececec;
    --dim: #9a9a9a;
    --line: #2c2c2c;
    --card: #1c1c1c;
    --accent: #6ba3ff;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

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

/* ---------------------------------------------------------------- topbar */

.topbar {
  position: sticky;
  inset-block-start: 0;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  align-items: baseline;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  padding-inline: max(1rem, env(safe-area-inset-left)) max(1rem, env(safe-area-inset-right));
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-block-end: 1px solid var(--line);
}

.crumbs { font-size: 1.05rem; }
.crumbs a { color: var(--dim); }
.crumbs .sep { color: var(--dim); margin-inline: 0.35em; }
.crumbs .here { font-weight: 600; }
.meta, .dim { color: var(--dim); font-size: 0.85rem; }

/* Filename plus the always-visible date and place. Wraps to a second line by
   itself when the bar is too narrow, rather than squeezing the filename. */
.titleline {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.15rem 0.75rem;
  min-inline-size: 0;
}
.photo-meta { white-space: nowrap; }

main {
  padding: 1rem;
  padding-inline: max(1rem, env(safe-area-inset-left)) max(1rem, env(safe-area-inset-right));
}

.blurb { color: var(--dim); max-inline-size: 60ch; }

h2.section {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--dim);
  margin-block: 1.5rem 0.75rem;
}
h2.section:first-child { margin-block-start: 0.25rem; }

/* ------------------------------------------------- album cards (11.1a)
 * Uniform tiles with the caption BELOW the image. An overlay would need a
 * scrim to survive a snow photo, and would dim the cover it sits on; since
 * albums have their own section, nothing requires the label to be inside.
 */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem 0.75rem;
}

.card { display: block; }
.card:hover { text-decoration: none; }

.card-img {
  aspect-ratio: 4 / 3;          /* uniform, so the captions line up */
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--card);
  transition: transform 0.12s ease;
}
.card:hover .card-img,
.card:focus-visible .card-img { transform: scale(1.02); }
.card-img img { inline-size: 100%; block-size: 100%; object-fit: cover; display: block; }

.card-blank {
  display: grid;
  place-items: center;
  block-size: 100%;
  font-size: 2.5rem;
  color: var(--dim);
}

/* Fixed height, so one long album name cannot shove its neighbours out of
 * alignment. */
.card-text {
  display: flex;
  flex-direction: column;
  margin-block-start: 0.45rem;
  min-block-size: 2.9rem;
}
.card-title {
  font-weight: 600;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-sub { color: var(--dim); font-size: 0.8rem; }

/* ------------------------------------------------- photo grid (11.1c)
 * Justified rows: true aspect ratios, never cropped. The flexbox rule below
 * is the no-JS fallback and the first-paint layout; app.js then replaces it
 * with exact rows.
 */

.grid { display: flex; flex-wrap: wrap; gap: var(--gap); }

.grid .tile {
  flex: 1 1 calc(var(--ar, 1) * 180px);
  block-size: 180px;
  overflow: hidden;
  border-radius: 3px;
  background: var(--card);
}
.grid .tile img { inline-size: 100%; block-size: 100%; object-fit: cover; display: block; }

/* Once JS has measured, rows are exact and nothing is cropped. */
.grid.justified { display: block; }
.grid.justified .row {
  display: flex;
  gap: var(--gap);
  margin-block-end: var(--gap);
  content-visibility: auto;     /* the browser skips off-screen rows entirely */
}
.grid.justified .tile { flex: none; border-radius: 3px; }
.grid.justified .tile img { object-fit: fill; }

/* ------------------------------------------------------ single photo view */

/* The photo page is one screenful: bar, photo, footer, nothing scrolls.
   The whole page has to be the flex column, not just .viewer -- the footer
   lives outside .viewer, so a `.viewer { min-block-size: 100dvh }` made the
   document 100dvh PLUS the footer and the page always scrolled.
   A definite height here is also what makes `max-block-size: 100%` on the
   photo mean anything: against an auto height it resolves to nothing at all,
   and the image sizes the stage instead of the stage bounding the image. */
.photo-page {
  block-size: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.photo-page .sitefoot { flex: none; }
.viewer { display: flex; flex-direction: column; min-block-size: 100dvh; }
.photo-page .viewer { flex: 1; min-block-size: 0; }
.viewer-bar { background: var(--bg); }

.actions { display: flex; gap: 0.5rem; align-items: center; }
.actions button, .actions .button {
  font: inherit;
  color: var(--fg);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.4rem 0.7rem;
  cursor: pointer;
  min-block-size: 44px;         /* touch target */
  display: inline-flex;
  align-items: center;
}
.actions .button:hover, .actions button:hover { border-color: var(--accent); text-decoration: none; }

.stage {
  position: relative;
  flex: 1;
  display: grid;
  place-items: center;
  min-block-size: 0;
}
/* The photo fills the stage and `object-fit` letterboxes it inside.
 *
 * The obvious `max-block-size: 100%` does not work here: a percentage
 * max-height needs a containing block with a definite height, and against a
 * flex-sized one it silently resolves to no constraint at all -- so the image
 * sized the stage instead of the stage bounding the image, and tall photos ran
 * off the bottom of the screen.
 *
 * Filling the box also takes layout out of `sizes`' hands. With `width: auto`
 * and a w-descriptor srcset the browser lays an image out at exactly the width
 * `sizes` claims, which meant a wrong estimate was not a resolution question
 * but a visibly wrong size -- and correcting it from JavaScript made the photo
 * grow a moment after it appeared. Now `sizes` only chooses which file to
 * fetch, and the geometry is settled before the first paint.
 */
.stage img {
  position: absolute;
  inset: 0.5rem;
  inline-size: calc(100% - 1rem);
  block-size: calc(100% - 1rem);
  object-fit: contain;
}

.nav {
  position: absolute;
  /* Above the photo. The image is absolutely positioned too and comes after
     the "previous" link in the document, so without this it paints over that
     arrow and swallows the click. */
  z-index: 1;
  inset-block: 0;
  display: flex;
  align-items: center;
  padding-inline: 0.75rem;
  font-size: 2.5rem;
  color: var(--fg);
  opacity: 0.35;
  text-decoration: none;
  user-select: none;
  min-inline-size: 44px;
}
.nav:hover { opacity: 1; text-decoration: none; }
.nav.prev { inset-inline-start: 0; }
.nav.next { inset-inline-end: 0; }

.info {
  border-block-start: 1px solid var(--line);
  padding: 1rem;
  padding-inline: max(1rem, env(safe-area-inset-left)) max(1rem, env(safe-area-inset-right));
  background: var(--card);
}
.info dl {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.35rem 1.25rem;
  margin: 0;
  max-inline-size: 70ch;
}
.info dt { color: var(--dim); font-size: 0.85rem; }
.info dd { margin: 0; }
.info a { color: var(--accent); }

.empty-page { padding: 4rem 1rem; text-align: center; }

@media (max-width: 600px) {
  .grid .tile { block-size: 120px; flex-basis: calc(var(--ar, 1) * 120px); }
  .cards { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
}

/* A phone held sideways. The viewport is barely 390 px tall, so a top bar
   sized for a desktop takes a third of the screen and the photo -- the entire
   point of the page -- gets what is left. Give the bar only what it needs:
   drop the breadcrumb trail (the album is one Escape away), stop the title
   wrapping, and shrink the touch targets to something still comfortable. */
@media (max-height: 520px) {
  /* The bar stays in the flow, above the photo, exactly as everywhere else.
     Floating it over the image bought about 9% more width and covered the top
     of every photo to do it -- a bad trade for a page whose entire purpose is
     looking at the picture. Shrinking the bar is the part that paid: 125px of
     a 390px screen down to 48px, without hiding anything. */
  .viewer .topbar { padding-block: 0.35rem; gap: 0.15rem 0.6rem; }
  .viewer .crumbs a, .viewer .crumbs .sep { display: none; }
  .viewer .crumbs { font-size: 0.95rem; }
  .viewer .titleline {
    flex: 1 1 auto;
    min-inline-size: 0;
    flex-wrap: nowrap;
    overflow: hidden;
  }
  .viewer .crumbs .here, .viewer .photo-meta {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .viewer .actions button, .viewer .actions .button {
    min-block-size: 36px;
    padding: 0.25rem 0.5rem;
    font-size: 0.9rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ------------------------------------------------- landing page (11.5) */

.landing {
  max-inline-size: 40rem;
  margin-inline: auto;
  padding: 2.5rem 1.25rem 3rem;
  padding-inline: max(1.25rem, env(safe-area-inset-left)) max(1.25rem, env(safe-area-inset-right));
  text-align: center;
}
.landing .hero {
  inline-size: 100%;
  max-inline-size: 640px;
  block-size: auto;
  border-radius: var(--radius);
  margin-block-end: 1.5rem;
}
.landing h1 { font-size: 2rem; margin: 0 0 0.35rem; }
.landing .tagline { color: var(--dim); margin-block: 0 2rem; }
.landing .notice, .landing .error {
  border-radius: var(--radius);
  padding: 0.6rem 0.8rem;
  margin-block-end: 1.25rem;
}
.landing .notice { background: var(--card); color: var(--dim); }
.landing .error  { background: #fdeaea; color: #8a1f1f; }
@media (prefers-color-scheme: dark) {
  .landing .error { background: #3a1b1b; color: #ffb4b4; }
}

form.login {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.6rem 0.9rem;
  align-items: center;
  text-align: start;
  max-inline-size: 24rem;
  margin-inline: auto;
}
form.login label { color: var(--dim); }
form.login input {
  font: inherit;
  padding: 0.55rem 0.6rem;
  min-block-size: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--fg);
  inline-size: 100%;
}
form.login input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
form.login button {
  grid-column: 2;
  font: inherit;
  font-weight: 600;
  min-block-size: 44px;
  border: 0;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

.landing .or {
  position: relative;
  margin-block: 1.75rem;
  color: var(--dim);
  font-size: 0.85rem;
}
.landing .or::before {
  content: "";
  position: absolute;
  inset-block-start: 50%;
  inset-inline: 0;
  border-block-start: 1px solid var(--line);
}
.landing .or span { position: relative; background: var(--bg); padding-inline: 0.75rem; }

.landing .google {
  display: inline-flex;
  align-items: center;
  min-block-size: 44px;
  padding: 0 1.1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.landing .google:hover { border-color: var(--accent); text-decoration: none; }
.landing .legal { margin-block-start: 2.5rem; font-size: 0.85rem; color: var(--dim); }

/* --------------------------------------------------- chrome (11.3) */

.usermenu { display: flex; align-items: center; gap: 0.6rem; font-size: 0.85rem; }
.usermenu form, form.inline { display: inline; }
button.linklike {
  font: inherit;
  color: var(--accent);
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
}
button.linklike:hover { color: var(--fg); }

.sitefoot {
  margin-block-start: 3rem;
  padding: 1.25rem;
  padding-inline: max(1.25rem, env(safe-area-inset-left)) max(1.25rem, env(safe-area-inset-right));
  border-block-start: 1px solid var(--line);
  color: var(--dim);
  font-size: 0.85rem;
}
.sitefoot.warn {
  background: #fff6e5;
  color: #6b4a00;
  border-block-start-color: #e8cf9a;
}
@media (prefers-color-scheme: dark) {
  .sitefoot.warn { background: #2e2510; color: #ffd88a; border-block-start-color: #4d3f18; }
}

.prose { max-inline-size: 44rem; margin-inline: auto; padding: 2rem 1.25rem; }
.prose h1 { font-size: 1.6rem; }
.prose a { color: var(--accent); }

/* A photo the scan has not reached yet. Deliberately no image: the original
   can be tens of megabytes, and a grid of those would be far worse than a
   blank tile. */
.tile.pending {
  display: grid;
  place-items: center;
  background: var(--card);
  border: 1px dashed var(--line);
}
.pending-mark { color: var(--dim); font-size: 1.2rem; letter-spacing: 0.1em; }
