:root {
  --accent: #c8402f; --accent-ink: #fff; --accent-soft: #ffdad4;
  --bg: #fcfcfd; --surface: #ffffff; --surface-2: #f1f1f4; --line: #e3e3e8;
  --ink: #1c1c20; --muted: #5f6068; --today: #c8402f;
  --radius: 12px; --shadow: 0 10px 40px rgba(20, 20, 30, .18);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --accent: #ff8f80; --accent-ink: #4a0e08; --accent-soft: #6e2a22;
    --bg: #141416; --surface: #1e1e21; --surface-2: #26262a; --line: #2f2f34;
    --ink: #ececf0; --muted: #a2a3ab; --today: #ff8f80;
    --shadow: 0 10px 40px rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
.loading { padding: 40px; text-align: center; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: 999px; padding: 7px 14px; cursor: pointer; text-decoration: none; white-space: nowrap;
  min-height: 36px;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: #c62828; }
.btn.icon { padding: 0; width: 36px; border-radius: 50%; font-size: 18px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: default; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 7px 14px; cursor: pointer; min-height: 36px; }
.seg button[aria-pressed="true"] { background: var(--accent-soft); font-weight: 600; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Layout */
.top {
  position: sticky; top: 0; z-index: 5; background: var(--bg);
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 10px 16px; border-bottom: 1px solid var(--line);
}
.top .title { display: flex; align-items: center; gap: 10px; min-width: 0; margin-right: auto; }
.top .title h1 { font-size: 18px; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .title .dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.top .home { display: flex; align-items: center; text-decoration: none; }
.top .home img { width: 30px; height: 30px; border-radius: 8px; display: block; }
.nav { display: flex; align-items: center; gap: 6px; padding: 10px 16px 0; flex-wrap: wrap; }
.nav h2 { font-size: 20px; margin: 0 auto 0 6px; font-weight: 600; }
.banner { margin: 10px 16px 0; padding: 10px 14px; border-radius: var(--radius); background: var(--accent-soft); display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.banner p { margin: 0; flex: 1 1 240px; }

/* Month */
.month { padding: 8px 16px 16px; }
.month .wd, .month .grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.month .wd div { font-size: 12px; color: var(--muted); text-align: center; padding: 4px 0; text-transform: uppercase; letter-spacing: .04em; }
.month .grid { border-top: 1px solid var(--line); border-left: 1px solid var(--line); }
.cell {
  border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
  min-height: 104px; padding: 4px; cursor: pointer; overflow: hidden; background: var(--surface);
  display: flex; flex-direction: column; gap: 2px; text-align: left; border-top: 0; border-left: 0; border-radius: 0;
}
.cell.out { background: var(--bg); }
.cell.out .num { color: var(--muted); opacity: .7; }
.cell.sel { box-shadow: inset 0 0 0 2px var(--accent); }
.cell .num { font-size: 13px; width: 26px; height: 26px; display: grid; place-items: center; border-radius: 50%; }
.cell.today .num { background: var(--today); color: var(--accent-ink); font-weight: 700; }
.chip {
  font-size: 12px; line-height: 18px; border-radius: 4px; padding: 0 5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--ink);
}
.chip.allday { color: #fff; }
.chip .t { color: var(--muted); margin-right: 3px; }
.chip.timed::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--c); margin-right: 4px; vertical-align: 1px; }
.more { font-size: 12px; color: var(--muted); padding: 0 5px; }
.daylist { padding: 0 16px 24px; }
.daylist h3 { font-size: 15px; margin: 4px 0 8px; }

/* Event rows (lists) */
.row {
  display: flex; gap: 12px; align-items: flex-start; padding: 10px 12px; border-radius: var(--radius);
  cursor: pointer; background: var(--surface); border: 1px solid var(--line); margin-bottom: 8px; width: 100%; text-align: left;
}
.row:hover { background: var(--surface-2); }
.row .bar { width: 4px; align-self: stretch; border-radius: 2px; flex: none; }
.row .time { width: 92px; flex: none; color: var(--muted); font-size: 13px; padding-top: 1px; }
.row .main { min-width: 0; }
.row .main b { display: block; font-weight: 600; overflow-wrap: anywhere; }
.row .main span { color: var(--muted); font-size: 13px; }
.empty { color: var(--muted); padding: 12px 2px; }

/* Agenda */
.agenda { padding: 8px 16px 32px; max-width: 760px; }
.agenda h3 { font-size: 14px; margin: 18px 0 8px; color: var(--muted); font-weight: 600; }
.agenda h3.today { color: var(--accent); }

/* Week */
.week { padding: 8px 0 16px; overflow-x: auto; }
.week .inner { min-width: 640px; padding: 0 16px; }
.week .head, .week .alld { display: grid; grid-template-columns: 56px repeat(7, minmax(0, 1fr)); }
.week .head div { text-align: center; font-size: 12px; color: var(--muted); padding: 4px 0; cursor: pointer; }
.week .head b { display: block; font-size: 20px; color: var(--ink); font-weight: 500; }
.week .head .today b { color: var(--accent); font-weight: 700; }
.week .alld { border-bottom: 1px solid var(--line); min-height: 8px; }
.week .alld > div { padding: 2px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.week .alld .lbl { font-size: 11px; color: var(--muted); text-align: right; padding-right: 6px; }
.week .body { display: grid; grid-template-columns: 56px repeat(7, minmax(0, 1fr)); position: relative; height: 60vh; min-height: 420px; overflow-y: auto; }
.week .hours, .week .col { position: relative; height: 1152px; }
.week .hours div { height: 48px; font-size: 11px; color: var(--muted); text-align: right; padding-right: 6px; transform: translateY(-7px); }
.week .col { border-left: 1px solid var(--line); background: repeating-linear-gradient(to bottom, var(--line) 0 1px, transparent 1px 48px); cursor: pointer; }
.week .col.today { background-color: color-mix(in srgb, var(--accent-soft) 25%, transparent); }
.week .ev {
  position: absolute; border-radius: 6px; padding: 2px 5px; font-size: 12px; line-height: 15px; overflow: hidden;
  color: #fff; cursor: pointer; border: 1px solid var(--surface); text-align: left;
}
.week .ev small { display: block; opacity: .9; }
.week .now { position: absolute; left: 0; right: 0; height: 2px; background: var(--accent); z-index: 2; pointer-events: none; }
.week .now::before { content: ""; position: absolute; left: -5px; top: -4px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }

/* Dialogs */
dialog {
  border: 0; border-radius: 16px; padding: 0; background: var(--surface); color: var(--ink);
  width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(10, 10, 15, .45); }
dialog .dlg { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
dialog h2 { margin: 0; font-size: 20px; overflow-wrap: anywhere; }
dialog .actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 4px; }
dialog .actions .spacer { margin-right: auto; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: 13px; color: var(--muted); }
.field input, .field select, .field textarea, .inline input, .box > input {
  border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 9px 11px; width: 100%; min-width: 0;
}
.field textarea { min-height: 84px; resize: vertical; }
.pair { display: flex; gap: 8px; }
.pair > * { flex: 1; min-width: 0; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.err { color: #c62828; font-size: 13px; margin: 0; }
.kv { display: grid; grid-template-columns: 24px 1fr; gap: 10px; align-items: start; }
.kv .ic { color: var(--muted); text-align: center; }
.kv p { margin: 0; overflow-wrap: anywhere; white-space: pre-wrap; }
.copy { display: flex; gap: 6px; }
.copy input { flex: 1; min-width: 0; border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 8px 10px; font-size: 13px; }
.box { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.box h3 { margin: 0; font-size: 15px; }
.box p { margin: 0; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatches button { width: 30px; height: 30px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; }
.swatches button[aria-pressed="true"] { border-color: var(--ink); }
.rsvp-list { display: flex; flex-wrap: wrap; gap: 6px; }
.pill { font-size: 13px; padding: 2px 10px; border-radius: 999px; background: var(--surface-2); }
.pill.yes { background: #d9f2df; color: #145c2a; }
.pill.maybe { background: #fff1c9; color: #6b4e00; }
.pill.no { background: #f3dcdc; color: #7a1d1d; }
@media (prefers-color-scheme: dark) {
  .pill.yes { background: #1d3b25; color: #a6e3b4; }
  .pill.maybe { background: #3d3317; color: #f1d27e; }
  .pill.no { background: #432124; color: #f0a7a7; }
}

/* Home */
.landing { max-width: 640px; margin: 0 auto; padding: 40px 20px 60px; }
.landing .hero { display: flex; align-items: center; gap: 16px; margin-bottom: 8px; }
.landing .hero img { width: 64px; height: 64px; border-radius: 16px; }
.landing h1 { margin: 0; font-size: 32px; }
.landing .lead { font-size: 17px; color: var(--muted); margin: 8px 0 28px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 20px; margin-bottom: 16px; }
.card h2 { margin: 0 0 12px; font-size: 18px; }
.inline { display: flex; gap: 8px; flex-wrap: wrap; }
.inline input { flex: 1 1 220px; }
.mine a { display: flex; align-items: center; gap: 10px; padding: 10px 4px; text-decoration: none; color: var(--ink); border-bottom: 1px solid var(--line); }
.mine a:last-child { border-bottom: 0; }
.mine .dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.features { margin: 0; padding-left: 20px; color: var(--muted); }
.features li { margin: 4px 0; }

/* Shared event page */
.event-page { display: flex; justify-content: center; padding: 24px 12px 48px; min-height: 100%; }
.share-card { width: min(560px, 100%); display: flex; flex-direction: column; gap: 14px; height: max-content; }
.share-card h1 { margin: 0; font-size: 26px; overflow-wrap: anywhere; }
.share-card .when { margin: 0; font-size: 16px; }
.brand { display: inline-flex; align-items: center; gap: 8px; text-decoration: none; color: var(--muted); font-size: 14px; font-weight: 600; }
.brand img { border-radius: 7px; }
#details { display: flex; flex-direction: column; gap: 14px; }
.choice { display: flex; gap: 8px; flex-wrap: wrap; }
.choice button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); opacity: 0;
  background: #222; color: #fff; padding: 10px 16px; border-radius: 10px; transition: .2s; pointer-events: none; z-index: 100;
  max-width: calc(100vw - 32px);
}
#toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 640px) {
  .top { padding: 8px 10px; }
  .nav { padding: 8px 10px 0; }
  .nav h2 { font-size: 17px; flex-basis: 100%; order: -1; margin: 0 0 6px 2px; }
  .month { padding: 6px 4px 12px; }
  .cell { min-height: 64px; padding: 2px; }
  .cell .num { width: 22px; height: 22px; font-size: 12px; }
  .chip { font-size: 10px; line-height: 14px; padding: 0 3px; }
  .chip .t { display: none; }
  .chip.timed::before { display: none; }
  .chip.timed { background: color-mix(in srgb, var(--c) 22%, transparent); }
  .daylist, .agenda { padding-left: 10px; padding-right: 10px; }
  .row .time { width: 72px; }
  .top .wide { display: none; }
}
