body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  min-height: 100vh;
  margin: 0;
  background: linear-gradient(135deg, #1f2937 0%, #374151 100%);
  color: #e5e7eb;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}
h1 {
  font-size: 2.5rem;
  font-weight: 700;
  color: #f9fafb;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  margin-bottom: 0.5rem;
  padding-bottom: 1.5rem;
}
/* Game Settings Menu */
.game-settings {
  position: fixed;
  top: 140px;
  right: 20px;
  z-index: 1000;
}

.settings-cog {
  background: #374151;
  color: #f9fafb;
  border: 2px solid #ff0000;
  border-radius: 50%;
  width: 50px;
  height: 50px;
  font-size: 20px;
  cursor: pointer;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3), 0 0 10px rgba(99, 102, 241, 0.2);
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.settings-cog:hover {
  background: #4b5563;
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.4), 0 0 15px rgba(99, 102, 241, 0.3);
  transform: translateY(-1px) rotate(90deg);
}

.settings-cog.active {
  background: #ff0000;
  border-color: #e54646;
  transform: rotate(180deg);
}

.settings-dropdown {
  position: absolute;
  top: 60px;
  right: 0;
  background: #1f2937;
  border: 2px solid #374151;
  border-radius: 12px;
  min-width: 200px;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.4), 0 0 20px rgba(99, 102, 241, 0.1);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: all 0.3s ease;
}

.settings-dropdown.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.settings-header {
  background: #374151;
  color: #f9fafb;
  padding: 12px 16px;
  border-radius: 10px 10px 0 0;
  font-weight: 600;
  font-size: 14px;
  text-align: center;
  border-bottom: 1px solid #4b5563;
}

.settings-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid #374151;
}

.settings-item:last-child {
  border-bottom: none;
  border-radius: 0 0 10px 10px;
}

.settings-item label {
  color: #f9fafb;
  font-weight: 500;
  font-size: 14px;
}

.setting-button {
  background: #374151;
  color: #f9fafb;
  border: 1px solid #4b5563;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  min-width: 70px;
  text-align: center;
}

.setting-button:hover {
  background: #4b5563;
  transform: translateY(-1px);
}

.sound-toggle.muted {
  background: #dc2626;
  border-color: #b91c1c;
  color: #fff;
}

.sound-toggle.muted:hover {
  background: #b91c1c;
}

.zoom-control {
  border-color: #ff0000;
}

.zoom-control:hover {
  background: #4b5563;
  border-color: #b91010;
}
.main-container {
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0.5rem;
  padding-top: 2rem; /* Extra top padding to give space for timer */
}
/* Responsive board container: stays square and fits device width between a sensible min and max */
#boardContainer {
  /* Slightly smaller defaults so game info/timers remain visible */
  width: clamp(240px, 36vw, 420px);
  height: auto;
  aspect-ratio: 1 / 1;
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 0 auto;
  touch-action: none;
  background: #374151;
  border-radius: 8px;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3), 0 0 20px rgba(255, 0, 0, 0.1);
  padding: 0.25rem;
  flex-shrink: 0;
  position: relative;
  transition: transform 0.3s ease, width 0.3s ease, height 0.3s ease;
}

/* Zoom levels */
#boardContainer.zoom-small {
  transform: scale(0.8);
}

#boardContainer.zoom-normal {
  transform: scale(1);
}

#boardContainer.zoom-large {
  transform: scale(1.2);
}

#boardContainer.zoom-xlarge {
  transform: scale(1.4);
}

/* Timer zoom compensation - keep text fixed size while following board */
#boardContainer.zoom-small #timer-section {
  transform: translateX(-50%) scale(1.25); /* Counteract 0.8x: 1/0.8 = 1.25 */
}

#boardContainer.zoom-normal #timer-section {
  transform: translateX(-50%) scale(1); /* Normal size: 1/1 = 1 */
}

#boardContainer.zoom-large #timer-section {
  transform: translateX(-50%) scale(0.8333); /* Counteract 1.2x: 1/1.2 = 0.8333 */
}

#boardContainer.zoom-xlarge #timer-section {
  transform: translateX(-50%) scale(0.7143); /* Counteract 1.4x: 1/1.4 = 0.7143 */
}

/* Chessboard fills the container and maintains square aspect ratio */
#chessboard {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 1 / 1;
  border: none;
}
#gameInfo {
  background: #374151;
  padding: 1rem;
  border-radius: 8px;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2), 0 0 20px rgba(255, 0, 0, 0.1);
  margin-top: 0.5rem;
  text-align: center;
  width: 100%;
  max-width: min(40vw, 560px);
  color: #f9fafb;
}
#white-timer.active, #black-timer.active {
  font-weight: bold;
  color: #dc2626;
}

/* Timer section styling */
#timer-section {
  display: none; /* Hidden by default */
  position: absolute;
  top: -3rem; /* Fixed above the board, not over it */
  left: 50%;
  transform: translateX(-50%);
  z-index: 20; /* Above board but below UI elements */
  width: max-content;
  pointer-events: none; /* Allow clicks through to board */
}

#timer-section.show {
  display: block;
}

#timer-section .inline-flex {
  background: rgba(55, 65, 81, 0.95);
  backdrop-filter: blur(15px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3), 0 0 20px rgba(255, 0, 0, 0.1);
  padding: 0.75rem 1rem;
  border-radius: 8px;
  width: fit-content;
  pointer-events: auto; /* Re-enable clicks on timer */
}

#timer-section #white-timer.active, 
#timer-section #black-timer.active {
  color: #ef4444;
  text-shadow: 0 0 8px rgba(239, 68, 68, 0.5);
}

@media (max-width: 768px) {
  #timer-section {
    top: -4rem; /* Much further above board on mobile to avoid overlap */
    z-index: 5; /* Lower z-index to avoid nav conflicts */
  }
  #timer-section .inline-flex {
    flex-direction: column;
    gap: 0.125rem; /* Tighter gap for compact mobile layout */
    padding: 0.375rem 0.625rem; /* More compact padding */
    font-size: 0.8125rem; /* Smaller text for mobile screens */
    border-radius: 6px; /* Slightly smaller border radius */
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.25), 0 0 15px rgba(255, 0, 0, 0.08); /* Softer shadow */
  }
  #timer-section #white-timer,
  #timer-section #black-timer {
    line-height: 1.2; /* Tighter line height for mobile */
    font-weight: 600; /* Slightly bolder for better readability */
  }
}
#gameControls, #tournamentInfo {
  width: 100%;
  max-width: 360px;
  background: #374151;
  padding: 1rem;
  border-radius: 8px;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2), 0 0 20px rgba(255, 0, 0, 0.1);
  color: #f9fafb;
}
#gameControls h2, #tournamentInfo h2 {
  font-size: 1.25rem;
  font-weight: 600;
  color: #f9fafb;
  margin-bottom: 1rem;
}
button {
  transition: all 0.3s ease;
  border: none;
  border-radius: 8px;
  font-weight: 500;
  font-size: 0.95rem;
  padding: 0.75rem 1rem;
}
button:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
}
#new-game-computer { background: #ff0000; }
#new-game-computer:hover { background: #2563eb; }
#local-multiplayer { background: #10b981; }
#local-multiplayer:hover { background: #059669; }
#online-multiplayer { background: #b90101; }
#online-multiplayer:hover { background: #ed3a3a; }
#puzzle-mode { background: #f59e0b; }
#puzzle-mode:hover { background: #d97706; }
#tournament { background: #a50101; }
#tournament:hover { background: #ed3a3a; }
#game-lobby { background: #c70000; }
#game-lobby:hover { background: #ed3a3a; }
#create-game, #startTournamentBtn { background: #ff0000; }
#create-game:hover, #startTournamentBtn:hover { background: #2563eb; }
#close-online-modal, #close-tournament-modal, #delete-game, #set-name, #show-history { background: #6b7280; }
#close-online-modal:hover, #close-tournament-modal:hover, #delete-game:hover, #set-name:hover, #show-history:hover { background: #4b5563; }
#forfeit-game { background: #dc2626; }
#forfeit-game:hover { background: #b91c1c; }
#piece-theme, #time-mode, #color-choice {
  width: 100%;
  padding: 0.75rem;
  border-radius: 8px;
  border: 1px solid #d1d5db;
  background: #4b5563;
  color: #f9fafb;
  font-size: 0.95rem;
}
#promotionModal, #online-games-modal, #create-tournament-modal, #history-modal, #game-lobby-modal {
  display: none;
  position: fixed;
  max-height: 80vh;
  overflow-y: auto;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #374151;
  padding: 2rem;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4), 0 0 30px rgba(255, 0, 0, 0.2);
  width: 90%;
  max-width: min(500px, 90vw);
  color: #f9fafb;
}
.modal-content h2 {
  font-size: 1.5rem;
  font-weight: 600;
  color: #f9fafb;
  margin-bottom: 1.5rem;
}
.piece-option {
  cursor: pointer;
  margin: 0 0.75rem;
  width: 60px;
  height: 60px;
  transition: transform 0.2s ease;
}
.piece-option:hover {
  transform: scale(1.15);
}
#available-games, #active-tournaments {
  max-height: 240px;
  overflow-y: auto;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #4b5563;
}
.game-item {
  cursor: pointer;
  padding: 0.75rem;
  border-bottom: 1px solid #e5e7eb;
  transition: background 0.2s ease;
  font-size: 0.95rem;
}
.game-item:hover {
  background: #6b7280;
}
.form-label {
  display: block;
  text-align: left;
  font-weight: 600;
  color: #f9fafb;
  margin-bottom: 0.5rem;
  font-size: 0.95rem;
}
input, select {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  background: #4b5563;
  color: #f9fafb;
  font-size: 0.95rem;
}
input:focus, select:focus {
  outline: none;
  border-color: #ff0000;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}
#custom-time-inputs {
  display: none;
}
footer {
  margin-top: 2rem;
  padding: 1.5rem;
  text-align: center;
  color: #d1d5db;
  font-size: 0.9rem;
}
@media (max-width: 768px) {
  .main-container {
    flex-direction: column;
    align-items: center;
    padding: 0.25rem;
    padding-top: 2.5rem; /* More space at top for timer positioned higher */
    gap: 0.75rem;
  }
  #boardContainer, #chessboard {
    max-width: min(90vw, 360px);
    min-width: 180px;
  }
  #boardContainer {
    padding: 0.125rem;
  }
  #gameInfo {
    max-width: min(90vw, 480px);
    padding: 0.75rem;
    margin-top: 0.25rem;
  }
  #gameControls, #tournamentInfo {
    max-width: 400px;
    padding: 0.75rem;
  }
  h1 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
  }
  .game-settings {
    top: 110px;
    right: 10px;
  }
  
  .settings-cog {
    width: 40px;
    height: 40px;
    font-size: 16px;
  }
  
  .settings-dropdown {
    min-width: 180px;
    top: 50px;
  }
  
  .settings-item {
    padding: 10px 12px;
  }
  
  .setting-button {
    padding: 4px 8px;
    font-size: 11px;
    min-width: 60px;
  }
}

/* My Creations bottom panel */
#my-creations {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: 100%;
  max-width: 920px;
  background: rgba(55, 65, 81, 0.95);
  color: #f9fafb;
  border-top-left-radius: 12px;
  border-top-right-radius: 12px;
  box-shadow: 0 -6px 18px rgba(0,0,0,0.25), 0 0 20px rgba(255, 0, 0, 0.1);
  z-index: 1100;
  padding: 12px;
}
#my-creations.hidden { display: none; }
#my-creations .my-creations-inner { display:flex; gap:12px; align-items:flex-start; justify-content:space-between; }
#created-games-list, #created-tournaments-list { max-height: 160px; overflow-y: auto; width: 48%; }
.creation-item { padding:8px; border-bottom:1px solid #e5e7eb; background:#4b5563; margin-bottom:6px; border-radius:6px; display:flex; align-items:center; justify-content:space-between; }
#show-my-creations { background:#111827; }
