/* Mio — evening-walk palette: misty sky, dusk ink, one golden-hour accent. */
:root {
  --ink: #1f2a3a;
  --dusk: #3b4f6b;
  --muted: #637083;
  --sky: #e9eef2;
  --paper: #fbfcfd;
  --line: #d5dde5;
  --gold: #e3a24a;
  --gold-deep: #b9771f;
  --danger: #a8402f;
  --ok: #3d7a57;

  --display: "Young Serif", Georgia, serif;
  --text: "Atkinson Hyperlegible", system-ui, sans-serif;

  --radius-s: 6px;
  --radius-m: 12px;
  --measure: 36rem;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--sky);
  color: var(--ink);
  font-family: var(--text);
  font-size: 1.0625rem;
  line-height: 1.55;
}
/* Scattered bones and paw prints. One transparent tile used as a mask, so each area can tint it
   to suit: dusk-blue on the light page, light on the dusk and morning headers. */
body { position: relative; }
body::before, .hero::before {
  content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none;
  background-color: var(--paw-color, var(--dusk));
  opacity: var(--paw-opacity, .07);
  -webkit-mask: url(/img/paws.webp) repeat 0 0 / 750px auto;
  mask: url(/img/paws.webp) repeat 0 0 / 750px auto;
}
@media (max-width: 600px) {
  body::before, .hero::before { -webkit-mask-size: 480px auto; mask-size: 480px auto; }
}
.hero { position: relative; isolation: isolate; --paw-color: #fff; --paw-opacity: .05; }
body.living .hero { --paw-color: #fff; --paw-opacity: .55; }

img, video { display: block; max-width: 100%; }
a { color: var(--dusk); }
h1, h2, h3 { font-family: var(--display); font-weight: 400; line-height: 1.15; margin: 0; }
h2 { font-size: 1.6rem; }
p { margin: 0; }

:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

.wrap { max-width: 72rem; margin: 0 auto; padding: 0 16px; }

/* ── Buttons & fields ─────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  min-height: 48px; padding: .7rem 1.4rem;
  font: 700 1rem/1 var(--text);
  border-radius: 999px; border: 2px solid transparent;
  cursor: pointer; text-decoration: none;
  transition: background-color .15s, transform .1s;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--gold); color: var(--ink); }
.btn-primary:hover { background: #eaae5c; }
.btn-primary:disabled { background: var(--line); color: var(--muted); cursor: default; }
.btn-quiet { background: transparent; color: var(--dusk); border-color: var(--line); }
.btn-quiet:hover { background: var(--paper); }
.btn-small { min-height: 36px; padding: .45rem .9rem; font-size: .9rem; }

label { display: block; font-weight: 700; margin-bottom: .35rem; }
.hint { font-weight: 400; color: var(--muted); font-size: .92rem; }
input[type=text], input[type=password], select, textarea {
  width: 100%; min-height: 48px; padding: .7rem .85rem;
  font: 1.0625rem/1.4 var(--text); color: var(--ink);
  background: var(--paper); border: 1.5px solid var(--line); border-radius: var(--radius-s);
}
textarea { min-height: 7rem; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--dusk); outline: none; box-shadow: 0 0 0 3px rgba(59,79,107,.18); }
.field { margin-bottom: 1.1rem; }
.error { color: var(--danger); font-weight: 700; }

/* ── Hero ─────────────────────────────────────────── */
/* Mio's portrait is shown whole, like a framed photo on the mantel, with the sunset in it
   echoed by a low golden glow on the dusk background. */
.hero {
  background:
    radial-gradient(ellipse 70% 60% at 30% 100%, rgba(227,162,74,.28), rgba(227,162,74,0) 70%),
    var(--dusk);
  color: var(--paper);
}
.hero-inner { max-width: 72rem; margin: 0 auto; }
.portrait { margin: 0; }
.portrait > img { width: 100%; height: auto; }
.hero .portrait > img { opacity: 0; transition: opacity 1.1s ease; }
.hero .portrait > img.loaded { opacity: 1; }
.hero-copy { padding: 1.6rem 16px 2.4rem; }

@media (min-width: 820px) {
  .hero-inner { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 3.5rem; padding: 3rem 24px; }
  .portrait > img {
    width: auto; max-height: min(84vh, 52rem); max-width: min(52vw, 40rem);
    border: 10px solid var(--paper); border-radius: 3px;
    box-shadow: 0 18px 50px rgba(13,18,26,.45);
    transform: rotate(-1.2deg);
  }
  .hero-copy { padding: 0; max-width: 32rem; }
}

.hero-name {
  font-family: var(--display);
  font-size: clamp(4rem, 14vw, 7rem);
  line-height: .9;
  margin: 0 0 .6rem;
}
/* Visually hidden while the lettered portrait is the hero; still read by screen readers. */
.hero:not(.has-cover) .hero-name {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}
.hero-dates { font-family: var(--display); font-size: 1.6rem; color: #f3d7ad; }
.hero-tagline { font-family: var(--display); font-size: 1.3rem; margin-top: .2rem; }
.hero-tribute { margin-top: 1.1rem; max-width: var(--measure); font-size: 1.15rem; line-height: 1.7; white-space: pre-line; color: #e7edf3; }
.hero-tribute:empty, .hero-dates:empty, .hero-tagline:empty { display: none; }

.hero-label { font-family: var(--display); font-size: 1.5rem; line-height: 1.2; color: #f3d7ad; margin-bottom: .6rem; }
.hero-family { font-size: 1.05rem; color: #c7d2de; margin-bottom: .5rem; }
.hero-label:empty, .hero-family:empty { display: none; }

.btn-ghost { background: transparent; color: var(--paper); border-color: rgba(251,252,253,.4); }
.btn-ghost:hover { background: rgba(251,252,253,.1); }

/* No portrait yet: a paw on a soft panel, same footprint as a photo. */
.portrait-empty {
  display: grid; place-items: center; aspect-ratio: 4 / 5; width: 100%;
  background: linear-gradient(160deg, rgba(255,255,255,.18), rgba(255,255,255,.04));
}
.portrait-empty img { width: 30%; opacity: .85; }
@media (min-width: 820px) {
  .hero .portrait-empty { width: 22rem; border: 10px solid var(--paper); border-radius: 3px; box-shadow: 0 18px 50px rgba(13,18,26,.35); }
}

/* Living pets: the same page in morning light instead of dusk. */
body.living .hero {
  background:
    radial-gradient(ellipse 60% 70% at 85% 0%, rgba(255,214,140,.65), rgba(255,214,140,0) 70%),
    linear-gradient(180deg, #bfe0f2 0%, #e4f1f8 100%);
  color: var(--ink);
}
body.living .hero-name { color: var(--ink); }
body.living .hero-dates { color: var(--gold-deep); }
body.living .hero-family { color: var(--dusk); }
body.living .hero-tribute { color: var(--ink); }
body.living .btn-ghost { color: var(--dusk); border-color: rgba(59,79,107,.35); }
body.living .btn-ghost:hover { background: rgba(255,255,255,.45); }
body.living .portrait-empty { background: linear-gradient(160deg, #fff6e6, #ffe2b3); }
body.living .story { border-left-color: #8cc0dd; }
body.living .topnav { background: #bfe0f2; }
body.living .topnav a { color: var(--dusk); }

.topnav { background: var(--dusk); padding: .7rem 16px; }
.topnav a { color: #e7edf3; font-weight: 700; text-decoration: none; }
.topnav a:hover { text-decoration: underline; }

.edit-hint { background: #fff4e0; border-left: 4px solid var(--gold); padding: .7rem .9rem; border-radius: var(--radius-s); margin-bottom: 1rem; font-size: .95rem; }

/* ── Page owner's panel ──────────────────────────── */
.manage { padding-bottom: 0; }
.manage-unlock summary { cursor: pointer; color: var(--muted); font-size: .95rem; text-decoration: underline; width: max-content; }
.manage-unlock form { margin-top: .8rem; max-width: 24rem; }
.unlock-row { display: flex; gap: .5rem; margin-top: .4rem; }
.unlock-row input { text-transform: uppercase; letter-spacing: .12em; }
.manage-panel { background: var(--paper); border-radius: var(--radius-m); padding: 1.3rem; max-width: 46rem; border-top: 4px solid var(--gold); }
.manage-panel h2 { margin-bottom: 1rem; }
.check { display: flex; align-items: center; gap: .6rem; font-weight: 700; margin: .2rem 0 .4rem; cursor: pointer; }
.check input { width: 1.3rem; height: 1.3rem; accent-color: var(--dusk); }

/* ── Family page ─────────────────────────────────── */
.family { padding-top: 2.4rem; }
.family-head h1 { font-size: clamp(2.4rem, 8vw, 3.6rem); margin-bottom: .6rem; }
.family-head .lede { max-width: var(--measure); font-size: 1.15rem; }
.pets { display: grid; gap: 2rem 1.2rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 15rem), 1fr)); margin-top: 2.2rem; }
/* Each pet is a print on the table: white border, a slight tilt that straightens on focus. */
.pet-card {
  display: block; text-decoration: none; color: var(--ink);
  background: var(--paper); padding: 10px 10px 0; border-radius: 3px;
  box-shadow: 0 8px 24px rgba(31,42,58,.14);
  transform: rotate(-1deg); transition: transform .2s, box-shadow .2s;
}
.pet-card:nth-child(even) { transform: rotate(1deg); }
.pet-card:hover, .pet-card:focus-visible { transform: rotate(0) translateY(-3px); box-shadow: 0 14px 32px rgba(31,42,58,.2); }
.pet-photo { aspect-ratio: 4 / 5; overflow: hidden; background: var(--sky); }
.pet-photo > img { width: 100%; height: 100%; object-fit: cover; object-position: center 35%; }
.pet-photo .portrait-empty { height: 100%; background: linear-gradient(160deg, #fff6e6, #ffe2b3); }
.pet-card.memorial .pet-photo .portrait-empty { background: linear-gradient(160deg, #5b6f8c, #3b4f6b); }
.pet-caption { display: flex; flex-direction: column; gap: .1rem; padding: .8rem .3rem 1rem; }
.pet-caption strong { font-family: var(--display); font-weight: 400; font-size: 1.6rem; line-height: 1.1; }
.pet-caption span { color: var(--muted); font-size: .95rem; }
.pet-caption .pet-memorial { color: var(--dusk); font-weight: 700; font-size: 1rem; }
.pet-caption .pet-count { font-size: .88rem; }

.lb-meta a { color: #f3d7ad; }
.lb-note {
  width: 100%; min-height: 4.5rem; padding: .6rem .7rem; resize: vertical;
  font: 1rem/1.45 var(--text); color: #eef2f6;
  background: #1b2330; border: 1.5px solid #3a4658; border-radius: var(--radius-s);
}
.lb-note:focus { border-color: #f3d7ad; outline: none; }
.lb-note-actions { display: flex; gap: .5rem; margin-top: .5rem; }
/* The viewer is always dark, even on a living pet's light page. */
.lightbox .lb-note-actions .btn-ghost { color: #eef2f6; border-color: rgba(255,255,255,.35); }
.lightbox .lb-note-actions .btn-ghost:hover { background: rgba(255,255,255,.1); }

.tribute-actions { display: flex; flex-wrap: wrap; gap: .7rem; margin-top: 1.6rem; }

/* ── Section headers ─────────────────────────────── */
.section { padding: 2.4rem 0 1rem; }
.section-head { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: .8rem 1.2rem; margin-bottom: 1rem; }
.section-head .count { color: var(--muted); }

.chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip {
  min-height: 38px; padding: .4rem .9rem; border-radius: 999px;
  border: 1.5px solid var(--line); background: var(--paper); color: var(--dusk);
  font: 700 .92rem/1 var(--text); cursor: pointer;
}
.chip[aria-pressed=true] { background: var(--dusk); border-color: var(--dusk); color: var(--paper); }

/* ── Gallery: justified rows, like a photo app ──────
   Each tile keeps its photo's real shape (--r = width / height), so nothing is cropped.
   Tiles grow in proportion to their shape, which keeps every row one even height. */
.grid { --row: 100px; display: flex; flex-wrap: wrap; gap: 4px; }
@media (min-width: 640px) { .grid { --row: 150px; } }
@media (min-width: 1000px) { .grid { --row: clamp(170px, 13vw, 260px); } }
/* The album spreads out to the window's width on big screens (the rest of the page keeps its reading width). */
.album-wide { width: calc(100vw - 48px); max-width: 120rem; position: relative; left: 50%; transform: translateX(-50%); }
@media (max-width: 640px) { .album-wide { width: 100%; left: 0; transform: none; } }
/* Stops a short last row from stretching across the page. */
.grid::after { content: ""; flex-grow: 999; }
.tile {
  --r: 1;
  position: relative; padding: 0; border: 0; background: #cfd8e1;
  cursor: pointer; overflow: hidden;
  flex: var(--r) 1 calc(var(--r) * var(--row));
  aspect-ratio: var(--r);
  max-width: 100%;
}
.tile img { width: 100%; height: 100%; object-fit: cover; }
.tile .star {
  position: absolute; left: 6px; top: 6px;
  background: rgba(31,42,58,.72); color: #f3d7ad; border-radius: 999px;
  padding: .1rem .45rem; font: 700 .8rem/1.4 var(--text);
}
.grid > .empty { flex-basis: 100%; }
.tile .badge {
  position: absolute; right: 6px; bottom: 6px;
  background: rgba(31,42,58,.72); color: #fff; border-radius: 999px;
  padding: .15rem .5rem; font: 700 .78rem/1.4 var(--text);
}
.tile.pending { display: grid; place-items: center; color: var(--dusk); font-size: .85rem; padding: .5rem; text-align: center; cursor: default; }
.tile.failed { color: var(--danger); }
.empty { background: var(--paper); border: 1.5px dashed var(--line); border-radius: var(--radius-m); padding: 2rem 1.2rem; text-align: center; color: var(--muted); }
.empty .btn { margin-top: 1rem; }

/* ── Stories ─────────────────────────────────────── */
.stories { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 22rem), 1fr)); align-items: start; }
.story { background: var(--paper); border-radius: var(--radius-s); padding: 1.3rem 1.3rem 1.1rem; border-left: 4px solid var(--gold); }
.story p { white-space: pre-line; font-size: 1.08rem; line-height: 1.65; }
.story .by { margin-top: .8rem; color: var(--muted); font-size: .95rem; display: flex; justify-content: space-between; gap: .5rem; align-items: center; }
.story .by strong { color: var(--ink); }
.link-btn { background: none; border: 0; padding: .25rem; color: var(--muted); text-decoration: underline; font: inherit; font-size: .88rem; cursor: pointer; }

.story-form { background: var(--paper); border-radius: var(--radius-m); padding: 1.3rem; margin-bottom: 1.2rem; max-width: 40rem; }
.row { display: grid; gap: 0 1rem; grid-template-columns: 1fr; }
@media (min-width: 560px) { .row { grid-template-columns: 1.4fr 1fr; } }

/* ── Floating share button ───────────────────────── */
.fab {
  position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 20;
  box-shadow: 0 6px 22px rgba(31,42,58,.28);
  transition: opacity .2s, transform .2s;
}
/* Hidden while the header's own button is on screen. */
.fab.is-away { opacity: 0; transform: translateY(12px); pointer-events: none; }

footer.site { padding: 3rem 0 6rem; color: var(--muted); font-size: .92rem; }
footer.site a { color: var(--muted); }

/* ── Lightbox ────────────────────────────────────── */
.lightbox { position: fixed; inset: 0; z-index: 50; background: #0d121a; color: #eef2f6; display: none; flex-direction: column; }
.lightbox.open { display: flex; }
.lb-stage { flex: 1; min-height: 0; display: grid; place-items: center; position: relative; touch-action: pan-y; }
.lb-stage img, .lb-stage video { position: absolute; inset: 0; margin: auto; max-width: 100%; max-height: 100%; object-fit: contain; }
.lb-bar { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .5rem .5rem .5rem 1rem; }
.lb-count { color: #aab6c4; font-size: .92rem; }
.lb-icon {
  min-width: 48px; min-height: 48px; border: 0; border-radius: 999px;
  background: rgba(255,255,255,.08); color: #fff; font-size: 1.4rem; cursor: pointer;
}
.lb-icon:hover { background: rgba(255,255,255,.16); }
.lb-nav { position: absolute; top: 50%; transform: translateY(-50%); z-index: 1; background: rgba(13,18,26,.6); }
.lb-nav:hover { background: rgba(13,18,26,.85); }
.lb-prev { left: 10px; } .lb-next { right: 10px; }
@media (hover: none) { .lb-nav { display: none; } }
.lb-info { padding: .9rem 1rem calc(1rem + env(safe-area-inset-bottom)); max-width: 48rem; width: 100%; margin: 0 auto; }
.lb-caption { font-size: 1.1rem; margin-bottom: .3rem; white-space: pre-line; }
.lb-meta { color: #aab6c4; font-size: .95rem; }
.lb-actions { display: flex; gap: .6rem; margin-top: .7rem; flex-wrap: wrap; }
.lb-actions a, .lb-actions button { color: #f3d7ad; background: none; border: 0; padding: .3rem 0; font: 700 .95rem var(--text); cursor: pointer; text-decoration: underline; }

/* ── Simple centered card pages (login, share) ───── */
.page-narrow { max-width: 38rem; margin: 0 auto; padding: 2rem 16px 4rem; }
.back { display: inline-block; margin-bottom: 1.2rem; font-weight: 700; text-decoration: none; }
.page-narrow h1 { font-size: clamp(2.2rem, 8vw, 3rem); margin-bottom: .6rem; }
.lede { color: var(--dusk); margin-bottom: 1.6rem; }

.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); z-index: 60;
  background: var(--ink); color: var(--paper); padding: .8rem 1.2rem; border-radius: var(--radius-s);
  font-weight: 700; max-width: calc(100% - 32px);
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
