:root {
  --bg: #f8f4ed;
  --paper: #fffdf9;
  --text: #2a2521;
  --muted: #6c6258;
  --accent: #8a6a32;
  --accent-dark: #6a5025;
  --line: #e6ddcf;
  --tint: #f2ebdf;
  --danger: #a3403a;
  --ok: #3d6b45;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --sans: "Segoe UI", -apple-system, BlinkMacSystemFont, Helvetica, Arial, sans-serif;
  --radius: 12px;
}

* { box-sizing: border-box; }
html { font-size: 18px; -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--sans); line-height: 1.55; }
img { max-width: 100%; height: auto; }
a { color: var(--accent-dark); }

/* ---- header / nav ---- */
.site-header { background: var(--paper); border-bottom: 1px solid var(--line); }
.site-header .inner { max-width: 760px; margin: 0 auto; padding: 0.9rem 1rem 0.6rem; }
.site-title { font-family: var(--serif); font-size: 1.45rem; margin: 0; letter-spacing: 0.01em; }
.site-title a { color: var(--text); text-decoration: none; }
.site-nav { display: flex; flex-wrap: wrap; gap: 0.3rem; padding: 0.55rem 0 0.1rem; }
.site-nav a {
  flex-shrink: 0; text-decoration: none; color: var(--muted); font-size: 0.92rem;
  padding: 0.35rem 0.75rem; border-radius: 999px; border: 1px solid transparent; white-space: nowrap;
}
.site-nav a:hover { color: var(--text); background: var(--tint); }
.site-nav a[aria-current="page"] { color: var(--accent-dark); border-color: var(--line); background: var(--tint); font-weight: 600; }

main { max-width: 760px; margin: 0 auto; padding: 1.2rem 1rem 4rem; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.25; }
h2 { font-size: 1.55rem; margin: 0.4rem 0 0.8rem; }
h3 { font-size: 1.2rem; margin: 0 0 0.5rem; }
.lead { font-size: 1.08rem; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 0.86rem; }
.center { text-align: center; }

.card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.2rem; margin-bottom: 1rem; }
.note { background: var(--tint); border-radius: var(--radius); padding: 0.85rem 1rem; }
.error-box { background: #fbeeec; color: var(--danger); border: 1px solid #ecc9c4; border-radius: var(--radius); padding: 0.75rem 1rem; margin-bottom: 1rem; }

.btn {
  display: inline-block; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; text-align: center;
  background: var(--accent); color: #fff; border: 1px solid var(--accent); border-radius: 999px; padding: 0.6rem 1.25rem;
}
.btn:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn.secondary { background: var(--paper); color: var(--accent-dark); border-color: var(--line); }
.btn.secondary:hover { background: var(--tint); }
.btn.danger { background: var(--paper); color: var(--danger); border-color: #ecc9c4; }
.btn.small { font-size: 0.84rem; padding: 0.3rem 0.75rem; font-weight: 600; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-row { display: flex; flex-wrap: wrap; gap: 0.6rem; }

label { display: block; font-weight: 600; margin: 1rem 0 0.35rem; }
input[type="text"], input[type="email"], input[type="password"], input[type="date"], textarea, select {
  width: 100%; font: inherit; color: var(--text); background: #fff; border: 1px solid var(--line);
  border-radius: 10px; padding: 0.6rem 0.7rem;
}
textarea { min-height: 9rem; resize: vertical; line-height: 1.5; }
input:focus, textarea:focus, select:focus, .btn:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* switch */
.switch { display: flex; align-items: flex-start; gap: 0.75rem; margin-top: 1.1rem; font-weight: normal; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { flex-shrink: 0; width: 3rem; height: 1.7rem; border-radius: 999px; background: #cfc5b6; position: relative; transition: background 0.15s; margin-top: 0.1rem; }
.switch .track::after { content: ""; position: absolute; top: 0.2rem; left: 0.2rem; width: 1.3rem; height: 1.3rem; border-radius: 50%; background: #fff; transition: transform 0.15s; box-shadow: 0 1px 2px rgba(0,0,0,0.2); }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(1.3rem); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch .label-text strong { display: block; }

/* hidden spam-trap field */
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

/* ---- home ---- */
.hero { text-align: center; padding: 0.6rem 0 0.2rem; }
.hero .portrait { width: 11rem; height: 11rem; object-fit: cover; border-radius: 50%; border: 4px solid var(--paper); box-shadow: 0 2px 10px rgba(60,40,10,0.15); }
.hero h2 { font-size: 2rem; margin: 0.8rem 0 0.1rem; }
.hero .dates { color: var(--muted); font-family: var(--serif); font-size: 1.1rem; }
.tiles { display: grid; gap: 0.9rem; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); margin-top: 1.4rem; }
.tile { display: block; text-decoration: none; color: inherit; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.2rem; }
.tile:hover { border-color: var(--accent); }
.tile h3 { margin-bottom: 0.25rem; }
.tile p { margin: 0; color: var(--muted); font-size: 0.95rem; }

/* ---- book ---- */
.book-cover { text-align: center; padding: 1rem 0 0.4rem; }
.book-cover h2 { font-size: 2.1rem; margin: 0.3rem 0; }
.toc { list-style: none; margin: 0; padding: 0; }
.toc li a { display: flex; justify-content: space-between; gap: 1rem; padding: 0.7rem 0.2rem; border-bottom: 1px solid var(--line); text-decoration: none; color: var(--text); font-family: var(--serif); font-size: 1.08rem; }
.toc li a:hover { color: var(--accent-dark); }
.toc li a .mins { color: var(--muted); font-family: var(--sans); font-size: 0.82rem; white-space: nowrap; }
.toc li a[aria-current="true"] { color: var(--accent-dark); font-weight: 600; }

.reader-bar {
  position: sticky; top: 0; z-index: 20; background: rgba(255,253,249,0.96); backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
}
.reader-bar .inner { max-width: 760px; margin: 0 auto; padding: 0.45rem 0.8rem; display: flex; align-items: center; gap: 0.4rem; }
.reader-bar .where { flex: 1; min-width: 0; font-family: var(--serif); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); font-size: 0.95rem; }
.icon-btn {
  font: inherit; font-weight: 600; background: var(--paper); color: var(--accent-dark); border: 1px solid var(--line);
  border-radius: 999px; min-width: 2.6rem; height: 2.4rem; padding: 0 0.7rem; cursor: pointer;
}
.icon-btn:hover { background: var(--tint); }
.progress { height: 3px; background: var(--line); }
.progress span { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.15s; }

.book-text { font-family: var(--serif); font-size: 19px; line-height: 1.7; max-width: 38em; margin: 0 auto; overflow-wrap: break-word; }
.book-text h1 { font-size: 1.8em; text-align: center; margin: 1.2em 0 0.8em; }
.book-text p { margin: 0 0 1em; }
.book-text figure { margin: 1.2em 0; text-align: center; }
.book-text figure img { border-radius: 6px; cursor: zoom-in; display: block; margin: 0 auto; }
.chapter-nav { display: flex; justify-content: space-between; gap: 0.6rem; margin: 2.5rem 0 0; padding-top: 1.2rem; border-top: 1px solid var(--line); }
.chapter-nav .btn { max-width: 48%; }

.drawer-backdrop { position: fixed; inset: 0; background: rgba(30,22,12,0.45); z-index: 50; display: flex; justify-content: flex-end; }
.drawer { background: var(--paper); width: min(26rem, 92vw); height: 100%; overflow-y: auto; padding: 1rem 1.1rem 2rem; box-shadow: -4px 0 20px rgba(0,0,0,0.15); }
.drawer .head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.4rem; }

/* ---- memories ---- */
.memory { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.2rem; margin-bottom: 1rem; }
.memory.featured { border-color: #d9c49b; box-shadow: 0 1px 0 #d9c49b inset; }
.memory .badges { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-bottom: 0.5rem; }
.badge { display: inline-block; font-size: 0.76rem; font-weight: 700; padding: 0.12rem 0.6rem; border-radius: 999px; background: var(--tint); color: var(--accent-dark); }
.badge.fb { background: #e7edf7; color: #2f4f86; }
.badge.private { background: #efe7f4; color: #5f3c78; }
.badge.hidden { background: #f4e2e0; color: var(--danger); }
.memory .photo { margin: 0 0 0.8rem; }
.memory .photo img { width: 100%; max-height: 32rem; object-fit: contain; background: var(--tint); border-radius: 8px; cursor: zoom-in; display: block; }
.memory .text { font-family: var(--serif); font-size: 1.08rem; line-height: 1.65; white-space: normal; }
.memory .text p { margin: 0 0 0.8em; }
.memory .text.clamped { max-height: 11.5em; overflow: hidden; position: relative; }
.memory .text.clamped::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 3em; background: linear-gradient(transparent, var(--paper)); }
.memory .byline { margin-top: 0.6rem; color: var(--muted); font-size: 0.92rem; }
.link-btn { background: none; border: none; padding: 0; font: inherit; color: var(--accent-dark); text-decoration: underline; cursor: pointer; }

/* ---- share ---- */
.photo-preview { margin-top: 0.6rem; position: relative; display: inline-block; }
.photo-preview img { max-height: 14rem; border-radius: 8px; display: block; }

/* ---- about ---- */
.about-photo { width: 100%; max-width: 22rem; border-radius: var(--radius); display: block; margin: 0 auto 1rem; }
.prose { font-family: var(--serif); font-size: 1.1rem; line-height: 1.7; }
.prose p { margin: 0 0 1em; }

/* ---- lightbox ---- */
.lightbox { position: fixed; inset: 0; z-index: 100; background: rgba(15,10,5,0.92); display: flex; align-items: center; justify-content: center; padding: 1rem; cursor: zoom-out; }
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 4px; }
.lightbox .close { position: absolute; top: 0.6rem; right: 0.8rem; color: #fff; background: rgba(0,0,0,0.4); border: none; font-size: 1.6rem; width: 2.6rem; height: 2.6rem; border-radius: 50%; cursor: pointer; }
.lightbox .nav { position: absolute; top: 50%; transform: translateY(-50%); color: #fff; background: rgba(0,0,0,0.4); border: none; font-size: 2rem; width: 2.8rem; height: 3.6rem; border-radius: 10px; cursor: pointer; }
.lightbox .prev { left: 0.5rem; }
.lightbox .next { right: 0.5rem; }
.lightbox .count { position: absolute; bottom: 0.9rem; left: 0; right: 0; text-align: center; color: #eee; font-size: 0.9rem; }

/* ---- several photos on a memory ---- */
.photo-strip { display: flex; gap: 0.4rem; overflow-x: auto; margin-top: 0.45rem; padding-bottom: 0.2rem; }
.photo-strip img { width: 4.5rem; height: 4.5rem; object-fit: cover; border-radius: 6px; cursor: zoom-in; flex-shrink: 0; border: 2px solid transparent; }
.photo-strip .more { width: 4.5rem; height: 4.5rem; flex-shrink: 0; border-radius: 6px; background: var(--tint); color: var(--accent-dark); font-weight: 700; display: flex; align-items: center; justify-content: center; border: none; cursor: pointer; font: inherit; }
.pick-grid { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-top: 0.6rem; }
.pick-grid figure { margin: 0; text-align: center; }
.pick-grid img { width: 6.5rem; height: 6.5rem; object-fit: cover; border-radius: 8px; display: block; }
.edit-mine { display: inline-block; margin-left: 0.4rem; font-size: 0.86rem; }
.copy-row { display: flex; gap: 0.5rem; margin-top: 0.5rem; }
.copy-row input { flex: 1; min-width: 0; font-size: 0.85rem; }

/* ---- book reader: way back to the site ---- */
.back-link { flex-shrink: 0; text-decoration: none; color: var(--accent-dark); font-weight: 600; font-size: 0.92rem; padding: 0.4rem 0.7rem; border: 1px solid var(--line); border-radius: 999px; background: var(--paper); white-space: nowrap; }
.back-link:hover { background: var(--tint); }
@media (max-width: 480px) { .reader-bar .where { visibility: hidden; } }

/* ---- admin ---- */
.tabs { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-bottom: 1rem; }
.tabs button { font: inherit; padding: 0.4rem 0.9rem; border-radius: 999px; border: 1px solid var(--line); background: var(--paper); cursor: pointer; }
.tabs button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.admin-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.8rem; padding-top: 0.7rem; border-top: 1px dashed var(--line); }
.thumb-row { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.6rem; }
.thumb-row figure { margin: 0; text-align: center; }
.thumb-row img { width: 7rem; height: 7rem; object-fit: cover; border-radius: 6px; display: block; }

.site-footer { text-align: center; color: var(--muted); font-size: 0.82rem; padding: 1.5rem 1rem 2rem; font-family: var(--serif); }

@media (max-width: 480px) {
  html { font-size: 17px; }
  main { padding: 1rem 0.85rem 4rem; }
  .hero .portrait { width: 9rem; height: 9rem; }
}

/* ---- reactions ---- */
.reactions { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.75rem; }
.reaction {
  display: inline-flex; align-items: center; gap: 0.3rem; font: inherit; font-size: 1rem; line-height: 1;
  background: var(--paper); border: 1px solid var(--line); border-radius: 999px; padding: 0.35rem 0.7rem;
  color: var(--muted); min-height: 2.3rem;
}
button.reaction { cursor: pointer; }
button.reaction:hover { background: var(--tint); }
.reaction .n { font-size: 0.85rem; font-weight: 600; min-width: 0.5em; }
.reaction.on { background: var(--tint); border-color: var(--accent); color: var(--accent-dark); }
.reaction .n:empty { display: none; }

/* ---- Apple / Other chooser ---- */
.chooser-backdrop { position: fixed; inset: 0; z-index: 90; background: rgba(30,22,12,0.45); display: flex; align-items: flex-end; justify-content: center; padding: 1rem; }
@media (min-width: 600px) { .chooser-backdrop { align-items: center; } }
.chooser { background: var(--paper); border-radius: 16px; padding: 1.2rem; width: 100%; max-width: 22rem; display: flex; flex-direction: column; gap: 0.6rem; box-shadow: 0 10px 30px rgba(0,0,0,0.25); }
.chooser h3 { margin: 0 0 0.3rem; text-align: center; }
.chooser .link-btn { align-self: center; margin-top: 0.2rem; }

/* ---- funeral ---- */
.event-card .when { font-family: var(--serif); font-size: 1.15rem; margin: 0.2rem 0 0.6rem; }
.event-card .place strong { display: block; }
.program { list-style: none; margin: 0; padding: 0; }
.program li { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0.2rem 0.8rem; padding: 0.6rem 0; border-bottom: 1px dotted var(--line); font-family: var(--serif); font-size: 1.05rem; }
.program li:last-child { border-bottom: none; }
.program .detail { color: var(--muted); }

/* ---- guest book ---- */
.guest { padding: 0.75rem 0; border-bottom: 1px solid var(--line); }
.guest:last-child { border-bottom: none; }
.guest .name { font-family: var(--serif); font-size: 1.12rem; font-weight: 600; }
.guest .rel { color: var(--muted); }
.guest .msg { margin-top: 0.25rem; font-family: var(--serif); }

/* ---- funeral: Zoom ---- */
.zoom-card p { margin: 0 0 0.8rem; }

/* ---- funeral program booklet: each slide is a printed half-letter page ---- */
.booklet { margin: 1.4rem 0 1rem; }
.booklet > h3 { margin-bottom: 0.6rem; }
.booklet-track {
  display: flex; gap: 1rem; overflow-x: auto; scroll-snap-type: x mandatory; scroll-behavior: smooth;
  overscroll-behavior-x: contain; scrollbar-width: none; padding: 0.4rem 0 0.9rem;
}
.booklet-track::-webkit-scrollbar { display: none; }
.booklet-track:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.booklet-page { flex: 0 0 100%; scroll-snap-align: start; scroll-snap-stop: always; display: flex; justify-content: center; }
.paper {
  width: 100%; max-width: 30rem; aspect-ratio: 5.5 / 8.5;
  background: #fff; color: #000; font-family: "Times New Roman", Times, serif; text-align: center;
  padding: 2.2rem 1.6rem 1.8rem; box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 6px 18px rgba(60,40,20,0.12);
  display: flex; flex-direction: column;
}
.paper h3 { font-family: inherit; font-weight: 700; font-size: 1.75rem; margin: 0 0 0.35rem; }
.paper hr { width: 100%; border: none; border-top: 1px solid #b5b5b5; margin: 0.9rem 0 1.4rem; }
.paper .sub { margin: 0; font-size: 0.95rem; line-height: 1.45; }
.paper .kicker { font-style: italic; font-size: 1.35rem; margin: 0.6rem 0 0.9rem; }
.paper .name { font-size: 2.1rem; margin-bottom: 0.7rem; }
.paper .dates { margin: 0; font-size: 1.02rem; }
.paper .portrait { width: 76%; margin: 1.8rem auto 0; border: 1px solid #888; display: block; }
.paper .foot { margin: auto 0 0; padding-top: 1.6rem; font-style: italic; font-size: 0.9rem; }
.paper .order { display: grid; grid-template-columns: auto 1fr; gap: 1.05rem 2.4rem; text-align: left; margin: 0; font-size: 0.92rem; line-height: 1.3; }
.paper .order dt { font-weight: 700; }
.paper .order dd { margin: 0; }
.paper .lyrics p { margin: 0 0 0.7rem; line-height: 1.35; font-size: 0.82rem; }
.paper .lyrics .chorus { font-style: italic; }
.paper .lyrics.big p { font-size: 1.12rem; line-height: 1.55; margin-bottom: 1.1rem; }
@media (max-width: 480px) {
  .paper { aspect-ratio: auto; min-height: 34rem; padding: 1.6rem 1rem 1.4rem; }
  .paper .order { gap: 0.9rem 1.2rem; }
  .paper .lyrics p { font-size: 0.85rem; }
}
.booklet-nav { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; margin-top: 0.3rem; }
.booklet-dots { display: flex; gap: 0.5rem; }
.booklet-dots button { width: 0.8rem; height: 0.8rem; padding: 0; border-radius: 50%; border: 1px solid var(--accent); background: transparent; cursor: pointer; }
.booklet-dots button[aria-current="true"] { background: var(--accent); }
.booklet-count { margin: 0.5rem 0 0; }
