:root {
  --bg: #24164a;
  --panel: rgba(28, 16, 58, 0.92);
  --text: #fff;
  --muted: #c9b8f0;
  --accent: #3fd0ff;
  --accent2: #ff7ad9;
  --yellow: #ffe066;
  --red: #ff5a5f;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

canvas#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.hidden { display: none !important; }

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  background: rgba(20, 10, 40, 0.35);
  overflow-y: auto;
}

#menu { background: transparent; justify-content: flex-start; padding-top: max(10vh, env(safe-area-inset-top)); }

.logo {
  font-size: clamp(64px, 18vw, 120px);
  font-weight: 900;
  margin: 0;
  letter-spacing: -2px;
  background: linear-gradient(180deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 4px 0 rgba(20, 10, 40, 0.6));
  animation: boing 1.2s ease-in-out infinite;
}

@keyframes boing {
  0%, 100% { transform: translateY(0) scale(1, 1); }
  45% { transform: translateY(-12px) scale(0.97, 1.04); }
  55% { transform: translateY(-12px) scale(0.97, 1.04); }
  90% { transform: translateY(0) scale(1.06, 0.94); }
}

.tagline { margin: 4px 0 24px; color: var(--muted); text-align: center; text-shadow: 0 2px 0 rgba(0,0,0,0.4); }

.buttons { display: flex; flex-direction: column; gap: 10px; width: min(280px, 100%); }
.buttons.row { flex-direction: row; }
.buttons.row > * { flex: 1; }

button {
  font: inherit;
  font-weight: 700;
  font-size: 17px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.12);
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-radius: 14px;
  padding: 12px 16px;
  cursor: pointer;
  transition: transform 0.08s, background 0.15s;
}
button:hover { background: rgba(255, 255, 255, 0.2); }
button:active { transform: scale(0.96); }
button.big {
  background: linear-gradient(180deg, var(--accent), #1f7fd6);
  border-color: transparent;
  font-size: 20px;
  box-shadow: 0 4px 0 #134f8a;
}
button.link { background: none; border: none; color: var(--muted); text-decoration: underline; }

.icon-btn {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  right: 12px;
  width: 46px;
  height: 46px;
  padding: 0;
  font-size: 18px;
  border-radius: 50%;
  z-index: 5;
}
.icon-btn.corner { position: absolute; }

.account { margin-top: 22px; text-align: center; color: var(--muted); font-size: 15px; line-height: 1.6; }
.account button { margin-top: 6px; font-size: 15px; padding: 8px 14px; }
.best { margin-top: 12px; color: var(--muted); }
.best b { color: var(--yellow); }

.panel {
  background: var(--panel);
  border: 2px solid rgba(255, 255, 255, 0.12);
  border-radius: 20px;
  padding: 22px 20px;
  width: min(380px, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
}
.panel.wide { width: min(460px, 100%); max-height: 100%; }
.panel h2 { margin: 0; font-size: 26px; }
.panel .buttons { width: 100%; }
.muted { color: var(--muted); margin: 0; font-size: 14px; text-align: center; }

label { width: 100%; display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--muted); }
input {
  font: inherit;
  font-size: 17px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  background: rgba(0, 0, 0, 0.3);
  color: var(--text);
  -webkit-user-select: text;
  user-select: text;
}
input:focus { outline: none; border-color: var(--accent); }
.error { color: var(--red); min-height: 1.2em; font-size: 14px; text-align: center; }

.help { margin: 0; padding-left: 20px; line-height: 1.5; font-size: 15px; }
.help li { margin-bottom: 6px; }
.red { color: var(--red); }
.yellow { color: var(--yellow); }

.tabs { display: flex; gap: 8px; width: 100%; }
.tabs.small .tab { padding: 5px; font-size: 13px; }
.tab.board.active { background: var(--accent2); border-color: var(--accent2); }
.tab { flex: 1; padding: 8px; font-size: 15px; }
.tab.active { background: var(--accent); border-color: var(--accent); color: #10223d; }

.rank-body { scrollbar-color: rgba(255,255,255,0.25) transparent; scrollbar-width: thin; width: 100%; overflow-y: auto; max-height: 55vh; min-height: 120px; }
.rank-row { display: grid; grid-template-columns: 34px 34px 1fr auto; gap: 8px; padding: 8px 6px; border-bottom: 1px solid rgba(255,255,255,0.08); align-items: center; }
.rank-row.me { background: rgba(63, 208, 255, 0.18); border-radius: 8px; }
.rank-pos { font-weight: 800; color: var(--muted); text-align: center; }
.rank-row:nth-child(1) .rank-pos { color: #ffd700; }
.rank-row:nth-child(2) .rank-pos { color: #d8d8e8; }
.rank-row:nth-child(3) .rank-pos { color: #e09a5a; }
.rank-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-name small { color: var(--muted); margin-left: 6px; }
.rank-score { font-weight: 800; color: var(--yellow); font-variant-numeric: tabular-nums; }
.rank-me { font-size: 14px; color: var(--muted); text-align: center; }
.rank-empty { text-align: center; color: var(--muted); padding: 30px 0; }

.final { font-size: 52px; font-weight: 900; color: var(--yellow); text-shadow: 0 3px 0 rgba(0,0,0,0.4); }
.stats { color: var(--muted); font-size: 15px; text-align: center; line-height: 1.5; }
.submit { text-align: center; font-size: 15px; min-height: 1.4em; }
.submit button { margin-top: 8px; }
.record { color: var(--accent2); font-weight: 800; }

.purple { color: #c77dff; }

.profile-bar {
  display: flex; align-items: center; gap: 14px; margin-bottom: 18px;
  background: rgba(20, 10, 40, 0.55); padding: 8px 14px; border-radius: 14px;
  width: min(320px, 100%);
}
.profile-bar .lvl { flex: 1; display: flex; flex-direction: column; gap: 3px; font-weight: 800; font-size: 15px; }
.profile-bar small { color: var(--muted); font-weight: 600; font-size: 11px; }
.xpbar { height: 7px; background: rgba(0,0,0,0.4); border-radius: 4px; overflow: hidden; }
.xpbar > div { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent2)); transition: width 0.4s; }
.profile-bar .coins { font-size: 18px; white-space: nowrap; }
.profile-bar .coins b { color: var(--yellow); }

.shop-grid {
  width: 100%; display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 10px;
  overflow-y: auto; max-height: 58vh; padding: 2px;
}
.card {
  background: rgba(255,255,255,0.06); border: 2px solid rgba(255,255,255,0.12); border-radius: 14px;
  padding: 8px; display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.card.selected { border-color: var(--accent); background: rgba(63, 208, 255, 0.15); }
.card.locked canvas { filter: grayscale(0.8) brightness(0.6); }
.card canvas { width: 80px; height: 80px; }
.card .name { font-weight: 800; }
.card button { width: 100%; padding: 6px 8px; font-size: 14px; border-radius: 10px; }
.card button:disabled { opacity: 0.5; cursor: default; }
.card .req { font-size: 12px; color: var(--muted); }

.rewards { display: flex; gap: 14px; font-weight: 800; font-size: 17px; }
.rewards .xp { color: #7ff3ff; }
.rewards .coin { color: var(--yellow); }
.levelup { color: var(--accent2); font-weight: 900; }
.rank-lvl { display: inline-block; font-size: 11px; font-weight: 800; background: rgba(127,243,255,0.2); color: #7ff3ff; border-radius: 6px; padding: 1px 5px; margin-right: 6px; }

/* Phones in landscape: short screens, keep the menus compact. */
@media (max-height: 520px) {
  #menu { padding-top: max(8px, env(safe-area-inset-top)); }
  .logo { font-size: clamp(40px, 14vh, 72px); }
  .tagline { margin: 2px 0 6px; font-size: 14px; }
  .buttons { flex-direction: row; flex-wrap: wrap; justify-content: center; gap: 8px; width: min(520px, 100%); }
  .buttons > button { flex: 1 1 40%; padding: 8px 12px; font-size: 15px; }
  button.big { font-size: 17px; }
  .account { margin-top: 8px; font-size: 13px; line-height: 1.3; }
  .panel { max-height: calc(100vh - 24px); overflow-y: auto; padding: 14px; gap: 8px; }
  .panel h2 { font-size: 20px; }
  .help { font-size: 13px; line-height: 1.35; }
  .final { font-size: 36px; }
  .icon-btn { width: 38px; height: 38px; font-size: 15px; }
}
.rotate-hint { display: none; margin-top: 10px; font-size: 14px; color: var(--muted); text-align: center; }
@media (orientation: portrait) and (pointer: coarse) { .rotate-hint { display: block; } }
.logo img { display: block; width: clamp(150px, 30vh, 240px); height: auto; border-radius: 22%; filter: drop-shadow(0 6px 12px rgba(20, 10, 40, 0.5)); }
@media (max-height: 520px) { .logo img { width: clamp(80px, 26vh, 130px); } }

.pink { color: #ff8fc8; }
.profile-bar .avatar { width: 44px; height: 44px; flex: none; }
.rank-av { width: 34px; height: 34px; }
.rank-assist { font-size: 12px; margin-left: 4px; }
button.pinkbtn { background: linear-gradient(180deg, #ff7ad9, #c2189b); box-shadow: 0 4px 0 #7a0f62; }
button:disabled { opacity: 0.45; cursor: default; }
.shop-scroll { scrollbar-color: rgba(255,255,255,0.25) transparent; scrollbar-width: thin; width: 100%; overflow-y: auto; max-height: 62vh; display: flex; flex-direction: column; gap: 8px; }
.shop-scroll .shop-grid { max-height: none; overflow: visible; }
.shop-scroll h3 { margin: 10px 0 0; font-size: 18px; }
.heart-shop { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 8px; }
.heart-shop > p { grid-column: 1 / -1; }
.heart-pack { background: rgba(255,122,217,0.1); border: 2px solid rgba(255,122,217,0.35); border-radius: 14px; padding: 8px; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.heart-pack .n { font-size: 20px; font-weight: 900; }
.heart-pack button { width: 100%; padding: 6px 8px; font-size: 14px; border-radius: 10px; }
.test-ad { position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,0.85); display: flex; align-items: center; justify-content: center; }
.test-ad-box { background: #fff; color: #222; border-radius: 16px; padding: 28px; width: min(320px, 90%); display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; }
.test-ad-box .link { color: #666; }
.test-ad-count { font-size: 40px; font-weight: 900; color: #1f7fd6; min-height: 48px; }
