:root {
  --bg: #FFF9EC;            /* warm cream */
  --surface: #ffffff;
  --ink: #2a2015;           /* warm dark brown */
  --ink-soft: #6b5d49;
  --primary: #B45309;       /* burnt amber (buttons, links, accents) */
  --primary-dark: #8a3f07;
  --gold: #F5B514;          /* sunflower gold */
  --past: #2E7D32;          /* stem green */
  --past-soft: #E6F0E1;
  --future: #B45309;        /* amber */
  --future-soft: #FBEBD2;
  --line: #e6dcc6;
  --danger: #b3261e;
  --radius: 20px;
  --shadow: 0 2px 10px rgba(74, 46, 11, 0.10);
  --tap: 64px; /* minimum touch target */
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

/* Soft sunflower watermark in the page corners (behind all content). */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background-image: url("../assets/sunflower.svg"), url("../assets/sunflower.svg");
  background-repeat: no-repeat, no-repeat;
  background-position: right -55px bottom -45px, left -85px top -75px;
  background-size: 380px, 250px;
  opacity: 0.16;
  pointer-events: none;
}

body {
  font-size: 20px;
  line-height: 1.45;
}

#app {
  max-width: 640px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ---------- Shared layout ---------- */
.screen {
  flex: 1;
  padding: 20px 18px calc(96px + env(safe-area-inset-bottom, 0px));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px calc(14px + env(safe-area-inset-top, 0px));
}

.topbar h1 {
  font-size: 1.4rem;
  margin: 0;
  color: var(--primary-dark);
}

.icon-btn {
  min-width: 52px;
  min-height: 52px;
  border: none;
  background: transparent;
  color: var(--ink-soft);
  font-size: 1.6rem;
  border-radius: 14px;
  cursor: pointer;
}
.icon-btn:active { background: rgba(0,0,0,0.06); }

/* ---------- Home: clock ---------- */
.clock-card {
  background: linear-gradient(160deg, #F7CE55 0%, #F0A400 100%);
  color: #3a2a0a;
  border-radius: var(--radius);
  padding: 26px 22px;
  text-align: center;
  box-shadow: 0 4px 16px rgba(176, 120, 10, 0.28);
}
.clock-greeting { font-size: 1.4rem; color: #5a3f0c; margin-bottom: 6px; font-weight: 600; }
.clock-time {
  font-size: clamp(4.2rem, 22vw, 6.5rem);
  font-weight: 700;
  letter-spacing: 2px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.clock-date { font-size: clamp(1.3rem, 6vw, 1.8rem); margin-top: 10px; font-weight: 600; }

.birthday-card {
  margin-top: 22px;
  background: #FFF0F5;
  border: 2px solid #F48FB1;
  border-radius: var(--radius);
  padding: 18px 16px;
}
.birthday-row {
  font-size: 1.25rem;
  font-weight: 600;
  padding: 8px 0;
  display: flex;
  align-items: center;
  gap: 10px;
}
.birthday-emoji { font-size: 1.4rem; }

/* ---------- Home: birthday banner (all-day, dismissible) ---------- */
.birthday-banner {
  margin-bottom: 22px;
  background: linear-gradient(160deg, #FFE1EC 0%, #FFC2D6 100%);
  border: 3px solid #EC407A;
  border-radius: var(--radius);
  padding: 22px 20px;
  text-align: center;
  box-shadow: 0 4px 16px rgba(180, 30, 90, 0.22);
}
.birthday-banner-emoji {
  font-size: 3.4rem;
  line-height: 1;
}
.birthday-banner-title {
  font-size: clamp(1.5rem, 7vw, 2rem);
  font-weight: 700;
  color: #8a1141;
  margin: 8px 0 10px;
}
.birthday-banner-name {
  font-size: clamp(1.25rem, 5.5vw, 1.6rem);
  font-weight: 600;
  color: #5a2035;
  padding: 4px 0;
}
.birthday-banner-dismiss {
  margin-top: 16px;
  min-height: var(--tap);
  min-width: 55%;
  padding: 12px 28px;
  font-size: 1.3rem;
  font-weight: 700;
  color: #fff;
  background: #EC407A;
  border: none;
  border-radius: 999px;
  cursor: pointer;
}
.birthday-banner-dismiss:active { background: #c2185b; }

/* ---------- Sections ---------- */
.section { margin-top: 26px; }
.section-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0 0 12px;
}
.section-title .dot {
  width: 18px; height: 18px; border-radius: 50%;
  display: inline-block; flex: none;
}
.section.past .dot { background: var(--past); }
.section.future .dot { background: var(--future); }

.empty {
  background: var(--surface);
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  padding: 22px;
  text-align: center;
  color: var(--ink-soft);
}

/* ---------- Activity cards ---------- */
.event {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 18px 18px 22px;
  margin-bottom: 14px;
  border-left: 10px solid var(--line);
}
.section.past .event { border-left-color: var(--past); }
.section.future .event { border-left-color: var(--future); }

.event-photos {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}
.event-photos.count-1 { grid-template-columns: 1fr; }
.event-photos.count-2,
.event-photos.count-3 { grid-template-columns: 1fr 1fr; }
.event-photos.count-3 .event-photo:first-child { grid-column: 1 / -1; }

.event-photo {
  display: block;
  width: 100%;
  max-height: 220px;
  object-fit: cover;
  border-radius: 14px;
  cursor: pointer;
}
.event-photos.count-2 .event-photo,
.event-photos.count-3 .event-photo:not(:first-child) {
  max-height: 140px;
}
.event-title { font-size: 1.5rem; font-weight: 700; margin: 0 0 6px; }
.event-when { font-size: 1.2rem; color: var(--ink-soft); }
.event-note { margin-top: 8px; color: var(--ink-soft); font-size: 1.05rem; }

.chip {
  display: inline-block;
  margin-top: 10px;
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 1.2rem;
  font-weight: 700;
}
.section.past .chip { background: var(--past-soft); color: var(--past); }
.section.future .chip { background: var(--future-soft); color: var(--future); }

/* ---------- Bottom navigation ---------- */
.nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 20;
  display: flex;
  gap: 8px;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom, 0px));
  background: var(--surface);
  border-top: 1px solid var(--line);
  max-width: 640px;
  margin: 0 auto;
}
.nav a {
  flex: 1;
  min-height: 76px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  text-decoration: none;
  color: var(--ink-soft);
  font-size: 1.15rem;
  font-weight: 700;
  border-radius: 16px;
}
.nav a .nav-ico { font-size: 1.8rem; line-height: 1; }
.nav a[aria-current="page"] { color: var(--primary); background: var(--future-soft); }

/* ---------- Family tree ---------- */
.tree { overflow-x: auto; padding: 6px 2px 4px; -webkit-overflow-scrolling: touch; }
.tree ul {
  display: flex;
  justify-content: center;
  padding-top: 16px;
  position: relative;
  list-style: none;
  margin: 0;
  padding-left: 0;
}
.tree li {
  position: relative;
  padding: 16px 6px 0;
  text-align: center;
}
/* connectors */
.tree li::before, .tree li::after {
  content: "";
  position: absolute;
  top: 0; right: 50%;
  border-top: 2px solid var(--line);
  width: 50%; height: 16px;
}
.tree li::after { right: auto; left: 50%; border-left: 2px solid var(--line); }
.tree li:only-child::before, .tree li:only-child::after { display: none; }
.tree li:first-child::before, .tree li:last-child::after { border: 0; }
.tree li:last-child::before {
  border-right: 2px solid var(--line);
  border-radius: 0 6px 0 0;
}
.tree li:first-child::after { border-radius: 6px 0 0 0; }
.tree > ul { padding-top: 0; }
.tree > ul > li { padding-top: 0; }
.tree > ul > li::before, .tree > ul > li::after { display: none; }
/* vertical line down from a parent */
.tree ul ul::before {
  content: "";
  position: absolute;
  top: 0; left: 50%;
  border-left: 2px solid var(--line);
  width: 0; height: 16px;
}

.person {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: var(--surface);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 8px 10px;
  min-width: 0;
  max-width: 88px;
}
.person .avatar {
  width: 64px; height: 64px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--future-soft);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.35rem; font-weight: 700; color: var(--primary);
  overflow: hidden;
  flex-shrink: 0;
}
.person .avatar img { width: 100%; height: 100%; object-fit: cover; pointer-events: none; }
.person .avatar.has-photo {
  cursor: pointer;
}
.person .avatar.has-photo:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}

/* Enlarged family photo overlay */
.photo-lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(42, 32, 21, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  padding-top: max(24px, env(safe-area-inset-top));
  padding-bottom: max(24px, env(safe-area-inset-bottom));
  cursor: pointer;
}
.photo-lightbox img {
  max-width: min(92vw, 420px);
  max-height: min(78vh, 420px);
  width: auto;
  height: auto;
  border-radius: 50%;
  object-fit: cover;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  cursor: default;
  aspect-ratio: 1;
}
.photo-lightbox-close {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  width: 52px;
  height: 52px;
  border: none;
  border-radius: 50%;
  background: var(--surface);
  color: var(--ink);
  font-size: 2rem;
  line-height: 1;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.photo-lightbox-close:active { background: var(--future-soft); }
.person .p-name {
  font-weight: 700;
  font-size: 0.95rem;
  line-height: 1.2;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.person .p-rel { font-size: 0.8rem; color: var(--ink-soft); line-height: 1.2; }
.person .p-birth { margin-top: 4px; line-height: 1.25; }
.person .p-age { font-size: 0.8rem; color: var(--ink); font-weight: 600; }
.person .p-birthday-label { font-size: 0.7rem; color: var(--ink-soft); margin-top: 2px; }
.person .p-birthday-date { font-size: 0.7rem; color: var(--ink-soft); }
.person.is-self { outline: 2px solid var(--primary); }

.couple {
  display: inline-flex;
  gap: 8px;
  align-items: flex-start;
  flex-wrap: wrap;
  justify-content: center;
}

/* Dementia-friendly mobile family view: simple vertical groups */
.family-simple {
  display: grid;
  gap: 14px;
}
.family-simple-section {
  background: var(--surface);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 12px;
}
.family-simple-title {
  margin: 0 0 10px;
  font-size: 1.05rem;
  color: var(--ink-soft);
}
.family-simple-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.family-simple-group {
  padding-left: 12px;
  border-left: 3px solid var(--line, rgba(0, 0, 0, 0.08));
  margin-bottom: 14px;
}
.family-simple-group:last-child {
  margin-bottom: 0;
}
.family-simple-subtitle {
  margin: 0 0 8px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--ink);
}
.family-simple .person {
  max-width: 112px;
  padding: 10px 12px;
}
.family-simple .person .avatar {
  width: 72px;
  height: 72px;
}

/* Slightly larger on tablets / wide screens */
@media (min-width: 600px) {
  .person { max-width: 110px; padding: 12px 14px; gap: 6px; }
  .person .avatar { width: 80px; height: 80px; font-size: 1.7rem; }
  .person .p-name { font-size: 1.1rem; }
  .person .p-rel { font-size: 0.9rem; }
  .tree li { padding: 20px 10px 0; }
  .tree ul { padding-top: 20px; }
  .tree li::before, .tree li::after { height: 20px; }
  .tree ul ul::before { height: 20px; }
}

/* ---------- Admin ---------- */
.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 18px;
}
.tabs button {
  flex: 1;
  min-height: 54px;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 14px;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--ink-soft);
  cursor: pointer;
}
.tabs button[aria-selected="true"] {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.list-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 14px 16px;
  margin-bottom: 12px;
}
/* Name column: keep enough width that when the action buttons don't fit beside
   it they wrap to their own line instead of crowding the name. */
.list-row .grow { flex: 1 1 55%; min-width: 55%; }
.list-row .r-title { font-weight: 700; font-size: 1.15rem; overflow-wrap: anywhere; }
.list-row .r-sub { color: var(--ink-soft); font-size: 1rem; overflow-wrap: anywhere; }

label.field {
  display: block;
  margin-bottom: 16px;
  font-weight: 600;
}
label.field span { display: block; margin-bottom: 6px; }
input, select, textarea {
  width: 100%;
  font: inherit;
  padding: 14px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: #fff;
  color: var(--ink);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
}
textarea { min-height: 84px; resize: vertical; }

.btn {
  min-height: var(--tap);
  padding: 0 22px;
  border: none;
  border-radius: 16px;
  font-size: 1.2rem;
  font-weight: 700;
  cursor: pointer;
  background: var(--primary);
  color: #fff;
}
.btn:active { background: var(--primary-dark); }
.btn.block { width: 100%; }
.btn.ghost { background: var(--surface); color: var(--primary); border: 2px solid var(--primary); }
.btn.danger { background: var(--danger); }
.btn.small { min-height: 48px; font-size: 1rem; padding: 0 16px; }
.btn:disabled { opacity: 0.45; cursor: default; }

.row-actions { display: flex; gap: 8px; flex-shrink: 0; margin-left: auto; }

/* Wide screens: name + actions fit on one line, so keep them inline.
   (Placed after the base .list-row rules so it wins at equal specificity.) */
@media (min-width: 600px) {
  .list-row { flex-wrap: nowrap; }
  .list-row .grow { flex: 1 1 auto; min-width: 0; }
}

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}
.form-actions .btn { flex: 1; }

/* ---------- PIN pad ---------- */
.pin-wrap {
  max-width: 340px;
  margin: 8vh auto 0;
  text-align: center;
}
.pin-title { font-size: 1.4rem; font-weight: 700; margin-bottom: 14px; }
.pin-dots { display: flex; gap: 14px; justify-content: center; margin: 18px 0 8px; }
.pin-dots i {
  width: 20px; height: 20px; border-radius: 50%;
  border: 3px solid var(--primary);
}
.pin-dots i.filled { background: var(--primary); }
.pin-error { color: var(--danger); min-height: 1.4em; font-weight: 700; }
.pin-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 12px;
}
.pin-grid button {
  min-height: 76px;
  font-size: 1.8rem;
  font-weight: 700;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 16px;
  cursor: pointer;
  color: var(--ink);
}
.pin-grid button:active { background: var(--future-soft); }
.pin-grid button.wide { grid-column: span 1; font-size: 1.1rem; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 110px;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 12px 20px;
  border-radius: 999px;
  font-weight: 700;
  box-shadow: var(--shadow);
  z-index: 50;
  opacity: 0;
  transition: opacity .2s;
  pointer-events: none;
}
.toast.show { opacity: 1; }

/* Photo picker preview (rectangular, for activities) */
.photo-preview {
  width: 96px;
  height: 72px;
  border-radius: 12px;
  background: var(--future-soft);
  border: 2px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex: none;
}
.photo-preview img { width: 100%; height: 100%; object-fit: cover; }
.photo-preview .photo-empty { font-size: 1.8rem; opacity: 0.6; }

.photos-field-list {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 8px;
}
.photos-field-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-start;
}
.photos-field-add {
  display: flex;
  align-items: center;
  min-height: 72px;
}

.hint { color: var(--ink-soft); font-size: 1rem; margin: -6px 0 16px; }
.subhead { font-size: 1.25rem; font-weight: 700; margin: 22px 0 12px; }

/* ---------- Auth / onboarding (owner + invites) ---------- */
.auth-body { max-width: 420px; margin: 4vh auto 0; }
.auth-card { text-align: left; }
.auth-card .btn.block { margin-top: 6px; }
.auth-card .btn.block + .hint { margin-top: 10px; }
.auth-lead { color: var(--ink-soft); font-size: 1.05rem; margin: 0 0 14px; }
.auth-divider { height: 1px; background: var(--line); margin: 26px 0 18px; }
.auth-icon { font-size: 3rem; text-align: center; margin: 8px 0; }
.invites-section, .claim-section { margin: 4px 0; }
.family-code {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 1.8rem;
  font-weight: 700;
  letter-spacing: 4px;
  text-align: center;
  background: var(--future-soft);
  border: 2px dashed var(--primary);
  border-radius: 14px;
  padding: 18px 12px;
  margin: 6px 0 10px;
  word-break: break-all;
}

/* Low-emphasis links for non-patient sign-in methods (owner/admin, switch family)
   — deliberately small so a patient doesn't tap them by accident. */
.auth-alt { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-top: 18px; }
.linkish {
  background: none;
  border: none;
  color: var(--ink-soft);
  font-size: 0.95rem;
  text-decoration: underline;
  cursor: pointer;
  padding: 6px 8px;
}
.linkish:active { color: var(--primary); }

/* Simple circular avatar used in Settings (patient photo). */
.circle-avatar {
  border-radius: 999px;
  background: var(--future-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.9rem;
  font-weight: 700;
  color: var(--primary);
  overflow: hidden;
  flex-shrink: 0;
}
.circle-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
