/* Default (tablet and above) */
:root {
  --tile-base-size: 3rem; /* Approximately 48px */
  --tile-font-size: 1.5rem;
  --board-cols: 18; /* Changed from 20 to 18 columns for tablet and desktop */
}

/* Reset styles */
*,
::after,
::before {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  border: 0 solid;
}

/* Layout */
.layout-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

header {
  height: 40px;
  background-color: #333;
  color: white;
  display: flex;
  align-items: center;
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 10;
  justify-content: space-between;
}

main {
  flex: 1;
}

footer {
  height: 40px;
  background-color: black;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  padding: 0 20px;
}

/* Game Container and Info Panel */
.game-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 30px auto 0;
  max-width: 800px;
  width: 100%;
  padding: 0 1rem;
}

.info-panel,
.board,
.letter-counts {
  width: calc(var(--tile-base-size) * var(--board-cols));
  margin: 0 auto;
}

.info-panel {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  padding: 0;
}

.score,
.tiles-count {
  font-size: 24px;
  font-weight: bold;
}

.info-panel button {
  padding: 8px 16px;
  border: none;
  border-radius: 4px;
  background-color: #4caf50;
  color: white;
  cursor: pointer;
  font-size: 16px;
}

.info-panel button:hover {
  background-color: #45a049;
}

.info-panel button:disabled {
  background-color: #cccccc;
  cursor: not-allowed;
}

.reset-btn {
  background-color: #c62828; /* Darker red for contrast */
}

.reset-btn:hover {
  background-color: #b71c1c;
}

/* Focus states */
button:focus-visible {
  outline: 3px solid #4c9aff;
  outline-offset: 2px;
}

.tile:focus-visible {
  outline: 3px solid white;
  outline-offset: -2px;
  position: relative;
  z-index: 2;
}

/* Game Board */
.board {
  display: flex;
  flex-direction: column;
  border: 0.125rem solid #333;
  border-radius: 0.5rem;
  overflow: hidden;
  margin: 0 auto;
  min-height: calc(var(--tile-base-size) * 10); /* Reserve height for 10 rows */
  width: calc(var(--tile-base-size) * var(--board-cols));
  max-width: 100%;
}

.row {
  display: flex;
}

/* Border styling for tiles */
.row:first-child .tile {
  border-top: none;
}

.row:last-child .tile {
  border-bottom: none;
}

.row .tile:first-child {
  border-left: none;
}

.row .tile:last-child {
  border-right: none;
}

/* Tile styling */
.tile {
  width: var(--tile-base-size);
  height: var(--tile-base-size);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--tile-font-size);
  font-weight: bold;
  user-select: none;
  transition: all 0.2s ease;
  position: relative;
  border: 1px solid blanchedalmond;
}

.tile:hover {
  opacity: 0.9;
}

.tile.selected {
  box-shadow: inset 0 0 20px rgba(255, 255, 255, 0.7),
    0 0 8px 2px rgba(255, 255, 255, 0.8);
  outline: 2px solid white;
  outline-offset: -2px;
  animation: pulse-highlight 1.5s infinite alternate;
  text-shadow: 0 0 3px rgba(0, 0, 0, 0.8), 0 0 5px rgba(255, 255, 255, 0.8);
  font-weight: 900;
}

.tile.selected::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.6) 0%,
    rgba(255, 255, 255, 0.2) 50%,
    rgba(255, 255, 255, 0) 100%
  );
  pointer-events: none;
}

.tile.empty {
  background-color: #eee;
}

/* Tile Colors */
.tile.letter-a {
  background-color: #ff5252;
  color: white;
}
.tile.letter-b {
  background-color: #448aff;
  color: white;
}
.tile.letter-c {
  background-color: #66bb6a;
  color: white;
}
.tile.letter-d {
  background-color: #ffc107;
  color: white;
}
.tile.letter-e {
  background-color: #9c27b0;
  color: white;
}

/* Animation */
@keyframes pulse-highlight {
  from {
    box-shadow: inset 0 0 15px rgba(255, 255, 255, 0.5),
      0 0 5px 1px rgba(255, 255, 255, 0.5);
  }
  to {
    box-shadow: inset 0 0 25px rgba(255, 255, 255, 0.8),
      0 0 10px 3px rgba(255, 255, 255, 0.8);
  }
}

/* Letter counts display */
.letter-counts {
  margin-top: 20px;
  padding: 10px;
  border: 1px solid #ccc;
  border-radius: 5px;
  background-color: #f8f8f8;
  width: max-content;
  display: inline-block;
  margin-left: auto;
  margin-right: auto;
}

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

.letter-count {
  display: flex;
  align-items: center;
}

.letter-count .tile {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  margin-right: 5px;
  background-color: #4caf50;
  color: white;
  font-weight: bold;
  border-radius: 4px;
}

.letter-count .count {
  font-size: 16px;
}

/* Responsive styling */

/* Mobile (up to 480px): 12 columns, smaller tiles */
@media (max-width: 480px) {
  :root {
    --tile-base-size: 2rem;
    --tile-font-size: 1rem;
    --board-cols: 12;
  }

  .info-panel {
    width: calc(var(--tile-base-size) * var(--board-cols));
    max-width: 100%;
    box-sizing: border-box;
    padding: 0;
    font-size: 0.9rem; /* Slightly smaller font size */
  }

  .score {
    font-size: 1.1rem; /* Smaller font size for score */
  }

  .info-panel button {
    padding: 6px 12px; /* Smaller padding for buttons */
    font-size: 0.9rem;
  }

  .letter-count .tile {
    width: 22px;
    height: 22px;
    font-size: 12px;
  }

  .letter-count .count {
    font-size: 12px;
  }

  .letter-counts {
    padding: 8px;
  }

  .counts-container {
    gap: 10px;
  }
}

/* Tablet (481px to 768px): keep 18 columns with slightly smaller tiles */
@media (min-width: 481px) and (max-width: 768px) {
  :root {
    --tile-base-size: 2.5rem;
    --tile-font-size: 1.25rem;
    --board-cols: 18;
  }

  header,
  footer {
    padding: 0 10px;
  }

  .letter-count .tile {
    width: 26px;
    height: 26px;
    font-size: 14px;
  }

  .letter-count .count {
    font-size: 14px;
  }
}

/* Extra adjustments for larger screens (min-width:768px) */
@media (min-width: 768px) {
  .game-container {
    width: calc(var(--tile-base-size) * var(--board-cols) + 0.25rem);
    max-width: 100%;
    padding: 0;
  }
}

@media (min-width: 800px) {
  :root {
    --tile-base-size: 3rem; /* 48px */
    --tile-font-size: 1.5rem;
    --board-cols: 18; /* Changed from 20 to 18 */
  }

  .game-container {
    /* Use the full board width instead of 800px max-width */
    max-width: calc(var(--tile-base-size) * var(--board-cols));
    padding: 0;
  }
}

/* Special adjustment for iPad-sized devices in portrait orientation */
@media (min-width: 768px) and (max-width: 834px) and (orientation: portrait) {
  :root {
    --tile-base-size: 2.8rem; /* Smaller tiles for iPad portrait */
    --tile-font-size: 1.3rem;
    --board-cols: 18; /* Keep 18 columns */
  }

  /* Adjust game container to fit iPad portrait mode */
  .game-container {
    padding: 0 0.5rem;
  }

  /* Explicitly set info panel width to match board width */
  .info-panel {
    width: calc(var(--tile-base-size) * var(--board-cols));
    max-width: 100%;
    box-sizing: border-box;
    padding: 0;
  }
}

/* Scoreboard button in header */
.scoreboard-btn {
  background-color: #f1c40f;
  color: #333;
  border: none;
  padding: 4px 10px;
  border-radius: 4px;
  font-weight: bold;
  cursor: pointer;
}

.scoreboard-btn:hover {
  background-color: #f39c12;
}

/* Modal styles with better animation */
.modal {
  position: fixed;
  z-index: 100;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.6);
  overflow: auto;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.modal.active {
  opacity: 1;
  visibility: visible;
}

.modal-content {
  background-color: #fefefe;
  margin: 10% auto;
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
  width: 90%;
  max-width: 500px;
  transform: translateY(-20px);
  opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
}

.modal.active .modal-content {
  transform: translateY(0);
  opacity: 1;
}

.close-btn {
  color: #aaa;
  float: right;
  font-size: 28px;
  font-weight: bold;
  cursor: pointer;
}

.close-btn:hover {
  color: black;
}

/* Grid styles for scoreboard */
.scoreboard {
  margin-top: 20px;
  width: 100%;
}

.scoreboard-header {
  display: grid;
  grid-template-columns: 0.5fr 1.5fr 1fr 1fr;
  gap: 8px;
  padding: 10px 0;
  font-weight: bold;
  background-color: #f2f2f2;
  border-bottom: 2px solid #ddd;
}

.scoreboard-rows {
  max-height: 60vh;
  overflow-y: auto;
}

.score-row {
  display: grid;
  grid-template-columns: 0.5fr 1.5fr 1fr 1fr;
  gap: 8px;
  padding: 10px 0;
  border-bottom: 1px solid #ddd;
}

.score-row:nth-child(even) {
  background-color: #f8f8f8;
}

.score-row:hover {
  background-color: #f1f1f1;
}

.rank-header,
.name-header,
.score-header,
.date-header,
.rank,
.name,
.date {
  padding: 0 8px;
}

.score-cell {
  font-weight: bold;
}

/* Make modal more accessible on mobile */
@media (max-width: 768px) {
  .modal-content {
    margin: 60px auto 20px;
    width: 95%;
    padding: 15px;
  }

  .scoreboard-header {
    padding: 8px 0;
  }

  .score-row {
    padding: 8px 0;
  }

  .rank-header,
  .name-header,
  .score-header,
  .date-header,
  .rank-cell,
  .name-cell,
  .score-cell,
  .date-cell {
    padding: 0 4px;
  }
}

/* Small phones */
@media (max-width: 480px) {
  .modal-content {
    margin: 40px auto 10px;
  }

  .scoreboard-header,
  .score-row {
    grid-template-columns: 0.3fr 1.2fr 0.8fr 0.8fr;
    gap: 4px;
  }

  .scoreboard-rows {
    max-height: 70vh;
  }
}

/* Tabs for the leaderboard */
.scoreboard-tabs {
  display: flex;
  margin-bottom: 1rem;
}

.tab-btn {
  flex: 1;
  padding: 0.5rem;
  background: #e0e0e0;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  transition: background-color 0.3s;
}

.tab-btn.active {
  background: #4caf50;
  color: white;
}

.tab-btn:hover:not(.active) {
  background: #d0d0d0;
}

/* Game Introduction Section Styles */
.game-intro {
  max-width: 800px;
  margin: 5rem auto;
  padding: 1.5rem 2rem;
  background: linear-gradient(to bottom, #ffffff, #f8f9fa);
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  text-align: center;
  border-left: 5px solid #4a86e8;
}

.game-intro h2 {
  color: #333;
  font-size: 1.8rem;
  margin-bottom: 1rem;
  font-weight: 600;
  position: relative;
}

.game-intro h2:after {
  content: "";
  display: block;
  width: 80px;
  height: 3px;
  background: linear-gradient(90deg, #4a86e8, #83b3f3);
  margin: 0.8rem auto 1.5rem;
  border-radius: 2px;
}

.game-intro h3 {
  color: #444;
  font-size: 1.4rem;
  margin: 1.5rem 0 0.8rem;
  font-weight: 500;
}

.game-intro p {
  color: #555;
  font-size: 1.1rem;
  line-height: 1.6;
  margin-bottom: 1rem;
}

/* Animation for better engagement */
@keyframes gentle-highlight {
  0% {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  }
  50% {
    box-shadow: 0 6px 16px rgba(74, 134, 232, 0.15);
  }
  100% {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  }
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .game-intro {
    margin: 80px 1rem;
    padding: 1.2rem 1.5rem;
  }

  .game-intro h2 {
    font-size: 1.5rem;
  }

  .game-intro h3 {
    font-size: 1.2rem;
  }

  .game-intro p {
    font-size: 1rem;
  }
}

/* Optional hover effect */
.game-intro:hover {
  animation: gentle-highlight 2s ease-in-out infinite;
}
