:root {
  color-scheme: dark;
  --bg: #14100d;
  --surface: #211a14;
  --surface-2: #2c231b;
  --line: #3a2f25;
  --text: #f5ecdc;
  --muted: #a99884;
  --accent: #e8a13a;
  --danger: #ef6a5b;
  --ok: #7bc47f;
  --radius: 12px;
  --display: "Bebas Neue", "Arial Narrow", Impact, sans-serif;

  --stage-1: #e8a13a;
  --stage-2: #e1704f;
  --stage-3: #b58ce6;
  --stage-4: #4fc4b0;
  --stage-5: #93c25b;
  --stage-6: #5fa8e8;
}

/* People (compare view): one color each, by sign-up order */
:root {
  --p-1: #ff8f6b;
  --p-2: #f5c451;
  --p-3: #7fd58f;
  --p-4: #4fd0e0;
  --p-5: #7aa2ff;
  --p-6: #c39bff;
  --p-7: #ff86c1;
  --p-8: #c4ccd6;
}
.person-1 { --c: var(--p-1); }
.person-2 { --c: var(--p-2); }
.person-3 { --c: var(--p-3); }
.person-4 { --c: var(--p-4); }
.person-5 { --c: var(--p-5); }
.person-6 { --c: var(--p-6); }
.person-7 { --c: var(--p-7); }
.person-8 { --c: var(--p-8); }

.stage-1 { --c: var(--stage-1); }
.stage-2 { --c: var(--stage-2); }
.stage-3 { --c: var(--stage-3); }
.stage-4 { --c: var(--stage-4); }
.stage-5 { --c: var(--stage-5); }
.stage-6 { --c: var(--stage-6); }

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

#app { display: flex; flex-direction: column; height: 100dvh; max-width: 1200px; margin: 0 auto; }
#main { flex: 1; min-height: 0; overflow: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }

/* ── Top bar ─────────────────────────────────────────────────────────── */
.topbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(6px + env(safe-area-inset-top)) 12px 6px;
  border-bottom: 1px solid var(--line);
  min-height: 52px;
}
.home {
  display: grid; place-items: center;
  width: 36px; height: 44px; margin-left: -8px;
  font-size: 2rem; line-height: 1; color: var(--muted); text-decoration: none;
}
.brand { font-family: var(--display); font-size: 1.7rem; letter-spacing: .05em; line-height: 1; flex: 1; white-space: nowrap; }
.brand em, .welcome h1 em { color: var(--accent); font-style: normal; }
.who {
  max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  min-height: 44px; padding: 0 14px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; font-size: .9rem;
}
.sync { display: inline-flex; align-items: center; gap: 6px; font-size: .75rem; color: var(--muted); }
.sync::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--ok); }
.sync::after { content: attr(data-label); }
.sync[data-status="pending"]::before { background: var(--accent); animation: pulse 1s infinite; }
.sync[data-status="offline"]::before { background: var(--danger); }
@keyframes pulse { 50% { opacity: .3; } }

/* ── Day bar ─────────────────────────────────────────────────────────── */
.daybar { flex: none; padding: 6px 12px 4px; border-bottom: 1px solid var(--line); display: grid; gap: 6px; }
.days { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.day {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 42px; padding: 3px 2px; line-height: 1.1;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
}
.day-name { font-family: var(--display); font-size: 1.15rem; letter-spacing: .05em; }
.day-date { font-size: .7rem; color: var(--muted); }
.day.active { background: var(--accent); border-color: var(--accent); color: #1a120b; }
.day.active .day-date { color: rgba(26, 18, 11, .75); }
.day-count {
  position: absolute; top: -6px; right: -4px; min-width: 20px; height: 20px; padding: 0 5px;
  display: grid; place-items: center; font-size: .7rem; font-weight: 800;
  background: var(--text); color: #1a120b; border-radius: 999px; border: 2px solid var(--bg);
}
.bar-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.bar-row .link-btn { padding: 0; }
.bar-title { font-family: var(--display); font-size: 1.45rem; letter-spacing: .04em; line-height: 1.1; }

.pchips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 1px 4px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.pchips::-webkit-scrollbar { display: none; }
.pchip {
  flex: none; display: inline-flex; align-items: center; gap: 8px; min-height: 38px; padding: 0 13px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
  font-size: .88rem; font-weight: 600; color: var(--muted);
}
.pchip .swatch { display: grid; place-items: center; width: 14px; height: 14px; border-radius: 50%; background: var(--c); font-size: .6rem; font-weight: 900; color: #1a120b; }
.pchip.on { background: var(--c); border-color: var(--c); color: #1a120b; }
.pchip.on .swatch { background: rgba(26, 18, 11, .85); color: var(--c); }
.pchip.on .swatch::after { content: "✓"; }
.pchip.all { border-style: dashed; color: var(--accent); }

.view-toggle { display: grid; grid-template-columns: 1fr 1fr; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.view-toggle button { min-height: 32px; border: 0; border-radius: 8px; background: transparent; font-size: .85rem; color: var(--muted); }
.view-toggle button.active { background: var(--surface-2); color: var(--text); font-weight: 700; }

/* ── Tab bar ─────────────────────────────────────────────────────────── */
.tabbar { flex: none; display: flex; border-top: 1px solid var(--line); background: var(--surface); padding-bottom: env(safe-area-inset-bottom); }
.tab { position: relative; flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 58px; border: 0; background: transparent; color: var(--muted); }
.tab-icon { font-size: 1.25rem; line-height: 1; }
.tab-label { font-size: .72rem; }
.tab.active { color: var(--accent); font-weight: 700; }
.tab-count {
  position: absolute; top: 6px; left: calc(50% + 8px); min-width: 18px; height: 18px; padding: 0 5px;
  display: grid; place-items: center; font-size: .68rem; font-weight: 800;
  background: var(--accent); color: #1a120b; border-radius: 999px;
}

/* ── Welcome ─────────────────────────────────────────────────────────── */
.welcome { max-width: 460px; margin: 0 auto; padding: 36px 20px 40px; }
.eyebrow { margin: 0 0 6px; font-size: .8rem; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); }
.welcome h1 { margin: 0 0 12px; font-family: var(--display); font-size: clamp(3.2rem, 15vw, 4.6rem); line-height: .95; letter-spacing: .03em; font-weight: 400; }
.lede { margin: 0 0 28px; color: var(--muted); font-size: 1.02rem; }
.name-form label { display: block; margin-bottom: 6px; font-size: .85rem; color: var(--muted); }
.name-row { display: flex; gap: 8px; }
.name-row input {
  flex: 1; min-width: 0; min-height: 50px; padding: 0 14px; font-size: 1.05rem;
  background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius);
}
.name-row input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.hint { margin: 28px 0 10px; color: var(--muted); font-size: .9rem; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: baseline; gap: 8px; min-height: 44px; padding: 0 16px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; font-weight: 600;
}
.chip span { font-size: .75rem; font-weight: 400; color: var(--muted); }

/* ── Buttons ─────────────────────────────────────────────────────────── */
.btn { min-height: 50px; padding: 0 20px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface-2); font-weight: 700; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #1a120b; }
.btn.ghost { min-height: 44px; padding: 0 14px; font-size: .85rem; white-space: nowrap; }
.link-btn { background: none; border: 0; padding: 10px 0; min-height: 44px; color: var(--accent); text-decoration: underline; text-underline-offset: 3px; font-size: .9rem; }
.link-btn.danger { color: var(--danger); }
.icon-btn { flex: none; width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--surface-2); color: var(--muted); font-size: 1rem; }
.mini-btn { flex: none; min-height: 44px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--accent); background: transparent; color: var(--accent); font-size: .85rem; font-weight: 700; }
.mini-btn.on { background: var(--accent); color: #1a120b; }

/* ── Timeline grid ───────────────────────────────────────────────────── */
.grid {
  display: grid;
  grid-template-columns: var(--tpl);
  grid-template-rows: auto var(--h);
  min-width: var(--minw);
}
.g-corner, .g-head { position: sticky; top: 0; z-index: 4; background: var(--bg); }
.g-corner { left: 0; z-index: 6; }
.g-head {
  display: grid; place-items: center; min-height: 40px; padding: 4px 6px;
  border-bottom: 3px solid var(--c); border-left: 1px solid var(--line);
  font-family: var(--display); font-size: 1.05rem; letter-spacing: .05em; line-height: 1.05; text-align: center;
}
.g-head small { display: block; margin-top: 1px; font-family: system-ui, sans-serif; font-size: .66rem; letter-spacing: 0; color: var(--muted); }
.g-times { position: sticky; left: 0; z-index: 3; background: var(--bg); }
.g-times span { position: absolute; right: 6px; margin-top: 3px; font-size: .68rem; color: var(--muted); white-space: nowrap; }
.g-col {
  position: relative;
  border-left: 1px solid var(--line);
  background-image: linear-gradient(to bottom, transparent calc(var(--hour) - 1px), var(--line) calc(var(--hour) - 1px));
  background-size: 100% var(--hour);
}

/* ── A set (shared by timeline blocks and stage-list rows) ───────────── */
.set {
  position: relative; display: block; width: 100%; margin: 0; text-align: left; overflow: hidden;
  background: var(--surface-2); border: 0; border-left: 4px solid var(--c); border-radius: 8px;
  color: var(--text); transition: background-color .12s;
}
.set-flags { position: absolute; right: 4px; bottom: 3px; display: flex; gap: 4px; font-size: .68rem; line-height: 1; }
.badge-going { padding: 2px 5px; border-radius: 999px; background: rgba(0, 0, 0, .35); color: var(--text); font-weight: 700; }
.badge-warn { padding: 1px 3px; color: var(--danger); font-weight: 900; font-size: .8rem; }
.set-check { position: absolute; top: 3px; right: 6px; font-weight: 900; opacity: 0; }
.set.picked { background: var(--c); color: #1a120b; }
.set.picked .badge-going { background: rgba(26, 18, 11, .25); color: #1a120b; }
.set.picked .badge-warn { color: #7a1208; }
.set.picked .set-check { opacity: 1; }
.set.conflict { box-shadow: inset 0 0 0 2px var(--danger); }

.g-col .set, .g-col .pblock { position: absolute; left: 3px; width: calc(100% - 6px); padding: 3px 22px 3px 7px; }

/* Read-only block: someone else's set, or a set in a person's compare column */
.g-col .pblock { padding-right: 5px; }
.pblock { display: block; overflow: hidden; background: var(--c); color: #1a120b; border-left: 4px solid rgba(26, 18, 11, .28); border-radius: 8px; }
.pblock .set-title { padding-right: var(--fp, 0px); }
.pblock .set-time { color: rgba(26, 18, 11, .78); overflow: hidden; text-overflow: ellipsis; }
/* badges sit in the top-right corner; the title reserves room via --fp */
.pblock .flags { position: absolute; top: 3px; right: 4px; display: flex; align-items: center; gap: 3px; font-size: .68rem; line-height: 1; }
.pblock .badge-going { background: rgba(26, 18, 11, .25); color: #1a120b; }
.pblock .badge-warn { color: #6b0d04; }
.pblock.conflict { box-shadow: inset 0 0 0 2px #5a0f07; }
.set-title { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font-weight: 700; font-size: .8rem; line-height: 1.15; }
.set-time { display: block; margin-top: 1px; font-size: .68rem; color: var(--muted); white-space: nowrap; }
.set.picked .set-time { color: rgba(26, 18, 11, .78); }
.set.short .set-title { font-size: .76rem; }

/* ── By-stage list ───────────────────────────────────────────────────── */
.stage-list { padding: 4px 12px 24px; }
.stage-sec h2 {
  display: flex; align-items: center; gap: 8px; margin: 18px 0 8px;
  font-family: var(--display); font-weight: 400; font-size: 1.4rem; letter-spacing: .05em; color: var(--c);
}
.stage-sec ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.set.row { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 8px 64px 8px 12px; }
.row-time { flex: none; width: 9.6em; font-size: .78rem; color: var(--muted); white-space: nowrap; }
.set.picked .row-time { color: rgba(26, 18, 11, .78); }
.row-title { flex: 1; min-width: 0; font-weight: 700; }
.set.row .set-check { top: 50%; transform: translateY(-50%); right: 12px; font-size: 1.1rem; }
.set.row .set-flags { bottom: 50%; transform: translateY(50%); right: 34px; }

.dot { flex: none; width: 9px; height: 9px; border-radius: 50%; background: var(--c); }

/* ── My schedule / Group ─────────────────────────────────────────────── */
.mine, .group { padding: 16px 12px 28px; max-width: 640px; margin: 0 auto; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.page-head h1 { margin: 0; font-family: var(--display); font-weight: 400; font-size: 2rem; letter-spacing: .04em; line-height: 1.05; }
.muted { margin: 2px 0 0; color: var(--muted); font-size: .9rem; }
.plan-day { margin-top: 22px; }
.plan-day h2, .section-title { margin: 0 0 10px; font-family: var(--display); font-weight: 400; font-size: 1.35rem; letter-spacing: .05em; color: var(--accent); }
.plan-day h2 span { margin-left: 6px; font-size: 1rem; color: var(--muted); }
.section-title { margin-top: 28px; }
.empty-day { margin: 0; color: var(--muted); font-size: .9rem; }
.empty { margin: 24px 0; padding: 24px 16px; text-align: center; background: var(--surface); border-radius: var(--radius); }
.empty p { margin: 0 0 14px; color: var(--muted); }
.empty.pad { max-width: 460px; margin: 24px auto; }

.card {
  display: flex; align-items: center; gap: 12px; padding: 12px;
  background: var(--surface); border-radius: var(--radius); border-left: 5px solid var(--c);
}
.card-time { flex: none; width: 78px; }
.card-time strong { display: block; font-size: .98rem; }
.card-time span { font-size: .74rem; color: var(--muted); }
.card-main { flex: 1; min-width: 0; }
.card-main h3 { margin: 0; font-size: 1.02rem; line-height: 1.2; }
.stage-pill { display: flex; align-items: center; gap: 6px; margin: 3px 0 0; font-size: .82rem; color: var(--muted); }
.going { margin: 4px 0 0; font-size: .82rem; color: var(--accent); }

.link { display: flex; flex-direction: column; gap: 2px; margin: 6px 0 6px 18px; padding: 8px 12px; border-radius: 10px; font-size: .82rem; line-height: 1.35; }
.link.overlap.slight { background: rgba(232, 161, 58, .13); border: 1px solid #b98328; color: #f3d38a; }
.link.overlap.heavy { background: rgba(239, 106, 91, .13); border: 1px solid var(--danger); color: #f7aca2; }
.link.tight { background: rgba(95, 168, 232, .11); border: 1px solid #3f78ad; color: #b5d6f5; }
.link.gap { margin: 2px 0 2px 18px; padding: 2px 12px; color: var(--muted); font-size: .76rem; }

.people, .together-list { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 8px; }
.person { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 56px; padding: 8px 14px; text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.avatar { flex: none; width: 36px; height: 36px; display: grid; place-items: center; border-radius: 50%; background: var(--accent); color: #1a120b; font-weight: 800; }
.person-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; font-weight: 700; }
.person-name em { font-weight: 400; font-style: normal; color: var(--muted); }
.person-count { font-size: .82rem; color: var(--muted); }
.chev { color: var(--muted); font-size: 1.4rem; }
.together { display: flex; align-items: center; gap: 12px; padding: 12px; background: var(--surface); border-radius: var(--radius); border-left: 5px solid var(--c); }
.account { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; margin-top: 32px; padding-top: 12px; border-top: 1px solid var(--line); }

/* ── Toast ───────────────────────────────────────────────────────────── */
.toast {
  position: fixed; left: 50%; bottom: calc(76px + env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: 12px; max-width: min(92vw, 460px);
  padding: 10px 16px; border-radius: 12px; font-size: .9rem;
  background: #efe3cf; color: #1a120b; box-shadow: 0 6px 24px rgba(0, 0, 0, .5);
  transform: translate(-50%, 12px); opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s; z-index: 20;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast.warn { background: #f3c96b; }
.toast button { flex: none; min-height: 36px; padding: 0 10px; border: 0; background: transparent; color: #1a120b; font-weight: 800; text-decoration: underline; }

@media (min-width: 700px) {
  .view-toggle { max-width: 360px; }
  .pchips { flex-wrap: wrap; overflow: visible; }
}

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