:root {
  --bg: #f6efe6;
  --card: #fffaf4;
  --card-2: #f1e7da;
  --ink: #3b2f2a;
  --muted: #84736a;
  --line: #e6d8c7;
  --accent: #4f7fae;      /* Max blue */
  --accent-soft: #dce8f3;
  --warm: #c9775a;        /* terracotta */
  --warm-soft: #f6e0d6;
  --sage: #6f9a6b;
  --sage-soft: #e1ecdd;
  --gold: #c9a24a;
  --danger: #b5483b;
  --shadow: 0 1px 2px rgba(80, 50, 30, .06), 0 6px 18px rgba(80, 50, 30, .07);
  --radius: 18px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not(.light) {
    --bg: #1c1715; --card: #26201d; --card-2: #2f2824; --ink: #f1e6da; --muted: #ae9d90;
    --line: #3e3530; --accent: #8fb6dc; --accent-soft: #2c3a48; --warm: #e39a7d; --warm-soft: #44302a;
    --sage: #9cc297; --sage-soft: #2d3a2b; --gold: #e0bf6c; --danger: #e57a6c;
    --shadow: 0 1px 2px rgba(0,0,0,.3); color-scheme: dark;
  }
}
:root.dark {
  --bg: #1c1715; --card: #26201d; --card-2: #2f2824; --ink: #f1e6da; --muted: #ae9d90;
  --line: #3e3530; --accent: #8fb6dc; --accent-soft: #2c3a48; --warm: #e39a7d; --warm-soft: #44302a;
  --sage: #9cc297; --sage-soft: #2d3a2b; --gold: #e0bf6c; --danger: #e57a6c;
  --shadow: 0 1px 2px rgba(0,0,0,.3); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink); font-family: var(--sans); font-size: 16px; line-height: 1.45;
  -webkit-font-smoothing: antialiased; min-height: 100vh;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
a { color: var(--accent); }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: 1.9rem; } h2 { font-size: 1.35rem; } h3 { font-size: 1.1rem; }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.center { text-align: center; }

.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; justify-content: space-between; align-items: center;
  padding: calc(10px + env(safe-area-inset-top)) 18px 10px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.brand { font-family: var(--serif); font-size: 1.35rem; color: var(--ink); text-decoration: none; font-weight: 600; }
.brand-star { color: var(--gold); }
.icon-btn { text-decoration: none; font-size: 1.3rem; color: var(--muted); padding: 4px 8px; }

main { max-width: 720px; margin: 0 auto; padding: 6px 16px 24px; outline: none; }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; display: flex; justify-content: space-around;
  background: var(--card); border-top: 1px solid var(--line);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1px; text-decoration: none;
  color: var(--muted); font-size: .72rem; padding: 4px 0; border-radius: 12px; max-width: 110px;
}
.tabbar a span { font-size: 1.25rem; filter: grayscale(.6); opacity: .8; }
.tabbar a.active { color: var(--accent); font-weight: 600; }
.tabbar a.active span { filter: none; opacity: 1; }

.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin: 0 0 14px;
  border: 1px solid var(--line);
}
.card.soft { background: var(--card-2); box-shadow: none; }
.card.accent { background: var(--accent-soft); border-color: transparent; }
.card.warm { background: var(--warm-soft); border-color: transparent; }
.card.sage { background: var(--sage-soft); border-color: transparent; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 8px; }
.card-head h2, .card-head h3 { margin: 0; }

.page-title { margin: 6px 2px 14px; }
.page-title p { color: var(--muted); margin: 0; }

/* Hero countdown */
.hero { text-align: center; padding: 26px 18px 22px; background:
  radial-gradient(120% 80% at 50% 0%, var(--accent-soft), transparent 70%), var(--card); }
.hero .eyebrow { text-transform: uppercase; letter-spacing: .12em; font-size: .75rem; color: var(--muted); }
.hero h1 { font-size: 2.1rem; margin: 6px 0 2px; }
.count { display: flex; justify-content: center; gap: 10px; margin: 18px 0 8px; }
.count div { background: var(--bg); border-radius: 14px; padding: 10px 6px; min-width: 66px; border: 1px solid var(--line); }
.count b { display: block; font-family: var(--serif); font-size: 2rem; font-variant-numeric: tabular-nums; line-height: 1.1; }
.count small { color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; }
.progress { height: 8px; border-radius: 99px; background: var(--card-2); overflow: hidden; margin: 14px 0 6px; }
.progress > i { display: block; height: 100%; background: linear-gradient(90deg, var(--sage), var(--accent)); border-radius: 99px; }

.size-card { display: flex; gap: 14px; align-items: center; }
.size-emoji { font-size: 3rem; line-height: 1; flex: none; width: 70px; height: 70px; display: grid; place-items: center;
  background: var(--bg); border-radius: 50%; }

.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.tile { display: flex; flex-direction: column; gap: 4px; text-decoration: none; color: var(--ink); background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); min-height: 92px; }
.tile .t-icon { font-size: 1.6rem; }
.tile b { font-family: var(--serif); font-size: 1.05rem; }
.tile small { color: var(--muted); font-size: .8rem; }
.section-label { text-transform: uppercase; letter-spacing: .1em; font-size: .72rem; color: var(--muted); margin: 18px 4px 8px; }

/* Forms */
label { display: block; font-size: .85rem; color: var(--muted); margin: 10px 0 4px; }
input, textarea, select {
  width: 100%; font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px 12px;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type=checkbox] { width: auto; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }
.inline { display: flex; gap: 8px; align-items: center; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600;
  border: 1px solid var(--line); background: var(--card); color: var(--ink); padding: 10px 16px; border-radius: 999px;
  cursor: pointer; text-decoration: none; min-height: 44px;
}
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
:root.dark .btn.primary { color: #10202f; }
@media (prefers-color-scheme: dark) { :root:not(.light) .btn.primary { color: #10202f; } }
.btn.warm { background: var(--warm); color: #fff; border-color: var(--warm); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 34px; padding: 6px 12px; font-size: .85rem; }
.btn.block { width: 100%; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.link-btn { background: none; border: 0; color: var(--muted); font: inherit; cursor: pointer; padding: 4px 6px; }
.link-btn:hover { color: var(--danger); }

/* Tabs (segmented) */
.seg { display: flex; background: var(--card-2); border-radius: 999px; padding: 4px; gap: 4px; margin: 0 0 14px; overflow-x: auto; }
.seg button, .seg a { flex: 1; border: 0; background: transparent; font: inherit; color: var(--muted); padding: 8px 10px;
  border-radius: 999px; cursor: pointer; white-space: nowrap; text-decoration: none; text-align: center; font-size: .9rem; }
.seg .on { background: var(--card); color: var(--ink); font-weight: 600; box-shadow: var(--shadow); }

/* Checklists */
.check-group h3 { margin-top: 6px; }
.check { display: flex; align-items: center; gap: 12px; padding: 10px 2px; border-bottom: 1px solid var(--line); }
.check:last-child { border-bottom: 0; }
.check input { width: 22px; height: 22px; accent-color: var(--sage); flex: none; }
.check span { flex: 1; }
.check.done span { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--line); }
.check .by { font-size: .72rem; color: var(--muted); }
.add-row { display: flex; gap: 8px; margin-top: 10px; }
.add-row input { flex: 1; }
.pill { display: inline-block; font-size: .72rem; padding: 2px 8px; border-radius: 99px; background: var(--card-2); color: var(--muted); }
.pill.good { background: var(--sage-soft); color: var(--sage); }
.pill.blue { background: var(--accent-soft); color: var(--accent); }
.pill.warm { background: var(--warm-soft); color: var(--warm); }

/* Contraction timer */
.big-timer { text-align: center; }
.big-btn {
  width: 210px; height: 210px; border-radius: 50%; border: 0; font: inherit; font-size: 1.25rem; font-weight: 700;
  color: #fff; background: var(--accent); box-shadow: 0 10px 30px rgba(79,127,174,.35); cursor: pointer; margin: 14px auto;
  display: grid; place-items: center; line-height: 1.3; -webkit-tap-highlight-color: transparent;
}
.big-btn.active { background: var(--warm); box-shadow: 0 10px 30px rgba(201,119,90,.4); animation: pulse 2s ease-in-out infinite; }
.big-btn small { display: block; font-weight: 400; font-size: .95rem; opacity: .9; }
.big-btn .elapsed { font-size: 2.4rem; font-family: var(--serif); font-variant-numeric: tabular-nums; }
@keyframes pulse { 50% { transform: scale(1.03); } }
.stats3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.stats3 div { background: var(--bg); border-radius: 12px; padding: 10px 4px; border: 1px solid var(--line); }
.stats3 b { display: block; font-family: var(--serif); font-size: 1.35rem; font-variant-numeric: tabular-nums; }
.stats3 small { color: var(--muted); font-size: .72rem; }
.alert { border-radius: var(--radius); padding: 14px 16px; margin: 0 0 14px; font-weight: 500; }
.alert.go { background: var(--warm); color: #fff; }
.alert.go a { color: #fff; }
.alert.near { background: var(--warm-soft); color: var(--ink); }
.alert.calm { background: var(--sage-soft); color: var(--ink); }

table.list { width: 100%; border-collapse: collapse; font-size: .9rem; font-variant-numeric: tabular-nums; }
table.list th { text-align: left; color: var(--muted); font-weight: 500; font-size: .78rem; padding: 6px 4px; border-bottom: 1px solid var(--line); }
table.list td { padding: 8px 4px; border-bottom: 1px solid var(--line); }

/* Contacts */
.contact { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.contact:last-child { border-bottom: 0; }
.avatar { width: 42px; height: 42px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid;
  place-items: center; font-weight: 700; flex: none; }
.contact .who { flex: 1; min-width: 0; }
.contact .who small { color: var(--muted); display: block; }

/* Logs */
.quick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.quick button { border: 1px solid var(--line); background: var(--card); border-radius: 16px; padding: 12px 4px; font: inherit;
  color: var(--ink); cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 74px; }
.quick button span { font-size: 1.5rem; }
.quick button small { color: var(--muted); font-size: .72rem; }
.quick button.active { background: var(--accent-soft); border-color: var(--accent); }
.entry { display: flex; gap: 10px; align-items: center; padding: 9px 0; border-bottom: 1px solid var(--line); }
.entry:last-child { border-bottom: 0; }
.entry .e-icon { font-size: 1.2rem; width: 28px; text-align: center; }
.entry .e-main { flex: 1; }
.entry .e-time { color: var(--muted); font-size: .8rem; font-variant-numeric: tabular-nums; }

/* Charts */
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart text { fill: var(--muted); font-size: 11px; font-family: var(--sans); }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .bar { fill: var(--accent); }
.chart .bar.warm { fill: var(--warm); }
.chart .bar.sage { fill: var(--sage); }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .hit:hover + .bar, .chart g:hover .bar { opacity: .8; }
.chart-tip { position: fixed; pointer-events: none; background: var(--ink); color: var(--bg); font-size: .8rem; padding: 6px 9px;
  border-radius: 8px; z-index: 50; white-space: nowrap; display: none; }
.chart-table { margin-top: 6px; }
.chart-table summary { color: var(--muted); font-size: .8rem; cursor: pointer; }

/* Timeline */
.timeline { position: relative; margin-left: 10px; padding-left: 22px; border-left: 2px solid var(--line); }
.tl-item { position: relative; padding: 4px 0 16px; }
.tl-item::before { content: ""; position: absolute; left: -30px; top: 8px; width: 12px; height: 12px; border-radius: 50%;
  background: var(--gold); border: 3px solid var(--bg); }
.tl-item.pending::before { background: var(--line); }
.tl-item h3 { margin: 0; font-size: 1rem; }
.tl-item img { max-width: 100%; border-radius: 12px; margin-top: 8px; }

/* Photos */
.photo-drop { display: grid; place-items: center; background: var(--bg); border: 2px dashed var(--line); border-radius: 16px;
  min-height: 140px; cursor: pointer; overflow: hidden; color: var(--muted); text-align: center; position: relative; }
.photo-drop img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-drop input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.months { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.month { aspect-ratio: 1; border-radius: 16px; background: var(--card-2); display: grid; place-items: center; text-decoration: none;
  color: var(--ink); overflow: hidden; position: relative; border: 1px solid var(--line); }
.month img { width: 100%; height: 100%; object-fit: cover; }
.month b { position: absolute; left: 8px; bottom: 6px; font-family: var(--serif); background: color-mix(in srgb, var(--card) 85%, transparent);
  padding: 1px 8px; border-radius: 99px; font-size: .85rem; }
.month .m-num { font-family: var(--serif); font-size: 1.8rem; color: var(--muted); }

/* Letters */
.envelope { background: linear-gradient(160deg, var(--warm-soft), var(--card)); border: 1px solid var(--line); border-radius: 16px;
  padding: 16px; margin-bottom: 10px; display: flex; gap: 12px; align-items: center; }
.envelope .seal { width: 44px; height: 44px; border-radius: 50%; background: var(--danger); color: #fff; display: grid; place-items: center;
  font-family: var(--serif); font-weight: 700; flex: none; }
.letter-body { white-space: pre-wrap; font-family: var(--serif); font-size: 1.05rem; line-height: 1.6; }

/* Day One */
.dayone-hero { text-align: center; padding: 22px 16px; }
.dayone-hero img { width: 100%; max-height: 380px; object-fit: cover; border-radius: 16px; margin-bottom: 14px; }
.facts { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 12px; }
.facts div { background: var(--bg); border-radius: 12px; padding: 10px; border: 1px solid var(--line); }
.facts small { display: block; color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; }
.facts b { font-family: var(--serif); font-size: 1.1rem; }

canvas.announce { width: 100%; height: auto; border-radius: 14px; box-shadow: var(--shadow); display: block; }
.swatches { display: flex; gap: 8px; }
.swatches button { width: 36px; height: 36px; border-radius: 50%; border: 2px solid var(--line); cursor: pointer; }
.swatches button.on { border-color: var(--ink); }

.empty { text-align: center; color: var(--muted); padding: 18px 8px; }

#toast { position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: .9rem; opacity: 0;
  transition: .25s; pointer-events: none; z-index: 60; max-width: 90vw; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.book-page { page-break-after: always; break-after: page; }

@media (min-width: 640px) {
  .grid { grid-template-columns: repeat(3, 1fr); }
  .months { grid-template-columns: repeat(4, 1fr); }
}
@media print {
  .topbar, .tabbar, .no-print, #toast { display: none !important; }
  body { padding: 0; background: #fff; color: #000; }
  .card { box-shadow: none; border: 0; }
  main { max-width: none; }
}
