:root {
  --bg: #10222c;
  --bg-2: #17303c;
  --raised: #1d3c4a;
  --line: rgba(255, 255, 255, 0.08);
  --text: #eef8f4;
  --muted: #8aa8b3;
  --accent: #2ee6a6;
  --accent-2: #3ce0d0;
  --gold: #ffc14d;
  --lava: #ff5a1f;
  --pink: #ff5dad;
  --blue: #3aa7ff;
  --shadow: 0 18px 24px rgba(6, 16, 28, 0.34);
  --radius: 14px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --pop: cubic-bezier(0.34, 1.56, 0.64, 1);
  --font-d: "Cairo", "Tajawal", sans-serif;
  --font-b: "Tajawal", "Cairo", sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; background: #0a1628; color: var(--text); }
html, body, #app { overflow: hidden; }
body {
  font-family: var(--font-b);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
#app {
  position: relative;
  width: 100%;
  height: 100%;
  background: #0a1628;
  color: var(--text);
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
button, .stat, .sheet, .heroes, h1, h2 { user-select: none; -webkit-user-select: none; }
img { display: block; max-width: 100%; }
button {
  font-family: inherit;
  border: 0;
  cursor: pointer;
  color: inherit;
  background: none;
}
button:focus-visible, .hero-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

#viewport {
  position: absolute;
  inset: 0;
  z-index: 0;
  background: #8ad8f8;
}
#viewport canvas {
  display: block;
  width: 100%;
  height: 100%;
}
#vignette {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background:
    radial-gradient(120% 80% at 50% 18%, transparent 55%, rgba(8, 22, 48, 0.14) 100%),
    linear-gradient(to top, rgba(8, 24, 36, 0.16), transparent 24%);
}

.screen, .overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
}
.screen { z-index: 12; }
#hud { z-index: 14; }
.hidden { display: none !important; }

#screen-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, rgba(12, 28, 36, 0.72), rgba(12, 28, 36, 0.88));
  color: var(--text);
}
.load-card {
  width: min(360px, calc(100% - 40px));
  text-align: center;
  padding: 32px 24px;
}
.logo-mark {
  display: flex;
  justify-content: center;
  gap: 8px;
  height: 56px;
  align-items: flex-end;
  margin-bottom: 16px;
}
.logo-cube {
  width: 22px;
  border-radius: 6px;
  display: block;
}
.logo-cube.c1 { height: 22px; background: #2ee6a6; }
.logo-cube.c2 { height: 36px; background: #ffc14d; }
.logo-cube.c3 { height: 28px; background: #3aa7ff; }
@media (prefers-reduced-motion: no-preference) {
  .logo-cube.c1 { animation: bob 1.4s var(--pop) infinite; }
  .logo-cube.c2 { animation: bob 1.4s var(--pop) infinite 0.12s; }
  .logo-cube.c3 { animation: bob 1.4s var(--pop) infinite 0.24s; }
}
@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}
.display {
  font-family: var(--font-d);
  font-weight: 900;
  letter-spacing: -0.02em;
  line-height: 1.15;
}
#screen-loading h1 { font-size: 34px; margin-bottom: 8px; color: var(--text); }
#load-status { color: var(--muted); margin-bottom: 20px; }
.bar {
  height: 8px;
  background: rgba(255,255,255,0.08);
  border-radius: 99px;
  overflow: hidden;
}
#load-bar {
  height: 100%;
  width: 8%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-radius: 99px;
  transition: width 280ms var(--ease);
}

#screen-menu {
  overflow: auto;
  background:
    radial-gradient(ellipse 90% 48% at 50% 10%, rgba(255, 196, 92, 0.28) 0%, rgba(255, 168, 64, 0.1) 32%, transparent 62%),
    linear-gradient(180deg, rgba(6, 14, 36, 0.66) 0%, rgba(7, 16, 40, 0.86) 36%, rgba(5, 12, 30, 0.96) 100%);
  color: var(--text);
}
.menu-inner {
  width: min(720px, 100%);
  margin: 0 auto;
  padding: 28px 20px 36px;
}
.menu-hero {
  position: relative;
  text-align: center;
  margin-bottom: 28px;
}
.menu-hero::before {
  content: "";
  position: absolute;
  left: 50%;
  top: -8px;
  transform: translateX(-50%);
  width: min(460px, 96%);
  height: 200px;
  background: radial-gradient(ellipse at center, rgba(255, 198, 96, 0.38) 0%, rgba(255, 164, 72, 0.14) 42%, transparent 72%);
  pointer-events: none;
  z-index: 0;
  filter: blur(6px);
}
.menu-hero > * { position: relative; z-index: 1; }
.eyebrow {
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent-2);
  font-weight: 700;
  margin-bottom: 8px;
}
.eyebrow.gold { color: var(--gold); }
.title-xl {
  font-size: clamp(34px, 10vw, 48px);
  color: #f7fbfc;
  text-shadow: 0 0 42px rgba(255, 196, 92, 0.38), 0 10px 24px rgba(6, 14, 28, 0.45);
}
.lede {
  color: #f2f7f8;
  max-width: 28em;
  margin: 10px auto 0;
  text-shadow: 0 2px 16px rgba(6, 14, 28, 0.5);
}
.best-pill {
  display: inline-flex;
  align-items: baseline;
  gap: 10px;
  margin-top: 16px;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(16, 34, 44, 0.72);
  color: var(--text);
  border: 1px solid var(--line);
  box-shadow: 0 16px 24px rgba(6, 16, 28, 0.3);
}
.pill-label { color: var(--muted); font-size: 13px; }
.best-pill strong { font-family: var(--font-d); font-size: 18px; color: var(--gold); }

.block { margin-bottom: 24px; }
.block-head { margin-bottom: 12px; }
.block-head h2 {
  font-family: var(--font-d);
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text);
}
.block-head p { color: #e8f1f4; font-size: 13px; }

.heroes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.hero-card {
  --hero-col: #2ee6a6;
  --hero-sec: #ffc14d;
  position: relative;
  text-align: center;
  border-radius: var(--radius);
  padding: 16px 12px 18px;
  background: #163644;
  color: var(--text);
  border: 1px solid color-mix(in srgb, var(--hero-col) 28%, rgba(255,255,255,0.06));
  min-height: 188px;
  box-shadow:
    0 0 0 1px color-mix(in srgb, var(--hero-col) 22%, transparent),
    0 0 18px color-mix(in srgb, var(--hero-col) 18%, transparent),
    0 18px 24px rgba(6, 16, 28, 0.34);
  transition: transform 160ms var(--ease), border-color 160ms var(--ease), background 160ms var(--ease), box-shadow 160ms var(--ease);
}
.hero-card:active { transform: scale(0.97); }
.hero-card.is-on {
  border-color: color-mix(in srgb, var(--hero-col) 80%, #fff);
  background: #1a4250;
  box-shadow:
    0 0 0 2px color-mix(in srgb, var(--hero-col) 72%, transparent),
    0 0 26px color-mix(in srgb, var(--hero-col) 42%, transparent),
    0 20px 24px rgba(6, 16, 28, 0.38);
}
.hero-bust {
  position: relative;
  display: block;
  width: 86px;
  height: 90px;
  margin: 0 auto 12px;
  perspective: 260px;
}
.hero-bust::after {
  content: "";
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 4px;
  height: 12px;
  background: radial-gradient(ellipse, rgba(0,0,0,0.38), transparent 72%);
  filter: blur(2px);
}
.bust-glow {
  position: absolute;
  inset: 14% 8% 6%;
  border-radius: 50%;
  background: radial-gradient(circle, color-mix(in srgb, var(--hero-col) 58%, transparent), transparent 72%);
  filter: blur(7px);
}
.bust-stage {
  position: absolute;
  inset: 0;
  transform: rotateY(-20deg) rotateX(10deg);
  transform-style: preserve-3d;
}
.bust-torso,
.bust-head,
.bust-arm,
.bust-hat {
  display: block;
  position: absolute;
}
.bust-torso {
  width: 38px;
  height: 34px;
  left: 24px;
  bottom: 10px;
  border-radius: 7px;
  background:
    linear-gradient(90deg, rgba(0,0,0,0.2), transparent 30%, transparent 70%, rgba(255,255,255,0.16)),
    linear-gradient(165deg, color-mix(in srgb, var(--hero-col) 62%, #fff) 0%, var(--hero-col) 48%, color-mix(in srgb, var(--hero-col) 62%, #000) 100%);
  box-shadow: 6px 8px 0 rgba(0,0,0,0.16), 0 10px 14px rgba(0,0,0,0.2);
}
.bust-arm {
  width: 11px;
  height: 26px;
  bottom: 16px;
  border-radius: 4px;
  background: linear-gradient(165deg, color-mix(in srgb, var(--hero-col) 55%, #fff), color-mix(in srgb, var(--hero-col) 70%, #000));
  box-shadow: 3px 4px 0 rgba(0,0,0,0.14);
}
.bust-arm.l { left: 16px; transform: rotate(12deg); }
.bust-arm.r { left: 59px; transform: rotate(-12deg); }
.bust-head {
  width: 30px;
  height: 30px;
  left: 28px;
  top: 16px;
  border-radius: 7px;
  z-index: 2;
  background: linear-gradient(155deg, #ffe3c8 0%, #f0c2a0 46%, #c98a68 100%);
  box-shadow: 5px 6px 0 rgba(0,0,0,0.14), inset 0 1px 0 rgba(255,255,255,0.35);
}
.bust-hat { z-index: 3; }
.hero-bust[data-hat="helm"] .bust-hat {
  width: 34px;
  height: 13px;
  left: 26px;
  top: 11px;
  border-radius: 5px 5px 3px 3px;
  background: linear-gradient(165deg, color-mix(in srgb, var(--hero-sec) 55%, #fff), var(--hero-sec));
  box-shadow: 4px 4px 0 rgba(0,0,0,0.16);
}
.hero-bust[data-hat="horns"] .bust-hat::before,
.hero-bust[data-hat="horns"] .bust-hat::after {
  content: "";
  position: absolute;
  width: 9px;
  height: 20px;
  top: 6px;
  border-radius: 4px 4px 2px 2px;
  background: linear-gradient(180deg, #ffe7a8, var(--hero-sec));
  box-shadow: 3px 4px 0 rgba(0,0,0,0.15);
}
.hero-bust[data-hat="horns"] .bust-hat::before { left: 24px; transform: rotate(-22deg); }
.hero-bust[data-hat="horns"] .bust-hat::after { left: 53px; transform: rotate(22deg); }
.hero-bust[data-hat="hat"] .bust-hat {
  width: 20px;
  height: 28px;
  left: 33px;
  top: 0;
  background: linear-gradient(180deg, color-mix(in srgb, var(--hero-col) 45%, #fff), var(--hero-col));
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
  filter: drop-shadow(3px 4px 0 rgba(0,0,0,0.16));
}
.hero-bust[data-hat="hat"] .bust-hat::after {
  content: "";
  position: absolute;
  width: 40px;
  height: 6px;
  left: -10px;
  bottom: -1px;
  background: var(--hero-sec);
  border-radius: 3px;
}
.hero-bust[data-hat="hood"] .bust-hat {
  width: 40px;
  height: 30px;
  left: 23px;
  top: 10px;
  border-radius: 16px 16px 7px 7px;
  background: linear-gradient(180deg, color-mix(in srgb, var(--hero-col) 35%, var(--hero-sec)), var(--hero-sec));
  box-shadow: 4px 5px 0 rgba(0,0,0,0.16);
  z-index: 1;
}
.hero-bust[data-hat="hood"] .bust-head {
  width: 26px;
  height: 24px;
  left: 30px;
  top: 22px;
}
@media (prefers-reduced-motion: no-preference) {
  .bust-stage { animation: bust-idle 4.6s ease-in-out infinite; }
}
@keyframes bust-idle {
  0%, 100% { transform: rotateY(-20deg) rotateX(10deg) translateY(0); }
  50% { transform: rotateY(-8deg) rotateX(8deg) translateY(-3px); }
}
.hero-card h3 {
  font-family: var(--font-d);
  font-size: 18px;
  font-weight: 800;
  color: #f7fbfc;
}
.hero-card p { color: #e4eef2; font-size: 13px; line-height: 1.45; }
.hero-check {
  position: absolute;
  top: 12px;
  inset-inline-end: 12px;
  width: 22px;
  height: 22px;
  border-radius: 99px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #10222c;
  display: none;
  place-items: center;
  font-size: 13px;
  font-weight: 800;
}
.hero-card.is-on .hero-check { display: grid; }
.hero-card.is-wait { opacity: 0.7; }

.menu-actions { display: flex; flex-direction: column; gap: 10px; }
.row-btns { display: flex; gap: 10px; }
.row-btns .btn { flex: 1; }

.btn {
  min-height: 48px;
  border-radius: 14px;
  padding: 12px 16px;
  font-weight: 700;
  font-size: 15px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 16px 22px rgba(6, 16, 28, 0.28);
  transition: transform 120ms ease-out, filter 160ms var(--ease), background 160ms var(--ease), box-shadow 160ms var(--ease);
}
.btn:active { transform: scale(0.97); }
.btn.primary {
  border-radius: 20px;
  background: linear-gradient(180deg, #5af3c8 0%, #2ee6a6 46%, #27d4b4 100%);
  color: #0b1e28;
  font-weight: 800;
  box-shadow:
    0 18px 24px rgba(6, 18, 28, 0.3),
    0 0 28px rgba(60, 224, 208, 0.42),
    inset 0 1px 0 rgba(255, 255, 255, 0.62),
    inset 0 -2px 0 rgba(10, 80, 70, 0.14);
}
.btn.primary:active {
  background: linear-gradient(180deg, #1aa882 0%, #148f70 100%);
  color: #041318;
  box-shadow:
    0 8px 16px rgba(6, 18, 28, 0.32),
    0 0 14px rgba(40, 180, 168, 0.22),
    inset 0 2px 8px rgba(6, 36, 32, 0.28);
}
.btn.primary:disabled {
  filter: grayscale(0.4);
  opacity: 0.55;
}
.btn.ghost {
  background: var(--raised);
  color: #f4fbf8;
  border: 1px solid var(--line);
  box-shadow: 0 16px 22px rgba(6, 16, 28, 0.28);
}
.btn.xl {
  min-height: 56px;
  font-size: 18px;
  font-family: var(--font-d);
  font-weight: 800;
  border-radius: 20px;
}

#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
#hud > * { pointer-events: none; }
#hud .icon-btn, #controls #stick, #btn-jump { pointer-events: auto; }

.hud-top {
  display: flex;
  align-items: stretch;
  gap: 8px;
  padding: 10px 10px 0;
}
.stat {
  flex: 1 1 0;
  min-width: 0;
  padding: 8px 10px;
  border-radius: 12px;
  color: var(--text);
}
.stat-k {
  display: block;
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--muted);
  line-height: 1.2;
}
.stat strong {
  display: block;
  font-family: var(--font-d);
  font-size: 16px;
  font-weight: 800;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stat-time { flex: 1.15; }
.stat-time strong { color: var(--gold); }
.glass {
  background: rgba(16, 34, 44, 0.72);
  color: var(--text);
  border: 1px solid var(--line);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}
.icon-btn {
  width: 48px;
  height: 48px;
  flex: 0 0 48px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: var(--text);
}
.icon-btn:active { transform: scale(0.96); }

#stage-banner, #toast, #countdown {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  pointer-events: none;
}
#stage-banner {
  top: 72px;
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(16, 34, 44, 0.82);
  color: var(--text);
  border: 1px solid var(--line);
  font-family: var(--font-d);
  font-weight: 800;
  font-size: 15px;
  max-width: calc(100% - 24px);
}
#toast {
  top: 118px;
  padding: 8px 14px;
  border-radius: 12px;
  background: rgba(16, 34, 44, 0.86);
  color: var(--text);
  font-size: 14px;
  max-width: min(320px, calc(100% - 32px));
}
#countdown {
  top: 38%;
  font-family: var(--font-d);
  font-weight: 900;
  font-size: clamp(64px, 18vw, 96px);
  color: #eef8f4;
  text-shadow: 0 8px 28px rgba(8, 18, 24, 0.45);
  letter-spacing: -0.03em;
}

#controls {
  position: absolute;
  inset-inline: 12px;
  bottom: 16px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  pointer-events: none;
}
#stick {
  width: 132px;
  height: 132px;
  pointer-events: auto;
  touch-action: none;
}
.stick-base {
  width: 132px;
  height: 132px;
  border-radius: 50%;
  background: rgba(16, 34, 44, 0.55);
  border: 1px solid rgba(255,255,255,0.1);
  position: relative;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.stick-ring {
  position: absolute;
  inset: 18px;
  border-radius: 50%;
  border: 2px dashed rgba(238, 248, 244, 0.16);
}
#stick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 58px;
  height: 58px;
  margin: -29px 0 0 -29px;
  border-radius: 50%;
  background: linear-gradient(160deg, #3ce0d0, #2ee6a6);
  box-shadow: 0 8px 18px rgba(8, 20, 24, 0.35);
  border: 2px solid rgba(255,255,255,0.35);
}
#stick.is-hold .stick-base { background: rgba(16, 34, 44, 0.72); }

#btn-jump {
  width: 76px;
  height: 76px;
  border-radius: 50%;
  pointer-events: auto;
  touch-action: none;
  background: linear-gradient(160deg, #ffd36a, #ff9a2e);
  color: #3a2408;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  box-shadow: 0 10px 22px rgba(80, 36, 4, 0.35);
  border: 2px solid rgba(255,255,255,0.28);
}
#btn-jump:active, #btn-jump.is-hold {
  transform: scale(0.94);
  filter: brightness(0.95);
}
.jump-glyph { display: grid; place-items: center; line-height: 0; }
.jump-label {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.04em;
  margin-top: -2px;
}

.overlay {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(8, 16, 22, 0.55);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: 16px;
  color: var(--text);
}
.sheet {
  width: min(420px, 100%);
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 24px 20px 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.sheet h2 {
  font-family: var(--font-d);
  font-size: 24px;
  font-weight: 900;
  letter-spacing: -0.02em;
  color: var(--text);
}
.muted { color: var(--muted); }
.sheet-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 6px 0 8px;
}
.sheet-stats > div, .win-cell {
  background: var(--bg-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
}
.sheet-stats span, .win-cell span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}
.sheet-stats strong, .win-cell strong {
  font-family: var(--font-d);
  font-size: 18px;
  color: var(--text);
}
.win-sheet { align-items: stretch; text-align: center; }
.time-hero {
  font-family: var(--font-d);
  font-size: 48px;
  font-weight: 900;
  letter-spacing: -0.03em;
  line-height: 1;
  color: var(--gold);
  margin: 4px 0;
}
#record-badge {
  align-self: center;
  background: linear-gradient(135deg, var(--gold), #ff8a3d);
  color: #3a2408;
  font-weight: 800;
  font-size: 13px;
  padding: 4px 12px;
  border-radius: 999px;
}
.win-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.splits {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: start;
  max-height: 132px;
  overflow: auto;
}
.splits li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 4px;
  color: var(--muted);
  font-size: 13px;
  border-bottom: 1px solid var(--line);
}
.splits strong { color: var(--text); font-weight: 700; }

.help-list { list-style: none; display: flex; flex-direction: column; gap: 10px; margin: 4px 0 10px; }
.help-list li { display: flex; gap: 10px; align-items: flex-start; }
.help-list strong { display: block; color: var(--text); font-size: 14px; }
.help-list span { color: var(--muted); font-size: 13px; }
.dot {
  width: 12px;
  height: 12px;
  border-radius: 99px;
  margin-top: 6px;
  flex: 0 0 12px;
}
.dot.mint { background: var(--accent); }
.dot.gold { background: var(--gold); }
.dot.blue { background: var(--blue); }
.dot.pink { background: var(--pink); }
.dot.lava { background: var(--lava); }

@media (min-width: 720px) {
  .heroes { grid-template-columns: repeat(4, 1fr); gap: 14px; }
  .overlay { align-items: center; }
  #screen-menu {
    display: flex;
    align-items: flex-end;
    justify-content: center;
  }
  .menu-inner {
    width: min(780px, 100%);
    padding: 20px 28px 52px;
  }
  .menu-hero { margin-bottom: 16px; }
  .block { margin-bottom: 14px; }
  .block-head { margin-bottom: 10px; }
  .hero-card { min-height: 228px; padding: 18px 14px 20px; }
  .menu-actions { gap: 10px; }
}
@media (max-width: 389px) {
  .stat strong { font-size: 14px; }
  #stick { width: 118px; height: 118px; }
  .stick-base { width: 118px; height: 118px; }
  #btn-jump { width: 68px; height: 68px; }
  .hud-top { gap: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}