:root {
  color-scheme: light;
  --bg: #f5f5f4;
  --surface: #ffffff;
  --surface-2: #efeeec;
  --ink: #1c1c1e;
  --muted: #6b6b70;
  --line: #e4e3e0;
  --accent: #1c1c1e;
  --accent-ink: #ffffff;
  --highlight: #2563eb;
  --gold: #d97706;
  --gold-soft: #fef3c7;
  --free: #16a34a;
  --free-soft: #e3f6e9;
  --on-free: #ffffff;
  --busy: #dc2626;
  --busy-soft: #fde8e7;
  --reserved: #b45309;
  --reserved-soft: #fdf3dc;
  --bar: #2563eb;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.05), 0 6px 20px rgb(0 0 0 / 0.05);
  --radius: 18px;
  --display: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --body: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;
    --bg: #111113;
    --surface: #1b1b1e;
    --surface-2: #242428;
    --ink: #f4f4f5;
    --muted: #a1a1aa;
    --line: #2e2e33;
    --accent: #f4f4f5;
    --accent-ink: #111113;
    --highlight: #60a5fa;
    --gold: #fbbf24;
    --gold-soft: #3a2c0c;
    --free: #4ade80;
    --free-soft: #11291a;
  --on-free: #052e16;
    --on-free: #052e16;
    --busy: #f87171;
    --busy-soft: #351616;
    --reserved: #fbbf24;
    --reserved-soft: #33270c;
    --bar: #60a5fa;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 6px 20px rgb(0 0 0 / 0.25);
  }
}
:root[data-theme='dark'] {
  color-scheme: dark;
  --bg: #111113;
  --surface: #1b1b1e;
  --surface-2: #242428;
  --ink: #f4f4f5;
  --muted: #a1a1aa;
  --line: #2e2e33;
  --accent: #f4f4f5;
  --accent-ink: #111113;
  --highlight: #60a5fa;
  --gold: #fbbf24;
  --gold-soft: #3a2c0c;
  --free: #4ade80;
  --free-soft: #11291a;
  --on-free: #052e16;
  --busy: #f87171;
  --busy-soft: #351616;
  --reserved: #fbbf24;
  --reserved-soft: #33270c;
  --bar: #60a5fa;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font: 400 16px/1.5 var(--body);
  -webkit-font-smoothing: antialiased;
}
h1, h2 { font-family: var(--display); font-weight: 800; line-height: 1.15; letter-spacing: -0.025em; margin: 0; }
h1 { font-size: clamp(1.8rem, 7vw, 2.4rem); }
h2 { font-size: 1.15rem; display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.75rem; }
button { font: inherit; color: inherit; }
.muted { color: var(--muted); margin: 0.25rem 0 0; }
.small { font-size: 0.875rem; }
.center { text-align: center; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* --- layout --- */
/* Header and the notifications bar above it stick together */
.sticky-top { position: sticky; top: 0; z-index: 5; }
.notify-bar {
  display: flex; align-items: center; justify-content: center; gap: 0.75rem; flex-wrap: wrap;
  width: 100%; border: 0; cursor: pointer; text-align: center;
  padding: calc(env(safe-area-inset-top) + 0.6rem) 16px 0.6rem;
  background: var(--highlight); color: #fff; font-size: 0.92rem;
}
.notify-bar:hover { filter: brightness(1.08); }
.notify-text.short { display: none; }
@media (max-width: 600px) {
  .notify-bar { flex-wrap: nowrap; justify-content: space-between; text-align: left; }
  .notify-text.long { display: none; }
  .notify-text.short { display: inline; }
}
.notify-cta {
  flex: none; padding: 0.3rem 0.85rem; border-radius: 999px;
  background: #fff; color: var(--highlight); font-weight: 700; font-size: 0.85rem;
}
:root:not([data-theme='light']) .notify-bar { color: #fff; }
#notify-bar:not([hidden]) + .topbar { padding-top: 0.75rem; } /* the bar already clears the notch */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: calc(env(safe-area-inset-top) + 0.75rem) 16px 0.75rem;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px);
}
.brand { font-family: var(--display); font-weight: 800; font-size: 1.25rem; letter-spacing: -0.03em; color: var(--ink); display: flex; align-items: center; gap: 0.4rem; }
.me-btn {
  display: flex; align-items: center; gap: 0.5rem; max-width: 55%;
  padding: 0.25rem 0.75rem 0.25rem 0.25rem; border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); cursor: pointer; font-size: 0.9rem; font-weight: 600;
}
.me-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app {
  max-width: 560px; margin: 0 auto;
  padding: 0.5rem 16px calc(env(safe-area-inset-bottom) + 2rem);
  display: flex; flex-direction: column; gap: 1rem;
}
.loading { text-align: center; color: var(--muted); padding: 4rem 0; }
.leaders-grid, .below-grid { display: flex; flex-direction: column; gap: 1rem; }

/* The hero: status, main button, queue and extras in one block */
.hero-queue {
  margin-top: 1.25rem; padding: 1rem 1.1rem; border-radius: 16px; text-align: left;
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow);
}
.hero-queue h2 { margin-bottom: 0.5rem; }
/* Secondary actions: two per row under the main button, matching its width */
.status-secondary {
  display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem;
  max-width: 420px; margin: 0.6rem auto 0;
}
.status-secondary .pill-btn { width: 100%; border-radius: 14px; padding: 0.75rem 0.6rem; }
.status-secondary .pill-btn:last-child:nth-child(odd) { grid-column: 1 / -1; } /* a lone one takes the full width */

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.25rem; box-shadow: var(--shadow);
}
.big-emoji { font-size: 3rem; margin: 0 0 0.5rem; }

body.offline .app::before {
  content: '📡 Connection lost. Retrying…';
  display: block; text-align: center; font-size: 0.875rem; font-weight: 600;
  padding: 0.5rem; border-radius: 12px; background: var(--busy-soft); color: var(--busy);
}

/* --- tabs --- */
.tabs { grid-template-columns: repeat(3, 1fr) !important; }
.tabs, .segmented {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px;
  background: var(--surface-2); border-radius: 999px;
}
.tabs button, .segmented button {
  border: 0; background: transparent; padding: 0.55rem; border-radius: 999px;
  font-weight: 600; color: var(--muted); cursor: pointer;
}
.tabs [aria-selected='true'], .segmented [aria-pressed='true'] {
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow);
}

/* --- status card --- */
.status {
  --tone: var(--free); --tone-soft: var(--free-soft);
  text-align: center; padding: 1.75rem 1.25rem; border-radius: 24px;
  background: var(--tone-soft); border: 2px solid color-mix(in srgb, var(--tone) 35%, transparent);
}
.status h1 { color: var(--tone); }
.status.busy, .status.mine { --tone: var(--busy); --tone-soft: var(--busy-soft); }
.status.mine { --tone: var(--highlight); --tone-soft: color-mix(in srgb, var(--highlight) 10%, var(--surface)); }
.status.reserved { --tone: var(--reserved); --tone-soft: var(--reserved-soft); }
.status.turn { --tone: var(--on-free); --tone-soft: var(--free); animation: glow 1.6s ease-in-out infinite; }
.status.turn .quip { color: var(--on-free); opacity: 0.85; }
.status-emoji { font-size: 3.25rem; margin: 0 0 0.25rem; line-height: 1; }
.occupant { display: inline-flex; align-items: center; gap: 0.6rem; margin-top: 0.9rem; font-weight: 600; font-size: 1.1rem; }
.quip { margin: 0.6rem 0 0; color: var(--muted); font-style: italic; min-height: 1.5em; }
@keyframes glow {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--free) 50%, transparent); }
  50% { box-shadow: 0 0 0 12px color-mix(in srgb, var(--free) 0%, transparent); }
}

/* --- buttons --- */
.btn {
  appearance: none; border: 0; border-radius: 14px; cursor: pointer;
  padding: 0.9rem 1.1rem; font-weight: 700; font-size: 1rem;
  transition: transform 0.08s ease, filter 0.15s ease;
}
.btn:active:not(:disabled) { transform: scale(0.98); }
.btn:disabled { opacity: 0.6; cursor: progress; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn.danger { background: var(--busy-soft); color: var(--busy); border: 1px solid color-mix(in srgb, var(--busy) 30%, transparent); }
.btn.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.btn.huge { font-size: 1.25rem; padding: 1.15rem; }
.btn.pulse { animation: pulse 1.2s ease-in-out infinite; }
.btn.wide { width: 100%; margin-top: 1rem; }
@keyframes pulse { 50% { transform: scale(1.025); } }
.wait {
  display: inline-block; margin: 0.9rem 0 0; padding: 0.35rem 0.8rem; border-radius: 999px;
  background: var(--surface); color: var(--muted); font-size: 0.9rem;
}
.wait strong { color: var(--ink); font-variant-numeric: tabular-nums; }
:focus-visible { outline: 3px solid var(--highlight); outline-offset: 2px; }

/* --- avatars --- */
.avatar { flex: none; border-radius: 50%; object-fit: cover; background: var(--surface-2); }
.avatar.sm { width: 28px; height: 28px; font-size: 0.7rem; }
.avatar.md { width: 36px; height: 36px; font-size: 0.8rem; }
.avatar.lg { width: 48px; height: 48px; font-size: 1rem; }
.avatar.initials {
  display: inline-grid; place-items: center; font-weight: 700;
  background: hsl(var(--h) 55% 88%); color: hsl(var(--h) 45% 28%);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) .avatar.initials { background: hsl(var(--h) 35% 28%); color: hsl(var(--h) 70% 88%); }
}

/* --- queue & feed --- */
.count {
  font: 600 0.8rem/1 var(--body); padding: 0.25rem 0.55rem; border-radius: 999px;
  background: var(--surface-2); color: var(--muted);
}
.queue, .ranks, .feed { list-style: none; margin: 0; padding: 0; }
.queue li, .ranks li {
  display: flex; align-items: center; gap: 0.7rem; padding: 0.6rem 0.5rem;
  border-bottom: 1px solid var(--line);
}
.queue li:last-child, .ranks li:last-child { border-bottom: 0; }
.queue li.me, .ranks li.me { background: color-mix(in srgb, var(--highlight) 9%, transparent); border-radius: 12px; }
.place, .medal { width: 1.6rem; text-align: center; font-weight: 700; color: var(--muted); flex: none; }
.name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.name em { color: var(--muted); font-weight: 400; }
.since { color: var(--muted); font-size: 0.8rem; flex: none; }
.feed li {
  display: flex; justify-content: space-between; gap: 1rem; padding: 0.45rem 0;
  border-bottom: 1px solid var(--line); font-size: 0.92rem;
}
.feed li:last-child { border-bottom: 0; }
.feed time { color: var(--muted); font-size: 0.8rem; flex: none; }

/* --- picker --- */
.search {
  width: 100%; margin: 1rem 0; padding: 0.8rem 1rem; font: inherit; color: var(--ink);
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2);
}
.people { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0.5rem; }
.person {
  display: flex; align-items: center; gap: 0.6rem; padding: 0.55rem; text-align: left;
  border: 1px solid var(--line); border-radius: 14px; background: var(--surface); cursor: pointer;
  font-weight: 600; font-size: 0.92rem; min-width: 0;
}
.person span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person:hover, .person.selected { border-color: var(--highlight); background: color-mix(in srgb, var(--highlight) 8%, var(--surface)); }
.code-form { display: flex; gap: 0.5rem; margin-top: 1.25rem; }
.code-form input {
  flex: 1; min-width: 0; padding: 0.8rem 1rem; font: inherit; color: var(--ink);
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2);
}

/* --- leaderboard --- */
.board { display: flex; flex-direction: column; gap: 1rem; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.stat-tile { text-align: center; padding: 1.1rem 0.75rem; }
.stat-number { font: 800 3rem/1 var(--display); margin: 0; letter-spacing: -0.03em; color: var(--ink); }
.score { font-weight: 700; font-variant-numeric: tabular-nums; flex: none; }
.score small { color: var(--muted); font-weight: 500; }
.hours {
  display: flex; align-items: flex-end; gap: 2px; height: 140px;
  margin-top: 1rem; padding-bottom: 1.4rem; border-bottom: 1px solid var(--line); position: relative;
}
.hour { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; position: relative; outline-offset: 0; }
.bar { background: var(--bar); border-radius: 4px 4px 0 0; min-height: 0; transition: height 0.4s ease; }
.bar.peak { background: var(--gold); }
.hour-label {
  position: absolute; bottom: -1.4rem; left: 50%; transform: translateX(-50%);
  font-size: 0.7rem; color: var(--muted); white-space: nowrap;
}
.hour:hover .bar, .hour:focus .bar { filter: brightness(1.15); }
.hour:hover::after, .hour:focus::after {
  content: attr(data-tip); position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 0.3rem 0.55rem; border-radius: 8px;
  font-size: 0.75rem; font-weight: 600; white-space: nowrap; z-index: 2; pointer-events: none;
}
.hour:first-child:hover::after, .hour:first-child:focus::after { left: 0; transform: none; }
.hour:last-child:hover::after, .hour:last-child:focus::after { left: auto; right: 0; transform: none; }

/* --- main action inside the status block, extras as pills --- */
.status-action { margin-top: 1.25rem; }
.status-action .btn { width: 100%; max-width: 420px; }
.status-hint { margin: 1rem auto 0; max-width: 420px; color: var(--tone); font-weight: 600; }
.status-hint strong { font-variant-numeric: tabular-nums; }
.pills { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.5rem; }
.pill-btn {
  appearance: none; cursor: pointer; border-radius: 999px; padding: 0.5rem 0.95rem;
  font-size: 0.88rem; font-weight: 600; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line);
  transition: border-color 0.15s ease, background 0.15s ease;
}
.pill-btn:hover:not(:disabled) { border-color: var(--muted); }
.pill-btn:disabled { opacity: 0.6; cursor: progress; }
.pill-btn.danger { color: var(--busy); background: var(--busy-soft); border-color: color-mix(in srgb, var(--busy) 30%, transparent); }
.queue li.you-slot { border: 1px dashed var(--line); border-radius: 12px; color: var(--muted); }
.queue li.you-slot .avatar { opacity: 0.55; }
.queue li.you-slot .name { color: var(--muted); font-style: italic; }

/* --- supplies --- */
.supply-list { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; }
.supply-btn { padding: 0.8rem 0.6rem; font-size: 0.92rem; }
.supply-btn:only-of-type { grid-column: 1 / -1; } /* the other one is already out */
.supply-alert {
  grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
  padding: 0.75rem 0.9rem; border-radius: 14px;
  background: var(--reserved-soft); border: 1px solid color-mix(in srgb, var(--reserved) 35%, transparent);
}
.supply-alert p { margin: 0; }
@media (max-width: 600px) {
  .supply-alert { flex-direction: column; align-items: stretch; }
}
.supply-alert.no-stock { background: color-mix(in srgb, var(--highlight) 9%, var(--surface)); border-color: color-mix(in srgb, var(--highlight) 35%, transparent); }
.btn.no-stock {
  width: 100%; margin: 0.25rem 0 0.25rem;
  background: color-mix(in srgb, var(--highlight) 9%, var(--surface)); color: var(--ink);
  border: 1px solid color-mix(in srgb, var(--highlight) 35%, transparent);
}
.supply-alert .btn { flex: none; padding: 0.65rem 0.9rem; font-size: 0.9rem; }
.suggested-label { margin: 0.75rem 0 0.35rem; font-size: 0.8rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.person.suggested { width: 100%; border-color: var(--highlight); background: color-mix(in srgb, var(--highlight) 8%, var(--surface)); }

/* --- badges --- */
.badge-summary { text-align: center; }
.stat-number .of { font-size: 1.4rem; color: var(--muted); }
.rarity-legend { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.4rem; margin-top: 0.9rem; }
.badge-group { margin: 0.75rem 0 -0.25rem; font-size: 1rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.badge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0.85rem; }
.badge-card {
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 0.45rem;
  padding: 1.1rem 0.75rem 1rem; border-radius: 18px;
  background: var(--surface); border: 2px solid var(--ink); box-shadow: 4px 4px 0 var(--ink);
}
.badge-card:not(.have) .badge-medal { filter: grayscale(0.85); opacity: 0.55; }
.badge-card.legendary { background: color-mix(in srgb, var(--gold) 16%, var(--surface)); }
.badge-card h3 { margin: 0.25rem 0 0; font-size: 1rem; font-weight: 800; letter-spacing: -0.02em; line-height: 1.2; }
.badge-medal {
  position: relative; width: 76px; height: 76px; border-radius: 50%;
  background: var(--c); border: 4px solid var(--ink); display: grid; place-items: center;
}
.badge-medal::before {
  content: ''; position: absolute; inset: 6px; border-radius: 50%;
  border: 2px dashed rgb(255 255 255 / 0.45);
}
.badge-medal span { font-size: 2rem; line-height: 1; filter: drop-shadow(0 1px 0 rgb(0 0 0 / 0.25)); }
.rarity {
  display: inline-block; padding: 0.15rem 0.6rem; border-radius: 999px;
  font-size: 0.68rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
  background: #e9e7e1; color: #3d3a33;
}
.rarity.uncommon { background: #d3f0dc; color: #1e5a33; }
.rarity.rare { background: #e2ddfb; color: #3f2f8f; }
.rarity.legendary { background: #fde7a6; color: #6b4b00; }
.rarity.shame { background: #f9d6d2; color: #8a1c12; }
.badge-desc { margin: 0; font-size: 0.85rem; color: var(--muted); line-height: 1.35; }
.holders { min-height: 28px; display: flex; align-items: center; }
.avatars { display: flex; }
.avatars > span { margin-left: -6px; }
.avatars > span:first-child { margin-left: 0; }
.avatars .avatar { border: 2px solid var(--surface); }
.avatars .more { font-size: 0.75rem; font-weight: 700; color: var(--muted); margin-left: 4px; align-self: center; }
.have-it { margin: 0; font-size: 0.78rem; font-weight: 700; color: var(--free); }
.badge-card.shame .have-it { color: var(--busy); }

/* --- toast & dialog --- */
.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 1.25rem); z-index: 20;
  transform: translate(-50%, calc(100% + 3rem)); width: min(92vw, 480px); visibility: hidden;
  padding: 0.85rem 1.1rem; border-radius: 14px; text-align: center; font-weight: 600;
  background: var(--ink); color: var(--bg); box-shadow: var(--shadow);
  transition: transform 0.25s ease, visibility 0s 0.25s; pointer-events: none;
}
.toast.show { transform: translate(-50%, 0); visibility: visible; transition: transform 0.25s ease; }
.toast[data-kind='error'] { background: var(--busy); color: #fff; }
.toast[data-kind='good'] { background: var(--free); color: var(--on-free); }
.confirm {
  border: 0; border-radius: 22px; padding: 1.5rem; width: min(92vw, 420px);
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow); text-align: center;
}
.confirm::backdrop { background: rgb(0 0 0 / 0.5); backdrop-filter: blur(2px); }
.confirm h2 { justify-content: center; font-size: 1.3rem; }
.confirm p { color: var(--muted); }
.confirm-emoji { font-size: 2.5rem; margin: 0; }
.confirm-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; margin-top: 1.25rem; }
.report-people { grid-template-columns: 1fr; max-height: 26dvh; overflow-y: auto; text-align: left; }
.confirm { max-height: 94dvh; overflow-y: auto; }
.report .confirm-emoji { font-size: 2rem; }
.report h2 { margin-bottom: 0.25rem; }
.report p { margin: 0.25rem 0; }
.report .search { margin: 0.5rem 0 0.75rem; }

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

/* Desktop: use the extra width instead of a phone-sized column */
@media (min-width: 900px) {
  :root { --page: 1120px; }
  .app { max-width: var(--page); gap: 1.5rem; padding-top: 1rem; }
  .topbar { padding-inline: max(16px, calc((100vw - var(--page)) / 2 + 16px)); }
  .tabs { width: 100%; max-width: 520px; align-self: center; }
  .segmented { width: 100%; max-width: 360px; align-self: center; }

  .status.hero {
    display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
    grid-template-areas: "main queue";
    gap: 1.25rem 2rem; align-items: center; padding: 2rem;
  }
  .hero-main { grid-area: main; }
  .hero-queue { grid-area: queue; margin-top: 0; align-self: stretch; }
  .below-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: 1.5rem; align-items: start; }
  .status h1 { font-size: 2.75rem; }
  .status-emoji { font-size: 4rem; }

  .board { gap: 1.5rem; }
  .tiles { gap: 1.5rem; }
  .hours { height: 200px; }
  .leaders-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 1.5rem; align-items: start; }
  .badge-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1.25rem; }
}