/* Keepsake album — warm ivory paper, deep brown ink, moss accent.
   Fraunces (display) + Karla (UI). Mobile-first. */

@font-face {
  font-family: "Fraunces";
  src: url("fonts/fraunces-latin.woff2") format("woff2");
  font-weight: 560;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Karla";
  src: url("fonts/karla-latin.woff2") format("woff2");
  font-weight: 300 800;
  font-style: normal;
  font-display: swap;
}

:root {
  --paper: #f6f1e7;
  --paper-deep: #efe8d9;
  --card: #fffdf8;
  --ink: #33291f;
  --ink-soft: #7a6f60;
  --ink-faint: #a99d8b;
  --moss: #4f6146;
  --moss-deep: #3d4c36;
  --moss-wash: #e4e6d8;
  --kraft: #e7dcc6;
  --kraft-deep: #d9cbae;
  --night: #201a13;
  --night-soft: #352c21;
  --danger: #a04432;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(51, 41, 31, 0.08), 0 6px 18px rgba(51, 41, 31, 0.07);
  --shadow-lift: 0 2px 4px rgba(51, 41, 31, 0.1), 0 12px 28px rgba(51, 41, 31, 0.12);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { height: 100%; }

body {
  font-family: "Karla", "Gill Sans", "Trebuchet MS", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--paper);
  background-image: radial-gradient(rgba(51, 41, 31, 0.028) 1px, transparent 1px);
  background-size: 22px 22px;
  min-height: 100%;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
}

img { display: block; max-width: 100%; }

:focus-visible {
  outline: 3px solid var(--moss);
  outline-offset: 2px;
  border-radius: 6px;
}

/* ── Header ─────────────────────────────────────────── */

.site-header {
  text-align: center;
  padding: 26px 16px 6px;
}

.wordmark {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 560;
  font-size: 30px;
  letter-spacing: 0.01em;
  line-height: 1.1;
}

.wordmark a { color: inherit; text-decoration: none; }

.header-rule {
  width: 54px;
  height: 3px;
  border-radius: 2px;
  background: var(--moss);
  margin: 12px auto 0;
  opacity: 0.75;
}

.tagline {
  color: var(--ink-soft);
  font-size: 14.5px;
  margin-top: 10px;
  letter-spacing: 0.03em;
}

/* ── Layout ─────────────────────────────────────────── */

main {
  max-width: 1060px;
  margin: 0 auto;
  padding: 18px 14px 40px;
  min-height: 55vh;
}

/* Album page header */
.crumb {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 4px 2px 16px;
  min-height: 44px;
}

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 14px 9px 10px;
  border-radius: 999px;
  background: var(--card);
  box-shadow: var(--shadow);
  font-weight: 600;
  font-size: 15px;
  color: var(--moss-deep);
  transition: transform 0.16s ease, box-shadow 0.16s ease;
}
.back-btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-lift); }
.back-btn:active { transform: translateY(0); }
.back-btn svg { width: 18px; height: 18px; }

.crumb-title {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 560;
  font-size: 22px;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.crumb-count {
  color: var(--ink-soft);
  font-size: 14px;
  white-space: nowrap;
  margin-left: auto;
  padding-left: 8px;
}

.menu-btn {
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--card);
  box-shadow: var(--shadow);
  color: var(--moss-deep);
  transition: transform 0.16s ease, box-shadow 0.16s ease;
}
.menu-btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-lift); }
.menu-btn:active { transform: translateY(0); }
.menu-btn svg { width: 20px; height: 20px; }

/* ── Grid ───────────────────────────────────────────── */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(105px, 1fr));
  gap: 10px;
}

@media (min-width: 480px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
}
@media (min-width: 900px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 16px; }
}

.tile {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius);
  overflow: hidden;
  padding: 0;
  width: 100%;
  display: block;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

@media (hover: hover) {
  .tile:hover { transform: translateY(-3px); box-shadow: var(--shadow-lift); }
}
.tile:active { transform: scale(0.975); }

/* Photo tile */
.tile.photo {
  background: var(--paper-deep);
  box-shadow: var(--shadow);
}
.tile.photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.tile.photo .tile-cap {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 18px 9px 7px;
  background: linear-gradient(180deg, transparent, rgba(24, 19, 13, 0.72));
  color: #f7f3ec;
  font-size: 12px;
  line-height: 1.3;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
@media (min-width: 900px) {
  .tile.photo .tile-cap { font-size: 13px; }
}

/* Add tile */
.tile.add {
  border: 2.5px dashed var(--kraft-deep);
  background: rgba(255, 253, 248, 0.6);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--moss-deep);
}
.tile.add .plus {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--moss);
  color: #fdfcf7;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.18s ease;
}
.tile.add .plus svg { width: 22px; height: 22px; }
.tile.add:hover .plus { transform: rotate(90deg); }
.tile.add .add-label { font-weight: 600; font-size: 14px; }

/* Folder (album) tile — stacked prints with kraft label */
.tile.folder {
  background: var(--kraft);
  box-shadow: var(--shadow);
}
.tile.folder .cover {
  position: absolute;
  inset: 0 0 38%;
  margin: 7px 7px 0;
  border-radius: 8px;
  overflow: hidden;
  background: var(--paper-deep);
}
.tile.folder .cover img { width: 100%; height: 100%; object-fit: cover; }
.tile.folder .cover .cover-empty {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  color: var(--ink-faint);
}
.tile.folder .cover .cover-empty svg { width: 30px; height: 30px; }
/* two prints peeking behind the cover */
.tile.folder::before,
.tile.folder::after {
  content: "";
  position: absolute;
  inset: 0 0 38%;
  margin: 7px 7px 0;
  border-radius: 8px;
  background: #fffdf8;
  border: 1px solid rgba(51, 41, 31, 0.1);
  z-index: 0;
}
.tile.folder::before { transform: rotate(-3.2deg) translate(-2px, 2px); }
.tile.folder::after { transform: rotate(2.4deg) translate(2px, 1px); }
.tile.folder .cover { z-index: 1; }
.tile.folder .folder-label {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 36%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2px 8px 4px;
  z-index: 1;
}
.tile.folder .folder-name {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 560;
  font-size: 13.5px;
  line-height: 1.15;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tile.folder .folder-count {
  font-size: 11px;
  color: var(--ink-soft);
}
@media (min-width: 480px) {
  .tile.folder .folder-name { font-size: 15px; }
  .tile.folder .folder-count { font-size: 12px; }
}
@media (min-width: 900px) {
  .tile.folder .folder-name { font-size: 17px; }
}

/* The built-in All album — same shape, a quiet moss tint sets it apart */
.tile.folder.all-album { background: var(--moss-wash); }
.tile.folder.all-album .folder-name { color: var(--moss-deep); }

/* Uploading tile */
.tile.uploading img { opacity: 0.45; width: 100%; height: 100%; object-fit: cover; }
.tile.uploading { box-shadow: var(--shadow); background: var(--paper-deep); cursor: default; }
.tile.uploading .spin {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.spinner {
  width: 30px; height: 30px;
  border-radius: 50%;
  border: 3px solid rgba(51, 41, 31, 0.18);
  border-top-color: var(--moss);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2.5s; }
  .tile, .back-btn, .tile.add .plus { transition: none; }
}

/* ── Search ─────────────────────────────────────────── */

.search-row {
  position: relative;
  max-width: 480px;
  margin: 2px auto 16px;
}
.search-icon {
  position: absolute;
  left: 14px; top: 50%;
  transform: translateY(-50%);
  color: var(--ink-faint);
  pointer-events: none;
}
.search-icon svg { width: 19px; height: 19px; display: block; }
.search-input {
  width: 100%;
  border: 2px solid var(--kraft-deep);
  border-radius: 999px;
  background: var(--card);
  font: inherit;
  font-size: 16px;
  padding: 12px 44px;
  color: var(--ink);
  box-shadow: var(--shadow);
}
.search-input:focus { outline: none; border-color: var(--moss); }
.search-input::placeholder { color: var(--ink-faint); }
.search-input::-webkit-search-cancel-button { display: none; }
.search-clear {
  position: absolute;
  right: 6px; top: 50%;
  transform: translateY(-50%);
  width: 38px; height: 38px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--ink-soft);
}
.search-clear:hover { background: var(--paper-deep); }
.search-clear svg { width: 17px; height: 17px; }

/* ── Show more ──────────────────────────────────────── */

.show-more-row {
  display: flex;
  justify-content: center;
  margin: 22px 0 6px;
}
.show-more .more-count { color: var(--ink-soft); font-weight: 400; }

/* ── Empty state ────────────────────────────────────── */

.empty {
  text-align: center;
  color: var(--ink-soft);
  padding: 40px 20px 8px;
  max-width: 380px;
  margin: 0 auto;
}
.empty svg { width: 84px; height: 84px; margin: 0 auto 14px; color: var(--kraft-deep); display: block; }
.empty h2 {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 560;
  color: var(--ink);
  font-size: 21px;
  margin-bottom: 6px;
}
.empty p { font-size: 15px; }

/* ── Footer ─────────────────────────────────────────── */

.site-footer {
  text-align: center;
  color: var(--ink-faint);
  font-size: 13.5px;
  padding: 26px 16px 34px;
  letter-spacing: 0.02em;
}
.site-footer .footer-rule {
  width: 40px; height: 2px;
  background: var(--kraft-deep);
  border-radius: 2px;
  margin: 0 auto 18px;
}
.footer-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ── Photo detail view ──────────────────────────────── */

.detail {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: var(--night);
  color: #efe8da;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* Flex children must NEVER shrink here: a tall photo would squeeze the
   header and overflow its own box. flex:none makes the view scroll instead. */
.detail-top,
.detail-stage,
.detail-body { flex: none; }

.detail-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 12px 4px;
  gap: 8px;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #efe8da;
  background: rgba(255, 253, 248, 0.09);
  transition: background 0.16s ease, transform 0.16s ease;
  flex: none;
}
.icon-btn:hover { background: rgba(255, 253, 248, 0.2); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn[disabled] { opacity: 0.3; pointer-events: none; }

.detail-date { font-size: 13.5px; color: rgba(239, 232, 218, 0.65); letter-spacing: 0.03em; }

.detail-stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px 56px;
  min-height: 38vh;
}
.detail-stage .stage-img {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: min(62vh, 1100px);
  border-radius: 10px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  background: var(--night-soft);
  object-fit: contain;
}
.stage-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
}
.stage-nav.prev { left: 8px; }
.stage-nav.next { right: 8px; }
@media (max-width: 640px) {
  .detail-stage { padding: 6px 10px; }
  .stage-nav { top: auto; bottom: -54px; transform: none; }
  .stage-nav.prev { left: 14px; }
  .stage-nav.next { right: 14px; }
  .detail-stage { margin-bottom: 46px; }
}

.detail-body {
  max-width: 620px;
  width: 100%;
  margin: 10px auto 0;
  padding: 6px 20px 40px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.caption-block { text-align: center; }

.caption-title {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 560;
  font-size: 24px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.caption-text {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 560;
  font-size: 20px;
  line-height: 1.45;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}
.caption-text.with-title {
  font-family: "Karla", sans-serif;
  font-weight: 400;
  font-size: 16.5px;
  color: rgba(239, 232, 218, 0.85);
  margin-top: 8px;
}

.caption-form { text-align: left; }
.cap-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(239, 232, 218, 0.6);
  margin: 14px 4px 6px;
}
.cap-label:first-child { margin-top: 0; }
.cap-title-input {
  width: 100%;
  border-radius: 12px;
  border: 2px solid rgba(239, 232, 218, 0.3);
  background: rgba(255, 253, 248, 0.06);
  color: #efe8da;
  font: inherit;
  font-size: 17px;
  padding: 11px 14px;
}
.cap-title-input:focus { outline: none; border-color: var(--moss-wash); }

.caption-edit-btn {
  margin-top: 8px;
  color: rgba(239, 232, 218, 0.7);
  font-size: 14.5px;
  text-decoration: underline;
  text-underline-offset: 3px;
  padding: 8px 10px;
  border-radius: 8px;
}
.caption-edit-btn:hover { color: #efe8da; }

.caption-empty-btn {
  border: 2px dashed rgba(239, 232, 218, 0.35);
  border-radius: 12px;
  color: rgba(239, 232, 218, 0.75);
  padding: 14px 18px;
  font-size: 16px;
  width: 100%;
  transition: border-color 0.16s ease, color 0.16s ease;
}
.caption-empty-btn:hover { border-color: rgba(239, 232, 218, 0.7); color: #efe8da; }

.caption-form textarea {
  width: 100%;
  min-height: 96px;
  border-radius: 12px;
  border: 2px solid rgba(239, 232, 218, 0.3);
  background: rgba(255, 253, 248, 0.06);
  color: #efe8da;
  font: inherit;
  font-size: 16px;
  padding: 12px 14px;
  resize: vertical;
}
.caption-form textarea:focus { outline: none; border-color: var(--moss-wash); }
.caption-form .form-row {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 10px;
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}

.chip-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 11px 18px;
  border-radius: 999px;
  background: rgba(255, 253, 248, 0.1);
  color: #efe8da;
  font-weight: 600;
  font-size: 15px;
  transition: background 0.16s ease, transform 0.16s ease;
  min-height: 44px;
}
.chip-btn:hover { background: rgba(255, 253, 248, 0.2); }
.chip-btn:active { transform: scale(0.97); }
.chip-btn svg { width: 18px; height: 18px; flex: none; }
.chip-btn span {
  max-width: min(58vw, 340px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chip-btn.danger { color: #f0b4a5; }
.chip-btn.danger:hover { background: rgba(160, 68, 50, 0.25); }

/* ── Buttons (light surfaces) ───────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 22px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 16px;
  min-height: 46px;
  transition: transform 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--moss); color: #fdfcf7; box-shadow: var(--shadow); }
.btn.primary:hover { background: var(--moss-deep); }
.btn.ghost { background: transparent; color: inherit; border: 2px solid rgba(127, 112, 96, 0.35); }
.btn.ghost:hover { border-color: rgba(127, 112, 96, 0.7); }
.detail .btn.ghost { border-color: rgba(239, 232, 218, 0.35); }
.detail .btn.ghost:hover { border-color: rgba(239, 232, 218, 0.7); }
.btn[disabled] { opacity: 0.55; pointer-events: none; }

/* ── Sheet / modal ──────────────────────────────────── */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(32, 26, 19, 0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fadeIn 0.18s ease;
}
@media (min-width: 640px) {
  .sheet-backdrop { align-items: center; padding: 24px; }
}
@keyframes fadeIn { from { opacity: 0; } }

.sheet {
  background: var(--card);
  color: var(--ink);
  width: 100%;
  max-width: 460px;
  border-radius: 22px 22px 0 0;
  padding: 10px 20px calc(22px + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -8px 40px rgba(32, 26, 19, 0.3);
  animation: sheetUp 0.22s ease;
  max-height: 86vh;
  overflow-y: auto;
}
@media (min-width: 640px) {
  .sheet { border-radius: 22px; padding-bottom: 24px; animation: fadeIn 0.18s ease; }
}
@keyframes sheetUp { from { transform: translateY(40px); opacity: 0.5; } }
@media (prefers-reduced-motion: reduce) {
  .sheet, .sheet-backdrop { animation: none; }
}

.sheet-handle {
  width: 40px; height: 4px;
  border-radius: 2px;
  background: var(--kraft-deep);
  margin: 4px auto 14px;
}
@media (min-width: 640px) { .sheet-handle { display: none; } }

.sheet h2 {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 560;
  font-size: 21px;
  text-align: center;
  margin-bottom: 16px;
}

.sheet .sheet-list { display: flex; flex-direction: column; gap: 8px; }

.list-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 13px 14px;
  border-radius: 12px;
  background: var(--paper);
  font-size: 16px;
  font-weight: 600;
  text-align: left;
  transition: background 0.14s ease, transform 0.14s ease;
  min-height: 50px;
}
.list-btn:hover { background: var(--paper-deep); }
.list-btn:active { transform: scale(0.985); }
.list-btn svg { width: 21px; height: 21px; color: var(--moss-deep); flex: none; }
.list-btn .grow { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-btn .meta { color: var(--ink-soft); font-weight: 400; font-size: 13.5px; }
.list-btn.checked { background: var(--moss-wash); }
.list-btn .check { opacity: 0; transition: opacity 0.12s ease; }
.list-btn.checked .check { opacity: 1; color: var(--moss-deep); }

.sheet .field-row { display: flex; flex-direction: column; gap: 12px; }

.text-input {
  width: 100%;
  border: 2px solid var(--kraft-deep);
  border-radius: 12px;
  background: #fff;
  font: inherit;
  font-size: 17px;
  padding: 12px 14px;
  color: var(--ink);
}
.text-input:focus { outline: none; border-color: var(--moss); }

.sheet .form-row { display: flex; gap: 10px; justify-content: flex-end; margin-top: 14px; }

.sheet-note { color: var(--ink-soft); font-size: 14px; text-align: center; margin-top: 12px; }

/* ── Toast ──────────────────────────────────────────── */

.toast-wrap {
  position: fixed;
  left: 0; right: 0;
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 90;
  pointer-events: none;
  padding: 0 16px;
}
.toast {
  background: var(--ink);
  color: var(--paper);
  border-radius: 999px;
  padding: 11px 20px;
  font-size: 15px;
  box-shadow: var(--shadow-lift);
  animation: toastUp 0.25s ease;
  max-width: 100%;
  text-align: center;
}
.toast.error { background: var(--danger); color: #fff5ef; }
@keyframes toastUp { from { transform: translateY(14px); opacity: 0; } }

/* ── Loading state ──────────────────────────────────── */

.boot-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 70px 0 30px;
  color: var(--ink-soft);
}

/* 404 page */
.lost {
  text-align: center;
  padding: 80px 20px;
}
.lost h1 { font-family: "Fraunces", Georgia, serif; font-weight: 560; font-size: 34px; margin-bottom: 10px; }
.lost p { color: var(--ink-soft); margin-bottom: 22px; }
