/* Import a modern Google Font */
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap');

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  max-width: 100%;
  overflow-x: hidden;
}

body {
  font-family: 'Roboto', sans-serif;
  background-color: #f7f7f7;
  color: #333;
  text-align: center;
  margin: 0;
  padding: 10px;
}

/* Header */
header {
  margin-bottom: 10px;
  padding: 5px;
}

header h1 {
  font-size: 1.8rem;
  margin: 10px 0;
}

/* Game container to align controls with board */
.game-container {
  position: relative;
  width: 320px;
  margin: 0 auto;
}

/* Control Panel - New Layout with absolute positioning */
#controls {
  position: relative;
  width: 100%;
  margin-bottom: 15px;
  height: 70px; /* Fixed height for controls section */
}

.section-title {
  font-weight: bold;
  margin-bottom: 5px;
  text-align: left;
}

/* Piece selection section - left aligned with board */
#piece-section {
  position: absolute;
  left: 0;
  top: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

#piece-controls {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 5px;
}

.piece-option {
  display: flex;
  align-items: center;
  gap: 5px;
}

.piece-option input[type="radio"] {
  margin: 0;
  width: 15px;
  height: 15px;
}

.piece-option label {
  font-size: 1rem;
}

/* Trials section - centered */
.trials-section {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  top: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.trials-section input[type="number"] {
  width: 60px;
  text-align: center;
  padding: 5px;
  font-size: 16px;
  border-radius: 4px;
  border: 1px solid #555;
  -moz-appearance: textfield;
}

/* Hide spin buttons on number inputs for better mobile appearance */
.trials-section input[type="number"]::-webkit-outer-spin-button,
.trials-section input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* Score section - right aligned with board */
.score-section {
  position: absolute;
  right: 0;
  top: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  text-align: right;
}

#score-tracker {
  font-size: 1.2rem;
  font-weight: bold;
}

#percentage {
  font-size: 1rem;
}

/* Main container for board alignment */
main {
  display: flex;
  justify-content: center;
  position: relative;
  margin: 10px auto;
  max-width: 100%;
}

/* Chess Board Container with complete border */
.board {
  position: relative; /* Position relative for absolute positioning of pseudo-elements */
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 320px;
  height: 320px;
  touch-action: manipulation;
  /* Remove border from the grid itself */
  border: none;
  /* Add outline instead of border to ensure it appears on all sides */
  outline: 2px solid #333;
  /* Add box shadow for depth */
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
  /* Ensure the box is a perfect square */
  box-sizing: content-box;
}

/* Board Square Styling */
.square {
  width: 40px;
  height: 40px;
  position: relative;
  transition: background-color 0.2s;
}

@media (hover: hover) {
  .square:hover {
    outline: 2px solid #0077cc;
  }
}

/* Use active state for touch devices */
.square:active {
  outline: 2px solid #0077cc;
}

/* Add this class for user-selected squares */
.user-selected {
  outline: 2px solid #000000;
  outline-offset: -2px;
  z-index: 1; /* Ensure the outline appears above other elements */
}

/* Light and Dark Square Colors */
.light {
  background-color: #f0f0f0;
}

.dark {
  background-color: #b0b0b0;
}

/* Chess Piece Styling */
.piece {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 32px;
  pointer-events: none;
  user-select: none;
}

/* Highlight Styles */
.highlight {
  background-color: var(--highlight-moves, rgba(255, 255, 0, 0.6)) !important;
}

.solution-blue {
  background-color: var(--highlight-solution, rgba(0, 150, 255, 0.5)) !important;
}

.non-solution-red {
  background-color: var(--highlight-incorrect, rgba(255, 50, 50, 0.5)) !important;
}

/* Buttons Container */
#buttons {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  margin: 15px auto;
  max-width: 100%;
}

/* Button Styling */
#buttons button {
  font-size: 16px;
  padding: 12px 15px;
  min-width: 120px;
  min-height: 48px;
  background-color: #0077cc;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.3s, opacity 0.3s;
  touch-action: manipulation;
}

#buttons button:hover:not(:disabled):not(.disabled-button) {
  background-color: #005fa3;
}

#buttons button:active:not(:disabled):not(.disabled-button) {
  transform: scale(0.98);
}

#buttons button:disabled,
#buttons button.disabled-button {
  background-color: #cccccc;
  color: #666666;
  cursor: not-allowed;
  opacity: 0.7;
}

/* Different colors for different button types */
#evaluate-button {
  background-color: #009900;
}

#evaluate-button:hover:not(:disabled):not(.disabled-button) {
  background-color: #007700;
}

#next-button {
  background-color: #0077cc;
}

/* Message Area Styling */
#message {
  margin: 12px auto;
  padding: 12px 10px;
  background-color: #fff;
  border: 1px solid #ddd;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.1);
  font-size: 1rem;
  line-height: 1.4;
  max-width: 100%;
  border-radius: 4px;
}

/* Footer Styling (for status elements) */
footer#status {
  margin-top: 15px;
  padding: 0 5px;
  max-width: 500px;
  margin-left: auto;
  margin-right: auto;
}

/* User Knight Styling */
.user-knight {
  color: var(--knight-accuracy, #00cc00) !important;
  font-weight: bold;
  font-size: 36px;
}

/* User Queen Styling */
.user-queen {
  color: var(--knight-accuracy, #00cc00) !important;
  font-weight: bold;
  font-size: 36px;
}

/* Solution knight styling */
.solution-knight {
  font-size: 32px;
}

/* Solution queen styling */
.solution-queen {
  font-size: 32px;
}

/* Default knight styling */
.default-knight {
  color: var(--knight-default, #000000) !important;
  font-size: 34px;
}

/* Default queen styling */
.default-queen {
  color: var(--knight-default, #000000) !important;
  font-size: 34px;
}

/* Correct knight styling (green) */
.correct-knight {
  color: var(--knight-correct, #00cc00) !important;
  font-weight: bold;
  font-size: 34px;
  text-shadow: var(--shadow-correct, 0 0 5px rgba(0, 204, 0, 0.5));
}

/* Correct queen styling (green) */
.correct-queen {
  color: var(--knight-correct, #00cc00) !important;
  font-weight: bold;
  font-size: 34px;
  text-shadow: var(--shadow-correct, 0 0 5px rgba(0, 204, 0, 0.5));
}

/* Incorrect knight styling (red) */
.incorrect-knight {
  color: var(--knight-incorrect, #ff0000) !important;
  font-weight: bold;
  font-size: 34px;
  text-shadow: var(--shadow-incorrect, 0 0 5px rgba(255, 0, 0, 0.5));
}

/* Incorrect queen styling (red) */
.incorrect-queen {
  color: var(--knight-incorrect, #ff0000) !important;
  font-weight: bold;
  font-size: 34px;
  text-shadow: var(--shadow-incorrect, 0 0 5px rgba(255, 0, 0, 0.5));
}

/* Override solution-blue for accuracy mode user selections */
.accuracy-selection {
  background-color: var(--highlight-accuracy, rgba(0, 204, 0, 0.3)) !important;
}

/* Responsive Design - Adjust layout for different screen sizes */
@media (max-width: 500px) {
  .game-container {
    width: 280px;
  }
  
  #controls {
    height: 140px; /* More height for stacked controls on mobile */
  }
  
  #piece-section {
    position: static;
    margin: 0 auto 15px;
    width: 100%;
  }
  
  .trials-section {
    position: static;
    transform: none;
    margin: 0 auto 15px;
    width: 100%;
  }
  
  .score-section {
    position: static;
    margin: 0 auto;
    width: 100%;
    align-items: center;
    text-align: center;
  }
  
  .section-title {
    text-align: center;
  }
  
  #piece-controls {
    flex-direction: row;
    justify-content: center;
    width: 100%;
    gap: 15px;
  }
  
  .board {
    width: 280px;
    height: 280px;
  }
  
  .square {
    width: 35px;
    height: 35px;
  }
  
  .piece {
    font-size: 28px;
  }
  
  header h1 {
    font-size: 1.5rem;
  }
  
  #buttons button {
    min-width: 100px;
    font-size: 14px;
    padding: 10px 12px;
  }
}

@media (max-width: 350px) {
  .game-container {
    width: 240px;
  }
  
  .board {
    width: 240px;
    height: 240px;
  }
  
  .square {
    width: 30px;
    height: 30px;
  }
  
  .piece {
    font-size: 24px;
  }
  
  #buttons {
    flex-direction: column;
    align-items: center;
  }
  
  #buttons button {
    width: 90%;
  }
}

/* Responsive Design - Adjust layout for different screen sizes */
@media (max-width: 500px) {
  .game-container {
    width: 90vw; /* Use viewport width to make board larger */
    max-width: 400px; /* But with a reasonable maximum */
  }
  
  #controls {
    height: 70px; /* Keep same height as desktop */
    margin-bottom: 10px; /* Less margin on mobile */
  }
  
  /* Keep absolute positioning on mobile */
  #piece-section {
    position: absolute;
    left: 0;
    top: 0;
    width: 30%; /* Allow some width for text */
  }
  
  .trials-section {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    top: 0;
    width: 30%;
  }
  
  .score-section {
    position: absolute;
    right: 0;
    top: 0;
    width: 30%;
  }
  
  /* Adjust font sizes and spacing for smaller screens */
  .section-title {
    font-size: 0.9rem;
    margin-bottom: 3px;
  }
  
  .piece-option label {
    font-size: 0.9rem;
  }
  
  /* Keep vertical layout for radio buttons */
  #piece-controls {
    flex-direction: column;
    gap: 3px;
  }
  
  /* Make board larger on mobile */
  .board {
    width: 90vw; /* Use 90% of viewport width */
    height: 90vw; /* Keep it square */
    max-width: 400px; /* But with a maximum size */
    max-height: 400px;
  }
  
  /* Adjust square sizes proportionally */
  .square {
    width: calc(90vw / 8);
    height: calc(90vw / 8);
    max-width: 50px; /* Maximum square size */
    max-height: 50px;
  }
  
  /* Adjust piece sizes */
  .piece {
    font-size: calc(90vw / 10); /* Proportional to square size */
    max-font-size: 40px;
  }
  
  header h1 {
    font-size: 1.5rem;
  }
  
  #message {
    font-size: 0.9rem;
    padding: 8px;
    margin: 8px auto;
  }
  
  /* Button sizes */
  #buttons button {
    min-width: 90px;
    font-size: 0.9rem;
    padding: 10px 12px;
  }
}

@media (max-width: 350px) {
  /* Even smaller screens */
  .game-container {
    width: 95vw;
  }
  
  /* Further reduce font sizes */
  .section-title {
    font-size: 0.8rem;
  }
  
  .piece-option label {
    font-size: 0.8rem;
  }
  
  #score-tracker, #percentage {
    font-size: 0.9rem;
  }
  
  /* Keep buttons in a row but make them smaller */
  #buttons {
    flex-direction: row;
    flex-wrap: wrap;
  }
  
  #buttons button {
    min-width: 80px;
    font-size: 0.8rem;
    padding: 8px 10px;
  }
}