:root {
  /* Dark mode defaults; app.js swaps in the light/dark values from src/config.js THEME. */
  --bg: #0a0a0a;
  --card: #161616;
  --card-2: #1f1f1f;
  --line: #2a2a2a;
  --text: #fafafa;
  --muted: #8e8e93;
  --faint: #48484a;
  --accent: #fafafa;
  --on-accent: #0a0a0a;
  --select: #fafafa;
  --on-select: #0a0a0a;
  --ink: #0a0a0a; /* text on colored member circles */
  --danger: #ff453a;
  --radius: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
button:disabled { cursor: default; opacity: .35; }

.loading { padding: 40vh 0; text-align: center; color: var(--muted); }

/* ---------- Layout ---------- */

.shell {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 16px) 16px calc(env(safe-area-inset-bottom) + 40px);
}

.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; gap: 12px; }
.topbar h1 { margin: 0; font-size: 26px; font-weight: 800; letter-spacing: -.02em; }
.topbar .sub { color: var(--muted); font-size: 13px; }

.section-title { margin: 28px 0 10px; font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card + .card { margin-top: 12px; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; }
.spacer { flex: 1; }

/* ---------- Buttons & inputs ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 44px; padding: 0 18px; border-radius: 12px;
  background: var(--accent); color: var(--on-accent); font-weight: 700;
}
.btn.block { width: 100%; }
.btn.ghost { background: var(--card-2); color: var(--text); border: 1px solid var(--line); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent); }
.btn.sm { height: 34px; padding: 0 12px; font-size: 13px; border-radius: 10px; }

.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center;
  background: var(--card); border: 1px solid var(--line); font-size: 18px;
}

.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.input {
  width: 100%; height: 46px; padding: 0 14px; border-radius: 12px;
  background: var(--card-2); border: 1px solid var(--line); outline: none;
}
textarea.input { height: 76px; padding: 12px 14px; resize: none; }
.input:focus { border-color: var(--accent); }

.error { color: var(--danger); font-size: 13px; min-height: 18px; margin: 4px 0 8px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  height: 36px; padding: 0 14px; border-radius: 999px;
  background: var(--card-2); border: 1px solid var(--line); font-size: 14px; font-weight: 500;
}
.chip.on { background: var(--select); color: var(--on-select); border-color: var(--select); font-weight: 700; }

.segmented { display: flex; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 3px; }
.segmented button { flex: 1; height: 36px; border-radius: 9px; font-size: 14px; font-weight: 600; color: var(--muted); }
.segmented button.on { background: var(--card-2); color: var(--text); }

/* ---------- Auth ---------- */

.auth { max-width: 380px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 12vh) 20px 40px; }
.auth .logo { width: 56px; height: 56px; margin-bottom: 20px; }
.auth h1 { font-size: 30px; margin: 0 0 6px; letter-spacing: -.02em; }
.auth p { margin: 0 0 24px; color: var(--muted); }
.auth .switch { margin: 20px 0 0; text-align: center; font-size: 14px; }
.link { color: var(--text); font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }
.code-input { text-transform: uppercase; letter-spacing: .2em; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.crew-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 30px; font-weight: 800;
  letter-spacing: .25em; text-align: center; padding: 16px 0; margin: 12px 0;
  background: var(--card-2); border: 1px solid var(--line); border-radius: 12px;
}

/* ---------- App bar & profile menu ---------- */

.appbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.brand { font-weight: 900; font-size: 15px; letter-spacing: .14em; color: var(--text); }
.profile { position: relative; }
.profile-btn { border-radius: 50%; display: block; }
.profile-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.menu {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 30; min-width: 200px;
  background: var(--card-2); border: 1px solid var(--line); border-radius: 14px; padding: 6px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .5); animation: drop .15s ease;
}
.menu[hidden] { display: none; }
.menu-head { padding: 8px 10px 10px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.menu-name { font-weight: 700; }
.menu button { display: block; width: 100%; text-align: left; padding: 10px; border-radius: 9px; font-weight: 500; }
.menu button:hover { background: var(--card); }
.danger-text { color: var(--danger); }

/* ---------- Creatine ---------- */

.creatine { margin-bottom: 20px; }
.cr-state { font-size: 20px; font-weight: 800; letter-spacing: -.01em; margin-bottom: 2px; }
.cr-state.ok { color: #34c759; }
.cr-state.warn { color: var(--danger); }
.cr-week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-top: 14px; }
.cr-day { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 11px; color: var(--muted); }
.cr-day i {
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-style: normal;
  font-size: 13px; font-weight: 800; background: var(--card-2); border: 1px solid var(--line);
}
.cr-day.on i { background: #34c759; border-color: #34c759; color: #fff; }
.cr-day.today span { color: var(--text); font-weight: 700; }
.toggle-row { cursor: pointer; }
.toggle-row input { width: 22px; height: 22px; accent-color: #34c759; }

/* ---------- Calendar ---------- */

.month-nav { display: flex; align-items: center; gap: 6px; }
.icon-btn svg { width: 18px; height: 18px; }
.month-label { font-size: 24px; font-weight: 800; letter-spacing: -.02em; margin: 0; }
.month-label .yr { color: var(--muted); font-weight: 600; }

.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal .dow { text-align: center; font-size: 11px; color: var(--muted); font-weight: 600; padding-bottom: 4px; }
.day {
  min-height: 66px; border-radius: 12px; min-width: 0;
  background: var(--card); border: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 4px; padding: 4px;
  cursor: pointer; user-select: none; -webkit-user-select: none;
}
.day.blank { background: transparent; border-color: transparent; cursor: default; }
.day.off { opacity: .3; cursor: default; }
.day:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.day .num { font-size: 12px; font-weight: 600; line-height: 18px; min-width: 18px; height: 18px; align-self: flex-start; text-align: center; border-radius: 9px; color: var(--muted); }
.day.today { border-color: var(--accent); }
.day.today .num { background: var(--accent); color: var(--on-accent); padding: 0 4px; }

.faces { display: flex; flex-wrap: wrap; gap: 3px; }
.face {
  position: relative; flex: none;
  width: 16px; height: 16px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 9px; font-weight: 800; line-height: 1;
  background: var(--card-2); color: var(--faint); border: 1px solid var(--line);
  transition: background .2s, color .2s, transform .2s;
}
.face.on { background: var(--c); color: var(--ink); border-color: color-mix(in srgb, var(--c) 80%, var(--text)); }
.face.me::after { content: ''; position: absolute; inset: -5px; } /* bigger tap target */
.face.pop { animation: pop .45s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes pop { 0% { transform: scale(.6); } 60% { transform: scale(1.35); } 100% { transform: scale(1); } }
@media (min-width: 480px) {
  .day { min-height: 76px; padding: 6px; }
  .face { width: 22px; height: 22px; font-size: 11px; }
}

.hint { margin-top: 12px; font-size: 12px; color: var(--muted); text-align: center; }

.legend { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.legend .item { display: flex; align-items: center; gap: 8px; padding: 6px 12px 6px 6px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); font-size: 13px; }
.legend .item b { font-variant-numeric: tabular-nums; }

/* ---------- Avatar ---------- */

.avatar {
  flex: none; width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center; font-size: 12px; font-weight: 800; color: var(--ink);
  background: var(--c); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--c) 80%, var(--text));
}
.avatar.lg { width: 40px; height: 40px; font-size: 16px; }

/* ---------- Sheet (modal) ---------- */

.overlay {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .6); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .15s ease;
}
.sheet {
  width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto;
  background: var(--card); border: 1px solid var(--line); border-bottom: 0;
  border-radius: 20px 20px 0 0;
  padding: 10px 16px calc(env(safe-area-inset-bottom) + 20px);
  animation: up .2s cubic-bezier(.2, .8, .2, 1);
}
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 14px; }
.sheet h2 { margin: 0 0 4px; font-size: 22px; letter-spacing: -.01em; }
.sheet .label { font-size: 13px; color: var(--muted); margin: 18px 0 8px; }
.sheet .actions { display: flex; gap: 10px; margin-top: 20px; }
.sheet .actions .btn { flex: 1; }
@media (min-width: 600px) {
  .overlay { align-items: center; }
  .sheet { border-radius: 20px; border-bottom: 1px solid var(--line); }
}
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }

.entry { display: flex; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.entry:first-child { border-top: 0; }
.entry.off { opacity: .4; }
.entry .what { font-weight: 600; }
.entry .note { color: var(--muted); font-size: 14px; margin-top: 2px; word-break: break-word; }

.dur-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.dur-row .input { width: 92px; height: 36px; border-radius: 999px; text-align: center; padding: 0 10px; }

/* ---------- Leaderboard ---------- */

.lb-row { width: 100%; text-align: left; display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.lb-row:first-child { border-top: 0; }
.lb-rank { width: 26px; text-align: center; font-weight: 800; color: var(--muted); font-variant-numeric: tabular-nums; }
.lb-rank.medal { font-size: 20px; }
.lb-main { flex: 1; min-width: 0; }
.lb-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lb-sub { font-size: 12px; color: var(--muted); }
.lb-bar { height: 4px; border-radius: 2px; background: var(--card-2); margin-top: 6px; overflow: hidden; }
.lb-bar > i { display: block; height: 100%; background: var(--c); border-radius: 2px; }
.lb-score { text-align: right; }
.lb-score b { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.lb-score div { font-size: 12px; color: var(--muted); }

/* ---------- Stats ---------- */

.person-picker { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 16px; scrollbar-width: none; }
.person-picker::-webkit-scrollbar { display: none; }
.person-picker .chip { display: flex; align-items: center; gap: 8px; padding-left: 4px; flex: none; }
.person-picker .avatar { width: 26px; height: 26px; font-size: 11px; }

.level-card { display: flex; align-items: center; gap: 16px; }
.level-num {
  width: 64px; height: 64px; border-radius: 18px; flex: none;
  display: grid; place-items: center; font-size: 26px; font-weight: 900; color: var(--ink); background: var(--c);
}
.xp-bar { height: 8px; border-radius: 4px; background: var(--card-2); overflow: hidden; margin: 8px 0 4px; }
.xp-bar > i { display: block; height: 100%; background: var(--c); }

.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 12px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.tile .k { font-size: 12px; color: var(--muted); }
.tile .v { font-size: 26px; font-weight: 800; letter-spacing: -.02em; margin-top: 2px; font-variant-numeric: tabular-nums; }
.tile .v small { font-size: 13px; color: var(--muted); font-weight: 600; letter-spacing: 0; }

.split-row { display: flex; align-items: center; gap: 10px; margin: 8px 0; font-size: 14px; }
.split-row .name { width: 76px; flex: none; }
.split-row .bar { flex: 1; height: 8px; border-radius: 4px; background: var(--card-2); overflow: hidden; }
.split-row .bar > i { display: block; height: 100%; background: var(--c); }
.split-row .n { width: 28px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }

.badges { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.badge { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 8px; text-align: center; }
.badge .ic { font-size: 28px; line-height: 1.2; }
.badge .nm { font-size: 12px; font-weight: 700; margin-top: 4px; }
.badge .ds { font-size: 11px; color: var(--muted); }
.badge.locked .ic { filter: grayscale(1); opacity: .25; }
.badge.locked .nm { color: var(--muted); }

/* ---------- Settings ---------- */

.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch { width: 34px; height: 34px; border-radius: 50%; background: var(--c); border: 3px solid transparent; }
.swatch.on { border-color: var(--text); }


.list-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.list-row:first-child { border-top: 0; }
.list-row .grow { flex: 1; min-width: 0; }
.list-row .grow > div:first-child { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.invite-link {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px;
  background: var(--card-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; word-break: break-all; margin: 10px 0;
}

/* ---------- Toasts ---------- */

#toasts {
  position: fixed; top: calc(env(safe-area-inset-top) + 12px); left: 0; right: 0; z-index: 100;
  display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 16px;
}
.toast {
  background: var(--select); color: var(--on-select); font-weight: 700; font-size: 14px;
  padding: 10px 16px; border-radius: 999px; box-shadow: 0 8px 30px rgba(0, 0, 0, .4);
  animation: drop .25s cubic-bezier(.2, .8, .2, 1);
}
.toast.err { background: var(--danger); color: var(--ink); }
@keyframes drop { from { transform: translateY(-16px); opacity: 0; } }
