:root {
  --ink: #252237;
  --muted: #747083;
  --paper: #ffffff;
  --background: #f6f3f8;
  --purple: #6f4b83;
  --purple-dark: #51345f;
  --purple-soft: #eee5f2;
  --rose: #d78da5;
  --line: #e5dee8;
  --danger: #aa3446;
  --shadow: 0 20px 60px rgba(61, 42, 70, 0.12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 85% 5%, rgba(215, 141, 165, 0.15), transparent 27%),
    var(--background);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 280px minmax(0, 1fr); }

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 30px 22px;
  background: #2d2533;
  color: white;
  display: flex;
  flex-direction: column;
  gap: 34px;
}

.brand { display: flex; align-items: center; gap: 13px; }
.brand-mark {
  width: 48px;
  height: 48px;
  border-radius: 17px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, #f5c6d5, #b489c6);
  color: #3b2944;
  font: 700 24px Georgia, serif;
}
.brand h1 { margin: 0; font: 600 21px Georgia, serif; }
.brand p { margin: 4px 0 0; color: #cfc3d3; font-size: 12px; }

.sidebar nav { display: grid; gap: 8px; }
.nav-button {
  padding: 13px 15px;
  border: 0;
  border-radius: 12px;
  text-align: left;
  background: transparent;
  color: #d7ceda;
}
.nav-button:hover, .nav-button.active { background: rgba(255,255,255,.1); color: white; }

.database-card {
  margin-top: auto;
  border: 1px solid rgba(255,255,255,.13);
  border-radius: 14px;
  padding: 14px;
  display: flex;
  gap: 10px;
  align-items: center;
  background: rgba(255,255,255,.05);
}
.database-card small { display: block; margin-top: 4px; color: #cfc3d3; }
.database-light { width: 10px; height: 10px; border-radius: 50%; background: #9ee4b0; box-shadow: 0 0 0 5px rgba(158,228,176,.1); }

main { min-width: 0; padding: 0 42px 60px; }
.topbar {
  min-height: 116px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}
.topbar h2 { margin: 2px 0 0; font: 600 34px Georgia, serif; }
.eyebrow { margin: 0; color: var(--purple); text-transform: uppercase; letter-spacing: .14em; font-size: 11px; font-weight: 800; }

.primary-button, .secondary-button, .danger-button, .icon-button, .edit-button {
  border-radius: 11px;
  border: 1px solid transparent;
  padding: 11px 16px;
  font-weight: 700;
}
.primary-button { background: var(--purple); color: white; }
.primary-button:hover { background: var(--purple-dark); }
.primary-button:disabled { opacity: .55; cursor: wait; }
.secondary-button { background: white; color: var(--ink); border-color: var(--line); }
.danger-button { background: #fff1f3; color: var(--danger); border-color: #f1c6cd; }
.icon-button { padding: 4px 10px; font-size: 28px; background: transparent; color: var(--muted); }
.hidden { display: none !important; }

.view { display: none; }
.view.active { display: block; }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 22px; }
.stats-grid article {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 8px 25px rgba(54,38,62,.05);
}
.stats-grid strong { display: block; font: 600 30px Georgia, serif; color: var(--purple-dark); }
.stats-grid span { display: block; margin-top: 5px; color: var(--muted); font-size: 13px; }

.toolbar {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) 220px;
  gap: 14px;
  padding: 18px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 16px;
}
label > span { display: block; margin-bottom: 7px; color: var(--muted); font-size: 12px; font-weight: 750; }
input, select, textarea {
  width: 100%;
  border: 1px solid #d9d1dd;
  border-radius: 10px;
  padding: 11px 12px;
  background: #fff;
  color: var(--ink);
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--purple); box-shadow: 0 0 0 3px rgba(111,75,131,.11); }
textarea { resize: vertical; }

.section-heading { display: flex; justify-content: space-between; align-items: end; margin: 30px 0 14px; }
.section-heading h3 { margin: 4px 0 0; font: 600 25px Georgia, serif; }
.section-heading > span { color: var(--muted); font-size: 13px; }

.memory-list { display: grid; gap: 13px; }
.memory-card {
  position: relative;
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr) auto;
  gap: 18px;
  padding: 18px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 17px;
  box-shadow: 0 8px 28px rgba(54,38,62,.045);
  transition: transform .15s ease, box-shadow .15s ease;
}
.memory-card:hover { transform: translateY(-1px); box-shadow: 0 14px 35px rgba(54,38,62,.09); }
.memory-card.important { border-left: 5px solid var(--rose); }
.date-tile {
  min-height: 82px;
  border-radius: 14px;
  background: var(--purple-soft);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--purple-dark);
}
.date-tile strong { font: 700 27px Georgia, serif; line-height: 1; }
.date-tile span { margin-top: 5px; font-weight: 800; font-size: 11px; letter-spacing: .1em; }
.date-tile small { margin-top: 2px; }
.memory-topline { display: flex; flex-wrap: wrap; gap: 7px; }
.category-badge, .important-badge { display: inline-flex; padding: 5px 8px; border-radius: 999px; font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; }
.category-badge { background: var(--purple-soft); color: var(--purple-dark); }
.important-badge { background: #fff0f4; color: #a54968; }
.memory-content h3 { margin: 10px 0 5px; font: 600 21px Georgia, serif; }
.memory-meta { margin: 0; color: var(--muted); font-size: 12px; }
.memory-description { max-width: 900px; margin: 12px 0 0; line-height: 1.55; color: #4d4855; white-space: pre-wrap; }
.memory-footer { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 13px; color: var(--muted); font-size: 12px; }
.edit-button { align-self: start; background: #faf8fb; border-color: var(--line); color: var(--purple); }
.empty-state { padding: 65px 20px; text-align: center; background: white; border: 1px dashed #cfc3d3; border-radius: 17px; color: var(--muted); }
.empty-state div { font-size: 35px; color: var(--rose); }
.empty-state h3 { margin-bottom: 6px; color: var(--ink); }
.empty-state p { margin: 0; }

.about-card { max-width: 850px; background: white; border: 1px solid var(--line); border-radius: 20px; padding: 35px; box-shadow: var(--shadow); }
.about-card h3 { margin: 7px 0 14px; font: 600 31px Georgia, serif; }
.about-card > p { color: var(--muted); line-height: 1.65; }
.included-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin: 26px 0; }
.included-grid div { padding: 17px; border-radius: 13px; background: var(--purple-soft); }
.included-grid strong, .included-grid span { display: block; }
.included-grid strong { color: var(--purple); font-size: 11px; text-transform: uppercase; letter-spacing: .1em; }
.included-grid span { margin-top: 5px; }
.next-note { border-left: 4px solid var(--rose); padding-left: 14px; }

.modal-backdrop { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 24px; background: rgba(34,27,39,.68); }
.modal { width: min(760px, 100%); max-height: calc(100vh - 48px); overflow-y: auto; background: white; border-radius: 20px; padding: 26px; box-shadow: var(--shadow); }
.modal-heading { display: flex; justify-content: space-between; align-items: start; margin-bottom: 21px; }
.modal-heading h3 { margin: 4px 0 0; font: 600 28px Georgia, serif; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.full-width { grid-column: 1 / -1; }
.checkbox-row { display: flex; gap: 10px; align-items: center; padding: 12px; background: #faf8fb; border-radius: 11px; }
.checkbox-row input { width: auto; }
.checkbox-row span { margin: 0; color: var(--ink); }
.form-error { margin: 15px 0 0; padding: 10px 12px; border-radius: 10px; background: #fff0f2; color: var(--danger); }
.modal-actions { display: flex; gap: 10px; margin-top: 22px; }
.action-spacer { flex: 1; }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 30; padding: 13px 17px; border-radius: 11px; background: #2e2832; color: white; box-shadow: var(--shadow); }
.toast.error { background: var(--danger); }

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; padding: 18px; }
  .sidebar nav { grid-template-columns: repeat(2, 1fr); }
  .database-card { margin-top: 0; }
  main { padding: 0 18px 40px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 600px) {
  .topbar { min-height: 100px; align-items: flex-start; padding-top: 22px; }
  .topbar h2 { font-size: 28px; }
  .stats-grid, .toolbar, .form-grid, .included-grid { grid-template-columns: 1fr; }
  .memory-card { grid-template-columns: 65px minmax(0, 1fr); }
  .edit-button { grid-column: 2; justify-self: start; }
  .date-tile { min-height: 68px; }
  .modal-backdrop { padding: 10px; }
  .modal { max-height: calc(100vh - 20px); padding: 20px; }
}

/* v0.2 media additions */
.memory-card { grid-template-columns: 150px minmax(0, 1fr) auto; overflow: hidden; }
.memory-cover { width: 150px; min-height: 128px; background: #ebe7df; overflow: hidden; display: grid; place-items: center; }
.memory-cover img, .memory-cover video { width: 100%; height: 100%; object-fit: cover; display: block; }
.memory-placeholder { font-size: 34px; color: var(--green); }
.memory-content { min-width: 0; }
.memory-meta span:last-child { font-weight: 700; }
.media-section { margin-top: 4px; padding-top: 20px; border-top: 1px solid var(--line); }
.media-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 10px; }
.media-heading > div { display: grid; gap: 3px; }
.media-heading > div > span { font-weight: 750; }
.media-heading small, #uploadSummary { color: var(--muted); }
.drop-zone { width: 100%; min-height: 104px; border: 2px dashed #b9c7bf; border-radius: 16px; background: #f8faf8; color: var(--ink); display: grid; place-content: center; gap: 6px; text-align: center; cursor: pointer; padding: 18px; }
.drop-zone:hover, .drop-zone.dragging { border-color: var(--green); background: #eef7f2; }
.drop-zone span { color: var(--muted); font-size: 13px; }
.asset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; margin-top: 12px; }
.asset-card { position: relative; min-width: 0; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; background: white; }
.asset-card.pending { border-style: dashed; }
.asset-preview { position: relative; height: 112px; background: #ecefeD; display: grid; place-items: center; overflow: hidden; text-decoration: none; color: var(--green); }
.asset-preview img, .asset-preview video { width: 100%; height: 100%; object-fit: cover; display: block; }
.file-icon { font-size: 34px; font-weight: 800; }
.play-badge { position: absolute; width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; background: rgba(255,255,255,.9); color: var(--green); box-shadow: 0 4px 18px rgba(0,0,0,.15); }
.asset-info { display: grid; gap: 3px; padding: 10px 34px 10px 11px; }
.asset-info strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.asset-info span { color: var(--muted); font-size: 11px; }
.remove-asset { position: absolute; right: 7px; bottom: 9px; width: 25px; height: 25px; border: 0; border-radius: 50%; background: #f5e9e7; color: #9a3026; cursor: pointer; font-size: 17px; line-height: 1; }
.upload-progress { margin-top: 16px; }
.upload-progress > div { height: 8px; border-radius: 99px; background: #e5ebe7; overflow: hidden; }
.upload-progress > div span { display: block; width: 0; height: 100%; background: var(--green); transition: width .2s ease; }
.upload-progress p { color: var(--muted); margin: 7px 0 0; font-size: 12px; }
@media (max-width: 720px) {
  .memory-card { grid-template-columns: 92px minmax(0, 1fr); }
  .memory-cover { width: 92px; min-height: 112px; }
  .edit-button { grid-column: 1 / -1; margin: 0 14px 14px; }
  .asset-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}