* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --ink: #1c2333;
  --panel: rgba(255, 255, 255, 0.94);
  --accent: #ff4757;
  --accent-dark: #d63447;
  --mustard: #ffd32a;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: #0d1322;
  font-family: 'Nunito', system-ui, sans-serif;
  color: var(--ink);
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
#cv { touch-action: none; }

#stage { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
#frame {
  position: relative;
  width: min(100vw, calc(100vh * 16 / 9));
  height: min(100vh, calc(100vw * 9 / 16));
}
#cv { width: 100%; height: 100%; display: block; }

.hidden { display: none !important; }

/* ---------- overlays / shared ---------- */
#overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none; }
#overlay.gone { display: none; }

.panel {
  pointer-events: auto;
  background: var(--panel);
  border-radius: 24px;
  padding: 36px 44px;
  width: min(460px, calc(100vw - 32px));
  max-height: 94vh; overflow-y: auto;
  text-align: center;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45), 0 2px 0 rgba(255,255,255,0.6) inset;
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
}

.title {
  font-family: 'Titan One', 'Nunito', sans-serif;
  font-size: 52px;
  line-height: 0.95;
  color: var(--accent);
  text-shadow: 0 3px 0 var(--accent-dark), 0 8px 18px rgba(214, 52, 71, 0.35);
}
.title::after { content: " 🏃"; font-size: 40px; text-shadow: none; }

.tagline { font-weight: 700; color: #7a8296; font-size: 14px; }
.title.small { font-size: 40px; }
.title.small::after { content: " 💀"; font-size: 30px; text-shadow: none; }

/* run-over summary stats */
.rostats { width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 4px 0 6px; }
.rocell {
  position: relative; background: #f4f6fb; border-radius: 14px; padding: 14px 10px 12px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.rocell b { font-family: 'Titan One', sans-serif; font-size: 32px; color: var(--ink); line-height: 1; }
.rocell span { font-weight: 800; font-size: 11px; letter-spacing: 1.5px; color: #97a0b5; }
.rocell.best { background: #fff8e0; box-shadow: 0 0 0 2px var(--mustard) inset; }
.rocell.best b { color: var(--accent); }
.rocell em {
  position: absolute; top: -9px; left: 50%; transform: translateX(-50%);
  background: var(--mustard); color: #5c4a00; font-style: normal; font-weight: 900;
  font-size: 9.5px; letter-spacing: 0.5px; border-radius: 8px; padding: 2px 8px; white-space: nowrap;
}

input {
  font-family: inherit; font-weight: 800; font-size: 18px; text-align: center;
  padding: 13px 16px; border-radius: 14px; border: 3px solid #dfe4ee;
  background: #f4f6fb; color: var(--ink); width: 100%; outline: none;
}
input:focus { border-color: var(--accent); }
input::placeholder { color: #aab2c5; font-weight: 700; }
#codeInput { text-transform: uppercase; letter-spacing: 6px; width: 130px; }

.btn {
  font-family: inherit; font-weight: 900; font-size: 17px; letter-spacing: 0.5px;
  padding: 13px 22px; border: none; border-radius: 14px;
  background: var(--accent); color: #fff; cursor: pointer;
  box-shadow: 0 4px 0 var(--accent-dark), 0 10px 20px rgba(214, 52, 71, 0.3);
  transition: transform 0.08s, box-shadow 0.08s, filter 0.15s;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--accent-dark); }
.btn:disabled { filter: grayscale(0.7) brightness(0.95); cursor: default; box-shadow: 0 4px 0 #9aa1b1; }
.btn.big { width: 100%; font-size: 20px; padding: 16px 22px; }
.btn.ghost { background: #eef1f8; color: #55607a; box-shadow: 0 3px 0 #d4dae8; font-size: 14px; padding: 10px 18px; }
.btn.ghost:active { box-shadow: 0 1px 0 #d4dae8; }

.divider { width: 100%; display: flex; align-items: center; gap: 10px; color: #aab2c5; font-weight: 700; font-size: 13px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 2px; background: #e6eaf3; border-radius: 2px; }
.joinrow { display: flex; gap: 10px; width: 100%; justify-content: center; }
.error { color: var(--accent-dark); font-weight: 800; font-size: 14px; }
.hint { color: #97a0b5; font-weight: 700; font-size: 13px; }

.lobbylabel { font-weight: 900; font-size: 13px; letter-spacing: 3px; color: #97a0b5; }
#codeBig { font-family: 'Titan One', sans-serif; font-size: 64px; letter-spacing: 14px; padding-left: 14px; line-height: 1; }
#playerList { width: 100%; display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.prow { display: flex; align-items: center; gap: 12px; background: #f4f6fb; border-radius: 12px; padding: 10px 16px; font-weight: 800; font-size: 16px; }
.pdot { width: 16px; height: 16px; border-radius: 50%; flex-shrink: 0; box-shadow: 0 0 0 3px rgba(0,0,0,0.08) inset; }
.phero { margin-left: auto; font-weight: 900; font-size: 12px; letter-spacing: 1px; }
.prow .pcrown { margin-left: 8px; }

#heroPicker { width: 100%; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.heroRow { display: flex; gap: 10px; justify-content: center; width: 100%; }
.heroCard {
  flex: 1; max-width: 190px;
  border: 3px solid #dfe4ee; background: #f4f6fb; border-radius: 14px;
  padding: 10px 12px; cursor: pointer; font-family: inherit; text-align: left;
  display: flex; flex-direction: column; gap: 3px;
  transition: border-color 0.1s, transform 0.08s;
}
.heroCard:hover { transform: translateY(-2px); }
.heroCard.sel { border-color: var(--accent); background: #fff0f1; }
.heroCard .hname { font-family: 'Titan One', sans-serif; font-size: 17px; }
.heroCard .hab { font-weight: 700; font-size: 10.5px; color: #7a8296; line-height: 1.3; }

/* ---------- HUD ---------- */
#hud { position: absolute; inset: 0; pointer-events: none; }

#areaTitle {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
  font-family: 'Titan One', sans-serif; font-size: 34px; color: #fff;
  text-shadow: 0 3px 0 rgba(0,0,0,0.45), 0 8px 20px rgba(0,0,0,0.4);
}
#bestPill {
  position: absolute; top: 14px; left: 16px;
  background: rgba(13, 19, 34, 0.75); color: var(--mustard);
  border-radius: 999px; padding: 7px 15px; font-weight: 900; font-size: 13px;
}
.rrow .rping { font-size: 10px; font-weight: 900; color: #5d6f94; margin-left: 6px; min-width: 34px; text-align: right; }
.rrow .rping.mid { color: var(--mustard); }
.rrow .rping.bad { color: var(--accent); }
#roster {
  position: absolute; top: 14px; right: 16px;
  background: rgba(13, 19, 34, 0.78); border-radius: 12px;
  padding: 10px 14px; min-width: 170px;
  display: flex; flex-direction: column; gap: 5px;
}
.rrow { display: flex; align-items: center; gap: 8px; color: #fff; font-weight: 800; font-size: 12.5px; }
.rrow .rdot { width: 10px; height: 10px; border-radius: 50%; }
.rrow .rarea { margin-left: auto; color: #8fa0c4; font-weight: 900; }
.rrow.down { opacity: 0.55; }
.rrow.down .rarea { color: var(--accent); }

#banner {
  position: absolute; top: 26%; left: 50%; transform: translateX(-50%);
  font-family: 'Titan One', sans-serif; font-size: clamp(26px, 4.5vw, 44px); color: #fff;
  text-shadow: 0 4px 0 rgba(0,0,0,0.35), 0 12px 30px rgba(0,0,0,0.4);
  animation: bannerIn 0.35s cubic-bezier(0.2, 1.6, 0.4, 1);
  white-space: nowrap; pointer-events: none; z-index: 3;
}
@keyframes bannerIn { from { transform: translateX(-50%) scale(0.4); opacity: 0; } }

#hint {
  position: absolute; bottom: 150px; left: 50%; transform: translateX(-50%);
  color: #2ed573; font-family: 'Titan One', sans-serif; font-size: 22px;
  text-shadow: 0 2px 0 rgba(0,0,0,0.55);
  white-space: nowrap; pointer-events: none;
}

#downOverlay {
  position: absolute; top: 34%; left: 50%; transform: translateX(-50%);
  text-align: center; pointer-events: none; z-index: 3;
}
#downTitle { font-family: 'Titan One', sans-serif; font-size: 44px; color: var(--accent); text-shadow: 0 3px 0 rgba(0,0,0,0.5); }
#downSub { font-weight: 800; color: #fff; font-size: 15px; text-shadow: 0 1px 3px rgba(0,0,0,0.6); }
#downTimer { font-family: 'Titan One', sans-serif; font-size: 64px; color: #fff; text-shadow: 0 4px 0 rgba(0,0,0,0.5); }

/* ---------- bottom dock: one clean panel, XP strip on top ---------- */
#dock {
  position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%);
  background: rgba(13, 19, 34, 0.92); border: 1px solid rgba(255,255,255,0.12);
  border-radius: 16px; overflow: hidden;
  display: flex; flex-direction: column;
  box-shadow: 0 6px 20px rgba(0,0,0,0.4);
  pointer-events: none;
}
/* XP-to-next-level: the top strip of the dock (under the map, over the stats) */
#xpWrap {
  position: relative; width: 100%; height: 15px;
  background: rgba(255,255,255,0.07);
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
#xpBar {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, #7a5cff, #b06cff);
  transition: width 0.12s linear;
}
#xpText {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-weight: 900; font-size: 9px; letter-spacing: 1.5px; color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.85);
}

#dockRow { display: flex; gap: 6px; align-items: stretch; padding: 9px 14px 10px; }

.dhero { display: flex; align-items: center; gap: 8px; padding-right: 12px; margin-right: 4px; border-right: 1px solid rgba(255,255,255,0.1); }
#dHeroDot { width: 20px; height: 20px; border-radius: 50%; background: var(--accent); flex-shrink: 0; }
.dhtext { display: flex; flex-direction: column; line-height: 1.05; }
#dHeroName { color: #fff; font-weight: 900; font-size: 14px; letter-spacing: 0.3px; }
#dLevel { color: var(--mustard); font-weight: 900; font-size: 11px; }
#dPts {
  color: #5c4a00; font-weight: 900; font-size: 11px;
  background: var(--mustard); border-radius: 8px; padding: 3px 8px;
  animation: pulse 0.7s infinite alternate;
}
@keyframes pulse { to { transform: scale(1.08); } }

/* uniform stat / ability columns */
.dcol {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  min-width: 64px; padding: 3px 6px 2px; border-radius: 10px;
  transition: background 0.12s;
}
.dcol .clabel { color: #8fa0c4; font-weight: 800; font-size: 10px; letter-spacing: 0.2px; }
.dcol .cval { color: #fff; font-weight: 900; font-size: 16px; line-height: 1.1; }
.dcol .csub { color: var(--mustard); font-weight: 800; font-size: 8.5px; }
.dkey {
  position: absolute; top: -6px; right: -3px;
  background: var(--mustard); color: #5c4a00;
  font-weight: 900; font-size: 9px; border-radius: 5px; padding: 0 4px;
}
/* when you have unspent points, glow the tiles you can spend on */
#dock.haspts .dcol { background: rgba(255, 211, 42, 0.14); box-shadow: 0 0 0 1px rgba(255,211,42,0.4) inset; }
/* maxed stats can't take more points — dim them and drop the glow */
.dcol.maxed { opacity: 0.5; }
.dcol.maxed .dkey { display: none; }
#dock.haspts .dcol.maxed { background: none; box-shadow: none; }

#energyWrap {
  position: relative; width: 120px; align-self: center; height: 22px; border-radius: 999px;
  background: rgba(255,255,255,0.12); overflow: hidden; margin-left: 4px;
  border: 1px solid rgba(94, 231, 255, 0.4);
}
#energyBar { height: 100%; width: 100%; background: linear-gradient(90deg, #2f7bd6, #5ee7ff); transition: width 0.15s; }
#energyText {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-weight: 900; font-size: 11px; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,0.7);
}

#toasts {
  position: absolute; bottom: 128px; right: 14px;
  display: flex; flex-direction: column; gap: 6px; align-items: flex-end; pointer-events: none;
}
.toast {
  background: rgba(13, 19, 34, 0.85); color: #fff; border-radius: 10px;
  padding: 8px 14px; font-weight: 800; font-size: 13px;
  animation: toastIn 0.25s ease-out;
}
@keyframes toastIn { from { transform: translateX(30px); opacity: 0; } }

@media (max-width: 1150px), (max-height: 700px) {
  #dock { transform: translateX(-50%) scale(0.8); transform-origin: bottom center; }
  #roster { transform: scale(0.85); transform-origin: top right; }
}

.dab.on { background: rgba(255, 160, 60, 0.28) !important; box-shadow: 0 0 10px rgba(255, 160, 60, 0.5) inset !important; }
.dab.on .cval, .dab.on .clabel { color: #ffb056; }
.dstat:hover .cval, .dab:hover .cval { color: var(--mustard); }

/* ---------- dock hover tooltip (evades-style) ---------- */
#tip {
  position: absolute; transform: translateX(-50%);
  background: rgba(13, 19, 34, 0.96); border: 1px solid rgba(255,255,255,0.18);
  border-radius: 12px; padding: 11px 16px;
  display: flex; flex-direction: column; gap: 4px; align-items: center;
  max-width: 300px; text-align: center;
  pointer-events: none; z-index: 20;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}
#tip .tipname { color: #fff; font-weight: 900; font-size: 14px; }
#tip .tipname em { font-style: normal; color: var(--mustard); }
#tip .tipdesc { color: #aab6cf; font-weight: 700; font-size: 11.5px; line-height: 1.35; }
#tip .tipprog { color: #7ec3ff; font-weight: 800; font-size: 12px; }
#tip .tipprog b { color: var(--mustard); font-size: 13px; }
#tip .tipprog small { color: #6a768f; font-size: 9.5px; }
#tip .tipkey { color: #6a768f; font-weight: 800; font-size: 9.5px; letter-spacing: 0.5px; }

/* ---------- rotate-to-landscape prompt ---------- */
#rotate { display: none; }
@media (orientation: portrait) {
  body.touch #rotate {
    position: fixed; inset: 0; z-index: 100;
    background: #0a0e1a; color: #fff;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 18px; text-align: center; padding: 30px;
  }
  body.touch #stage { display: none; }
}
#rotate .rotico { font-size: 64px; animation: rot 2s ease-in-out infinite; }
#rotate .rottxt { font-weight: 800; font-size: 19px; color: #aab6cf; line-height: 1.5; }
#rotate .rottxt b { color: var(--mustard); }
@keyframes rot { 0%,55% { transform: rotate(0deg); } 75%,100% { transform: rotate(-90deg); } }

/* ---------- mobile touch controls ---------- */
#stick, #stickKnob, #touchAbilities { display: none; }
body.touch #touchAbilities { display: flex; }
#stick, #stickKnob {
  position: fixed; z-index: 8; pointer-events: none;
  border-radius: 50%; transform: translate(-50%, -50%);
}
#stick {
  width: 130px; height: 130px;
  background: rgba(255,255,255,0.08); border: 2px solid rgba(255,255,255,0.25);
}
#stickKnob {
  width: 62px; height: 62px;
  background: rgba(255,255,255,0.28); border: 2px solid rgba(255,255,255,0.55);
  box-shadow: 0 2px 10px rgba(0,0,0,0.4);
}
body.touch #stick.on, body.touch #stickKnob.on { display: block; }
#touchAbilities {
  position: absolute; right: 16px; bottom: 132px; z-index: 8;
  flex-direction: column; gap: 12px; pointer-events: auto;
}
.abtn {
  width: 74px; height: 74px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.35);
  background: rgba(13, 19, 34, 0.82); color: #fff;
  font-family: 'Nunito', sans-serif; font-weight: 900; font-size: 13px;
  line-height: 1.05; letter-spacing: 0.3px;
  display: flex; align-items: center; justify-content: center; text-align: center;
  box-shadow: 0 3px 12px rgba(0,0,0,0.4);
  -webkit-tap-highlight-color: transparent;
}
.abtn:active { transform: scale(0.94); background: rgba(46, 213, 115, 0.3); }
.abtn.on { background: rgba(255, 160, 60, 0.35); border-color: #ffb056; color: #ffd9ad; box-shadow: 0 0 14px rgba(255,160,60,0.5); }

/* ---------- escape menu ---------- */
#gameMenu {
  position: absolute; inset: 0; z-index: 50;
  background: rgba(10, 14, 26, 0.78);
  display: flex; align-items: center; justify-content: center;
  pointer-events: auto;
}
.menuCard {
  background: var(--panel); border-radius: 22px;
  padding: 28px 34px; width: min(560px, calc(100vw - 40px));
  max-height: 86vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 14px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.5);
}
.menuTitle { font-family: 'Titan One', sans-serif; font-size: 26px; color: var(--accent); text-align: center; }
.menuHelp { display: flex; flex-direction: column; gap: 8px; font-weight: 700; font-size: 13.5px; color: #55607a; line-height: 1.45; }
.menuHelp b { color: var(--ink); }
.menuHubBtn { text-align: center; text-decoration: none; display: block; }

/* ---------- escape menu legend (visual reference, not a wall of text) ---------- */
.legendLabel { font-weight: 900; font-size: 11px; letter-spacing: 2.5px; color: #97a0b5; margin-top: 6px; }
.legend { display: grid; grid-template-columns: 1fr 1fr; gap: 7px 14px; }
.lrow {
  display: flex; align-items: center; gap: 11px;
  background: #f4f6fb; border-radius: 11px; padding: 7px 11px;
  min-height: 46px;
}
.lrow .lico {
  width: 34px; height: 34px; flex-shrink: 0; font-size: 22px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
}
.lrow .lorb { border-radius: 50%; border: 3px solid rgba(0,0,0,0.45); }
.lrow .lzone { width: 30px; height: 30px; border-radius: 7px; }
.lrow .ltxt { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.lrow .ltxt b { font-size: 12px; color: var(--ink); letter-spacing: 0.3px; }
.lrow .ltxt small { font-size: 10.5px; color: #7a8296; font-weight: 700; }
.lrow.wide { grid-column: 1 / -1; }
@media (max-width: 700px) { .legend { grid-template-columns: 1fr; } }
