:root{
  --primary:#4DA8FF;
  --secondary:#50E3C2;
  --accent:#FFD93D;
  --purple:#7B5CFF;
  --danger:#FF5C5C;

  --bg1:#0b1020;
  --bg2:#151a35;

  --text:#111827;
  --muted:#6b7280;

  --card: rgba(255,255,255,0.78);
  --card-border: rgba(255,255,255,0.55);
  --shadow: 0 18px 60px rgba(0,0,0,0.22);

  --radius: 22px;
  --radius2: 16px;
  --font: ui-sans-serif, system-ui, -apple-system, Segoe UI, Verdana, Arial, sans-serif;
  --side-panel-w: 340px;
  --side-panel-h: 410px;
}

*{ box-sizing:border-box; }

html{
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(1200px 700px at 20% 10%, rgba(77,168,255,0.24), transparent 60%),
    radial-gradient(900px 600px at 90% 25%, rgba(123,92,255,0.22), transparent 55%),
    radial-gradient(800px 500px at 55% 95%, rgba(255,217,61,0.18), transparent 55%),
    linear-gradient(180deg, var(--bg1), var(--bg2));
  background-color: var(--bg1);
}

body{
  margin:0;
  font-family:var(--font);
  min-height:100vh;
  color:var(--text);
  display:flex;
  align-items:center;
  justify-content:center;
  overflow:hidden;

  background:
    radial-gradient(1200px 700px at 20% 10%, rgba(77,168,255,0.24), transparent 60%),
    radial-gradient(900px 600px at 90% 25%, rgba(123,92,255,0.22), transparent 55%),
    radial-gradient(800px 500px at 55% 95%, rgba(255,217,61,0.18), transparent 55%),
    linear-gradient(180deg, var(--bg1), var(--bg2));
}

#bg-canvas{
  position:fixed;
  inset:0;
  z-index:0;
  pointer-events:none;
  opacity:0.9;
}

.container{
  position:relative;
  z-index:1;
  width:min(520px, 92vw);
  padding:22px;
  border-radius:var(--radius);
  box-shadow:var(--shadow);
  border:1px solid rgba(255,255,255,0.22);
}

.glass{
  background: var(--card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.page-in{
  animation: popIn 420ms cubic-bezier(.2,.9,.2,1) both;
}

@keyframes popIn{
  from{ transform: translateY(10px) scale(0.98); opacity:0; }
  to{ transform: translateY(0) scale(1); opacity:1; }
}

/* Header */
header{
  text-align:center;
  margin-bottom:10px;
}

.title{
  margin: 0 0 6px 0;
  font-size: 2.75rem;
  letter-spacing: -0.02em;
  color: rgba(255, 255, 255, 0.7);
}
.subtitle{
  margin:0 0 8px 0;
  color: rgba(255, 255, 255, 0.7);
  font-weight: 700;
}
.emoji{ filter: drop-shadow(0 6px 10px rgba(0,0,0,0.15)); }

.menu-box{ padding: 18px; border-radius: var(--radius2); }
/* Make homepage fit better on one screen */
.menu-box{
  padding: 16px;
}

/* Slightly tighten spacing on homepage */
.stats-display{
  padding: 12px 14px 10px 14px;
}


.micro-row{
  margin-top: 10px;
}

/* New instructions box */
.instructions-box{
  margin-top: 12px;
  padding: 14px 16px;
  border-radius: var(--radius2);
  border: 1px solid rgba(255,255,255,0.22);
  box-shadow: 0 18px 60px rgba(0,0,0,0.12);
}

.instructions-title{
  margin: 0 0 10px 0;
  font-size: 1.05rem;
  font-weight: 950;
  letter-spacing: -0.01em;
  color: rgba(17,24,39,0.85);
  text-align:center;
}

.instructions-list{
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 6px;
  color: rgba(17,24,39,0.74);
  font-weight: 800;
  font-size: 0.95rem;
}

.instructions-list strong{
  color: rgba(17,24,39,0.92);
}

.instructions-tip{
  margin-top: 10px;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(255,255,255,0.65);
  border: 1px solid rgba(0,0,0,0.06);
  color: rgba(17,24,39,0.70);
  font-weight: 900;
  font-size: 0.92rem;

  /* Center content + button underneath */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
}
/* GitHub button inside the tip box */
.instructions-tip a,
.instructions-tip button{
  width: fit-content;
  min-width: 220px;
  padding: 12px 18px;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  font-weight: 950;
  text-decoration: none;
  color: white;
  background: linear-gradient(90deg, var(--primary), var(--purple));
  box-shadow: 0 16px 32px rgba(77,168,255,0.22);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.instructions-tip a:hover,
.instructions-tip button:hover{
  transform: translateY(-1px);
  filter: brightness(1.03);
}

.instructions-tip a:active,
.instructions-tip button:active{
  transform: translateY(1px) scale(0.99);
}
/* If the screen is small, allow scrolling instead of squishing */
@media (max-height: 720px), (max-width: 520px){
  body{
    overflow-y: auto;
    overflow-x: hidden;
    align-items: center;
    justify-content: flex-start;
  }
  .container{ margin: 24px auto; }
}

.stats-display{
  padding: 14px 14px 10px 14px;
  border-radius: 16px;
  background: rgba(255,255,255,0.65);
  border: 1px solid rgba(0,0,0,0.06);
}

h2{
  margin: 0;
  font-size: 1.05rem;
  text-align:center;
}
.big-number{
  font-size: 4.5rem;
  font-weight: 900;
  margin: 10px 0 6px;
  letter-spacing: -0.04em;
  background: linear-gradient(90deg, var(--primary), var(--purple), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 14px 40px rgba(77,168,255,0.20);
  text-align:center;
}
.hint{
  font-size: 0.92rem;
  color: rgba(17,24,39,0.66);
  font-weight: 700;
}

/* Grade selector (segmented control) */
.grade-selector{
  margin-top: 14px;
  text-align:left;
}
.label{
  display:block;
  font-weight: 900;
  color: rgba(17,24,39,0.78);
  margin-bottom: 8px;
  letter-spacing: -0.01em;
}

.segmented{
  display:flex;
  gap:10px;
  background: rgba(255,255,255,0.62);
  border:1px solid rgba(0,0,0,0.06);
  padding:10px;
  border-radius: 18px;
}

/* spacing between stacked segmented rows */
.segmented + .segmented{
  margin-top: 10px;
}

/* 3-button row: slightly tighter so it fits on one screen */
.segmented-3 .seg-btn{
  padding: 11px 10px;
  font-size: 1.05rem;
}

.seg-btn{
  flex:1;
  border:0;
  border-radius: 14px;
  padding: 12px 12px;
  font-weight: 900;
  cursor:pointer;
  background: rgba(255,255,255,0.55);
  color: rgba(17,24,39,0.72);
  transition: transform 140ms ease, box-shadow 140ms ease, background 160ms ease;
  box-shadow: 0 10px 24px rgba(0,0,0,0.06);
  font-size: 1.05rem;
}
.seg-btn:hover{ transform: translateY(-1px); }
.seg-btn:active{ transform: translateY(1px) scale(0.99); }

.seg-btn.is-active{
  background: linear-gradient(90deg, rgba(77,168,255,0.95), rgba(123,92,255,0.92));
  color: white;
  box-shadow: 0 14px 30px rgba(77,168,255,0.22);
}

/* Buttons */
.btn{
  width:100%;
  margin-top: 12px;
  border:0;
  border-radius: 999px;
  padding: 15px 18px;
  font-size: 1.15rem;
  font-weight: 950;
  cursor:pointer;
  position:relative;
  overflow:hidden;
  transform: translateZ(0);
  transition: transform 140ms ease, box-shadow 140ms ease, filter 160ms ease;
}

.btn-primary{
  color:white;
  background: linear-gradient(90deg, var(--primary), var(--purple));
  box-shadow: 0 16px 32px rgba(77,168,255,0.24);
}
.btn-secondary{
  color: rgba(17,24,39,0.85);
  background: rgba(255,255,255,0.80);
  border: 1px solid rgba(0,0,0,0.08);
  box-shadow: 0 16px 32px rgba(0,0,0,0.10);
}

.btn:hover{ transform: translateY(-2px); filter: brightness(1.03); }
.btn:active{ transform: translateY(1px) scale(0.99); }

.btn-juice{
  animation: breathe 2.8s ease-in-out infinite;
}
@keyframes breathe{
  0%,100%{ transform: translateY(0); }
  50%{ transform: translateY(-1px); }
}

.btn-shine{
  position:absolute;
  inset:-40%;
  transform: rotate(20deg) translateX(-60%);
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.35), transparent);
  animation: shine 2.6s ease-in-out infinite;
  pointer-events:none;
}
@keyframes shine{
  0%{ transform: rotate(20deg) translateX(-70%); opacity:0; }
  35%{ opacity:1; }
  70%{ transform: rotate(20deg) translateX(70%); opacity:0; }
  100%{ opacity:0; }
}

/* Game HUD */
.hud{
  display:flex;
  justify-content:space-between;
  gap:10px;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(0,0,0,0.08);
  font-weight: 950;
}

.timer-box, .score-box{
  padding: 10px 12px;
  border-radius: 16px;
  background: rgba(255,255,255,0.72);
  border: 1px solid rgba(0,0,0,0.06);
  box-shadow: 0 12px 28px rgba(0,0,0,0.08);
}

.question-box{
  font-size: 2rem;
  margin: 18px 0;
  font-weight: 950;
  text-align:center;
  min-height: 72px;
  letter-spacing: -0.02em;
}

.options-grid{
  display:grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.option-btn{
  border-radius: 18px;
  padding: 18px 14px;
  font-size: 1.35rem;
  font-weight: 950;
  cursor:pointer;
  border: 1px solid rgba(0,0,0,0.08);
  background: rgba(255,255,255,0.70);
  box-shadow: 0 14px 28px rgba(0,0,0,0.08);
  transition: transform 120ms ease, box-shadow 140ms ease, filter 160ms ease;
  position: relative;
  overflow:hidden;
}
.option-btn:hover{
  transform: translateY(-2px);
  box-shadow: 0 18px 34px rgba(0,0,0,0.12);
}
.option-btn:active{
  transform: translateY(1px) scale(0.99);
}

.option-btn::after{
  content:"";
  position:absolute;
  inset:-40%;
  transform: rotate(25deg) translateX(-70%);
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.45), transparent);
  opacity:0;
  transition: opacity 160ms ease;
}
.option-btn:hover::after{
  opacity:1;
  animation: shine 1.6s ease-in-out infinite;
}

/* Feedback */
.correct{
  background: rgba(46,204,113,0.25) !important;
  border-color: rgba(46,204,113,0.55) !important;
}
.wrong{
  background: rgba(255,92,92,0.22) !important;
  border-color: rgba(255,92,92,0.55) !important;
}

.tiny-hint{
  margin-top: 10px;
  text-align:center;
  font-weight: 800;
  color: rgba(17,24,39,0.60);
}

/* Results */
.results-box{
  padding: 14px;
  border-radius: 16px;
  background: rgba(255,255,255,0.65);
  border: 1px solid rgba(0,0,0,0.06);
  text-align:center;
}

.stats-grid{
  display:flex;
  justify-content:space-around;
  gap:12px;
  margin: 14px 0;
  background: rgba(255,255,255,0.62);
  border: 1px solid rgba(0,0,0,0.06);
  padding: 12px;
  border-radius: 16px;
  font-weight: 900;
}

.average-update{
  text-align:center;
  font-weight: 900;
  color: rgba(17,24,39,0.74);
}

hr{
  border:0;
  height:1px;
  background: rgba(0,0,0,0.08);
  margin: 14px 0;
}

/* Small “pills” row */
.micro-row{
  margin-top: 12px;
  display:flex;
  gap:10px;
  flex-wrap:wrap;
  justify-content:center;
}
.pill{
  padding: 8px 10px;
  border-radius: 999px;
  background: rgba(255,255,255,0.60);
  border: 1px solid rgba(0,0,0,0.06);
  font-weight: 900;
  color: rgba(17,24,39,0.70);
  margin-left: auto;
  margin-right: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ===============================
   LEFT ACCOUNT PANEL (UI ONLY)
================================ */

.account-panel{
  width: var(--side-panel-w);
  padding: 18px;
  border-radius: 22px;
  box-shadow: var(--shadow);
  height: var(--side-panel-h);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.account-title{
  margin:0 0 6px 0;
  text-align:center;
  font-weight:950;
  font-size:1.15rem;
}

.account-sub{
  margin:0 0 14px 0;
  text-align:center;
  color: rgba(17,24,39,0.68);
  font-weight: 800;
}

.account-btn{
  width:100%;
  border:0;
  border-radius:16px;
  padding:12px 12px;
  font-weight:950;
  cursor:pointer;
  background: rgba(255,255,255,0.70);
  border: 1px solid rgba(0,0,0,0.08);
  box-shadow: 0 14px 28px rgba(0,0,0,0.08);
  transition: transform 140ms ease, box-shadow 140ms ease, filter 160ms ease;
  display:flex;
  align-items:center;
  justify-content:center;
  gap:10px;
}

.account-btn:hover{ transform: translateY(-2px); filter: brightness(1.03); }
.account-btn:active{ transform: translateY(1px) scale(0.99); }

.google-btn{
  color:white;
  background: linear-gradient(90deg, var(--primary), var(--purple));
  border: none;
  box-shadow: 0 16px 32px rgba(77,168,255,0.22);
}

.secondary-btn{
  background: rgba(255,255,255,0.80);
}

.danger-btn{
  background: rgba(255,92,92,0.16);
  border-color: rgba(255,92,92,0.35);
}

.account-btn:disabled{
  opacity:0.65;
  cursor:not-allowed;
  transform:none;
}

.g-icon{
  width:28px;
  height:28px;
  border-radius:10px;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  font-weight: 1000;
  background: rgba(255,255,255,0.22);
  border: 1px solid rgba(255,255,255,0.28);
}

.account-divider{
  margin: 14px 0;
  display:flex;
  align-items:center;
  gap:10px;
  color: rgba(17,24,39,0.55);
  font-weight: 900;
}

.account-divider::before,
.account-divider::after{
  content:"";
  flex:1;
  height:1px;
  background: rgba(0,0,0,0.10);
}

.account-divider span{
  font-size:1.0rem;
}

.account-note{
  margin: 5px 0 0 0;
  text-align:center;
  color: rgba(17,24,39,0.58);
  font-weight: 800;
  font-size: 0.9rem;
}

.hidden{ display:none !important; }

.account-guest,
.account-signedin{
  display:flex;
  flex-direction:column;
  gap:10px;
}

/* ===============================
   RIGHT LEADERBOARD PANEL
================================ */

.dashboard{
  display:flex;
  gap:28px;
  align-items:center;
  justify-content:center;
}

.center-panel{
  flex:0 0 auto;
}

.leaderboard-panel{
  width: var(--side-panel-w);
  padding: 18px;
  border-radius: 22px;
  box-shadow: var(--shadow);
  height: var(--side-panel-h);
  display:flex;
  flex-direction:column;
  justify-content:space-between;
}

.leaderboard-title{
  margin:0 0 14px 0;
  text-align:center;
  font-weight:950;
  font-size:1.15rem;
}

.leaderboard-list{
  display:flex;
  flex-direction:column;
  gap:10px;
  flex: 1;
}

.leaderboard-row{
  display:grid;
  grid-template-columns: 30px 1fr auto;
  align-items:center;
  column-gap: 12px;
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(255,255,255,0.65);
  border:1px solid rgba(0,0,0,0.06);
  font-weight: 900;
  transition: transform .15s ease;
}

.leaderboard-row:hover{
  transform: translateY(-2px);
}

.rank{
  font-weight:950;
  opacity:0.8;
}

.name{
  font-size: 1.02rem;
  line-height: 1.15;
  white-space: normal;      /* allow wrap */
  overflow: visible;
  text-overflow: unset;
  word-break: break-word;   /* prevents overflow on long names */
}

.avg{
  font-weight: 1000;
  font-variant-numeric: tabular-nums;
}

.gold{
  background: linear-gradient(90deg,#ffd70055,#ffffffaa);
}

.silver{
  background: linear-gradient(90deg,#cfd8dc88,#ffffffaa);
}

.bronze{
  background: linear-gradient(90deg,#cd7f3255,#ffffffaa);
}

.leaderboard-more{
  margin-top:14px;
  width:100%;
  padding:10px;
  border-radius:999px;
  border:none;
  cursor:pointer;
  font-weight:950;
  background: linear-gradient(90deg,var(--primary),var(--purple));
  color:white;
}

/* Desktop-only: slightly smaller center panel so everything fits */
@media (min-width: 901px){
  body:not(.lb-scroll) .container{
    width: min(500px, 92vw);
    padding: 18px;
  }

  body:not(.lb-scroll) .title{ font-size: 2.55rem; }
  body:not(.lb-scroll) .big-number{ font-size: 4.15rem; }
  body:not(.lb-scroll) .btn{ padding: 14px 18px; }
  body:not(.lb-scroll) .menu-box{ padding: 14px; }
}

/* Mobile stacking */
@media (max-width: 900px){
  .dashboard{
    flex-direction:column;
    align-items:center;
    width: 100%;
    padding: 0 10px;
  }

  .center-panel,
  .account-panel,
  .leaderboard-panel{
    margin-left: auto;
    margin-right: auto;
  }

  .leaderboard-panel{
    height: auto;
    width:92vw;
    max-width:520px;
  }

  .account-panel{
    width:92vw;
    max-width:520px;
  }

  /* stack order: main menu first, then account, then leaderboard */
  .center-panel{ order: 1; }
  .account-panel{ order: 2; }
  .leaderboard-panel{ order: 3; }
}

/* ===============================
   MODAL (View More – Guest)
================================ */
.modal-overlay{
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display:flex;
  align-items:center;
  justify-content:center;
  padding: 18px;
  z-index: 9999;
}

.modal-card{
  width: min(520px, 94vw);
  padding: 18px;
  border-radius: 22px;
  box-shadow: 0 30px 70px rgba(0,0,0,0.25);
  position: relative;
  animation: modalIn 180ms ease;
}

@keyframes modalIn{
  from{ transform: translateY(8px) scale(0.98); opacity: 0; }
  to{ transform: translateY(0) scale(1); opacity: 1; }
}

.modal-title{
  margin: 2px 0 6px;
  text-align:center;
  font-weight: 950;
  font-size: 1.2rem;
}

.modal-sub{
  margin: 0 0 14px;
  text-align:center;
  color: rgba(17,24,39,0.68);
  font-weight: 800;
}

.modal-close{
  position:absolute;
  top: 10px;
  right: 10px;
  width: 38px;
  height: 38px;
  border-radius: 14px;
  border: 1px solid rgba(0,0,0,0.08);
  background: rgba(255,255,255,0.72);
  font-size: 22px;
  font-weight: 950;
  cursor:pointer;
  display:flex;
  align-items:center;
  justify-content:center;
  transition: transform 140ms ease, filter 140ms ease;
}

.modal-close:hover{ transform: translateY(-1px); filter: brightness(1.03); }
.modal-close:active{ transform: translateY(1px) scale(0.98); }

/* ===============================
   PROFILE MODAL CONTENT
================================ */
.profile-grid{
  display:grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 10px 0 14px;
}

.profile-item{
  background: rgba(255,255,255,0.65);
  border: 1px solid rgba(0,0,0,0.06);
  border-radius: 16px;
  padding: 12px;
}

.profile-label{
  font-weight: 950;
  font-size: 0.9rem;
  color: rgba(17,24,39,0.72);
  margin-bottom: 6px;
}

.profile-value{
  font-weight: 1000;
  font-size: 1.15rem;
  color: rgba(17,24,39,0.92);
}

.profile-input{
  width: 100%;
  border-radius: 14px;
  border: 1px solid rgba(0,0,0,0.10);
  background: rgba(255,255,255,0.85);
  padding: 10px 12px;
  font-weight: 900;
  color: rgba(17,24,39,0.90);
  outline: none;
}

.profile-input:focus{
  border-color: rgba(77,168,255,0.55);
  box-shadow: 0 0 0 4px rgba(77,168,255,0.18);
}

@media (max-width: 520px){
  .profile-grid{
    grid-template-columns: 1fr;
  }
}

/* ===============================
   DESKTOP SCROLL (Leaderboard page only)
   Requires <body class="lb-scroll"> in leaderboard.html
================================ */
@media (min-width: 901px){
  body.lb-scroll{
    /* override homepage "app" layout */
    display: block;
    overflow-y: auto !important;
    overflow-x: hidden;
    min-height: 100vh;
    height: auto;
  }

  /* Ensure the page can actually grow beyond the viewport */
  html:has(body.lb-scroll){
    height: auto;
  }

  body.lb-scroll .container{
    margin: 24px auto;
  }
}


/* Mobile centering helper for Top 100 rows */
@media (max-width: 520px){
  body.lb-scroll .lb-head,
  body.lb-scroll .lb-row{
    width: 100%;
    margin-left: auto;
    margin-right: auto;
  }
}

/* ===============================
   LEADERBOARD (PC) — wider + no username truncation
   Applies to leaderboard.html (body.lb-scroll)
================================ */
@media (min-width: 901px){
  /* Allow the leaderboard container to use more width on desktop */
  body.lb-scroll .container{
    width: min(980px, 94vw);
  }

  /* Ensure Username column never shows as U.. on desktop */
  body.lb-scroll .lb-head .lb-cell:nth-child(2),
  body.lb-scroll .lb-row .lb-cell:nth-child(2){
    text-overflow: clip !important;
  }
}
