:root {
  --ink: #1f2a44;
  --ink-soft: #55607a;
  --ink-faint: #8d95a8;
  --mist: #f2f5f7;
  --paper: #ffffff;
  --line: #dde3ea;
  --fern: #2f7d5a;
  --fern-soft: #e2f1e8;
  --marigold: #e8a33d;
  --marigold-soft: #fbefd8;
  --brick: #c8493c;
  --radius: 14px;
  --sans: "Public Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --serif: "Fraunces", Georgia, "Times New Roman", serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--mist); color: var(--ink);
  font-family: var(--sans); font-size: 16px; line-height: 1.4;
  -webkit-font-smoothing: antialiased; overscroll-behavior-y: none;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; touch-action: manipulation; }
button:focus-visible, input:focus-visible, .chip:focus-within { outline: 3px solid var(--marigold); outline-offset: 2px; }
h1, h2, h3 { margin: 0; font-family: var(--serif); font-variation-settings: "SOFT" 50, "opsz" 72; font-weight: 700; letter-spacing: -0.01em; }
a { color: inherit; }
[hidden] { display: none !important; }

/* ---- shell ---- */
.screen { min-height: 100dvh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 5; background: var(--ink); color: #fff;
  padding: calc(var(--safe-top) + 12px) 16px 12px;
}
.topbar-row { display: flex; align-items: center; gap: 10px; min-height: 40px; }
.topbar h1 { font-size: 24px; line-height: 1.1; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .sub { color: #c5cddc; font-size: 14px; margin-top: 2px; }
.iconbtn {
  width: 40px; height: 40px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  color: inherit; flex: none;
}
.iconbtn:active { background: rgba(255,255,255,.15); }
.iconbtn svg { width: 22px; height: 22px; }
.textbtn { padding: 8px 12px; border-radius: 999px; font-weight: 600; font-size: 15px; }
.topbar .textbtn { color: #fff; background: rgba(255,255,255,.14); }
.topbar .textbtn.on { background: var(--marigold); color: var(--ink); }
.progress { height: 6px; background: rgba(255,255,255,.18); border-radius: 3px; overflow: hidden; margin-top: 12px; }
.progress > i { display: block; height: 100%; background: var(--marigold); border-radius: 3px; transition: width .35s ease; }
.progress > i.full { background: #58c48f; }
.content { flex: 1; padding: 16px 16px calc(var(--safe-bottom) + 96px); max-width: 640px; width: 100%; margin: 0 auto; }

/* ---- sign in ---- */
.signin { justify-content: center; align-items: center; text-align: center; padding: 32px 24px; gap: 20px; background: var(--ink); color: #fff; }
.signin .mark { width: 88px; height: 88px; }
.signin h1 { font-size: 40px; line-height: 1; }
.signin p { color: #c5cddc; max-width: 30ch; margin: 0; }
.signin .gbtn { min-height: 44px; margin-top: 8px; }
.signin .note { font-size: 14px; color: #8d95a8; }
.signin .denied { background: rgba(200,73,60,.25); border: 1px solid rgba(200,73,60,.6); padding: 12px 16px; border-radius: var(--radius); color: #fff; max-width: 34ch; }

/* ---- trips list ---- */
.trip-list { list-style: none; margin: 0; padding: 0; background: var(--paper); border-radius: var(--radius); overflow: hidden; box-shadow: 0 1px 0 var(--line); }
.trip-list li + li { border-top: 1px solid var(--line); }
.trip-link { display: block; width: 100%; text-align: left; padding: 16px; }
.trip-link:active { background: var(--mist); }
.trip-link h2 { font-size: 24px; line-height: 1.1; }
.trip-link .when { color: var(--ink-soft); margin-top: 3px; font-size: 15px; }
.trip-meta { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.initials { display: flex; gap: 4px; }
.initial {
  width: 26px; height: 26px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  font-family: var(--serif); font-weight: 700; font-size: 13px; background: var(--mist); color: var(--ink); border: 1.5px solid var(--line);
}
.initial.p0 { background: #e2f1e8; border-color: #b5dac6; } .initial.p1 { background: #fbefd8; border-color: #f0d59c; }
.initial.p2 { background: #e5e9f8; border-color: #bcc6ee; } .initial.p3 { background: #fbe4e1; border-color: #f0b8b1; }
.initial.p4 { background: #eee6f7; border-color: #d3c1ea; } .initial.p5 { background: #e0f2f4; border-color: #b3dde2; }
.mini { flex: 1; height: 5px; background: var(--line); border-radius: 3px; overflow: hidden; }
.mini > i { display: block; height: 100%; background: var(--marigold); border-radius: 3px; }
.mini > i.full { background: var(--fern); }
.count { color: var(--ink-soft); font-size: 14px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.empty { text-align: center; color: var(--ink-soft); padding: 48px 16px; }
.empty h2 { font-size: 26px; color: var(--ink); margin-bottom: 8px; }
.fab {
  position: fixed; right: 16px; bottom: calc(var(--safe-bottom) + 20px); z-index: 4;
  height: 56px; padding: 0 22px 0 18px; border-radius: 28px; background: var(--marigold); color: var(--ink);
  font-weight: 600; font-size: 16px; display: inline-flex; align-items: center; gap: 8px;
  box-shadow: 0 6px 18px rgba(31,42,68,.25);
}
.fab svg { width: 22px; height: 22px; }
.fab:active { transform: translateY(1px); }

/* ---- forms ---- */
.field { margin-bottom: 18px; }
.field label, .field .lbl { display: block; font-weight: 600; margin-bottom: 6px; }
.field input[type=text], .field input[type=date] {
  width: 100%; min-height: 48px; padding: 10px 14px; border: 1.5px solid var(--line); border-radius: 12px; background: var(--paper);
  -webkit-appearance: none; appearance: none;
}
.field input[type=date] { min-width: 0; }
.field input:focus { border-color: var(--ink); outline: none; }
.dates { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.hint { color: var(--ink-soft); font-size: 14px; margin-top: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { position: relative; }
.chip input { position: absolute; inset: 0; opacity: 0; margin: 0; }
.chip span {
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 16px 0 10px; border-radius: 999px;
  background: var(--paper); border: 1.5px solid var(--line); font-weight: 500;
}
.chip input:checked + span { background: var(--ink); color: #fff; border-color: var(--ink); }
.chip input:checked + span .initial { background: var(--marigold); border-color: var(--marigold); color: var(--ink); }
.switches { background: var(--paper); border-radius: var(--radius); overflow: hidden; }
.switch { display: flex; align-items: center; gap: 12px; padding: 12px 14px; min-height: 56px; }
.switch + .switch { border-top: 1px solid var(--line); }
.switch .txt { flex: 1; }
.switch .txt small { display: block; color: var(--ink-soft); font-size: 13px; }
.switch input { appearance: none; -webkit-appearance: none; width: 50px; height: 30px; border-radius: 15px; background: var(--line); position: relative; flex: none; margin: 0; transition: background .2s; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .2s; }
.switch input:checked { background: var(--fern); }
.switch input:checked::after { transform: translateX(20px); }
.primary {
  width: 100%; min-height: 52px; border-radius: 14px; background: var(--ink); color: #fff; font-weight: 600; font-size: 17px; margin-top: 8px;
}
.primary:disabled { opacity: .5; }
.secondary { width: 100%; min-height: 48px; border-radius: 14px; background: var(--paper); border: 1.5px solid var(--line); font-weight: 600; margin-top: 10px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.secondary svg { width: 18px; height: 18px; }
.danger { color: var(--brick); }
.error { color: var(--brick); font-weight: 500; margin-top: 10px; }

/* ---- trip screen ---- */
.section { margin-bottom: 22px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; padding: 0 4px 8px; }
.section-head h2 { font-size: 26px; display: flex; align-items: center; gap: 10px; }
.section-head h2 .initial { width: 30px; height: 30px; font-size: 15px; }
.section-head .count { font-size: 15px; }
.section-head .count.full { color: var(--fern); font-weight: 600; }
.rows { list-style: none; margin: 0; padding: 0; background: var(--paper); border-radius: var(--radius); overflow: hidden; }
.rows li + li { border-top: 1px solid var(--line); }
.row { display: flex; align-items: center; gap: 10px; padding: 0 6px 0 14px; min-height: 58px; }
.row .tap { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; text-align: left; padding: 10px 0; }
.row .label { flex: 1; min-width: 0; font-size: 17px; font-weight: 500; }
.row .label .custom { color: var(--ink-faint); font-size: 12px; margin-left: 6px; }
.row.done .label { color: var(--ink-faint); text-decoration: line-through; text-decoration-thickness: 2px; text-decoration-color: var(--ink-soft); }
.tally { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px; max-width: 58%; }
.tally b {
  width: 26px; height: 26px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  font-family: var(--serif); font-weight: 700; font-size: 13px; font-variation-settings: "SOFT" 50, "opsz" 14;
  border: 1.5px solid var(--line); color: var(--ink-soft); position: relative; background: var(--paper);
}
.tally b.x { background: var(--marigold-soft); border-color: var(--marigold); color: var(--ink); }
.row.done .tally b.x { background: var(--fern-soft); border-color: var(--fern); color: var(--fern); }
.tally b.x::after { content: ""; position: absolute; left: 3px; right: 3px; top: 50%; height: 2px; background: currentColor; transform: rotate(-28deg); border-radius: 1px; }
.tally b.x.pop { animation: pop .22s ease-out; }
@keyframes pop { 0% { transform: scale(.6); } 70% { transform: scale(1.15); } 100% { transform: scale(1); } }
.tally .big { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 15px; color: var(--ink-soft); }
.tally .big.x { color: var(--marigold); }
.row.done .tally .big.x { color: var(--fern); }
.row .undo { width: 40px; height: 40px; border-radius: 50%; color: var(--ink-faint); display: inline-flex; align-items: center; justify-content: center; flex: none; }
.row .undo:active { background: var(--mist); }
.row .undo svg { width: 20px; height: 20px; }
.row .undo[disabled] { opacity: .25; }
.row.editing .tally { display: none; }
.edit-tools { display: flex; align-items: center; gap: 4px; flex: none; }
.stepper { display: inline-flex; align-items: center; border: 1.5px solid var(--line); border-radius: 999px; overflow: hidden; }
.stepper button { width: 36px; height: 36px; font-size: 20px; line-height: 1; color: var(--ink); }
.stepper button:active { background: var(--mist); }
.stepper output { min-width: 28px; text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; }
.del { width: 36px; height: 36px; border-radius: 50%; color: var(--brick); font-size: 22px; line-height: 1; }
.addrow { display: flex; align-items: center; gap: 8px; width: 100%; padding: 12px 14px; color: var(--fern); font-weight: 600; text-align: left; }
.addrow svg { width: 18px; height: 18px; }
.addform { display: flex; gap: 8px; padding: 10px 10px 12px 14px; align-items: center; }
.addform input[type=text] { flex: 1; min-width: 0; min-height: 44px; padding: 8px 12px; border: 1.5px solid var(--line); border-radius: 10px; }
.addform input[type=number] { width: 58px; min-height: 44px; padding: 8px; border: 1.5px solid var(--line); border-radius: 10px; text-align: center; }
.addform button { min-height: 44px; padding: 0 14px; border-radius: 10px; background: var(--ink); color: #fff; font-weight: 600; }

/* ---- sheet / menu ---- */
.scrim { position: fixed; inset: 0; background: rgba(31,42,68,.45); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--paper); border-radius: 18px 18px 0 0; width: 100%; max-width: 640px; padding: 8px 16px calc(var(--safe-bottom) + 16px); }
.sheet .grab { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 4px auto 12px; }
.sheet h2 { font-size: 22px; margin-bottom: 12px; }
.sheet .item { display: block; width: 100%; text-align: left; padding: 14px 4px; font-size: 17px; font-weight: 500; border-top: 1px solid var(--line); }
.sheet .item:first-of-type { border-top: 0; }

/* ---- family ---- */
.members { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.member { background: var(--paper); border-radius: var(--radius); padding: 12px 12px 12px 14px; display: grid; grid-template-columns: 1fr 64px auto auto; gap: 8px; align-items: center; }
.member input { min-height: 44px; padding: 8px 12px; border: 1.5px solid var(--line); border-radius: 10px; min-width: 0; width: 100%; }
.member .kind { display: inline-flex; border: 1.5px solid var(--line); border-radius: 999px; overflow: hidden; }
.member .kind button { padding: 0 12px; height: 40px; font-weight: 600; font-size: 14px; color: var(--ink-soft); }
.member .kind button.on { background: var(--ink); color: #fff; }

/* ---- toast ---- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-bottom) + 88px); transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 15px; z-index: 30;
  box-shadow: 0 6px 18px rgba(31,42,68,.3); max-width: calc(100% - 32px);
}
.toast.err { background: var(--brick); }
.loading { text-align: center; color: var(--ink-soft); padding: 40px; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
@media (min-width: 640px) { .topbar-inner { max-width: 640px; margin: 0 auto; } }
