:root {
  --tg-theme-bg-color: #ffffff;
  --tg-theme-text-color: #000000;
  --tg-theme-button-color: #3390ec;
  --tg-theme-button-text-color: #ffffff;
}

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

body {
  font-family: 'Nunito', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--tg-theme-bg-color, #f0f4f8);
  color: var(--tg-theme-text-color, #1a1a2e);
  min-height: 100vh;
  overflow-x: hidden;
}

/* Splash Screen */
.splash-container {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  padding: 20px;
  text-align: center;
}

.splash-title {
  font-size: 2.5rem;
  font-weight: 900;
  margin-bottom: 10px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.splash-subtitle {
  font-size: 1.1rem;
  color: #666;
  margin-bottom: 40px;
}

.splash-buttons {
  display: flex;
  flex-direction: column;
  gap: 15px;
  width: 100%;
  max-width: 280px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px 32px;
  font-size: 1.1rem;
  font-weight: 700;
  border: none;
  border-radius: 16px;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.2s ease;
  background: #e8eef4;
  color: #333;
}

.btn:hover, .btn:active {
  transform: scale(0.98);
}

.btn.primary {
  background: var(--tg-theme-button-color, linear-gradient(135deg, #667eea 0%, #764ba2 100%));
  color: var(--tg-theme-button-text-color, #fff);
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

/* Game Container */
.game-container {
  padding: 10px;
  max-width: 100vw;
}

.container {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 15px;
}

/* Player Status */
.player {
  padding: 10px 15px;
  background: #f5f5f5;
  border-radius: 12px;
  font-weight: 700;
  font-size: 0.9rem;
}

.connected, .ready {
  font-size: 0.75rem;
  font-weight: 400;
  opacity: 0.4;
  text-decoration: line-through;
}

.connected.active, .ready.active {
  opacity: 1;
  text-decoration: none;
  color: #4CAF50;
}

/* Game Grid */
.battleship-grid {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 2px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 3px;
  border-radius: 12px;
  width: min(45vw, 200px);
  aspect-ratio: 1;
}

.battleship-grid div {
  background: rgba(255, 255, 255, 0.9);
  border-radius: 2px;
  transition: all 0.15s ease;
}

.grid-user div:hover {
  background: rgba(255, 255, 255, 0.7);
}

/* Ships */
.taken {
  background: #546e7a !important;
}

.grid-computer .taken {
  background: rgba(255, 255, 255, 0.9) !important;
}

/* Hit & Miss */
.boom {
  background: #ef5350 !important;
  animation: boom 0.3s ease-out;
}

.miss {
  background: rgba(255, 255, 255, 0.5) !important;
  position: relative;
}

.miss::after {
  content: '•';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: #999;
  font-size: 0.6rem;
}

@keyframes boom {
  0% { transform: scale(1.3); }
  100% { transform: scale(1); }
}

/* Ship containers for drag */
.grid-display {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  padding: 10px;
  background: #f5f5f5;
  border-radius: 12px;
  margin: 10px;
}

.ship {
  display: flex;
  background: #546e7a;
  border-radius: 8px;
  cursor: grab;
}

.ship > div {
  width: min(8vw, 28px);
  height: min(8vw, 28px);
}

.ship:active {
  cursor: grabbing;
  opacity: 0.8;
}

/* Vertical ships */
.destroyer-container-vertical,
.submarine-container-vertical,
.cruiser-container-vertical,
.battleship-container-vertical,
.carrier-container-vertical {
  flex-direction: column;
}

/* Info section */
.info-section {
  text-align: center;
  padding: 15px;
}

.info-text {
  font-size: 1.1rem;
  font-weight: 700;
  margin: 8px 0;
}

#info {
  color: #667eea;
  min-height: 1.5em;
}

#whose-go {
  color: #333;
}

/* Buttons */
#setup-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-bottom: 15px;
}

#setup-buttons .btn {
  padding: 12px 20px;
  font-size: 0.95rem;
}

#start {
  background: linear-gradient(135deg, #4CAF50 0%, #43A047 100%);
  color: white;
}

#rotate {
  background: #e8eef4;
  color: #333;
}

/* Ship styling on grid */
.taken.start.horizontal {
  border-radius: 8px 0 0 8px;
}

.taken.end.horizontal {
  border-radius: 0 8px 8px 0;
}

.taken.start.vertical {
  border-radius: 8px 8px 0 0;
}

.taken.end.vertical {
  border-radius: 0 0 8px 8px;
}

/* Responsive */
@media (max-width: 400px) {
  .splash-title {
    font-size: 2rem;
  }
  
  .battleship-grid {
    width: min(42vw, 180px);
  }
  
  .ship > div {
    width: min(7vw, 24px);
    height: min(7vw, 24px);
  }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  body {
    background: #1a1a2e;
    color: #eee;
  }
  
  .player, .grid-display {
    background: #252542;
  }
  
  .btn {
    background: #252542;
    color: #eee;
  }
  
  #rotate {
    background: #252542;
    color: #eee;
  }
}

/* Ship selection for mobile */
.ship {
  cursor: pointer;
  transition: all 0.2s ease;
  touch-action: manipulation;
}

.ship:hover {
  transform: scale(1.05);
  opacity: 0.9;
}

.ship.selected {
  outline: 3px solid #4CAF50;
  transform: scale(1.1);
  box-shadow: 0 4px 15px rgba(76, 175, 80, 0.4);
}

/* Grid cells clickable */
.grid-user div {
  cursor: pointer;
  transition: background 0.15s;
}

.grid-user div:hover {
  background: rgba(102, 126, 234, 0.3) !important;
}

/* Placed ships visible */
.grid-user .taken {
  background: #546e7a !important;
}

/* Info text styling */
#info {
  font-size: 0.95rem;
  min-height: 1.5em;
  color: #667eea;
}
