:root {
  --bg: #f7f8fb;
  --surface: #ffffff;
  --surface-soft: #f9fafb;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #d8dee8;
  --teal: #146c63;
  --teal-dark: #0f4f47;
  --coral: #ba4e3a;
  --gold: #9f6b16;
  --blue: #2f5f9f;
  --shadow: 0 14px 34px rgba(15, 23, 42, 0.07);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.4;
}

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

button {
  cursor: pointer;
}

.app {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr) 300px;
  grid-template-rows: 72px minmax(0, 1fr);
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 220px minmax(220px, 1fr) auto;
  align-items: center;
  gap: 18px;
  padding: 12px 22px;
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(16px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0;
  border: 0;
  color: var(--ink);
  background: transparent;
  text-align: left;
}

.brand-mark,
.avatar {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  overflow: hidden;
  width: 42px;
  height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 7px;
  background: var(--teal);
  color: #fff;
  font-weight: 800;
}

.brand small,
.person-meta small,
.post-meta,
.mini-panel span,
.account-gate p,
.eyebrow,
.empty-state,
.attachment-meta {
  color: var(--muted);
}

.search {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  max-width: 650px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
}

.search span {
  color: var(--muted);
  font-size: 0.83rem;
  font-weight: 700;
  text-transform: uppercase;
}

.search input {
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
}

.top-actions,
.form-actions,
.post-actions,
.person-actions,
.dialog-actions,
.profile-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.sidebar,
.right-rail {
  padding: 18px 16px;
}

.sidebar {
  border-right: 1px solid var(--line);
}

.right-rail {
  border-left: 1px solid var(--line);
}

nav {
  display: grid;
  gap: 8px;
}

.nav-button,
.category-button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  padding: 9px 10px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--ink);
  text-align: left;
}

.nav-button.active,
.category-button.active,
.segmented button.active {
  border-color: rgba(31, 122, 116, 0.28);
  background: #e8f1ee;
  color: var(--teal-dark);
}

.nav-icon {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: #eef2f7;
  font-size: 0.78rem;
  font-weight: 800;
}

.content {
  min-width: 0;
  padding: 24px 28px;
}

.view {
  display: none;
}

.active-view {
  display: block;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
}

.section-heading h1,
.section-heading h2,
.account-gate h1 {
  margin: 0;
  line-height: 1.12;
}

.section-heading h2 {
  max-width: 760px;
  font-size: clamp(1.25rem, 1.8vw, 1.65rem);
  font-weight: 760;
}

.eyebrow {
  margin: 0 0 6px;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.mini-panel,
.composer,
.account-gate,
.profile-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.mini-panel {
  margin-top: 18px;
  padding: 16px;
  box-shadow: none;
}

.mini-panel h2 {
  margin: 0 0 12px;
  font-size: 0.96rem;
}

.category-stack {
  display: grid;
  gap: 8px;
}

.category-button {
  justify-content: space-between;
  min-height: 38px;
  background: transparent;
  font-size: 0.92rem;
}

.category-button strong {
  color: var(--muted);
  font-size: 0.8rem;
}

.account-gate {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 24px;
  align-items: center;
  margin-bottom: 22px;
  padding: 24px;
  background: linear-gradient(135deg, #ffffff 0%, #f5f8fa 100%);
}

.account-gate[hidden],
.composer[hidden] {
  display: none;
}

.account-gate h1 {
  max-width: 620px;
  font-size: clamp(2rem, 4vw, 3.5rem);
  letter-spacing: 0;
}

.account-gate p {
  max-width: 600px;
  font-size: 1.02rem;
}

.account-form,
.memory-form {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 7px;
}

label span {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 750;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
}

input,
select {
  min-height: 42px;
  padding: 0 11px;
}

textarea {
  resize: vertical;
  padding: 11px;
}

.composer {
  margin-bottom: 22px;
  padding: 18px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.dropzone {
  display: grid;
  gap: 12px;
  place-items: center;
  min-height: 126px;
  padding: 18px;
  border: 1px dashed #9db2ad;
  border-radius: 7px;
  background: #f5faf9;
  text-align: center;
}

.dropzone.is-dragging {
  border-color: var(--teal);
  background: #e8f1ee;
}

.dropzone.photos-ready {
  border-color: var(--teal);
  background: #eef8f4;
}

.picker-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  width: 100%;
}

.picker-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 150px;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid rgba(20, 108, 99, 0.25);
  border-radius: 7px;
  background: #ffffff;
  color: var(--teal-dark);
  cursor: pointer;
  font-weight: 850;
  text-decoration: none;
}

.picker-button:hover {
  background: #e8f1ee;
}

.photos-panel {
  display: grid;
  gap: 6px;
  width: min(100%, 560px);
  min-height: 92px;
  padding: 18px;
  place-content: center;
  border: 2px dashed rgba(20, 108, 99, 0.42);
  border-radius: 7px;
  background: #ffffff;
  color: var(--teal-dark);
  outline: 0;
  text-align: center;
}

.photos-panel[hidden] {
  display: none;
}

.photos-panel span {
  color: var(--muted);
  font-size: 0.9rem;
}

.photos-panel em {
  color: var(--teal-dark);
  font-size: 0.86rem;
  font-style: normal;
  font-weight: 800;
}

.picker-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.dropzone small {
  color: var(--muted);
}

.primary-button,
.ghost-button,
.icon-button,
.small-button,
.segmented button {
  min-height: 40px;
  border-radius: 7px;
  font-weight: 750;
}

.primary-button {
  border: 1px solid var(--teal-dark);
  background: var(--teal);
  color: #fff;
  padding: 0 15px;
}

.ghost-button,
.small-button,
.segmented button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  padding: 0 12px;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 40px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
}

.segmented {
  display: flex;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.segmented button {
  min-height: 34px;
  border-color: transparent;
}

.post-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(330px, 1fr));
  gap: 16px;
}

.memory-list {
  display: grid;
  gap: 10px;
}

.memory-list-heading {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-end;
  margin: 4px 0 6px;
  color: var(--muted);
}

.memory-list-heading strong {
  color: var(--ink);
  font-size: 1rem;
}

.memory-list-heading span {
  font-size: 0.88rem;
}

.memory-row {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 8px 16px;
  align-items: center;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.04);
}

.memory-open {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  text-align: left;
}

.memory-open span {
  color: var(--teal);
  font-size: 0.82rem;
  font-weight: 850;
  text-transform: uppercase;
}

.memory-open strong {
  min-width: 0;
  overflow: hidden;
  font-size: 1rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.memory-row-meta,
.memory-facts,
.document-facts {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.memory-row-meta {
  justify-content: flex-end;
}

.memory-row-meta span,
.memory-facts span {
  min-height: 24px;
  padding: 3px 7px;
  border-radius: 6px;
  background: #f1f5f9;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 750;
}

.memory-row p {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.post-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.05);
}

.post-media {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 16 / 10;
  overflow: hidden;
  border: 0;
  background: #eef2f7;
}

.post-media img,
.post-media video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.post-media.placeholder {
  display: grid;
  place-items: center;
  padding: 20px;
  color: var(--teal-dark);
  font-weight: 850;
  min-height: 190px;
}

.post-body {
  padding: 16px;
}

.post-author,
.person-card,
.profile-card {
  display: flex;
  gap: 10px;
  align-items: center;
}

.post-author {
  margin-bottom: 12px;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.post-title-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
}

.post-card h3 {
  margin: 0;
  font-size: 1.1rem;
  line-height: 1.2;
}

.post-card p {
  margin: 8px 0 12px;
  color: #3a433e;
  line-height: 1.45;
}

.memory-facts {
  margin: 0 0 10px;
}

.pill,
.media-pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 8px;
  border-radius: 7px;
  background: #f2eee7;
  color: #6b5740;
  font-size: 0.78rem;
  font-weight: 800;
  white-space: nowrap;
}

.media-pill {
  background: #e8f1ee;
  color: var(--teal-dark);
}

.post-actions {
  justify-content: space-between;
  margin-top: 12px;
}

.small-button:hover,
.ghost-button:hover,
.icon-button:hover,
.segmented button:hover {
  background: #f8fafc;
}

.primary-button:hover {
  background: var(--teal-dark);
}

.small-button.liked {
  border-color: rgba(207, 96, 74, 0.36);
  background: #fae9e5;
  color: #9a351f;
}

.people-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
}

.person-card {
  align-items: flex-start;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.04);
}

.person-card .person-meta {
  min-width: 0;
  flex: 1;
}

.person-card h3,
.profile-panel h2 {
  margin: 0;
}

.person-card p,
.profile-panel p {
  margin: 6px 0 10px;
  color: var(--muted);
  line-height: 1.4;
}

.person-actions {
  margin-top: 10px;
}

.profile-panel {
  margin-bottom: 18px;
  padding: 20px;
}

.profile-card {
  align-items: flex-start;
  gap: 16px;
}

.profile-card .avatar {
  width: 74px;
  height: 74px;
  font-size: 1.5rem;
}

.profile-card.compact .avatar {
  width: 42px;
  height: 42px;
  font-size: 1rem;
}

.profile-copy {
  min-width: 0;
}

.stat-list {
  display: grid;
  gap: 10px;
}

.stat-list div {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 0;
  border-top: 1px solid var(--line);
}

.stat-list div:first-child {
  border-top: 0;
  padding-top: 0;
}

.memory-dialog {
  width: min(960px, calc(100vw - 28px));
  max-height: min(860px, calc(100vh - 28px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 22px 80px rgba(0, 0, 0, 0.28);
}

.memory-dialog::backdrop {
  background: rgba(23, 32, 28, 0.48);
}

.memory-document {
  display: grid;
  max-height: inherit;
  overflow: auto;
}

.document-cover {
  min-height: 230px;
  background: #eef2f7;
}

.document-cover img,
.document-cover video {
  width: 100%;
  height: 100%;
  max-height: 420px;
  object-fit: cover;
  display: block;
}

.document-body {
  padding: 24px;
}

.document-title {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
}

.document-title h2 {
  margin: 0;
  font-size: clamp(1.5rem, 3.3vw, 2.5rem);
  line-height: 1.1;
}

.document-story {
  max-width: 720px;
  color: #334155;
  font-size: 1.03rem;
  line-height: 1.6;
}

.document-facts {
  margin-bottom: 18px;
}

.attachment-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 18px;
}

.attachment-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.attachment-card img,
.attachment-card video {
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  display: block;
}

.attachment-card audio {
  width: calc(100% - 20px);
  margin: 12px 10px 4px;
}

.attachment-file {
  display: grid;
  gap: 8px;
  min-height: 128px;
  padding: 14px;
  place-content: center;
  text-align: center;
}

.attachment-meta {
  padding: 10px;
  font-size: 0.84rem;
}

.empty-state {
  grid-column: 1 / -1;
  padding: 22px;
  border: 1px dashed #c8d1df;
  border-radius: 8px;
  background: #fbfcfe;
  text-align: left;
}

.empty-state strong {
  display: block;
  color: var(--ink);
  font-size: 1rem;
  margin-bottom: 5px;
}

.empty-state p {
  margin: 0;
  color: var(--muted);
}

@media (max-width: 1120px) {
  .app {
    grid-template-columns: 188px minmax(0, 1fr);
  }

  .right-rail {
    display: none;
  }

  .topbar {
    grid-template-columns: 188px minmax(180px, 1fr) auto;
  }

  .people-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 820px) {
  .app {
    display: block;
  }

  .topbar {
    position: static;
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .top-actions {
    justify-content: stretch;
  }

  .top-actions button {
    flex: 1;
  }

  .sidebar {
    padding: 10px 14px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .sidebar nav {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .nav-button {
    justify-content: center;
    min-width: 0;
  }

  .nav-button span:last-child {
    display: none;
  }

  .sidebar .mini-panel {
    display: none;
  }

  .content {
    padding: 16px;
  }

  .section-heading,
  .document-title {
    align-items: flex-start;
    flex-direction: column;
  }

  .account-gate,
  .form-grid,
  .post-grid,
  .people-grid,
  .attachment-grid {
    grid-template-columns: 1fr;
  }

  .memory-row {
    grid-template-columns: 1fr;
  }

  .memory-row-meta {
    justify-content: flex-start;
  }

  .memory-list-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .segmented {
    width: 100%;
  }

  .segmented button {
    flex: 1;
  }
}
