/* Layout: phone-first single column (max 480px, centred on bigger screens); times set in mono like a world-clock board. */
:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --ink: #16202e;
  --muted: #5d6b7e;
  --line: #dde3eb;
  --accent: #2456d6;
  --accent-soft: #e4ecfd;
  --free: #1d8a5b;
  --free-soft: #def3e8;
  --night: #6b4fc4;
  --night-soft: #ece7fb;
  --danger: #b4372f;
  --shade: rgba(10, 16, 26, 0.45);
  --display: "Bricolage Grotesque", "Avenir Next", system-ui, sans-serif;
  --body: "Figtree", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141c; --surface: #18202c; --ink: #e8edf4; --muted: #96a3b5; --line: #2a3443;
    --accent: #7ea2ff; --accent-soft: #1f2d4d; --free: #4cc38e; --free-soft: #173528;
    --night: #a994f0; --night-soft: #2a2245; --danger: #f08a80; --shade: rgba(0, 0, 0, 0.6); color-scheme: dark;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; overflow-x: clip; }
body {
  background: var(--bg); color: var(--ink); font: 16px/1.5 var(--body);
  -webkit-text-size-adjust: 100%;
}
.wrap {
  max-width: 480px; margin: 0 auto;
  padding-block: 0 calc(48px + env(safe-area-inset-bottom, 0px));
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  display: grid; gap: 22px;
}
.wrap > header:first-child { padding-top: calc(24px + env(safe-area-inset-top, 0px)); }
h1, h2 { font-family: var(--display); margin: 0; text-wrap: balance; letter-spacing: -0.01em; }
h1 { font-size: 30px; line-height: 1.1; }
h2 { font-size: 20px; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.stack { display: grid; gap: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }

/* Sticky "who am I" bar */
.topbar {
  position: sticky; top: 0; z-index: 5;
  margin-left: calc(-1 * max(16px, env(safe-area-inset-left, 0px)));
  margin-right: calc(-1 * max(16px, env(safe-area-inset-right, 0px)));
  padding: calc(8px + env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) 8px max(16px, env(safe-area-inset-left, 0px));
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.topbar > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Controls: 48px tap targets, 16px text so phones don't zoom in */
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn {
  min-height: 48px; border: 0; border-radius: 12px; padding: 0 18px; font-weight: 600;
  background: var(--accent); color: #fff;
}
.btn.wide { width: 100%; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.ghost { background: transparent; color: var(--accent); padding: 0 10px; min-height: 44px; }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--line); }
input[type=text], input[type=search], input[type=password], input[type=date], input[type=time], select {
  width: 100%; min-height: 48px; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); font-size: 16px; -webkit-appearance: none; appearance: none;
}
select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 15px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 36px; }
.card, .panel { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 16px; }
.err { color: var(--danger); font-size: 14px; }
.err:empty { display: none; }
.yes { color: var(--free); font-weight: 600; }

/* Join */
.picker { border: 1px solid var(--line); border-radius: 12px; background: var(--surface); max-height: 280px; overflow-y: auto; overscroll-behavior: contain; }
.opt {
  display: flex; gap: 10px; align-items: center; width: 100%; min-height: 48px; text-align: left;
  border: 0; border-bottom: 1px solid var(--line); background: transparent; padding: 10px 14px;
}
.opt:last-child { border-bottom: 0; }
.opt.hl { background: var(--accent-soft); }
.opt.on { background: var(--accent); color: #fff; }
.opt.on .muted { color: rgba(255,255,255,0.85); }
.opt .grow { flex: 1; min-width: 0; }
.flag { font-size: 22px; line-height: 1; }

/* Times */
.slot { display: grid; gap: 10px; }
.slot.best { border-color: var(--free); box-shadow: 0 0 0 1px var(--free) inset; }
.when-day { font-weight: 600; }
.when-time { font-family: var(--mono); font-size: 28px; font-variant-numeric: tabular-nums; line-height: 1.15; }
.tick {
  width: 100%; min-height: 52px; border: 2px solid var(--line); background: var(--surface);
  border-radius: 14px; font-weight: 600; font-size: 17px;
}
.tick.on { background: var(--free); border-color: var(--free); color: #fff; }
.bar { height: 6px; border-radius: 99px; background: var(--line); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--free); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 13px; padding: 3px 10px; border-radius: 99px; background: var(--free-soft); color: var(--ink); }
.chip.night { background: var(--night-soft); }
.badge { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--free); color: #fff; }

/* People list */
.list { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
.person {
  display: flex; gap: 12px; align-items: center; width: 100%; min-height: 60px; text-align: left;
  background: transparent; border: 0; border-bottom: 1px solid var(--line); padding: 10px 14px;
}
.person:last-child { border-bottom: 0; }
.person .grow { flex: 1; min-width: 0; display: grid; }
.person .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Bottom sheet for one person */
.backdrop { position: fixed; inset: 0; background: var(--shade); z-index: 10; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 11;
  max-width: 480px; margin: 0 auto; max-height: 82vh; max-height: 82dvh; overflow-y: auto;
  background: var(--surface); border-radius: 20px 20px 0 0;
  padding: 18px max(16px, env(safe-area-inset-right, 0px)) calc(20px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
  display: grid; gap: 10px;
}
.trow { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.trow:last-child { border-bottom: 0; }

/* Organiser */
.linkbox { padding: 12px 14px; border-radius: 12px; background: var(--bg); border: 1px dashed var(--line); overflow-wrap: anywhere; font-size: 14px; user-select: all; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid2 > * { min-width: 0; }

@media (prefers-reduced-motion: no-preference) {
  .bar > i { transition: width .3s ease; }
  .sheet { animation: up .2s ease-out; }
  @keyframes up { from { transform: translateY(24px); opacity: .6; } }
}
input[type=date], input[type=time] { display: block; min-width: 0; max-width: 100%; }
a.person { color: inherit; text-decoration: none; }
.btn.quiet { background: var(--accent-soft); color: var(--accent); }
.preview { display: grid; gap: 6px; }
.preview .trow { padding: 8px 0; }

/* Date strip + time grid */
.datestrip { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scroll-snap-type: x proximity; overscroll-behavior-x: contain; }
.datechip {
  position: relative; flex: 0 0 60px; display: grid; justify-items: center; gap: 0; padding: 8px 4px;
  border: 1px solid var(--line); border-radius: 14px; background: var(--surface); scroll-snap-align: start; cursor: pointer; line-height: 1.25;
}
.datechip b { font-family: var(--display); font-size: 22px; }
.datechip .small { font-size: 12px; color: var(--muted); }
.datechip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.datechip.on .small { color: rgba(255,255,255,0.85); }
.datechip .dot { position: absolute; top: 6px; right: 6px; width: 7px; height: 7px; border-radius: 50%; background: var(--free); }
.hiddeninput { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; pointer-events: none; }
.timegrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.timechip { min-height: 46px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); font-size: 15px; }
.timechip.on { background: var(--free); border-color: var(--free); color: #fff; }
.timechip:disabled { opacity: 0.35; cursor: default; }
.seg { display: grid; grid-template-columns: repeat(5, 1fr); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--surface); }
.seg button { min-height: 44px; border: 0; border-right: 1px solid var(--line); background: transparent; font-weight: 600; }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--accent); color: #fff; }
.pin { font-size: 28px; letter-spacing: 0.5em; text-align: center; max-width: 220px; justify-self: center; }
.hero-card { background: var(--free-soft); border-color: var(--free); }
.gcal { display: grid; place-items: center; text-decoration: none; }

/* Organiser: who-voted-what grid + folded sections */
.vgrid { border-collapse: separate; border-spacing: 0; width: 100%; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; font-size: 14px; }
.vgrid th, .vgrid td { padding: 8px 6px; text-align: center; border-bottom: 1px solid var(--line); white-space: nowrap; }
.vgrid tr:last-child th, .vgrid tr:last-child td { border-bottom: 0; }
.vgrid thead th { font-weight: 600; font-size: 12px; vertical-align: bottom; }
.vgrid thead th .flag { display: block; font-size: 18px; }
.vgrid .vname { display: block; max-width: 64px; overflow: hidden; text-overflow: ellipsis; }
.vgrid tbody th { text-align: left; font-weight: 500; position: sticky; left: 0; background: var(--surface); }
.vgrid td.y { color: var(--free); font-weight: 700; font-size: 17px; }
.vgrid td.n { color: var(--line); }
.vgrid td.night { background: var(--night-soft); }
.vgrid tr.lead th, .vgrid tr.lead td:last-child { color: var(--free); }
.vgrid tr.fin th, .vgrid tr.fin td { background: var(--free-soft); }
.scroll-x { overflow-x: auto; }
.fold > summary { cursor: pointer; font-weight: 600; min-height: 28px; display: flex; align-items: center; justify-content: space-between; list-style: none; }
.fold > summary::-webkit-details-marker { display: none; }
.fold > summary::after { content: "+"; font-size: 22px; color: var(--muted); }
.fold[open] > summary::after { content: "–"; }
.mrow { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.mrow .btn { min-height: 40px; }
.vgrid td.me { padding: 4px; }
.vbtn { width: 40px; height: 40px; border-radius: 10px; border: 2px solid var(--line); background: var(--surface); color: #fff; font-size: 18px; font-weight: 700; }
.vbtn.on { background: var(--free); border-color: var(--free); }
/* Name icons */
.av { --h: 210; display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%;
  background: hsl(var(--h) 55% 45%); color: #fff; font-size: 11px; font-weight: 700; line-height: 1; flex: none; }
.vgrid thead th .av { width: 26px; height: 26px; font-size: 12px; margin-bottom: 2px; }
.vgrid .vname { font-size: 11px; }
.vgrid td.free { text-align: left; min-width: 64px; }
.avs { display: flex; flex-wrap: wrap; gap: 2px; margin-top: 3px; max-width: 96px; }
.avs .av { width: 18px; height: 18px; font-size: 10px; }
.voters { display: flex; flex-wrap: wrap; gap: 6px; }
.voter { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; padding: 2px 8px 2px 2px; border-radius: 99px; background: var(--bg); border: 1px solid var(--line); }
.voter.wait { opacity: 0.55; }

/* Invitee: dates fold open (Calendly-style), one row per time */
details.day { padding: 0; overflow: hidden; }
details.day > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 10px; padding: 14px 16px; min-height: 60px; }
details.day > summary::-webkit-details-marker { display: none; }
details.day > summary .grow { display: grid; flex: 1; min-width: 0; }
details.day > summary::after { content: ""; width: 9px; height: 9px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); margin: -4px 4px 0 0; transition: transform .15s; }
details.day[open] > summary::after { transform: rotate(-135deg); margin-top: 4px; }
.dayname { font-weight: 600; font-size: 17px; }
.slots { display: grid; gap: 10px; padding: 0 12px 12px; }
.srow { display: grid; gap: 8px; padding: 10px; border: 1px solid var(--line); border-radius: 14px; }
.srow.on { border-color: var(--free); background: var(--free-soft); }
.srow.fin { box-shadow: 0 0 0 2px var(--free) inset; }
.sbtn { display: flex; justify-content: space-between; align-items: center; gap: 10px; width: 100%; min-height: 52px; padding: 0 14px;
  border-radius: 12px; border: 2px solid var(--accent); background: var(--surface); color: var(--accent); }
.sbtn .stime { font-size: 18px; font-weight: 500; color: var(--ink); }
.sbtn .sstate { font-weight: 600; font-size: 14px; white-space: nowrap; }
.srow.on .sbtn { background: var(--free); border-color: var(--free); color: #fff; }
.srow.on .sbtn .stime { color: #fff; }
.sbtn:disabled { border-color: var(--line); color: var(--muted); cursor: default; }
.smeta { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.smeta .avs { margin: 0; max-width: none; justify-content: flex-end; }
.smeta .av, .voters .av { cursor: pointer; }
.smeta .av { width: 22px; height: 22px; font-size: 11px; }
.night-note { color: var(--night); }
.voter { cursor: pointer; }

/* Compact time rows: button + who's free on one line */
.slots { gap: 6px; padding: 0 10px 10px; }
.srow { grid-template-columns: auto 1fr; align-items: center; gap: 4px 10px; padding: 6px; border-radius: 12px; }
.sbtn { width: auto; min-height: 44px; padding: 0 12px; gap: 8px; border-width: 1.5px; border-radius: 10px; }
.sbtn .stime { font-size: 15px; }
.sbtn .sstate { font-size: 13px; }
.smeta { justify-content: flex-end; gap: 6px; flex-wrap: wrap; }
.smeta .small { font-size: 12px; }
.smeta .av { width: 20px; height: 20px; font-size: 10px; }
.night-note { grid-column: 1 / -1; font-size: 12px; }
details.day > summary { min-height: 52px; padding: 10px 14px; }
.dayname { font-size: 16px; }

/* Submit bar fixed to the bottom of the invitee page */
.submitbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 8;
  padding: 10px max(16px, env(safe-area-inset-right, 0px)) calc(10px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
  background: var(--surface); border-top: 1px solid var(--line); box-shadow: 0 -6px 18px rgba(0,0,0,0.06);
}
.submitbar > * { max-width: 448px; margin: 0 auto; }
.submitbar.sent { background: var(--free-soft); color: var(--ink); }
.submitbar.idle { color: var(--muted); text-align: center; }
.wrap:has(.submitbar) { padding-bottom: calc(110px + env(safe-area-inset-bottom, 0px)); }
.event-title { font-size: 36px; line-height: 1.05; }
.ask { font-size: 18px; font-family: var(--body); font-weight: 600; }
