/* ------------------------------------------------------------------ *
 * Flappy Dragon — styles
 * Mobile-first: no scrolling, no tap-zoom. Layout is a vertical stack:
 * the game playfield on top, a fixed ad banner pinned at the bottom.
 * ------------------------------------------------------------------ */

:root {
  /* Height of the bottom ad bar. 100px suits a 320x100 large mobile banner. */
  --ad-height: 100px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  overflow: hidden;
  background: #094f54; /* deep teal — matches canvas edge so letterboxing blends */
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  overscroll-behavior: none;
}

/* Vertical stack: playfield grows, ad bar is a fixed strip at the bottom. */
body {
  display: flex;
  flex-direction: column;
}

/* ----------------------------- PLAYFIELD ----------------------------- */
#playfield {
  position: relative; /* anchor for the absolutely-positioned overlays */
  flex: 1 1 auto;
  min-height: 0; /* let it shrink so the ad bar always fits */
  overflow: hidden;
}

#game {
  display: block;
  touch-action: none; /* we handle all touches ourselves */
}

/* Overlays sit over the canvas, inside the playfield only. */
.hud,
.overlay {
  position: absolute;
  left: 0;
  right: 0;
  pointer-events: none; /* taps fall through to the playfield */
  text-align: center;
  color: #fff;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.45);
}

.hud {
  top: max(20px, env(safe-area-inset-top, 0px));
}
.score {
  font-size: clamp(40px, 12vmin, 88px);
  font-weight: 800;
  letter-spacing: 2px;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.hud.playing .score {
  opacity: 1;
}

.overlay {
  top: 50%;
  transform: translateY(-50%);
  transition: opacity 0.25s ease;
}
.overlay.hidden {
  opacity: 0;
}
.overlay h1 {
  font-size: clamp(34px, 10vmin, 72px);
  font-weight: 800;
  letter-spacing: 1px;
  margin-bottom: 0.3em;
  /* Mahjong-Ways-style gold lettering with a dark-red outline + glow */
  color: #ffce3d;
  -webkit-text-stroke: 2px #7a1408;
  paint-order: stroke fill;
  text-shadow: 0 0 22px rgba(255, 206, 61, 0.6), 0 4px 0 #5a0f06;
}
.overlay #message {
  font-size: clamp(18px, 5vmin, 30px);
  font-weight: 600;
  animation: pulse 1.2s ease-in-out infinite;
}
.overlay .best {
  margin-top: 1em;
  font-size: clamp(15px, 4vmin, 22px);
  font-weight: 600;
  opacity: 0.9;
}

@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
    opacity: 0.95;
  }
  50% {
    transform: scale(1.08);
    opacity: 0.7;
  }
}
@media (prefers-reduced-motion: reduce) {
  .overlay #message {
    animation: none;
  }
}

/* ---- username entry ---- */
.name-prompt {
  display: none;
  color: #ffce3d;
  font-weight: 700;
  font-size: clamp(15px, 4.2vmin, 22px);
  margin: 4px 0 8px;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.4);
}
.name-prompt.show {
  display: block;
}
.name-form {
  pointer-events: auto; /* interactive, unlike the rest of the overlay */
  display: none; /* shown by JS when no username is set */
  gap: 8px;
  justify-content: center;
  margin: 6px 0 4px;
}
.name-form.show {
  display: flex;
}
#nameInput {
  width: min(60vw, 260px);
  padding: 12px 14px;
  border-radius: 10px;
  border: 2px solid #f0a92e;
  background: rgba(0, 0, 0, 0.25);
  color: #fff;
  font-size: 17px;
  text-align: center;
  outline: none;
}
#nameInput::placeholder {
  color: rgba(255, 255, 255, 0.6);
}
.name-form button {
  padding: 12px 20px;
  border: none;
  border-radius: 10px;
  background: #ffce3d;
  color: #5a3a00;
  font-weight: 800;
  font-size: 16px;
  cursor: pointer;
}

.who {
  pointer-events: auto;
  font-size: clamp(13px, 3.6vmin, 17px);
  font-weight: 600;
  opacity: 0.95;
  margin-top: 2px;
}
.who .change {
  color: #ffce3d;
  text-decoration: underline;
  cursor: pointer;
}

/* ---- leaderboard ---- */
.lb-wrap {
  margin-top: 14px;
}
.lb-title {
  font-size: clamp(14px, 4vmin, 19px);
  font-weight: 800;
  color: #ffce3d;
  margin-bottom: 6px;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.4);
}
.leaderboard {
  list-style: none;
  margin: 0 auto;
  padding: 0;
  width: min(72vw, 280px);
  font-size: clamp(13px, 3.8vmin, 17px);
}
.leaderboard li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 3px 4px;
  font-weight: 600;
}
.leaderboard li .rank {
  color: #ffce3d;
  margin-right: 8px;
}
.leaderboard li .nm {
  flex: 1;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ----------------------------- POPUP AD ------------------------------ */
.ad-popup {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(0, 0, 0, 0.78);
  backdrop-filter: blur(2px);
  animation: popupFade 0.2s ease;
}
.ad-popup.hidden {
  display: none;
}
@keyframes popupFade {
  from { opacity: 0; }
  to { opacity: 1; }
}
.ad-popup-inner {
  position: relative;
  max-width: min(94vw, 520px);
  animation: popupPop 0.25s ease;
}
@keyframes popupPop {
  from { transform: scale(0.85); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
.ad-popup-inner img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
}
.ad-popup-close {
  position: absolute;
  top: -14px;
  right: -14px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 3px solid #fff;
  background: #ff4d4d;
  color: #fff;
  font-size: 22px;
  line-height: 1;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}
.ad-popup-close:hover {
  background: #ff3030;
}
@media (prefers-reduced-motion: reduce) {
  .ad-popup, .ad-popup-inner { animation: none; }
}

/* ----------------------------- AD BANNER ----------------------------- */
#adbanner {
  flex: 0 0 auto;
  height: calc(var(--ad-height) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  display: flex;
  align-items: center;
  justify-content: center;
  background: #062f33; /* dark teal bar, set apart from the game */
  border-top: 3px solid #f0a92e; /* gold trim ties into the theme */
  overflow: hidden;
}

/* The slot your real ad fills. Sized to common banner dimensions. */
#ad-slot {
  width: 100%;
  max-width: 728px; /* leaderboard cap on desktop; full width on mobile */
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none; /* it's an <a> — no underline */
  cursor: pointer;
}

/* Real banner image: scale to fit the bar, show the whole ad. */
.ad-img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: 100%;
  object-fit: contain;
  display: block;
}

/* Placeholder shown until a real ad is dropped in. */
.ad-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #6fb8b0;
  background: repeating-linear-gradient(
    45deg,
    #0a3d40,
    #0a3d40 10px,
    #0d484c 10px,
    #0d484c 20px
  );
  border: 1px dashed #2f7a72;
}
