:root {
  --bg: #F6F1E9;
  --surface: #FFFDF9;
  --surface-2: #F0E9DE;
  --line: #E4DACB;
  --ink: #26211C;
  --ink-2: #5F574C;
  --ink-3: #8D8478;
  --accent: #2E6B5E;
  --accent-ink: #FFFFFF;
  --accent-soft: #DDEBE6;
  --warm: #D9663A;
  --warm-soft: #FBE6DA;
  --good: #2F7D4F;
  --good-soft: #DFF0E4;
  --maybe: #A9741A;
  --maybe-soft: #F6EBD3;
  --bad: #B8433A;
  --bad-soft: #F7E0DD;
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 4px 16px rgba(60, 40, 20, .06);
  --radius: 18px;
  --radius-sm: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif,
          "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji";
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1A1714;
    --surface: #24201C;
    --surface-2: #2D2823;
    --line: #3B342D;
    --ink: #F2ECE3;
    --ink-2: #C7BEB1;
    --ink-3: #91887C;
    --accent: #72B8A6;
    --accent-ink: #10201C;
    --accent-soft: #23362F;
    --warm: #EE8C5E;
    --warm-soft: #3A2A21;
    --good: #7BC796;
    --good-soft: #21332A;
    --maybe: #E2B45E;
    --maybe-soft: #372E1E;
    --bad: #F0857A;
    --bad-soft: #3A2424;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #1A1714;
  --surface: #24201C;
  --surface-2: #2D2823;
  --line: #3B342D;
  --ink: #F2ECE3;
  --ink-2: #C7BEB1;
  --ink-3: #91887C;
  --accent: #72B8A6;
  --accent-ink: #10201C;
  --accent-soft: #23362F;
  --warm: #EE8C5E;
  --warm-soft: #3A2A21;
  --good: #7BC796;
  --good-soft: #21332A;
  --maybe: #E2B45E;
  --maybe-soft: #372E1E;
  --bad: #F0857A;
  --bad-soft: #3A2424;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.wrap { max-width: 760px; margin: 0 auto; padding: 0 16px 64px; }
.boot { height: 100vh; }

/* ---------- top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar .inner {
  max-width: 760px; margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; gap: 10px;
  padding-top: max(10px, env(safe-area-inset-top));
}
.brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 18px; color: var(--ink); text-decoration: none;
  min-width: 0;
}
.brand img { width: 30px; height: 30px; flex: none; }
.brand span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .spacer { flex: 1; }
.who-btn {
  display: flex; align-items: center; gap: 8px;
  border: 1px solid var(--line); background: var(--surface);
  border-radius: 999px; padding: 4px 12px 4px 4px; min-height: 40px;
  max-width: 50vw;
}
.who-btn .label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; font-size: 15px; }

.avatar {
  flex: none; width: 32px; height: 32px; border-radius: 50%;
  display: inline-grid; place-items: center;
  font-size: 13px; font-weight: 700; color: #fff;
  background: var(--accent);
}
.avatar.sm { width: 26px; height: 26px; font-size: 11px; }

/* ---------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 0 20px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); font-weight: 600; text-decoration: none; color: var(--ink);
  transition: transform .08s ease, background .15s ease;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: default; transform: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.warm { background: var(--warm); border-color: var(--warm); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { min-height: 36px; padding: 0 14px; font-size: 15px; }
.btn.block { width: 100%; }
.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px; flex: none;
  border: 0; border-radius: 50%; background: transparent; color: var(--ink-3); font-size: 18px;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }

/* ---------- cards & text */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px;
}
.card + .card, .section + .section { margin-top: 16px; }
.section { margin-top: 28px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 0 4px 10px; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-family: var(--serif); font-size: 32px; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 20px; }
h3 { font-size: 17px; }
.eyebrow { font-size: 13px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); }
.muted { color: var(--ink-2); }
.faint { color: var(--ink-3); font-size: 15px; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap-row { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 12px; }

/* ---------- forms */
.field { display: block; }
.field > .lbl { display: block; font-weight: 600; font-size: 15px; margin-bottom: 6px; }
.field .hint { display: block; font-size: 14px; color: var(--ink-3); margin-top: 4px; }
.input, textarea.input, select.input {
  width: 100%; min-height: 48px; padding: 10px 14px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); font-size: 17px;
}
textarea.input { min-height: 96px; resize: vertical; line-height: 1.4; }
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; font-weight: 500; cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }
.error { color: var(--bad); font-size: 15px; font-weight: 600; min-height: 1em; }

/* ---------- gate / welcome */
.gate { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.gate .card { width: 100%; max-width: 420px; padding: 28px 22px; text-align: center; }
.gate .logo { width: 64px; height: 64px; margin: 0 auto 14px; display: block; }
.gate h1 { font-size: 28px; margin-bottom: 6px; }
.gate form { text-align: left; margin-top: 22px; }
.gate .switch { margin-top: 18px; font-size: 15px; }
.linkish { background: none; border: 0; padding: 4px; color: var(--accent); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }

.names { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-top: 20px; text-align: left; }
.name-btn {
  display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 8px 12px;
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface);
  font-weight: 600; text-align: left;
}
.name-btn:hover { border-color: var(--accent); }
.name-btn span { overflow-wrap: anywhere; line-height: 1.2; }
.or { display: flex; align-items: center; gap: 12px; color: var(--ink-3); font-size: 14px; margin: 22px 0 12px; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* ---------- home */
.hello { margin: 26px 4px 4px; }
.hello h1 { font-size: 30px; }
.event-card {
  display: flex; gap: 16px; align-items: stretch;
  text-decoration: none; color: inherit;
  transition: transform .1s ease, border-color .15s ease;
}
.event-card:hover { border-color: var(--accent); }
.event-card:active { transform: scale(.99); }
.datetile {
  flex: none; width: 64px; border-radius: 14px; overflow: hidden; text-align: center;
  background: var(--surface-2); border: 1px solid var(--line); align-self: flex-start;
}
.datetile .m { background: var(--warm); color: #fff; font-size: 12px; font-weight: 800; letter-spacing: .1em; padding: 3px 0; }
.datetile .d { font-family: var(--serif); font-size: 28px; font-weight: 700; line-height: 1.1; padding-top: 4px; }
.datetile .w { font-size: 12px; font-weight: 700; color: var(--ink-3); padding-bottom: 6px; text-transform: uppercase; }
.event-card .body { min-width: 0; flex: 1; }
.event-card h2 { font-family: var(--serif); font-size: 21px; margin-bottom: 2px; overflow-wrap: anywhere; }
.event-card .meta { color: var(--ink-2); font-size: 15px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 999px; font-size: 14px; font-weight: 600;
  background: var(--surface-2); color: var(--ink-2); max-width: 100%;
}
.chip.open { background: var(--warm-soft); color: var(--warm); }
.chip.full, .chip.yes { background: var(--good-soft); color: var(--good); }
.chip.maybe { background: var(--maybe-soft); color: var(--maybe); }
.chip.no { background: var(--bad-soft); color: var(--bad); }
.chip.mine { background: var(--accent-soft); color: var(--accent); }
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.past summary { cursor: pointer; font-weight: 600; color: var(--ink-2); padding: 8px 4px; list-style: none; }
.past summary::-webkit-details-marker { display: none; }
.past summary::before { content: "▸ "; }
.past[open] summary::before { content: "▾ "; }
.past .event-card { opacity: .78; }
.empty { text-align: center; padding: 36px 20px; }
.empty .big { font-size: 44px; }

/* ---------- event page */
.back { display: inline-flex; align-items: center; gap: 6px; margin: 16px 0 4px; color: var(--ink-2); text-decoration: none; font-weight: 600; font-size: 15px; padding: 6px 2px; }
.hero { padding: 22px 20px; }
.hero h1 { overflow-wrap: anywhere; }
.facts { margin-top: 14px; display: grid; gap: 10px; }
.fact { display: flex; gap: 12px; align-items: flex-start; }
.fact .ico { flex: none; width: 24px; text-align: center; font-size: 18px; line-height: 1.4; }
.fact .t { min-width: 0; overflow-wrap: anywhere; }
.hero .actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.desc { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }

.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.seg button {
  min-height: 52px; border-radius: var(--radius-sm); border: 1.5px solid var(--line);
  background: var(--surface); font-weight: 700; font-size: 15px; padding: 4px;
}
.seg button.on.yes { background: var(--good-soft); border-color: var(--good); color: var(--good); }
.seg button.on.maybe { background: var(--maybe-soft); border-color: var(--maybe); color: var(--maybe); }
.seg button.on.no { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }

.stepper { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 52px; }
.stepper .ctrl { display: flex; align-items: center; gap: 4px; }
.stepper button {
  width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--surface); font-size: 22px; font-weight: 600; line-height: 1;
}
.stepper output { min-width: 36px; text-align: center; font-size: 20px; font-weight: 700; }

.headcount { display: flex; flex-wrap: wrap; gap: 8px 18px; margin-top: 4px; }
.headcount b { font-size: 22px; }
.people { margin-top: 10px; }
.person { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.person:first-child { border-top: 0; }
.person .grow .faint { font-size: 14px; }

.slot { padding: 16px 0; border-top: 1px solid var(--line); }
.slot:first-of-type { border-top: 0; padding-top: 4px; }
.slot-head { display: flex; align-items: flex-start; gap: 12px; }
.slot-head .grow h3 { overflow-wrap: anywhere; }
.count { flex: none; font-weight: 700; font-size: 15px; color: var(--ink-2); padding-top: 2px; }
.bar { height: 6px; border-radius: 6px; background: var(--surface-2); margin: 8px 0 2px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--warm); border-radius: 6px; }
.bar.done i { background: var(--good); }
.claims { margin-top: 8px; }
.claim { display: flex; align-items: center; gap: 10px; padding: 6px 0; }
.claim .grow { font-size: 16px; }
.claim .what { color: var(--ink-2); }
.claim.mine .who { color: var(--accent); }
.slot .act { margin-top: 10px; display: flex; gap: 8px; flex-wrap: wrap; }

.comment { display: flex; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.comment:first-child { border-top: 0; padding-top: 0; }
.comment .head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.comment .head b { font-size: 15px; }
.comment-form { margin-top: 14px; display: grid; gap: 10px; }
.comment-form textarea { min-height: 70px; }

/* ---------- editor */
.slot-edit {
  border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px;
  background: var(--bg); display: grid; gap: 10px;
}
.slot-edit + .slot-edit { margin-top: 10px; }
.slot-edit .top { display: flex; gap: 8px; align-items: center; }
.slot-edit .mid { display: grid; grid-template-columns: 110px 1fr; gap: 10px; align-items: center; }
.slot-edit .tools { display: flex; gap: 2px; }
.presets { display: flex; flex-wrap: wrap; gap: 8px; }
.sticky-save {
  position: sticky; bottom: 0; margin: 20px -16px 0; padding: 12px 16px max(12px, env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-end;
}

/* ---------- admin */
.list-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.list-row:first-child { border-top: 0; }
.list-row .grow b { overflow-wrap: anywhere; }
.copybox { display: flex; gap: 8px; margin-top: 10px; }
.copybox input { font-size: 14px; }

/* ---------- sheet (modal) */
dialog.sheet {
  border: 0; padding: 0; width: min(520px, 100%); max-height: 92vh;
  border-radius: 22px; background: var(--surface); color: var(--ink);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
dialog.sheet::backdrop { background: rgba(20, 15, 10, .45); }
dialog.sheet .sheet-in { padding: 22px 20px max(20px, env(safe-area-inset-bottom)); overflow-y: auto; max-height: 92vh; }
dialog.sheet h2 { font-family: var(--serif); font-size: 24px; margin-bottom: 4px; padding-right: 36px; overflow-wrap: anywhere; }
dialog.sheet .close { position: absolute; top: 14px; right: 14px; }
dialog.sheet .foot { display: flex; gap: 10px; margin-top: 20px; flex-wrap: wrap; }
dialog.sheet .foot .btn { flex: 1; }
.menu-list { display: grid; gap: 4px; margin-top: 12px; }
.menu-list button, .menu-list a {
  display: flex; align-items: center; gap: 12px; text-align: left; width: 100%;
  min-height: 52px; padding: 0 12px; border: 0; border-radius: var(--radius-sm);
  background: transparent; font-weight: 600; color: var(--ink); text-decoration: none;
}
.menu-list button:hover, .menu-list a:hover { background: var(--surface-2); }
.menu-list .ico { width: 24px; text-align: center; }
.taken-list { margin-top: 6px; font-size: 15px; color: var(--ink-2); }

@media (max-width: 560px) {
  dialog.sheet { margin: auto 0 0; width: 100%; max-width: 100%; border-radius: 22px 22px 0 0; }
  h1 { font-size: 28px; }
  .two { grid-template-columns: 1fr; }
}

#toast {
  position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 100; max-width: calc(100% - 32px);
  background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 14px;
  font-weight: 600; box-shadow: 0 8px 30px rgba(0, 0, 0, .25);
}
#toast.bad { background: var(--bad); color: #fff; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ---------- per-event invite box (organizers) */
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, Menlo, monospace; }
.invite { border-color: var(--accent); background: linear-gradient(var(--accent-soft), var(--accent-soft)) top / 100% 4px no-repeat, var(--surface); }
.kv { display: flex; gap: 12px; align-items: baseline; padding: 6px 0; }
.kv .k { flex: none; width: 96px; font-size: 14px; font-weight: 700; color: var(--ink-3); text-transform: uppercase; letter-spacing: .05em; }
.kv .v { min-width: 0; overflow-wrap: anywhere; font-size: 16px; }
.avatar.ghost { background: var(--surface-2); color: var(--ink-2); font-size: 15px; }

/* ---------- light/dark toggle */
.theme-btn {
  display: inline-grid; place-items: center; flex: none; width: 40px; height: 40px;
  border: 1px solid var(--line); border-radius: 50%; background: var(--surface);
  font-size: 18px; line-height: 1;
}
.theme-btn:active { transform: scale(.94); }
.gate .card { position: relative; }
.theme-btn.corner { position: absolute; top: 12px; right: 12px; }
.btn { white-space: nowrap; }
@media (max-width: 420px) {
  .topbar .inner { gap: 6px; }
  .who-btn { max-width: 38vw; }
}
