:root {
  --bg: #0b1220;
  --bg-2: #101a2e;
  --card: #141f36;
  --card-2: #1b2a48;
  --border: #243553;
  --text: #eaf1ff;
  --muted: #8ea3c4;
  --green: #16c784;
  --green-soft: #0e3d2c;
  --red: #f6465d;
  --red-soft: #3d1620;
  --gold: #f5b942;
  --blue: #4aa3ff;
  --violet: #8b7bff;
  --radius: 16px;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  background: #070b14;
  color: var(--text);
  height: 100dvh;
  overflow: hidden;
}


.hidden { display: none !important; }

/* ------------------------------- App shell ------------------------------- */
.app-shell {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(100vw, 430px);
  height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(74, 163, 255, 0.14), transparent 60%),
    radial-gradient(900px 500px at 0% 110%, rgba(139, 123, 255, 0.12), transparent 55%),
    var(--bg);
}
@media (min-width: 641px) {
  body { padding: 16px 0; }
  .app-shell {
    height: calc(100dvh - 32px);
    border: 1px solid var(--border);
    border-radius: 26px;
    box-shadow: 0 26px 80px rgba(0, 0, 0, 0.6);
  }
}

/* App top bar */
.app-topbar {
  flex: none;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  background: rgba(11, 18, 32, 0.75);
  backdrop-filter: blur(8px);
}
.topbar-user {
  margin-left: auto;
  display: flex; align-items: center;
  cursor: pointer;
  transition: opacity 0.12s ease, transform 0.1s ease;
}
.topbar-user:hover { opacity: 0.82; }
.topbar-user:active { transform: scale(0.92); }
.topbar-user-fallback {
  width: 34px; height: 34px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--card-2); border: 2px solid var(--border);
  font-size: 16px;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 17px; }
.app-logo {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 28%, #2c3f66, #141f36 70%);
  border: 2px solid rgba(245, 185, 66, 0.85);
  box-shadow: 0 0 0 4px rgba(245, 185, 66, 0.1);
  display: flex; align-items: center; justify-content: center;
  container-type: inline-size;
}

/* Bottom tab bar */
.app-tabs {
  flex: none;
  display: flex;
  gap: 6px;
  padding: 6px 10px calc(env(safe-area-inset-bottom, 0px) + 6px);
  border-top: 1px solid var(--border);
  background: rgba(11, 18, 32, 0.92);
  backdrop-filter: blur(8px);
}
.app-tab {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 6px;
  border: none; border-radius: 12px;
  background: transparent; color: var(--muted);
  font-size: 11px; font-weight: 700; cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease;
}
.app-tab .tab-icon { font-size: 18px; line-height: 1; }
.app-tab.active { color: var(--gold); background: rgba(245, 185, 66, 0.1); }

/* Sign-in screen: no top bar, no bottom tabs — clean, app-like */
body.no-chrome .app-topbar,
body.no-chrome .app-tabs { display: none; }

/* ------------------------------- Screens ------------------------------- */
main { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow-y: auto; padding: 20px 16px 28px; }

/* App-like scrolling: content still scrolls, but no native scrollbar chrome is shown */
.app-shell, .app-shell * {
  scrollbar-width: none;      /* Firefox */
  -ms-overflow-style: none;   /* legacy Edge/IE */
}
.app-shell ::-webkit-scrollbar {
  display: none;              /* Chrome/Safari/Edge */
}
.screen { display: none; }
.screen.active { display: block; animation: fadeUp 0.32s ease; }
.screen.leaving { animation: fadeOut 0.18s ease forwards; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes fadeOut { from { opacity: 1; transform: translateY(0); } to { opacity: 0; transform: translateY(-8px); } }

.card {
  background: linear-gradient(180deg, var(--card), var(--bg-2));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 34px;
  box-shadow: var(--shadow);
}
h1 { font-size: 30px; margin-bottom: 6px; }
h2 { font-size: 22px; margin-bottom: 10px; }
.sub { color: var(--muted); margin-bottom: 22px; line-height: 1.55; }

.google-btn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; padding: 14px; margin-top: auto;
  margin-bottom: calc(env(safe-area-inset-bottom, 0px) + 8px);
  background: #fff; color: #202124; font-size: 15px; font-weight: 600;
  border: 1px solid #dadce0; border-radius: 12px; cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.google-btn:hover { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(0,0,0,0.35); }

.hint { color: var(--muted); font-size: 13px; line-height: 1.5; margin-bottom: 24px; }
.picker-title { margin-top: 8px; }

/* ------------------------------- Welcome hero ------------------------------- */
#screen-profile.active,
#screen-signup.active {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.hero {
  flex: 1;
  display: flex; flex-direction: column; align-items: center;
  text-align: center;
  padding: 16vh 6px 8px;
}
.hero-emblem {
  width: 96px; height: 96px;
  margin: 0 auto 16px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 28%, #2c3f66, #141f36 70%);
  border: 3px solid rgba(245, 185, 66, 0.85);
  box-shadow: 0 0 0 7px rgba(245, 185, 66, 0.12), 0 18px 44px rgba(0, 0, 0, 0.5);
  display: flex; align-items: center; justify-content: center;
  container-type: inline-size;
}
.emblem-text {
  font-weight: 900;
  font-size: 26cqw; /* scales with the circle width so text never overflows */
  letter-spacing: 0.12em;
  background: linear-gradient(135deg, var(--gold), #ffd77a);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero-title {
  font-size: clamp(34px, 9vw, 48px);
  font-weight: 900; letter-spacing: -0.5px;
  margin: 12px 0 10px;
  background: linear-gradient(135deg, #ffffff, #c7d3ef);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero-accent {
  background: linear-gradient(135deg, var(--gold), #ffb02e);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero-sub {
  color: var(--muted);
  font-size: 15px; line-height: 1.6;
  max-width: 480px; margin: 0 auto;
}
.hero-features {
  display: flex; flex-wrap: wrap; gap: 8px; justify-content: center;
  margin: 20px 0 24px;
}
.feature {
  font-size: 12px; font-weight: 700;
  color: var(--text);
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px;
}

/* ------------------------------ Start splash ------------------------------ */
#screen-splash {
  position: absolute; inset: 0; z-index: 30;
  background:
    radial-gradient(1000px 600px at 70% -10%, rgba(74, 163, 255, 0.18), transparent 60%),
    radial-gradient(800px 520px at 10% 110%, rgba(139, 123, 255, 0.16), transparent 55%),
    var(--bg);
  display: flex; align-items: center; justify-content: center;
  padding: 20px 24px 12px;
  transition: opacity 0.55s ease;
}
#screen-splash.splash-leaving { opacity: 0; pointer-events: none; }
#screen-splash.splash-leaving .splash { transform: scale(1.05); }
.splash {
  text-align: center;
  width: 100%; max-width: 420px;
  height: 100%;
  display: flex; flex-direction: column; align-items: center;
  justify-content: flex-start;
  padding-top: 16vh;
  transition: transform 0.55s ease;
}
.splash-progress {
  width: 160px; height: 4px;
  margin-top: 26px;
  border-radius: 999px;
  background: rgba(245, 185, 66, 0.15);
  overflow: hidden;
}
.splash-progress-fill {
  display: block; height: 100%; width: 0;
  background: linear-gradient(90deg, var(--gold), #ffd77a);
  border-radius: 999px;
  animation: splashFill 2.4s ease-in-out forwards;
}
@keyframes splashFill { to { width: 100%; } }
.splash .hero-emblem { margin-bottom: 14px; }
.splash-footer { margin-top: auto; width: 100%; padding-top: 40px; }
.dev-by {
  color: var(--muted);
  font-size: 11px; font-weight: 600; letter-spacing: 2px; text-transform: uppercase;
  margin-bottom: 6px;
}
.dev-brand { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 14px; }
.dev-logo {
  width: 28px; height: 28px; border-radius: 50%;
  background: linear-gradient(135deg, var(--violet), var(--blue));
  color: #fff; font-size: 11px; font-weight: 800; letter-spacing: 0.5px;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.dev-logo img { width: 100%; height: 100%; object-fit: cover; }
.dev-name { color: var(--muted); font-size: 13px; font-weight: 700; letter-spacing: 1px; }
.splash-disclaimer {
  color: var(--muted);
  font-size: 11px; line-height: 1.55;
  border-top: 1px solid var(--border);
  padding-top: 14px;
  max-width: 380px;
  margin: 0 auto;
}

/* ----------------------------- Profile picker ----------------------------- */
.picker-section { margin-top: 30px; }
.picker-heading { text-align: center; margin-bottom: 16px; }
.picker-title { font-size: 20px; font-weight: 800; margin: 0; }
.picker-sub { color: var(--muted); font-size: 13px; margin-top: 4px; }

/* ----------------------------- Mode selection ----------------------------- */
#screen-mode.active {
  flex: 1; min-height: 0;
  display: flex; flex-direction: column;
  justify-content: safe center; /* when the card is taller than the screen, fall back to top so nothing is clipped */
  align-items: center;
}
/* Learn referral banner (opens the learning website in the default browser) */
.learn-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 380px;            /* matches .mode-card */
  margin: 0 auto 16px;
  padding: 14px 16px;
  border-radius: 16px;
  background: linear-gradient(135deg, rgba(74,163,255,0.16), rgba(139,123,255,0.14));
  border: 1px solid rgba(74,163,255,0.35);
  color: var(--text);
  text-decoration: none;
  transition: transform 0.15s ease, border-color 0.15s ease;
}
.learn-banner:hover { border-color: var(--blue); transform: translateY(-1px); }
.learn-banner:active { transform: scale(0.99); }
.learn-banner-icon { font-size: 26px; flex: none; }
.learn-banner-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.learn-banner-title { font-weight: 800; font-size: 15px; }
.learn-banner-sub { color: var(--muted); font-size: 12px; line-height: 1.4; }
.learn-banner-cta {
  margin-left: auto; flex: none;
  font-weight: 800; font-size: 14px; color: var(--blue);
  white-space: nowrap;
}

.mode-card { text-align: center; width: 100%; max-width: 380px; margin: 0 auto; }
.mode-option {
  width: 100%;
  display: flex; align-items: center; gap: 14px;
  background: var(--card-2);
  border: 2px solid var(--border);
  border-radius: 16px;
  padding: 18px;
  margin-top: 14px;
  cursor: pointer;
  text-align: left;
  color: var(--text);
  transition: transform 0.12s ease, border-color 0.12s ease;
}
.mode-option.training { border-color: rgba(22, 199, 132, 0.35); }
.mode-option:hover:not(:disabled) { transform: translateY(-2px); border-color: var(--gold); }
.mode-option:disabled { opacity: 0.55; cursor: not-allowed; }
.mode-icon { font-size: 28px; flex: none; }
.mode-body { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.mode-name { font-weight: 800; font-size: 16px; }
.mode-desc { color: var(--muted); font-size: 12px; line-height: 1.4; }
.mode-cta {
  flex: none;
  font-weight: 800; font-size: 13px; color: var(--green);
  background: var(--green-soft); border-radius: 999px; padding: 6px 14px;
}

/* ----------------------------- Round selection ----------------------------- */
.rounds-head { text-align: center; margin-bottom: 18px; }
.rounds-head h2 { margin-bottom: 4px; }
.round-list { display: flex; flex-direction: column; gap: 10px; }
.round-option {
  width: 100%; display: flex; align-items: center; gap: 14px;
  background: var(--card-2); border: 2px solid var(--border); border-radius: 16px;
  padding: 14px 16px; cursor: pointer; text-align: left; color: var(--text);
  transition: transform 0.12s ease, border-color 0.12s ease;
}
.round-option .r-badge {
  width: 44px; height: 44px; border-radius: 50%; flex: none;
  display: flex; align-items: center; justify-content: center;
  background: var(--card); border: 2px solid var(--border);
  font-weight: 800; font-size: 16px; color: var(--gold);
}
.round-option .r-name { flex: 1; min-width: 0; font-weight: 800; font-size: 15px; }
.round-option .r-soon {
  flex: none; font-size: 11px; font-weight: 800; color: var(--muted);
  background: var(--card); border: 1px solid var(--border); border-radius: 999px; padding: 4px 10px;
}
.round-option .r-check { flex: none; font-size: 18px; color: var(--green); width: 20px; text-align: center; }
.round-option.available:hover:not(.selected) { transform: translateY(-2px); border-color: var(--green); }
.round-option.selected { border-color: var(--green); box-shadow: 0 0 0 2px rgba(22, 199, 132, 0.25); }
.round-option:not(.available) { opacity: 0.5; cursor: not-allowed; }
.rounds-start { width: 100%; margin-top: 22px; }
.rounds-start:disabled { opacity: 0.45; cursor: not-allowed; }

/* ----------------------------- Create profile ----------------------------- */
/* (profile + signup full-height flex layout is defined with .active above) */
.field-label {
  display: block; text-align: left;
  font-size: 13px; font-weight: 700; margin: 18px 0 6px;
}
.text-input {
  width: 100%; padding: 12px 14px;
  background: var(--card-2); border: 1px solid var(--border); border-radius: 12px;
  color: var(--text); font-size: 15px; outline: none;
}
.text-input::placeholder { color: var(--muted); }
.text-input:focus { border-color: var(--gold); }
.school-list {
  margin-top: 8px; max-height: 150px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 4px;
  border: 1px solid var(--border); border-radius: 12px; padding: 6px;
  background: var(--card);
}
.school-option {
  display: flex; align-items: center; gap: 10px;
  text-align: left; padding: 10px 12px; border-radius: 8px;
  background: transparent; border: none; color: var(--text);
  font-size: 14px; cursor: pointer;
}
.school-option:hover { background: var(--card-2); }
.school-option.selected { background: var(--green-soft); color: var(--green); }
.school-option-logo {
  width: 26px; height: 26px; border-radius: 50%; flex: none;
  display: flex; align-items: center; justify-content: center;
  font-size: 8px; font-weight: 800; color: #fff; text-transform: uppercase;
  letter-spacing: 0.5px; line-height: 1; overflow: hidden; border: 2px solid var(--border);
}
.school-option-logo img { width: 100%; height: 100%; object-fit: cover; }
.school-option-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.school-empty { color: var(--muted); text-align: center; padding: 12px; font-size: 13px; }
.school-selected { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-size: 13px; color: var(--green); font-weight: 700; }
.school-selected-logo {
  width: 26px; height: 26px; border-radius: 50%; flex: none;
  display: flex; align-items: center; justify-content: center;
  font-size: 8px; font-weight: 800; color: #fff; text-transform: uppercase;
  letter-spacing: 0.5px; line-height: 1; overflow: hidden; border: 2px solid var(--border);
}
.school-selected-logo img { width: 100%; height: 100%; object-fit: cover; }
.signup-submit { width: 100%; margin-top: 22px; }
.signup-submit:disabled { opacity: 0.45; cursor: not-allowed; }

/* Profile picture picker */
.avatar-picker {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  cursor: pointer; margin-top: 4px;
}
.avatar-preview {
  width: 88px; height: 88px; border-radius: 50%;
  background: var(--card-2); border: 2px dashed var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 28px; color: var(--muted);
  overflow: hidden;
  transition: border-color 0.15s ease;
}
.avatar-picker:hover .avatar-preview { border-color: var(--gold); }
.avatar-picker.has-photo .avatar-preview { border: 2px solid var(--green); }
.avatar-preview img { width: 100%; height: 100%; object-fit: cover; }
.avatar-caption { font-size: 12px; color: var(--muted); font-weight: 600; }
.avatar-note {
  margin-top: 8px;
  font-size: 12px;
  font-weight: 700;
  color: var(--gold);
  text-align: center;
}
.name-row { display: flex; gap: 10px; }
.name-field { flex: 1; min-width: 0; }

/* Rendered avatar images (uploaded profile pictures) */
.avatar-img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.mode-soon {
  flex: none;
  font-weight: 800; font-size: 12px; color: var(--muted);
  background: var(--card); border: 1px solid var(--border); border-radius: 999px; padding: 6px 12px;
}

/* Profile grid */
.profile-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px;
}
.profile-card {
  display: flex; align-items: center; gap: 12px;
  background: var(--card-2); border: 1px solid var(--border); border-radius: 14px;
  padding: 14px; cursor: pointer; text-align: left;
  transition: transform 0.12s ease, border-color 0.12s ease;
}
.profile-card:hover { transform: translateY(-2px); border-color: var(--blue); }
.profile-card.selected { border-color: var(--green); box-shadow: 0 0 0 2px rgba(22,199,132,0.25); }
.avatar {
  width: 46px; height: 46px; border-radius: 50%; flex: none;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: #fff; font-size: 15px;
}

/* Stacked avatar: main profile circle + school-logo badge at bottom-mid */
.avatar-stack { position: relative; width: 52px; height: 52px; flex: none; }
.avatar-stack .avatar { width: 100%; height: 100%; font-size: 17px; }
.school-logo {
  position: absolute; left: 50%; bottom: -3px; transform: translateX(-50%);
  width: 22px; height: 22px; border-radius: 50%;
  border: 2.5px solid var(--card-2);
  display: flex; align-items: center; justify-content: center;
  font-size: 8px; font-weight: 800; letter-spacing: 0.5px; color: #fff;
  line-height: 1; text-transform: uppercase; overflow: hidden;
}
.school-logo img { width: 100%; height: 100%; object-fit: cover; }
.avatar-stack.sm { width: 34px; height: 34px; }
.avatar-stack.sm .avatar { font-size: 11px; }
.avatar-stack.sm .school-logo { width: 15px; height: 15px; font-size: 6px; border-width: 2px; bottom: -2px; }
.profile-info { min-width: 0; }
.profile-info .name { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.profile-info .school { color: var(--muted); font-size: 12px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { font-size: 10px; font-weight: 700; letter-spacing: 0.6px; padding: 2px 8px; border-radius: 999px; margin-top: 4px; display: inline-block; }
.badge.approved { color: var(--green); background: var(--green-soft); }
.badge.pending { color: var(--gold); background: rgba(245,185,66,0.12); }

/* ------------------------------- Lobby ------------------------------- */
.lobby-card { text-align: center; padding: 60px 34px; }
.dots { display: flex; gap: 8px; justify-content: center; margin: 26px 0; }
.dots span {
  width: 12px; height: 12px; border-radius: 50%; background: var(--gold);
  animation: bounce 1.1s infinite ease-in-out;
}
.dots span:nth-child(2) { animation-delay: 0.15s; }
.dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce { 0%, 80%, 100% { transform: translateY(0); opacity: 0.5; } 40% { transform: translateY(-12px); opacity: 1; } }
#lobby-status { color: var(--muted); margin-bottom: 22px; }

/* ------------------------------- Buttons ------------------------------- */
.btn { padding: 12px 24px; border-radius: 12px; border: none; font-size: 15px; font-weight: 700; cursor: pointer; }

/* Profile overlay (self-serve sign out / delete account) */
.account-backdrop {
  position: fixed; inset: 0; z-index: 60; background: rgba(4, 8, 16, 0.74);
  display: flex; align-items: center; justify-content: center; padding: 16px;
  animation: fadeIn 0.18s ease;
}
.profile-card-lg {
  width: 100%; max-width: 380px;
  background: linear-gradient(180deg, var(--card-2), var(--card));
  border: 1px solid var(--border); border-radius: 20px;
  overflow: hidden; box-shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
  animation: popIn 0.22s cubic-bezier(0.2, 0.9, 0.3, 1.15);
}
.pc-banner {
  height: 104px; position: relative;
  background:
    radial-gradient(130% 150% at 12% 0%, rgba(245, 185, 66, 0.32), transparent 55%),
    radial-gradient(130% 150% at 88% 18%, rgba(41, 144, 255, 0.3), transparent 55%),
    linear-gradient(135deg, #13203c, #0a1122);
  border-bottom: 1px solid var(--border);
}
.pc-body { padding: 0 22px 22px; display: flex; flex-direction: column; align-items: center; text-align: center; }
.pc-avatar { margin-top: -48px; }
.pc-avatar .avatar-stack { width: 96px; height: 96px; }
.pc-avatar .avatar { font-size: 32px; border: 4px solid var(--card-2); box-shadow: 0 6px 22px rgba(0, 0, 0, 0.45); }
.pc-avatar .school-logo { width: 34px; height: 34px; font-size: 11px; border-width: 3.5px; bottom: -4px; border-color: var(--card-2); }
.pc-name { font-size: 21px; margin: 16px 0 2px; }
.pc-school { color: var(--muted); font-size: 14px; display: flex; align-items: center; gap: 7px; justify-content: center; }
.pc-crest {
  width: 22px; height: 22px; border-radius: 50%; flex: none;
  display: flex; align-items: center; justify-content: center;
  font-size: 8px; font-weight: 800; color: #fff; text-transform: uppercase;
  overflow: hidden; border: 2px solid var(--border);
}
.pc-crest img { width: 100%; height: 100%; object-fit: cover; }
.pc-badge { margin-top: 10px; }
.pc-email { color: var(--muted); font-size: 13px; margin-top: 8px; }
.pc-email:empty { display: none; }
.pc-stats { display: flex; gap: 10px; width: 100%; margin: 20px 0 2px; }
.pc-stats .stat {
  flex: 1; background: var(--card-2); border: 1px solid var(--border);
  border-radius: 12px; padding: 12px 6px; display: flex; flex-direction: column; gap: 3px;
  min-width: 0;
}
.stat-num { font-size: 20px; font-weight: 800; color: var(--text); }
.stat-label { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.6px; }
.pc-legal {
  display: flex; gap: 18px; justify-content: center; width: 100%;
  padding: 14px 0 2px; margin-top: 16px;
  border-top: 1px solid var(--border);
}
.pc-legal a { color: var(--blue); font-size: 13px; font-weight: 600; text-decoration: none; }
.pc-legal a:hover { color: var(--text); text-decoration: underline; }
.pc-actions { display: flex; flex-direction: column; gap: 8px; width: 100%; margin-top: 12px; }
.pc-actions .btn { width: 100%; }

/* In-card delete confirmation */
.pc-delete-confirm {
  width: 100%; margin-top: 12px;
  background: var(--red-soft); border: 1px solid rgba(246, 70, 93, 0.4);
  border-radius: 14px; padding: 14px; text-align: left;
  animation: popIn 0.18s ease;
}
.pc-delete-title { font-weight: 800; color: var(--red); margin-bottom: 6px; }
.pc-delete-note { color: var(--muted); font-size: 13px; line-height: 1.5; margin-bottom: 12px; }
.pc-delete-btns { display: flex; gap: 8px; }
.pc-delete-btns .btn { flex: 1; padding: 10px; font-size: 14px; }
.btn.danger-solid { background: linear-gradient(135deg, var(--red), #d12b42); color: #fff; }
.btn.danger-solid:hover { filter: brightness(1.08); }
.btn.danger-solid:disabled { opacity: 0.6; cursor: default; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn { from { opacity: 0; transform: scale(0.94) translateY(10px); } to { opacity: 1; transform: none; } }
.btn.danger-soft { background: transparent; color: var(--red); border: 1px solid var(--red); }
.btn.danger-soft:hover { background: rgba(246, 70, 93, 0.12); }
.btn.primary { background: linear-gradient(135deg, var(--gold), #ffd77a); color: #1a1200; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn.ghost:hover { color: var(--text); border-color: var(--muted); }

/* ------------------------------- HUD ------------------------------- */
/* Full-screen fixed contest layer (mobile-first, no overlap) */
#screen-hud {
  position: absolute; inset: 0; z-index: 10;
  background:
    radial-gradient(900px 500px at 80% -10%, rgba(74,163,255,0.12), transparent 60%),
    var(--bg);
  display: none;
  flex-direction: column;
  gap: 10px;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 12px calc(env(safe-area-inset-bottom, 0px) + 12px);
  overflow: hidden;
}
#screen-hud.active { display: flex; }
body.mode-hud .app-topbar,
body.mode-hud .app-tabs { display: none; }

/* Round indicator pinned to the top of the contest screen */
.hud-top { flex: none; display: flex; align-items: center; justify-content: center; gap: 8px; }
.mode-tag {
  font-size: 11px; font-weight: 800; letter-spacing: 1px; text-transform: uppercase;
  color: var(--blue);
  background: rgba(74, 163, 255, 0.12);
  border: 1px solid rgba(74, 163, 255, 0.35);
  border-radius: 999px;
  padding: 4px 12px;
  display: inline-block;
}
.round-num {
  font-size: 12px; font-weight: 800; letter-spacing: 1.5px; text-transform: uppercase;
  color: var(--gold);
  background: rgba(245, 185, 66, 0.1);
  border: 1px solid rgba(245, 185, 66, 0.35);
  border-radius: 999px;
  padding: 4px 16px;
}

/* Set counter on the question card (e.g., "Set 3/12") */
.set-num {
  font-size: 12px; font-weight: 700; letter-spacing: 0.5px;
  color: var(--muted);
  background: rgba(16, 26, 46, 0.7);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 10px;
}

/* Fixed meta widths so the row never shifts while the subject is empty/loading */
.statement-meta #subject-chip {
  width: 96px; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  white-space: nowrap;
}
.statement-meta .set-num {
  width: 92px; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  white-space: nowrap;
}

/* 7-segment display: which seat (1/2/3) ran the bell (always visible, between subject and set) */
.seven-seg {
  position: relative;
  width: 30px; height: 38px; flex: none;
  background: #0a0f1a;
  border: 1px solid var(--border);
  border-radius: 7px;
  box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.65);
}
.seven-seg .seg { position: absolute; border-radius: 2px; background: rgba(120, 140, 170, 0.16); }
.seven-seg .seg.a, .seven-seg .seg.d, .seven-seg .seg.g { height: 4px; width: 16px; left: 7px; }
.seven-seg .seg.a { top: 5px; }
.seven-seg .seg.g { top: 17px; }
.seven-seg .seg.d { top: 29px; }
.seven-seg .seg.b, .seven-seg .seg.c, .seven-seg .seg.e, .seven-seg .seg.f { width: 4px; height: 11px; }
.seven-seg .seg.b { top: 5px;  left: 19px; }
.seven-seg .seg.f { top: 5px;  left: 7px; }
.seven-seg .seg.c { top: 17px; left: 19px; }
.seven-seg .seg.e { top: 17px; left: 7px; }
.seven-seg[data-digit="1"] .seg.b, .seven-seg[data-digit="1"] .seg.c,
.seven-seg[data-digit="2"] .seg.a, .seven-seg[data-digit="2"] .seg.b, .seven-seg[data-digit="2"] .seg.g,
.seven-seg[data-digit="2"] .seg.e, .seven-seg[data-digit="2"] .seg.d,
.seven-seg[data-digit="3"] .seg.a, .seven-seg[data-digit="3"] .seg.b, .seven-seg[data-digit="3"] .seg.g,
.seven-seg[data-digit="3"] .seg.c, .seven-seg[data-digit="3"] .seg.d {
  background: var(--gold);
  box-shadow: 0 0 6px rgba(245, 185, 66, 0.8);
}

/* Horizontal scoreboard — all 3 players in one block */
.scores {
  flex: none;
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
}
.player-card {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px;
  padding: 10px 4px 8px;
  background: var(--card);
  border: 2px solid var(--border); border-radius: 16px;
  min-width: 0;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.player-card .avatar-stack { width: 46px; height: 46px; }
.player-card .school-logo { border-color: var(--card); }
.player-card .pname {
  font-weight: 600; font-size: 12px; line-height: 1.1;
  max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.player-card.is-me { border-color: var(--blue); box-shadow: 0 0 0 1px rgba(74,163,255,0.35); }
.player-card.is-target { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(245,185,66,0.25); }
.player-card .delta { position: absolute; top: 4px; right: 4px; font-size: 12px; font-weight: 800; opacity: 0; }
.player-card .delta.show { opacity: 1; animation: pop 0.8s ease; }
.player-card .delta.up { color: var(--green); }
.player-card .delta.down { color: var(--red); }

/* Score as a badge pinned to the avatar's top-right corner */
.avatar-stack .pscore {
  position: absolute; top: -7px; right: -7px; z-index: 3;
  min-width: 21px; height: 21px; padding: 0 5px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--gold), #ffd77a);
  border: 2px solid var(--card);
  color: #1a1200;
  font-size: 12px; font-weight: 800; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  font-variant-numeric: tabular-nums;
}
@keyframes pop { 0% { transform: translateY(0); opacity: 1; } 60% { transform: translateY(-14px); opacity: 1; } 100% { transform: translateY(-14px); opacity: 0; } }

.stage { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 10px; }
.statement-card {
  position: relative;
  flex: 1; min-height: 0;
  background: linear-gradient(180deg, var(--card-2), var(--card));
  border: 1px solid var(--border); border-radius: 18px; padding: 56px 20px 16px;
  display: flex; flex-direction: column; align-items: center; text-align: center;
  overflow: hidden;
}
.statement-meta { position: absolute; top: 16px; left: 18px; right: 18px; display: flex; justify-content: space-between; align-items: center; }

/* Preamble is part of the question display — clearly visible, same brightness
   as the question text, never muted/small */
.statement-preamble {
  flex: none; width: 100%;
  text-align: left; overflow-wrap: break-word;
  font-size: clamp(17px, 4.4vw, 23px); /* same size as the question */
  line-height: 1.45; color: var(--text);
  background: rgba(74, 163, 255, 0.12);
  border-left: 3px solid var(--blue);
  border-radius: 8px; padding: 8px 12px;
}
.preamble-label {
  font-weight: 800; font-size: 12px; letter-spacing: 1px;
  text-transform: uppercase; color: var(--blue);
  margin-right: 8px;
}
.chip {
  font-size: 11px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase;
  padding: 4px 12px; border-radius: 999px;
}
.chip.math { background: rgba(74,163,255,0.15); color: var(--blue); }
.chip.physics { background: rgba(139,123,255,0.15); color: var(--violet); }
.chip.chemistry { background: rgba(22,199,132,0.15); color: var(--green); }
.chip.biology { background: rgba(245,66,140,0.15); color: #f5428c; }
.idx { color: var(--muted); font-size: 13px; font-weight: 600; }

.timer-wrap { position: relative; width: 56px; height: 56px; flex: none; margin-bottom: 14px; }
.timer { width: 56px; height: 56px; transform: rotate(-90deg); }
.timer-bg { fill: none; stroke: var(--border); stroke-width: 10; }
.timer-fg { fill: none; stroke: var(--gold); stroke-width: 10; stroke-linecap: round; transition: stroke 0.15s ease; }
.timer-num {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--text);
}
.timer-num.reading { font-size: 11px; letter-spacing: 2px; color: var(--blue); }

/* Statement area: preamble + question are fit-to-fit (never scroll) via
   fitStatement() — the smaller timer is the tradeoff for full visibility. */
.statement-text-wrap {
  flex: 1; min-height: 0; width: 100%;
  display: flex; align-items: flex-start; justify-content: center;
  overflow: hidden;
}
.statement-content {
  width: 100%; max-width: 720px;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.statement-text {
  margin: 0;
  font-size: clamp(17px, 4.4vw, 23px);
  font-weight: 600; line-height: 1.45;
  max-width: 720px;
  overflow-wrap: break-word;
}
.status-line { flex: none; margin-top: 12px; color: var(--muted); font-size: 14px; font-weight: 600; letter-spacing: 0.3px; }

/* Actions */
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.answer-btn {
  padding: 20px; border: none; border-radius: 16px; font-size: 20px; font-weight: 800; letter-spacing: 1px;
  cursor: pointer; color: #fff; transition: transform 0.1s ease, filter 0.15s ease, opacity 0.15s ease;
}
.answer-btn.true { background: linear-gradient(135deg, #17b877, #12a463); box-shadow: 0 8px 22px rgba(22,199,132,0.28); }
.answer-btn.false { background: linear-gradient(135deg, #ef3a50, #d6223a); box-shadow: 0 8px 22px rgba(246,70,93,0.28); }
.answer-btn:disabled { opacity: 0.32; cursor: not-allowed; transform: none; box-shadow: none; }
.answer-btn:not(:disabled):hover { transform: translateY(-2px); filter: brightness(1.06); }
.answer-btn:not(:disabled):active { transform: translateY(0); }

.buzz-btn {
  grid-column: 1 / -1; padding: 22px; border: none; border-radius: 16px;
  background: radial-gradient(circle at 30% 20%, #ffe08a, var(--gold) 60%, #d99a1f);
  color: #1a1200; font-size: 22px; font-weight: 900; letter-spacing: 4px; cursor: pointer;
  box-shadow: 0 10px 28px rgba(245,185,66,0.35);
  transition: transform 0.1s ease, filter 0.15s ease, opacity 0.15s ease;
}
.buzz-btn.enabled { animation: pulse 1s infinite; }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.015); } }
.buzz-btn:disabled { opacity: 0.3; cursor: not-allowed; box-shadow: none; animation: none; }
.buzz-btn:not(:disabled):hover { filter: brightness(1.06); }

.feedback {
  flex: none;
  min-height: 34px;
  display: flex; align-items: center; justify-content: center;
  text-align: center;
  font-size: 15px; font-weight: 700;
  border-radius: 12px;
  /* The slot is always reserved — showing text never shifts the layout. */
}
.feedback.ok { color: var(--green); background: var(--green-soft); }
.feedback.bad { color: var(--red); background: var(--red-soft); }
.feedback.info { color: var(--gold); background: rgba(245,185,66,0.12); }
/* Reserved ad banner space — keeps the bottom fixed so buttons sit above it */
.ad-slot {
  flex: none;
  height: 52px;
  border: 1px dashed rgba(142, 163, 196, 0.35);
  border-radius: 12px;
  background: rgba(16, 26, 46, 0.55);
  display: flex; align-items: center; justify-content: center;
}
.ad-slot-label {
  color: var(--muted);
  font-size: 10px; font-weight: 700; letter-spacing: 1.5px; text-transform: uppercase;
}
/* Contest preview (ready screen) */
.preview-overlay {
  position: absolute; inset: 0; z-index: 60;
  background: linear-gradient(180deg, rgba(11, 18, 32, 0.94), rgba(7, 11, 20, 0.98));
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.preview-card {
  width: 100%; max-width: 400px; text-align: center;
  animation: fadeUp 0.32s ease;
}
.preview-head { display: flex; align-items: center; justify-content: center; gap: 8px; margin-bottom: 18px; }
.preview-title { font-size: 26px; font-weight: 800; }
.preview-sub { color: var(--muted); margin: 6px 0 18px; font-size: 13px; }
.matchup-row {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  margin-bottom: 22px;
}
.matchup-player {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 12px 6px 10px;
}
.matchup-player.is-me { border-color: var(--blue); box-shadow: 0 0 0 2px rgba(74, 163, 255, 0.25); }
.matchup-player .avatar-stack { width: 46px; height: 46px; }
.matchup-player .avatar-stack .school-logo { border-color: var(--card); }
.matchup-player .m-name {
  font-weight: 700; font-size: 13px; max-width: 100%;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.matchup-player .m-school {
  color: var(--muted); font-size: 10px; text-align: center; max-width: 100%;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.matchup-player .m-tagline { color: var(--gold); font-size: 9px; font-weight: 600; text-align: center; line-height: 1.3; }
.matchup-vs {
  flex: none;
  font-size: 16px; font-weight: 900; font-style: italic; color: var(--gold);
  letter-spacing: 1px;
  text-shadow: 0 0 14px rgba(245, 185, 66, 0.5);
}
.start-btn { width: 100%; padding: 16px; font-size: 17px; letter-spacing: 0.5px; }
.start-btn:disabled { opacity: 0.6; cursor: default; }
.preview-countdown { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.preview-countdown-num {
  font-size: 84px; font-weight: 900; line-height: 1; color: var(--gold);
  font-variant-numeric: tabular-nums;
}
.preview-countdown-num.pop { animation: cdPop 1s ease; }
@keyframes cdPop {
  0% { transform: scale(1.5); opacity: 0; }
  30% { transform: scale(1); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}
.preview-countdown-label {
  color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: 2px; text-transform: uppercase;
}
/* Overlay */
.overlay {
  position: absolute; inset: 0; background: rgba(4, 8, 16, 0.8); backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px;
  overflow-y: auto;
}
.end-card { width: 100%; max-width: 460px; text-align: center; }
.end-standings { margin: 18px 0 24px; display: flex; flex-direction: column; gap: 10px; }
.end-row {
  display: flex; align-items: center; justify-content: flex-start; gap: 12px;
  background: var(--card-2); border: 1px solid var(--border); border-radius: 12px; padding: 12px 16px;
}
.end-row .rank { font-weight: 800; color: var(--gold); width: 30px; }
.end-row .ename { font-weight: 600; }
.end-row .escore { font-weight: 800; font-variant-numeric: tabular-nums; margin-left: auto; }
.end-row.winner { border-color: var(--gold); box-shadow: 0 0 0 2px rgba(245,185,66,0.25); }

/* Leave-contest confirm overlay */
.leave-card { width: 100%; max-width: 400px; text-align: center; animation: fadeUp 0.32s ease; }
.leave-sub { color: var(--muted); margin: 8px 0 18px; font-size: 13px; }
.leave-countdown { display: flex; flex-direction: column; align-items: center; gap: 6px; margin-bottom: 22px; }
.leave-countdown-num {
  font-size: 56px; font-weight: 900; line-height: 1; color: var(--gold);
  font-variant-numeric: tabular-nums;
}
.leave-countdown-label {
  color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: 2px; text-transform: uppercase;
}
.leave-actions { display: flex; gap: 10px; }
.leave-actions .btn { flex: 1; padding: 14px; }

/* ------------------------------- Leaderboard ------------------------------- */
.lb-tabs { display: flex; gap: 8px; margin-bottom: 18px; }
.tab {
  background: transparent; color: var(--muted); border: 1px solid var(--border);
  padding: 8px 16px; border-radius: 10px; cursor: pointer; font-weight: 600; font-size: 14px;
}
.tab.active { color: var(--text); background: var(--card-2); border-color: var(--gold); }
.lb-list { display: flex; flex-direction: column; gap: 8px; }
.lb-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--card-2); border: 1px solid var(--border); border-radius: 12px; padding: 12px 16px;
}
.lb-rank { font-weight: 800; color: var(--gold); width: 24px; flex: none; }
.lb-row .avatar { width: 34px; height: 34px; font-size: 11px; flex: none; }
.lb-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.lb-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lb-sub { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lb-pts { font-weight: 800; font-variant-numeric: tabular-nums; font-size: 18px; flex: none; }
.lb-school-logo {
  width: 34px; height: 34px; border-radius: 50%; flex: none;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 800; color: #fff; text-transform: uppercase;
  letter-spacing: 0.5px; line-height: 1; overflow: hidden; border: 2px solid var(--border);
}
.lb-school-logo img { width: 100%; height: 100%; object-fit: cover; }
.empty { color: var(--muted); text-align: center; padding: 20px; }

@media (max-width: 640px) {
  .scores { gap: 6px; }
  .player-card { padding: 8px 2px 7px; gap: 5px; border-radius: 14px; }
  .player-card .avatar-stack { width: 40px; height: 40px; }
  .player-card .pname { font-size: 11px; }
  .timer-wrap { width: 50px; height: 50px; }
  .timer { width: 50px; height: 50px; }
  .timer-num { font-size: 18px; }
  .answer-btn { padding: 15px; font-size: 17px; border-radius: 14px; }
  .buzz-btn { padding: 17px; font-size: 19px; letter-spacing: 3px; }
  .statement-card { padding: 56px 14px 14px; }
  .status-line { margin-top: 12px; font-size: 13px; }
  .feedback { min-height: 30px; font-size: 14px; }
  main { padding: 16px 12px 60px; }
}
