/* media.css: voice player, photo tiles, the lightbox (web/js/media.js, SPEC §11) and portraits
   (SPEC-TREE §12).
   Loaded by index.html after the inline <style>, after drawer.css, family.css and leave.css.
   Tokens come from :root (--bg --fg --dim --faint --sans --mono); literal fallbacks keep the page
   legible if a token is missing. Person color reaches only played bars, marks, names and the 1 px
   rule on photo items, through --c set per element by media.js. Never on buttons or backgrounds. */

/* ------------------------------------------------------------------ voice player (.vp) */

/* One row: button · bars · time. The bars column shrinks (bars thin to 1 px) before the row wraps;
   the error line spans the row below. */
.vp {
  --c: var(--fg, #1F2878);
  display: grid;
  grid-template-columns: 32px minmax(0, max-content) max-content;
  justify-content: start;
  align-items: center;
  gap: 6px 12px;
  min-height: 44px;
  max-width: 100%;
  color: var(--fg, #1F2878);
}
@media (max-width: 420px) { .vp { column-gap: 10px; } }

.vp-btn {
  -webkit-appearance: none;
  appearance: none;
  position: relative;
  flex: none;
  display: inline-grid;
  place-items: center;
  box-sizing: border-box;
  width: 32px;
  height: 32px;
  margin: 0;
  padding: 0;
  border: 1px solid var(--dim, #5D618C);
  border-radius: 50%;
  background: transparent;
  color: var(--fg, #1F2878);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
/* 44 px touch target around the 32 px circle */
.vp-btn::before { content: ''; position: absolute; inset: -6px; border-radius: 50%; }
.vp-btn svg { display: block; width: 12px; height: 12px; pointer-events: none; }
.vp-btn:hover, .vp-btn:focus-visible { border-color: var(--fg, #1F2878); outline: none; }
.vp-btn:focus-visible { box-shadow: 0 0 0 2px var(--bg, #F1E6D3), 0 0 0 3px var(--fg, #1F2878); }
.vp.is-loading .vp-btn { animation: vp-wait 1.1s ease-in-out infinite; }
@keyframes vp-wait { 50% { border-color: var(--faint, #1F2878); } }

/* 48 bars, 2 px wide with a 2 px gap; heights are set by media.js (2 + peak/255 · 20 px). */
.vp-bars {
  display: flex;
  align-items: center;
  gap: 2px;
  box-sizing: border-box;
  height: 28px;
  min-width: 0;
  overflow: hidden;
  padding: 0 2px;
  cursor: pointer;
  outline: none;
  touch-action: pan-y;   /* taps and sideways drags seek; vertical swipes still scroll the drawer */
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.vp-bars:focus-visible { box-shadow: 0 0 0 1px var(--fg, #1F2878); }
.vp-bar {
  flex: 0 1 2px;
  width: 2px;
  min-width: 1px;
  height: 2px;
  background: var(--dim, #5D618C);
  pointer-events: none;
}
.vp-bar.on { background: var(--c); }

.vp-time {
  font: 300 10px/1 var(--mono, 'IBM Plex Mono', ui-monospace, Menlo, monospace);
  letter-spacing: .08em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  color: var(--dim, #5D618C);
}
.vp.is-playing .vp-time { color: var(--fg, #1F2878); }

.vp-err {
  grid-column: 1 / -1;
  width: 0;          /* takes the row's width without widening the columns above it */
  min-width: 100%;
  font: 300 12px/1.5 var(--sans, 'Zen Kaku Gothic New', system-ui, sans-serif);
  color: var(--dim, #5D618C);
}
.vp-err[hidden] { display: none; }

/* ------------------------------------------------------------------ photo frames (.ph) */

.ph {
  -webkit-appearance: none;
  appearance: none;
  position: relative;
  display: block;
  box-sizing: border-box;
  width: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  overflow: hidden;
  background: transparent;   /* paper: the tile before its photo arrives (no tint) */
  color: inherit;
  font: inherit;
  text-align: left;
}
button.ph { cursor: zoom-in; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
button.ph:focus-visible { outline: 1px solid var(--fg, #1F2878); outline-offset: 2px; }
.ph-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity .24s ease;
  -webkit-user-drag: none;
  -webkit-user-select: none;
  user-select: none;
}
.ph.is-loaded .ph-img { opacity: 1; }
.ph.is-failed .ph-img { display: none; }
.ph-msg {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 12px;
  font: 300 12px/1.5 var(--sans, 'Zen Kaku Gothic New', system-ui, sans-serif);
  color: var(--dim, #5D618C);
  text-align: center;
}

/* ------------------------------------------------------------------ PHOTOS section (.phg) */
/* First photo at full inner width (ratio clamped to 4:5 by media.js); the rest in 2 columns of
   square crops with captions clamped to 2 lines. */

.phg { display: flex; flex-direction: column; gap: 20px; }
.phg-rest {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px 12px;
}
.phg-item { --c: var(--dim, #5D618C); min-width: 0; }
.phg-attr {
  margin-top: 10px;
  padding-left: 10px;
  border-left: 1px solid var(--c);
}
.phg-tile .phg-attr { margin-top: 8px; }
.phg-by {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0 6px;
  font: 300 10px/1.7 var(--mono, 'IBM Plex Mono', ui-monospace, Menlo, monospace);
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--dim, #5D618C);
}
.phg-name { color: var(--c); opacity: 1; }
.phg-years, .phg-added { color: var(--dim, #5D618C); }
.phg-new {
  color: var(--fg, #1F2878);
  font-size: 9px;
  letter-spacing: .16em;
  animation: phg-new-fade .6s ease 3s forwards;
}
@keyframes phg-new-fade { to { opacity: 0; } }
.phg-cap {
  margin: 4px 0 0;
  font: 300 14px/1.55 var(--sans, 'Zen Kaku Gothic New', system-ui, sans-serif);
  color: var(--fg, #1F2878);
  overflow-wrap: anywhere;
}
.phg-tile .phg-cap {
  font-size: 13px;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
}
.phg-demo {
  margin-top: 4px;
  font: 300 9px/1.4 var(--mono, 'IBM Plex Mono', ui-monospace, Menlo, monospace);
  letter-spacing: .16em;
  color: var(--dim, #5D618C);
}

/* ------------------------------------------------------------------ lightbox (#lightbox) */

#lightbox {
  position: fixed;
  inset: 0;
  z-index: 120;   /* above the drawer, peek bar and HUD */
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  box-sizing: border-box;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
  background: var(--bg, #F1E6D3);   /* opaque paper (§21.5) */
  color: var(--fg, #1F2878);
  overscroll-behavior: contain;
  animation: lb-in .16s ease-out;
}
#lightbox[hidden] { display: none !important; }
@keyframes lb-in { from { opacity: 0; } }

.lb-head {
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 56px;
  padding: 6px 8px 6px 24px;
  font: 300 10px/1.4 var(--mono, 'IBM Plex Mono', ui-monospace, Menlo, monospace);
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--dim, #5D618C);
}
.lb-label {
  flex: 1 1 auto;
  min-width: 0;
  overflow-wrap: anywhere;   /* wraps to a second line on phones rather than hiding the place */
}
.lb-who { display: inline-flex; align-items: center; gap: 6px; vertical-align: -1px; white-space: nowrap; }
.lb-name { opacity: 1; }
.lb-count { flex: none; font-variant-numeric: tabular-nums; }
.lb-count[hidden] { display: none; }
.lb-close {
  -webkit-appearance: none;
  appearance: none;
  flex: none;
  width: 44px;
  height: 44px;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--fg, #1F2878);
  font: 300 24px/1 var(--mono, 'IBM Plex Mono', ui-monospace, Menlo, monospace);
  cursor: pointer;
  touch-action: manipulation;
}
.lb-close { text-align: center; }
.lb-close:hover { text-decoration: underline; }
.lb-close:focus-visible, .lb-nav:focus-visible { outline: 1px solid var(--fg, #1F2878); outline-offset: -4px; }

.lb-stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  overflow: hidden;
  touch-action: none;   /* swipes are ours */
  -webkit-user-select: none;
  user-select: none;
}
.lb-img {
  display: block;
  width: auto;
  height: auto;
  max-width: 92vw;
  max-height: min(78vh, 100%);
  object-fit: contain;
  opacity: 0;
  transition: opacity .2s ease;
  -webkit-user-drag: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
#lightbox.is-loaded .lb-img { opacity: 1; }
/* the photo in a hairline (§21.5) */
#lightbox .lb-img { border: 1px solid var(--fg, #1F2878); }
#lightbox.is-failed .lb-img { display: none; }
.lb-msg {
  position: absolute;
  left: 24px;
  right: 24px;
  top: 50%;
  transform: translateY(-50%);
  font: 300 13px/1.5 var(--sans, 'Zen Kaku Gothic New', system-ui, sans-serif);
  color: var(--dim, #5D618C);
  text-align: center;
}
.lb-msg[hidden] { display: none; }

.lb-nav {
  -webkit-appearance: none;
  appearance: none;
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 52px;
  height: 80px;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--fg, #1F2878);
  font: 300 32px/1 var(--mono, 'IBM Plex Mono', ui-monospace, Menlo, monospace);
  cursor: pointer;
  touch-action: manipulation;
}
.lb-prev { left: 8px; }
.lb-next { right: 8px; }
.lb-nav:hover:not(:disabled), .lb-nav:focus-visible { text-decoration: underline; }
.lb-nav:disabled { color: var(--dim, #5D618C); cursor: default; }
.lb-nav[hidden] { display: none; }

.lb-foot {
  padding: 12px 24px 24px;
  text-align: center;
}
.lb-cap {
  max-width: 640px;
  max-height: 24vh;
  margin: 0 auto;
  overflow: auto;
  font: 300 15px/1.55 var(--sans, 'Zen Kaku Gothic New', system-ui, sans-serif);
  color: var(--fg, #1F2878);
  overflow-wrap: anywhere;
}
.lb-cap[hidden], .lb-note[hidden] { display: none; }
.lb-note {
  margin-top: 8px;
  font: 300 9px/1.4 var(--mono, 'IBM Plex Mono', ui-monospace, Menlo, monospace);
  letter-spacing: .16em;
  color: var(--dim, #5D618C);
}

@media (max-width: 699px) {
  .lb-head { padding-left: 16px; }
  .lb-foot { padding: 10px 16px 20px; }
  .lb-nav { width: 44px; height: 64px; font-size: 26px; }
  .lb-prev { left: 0; }
  .lb-next { right: 0; }
  .lb-cap { font-size: 14px; }
}

/* ------------------------------------------------------------------ portraits (SPEC-TREE §12) */

/* A person's round thumb in a 1.5 px ring of their color (media.js portraitEl), where their mark
   would be: tree nodes and FAMILY rows. The faint disc shows until the image has loaded. */
.pt {
  position: relative;
  display: inline-block;
  flex: none;
  box-sizing: border-box;
  overflow: hidden;
  border: 1.5px solid var(--c, var(--dim, #5D618C));
  border-radius: 50%;
  background: transparent;
  vertical-align: middle;
}
.pt-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 30%;
  opacity: 0;
  transition: opacity .2s ease-out;
}
.pt-img.is-loaded { opacity: 1; }

/* the hidden picker behind "add a photo" (media.js imageInput): camera or library, one image */
.wf-file {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
  pointer-events: none;
  clip: rect(0 0 0 0);
}

/* ------------------------------------------------------------------ reduced motion */

@media (prefers-reduced-motion: reduce) {
  #lightbox { animation: none; }
  .lb-img, .ph-img, .pt-img { transition: none; }
  .vp.is-loading .vp-btn { animation: none; }
  .phg-new { animation: none; }
}
#lightbox.lb-still { animation: none; }
