/* Kingdom Runners — styles */
* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  position: fixed;
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  font-family: "Avenir Next", "Trebuchet MS", "Comic Sans MS", sans-serif;
  background: #5b3fbf;
}

#app { position: fixed; inset: 0; touch-action: none; }

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

/* ---------- Screens ---------- */
.screen {
  position: absolute; inset: 0;
  display: none;
  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));
  z-index: 20;
  touch-action: none;
}
.screen.active { display: flex; }
.hidden { display: none !important; }

#screen-title {
  background: linear-gradient(180deg, #7ec8ff 0%, #a5e0ff 45%, #8ee6a1 100%);
  overflow: hidden;
}
.title-sky { position: absolute; inset: 0; pointer-events: none; }
.cloud {
  position: absolute; width: 140px; height: 48px; border-radius: 40px;
  background: rgba(255,255,255,.9);
  box-shadow: 30px -18px 0 6px rgba(255,255,255,.9), 65px -6px 0 2px rgba(255,255,255,.9);
  animation: drift 40s linear infinite;
}
.cloud.c1 { top: 10%; left: -20%; }
.cloud.c2 { top: 24%; left: -50%; animation-duration: 55s; transform: scale(.7); }
.cloud.c3 { top: 6%; left: -80%; animation-duration: 70s; transform: scale(1.2); }
@keyframes drift { from { transform: translateX(0); } to { transform: translateX(160vw); } }

.title-box {
  position: relative; text-align: center;
  background: rgba(255,255,255,.85);
  border-radius: 32px; padding: 28px 36px;
  box-shadow: 0 12px 0 rgba(60,40,120,.18);
  max-width: 92vw;
}
.title-crown { font-size: 52px; animation: bob 2.2s ease-in-out infinite; }
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
.game-title {
  font-size: clamp(40px, 8vw, 68px); line-height: 1.02;
  color: #5b3fbf; letter-spacing: 1px;
  text-shadow: 0 4px 0 #ffd93d;
}
.tagline { margin: 12px 0 20px; font-size: clamp(15px, 2.4vw, 20px); color: #4a3d7a; font-weight: 600; }
.hint-2p { margin-top: 14px; font-size: 14px; color: #6a5aa8; font-weight: 600; }

.mode-buttons { display: flex; gap: 18px; justify-content: center; flex-wrap: wrap; }

.big-btn {
  min-width: 180px; min-height: 64px;
  padding: 14px 26px;
  font-family: inherit; font-size: 22px; font-weight: 800;
  color: #fff; border: none; border-radius: 20px;
  cursor: pointer; touch-action: manipulation;
  transition: transform .1s;
}
.big-btn:active { transform: scale(.94); }
.btn-1p { background: linear-gradient(180deg, #4cd964, #2fae4a); box-shadow: 0 6px 0 #1e8236; }
.btn-2p { background: linear-gradient(180deg, #ff9f43, #f37f1a); box-shadow: 0 6px 0 #c05f08; }
.btn-soft { background: linear-gradient(180deg, #9b8bd8, #7a63c4); box-shadow: 0 6px 0 #55429b; }

/* ---------- Picker ---------- */
#screen-picker, #screen-map {
  background: linear-gradient(180deg, #6d4fd4 0%, #4a2fa8 100%);
}
.screen-heading {
  color: #fff; font-size: clamp(26px, 4.5vw, 40px);
  text-shadow: 0 3px 0 rgba(0,0,0,.25);
  margin-bottom: 14px; text-align: center;
}
.picker-grid {
  display: grid; grid-template-columns: repeat(4, minmax(120px, 160px));
  gap: 14px; justify-content: center; max-width: 92vw;
}
@media (max-width: 820px) { .picker-grid { grid-template-columns: repeat(2, minmax(130px, 180px)); } }
.hero-card {
  min-height: 108px; border: none; border-radius: 22px;
  background: rgba(255,255,255,.94);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; padding: 12px; cursor: pointer;
  font-family: inherit; box-shadow: 0 5px 0 rgba(0,0,0,.22);
  transition: transform .1s; touch-action: manipulation;
}
.hero-card:active { transform: scale(.93); }
.hero-card.taken { opacity: .38; pointer-events: none; }
.hero-emoji { font-size: 44px; line-height: 1; }
.hero-name { font-size: 16px; font-weight: 800; color: #3d2f73; }
.hero-tag { font-size: 11px; font-weight: 700; color: #8b7fc0; }

/* ---------- Map ---------- */
.map-sub { color: #d8ccff; font-weight: 700; margin-bottom: 10px; font-size: 15px; text-align: center; }
.map-scroll {
  width: 100%; max-width: 1080px; overflow-y: auto; overflow-x: hidden;
  -webkit-overflow-scrolling: touch; touch-action: pan-y;
  max-height: 62vh; padding: 4px 8px 18px;
}
.map-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 14px;
}
.stage-card {
  border: none; border-radius: 20px; padding: 14px;
  min-height: 130px; text-align: left; cursor: pointer;
  font-family: inherit; box-shadow: 0 5px 0 rgba(0,0,0,.25);
  display: flex; flex-direction: column; gap: 4px;
  transition: transform .1s; touch-action: manipulation;
  color: #fff; position: relative;
}
.stage-card:active { transform: scale(.96); }
.stage-card.locked { filter: grayscale(.85) brightness(.72); cursor: default; }
.stage-num { font-size: 12px; font-weight: 800; opacity: .85; }
.stage-name { font-size: 20px; font-weight: 900; text-shadow: 0 2px 0 rgba(0,0,0,.25); }
.stage-mech { font-size: 12px; font-weight: 700; opacity: .92; }
.stage-best { margin-top: auto; font-size: 13px; font-weight: 800; background: rgba(0,0,0,.22); border-radius: 10px; padding: 4px 8px; align-self: flex-start; }
.stage-lock { position: absolute; top: 10px; right: 12px; font-size: 24px; }
.stage-stars { position: absolute; top: 10px; right: 12px; font-size: 14px; letter-spacing: 1px; }

/* ---------- Nav ---------- */
.nav-btn {
  margin-top: 16px; min-height: 60px; min-width: 130px;
  border: none; border-radius: 18px;
  background: rgba(255,255,255,.2); color: #fff;
  font-family: inherit; font-size: 19px; font-weight: 800;
  cursor: pointer; touch-action: manipulation;
}
.nav-btn:active { transform: scale(.95); }

/* ---------- HUD ---------- */
#hud { position: absolute; inset: 0; z-index: 10; pointer-events: none; }
.hud-top {
  position: absolute; top: max(10px, env(safe-area-inset-top));
  left: 12px; right: 12px;
  display: flex; align-items: center; gap: 10px;
}
.hud-btn {
  width: 62px; height: 62px; border: none; border-radius: 18px;
  background: rgba(255,255,255,.9); font-size: 28px;
  box-shadow: 0 4px 0 rgba(0,0,0,.25); cursor: pointer;
  pointer-events: auto; touch-action: manipulation;
}
.hud-stage {
  font-size: 17px; font-weight: 900; color: #fff;
  text-shadow: 0 2px 3px rgba(0,0,0,.5);
}
.hud-timer {
  margin-left: auto; font-size: 24px; font-weight: 900; color: #fff;
  background: rgba(0,0,0,.35); padding: 8px 16px; border-radius: 16px;
  font-variant-numeric: tabular-nums; min-width: 110px; text-align: center;
}
.hud-player {
  position: absolute; top: calc(max(10px, env(safe-area-inset-top)) + 70px);
  left: 12px; font-size: 15px; font-weight: 800; color: #fff;
  background: rgba(0,0,0,.3); padding: 6px 12px; border-radius: 12px;
}
.hud-stars {
  position: absolute; top: calc(max(10px, env(safe-area-inset-top)) + 70px);
  right: 12px; font-size: 18px; font-weight: 800; color: #ffd93d;
  background: rgba(0,0,0,.3); padding: 6px 12px; border-radius: 12px;
}
.toast {
  position: absolute; top: 26%; left: 50%; transform: translateX(-50%) scale(.8);
  background: rgba(255,255,255,.95); color: #4a2fa8;
  font-size: 24px; font-weight: 900; padding: 12px 26px; border-radius: 20px;
  opacity: 0; transition: opacity .25s, transform .25s;
  box-shadow: 0 6px 0 rgba(0,0,0,.2); pointer-events: none;
  text-align: center; max-width: 86vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) scale(1); }

.touch-zone { position: absolute; bottom: 0; height: 78%; touch-action: none; pointer-events: auto; }
#touch-move { left: 0; width: 45%; }
#touch-look { right: 0; width: 55%; }

#joystick {
  position: absolute; width: 130px; height: 130px;
  border-radius: 50%; background: rgba(255,255,255,.18);
  border: 3px solid rgba(255,255,255,.5);
  pointer-events: none; transform: translate(-50%, -50%);
}
#joystick-knob {
  position: absolute; left: 50%; top: 50%; width: 56px; height: 56px;
  border-radius: 50%; background: rgba(255,255,255,.85);
  transform: translate(-50%, -50%);
  box-shadow: 0 3px 8px rgba(0,0,0,.3);
}

#btn-jump {
  position: absolute; right: max(22px, env(safe-area-inset-right));
  bottom: max(26px, env(safe-area-inset-bottom));
  width: 110px; height: 110px; border-radius: 50%;
  border: none; background: linear-gradient(180deg, #ffd93d, #ffb347);
  box-shadow: 0 6px 0 #d98e1f;
  font-family: inherit; font-size: 34px; font-weight: 900; color: #7a4a00;
  pointer-events: auto; touch-action: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  line-height: 1;
}
#btn-jump span { font-size: 15px; letter-spacing: 1px; }
#btn-jump.pressed { transform: scale(.92); box-shadow: 0 3px 0 #d98e1f; }

/* ---------- Dialogs / overlays ---------- */
.overlay { background: rgba(30, 18, 70, .55); z-index: 30; }
.hidden-screen { display: none; }
.hidden-screen.active { display: flex; }
#screen-handoff { background: linear-gradient(180deg, #ff9f43, #ffce54); z-index: 30; }
#screen-results { background: linear-gradient(180deg, #6d4fd4, #4a2fa8); z-index: 30; }

.dialog {
  background: #fff; border-radius: 28px; padding: 30px 34px;
  max-width: min(92vw, 520px); width: 100%;
  text-align: center; box-shadow: 0 12px 0 rgba(0,0,0,.22);
  display: flex; flex-direction: column; gap: 14px; align-items: center;
  max-height: 88vh; overflow-y: auto; touch-action: pan-y;
}
.dialog h2 { color: #4a2fa8; font-size: clamp(24px, 4vw, 34px); }
.tut-row {
  display: flex; align-items: center; gap: 14px; width: 100%;
  background: #f2eeff; border-radius: 16px; padding: 10px 14px;
  font-size: 16px; font-weight: 700; color: #3d2f73; text-align: left;
}
.tut-icon { font-size: 32px; flex-shrink: 0; }

.finish-burst { font-size: 56px; animation: bob 1.6s ease-in-out infinite; }
.finish-time { font-size: 42px; font-weight: 900; color: #2fae4a; font-variant-numeric: tabular-nums; }
.finish-note { font-size: 17px; font-weight: 800; color: #7a63c4; }
.finish-buttons { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; }

.handoff-emoji { font-size: 64px; animation: bob 1.8s ease-in-out infinite; }
.handoff-text { font-size: 20px; font-weight: 800; color: #b3551a; }

.results-rows { display: flex; flex-direction: column; gap: 10px; width: 100%; }
.result-row {
  display: flex; align-items: center; gap: 12px;
  background: #f2eeff; border-radius: 16px; padding: 12px 16px;
}
.result-row .hero-emoji { font-size: 34px; }
.result-info { text-align: left; flex: 1; }
.result-name { font-weight: 900; color: #3d2f73; font-size: 18px; }
.result-cheerline { font-size: 13px; font-weight: 700; color: #8b7fc0; }
.result-time { font-size: 24px; font-weight: 900; color: #4a2fa8; font-variant-numeric: tabular-nums; }
.results-cheer { font-size: 16px; font-weight: 800; color: #7a63c4; }

/* ---------- Confetti ---------- */
#confetti-layer { position: absolute; inset: 0; pointer-events: none; z-index: 40; overflow: hidden; }
.confetti-bit {
  position: absolute; top: -20px; width: 12px; height: 12px;
  border-radius: 3px; animation: fall linear forwards;
}
@keyframes fall {
  to { transform: translateY(110vh) rotate(720deg); opacity: .9; }
}

#orientation-note {
  position: absolute; bottom: 8px; left: 50%; transform: translateX(-50%);
  color: rgba(255,255,255,.0); font-size: 0; pointer-events: none;
}
