* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  height: 100dvh;
  width: 100%;
  width: 100dvw;
  overflow: hidden;
  background: radial-gradient(circle at 50% 30%, #151f32 0%, #0a0e17 70%, #04070c 100%);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color: #f1f5f9;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

/* Three.js Canvas */
#webgl-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
  outline: none;
  touch-action: none;
  cursor: pointer;
}

/* ==========================================
   MENU INICIAL (START SCREEN - MOBILE FIRST)
   ========================================== */
.menu-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: radial-gradient(circle at 50% 35%, rgba(15, 23, 42, 0.72) 0%, rgba(3, 7, 18, 0.88) 100%);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  transition: opacity 0.28s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.28s;
  pointer-events: auto;
}

.menu-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.menu-overlay.fade-in .menu-card {
  animation: menuCardIn 0.32s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.menu-overlay.fade-out {
  opacity: 0;
}

.menu-overlay.fade-out .menu-card {
  transform: scale(0.94);
  transition: transform 0.26s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes menuCardIn {
  from {
    opacity: 0;
    transform: scale(0.92) translateY(12px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.menu-card {
  width: 100%;
  max-width: min(92vw, 420px);
  background: linear-gradient(165deg, rgba(26, 38, 62, 0.94) 0%, rgba(11, 18, 33, 0.98) 100%);
  border: 1px solid rgba(56, 189, 248, 0.28);
  border-radius: 26px;
  padding: 24px 20px;
  box-shadow: 0 25px 60px -10px rgba(0, 0, 0, 0.9), 0 0 35px rgba(56, 189, 248, 0.16);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  position: relative;
  overflow: hidden;
}

.menu-card::before {
  content: "";
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle at 50% 10%, rgba(56, 189, 248, 0.12), transparent 55%);
  pointer-events: none;
}

/* Top Hero Area */
.menu-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
  width: 100%;
}

.menu-badge {
  background: linear-gradient(90deg, rgba(56, 189, 248, 0.15), rgba(168, 85, 247, 0.15));
  border: 1px solid rgba(56, 189, 248, 0.4);
  color: #38bdf8;
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 1px;
  padding: 4px 12px;
  border-radius: 20px;
  text-transform: uppercase;
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.2);
}

.menu-title {
  font-size: clamp(22px, 6.2vw, 29px);
  font-weight: 900;
  letter-spacing: -0.6px;
  line-height: 1.15;
  background: linear-gradient(135deg, #ffffff 25%, #7dd3fc 70%, #c084fc 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin: 0;
  text-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.menu-subtitle {
  font-size: clamp(12px, 3.3vw, 13.5px);
  color: #94a3b8;
  line-height: 1.4;
  max-width: 320px;
  margin: 0;
}

/* Banner de Recorde (High Score) */
.record-banner {
  width: 100%;
  background: linear-gradient(135deg, rgba(251, 191, 36, 0.12), rgba(245, 158, 11, 0.05));
  border: 1px solid rgba(251, 191, 36, 0.35);
  border-radius: 16px;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  box-shadow: 0 4px 18px rgba(251, 191, 36, 0.15);
}

.record-icon {
  font-size: 26px;
  animation: trophyBob 2s ease-in-out infinite;
}

@keyframes trophyBob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px) rotate(4deg); }
}

.record-content {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.record-label {
  font-size: 9.5px;
  font-weight: 800;
  color: #f59e0b;
  letter-spacing: 0.8px;
  text-transform: uppercase;
}

.record-value {
  font-size: 22px;
  font-weight: 900;
  color: #fef08a;
  line-height: 1.1;
  text-shadow: 0 0 14px rgba(251, 191, 36, 0.6);
}

/* Menu Actions & Buttons */
.menu-actions {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Botão Principal Jogar */
.btn-play {
  width: 100%;
  min-height: 56px;
  background: linear-gradient(135deg, #0284c7 0%, #2563eb 60%, #4f46e5 100%);
  border: 1px solid rgba(125, 211, 252, 0.5);
  border-radius: 16px;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  cursor: pointer;
  box-shadow: 0 8px 25px rgba(2, 132, 199, 0.5), 0 0 18px rgba(56, 189, 248, 0.35);
  transition: all 0.22s cubic-bezier(0.16, 1, 0.3, 1);
  position: relative;
  overflow: hidden;
}

.btn-play::after {
  content: "";
  position: absolute;
  top: -50%;
  left: -60%;
  width: 50%;
  height: 200%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.35), transparent);
  transform: rotate(25deg);
  animation: playShine 3s ease-in-out infinite;
}

@keyframes playShine {
  0%   { left: -60%; }
  35%  { left: 140%; }
  100% { left: 140%; }
}

.btn-play:hover {
  transform: translateY(-2px) scale(1.01);
  box-shadow: 0 12px 30px rgba(2, 132, 199, 0.65), 0 0 25px rgba(56, 189, 248, 0.5);
}

.btn-play:active {
  transform: translateY(1px) scale(0.97);
}

.btn-play-icon {
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-play-text {
  font-size: 17px;
  font-weight: 900;
  letter-spacing: 0.8px;
}

/* Secondary Button Row */
.menu-secondary-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  width: 100%;
}

.btn-secondary {
  min-height: 44px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 12px;
  color: #e2e8f0;
  font-size: 12.5px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  backdrop-filter: blur(8px);
}

.btn-secondary:hover {
  background: rgba(56, 189, 248, 0.18);
  border-color: rgba(56, 189, 248, 0.4);
  color: #ffffff;
  transform: translateY(-1px);
}

.btn-secondary:active {
  transform: scale(0.97);
}

/* Tertiary Button Row */
.menu-tertiary-row {
  display: flex;
  width: 100%;
}

.btn-tertiary {
  min-height: 38px;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  color: #94a3b8;
  font-size: 11.5px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.2s ease;
  width: 100%;
}

.btn-tertiary:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #f1f5f9;
}

.menu-footer-tip {
  font-size: 11px;
  color: #64748b;
  text-align: center;
  line-height: 1.35;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}

/* ==========================================
   MODAL COMO JOGAR
   ========================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 250;
  background: rgba(3, 7, 18, 0.85);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  opacity: 1;
  visibility: visible;
  transition: opacity 0.25s, visibility 0.25s;
}

.modal-backdrop.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.modal-dialog {
  width: 100%;
  max-width: min(92vw, 440px);
  max-height: 88dvh;
  background: linear-gradient(165deg, rgba(20, 29, 47, 0.98), rgba(9, 14, 26, 0.99));
  border: 1px solid rgba(56, 189, 248, 0.3);
  border-radius: 22px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.95);
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

.modal-title {
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-title h3 {
  font-size: 18px;
  font-weight: 800;
  color: #f8fafc;
  margin: 0;
}

.rules-container {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.rule-card {
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.rule-icon {
  font-size: 20px;
  flex-shrink: 0;
  margin-top: 2px;
}

.rule-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.rule-title {
  font-size: 13px;
  font-weight: 700;
  color: #38bdf8;
}

.rule-body p {
  font-size: 11.5px;
  color: #94a3b8;
  line-height: 1.4;
  margin: 0;
}

.btn-got-it {
  width: 100%;
  min-height: 44px;
  background: linear-gradient(135deg, #0284c7, #2563eb);
  border: 1px solid #38bdf8;
  border-radius: 12px;
  color: #fff;
  font-size: 13.5px;
  font-weight: 800;
  cursor: pointer;
  margin-top: 4px;
  transition: all 0.2s;
}

.btn-got-it:hover {
  background: linear-gradient(135deg, #0369a1, #1d4ed8);
}

.btn-got-it:active {
  transform: scale(0.98);
}

/* ==========================================
   HUD DO JOGO (GAMEPLAY OVERLAY)
   ========================================== */
#ui-container {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  padding: max(8px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  z-index: 10;
  transition: opacity 0.28s ease, transform 0.28s ease;
}

#ui-container.menu-active {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.98);
}

/* Header Section */
.header {
  width: 100%;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  pointer-events: none;
}

.title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  pointer-events: none;
  gap: 6px;
}

.header-right-btns {
  display: flex;
  align-items: center;
  gap: 6px;
  pointer-events: auto;
}

h1 {
  font-size: clamp(15px, 4.2vw, 19px);
  font-weight: 800;
  letter-spacing: -0.4px;
  background: linear-gradient(135deg, #ffffff 40%, #94a3b8 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  pointer-events: none;
}

/* Botões de Ícone Compactos no HUD */
.icon-hud-btn {
  pointer-events: auto;
  background: rgba(15, 23, 42, 0.8);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #e2e8f0;
  min-height: 34px;
  padding: 4px 10px;
  border-radius: 18px;
  font-size: 11.5px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  text-decoration: none;
}

.icon-hud-btn:hover {
  background: rgba(56, 189, 248, 0.22);
  border-color: rgba(56, 189, 248, 0.4);
  color: #fff;
  transform: translateY(-1px);
}

.icon-hud-btn:active {
  transform: scale(0.95);
}

.icon-hud-btn-subtle {
  padding: 4px 8px;
  font-size: 10px;
  color: #94a3b8;
}

.subtitle {
  font-size: clamp(10.5px, 2.8vw, 11.5px);
  color: #94a3b8;
  text-align: center;
  font-weight: 400;
  pointer-events: none;
}

/* Score Bar Adaptável */
.score-bar {
  display: flex;
  gap: 6px;
  width: 100%;
  margin-top: 1px;
  pointer-events: none;
}

.score-card {
  flex: 1;
  min-width: 0;
  background: rgba(15, 23, 42, 0.8);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 12px;
  padding: 5px 6px;
  text-align: center;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

.score-label {
  font-size: clamp(8px, 2.2vw, 9px);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: #64748b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.score-value {
  font-size: clamp(16px, 4.8vw, 20px);
  font-weight: 800;
  color: #f8fafc;
  line-height: 1.15;
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#score { color: #38bdf8; text-shadow: 0 0 12px rgba(56,189,248,0.4); }
#combo { color: #a855f7; text-shadow: 0 0 12px rgba(168,85,247,0.4); }
#bonus { color: #fbbf24; text-shadow: 0 0 12px rgba(251,191,36,0.4); }

/* Bonus Container */
.bonus-bar-container {
  width: 100%;
  background: rgba(15, 23, 42, 0.8);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 10px;
  padding: 5px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  transition: transform 0.3s, background 0.3s, box-shadow 0.3s;
  pointer-events: none;
}

.bonus-bar-container.flash {
  animation: bonusGlow 0.6s ease-out;
}

@keyframes bonusGlow {
  0%   { transform: scale(1); background: rgba(15, 23, 42, 0.8); }
  40%  { transform: scale(1.03); background: rgba(251, 191, 36, 0.25); box-shadow: 0 0 20px rgba(251, 191, 36, 0.6); }
  100% { transform: scale(1); background: rgba(15, 23, 42, 0.8); }
}

.bonus-info-label {
  font-size: clamp(8.5px, 2.5vw, 10px);
  font-weight: 600;
  color: #94a3b8;
  white-space: nowrap;
  letter-spacing: 0.2px;
}

.bonus-bar {
  display: flex;
  gap: 4px;
  flex: 1;
  height: 8px;
}

.bonus-segment {
  flex: 1;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.08);
  transition: all 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.bonus-segment.filled {
  background: linear-gradient(90deg, #fbbf24, #f43f5e);
  box-shadow: 0 0 8px rgba(251, 191, 36, 0.85);
  transform: scaleY(1.2);
}

/* Footer Section */
.footer {
  width: 100%;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
  margin-bottom: 4px;
}

#status {
  background: rgba(15, 23, 42, 0.88);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 5px 14px;
  border-radius: 18px;
  font-size: clamp(11px, 3vw, 12px);
  font-weight: 500;
  color: #e2e8f0;
  text-align: center;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
  pointer-events: none;
  max-width: 92%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.actions {
  display: flex;
  gap: 8px;
  pointer-events: auto;
}

.btn {
  background: linear-gradient(135deg, rgba(255,255,255,0.14), rgba(255,255,255,0.06));
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: #f8fafc;
  padding: 8px 16px;
  min-height: 38px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  pointer-events: auto;
}

.btn:hover {
  background: linear-gradient(135deg, rgba(255,255,255,0.24), rgba(255,255,255,0.1));
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
}

.btn:active {
  transform: translateY(1px) scale(0.97);
}

/* 3D Floating Score Popup */
.score-popup {
  position: absolute;
  pointer-events: none;
  font-weight: 900;
  font-size: 24px;
  color: #fbbf24;
  text-shadow: 0 0 16px rgba(251,191,36,0.8), 0 3px 8px rgba(0,0,0,0.8);
  transform: translate(-50%, -50%);
  animation: floatUp 1.1s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  z-index: 50;
}

@keyframes floatUp {
  0% { transform: translate(-50%, 0) scale(0.6); opacity: 0; }
  25% { transform: translate(-50%, -18px) scale(1.2); opacity: 1; }
  75% { transform: translate(-50%, -45px) scale(1.0); opacity: 0.9; }
  100% { transform: translate(-50%, -65px) scale(0.85); opacity: 0; }
}

/* ==========================================
   MEDIA QUERIES PARA CELULAR (< 480px)
   ========================================== */
@media (max-width: 480px) {
  .hud-btn-label {
    display: none;
  }
  .icon-hud-btn {
    padding: 6px 9px;
    border-radius: 50%;
    min-height: 36px;
    min-width: 36px;
  }
  .header {
    gap: 4px;
  }
  .score-card {
    padding: 4px 4px;
  }
}
