/* ==========================================================================
   Photos

   A grid that gets out of the way, and a viewer that fills the screen.

   The three colour modes are one CSS filter on a container. Switching is a
   repaint, not a reload — which is the whole reason the modes are usable on
   a phone at all.
   ========================================================================== */

/* The tone is set on <html> so the viewer, which sits outside the gallery
   element, is covered by the same rule. */
:root[data-tone="soft"] .ph-cell img,
:root[data-tone="soft"] .ph-stage img {
  filter: saturate(0.42) sepia(0.32) contrast(1.04);
}

:root[data-tone="mono"] .ph-cell img,
:root[data-tone="mono"] .ph-stage img {
  filter: grayscale(1) contrast(1.06);
}

.ph-cell img,
.ph-stage img {
  transition: filter .35s var(--ease, ease);
}

@media (prefers-reduced-motion: reduce) {
  .ph-cell img, .ph-stage img { transition: none; }
}

/* ---------- The gate ---------- */

.gate-wrap {
  min-height: 60vh;
  display: grid;
  place-items: center;
  padding: var(--space-8) var(--gutter);
}

.gate-card {
  width: 100%;
  max-width: 24rem;
  text-align: center;
  padding: var(--space-8) var(--space-6);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
}

.gate-card__title { margin: 0 0 var(--space-2); font-size: var(--fs-2xl); }
.gate-card__sub { margin: 0 0 var(--space-6); color: var(--text-dim); }

.gate-form { display: grid; gap: var(--space-3); }

.gate-input {
  width: 100%;
  min-height: 3rem;
  padding: 0 var(--space-4);
  text-align: center;
  font-size: var(--fs-lg);
  letter-spacing: 0.18em;
  color: var(--text);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
}

.gate-input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.gate-btn { width: 100%; justify-content: center; }
.gate-error { margin: var(--space-4) 0 0; color: var(--bad); font-size: var(--fs-sm); }

/* ---------- Toolbar ---------- */

.ph-bar {
  position: sticky;
  top: var(--header-h, 0);
  z-index: 20;
  padding: var(--space-4) 0;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.ph-bar__inner { display: grid; gap: var(--space-3); }
.ph-bar__title h1 { margin: 0; font-size: var(--fs-xl); letter-spacing: -0.02em; }
.ph-bar__title p { margin: 2px 0 0; color: var(--text-dim); font-size: var(--fs-sm); }

.ph-bar__tools {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: center;
  justify-content: space-between;
}

.ph-bar__right { display: flex; gap: var(--space-2); align-items: center; }

/* The colour switch. A segmented control: the three options are one
   decision, and showing them together is what makes that obvious. */
.ph-tones {
  display: flex;
  gap: 2px;
  padding: 3px;
  background: var(--surface-2);
  border-radius: var(--r-full);
}

.ph-tone {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 2.5rem;
  padding: 0 var(--space-4);
  border: 0;
  border-radius: var(--r-full);
  background: none;
  color: var(--text-dim);
  font: inherit;
  font-size: var(--fs-sm);
  cursor: pointer;
  transition: background .18s var(--ease, ease), color .18s var(--ease, ease);
}

.ph-tone[aria-pressed="true"] {
  background: var(--surface-1);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* A swatch showing what each option does, so the labels do not have to
   carry the whole explanation. */
.ph-tone__dot {
  width: 14px; height: 14px; flex: none;
  border-radius: 50%;
  background: linear-gradient(135deg, #e8503a, #2f7fd8);
}
.ph-tone__dot--soft { background: linear-gradient(135deg, #c99a6a, #8d7f73); }
.ph-tone__dot--mono { background: linear-gradient(135deg, #e8e8e8, #4a4a4a); }

.ph-select {
  min-height: 2.5rem;
  padding: 0 var(--space-3);
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  font: inherit;
  font-size: var(--fs-sm);
}

.ph-icon {
  width: 2.5rem; height: 2.5rem; flex: none;
  display: grid; place-items: center;
  border: 0; border-radius: var(--r-md);
  background: var(--surface-2);
  color: var(--text-dim);
  cursor: pointer;
  transition: background .18s var(--ease, ease), color .18s var(--ease, ease);
}

.ph-icon svg { width: 18px; height: 18px; fill: currentColor; }
.ph-icon[aria-pressed="true"] { background: var(--accent); color: var(--accent-contrast); }
.ph-icon--light { background: rgba(255,255,255,.10); color: #fff; }
.ph-icon--light:hover { background: rgba(255,255,255,.20); }

.ph-dl { white-space: nowrap; }

/* ---------- Grid ---------- */

.ph-main { padding: var(--space-6) 0 var(--space-10); }

.ph-group + .ph-group { margin-top: var(--space-8); }
.ph-group[hidden] { display: none; }

.ph-group__name {
  margin: 0 0 var(--space-3);
  font-size: var(--fs-md);
  color: var(--text-dim);
  font-weight: 500;
}

/* Tile size is a data attribute rather than three class names so the
   button can cycle it without knowing what the sizes are. */
.ph-grid {
  display: grid;
  gap: var(--space-3);
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
[data-size="s"] .ph-grid { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); }
[data-size="l"] .ph-grid { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }

.ph-cell {
  position: relative;
  margin: 0;
  border-radius: var(--r-md);
  overflow: hidden;
  background: var(--surface-2);
}
.ph-cell[hidden] { display: none; }

.ph-open {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}

.ph-cell img {
  display: block;
  width: 100%;
  height: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  transition: transform .3s var(--ease, ease), filter .35s var(--ease, ease);
}

/* Portrait frames get a taller tile instead of being cropped to a letterbox
   — in this set they are the single portraits, and cropping them to 4:3
   takes someone's head off. */
.ph-cell--tall img { aspect-ratio: 3 / 4; }

.ph-open:hover img { transform: scale(1.04); }
.ph-open:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* The star: quiet until wanted, or until it has been used. */
.ph-fav {
  position: absolute;
  top: 6px; right: 6px;
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border: 0; border-radius: 50%;
  background: rgba(10, 12, 20, .55);
  color: rgba(255,255,255,.75);
  cursor: pointer;
  opacity: 0;
  transition: opacity .18s var(--ease, ease), color .18s var(--ease, ease);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.ph-fav svg { width: 16px; height: 16px; fill: currentColor; }
.ph-cell:hover .ph-fav,
.ph-fav:focus-visible { opacity: 1; }
.ph-cell.is-fav .ph-fav { opacity: 1; color: var(--accent); }

/* Touch has no hover, so the star is always there on a phone. */
@media (hover: none) {
  .ph-fav { opacity: 1; }
}

/* Selection tick */
.ph-tick {
  position: absolute;
  top: 6px; left: 6px;
  width: 26px; height: 26px;
  display: none; place-items: center;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,.85);
  background: rgba(10, 12, 20, .45);
  color: transparent;
}
.ph-tick svg { width: 14px; height: 14px; fill: currentColor; }
.is-picking .ph-tick { display: grid; }
.is-picking .ph-fav { display: none; }
.ph-cell.is-picked .ph-tick { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.ph-cell.is-picked img { transform: scale(.94); }
.ph-cell.is-picked { outline: 3px solid var(--accent); outline-offset: -3px; }

.ph-empty { text-align: center; color: var(--text-mute); padding: var(--space-10) 0; }

/* ---------- Selection bar ---------- */

.ph-sel {
  position: fixed;
  left: 50%; transform: translateX(-50%);
  bottom: calc(1rem + env(safe-area-inset-bottom));
  z-index: 30;
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  box-shadow: var(--shadow-lg);
  max-width: calc(100vw - 2rem);
}
.ph-sel[hidden] { display: none; }
.ph-sel__count { font-size: var(--fs-sm); color: var(--text-dim); white-space: nowrap; }
.ph-sel__cancel, .ph-sel__all {
  border: 0; background: none; color: var(--text-dim);
  font: inherit; font-size: var(--fs-sm); cursor: pointer;
  padding: var(--space-2);
}
.ph-sel .is-off { opacity: .45; pointer-events: none; }

/* ---------- Viewer ---------- */

.ph-view {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: #07080c;
  display: grid;
  grid-template-rows: auto 1fr auto;
}
.ph-view[hidden] { display: none; }
body.ph-locked { overflow: hidden; }

.ph-view__bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-3);
  padding: calc(var(--space-3) + env(safe-area-inset-top)) var(--space-4) var(--space-3);
}
.ph-view__where { color: rgba(255,255,255,.65); font-size: var(--fs-sm); }
.ph-view__acts { display: flex; gap: var(--space-2); }

.ph-stage {
  grid-row: 2;
  margin: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: 0 var(--space-3);
}

.ph-stage img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  /* Lets a phone pinch-zoom the photo without zooming the chrome. */
  touch-action: pinch-zoom;
}

.ph-nav {
  position: absolute;
  top: 50%; transform: translateY(-50%);
  width: 3rem; height: 3rem;
  display: grid; place-items: center;
  border: 0; border-radius: 50%;
  background: rgba(255,255,255,.10);
  color: #fff;
  cursor: pointer;
  z-index: 2;
}
.ph-nav svg { width: 24px; height: 24px; fill: currentColor; }
.ph-nav:hover { background: rgba(255,255,255,.2); }
.ph-nav--prev { left: var(--space-3); }
.ph-nav--next { right: var(--space-3); }

.ph-hint {
  grid-row: 3;
  margin: 0;
  padding: var(--space-3) var(--space-4) calc(var(--space-4) + env(safe-area-inset-bottom));
  text-align: center;
  color: rgba(255,255,255,.35);
  font-size: var(--fs-xs);
}

/* On a phone the arrows are in the way of the photo and swiping is the
   natural move, so they go, and so does the keyboard hint. */
@media (max-width: 40rem) {
  .ph-nav { display: none; }
  .ph-hint { font-size: 11px; }
  .ph-bar__tools { gap: var(--space-2); }
  .ph-tones { width: 100%; }
  .ph-tone { flex: 1; justify-content: center; padding: 0 var(--space-2); }
  .ph-tone__text { display: none; }
  .ph-tone__dot { width: 16px; height: 16px; }
  .ph-bar__right { width: 100%; }
  .ph-select { flex: 1; min-width: 0; }
  .ph-dl { flex: none; }
}

/* Wide screens: the photo gets the room, the chrome stays small. */
@media (min-width: 64rem) {
  .ph-stage { padding: 0 var(--space-10); }
}

/* ==========================================================================
   Added in the second pass: PIN gate, filmstrip, zoom, details, help
   ========================================================================== */

/* ---------- The PIN ---------- */

.gate-mark {
  width: 3rem; height: 3rem;
  margin: 0 auto var(--space-4);
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--accent-wash, var(--surface-1));
  color: var(--accent);
}
.gate-mark svg { width: 24px; height: 24px; fill: currentColor; }

/* One real input sitting invisibly over the boxes that represent it. The
   boxes are decoration; the field is what the browser autofills. */
.pin-wrap { position: relative; height: 4rem; cursor: text; }

.pin-input {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  padding: 0;
  border: 0; background: none;
  color: transparent; caret-color: transparent;
  font-size: 2rem; text-align: center; letter-spacing: 2.6rem; text-indent: 2.6rem;
  z-index: 2;
}
.pin-input:focus { outline: none; }

.pin-boxes {
  position: absolute; inset: 0;
  display: flex; gap: var(--space-2);
  justify-content: center;
  pointer-events: none;
}

.pin-box {
  width: 3.25rem;
  border-radius: var(--r-md);
  background: var(--surface-1);
  border: 2px solid var(--border);
  transition: border-color .15s ease, background .15s ease, transform .15s ease;
  position: relative;
}
.pin-box.is-on { border-color: var(--accent); background: var(--accent-wash, var(--surface-1)); }
.pin-box.is-on::after {
  content: '';
  position: absolute; inset: 0;
  margin: auto;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--accent);
}
.pin-input:focus + .pin-boxes .pin-box.is-next { border-color: var(--accent); }

@media (max-width: 24rem) {
  .pin-box { width: 2.75rem; }
  .pin-input { letter-spacing: 2.2rem; text-indent: 2.2rem; }
}

/* ---------- Download menu ---------- */

.ph-menu { position: relative; }

.ph-menu__list {
  position: absolute;
  right: 0; top: calc(100% + 6px);
  z-index: 40;
  min-width: 15rem;
  padding: var(--space-2);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
}
.ph-menu__list[hidden] { display: none; }
.ph-menu__list a {
  display: block;
  padding: var(--space-3);
  border-radius: var(--r-sm);
  text-decoration: none;
  color: var(--text);
}
.ph-menu__list a:hover { background: var(--surface-2); }
.ph-menu__list b { display: block; font-weight: 500; }
.ph-menu__list span { display: block; color: var(--text-mute); font-size: var(--fs-xs); }

/* ---------- Viewer: loading, zoom, details ---------- */

.ph-stage { position: relative; transition: transform .2s ease, opacity .2s ease; }

.ph-stage img {
  opacity: 0;
  transition: opacity .25s ease, transform .25s ease, filter .35s ease;
  user-select: none; -webkit-user-select: none;
}
.ph-stage img.is-ready { opacity: 1; }
.ph-stage img.is-zoomed { cursor: grab; transition: none; }
.ph-stage.is-zoomed { touch-action: none; }

.ph-spin {
  position: absolute;
  width: 2rem; height: 2rem;
  border: 2px solid rgba(255,255,255,.2);
  border-top-color: rgba(255,255,255,.85);
  border-radius: 50%;
  animation: ph-spin .8s linear infinite;
}
.ph-spin[hidden] { display: none; }
@keyframes ph-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .ph-spin { animation-duration: 2.4s; } }

.ph-side {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: min(20rem, 82vw);
  z-index: 3;
  padding: calc(var(--space-6) + env(safe-area-inset-top)) var(--space-5) var(--space-6);
  background: rgba(12, 14, 20, .94);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  color: #fff;
  overflow-y: auto;
}
.ph-side[hidden] { display: none; }
.ph-side h2 { margin: 0 0 var(--space-4); font-size: var(--fs-md); }
.ph-side dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: var(--space-2) var(--space-4); }
.ph-side dt { color: rgba(255,255,255,.45); font-size: var(--fs-sm); }
.ph-side dd { margin: 0; font-size: var(--fs-sm); }

/* ---------- Filmstrip ---------- */

.ph-strip {
  grid-row: 3;
  display: flex;
  gap: 6px;
  padding: var(--space-2) var(--space-3);
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.ph-strip::-webkit-scrollbar { display: none; }

.ph-strip__item {
  flex: none;
  width: 54px; height: 54px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: var(--r-sm);
  overflow: hidden;
  background: none;
  cursor: pointer;
  opacity: .5;
  transition: opacity .15s ease, border-color .15s ease;
}
.ph-strip__item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ph-strip__item.is-on { opacity: 1; border-color: var(--accent); }
.ph-strip__item:hover { opacity: .85; }

/* The hint sits under the strip now, so the grid gained a row. */
.ph-view { grid-template-rows: auto 1fr auto auto; }
.ph-hint { grid-row: 4; padding-top: 0; }

/* ---------- Shortcuts ---------- */

.ph-help {
  position: fixed; inset: 0; z-index: 70;
  display: grid; place-items: center;
  padding: var(--gutter);
  background: rgba(6, 8, 12, .72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.ph-help[hidden] { display: none; }

.ph-help__card {
  width: 100%; max-width: 27rem;
  padding: var(--space-6);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  max-height: 86vh; overflow-y: auto;
}
.ph-help__card h2 { margin: 0 0 var(--space-4); font-size: var(--fs-lg); }
.ph-help__card dl {
  margin: 0 0 var(--space-5);
  display: grid; grid-template-columns: auto 1fr;
  gap: var(--space-3) var(--space-4);
  align-items: baseline;
}
.ph-help__card dt {
  font-family: var(--ff-mono); font-size: var(--fs-sm);
  padding: 2px 8px; border-radius: var(--r-sm);
  background: var(--surface-2); color: var(--text);
  white-space: nowrap; justify-self: start;
}
.ph-help__card dd { margin: 0; color: var(--text-dim); font-size: var(--fs-sm); }
.ph-help__touch { color: var(--text-mute); font-size: var(--fs-sm); margin: 0 0 var(--space-5); }
.ph-help__card .btn { width: 100%; justify-content: center; }

/* Keyboard shortcuts are not a thing on a touch device. */
@media (hover: none) {
  .ph-help__card dl { display: none; }
}

/* ---------- Phones ---------- */

@media (max-width: 40rem) {
  .ph-strip__item { width: 44px; height: 44px; }
  .ph-side { width: 100%; }
  .ph-menu__list { right: auto; left: 0; }
  /* The viewer chrome is thumb-sized and out of the photo's way. */
  .ph-view__acts .ph-icon { width: 2.75rem; height: 2.75rem; }
}

/* Short landscape phones: the strip costs more than it gives. */
@media (max-height: 26rem) {
  .ph-strip, .ph-hint { display: none; }
  .ph-view { grid-template-rows: auto 1fr; }
}
