:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #0f172a;
  --muted: #5b6475;
  --border: #e3e7ee;
  --brand: #2563eb;
  --brand-soft: #e8efff;
  --join: #059669;
  --danger: #dc2626;
  --warn: #c2410c;
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0e14;
    --surface: #151a23;
    --text: #e8ecf3;
    --muted: #98a2b3;
    --border: #262d3a;
    --brand: #5b8cff;
    --brand-soft: #1b2640;
    --join: #10b981;
    --danger: #f87171;
    --warn: #fb923c;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 24px; margin: 0 0 4px; letter-spacing: -0.01em; }
h2 { font-size: 15px; margin: 24px 0 8px; color: var(--muted); font-weight: 600; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* Layout: side nav on wide screens, top tabs on phones */
.shell { display: flex; min-height: 100vh; }
.nav {
  width: 220px; flex: none; padding: 20px 12px; border-right: 1px solid var(--border);
  background: var(--surface); display: flex; flex-direction: column; gap: 2px;
}
.brand { font-weight: 700; font-size: 18px; padding: 4px 12px 16px; letter-spacing: -0.01em; }
.nav a {
  display: block; padding: 8px 12px; border-radius: 8px; color: var(--text); font-weight: 500;
}
.nav a:hover { background: var(--bg); text-decoration: none; }
.nav a[aria-current="page"] { background: var(--brand-soft); color: var(--brand); }
.nav .spacer { flex: 1; }
main { flex: 1; min-width: 0; padding: 32px 40px; max-width: 820px; }
@media (max-width: 760px) {
  .shell { flex-direction: column; }
  .nav {
    width: auto; flex-direction: row; align-items: center; gap: 4px; padding: 10px 16px;
    border-right: 0; border-bottom: 1px solid var(--border); overflow-x: auto;
  }
  .brand { padding: 0 8px 0 0; }
  .nav .spacer { display: none; }
  main { padding: 20px 16px; }
}

/* Cards and rows */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--border); }
.row:first-child { border-top: 0; }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.bar { width: 4px; align-self: stretch; border-radius: 2px; flex: none; }
.time { width: 72px; flex: none; font-variant-numeric: tabular-nums; font-size: 13px; }
.tag { font-size: 12px; font-weight: 600; color: var(--warn); margin-left: 6px; }

/* Controls */
button, .button {
  font: inherit; font-weight: 600; border-radius: 10px; padding: 9px 16px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  min-height: 40px; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: background-color .15s, border-color .15s;
}
button:hover, .button:hover { border-color: var(--muted); text-decoration: none; }
button.primary, .button.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
button.primary:hover { filter: brightness(1.06); }
button.join { background: var(--join); border-color: var(--join); color: #fff; padding: 6px 12px; min-height: 32px; font-size: 13px; }
button.danger { color: var(--danger); }
button.link { border: 0; background: none; color: var(--brand); padding: 0; min-height: 0; font-weight: 500; }
button:disabled { opacity: .5; cursor: default; }
button:focus-visible, a:focus-visible, input:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
input[type=text], input[type=email], input[type=password] {
  font: inherit; width: 100%; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
label.field { display: block; margin-bottom: 12px; }
label.field span { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.switch { position: relative; width: 42px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; position: absolute; margin: 0; cursor: pointer; }
.switch i { position: absolute; inset: 0; border-radius: 12px; background: var(--border); transition: background .15s; pointer-events: none; }
.switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked + i { background: var(--brand); }
.switch input:checked + i::after { transform: translateX(18px); }
.switch input:focus-visible + i { outline: 2px solid var(--brand); outline-offset: 2px; }
.toggles { display: flex; gap: 20px; flex-wrap: wrap; }
.toggles label { display: flex; align-items: center; gap: 8px; font-size: 13px; }

/* Sign-in */
.auth { max-width: 400px; margin: 10vh auto; padding: 0 16px; }
.auth .card { padding: 24px; }
.stack { display: grid; gap: 10px; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 13px; margin: 8px 0; }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--border); }
.tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--bg); border-radius: 10px; padding: 3px; margin-bottom: 16px; }
.tabs button { border: 0; background: none; min-height: 34px; padding: 4px; }
.tabs button[aria-selected="true"] { background: var(--surface); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.error { color: var(--danger); font-size: 13px; margin-top: 8px; }
.qr { display: flex; justify-content: center; margin: 12px 0; }
.qr img { width: 180px; height: 180px; image-rendering: pixelated; background: #fff; padding: 8px; border-radius: 8px; }
.code { font-family: ui-monospace, Menlo, monospace; font-size: 13px; letter-spacing: .03em; }
.codes { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 16px; margin: 12px 0; }
.empty { padding: 40px 16px; text-align: center; }
.loading { padding: 40px 0; text-align: center; color: var(--muted); }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* Event details */
.event-link { font-weight: 500; color: var(--text); text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.event-link:hover { color: var(--brand); text-decoration: underline; }
dialog.event {
  border: 1px solid var(--border); border-radius: 16px; background: var(--surface); color: var(--text);
  width: min(440px, calc(100vw - 32px)); padding: 20px 24px 24px;
}
dialog.event::backdrop { background: rgba(15, 23, 42, .45); }
.event-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.event-head .close { margin-left: auto; font-size: 18px; color: var(--muted); min-width: 32px; min-height: 32px; }
dialog.event h1 { font-size: 20px; margin-bottom: 8px; }
button.join-wide { background: var(--join); border-color: var(--join); }
.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--brand-soft); color: var(--brand); margin-right: 6px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 16px 0 8px; }
.stat { padding: 14px 16px; display: flex; flex-direction: column; }
.stat b { font-size: 22px; font-variant-numeric: tabular-nums; }
@media (max-width: 480px) { .stats { grid-template-columns: 1fr 1fr; } }
form.row { margin: 0; }
