@import url('https://fonts.googleapis.com/css2?family=Caveat:wght@400;700&family=Permanent+Marker&display=swap');

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

html, body {
  height: 100%;
  overflow: hidden;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  height: 100vh;
  height: 100dvh;
  background: #1a1a2e;
  margin: 0;
  overflow: hidden;
  font-family: 'Caveat', cursive;
  -webkit-user-select: none;
  user-select: none;
}

/* ───── Canvas ───── */
#gameCanvas {
  border: none; /* wobbly border drawn on canvas */
  max-width: 95vw;
  max-height: 90vh;
  background: transparent;
  transition: filter 0.3s ease, transform 0.15s ease;
  cursor: pointer;
  will-change: transform, filter;
  contain: layout style paint;
}

/* ───── Trip videos ───── */
#goodTrip, #badTrip {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  z-index: -1;
  display: none;
  pointer-events: none;
}

/* ───── Menu ───── */
.menu {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fdf6e3;
  z-index: 1000;

  /* Notebook paper background */
  background-image:
    repeating-linear-gradient(
      transparent,
      transparent 27px,
      rgba(0, 0, 220, 0.12) 27px,
      rgba(0, 0, 220, 0.12) 28px
    );
}

.menu-paper {
  width: 90%;
  max-width: 480px;
  padding: 35px 30px;
  border: 2.5px solid #222;
  background: repeating-linear-gradient(
    #fff,
    #fff 27px,
    #dceafc 27px,
    #dceafc 28px
  );
  position: relative;
  text-align: center;
  box-shadow:
    4px 4px 0 rgba(0,0,0,0.15),
    0 0 30px rgba(0,0,0,0.1);
  border-radius: 4px;
  transform: rotate(-1.2deg);
  animation: paperWobble 4s ease-in-out infinite;
}

@keyframes paperWobble {
  0%, 100% { transform: rotate(-1.2deg); }
  25% { transform: rotate(-0.5deg) translateY(-2px); }
  50% { transform: rotate(0.8deg); }
  75% { transform: rotate(0.2deg) translateY(1px); }
}

/* Red margin line */
.menu-paper::before {
  content: "";
  position: absolute;
  top: 0;
  left: 48px;
  width: 2px;
  height: 100%;
  background: rgba(220, 30, 30, 0.35);
}

/* Coffee stain on menu */
.menu-paper::after {
  content: "";
  position: absolute;
  top: -15px;
  right: 25px;
  width: 70px;
  height: 70px;
  border-radius: 50%;
  background: radial-gradient(
    circle,
    rgba(139, 90, 43, 0.08) 30%,
    rgba(139, 90, 43, 0.04) 60%,
    transparent 70%
  );
  pointer-events: none;
}

.menu-paper h1 {
  font-family: 'Permanent Marker', 'Caveat', cursive;
  font-size: clamp(40px, 10vw, 72px);
  margin: 15px 0 5px;
  color: #1a1a2e;
  text-shadow: 2px 2px 0 rgba(0,0,0,0.1);
  animation: titleScribble 3s ease-in-out infinite;
  letter-spacing: 3px;
}

@keyframes titleScribble {
  0%, 100% { transform: rotate(0deg) scale(1); }
  10% { transform: rotate(-0.8deg) scale(1.01); }
  20% { transform: rotate(0.5deg) scale(0.99); }
  30% { transform: rotate(-0.3deg); }
  40% { transform: rotate(0.6deg) scale(1.01); }
  50% { transform: rotate(-0.4deg); }
  60% { transform: rotate(0.3deg) scale(0.99); }
  70% { transform: rotate(-0.7deg); }
  80% { transform: rotate(0.2deg) scale(1.01); }
  90% { transform: rotate(-0.5deg); }
}

.menu-subtitle {
  font-family: 'Caveat', cursive;
  font-size: clamp(14px, 3vw, 18px);
  color: #888;
  margin-bottom: 10px;
  font-style: italic;
}

.menu-high-score {
  font-family: 'Caveat', cursive;
  font-size: clamp(16px, 4vw, 22px);
  color: #666;
  margin-bottom: 15px;
}

#menuStoner {
  width: clamp(80px, 20vw, 120px);
  display: block;
  margin: 0 auto;
  animation: stonerBob 2.5s ease-in-out infinite;
  filter: drop-shadow(2px 3px 0 rgba(0,0,0,0.1));
}

@keyframes stonerBob {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  25% { transform: translateY(-6px) rotate(-2deg); }
  50% { transform: translateY(-2px) rotate(1deg); }
  75% { transform: translateY(-8px) rotate(-1deg); }
}

/* ───── Buttons ───── */
.menu-btn {
  margin: 8px;
  padding: 12px 28px;
  font-size: clamp(16px, 4vw, 22px);
  font-family: 'Caveat', cursive;
  font-weight: 700;
  background: #1a1a2e;
  color: #fdf6e3;
  border: 2px solid #333;
  border-radius: 6px;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.2s ease;
  position: relative;
  letter-spacing: 1px;
}

.menu-btn:hover {
  transform: scale(1.08) rotate(-1deg);
  background: #2d2d4e;
}

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

.mute-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  padding: 5px;
  opacity: 0.6;
  transition: opacity 0.2s, transform 0.2s;
}

.mute-btn:hover {
  opacity: 1;
  transform: scale(1.2);
}

/* ───── Popups ───── */
.popup {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0, 0, 0, 0.7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  backdrop-filter: blur(3px);
}

.popup-content {
  width: 90%;
  max-width: 460px;
  padding: 35px 30px;
  border: 2.5px solid #222;
  background: repeating-linear-gradient(
    #fff,
    #fff 27px,
    #dceafc 27px,
    #dceafc 28px
  );
  position: relative;
  text-align: center;
  font-family: 'Caveat', cursive;
  color: #1a1a2e;
  border-radius: 4px;
  box-shadow:
    4px 4px 0 rgba(0,0,0,0.2),
    0 0 40px rgba(0,0,0,0.3);
  animation: popupSlam 0.3s ease-out;
}

@keyframes popupSlam {
  0% {
    transform: scale(0.5) rotate(-5deg);
    opacity: 0;
  }
  60% {
    transform: scale(1.05) rotate(1deg);
  }
  100% {
    transform: scale(1) rotate(0deg);
    opacity: 1;
  }
}

/* Red margin line on popups */
.popup-content::before {
  content: "";
  position: absolute;
  top: 0;
  left: 48px;
  width: 2px;
  height: 100%;
  background: rgba(220, 30, 30, 0.3);
}

.popup-content h2 {
  font-family: 'Permanent Marker', 'Caveat', cursive;
  font-size: clamp(22px, 5vw, 32px);
  margin-bottom: 10px;
  line-height: 1.5;
}

.popup-content p {
  font-size: clamp(15px, 3.5vw, 19px);
  line-height: 1.8;
  text-align: left;
  padding-left: 30px;
  color: #333;
}

/* ───── Replay button (token) ───── */
#replayBtn {
  margin-top: 20px;
  width: clamp(60px, 15vw, 85px);
  cursor: pointer;
  transition: transform 0.2s ease;
  filter: drop-shadow(2px 3px 2px rgba(0,0,0,0.2));
  animation: tokenPulse 1.5s ease-in-out infinite;
}

@keyframes tokenPulse {
  0%, 100% { transform: scale(1) rotate(0deg); }
  50% { transform: scale(1.1) rotate(5deg); }
}

#replayBtn:hover {
  transform: scale(1.25) rotate(-5deg);
  animation: none;
  content: url("assets/light_token.png");
}

/* ───── Responsive ───── */
@media (max-width: 600px) {
  .menu-paper {
    padding: 25px 20px;
  }
  
  .popup-content {
    padding: 25px 20px;
  }
  
  .menu-btn {
    padding: 10px 20px;
  }
}

@media (max-height: 500px) {
  .menu-paper {
    padding: 15px;
  }
  
  #menuStoner {
    width: 60px;
  }
  
  .menu-paper h1 {
    font-size: 36px;
    margin: 5px 0;
  }

  .menu-subtitle {
    margin-bottom: 5px;
  }

  .menu-high-score {
    margin-bottom: 8px;
    font-size: 16px;
  }

  .menu-btn {
    padding: 8px 18px;
    margin: 4px;
  }

  .popup-content {
    padding: 15px;
  }

  .popup-content h2 {
    font-size: 20px;
    margin-bottom: 5px;
  }

  .popup-content p {
    font-size: 14px;
    line-height: 1.5;
  }

  #replayBtn {
    margin-top: 10px;
    width: clamp(50px, 12vw, 70px);
  }
}

/* ───── Landscape Overlay ───── */
.landscape-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #fdf6e3;
  background-image: repeating-linear-gradient(
    transparent,
    transparent 27px,
    rgba(0, 0, 220, 0.12) 27px,
    rgba(0, 0, 220, 0.12) 28px
  );
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  z-index: 9999;
  text-align: center;
}

.landscape-content {
  font-family: 'Caveat', cursive;
  color: #1a1a2e;
}

.landscape-content .rotate-icon {
  font-size: clamp(48px, 12vw, 72px);
  animation: rotatePhone 2.5s ease-in-out infinite;
  display: inline-block;
  margin-bottom: 20px;
}

@keyframes rotatePhone {
  0%, 100% { transform: rotate(0deg); }
  20% { transform: rotate(90deg); }
  60% { transform: rotate(90deg); }
  80% { transform: rotate(0deg); }
}

.landscape-content p {
  font-family: 'Permanent Marker', 'Caveat', cursive;
  font-size: clamp(18px, 5vw, 28px);
  font-weight: 700;
  margin-top: 10px;
  max-width: 80%;
  margin-left: auto;
  margin-right: auto;
  color: #1a1a2e;
}

/* ───── Tablet ───── */
@media (min-width: 768px) and (max-width: 1024px) {
  .menu-paper {
    max-width: 420px;
    padding: 30px 25px;
  }

  .popup-content {
    max-width: 400px;
  }
}

/* ───── Large Desktop ───── */
@media (min-width: 1200px) {
  .menu-paper {
    max-width: 520px;
  }

  .popup-content {
    max-width: 500px;
  }
}

/* ───── Touch Devices ───── */
@media (hover: none) and (pointer: coarse) {
  .menu-btn {
    padding: 14px 32px;
    font-size: clamp(18px, 4.5vw, 24px);
    min-height: 48px;
    min-width: 48px;
  }

  .mute-btn {
    font-size: 28px;
    padding: 10px;
    min-height: 48px;
    min-width: 48px;
  }

  #replayBtn {
    width: clamp(70px, 18vw, 100px);
  }
}

/* ───── Safe Area (Notched Phones) ───── */
@supports (padding: env(safe-area-inset-top)) {
  body {
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }
}

/* ───── Trip Video Performance ───── */
#goodTrip, #badTrip {
  will-change: opacity;
  transform: translateZ(0);
}

/* ───── Reduced Motion ───── */
@media (prefers-reduced-motion: reduce) {
  .menu-paper,
  .menu-paper h1,
  #menuStoner,
  #replayBtn,
  .popup-content {
    animation: none !important;
  }
}
