/* ===== Mobile Landscape + Accessible Touch Controls ===== */
*,
*::before,
*::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0b1020;
  color: #eaf0ff;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}

#root,
#app {
  position: relative;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* Game canvas container — fills viewport, respects notches/safe areas */
#game-container {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
    env(safe-area-inset-bottom) env(safe-area-inset-left);
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
}

#game-container canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
  touch-action: none;
}

/* HUD overlay layer sits above canvas, never blocks the play field center */
.hud,
#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
    env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.hud > * {
  pointer-events: auto;
}

/* Top HUD bar — pause / mute / guide, thumb-reachable, safe-area aware */
.top-bar {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 8px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 12px;
  z-index: 40;
}

/* ===== Accessible on-screen touch controls ===== */
.touch-controls {
  position: absolute;
  inset: 0;
  z-index: 30;
  pointer-events: none;
}
.touch-cluster {
  position: absolute;
  bottom: calc(env(safe-area-inset-bottom) + 16px);
  display: flex;
  gap: 12px;
  align-items: flex-end;
  pointer-events: none;
}
.touch-cluster.left {
  left: calc(env(safe-area-inset-left) + 16px);
}
.touch-cluster.right {
  right: calc(env(safe-area-inset-right) + 16px);
  flex-wrap: wrap;
  justify-content: flex-end;
  max-width: 58vw;
}

/* Primary touch targets: 64px, high contrast, active press feedback */
.touch-btn {
  pointer-events: auto;
  min-width: 64px;
  min-height: 64px;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.85);
  background: rgba(20, 28, 54, 0.72);
  color: #ffffff;
  font-size: 26px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  box-shadow: 0 0 0 0 rgba(120, 190, 255, 0);
  transition: transform 0.06s ease, background 0.12s ease,
    box-shadow 0.12s ease;
}
.touch-btn.secondary {
  min-width: 56px;
  min-height: 56px;
  width: 56px;
  height: 56px;
  font-size: 20px;
}
.touch-btn .lbl {
  font-size: 11px;
  margin-top: 2px;
}
.touch-btn:active,
.touch-btn.pressed {
  transform: scale(0.92);
  background: rgba(64, 130, 220, 0.92);
  box-shadow: 0 0 18px 4px rgba(120, 190, 255, 0.55);
}
.touch-btn.jump {
  background: rgba(40, 150, 90, 0.8);
}
.touch-btn.interact {
  background: rgba(190, 120, 30, 0.85);
}
.touch-btn.rewind {
  background: rgba(120, 60, 180, 0.85);
}
.touch-btn.reset {
  background: rgba(190, 50, 70, 0.85);
}

/* ===== Portrait -> Landscape rotate prompt overlay ===== */
.rotate-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  text-align: center;
  padding: 24px;
  background: radial-gradient(circle at 50% 40%, #16224a 0%, #0b1020 70%);
}
.rotate-overlay .device {
  width: 64px;
  height: 104px;
  border: 4px solid #8fb6ff;
  border-radius: 12px;
  animation: rotate-hint 2.2s ease-in-out infinite;
}
.rotate-overlay .msg {
  font-size: 18px;
  font-weight: 600;
  max-width: 280px;
}
@keyframes rotate-hint {
  0%,
  20% {
    transform: rotate(0deg);
  }
  60%,
  100% {
    transform: rotate(90deg);
  }
}

/* Show the rotate prompt only in portrait on small screens */
@media (orientation: portrait) and (max-width: 900px) {
  .rotate-overlay {
    display: flex;
  }
}

/* ===== Landscape adaptation for menus / modals / level cards ===== */
@media (orientation: landscape) and (max-height: 500px) {
  .menu,
  .modal,
  .level-select,
  .pause-menu,
  .guide-modal {
    max-height: 92dvh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 12px 16px;
    font-size: 14px;
  }
  .menu h1,
  .modal h2 {
    font-size: 22px;
    margin: 6px 0;
  }
  .btn,
  .menu-btn,
  .level-card {
    min-height: 48px;
  }
}

/* Desktop: hide touch controls when a fine pointer is present */
@media (pointer: fine) {
  .touch-controls {
    display: none;
  }
}

/* ===== FINAL GATE UNSEALED notification badge (upward slide + golden glow) ===== */
.hud-root .gate-notification-badge,
.gate-notification-badge {
  position: absolute;
  top: 12%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  animation: gate-badge-slide-in 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) forwards,
    gate-badge-glow 1.2s ease-in-out 0.6s infinite alternate;
  pointer-events: none;
}
.gate-notification-text {
  display: block;
  padding: 12px 32px;
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #fff;
  background: linear-gradient(135deg, rgba(255, 180, 50, 0.92), rgba(255, 100, 50, 0.88));
  border: 2px solid rgba(255, 220, 100, 0.7);
  border-radius: 8px;
  box-shadow: 0 0 20px rgba(255, 180, 50, 0.5), 0 4px 12px rgba(0, 0, 0, 0.3);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  white-space: nowrap;
}
@keyframes gate-badge-slide-in {
  from { opacity: 0; transform: translateX(-50%) translateY(40px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}
@keyframes gate-badge-glow {
  from { filter: brightness(1) drop-shadow(0 0 6px rgba(255, 200, 80, 0.4)); }
  to   { filter: brightness(1.15) drop-shadow(0 0 14px rgba(255, 200, 80, 0.7)); }
}