:root {
  --primary-blue: #003087; /* Sheffield Wednesday blue */
  --white: #FFFFFF;
  --accent-gold: #FFD700; /* Inspired by kit accents */
  --text-color: #000000;
  --tile-border: #ccc;
  --container-bg: #FFFFFF;
  --button-hover: #005BB5;
  --suggestions-bg: #FFFFFF;
  --suggestions-border: #ccc;
}

body.dark-mode {
  --text-color: #E0E0E0; /* Softer white for readability */
  --tile-border: #555;
  --container-bg: #1a1a1a;
  --suggestions-bg: #2c2c2c;
  --suggestions-border: #555;
}

body {
  font-family: 'Inter', sans-serif;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background: radial-gradient(circle at 50% 50%, var(--primary-blue) 0%, #00205B 50%, var(--white) 100%);
  background-size: 200% 200%;
  animation: gradientShift 15s ease infinite;
  color: var(--text-color);
  margin: 0;
  transition: background-color 0.3s ease;
}

body.dark-mode h1, body.dark-mode h2, body.dark-mode p, body.dark-mode .suggestion-item, body.dark-mode #community-stats-info {
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3); /* Improve contrast */
}

@keyframes gradientShift {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

.wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  padding: 20px;
  box-sizing: border-box;
}

.container {
  text-align: center;
  max-width: 800px;
  width: 100%;
  padding: 30px;
  background-color: var(--container-bg);
  border-radius: 15px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  position: relative;
  overflow: visible;
}

.container::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(45deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.1));
  opacity: 0.3;
  pointer-events: none;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  gap: 30px;
}

.header-buttons {
  display: flex;
  gap: 10px; /* Reduced for mobile */
  flex-wrap: wrap;
  justify-content: center;
}

h1 {
  font-family: 'Poppins', sans-serif;
  font-weight: 700;
  color: var(--primary-blue);
  font-size: 2.8em;
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 1px;
}

h2, button, .category-title {
  font-family: 'Poppins', sans-serif;
  font-weight: 600;
}

#theme-toggle, #how-to-play-button, #stats-button, #archive-button, #view-profile-button {
  padding: 12px 24px;
  background-color: var(--accent-gold);
  color: var(--primary-blue);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-size: 16px;
  font-weight: 600;
  transition: transform 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease;
}

#theme-toggle:hover, #how-to-play-button:hover, #stats-button:hover, #archive-button:hover, #view-profile-button:hover {
  background-color: #FFC107;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

#game-board {
  display: grid;
  gap: 10px;
  margin: 30px 0;
}

#timer {
  margin-top: 20px;
  font-size: 18px;
  font-weight: 500;
  color: var(--primary-blue);
  text-align: center;
}

.category-row {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-bottom: 10px;
}

.category-title {
  width: 100px;
  height: 55px;
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--primary-blue);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

body.dark-mode .category-title {
  font-weight: 600; /* Bolder for readability */
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.category-row .category-title:first-child {
  width: 150px; /* Wider for Player Name */
  white-space: normal; /* Allow wrapping */
  text-overflow: clip; /* No ellipsis */
}

.row, .example-row {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.tile {
  width: 100px;
  height: 55px;
  border: 2px solid var(--tile-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 500;
  text-transform: uppercase;
  background-color: var(--container-bg);
  color: var(--text-color);
  border-radius: 10px;
  transition: transform 0.3s ease, background-color 0.3s ease, box-shadow 0.3s ease;
  visibility: visible;
  position: relative;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

body.dark-mode .tile {
  font-weight: 600; /* Bolder for readability */
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.row .tile:first-child {
  width: 150px; /* Wider for Player Name */
  white-space: normal; /* Allow wrapping */
  text-overflow: clip; /* No ellipsis */
}

.tile.green {
  background-color: #6aaa64;
  color: white;
}

.tile.yellow {
  background-color: #c9b458;
  color: white;
}

.tile.gray {
  background-color: #787c7e;
  color: white;
}

.tile.new-guess.green, .tile.new-guess.yellow, .tile.new-guess.gray {
  animation: popUp 0.6s ease-in-out forwards;
}

.tile.new-guess span {
  animation: textFadeIn 0.6s ease-in-out forwards;
}

.tile.gray.era-arrow::after {
  content: attr(data-arrow);
  position: absolute;
  font-size: 10px;
  color: var(--accent-gold);
  font-weight: 600;
  top: 50%;
  left: 80%;
  transform: translateY(-50%);
}

.tile.placeholder {
  background-color: #e0e0e0;
  border: 2px dashed var(--tile-border);
  color: transparent;
  transition: none;
}

@keyframes popUp {
  0% { transform: scale(0.5); opacity: 0; }
  80% { transform: scale(1.1); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes textFadeIn {
  0% { opacity: 0; }
  100% { opacity: 1; }
}

.input-container {
  display: flex;
  gap: 20px;
  justify-content: center;
  margin-bottom: 25px;
  flex-wrap: wrap;
}

.input-wrapper {
  position: relative;
}

#guess-input {
  padding: 14px;
  font-size: 18px;
  width: 280px;
  background-color: var(--white);
  color: var(--text-color);
  border: 2px solid var(--primary-blue);
  border-radius: 10px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

body.dark-mode #guess-input {
  background-color: #2c2c2c; /* Darker input background */
  color: #E0E0E0;
}

#guess-input:focus {
  outline: none;
  border-color: var(--accent-gold);
  box-shadow: 0 0 8px rgba(255, 215, 0, 0.3);
}

.suggestions {
  position: absolute;
  top: calc(100% + 5px); /* Moved below input */
  left: 0;
  right: 0;
  background-color: var(--suggestions-bg);
  border: 1px solid var(--suggestions-border);
  border-radius: 10px;
  max-height: 160px;
  overflow-y: auto;
  z-index: 1000;
  display: none;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.2);
}

.suggestion-item {
  padding: 12px;
  cursor: pointer;
  color: var(--text-color);
  font-size: 16px;
  transition: background-color 0.2s ease;
}

.suggestion-item:hover {
  background-color: var(--primary-blue);
  color: var(--white);
}

#submit-guess, #share-button {
  padding: 14px 35px;
  background-color: var(--primary-blue);
  color: var(--white);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-family: 'Poppins', sans-serif;
  font-size: 18px;
  font-weight: 600;
  transition: transform 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease;
}

#submit-guess:hover, #share-button:hover {
  background-color: var(--button-hover);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

#message {
  font-weight: 500;
  margin: 20px 0;
  color: var(--primary-blue);
  font-size: 18px;
}

#share-container {
  display: flex;
  gap: 20px;
  justify-content: center;
  flex-wrap: wrap;
}

.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.6);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
}

.modal-content {
  background-color: var(--container-bg);
  padding: 20px; /* Reduced for mobile */
  border-radius: 15px;
  text-align: center;
  max-width: 90%;
  width: 90%;
  max-height: 80vh; /* Increased for more content space */
  overflow-y: auto;
  animation: slideIn 0.4s ease;
  position: relative;
}

.modal-content.profile-card {
  background: linear-gradient(135deg, var(--white) 0%, #f8f9fa 100%);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.15);
  border: 2px solid var(--primary-blue);
  border-radius: 20px;
  padding: 25px;
  position: relative;
  overflow: hidden;
}

.modal-content.profile-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: url('/images/owl-logo.png'); /* Updated path */
  background-repeat: no-repeat;
  background-position: center;
  background-size: 50%;
  opacity: 0.1;
  pointer-events: none;
}

.modal-content.profile-card h2 {
  color: var(--primary-blue);
  font-size: 2.2em;
  font-weight: 700;
  margin-bottom: 15px;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.1);
}

.modal-content.profile-card #player-profile-image {
  width: 150px;
  height: 150px;
  border-radius: 10px;
  margin: 0 auto 15px;
  display: block;
  object-fit: cover;
  border: 2px solid var(--primary-blue);
}

.modal-content.profile-card p {
  font-size: 16px;
  margin-bottom: 20px;
  color: var(--text-color);
}

.modal-content.profile-card #player-profile-fact {
  font-style: italic;
  color: #333;
  line-height: 1.5;
}

.modal-content::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(45deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.1));
  opacity: 0.3;
  pointer-events: none;
}

.modal-content h2 {
  color: var(--primary-blue);
  margin-bottom: 25px;
  font-size: 2em;
}

.modal-content p, .modal-content ul, #community-stats-info {
  font-size: 16px;
  margin-bottom: 25px;
  text-align: left;
  color: var(--text-color);
}

#community-stats-info {
  margin-bottom: 10px;
  text-align: center;
}

.modal-content ul {
  padding-left: 25px;
}

.modal-content ul li {
  margin-bottom: 10px;
}

.modal-content .example-row {
  margin: 20px 0;
}

.modal-content button {
  padding: 14px 35px;
  margin: 10px;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-family: 'Poppins', sans-serif;
  font-size: 18px;
  font-weight: 600;
  transition: transform 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease;
}

.congrats-modal-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

#share-modal-button, #view-profile-modal-button, #play-again, #close-congrats {
  padding: 12px 24px;
  width: 160px; /* Uniform width */
  font-size: 16px;
  margin: 10px;
}

#share-modal-button, #close-congrats, #close-how-to-play, #close-stats, #close-archive, #close-profile {
  background-color: var(--accent-gold);
  color: var(--primary-blue);
}

#close-how-to-play {
  position: sticky;
  bottom: 10px;
  margin-top: 20px;
  z-index: 10;
}

#close-profile, #close-congrats {
  border: 2px solid var(--primary-blue);
  background: linear-gradient(135deg, var(--accent-gold) 0%, #FFC107 100%);
}

#share-modal-button:hover, #close-how-to-play:hover, #close-stats:hover, #close-archive:hover, #close-profile:hover, #close-congrats:hover {
  background: linear-gradient(135deg, #FFC107 0%, #FFA500 100%);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

#play-again {
  background-color: var(--primary-blue);
  color: var(--white);
}

#play-again:hover {
  background-color: var(--button-hover);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

#community-stats {
  margin-top: 20px; /* Separate from buttons */
  border-top: 1px solid var(--suggestions-border); /* Visual divider */
  padding-top: 15px;
}

#archive-list {
  max-height: 300px;
  overflow-y: auto;
  text-align: left;
}

.archive-item {
  padding: 10px;
  cursor: pointer;
  font-size: 16px;
  color: var(--text-color);
  border-bottom: 1px solid var(--suggestions-border);
  transition: background-color 0.2s ease;
}

.archive-item:hover {
  background-color: var(--primary-blue);
  color: var(--white);
}

#guess-distribution, #community-stats {
  margin: 20px 0;
}

.distribution-bar, .community-stats-bar {
  display: flex;
  align-items: center;
  margin: 8px 0;
}

.distribution-label, .community-stats-label {
  width: 80px;
  text-align: right;
  margin-right: 10px;
  font-size: 14px;
  color: var(--text-color);
}

.distribution-bar-fill, .community-stats-bar-fill {
  height: 20px;
  background-color: var(--primary-blue);
  border-radius: 5px;
  transition: width 0.3s ease;
  position: relative;
  min-width: 20px;
}

.community-stats-bar-fill::after {
  content: attr(data-percentage);
  position: absolute;
  right: 5px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--white);
  font-size: 10px;
  font-weight: 500;
}

@keyframes slideIn {
  from { transform: translateY(-50px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@media (max-width: 600px) {
  .wrapper {
    padding: 10px;
  }

  .container {
    padding: 15px;
  }

  .header {
    flex-direction: column;
    gap: 20px;
    align-items: center;
  }

  .header-buttons {
    gap: 8px; /* Tighter spacing */
    justify-content: center;
    flex-direction: row;
    flex-wrap: wrap;
  }

  h1 {
    font-size: 2em;
  }

  .category-title {
    width: 60px;
    font-size: 10px;
    height: 40px;
    padding: 5px;
  }

  .category-row .category-title:first-child {
    width: 90px; /* Wider for Player Name on mobile */
    font-size: 10px;
    white-space: normal;
    text-overflow: clip;
  }

  .tile {
    width: 60px;
    height: 40px;
    font-size: 10px;
    padding: 5px;
    visibility: visible;
  }

  .row .tile:first-child {
    width: 90px; /* Wider for Player Name on mobile */
    font-size: 10px;
    white-space: normal;
    text-overflow: clip;
  }

  .tile.gray.era-arrow::after {
    font-size: 8px;
    left: 80%;
  }

  .tile.placeholder {
    width: 60px;
    height: 40px;
  }

  .row .tile.placeholder:first-child {
    width: 90px; /* Match Player Name width */
  }

  #guess-input {
    width: 200px;
    font-size: 14px;
    padding: 10px;
  }

  .suggestions {
    width: 200px;
    top: calc(100% + 5px); /* Ensure below input */
    right: auto; /* Prevent overflow */
  }

  .suggestion-item {
    font-size: 14px;
    padding: 8px;
  }

  #submit-guess, #share-button, #view-profile-button {
    padding: 8px 16px; /* Smaller buttons */
    font-size: 14px;
  }

  #share-modal-button, #view-profile-modal-button, #play-again, #close-congrats {
    padding: 8px 16px;
    width: 120px; /* Uniform width for mobile */
    font-size: 14px;
    margin: 5px;
  }

  #timer {
    font-size: 14px;
    margin-top: 15px;
  }

  #message {
    font-size: 14px;
  }

  .modal-content {
    padding: 15px;
    max-height: 85vh; /* More space for content */
  }

  .modal-content.profile-card {
    padding: 15px;
  }

  .modal-content.profile-card #player-profile-image {
    width: 100px;
    height: 100px;
    margin: 0 auto 10px;
  }

  .modal-content h2 {
    font-size: 1.5em;
  }

  .modal-content p, .modal-content ul, #community-stats-info {
    font-size: 14px;
  }

  #community-stats {
    margin-top: 15px; /* Smaller margin for mobile */
    padding-top: 10px;
  }

  .distribution-label, .community-stats-label {
    width: 60px;
    font-size: 12px;
  }

  .distribution-bar-fill, .community-stats-bar-fill {
    height: 15px;
  }

  .community-stats-bar-fill::after {
    font-size: 8px;
  }
}

@media (max-width: 400px) {
  .category-title {
    width: 50px;
    font-size: 9px;
    height: 35px;
  }

  .category-row .category-title:first-child {
    width: 80px; /* Wider for Player Name on very small screens */
    font-size: 9px;
    white-space: normal;
    text-overflow: clip;
  }

  .tile {
    width: 50px;
    height: 35px;
    font-size: 8px; /* Smaller font for very small screens */
    visibility: visible;
  }

  .row .tile:first-child {
    width: 80px; /* Wider for Player Name on very small screens */
    font-size: 8px;
    white-space: normal;
    text-overflow: clip;
  }

  .tile.gray.era-arrow::after {
    font-size: 8px;
    left: 80%;
  }

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

  .row .tile.placeholder:first-child {
    width: 80px; /* Match Player Name width */
  }

  #guess-input {
    width: 160px;
  }

  .suggestions {
    width: 160px;
  }

  #share-modal-button, #view-profile-modal-button, #play-again, #close-congrats {
    padding: 6px 12px;
    width: 100px; /* Smaller uniform width */
    font-size: 12px;
  }

  #timer {
    font-size: 12px;
    margin-top: 10px;
  }

  #community-stats {
    margin-top: 10px;
    padding-top: 8px;
  }
}