:root {
  --bg: #f7f3eb; --card: #fffdf8; --ink: #29241f; --muted: #625c51; --line: #dfd7ca;
  --accent: #285844; --accent-ink: #fffdf8; --accent-soft: #e3eee5;
  --warn: #9a4a00; --warn-soft: #fbead6; --danger: #b3261e;
  --on: var(--accent); --off: #77786d; --shadow: 0 1px 2px rgba(41,36,31,.07);
  --brand: #963c25; --brand-surface: #f3e6d6; --brand-line: #dfcdb7;
  --display-font: Georgia, "Times New Roman", serif;
  --tabbar-h: 56px; --bar-h: 64px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #181714; --card: #24221d; --ink: #f4ede2; --muted: #c1b8a9; --line: #403b32;
    --accent: #b3d5b9; --accent-ink: #182c21; --accent-soft: #2b3c31;
    --warn: #f0b36b; --warn-soft: #3a2b16; --danger: #ff8f86;
    --off: #9c978a; --shadow: none;
    --brand: #f0a688; --brand-surface: #2b211c; --brand-line: #4a352b;
  }
}
:root[data-theme="dark"] {
  --bg: #181714; --card: #24221d; --ink: #f4ede2; --muted: #c1b8a9; --line: #403b32;
  --accent: #b3d5b9; --accent-ink: #182c21; --accent-soft: #2b3c31;
  --warn: #f0b36b; --warn-soft: #3a2b16; --danger: #ff8f86;
  --off: #9c978a; --shadow: none;
  --brand: #f0a688; --brand-surface: #2b211c; --brand-line: #4a352b;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); overflow-x: hidden;
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
main { padding: calc(env(safe-area-inset-top) + 12px) 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px); max-width: 640px; margin: 0 auto; min-width: 0; }
main.has-bar { padding-bottom: calc(var(--tabbar-h) + var(--bar-h) + env(safe-area-inset-bottom) + 24px); }
h1 { font-size: 28px; line-height: 1.15; margin: 8px 0 16px; letter-spacing: -.01em; overflow-wrap: anywhere; }
h2 { font-size: 13px; text-transform: none; letter-spacing: .02em; color: var(--muted); font-weight: 600; margin: 24px 4px 8px; }
p { margin: 0 0 12px; overflow-wrap: anywhere; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; }
.pad { padding: 14px 16px; }
.btn { min-height: 44px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); font-weight: 600; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--danger); }
.btns { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.btns .btn { flex: 1 1 120px; white-space: nowrap; padding: 0 12px; }

.welcome { max-width: 424px; margin: clamp(4px, 3vh, 24px) auto 0; }
.welcome-intro { padding: clamp(18px, 5vw, 28px); border: 1px solid var(--brand-line); border-radius: 20px; background: var(--brand-surface); }
.brand-logo { display: block; width: 184px; max-width: 100%; height: auto; }
.welcome-intro h1 { margin: 16px 0 8px; font: 400 clamp(30px, 8.8vw, 38px)/1.08 var(--display-font); letter-spacing: -.025em; text-wrap: balance; }
.welcome-intro p { margin: 0; color: var(--muted); }
.welcome-actions { display: grid; gap: 8px; margin-top: 12px; }
.welcome-actions .btn { min-height: 46px; }
.welcome-actions p { margin: 2px 0 0; text-align: center; }

.list { list-style: none; margin: 0; padding: 0; }
.list > li + li { border-top: 1px solid var(--line); }
.row { display: flex; align-items: center; gap: 8px; min-height: 56px; padding: 6px 8px 6px 16px; min-width: 0; }
.row .grow { flex: 1 1 auto; min-width: 0; }
.row .title { font-weight: 600; overflow-wrap: anywhere; }
.row .sub { font-size: 14px; color: var(--muted); overflow-wrap: anywhere; }
a.row, button.row { width: 100%; text-align: left; background: none; border: 0; color: inherit; text-decoration: none; }
.chev { width: 20px; height: 20px; stroke: var(--muted); fill: none; stroke-width: 2; flex: none; }

.toggle { width: 44px; height: 44px; flex: none; border-radius: 22px; border: 0; background: transparent; display: grid; place-items: center; padding: 0; }
.toggle svg { width: 24px; height: 24px; fill: none; stroke: var(--off); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.toggle[aria-pressed="true"] svg { stroke: var(--on); }
.toggle[aria-pressed="true"] { background: var(--accent-soft); }
.toggle:focus-visible, .btn:focus-visible, .seg button:focus-visible, .switch:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.seg { display: flex; background: var(--line); border-radius: 12px; padding: 3px; gap: 2px; margin-bottom: 12px; }
.seg button { flex: 1; min-height: 40px; border: 0; background: transparent; border-radius: 10px; font-weight: 600; color: var(--muted); }
.seg button[aria-selected="true"] { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }

.switch { width: 52px; height: 32px; border-radius: 16px; border: 0; background: var(--off); position: relative; flex: none; padding: 0; margin-right: 8px; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 13px; background: var(--card); transition: transform .15s; }
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"]::after { transform: translateX(20px); }
.switch-row { display: flex; align-items: center; min-height: 56px; padding: 6px 8px 6px 16px; gap: 8px; }
.switch-row .grow { flex: 1; min-width: 0; }

.day { font-size: 13px; font-weight: 700; color: var(--muted); margin: 20px 4px 6px; position: sticky; top: 0; }
.ev { display: flex; gap: 12px; padding: 10px 8px 10px 16px; min-height: 52px; align-items: flex-start; }
.ev .when { width: 58px; flex: none; font-size: 14px; color: var(--muted); padding-top: 2px; font-variant-numeric: tabular-nums; }
.ev .when .until-clock { display: block; color: var(--muted); font-weight: 400; }
.ev .grow { flex: 1; min-width: 0; }
.ev .title { font-weight: 600; overflow-wrap: anywhere; }
.ev .sub { font-size: 14px; color: var(--muted); overflow-wrap: anywhere; }
.ev.hidden-ev .title { text-decoration: line-through; color: var(--muted); }
.ev .reason { font-size: 13px; color: var(--warn); }
.ev .bell { width: 20px; height: 20px; flex: none; fill: none; stroke: var(--on); stroke-width: 1.8; margin-top: 2px; }
.agenda > h1 { margin: 2px 0 8px; font: 400 38px/1.1 var(--display-font); letter-spacing: -.025em; }
.agenda-day + .agenda-day { margin-top: 14px; }
.agenda-date { position: sticky; top: env(safe-area-inset-top); z-index: 1; display: flex; align-items: center; gap: 10px; margin: 0; padding: 7px 2px; background: var(--bg); color: var(--ink); font-size: 14px; font-weight: 700; }
.agenda-date::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.agenda-date.is-today { color: var(--brand); }
.agenda-date.is-today::after { background: var(--brand-line); }
.agenda-day .card { box-shadow: none; }
.agenda-day .ev { gap: 9px; padding: 10px 11px; min-height: 46px; }
.agenda-day .when { width: 46px; color: var(--accent); font-size: 13px; font-weight: 650; padding-top: 2px; }
.agenda-day .event-meta { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.agenda-day .event-meta .sub { display: inline; font-size: inherit; }
.agenda-day .event-meta .sub + .sub::before { content: " · "; }
.agenda-day .event-alert { display: grid; place-items: center; flex: none; width: 26px; height: 26px; border: 1px solid var(--brand-line); border-radius: 50%; background: var(--brand-surface); }
.agenda-day .bell { width: 17px; height: 17px; margin: 0; stroke: var(--brand); }
.agenda-empty { padding: 18px 16px; }
.agenda-empty h2 { margin: 0 0 4px; color: var(--ink); font-size: 16px; letter-spacing: 0; }
.agenda-empty .btn { display: inline-flex; align-items: center; text-decoration: none; }
.pill { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); margin-right: 6px; }
.pill.removed { background: var(--warn-soft); color: var(--warn); }

#tabbar { position: fixed; left: 0; right: 0; bottom: 0; display: flex; background: var(--card); border-top: 1px solid var(--line); padding-inline: max(0px, calc((100% - 640px) / 2)); padding-bottom: env(safe-area-inset-bottom); z-index: 5; }
#tabbar a { flex: 1; height: var(--tabbar-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; color: var(--muted); text-decoration: none; min-width: 0; }
#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); font-weight: 700; }

#bar-slot { position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); z-index: 4; }
.bar { display: flex; align-items: center; gap: 12px; min-height: var(--bar-h); padding: 8px 16px; background: var(--card); border-top: 1px solid var(--line); box-shadow: 0 -4px 12px rgba(0,0,0,.06); }
.bar .grow { flex: 1; min-width: 0; }
.bar .count { font-weight: 700; }
.bar .btn { flex: none; }

.back { display: inline-flex; align-items: center; gap: 2px; min-height: 44px; padding: 0 8px 0 0; border: 0; background: none; color: var(--accent); font-weight: 600; text-decoration: none; }
.back svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 2.2; }
.field { width: 100%; min-height: 48px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); padding: 0 14px; }
.notice { background: var(--warn-soft); color: var(--warn); border-radius: 12px; padding: 10px 14px; font-size: 14px; margin: 12px 0; }
.empty { text-align: center; color: var(--muted); padding: 32px 16px; }

#overlay { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
#overlay[hidden], #toast[hidden] { display: none; }
.sheet { background: var(--card); width: 100%; max-width: 640px; border-radius: 18px 18px 0 0; padding: 20px 16px calc(env(safe-area-inset-bottom) + 16px); }
.sheet h3 { margin: 0 0 8px; font-size: 18px; overflow-wrap: anywhere; }
#toast { position: fixed; left: 16px; right: 16px; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 76px); background: var(--ink); color: var(--bg); padding: 12px 16px; border-radius: 12px; z-index: 30; text-align: center; }
.spinner { text-align: center; color: var(--muted); padding: 40px 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.link-btn { min-height: 44px; min-width: 44px; padding: 0 4px 0 8px; border: 0; background: none; color: var(--accent); font-weight: 600; }
.link-btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* People and joining (PLAN_ACCOUNTS §11) */
.invite-link { font-family: ui-monospace, Menlo, monospace; font-size: 13px; word-break: break-all; user-select: all; -webkit-user-select: all; padding: 10px 12px; border-radius: 10px; background: color-mix(in srgb, currentColor 7%, transparent); margin: 0 0 10px; }
.list li.indent .row { padding-left: 32px; }

/* First run and adding a calendar (WC-D13) */
.first-run h1 { margin: 2px 0 12px; font: 400 34px/1.1 var(--display-font); letter-spacing: -.025em; }
.steps { margin: 0 0 16px; padding: 0 0 0 22px; color: var(--muted); }
.steps li { margin: 0 0 6px; padding-left: 2px; }
.steps li::marker { color: var(--brand); font-weight: 700; }
.steps b, .help b { color: var(--ink); }
.center { text-align: center; }
.link-btn.inline { min-height: 44px; padding: 0; justify-self: start; text-align: left; }
.add-form { display: grid; gap: 8px; }
.add-form label { font-weight: 600; font-size: 15px; }
.add-form label:not(:first-child) { margin-top: 4px; }
.add-form .notice { margin: 0; }
.add-form .btn.primary { margin-top: 4px; }
.field-row { display: flex; gap: 8px; min-width: 0; }
.field-row .field { flex: 1 1 auto; min-width: 0; }
.field-row .btn { flex: none; }
.ask-name { display: grid; gap: 0; margin-bottom: 12px; border-color: var(--brand-line); background: var(--brand-surface); }
.subscribe { border-color: var(--brand-line); background: var(--brand-surface); margin-bottom: 12px; }
.subscribe .btns { margin-top: 4px; }
.hint { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; margin: 0 0 12px; border-radius: 12px; background: var(--accent-soft); font-size: 14px; }
.hint svg { width: 20px; height: 20px; flex: none; fill: none; stroke: var(--accent); stroke-width: 1.8; margin-top: 1px; }
.help { margin: 0 0 4px; padding-left: 20px; font-size: 15px; }
.help li { margin: 0 0 10px; }
.help code { font-size: 13px; padding: 1px 4px; border-radius: 5px; background: var(--bg); border: 1px solid var(--line); }
.sheet { max-height: 88vh; overflow-y: auto; }
