* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  width: 100%; height: 100%; overflow: hidden;
  background: #7ec0ee;
  font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
  user-select: none; -webkit-user-select: none;
  touch-action: none;
}
#game-wrap { position: fixed; inset: 0; overflow: hidden; }
#game { display: block; width: 100%; height: 100%; touch-action: none; }

.hidden { display: none !important; }

/* ===== HUD ===== */
#hud {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; gap: 8px;
  pointer-events: none; z-index: 20;
}
#hud .hud-left, #hud .hud-right { display: flex; align-items: center; gap: 6px; }
#hud .hud-center { display: flex; align-items: center; gap: 8px; }
.hearts { display: flex; gap: 3px; font-size: 22px; filter: drop-shadow(0 2px 2px rgba(0,0,0,.3)); }
.heart-lost { filter: grayscale(1) brightness(.6); opacity: .5; }

.hud-pill {
  background: rgba(0,0,0,.32); color: #fff;
  padding: 6px 12px; border-radius: 999px;
  font-weight: 800; font-size: 15px;
  display: flex; align-items: center; gap: 5px;
  backdrop-filter: blur(4px);
  box-shadow: 0 2px 6px rgba(0,0,0,.2);
}
.hud-pill .hud-k { font-weight: 600; opacity: .85; font-size: 13px; }
.hud-score { color: #ffe680; }
.hud-ebe { background: rgba(255, 122, 61, 0.42); color: #fff; border: 1.5px solid rgba(255, 122, 61, 0.8); }
.hud-ebe #ebe-name { color: #ffe066; font-weight: 900; }
.hud-combo { background: #ff5a5f; color: #fff; animation: pop .3s ease; }
@keyframes pop { 0%{ transform: scale(.5);} 60%{ transform: scale(1.2);} 100%{ transform: scale(1);} }

.icon-btn {
  pointer-events: auto; cursor: pointer;
  width: 40px; height: 40px; border: none; border-radius: 12px;
  background: rgba(0,0,0,.32); color: #fff; font-size: 20px;
  display: flex; align-items: center; justify-content: center;
  text-decoration: none; backdrop-filter: blur(4px);
  transition: transform .1s, background .2s;
}
.icon-btn:hover { background: rgba(0,0,0,.5); }
.icon-btn:active { transform: scale(.9); }

/* ===== Aim timer bar ===== */
#timerbar {
  position: absolute; top: 62px; left: 50%; transform: translateX(-50%);
  width: min(280px, 70%); height: 8px; border-radius: 999px;
  background: rgba(0,0,0,.28); overflow: hidden; z-index: 20;
}
#timerfill { width: 100%; height: 100%; border-radius: 999px;
  background: linear-gradient(90deg, #7dff8a, #ffe066, #ff5a5f); transition: width .1s linear; }

/* ===== 3D scene overlays ===== */
#vignette {
  position: absolute; inset: 0; z-index: 10; pointer-events: none;
  background: radial-gradient(ellipse at 50% 45%, rgba(0,0,0,0) 45%, rgba(10,25,45,.42) 100%);
}

.callout {
  position: absolute; top: 16%; left: 50%; transform: translateX(-50%);
  z-index: 22; pointer-events: none; white-space: nowrap;
  font-family: 'Space Grotesk', 'Inter', sans-serif;
  font-size: clamp(30px, 8vw, 62px); font-weight: 900; letter-spacing: 2px;
  color: #fff; text-shadow: 0 4px 0 rgba(0,0,0,.35), 0 0 26px rgba(255,190,90,.7);
  animation: calloutIn .5s cubic-bezier(.2,.9,.3,1.4);
}
@keyframes calloutIn {
  0% { transform: translateX(-50%) scale(.4); opacity: 0; }
  60% { transform: translateX(-50%) scale(1.15); opacity: 1; }
  100% { transform: translateX(-50%) scale(1); opacity: 1; }
}

.istop-flash {
  position: absolute; top: 34%; left: 50%; transform: translate(-50%,-50%);
  z-index: 24; pointer-events: none;
  font-family: 'Space Grotesk', 'Inter', sans-serif;
  font-size: clamp(46px, 15vw, 130px); font-weight: 900; letter-spacing: 4px;
  color: #fff; -webkit-text-stroke: 3px #ff2b4e;
  text-shadow: 0 0 40px rgba(255,43,78,.9), 0 8px 0 rgba(0,0,0,.3);
  animation: istopSlam .55s cubic-bezier(.15,1.2,.3,1);
}
@keyframes istopSlam {
  0% { transform: translate(-50%,-50%) scale(3); opacity: 0; }
  45% { transform: translate(-50%,-50%) scale(.88); opacity: 1; }
  100% { transform: translate(-50%,-50%) scale(1); opacity: 1; }
}

.hint {
  position: absolute; bottom: 8%; left: 50%; transform: translateX(-50%);
  z-index: 22; pointer-events: none; white-space: nowrap;
  background: rgba(10,22,40,.55); backdrop-filter: blur(6px);
  border: 2px solid rgba(255,255,255,.25); border-radius: 999px;
  padding: 9px 20px; color: #fff; font-weight: 800;
  font-size: clamp(13px, 3.4vw, 17px);
  animation: hintPulse 1.4s ease-in-out infinite;
}
.runner-hint {
  position: absolute; top: 26%; left: 50%; transform: translateX(-50%);
  z-index: 22; pointer-events: none; white-space: nowrap;
  background: rgba(255,140,0,.85); backdrop-filter: blur(6px);
  border: 2px solid #fff; border-radius: 999px;
  padding: 10px 24px; color: #fff; font-weight: 900;
  font-size: clamp(15px, 4vw, 22px);
  box-shadow: 0 4px 20px rgba(255,140,0,.5);
  animation: hintPulse 1.0s ease-in-out infinite;
}
@keyframes hintPulse { 0%,100% { opacity: .85; } 50% { opacity: 1; } }

/* ===== DODGE OVERLAY CONTROLS ===== */
.dodge-overlay {
  position: absolute; bottom: 12%; left: 50%; transform: translateX(-50%);
  z-index: 30; pointer-events: auto;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  width: min(420px, 92%);
}
.dodge-alert {
  background: rgba(255, 43, 78, 0.9); color: #fff;
  padding: 10px 20px; border-radius: 999px; font-weight: 900;
  font-size: clamp(14px, 3.5vw, 18px); letter-spacing: 1px;
  border: 2px solid #fff; box-shadow: 0 4px 25px rgba(255, 43, 78, 0.7);
  animation: alertPulse 0.4s ease-in-out infinite alternate;
}
@keyframes alertPulse { from { transform: scale(0.96); } to { transform: scale(1.04); } }

.dodge-buttons { display: flex; gap: 16px; width: 100%; justify-content: center; }
.dodge-btn {
  flex: 1; max-width: 180px; padding: 16px 12px; border: 3px solid #fff;
  border-radius: 20px; cursor: pointer; font-family: 'Space Grotesk', 'Inter', sans-serif;
  font-weight: 900; font-size: 18px; color: #fff;
  background: linear-gradient(180deg, #4aa3ff, #1d69d8);
  box-shadow: 0 6px 0 #124da3, 0 8px 20px rgba(0,0,0,.4);
  transition: transform 0.08s, box-shadow 0.08s;
  user-select: none; touch-action: manipulation;
}
.dodge-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #124da3, 0 4px 10px rgba(0,0,0,.4); }

/* ===== MOVEMENT D-PAD (mobile only) ===== */
.dpad {
  position: absolute; bottom: 5%; left: 50%; transform: translateX(-50%);
  z-index: 30; pointer-events: auto;
  display: grid; grid-template-columns: repeat(3, 62px); grid-template-rows: repeat(3, 62px);
  gap: 6px;
}
.dbtn {
  border: none; border-radius: 16px; cursor: pointer;
  background: rgba(0, 194, 178, 0.42); color: #fff; font-size: 26px; font-weight: 900;
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(4px); border: 2px solid rgba(255,255,255,.5);
  user-select: none; touch-action: none;
  box-shadow: 0 4px 12px rgba(0,0,0,.3);
  transition: transform .06s, background .12s;
}
.dbtn:active { transform: scale(.9); background: rgba(0, 194, 178, 0.85); }
.dbtn-up    { grid-column: 2; grid-row: 1; }
.dbtn-left  { grid-column: 1; grid-row: 2; }
.dbtn-right { grid-column: 3; grid-row: 2; }
.dbtn-down  { grid-column: 2; grid-row: 3; }
/* Hide the touch d-pad on devices that have a real pointer (desktop) */
@media (hover: hover) and (pointer: fine) { .dpad { display: none !important; } }

/* ===== SCREENS ===== */
.screen {
  position: absolute; inset: 0; z-index: 40;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: radial-gradient(circle at 50% 30%, rgba(20,40,70,.5), rgba(10,20,40,.82));
  backdrop-filter: blur(3px);
}
.screen-card {
  width: 100%; max-width: 420px; text-align: center; margin: auto;
  background: linear-gradient(180deg, rgba(255,255,255,.97), rgba(240,247,255,.97));
  border: 3px solid #fff; border-radius: 26px;
  padding: 26px 24px; color: #14203a;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
  animation: cardIn .35s cubic-bezier(.2,.9,.3,1.2);
}
.screen-card.small { max-width: 340px; }
@keyframes cardIn { from{ transform: translateY(20px) scale(.94); opacity: 0;} to{ transform: none; opacity: 1;} }

.title {
  font-family: 'Space Grotesk', 'Inter', sans-serif;
  font-size: 62px; font-weight: 900; letter-spacing: 2px; line-height: 1;
  background: linear-gradient(180deg, #ff7a3d, #ff3d6e);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  text-shadow: 0 3px 0 rgba(0,0,0,.06);
}
.subtitle { font-size: 15px; color: #5a6b86; margin: 4px 0 18px; font-weight: 600; }

.how { text-align: left; display: flex; flex-direction: column; gap: 9px; margin: 4px 0 16px; }
.how-row { display: flex; align-items: flex-start; gap: 10px; font-size: 14px; color: #33425e; line-height: 1.35; }
.how-em { font-size: 20px; flex-shrink: 0; }
.how-row b { color: #ff3d6e; }

.best-line { font-size: 15px; color: #5a6b86; margin-bottom: 14px; }
.best-line b { color: #ff7a3d; font-size: 18px; }

.big-btn {
  width: 100%; border: none; cursor: pointer;
  padding: 16px; border-radius: 16px;
  font-family: 'Space Grotesk', 'Inter', sans-serif;
  font-size: 22px; font-weight: 800; letter-spacing: 1px; color: #fff;
  background: linear-gradient(180deg, #37d67a, #1aa657);
  box-shadow: 0 6px 0 #148544, 0 10px 20px rgba(26,166,87,.4);
  transition: transform .08s, box-shadow .08s;
}
.big-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #148544, 0 4px 10px rgba(26,166,87,.4); }

.screen-lang { display: flex; gap: 6px; justify-content: center; margin-top: 14px; }
.lang-btn {
  cursor: pointer; border: 2px solid #d3ddec; background: #fff; color: #5a6b86;
  border-radius: 10px; padding: 5px 12px; font-weight: 800; font-size: 13px;
}
.lang-btn.active { background: #ff7a3d; border-color: #ff7a3d; color: #fff; }

/* ===== Round clear ===== */
.rc-title {
  font-family: 'Space Grotesk', sans-serif; font-size: 34px; font-weight: 900;
  color: #1aa657; margin-bottom: 6px;
}
.rc-bonus { font-size: 24px; font-weight: 800; color: #ff7a3d; margin-bottom: 8px; }
.rc-next { font-size: 14px; color: #5a6b86; }

/* ===== Game over ===== */
.go-title {
  font-family: 'Space Grotesk', sans-serif; font-size: 40px; font-weight: 900;
  color: #ff3d6e; margin-bottom: 10px;
}
.record-badge {
  display: inline-block; background: linear-gradient(90deg,#ffb300,#ff7a3d);
  color: #fff; font-weight: 800; padding: 6px 16px; border-radius: 999px;
  margin-bottom: 14px; font-size: 15px; animation: pop .4s ease;
}
.go-stats { display: flex; gap: 12px; margin-bottom: 18px; }
.go-stat { flex: 1; background: #eef3fb; border-radius: 14px; padding: 12px; }
.go-k { font-size: 13px; color: #5a6b86; font-weight: 600; margin-bottom: 2px; }
.go-v { font-size: 30px; font-weight: 900; color: #14203a; }
.go-actions { display: flex; gap: 10px; margin-top: 12px; }
.ghost-btn {
  flex: 1; cursor: pointer; text-decoration: none; text-align: center;
  padding: 12px; border-radius: 14px; border: 2px solid #d3ddec;
  background: #fff; color: #33425e; font-weight: 800; font-size: 14px;
  display: flex; align-items: center; justify-content: center;
}
.ghost-btn:active { transform: scale(.96); }

@media (max-width: 380px) {
  .title { font-size: 50px; }
  .screen-card { padding: 22px 18px; }
}

/* Landscape / short screens: compact start card so it fits without clipping */
@media (max-height: 520px) {
  .screen-card { padding: 16px 20px; border-radius: 18px; }
  .title { font-size: 40px; }
  .subtitle { font-size: 13px; margin: 2px 0 10px; }
  .how { gap: 5px; margin: 4px 0 10px; }
  .how-row { font-size: 12.5px; line-height: 1.25; }
  .how-em { font-size: 17px; }
  .best-line { margin-bottom: 10px; }
  .big-btn { padding: 12px; font-size: 19px; }
  .screen-lang { margin-top: 10px; }
}
