/* ===== Tokens ===== */
:root {
  --paper: #f7f2e9;
  --card: #fffdf8;
  --ink: #2b2420;
  --ink-soft: #5e534a;
  --line: #e2d8c6;
  --brown: #7b5a43;
  --brown-deep: #5a4130;
  --brown-wash: #efe5d6;
  --ok: #3f6a3b;
  --danger: #a3412e;
  --warn: #7a5210;
  --serif: 'Newsreader', Georgia, 'Times New Roman', serif;
  --sans: 'Instrument Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --r-card: 10px;
  --r-photo: 4px;
  --r-btn: 8px;
  --shadow: 0 1px 2px rgba(60, 40, 20, 0.06), 0 8px 22px rgba(60, 40, 20, 0.06);
  --pad: clamp(16px, 4.5vw, 36px);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.55;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}
main { flex: 1; outline: none; padding-bottom: 3rem; }
img, video { max-width: 100%; display: block; }
a { color: var(--brown-deep); text-underline-offset: 3px; }
a:hover { color: var(--brown); }
h1, h2, h3 { font-family: var(--serif); font-weight: 500; line-height: 1.15; margin: 0 0 0.5em; letter-spacing: -0.01em; }
h1 { font-size: clamp(2rem, 7vw, 3.4rem); }
h2 { font-size: clamp(1.4rem, 4vw, 1.9rem); }
h3 { font-size: 1.15rem; }
p { margin: 0 0 1em; }
:focus-visible { outline: 3px solid var(--brown); outline-offset: 2px; }
[hidden] { display: none !important; }

.skip { position: absolute; left: -999px; top: 8px; background: var(--ink); color: #fff; padding: 8px 14px; border-radius: 6px; z-index: 100; }
.skip:focus { left: 8px; }
.wrap { width: 100%; max-width: 70rem; margin-inline: auto; padding-inline: var(--pad); }
.narrow { max-width: 44rem; }
.center { text-align: center; margin-top: 1.5rem; }
.muted { color: var(--ink-soft); font-size: 0.95rem; }
.section { padding-top: clamp(2rem, 6vw, 4rem); }
.section-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }

/* ===== Header and footer ===== */
.site-header { background: var(--paper); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.header-inner { display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 62px; flex-wrap: wrap; }
.brand { font-family: var(--serif); font-size: 1.35rem; font-weight: 500; color: var(--ink); text-decoration: none; letter-spacing: -0.01em; }
.menu-toggle { min-height: 44px; padding: 0 16px; border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: var(--r-btn); font: 500 0.95rem var(--sans); cursor: pointer; }
.nav { display: none; width: 100%; flex-direction: column; gap: 2px; padding-bottom: 12px; }
.nav.nav-open { display: flex; }
.nav a, .nav-signout { display: block; padding: 12px 4px; color: var(--ink); text-decoration: none; font-weight: 500; border: 0; background: none; font-family: var(--sans); font-size: 1rem; text-align: left; cursor: pointer; border-bottom: 1px solid var(--line); }
.nav a[aria-current='page'] { color: var(--brown); box-shadow: inset 3px 0 0 var(--brown); padding-left: 12px; }
.site-footer { border-top: 1px solid var(--line); padding: 1.6rem 0; color: var(--ink-soft); font-size: 0.92rem; }
.footer-inner { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.footer-inner p { margin: 0; }
.quiet-link { color: var(--ink-soft); }

@media (min-width: 760px) {
  .menu-toggle { display: none; }
  .nav, .nav.nav-open { display: flex; flex-direction: row; width: auto; align-items: center; gap: 1.6rem; padding: 0; }
  .nav a, .nav-signout { border: 0; padding: 6px 0; font-size: 0.98rem; }
  .nav a[aria-current='page'] { box-shadow: none; padding-left: 0; border-bottom: 2px solid var(--brown); }
}

/* ===== Buttons and forms ===== */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 0 20px; border-radius: var(--r-btn); border: 1px solid transparent; font: 600 0.98rem var(--sans); cursor: pointer; text-decoration: none; transition: background-color 0.15s, border-color 0.15s; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-primary { background: var(--brown); color: #fff; }
.btn-primary:hover { background: var(--brown-deep); color: #fff; }
.btn-quiet { background: var(--card); color: var(--ink); border-color: var(--line); }
.btn-quiet:hover { border-color: var(--brown); color: var(--ink); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger-quiet { background: var(--card); color: var(--danger); border-color: var(--line); }
.btn-danger-quiet:hover { border-color: var(--danger); color: var(--danger); }
.btn-block { width: 100%; }
.btn-small { min-height: 40px; min-width: 40px; padding: 0 12px; }

.stack { display: flex; flex-direction: column; gap: 1.1rem; }
.field label { display: block; font-weight: 600; font-size: 0.95rem; margin-bottom: 6px; }
input[type='text'], input[type='email'], input[type='password'], input[type='search'], input[type='date'], input[type='number'], select, textarea {
  width: 100%; min-height: 46px; padding: 10px 12px; font: 1rem var(--sans); color: var(--ink); background: var(--card); border: 1px solid #cdbfa8; border-radius: var(--r-btn);
}
textarea { min-height: 120px; resize: vertical; line-height: 1.5; font-family: var(--serif); font-size: 1.08rem; }
input[type='file'] { width: 100%; font: 0.95rem var(--sans); padding: 10px; border: 1px dashed #b9a98e; border-radius: var(--r-btn); background: var(--card); }
input:focus, select:focus, textarea:focus { border-color: var(--brown); }
.hint { margin: 6px 0 0; color: var(--ink-soft); font-size: 0.88rem; }
.check { display: grid; grid-template-columns: 24px 1fr; column-gap: 10px; align-items: start; }
.check input { width: 22px; height: 22px; margin: 2px 0 0; accent-color: var(--brown); }
.check .hint { grid-column: 2; margin-top: 2px; }
.form-error { color: var(--danger); font-weight: 500; margin: 0; min-height: 1.2em; }
progress { width: 100%; height: 10px; accent-color: var(--brown); }

/* ===== Page parts ===== */
.page-heading { padding-top: clamp(1.6rem, 5vw, 3rem); margin-bottom: 1.2rem; }
.page-heading.row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.page-heading h1 { margin-bottom: 0.2em; }
.lede { font-family: var(--serif); font-size: 1.25rem; color: var(--ink-soft); line-height: 1.45; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-card); padding: 1.2rem; box-shadow: var(--shadow); }
.notice { background: var(--brown-wash); border: 1px solid var(--line); border-radius: var(--r-card); padding: 1rem 1.2rem; margin: 1rem 0; display: flex; flex-direction: column; gap: 0.6rem; align-items: flex-start; }
.notice p { margin: 0; }
.notice-error { background: #f8e6e1; border-color: #e3bdb3; color: #6f2415; }
.notice-warn { background: #f6ecd2; border-color: #e1cd98; color: #5b3d08; }
.notice-preview { background: #e8eddc; border-color: #c6d1aa; color: #34411f; margin-top: 1.4rem; }
.empty { text-align: center; padding: 2.5rem 1rem; border: 1px dashed #c9bba3; border-radius: var(--r-card); background: rgba(255, 253, 248, 0.6); }
.empty .btn { margin-top: 0.5rem; }
.empty p { color: var(--ink-soft); max-width: 32rem; margin-inline: auto; }
.loading { display: flex; gap: 12px; align-items: center; justify-content: center; padding: 4rem 1rem; color: var(--ink-soft); }
.spinner { width: 20px; height: 20px; border: 3px solid var(--line); border-top-color: var(--brown); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 0.82rem; font-weight: 600; border: 1px solid var(--line); background: var(--card); }
.badge-published { color: var(--ok); border-color: #b9cfb4; background: #eef4ea; }
.badge-draft { color: var(--ink-soft); }
.badge-unpublished { color: var(--warn); border-color: #e1cd98; background: #f8f0d9; }
.badge-featured { color: var(--brown-deep); background: var(--brown-wash); }

/* ===== Hero ===== */
.hero { display: grid; gap: 2rem; padding-top: clamp(2rem, 7vw, 5rem); padding-bottom: 1rem; align-items: center; }
.hero h1 { font-size: clamp(2.3rem, 9vw, 4.6rem); line-height: 1.04; max-width: 14ch; }
.hero-name { font-family: var(--serif); font-style: italic; font-size: 1.25rem; color: var(--brown); margin-top: -0.2rem; }
.hero-intro { font-family: var(--serif); font-size: clamp(1.15rem, 3vw, 1.4rem); line-height: 1.5; color: var(--ink-soft); max-width: 36rem; }
.hero-actions { display: flex; gap: 0.8rem; flex-wrap: wrap; margin-top: 1.4rem; }
.hero-photo { width: min(100%, 22rem); aspect-ratio: 4 / 5; object-fit: cover; background: #fff; padding: 10px; border: 1px solid var(--line); border-radius: 3px; box-shadow: var(--shadow); justify-self: start; }
.about-photo { width: min(100%, 18rem); aspect-ratio: 4 / 5; object-fit: cover; background: #fff; padding: 8px; border: 1px solid var(--line); border-radius: 3px; box-shadow: var(--shadow); margin-bottom: 1.6rem; }
@media (min-width: 820px) {
  .hero { grid-template-columns: 1.4fr 1fr; gap: 4rem; }
  .hero-photo { justify-self: end; }
}

/* ===== Memory grid ===== */
.memory-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1.1rem 0.9rem; margin-top: 1rem; }
@media (min-width: 640px) { .memory-grid { grid-template-columns: repeat(3, 1fr); gap: 1.6rem 1.2rem; } }
@media (min-width: 1000px) { .memory-grid { grid-template-columns: repeat(4, 1fr); } }
.memory-card { display: block; text-decoration: none; color: inherit; }
.card-media { aspect-ratio: 4 / 5; background: var(--brown-wash); border-radius: var(--r-photo); overflow: hidden; border: 1px solid var(--line); }
.card-img { width: 100%; height: 100%; object-fit: cover; transition: transform 0.35s ease; }
.memory-card:hover .card-img { transform: scale(1.03); }
.card-tile { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; padding: 14px; text-align: center; font-family: var(--serif); font-style: italic; color: var(--ink-soft); font-size: 0.98rem; line-height: 1.35; }
.card-tile-video { background: #3a2f28; color: #f7f2e9; font-size: 2rem; font-style: normal; }
.card-body { padding-top: 0.55rem; }
.card-body h3 { margin: 0 0 0.1em; font-size: 1.1rem; }
.card-date { margin: 0; font-family: var(--serif); font-style: italic; color: var(--ink-soft); font-size: 0.95rem; }
.now-grid { display: grid; gap: 1.2rem; margin-top: 0.8rem; }
@media (min-width: 760px) { .now-grid { grid-template-columns: repeat(3, 1fr); } }
.now-item { border-top: 2px solid var(--brown); padding-top: 0.7rem; }
.now-item p { font-family: var(--serif); font-size: 1.08rem; color: var(--ink-soft); }
.info-block { margin-bottom: 2rem; }
.info-block p { font-family: var(--serif); font-size: 1.18rem; line-height: 1.65; }

/* ===== Filters ===== */
.search-form { display: flex; gap: 0.6rem; margin-bottom: 1rem; }
.search-form input { flex: 1; }
.chips { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0.6rem 0; }
.chip { min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); color: var(--ink); font: 500 0.92rem var(--sans); cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; }
.chip[aria-pressed='true'] { background: var(--brown); border-color: var(--brown); color: #fff; }
.chips-small .chip { min-height: 34px; font-size: 0.85rem; }
.chip-tag { color: var(--brown-deep); }
.filter-row { display: flex; gap: 0.8rem; flex-wrap: wrap; margin: 0.6rem 0; }
.select-wrap { display: flex; flex-direction: column; gap: 4px; font-size: 0.88rem; font-weight: 600; min-width: 9rem; }
.select-wrap select { font-weight: 400; }
.summary { color: var(--ink-soft); margin: 1rem 0 0; min-height: 1.4em; }

/* ===== Single memory ===== */
.memory h1 { margin-top: 0.6rem; }
.back { display: inline-block; margin-top: 1.6rem; }
.memory-meta { font-family: var(--serif); font-style: italic; color: var(--ink-soft); font-size: 1.1rem; margin-bottom: 0.3rem; }
.tag-line { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.8rem 0 1.4rem; }
.photo-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.6rem; margin: 1.4rem 0; }
@media (min-width: 640px) { .photo-grid { grid-template-columns: repeat(3, 1fr); } }
.photo { padding: 0; border: 1px solid var(--line); background: var(--brown-wash); border-radius: var(--r-photo); overflow: hidden; cursor: zoom-in; aspect-ratio: 1; }
.photo img { width: 100%; height: 100%; object-fit: cover; }
.video { margin: 1.4rem 0; }
.video video { width: 100%; max-height: 70dvh; background: #000; border-radius: var(--r-photo); }
.video figcaption { color: var(--ink-soft); font-size: 0.92rem; margin-top: 6px; }
.prose { font-family: var(--serif); font-size: 1.2rem; line-height: 1.7; max-width: 38rem; }

/* ===== Dialogs and lightbox ===== */
.dialog { border: 0; border-radius: var(--r-card); padding: 1.4rem; max-width: min(32rem, calc(100vw - 2rem)); width: 100%; background: var(--card); color: var(--ink); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3); }
.dialog::backdrop, .lightbox::backdrop { background: rgba(43, 36, 32, 0.55); }
.dialog-title { font-size: 1.4rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 0.6rem; margin-top: 1.2rem; flex-wrap: wrap; }
.lightbox { width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 0; border: 0; background: #1b1512; color: #f7f2e9; }
.lightbox[open] { display: flex; flex-direction: column; }
.lb-stage { flex: 1; display: flex; align-items: center; justify-content: center; min-height: 0; position: relative; padding: 56px 8px 8px; }
.lb-img { max-width: 100%; max-height: 100%; object-fit: contain; }
.lb-status { position: absolute; margin: 0; color: #d8cdbc; }
.lb-btn { position: absolute; z-index: 2; width: 48px; height: 48px; border-radius: 50%; border: 0; background: rgba(247, 242, 233, 0.16); color: #fff; font-size: 1.8rem; line-height: 1; cursor: pointer; }
.lb-close { top: 8px; right: 8px; }
.lb-prev { left: 8px; top: 50%; }
.lb-next { right: 8px; top: 50%; }
.lb-bar { padding: 10px 16px calc(12px + env(safe-area-inset-bottom)); text-align: center; }
.lb-caption { margin: 0; font-family: var(--serif); font-size: 1.05rem; }
.lb-counter { margin: 2px 0 0; color: #bfb3a1; font-size: 0.88rem; }

/* ===== Toasts ===== */
.toasts { position: fixed; left: 0; right: 0; bottom: calc(14px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 60; pointer-events: none; padding-inline: 12px; }
.toast { pointer-events: auto; max-width: 30rem; width: 100%; padding: 12px 16px; border-radius: var(--r-btn); background: var(--ink); color: #fff; box-shadow: var(--shadow); font-size: 0.95rem; cursor: pointer; }
.toast-success { background: var(--ok); }
.toast-error { background: var(--danger); }

/* ===== Private dashboard ===== */
.admin { padding-top: 1rem; }
.admin-nav { display: flex; gap: 0.4rem; overflow-x: auto; padding: 0.6rem 0; border-bottom: 1px solid var(--line); scrollbar-width: thin; }
.admin-link { flex: none; padding: 8px 14px; border-radius: 999px; text-decoration: none; color: var(--ink); font-weight: 500; font-size: 0.95rem; min-height: 40px; display: inline-flex; align-items: center; }
.admin-link[aria-current='page'] { background: var(--brown); color: #fff; }
.admin-link-out { margin-left: auto; color: var(--ink-soft); }
.stat-grid { display: grid; gap: 1rem; margin: 1.2rem 0; }
@media (min-width: 760px) { .stat-grid { grid-template-columns: repeat(3, 1fr); } }
.stat-grid .card { display: flex; flex-direction: column; gap: 0.4rem; align-items: flex-start; }
.stat-grid h2 { font-size: 1.15rem; margin: 0; }
.big { font-family: var(--serif); font-size: 2.6rem; line-height: 1; margin: 0.2rem 0; }
.row-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.4rem; }
.form-card { max-width: 26rem; display: flex; flex-direction: column; gap: 1rem; margin-top: 1rem; }
.profile-field { display: flex; flex-direction: column; gap: 0.6rem; padding-bottom: 1rem; border-bottom: 1px solid var(--line); }
.avatar-preview { width: 9rem; aspect-ratio: 4 / 5; object-fit: cover; border-radius: 3px; border: 1px solid var(--line); }
.sticky-actions { position: sticky; bottom: 0; z-index: 10; display: flex; gap: 0.6rem; flex-wrap: wrap; padding: 0.8rem 0 calc(0.8rem + env(safe-area-inset-bottom)); background: linear-gradient(to top, var(--paper) 75%, rgba(247, 242, 233, 0)); margin-top: 1rem; }
.admin-list { display: flex; flex-direction: column; gap: 0.9rem; margin-top: 1rem; }
.admin-row { display: flex; gap: 0.9rem; background: var(--card); border: 1px solid var(--line); border-radius: var(--r-card); padding: 0.8rem; }
.row-thumb { width: 84px; height: 105px; flex: none; object-fit: cover; border-radius: var(--r-photo); background: var(--brown-wash); border: 1px solid var(--line); }
.row-thumb-empty { display: flex; align-items: center; justify-content: center; color: var(--ink-soft); font-size: 1.4rem; }
.row-main { min-width: 0; flex: 1; }
.row-main h3 { margin: 0 0 0.1em; overflow-wrap: anywhere; }
.row-main .muted { margin: 0 0 0.4rem; }
.row-badges { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.file-list { display: flex; flex-direction: column; gap: 0.8rem; }
.file-item { display: flex; gap: 0.8rem; padding: 0.7rem; border: 1px solid var(--line); border-radius: var(--r-card); background: var(--paper); }
.file-preview { width: 88px; height: 88px; flex: none; object-fit: cover; border-radius: var(--r-photo); background: var(--brown-wash); }
.file-preview-empty { display: flex; align-items: center; justify-content: center; font-size: 1.6rem; color: var(--ink-soft); }
.file-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.file-info p { margin: 0; font-size: 0.9rem; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
