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

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: #0b1020;
  font-family: -apple-system, "SF Pro Display", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

#game {
  position: fixed; inset: 0;
  display: block;
  touch-action: none;
}

.hidden { display: none !important; }

/* ---------- HUD ---------- */
#hud {
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 5;
}

#topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: max(10px, env(safe-area-inset-top)) 14px 0;
}

#hearts { display: flex; gap: 4px; font-size: 24px; min-width: 92px; filter: drop-shadow(0 2px 3px rgba(0,0,0,.35)); }
#hearts .off { opacity: .22; filter: grayscale(1); }

#scoreWrap { text-align: center; }
#score {
  font-size: 44px; font-weight: 800; color: #fff;
  text-shadow: 0 3px 10px rgba(0,0,0,.4);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
#score.pop { animation: pop .22s ease; }
@keyframes pop { 40% { transform: scale(1.25); } }
#bestSmall { font-size: 12px; font-weight: 700; color: rgba(255,255,255,.75); letter-spacing: 1px; margin-top: 2px; }

#topRight { display: flex; align-items: center; gap: 10px; min-width: 92px; justify-content: flex-end; }
#coins {
  display: flex; align-items: center; gap: 6px;
  background: rgba(0,0,0,.28);
  border-radius: 20px; padding: 5px 12px;
  color: #ffd75e; font-weight: 800; font-size: 15px;
  font-variant-numeric: tabular-nums;
}
.coinIcon {
  width: 14px; height: 14px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffe9a0, #f5b820 65%, #c78a00);
  box-shadow: inset 0 0 0 2px rgba(160,110,0,.5);
}
#pauseBtn {
  pointer-events: auto;
  position: relative;
  width: 38px; height: 38px; border-radius: 12px;
  border: none; background: rgba(0,0,0,.28); color: #fff;
  font-size: 14px; font-weight: 800; cursor: pointer;
}
#pauseBtn::after { content: ''; position: absolute; inset: -4px; } /* 46px hit area, 44px+ thumb rule */

#combo {
  position: absolute; top: 96px; left: 50%; transform: translateX(-50%);
  background: linear-gradient(135deg, #ff8a3d, #ff3d6e);
  color: #fff; font-weight: 900; font-size: 18px; letter-spacing: 1px;
  padding: 7px 18px; border-radius: 24px;
  box-shadow: 0 4px 18px rgba(255,80,90,.45);
  animation: comboIn .25s ease;
}
@keyframes comboIn { from { transform: translateX(-50%) scale(.5); opacity: 0; } }

#windWrap {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%) translateY(84px);
  display: flex; align-items: center; gap: 6px;
  color: #fff; font-weight: 700; font-size: 13px;
  background: rgba(0,0,0,.25); padding: 4px 12px; border-radius: 16px;
}
#windWrap:not(.hidden) ~ #combo, #combo:not(.hidden) { top: 130px; }
#windArrow { display: inline-block; font-size: 16px; transition: transform .3s; }

/* ---------- Screens ---------- */
.screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  z-index: 10;
  background: rgba(8, 12, 28, .45);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: max(10px, env(safe-area-inset-top)) 0 max(10px, env(safe-area-inset-bottom));
}

.panel {
  text-align: center;
  padding: 28px 34px;
  animation: panelIn .3s ease;
  max-width: 92vw;
  margin: auto; /* centers when it fits, scrolls (no clip) when taller than screen */
}
@keyframes panelIn { from { transform: translateY(18px) scale(.96); opacity: 0; } }

h1 {
  font-size: clamp(44px, 10vw, 72px);
  font-weight: 900; letter-spacing: 2px; color: #fff;
  text-shadow: 0 6px 24px rgba(0,0,0,.5);
  line-height: .95;
}
h1 span {
  display: block;
  background: linear-gradient(135deg, #ffd75e, #ff8a3d);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
}
h2 { font-size: 34px; font-weight: 900; color: #fff; letter-spacing: 2px; margin-bottom: 14px; }
.tag { color: rgba(255,255,255,.85); font-weight: 600; margin: 10px 0 26px; letter-spacing: .5px; }

button.big {
  display: block; width: min(280px, 78vw);
  margin: 10px auto;
  padding: 16px 0;
  font-size: 20px; font-weight: 900; letter-spacing: 2px;
  color: #08331a;
  background: linear-gradient(135deg, #6dedb0, #22c76a);
  border: none; border-radius: 18px; cursor: pointer;
  box-shadow: 0 6px 0 #169148, 0 10px 26px rgba(0,0,0,.35);
  transition: transform .08s;
}
button.big:active { transform: translateY(4px); box-shadow: 0 2px 0 #169148, 0 6px 16px rgba(0,0,0,.3); }
button.big.gold {
  color: #4a2c00;
  background: linear-gradient(135deg, #ffe07a, #ffb02e);
  box-shadow: 0 6px 0 #c77e0a, 0 10px 26px rgba(0,0,0,.35);
}
button.big.gold:active { box-shadow: 0 2px 0 #c77e0a, 0 6px 16px rgba(0,0,0,.3); }
button.big.blue {
  color: #0b2d4a;
  background: linear-gradient(135deg, #74c0fc, #339af0);
  box-shadow: 0 6px 0 #1c7ed6, 0 10px 26px rgba(0,0,0,.35);
}
button.big.blue:active { box-shadow: 0 2px 0 #1c7ed6, 0 6px 16px rgba(0,0,0,.3); }
button.big small { display: block; font-size: 11px; letter-spacing: 1px; font-weight: 700; opacity: .75; margin-top: 2px; }

button.ghost {
  background: none; border: none; color: rgba(255,255,255,.7);
  font-size: 14px; font-weight: 700; letter-spacing: 1px;
  margin-top: 14px; cursor: pointer; padding: 8px 16px;
}
button.round {
  width: 52px; height: 52px; border-radius: 50%;
  border: none; background: rgba(255,255,255,.14); color: #fff;
  font-size: 22px; cursor: pointer;
}
.menuRow { display: flex; justify-content: center; gap: 12px; margin-top: 8px; }

#menuBest { color: #ffd75e; font-weight: 800; letter-spacing: 2px; margin-top: 22px; font-size: 15px; }
.hint { color: rgba(255,255,255,.55); font-size: 13px; margin-top: 10px; }

#newBest {
  display: inline-block;
  background: linear-gradient(135deg, #ffd75e, #ff8a3d);
  color: #4a2c00; font-weight: 900; letter-spacing: 1px;
  padding: 5px 16px; border-radius: 16px; font-size: 14px;
  margin-bottom: 12px;
  animation: pop .4s ease;
}

/* ---------- Score card ---------- */
#scoreCard {
  width: min(280px, 78vw);
  margin: 0 auto 14px;
  padding: 18px 16px 14px;
  background: linear-gradient(160deg, rgba(255,255,255,.10), rgba(255,255,255,.04));
  border: 1px solid rgba(255,215,94,.35);
  border-radius: 20px;
  box-shadow: 0 12px 32px rgba(0,0,0,.35);
}
#cardGame {
  font-size: 12px; font-weight: 900; letter-spacing: 3px;
  color: rgba(255,255,255,.65); margin-bottom: 8px;
}
#finalScore {
  font-size: 56px; font-weight: 900; color: #fff; line-height: 1;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 4px 18px rgba(0,0,0,.4);
}
#rankLine {
  display: inline-block;
  margin-top: 8px;
  background: rgba(116,192,252,.16);
  border: 1px solid rgba(116,192,252,.45);
  color: #a5d8ff; font-weight: 800; font-size: 13px; letter-spacing: .5px;
  padding: 4px 14px; border-radius: 14px;
  animation: pop .35s ease;
}
#cardRow {
  display: flex; justify-content: space-around; align-items: baseline;
  margin-top: 12px; padding-top: 10px;
  border-top: 1px solid rgba(255,255,255,.12);
  color: rgba(255,255,255,.6); font-weight: 800; font-size: 11px; letter-spacing: 1.5px;
}
#cardRow b { color: #ffd75e; font-size: 18px; margin-left: 4px; font-variant-numeric: tabular-nums; }

/* ---------- Ad modal ---------- */
#adModal { background: rgba(4, 6, 16, .88); z-index: 20; }
#adBox {
  width: min(340px, 88vw);
  background: #171c2e;
  border-radius: 20px;
  padding: 26px 22px;
  text-align: center;
  position: relative;
  box-shadow: 0 20px 60px rgba(0,0,0,.6);
}
#adTag {
  position: absolute; top: 12px; left: 14px;
  background: #ffd75e; color: #4a2c00;
  font-size: 11px; font-weight: 900; letter-spacing: 1px;
  padding: 2px 8px; border-radius: 6px;
}
#adArt { font-size: 64px; margin: 18px 0 8px; animation: adFloat 1.6s ease-in-out infinite; }
@keyframes adFloat { 50% { transform: translateY(-8px); } }
#adText { color: rgba(255,255,255,.7); font-size: 14px; font-weight: 600; margin-bottom: 20px; }
#adBarWrap { height: 6px; background: rgba(255,255,255,.12); border-radius: 4px; overflow: hidden; margin-bottom: 16px; }
#adBar { height: 100%; width: 0%; background: linear-gradient(90deg, #6dedb0, #22c76a); transition: width .25s linear; }
#adClose {
  border: none; background: rgba(255,255,255,.12); color: #fff;
  font-weight: 800; font-size: 14px; padding: 10px 26px;
  border-radius: 12px; cursor: pointer;
}
#adClose:disabled { opacity: .45; cursor: default; }

/* ---------- Short screens (e.g. 360x640): compact so nothing clips ---------- */
@media (max-height: 720px) {
  .panel { padding: 16px 30px; }
  h1 { font-size: clamp(40px, 13vw, 60px); }
  h2 { font-size: 30px; margin-bottom: 10px; }
  .tag { margin: 8px 0 18px; }
  button.big { padding: 13px 0; margin: 8px auto; font-size: 19px; }
  button.ghost { margin-top: 10px; }
  #scoreCard { padding: 14px 16px 12px; margin-bottom: 12px; }
  #finalScore { font-size: 48px; }
  #newBest { margin-bottom: 8px; }
  #menuBest { margin-top: 16px; }
  .hint { margin-top: 8px; }
  .menuRow { margin-top: 6px; }
}
