:root {
  --bg: #f6f0e7;
  --surface: #fffaf3;
  --surface-2: #efe6da;
  --ink: #24362e;
  --muted: #718078;
  --green: #456b5a;
  --green-dark: #315043;
  --sage: #dbe7df;
  --pink: #e8b8b5;
  --pink-soft: #f7d8d4;
  --gold: #a68452;
  --border: rgba(69, 107, 90, .15);
  --shadow: 0 24px 60px rgba(48, 65, 56, .12);
  --radius: 24px;
}

* { box-sizing: border-box; }
html { background: var(--bg); scroll-behavior: smooth; }
body { margin: 0; color: var(--ink); background: var(--bg); font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
img, video { max-width: 100%; display: block; }
.hidden { display: none !important; }

h1, h2, h3 { font-family: Georgia, "Times New Roman", serif; letter-spacing: -.025em; margin: 0; }
p { line-height: 1.6; }
code { background: #efe7dc; padding: .12rem .35rem; border-radius: 6px; }

.eyebrow { margin: 0 0 .45rem; text-transform: uppercase; letter-spacing: .13em; font-size: .72rem; font-weight: 800; color: var(--green); }
.eyebrow.light { color: rgba(255,255,255,.78); }
.muted { color: var(--muted); }

.centered-view { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.auth-grid { width: min(1040px, 100%); display: grid; grid-template-columns: 1.1fr .9fr; border-radius: 34px; overflow: hidden; background: var(--surface); box-shadow: var(--shadow); min-height: 650px; }
.auth-visual { position: relative; background: linear-gradient(135deg, rgba(49,80,67,.1), rgba(49,80,67,.55)), url('https://images.unsplash.com/photo-1522673607200-164d1b6ce486?auto=format&fit=crop&w=1400&q=85') center/cover; min-height: 520px; }
.visual-overlay { position: absolute; inset: auto 46px 46px; color: white; }
.visual-overlay h1 { font-size: clamp(2.5rem, 5vw, 4.4rem); }
.visual-overlay p { font-size: 1.15rem; margin-bottom: 0; }
.mini-heart { font-size: 2.2rem; }
.auth-card { background: var(--surface); padding: 54px; display: flex; flex-direction: column; justify-content: center; }
.auth-card h2, .setup-card h1, .onboarding-card h1 { font-size: clamp(2rem, 4vw, 3.4rem); }
.setup-card { max-width: 650px; border-radius: 30px; box-shadow: var(--shadow); }
.setup-card ol { color: var(--muted); line-height: 1.8; padding-left: 1.2rem; }
.brand-mark { width: 64px; height: 64px; display: grid; place-items: center; border-radius: 50%; background: var(--green); color: white; font-size: 2rem; margin-bottom: 20px; }
.brand-mark.small { width: 44px; height: 44px; font-size: 1.35rem; margin: 0; flex: 0 0 auto; }
.stack-form, .option-card { display: grid; gap: 18px; }
label { display: grid; gap: 8px; color: var(--ink); font-weight: 700; font-size: .9rem; }
input, textarea, select { width: 100%; border: 1px solid var(--border); border-radius: 14px; background: #fff; padding: 13px 14px; color: var(--ink); outline: none; transition: .2s ease; }
input:focus, textarea:focus, select:focus { border-color: var(--green); box-shadow: 0 0 0 4px rgba(69,107,90,.1); }
textarea { resize: vertical; }
.privacy-note { color: var(--muted); font-size: .8rem; margin-top: 24px; }

.button { border: 0; border-radius: 999px; padding: 12px 18px; font-weight: 800; display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; transition: transform .15s ease, box-shadow .15s ease, background .15s ease; }
.button:hover { transform: translateY(-1px); }
.button.primary { background: var(--green); color: white; box-shadow: 0 10px 28px rgba(69,107,90,.22); }
.button.primary:hover { background: var(--green-dark); }
.button.secondary { background: var(--pink-soft); color: #704846; }
.button.ghost { background: transparent; color: var(--green); border: 1px solid var(--border); }
.button.light { background: #fff; color: var(--green-dark); }
.button.danger { background: #8d413d; color: white; }
.button.full { width: 100%; }
.text-button { border: 0; background: transparent; padding: 8px 0; color: var(--green); font-weight: 800; }
.icon-button { width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--border); background: white; font-size: 1.5rem; color: var(--ink); }

.onboarding-card { width: min(900px, 100%); padding: 50px; background: var(--surface); border-radius: 34px; box-shadow: var(--shadow); }
.onboarding-options { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; margin: 34px 0 20px; }
.option-card { padding: 26px; border: 1px solid var(--border); border-radius: 22px; background: #fff; }
.option-card h3 { font-size: 1.55rem; }

.app-shell { min-height: 100dvh; display: grid; grid-template-columns: 270px 1fr; }
.sidebar { position: sticky; top: 0; height: 100dvh; background: var(--surface); border-right: 1px solid var(--border); padding: 28px 20px; display: flex; flex-direction: column; z-index: 10; }
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 34px; }
.brand strong { display: block; font-family: Georgia, serif; font-size: 1.1rem; }
.brand span { display: block; color: var(--muted); font-size: .78rem; margin-top: 2px; }
.sidebar-nav { display: grid; gap: 7px; }
.nav-item { border: 0; background: transparent; border-radius: 14px; padding: 12px 14px; display: flex; align-items: center; gap: 12px; color: var(--muted); font-weight: 800; text-align: left; }
.nav-item span { font-size: 1.25rem; }
.nav-item.active, .nav-item:hover { color: var(--green-dark); background: var(--sage); }
.sidebar-footer { margin-top: auto; display: grid; gap: 10px; }
.main-content { min-width: 0; padding: 34px clamp(24px, 4vw, 58px) 80px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 24px; margin-bottom: 32px; }
.topbar h1 { font-size: clamp(2rem, 4vw, 3.3rem); }
.topbar-actions { display: flex; gap: 12px; align-items: center; }
.search-box { width: min(380px, 38vw); display: flex; align-items: center; gap: 8px; background: white; border: 1px solid var(--border); border-radius: 999px; padding: 0 14px; font-weight: 400; }
.search-box input { border: 0; background: transparent; padding-left: 4px; box-shadow: none; }

.hero-card { min-height: 390px; border-radius: 34px; overflow: hidden; position: relative; display: flex; align-items: end; background: linear-gradient(90deg, rgba(24,45,36,.86) 0%, rgba(24,45,36,.55) 45%, rgba(24,45,36,.1) 100%), url('https://images.unsplash.com/photo-1474552226712-ac0f0961a954?auto=format&fit=crop&w=1800&q=88') center/cover; box-shadow: var(--shadow); }
.hero-copy { color: white; padding: clamp(30px, 6vw, 62px); max-width: 680px; }
.hero-copy h2 { font-size: clamp(2.3rem, 5vw, 4.4rem); line-height: 1.02; }
.hero-copy p:not(.eyebrow) { color: rgba(255,255,255,.82); font-size: 1.05rem; max-width: 550px; }
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin: 22px 0 40px; }
.stat-card { padding: 22px; background: var(--surface); border: 1px solid var(--border); border-radius: 20px; display: flex; align-items: end; justify-content: space-between; }
.stat-card span { color: var(--muted); font-weight: 700; }
.stat-card strong { font-family: Georgia, serif; font-size: 2rem; color: var(--green); }
.section-heading { display: flex; justify-content: space-between; align-items: end; gap: 20px; margin: 40px 0 18px; }
.section-heading h2 { font-size: 2rem; }
.memory-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; }
.memory-card { border: 1px solid var(--border); border-radius: 24px; overflow: hidden; background: var(--surface); min-width: 0; box-shadow: 0 12px 30px rgba(48,65,56,.07); transition: transform .2s ease, box-shadow .2s ease; }
.memory-card:hover { transform: translateY(-3px); box-shadow: 0 20px 38px rgba(48,65,56,.12); }
.memory-cover { aspect-ratio: 4 / 3; background: linear-gradient(135deg, var(--sage), var(--pink-soft)); position: relative; overflow: hidden; }
.memory-cover img, .memory-cover video { width: 100%; height: 100%; object-fit: cover; }
.memory-cover .placeholder-heart { position: absolute; inset: 0; display: grid; place-items: center; font-size: 3rem; color: rgba(69,107,90,.4); }
.favorite-badge { position: absolute; top: 12px; right: 12px; width: 38px; height: 38px; border-radius: 50%; border: 0; background: rgba(255,255,255,.88); color: #9b5550; font-size: 1.2rem; backdrop-filter: blur(10px); }
.memory-content { padding: 20px; }
.memory-meta { display: flex; flex-wrap: wrap; gap: 8px; color: var(--muted); font-size: .78rem; font-weight: 700; margin-bottom: 10px; }
.memory-category { display: inline-flex; padding: 5px 9px; background: var(--sage); color: var(--green-dark); border-radius: 999px; }
.memory-content h3 { font-size: 1.45rem; margin-bottom: 8px; }
.memory-content p { color: var(--muted); margin: 0; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.memory-card-footer { display: flex; justify-content: space-between; align-items: center; margin-top: 18px; }
.tag-list { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { font-size: .72rem; padding: 4px 8px; border-radius: 999px; background: #efe8de; color: #6b645b; }
.discovery-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 30px; }
.discovery-card { padding: 34px; border-radius: 28px; min-height: 245px; display: flex; flex-direction: column; align-items: flex-start; justify-content: flex-end; }
.discovery-card h3 { font-size: 2rem; }
.discovery-card p:not(.eyebrow) { color: var(--muted); }
.today-card { background: var(--pink-soft); }
.random-card { background: var(--sage); }

.filter-row { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 24px; }
.filter-row select { width: auto; min-width: 180px; background: white; }
.timeline-list { display: grid; gap: 42px; }
.timeline-year h2 { font-size: 3rem; margin-bottom: 18px; }
.timeline-items { position: relative; display: grid; gap: 18px; padding-left: 34px; }
.timeline-items::before { content: ''; position: absolute; left: 11px; top: 10px; bottom: 10px; width: 2px; background: var(--border); }
.timeline-entry { position: relative; }
.timeline-entry::before { content: ''; position: absolute; left: -29px; top: 30px; width: 12px; height: 12px; border-radius: 50%; background: var(--pink); border: 4px solid var(--bg); }
.timeline-entry .memory-card { display: grid; grid-template-columns: 210px 1fr; }
.timeline-entry .memory-cover { aspect-ratio: auto; min-height: 190px; }

.places-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.place-card { border: 1px solid var(--border); background: var(--surface); border-radius: 24px; padding: 26px; }
.place-card h3 { font-size: 1.6rem; }
.place-card strong { font-family: Georgia, serif; color: var(--green); font-size: 2.4rem; }
.settings-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px; }
.settings-card { background: var(--surface); border: 1px solid var(--border); border-radius: 26px; padding: 30px; }
.settings-card h2 { font-size: 2rem; }
.invite-code { display: flex; gap: 10px; align-items: center; margin-top: 24px; }
.invite-code code { font-size: 1.5rem; letter-spacing: .18em; background: var(--sage); color: var(--green-dark); padding: 12px 16px; }
.danger-card { border-color: rgba(141,65,61,.2); }

.memory-dialog, .detail-dialog { width: min(920px, calc(100% - 28px)); max-height: calc(100dvh - 28px); border: 0; padding: 0; border-radius: 28px; background: var(--surface); box-shadow: var(--shadow); }
.memory-dialog::backdrop, .detail-dialog::backdrop { background: rgba(24,45,36,.55); backdrop-filter: blur(5px); }
.memory-dialog form, .detail-shell { padding: 30px; overflow: auto; max-height: calc(100dvh - 28px); }
.dialog-header { display: flex; justify-content: space-between; gap: 20px; align-items: start; margin-bottom: 24px; }
.dialog-header h2 { font-size: 2.4rem; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.form-grid .wide { grid-column: 1 / -1; }
.check-label { display: flex; grid-template-columns: auto 1fr; align-items: center; gap: 10px; }
.check-label input { width: auto; }
.dialog-actions, .detail-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 26px; flex-wrap: wrap; }
.selected-files { display: flex; gap: 10px; flex-wrap: wrap; color: var(--muted); font-size: .82rem; }
.selected-files span { background: var(--surface-2); padding: 7px 10px; border-radius: 999px; }
.detail-gallery { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 28px; }
.detail-gallery img, .detail-gallery video { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 16px; background: var(--surface-2); }
.detail-body { display: grid; gap: 20px; }
.detail-block { border-top: 1px solid var(--border); padding-top: 18px; }
.detail-block:first-child { border-top: 0; padding-top: 0; }
.detail-block h3 { font-size: 1.3rem; margin-bottom: 6px; }
.detail-block p { color: var(--muted); white-space: pre-wrap; margin: 0; }
.empty-state { grid-column: 1 / -1; border: 1px dashed var(--border); border-radius: 24px; padding: 46px; text-align: center; color: var(--muted); background: rgba(255,255,255,.4); }
.empty-state h3 { color: var(--ink); font-size: 1.8rem; }

.toast { position: fixed; right: 20px; bottom: 20px; background: var(--ink); color: white; padding: 13px 17px; border-radius: 14px; box-shadow: var(--shadow); z-index: 1000; transform: translateY(150%); transition: transform .25s ease; max-width: min(380px, calc(100% - 40px)); }
.toast.show { transform: translateY(0); }
.mobile-nav { display: none; }

@media (max-width: 1100px) {
  .memory-grid { grid-template-columns: repeat(2, 1fr); }
  .places-grid { grid-template-columns: repeat(2, 1fr); }
  .topbar { align-items: flex-start; }
  .topbar-actions { flex-direction: column; align-items: stretch; }
  .search-box { width: 320px; max-width: 42vw; }
}

@media (max-width: 820px) {
  body { padding-bottom: 72px; }
  .auth-grid { grid-template-columns: 1fr; }
  .auth-visual { min-height: 310px; }
  .auth-card { padding: 34px 26px; }
  .onboarding-card { padding: 34px 22px; }
  .onboarding-options { grid-template-columns: 1fr; }
  .app-shell { display: block; }
  .sidebar { display: none; }
  .main-content { padding: 22px 16px 96px; }
  .topbar { margin-bottom: 22px; }
  .topbar-actions { display: none; }
  .hero-card { min-height: 450px; background-position: 62% center; }
  .hero-copy { padding: 30px 24px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .memory-grid, .places-grid, .settings-grid, .discovery-grid { grid-template-columns: 1fr; }
  .timeline-entry .memory-card { grid-template-columns: 1fr; }
  .timeline-entry .memory-cover { min-height: auto; aspect-ratio: 4 / 3; }
  .mobile-nav { position: fixed; display: grid; grid-template-columns: repeat(5, 1fr); align-items: end; left: 0; right: 0; bottom: 0; padding: 8px max(8px, env(safe-area-inset-left)) calc(8px + env(safe-area-inset-bottom)); background: rgba(255,250,243,.96); border-top: 1px solid var(--border); backdrop-filter: blur(18px); z-index: 30; }
  .mobile-nav-item { border: 0; background: transparent; color: var(--muted); display: grid; justify-items: center; gap: 2px; font-size: .66rem; font-weight: 800; }
  .mobile-nav-item span { font-size: 1.35rem; }
  .mobile-nav-item.active { color: var(--green); }
  .mobile-add { width: 54px; height: 54px; border-radius: 50%; border: 5px solid var(--surface); background: var(--green); color: white; font-size: 1.7rem; margin: -28px auto 0; box-shadow: 0 12px 24px rgba(69,107,90,.3); }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .wide { grid-column: auto; }
  .detail-gallery { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 520px) {
  .stats-grid { gap: 10px; }
  .stat-card { padding: 16px; display: grid; gap: 6px; }
  .section-heading { align-items: flex-start; flex-direction: column; }
  .dialog-header h2 { font-size: 1.85rem; }
  .memory-dialog form, .detail-shell { padding: 22px 18px; }
  .detail-gallery { grid-template-columns: 1fr; }
  .invite-code { align-items: stretch; flex-direction: column; }
}
