:root {
  --ink: #24160f;
  --cream: #fff6e4;
  --saffron: #f28a22;
  --teal: #0e7d72;
  --crimson: #d0122d;
  --sky: #79c0f5;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--sky);
  overflow: hidden;
  position: fixed;
  inset: 0;
  width: 100%;
  touch-action: none;
  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", "Geeza Pro", Tahoma, sans-serif;
}

body.lang-ar {
  font-family: "Geeza Pro", "SF Arabic", "Damascus", Tahoma, "Noto Naskh Arabic", sans-serif;
}

#stage {
  position: fixed;
  inset: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  overflow: hidden;
  touch-action: none;
  direction: ltr;
  background: #79c0f5;
}

canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  background: #79c0f5;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
}

#hud {
  position: absolute;
  top: 4px;
  left: 10px;
  right: 10px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  pointer-events: none;
  direction: ltr;
  color: #fffaf2;
  text-shadow: 2px 2px 0 rgba(20, 16, 12, 0.55);
  z-index: 4;
}

#hud[hidden] { display: none !important; }

#hud .col { display: flex; flex-direction: column; min-width: 0; }
#hud .col.mid { align-items: center; }
#hud .col.end { align-items: flex-end; }
#hud .lbl {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  opacity: 0.92;
}
#hud b {
  font-size: 16px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
}
#hud .sun {
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-inline-end: 4px;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 40%, #fff6c8, #f0b429 60%, #d08010);
  box-shadow: 0 0 0 2px #ffe9a0;
  vertical-align: -1px;
}
#hud-time.hurry { color: #ffe14a; }
#pause-btn {
  pointer-events: auto;
  width: 42px;
  height: 36px;
  border: 3px solid var(--ink);
  background: var(--cream);
  color: var(--ink);
  font-weight: 900;
  border-radius: 10px;
  box-shadow: 0 3px 0 var(--ink);
}
#lives-pip {
  position: absolute;
  top: 40px;
  left: 10px;
  color: #fffaf2;
  font-weight: 800;
  text-shadow: 2px 2px 0 rgba(20, 16, 12, 0.55);
  z-index: 4;
  direction: ltr;
}
#lives-pip[hidden] { display: none !important; }

#touch {
  position: absolute;
  left: 0;
  right: 0;
  bottom: max(6px, env(safe-area-inset-bottom));
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 10px;
  z-index: 6;
  pointer-events: none;
  direction: ltr;
}
#touch[hidden] { display: none !important; }
.cluster { display: flex; gap: 8px; align-items: flex-end; }
#touch button {
  pointer-events: auto;
  border: 3px solid var(--ink);
  color: var(--ink);
  font: inherit;
  font-weight: 900;
  background: rgba(255, 246, 228, 0.82);
  box-shadow: 0 4px 0 rgba(36, 22, 15, 0.85);
  touch-action: none;
}
#touch button.on {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(36, 22, 15, 0.85);
}
.pad {
  width: 64px;
  height: 64px;
  border-radius: 18px;
  font-size: 22px;
}
#btn-jump {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  background: rgba(242, 138, 34, 0.92);
  font-size: 14px;
  line-height: 1.05;
}
#btn-run {
  width: 70px;
  height: 70px;
  border-radius: 50%;
  background: rgba(14, 125, 114, 0.92);
  color: #fffaf2;
  font-size: 13px;
}

#overlay {
  position: absolute;
  inset: 0;
  z-index: 8;
  pointer-events: none;
}
#overlay[hidden] { display: none !important; }
#overlay .panel,
#overlay .card,
#overlay .dock { pointer-events: auto; }

.panel {
  position: absolute;
  top: 10px;
  left: 12px;
  width: min(430px, 58%);
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 4px;
  overflow: visible;
  max-height: calc(100% - 16px);
}
.lang-ar .panel { direction: rtl; text-align: right; }

.wordmark {
  margin: 0;
  color: #fffaf2;
  font-size: clamp(30px, 5vw, 46px);
  line-height: 0.95;
  font-weight: 900;
  letter-spacing: -0.03em;
  text-shadow: 0 3px 0 #8e0c22, 0 6px 0 rgba(20, 10, 8, 0.28);
}
.lang-ar .wordmark { letter-spacing: 0; font-size: clamp(28px, 4.4vw, 40px); }
.subtitle, .fine, .keys {
  margin: 0;
  color: #fffaf2;
  text-shadow: 0 2px 0 rgba(20, 16, 12, 0.45);
  font-weight: 700;
}
.subtitle { font-size: 15px; }
.fine, .keys { font-size: 13px; opacity: 0.95; }

.menu, .row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
  align-items: center;
}

button, .btn {
  appearance: none;
  border: 3px solid var(--ink);
  background: var(--cream);
  color: var(--ink);
  font: inherit;
  font-weight: 800;
  border-radius: 12px;
  padding: 8px 12px;
  box-shadow: 0 3px 0 var(--ink);
  cursor: pointer;
}
button:active, .btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
button.primary { background: var(--saffron); }
button.teal { background: var(--teal); color: #fffaf2; }
button.ghost { background: rgba(255, 246, 228, 0.88); }
button.locked { opacity: 0.5; }

.card {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(460px, calc(100% - 24px));
  max-height: calc(100% - 20px);
  overflow: auto;
  background: var(--cream);
  color: var(--ink);
  border: 4px solid var(--ink);
  border-radius: 18px;
  box-shadow: 6px 6px 0 rgba(20, 12, 8, 0.35);
  padding: 14px 16px 16px;
  text-align: center;
}
.lang-ar .card { direction: rtl; }
.card h2 { margin: 0 0 4px; font-size: 28px; line-height: 1.1; }
.card p { margin: 6px 0; font-weight: 700; }
.card .world-no { letter-spacing: 0.08em; color: var(--crimson); font-size: 14px; }
.levels {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 10px 0;
}
.levels button { min-height: 72px; }
.levels small { display: block; font-weight: 700; opacity: 0.8; }
@media (max-width: 760px) {
  .levels { grid-template-columns: 1fr 1fr; }
  .panel { width: min(320px, 54%); }
}

#rotate {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: #143e72;
  color: #fff6e4;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 8px;
  padding: 24px;
}
#rotate[hidden] { display: none !important; }
#rotate h2 { margin: 8px 0 0; font-size: 28px; }
#rotate p { margin: 0; font-size: 18px; font-weight: 700; }
.phone {
  width: 54px;
  height: 86px;
  border: 4px solid #fff6e4;
  border-radius: 10px;
  position: relative;
  animation: tilt 1.6s ease-in-out infinite;
}
.phone::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 6px;
  width: 10px;
  height: 10px;
  border: 2px solid #fff6e4;
  border-radius: 50%;
  transform: translateX(-50%);
}
@keyframes tilt {
  0%, 30% { transform: rotate(0deg); }
  55%, 100% { transform: rotate(90deg); }
}

@media (max-height: 430px) {
  .keys, .install { display: none; }
  .wordmark { font-size: 34px; }
  .subtitle, .fine { font-size: 13px; }
  .menu { gap: 6px; }
  button, .btn { padding: 7px 10px; }
}

@media (max-height: 360px) {
  .wordmark { font-size: 28px; }
  .card h2 { font-size: 22px; }
  .pad { width: 54px; height: 54px; }
  #btn-jump { width: 70px; height: 70px; }
  #btn-run { width: 60px; height: 60px; }
}
