@import url("https://fonts.googleapis.com/css2?family=Montserrat:wght@900&display=swap");

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: white;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  cursor: pointer;
  overflow: hidden;
  background: linear-gradient(to bottom, var(--bg-gradient-top), var(--bg-gradient-top) 70%, var(--bg-gradient-bottom) 70%, var(--bg-gradient-bottom) 100%);
  /* Support for notched devices */
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  /* Better text rendering */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* UI Elements */
#instructions,
#results,
#score,
#youtube-card {
  position: absolute;
  z-index: 10;
  color: white;
  text-align: center;
  user-select: none;
}

#instructions {
  top: clamp(8px, 2.5vh, 20px);
  left: 50%;
  transform: translateX(-50%);
  display: block;
  padding: 0.6rem 1rem;
  background: rgb(0 0 0 / 18%);
  border-radius: 8px;
}

#results {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: none;
  padding: 0;
  background: linear-gradient(135deg, rgba(50, 40, 30, 0.95), rgba(40, 35, 25, 0.95));
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5),
    0 0 0 1px rgba(255, 200, 100, 0.2),
    inset 0 1px 0 rgba(255, 220, 150, 0.15);
  backdrop-filter: blur(10px);
  width: 90%;
  /* take most of the screen */
  max-width: 700px;
  /* limit on large screens */
  min-width: 280px;
  /* minimum size on small devices */
  animation: resultsFadeIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes resultsFadeIn {
  from {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.8);
  }

  to {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
}

#results .content {
  padding: 2rem 2rem;
  width: 100%;
}

.game-over-title {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
  animation: bounceIn 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes bounceIn {
  0% {
    transform: scale(0);
    opacity: 0;
  }

  50% {
    transform: scale(1.1);
  }

  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.game-over-title h1 {
  margin: 0;
  font-size: clamp(1.75rem, 5vw, 2.3rem);
  font-weight: 900;
  background: linear-gradient(135deg, #ff6b6b, #ffd93d);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 2px 10px rgba(255, 107, 107, 0.3);
}

.miss-icon {
  width: clamp(2rem, 6vw, 3rem);
  height: clamp(2rem, 6vw, 3rem);
  color: #ff6b6b;
  filter: drop-shadow(0 0 10px rgba(255, 107, 107, 0.5));
  animation: rotate 0.6s ease-in-out;
}

@keyframes rotate {
  from {
    transform: rotate(-180deg);
  }

  to {
    transform: rotate(0deg);
  }
}

.miss-message {
  color: rgba(255, 255, 255, 0.7);
  font-size: clamp(0.9rem, 2.5vw, 1.2rem);
  margin: 1rem 0 1.5rem 0;
  font-weight: 500;
}

.score-container {
  display: flex;
  gap: 1rem;
  margin: 2.3rem 0;
  align-items: stretch;
  justify-content: center;
  animation: slideUp 0.5s ease-out 0.2s backwards;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.score-card {
  flex: 1;
  background: rgba(60, 50, 40, 0.4);
  border: 1px solid rgba(255, 200, 100, 0.15);
  border-radius: 12px;
  padding: 1rem 1rem 2rem;
  text-align: center;
  transition: all 0.3s ease;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.score-card:hover {
  background: rgba(80, 65, 50, 0.5);
  transform: translateY(-2px);
  box-shadow: 0 4px 15px rgba(255, 150, 50, 0.2);
}

.score-label {
  font-size: clamp(0.7rem, 2vw, 0.85rem);
  text-transform: uppercase;
  letter-spacing: 1px;
  color: rgba(255, 255, 255, 0.6);
  margin-bottom: 1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 1.5rem;
}

.trophy-icon {
  width: 1rem;
  height: 1rem;
  color: #ffcc00;
  filter: drop-shadow(0 0 5px rgba(255, 204, 0, 0.5));
}

.score-value {
  font-size: clamp(2rem, 6vw, 3rem);
  font-weight: 900;
  line-height: 1;
  background: linear-gradient(135deg, #ffd93d, #ffb84d);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 2px 10px rgba(255, 217, 61, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.high-score .score-value {
  background: linear-gradient(135deg, #ffcc00, #ff9900);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 2px 10px rgba(255, 153, 0, 0.4);
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {

  0%,
  100% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.05);
  }
}

.score-divider {
  width: 1px;
  background: linear-gradient(to bottom,
      transparent,
      rgba(255, 200, 100, 0.25),
      transparent);
}

.restart-hint {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin: 2rem 0 1rem;
  color: rgba(255, 255, 255, 0.8);
  font-size: clamp(0.85rem, 2.2vw, 1rem);
  animation: slideUp 0.5s ease-out 0.4s backwards;
}

.restart-icon {
  width: 1.2rem;
  height: 1.2rem;
  color: #ffb84d;
  animation: spin 2s linear infinite;
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(360deg);
  }
}

.restart-hint kbd {
  background: linear-gradient(135deg, rgba(80, 60, 40, 0.6), rgba(60, 45, 30, 0.6));
  border: 1px solid rgba(255, 200, 100, 0.3);
  border-radius: 6px;
  padding: 0.3rem 0.6rem;
  font-family: 'Courier New', monospace;
  font-weight: 700;
  font-size: clamp(0.85rem, 2.2vw, 1rem);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.3),
    inset 0 1px 0 rgba(255, 220, 150, 0.2);
  color: #ffcc00;
}

.social-follow {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid rgba(255, 200, 100, 0.15);
  color: rgba(255, 255, 255, 0.7);
  font-size: clamp(0.85rem, 2.2vw, 0.95rem);
  animation: slideUp 0.5s ease-out 0.6s backwards;
}

.twitter-link {
  color: #1da1f2;
  text-decoration: none;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.3rem 0.6rem;
  border-radius: 6px;
  transition: all 0.3s ease;
  margin-left: 0.3rem;
}

.twitter-link:hover {
  background: rgba(29, 161, 242, 0.1);
  transform: translateY(-1px);
  color: #1da1f2;
}

.twitter-link svg {
  width: 1rem;
  height: 1rem;
}

#score {
  position: absolute;
  top: clamp(8px, 2.5vh, 20px);
  right: clamp(8px, 2.5vw, 20px);
  font-size: clamp(1rem, 3.5vw, 2rem);
  font-weight: bold;
  padding: 0.3rem 1rem;
  background: rgb(0 0 0 / 18%);
  border-radius: 6px;
  z-index: 11;
}

#youtube {
  position: absolute;
  bottom: 10px;
  left: 10px;
  color: white;
  text-decoration: none;
  display: none;
}

#youtube-card {
  position: absolute;
  bottom: 50px;
  left: 10px;
  color: white;
  display: none;
}

/* Make the canvas cover the full viewport and sit behind UI */
canvas {
  display: block;
  z-index: 1;
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
}

a:visited {
  color: inherit;
}

/* Add diamond icon after score */
.score-value::after {
  content: '◆';
  display: inline-block;
  font-size: 0.6em;
  opacity: 0.9;
  transform: translateY(-0.1em);
}

/* Theme Controls */
.theme-btn {
  background: rgba(255, 255, 255, 0.2);
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 12px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 1.2rem;
  transition: all 0.3s ease;
  backdrop-filter: blur(10px);
}

.theme-btn:hover {
  background: rgba(255, 255, 255, 0.3);
  border-color: rgba(255, 255, 255, 0.6);
  transform: scale(1.1);
}

.theme-btn.active {
  background: rgba(255, 200, 100, 0.4);
  border-color: rgba(255, 200, 100, 0.8);
  box-shadow: 0 0 15px rgba(255, 200, 100, 0.3);
}

/* Close Button */
.close-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  background: rgba(255, 200, 100, 0.2);
  border: 2px solid rgba(255, 200, 100, 0.4);
  color: rgba(255, 200, 100, 0.8);
  font-size: 2rem;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  z-index: 100;
  padding: 0;
  line-height: 1;
}

.close-btn:hover {
  background: rgba(255, 200, 100, 0.4);
  border-color: rgba(255, 200, 100, 0.8);
  color: #ffcc00;
  transform: scale(1.1);
}

/* Responsive tweaks for small screens */
@media (max-width: 600px) {
  #instructions .content p {
    font-size: 0.85rem;
    margin: 0.25rem 0;
  }

  /* Make instructions more compact on mobile */
  #instructions {
    top: clamp(8px, 2vh, 16px);
    padding: 0.5rem 0.8rem;
    max-width: 90vw;
  }

  #results {
    min-width: 280px;
    max-width: 92vw;
    width: 90%;
  }

  #results .content {
    padding: 1.5rem 1.25rem;
  }

  .score-container {
    flex-direction: column;
    gap: 1.5rem;
    justify-content: center;
  }

  .score-divider {
    display: none;
  }

  .game-over-title {
    margin-bottom: 0.4rem;
    width: 100%;
  }

  .game-over-title h1 {
    font-size: 1.5rem;
  }

  .miss-icon {
    width: 1.75rem;
    height: 1.75rem;
  }

  .miss-message {
    font-size: 0.85rem;
    margin: 0 0 1rem 0;
  }

  .score-card {
    padding: 1rem 0.75rem;
    min-width: 120px;
  }

  .score-label {
    font-size: 0.65rem;
    margin-bottom: 0.4rem;
  }

  .score-value {
    font-size: 2rem;
  }

  .score-value::after {
    font-size: 0.5em;
  }

  #score {
    font-size: 1.1rem;
    top: clamp(8px, 2vh, 16px);
    right: clamp(8px, 2vw, 16px);
  }

  /* Improve touch targets */
  .restart-hint {
    font-size: 0.9rem;
    padding: 0.4rem;
    margin: 1rem 0 0.75rem;
  }

  .restart-icon {
    width: 1rem;
    height: 1rem;
  }

  .social-follow {
    font-size: 0.85rem;
    margin-top: 1rem;
    padding-top: 1rem;
  }

  .twitter-link {
    padding: 0.4rem 0.6rem;
    font-size: 0.85rem;
    min-height: 40px;
    display: inline-flex;
    align-items: center;
  }

  .twitter-link svg {
    width: 0.85rem;
    height: 0.85rem;
  }

  /* Make restart message more prominent on mobile */
  .restart-hint kbd {
    font-size: 0.9rem;
    padding: 0.35rem 0.65rem;
  }
}

/* Add landscape mobile optimization */
@media (max-width: 900px) and (orientation: landscape) {
  #instructions {
    top: 5px;
    padding: 0.4rem 0.8rem;
  }

  #instructions .content p {
    font-size: 0.75rem;
    margin: 0.2rem 0;
  }

  #score {
    top: 5px;
    right: 5px;
    font-size: 1rem;
    padding: 0.2rem 0.5rem;
  }

  #results {
    max-height: 90vh;
    overflow-y: auto;
    width: 90%;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
  }

  #results .content {
    padding: 1rem 0.8rem;
    width: 80%;
  }

  .game-over-title h1 {
    font-size: 1.5rem;
  }

  .score-value {
    font-size: 2rem;
  }

  .miss-message {
    margin: 0 0 0.75rem 0;
  }

  .score-container {
    margin: 1rem 0;
  }

  .restart-hint,
  .social-follow {
    margin: 0.75rem 0;
  }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
  body {
    -webkit-tap-highlight-color: rgba(255, 200, 100, 0.1);
    touch-action: none;
    /* Prevent unwanted touch gestures during gameplay */
  }

  /* Make tappable areas more obvious */
  #results,
  #instructions {
    touch-action: manipulation;
  }

  /* Ensure minimum touch target sizes (44x44px recommended) */
  .score-card {
    min-height: 80px;
    padding: 1.2rem 1rem;
  }

  .twitter-link {
    min-height: 44px;
    padding: 0.6rem 0.8rem;
  }
}

/* Extra small screens (phones < 360px) */
@media (max-width: 360px) {
  #results {
    min-width: 260px;
    max-width: 95vw;
  }

  #results .content {
    padding: 1.25rem 1rem;
  }

  .game-over-title h1 {
    font-size: 1.4rem;
  }

  .miss-icon {
    width: 1.5rem;
    height: 1.5rem;
  }

  .score-card {
    padding: 0.75rem 0.5rem;
    min-width: 100px;
  }

  .score-value {
    font-size: 1.6rem;
  }

  .score-label {
    font-size: 0.6rem;
  }

  .restart-hint {
    font-size: 0.8rem;
  }

  .social-follow {
    font-size: 0.8rem;
  }
}

@media (min-width: 1200px) {
  #instructions .content p {
    font-size: 1.05rem;
  }

  #results {
    min-width: 420px;
  }
}