:root {
  --primary-color: #3b82f6;
  --secondary-color: #f59e0b;
  --accent-color: #10b981;
  --background-color: #0f172a;
  --surface-color: #1e293b;
  --text-primary: #f8fafc;
  --text-secondary: #cbd5e1;
  --border-color: #334155;
  --grid-color: #e5e7eb;
  --shadow-light: 0 1px 3px 0 rgb(0 0 0 / 0.3), 0 1px 2px -1px rgb(0 0 0 / 0.3);
  --shadow-medium: 0 4px 6px -1px rgb(0 0 0 / 0.3),
    0 2px 4px -2px rgb(0 0 0 / 0.3);
  --shadow-large: 0 10px 15px -3px rgb(0 0 0 / 0.3),
    0 4px 6px -4px rgb(0 0 0 / 0.3);
  --glow-primary: 0 0 20px rgba(59, 130, 246, 0.4);
  --glow-secondary: 0 0 20px rgba(245, 158, 11, 0.4);
  --glow-accent: 0 0 20px rgba(16, 185, 129, 0.4);
}

body {
  font-family: "Inter", sans-serif;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #334155 100%);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  margin: 0;
  box-sizing: border-box;
  position: relative;
  overflow-x: hidden;
}

/* Animated background particles */
body::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: radial-gradient(
      circle at 20% 80%,
      rgba(59, 130, 246, 0.1) 0%,
      transparent 50%
    ),
    radial-gradient(
      circle at 80% 20%,
      rgba(245, 158, 11, 0.1) 0%,
      transparent 50%
    ),
    radial-gradient(
      circle at 40% 40%,
      rgba(16, 185, 129, 0.1) 0%,
      transparent 50%
    );
  animation: float 20s ease-in-out infinite;
  z-index: -1;
}

@keyframes float {
  0%,
  100% {
    transform: translateY(0px) rotate(0deg);
  }
  33% {
    transform: translateY(-20px) rotate(120deg);
  }
  66% {
    transform: translateY(10px) rotate(240deg);
  }
}

/* Game Header */
.game-header {
  display: flex;
  justify-content: space-around;
  align-items: start;
  padding: 1rem;
  border-radius: 16px;
}

.turn-indicator {
  display: flex;
  align-items: center;
}

.status-message {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-radius: 16px;
  font-weight: 600;
  font-size: 0.95rem;
  transition: all 0.3s ease;
  border: 2px solid transparent;
  position: relative;
  overflow: hidden;
}

.status-message::before {
  content: "";
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.1),
    transparent
  );
  transition: left 0.5s ease;
}

.status-message:hover::before {
  left: 100%;
}

.status-player {
  background: linear-gradient(
    135deg,
    rgba(59, 130, 246, 0.2),
    rgba(59, 130, 246, 0.1)
  );
  color: var(--primary-color);
  border-color: var(--primary-color);
  box-shadow: var(--glow-primary);
}

.status-computer {
  background: linear-gradient(
    135deg,
    rgba(245, 158, 11, 0.2),
    rgba(245, 158, 11, 0.1)
  );
  color: var(--secondary-color);
  border-color: var(--secondary-color);
  box-shadow: var(--glow-secondary);
}

.status-win {
  background: linear-gradient(
    135deg,
    rgba(16, 185, 129, 0.2),
    rgba(16, 185, 129, 0.1)
  );
  color: var(--accent-color);
  border-color: var(--accent-color);
  box-shadow: var(--glow-accent);
}

.player-icon {
  font-size: 1.2rem;
  animation: pulse 2s infinite;
}

.computer-icon {
  font-size: 1.2rem;
  animation: pulse 2s infinite;
}

.status-text {
  font-weight: 600;
}

.board-container {
  background: rgba(15, 23, 42, 0.6);
  border-radius: 20px;
  padding: 2rem;
  box-shadow: var(--shadow-medium), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  min-height: 400px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  backdrop-filter: blur(10px);
}

.board-container::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(
    45deg,
    transparent 30%,
    rgba(255, 255, 255, 0.02) 50%,
    transparent 70%
  );
  border-radius: 20px;
  pointer-events: none;
}

#game-board {
  width: 100%;
  height: 100%;
  min-height: 350px;
  max-width: 500px;
  max-height: 500px;
  filter: drop-shadow(0 0 10px rgba(59, 130, 246, 0.2));
}

.node-group {
  cursor: pointer;
  transition: all 0.3s ease;
}

.node-base {
  fill: rgba(30, 41, 59, 0.8);
  stroke: var(--border-color);
  stroke-width: 2;
  transition: all 0.3s ease;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}

.node-group:hover .node-base {
  fill: rgba(59, 130, 246, 0.1);
  stroke: var(--primary-color);
  stroke-width: 3;
  filter: drop-shadow(0 4px 8px rgba(59, 130, 246, 0.4));
  transform: scale(1.05);
}

.node-group.valid-move .node-base {
  fill: rgba(59, 130, 246, 0.2);
  stroke: var(--primary-color);
  animation: pulse 1.5s infinite;
}

.node-group.selected-piece .node-base {
  fill: rgba(59, 130, 246, 0.3);
  stroke: var(--primary-color);
  stroke-width: 3;
}

.piece {
  transition: all 0.4s ease;
  animation: fadeIn 0.5s ease;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}

.player-piece {
  color: var(--primary-color);
  filter: drop-shadow(0 0 8px var(--primary-color));
}

.computer-piece {
  color: var(--secondary-color);
  filter: drop-shadow(0 0 8px var(--secondary-color));
}

.selected-piece .piece {
  filter: drop-shadow(0 0 12px currentColor);
  animation: glow 1.5s infinite alternate;
}

.winning-line {
  stroke: var(--accent-color);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-dasharray: 1000;
  stroke-dashoffset: 1000;
  animation: draw-line 1s forwards, glow 1.5s infinite alternate 1s;
  filter: drop-shadow(0 0 8px var(--accent-color));
}

.connection-line {
  stroke: var(--border-color);
  stroke-width: 1.5;
  opacity: 0.4;
}

/* Control Buttons */
.control-buttons {
  position: fixed;
  top: 2rem;
  left: 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  z-index: 10;
}

.control-btn {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  transition: all 0.3s ease;
  cursor: pointer;
  backdrop-filter: blur(10px);
  position: relative;
  overflow: hidden;
}

.control-btn::before {
  content: "";
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.2),
    transparent
  );
  transition: left 0.5s ease;
}

.control-btn:hover::before {
  left: 100%;
}

.restart-btn {
  background: linear-gradient(135deg, var(--primary-color), #2563eb);
  color: white;
  box-shadow: var(--shadow-medium), var(--glow-primary);
}

.restart-btn:hover {
  transform: translateY(-2px) scale(1.05);
  box-shadow: var(--shadow-large), var(--glow-primary);
}

.home-btn {
  background: linear-gradient(
    135deg,
    var(--surface-color),
    var(--border-color)
  );
  color: var(--text-primary);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: var(--shadow-medium);
}

.home-btn:hover {
  background: linear-gradient(
    135deg,
    var(--border-color),
    var(--text-secondary)
  );
  color: white;
  transform: translateY(-2px) scale(1.05);
  box-shadow: var(--shadow-large);
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: scale(0.8) rotate(-10deg);
  }
  to {
    opacity: 1;
    transform: scale(1) rotate(0deg);
  }
}

@keyframes pulse {
  0% {
    filter: drop-shadow(0 0 4px currentColor);
  }
  50% {
    filter: drop-shadow(0 0 12px currentColor);
  }
  100% {
    filter: drop-shadow(0 0 4px currentColor);
  }
}

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

@keyframes glow {
  from {
    filter: drop-shadow(0 0 4px currentColor);
  }
  to {
    filter: drop-shadow(0 0 12px currentColor);
  }
}

.game-end-popup {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(10px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.3s ease-in-out;
}

.game-end-popup.show {
  opacity: 1;
}

.game-end-popup .popup-content {
  background: linear-gradient(
    135deg,
    var(--surface-color),
    rgba(30, 41, 59, 0.9)
  );
  backdrop-filter: blur(20px);
  border-radius: 20px;
  padding: 2.5rem;
  box-shadow: var(--shadow-large);
  text-align: center;
  max-width: 400px;
  width: 90%;
  border: 1px solid rgba(255, 255, 255, 0.1);
  position: relative;
  overflow: hidden;
}

.game-end-popup .popup-content::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(
    45deg,
    transparent 30%,
    rgba(255, 255, 255, 0.02) 50%,
    transparent 70%
  );
  border-radius: 20px;
  pointer-events: none;
}

.game-end-popup .popup-title {
  font-size: 2.25rem;
  font-weight: 800;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
  background: linear-gradient(
    135deg,
    var(--primary-color),
    var(--accent-color)
  );
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.game-end-popup .popup-message {
  font-size: 1.125rem;
  color: var(--text-secondary);
  margin-bottom: 1.5rem;
  line-height: 1.6;
}

.game-end-popup .popup-button {
  background: linear-gradient(
    135deg,
    var(--primary-color),
    var(--accent-color)
  );
  color: white;
  border: none;
  border-radius: 12px;
  padding: 0.875rem 2rem;
  font-weight: 600;
  font-size: 1rem;
  transition: all 0.3s ease;
  box-shadow: var(--shadow-medium);
  cursor: pointer;
}

.game-end-popup .popup-button:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-large);
}

.game-end-popup .popup-button:active {
  transform: translateY(0);
}

.game-end-popup .popup-buttons {
  display: flex;
  gap: 1rem;
  justify-content: center;
  margin-top: 1.5rem;
}

.game-end-popup .popup-button-primary {
  background: linear-gradient(
    135deg,
    var(--primary-color),
    var(--accent-color)
  );
  color: white;
}

.game-end-popup .popup-button-secondary {
  background: linear-gradient(
    135deg,
    var(--surface-color),
    var(--border-color)
  );
  color: var(--text-primary);
  border: 2px solid var(--border-color);
}

.game-end-popup .popup-button-secondary:hover {
  background: linear-gradient(
    135deg,
    var(--border-color),
    var(--text-secondary)
  );
  color: white;
}

.game-end-win .popup-content {
  border: 2px solid var(--primary-color);
  box-shadow: var(--shadow-large), var(--glow-primary);
}

.game-end-defeat .popup-content {
  border: 2px solid var(--secondary-color);
  box-shadow: var(--shadow-large), var(--glow-secondary);
}

.difficulty-popup {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(10px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  opacity: 1;
  transition: opacity 0.3s ease-in-out;
}

.difficulty-popup .popup-content {
  background: linear-gradient(
    135deg,
    var(--surface-color),
    rgba(30, 41, 59, 0.9)
  );
  backdrop-filter: blur(20px);
  border-radius: 20px;
  padding: 2.5rem;
  box-shadow: var(--shadow-large);
  text-align: center;
  max-width: 500px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.difficulty-popup .popup-title {
  font-size: 2.25rem;
  font-weight: 800;
  color: var(--text-primary);
  margin-bottom: 1rem;
  background: linear-gradient(
    135deg,
    var(--primary-color),
    var(--accent-color)
  );
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.difficulty-popup .popup-subtitle {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 1rem;
}

.difficulty-popup .rules-section {
  text-align: left;
  margin-bottom: 1.5rem;
  padding: 1.25rem;
  background: rgba(15, 23, 42, 0.6);
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.difficulty-popup .rules-title {
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
}

.difficulty-popup .rules-text {
  color: var(--text-secondary);
  font-size: 0.9rem;
  line-height: 1.5;
}

.difficulty-popup .difficulty-buttons {
  display: flex;
  flex-direction: row;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.difficulty-popup .difficulty-btn {
  padding: 1.25rem;
  border-radius: 16px;
  border: 2px solid var(--border-color);
  background: rgba(30, 41, 59, 0.8);
  color: var(--text-primary);
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.3s ease;
  text-align: center;
  flex: 1;
  backdrop-filter: blur(10px);
}

.difficulty-popup .difficulty-btn:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-medium);
}

.difficulty-popup .difficulty-btn.easy {
  border-color: #10b981;
  background: linear-gradient(
    135deg,
    rgba(16, 185, 129, 0.2),
    rgba(16, 185, 129, 0.1)
  );
  box-shadow: var(--glow-accent);
}

.difficulty-popup .difficulty-btn.easy:hover {
  background: linear-gradient(
    135deg,
    rgba(16, 185, 129, 0.3),
    rgba(16, 185, 129, 0.2)
  );
  box-shadow: var(--shadow-medium), var(--glow-accent);
}

.difficulty-popup .difficulty-btn.medium {
  border-color: #f59e0b;
  background: linear-gradient(
    135deg,
    rgba(245, 158, 11, 0.2),
    rgba(245, 158, 11, 0.1)
  );
  box-shadow: var(--glow-secondary);
}

.difficulty-popup .difficulty-btn.medium:hover {
  background: linear-gradient(
    135deg,
    rgba(245, 158, 11, 0.3),
    rgba(245, 158, 11, 0.2)
  );
  box-shadow: var(--shadow-medium), var(--glow-secondary);
}

.difficulty-popup .difficulty-btn.hard {
  border-color: #ef4444;
  background: linear-gradient(
    135deg,
    rgba(239, 68, 68, 0.2),
    rgba(239, 68, 68, 0.1)
  );
  box-shadow: 0 0 20px rgba(239, 68, 68, 0.4);
}

.difficulty-popup .difficulty-btn.hard:hover {
  background: linear-gradient(
    135deg,
    rgba(239, 68, 68, 0.3),
    rgba(239, 68, 68, 0.2)
  );
  box-shadow: var(--shadow-medium), 0 0 20px rgba(239, 68, 68, 0.4);
}

.difficulty-popup .difficulty-btn.selected {
  transform: scale(1.02);
  box-shadow: var(--shadow-medium);
}

.difficulty-popup .start-btn {
  background: linear-gradient(
    135deg,
    var(--primary-color),
    var(--accent-color)
  );
  color: white;
  border: none;
  border-radius: 12px;
  padding: 0.875rem 2rem;
  font-weight: 600;
  font-size: 1rem;
  transition: all 0.3s ease;
  box-shadow: var(--shadow-medium);
  cursor: pointer;
  width: 100%;
}

.difficulty-popup .start-btn:hover {
  background: linear-gradient(135deg, #2563eb, #059669);
  transform: translateY(-2px);
  box-shadow: var(--shadow-large);
}

.difficulty-popup .start-btn:active {
  transform: translateY(0);
}

/* Large Desktop Screens (1200px and above) */
@media (min-width: 1200px) {
  body {
    padding: 2rem;
  }

  .game-header {
    padding: 1.5rem;
  }

  .board-container {
    padding: 2.5rem;
    min-height: 450px;
  }

  #game-board {
    max-width: 550px;
    max-height: 550px;
  }

  .status-message {
    font-size: 1.125rem;
  }

  .control-btn {
    width: 56px;
    height: 56px;
    font-size: 1.25rem;
  }
}

/* Desktop Screens (1024px to 1199px) */
@media (min-width: 1024px) and (max-width: 1199px) {
  body {
    padding: 1.5rem;
  }

  .game-header {
    padding: 1.25rem;
  }

  .board-container {
    padding: 2rem;
    min-height: 400px;
  }

  #game-board {
    max-width: 500px;
    max-height: 500px;
  }
}

/* Tablet Landscape (768px to 1023px) */
@media (min-width: 768px) and (max-width: 1023px) {
  body {
    padding: 1rem;
  }

  .game-header {
    padding: 1rem;
  }

  .board-container {
    padding: 1.75rem;
    min-height: 380px;
  }

  #game-board {
    max-width: 450px;
    max-height: 450px;
  }

  .status-message {
    font-size: 1rem;
  }
}

/* Tablet Portrait (481px to 767px) */
@media (min-width: 481px) and (max-width: 767px) {
  body {
    padding: 0.75rem;
  }

  .game-header {
    padding: 0.875rem;
  }

  .board-container {
    padding: 1.5rem;
    min-height: 350px;
  }

  #game-board {
    max-width: 400px;
    max-height: 400px;
  }

  .status-message {
    font-size: 0.95rem;
  }

  .control-btn {
    width: 44px;
    height: 44px;
    font-size: 1rem;
  }
}

/* Mobile Large (375px to 480px) */
@media (min-width: 375px) and (max-width: 480px) {
  body {
    padding: 0.5rem;
  }

  .game-header {
    padding: 0.75rem;
    border-radius: 12px;
  }

  .board-container {
    padding: 1.25rem;
    min-height: 320px;
    border-radius: 16px;
  }

  #game-board {
    max-width: 380px;
    max-height: 380px;
    min-height: 280px;
  }

  .status-message {
    font-size: 0.9rem;
    padding: 0.625rem 0.875rem;
  }

  .control-btn {
    width: 40px;
    height: 40px;
    font-size: 0.9rem;
  }

  .game-end-popup .popup-content {
    padding: 1.5rem;
    max-width: 320px;
  }

  .game-end-popup .popup-title {
    font-size: 1.75rem;
  }

  .game-end-popup .popup-message {
    font-size: 1rem;
  }

  .difficulty-popup .popup-content {
    padding: 1.5rem;
    max-width: 400px;
  }

  .difficulty-popup .popup-title {
    font-size: 1.75rem;
  }

  .difficulty-popup .difficulty-buttons {
    flex-direction: column;
    gap: 0.5rem;
  }

  .difficulty-popup .difficulty-btn {
    padding: 1rem;
    font-size: 0.95rem;
  }
}

/* Mobile Small (320px to 374px) */
@media (min-width: 320px) and (max-width: 374px) {
  body {
    padding: 0.25rem;
  }

  .game-header {
    padding: 0.625rem;
    border-radius: 10px;
  }

  .board-container {
    padding: 1rem;
    min-height: 300px;
    border-radius: 12px;
  }

  #game-board {
    max-width: 320px;
    max-height: 320px;
    min-height: 260px;
  }

  .status-message {
    font-size: 0.85rem;
    padding: 0.5rem 0.75rem;
  }

  .control-btn {
    width: 36px;
    height: 36px;
    font-size: 0.85rem;
  }

  .game-end-popup .popup-content {
    padding: 1.25rem;
    max-width: 280px;
  }

  .game-end-popup .popup-title {
    font-size: 1.5rem;
  }

  .game-end-popup .popup-message {
    font-size: 0.95rem;
  }

  .difficulty-popup .popup-content {
    padding: 1.25rem;
    max-width: 320px;
  }

  .difficulty-popup .popup-title {
    font-size: 1.5rem;
  }

  .difficulty-popup .difficulty-buttons {
    flex-direction: column;
    gap: 0.5rem;
  }

  .difficulty-popup .difficulty-btn {
    padding: 0.875rem;
    font-size: 0.9rem;
  }
}

/* Extra Small Mobile (below 320px) */
@media (max-width: 319px) {
  body {
    padding: 0.125rem;
  }

  .game-header {
    padding: 0.5rem;
    border-radius: 8px;
  }

  .board-container {
    padding: 0.875rem;
    min-height: 280px;
    border-radius: 10px;
  }

  #game-board {
    max-width: 280px;
    max-height: 280px;
    min-height: 240px;
  }

  .status-message {
    font-size: 0.8rem;
    padding: 0.5rem 0.625rem;
  }

  .control-btn {
    width: 32px;
    height: 32px;
    font-size: 0.8rem;
  }

  .game-end-popup .popup-content {
    padding: 1rem;
    max-width: 250px;
  }

  .game-end-popup .popup-title {
    font-size: 1.25rem;
  }

  .game-end-popup .popup-message {
    font-size: 0.9rem;
  }

  .difficulty-popup .popup-content {
    padding: 1rem;
    max-width: 280px;
  }

  .difficulty-popup .popup-title {
    font-size: 1.25rem;
  }

  .difficulty-popup .difficulty-buttons {
    flex-direction: column;
    gap: 0.375rem;
  }

  .difficulty-popup .difficulty-btn {
    padding: 0.75rem;
    font-size: 0.85rem;
  }
}

/* Landscape orientation adjustments for mobile */
@media (max-height: 500px) and (orientation: landscape) {
  body {
    padding: 0.25rem;
  }

  .game-header {
    padding: 0.5rem;
  }

  .board-container {
    padding: 1rem;
    min-height: 250px;
  }

  #game-board {
    max-width: 350px;
    max-height: 350px;
    min-height: 220px;
  }

  .status-message {
    margin-bottom: 1rem;
    padding: 0.5rem;
  }

  .control-btn {
    width: 40px;
    height: 40px;
    font-size: 0.9rem;
  }
}

/* High DPI displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .node-base {
    stroke-width: 1.5;
  }

  .connection-line {
    stroke-width: 1;
  }

  .winning-line {
    stroke-width: 3;
  }
}
