* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-tile: #334155;
  --bg-tile-hover: #475569;
  --accent: #22d3ee;
  --accent-glow: rgba(34, 211, 238, 0.4);
  --accent-dim: #0891b2;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --success: #10b981;
  --success-glow: rgba(16, 185, 129, 0.5);
  --pipe-inactive: #64748b;
  --pipe-active: #22d3ee;
  --server-color: #f59e0b;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 1rem;
}

.game-container {
  max-width: 600px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.game-header {
  text-align: center;
}

.game-header h1 {
  font-size: 2.5rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent) 0%, var(--success) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 0.25rem;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 0.95rem;
}

.game-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.control-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.control-group label {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

select {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--bg-tile);
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  font-size: 0.9rem;
  cursor: pointer;
  transition: border-color 0.2s;
}

select:hover,
select:focus {
  border-color: var(--accent);
  outline: none;
}

.btn {
  padding: 0.6rem 1.5rem;
  border: none;
  border-radius: 0.5rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary {
  background: var(--accent);
  color: var(--bg-primary);
}

.btn-primary:hover {
  background: var(--accent-dim);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px var(--accent-glow);
}

.game-stats {
  display: flex;
  justify-content: center;
  gap: 2rem;
}

.stat {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.stat-label {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.stat-value {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--accent);
  min-width: 3rem;
}

.game-board-container {
  display: flex;
  justify-content: center;
  padding: 1rem;
}

.game-board {
  display: grid;
  gap: 4px;
  background: var(--bg-secondary);
  padding: 12px;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.tile {
  width: 60px;
  height: 60px;
  background: var(--bg-tile);
  border-radius: 8px;
  cursor: pointer;
  position: relative;
  transition: background-color 0.2s, transform 0.1s;
  overflow: hidden;
}

.tile:hover {
  background: var(--bg-tile-hover);
}

.tile:active {
  transform: scale(0.95);
}

/* Rotation is handled via JS transform on the SVG */

.tile svg {
  width: 100%;
  height: 100%;
  transition: transform 0.2s ease-out;
}

.tile.connected .pipe-line {
  stroke: var(--pipe-active);
  filter: drop-shadow(0 0 4px var(--accent-glow));
}

.tile:not(.connected) .pipe-line {
  stroke: var(--pipe-inactive);
}

.tile.server {
  background: var(--bg-tile);
}

.tile.server .server-icon {
  fill: var(--server-color);
  filter: drop-shadow(0 0 6px rgba(245, 158, 11, 0.5));
}

.tile.server.connected .server-icon {
  fill: var(--success);
  filter: drop-shadow(0 0 8px var(--success-glow));
}

.pipe-line {
  stroke-width: 8;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.pipe-end {
  fill: var(--pipe-inactive);
}

.tile.connected .pipe-end {
  fill: var(--pipe-active);
}

/* Win message overlay */
.win-message {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.9);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
  animation: fade-in 0.3s ease-out;
}

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

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.win-content {
  background: var(--bg-secondary);
  padding: 2.5rem;
  border-radius: 1rem;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  animation: scale-in 0.3s ease-out;
}

@keyframes scale-in {
  from {
    transform: scale(0.9);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

.win-content h2 {
  font-size: 2rem;
  color: var(--success);
  margin-bottom: 0.5rem;
}

.win-content p {
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

.win-stats {
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 1.5rem;
}

/* Responsive design */
@media (max-width: 480px) {
  .game-header h1 {
    font-size: 2rem;
  }

  .subtitle {
    font-size: 0.85rem;
  }

  .game-controls {
    flex-direction: column;
    gap: 0.75rem;
  }

  .game-stats {
    gap: 1.5rem;
  }

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

  .game-board {
    padding: 8px;
    gap: 3px;
  }
}

@media (max-width: 360px) {
  .tile {
    width: 42px;
    height: 42px;
  }

  .game-board {
    padding: 6px;
    gap: 2px;
  }
}

/* Larger screens */
@media (min-width: 768px) {
  .tile {
    width: 70px;
    height: 70px;
  }

  .game-board {
    padding: 16px;
    gap: 5px;
  }
}

.game-footer {
  margin-top: 2rem;
  padding: 1rem 0;
  text-align: center;
  border-top: 1px solid var(--bg-tile);
}

.footer-link {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.9rem;
  transition: color 0.2s;
}

.footer-link:hover {
  color: var(--accent);
}
