:root {
  --bg: #faf6f0;
  --card: #ffffff;
  --ink: #2b211c;
  --muted: #6f625a;
  --accent: #7a2e1f;
  --accent-soft: #f3e4dc;
  --line: #e8ded3;
  --danger: #a3261b;
  --radius: 16px;
  --tabbar-h: 64px;
  color-scheme: light dark;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1613; --card: #26201c; --ink: #f3ebe3; --muted: #b5a89d;
    --accent: #e8a48f; --accent-soft: #3a2a23; --line: #3a312b; --danger: #f08a7e;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { min-height: 100vh; padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px); }
p { margin: 0; }
h1, h2 { margin: 0; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  padding: calc(env(safe-area-inset-top) + 12px) 20px 12px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
}
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; color: var(--accent); }
.brand img { border-radius: 8px; }

main {
  max-width: 520px; margin: 0 auto; outline: none;
  padding: 4px max(16px, env(safe-area-inset-right)) 24px max(16px, env(safe-area-inset-left));
}

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin: 0 0 12px; }
.section { margin-top: 24px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; margin: 0 4px 8px; }
.section-head h2 { font-size: 15px; font-weight: 650; color: var(--muted); letter-spacing: .01em; }
.page-title { font-size: 26px; margin: 8px 4px 16px; }

.eyebrow { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; line-height: 1.45; }
.pad { padding: 4px 4px 0; }
.meta { font-size: 13px; color: var(--muted); margin-top: 12px; line-height: 1.45; }
.note { font-size: 13px; margin-top: 10px; padding: 8px 12px; border-radius: 10px; background: var(--accent-soft); }
.error { color: var(--danger); font-size: 14px; padding: 8px 4px; }

.today { border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); }
.today .roj { font-size: 32px; line-height: 1.15; font-weight: 750; color: var(--accent); }
.today .mah { font-size: 21px; margin-top: 4px; }

.empty { text-align: left; }
.empty-title { font-weight: 650; margin-bottom: 6px; }
.empty .btn { margin-top: 14px; }

.list { list-style: none; padding: 4px 20px; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row-title { font-weight: 600; font-size: 15px; }
.row-right { text-align: right; flex-shrink: 0; }
.row-date { font-weight: 600; font-size: 14px; }

.btn {
  font: inherit; font-size: 15px; font-weight: 600; border: 0; border-radius: 12px;
  padding: 12px 16px; background: var(--accent); color: #fff; cursor: pointer;
}
@media (prefers-color-scheme: dark) { .btn { color: #1b1613; } }
.btn.ghost { background: transparent; color: var(--accent); border: 1px solid var(--line); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.tip { border-style: dashed; }
.tip-actions { display: flex; gap: 8px; margin-top: 12px; }

.tabs { display: flex; gap: 4px; padding: 4px; background: var(--accent-soft); border-radius: 12px; margin-bottom: 12px; }
.tabs button {
  flex: 1; font: inherit; font-size: 14px; font-weight: 600; border: 0; border-radius: 9px;
  padding: 10px; background: transparent; color: var(--muted); cursor: pointer;
}
.tabs button[aria-selected="true"] { background: var(--card); color: var(--ink); box-shadow: 0 1px 2px rgb(0 0 0 / .08); }

.form { display: grid; gap: 14px; }
.form label { display: grid; gap: 6px; font-size: 14px; font-weight: 600; }
.form label[hidden] { display: none; }
input, select, textarea {
  font: inherit; font-size: 16px; font-weight: 400; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; width: 100%; min-height: 46px;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible, .tabs button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.result .cal-row { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); font-size: 15px; }
.result .cal-row.main { border-top: 0; font-size: 18px; font-weight: 700; color: var(--accent); }
.result .cal-name { color: var(--muted); font-weight: 500; font-size: 14px; }
.result .cal-row.main .cal-name { color: var(--accent); }
.result .cal-val { text-align: right; }
.big-date { font-size: 20px; font-weight: 700; color: var(--accent); margin-top: 2px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: space-around;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card); border-top: 1px solid var(--line);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); text-decoration: none; font-size: 12px; font-weight: 600;
}
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a[aria-current="page"] { color: var(--accent); }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 14px; z-index: 20;
}

/* ---- Version 0.3: people, add/edit, welcome ---- */
.title-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.title-row .page-title { margin-right: auto; }
.head-link { color: var(--accent); font-weight: 600; font-size: 15px; text-decoration: none; padding: 6px 4px; }
.small-btn { padding: 8px 14px; font-size: 14px; text-decoration: none; }
a.btn { display: inline-block; text-decoration: none; text-align: center; }
.btn.wide { width: 100%; }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--line); }
.stack { display: grid; gap: 10px; }
.block { display: block; }
.soon { color: var(--accent); font-weight: 600; }

.list a.row.link { color: inherit; text-decoration: none; }
.list li { list-style: none; }
.list li:last-child .row { border-bottom: 0; }

.person { padding: 16px 20px; }
.person-name { font-size: 18px; font-weight: 700; margin-bottom: 4px; }
.plain { list-style: none; margin: 0; padding: 0; }
.event-line { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); color: inherit; text-decoration: none; }
.plain li:first-child .event-line { border-top: 0; }
.star { color: var(--accent); }
.chev { color: var(--muted); font-size: 22px; }

fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
legend { font-size: 14px; font-weight: 600; margin-bottom: 8px; padding: 0; }

.seg { display: flex; flex-wrap: wrap; gap: 8px; }
.seg label, .chip { position: relative; display: inline-flex; font-weight: 500; }
.seg input, .chip input, .option input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.seg span, .chip span {
  display: inline-block; padding: 9px 14px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--bg); font-size: 14px; cursor: pointer; user-select: none;
}
.seg input:checked + span, .chip input:checked + span { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .seg input:checked + span, .chip input:checked + span { color: #1b1613; } }
.seg input:focus-visible + span, .chip input:focus-visible + span, .option input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }

.options { display: grid; gap: 8px; }
.option { position: relative; display: block; font-weight: 400; }
.option > span { display: block; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); cursor: pointer; }
.option input:checked + span { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); background: var(--accent-soft); }

.note .linkish, .linkish { font: inherit; font-weight: 600; color: var(--accent); background: none; border: 0; padding: 0; cursor: pointer; text-decoration: underline; }

.confirm { border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); }
.confirm-line { font-size: 15px; line-height: 1.5; padding: 6px 0; border-top: 1px solid var(--line); }
.confirm .eyebrow + .confirm-line { border-top: 0; }

.file-btn { cursor: pointer; }

.welcome { text-align: left; padding: 24px 4px 16px; }
.welcome h1 { font-size: 26px; line-height: 1.2; margin: 12px 0 8px; }
.welcome-icon { border-radius: 18px; }
.steps { margin: 0; padding-left: 20px; display: grid; gap: 10px; line-height: 1.45; }
.steps + .note { margin-top: 14px; }
body.no-tabs .tabbar { display: none; }
body.no-tabs { padding-bottom: 32px; }
.list li > a.row { border-bottom: 1px solid var(--line); }
.list li:last-child > a.row { border-bottom: 0; }
.field { display: grid; gap: 6px; }
.field-label { font-size: 14px; font-weight: 600; }
.date3 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; }
.date3 [data-part=m] { grid-column: 1 / -1; order: -1; } /* month on top, full width, so nothing gets cut off */
.date3 > * { min-width: 0; }
.field-error { color: var(--danger); }
.field-error[hidden] { display: none; }
.ios-icon {
  display: inline-block; width: 1.35em; height: 1.35em; vertical-align: -0.3em; margin: 0 2px;
  fill: none; stroke: #0a84ff; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 20px; font-weight: 700; letter-spacing: .04em; color: var(--accent); margin: 8px 0 4px; word-break: break-all; user-select: all; }
.sync-status { color: var(--muted); margin-top: 8px; }
#restore-code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; text-transform: uppercase; }
.pill { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--accent); color: #fff; vertical-align: 2px; margin-left: 6px; }
@media (prefers-color-scheme: dark) { .pill { color: #1b1613; } }

/* WhatsApp wishes */
textarea { resize: vertical; line-height: 1.45; min-height: 110px; }
.wa-icon { width: 18px; height: 18px; vertical-align: -4px; margin-right: 6px; }
.btn.wa { background: #1f8a4c; color: #fff; }
@media (prefers-color-scheme: dark) { .btn.wa { background: #2fa866; color: #0d1f14; } }
.list li:has(> .wish-link) > a.row { border-bottom: 0; padding-bottom: 4px; }
.wish-link {
  display: block; padding: 4px 0 14px; color: #1f8a4c; font-size: 14px; font-weight: 600;
  text-decoration: none; border-bottom: 1px solid var(--line);
}
@media (prefers-color-scheme: dark) { .wish-link { color: #49c07f; } }
.list li:last-child > .wish-link { border-bottom: 0; }
.title-row + .btn.wa { margin-bottom: 12px; }
.form p a { color: var(--accent); font-weight: 600; }

/* Keep every box inside the screen, on every phone. */
.form > *, .form label, .field, .stack > * { min-width: 0; }
input, select, textarea { max-width: 100%; }
select { text-overflow: ellipsis; }
/* iPhones draw time and date boxes wider than the screen unless told not to. */
input[type=time], input[type=date] {
  -webkit-appearance: none; appearance: none; display: block; min-width: 0; text-align: left;
}
input::-webkit-date-and-time-value { text-align: left; margin: 0; }
/* Long names and words wrap instead of pushing things off the screen. */
.row > div:first-child, .event-line > span { min-width: 0; }
.row-title, .person-name, .page-title, .confirm-line, .eyebrow, .muted { overflow-wrap: anywhere; }
.title-row { gap: 12px; }
.title-row .page-title { min-width: 0; }
.tip-actions { flex-wrap: wrap; }
/* Small phones: a little less padding. */
@media (max-width: 359px) {
  .card { padding: 16px; }
  main { padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
}
.date3 select { padding-right: 28px; }
#restore-code::placeholder { font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; text-transform: none; }

/* Popup (calendar) */
dialog.sheet {
  width: min(440px, calc(100vw - 32px)); max-height: calc(100dvh - 48px); overflow: auto;
  border: 1px solid var(--line); border-radius: 20px; padding: 24px 20px 20px;
  background: var(--card); color: var(--ink); box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
}
dialog.sheet::backdrop { background: rgba(20, 12, 8, .45); }
dialog.sheet h2 { font-size: 20px; line-height: 1.25; margin-bottom: 8px; }
dialog.sheet > .muted { margin-bottom: 16px; line-height: 1.45; }
dialog.sheet .stack { margin-bottom: 10px; }
dialog.sheet .small { margin-top: 12px; }
.gap-top { margin-top: 10px; }
