/* jrow: plain CSS, no framework. Tokens first, then components. */

:root {
  color-scheme: light dark;

  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-hover: #fbfaf8;
  --text: #1c1b19;
  --muted: #6b6862;
  --border: #e4e1db;
  --accent: #2f6f5e;
  --accent-soft: #e3efe9;
  --danger-soft: #f8e6e3;
  --shadow: 0 1px 2px rgb(0 0 0 / .04), 0 4px 16px rgb(0 0 0 / .05);
  --cell-past: #8f8a80;
  --cell-future: #e6e2da;

  --radius: 14px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141413;
    --surface: #1d1c1a;
    --surface-hover: #232220;
    --text: #ecebe7;
    --muted: #9b978f;
    --border: #2e2d2a;
    --accent: #7cc4ad;
    --accent-soft: #1f2e29;
    --danger-soft: #3a2320;
    --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 4px 16px rgb(0 0 0 / .25);
    --cell-past: #77736b;
    --cell-future: #34332f;
  }
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }
h1, h2, h3 { line-height: 1.2; margin: 0; }

.wordmark {
  font-weight: 700;
  letter-spacing: -.03em;
  text-decoration: none;
}
.wordmark span { color: var(--accent); }

/* Flash */
.flash {
  max-width: 1040px;
  margin: 16px auto 0;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--accent-soft);
  font-size: .9rem;
}
.flash-alert { background: var(--danger-soft); }
.flash-stack { padding: 0 16px; }

/* Sign in */
.signin {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 16px;
}
.signin-card {
  width: min(100%, 380px);
  padding: 40px 32px 32px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: center;
}
.signin-card .wordmark { font-size: 2.25rem; }
.signin-card p { margin: 8px 0 28px; color: var(--muted); }
.signin-card form { margin: 0; }
.signin-foot { margin-top: 20px; font-size: .8rem; color: var(--muted); }

.btn-google {
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 11px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: 500 .95rem var(--font);
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.btn-google:hover { background: var(--surface-hover); border-color: var(--muted); }
.btn-google svg { width: 18px; height: 18px; }

/* App shell */
.topbar {
  position: sticky;
  top: 0;
  z-index: 1;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1040px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.topbar .wordmark { font-size: 1.25rem; }

.user {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  font-size: .875rem;
  color: var(--muted);
}
.user form { margin: 0; }
.user-email { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  flex: none;
  background: var(--accent-soft);
  color: var(--accent);
  display: grid;
  place-items: center;
  font-weight: 600;
  font-size: .8rem;
}
@media (max-width: 560px) { .user-email { display: none; } }

.btn-quiet {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font: 500 .8rem var(--font);
  cursor: pointer;
}
.btn-quiet:hover { background: var(--surface); }

.page {
  max-width: 1040px;
  margin: 0 auto;
  padding: 40px 16px 64px;
}
.page-header { margin-bottom: 28px; }
.page-header h1 { font-size: 1.75rem; letter-spacing: -.02em; }
.page-header p { margin: 6px 0 0; color: var(--muted); }

/* Launcher */
.launcher {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 16px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.tile {
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  transition: transform .15s, box-shadow .15s, border-color .15s;
}
a.tile:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--muted); }
.tile-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent);
}
.tile-icon svg { width: 22px; height: 22px; }
.tile h2 { font-size: 1.05rem; }
.tile p { margin: 0; color: var(--muted); font-size: .9rem; }
.tile-soon { opacity: .7; }
.badge {
  align-self: flex-start;
  margin-top: auto;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: .72rem;
  font-weight: 500;
}

.section-title {
  margin: 0 0 16px;
  font-size: .8rem;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}
.modules { margin-top: 56px; }
.tabular { font-variant-numeric: tabular-nums; }

/* Life calendar */
.life-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px 24px;
}
.eyebrow {
  margin: 0 0 6px;
  font-size: .8rem;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--accent);
}
.life-age { font-size: clamp(1.5rem, 4vw, 2.25rem); letter-spacing: -.02em; }
.life-sub { margin: 6px 0 0; color: var(--muted); font-variant-numeric: tabular-nums; }

.segmented {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}
.segmented button {
  padding: 6px 14px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font: 500 .875rem var(--font);
  cursor: pointer;
}
.segmented button:hover { color: var(--text); }
.segmented button[aria-pressed="true"] { background: var(--text); color: var(--bg); }

.life-meter { margin: 24px 0 28px; }
.life-meter-bar {
  height: 6px;
  border-radius: 999px;
  background: var(--cell-future);
  overflow: hidden;
}
.life-meter-bar span { display: block; height: 100%; width: 0; background: var(--accent); }
.life-meter p { margin: 8px 0 0; font-size: .875rem; color: var(--muted); }
.life-meter strong { color: var(--text); font-weight: 600; }

.life-frame {
  padding: 20px 20px 16px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.axis { margin: 0 0 10px 2.25rem; font-size: .75rem; color: var(--muted); }

.life-grid {
  --gap: 3px;
  --label: 2.25rem;
  display: grid;
  gap: var(--gap);
  margin: 0 auto;
}
.life-canvas { margin: 0 auto; }
.life[data-scale="weeks"] .life-grid { --gap: 2px; }
.life[data-scale="months"] .life-canvas { max-width: 760px; }
.life[data-scale="years"] .life-canvas { max-width: 560px; }
.life[data-scale="years"] .life-grid { --gap: 6px; }

.life-grid .row {
  display: grid;
  grid-template-columns: var(--label) repeat(var(--cols), minmax(0, 1fr));
  gap: var(--gap);
}
.life-grid .row.decade { margin-top: calc(var(--gap) * 3); }
.row-label {
  align-self: center;
  padding-right: 8px;
  text-align: right;
  font-size: .7rem;
  line-height: 1;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.cell {
  display: block;
  aspect-ratio: 1;
  border-radius: 2px;
  background: var(--cell-future);
}
.life[data-scale="months"] .life-grid .cell { border-radius: 3px; }
.life[data-scale="years"] .life-grid .cell { border-radius: 6px; }
.cell.past { background: var(--cell-past); }
.cell.now {
  background: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 35%, transparent);
  animation: pulse 2s ease-in-out infinite;
}
.life-grid .cell:hover { outline: 2px solid var(--accent); outline-offset: 1px; }

@keyframes pulse { 50% { box-shadow: 0 0 0 5px color-mix(in srgb, var(--accent) 0%, transparent); } }
@media (prefers-reduced-motion: reduce) { .cell.now { animation: none; } }

.legend {
  display: flex;
  gap: 18px;
  justify-content: flex-end;
  margin: 16px 0 0;
  padding: 0;
  list-style: none;
  font-size: .75rem;
  color: var(--muted);
}
.legend li { display: flex; align-items: center; gap: 6px; }
.legend .cell { width: 10px; }

.life-tooltip {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 10;
  display: grid;
  gap: 2px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--text);
  color: var(--bg);
  font-size: .8rem;
  line-height: 1.35;
  pointer-events: none;
  white-space: nowrap;
  box-shadow: var(--shadow);
}
.life-tooltip[hidden] { display: none; }
.life-tooltip em { font-style: normal; opacity: .65; font-size: .72rem; }

@media (max-width: 640px) {
  .life-frame { padding: 12px 10px 12px 4px; }
  .life-grid { --label: 1.5rem; }
  .life[data-scale="weeks"] .life-grid { --gap: 1px; }
  .life[data-scale="weeks"] .life-grid .cell { border-radius: 1px; }
  .axis { margin-left: 1.5rem; }
}

/* Birthday form */
.birthday-card {
  max-width: 520px;
  padding: 32px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.birthday-card p { color: var(--muted); }
.birthday-form { display: flex; flex-wrap: wrap; gap: 10px; }
.birthday-form input[type="date"] {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
.btn-primary {
  padding: 10px 16px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: var(--surface);
  font: 600 .9rem var(--font);
  cursor: pointer;
}

/* Module pages */
.crumbs { margin: 0 0 8px; font-size: .85rem; color: var(--muted); }
.crumbs a { text-decoration: none; }
.crumbs a:hover { color: var(--text); }
.panel {
  max-width: 560px;
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.panel h2 { font-size: 1.15rem; }
.panel p { color: var(--muted); }
.panel form { margin: 0; }
.facts {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 6px 20px;
  margin: 16px 0 24px;
  font-size: .9rem;
}
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.panel .panel-error { padding: 10px 12px; border-radius: 10px; background: var(--danger-soft); color: var(--text); font-size: .9rem; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }

/* Swarm: filters, check-ins, top places */
.filters {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
  align-items: end;
  margin: 0 0 32px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.filters label { display: flex; flex-direction: column; gap: 4px; font-size: .8rem; color: var(--muted); }
.filters input, .filters select {
  width: 100%;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: .9rem;
}
.filters-wide { grid-column: span 2; }
.filters-actions { display: flex; gap: 8px; align-items: center; }
.filters-compact { max-width: 480px; margin-bottom: 24px; }
@media (max-width: 560px) { .filters-wide { grid-column: auto; } }

.empty { color: var(--muted); }
.more { margin: 24px 0 0; }

.checkin-day { margin-bottom: 28px; }
.checkin-date {
  position: sticky;
  top: 55px;
  margin: 0 0 8px;
  padding: 6px 0;
  background: var(--bg);
  font-size: .85rem;
  font-weight: 600;
  color: var(--muted);
}
.checkins, .places { margin: 0; padding: 0; list-style: none; }
.checkin, .place {
  display: grid;
  grid-template-columns: 5.5rem 22px 1fr;
  gap: 4px 14px;
  align-items: start;
  padding: 12px 0;
  border-top: 1px solid var(--border);
}
.checkin-time { font-size: .9rem; line-height: 22px; }
.checkin-time span { display: block; font-size: .72rem; line-height: 1.2; color: var(--muted); }
.category-icon { width: 22px; height: 22px; border-radius: 6px; background: var(--cell-future); }
.checkin-body, .place-body { min-width: 0; }
.checkin-body p, .place-body p { margin: 0; }
.checkin-venue, .place-name { font-weight: 600; line-height: 22px; overflow-wrap: anywhere; }
.checkin-venue a, .place-name a { text-decoration: none; }
.checkin-venue a:hover, .place-name a:hover { text-decoration: underline; }
.checkin-venue .badge { margin-left: 6px; vertical-align: 2px; font-weight: 500; }
.checkin-meta { font-size: .85rem; color: var(--muted); }
.checkin-body .checkin-shout { margin-top: 4px; overflow-wrap: anywhere; }
.thumbs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.thumbs img { display: block; width: 64px; height: 64px; border-radius: 8px; object-fit: cover; background: var(--cell-future); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 16px; }
.chip {
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: .85rem;
  text-decoration: none;
  color: var(--muted);
}
.chip:hover { color: var(--text); border-color: var(--muted); }
.chip[aria-current="page"] { background: var(--text); border-color: var(--text); color: var(--bg); }
.place { grid-template-columns: 2.5rem 22px 1fr auto; align-items: center; }
.place-rank { font-size: .9rem; color: var(--muted); text-align: right; }
.place-stats { display: flex; flex-direction: column; align-items: flex-end; font-size: .85rem; white-space: nowrap; }
.place-stats span { color: var(--muted); font-size: .78rem; }
@media (max-width: 560px) {
  .place { grid-template-columns: 2rem 22px 1fr; }
  .place-stats { grid-column: 3; align-items: flex-start; flex-direction: row; gap: 8px; }
}

/* Life calendar: Swarm check-in shading and drill-in panel */
:root { --heat-1: color-mix(in srgb, var(--accent) 35%, var(--cell-past)); --heat-2: color-mix(in srgb, var(--accent) 55%, var(--cell-past)); --heat-3: color-mix(in srgb, var(--accent) 78%, var(--cell-past)); --heat-4: var(--accent); }
.cell[data-level="1"] { background: var(--heat-1); }
.cell[data-level="2"] { background: var(--heat-2); }
.cell[data-level="3"] { background: var(--heat-3); }
.cell[data-level="4"] { background: var(--heat-4); }
.life-grid .cell.past, .life-grid .cell.now { cursor: pointer; }
.life-grid button.cell { width: 100%; min-width: 0; padding: 0; border: 0; appearance: none; }
.life-grid button.cell:focus-visible { outline: 2px solid var(--text); outline-offset: 1px; }
.life-grid .cell.selected { outline: 2px solid var(--text); outline-offset: 1px; }
.life-hint { margin: 0 0 10px 2.25rem; font-size: .75rem; color: var(--muted); }
@media (max-width: 640px) { .life-hint { margin-left: 1.5rem; } } /* matches .axis and the narrower label column */
.life-panel { margin-top: 24px; padding: 20px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.life-panel[hidden] { display: none; }
.life-panel-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin-bottom: 12px; }
.life-panel-head h2 { flex: 1 1 auto; font-size: 1rem; }
.life-panel-head a { font-size: .85rem; color: var(--muted); }
.life-panel turbo-frame { display: block; transition: opacity .15s; }
.life-panel turbo-frame[busy] { opacity: .5; }

/* Swarm map (Google Maps). The map fills the window behind the translucent topbar, with the title,
   counts and filters in a panel floating over it. Dots, clusters and the info window's contents use the
   tokens; the map itself follows the system light/dark setting (colorScheme: FOLLOW_SYSTEM). */
.map-frame { position: fixed; inset: 0; z-index: 0; }
.swarm-map { width: 100%; height: 100%; background: var(--bg); }
.map-panel {
  position: relative; /* in the page flow, so it always sits just below the topbar, whatever its height */
  z-index: 1;
  width: min(420px, calc(100vw - 32px));
  margin: 16px;
  padding: 14px 16px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.map-panel .flash-stack, .map-panel .flash { padding: 0; margin: 0 0 10px; max-width: none; }
.map-panel h1 { font-size: 1.25rem; letter-spacing: -.02em; }
.map-panel .crumbs { margin-bottom: 4px; }
.map-panel-counts { margin: 4px 0 10px; color: var(--muted); font-size: .9rem; }
.map-panel .empty { margin: 0 0 10px; font-size: .9rem; }
.map-panel .chips { flex-wrap: nowrap; overflow-x: auto; margin: 0; padding-bottom: 2px; scrollbar-width: none; }
.map-panel .chip { flex: none; }
.range-details { margin-top: 10px; font-size: .85rem; }
.range-details summary { cursor: pointer; color: var(--muted); }
.range-details .filters { margin: 10px 0 0; padding: 0; border: 0; background: none; box-shadow: none; }
.map-location, .map-cluster, .map-you {
  border: 2px solid #fff;
  border-radius: 999px;
  box-shadow: 0 1px 3px rgb(0 0 0 / .35);
  transform: translateY(50%); /* advanced markers anchor at the bottom centre; centre the marker instead */
}
.map-location { width: 14px; height: 14px; background: var(--accent); }
.map-cluster {
  min-width: 32px; height: 32px; padding: 0 8px;
  display: grid; place-items: center;
  background: var(--accent);
  color: #fff;
  font: 600 .8rem/1 var(--font);
  font-variant-numeric: tabular-nums;
}
.map-you {
  width: 16px; height: 16px;
  background: #1a73e8;
  border-width: 3px;
  box-shadow: 0 0 0 6px rgb(26 115 232 / .2), 0 1px 3px rgb(0 0 0 / .35);
}
.map-unavailable { position: absolute; right: 24px; bottom: 24px; max-width: 420px; margin: 0; color: var(--muted); }
/* Google draws the info window's frame; recolour it so the popup follows the app's tokens in both themes.
   These are Google's own class names, so .map-popup also carries the surface colour itself: if Google
   renames them, the frame turns white but the popup stays readable. */
.swarm-map .gm-style-iw-c, .swarm-map .gm-style-iw-d { background: var(--surface); color: var(--text); }
.swarm-map .gm-style-iw-tc::after { background: var(--surface); }
.swarm-map .gm-style-iw-chr button span { background-color: var(--muted) !important; }
.map-popup { display: grid; gap: 10px; max-height: min(50vh, 360px); overflow-y: auto; padding: 2px; background: var(--surface); color: var(--text); font: .85rem/1.4 var(--font); }
.map-popup-venue { display: grid; gap: 2px; }
.map-popup-venue + .map-popup-venue { padding-top: 10px; border-top: 1px solid var(--border); }
.map-popup-venue strong { font-size: .95rem; }
.map-popup-venue span { color: var(--muted); }
.map-popup-links { display: flex; flex-wrap: wrap; gap: 4px 12px; }
.map-popup-links a { color: var(--accent); }
