@import url('https://fonts.googleapis.com/css2?family=Abril+Fatface&family=Barlow+Condensed:wght@400;600;700&display=swap');

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

:root {
  --carnival-red: #c41e3a;
  --carnival-gold: #d4a574;
  --brass: #b8860b;
  --warm-white: #fef3e2;
  --aged-cream: #f5e6d3;
  --deep-mahogany: #2d1810;
  --rust: #8b4513;
  --twilight: #1a0f1e;
  --incandescent: #ffb347;
}

body {
  font-family: "Barlow Condensed", sans-serif;
  background: var(--twilight);
  background-image:
    radial-gradient(ellipse at 30% 20%, rgba(255, 179, 71, 0.08) 0%, transparent 50%),
    radial-gradient(ellipse at 70% 80%, rgba(196, 30, 58, 0.06) 0%, transparent 50%),
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 2px,
      rgba(0,0,0,0.03) 2px,
      rgba(0,0,0,0.03) 4px
    );
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: hidden;
  position: relative;
}

/* Subtle grain overlay */
body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(/%23noise)'/%3E%3C/svg%3E");
  opacity: 0.04;
  pointer-events: none;
  z-index: 1000;
}

.game-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 15px;
  margin: auto;
  padding: 10px;
}

.game-container {
  position: relative;
  width: 90vmin;
  height: 90vmin;
  max-width: 700px;
  max-height: 700px;
  background:
    linear-gradient(135deg, #3d2817 0%, #2d1810 50%, #1a0f0a 100%);
  border-radius: 12px;
  border: 6px solid var(--brass);
  box-shadow:
    0 0 0 2px rgba(0,0,0,0.8),
    0 0 0 8px #1a0f0a,
    0 0 60px rgba(255, 179, 71, 0.15),
    inset 0 0 80px rgba(0,0,0,0.5);
  overflow: hidden;
}

/* Decorative corner brass plates */
.game-container::before,
.game-container::after {
  content: '';
  position: absolute;
  width: 40px;
  height: 40px;
  border: 3px solid var(--brass);
  z-index: 25;
  pointer-events: none;
}

.game-container::before {
  top: 10px;
  left: 10px;
  border-right: none;
  border-bottom: none;
  border-radius: 4px 0 0 0;
}

.game-container::after {
  bottom: 10px;
  right: 10px;
  border-left: none;
  border-top: none;
  border-radius: 0 0 4px 0;
}

.game-container.shake {
  animation: screenShake 0.3s ease;
}

@keyframes screenShake {
  0%, 100% { transform: translateX(0) rotate(0); }
  20% { transform: translateX(-6px) rotate(-0.3deg); }
  40% { transform: translateX(6px) rotate(0.3deg); }
  60% { transform: translateX(-4px) rotate(-0.2deg); }
  80% { transform: translateX(4px) rotate(0.2deg); }
}

#gameCanvas {
  width: 100%;
  height: 100%;
  border-radius: 6px;
}

.round-squares {
  display: flex;
  gap: 8px;
  justify-content: center;
  padding: 10px 16px;
  background: linear-gradient(180deg, rgba(45, 24, 16, 0.95) 0%, rgba(26, 15, 10, 0.95) 100%);
  border: 2px solid var(--brass);
  border-radius: 8px;
  box-shadow:
    0 4px 12px rgba(0,0,0,0.4),
    inset 0 1px 0 rgba(255,255,255,0.05);
}

.round-square {
  width: 34px;
  height: 34px;
  background: linear-gradient(180deg, #1a0f0a 0%, #0d0705 100%);
  border: 2px solid rgba(184, 134, 11, 0.4);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  color: var(--aged-cream);
  font-family: "Barlow Condensed", sans-serif;
  transition: all 0.3s ease;
}

.round-square.current {
  border-color: var(--incandescent);
  box-shadow:
    0 0 12px rgba(255, 179, 71, 0.5),
    inset 0 0 8px rgba(255, 179, 71, 0.1);
  animation: currentPulse 1.5s ease-in-out infinite;
}

@keyframes currentPulse {
  0%, 100% { box-shadow: 0 0 12px rgba(255, 179, 71, 0.5), inset 0 0 8px rgba(255, 179, 71, 0.1); }
  50% { box-shadow: 0 0 20px rgba(255, 179, 71, 0.7), inset 0 0 12px rgba(255, 179, 71, 0.2); }
}

.round-square.perfect {
  background: linear-gradient(180deg, #1a3a1a 0%, #0d200d 100%);
  border-color: #2ecc71;
  color: #2ecc71;
  box-shadow: 0 0 12px rgba(46, 204, 113, 0.4);
}

/* Popup */
.popup {
  position: absolute;
  top: 45%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  z-index: 15;
  pointer-events: none;
  opacity: 0;
}

.popup.show {
  opacity: 1;
  animation: popupAnim 0.8s ease forwards;
}

.popup-text {
  font-family: "Abril Fatface", serif;
  font-size: 56px;
  text-shadow:
    0 4px 8px rgba(0,0,0,0.6),
    0 0 40px currentColor;
  letter-spacing: 4px;
}

.popup-text.success {
  color: #4ecdc4;
  text-shadow:
    0 4px 8px rgba(0,0,0,0.6),
    0 0 30px rgba(78, 205, 196, 0.5);
}

.popup-text.fail {
  color: #ffffff;
  text-shadow:
    0 4px 8px rgba(0,0,0,0.6),
    0 0 20px rgba(255, 255, 255, 0.7),
    0 0 40px rgba(255, 255, 255, 0.4);
  animation: electricFlicker 0.08s ease-in-out infinite;
}

@keyframes electricFlicker {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.9; }
}

.popup-text.levelup {
  color: var(--carnival-gold);
  text-shadow:
    0 4px 8px rgba(0,0,0,0.6),
    0 0 40px rgba(212, 165, 116, 0.6);
}

@keyframes popupAnim {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.5) rotate(-5deg);
  }
  20% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.15) rotate(2deg);
  }
  40% {
    transform: translate(-50%, -50%) scale(1) rotate(0deg);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -70%) scale(1) rotate(0deg);
  }
}

/* Screens */
.screen {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background:
    radial-gradient(ellipse at center, rgba(45, 24, 16, 0.97) 0%, rgba(26, 15, 10, 0.99) 100%);
  backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  color: var(--aged-cream);
  text-align: center;
  z-index: 20;
  border-radius: 6px;
  padding: 30px;
}

.screen.hidden { display: none; }

.screen h1 {
  font-family: "Abril Fatface", serif;
  font-size: 4.5rem;
  margin-bottom: 8px;
  color: var(--carnival-gold);
  text-shadow:
    0 4px 0 #8b4513,
    0 6px 0 #5c3317,
    0 8px 20px rgba(0,0,0,0.5),
    0 0 60px rgba(212, 165, 116, 0.3);
  letter-spacing: 12px;
  position: relative;
}

/* Decorative lines around title */
.screen h1::before,
.screen h1::after {
  content: '◆';
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1rem;
  color: var(--brass);
}

.screen h1::before {
  left: -30px;
}

.screen h1::after {
  right: -30px;
}

.screen h2 {
  font-family: "Abril Fatface", serif;
  font-size: 2.5rem;
  margin-bottom: 20px;
  color: var(--carnival-red);
  text-shadow:
    0 3px 0 #6b1020,
    0 5px 15px rgba(0,0,0,0.4);
  letter-spacing: 6px;
}

.instructions {
  max-width: 280px;
  margin-bottom: 35px;
  line-height: 1.9;
  color: rgba(245, 230, 211, 0.75);
  font-size: 1.1rem;
  font-weight: 400;
  letter-spacing: 0.5px;
}

.instructions strong {
  color: var(--carnival-red);
  font-weight: 700;
}

.instructions em {
  color: var(--carnival-gold);
  font-style: normal;
  font-weight: 600;
}

.btn {
  background: linear-gradient(180deg, var(--carnival-red) 0%, #8b1428 100%);
  border: 3px solid var(--carnival-gold);
  padding: 18px 50px;
  border-radius: 6px;
  color: var(--warm-white);
  font-family: "Barlow Condensed", sans-serif;
  font-size: 20px;
  font-weight: 700;
  cursor: pointer;
  margin: 12px;
  box-shadow:
    0 6px 0 #5c1020,
    0 8px 20px rgba(0,0,0,0.4),
    inset 0 1px 0 rgba(255,255,255,0.15);
  transition: all 0.15s ease;
  text-transform: uppercase;
  letter-spacing: 3px;
  position: relative;
  overflow: hidden;
}

.btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.15), transparent);
  transition: left 0.4s ease;
}

.btn:hover::before {
  left: 100%;
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow:
    0 8px 0 #5c1020,
    0 12px 30px rgba(0,0,0,0.5),
    inset 0 1px 0 rgba(255,255,255,0.2);
}

.btn:active {
  transform: translateY(2px);
  box-shadow:
    0 3px 0 #5c1020,
    0 5px 15px rgba(0,0,0,0.3),
    inset 0 1px 0 rgba(255,255,255,0.1);
}

.high-score {
  margin-top: 30px;
  font-size: 1rem;
  color: rgba(245, 230, 211, 0.5);
  text-transform: uppercase;
  letter-spacing: 2px;
}

.high-score span {
  color: var(--carnival-gold);
  font-weight: 700;
  font-size: 1.2rem;
}

.final-score {
  font-family: "Abril Fatface", serif;
  font-size: 5rem;
  color: var(--carnival-gold);
  text-shadow:
    0 4px 0 #8b4513,
    0 6px 20px rgba(0,0,0,0.4),
    0 0 50px rgba(212, 165, 116, 0.4);
  margin-bottom: 5px;
  letter-spacing: 8px;
}

.final-label {
  font-size: 1.1rem;
  color: rgba(245, 230, 211, 0.5);
  margin-bottom: 30px;
  text-transform: uppercase;
  letter-spacing: 4px;
}

.new-high-score {
  color: var(--carnival-gold);
  font-family: "Abril Fatface", serif;
  font-size: 1.3rem;
  animation: newHighPulse 0.6s ease infinite;
  margin-bottom: 20px;
  text-shadow: 0 0 20px rgba(212, 165, 116, 0.5);
  letter-spacing: 2px;
}

@keyframes newHighPulse {
  0%, 100% {
    opacity: 1;
    transform: scale(1);
    text-shadow: 0 0 20px rgba(212, 165, 116, 0.5);
  }
  50% {
    opacity: 0.9;
    transform: scale(1.03);
    text-shadow: 0 0 30px rgba(212, 165, 116, 0.7);
  }
}

/* Decorative fairground lights simulation */
@keyframes fairgroundLights {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

@media (max-width: 600px) {
  .game-wrapper {
    gap: 10px;
    padding: 5px;
  }

  .game-container {
    width: 95vmin;
    height: 95vmin;
    border-width: 4px;
  }

  .round-squares {
    gap: 4px;
    padding: 6px 8px;
  }

  .round-square {
    width: 28px;
    height: 28px;
    font-size: 12px;
  }

  .screen h1 {
    font-size: 3rem;
    letter-spacing: 8px;
  }

  .screen h1::before,
  .screen h1::after {
    display: none;
  }

  .final-score {
    font-size: 3.5rem;
  }

  .btn {
    padding: 14px 40px;
    font-size: 18px;
  }

  .popup-text {
    font-size: 42px;
  }
}
