﻿*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: #0a0a1a;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  color: #fff;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

html:fullscreen,
html:-webkit-full-screen {
  overflow: hidden;
  width: 100%;
  height: 100%;
}

html:fullscreen body,
html:-webkit-full-screen body {
  overflow: hidden;
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
}

html:fullscreen #gameCanvas,
html:-webkit-full-screen #gameCanvas {
  width: 100vw;
  height: 100vh;
  position: fixed;
  inset: 0;
}

/* ===== FULLSCREEN MENU STYLES ===== */
:fullscreen .menu-screen,
:-webkit-full-screen .menu-screen {
  width: 100vw;
  height: 100vh;
}

:fullscreen .game-title,
:-webkit-full-screen .game-title {
  text-shadow:
    0 0 30px rgba(0, 255, 0, 0.7),
    0 0 80px rgba(0, 255, 0, 0.4),
    0 0 130px rgba(0, 255, 0, 0.2);
}

/* ===== ADDITIONAL MOBILE RESPONSIVENESS ===== */
@media (display-mode: standalone) {
  body {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }
}

#gameCanvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  display: block;
}

.hidden {
  display: none !important;
}

kbd {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  padding: 2px 8px;
  font-family: inherit;
  font-size: 0.85em;
  color: #0f0;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.4);
}

/* ===== FULLSCREEN BUTTON ===== */
.fullscreen-btn {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  right: max(14px, env(safe-area-inset-right));
  z-index: 200;
  width: 46px;
  height: 46px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.2s ease, transform 0.2s ease;
}

.fullscreen-btn:hover {
  background: rgba(255, 255, 255, 0.14);
}

.fullscreen-btn:active {
  transform: scale(0.92);
}

.fullscreen-btn svg {
  width: 20px;
  height: 20px;
  display: block;
}

/* ===== MENU SCREENS ===== */
.menu-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  scrollbar-width: none;
  -ms-overflow-style: none;
  animation: fadeIn 0.3s ease;
}
.menu-screen::-webkit-scrollbar { display: none; }

.menu-content {
  margin: auto;
  text-align: center;
  padding: 32px;
  max-width: 520px;
  width: 90%;
}

.menu-scroll {
  max-height: none;
}

/* ===== TITLE ===== */
.game-title {
  font-size: clamp(2.2rem, 9vw, 5rem);
  font-weight: 900;
  letter-spacing: 8px;
  color: #fff;
  text-shadow:
    0 0 20px rgba(0, 255, 0, 0.6),
    0 0 60px rgba(0, 255, 0, 0.3),
    0 0 100px rgba(0, 255, 0, 0.15);
  animation: pulseGlow 2s ease-in-out infinite;
  margin-bottom: 12px;
  line-height: 1.1;
}

.title-dot {
  color: #0f0;
}

.tagline {
  letter-spacing: 6px;
  color: #888;
  margin-bottom: 40px;
  font-size: 0.85rem;
}

.menu-title {
  font-size: 2.5rem;
  color: #0f0;
  text-shadow:
    0 0 15px rgba(0, 255, 0, 0.5),
    0 0 40px rgba(0, 255, 0, 0.2);
  margin-bottom: 30px;
  font-weight: 800;
  letter-spacing: 2px;
}

.game-over-title {
  color: #f44;
  text-shadow:
    0 0 15px rgba(255, 68, 68, 0.5),
    0 0 40px rgba(255, 68, 68, 0.2);
}

.elimination-text {
  font-size: 1rem;
  color: #999;
  letter-spacing: 3px;
  margin-bottom: 16px;
}

.new-best {
  font-size: 1.5rem;
  color: #ffd700;
  animation: newBest 0.6s ease;
  margin-bottom: 20px;
  text-shadow: 0 0 20px rgba(255, 215, 0, 0.4);
}

/* ===== BUTTONS ===== */
.btn {
  display: block;
  width: 100%;
  max-width: 300px;
  margin: 12px auto;
  padding: 16px 32px;
  border: none;
  border-radius: 12px;
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: 3px;
  cursor: pointer;
  transition: all 0.2s ease;
  text-transform: uppercase;
  text-align: center;
  position: relative;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

.btn:active {
  transform: scale(0.95);
}

.btn-play {
  background: linear-gradient(135deg, #00c853 0%, #00e676 50%, #00ff64 100%);
  color: #fff;
  box-shadow: 0 4px 25px rgba(0, 255, 100, 0.35);
}

.btn-play:hover {
  box-shadow: 0 4px 35px rgba(0, 255, 100, 0.55);
  filter: brightness(1.1);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  color: #ccc;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

/* ===== SETTINGS ===== */
.settings-list {
  max-width: 300px;
  margin: 0 auto;
  text-align: left;
}

.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  color: #ccc;
  font-size: 0.9rem;
  letter-spacing: 1px;
}

.setting-row:last-child {
  border-bottom: none;
}

.toggle-btn {
  padding: 8px 20px;
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: transparent;
  color: #888;
  font-weight: 700;
  font-size: 0.8rem;
  letter-spacing: 1px;
  cursor: pointer;
  transition: all 0.25s ease;
  -webkit-tap-highlight-color: transparent;
  min-width: 70px;
}

.toggle-btn.active {
  background: rgba(0, 255, 0, 0.2);
  color: #0f0;
  border-color: #0f0;
  box-shadow: 0 0 10px rgba(0, 255, 0, 0.15);
}

/* ===== SKIN GRID ===== */
.skin-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 12px;
  margin: 20px 0;
}

.skin-btn {
  padding: 12px;
  border-radius: 12px;
  border: 2px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.05);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  transition: all 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.skin-btn:hover {
  border-color: rgba(0, 255, 0, 0.3);
  background: rgba(0, 255, 0, 0.05);
}

.skin-btn.selected {
  border-color: #0f0;
  box-shadow: 0 0 15px rgba(0, 255, 0, 0.3);
}

.skin-preview {
  width: 40px;
  height: 40px;
  border-radius: 50%;
}

.skin-name {
  font-size: 0.8rem;
  color: #aaa;
  letter-spacing: 0.5px;
}

/* ===== HOW TO PLAY ===== */
.instructions {
  text-align: left;
  margin: 20px 0;
}

.instruction-section {
  background: rgba(255, 255, 255, 0.03);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 12px;
}

.instruction-section h3 {
  font-size: 0.85rem;
  color: #0f0;
  letter-spacing: 2px;
  margin-bottom: 10px;
  text-transform: uppercase;
}

.instruction-section p {
  font-size: 0.9rem;
  color: #aaa;
  margin-bottom: 8px;
  line-height: 1.5;
}

.instruction-section p:last-child {
  margin-bottom: 0;
}

/* ===== HUD ===== */
#hud {
    position: fixed;
    inset: 0;
    z-index: 50;
    pointer-events: none;
}

.hud-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    pointer-events: none;
    padding-top: max(12px, env(safe-area-inset-top));
}

.hud-left,
.hud-right {
    display: flex;
    gap: 16px;
    align-items: center;
    margin-right: 200px;
}

.hud-top-right {
    position: fixed;
    top: max(50px, env(safe-area-inset-top));
    right: max(10px, env(safe-area-inset-right));
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
    pointer-events: none;
}

.hud-score,
.hud-length,
.hud-rank,
.hud-best {
    font-size: 0.9rem;
    font-weight: 700;
    color: #fff;
    letter-spacing: 1px;
    white-space: nowrap;
}

.hud-pause {
    background: transparent;
    border: none;
    color: #fff;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    transition: opacity 0.2s;
    pointer-events: auto;
}

.hud-pause:hover {
    opacity: 0.7;
}

/* ===== LEADERBOARD ===== */
.hud-leaderboard {
    width: 180px;
    background: transparent;
    backdrop-filter: none;
    border: none;
    border-radius: 0;
    padding: 4px 0;
    pointer-events: none;
}

.lb-title {
    font-size: 0.6rem;
    text-transform: uppercase;
    letter-spacing: 3px;
    color: rgba(255, 255, 255, 0.5);
    margin-bottom: 4px;
    text-align: right;
}

.lb-entry {
    display: flex;
    justify-content: space-between;
    padding: 2px 0;
    font-size: 0.72rem;
    color: #aaa;
}

.lb-entry.me {
    color: #0f0;
    font-weight: 600;
}

.lb-rank {
    width: 18px;
    color: rgba(255, 255, 255, 0.3);
}

.lb-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.lb-score {
    margin-left: 8px;
    color: rgba(255, 255, 255, 0.5);
}

.lb-separator {
    color: rgba(255, 255, 255, 0.2);
    text-align: center;
    padding: 2px 0;
    font-size: 0.6rem;
    letter-spacing: 2px;
}

/* ===== RANK UP POPUP ===== */
.rank-up {
    position: fixed;
    top: 8%;
    left: 50%;
    transform: translate(-50%, 0);
    z-index: 60;
    font-size: 1.2rem;
    font-weight: 800;
    color: #0f0;
    text-shadow:
        0 0 20px rgba(0, 255, 0, 0.8),
        0 0 50px rgba(0, 255, 0, 0.4);
    pointer-events: none;
    animation: rankUpAnim 1.5s ease forwards;
    letter-spacing: 4px;
    background: transparent;
    backdrop-filter: none;
    padding: 4px 12px;
    border-radius: 0;
    border: none;
}

/* ===== BOUNDARY WARNING ===== */
.boundary-warning {
  position: fixed;
  inset: 0;
  z-index: 40;
  pointer-events: none;
  border: 4px solid transparent;
  animation: boundaryPulse 1s ease infinite;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: max(120px, calc(70px + env(safe-area-inset-bottom)));
  font-size: 0.75rem;
  letter-spacing: 3px;
  color: rgba(255, 80, 80, 0.6);
  font-weight: 700;
}

/* ===== GAME OVER STATS ===== */
.game-over-stats {
  max-width: 300px;
  margin: 20px auto;
  text-align: left;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.stat-row:last-child {
  border-bottom: none;
}

.stat-label {
  font-size: 0.8rem;
  color: #888;
  letter-spacing: 1px;
}

.stat-value {
  font-size: 1.1rem;
  font-weight: 700;
  color: #fff;
}

/* ===== ANIMATIONS ===== */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes pulseGlow {
  0%, 100% {
    text-shadow:
      0 0 20px rgba(0, 255, 0, 0.6),
      0 0 60px rgba(0, 255, 0, 0.3);
  }
  50% {
    text-shadow:
      0 0 30px rgba(0, 255, 0, 0.8),
      0 0 80px rgba(0, 255, 0, 0.5),
      0 0 120px rgba(0, 255, 0, 0.2);
  }
}

@keyframes menuBgPulse {
  0%, 100% {
    background-position: 0% 0%, 100% 100%, 50% 50%, center;
  }
  50% {
    background-position: 30% 20%, 70% 80%, 50% 50%, center;
    background-size: 120% 120%, 110% 110%, 100% 100%, 100% 100%;
  }
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes bounceIn {
  0% {
    opacity: 0;
    transform: scale(0.8);
  }
  60% {
    transform: scale(1.04);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes rankUpAnim {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.5);
  }
  20% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.1);
  }
  40% {
    transform: translate(-50%, -50%) scale(1);
  }
  80% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -60%) scale(0.9);
  }
}

@keyframes boundaryPulse {
  0%, 100% {
    border-color: rgba(255, 60, 60, 0);
    box-shadow: inset 0 0 40px rgba(255, 60, 60, 0);
  }
  50% {
    border-color: rgba(255, 60, 60, 0.5);
    box-shadow: inset 0 0 60px rgba(255, 60, 60, 0.12);
  }
}

@keyframes newBest {
  0% { transform: scale(1); }
  30% { transform: scale(1.12); }
  60% { transform: scale(0.97); }
  100% { transform: scale(1); }
}

/* ===== RESPONSIVE: TABLETS & PHONES ===== */
@media (max-width: 768px) {
  .game-title {
    font-size: clamp(2rem, 9vw, 3rem);
    letter-spacing: 3px;
  }

  .tagline {
    font-size: 0.65rem;
    letter-spacing: 4px;
    margin-bottom: 24px;
  }

  .menu-title {
    font-size: 1.7rem;
    margin-bottom: 20px;
  }

  .menu-content {
    padding: 20px 14px;
    width: 94%;
  }

  .btn {
    padding: 14px 20px;
    font-size: 1rem;
    max-width: 260px;
    margin: 9px auto;
  }

  .hud-leaderboard {
    width: min(150px, 42vw);
    background: transparent;
    backdrop-filter: none;
    border: none;
    padding: 4px 0;
    border-radius: 0;
  }

  .hud-pause {
    background: transparent;
    border: none;
    font-size: 1.1rem;
    padding: 6px;
    border-radius: 0;
  }

  .hud-top-right {
    top: max(50px, env(safe-area-inset-top));
    right: max(8px, env(safe-area-inset-right));
    flex-direction: column;
    gap: 4px;
  }

  .hud-right {
    margin-right: 0;
  }

  .fullscreen-btn {
    top: max(10px, env(safe-area-inset-top));
    right: max(60px, calc(env(safe-area-inset-right) + 150px));
    width: 38px;
    height: 38px;
  }

  .rank-up {
    font-size: 1rem;
    background: transparent;
    backdrop-filter: none;
    padding: 4px 10px;
    border-radius: 0;
    border: none;
    letter-spacing: 1px;
  }

  .boundary-warning {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding-bottom: max(120px, calc(70px + env(safe-area-inset-bottom)));
  }

  .hud-score,
  .hud-length,
  .hud-rank,
  .hud-best {
    font-size: 0.72rem;
  }

  .hud-left,
  .hud-right {
    gap: 8px;
  }

  .hud-top {
    padding: 10px 12px;
    padding-top: max(10px, env(safe-area-inset-top));
  }
}
  .game-over-stats {
    max-width: 260px;
  }

  .stat-label {
    font-size: 0.75rem;
  }

  .stat-value {
    font-size: 0.95rem;
  }

  .instruction-section {
    padding: 12px;
  }

  .skin-grid {
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 8px;
  }

  .fullscreen-btn {
    width: 42px;
    height: 42px;
  }

  .rank-up {
    font-size: 1.2rem;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    padding: 6px 14px;
    border-radius: 8px;
    border: 1px solid rgba(0, 255, 0, 0.15);
    letter-spacing: 2px;
  }

  .boundary-warning {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding-bottom: max(120px, calc(70px + env(safe-area-inset-bottom)));
  }
}

/* ===== RESPONSIVE: SHORT SCREENS / LANDSCAPE PHONES ===== */
@media (max-height: 560px) {
  .game-title {
    font-size: clamp(1.5rem, 8vh, 2.4rem);
    letter-spacing: 2px;
    margin-bottom: 6px;
  }

  .tagline {
    margin-bottom: 14px;
    letter-spacing: 3px;
  }

  .menu-title {
    font-size: 1.3rem;
    margin-bottom: 12px;
  }

  .menu-content {
    padding: 12px 14px;
  }

  .btn {
    padding: 9px 16px;
    margin: 7px auto;
    font-size: 0.85rem;
    max-width: 220px;
  }

  .instruction-section {
    padding: 8px 10px;
    margin-bottom: 8px;
  }

  .instruction-section h3 {
    margin-bottom: 6px;
  }

  .instruction-section p {
    font-size: 0.78rem;
    margin-bottom: 4px;
  }

  .skin-grid {
    margin: 12px 0;
  }

  .setting-row {
    padding: 8px 0;
  }

  .new-best {
    margin-bottom: 12px;
  }
}

@media (max-height: 480px) {
  .hud-leaderboard {
    display: none;
  }
}

/* ===== FULLSCREEN STYLES ===== */
.fullscreen-btn {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  right: max(14px, env(safe-area-inset-right));
  z-index: 200;
  width: 46px;
  height: 46px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.2s ease, transform 0.2s ease, opacity 0.3s ease;
  backdrop-filter: blur(4px);
}

.fullscreen-btn:hover { background: rgba(255, 255, 255, 0.14); }
.fullscreen-btn:active { transform: scale(0.92); }
.fullscreen-btn svg { width: 20px; height: 20px; display: block; }
.fullscreen-btn .fs-compress.hidden,
.fullscreen-btn .fs-expand.hidden { display: none; }

html:fullscreen .fullscreen-btn,
html:-webkit-full-screen .fullscreen-btn {
  background: rgba(0, 0, 0, 0.3);
  border-color: rgba(255, 255, 255, 0.2);
}

/* ===== RESPONSIVE: ORIENTATION SPECIFIC ===== */
@media (orientation: landscape) and (max-height: 500px) {
  .menu-content { padding: 10px 20px; max-width: 90%; }
  .game-title { font-size: clamp(1.4rem, 6vh, 2.2rem); letter-spacing: 2px; margin-bottom: 4px; }
  .tagline { font-size: 0.7rem; letter-spacing: 3px; margin-bottom: 10px; }
  .btn { padding: 8px 14px; font-size: 0.8rem; max-width: 200px; margin: 6px auto; }
  .menu-title { font-size: 1.2rem; margin-bottom: 8px; }
  .instruction-section { padding: 6px 8px; margin-bottom: 6px; }
  .instruction-section h3 { font-size: 0.75rem; margin-bottom: 4px; }
  .instruction-section p { font-size: 0.72rem; margin-bottom: 3px; }
  .fullscreen-btn { width: 38px; height: 38px; top: max(8px, env(safe-area-inset-top)); right: max(8px, env(safe-area-inset-right)); }
}

@media (orientation: portrait) and (max-width: 360px) {
  .menu-content { padding: 16px 10px; width: 96%; }
  .game-title { font-size: clamp(1.8rem, 10vw, 3rem); letter-spacing: 2px; }
  .btn { padding: 12px 16px; font-size: 0.9rem; max-width: 240px; margin: 8px auto; }
  .fullscreen-btn { width: 36px; height: 36px; top: max(8px, env(safe-area-inset-top)); right: max(8px, env(safe-area-inset-right)); }
}

@media (min-width: 1920px) and (min-height: 1080px) {
  .game-title { font-size: clamp(3rem, 8vw, 5.5rem); }
  .tagline { font-size: 1rem; }
  .btn { padding: 20px 40px; font-size: 1.4rem; max-width: 340px; margin: 16px auto; }
  .menu-content { padding: 40px; max-width: 560px; }
  .fullscreen-btn { width: 52px; height: 52px; }
}

@media (min-aspect-ratio: 21/9) {
  .menu-content { max-width: 480px; }
  .game-title { font-size: clamp(2.5rem, 8vw, 4.5rem); }
}

@media (min-width: 768px) and (max-width: 1024px) and (orientation: landscape) {
  .game-title { font-size: clamp(2rem, 6vw, 3.5rem); }
  .menu-content { padding: 24px 20px; max-width: 500px; }
  .btn { padding: 14px 24px; font-size: 1.1rem; max-width: 280px; }
}

@media (min-aspect-ratio: 2/1) and (max-height: 400px) {
  .game-title { font-size: clamp(1rem, 5vh, 1.8rem); letter-spacing: 1px; margin-bottom: 2px; }
  .tagline { font-size: 0.55rem; letter-spacing: 2px; margin-bottom: 6px; }
  .menu-content { padding: 6px 10px; }
  .btn { padding: 5px 10px; font-size: 0.7rem; max-width: 160px; margin: 4px auto; }
  .menu-title { font-size: 1rem; margin-bottom: 6px; }
  .fullscreen-btn { width: 32px; height: 32px; top: max(4px, env(safe-area-inset-top)); right: max(4px, env(safe-area-inset-right)); }
}

@media (min-width: 2560px) {
  .game-title { font-size: clamp(3.5rem, 6vw, 6rem); }
  .btn { padding: 22px 44px; font-size: 1.5rem; max-width: 380px; }
  .menu-content { padding: 48px; max-width: 600px; }
}

@media (orientation: landscape) and (max-height: 500px) and (max-width: 768px) {
  .hud-top-right {
    top: auto;
    bottom: calc(150px + env(safe-area-inset-bottom));
    right: max(8px, env(safe-area-inset-right));
    flex-direction: column-reverse;
    gap: 4px;
  }

  .fullscreen-btn {
    top: max(8px, env(safe-area-inset-top));
    right: max(8px, env(safe-area-inset-right));
    width: 36px;
    height: 36px;
  }

  .rank-up {
    font-size: 1rem;
    padding: 4px 10px;
  }

  .hud-leaderboard {
    width: 120px;
    padding: 6px;
  }
}

@media (orientation: landscape) and (min-width: 769px) {
  .hud-top-right {
    flex-direction: row;
    flex-direction: row-reverse;
    align-items: center;
    gap: 8px;
  }
}

@supports (padding: max(0px)) {
  .menu-content {
    padding-left: max(32px, env(safe-area-inset-left));
    padding-right: max(32px, env(safe-area-inset-right));
  }
}

@media (hover: none) and (pointer: coarse) {
  .btn { min-height: 48px; padding: 16px 24px; }
  .fullscreen-btn { min-width: 44px; min-height: 44px; }
  .hud-pause { padding: 12px; min-width: 44px; min-height: 44px; }
  .toggle-btn { min-height: 44px; min-width: 80px; }
}

/* ===== VIRTUAL JOYSTICK (floating: appears where the player touches) ===== */
.virtual-joystick {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 150;
  pointer-events: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  transform: translate(-50%, -50%);
  opacity: 0.9;
}

.virtual-joystick.hidden {
  display: none !important;
}

.joystick-base {
  position: relative;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  border: 2px solid rgba(255, 255, 255, 0.35);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.28),
              inset 0 0 32px rgba(255, 255, 255, 0.06);
  display: flex;
  align-items: center;
  justify-content: center;
}

.joystick-knob {
  position: absolute;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 40%,
              rgba(255, 255, 255, 0.7) 0%,
              rgba(190, 190, 190, 0.55) 60%,
              rgba(130, 130, 130, 0.45) 100%);
  border: 2px solid rgba(255, 255, 255, 0.5);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.36),
              inset 0 2px 8px rgba(255, 255, 255, 0.3);
  transform: translate(0, 0);
  will-change: transform;
}

@media (max-height: 420px), (max-width: 420px) {
  .joystick-base { width: 104px; height: 104px; }
  .joystick-knob { width: 46px; height: 46px; }
}

.touch-hint {
  position: fixed;
  left: 50%;
  bottom: max(28px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 60;
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.45);
  color: rgba(255, 255, 255, 0.85);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 1.5px;
  white-space: nowrap;
  pointer-events: none;
  animation: hintPulse 1.6s ease-in-out infinite;
}

@keyframes hintPulse {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}

/* ===== GAME ROOT / FORCED LANDSCAPE ===== */
#gameRoot {
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

/* Portrait phone in fullscreen mode: the whole game is rotated into
   landscape (size and transform are set from JS). Fixed children are
   positioned relative to #gameRoot because it has a transform. */
html.force-landscape #gameRoot {
  transform-origin: 0 0;
}

html.force-landscape #gameCanvas,
html.force-landscape .menu-screen {
  width: 100% !important;
  height: 100% !important;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

@media (prefers-contrast: high) {
  .btn { border: 2px solid #fff; }
  .fullscreen-btn { border: 2px solid #fff; }
  .toggle-btn.active { border: 2px solid #0f0; }
}