/* ---------- theme ---------- */
:root {
  --bg: #f4f5fb;
  --surface: #ffffff;
  --surface-2: #f0f1f8;
  --text: #1c1d27;
  --muted: #6b6e80;
  --line: #e3e4ee;
  --accent: #6d5dfc;
  --accent-ink: #ffffff;
  --yes: #1faa59;
  --maybe: #e0a000;
  --no: #e0533d;
  --none: #c3c6d4;
  --shadow: 0 1px 3px rgba(20, 22, 40, .08), 0 6px 18px rgba(20, 22, 40, .06);
  --radius: 16px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14151c;
    --surface: #1d1f29;
    --surface-2: #262936;
    --text: #ecedf4;
    --muted: #9a9daf;
    --line: #2c2f3d;
    --accent: #8b7dff;
    --none: #4a4d5e;
    --shadow: 0 1px 3px rgba(0,0,0,.4), 0 6px 18px rgba(0,0,0,.3);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; font-weight: 700; }
button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input { font: inherit; }
.muted { color: var(--muted); }
.error { color: var(--no); font-size: .9rem; }
[hidden] { display: none !important; }

/* ---------- gate ---------- */
.gate {
  min-height: 100dvh; display: grid; place-items: center; padding: 24px;
}
.gate-card {
  background: var(--surface); border-radius: 24px; box-shadow: var(--shadow);
  padding: 32px 24px; width: 100%; max-width: 360px; text-align: center;
}
.gate-card .logo { font-size: 44px; }
.gate-card h1 { margin: 6px 0 18px; font-size: 1.6rem; }
.gate-card .muted { margin: 0 0 14px; }
#email-input, #password-input {
  width: 100%; padding: 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--text); margin-bottom: 12px; text-align: center;
}
#login-msg, #login-error { margin: 14px 0 0; }
.btn-link { display: inline-block; margin-top: 14px; color: var(--accent);
  font-weight: 600; font-size: .9rem; background: none; }
.who-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.who-buttons button {
  padding: 18px 10px; border-radius: 14px; background: var(--surface-2);
  border: 1px solid var(--line); font-size: 1.05rem; font-weight: 600;
  transition: transform .08s ease, background .15s ease;
}
.who-buttons button:active { transform: scale(.97); background: var(--accent); color: var(--accent-ink); }

/* ---------- buttons ---------- */
.btn {
  padding: 12px 16px; border-radius: 12px; font-weight: 600;
  background: var(--surface-2); border: 1px solid var(--line);
  transition: transform .08s ease;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.block { width: 100%; }
.btn.small { padding: 8px 12px; font-size: .9rem; border-radius: 10px; }
.btn.danger { color: var(--no); }

/* ---------- app shell ---------- */
.app-header {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding-top: max(14px, env(safe-area-inset-top));
}
.brand { font-weight: 800; font-size: 1rem; letter-spacing: -.01em;
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip-wrap { position: relative; flex: none; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface-2); border: 1px solid var(--line); font-size: 1.25rem; color: var(--text); }
.icon-btn:active { transform: scale(.95); }
.menu { position: absolute; right: 0; top: calc(100% + 6px); z-index: 20;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); overflow: hidden; min-width: 160px; }
.menu-header { padding: 11px 14px; font-size: .8rem; color: var(--muted);
  border-bottom: 1px solid var(--line); }
.menu button { display: block; width: 100%; text-align: left; padding: 12px 14px;
  font-size: .92rem; font-weight: 600; }
.menu button:active { background: var(--surface-2); }
.menu button + button { border-top: 1px solid var(--line); }
.user-chip {
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px;
  padding: 7px 14px; font-weight: 600; font-size: .9rem;
}
.view { padding: 16px 16px 96px; max-width: 640px; margin: 0 auto; }

/* ---------- tab bar ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: flex; background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: var(--safe-bottom);
}
.tab {
  position: relative;
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 10px 0 8px; font-size: .72rem; font-weight: 600; color: var(--muted);
}
.tab-badge { position: absolute; top: 3px; left: calc(50% + 7px);
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px;
  font-size: .68rem; font-weight: 800; color: #fff; line-height: 1;
  display: inline-grid; place-items: center; }
.tab-badge.red { background: var(--no); }
.tab-badge.orange { background: var(--maybe); }
.tab-badge.green { background: var(--yes); }
.tab .tab-ico { font-size: 1.25rem; filter: grayscale(.3); }
.tab.active { color: var(--accent); }
.tab.active .tab-ico { filter: none; }

/* ---------- section headers ---------- */
.section-title { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); margin: 4px 2px 10px; }
.plan-title { text-align: center; font-size: 1.2rem; font-weight: 800;
  margin: 6px 8px 20px; }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.empty .big { font-size: 32px; display: block; margin-bottom: 8px; }

/* ---------- date card (Plan) ---------- */
.date-card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  margin-bottom: 14px; overflow: hidden; border: 1px solid var(--line);
}
.date-card.booked { outline: 2px solid var(--yes); }
.date-head {
  display: flex; align-items: baseline; gap: 8px; padding: 14px 16px 6px;
}
.date-head .dow { font-weight: 800; font-size: 1.4rem; }
.date-head .dnum { color: var(--muted); font-size: 1.15rem; }
.badge { font-size: .68rem; font-weight: 700; padding: 2px 7px; border-radius: 999px;
  background: var(--accent); color: var(--accent-ink); }
.badge.bh { background: #d98324; }
.badge.booked { background: var(--yes); }

.slot-row { padding: 8px 16px 14px; }
.slot-row + .slot-row { border-top: 1px solid var(--line); }
.slot-row.dead { padding: 0; }
.slot-row.expanded-dead { opacity: .9; }
.slot-toggle { display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 13px 16px; text-align: left; color: var(--muted); }
.slot-toggle:active { background: var(--surface-2); }
.slot-toggle .arrow { font-size: .72rem; flex: none; }
.slot-toggle .slot-name { width: auto; color: var(--muted); }
.slot-toggle .count { margin-left: auto; }
.slot-toggle.inline { width: auto; padding: 0; flex: none; }
.strike { text-decoration: line-through; }
.slot-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.slot-name { font-weight: 700; flex: none; white-space: nowrap; }
.slot-name .icn { margin-right: 5px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.slot-head .book, .slot-head .booked-tag { margin-left: auto; }
.booked-tag { color: var(--yes); font-weight: 700; font-size: .85rem; }
.chip {
  min-width: 34px; height: 32px; border-radius: 999px; padding: 0 9px;
  display: inline-flex; align-items: center; justify-content: center; gap: 3px;
  font-size: .82rem; font-weight: 700; border: 2px solid var(--none); color: var(--muted);
  background: var(--surface-2);
}
.chip-sym { font-size: .8rem; font-weight: 800; }
.chip.yes { background: var(--yes); border-color: var(--yes); color: #fff; }
.chip.maybe { background: var(--maybe); border-color: var(--maybe); color: #fff; }
.chip.no { background: var(--no); border-color: var(--no); color: #fff; }

.notes { margin-top: 10px; display: flex; flex-direction: column; gap: 5px; }
.note-line { font-size: .82rem; color: var(--muted); background: var(--surface-2);
  padding: 6px 10px; border-radius: 9px; }
.note-line b { color: var(--text); font-weight: 700; }
.note-input { width: 100%; margin-top: 8px; padding: 9px 11px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text); font-size: .88rem; }
.note-input::placeholder { color: var(--muted); }

.set-label { font-size: .7rem; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); margin: 14px 0 7px; font-weight: 700; }
.set-buttons { display: flex; gap: 8px; }
.set {
  flex: 1; padding: 10px 6px; border-radius: 11px; font-weight: 700; font-size: .85rem;
  background: var(--surface-2); border: 1.5px solid var(--line); color: var(--muted);
  transition: transform .08s ease, background .12s ease, color .12s ease;
}
.set:active { transform: scale(.95); }
.set.yes.active { background: var(--yes); border-color: var(--yes); color: #fff; }
.set.maybe.active { background: var(--maybe); border-color: var(--maybe); color: #fff; }
.set.no.active { background: var(--no); border-color: var(--no); color: #fff; }

/* Subtle until enough people can play, prominent once it's worth booking */
.btn.book.subtle { background: transparent; border: none; color: var(--muted);
  font-weight: 600; font-size: .82rem; padding: 6px 2px; }
.btn.book.ready { background: var(--accent); color: var(--accent-ink); border: none;
  font-weight: 700; font-size: .85rem; padding: 8px 13px; border-radius: 10px;
  box-shadow: 0 3px 10px rgba(109, 93, 252, .3); }

/* Collapsed summary of my own answer (status already shows in the chip above) */
.my-answer { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 8px; margin-top: 10px; }
.my-note { flex-basis: 100%; font-size: .85rem; color: var(--muted); font-style: italic; }
.my-answer .edit { margin-left: auto; margin-top: 0; }
.btn-link.done { margin-top: 12px; }
.count { font-size: .82rem; color: var(--muted); }
.count b { color: var(--yes); }
.count .ready { color: var(--yes); font-weight: 700; }

/* ---------- event card (Booked / History) ---------- */
.event-card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  border: 1px solid var(--line); padding: 16px; margin-bottom: 14px;
}
.event-card .when { font-weight: 800; font-size: 1.1rem; }
.event-card .sub { color: var(--muted); font-size: .9rem; margin-top: 2px; }
.field { margin-top: 14px; }
.field label { display: block; font-size: .72rem; text-transform: uppercase;
  letter-spacing: .05em; color: var(--muted); margin-bottom: 6px; }
.field input, .field select {
  width: 100%; padding: 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--text);
}
.game-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.game-chips button {
  padding: 9px 13px; border-radius: 999px; background: var(--surface-2);
  border: 1px solid var(--line); font-weight: 600; font-size: .9rem;
}
.game-chips button.sel { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.event-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.event-card .game-tag { display: inline-block; margin-top: 8px; padding: 4px 12px;
  border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: .85rem; }
.event-card.past { opacity: .92; }

/* ---------- admin ---------- */
.admin-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.admin-row {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px 16px; margin-bottom: 12px;
}
.admin-row.add { border-style: dashed; box-shadow: none; }
.admin-row .field { margin-top: 10px; }
.admin-row .field:first-of-type { margin-top: 0; }
.admin-note { font-size: .82rem; margin-top: 10px; }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  background: rgba(15, 16, 28, .5); padding: 24px; }
.modal-card { background: var(--surface); border-radius: 20px; box-shadow: var(--shadow);
  padding: 24px; width: 100%; max-width: 360px; }
.modal-card h2 { font-size: 1.2rem; margin-bottom: 6px; }
.modal-card .muted { margin: 0 0 16px; font-size: .9rem; }
.modal-card input { width: 100%; padding: 13px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--text); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* ---------- loading ---------- */
.loading { position: fixed; inset: 0; display: grid; place-items: center;
  background: var(--bg); color: var(--muted); z-index: 100; }
