:root {
  --bg: #f5f4f2;
  --card: #ffffff;
  --ink: #1a1a1a;
  --muted: #8a8a8a;
  --accent: #c2410c;
  --line: #e6e3df;
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.4;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: #b91c1c; font-size: 0.9rem; }

img { max-width: 100%; display: block; }
button { font: inherit; cursor: pointer; }

/* --- Login --- */
.screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 28px 24px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 8px 30px rgba(0,0,0,.08);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.login-card h1 { margin: 0; font-size: 1.6rem; }
.login-card input {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 1rem;
}
.login-card button, .primary {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 14px;
  border-radius: 12px;
  font-weight: 600;
}

/* --- Topbar --- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(10px + var(--safe-top)) 14px 10px;
  background: rgba(245,244,242,.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { flex: 1; text-align: center; font-size: 1.05rem; }
.icon-btn {
  background: none; border: none; font-size: 1.3rem;
  width: 40px; height: 40px; border-radius: 50%;
}
.icon-btn:active { background: var(--line); }

main { padding: 14px 14px calc(90px + var(--safe-bottom)); max-width: 720px; margin: 0 auto; }

/* --- FAB --- */
.fab {
  position: fixed;
  right: 18px;
  bottom: calc(18px + var(--safe-bottom));
  width: 60px; height: 60px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 2rem;
  line-height: 1;
  box-shadow: 0 6px 20px rgba(194,65,12,.4);
  z-index: 20;
}

/* --- Feed --- */
.memory-card {
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 16px;
  box-shadow: 0 2px 10px rgba(0,0,0,.05);
}
.memory-card .cover { width: 100%; aspect-ratio: 4/3; object-fit: cover; background: var(--line); }
.memory-card .count-badge {
  position: absolute; top: 10px; right: 10px;
  background: rgba(0,0,0,.6); color: #fff;
  font-size: .8rem; padding: 3px 9px; border-radius: 20px;
}
.memory-card .cover-wrap { position: relative; }
.memory-card .body { padding: 12px 14px; }
.memory-card h3 { margin: 0 0 4px; font-size: 1.1rem; }
.memory-card .meta { color: var(--muted); font-size: .85rem; }

.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tag {
  font-size: .8rem; padding: 4px 10px;
  background: var(--bg); border: 1px solid var(--line);
  border-radius: 20px; text-transform: capitalize;
}
.tag.person { background: #fef3e8; border-color: #f6d3b0; }
.tag.removable::after { content: " ✕"; color: var(--muted); }

/* --- Detail / Gallery --- */
.gallery img { border-radius: 12px; margin-bottom: 8px; }
.section-title { margin: 18px 0 8px; font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.btn {
  padding: 10px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); font-weight: 500;
}
.btn.danger { color: #b91c1c; border-color: #f0c2c2; }

/* --- Forms (new memory, persons) --- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 6px; }
.field input, .field textarea {
  width: 100%; padding: 12px; border: 1px solid var(--line); border-radius: 10px; font-size: 1rem;
}
.preview-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 10px 0; }
.preview-grid img { aspect-ratio: 1; object-fit: cover; border-radius: 10px; }

.upload-drop {
  border: 2px dashed var(--line); border-radius: var(--radius);
  padding: 28px; text-align: center; color: var(--muted);
}
.spinner {
  width: 22px; height: 22px; border: 3px solid var(--line);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin .8s linear infinite; display: inline-block; vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty { text-align: center; color: var(--muted); padding: 60px 20px; }

.person-item {
  background: var(--card); border-radius: 12px; padding: 12px 14px;
  margin-bottom: 10px; display: flex; justify-content: space-between; gap: 10px;
}
.person-item .desc { color: var(--muted); font-size: .85rem; }
