@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;700&display=swap");

body {
  font-family: "Poppins", sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px;
  color: #333;
  min-height: 100vh;
  margin: 0;
  position: relative;
}

.container {
  width: 100%;
  height: 100%;
  position: fixed;
  top: 0;
  left: 0;
  z-index: -1;
  --s: 100px;
  --c1: #f8b195;
  --c2: #355c7d;
  --_g: var(--c2) 4% 14%, var(--c1) 14% 24%, var(--c2) 22% 34%,
    var(--c1) 34% 44%, var(--c2) 44% 56%, var(--c1) 56% 66%, var(--c2) 66% 76%,
    var(--c1) 76% 86%, var(--c2) 86% 96%;
  background: radial-gradient(
      100% 100% at 100% 0,
      var(--c1) 4%,
      var(--_g),
      #0008 96%,
      #0000
    ),
    radial-gradient(
        100% 100% at 0 100%,
        #0000,
        #0008 4%,
        var(--_g),
        var(--c1) 96%
      )
      var(--c1);
  background-size: var(--s) var(--s);
}

/* Title Styling */
#title-container {
  background: rgba(255, 255, 255, 0.9);
  padding: 20px 40px;
  border-radius: 15px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
  margin-bottom: 30px;
  text-align: center;
  width: fit-content;
  max-width: 90%;
  border: 2px solid #355c7d;
}

#title-container h1 {
  margin: 0;
  font-size: 2.6em;
  font-weight: 700;
  color: #355c7d;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Screen Management */
.hidden {
  display: none !important;
}

#mode-selection-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 30px;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 15px;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
  margin-top: 30px;
  border: 2px solid #355c7d;
}

#game-screen {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

#game-setup {
  margin-bottom: 25px;
  padding: 20px;
  background: rgba(248, 177, 149, 0.1);
  border-radius: 10px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
  border: 1px solid #355c7d;
}

#game-setup fieldset {
  border: 1px solid #355c7d;
  border-radius: 8px;
  padding: 15px 20px;
  margin: 10px 0;
  background: rgba(255, 255, 255, 0.5);
}

#game-setup legend {
  color: #355c7d;
  font-weight: 600;
}

#top-controls {
  position: relative;
  width: 100%;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 20px;
  z-index: 10;
}

.board {
  display: grid;
  grid-template-columns: repeat(3, 110px);
  grid-template-rows: repeat(3, 110px);
  grid-gap: 12px;
  margin-bottom: 25px;
  padding: 15px;
  background: rgba(255, 255, 255, 0.9);
  border: 3px solid #355c7d;
  border-radius: 15px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
}

.mini-board {
  background: rgba(248, 177, 149, 0.3);
  border: 2px solid #355c7d;
  height: 110px;
  position: relative;
  width: 110px;
  font-size: 26px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  grid-gap: 3px;
  padding: 3px;
  border-radius: 8px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
}

.mini-board:hover {
  transform: scale(1.02);
  box-shadow: 0 6px 15px rgba(0, 0, 0, 0.15);
}

.cell {
  background: rgba(255, 255, 255, 0.8);
  border: 1px solid #355c7d;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #333;
  font-size: 24px;
  font-weight: 700;
  cursor: pointer;
  height: 100%;
  width: 100%;
  border-radius: 4px;
  transition: all 0.3s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.cell:hover {
  background: rgba(248, 177, 149, 0.5);
  transform: scale(1.05);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.highlight {
  background: rgba(53, 92, 125, 0.3) !important;
  border: 3px solid #355c7d !important;
  box-shadow: 0 0 15px rgba(53, 92, 125, 0.5);
}

.mini-board.won-x {
  background: rgba(53, 92, 125, 0.2);
  border-color: #355c7d;
}

.mini-board.won-o {
  background: rgba(248, 177, 149, 0.4);
  border-color: #f8b195;
}

.cell.x {
  color: #355c7d;
  font-weight: 900;
}

.cell.o {
  color: #f8b195;
  font-weight: 900;
}

#game-status {
  margin-bottom: 30px;
  margin-top: 25px;
  font-size: 1.3em;
  font-weight: 600;
  padding: 15px 35px;
  background: rgba(255, 255, 255, 0.9);
  color: #333;
  border-radius: 10px;
  border: 2px solid #355c7d;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
  text-align: center;
  max-width: 600px;
  width: fit-content;
}

.player-x-indicator {
  color: #355c7d;
  font-weight: 700;
}

.player-o-indicator {
  color: #f8b195;
  font-weight: 700;
}

/* Button Styling */
button {
  padding: 12px 20px;
  font-size: 16px;
  margin: 8px;
  font-family: "Poppins", sans-serif;
  cursor: pointer;
  border-radius: 8px;
  border: 2px solid #355c7d;
  font-weight: 600;
  background: #f8b195;
  color: #333;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
}

button:hover {
  background: #355c7d;
  color: white;
  transform: translateY(-2px);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
}

button#start-game-button {
  background: #355c7d;
  color: white;
  border: 2px solid #355c7d;
  padding: 15px 40px;
  font-size: 1.2em;
  font-weight: 700;
  box-shadow: 0 6px 15px rgba(0, 0, 0, 0.2);
}

button#start-game-button:hover {
  background: #f8b195;
  color: #333;
  transform: translateY(-3px) scale(1.05);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.25);
}

button:disabled {
  background: #ccc;
  color: #666;
  cursor: not-allowed;
  opacity: 0.6;
  border-color: #999;
}

button:disabled:hover {
  transform: none;
  background: #ccc;
  color: #666;
}

/* SVG Winning Line Animation */
.winning-stroke {
  stroke-dasharray: 100;
  stroke-dashoffset: 100;
  animation: draw-line 0.6s ease-out forwards;
}

@keyframes draw-line {
  to {
    stroke-dashoffset: 0;
  }
}

/* Overlay styles */
.overlay-hidden {
  display: none !important;
}

#game-over-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  color: white;
  text-align: center;
  opacity: 0;
  transition: opacity 0.3s ease-in-out;
}

#game-over-overlay.visible {
  opacity: 1;
}

#game-over-message {
  font-size: 3em;
  font-weight: 700;
  margin-bottom: 30px;
  color: #f8b195;
}

#play-again-button {
  padding: 20px 50px;
  font-size: 1.5em;
  font-weight: 700;
  background: #355c7d;
  color: white;
  border: 3px solid #355c7d;
  border-radius: 12px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
}

#play-again-button:hover {
  background: #f8b195;
  color: #333;
  border-color: #f8b195;
  transform: translateY(-4px) scale(1.05);
  box-shadow: 0 12px 25px rgba(0, 0, 0, 0.4);
}

/* Rulebook Overlay */
#rulebook-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.8);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1001;
  opacity: 0;
  transition: opacity 0.3s ease-in-out;
  padding: 20px;
  box-sizing: border-box;
}

#rulebook-overlay.visible {
  opacity: 1;
}

#rulebook-content {
  background-color: rgba(255, 255, 255, 0.95);
  color: #333;
  padding: 30px 40px;
  border-radius: 15px;
  max-width: 700px;
  max-height: 80vh;
  overflow-y: auto;
  position: relative;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  border: 2px solid #355c7d;
}

#rulebook-content h2,
#rulebook-content h3 {
  color: #355c7d;
  margin-top: 0;
}

#rulebook-content ul,
#rulebook-content ol {
  text-align: left;
  padding-left: 20px;
}

#close-rulebook-button {
  position: absolute;
  top: 15px;
  right: 15px;
  background: none;
  border: none;
  color: #355c7d;
  font-size: 28px;
  font-weight: bold;
  cursor: pointer;
  padding: 0 5px;
}

#close-rulebook-button:hover {
  color: #f8b195;
}

/* Statistics Overlay */
#stats-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.8);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1001;
  opacity: 0;
  transition: opacity 0.3s ease-in-out;
  padding: 20px;
  box-sizing: border-box;
}

#stats-overlay.visible {
  opacity: 1;
}

#stats-content {
  background: rgba(255, 255, 255, 0.95);
  color: #333;
  padding: 30px;
  border-radius: 15px;
  max-width: 500px;
  width: 100%;
  position: relative;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  border: 2px solid #355c7d;
}

#stats-content h2 {
  color: #355c7d;
  text-align: center;
  margin-bottom: 25px;
  font-size: 1.8em;
}

#stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 15px;
  margin-bottom: 25px;
}

.stat-item {
  background: rgba(248, 177, 149, 0.2);
  padding: 15px;
  border-radius: 8px;
  text-align: center;
  border: 1px solid #355c7d;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.stat-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
}

.stat-label {
  font-size: 0.9em;
  color: #666;
  margin-bottom: 8px;
}

.stat-value {
  font-size: 1.5em;
  font-weight: 700;
  color: #355c7d;
}

#close-stats-button {
  position: absolute;
  top: 15px;
  right: 15px;
  background: none;
  border: none;
  color: #355c7d;
  font-size: 28px;
  font-weight: bold;
  cursor: pointer;
  padding: 0 5px;
}

#close-stats-button:hover {
  color: #f8b195;
}

#reset-stats-button {
  background: #f8b195;
  color: #333;
  border: 2px solid #f8b195;
  padding: 14px 30px;
  border-radius: 8px;
  font-weight: 600;
  width: 100%;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

#reset-stats-button:hover {
  background: #355c7d;
  color: white;
  border-color: #355c7d;
  transform: translateY(-2px);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2);
}

/* Timer Styles */
#timer-container {
  margin: 15px 0;
  display: flex;
  justify-content: center;
}

#timer-display-game {
  background: rgba(255, 255, 255, 0.9);
  border-radius: 10px;
  padding: 12px 20px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
  border: 2px solid #355c7d;
  display: flex;
  align-items: center;
  gap: 15px;
  min-width: 200px;
}

#timer-text {
  color: #333;
  font-weight: 600;
}

#timer-value {
  color: #355c7d;
  font-size: 1.2em;
  font-weight: 700;
  min-width: 25px;
  text-align: center;
}

#timer-bar {
  flex: 1;
  background-color: rgba(248, 177, 149, 0.3);
  border-radius: 5px;
  height: 8px;
  overflow: hidden;
}

#timer-progress {
  height: 100%;
  background: #355c7d;
  border-radius: 5px;
  transition: width 0.3s ease;
}

#timer-duration-container {
  margin-top: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
}

#timer-duration {
  flex: 1;
  background: #f8b195;
  border: 1px solid #355c7d;
  border-radius: 5px;
  height: 8px;
  outline: none;
  appearance: none;
}

#timer-duration::-webkit-slider-thumb {
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #355c7d;
  cursor: pointer;
}

#timer-display {
  background: #355c7d;
  color: white;
  padding: 5px 10px;
  border-radius: 5px;
  font-weight: 600;
  min-width: 40px;
  text-align: center;
}

/* Input Styling */
input[type="checkbox"] {
  appearance: none;
  width: 18px;
  height: 18px;
  border: 2px solid #355c7d;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.8);
  cursor: pointer;
  position: relative;
  transition: all 0.3s ease;
}

input[type="checkbox"]:checked {
  background: #355c7d;
  border-color: #355c7d;
}

input[type="checkbox"]:checked::before {
  content: "✓";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: white;
  font-weight: bold;
  font-size: 12px;
}

input[type="radio"] {
  appearance: none;
  width: 16px;
  height: 16px;
  border: 2px solid #355c7d;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.8);
  cursor: pointer;
  position: relative;
  transition: all 0.3s ease;
  margin-right: 8px;
}

input[type="radio"]:checked {
  background: #355c7d;
  border-color: #355c7d;
}

input[type="radio"]:checked::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: white;
}

/* Label Styling */
label {
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  margin: 8px 0;
  padding: 4px 8px;
  border-radius: 5px;
}

label:hover {
  color: #355c7d;
  background: rgba(248, 177, 149, 0.1);
}

/* Mobile Adjustments */
@media (max-width: 600px) {
  #title-container h1 {
    font-size: 1.8em;
  }

  #top-controls {
    position: relative;
    top: auto;
    left: auto;
    width: 100%;
    justify-content: center;
    margin-bottom: 15px;
    margin-top: 10px;
    flex-wrap: wrap;
    gap: 5px;
  }

  #top-controls button {
    padding: 8px 12px;
    font-size: 0.9em;
  }

  .board {
    grid-template-columns: repeat(3, 80px);
    grid-template-rows: repeat(3, 80px);
  }

  .mini-board {
    height: 80px;
    width: 80px;
  }

  .cell {
    font-size: 18px;
  }

  #game-status {
    font-size: 1em;
    padding: 10px 15px;
  }

  #game-over-message {
    font-size: 2em;
  }

  #play-again-button {
    padding: 12px 25px;
    font-size: 1.1em;
  }

  #rulebook-content,
  #stats-content {
    padding: 20px;
    max-height: 75vh;
  }

  #stats-grid {
    grid-template-columns: 1fr;
  }

  #timer-display-game {
    min-width: 150px;
    padding: 10px 15px;
  }

  #timer-duration-container {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
}