:root {
  --bg: #26262b;
  --dot: #34343b;
  --panel: #15151c;
  --panel-2: #20202b;
  --line: #2e2e3c;
  --ink: #ffffff;
  --muted: #9aa0b5;
  --yellow: #ffd91a;
  --yellow-deep: #c99a00;
  --blue: #2a3fd0;
  --blue-deep: #1a2890;
  --red: #ff3d5a;
  --green: #3ecb4f;
  --font: "Arial Rounded MT Bold", "Nunito", "Baloo 2", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-weight: 800;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#view {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

button { font: inherit; color: inherit; border: 0; cursor: pointer; }
button:disabled { cursor: not-allowed; }

/* ---- shared pieces ------------------------------------------------------ */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 16px;
  background: rgba(16, 16, 24, 0.86);
  font-size: 22px;
  line-height: 1;
  letter-spacing: 0.5px;
  font-variant-numeric: tabular-nums;
}
.ico { width: 26px; height: 26px; flex: none; }

.lv-badge {
  display: inline-block;
  padding: 3px 7px;
  border-radius: 7px;
  background: linear-gradient(#4f7dff, #2a3fd0);
  font-size: 0.72em;
  line-height: 1;
}

.coin {
  display: inline-block;
  width: 1em;
  height: 1em;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff6b0 0 18%, var(--yellow) 19% 62%, var(--yellow-deep) 63%);
  box-shadow: 0 0 0 2px #111;
  vertical-align: -0.12em;
}

.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 132px;
  padding: 14px 24px;
  border-radius: 16px;
  background: #3a3a4a;
  box-shadow: 0 6px 0 #1b1b25, 0 0 0 3px #111;
  font-size: 22px;
  letter-spacing: 1px;
  transition: transform 0.06s, box-shadow 0.06s, filter 0.1s;
}
.btn:hover { filter: brightness(1.1); }
.btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #1b1b25, 0 0 0 3px #111; }
.btn.primary { background: var(--yellow); color: #1a1500; box-shadow: 0 6px 0 var(--yellow-deep), 0 0 0 3px #111; }
.btn.primary:active { box-shadow: 0 2px 0 var(--yellow-deep), 0 0 0 3px #111; }
.btn.blue { background: #3d5bff; box-shadow: 0 6px 0 var(--blue-deep), 0 0 0 3px #111; }
.btn.blue:active { box-shadow: 0 2px 0 var(--blue-deep), 0 0 0 3px #111; }
.btn:disabled { filter: grayscale(0.9) brightness(0.7); }
.btn.small { min-width: 0; padding: 8px 14px; font-size: 16px; border-radius: 12px; box-shadow: 0 4px 0 #1b1b25, 0 0 0 2px #111; }
.btn.small.primary { box-shadow: 0 4px 0 var(--yellow-deep), 0 0 0 2px #111; }

.icon-btn {
  width: 42px;
  height: 42px;
  padding: 9px;
  border-radius: 14px;
  background: rgba(16, 16, 24, 0.86);
  color: #fff;
}
.icon-btn svg { width: 100%; height: 100%; display: block; }
.icon-btn.off .waves { display: none; }
.icon-btn.off { color: var(--muted); }

/* ---- HUD ---------------------------------------------------------------- */

#hud { position: fixed; inset: 0; pointer-events: none; }
#hud button { pointer-events: auto; }

.hud-left {
  position: absolute;
  left: max(14px, env(safe-area-inset-left));
  top: max(14px, env(safe-area-inset-top));
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
}
.timer { font-size: 28px; padding: 12px 20px; border-radius: 20px; min-width: 124px; justify-content: center; }
.timer.low { color: var(--red); animation: pulse 0.5s infinite alternate; }

.buffs { display: flex; flex-direction: column; gap: 6px; }
.buff {
  display: none;
  padding: 5px 10px;
  border-radius: 10px;
  font-size: 13px;
  letter-spacing: 1px;
  box-shadow: 0 0 0 2px #111;
}
.buff.on { display: inline-block; }
.buff.speed { background: #19c3ff; color: #00212e; }
.buff.shield { background: #4d7dff; }
.buff.magnet { background: #ff4d6d; }

.hud-top {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  padding: 7px 14px;
  border-radius: 12px;
  background: rgba(16, 16, 24, 0.86);
  font-size: 15px;
  letter-spacing: 3px;
  color: rgba(255, 255, 255, 0.8);
}
.hud-top:empty { display: none; }

.hud-right {
  position: absolute;
  right: max(14px, env(safe-area-inset-right));
  top: max(14px, env(safe-area-inset-top));
  width: 250px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}
.boss { width: 100%; justify-content: center; }
.boss.online .ico, .boss.online .lv-badge { display: none; }
.meter {
  width: 100%;
  height: 8px;
  border-radius: 4px;
  background: rgba(16, 16, 24, 0.86);
  overflow: hidden;
}
.meter i { display: block; height: 100%; width: 0; background: var(--red); transition: width 0.2s; }
.meter.full i { background: var(--green); }
.crown { width: 30px; margin: 2px 196px -4px 0; }

#hud-board { list-style: none; margin: 0; padding: 0; width: 100%; display: flex; flex-direction: column; gap: 6px; }
#hud-board li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-left: calc(var(--i) * 14px);
  padding: 7px 14px;
  border-radius: 12px;
  background: rgba(16, 16, 24, 0.86);
  font-size: 17px;
  font-variant-numeric: tabular-nums;
}
#hud-board li span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#hud-board li.me { background: var(--blue-deep); }

#banner {
  position: absolute;
  left: 50%;
  top: 24%;
  transform: translate(-50%, -50%) rotate(-3deg);
  font-size: clamp(40px, 9vw, 96px);
  white-space: nowrap;
  color: var(--yellow);
  -webkit-text-stroke: 3px #111;
  paint-order: stroke fill;
  text-shadow: 0 6px 0 #111;
  animation: pop 0.35s cubic-bezier(0.2, 2, 0.4, 1);
}
#banner.bad { color: var(--red); }
#banner.good { color: var(--green); }

#respawn {
  position: absolute;
  left: 50%;
  top: 60%;
  transform: translateX(-50%);
  padding: 10px 18px;
  border-radius: 14px;
  background: rgba(16, 16, 24, 0.86);
  font-size: 18px;
}

#btn-boost {
  position: absolute;
  right: max(22px, env(safe-area-inset-right));
  bottom: max(22px, env(safe-area-inset-bottom));
  width: 84px;
  height: 84px;
  padding: 20px;
  border-radius: 50%;
  color: #00212e;
  background: conic-gradient(#19c3ff var(--charge, 100%), rgba(16, 16, 24, 0.86) 0);
  box-shadow: 0 0 0 3px #111;
}
#btn-boost svg { width: 100%; height: 100%; display: block; }
#btn-boost.cooling { color: #5d6478; }

.hud-corner {
  position: absolute;
  left: max(14px, env(safe-area-inset-left));
  bottom: max(14px, env(safe-area-inset-bottom));
  display: flex;
  gap: 8px;
}

#stick {
  position: fixed;
  width: 120px;
  height: 120px;
  margin: -60px 0 0 -60px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.06);
  pointer-events: none;
}
#stick i {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 48px;
  height: 48px;
  margin: -24px 0 0 -24px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.4);
}

/* ---- screens ------------------------------------------------------------ */

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 28px;
  /* Installed as an app there is no browser chrome, so keep clear of notches and the home indicator. */
  padding: max(20px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right))
    max(20px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
  overflow: auto;
  -webkit-user-select: none;
  user-select: none;
}
#menu, .auth {
  background:
    radial-gradient(circle, var(--dot) 3px, transparent 3.5px) 0 0 / 56px 56px,
    radial-gradient(ellipse at 50% 30%, #33333b, var(--bg) 70%);
}
.overlay { background: rgba(10, 10, 16, 0.72); backdrop-filter: blur(3px); animation: fade 0.25s; }

.menu-main { display: flex; flex-direction: column; align-items: center; gap: 16px; width: min(560px, 100%); }

.logo {
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 0.92;
  font-size: clamp(54px, 11vw, 104px);
  letter-spacing: 2px;
  transform: rotate(-4deg);
  -webkit-text-stroke: 4px #111;
  paint-order: stroke fill;
  text-shadow: 0 8px 0 #111;
}
.logo span:first-child { color: var(--green); }
.logo span:last-child { color: var(--yellow); margin-left: 0.6em; }

#preview { width: 100%; max-width: 480px; height: auto; margin: -6px 0; }

.account {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px 14px;
  padding: 8px 18px;
  border-radius: 14px;
  background: rgba(16, 16, 24, 0.86);
}
.account .who { margin-right: 4px; font-size: 20px; }
.account form { display: contents; }
.account a, .account button {
  padding: 0;
  background: none;
  color: var(--muted);
  font-size: 14px;
  text-decoration: underline;
}
.account a:hover, .account button:hover { color: var(--ink); }

.stage-card {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 20px;
  border-radius: 16px;
  background: rgba(16, 16, 24, 0.86);
  font-size: 22px;
}
.stage-card b { color: var(--yellow); }
.boss-chip .lv-badge { background: linear-gradient(#ff6a7f, #d81e3c); margin-right: 4px; }

.play-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 16px; }
.play-row .btn.primary { min-width: 190px; font-size: 28px; }

.hint { margin: 4px 0 0; text-align: center; font-size: 13px; font-weight: 600; line-height: 1.5; color: var(--muted); }

.menu-side {
  width: min(400px, 100%);
  max-height: min(640px, 100%);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  border-radius: 22px;
  background: rgba(16, 16, 24, 0.9);
  box-shadow: 0 0 0 3px #111;
}
.wallet { display: flex; justify-content: space-between; align-items: center; font-size: 22px; }
.coins { display: flex; align-items: center; gap: 8px; color: var(--yellow); font-variant-numeric: tabular-nums; }
.best { font-size: 15px; color: var(--muted); }
.best b { color: var(--ink); }

.tabs { display: flex; gap: 6px; padding: 4px; border-radius: 14px; background: var(--panel-2); }
.tabs button { flex: 1; padding: 9px 4px; border-radius: 10px; background: transparent; color: var(--muted); font-size: 15px; }
.tabs button.on { background: var(--blue); color: #fff; }

.tab-body { overflow-y: auto; min-height: 0; display: flex; flex-direction: column; gap: 10px; padding: 2px; }

.upgrade {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  align-items: center;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--panel-2);
}
.upgrade h3 { margin: 0; font-size: 17px; }
.upgrade h3 small { margin-left: 6px; font-size: 12px; color: var(--muted); }
.upgrade p { margin: 0; font-size: 12px; font-weight: 600; color: var(--muted); }
.upgrade .effect { font-size: 14px; color: var(--green); }
.upgrade .effect i { font-style: normal; color: var(--muted); }
.upgrade .btn { grid-column: 2; grid-row: 1 / span 3; }
.pips { display: flex; gap: 2px; margin-top: 4px; }
.pips i { flex: 1; max-width: 14px; height: 5px; border-radius: 2px; background: var(--line); }
.pips i.on { background: var(--yellow); }

.skins { display: grid; grid-template-columns: repeat(auto-fill, minmax(106px, 1fr)); gap: 10px; }
.skin {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 6px 10px;
  border-radius: 14px;
  background: var(--panel-2);
  box-shadow: inset 0 0 0 3px transparent;
}
.skin canvas { width: 100%; height: auto; }
.skin.on { box-shadow: inset 0 0 0 3px var(--yellow); }
.skin.locked canvas { filter: saturate(0.8) brightness(0.85); }
.skin span { font-size: 12px; }
.skin em { font-style: normal; font-size: 13px; color: var(--yellow); display: flex; align-items: center; gap: 5px; }
.skin em.have { color: var(--green); }

.ranking { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.ranking li, #r-board li {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--panel-2);
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}
.ranking li span:nth-child(2), #r-board li span:nth-child(2) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ranking li:first-child { color: var(--yellow); }
.empty { margin: 12px 0; text-align: center; font-size: 14px; font-weight: 600; color: var(--muted); }

.card {
  width: min(460px, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 26px 24px;
  border-radius: 26px;
  background: var(--panel);
  box-shadow: 0 0 0 4px #111, 0 18px 0 rgba(0, 0, 0, 0.35);
  text-align: center;
  animation: pop 0.3s cubic-bezier(0.2, 1.6, 0.4, 1);
}
.card h2 {
  margin: 0;
  font-size: clamp(34px, 8vw, 52px);
  color: var(--yellow);
  -webkit-text-stroke: 2px #111;
  paint-order: stroke fill;
  text-shadow: 0 4px 0 #111;
  transform: rotate(-2deg);
}
.card.lost h2 { color: var(--red); }
.card p { margin: 0; font-size: 16px; font-weight: 600; color: var(--muted); }
.stats { display: flex; gap: 10px; width: 100%; }
.stats div { flex: 1; padding: 12px 6px; border-radius: 14px; background: var(--panel-2); }
.stats span { display: block; font-size: 12px; letter-spacing: 1px; text-transform: uppercase; color: var(--muted); }
.stats b { font-size: 26px; font-variant-numeric: tabular-nums; }
#r-coins { color: var(--yellow); }
#r-board { list-style: none; margin: 0; padding: 0; width: 100%; max-height: 220px; overflow-y: auto; display: flex; flex-direction: column; gap: 5px; text-align: left; }
#r-board li.me { background: var(--blue-deep); }

.countdown { width: 100%; height: 10px; border-radius: 5px; background: var(--panel-2); overflow: hidden; }
.countdown i { display: block; height: 100%; width: 100%; background: var(--yellow); transform-origin: left; }

#toast {
  position: fixed;
  left: 50%;
  bottom: max(28px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: 90vw;
  padding: 12px 20px;
  border-radius: 14px;
  background: var(--red);
  box-shadow: 0 0 0 3px #111;
  font-size: 16px;
  z-index: 10;
  animation: pop 0.25s;
}

/* ---- account pages -------------------------------------------------------- */

.auth {
  flex-direction: column;
  justify-content: flex-start;
  gap: 22px;
  padding-top: max(20px, 5vh, env(safe-area-inset-top));
}
.auth .logo { flex: none; font-size: clamp(40px, 9vw, 68px); }
.auth .card { flex: none; align-items: stretch; }
.auth .card h2 { align-self: center; }
.auth .card a { color: var(--yellow); }
.auth .btn { align-self: center; }
.auth form > div { display: flex; flex-direction: column; gap: 6px; text-align: left; }
.auth label { font-size: 14px; color: var(--muted); }
.auth input[type="text"], .auth input[type="password"] {
  width: 100%;
  padding: 12px 14px;
  border: 3px solid #111;
  border-radius: 12px;
  background: var(--panel-2);
  color: var(--ink);
  font: inherit;
  font-size: 18px;
  outline: none;
  -webkit-user-select: text;
  user-select: text;
}
.auth input:focus { border-color: var(--yellow); }
.auth .errorlist {
  list-style: none;
  margin: 0;
  padding: 8px 12px;
  border-radius: 10px;
  background: rgba(255, 61, 90, 0.16);
  color: #ff8a96;
  font-size: 13px;
  font-weight: 600;
  text-align: left;
}
.auth .helptext { font-size: 12px; font-weight: 600; line-height: 1.4; color: var(--muted); }
.auth .helptext ul { margin: 0; padding-left: 18px; }
/* Within a field: label, input, its errors, then the help text. Form-wide errors stay on top. */
.auth form > div > input { order: 1; }
.auth form > div > .errorlist { order: 2; }
.auth form > div > .helptext { order: 3; }

@keyframes pop { from { scale: 0.6; opacity: 0; } to { scale: 1; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pulse { from { scale: 1; } to { scale: 1.08; } }

@media (max-width: 900px) {
  #menu { flex-direction: column; justify-content: flex-start; gap: 18px; }
  .menu-side { max-height: none; }
  .tab-body { overflow: visible; }
}

@media (max-width: 640px) {
  .pill { font-size: 16px; padding: 6px 12px; }
  .timer { font-size: 20px; padding: 8px 14px; min-width: 92px; }
  .hud-right { width: 172px; }
  #hud-board li { font-size: 13px; padding: 5px 10px; margin-left: calc(var(--i) * 8px); }
  .crown { width: 22px; margin-right: 136px; }
  .hud-top { display: none; }
  #btn-boost { width: 72px; height: 72px; padding: 17px; }
}
