:root {
  --table-felt: #008080;
  --table-rail: #8d6e63;
  --background-start: #2a5298;
  --background-end: #1e3c72;
  --text-color: #ffffff;
  --shadow-color: rgba(0, 0, 0, 0.3);
  --button-bg: #ff6d00;
  --button-hover-bg: #ff8124;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100vh;
  overflow: hidden;
  background: linear-gradient(to top, var(--background-start), var(--background-end));
  display: flex;
  justify-content: center;
  align-items: top;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  color: var(--text-color);
}

#game-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  width: 100%;
  height: 97vh;
  position: relative;
}

#top-ui {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  width: 100%;
  max-width: 1200px;
  padding: 10px 0;
  flex-shrink: 0;
}

.pocketed-balls-area {
  width: 30%;
  min-height: 50px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 8px;
  padding: 8px;
  box-sizing: border-box;
  transition: all 0.3s ease;
}

.pocketed-balls-area h3 {
  margin: 0 0 8px 0;
  font-size: clamp(0.8rem, 2vw, 0.9rem);
  text-align: center;
}

.pocketed-balls-container {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  min-height: 25px;
}

.pocketed-ball-display {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background-color: white;
  box-shadow: inset 2px 2px 5px rgba(0, 0, 0, 0.5);
}

.pocketed-ball-display.stripe {
  background-image: repeating-linear-gradient(-45deg,
      white,
      white 5px,
      var(--stripe-color) 5px,
      var(--stripe-color) 10px);
}

#header {
  text-align: center;
  color: var(--text-color);
  text-shadow: 0 2px 4px var(--shadow-color);
  flex-shrink: 0;
  width: 40%;
  position: relative;
}

#game-title {
  font-size: clamp(1.2rem, 3vw, 2rem);
  margin: 0 0 5px 0;
}

#game-status {
  font-size: clamp(0.9rem, 2vw, 0.9rem);
  min-height: 1.5em;
  margin-top: 5px;
}

#canvas-container {
  background: var(--table-rail);
  padding: 15px;
  border-radius: 15px;
  box-shadow: 0 10px 30px var(--shadow-color);
}

canvas {
  display: block;
  background: var(--table-felt);
  border-radius: 10px;
  cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='32' height='32' viewBox='0 0 32 32'%3E%3Cline x1='16' y1='4' x2='16' y2='12' stroke='black' stroke-width='3'/%3E%3Cline x1='16' y1='20' x2='16' y2='28' stroke='black' stroke-width='3'/%3E%3Cline x1='4' y1='16' x2='12' y2='16' stroke='black' stroke-width='3'/%3E%3Cline x1='20' y1='16' x2='28' y2='16' stroke='black' stroke-width='3'/%3E%3C/svg%3E") 16 16, crosshair;
}

.game-button {
  background-color: var(--button-bg);
  color: var(--text-color);
  border: none;
  border-radius: 8px;
  padding: 10px 20px;
  font-size: clamp(1rem, 2.5vw, 1.2rem);
  font-weight: bold;
  cursor: pointer;
  box-shadow: 0 4px 15px var(--shadow-color);
  transition: all 0.2s ease-in-out;
}

.game-button:hover {
  background-color: var(--button-hover-bg);
  transform: translateY(-2px);
}

#play-again-btn {
  position: absolute;
  top: 120px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: none;
}

#how-to-play-btn {
  padding: 6px 12px;
  font-size: clamp(0.8rem, 1.5vw, 0.9rem);
  margin-bottom: 5px;
}

#rules-modal {
  display: none;
  position: fixed;
  z-index: 200;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  background-color: rgba(0, 0, 0, 0.6);
  padding-top: 10px;
}

.modal-content {
  background: linear-gradient(to bottom, var(--background-start), var(--background-end));
  margin: 0 auto;
  padding: 25px;
  border: 1px solid var(--table-rail);
  border-radius: 10px;
  width: 100%;
  max-width: 800px;
  position: relative;
}

.modal-content h2 {
  margin-top: 0;
  color: var(--button-bg);
}

.modal-content p,
.modal-content li {
  line-height: 1.6;
}

.close-btn {
  color: #aaa;
  position: absolute;
  top: 10px;
  right: 25px;
  font-size: 35px;
  font-weight: bold;
  cursor: pointer;
}

.close-btn:hover,
.close-btn:focus {
  color: white;
}
