:root {
  --bg: #1b2430;
  --bg2: #223040;
  --ink: #f2ede3;
  --accent: #ffcf4d;
  --danger: #e2574c;
  --good: #7cc47f;
  --panel: #2c3a4c;
  --shadow: rgba(0, 0, 0, 0.35);
}

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: "Comic Sans MS", "Segoe UI", system-ui, sans-serif;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.hidden { display: none !important; }

/* ---------- Title / menus ---------- */
#bgfx {
  position: absolute;
  inset: 0;
  z-index: 0;
  display: block;
  width: 100%;
  height: 100%;
}

/* menus sit above the animated backdrop; keep them slightly darkened for readability */
#startScreen { background: rgba(10, 12, 18, 0.35); }
#howScreen, #levelScreen, #overlay { background: rgba(10, 12, 18, 0.45); }

#authBox {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 12px);
  left: 14px;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 8px;
}
#authBox button {
  background: var(--panel);
  color: var(--ink);
  border: 2px solid #4a5c72;
  border-radius: 10px;
  padding: 7px 12px;
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
}
body.in-game #authBox { display: none; } /* would cover the money HUD */
#authBox .au-name {
  background: rgba(0, 0, 0, 0.4);
  padding: 7px 12px;
  border-radius: 10px;
  font-size: 14px;
  max-width: 46vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lang-select {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 12px);
  right: 14px;
  background: var(--panel);
  color: var(--ink);
  border: 2px solid #4a5c72;
  border-radius: 10px;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 15px;
  z-index: 5;
}

.title-card {
  text-align: center;
  padding: 28px;
}

.title-card h1 {
  font-size: clamp(38px, 11vw, 84px);
  line-height: 0.95;
  margin: 0 0 8px;
  color: var(--accent);
  text-shadow: 3px 4px 0 #000, -2px -1px 0 var(--danger);
  transform: rotate(-3deg);
  letter-spacing: 1px;
}

.subtitle {
  font-size: clamp(15px, 4vw, 22px);
  margin: 0 0 26px;
  opacity: 0.9;
}

.big-btn, .ghost-btn {
  display: block;
  width: min(78vw, 320px);
  margin: 10px auto;
  padding: 16px 20px;
  font-size: 20px;
  font-family: inherit;
  border: none;
  border-radius: 16px;
  cursor: pointer;
  font-weight: bold;
}

.big-btn {
  background: var(--accent);
  color: #2a1e00;
  box-shadow: 0 6px 0 #b9902f, 0 8px 14px var(--shadow);
}
.big-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #b9902f; }

.ghost-btn {
  background: transparent;
  color: var(--ink);
  border: 3px solid #4a5c72;
}
.ghost-btn:active { transform: translateY(2px); }

.panel {
  background: var(--panel);
  border-radius: 22px;
  padding: 26px 22px;
  width: min(90vw, 460px);
  box-shadow: 0 12px 30px var(--shadow);
  text-align: center;
}
.panel h2 { margin-top: 0; color: var(--accent); font-size: 28px; }

.how-list {
  text-align: left;
  line-height: 1.7;
  font-size: 16px;
  padding-left: 4px;
  list-style: none;
}
.how-list li { margin-bottom: 6px; }

/* ---------- Player name + leaderboard ---------- */
#playerRow {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  margin: 0 0 14px; font-size: 16px; flex-wrap: wrap;
}
#playerRow .pl-name {
  background: rgba(0, 0, 0, 0.35); padding: 6px 12px; border-radius: 10px;
  max-width: 60vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
#playerRow .pl-edit {
  background: transparent; color: var(--ink); border: 2px solid #4a5c72;
  border-radius: 10px; padding: 5px 10px; font-family: inherit; font-size: 14px; cursor: pointer;
}
/* girl / boy hero picker on the start screen */
.sex-pick { display: inline-flex; gap: 6px; }
.pl-edit.sex-on {
  border-color: var(--accent);
  background: rgba(255, 207, 77, 0.18);
  color: var(--accent);
}

#scoreList { display: flex; flex-direction: column; gap: 4px; margin: 4px 0 14px; max-height: 46vh; overflow-y: auto; }
.score-row {
  display: flex; align-items: center; gap: 8px; font-size: 15px;
  background: rgba(0, 0, 0, 0.25); border-radius: 10px; padding: 7px 10px; text-align: left;
}
.score-row.mine { background: rgba(255, 207, 77, 0.18); border: 1px solid rgba(255, 207, 77, 0.5); }
.score-row .pos { width: 26px; opacity: 0.75; }
.score-row .who { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: bold; }
.score-row .wv { color: var(--accent); }
.score-row .mp { opacity: 0.7; font-size: 13px; }
.no-scores { opacity: 0.8; font-size: 15px; margin: 10px 0 16px; }

/* ---------- Level select ---------- */
.level-hint { font-size: 15px; opacity: 0.85; margin: -6px 0 16px; line-height: 1.45; }
#levelList { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.level-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: min(80vw, 340px);
  padding: 14px 18px;
  font-size: 18px;
}
.level-btn .stars { color: #b9902f; font-size: 16px; letter-spacing: 2px; }

/* ---------- Game HUD ---------- */
#gameScreen { flex-direction: column; padding: 0; }

#hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  gap: 8px;
  align-items: center;
  padding: calc(env(safe-area-inset-top) + 8px) 12px 8px;
  z-index: 10;
  pointer-events: none;
}
.hud-item {
  background: rgba(0,0,0,0.42);
  padding: 7px 12px;
  border-radius: 12px;
  font-size: 16px;
  font-weight: bold;
  white-space: nowrap;
}
/* the two speed buttons sit next to the speed readout, not pushed to the edge */
.hud-btn.speed-btn { margin-left: 0; padding: 7px 10px; }
#slowBtn { margin-left: auto; }
#speedLabel { min-width: 62px; text-align: center; }

.hud-btn {
  margin-left: auto;
  pointer-events: auto;
  background: rgba(0,0,0,0.42);
  color: var(--ink);
  border: none;
  border-radius: 12px;
  font-size: 18px;
  padding: 7px 12px;
  cursor: pointer;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* ---------- Shop bar ---------- */
#shop {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  display: flex;
  gap: 8px;
  padding: 8px 10px calc(env(safe-area-inset-bottom) + 10px);
  z-index: 10;
  justify-content: center;
}
.shop-btn {
  flex: 1 1 0;
  max-width: 120px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: var(--panel);
  color: var(--ink);
  border: 3px solid #3d4f64;
  border-radius: 14px;
  padding: 8px 4px;
  font-family: inherit;
  cursor: pointer;
}
.shop-btn:active { transform: translateY(2px); }
.shop-btn.wave { background: #3a5a3c; border-color: #4f7d52; }
.shop-btn .ico { font-size: 22px; }
.shop-btn .lbl { font-size: 13px; font-weight: bold; }
.shop-btn .cost { font-size: 12px; opacity: 0.85; }
.shop-btn.disabled { opacity: 0.4; }
.shop-btn.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }

/* ---------- Build menu ---------- */
#buildMenu {
  position: absolute;
  z-index: 20;
  display: flex;
  gap: 6px;
  background: rgba(0,0,0,0.7);
  padding: 6px;
  border-radius: 12px;
  transform: translate(-50%, -120%);
}
#buildMenu button {
  background: var(--accent);
  color: #2a1e00;
  border: none;
  border-radius: 9px;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 13px;
  font-weight: bold;
  cursor: pointer;
  white-space: nowrap;
}
#buildMenu button[data-build="cancel"] { background: var(--danger); color: #fff; }

/* ---------- flash message ---------- */
#flash {
  position: absolute;
  top: 64px; left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.7);
  color: #fff;
  padding: 8px 16px;
  border-radius: 12px;
  font-size: 15px;
  z-index: 30;
  pointer-events: none;
  transition: opacity 0.3s;
}
