/* Copyright 2025, 2026 R.V. Walsh */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  overflow: hidden;
  background-color: #222;
  color: #eee;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* Lawn Wrapper */
#lawn-wrapper {
  flex-grow: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #2c3e50;
  position: relative;
  overflow: hidden;
  cursor: default;
}

/* The Court */
#lawn {
  position: absolute;
  width: 90vw;
  height: auto;
  aspect-ratio: 9 / 5;
  
  background-color: #4b9e4b;
  background-image: repeating-linear-gradient(
    90deg,
    rgba(255,255,255,0.05) 0px,
    rgba(255,255,255,0.05) 20px,
    transparent 20px,
    transparent 40px
  );
  border: 5px solid #fff;
  box-shadow: 0 10px 50px rgba(0,0,0,0.7);
  transform-origin: center center;
  transition: transform 0.1s ease-out;
}

canvas {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  z-index: 10;
  pointer-events: none;
}

/* 3D Balls */
.ball {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  position: absolute;
  z-index: 20;
  cursor: grab;
  touch-action: none;
  box-shadow: 2px 4px 6px rgba(0,0,0,0.4);
  /* Default transition for Reset animation */
  transition: width 0.2s, height 0.2s, top 0.5s, left 0.5s; 
}

.ball:active {
  cursor: grabbing;
  /* Important: JS handles disabling transition now for better touch support */
}

/* Initial Positions */
#blue   { background: radial-gradient(circle at 35% 35%, #4da6ff, #0044cc); left: 5%; top: 85%; }
#red    { background: radial-gradient(circle at 35% 35%, #ff4d4d, #cc0000); left: 10%; top: 85%; }
#black  { background: radial-gradient(circle at 35% 35%, #666, #000);       left: 15%; top: 85%; }
#yellow { background: radial-gradient(circle at 35% 35%, #ffff66, #e6c200); left: 20%; top: 85%; }

/* Wickets */
.wicket {
  width: 14px; 
  height: 40px; 
  background-color: transparent; 
  border-top: 5px solid #eee;
  border-bottom: 5px solid #eee;
  position: absolute;
  z-index: 5; 
  box-shadow: 1px 1px 2px rgba(0,0,0,0.3);
  transform: translate(-50%, -50%);
}

#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%; }
#wicket6 { left: 66%; top: 50%; }

.wicket span {
  position: absolute;
  top: -20px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 12px;
  color: white;
  font-weight: bold;
  text-shadow: 1px 1px 2px black;
  pointer-events: none;
}

/* Stake */
#stake {
  width: 10px;
  height: 25px;
  background: repeating-linear-gradient(
    45deg,
    white,
    white 5px,
    red 5px,
    red 10px
  );
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 5;
  box-shadow: 2px 2px 4px rgba(0,0,0,0.4);
}

/* Floating Toolbar (Dark Theme) */
#toolbar {
  flex-shrink: 0;
  background: #2c3e50;
  border-top: 1px solid #444;
  padding: 10px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 15px;
  z-index: 100;
  color: #fff;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 0 10px;
  border-right: 1px solid #555;
}
.toolbar-group:last-child { border-right: none; }
.toolbar-group.hidden { display: none; }

.tool-label {
  font-size: 0.8rem;
  color: #aaa;
  margin-right: 4px;
}

.tool-btn {
  background: #3e5871;
  color: #fff;
  border: 1px solid #555;
  border-radius: 4px;
  padding: 8px 12px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-width: 36px;
}

.tool-btn:hover { background: #4e6e8e; }
.tool-btn.active { 
  background: #27ae60;
  border-color: #2ecc71;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.2);
}

#toggle-draw.active { background-color: #e74c3c; } 
#toggle-pan.active { background-color: #f39c12; }

/* Color Picker */
#color-picker {
  display: flex;
  gap: 5px;
  margin-left: 5px;
}

.color-swatch {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid #555;
  cursor: pointer;
}
.color-swatch.active {
  transform: scale(1.2);
  border-color: #fff;
  box-shadow: 0 0 5px rgba(255,255,255,0.5);
}

/* Modal */
.modal {
  display: none; 
  position: fixed; 
  z-index: 2000; 
  left: 0; top: 0;
  width: 100%; height: 100%;
  background-color: rgba(0,0,0,0.7);
  backdrop-filter: blur(2px);
}

.modal-content {
  background-color: #fff;
  color: #333;
  margin: 10% auto;
  padding: 25px;
  border-radius: 8px;
  width: 90%;
  max-width: 500px;
  position: relative;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}

.modal-content h2 { margin-bottom: 15px; border-bottom: 2px solid #eee; padding-bottom: 10px;}
.modal-content ul { text-align: left; margin-left: 20px; line-height: 1.6; }

.close-button {
  position: absolute;
  top: 10px; right: 15px;
  font-size: 24px;
  font-weight: bold;
  color: #999;
  cursor: pointer;
}
.close-button:hover { color: #000; }