:root {
  --bg: #f6f4ef;
  --card: rgba(255, 255, 255, .88);
  --ink: #24231f;
  --muted: #77736b;
  --line: rgba(36, 35, 31, .1);
  --accent: #7058d6;
  --accent-soft: #ece8ff;
  --warm: #e8865a;
  --shadow: 0 20px 55px rgba(50, 44, 35, .08);
  --surface: rgba(255, 255, 255, .76);
  --surface-solid: #fff;
  --modal: #fbfaf7;
  --topbar: rgba(246,244,239,.78);
  --soft-bg: #efede8;
  --media-bg: #e9e5dd;
  --body-text: #5f5b54;
  --label: #5c5953;
  --glow: #fff;
  --primary-bg: #24231f;
  --primary-text: #fff;
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-synthesis: none;
}

:root[data-theme="dark"] {
  --bg: #11110f;
  --card: rgba(31, 31, 28, .94);
  --ink: #f5f3ed;
  --muted: #aaa69c;
  --line: rgba(255, 255, 255, .12);
  --accent: #a993ff;
  --accent-soft: #332b52;
  --shadow: 0 22px 60px rgba(0,0,0,.28);
  --surface: rgba(40, 40, 36, .84);
  --surface-solid: #292925;
  --modal: #1d1d1a;
  --topbar: rgba(17,17,15,.82);
  --soft-bg: #30302c;
  --media-bg: #242420;
  --body-text: #c6c2b8;
  --label: #c5c1b8;
  --glow: #26231f;
  --primary-bg: #a993ff;
  --primary-text: #171512;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: radial-gradient(circle at 20% -20%, var(--glow) 0, transparent 38%), var(--bg); transition: background .25s, color .25s; }
button, input, textarea, select { font: inherit; }
button { border: 0; cursor: pointer; }
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 3px solid rgba(112, 88, 214, .25); outline-offset: 2px; }
.hidden { display: none !important; }

.auth-shell { min-height: 100vh; display: grid; grid-template-columns: 1.05fr .95fr; padding: 28px; gap: 28px; }
.auth-art { border-radius: 34px; padding: clamp(32px, 6vw, 88px); display: flex; flex-direction: column; justify-content: space-between; min-height: calc(100vh - 56px); color: white; overflow: hidden; position: relative; background: linear-gradient(145deg, #5941bd, #8c77e6 55%, #d39dea); }
.auth-art::after { content: ""; position: absolute; width: 480px; height: 480px; border-radius: 50%; background: rgba(255,255,255,.12); right: -150px; bottom: -170px; }
.brand { display: flex; align-items: center; gap: 12px; font-weight: 700; letter-spacing: -.02em; position: relative; z-index: 1; }
.brand-mark { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 14px; background: rgba(255,255,255,.18); backdrop-filter: blur(14px); font-size: 21px; }
.auth-quote { max-width: 600px; position: relative; z-index: 1; }
.auth-quote h1 { margin: 0 0 20px; font-size: clamp(40px, 6vw, 76px); line-height: .98; letter-spacing: -.065em; font-weight: 650; }
.auth-quote p { margin: 0; max-width: 470px; color: rgba(255,255,255,.8); font-size: 18px; line-height: 1.55; }
.auth-card-wrap { display: grid; place-items: center; padding: 32px; }
.auth-card { width: min(430px, 100%); }
.eyebrow { font-size: 12px; text-transform: uppercase; letter-spacing: .14em; font-weight: 750; color: var(--accent); }
.auth-card h2 { font-size: 38px; letter-spacing: -.05em; margin: 12px 0 10px; }
.auth-card > p { color: var(--muted); line-height: 1.5; margin: 0 0 30px; }

.field { display: grid; gap: 8px; margin-bottom: 16px; }
.field label { font-size: 13px; font-weight: 650; color: var(--label); }
.field input, .field textarea, .field select { width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 15px; padding: 14px 15px; color: var(--ink); transition: border .2s, box-shadow .2s; }
.field textarea { min-height: 145px; resize: vertical; line-height: 1.5; }
.field input:focus, .field textarea:focus, .field select:focus { border-color: rgba(112,88,214,.5); box-shadow: 0 0 0 4px rgba(112,88,214,.08); outline: none; }
.primary { width: 100%; background: var(--primary-bg); color: var(--primary-text); border-radius: 15px; padding: 15px 20px; font-weight: 750; transition: transform .15s, opacity .15s; }
.primary:hover { transform: translateY(-1px); }
.primary:disabled { opacity: .72; cursor: progress; }
.form-error { color: #b53f3f; min-height: 20px; font-size: 14px; margin: 10px 0; }

.app-shell { min-height: 100vh; }
.topbar { height: 78px; display: flex; align-items: center; justify-content: space-between; padding: 0 max(28px, calc((100vw - 1180px)/2)); position: sticky; top: 0; z-index: 20; backdrop-filter: saturate(180%) blur(20px); background: var(--topbar); border-bottom: 1px solid var(--line); }
.topbar .brand-mark { color: white; background: var(--accent); width: 38px; height: 38px; border-radius: 12px; }
.topbar-actions { display: flex; gap: 10px; align-items: center; }
.icon-btn, .soft-btn { min-height: 42px; border-radius: 13px; background: var(--surface); color: var(--ink); border: 1px solid var(--line); padding: 0 15px; font-weight: 650; display: inline-flex; align-items: center; gap: 8px; }
.theme-button { width: 42px; justify-content: center; padding: 0; font-size: 18px; }
.add-btn { min-height: 44px; border-radius: 14px; background: var(--primary-bg); color: var(--primary-text); padding: 0 18px; font-weight: 700; display: inline-flex; align-items: center; gap: 8px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: inline-grid; place-items: center; color: white; font-weight: 750; font-size: 13px; flex: 0 0 auto; }

.page { width: min(1180px, calc(100% - 40px)); margin: 0 auto; padding: 54px 0 80px; }
.hero { display: grid; grid-template-columns: 1fr auto; gap: 30px; align-items: end; margin-bottom: 38px; }
.hero h1 { font-size: clamp(42px, 7vw, 72px); line-height: .98; letter-spacing: -.065em; margin: 9px 0 10px; font-weight: 650; }
.hero p { margin: 0; color: var(--muted); font-size: 17px; }
.member-stack { display: flex; align-items: center; justify-content: flex-end; }
.member-stack .avatar { margin-left: -8px; border: 3px solid var(--bg); width: 42px; height: 42px; }

.toolbar { display: flex; gap: 12px; margin-bottom: 30px; align-items: center; }
.search { flex: 1; position: relative; }
.search input { width: 100%; min-height: 48px; border: 1px solid var(--line); background: var(--surface); border-radius: 16px; padding: 0 16px 0 44px; color: var(--ink); }
.search::before { content: "⌕"; position: absolute; left: 16px; top: 10px; font-size: 23px; color: var(--muted); transform: rotate(-12deg); }
.tabs { display: flex; padding: 4px; border-radius: 15px; background: var(--surface); border: 1px solid var(--line); }
.tab { background: transparent; border-radius: 11px; padding: 10px 14px; color: var(--muted); font-weight: 650; }
.tab.active { background: var(--surface-solid); color: var(--ink); box-shadow: 0 4px 16px rgba(36,35,31,.06); }

.timeline { display: grid; grid-template-columns: repeat(12, 1fr); gap: 24px; }
.memory { grid-column: span 6; border-radius: 26px; overflow: hidden; background: var(--card); box-shadow: var(--shadow); border: 1px solid var(--line); }
.memory.featured { grid-column: span 12; display: grid; grid-template-columns: 1.25fr .75fr; }
.media-wrap { background: var(--media-bg); min-height: 260px; display: grid; position: relative; overflow: hidden; }
.memory.featured .media-wrap { min-height: 470px; }
.media-wrap img, .media-wrap video { width: 100%; height: 100%; object-fit: cover; position: absolute; inset: 0; }
.media-wrap audio { width: calc(100% - 40px); margin: auto 20px 20px; align-self: end; z-index: 2; }
.audio-art { display: grid; place-items: center; color: white; background: linear-gradient(135deg, #7058d6, #d88aab); font-size: 56px; }
.photo-count { position: absolute; z-index: 3; top: 14px; right: 14px; padding: 7px 10px; border-radius: 999px; color: white; background: rgba(25,24,22,.55); backdrop-filter: blur(10px); font-size: 12px; font-weight: 700; }
.gallery-hit { position: absolute; inset: 0; z-index: 2; background: transparent; cursor: zoom-in; }
.memory-body { padding: 26px; display: flex; flex-direction: column; }
.memory-meta { display: flex; align-items: center; gap: 9px; color: var(--muted); font-size: 13px; }
.memory h2 { font-size: 26px; line-height: 1.1; letter-spacing: -.035em; margin: 18px 0 10px; }
.memory-location { display: flex; align-items: center; gap: 6px; color: var(--accent); font-size: 13px; font-weight: 700; margin: -2px 0 10px; }
.memory p { color: var(--body-text); line-height: 1.6; margin: 0; white-space: pre-wrap; }
.memory-tags { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 20px; }
.tag { background: var(--accent-soft); color: #5d48bd; border-radius: 99px; padding: 6px 10px; font-size: 12px; font-weight: 700; }
.privacy-badge { background: #f2e7d8; color: #805b2c; border-radius: 999px; padding: 5px 8px; font-size: 11px; font-weight: 750; }
.memory-actions { display: flex; align-items: center; justify-content: space-between; margin-top: auto; padding-top: 22px; }
.byline { display: flex; align-items: center; gap: 9px; font-size: 13px; font-weight: 650; }
.post-actions { display: flex; gap: 4px; }
.edit, .delete { background: transparent; padding: 8px; border-radius: 10px; }
.edit { color: var(--accent); }
.delete { color: #c16b6b; }
.edit:hover { background: var(--accent-soft); }
.delete:hover { background: #fff0f0; }

.empty { grid-column: 1/-1; min-height: 390px; border: 1px dashed rgba(36,35,31,.18); border-radius: 26px; display: grid; place-items: center; text-align: center; padding: 40px; }
.empty-icon { width: 78px; height: 78px; border-radius: 26px; background: var(--accent-soft); display: grid; place-items: center; font-size: 34px; margin: 0 auto 20px; }
.empty h2 { margin: 0 0 8px; font-size: 25px; }
.empty p { color: var(--muted); margin: 0 0 22px; }

.modal-backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(20,18,15,.38); backdrop-filter: blur(8px); display: grid; place-items: center; padding: 20px; animation: fade .18s ease-out; }
.modal { width: min(680px, 100%); max-height: min(850px, calc(100vh - 30px)); overflow: auto; border-radius: 28px; background: var(--modal); box-shadow: 0 34px 100px rgba(20,18,15,.26); padding: 30px; animation: lift .22s ease-out; }
.modal.small { width: min(500px, 100%); }
.modal.gallery-modal { width: min(980px, 100%); }
.modal-head { display: flex; justify-content: space-between; align-items: start; margin-bottom: 25px; }
.modal h2 { margin: 0 0 5px; font-size: 29px; letter-spacing: -.04em; }
.modal-head p { color: var(--muted); margin: 0; }
.close { width: 38px; height: 38px; border-radius: 50%; background: var(--soft-bg); color: var(--ink); font-size: 20px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.location-row { display: flex; gap: 8px; }
.location-row input { min-width: 0; flex: 1; }
.location-row button { white-space: nowrap; }
.field-note { display: block; color: var(--muted); font-size: 12px; line-height: 1.4; margin-top: 7px; }
.textarea-wrap { position: relative; }
.voice { position: absolute; right: 10px; bottom: 10px; width: 40px; height: 40px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-size: 18px; }
.voice.listening { background: #ffdddd; color: #bd3d3d; animation: pulse 1.2s infinite; }
.dropzone { border: 1.5px dashed var(--line); border-radius: 18px; padding: 24px; text-align: center; background: var(--surface); transition: border .2s, background .2s; }
.dropzone.drag { border-color: var(--accent); background: var(--accent-soft); }
.dropzone strong { display: block; margin-bottom: 5px; }
.dropzone span { color: var(--muted); font-size: 13px; }
.media-buttons { display: flex; gap: 7px; flex-wrap: wrap; justify-content: center; }
.file-input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.dropzone button, .record-btn { margin-top: 13px; color: var(--accent); background: var(--accent-soft); padding: 10px 14px; border-radius: 12px; font-weight: 700; }
.record-btn.recording { color: #ad3434; background: #ffe5e5; }
.preview-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 9px; margin-top: 13px; }
.preview { aspect-ratio: 1; border-radius: 12px; overflow: hidden; background: var(--soft-bg); position: relative; display: grid; place-items: center; }
.preview img, .preview video { width: 100%; height: 100%; object-fit: cover; }
.preview.audio { color: var(--accent); font-weight: 750; font-size: 12px; padding: 7px; text-align: center; }
.preview-tools { position: absolute; inset: auto 5px 5px 5px; display: flex; justify-content: space-between; gap: 4px; z-index: 3; }
.preview-tools button { margin: 0; padding: 6px 8px; min-width: 31px; background: rgba(22,21,19,.74); color: white; backdrop-filter: blur(8px); border-radius: 9px; font-size: 11px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 25px; }
.modal-actions .primary { width: auto; min-width: 150px; }
.members { display: grid; gap: 10px; margin: 18px 0 24px; }
.member-row { background: var(--surface-solid); border: 1px solid var(--line); border-radius: 16px; display: flex; align-items: center; padding: 12px; gap: 11px; }
.member-row small { display: block; color: var(--muted); margin-top: 3px; }
.invite-result { margin-top: 14px; padding: 13px; background: var(--accent-soft); border-radius: 13px; word-break: break-all; font-size: 13px; }
.gallery-view { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.gallery-view figure { margin: 0; border-radius: 18px; overflow: hidden; background: var(--soft-bg); }
.gallery-view img, .gallery-view video { display: block; width: 100%; max-height: 72vh; object-fit: contain; background: var(--media-bg); }
.gallery-view figcaption { padding: 10px 12px; color: var(--muted); font-size: 12px; }
.gallery-audio { padding: 24px; }
.gallery-audio audio { width: 100%; }
.draw-layer { position: fixed; inset: 0; z-index: 100; background: rgba(8,8,7,.92); display: grid; place-items: center; padding: 16px; }
.draw-shell { width: min(1100px, 100%); height: min(900px, calc(100vh - 32px)); display: grid; grid-template-rows: auto minmax(0, 1fr) auto; border-radius: 25px; overflow: hidden; background: var(--modal); box-shadow: 0 30px 100px rgba(0,0,0,.45); }
.draw-head { display: flex; align-items: center; justify-content: space-between; gap: 15px; padding: 16px 18px; }
.draw-head strong { display: block; font-size: 19px; }
.draw-head span { display: block; color: var(--muted); font-size: 13px; margin-top: 3px; }
.draw-stage { min-height: 0; display: grid; place-items: center; overflow: hidden; background: #0c0c0b; touch-action: none; }
.draw-stage canvas { display: block; max-width: 100%; max-height: 100%; width: auto; height: auto; touch-action: none; cursor: crosshair; }
.draw-toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; padding: 13px 16px max(13px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.draw-colors { display: flex; gap: 6px; }
.color { width: 30px; height: 30px; border-radius: 50%; background: var(--swatch); border: 2px solid rgba(128,128,128,.35); }
.color.active { box-shadow: 0 0 0 3px var(--accent); }
.draw-size { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; }
.draw-size input { width: 100px; }
.draw-text { display: flex; flex: 1; min-width: 220px; gap: 6px; }
.draw-text input { min-width: 0; flex: 1; border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 12px; padding: 10px 12px; }
.draw-save { width: auto; min-width: 135px; }
.toast { position: fixed; z-index: 90; bottom: 22px; left: 50%; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; background: #24231f; color: white; border-radius: 13px; padding: 12px 18px; box-shadow: var(--shadow); transition: .22s; font-size: 14px; }
.toast.show { transform: translate(-50%, 0); opacity: 1; }

@keyframes fade { from { opacity: 0; } }
@keyframes lift { from { transform: translateY(14px) scale(.985); opacity: .7; } }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px rgba(189,61,61,.12); } }

@media (max-width: 900px) {
  .auth-shell { grid-template-columns: 1fr; padding: 0; }
  .auth-art { min-height: 38vh; border-radius: 0 0 32px 32px; padding: 34px; }
  .auth-quote h1 { font-size: 48px; }
  .auth-card-wrap { padding: 30px 24px 50px; }
  .memory, .memory.featured { grid-column: span 12; display: block; }
  .memory.featured .media-wrap { min-height: 360px; }
}

@media (max-width: 600px) {
  .topbar { height: 68px; padding: 0 16px; }
  .topbar .brand span:last-child, .family-label, .add-label { display: none; }
  .topbar-actions { gap: 7px; }
  .icon-btn, .soft-btn { padding: 0 11px; }
  .add-btn { width: 42px; justify-content: center; padding: 0; font-size: 20px; }
  .page { width: min(100% - 28px, 1180px); padding-top: 35px; }
  .hero { grid-template-columns: 1fr; gap: 18px; margin-bottom: 26px; }
  .hero h1 { font-size: 47px; }
  .member-stack { justify-content: flex-start; padding-left: 7px; }
  .toolbar { align-items: stretch; flex-direction: column; }
  .tabs { width: 100%; }
  .tab { flex: 1; }
  .timeline { gap: 17px; }
  .memory .media-wrap, .memory.featured .media-wrap { min-height: 280px; }
  .memory-body { padding: 21px; }
  .modal-backdrop { padding: 0; align-items: end; }
  .modal, .modal.small { border-radius: 26px 26px 0 0; max-height: 94vh; padding: 24px 20px max(25px, env(safe-area-inset-bottom)); }
  .field-row { grid-template-columns: 1fr; gap: 0; }
  .preview-grid { grid-template-columns: repeat(3, 1fr); }
  .draw-layer { padding: 0; }
  .draw-shell { width: 100%; height: 100%; border-radius: 0; }
  .draw-toolbar { gap: 8px; }
  .draw-text { order: 5; flex-basis: 100%; }
  .draw-save { flex: 1; }
  .gallery-view { grid-template-columns: 1fr; }
  .auth-art { min-height: 320px; }
  .auth-art .brand { margin-bottom: 60px; }
  .auth-quote h1 { font-size: 42px; }
}

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; scroll-behavior: auto !important; } }
