/* Reset and Base Styles */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-user-select: none; user-select: none; }
body { background-color: #f0f0f0; display: block; min-height: 100vh; font-family: Arial, sans-serif; overflow-x: hidden; overflow-y: auto; }

#main-container { display: flex; align-items: flex-start; gap: 16px; padding: 20px; width: 100%; max-width: 100vw; }
@supports not (gap: 16px) { #main-container > * { margin-right: 16px; } #main-container > *:last-child { margin-right: 0; } }

#lawn-container {
  position: relative; flex: 1 1 auto; width: 100%; min-width: 800px;
  padding-top: calc(100% * 5 / 9);
  background-color: #00a000;
  background-image: repeating-linear-gradient(0deg, #009000 0px, #009000 40px, #00a000 40px, #00a000 80px);
  overflow: hidden; z-index: 3;
  box-shadow: inset 0 0 20px rgba(0,0,0,0.3); border: 4px solid #4a3c31;
}
@supports (aspect-ratio: 9/5) { #lawn-container { padding-top: 0; aspect-ratio: 9 / 5; } }

.shake { animation: shake 0.4s cubic-bezier(.36,.07,.19,.97) both; }
@keyframes shake {
  10%, 90% { transform: translate3d(-2px, 0, 0); }
  20%, 80% { transform: translate3d(4px, 0, 0); }
  30%, 50%, 70% { transform: translate3d(-6px, 0, 0); }
  40%, 60% { transform: translate3d(6px, 0, 0); }
}

#drawing-layer { display: none; }
#arrow-layer { position: absolute; z-index: 4; background: transparent; display: none; pointer-events: none; touch-action: none; }
#lawn { width: 100%; height: 100%; position: relative; }

.ball {
  width: 30px; height: 30px; border-radius: 50%;
  position: absolute; z-index: 2; cursor: pointer; touch-action: none;
  transition: transform 0.1s ease-out;
  background-image: radial-gradient(circle at 35% 35%, rgba(255,255,255,0.8), rgba(255,255,255,0) 40%);
  box-shadow: 2px 4px 6px rgba(0,0,0,0.4);
}

/* Explicit Colors (No Filters) */
#blue { background-color: #0044ff; }
#red { background-color: #d32f2f; }
#black { background-color: #111; }
#yellow { background-color: #fbc02d; }

.ball.active {
  animation: activeBallPulse 1.5s ease-in-out infinite; z-index: 3;
  outline: 2px solid rgba(255, 255, 255, 0.8); outline-offset: 2px;
}
@keyframes activeBallPulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.1); } }

/* Wickets */
.wicket {
  width: 10px; height: 40px; background-color: transparent;
  border-top: 5px solid #eee; border-bottom: 5px solid #eee;
  position: absolute; z-index: 1; box-shadow: 1px 1px 2px rgba(0,0,0,0.2);
}
.wicket.target-wicket { border-color: yellow; filter: drop-shadow(0 0 5px yellow); }
.wicket.target-wicket::after {
  content: 'TARGET'; position: absolute; top: -30px; left: 50%;
  transform: translateX(-50%); color: yellow; font-size: 10px; font-weight: bold;
  background: rgba(0,0,0,0.7); padding: 2px 4px; border-radius: 4px;
  animation: bounceArrow 1s infinite alternate;
}
@keyframes bounceArrow { from { top: -30px; } to { top: -35px; } }

.wicket-number {
  position: absolute; left: -20px; top: 50%; transform: translateY(-50%);
  color: rgba(255,255,255,0.9); font-size: 14px; font-weight: bold;
  text-shadow: 1px 1px 2px black; pointer-events: none;
}
#wicket1 { left: 20%; top: 80%; }
#wicket2 { left: 20%; top: 20%; }
#wicket3 { left: 80%; top: 20%; }
#wicket4 { left: 80%; top: 80%; }
#wicket5 { left: 34%; top: 50%; transform: translate(-50%, -50%); }
#wicket6 { left: 66%; top: 50%; transform: translate(-50%, -50%); }

#stake {
  width: 12px; height: 12px; background: radial-gradient(circle at 30% 30%, #fff, #aaa);
  border-radius: 50%; position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%); z-index: 2; box-shadow: 2px 4px 5px rgba(0,0,0,0.5);
}
.boundary-label {
  position: absolute; font-size: 2rem; font-weight: bold; color: rgba(255,255,255,0.4);
  z-index: 1; pointer-events: none; font-family: serif;
}
#north-label { left: 10px; top: 50%; transform: translateY(-50%); }
#east-label  { top: 10px; left: 50%; transform: translateX(-50%); }
#south-label { right: 10px; top: 50%; transform: translateY(-50%); }
#west-label  { bottom: 10px; left: 50%; transform: translateX(-50%); }

#description-box {
  flex: 0 0 auto; width: 300px; background-color: white; border-radius: 8px;
  padding: 15px; overflow-y: auto; font-size: 0.95rem; line-height: 1.5;
  color: #333; box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
#description-box header { text-align: center; margin-bottom: 15px; border-bottom: 2px solid #eee; padding-bottom: 10px; }
#description-box h1 { font-size: 1.4rem; color: #2c3e50; margin: 0; }

#scoreboard-display { background: #f8f9fa; padding: 10px; border-radius: 6px; border: 1px solid #e9ecef; margin-bottom: 15px; }
#scoreboard-display .score-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 8px; }

#turn-controls { margin-top: 15px; padding-top: 15px; border-top: 1px solid #eee; text-align: center; }
.turn-buttons { display: flex; gap: 5px; justify-content: center; margin: 10px 0; }
.turn-buttons button { padding: 6px 10px; border: 1px solid #ccc; border-radius: 4px; cursor: pointer; background: white; }
.turn-buttons button:hover { background: #eee; }

#btn-strike {
  width: 100%; padding: 10px; font-size: 1.1rem; font-weight: bold;
  border: none; border-radius: 4px; background: #34495e; color: white;
  cursor: pointer; transition: background 0.2s;
}
#btn-strike.active { background-color: #27ae60; }
input[type=range] { width: 100%; } meter { width: 100%; height: 20px; }
#how-to-play summary { cursor: pointer; padding: 10px 0; font-weight: bold; color: #2980b9; }

@media only screen and (max-width: 1300px) { #main-container { transform: scale(0.9); transform-origin: top left; width: 111%; } }
@media only screen and (max-width: 900px) {
  #main-container { flex-direction: column; transform: none; width: 100%; }
  #description-box { width: 100%; order: 2; } #lawn-container { order: 1; }
}