:root{
  --bg0:#060811;
  --bg1:#0a1022;
  --card:rgba(255,255,255,.06);
  --stroke:rgba(255,255,255,.12);
  --text:rgba(240,245,255,.92);
  --muted:rgba(240,245,255,.62);

  --green:#56ff9a;
  --amber:#ffcc66;
  --blue:#76b6ff;

  --shadow: 0 26px 80px rgba(0,0,0,.55);
  --radius: 20px;
}

*{box-sizing:border-box}
html,body{height:100%}

body{
  margin:0;
  color:var(--text);
  background:
    radial-gradient(1200px 700px at 70% 15%, rgba(118,182,255,.15), transparent 55%),
    radial-gradient(900px 600px at 25% 35%, rgba(255,255,255,.04), transparent 55%),
    radial-gradient(900px 700px at 60% 80%, rgba(86,255,154,.10), transparent 55%),
    linear-gradient(180deg, var(--bg0), var(--bg1));
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji","Segoe UI Emoji";
  overflow:hidden;
  user-select:none;
  -webkit-tap-highlight-color: transparent;
}

/* Big title outside the modal */
.gameTitle{
  position:fixed;
  top:72px;
  left:50%;
  transform:translateX(-50%);
  z-index:65;             /* above modal card (60), below pills (70/80) */
  pointer-events:none;
}

.gameTitleInner{
  position:relative;
  display:inline-flex;
  align-items:flex-end;
  justify-content:center;
}

.gameTitleText{
  font-size:34px;
  font-weight:950;
  letter-spacing:.03em;
  text-shadow:0 18px 60px rgba(0,0,0,.65);
  white-space:nowrap;
}

/* First "O" */
.gameTitleFirstO{
  display:inline-block;
}

.gameTitleCap{
  position:absolute;
  left:-26px;
  top:-42px;
  width:60px;
  transform:rotate(-17deg);
  filter: drop-shadow(0 20px 45px rgba(0,0,0,.65));
  pointer-events:none;
}

/* Hide title while playing OR while instructions modal is open */
body.playing .gameTitle,
body.instructions-open .gameTitle{
  display:none;
}

.grid{
  position:fixed; inset:0;
  background-image:
    linear-gradient(rgba(255,255,255,.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.06) 1px, transparent 1px);
  background-size: 60px 60px;
  opacity:.14;
  pointer-events:none;
  mask-image: radial-gradient(800px 500px at 50% 40%, black 55%, transparent 100%);
}

canvas#game{
  position:fixed; inset:0;
  width:100vw; height:100vh;
  display:block;
  cursor: default;
}

/* crosshair ONLY while actually playing */
body.playing canvas#game{ cursor: crosshair; }

/* HUD */
.hud{
  position:fixed;
  top:16px; left:16px; right:16px;
  display:flex;
  justify-content:center;
  pointer-events:none;
  z-index: 50;
}

.stats{
  width:min(1100px, calc(100vw - 32px));
  display:grid;
  grid-template-columns: 1.1fr 1fr 1fr 1.2fr;
  gap:12px;
}

.panel{
  padding:12px 14px;
  background:var(--card);
  border:1px solid var(--stroke);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  display:flex;
  flex-direction:column;
  justify-content:center;
  min-height:64px;
  position:relative;
  overflow:hidden;
}

/* Base label/value styles (shared by all panels) */
.panel .label{
  font-size:12px;
  color:var(--muted);
  letter-spacing:.2px;
}

.panel .value{
  margin-top:4px;
  font-size:22px;
  font-weight:950;
  letter-spacing:.2px;
}

.panel .sub{
  margin-top:2px;
  font-size:12px;
  color:var(--muted);
  min-height: 1.2em; /* keep HUD height stable even when subtext appears/changes */
}

/* center COUNTDOWN / SCORE / ACCURACY panels */
.panelCenter{
  align-items:center;
  text-align:center;
}

/* slightly larger numbers for centered panels by default */
.panelCenter .value{
  font-size:26px;
}

/* Special styling for the COUNTDOWN panel */
.panelCountdown {
  padding-top:12px;
  padding-bottom:12px;
}

/* Label: same font as other labels */
.panelCountdown .label{
  font-family: inherit;
  font-size:12px;
  letter-spacing:.2px;
}

/* Robot-y countdown number: a bit smaller than SCORE (42px) */
.panelCountdown .value{
  font-family: "SF Mono", "Roboto Mono", "Menlo", "Consolas", monospace;
  font-size:38px;
  line-height:1.05;
  text-shadow:0 0 16px rgba(86,255,154,0.65);
}

/* Panic mode (last 10s): reddish + stronger glow */
.panelCountdown.panic .value{
  color:#ff6b6b;
  text-shadow:0 0 18px rgba(255,107,107,0.95);
}

.latPanel{
  display:grid;
  grid-template-columns: 1fr 140px;
  gap:12px;
  align-items:center;
}

.latBig{ display:flex; flex-direction:column; }

.latBig .value{
  font-size:26px;
  display:flex;
  gap:10px;
  align-items:baseline;
}

.ms{
  font-size:13px;
  color:var(--muted);
  font-weight:800;
  transform: translateY(-1px);
}

.spark{
  width:140px; height:44px;
  border-radius: 14px;
  border:1px solid rgba(86,255,154,.22);
  background: rgba(10,16,34,.25);
}

/* Bigger, more prominent score in HUD + yellowish color */
#score {
  font-size: 42px;
  color: var(--amber);
}

/* ACCURACY: ONLY number + % */
#accuracy {
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial;
  font-size: 32px;
  font-weight: 900;
  letter-spacing: 0.01em;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
}

/* Hide targets / attempts line under ACCURACY only */
#accuracy + .sub {
  display: none;
}

/* Hide "best hit" / points line under SCORE */
#combo {
  display: none;
}

/* Urgent color for last seconds of countdown */
.time-urgent {
  color: #ff7a7a;
}

/* Overlay */
.overlay{
  position:fixed; inset:0;
  display:flex;
  align-items:center;
  justify-content:center;
  padding:18px;
  pointer-events:none;
  z-index: 60;
  overflow:hidden;   /* no page scroll; scroll lives inside cardScrollable */
}

/* MODAL CARD */
.card{
  width:min(640px, 90vw);
  border-radius: 26px;
  background: linear-gradient(180deg, rgba(255,255,255,.08), rgba(255,255,255,.05));
  border:1px solid rgba(255,255,255,.14);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  padding:22px;
  pointer-events:auto;
  position:relative;
  overflow:hidden;     /* curved corners stay clean */
  max-height:none;
  isolation:isolate;
}

/* Extra class: scrollable content (used for Instructions) */
.cardScrollable{
  max-height: calc(100vh - 44px);
  overflow:auto;
}

.card:before{
  content:"";
  position:absolute; inset:-1px;
  background:
    radial-gradient(600px 200px at 20% 0%, rgba(118,182,255,.25), transparent 60%),
    radial-gradient(600px 250px at 80% 10%, rgba(86,255,154,.18), transparent 60%),
    radial-gradient(600px 250px at 40% 120%, rgba(255,255,255,.08), transparent 60%);
  opacity:.9;
  border-radius: inherit; /* fixes overlay colour leaking past curved corners */
  pointer-events:none;
  z-index:0;
}
.card > *{ position:relative; z-index:1; }

/* (Unused now but harmless if left) */
.cardHome{
  width:min(520px, 90vw);
  max-height:none;
  overflow:hidden;
}

.h1{
  font-size:30px;
  font-weight:950;
  margin:0 0 6px;
  letter-spacing:.2px;
}

.center{ text-align:center; }

.h2{
  font-size:16px;
  font-weight:950;
  margin:14px 0 6px;
  letter-spacing:.2px;
  color: rgba(240,245,255,.90);
}

.h3{
  font-size:14px;
  font-weight:950;
  margin:0;
  letter-spacing:.2px;
  color: rgba(240,245,255,.90);
}

.p{
  margin:0 0 14px;
  color:var(--muted);
  line-height:1.45;
  font-size:14px;
}

.section{
  margin-top: 6px;
}

.bul{
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  line-height: 1.45;
  font-size: 14px;
}

.grid2{
  display:grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 8px;
}

.infoPanel{
  margin-top:12px;
  padding:12px 14px;
  border-radius: 18px;
  border:1px solid rgba(255,255,255,.12);
  background: rgba(0,0,0,.22);
  backdrop-filter: blur(10px);
  box-shadow: 0 16px 55px rgba(0,0,0,.25);
}

/* Top-right close button (smaller) */
.closeBtn{
  position:absolute;
  top:12px;
  right:12px;
  width:36px;
  height:36px;
  padding:0;
  border-radius: 14px;
  border:1px solid rgba(255,255,255,.14);
  background: rgba(0,0,0,.18);
  color: rgba(240,245,255,.90);
  font-weight:950;
  cursor:pointer;
  display:flex;
  align-items:center;
  justify-content:center;
  line-height:1;
  backdrop-filter: blur(10px);
  pointer-events:auto;
  z-index:3;
}
.closeBtn:hover{
  background: rgba(255,255,255,.08);
  border-color: rgba(255,255,255,.22);
}
.closeBtn:active{ transform: translateY(1px) scale(.99); }
.closeBtn span{
  display:block;
  width:100%;
  height:100%;
  display:flex;
  align-items:center;
  justify-content:center;
  pointer-events:none;
  font-size:18px;
}

/* Buttons */
.btn{
  appearance:none;
  border:1px solid rgba(255,255,255,.14);
  background: rgba(0,0,0,.18);
  color: var(--text);
  border-radius: 16px;
  padding:14px 16px;
  font-weight:950;
  cursor:pointer;
  transition: transform .08s ease, background .15s ease, border-color .15s ease, box-shadow .15s ease;
  text-align:center;
}
.btn:hover{
  background: rgba(255,255,255,.08);
  border-color: rgba(255,255,255,.20);
  box-shadow: 0 0 0 6px rgba(255,255,255,.03), 0 16px 55px rgba(0,0,0,.35);
}
.btn:active{ transform: translateY(1px) scale(.99); }

.btn.primary{
  border-color: rgba(86,255,154,.30);
  background: rgba(86,255,154,.10);
  box-shadow: 0 0 0 6px rgba(86,255,154,.05), 0 16px 55px rgba(0,0,0,.35);
}
.btn.primary:hover{
  background: rgba(86,255,154,.14);
  border-color: rgba(86,255,154,.44);
  box-shadow: 0 0 0 7px rgba(86,255,154,.08), 0 18px 65px rgba(0,0,0,.40);
}

/* Centered button stack */
.stack{
  display:flex;
  flex-direction:column;
  gap:12px;
  margin-top:14px;
  width:100%;
  align-items:center;
}
.stack .btn{
  width:min(420px, 100%);
}

/* Leaderboard list */
.list{
  margin-top:10px;
  border-radius: 16px;
  border:1px solid rgba(255,255,255,.10);
  background: rgba(0,0,0,.18);
  overflow:hidden;
}

.scoreRight{
  color: var(--text);
  font-weight: 950;
  font-size: 13px;
  white-space: nowrap;
}

.listRow{
  display:flex;
  justify-content:space-between;
  align-items:center;
  padding:10px 12px;
  border-top: 1px solid rgba(255,255,255,.08);
  gap: 12px;
}
.nameCell{
  display:flex;
  align-items:center;
  gap:10px;
  min-width: 0;
}
.nameText{
  display:flex;
  gap:6px;
  align-items:baseline;
  min-width: 0;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}
.muted{
  color: rgba(240,245,255,.58);
  font-size:12px;
  white-space:nowrap;
}
.badgeRank{
  width:34px;
  height:26px;
  border-radius: 10px;
  display:flex;
  align-items:center;
  justify-content:center;
  font-weight: 950;
  background: rgba(86,255,154,.10);
  border:1px solid rgba(86,255,154,.22);
  color: rgba(240,245,255,.92);
  flex: 0 0 auto;
}
.avatar{
  width:26px;
  height:26px;
  border-radius: 10px;
  background: rgba(255,255,255,.08);
  border:1px solid rgba(255,255,255,.12);
  object-fit: cover;
  flex: 0 0 auto;
}

/* Highlight row for "you" */
.listRow.selfRow{
  background: linear-gradient(90deg, rgba(118,182,255,0.28), rgba(118,182,255,0.04));
}

/* Leaderboard header row */
.listHeaderRow{
  background: rgba(0,0,0,0.26);
}

.listHeaderRow .badgeRank{
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}

.listHeaderRow .nameText{
  font-weight: 800;
  color: var(--muted);
}

/* Leaderboard stat columns */
.leaderStats{
  display:grid;
  grid-template-columns: repeat(4, 80px);
  column-gap:0;
  align-items:center;
  justify-items:center;
  font-size:13px;
  text-align:center;
}

.leaderStats > div{
  white-space:nowrap;
}

.leaderStats.leaderHeader{
  font-size:11px;
  text-transform:uppercase;
  letter-spacing:.08em;
  color:var(--muted);
  font-weight:800;
}

/* numeric cells */
.leaderStats .leaderStatValue{
  font-weight:950;
  font-size:14px;
  color: rgba(240,245,255,.92);
}

/* Points emphasis */
.leaderStats .pointsHeader{
  color: var(--amber);
}

.leaderStats .pointsValue{
  color: var(--amber);
  font-weight:950;
}

/* Gap rows (dashed separators with dots) */
.listRow.gapRow{
  justify-content:center;
  border-top-style:dashed;
  border-color: rgba(255,255,255,.20);
  color:var(--muted);
  font-size:12px;
  font-style:italic;
}
.gapDots{
  width:100%;
  text-align:center;
  letter-spacing:4px;
}

/* Discord account pill (top right) */
.accountPill{
  position:fixed;
  top:16px;
  right:16px;
  z-index:70;
  display:none;
  pointer-events:auto;
  appearance:none;
  border:1px solid rgba(255,255,255,.18);
  background:rgba(0,0,0,.40);
  color:var(--text);
  border-radius:999px;
  padding:8px 14px;
  font-size:13px;
  font-weight:800;
  cursor:pointer;
  backdrop-filter:blur(12px);
  box-shadow:0 20px 60px rgba(0,0,0,.55);
  display:flex;
  align-items:center;
  gap:10px;
}
.accountPill .avatar{
  width:28px;
  height:28px;
  border-radius:999px;
  background:rgba(255,255,255,.08);
  border:1px solid rgba(255,255,255,.20);
  object-fit:cover;
}
.accountPill .name{
  max-width:130px;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}
.accountPill .status{
  font-size:12px;
  color:var(--muted);
}

/* Audio toggle */
.audioToggle{
  position:fixed;
  top:16px;
  right:16px;
  z-index:80;
  display:none;
  pointer-events:auto;
  appearance:none;
  border:1px solid rgba(255,255,255,.18);
  background:rgba(0,0,0,.40);
  color:var(--text);
  border-radius:50%;
  width:38px;
  height:38px;
  font-size:20px;
  font-weight:800;
  cursor:pointer;
  backdrop-filter:blur(12px);
  box-shadow:0 20px 60px rgba(0,0,0,.55);
  align-items:center;
  justify-content:center;
  padding:0;
}
.audioToggle:hover{
  background: rgba(255,255,255,.10);
  border-color: rgba(255,255,255,.24);
}
.audioToggle:active{
  transform: translateY(1px) scale(.99);
}

/* Exit button */
.exitBtn{
  position:fixed;
  top:16px;
  right:64px;
  z-index:70;
  display:none;
  pointer-events:auto;
  appearance:none;
  border:1px solid rgba(255,255,255,.14);
  background: rgba(0,0,0,.18);
  color: var(--text);
  border-radius: 16px;
  padding:10px 12px;
  font-weight:950;
  cursor:pointer;
  backdrop-filter: blur(10px);
  box-shadow: 0 16px 55px rgba(0,0,0,.35);
}
.exitBtn:hover{
  background: rgba(255,255,255,.08);
  border-color: rgba(255,255,255,.20);
}
.exitBtn:active{ transform: translateY(1px) scale(.99); }

/* Toast */
.toast{
  position:fixed;
  left:50%;
  top:110px;
  transform:translateX(-50%) translateY(-6px);
  padding:10px 14px;
  border-radius: 999px;
  border:1px solid rgba(255,255,255,.14);
  background: rgba(0,0,0,.28);
  backdrop-filter: blur(10px);
  box-shadow: 0 18px 50px rgba(0,0,0,.45);
  font-weight: 950;
  letter-spacing: .3px;
  pointer-events:none;
  opacity:0;
  transition: opacity .12s ease, transform .12s ease;
  z-index: 9999;
  color: rgba(240,245,255,.92);
}
.toast.show{
  opacity:1;
  transform:translateX(-50%) translateY(0);
}

/* Countdown overlay (3-2-1 / GO) */
.countdown{
  position:fixed;
  left:50%;
  top:50%;
  transform:translate(-50%, -50%);
  z-index: 80;
  pointer-events:none;
  opacity:0;
  transition: opacity .12s ease, transform .12s ease;
  font-weight:950;
  letter-spacing:.5px;
  text-align:center;
  color: rgba(240,245,255,.92);
  text-shadow: 0 18px 60px rgba(0,0,0,.60);
}
.countdown.show{
  opacity:1;
  transform:translate(-50%, -50%) scale(1);
}
.countdown .chip{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  min-width: 180px;
  padding: 16px 22px;
  border-radius: 999px;
  border:1px solid rgba(255,255,255,.14);
  background: rgba(0,0,0,.30);
  backdrop-filter: blur(10px);
  box-shadow: 0 22px 80px rgba(0,0,0,.45);
}
.countdown .big{
  font-size: 76px;
  line-height: 1;
}
.countdown .go{
  font-size: 58px;
  line-height: 1;
  letter-spacing: 1px;
  color: rgba(86,255,154,.95);
}

/* Hide HUD unless playing */
body:not(.playing) #statsHud{ display:none; }

/* Show Exit button whenever playing */
body.playing #exitBtn{ display:block; }

/* Show audio toggle only when playing */
body.playing .audioToggle{ display:flex; }

/* Mobile tweaks */
@media (max-width: 720px){
  .listRow{
    flex-direction:column;
    align-items:flex-start;
  }
  .leaderStats{
    justify-items:flex-start;
    margin-top:4px;
  }
}

@media (max-width: 860px){
  .stats{ grid-template-columns: 1fr 1fr; }
  .toast{ top: 98px; }
  .countdown .big{ font-size: 60px; }
  .countdown .go{ font-size: 46px; }
  .countdown .chip{ min-width: 150px; }
  .grid2{ grid-template-columns: 1fr; }
}
