/* Task 14: the family home, the album view, the justified gallery and the
   viewer. Reuses app.css's tokens and classes (.title, .meta, .btn,
   .btn-main, .btn-quiet, .page, .dark, .sheet*) and adds only what's new,
   per Ruling 2. No inline styles anywhere: --ar and --row are the only
   runtime-set custom properties (gallery.js, via el.style.setProperty). */

/* ---------- global (Task 14 fix round 1, item 5) ---------- */

/* A dark view (the album, the viewer) fills its own box, but the body
   behind it is still paper by default: a short album, a loading or error
   screen, or iOS's own rubber-band overscroll can all show a sliver of
   white at the edges without this. */
:root:has(.dark) body {
  background: var(--night);
}

/* Each fixed dock's own height above the bottom safe area: 10px top
   padding, its tallest row, 20px bottom padding and the 1px border. The
   home dock is one 56px row; the album dock on a phone is a 48px row, an 8px
   gap and the 56px main action, and from 600px one 56px row. The page's own
   bottom padding, its scroll-padding-bottom and the toasts all use these, so
   the last row, a focused control scrolled into view, or a toast is never
   left under a dock.

   --album-dock-space is the album dock's whole height, safe area included.
   album.js measures the real dock and sets it on the root (fix round 2):
   at large text sizes its row of two buttons wraps onto two lines, and no
   fixed number can know that. Until it's measured, it's worked out here. */
:root {
  --home-dock-h: 87px;
  --album-dock-h: 143px;
}

@media (min-width: 600px) {
  :root {
    --album-dock-h: 87px;
  }
}

:root:has(.home-dock) {
  scroll-padding-bottom: calc(var(--home-dock-h) + env(safe-area-inset-bottom, 0px));
}

:root:has(.album-dock) {
  scroll-padding-bottom: var(--album-dock-space, calc(var(--album-dock-h) + env(safe-area-inset-bottom, 0px)));
}

/* A toast normally sits just above the bottom safe area (app.css); with a
   fixed dock there too, it would otherwise land on top of or under it. */
body:has(.home-dock) .toast-stack {
  bottom: calc(var(--home-dock-h) + 10px + env(safe-area-inset-bottom, 0px));
}

body:has(.album-dock) .toast-stack {
  bottom: calc(var(--album-dock-space, calc(var(--album-dock-h) + env(safe-area-inset-bottom, 0px))) + 10px);
}

/* While the viewer is open, the album behind it stays put: a vertical drag
   on a phone would otherwise scroll it (and could page in more tiles, or
   make iOS collapse its toolbar and resize the viewer). */
:root:has(.viewer-backdrop) {
  overflow: hidden;
}

/* ---------- sheet: a vertical list of named destinations (Task 14) ----------
   Additive only: a plain .sheet-actions (no list flag) is untouched. */

.sheet-actions-list {
  flex-direction: column;
  gap: 4px;
  max-height: 70vh;
  overflow-y: auto;
}

.sheet-list-item {
  justify-content: flex-start;
  height: 52px;
  font-weight: 500;
}

/* ---------- home (light) ---------- */

.home {
  padding-bottom: calc(var(--home-dock-h) + 8px + env(safe-area-inset-bottom, 0px));
}

.home-head {
  max-width: 720px;
  margin: 0 auto;
  padding: calc(40px + env(safe-area-inset-top, 0px)) calc(20px + env(safe-area-inset-right, 0px)) 0
    calc(20px + env(safe-area-inset-left, 0px));
}

.home-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.home-top .title {
  font-size: 34px;
}

.avatars {
  display: flex;
  flex: none;
  padding-top: 4px;
}

.avatar {
  /* Grown from 32px/13px (the 15px text floor needs a bit more room). */
  width: 36px;
  height: 36px;
  margin-left: -8px;
  border-radius: 50%;
  background: var(--ink);
  color: var(--paper);
  box-shadow: 0 0 0 2px var(--paper);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 650;
}

.avatar:first-child {
  margin-left: 0;
}

.private-line {
  margin-top: 9px;
}

.family-switcher {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

/* A 48px pill (the touch-target floor), rounded like every other 48px
   button here. */
.family-switcher-pill {
  min-height: 48px;
  padding: 6px 16px;
  border: 0;
  border-radius: 24px;
  background: var(--wash);
  color: var(--ink);
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.family-switcher-pill[aria-current='true'] {
  background: var(--ink);
  color: var(--paper);
}

.home-more {
  margin-top: 14px;
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  padding: 0 4px;
  border: 0;
  background: transparent;
  color: var(--ink-quiet);
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
}

.home-empty {
  max-width: 720px;
  margin: 24px auto 0;
  padding: 0 20px;
}

.home-wall {
  margin-top: 20px;
  max-width: 720px;
  margin-left: auto;
  margin-right: auto;
}

.home-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
  margin-top: 2px;
}

.home-dock {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: flex;
  gap: 10px;
  max-width: 720px;
  margin: 0 auto;
  padding: 10px calc(20px + env(safe-area-inset-right, 0px)) calc(20px + env(safe-area-inset-bottom, 0px))
    calc(20px + env(safe-area-inset-left, 0px));
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(18px) saturate(170%);
  -webkit-backdrop-filter: blur(18px) saturate(170%);
  border-top: 1px solid var(--line);
  /* Centred as a pair once each button hits its 280px cap (desktop), and the
     48px New album on the same centre line as the 56px Add photos. */
  justify-content: center;
  align-items: center;
}

.home-dock .btn {
  flex: 1 1 0;
  max-width: 280px;
  white-space: nowrap; /* a label never wraps */
}

/* ---------- album tiles (home) and the album cover (album view): both
   crop to a fixed box (object-fit: cover), unlike the gallery's tiles,
   which keep their exact shape ---------- */

.album-tile {
  position: relative;
  display: block;
  width: 100%;
  height: 168px;
  padding: 0;
  border: 0;
  overflow: hidden;
  background: var(--night-btn);
  color: var(--moon);
  /* A <button> doesn't inherit the page's font by itself: without this its
     label is in the browser's own button font (fix round 2). */
  font: inherit;
  text-align: left;
  cursor: pointer;
}

/* Same reason as .gallery-tile's below: the next tile along (or the grid
   under the big one) would otherwise paint over most of the focus ring. */
.album-tile:focus-visible {
  z-index: 3;
}

.home-hero {
  height: 220px;
}

.home-grid .album-tile {
  height: 150px;
}

.album-tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.album-tile::after {
  content: '';
  position: absolute;
  /* Taller and stronger than the mockup's (inset: 40% 0 0, .74 to .3 to 0),
     with a middle stop that keeps the title's band dark: over a white cover
     (sand, snow, a white wall) a 150px tile's title still gets at least
     4.5:1 at its top edge (home.spec.js measures it). */
  inset: 30% 0 0;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.82), rgba(0, 0, 0, 0.62) 55%, rgba(0, 0, 0, 0));
}

.album-tile-label {
  position: absolute;
  left: 14px;
  right: 10px;
  bottom: 10px;
  z-index: 2;
  /* The mockup's own text-shadow (gallery.html's .lab): extra separation
     from the photo underneath on top of the scrim. */
  text-shadow: 0 1px 10px rgba(0, 0, 0, 0.35);
}

/* One line, as in the mockup (.lab's nowrap): a second line would sit up
   in the scrim's faint part. A long title ends in an ellipsis on screen,
   and the tile's accessible name is still the whole title. */
.album-tile-title {
  font-size: 19px;
  line-height: 1.2;
  color: #ffffff;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.home-hero .album-tile-title {
  font-size: 26px;
}

.album-tile-meta {
  font-size: 15px;
  line-height: 1.4;
  color: rgba(255, 255, 255, 0.85);
  margin: 3px 0 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- the album view (dark) ---------- */

.album-page {
  min-height: 100dvh;
  padding-bottom: var(--album-dock-space, calc(var(--album-dock-h) + env(safe-area-inset-bottom, 0px)));
}

.album-loading,
.album-error {
  padding: calc(40px + env(safe-area-inset-top, 0px)) calc(20px + env(safe-area-inset-right, 0px)) 0
    calc(20px + env(safe-area-inset-left, 0px));
}

.album-error {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 14px;
}

.album-error-title {
  font-size: 24px;
  max-width: 480px;
}

.album-error .btn {
  width: auto;
  padding: 0 28px;
}

.album-cover {
  position: relative;
  height: 280px;
  max-width: 720px;
  margin: 0 auto;
  background: var(--night-btn);
}

.album-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.album-cover::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0.22) 0,
    rgba(0, 0, 0, 0) 24%,
    rgba(0, 0, 0, 0) 34%,
    rgba(10, 10, 11, 0.55) 62%,
    rgba(10, 10, 11, 0.97) 100%
  );
}

.album-cover-empty::after {
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.1) 0, rgba(10, 10, 11, 0.97) 100%);
}

/* The shared .back-link (common.js/people.css) sits inline at the top of a
   plain page there; here it floats over a photo, gallery.html's own way
   (top-left pill, its drop shadow, safe-area insets on a side that can sit
   under a device's rounded corner or notch). */
.album-cover .back-link,
.viewer .back-link {
  position: absolute;
  top: calc(16px + env(safe-area-inset-top, 0px));
  left: calc(12px + env(safe-area-inset-left, 0px));
  z-index: 3;
  margin: 0;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.22);
}

/* The Marigold focus ring (app.css: a 2px outline, 2px out) sits over the
   photo here, where it can be as little as 1.2:1 against a light one. A
   2px night band fills the gap between the pill and its ring, so the ring
   always has a dark edge (Marigold on night is 11.8:1). */
.album-cover .back-link:focus-visible {
  box-shadow: 0 0 0 2px var(--night), 0 4px 14px rgba(0, 0, 0, 0.22);
}

/* .back-link-icon's own size/display is people.css's; this just mirrors it
   for the viewer's Next control (item 3: "the chevron SVG, mirrored for
   Next"), reusing the same icon rather than a second, reversed path. */
.icon-chevron-next {
  transform: scaleX(-1);
}

.album-cover-text {
  position: absolute;
  left: calc(20px + env(safe-area-inset-left, 0px));
  right: calc(20px + env(safe-area-inset-right, 0px));
  bottom: 14px;
  z-index: 3;
  max-width: 640px;
}

.album-cover-text .title {
  font-size: 28px;
  color: var(--moon);
}

.album-cover-text .meta {
  margin-top: 6px;
}

/* The cover's own 720px cap, so its text lines up with the title's. */
.album-addedby {
  max-width: 720px;
  margin: 0 auto;
  padding: 14px calc(20px + env(safe-area-inset-right, 0px)) 0 calc(20px + env(safe-area-inset-left, 0px));
}

/* The toolbar (item 2): below 600px, a row of quiet buttons (Share link,
   Download all) stacked above the one main action (Add photos), so no
   label ever wraps; .album-dock-row's display:contents at 600px+ folds it
   back into one row alongside Add photos, in DOM order. */
.album-dock {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 720px;
  margin: 0 auto;
  padding: 10px calc(16px + env(safe-area-inset-right, 0px)) calc(20px + env(safe-area-inset-bottom, 0px))
    calc(16px + env(safe-area-inset-left, 0px));
  background: rgba(12, 12, 14, 0.9);
  backdrop-filter: blur(20px) saturate(140%);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  border-top: 1px solid var(--night-line);
}

/* flex-wrap: at large text sizes (or a very narrow screen) the two can't
   share a line; each then takes a full-width line of its own, rather than
   running off the dock's edge. album.js measures the taller dock. */
.album-dock-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.album-dock .btn {
  white-space: nowrap; /* a label never wraps */
}

/* The row's own two buttons can always sit side by side, so they're capped
   at all widths; .btn-main stays uncapped here, full width at 56px until
   the dock itself goes row-direction below. */
.album-dock-row .btn {
  flex: 1 1 0;
  max-width: 280px;
  padding: 0 12px;
}

@media (min-width: 600px) {
  .album-dock {
    flex-direction: row;
    justify-content: center;
    /* The 48px pair on the same centre line as the 56px main action. */
    align-items: center;
  }

  .album-dock-row {
    display: contents;
  }

  .album-dock .btn-main {
    flex: 1 1 0;
    max-width: 280px;
  }
}

/* ---------- the justified gallery: pure flex-wrap, no row-grouping JS.
   Every tile's flex-grow equals its own --ar, so the browser's own line
   wrapping gives every tile on a line the same height; the trailing ::after
   (flex: 999) keeps the last, partial line from being stretched to fit. ---------- */

.gallery-grid {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 2px;
  margin-top: 10px;
  /* Ruling 67 (overrides the brief's 150px): at 150px, two landscape photos
     (4:3, 3:2, 16:9) never fit one line at a 375-393px phone width, so each
     one sits alone at roughly 290px tall. 120px lets two 4:3 photos share a
     line and grow to about 145px, closer to the mockup. */
  --row: 120px;
}

@media (min-width: 600px) {
  .gallery-grid {
    --row: 190px;
  }
}

@media (min-width: 1024px) {
  .gallery-grid {
    --row: 230px;
  }
}

.gallery-grid::after {
  content: '';
  flex: 999 1 0;
}

.gallery-tile {
  position: relative;
  display: block;
  flex: var(--ar) 1 calc(var(--ar) * var(--row));
  min-width: 0;
  aspect-ratio: var(--ar);
  padding: 0;
  border: 0;
  background: var(--night-btn);
  /* Same as .album-tile: the duration badge and placeholder text otherwise
     use the browser's own button font. */
  font: inherit;
  overflow: hidden;
  cursor: zoom-in;
}

.gallery-tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Without this, a focused tile's own outline can be visually covered by the
   next sibling tile along the same line (plain sibling order, no z-index,
   so later tiles paint over earlier ones' overflow at the shared edge). */
.gallery-tile:focus-visible {
  z-index: 3;
}

.gallery-placeholder {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--moon-quiet);
  font-size: 15px;
}

.gallery-dur {
  position: absolute;
  right: 6px;
  bottom: 6px;
  z-index: 2;
  height: 24px;
  padding: 0 9px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.6);
  color: #ffffff;
  /* The 15px text floor: grown from 22/13px so the badge still fits it. */
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
}

.gallery-sentinel {
  height: 1px;
}

/* Both sit inside .gallery-status, the paging state's live region
   (gallery.js), which is always in the page and takes no room when empty. */
.gallery-error,
.gallery-loading {
  margin-top: 16px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
}

.gallery-error .btn {
  width: auto;
  padding: 0 28px;
}

/* ---------- the full-screen viewer ---------- */

.viewer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--night);
  overscroll-behavior: contain;
}

.viewer {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.viewer-stage {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Two declarations on purpose: a browser that doesn't understand the
     multi-value syntax drops the whole second line and keeps the first
     (pan-y only) rather than ignoring touch-action entirely. */
  touch-action: pan-y;
  touch-action: pan-y pinch-zoom;
}

.viewer-media {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.viewer-placeholder {
  color: var(--moon-quiet);
  font-size: 16px;
  text-align: center;
  padding: 0 24px;
}

/* Position and dark colouring for the viewer's own back pill: `.viewer
   .back-link` (two classes) outweighs people.css's plain `.back-link` (one
   class) regardless of which stylesheet loads last. Layout (top, left,
   safe-area, z-index) is shared with the album cover's own back pill,
   above; only the colours and shadow differ here. */
.viewer .back-link {
  background: var(--night-btn);
  box-shadow: inset 0 0 0 1px var(--night-line);
  color: var(--moon);
}

/* The same night band as the album cover's back pill: a wide photo (3:2 or
   wider on desktop, most photos on a phone) runs under these controls. */
.viewer .back-link:focus-visible,
.viewer-nav:focus-visible {
  box-shadow: inset 0 0 0 1px var(--night-line), 0 0 0 2px var(--night);
}

/* Its own night pill, like the controls around it: a photo that reaches
   the top-right corner would otherwise leave this text at about 2:1. Its
   centre lines up with the 48px back pill's. */
.viewer-counter {
  position: absolute;
  top: calc(24px + env(safe-area-inset-top, 0px));
  right: calc(16px + env(safe-area-inset-right, 0px));
  z-index: 5;
  height: 32px;
  margin: 0;
  padding: 0 12px;
  display: flex;
  align-items: center;
  border-radius: 16px;
  background: var(--night-btn);
  box-shadow: inset 0 0 0 1px var(--night-line);
  color: var(--moon-quiet);
  font-size: 15px;
}

/* Paging news ("Loading more photos...", "Couldn't load more photos."), a
   night pill under the top controls, centred. It sits at the top because a
   video's own controls are at the bottom of the stage; left and right are
   both set (rather than left: 50% and a transform) so it has the whole
   width to fit one line on a 390px phone. Always in the page as a live
   region; empty, it has no box at all. */
.viewer-note {
  position: absolute;
  top: calc(80px + env(safe-area-inset-top, 0px));
  left: calc(16px + env(safe-area-inset-left, 0px));
  right: calc(16px + env(safe-area-inset-right, 0px));
  z-index: 5;
  width: fit-content;
  margin: 0 auto;
  color: var(--moon);
  font-size: 15px;
  text-align: center;
}

.viewer-note:not(:empty) {
  padding: 8px 16px;
  border-radius: 18px;
  background: var(--night-btn);
  box-shadow: inset 0 0 0 1px var(--night-line);
}

/* Read out, not shown: the stage already shows the same words. */
.viewer-announce {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.viewer-nav {
  position: absolute;
  top: 50%;
  z-index: 5;
  width: 48px;
  height: 48px;
  margin-top: -24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 24px;
  background: var(--night-btn);
  box-shadow: inset 0 0 0 1px var(--night-line);
  color: var(--moon);
  cursor: pointer;
}

.viewer-prev {
  left: calc(12px + env(safe-area-inset-left, 0px));
}

.viewer-next {
  right: calc(12px + env(safe-area-inset-right, 0px));
}

.viewer-nav:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.viewer-fallback {
  width: 100%;
  height: 100%;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 0 24px;
  text-align: center;
}

.viewer-fallback-poster {
  position: absolute;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  /* contain, not cover (item 3): it fills the stage without ever cropping
     into a poster that might be a very different shape from the screen. */
  object-fit: contain;
  opacity: 0.4;
}

.viewer-fallback .meta {
  position: relative;
  z-index: 1;
  color: var(--moon);
  max-width: 420px;
}

.viewer-fallback .btn {
  position: relative;
  z-index: 1;
  width: auto;
  padding: 0 28px;
  /* It's an <a>, not a <button> (a real download link): undo the browser's
     own underline, which .btn (app.css) never had to think about before. */
  text-decoration: none;
}
