* {
  box-sizing: border-box;
}

body {
  font-family: "Montserrat", Arial, sans-serif;
  text-align: center;
  background-color: #f3f3f3;
  margin: 0;
  color: #1c1c1c;
}

header {
  background-color: #ffc907;
  padding: 28px 16px;
}

header h1 {
  margin: 0;
  font-size: 3rem;
  font-weight: 800;
}

header p {
  margin: 12px 0 0;
  font-size: 1.2rem;
  font-weight: 600;
}

main {
  padding: 20px 12px 40px;
}

.difficulty-section {
  margin-bottom: 20px;
}

.difficulty-section h2 {
  margin-bottom: 10px;
  font-size: 1.3rem;
}

.difficulty-buttons {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.difficulty-btn {
  padding: 10px 16px;
  border: 2px solid #1f6fa8;
  background-color: white;
  color: #1f6fa8;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 700;
  transition: 0.2s ease;
}

.difficulty-btn:hover,
.difficulty-btn.active {
  background-color: #1f6fa8;
  color: white;
}

#difficultyDescription {
  margin: 8px 0 0;
  font-size: 0.95rem;
  font-weight: 600;
}

.game-info {
  display: flex;
  justify-content: center;
  gap: 20px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.stat-card {
  background: white;
  border-radius: 12px;
  padding: 12px 18px;
  min-width: 120px;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.08);
  font-weight: 700;
}

.legend {
  display: flex;
  justify-content: center;
  gap: 20px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  font-size: 1rem;
  font-weight: 600;
}


.milestone-section {
  margin-bottom: 18px;
}

#milestoneMessage {
  display: inline-block;
  min-height: 24px;
  padding: 10px 16px;
  background-color: #fff7d1;
  border: 2px solid #ffc907;
  border-radius: 10px;
  font-weight: 700;
}

.game-container {
  display: flex;
  justify-content: center;
  margin-bottom: 24px;
}

#grid {
  display: grid;
  grid-template-columns: repeat(6, 72px);
  grid-template-rows: repeat(6, 72px);
  gap: 8px;
  position: relative;
}

.tile {
  width: 72px;
  height: 72px;
  background-color: #d9d9d9;
  border: 3px solid #9a9a9a;
  border-radius: 8px;
  position: relative;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
  overflow: hidden;
}

.tile:hover {
  background-color: #cfcfcf;
}

.tile.source,
.tile.tank {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  background-color: #dff1ff;
}

.tile.tank {
  background-color: #e7f7e7;
}

.tile.connected {
  box-shadow: 0 0 14px rgba(31, 111, 168, 0.8);
}

.pipe-line {
  position: absolute;
  background-color: #1f6fa8;
  border-radius: 10px;
}

.pipe-center {
  width: 18px;
  height: 18px;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.pipe-up,
.pipe-down {
  width: 12px;
  height: 28px;
  left: 50%;
  transform: translateX(-50%);
}

.pipe-up {
  top: 6px;
}

.pipe-down {
  bottom: 6px;
}

.pipe-left,
.pipe-right {
  height: 12px;
  width: 28px;
  top: 50%;
  transform: translateY(-50%);
}

.pipe-left {
  left: 6px;
}

.pipe-right {
  right: 6px;
}

.feedback-popup {
  position: absolute;
  top: 6px;
  right: 6px;
  background-color: rgba(255, 255, 255, 0.95);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 0.8rem;
  font-weight: 800;
  animation: floatUp 0.8s ease forwards;
  pointer-events: none;
  z-index: 5;
}

.feedback-popup.good {
  color: #1f6fa8;
}

.feedback-popup.bad-text {
  color: #b22222;
}

.controls {
  margin-bottom: 16px;
}

button {
  padding: 12px 20px;
  margin: 6px;
  font-size: 1rem;
  font-family: "Montserrat", Arial, sans-serif;
  font-weight: 700;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  background-color: #1f6fa8;
  color: white;
  transition: transform 0.2s ease, background-color 0.2s ease;
}

button:hover {
  background-color: #185784;
  transform: scale(1.03);
}

#message {
  min-height: 30px;
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 30px;
}

footer {
  background-color: #ffffff;
  padding: 24px 16px 36px;
  border-top: 4px solid #ffc907;
}

footer h3 {
  margin-top: 0;
  font-size: 1.3rem;
}

footer p {
  max-width: 700px;
  margin: 10px auto 16px;
  line-height: 1.5;
}

.footer-links {
  display: flex;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
}

.footer-links a {
  text-decoration: none;
  background-color: #ffc907;
  color: #1c1c1c;
  padding: 10px 16px;
  border-radius: 10px;
  font-weight: 800;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.footer-links a:hover {
  transform: translateY(-2px);
  opacity: 0.92;
}

/* ── WIN OVERLAY ── */
.win-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.win-overlay.hidden {
  display: none;
}

.win-box {
  background: white;
  border-radius: 20px;
  padding: 44px 52px;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
  max-width: 400px;
  width: 90%;
  animation: popIn 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.win-emoji {
  font-size: 4rem;
  margin-bottom: 12px;
}

.win-box h2 {
  font-size: 2rem;
  margin: 0 0 12px;
  color: #1f6fa8;
  font-weight: 800;
}

.win-box p {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 28px;
  color: #444;
  line-height: 1.5;
}

#winPlayAgain {
  background-color: #ffc907;
  color: #1c1c1c;
  font-size: 1.1rem;
  padding: 14px 32px;
  border-radius: 12px;
}

#winPlayAgain:hover {
  background-color: #e6b400;
}

@keyframes popIn {
  0% {
    opacity: 0;
    transform: scale(0.7);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes floatUp {
  0% {
    opacity: 0;
    transform: translateY(10px);
  }
  30% {
    opacity: 1;
    transform: translateY(0);
  }
  100% {
    opacity: 0;
    transform: translateY(-12px);
  }
}

@media (max-width: 700px) {
  header h1 {
    font-size: 2.2rem;
  }

  header p {
    font-size: 1rem;
  }

  #grid {
    grid-template-columns: repeat(6, 52px);
    grid-template-rows: repeat(6, 52px);
    gap: 6px;
  }

  .tile {
    width: 52px;
    height: 52px;
  }

  .tile.source,
  .tile.tank {
    font-size: 1.4rem;
  }

  .pipe-center {
    width: 14px;
    height: 14px;
  }

  .pipe-up,
  .pipe-down {
    width: 10px;
    height: 18px;
  }

  .pipe-left,
  .pipe-right {
    height: 10px;
    width: 18px;
  }

  .game-info {
    gap: 12px;
  }

  .stat-card {
    min-width: 100px;
    padding: 10px 12px;
  }

  .win-box {
    padding: 32px 24px;
  }

  .win-box h2 {
    font-size: 1.6rem;
  }
}