:root {
  --bg1: #1b1350;
  --bg2: #0a0a24;
  --panel: rgba(28, 24, 78, 0.94);
  --line: rgba(150, 160, 255, 0.28);
  --text: #f4f2ff;
  --muted: #b7b3e6;
  --accent: #ffcf40;
  --accent2: #ff9d2e;
  --good: #3ddc84;
  --ad: #8a5cff;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg2);
  color: var(--text);
  font-family: var(--font);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
}

#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(circle at 20% 15%, rgba(140, 90, 255, 0.35), transparent 40%),
    radial-gradient(circle at 85% 80%, rgba(40, 160, 255, 0.25), transparent 45%),
    linear-gradient(160deg, var(--bg1), var(--bg2));
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

button {
  font-family: inherit;
  color: inherit;
  cursor: pointer;
  border: 0;
  background: none;
}

/* ---------- HUD ---------- */
#hud {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px 0;
  height: clamp(54px, 9vh, 76px);
}

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
}

.icon-btn svg {
  width: 22px;
  height: 22px;
  fill: var(--text);
}

.scores {
  text-align: center;
  line-height: 1;
}

.score {
  font-size: clamp(26px, 5.2vh, 44px);
  font-weight: 900;
  letter-spacing: 1px;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.35);
}

.best {
  font-size: 13px;
  color: var(--muted);
  margin-top: 4px;
}

.best b {
  color: var(--accent);
}

.coin-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 96px;
  height: 40px;
  padding: 0 6px 0 8px;
  border-radius: 20px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--line);
  font-weight: 800;
  font-size: 16px;
}

.coin-pill .plus {
  margin-left: auto;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--good);
  color: #073b1d;
  position: relative;
  flex: 0 0 auto;
}

/* Plus drawn with two bars: a text "+" sits off-center depending on font metrics. */
.coin-pill .plus::before,
.coin-pill .plus::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 50%;
  height: 3px;
  border-radius: 2px;
  background: #073b1d;
  transform: translate(-50%, -50%);
}

.coin-pill .plus::after {
  transform: translate(-50%, -50%) rotate(90deg);
}

.coin {
  display: inline-block;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff6b0, var(--accent) 45%, var(--accent2));
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.25), 0 0 0 2px rgba(120, 60, 0, 0.35);
  flex: 0 0 auto;
}

/* ---------- stage ---------- */
#stage {
  flex: 1 1 auto;
  position: relative;
  min-height: 0;
}

#cv {
  position: absolute;
  inset: 0;
  display: block;
  touch-action: none;
}

/* ---------- boosters ---------- */
#boosters {
  flex: 0 0 auto;
  display: flex;
  justify-content: center;
  gap: clamp(8px, 3vw, 22px);
  padding: 4px 12px 10px;
}

.booster {
  position: relative;
  width: clamp(76px, 22vw, 108px);
  height: clamp(56px, 9vh, 72px);
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0.06));
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  transition: transform 0.08s;
}

.booster:active {
  transform: scale(0.95);
}

.booster svg {
  width: 26px;
  height: 26px;
  fill: var(--text);
  stroke: var(--text);
}

.booster .bname {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}

.booster .badge {
  position: absolute;
  top: -8px;
  right: -6px;
  min-width: 24px;
  height: 24px;
  padding: 0 6px;
  border-radius: 12px;
  background: var(--good);
  color: #062b15;
  font-weight: 900;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
}

.booster .badge.price {
  background: #2a2166;
  color: var(--accent);
  border: 1px solid var(--line);
}

.booster .badge .coin {
  width: 12px;
  height: 12px;
}

.booster.active {
  background: linear-gradient(180deg, #ff6a4d, #c8321a);
  border-color: #ffb199;
}

.booster.active .bname {
  color: #fff;
}

.booster:disabled {
  opacity: 0.4;
}

/* ---------- overlays ---------- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 16px;
  background: rgba(8, 6, 30, 0.72);
  backdrop-filter: blur(4px);
  z-index: 10;
  animation: fade 0.18s ease-out;
}

#scr-loading,
#scr-menu {
  background: linear-gradient(160deg, rgba(27, 19, 80, 0.97), rgba(10, 10, 36, 0.97));
}

.hidden {
  display: none !important;
}

@keyframes fade {
  from {
    opacity: 0;
  }
}

@keyframes pop {
  from {
    transform: scale(0.9);
    opacity: 0;
  }
}

.card {
  position: relative;
  width: min(92vw, 380px);
  max-height: 92%;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 22px 18px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  animation: pop 0.2s ease-out;
  touch-action: pan-y;
}

.card.wide {
  width: min(94vw, 460px);
}

.card h2 {
  margin: 0;
  font-size: 26px;
  font-weight: 900;
}

/* A long title wraps clear of the close button (×), on both sides so it stays centred. */
.card .close + h2 {
  padding: 0 34px;
}

.card h3 {
  margin: 6px 0 0;
  font-size: 15px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.close {
  position: absolute;
  top: 8px;
  right: 10px;
  width: 38px;
  height: 38px;
  font-size: 30px;
  line-height: 1;
  color: var(--muted);
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 13px;
}

/* The support address can be selected and copied (the page forbids selection elsewhere). */
#support-addr {
  text-align: center;
  user-select: text;
  -webkit-user-select: text;
}

.btn {
  min-height: 52px;
  padding: 0 18px;
  border-radius: 16px;
  font-size: 18px;
  font-weight: 800;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid var(--line);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.08s, filter 0.1s;
}

a.btn {
  color: inherit;
  text-decoration: none;
}

.btn:active {
  transform: scale(0.97);
}

.btn:hover {
  filter: brightness(1.12);
}

.btn.primary {
  background: linear-gradient(180deg, #ffd84d, #ff9f1c);
  color: #3a1d00;
  border: 0;
  box-shadow: 0 5px 0 #b86400;
}

.btn.ad {
  background: linear-gradient(180deg, #a57bff, #6a3de8);
  border: 0;
  box-shadow: 0 4px 0 #3f1fa3;
}

.btn.small {
  min-height: 44px;
  font-size: 15px;
  padding: 0 14px;
}

.btn:disabled {
  opacity: 0.45;
  filter: grayscale(0.6);
}

.ad-ic {
  width: 22px;
  height: 16px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.9);
  position: relative;
  flex: 0 0 auto;
}

.ad-ic::after {
  content: "";
  position: absolute;
  left: 8px;
  top: 4px;
  border-left: 7px solid #6a3de8;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
}

.col {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: min(80vw, 300px);
}

.row {
  display: flex;
  gap: 10px;
}

.row > * {
  flex: 1;
}

/* ---------- logo / menu ---------- */
.logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  font-weight: 900;
  font-size: 34px;
  line-height: 1;
  letter-spacing: 1px;
  text-align: center;
}

.logo span:nth-of-type(1) {
  background: linear-gradient(180deg, #9fe3ff, #5ab8ff 50%, #b88cff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.logo span:nth-of-type(2) {
  background: linear-gradient(180deg, #ffe066, #ff9f1c);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.logo.big {
  font-size: clamp(38px, 9vmin, 64px);
  filter: drop-shadow(0 6px 0 rgba(0, 0, 0, 0.35));
}

.menu-gems {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}

.menu-gems i {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  transform: rotate(45deg);
  animation: bob 2.4s ease-in-out infinite;
}

@keyframes bob {
  50% {
    transform: rotate(45deg) translate(-4px, -4px);
  }
}

.menu-best {
  color: var(--muted);
  font-size: 18px;
}

.menu-best b {
  color: var(--accent);
}

.spinner {
  width: 42px;
  height: 42px;
  border: 4px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* Under the spinner while the game waits for another device to save (one active session). */
.loading-note {
  margin: 18px 16px 0;
  max-width: 320px;
  text-align: center;
  font-weight: 700;
  line-height: 1.35;
  opacity: 0.85;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---------- game over ---------- */
.final {
  font-size: 56px;
  font-weight: 900;
  color: var(--accent);
  line-height: 1;
}

.record {
  color: var(--good);
  font-weight: 900;
  font-size: 20px;
}

.chance {
  border: 1px dashed var(--line);
  border-radius: 16px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chance-title {
  font-weight: 900;
  font-size: 18px;
}

/* ---------- shop ---------- */
.balance {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 24px;
}

.product {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--line);
  text-align: left;
  margin-bottom: 8px;
}

.product.free {
  background: rgba(138, 92, 255, 0.18);
}

.product img.pimg {
  width: 44px;
  height: 44px;
  object-fit: contain;
  border-radius: 10px;
  flex: 0 0 auto;
}

.pinfo {
  flex: 1;
  min-width: 0;
}

.pname {
  font-weight: 800;
  font-size: 16px;
}

.pdesc {
  font-size: 13px;
  color: var(--muted);
}

.price {
  min-width: 96px;
}

.pricetag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  line-height: 1;
}

.pricetag img {
  display: block;
  width: 20px;
  height: 20px;
  object-fit: contain;
}

.owned {
  color: var(--good);
  font-weight: 800;
  min-width: 96px;
  text-align: center;
}

/* ---------- settings ---------- */
.setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 18px;
  font-weight: 700;
  padding: 4px 4px 8px;
}

.toggle {
  min-width: 84px;
  height: 40px;
  border-radius: 20px;
  font-weight: 800;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid var(--line);
}

.toggle.on {
  background: var(--good);
  color: #062b15;
}

.login-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 6px;
  border-top: 1px solid var(--line);
}

/* The name in the leaderboard (the site build): 4 characters A-Z and 0-9. */
.nick-box {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 0;
}

.nick-row {
  display: flex;
  gap: 8px;
  justify-content: center;
}

#nick-input {
  width: 7.5em;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  color: inherit;
  font: inherit;
  font-weight: 700;
  font-size: 20px;
  letter-spacing: 0.25em;
  text-align: center;
  text-transform: uppercase;
}

.nick-error {
  color: #ff8a8a;
}

.account-name {
  text-align: center;
  font-weight: 700;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.account-name::before {
  content: "✓ ";
  color: var(--good);
}

/* ---------- tutorial ---------- */
.tut {
  text-align: left;
  margin: 0;
  padding-left: 22px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 16px;
}

.tut-demo {
  position: relative;
  height: 80px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.tut-row {
  display: flex;
  gap: 4px;
}

.tut-row i,
.tut-piece {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  background: linear-gradient(135deg, #5ab8ff, #1d5fd6);
}

.tut-row i.empty {
  background: rgba(255, 255, 255, 0.1);
}

.tut-piece {
  position: absolute;
  left: calc(50% + 53px);
  bottom: 0;
  background: linear-gradient(135deg, #ffe066, #caa000);
  animation: drop 2s ease-in-out infinite;
}

@keyframes drop {
  0%,
  15% {
    transform: translate(40px, -50px);
  }
  55%,
  100% {
    transform: translate(0, 0);
  }
}

/* ---------- toast / hint ---------- */
.toast {
  position: absolute;
  left: 50%;
  bottom: 110px;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.8);
  padding: 10px 18px;
  border-radius: 14px;
  font-weight: 700;
  z-index: 30;
  width: max-content; /* centred with left: 50%, it would otherwise wrap at half the screen width */
  max-width: 90vw;
  text-align: center;
  pointer-events: none;
  animation: toast-pop 0.2s ease-out;
}

/* Like pop, but keeps the centring shift: with pop the toast stood half its width to the right for 0.2 s. */
@keyframes toast-pop {
  from {
    transform: translateX(-50%) scale(0.9);
    opacity: 0;
  }
  to {
    transform: translateX(-50%);
    opacity: 1;
  }
}

/* Over the menu: above the logo, clear of the menu buttons. */
.toast.top {
  top: calc(12px + env(safe-area-inset-top, 0px));
  bottom: auto;
}

.hint {
  position: absolute;
  top: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(200, 50, 26, 0.92);
  padding: 8px 14px;
  border-radius: 12px;
  font-weight: 700;
  font-size: 14px;
  z-index: 5;
  max-width: 92vw;
  text-align: center;
  pointer-events: none;
}

@media (orientation: landscape) and (max-height: 500px) {
  #hud {
    height: 50px;
    padding-top: 4px;
  }
  .score {
    font-size: 26px;
  }
  .booster {
    height: 48px;
  }
  .booster .bname {
    display: none;
  }
  .card {
    padding: 14px;
    gap: 8px;
  }
  .btn {
    min-height: 42px;
  }
}

/* Large desktop screens: scale the chrome up with the board. */
@media (min-width: 1000px) and (min-height: 760px) {
  #hud {
    height: 96px;
    padding: 14px 24px 0;
  }
  .icon-btn {
    width: 56px;
    height: 56px;
  }
  .icon-btn svg {
    width: 28px;
    height: 28px;
  }
  .score {
    font-size: 56px;
  }
  .best {
    font-size: 18px;
  }
  .coin-pill {
    height: 52px;
    min-width: 140px;
    font-size: 22px;
    padding: 0 8px 0 12px;
    border-radius: 26px;
  }
  .coin-pill .plus {
    width: 34px;
    height: 34px;
  }
  .coin-pill .coin {
    width: 28px;
    height: 28px;
  }
  .booster {
    width: 128px;
    height: 84px;
  }
  .booster svg {
    width: 32px;
    height: 32px;
  }
  .booster .bname {
    font-size: 15px;
  }
}

.chance .row {
  flex-direction: column;
}

.btn {
  white-space: nowrap;
}

/* ---------- leaderboard ---------- */
.trophy {
  display: inline-block;
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  background: var(--accent);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M7 3h10v2h4v3a5 5 0 0 1-4.6 5A5 5 0 0 1 13 16.9V19h4v2H7v-2h4v-2.1A5 5 0 0 1 7.6 13 5 5 0 0 1 3 8V5h4V3zm10 4v4a3 3 0 0 0 2-3V7h-2zM5 7v1a3 3 0 0 0 2 3V7H5z'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M7 3h10v2h4v3a5 5 0 0 1-4.6 5A5 5 0 0 1 13 16.9V19h4v2H7v-2h4v-2.1A5 5 0 0 1 7.6 13 5 5 0 0 1 3 8V5h4V3zm10 4v4a3 3 0 0 0 2-3V7h-2zM5 7v1a3 3 0 0 0 2 3V7H5z'/%3E%3C/svg%3E") center / contain no-repeat;
}

.trophy.big {
  width: 26px;
  height: 26px;
  vertical-align: -3px;
}

.gold {
  color: var(--accent);
}

#lb-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 60px;
}

.lb-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.06);
  text-align: left;
}

.lb-row.me {
  background: rgba(255, 207, 64, 0.18);
  border: 1px solid rgba(255, 207, 64, 0.6);
}

.lb-rank {
  min-width: 28px;
  text-align: center;
  font-weight: 900;
  color: var(--muted);
}

.lb-rank.top1 {
  color: #ffd84d;
}

.lb-rank.top2 {
  color: #d9e2ff;
}

.lb-rank.top3 {
  color: #ffae6b;
}

.lb-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  overflow: hidden;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  font-weight: 900;
  background: linear-gradient(135deg, #5ab8ff, #8a5cff);
}

.lb-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.lb-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb-score {
  font-size: 17px;
}

.lb-gap {
  text-align: center;
  color: var(--muted);
  line-height: 1;
}

.small-spinner {
  width: 28px;
  height: 28px;
  margin: 16px auto;
}
