:root {
  --bg: #f6f7f9; --card: #fff; --ink: #1c2330; --muted: #6b7686;
  --brand: #1a73e8; --line: #e1e5ea; --danger: #c5221f;
  --upcoming: #e8710a; --past: #1a73e8; --planning: #8e63ce;
  --topbar: 53px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; font: 15px/1.45 system-ui, sans-serif; color: var(--ink); background: var(--bg); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 26px; margin: 0 0 6px; }
h2 { margin: 18px 0 8px; font-size: 17px; }
h3 { margin: 20px 0 6px; font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

/* ---------- Top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; gap: 16px; align-items: center; padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; color: var(--ink); }
.brand:hover { text-decoration: none; }
.brand img { width: 30px; height: 30px; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { padding: 6px 12px; border-radius: 8px; color: var(--muted); }
.nav a:hover { background: var(--bg); text-decoration: none; }
.nav a.active { color: var(--ink); background: var(--bg); font-weight: 600; }
#user-area { display: flex; gap: 10px; align-items: center; margin-left: auto; }
#user-name { color: var(--muted); font-size: 14px; }

.center { text-align: center; padding: 72px 16px; color: var(--muted); }

/* ---------- Signed-out landing ---------- */
.landing {
  position: relative; overflow: hidden;
  min-height: calc(100vh - var(--topbar)); display: flex; justify-content: center;
  background: linear-gradient(180deg, #f6f9ff 0%, #eaf1fd 100%);
}
.landing-art {
  position: absolute; left: 0; right: 0; bottom: 0; width: 100%; height: 62%;
  object-fit: cover; object-position: center bottom; opacity: .13; pointer-events: none;
}
.landing-text { position: relative; text-align: center; padding: 8vh 16px 0; max-width: 680px; }
.landing-logo { width: clamp(96px, 16vw, 150px); height: auto; display: block; margin: 0 auto 18px; }
.landing h1 { font-size: clamp(56px, 11vw, 112px); line-height: 1; letter-spacing: -.03em; margin: 0 0 20px; color: var(--ink); }
.landing p { font-size: clamp(17px, 2.2vw, 21px); color: #3c4757; margin: 0 0 28px; }
button.big { font-size: 17px; padding: 12px 22px; border-radius: 999px; box-shadow: 0 2px 10px rgba(26,115,232,.25); }
.center h1 { color: var(--ink); }
.error { color: var(--danger); padding: 8px 16px; margin: 0; background: #fce8e6; }
.hint { color: var(--muted); font-size: 13px; }
.empty { color: var(--muted); text-align: center; padding: 40px 16px; }
#view { padding: 20px; max-width: 1400px; margin: 0 auto; }

/* ---------- Controls ---------- */
input, select, textarea, button, .button { font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
input[type=text], input[type=date], input[type=email], textarea, select { width: 100%; margin-top: 6px; }
textarea { resize: vertical; }
label { display: block; font-weight: 600; margin: 12px 0 0; font-size: 13px; }
button, .button { cursor: pointer; background: var(--brand); color: #fff; border-color: var(--brand); display: inline-block; }
.button:hover { text-decoration: none; }
button.ghost { background: #fff; color: var(--ink); border-color: var(--line); }
button.danger { color: var(--danger); }
button.small { padding: 3px 9px; font-size: 13px; }
button.full { width: 100%; margin-top: 10px; }
button:disabled { opacity: .5; cursor: default; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > div { flex: 1; min-width: 120px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 4px 18px 18px; margin-bottom: 18px; }
.chip { display: inline-block; background: #e8f0fe; color: #174ea6; border-radius: 999px; padding: 1px 9px; font-size: 12px; }
.badge { display: inline-block; border-radius: 999px; padding: 1px 9px; font-size: 12px; color: #fff; font-weight: 600; }
.badge.past { background: var(--past); } .badge.upcoming { background: var(--upcoming); } .badge.planning { background: var(--planning); }

/* ---------- Home collage ---------- */
.hero { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
/* Scattered prints: positions, sizes, and tilts are set per photo in home.js. */
.collage { position: relative; min-height: 200px; transition: height .6s ease; }
.collage-grid { position: relative; transition: opacity 1s ease; }
.tile {
  position: absolute; margin: 0; padding: 6px; background: #fff; border-radius: 3px;
  box-shadow: 0 1px 2px rgba(0,0,0,.12), 0 6px 18px rgba(28,35,48,.18);
  transition: transform .35s ease, box-shadow .35s ease, opacity .9s ease;
}
.tile.fading-in { opacity: 0; }
.tile.fading-out { opacity: 0; pointer-events: none; }
.tile { cursor: zoom-in; }
.tile:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }
.tile:hover, .tile:focus-visible { transform: rotate(0deg) scale(1.06) !important; z-index: 100 !important; box-shadow: 0 12px 34px rgba(28,35,48,.32); }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; border-radius: 1px; background: #dde3ea; }

/* Full-size photo viewer */
.lightbox { border: 0; padding: 0; margin: 0; width: 100vw; height: 100vh; max-width: 100vw; max-height: 100vh; background: rgba(10,14,20,.9); }
.lightbox::backdrop { background: transparent; }
.lb-stage { width: 100%; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 56px 76px 28px; box-sizing: border-box; }
.lb-img { max-width: 100%; max-height: calc(100% - 66px); object-fit: contain; border-radius: 4px; box-shadow: 0 12px 48px rgba(0,0,0,.55); }
.lb-caption { margin: 0; min-height: 20px; color: #d6dbe3; font-size: 14px; }
.lb-place { margin: -6px 0 0; min-height: 20px; color: #d6dbe3; font-size: 14px; }
.lb-place a { color: #9cc3ff; }
.lb-btn { position: fixed; width: 46px; height: 46px; padding: 0; border: 0; border-radius: 999px; display: grid; place-items: center;
  background: rgba(255,255,255,.14); color: #fff; font-size: 30px; line-height: 1; }
.lb-btn:hover { background: rgba(255,255,255,.28); }
.lb-close { top: 14px; right: 14px; }
.lb-prev { left: 14px; top: 50%; transform: translateY(-50%); }
.lb-next { right: 14px; top: 50%; transform: translateY(-50%); }

.section-title { font-size: 20px; margin: 28px 0 12px; }

/* Home highlights: next-trip countdown + on this day */
.highlights { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.highlights:empty { display: none; }
.highlight { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px 18px; display: flex; flex-direction: column; gap: 4px; }
.countdown { color: var(--ink); min-width: 220px; flex: 0 1 300px; background: linear-gradient(135deg, #fff7ef, #fff); border-color: #f5d3b3; }
.countdown:hover { text-decoration: none; box-shadow: 0 2px 10px rgba(232,113,10,.15); }
.hl-label { font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.countdown .hl-label { color: var(--upcoming); }
.hl-big { font-size: 34px; font-weight: 800; line-height: 1.1; }
.hl-sub { color: var(--muted); font-size: 14px; }
.birthdays { min-width: 220px; flex: 0 1 300px; background: linear-gradient(135deg, #fdf0f6, #fff); border-color: #f1c9dc; }
.birthdays .hl-label { color: #c2407e; }
.bday-list { list-style: none; margin: 6px 0 0; padding: 8px 0 0; border-top: 1px solid #f1d9e5; display: grid; gap: 3px; font-size: 13px; }
.bday-list li { display: grid; grid-template-columns: 10px 1fr auto; align-items: center; gap: 8px; }
.bday-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.bday-when { color: var(--muted); font-variant-numeric: tabular-nums; }
.away { color: var(--ink); min-width: 220px; flex: 0 1 300px; background: linear-gradient(135deg, #eef5ff, #fff); border-color: #c5dbf7; }
a.away:hover { text-decoration: none; box-shadow: 0 2px 10px rgba(26,95,208,.15); }
.away .hl-label { color: var(--brand); }
.away-clocks { list-style: none; margin: 6px 0 0; padding: 8px 0 0; border-top: 1px solid #d6e4f5; display: grid; gap: 3px; font-size: 13px; }
.away-clocks li { display: flex; justify-content: space-between; gap: 10px; }
.away-time { color: var(--muted); font-variant-numeric: tabular-nums; }
.otd { flex: 1 1 360px; min-width: 0; }
.otd-strip { display: flex; gap: 10px; overflow-x: auto; padding: 4px 2px 2px; }
.otd-thumb { margin: 0; flex: 0 0 auto; width: 104px; cursor: zoom-in; }
.otd-thumb img { width: 104px; height: 104px; object-fit: cover; border-radius: 8px; display: block; background: #dde3ea; }
.otd-thumb figcaption { font-size: 12px; color: var(--muted); text-align: center; margin-top: 3px; }
.otd-thumb:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; border-radius: 8px; }

/* Travel stats */
.person-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; margin-bottom: 14px; }
.person-card { display: grid; grid-template-columns: 44px 1fr; grid-template-rows: auto auto auto; column-gap: 10px; row-gap: 2px; text-align: left;
  background: var(--card); color: var(--ink); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; cursor: pointer; }
.person-card:hover { border-color: #b9c6d8; }
.person-card.selected { border-color: var(--brand); box-shadow: 0 0 0 2px rgba(26,115,232,.18); }
.avatar { grid-row: 1 / 4; width: 44px; height: 44px; border-radius: 50%; background: var(--c); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 18px; overflow: hidden; align-self: center; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.pc-name { font-weight: 700; }
.pc-nums { display: flex; flex-wrap: wrap; gap: 0 8px; font-size: 13px; color: var(--muted); }
.pc-nums b { color: var(--ink); font-size: 15px; }
.pc-extra { font-size: 12px; color: var(--muted); }
.world { width: 100%; height: auto; display: block; background: #f9fbfe; border: 1px solid var(--line); border-radius: 12px; }
.world .sphere { fill: #eef4fc; }
.world .country { fill: #dfe5ec; stroke: #fff; stroke-width: .5; transition: fill .3s; }
.world .country.visited { fill-opacity: .8; }
.world .stop-dot { fill: #fff; stroke: var(--ink); stroke-width: 1.2; }
.world-legend { margin-top: 8px; }
.world .home-mark { stroke: #fff; stroke-width: 1.2; }
.stats-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 0 32px; align-items: start; }
.stats-layout.no-homes { grid-template-columns: minmax(0, 1fr); }
.stats-layout.no-homes .homes { display: none; }
/* Beside the timeline, the six cards share one row the width of the map, so each card stacks its content. */
.stats-layout .person-cards { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; }
.stats-layout .person-card { grid-template-columns: 1fr; grid-template-rows: none; justify-items: center; text-align: center; padding: 10px 6px; }
.stats-layout .avatar { grid-row: auto; margin-bottom: 4px; }
.stats-layout .pc-nums { flex-direction: column; align-items: center; }
@media (max-width: 1000px) {
  .stats-layout { grid-template-columns: minmax(0, 1fr); }
  .stats-layout .person-cards { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
.home-list { list-style: none; margin: 0; padding: 0; border-left: 2px solid var(--line); }
.home-list li { position: relative; display: grid; grid-template-columns: 96px 1fr; column-gap: 12px; padding: 6px 0 6px 16px; }
.home-list li::before { content: ""; position: absolute; left: -6px; top: 12px; width: 10px; height: 10px; border-radius: 50%; background: var(--card); border: 2px solid var(--muted); }
.home-list li.current::before { background: var(--brand); border-color: var(--brand); }
.home-years { color: var(--muted); font-variant-numeric: tabular-nums; }
.home-name { font-weight: 600; }
.home-name .chip { margin-left: 8px; font-weight: 500; }
.home-who { grid-column: 2; font-size: 13px; color: var(--muted); }

/* Family: height lineup */
.lineup-wrap { background: linear-gradient(180deg, #f3f8ff 0%, #fff 70%); border: 1px solid var(--line); border-radius: 14px; padding: 8px; overflow-x: auto; }
.lineup { display: block; width: 100%; max-width: 1150px; min-width: 560px; height: auto; margin: 0 auto; }
.lineup .tick { stroke: #9aa6b5; stroke-width: 2; }
.lineup .gridline { stroke: #e3e8ef; stroke-width: 1.5; stroke-dasharray: 6 8; }
.lineup .tick-label { font: 600 16px system-ui, sans-serif; fill: #7a8696; }
.lineup .ground { stroke: #8a6d4b; stroke-width: 6; stroke-linecap: round; }
.lineup .kid-name { font: 800 26px system-ui, sans-serif; fill: var(--ink); }
.lineup .kid-stats { font: 500 19px system-ui, sans-serif; fill: var(--muted); }
.lineup .kid-head { animation: bob 2.6s ease-in-out infinite; animation-delay: var(--bob-delay, 0s); transform-box: fill-box; transform-origin: 50% 100%; }
@keyframes bob { 0%, 100% { transform: rotate(-3deg); } 50% { transform: rotate(3deg) translateY(-3px); } }
@media (prefers-reduced-motion: reduce) { .lineup .kid-head { animation: none; } }
.kid-editors { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; margin-top: 16px; }
.kid-editor { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.kid-editor label { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-weight: 500; }
.kid-editor input[type=number] { width: 96px; margin: 0; }
.kid-editor .row { margin-top: 10px; }
.crop-dialog { border: 0; border-radius: 14px; padding: 18px 20px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.crop-dialog::backdrop { background: rgba(10,14,20,.6); }
.crop-dialog h3 { margin: 0 0 12px; text-transform: none; letter-spacing: 0; color: var(--ink); font-size: 16px; }
.crop-box { position: relative; width: 260px; height: 260px; overflow: hidden; border-radius: 12px; background: #222; touch-action: none; cursor: grab; }
.crop-img { position: absolute; left: 0; top: 0; transform-origin: 0 0; user-select: none; max-width: none; }
.crop-ring { position: absolute; inset: 0; border-radius: 50%; box-shadow: 0 0 0 999px rgba(0,0,0,.45); border: 2px solid #fff; pointer-events: none; }
.crop-dialog label { display: flex; align-items: center; gap: 10px; }
.crop-dialog input[type=range] { flex: 1; }

/* ---------- Travel overview ---------- */
.travel-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; margin-bottom: 12px; }
.stats { color: var(--muted); }
.overview-map { height: 46vh; min-height: 300px; border-radius: 12px; overflow: hidden; border: 1px solid var(--line); }
.trip-group h2 { margin-top: 26px; font-size: 20px; }
.trip-group { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
.trip-group h2 { grid-column: 1 / -1; margin-bottom: 0; }
.trip-card { display: block; background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--past); border-radius: 10px; padding: 12px 14px; color: var(--ink); }
.trip-card:hover { text-decoration: none; box-shadow: 0 2px 8px rgba(0,0,0,.08); }
.trip-card.upcoming { border-left-color: var(--upcoming); }
.trip-card.planning { border-left-color: var(--planning); }
.trip-card h3 { margin: 0; font-size: 16px; color: var(--ink); text-transform: none; letter-spacing: 0; }
.trip-dates { color: var(--muted); font-size: 13px; }
.trip-summary { margin: 8px 0; font-size: 14px; }
.trip-meta { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; margin-top: 6px; }
.trip-meta .label { font-size: 13px; color: var(--muted); margin-right: 2px; }
.stop-count { margin-left: auto; color: var(--muted); font-size: 12px; }
.info { font-size: 13px; line-height: 1.5; }

/* ---------- Trip detail ---------- */
.crumbs { margin: 0 0 10px; }
.layout { display: grid; grid-template-columns: 380px 1fr; gap: 16px; height: calc(100vh - var(--topbar) - 90px); min-height: 520px; }
.sidebar { overflow-y: auto; padding: 16px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
.trip-map { height: 100%; border-radius: 12px; overflow: hidden; border: 1px solid var(--line); }
.trip-title-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.trip-title-row h1 { font-size: 22px; }
.edit-trip { margin-bottom: 8px; }
.edit-trip .row { margin-top: 12px; }
.add-stop { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 10px; }
.add-stop summary { cursor: pointer; font-weight: 600; }
.add-stop input { margin-top: 8px; }
gmp-place-autocomplete { width: 100%; margin-top: 8px; }
.stops { list-style: none; padding: 0; margin: 0; counter-reset: n; }
.stops li { counter-increment: n; display: grid; grid-template-columns: 28px 1fr auto; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.stops li::before { content: counter(n); background: var(--brand); color: #fff; border-radius: 50%; width: 24px; height: 24px; display: grid; place-items: center; font-size: 12px; font-weight: 600; }
.stop-name { font-weight: 600; }
.stop-meta { color: var(--muted); font-size: 13px; }
.stop-actions { display: flex; flex-direction: column; gap: 4px; }
.stop-actions button { padding: 2px 8px; background: #fff; color: var(--ink); border-color: var(--line); font-size: 12px; }
.stop-actions .del { color: var(--danger); }
.pin { background: var(--brand); color: #fff; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4); }
.pin.dot { width: 14px; height: 14px; }
.pin.dot.past { background: var(--past); } .pin.dot.upcoming { background: var(--upcoming); } .pin.dot.planning { background: var(--planning); }

/* ---------- Admin ---------- */
.plain-list { list-style: none; padding: 0; margin: 8px 0; }
.plain-list li { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }
.card form.row input { flex: 1; margin-top: 0; }
/* At most 5 rows of thumbnails show; the rest scroll inside the box. */
.admin-photos { --thumb-row: 150px; display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); grid-auto-rows: var(--thumb-row); gap: 8px;
  margin-top: 12px; max-height: calc(5 * var(--thumb-row) + 4 * 8px); overflow-y: auto; padding-right: 4px; overscroll-behavior: contain; }
.admin-photos figure { margin: 0; }
.admin-photos img { width: 100%; height: 120px; object-fit: cover; border-radius: 6px; background: #dde3ea; display: block; }
.admin-photos figcaption { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--muted); margin-top: 3px; }

@media (max-width: 800px) {
  #view { padding: 12px; }
  .topbar { flex-wrap: wrap; gap: 8px; }
  #user-name { display: none; }
  .layout { grid-template-columns: 1fr; height: auto; }
  .trip-map { order: -1; height: 45vh; }
  .tile { padding: 4px; }
  .lb-stage { padding: 64px 10px 24px; }
  .lb-prev, .lb-next { top: auto; bottom: 18px; transform: none; }
  .trip-group { grid-template-columns: 1fr; }
}
