:root {
  --paper: #f7f4ee;
  --card: #fffdf9;
  --sage: #5c7250;
  --sage-mid: #7a9468;
  --sage-soft: #e9eee3;
  --sage-softer: #f2f5ee;
  --ink: #2a2420;
  --mid: #5a5248;
  --muted: #8a847c;
  --oyster: #c4b8a5;
  --rule: #e4dccf;
  --danger: #a5523f;
  --serif: 'Cormorant Garamond', Garamond, Georgia, serif;
  --caps: 'Cinzel', 'Cormorant Garamond', serif;
  --script: 'Great Vibes', 'Edwardian Script ITC', cursive;
  --shadow: 0 1px 2px rgba(42,36,32,.04), 0 6px 24px rgba(42,36,32,.06);
  --line: 34px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font-family: var(--serif); font-size: 19px; line-height: 1.35;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.boot { min-height: 100vh; display: grid; place-items: center; opacity: .5; }

/* ── layout ─────────────────────────────────────── */
.wrap { max-width: 780px; margin: 0 auto; padding: 0 16px 80px; }
.caps { font-family: var(--caps); text-transform: uppercase; letter-spacing: .2em; font-size: 11px; color: var(--muted); }

header.top { text-align: center; padding: 26px 0 10px; }
header.top .logo { width: 64px; height: auto; opacity: .9; }
header.top h1 { font-family: var(--script); font-weight: 400; color: var(--sage); font-size: 54px; line-height: 1; margin: 6px 0 0; }
header.top .sub { font-style: italic; color: var(--mid); margin-top: 4px; }
.progress { margin: 14px auto 0; max-width: 360px; }
.bar { height: 6px; border-radius: 6px; background: var(--sage-soft); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--sage-mid); border-radius: 6px; transition: width .4s ease; }
.progress .caps { margin-top: 7px; display: block; }

.userbar { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 15px; color: var(--muted); padding: 10px 0 0; }
.userbar button { background: none; border: 0; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; padding: 6px 0; }
.live { display: inline-flex; align-items: center; gap: 6px; }
.live::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--sage-mid); }
.live.off::before { background: var(--oyster); }

/* ── tabs ───────────────────────────────────────── */
nav.weeks {
  position: sticky; top: 0; z-index: 5; background: rgba(247,244,238,.94);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  margin: 14px -16px 0; padding: 10px 16px; border-bottom: 1px solid var(--rule);
}
.tabs { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 1 0 auto; border: 1px solid var(--rule); background: var(--card); border-radius: 999px;
  padding: 8px 14px; font-size: 16px; white-space: nowrap; color: var(--mid);
}
.tab small { color: var(--muted); font-size: 13px; margin-left: 4px; }
.tab.on { background: var(--sage); border-color: var(--sage); color: #fff; }
.tab.on small { color: #e5ecdf; }
.tools { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; gap: 10px; font-size: 15px; color: var(--mid); }
.tools label { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.tools input { width: 18px; height: 18px; accent-color: var(--sage); }
.linkbtn { background: none; border: 0; color: var(--sage); padding: 4px 0; font-size: 15px; }

/* ── week + day ─────────────────────────────────── */
.week-head { text-align: center; margin: 26px 0 8px; }
.week-head h2 { font-family: var(--script); font-weight: 400; color: var(--sage); font-size: 44px; line-height: 1.05; margin: 4px 0; }
.week-head .sub { font-style: italic; color: var(--mid); }
.orn { display: flex; align-items: center; gap: 10px; margin: 12px 0 4px; }
.orn::before, .orn::after { content: ''; flex: 1; height: 1px; background: var(--sage-mid); opacity: .6; }
.orn i { width: 7px; height: 7px; background: var(--sage-mid); transform: rotate(45deg); }

.day {
  background: var(--card); border-radius: 16px; box-shadow: var(--shadow);
  margin: 16px 0; padding: 16px 16px 12px; border: 1px solid #efe9df; scroll-margin-top: 120px;
}
.day.today { border-color: var(--sage-mid); box-shadow: 0 0 0 2px rgba(122,148,104,.18), var(--shadow); }
.day.past { opacity: .82; }
.day-head { display: flex; align-items: center; gap: 12px; }
.day-head .dnum { font-size: 40px; line-height: 1; color: var(--ink); min-width: 44px; }
.day-head .dname { display: flex; flex-direction: column; gap: 2px; }
.day-head .dname b { font-family: var(--caps); font-weight: 400; letter-spacing: .22em; text-transform: uppercase; font-size: 14px; }
.day-head .dname span { font-size: 15px; color: var(--muted); font-style: italic; }
.day-head .right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.circle {
  width: 40px; height: 40px; border-radius: 50%; border: 1.5px solid var(--sage-mid); color: var(--sage);
  display: grid; place-items: center; font-size: 17px; line-height: 1; flex: none;
}
.circle.fill { background: var(--sage-mid); color: #fff; border-color: var(--sage-mid); }
.pill { font-family: var(--caps); font-size: 10px; letter-spacing: .2em; text-transform: uppercase; background: var(--sage); color: #fff; padding: 4px 8px; border-radius: 999px; }
.count { font-size: 14px; color: var(--muted); white-space: nowrap; }
.count.all { color: var(--sage); }

ul.items { list-style: none; margin: 10px 0 0; padding: 0; }
li.item { display: flex; align-items: flex-start; gap: 4px; border-bottom: 1px solid var(--rule); min-height: var(--line); }
li.item:last-child { border-bottom: 0; }
.tick {
  flex: none; width: 44px; height: 44px; margin: -3px 0 -3px -10px; border: 0; background: none; display: grid; place-items: center;
  -webkit-tap-highlight-color: transparent;
}
.tick span {
  width: 22px; height: 22px; border-radius: 6px; border: 1.6px solid var(--sage-mid); background: #fff;
  display: grid; place-items: center; transition: background .15s, transform .1s;
}
.tick:active span { transform: scale(.9); }
.tick span svg { width: 14px; height: 14px; opacity: 0; }
li.done .tick span { background: var(--sage-mid); }
li.done .tick span svg { opacity: 1; }
.heart { flex: none; width: 34px; height: 38px; display: grid; place-items: center; color: var(--sage-mid); font-size: 17px; }
.itext {
  flex: 1; text-align: left; background: none; border: 0; padding: 8px 2px; font-size: 19px; line-height: 1.3; min-width: 0;
  overflow-wrap: anywhere; -webkit-tap-highlight-color: rgba(122,148,104,.12); border-radius: 6px;
}
.itext .time { font-family: var(--caps); font-size: 13px; letter-spacing: .06em; color: var(--sage); font-weight: 500; margin-right: 6px; }
.itext .meta { display: block; font-size: 14px; color: var(--muted); font-style: italic; margin-top: 1px; }
li.note .itext .t { font-style: italic; color: var(--sage); }
li.event .itext .t, li.wed .itext .t { color: var(--sage); font-weight: 600; }
li.done .itext .t { text-decoration: line-through; text-decoration-color: rgba(90,82,72,.5); color: var(--muted); }

.add {
  display: flex; align-items: center; gap: 8px; width: 100%; background: none; border: 1px dashed var(--oyster);
  border-radius: 10px; padding: 9px 12px; margin-top: 10px; color: var(--sage); font-size: 17px;
}
.add b { font-size: 22px; line-height: 1; font-weight: 400; }

.notes { margin-top: 12px; }
.notes .lbl { display: flex; justify-content: space-between; align-items: baseline; }
.notes .saved { font-size: 13px; color: var(--muted); font-style: italic; }
.notes textarea {
  width: 100%; min-height: calc(var(--line) * 3 + 6px); resize: vertical; border: 0; outline: 0; padding: 6px 2px 0;
  background: transparent repeating-linear-gradient(to bottom, transparent 0, transparent calc(var(--line) - 1px), var(--rule) calc(var(--line) - 1px), var(--rule) var(--line));
  background-position: 0 6px; line-height: var(--line); font-size: 19px; display: block;
}
.notes textarea::placeholder { color: #bdb4a6; font-style: italic; }

.weekbox { background: var(--sage-softer); border: 1px solid #e1e8d9; }

.empty { color: var(--muted); font-style: italic; font-size: 16px; padding: 8px 0 2px; }

footer.foot { text-align: center; color: var(--muted); font-size: 14px; margin: 30px 0 10px; }
footer.foot img { width: 30px; opacity: .7; display: block; margin: 0 auto 6px; }

/* ── sheets ─────────────────────────────────────── */
.overlay {
  position: fixed; inset: 0; z-index: 50; background: rgba(42,36,32,.35); display: flex; align-items: flex-end; justify-content: center;
  animation: fade .15s ease;
}
@media (min-width: 640px) { .overlay { align-items: center; } }
.sheet {
  width: 100%; max-width: 480px; background: var(--card); border-radius: 20px 20px 0 0; padding: 22px 20px calc(18px + env(safe-area-inset-bottom));
  box-shadow: 0 -10px 40px rgba(0,0,0,.15); animation: up .2s ease; max-height: 92vh; overflow-y: auto;
}
@media (min-width: 640px) { .sheet { border-radius: 20px; } }
.sheet h3 { font-family: var(--script); font-weight: 400; color: var(--sage); font-size: 38px; margin: 0 0 4px; line-height: 1.1; text-align: center; }
.sheet .q { text-align: center; color: var(--mid); margin: 0 0 18px; font-size: 19px; }
.sheet .q em { color: var(--ink); }
.btns { display: flex; flex-direction: column; gap: 8px; }
.btn { border: 0; border-radius: 12px; padding: 13px 16px; font-size: 18px; background: var(--sage-soft); color: var(--ink); }
.btn.primary { background: var(--sage); color: #fff; }
.btn.danger { background: #f6e9e5; color: var(--danger); }
.btn.ghost { background: none; color: var(--mid); }
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; margin-bottom: 6px; }
.field textarea, .field input, .field select {
  width: 100%; border: 1px solid var(--rule); border-radius: 10px; padding: 10px 12px; background: #fff; font-size: 18px;
}
.field textarea { min-height: 84px; resize: vertical; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button { flex: 1; border: 1px solid var(--rule); border-radius: 10px; background: #fff; padding: 9px 8px; font-size: 16px; }
.seg button.on { border-color: var(--sage); background: var(--sage-soft); color: var(--sage); }
.timewrap { display: flex; gap: 6px; }
.timewrap button { border: 1px solid var(--rule); background: #fff; border-radius: 10px; padding: 0 12px; color: var(--muted); }
.err { color: var(--danger); font-size: 16px; min-height: 20px; margin: -4px 0 8px; text-align: center; }

/* ── login ──────────────────────────────────────── */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login .card { width: 100%; max-width: 380px; text-align: center; background: var(--card); border-radius: 22px; box-shadow: var(--shadow); padding: 32px 24px 26px; }
.login img { width: 92px; }
.login h1 { font-family: var(--script); font-weight: 400; color: var(--sage); font-size: 52px; margin: 6px 0 0; line-height: 1; }
.login p { font-style: italic; color: var(--mid); margin: 6px 0 20px; }
.login .seg { margin-bottom: 12px; }
.login .seg button { font-size: 19px; padding: 12px; }
.login input { width: 100%; border: 1px solid var(--rule); border-radius: 12px; padding: 12px 14px; font-size: 18px; margin-bottom: 10px; background: #fff; }
.login .btn { width: 100%; }

/* ── toast ──────────────────────────────────────── */
#toast {
  position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translate(-50%, 140%);
  background: var(--ink); color: #fff; border-radius: 12px; padding: 11px 16px; font-size: 17px; z-index: 60;
  display: flex; gap: 14px; align-items: center; transition: transform .25s ease; max-width: calc(100% - 32px);
}
#toast.show { transform: translate(-50%, 0); }
#toast button { background: none; border: 0; color: #cfe0c2; font-weight: 600; padding: 0; }

@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(30px); opacity: .6; } }

@media print {
  nav.weeks, .add, .userbar, .tools, #toast { display: none !important; }
  body { background: #fff; }
  .day { box-shadow: none; break-inside: avoid; }
}
