:root {
  --bg: #f8f9fa;
  --card: #ffffff;
  --accent: #4dabf7;
  --muted: #6c757d;
  --text: #212529;
  --border: #dee2e6;
}

* {
  box-sizing: border-box
}

html,
body {
  height: 100%;
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, 'Helvetica Neue', Arial;
  background: var(--bg);
  color: var(--text)
}

.wrap {
  max-width: 900px;
  margin: 24px auto;
  padding: 16px
}

.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.game-title {
  margin: 0;
  height: auto;
  border-radius: 12px;
  max-width: 300px;
  width: auto;
}

.hud,
.controls {
  display: flex;
  gap: 16px;
  align-items: center;
}

.controls {
  justify-content: flex-start;
}

.hud {
  flex-direction: column;
  gap: 8px;
  align-items: flex-end;
}

.hud-item {
  background: var(--card);
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  text-align: center;
  min-width: 80px
}

.hud-item .label {
  font-size: 0.8rem;
  color: var(--muted);
  display: block
}

.hud-item .value {
  font-size: 1.8rem;
  font-weight: bold;
  color: var(--accent);
  display: block;
  line-height: 1;
}

.game-board-wrap {
  position: relative;
  background: transparent;
  border-radius: 12px;
  padding: 8px
}

#word-rings-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  /* Allow clicks to pass through to tiles */
}

#game-board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-gap: 2px;
  aspect-ratio: 1;
  width: 90vmin;
  max-width: 500px;
  margin: 0 auto
}

.tile {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  user-select: none;
  transition: transform 0.2s, background 0.2s, top 0.5s ease-out
}

.tile .letter {
  font-size: clamp(1.5rem, 5vw, 2.5rem);
  font-weight: bold
}

.tile .value {
  position: absolute;
  bottom: 4px;
  right: 6px;
  font-size: clamp(0.7rem, 2vw, 0.9rem);
  font-weight: bold;
  color: var(--muted)
}

.tile.selected {
  background: var(--accent);
  color: white;
  animation: pulse 0.5s 1
}

.tile.found-placed-word {
  background: #28a745;
  /* Green */
  color: white;
}

.tile.found-bonus-word {
  background: #007bff;
  /* Blue */
  color: white;
}

.tile.found-bonus-word.flash {
  animation: bonus-flash 0.3s ease-in-out;
}

@keyframes bonus-flash {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.5;
  }
}

.tile.hint-highlight {
  background: #28a745;
  color: white;
}

.tile.shake {
  animation: shake 0.5s;
}

.tile.empty {
  background: transparent;
  border-color: transparent;
  cursor: default;
}

#placed-words-display {
  margin-top: 20px;
  padding: 10px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
}

#placed-words-display h3 {
  margin-top: 0;
  color: var(--text);
  text-align: center;
  margin-bottom: 15px;
}

.word-list-columns {
  display: flex;
  flex-wrap: wrap;
  /* Allow columns to wrap on smaller screens */
  justify-content: center;
  gap: 10px;
  /* Space between columns */
}

.word-list-column {
  flex: 1;
  /* Allow columns to grow and shrink */
  min-width: 100px;
  /* Minimum width for a column */
  max-width: 150px;
  /* Maximum width for a column */
  padding: 5px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--bg);
  text-align: center;
}

.word-list-column h4 {
  margin-top: 0;
  margin-bottom: 8px;
  color: var(--accent);
  font-size: 1rem;
  white-space: nowrap;
  /* Prevent heading from wrapping */
}

.word-list-column ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  /* Stack words vertically within a column */
  gap: 3px;
  /* Space between words */
}

.word-list-column li {
  background: var(--card);
  padding: 3px 5px;
  border-radius: 3px;
  border: 1px solid var(--border);
  color: var(--text);
  font-family: 'Courier New', Courier, monospace;
  font-weight: bold;
  text-align: left;
  /* Align text to the left within the list item */
  display: flex;
  align-items: center;
  justify-content: flex-start;
  /* Align content to the start */
  font-size: 0.9em;
  /* Slightly smaller font for compactness */
  white-space: nowrap;
  /* Prevent words from wrapping */
}

.hint-button-container {
  display: flex;
  justify-content: center;
  margin-top: 20px;
  /* Add some space above the button */
  gap: 10px;
  /* Space between the hint and rules buttons */
}

#placed-words-display li .found-checkmark {
  color: #28a745;
  margin-right: 5px;
  font-weight: bolder;
  font-size: 1.1em;
}

#placed-words-display li.found-word-debug {
  color: var(--text);
  background: #e9ecef;
  text-decoration: none;
}

@keyframes pulse {
  0% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.1);
  }

  100% {
    transform: scale(1);
  }
}

@keyframes shake {
  0% {
    transform: translate(1px, 1px) rotate(0deg);
  }

  10% {
    transform: translate(-1px, -2px) rotate(-1deg);
  }

  20% {
    transform: translate(-3px, 0px) rotate(1deg);
  }

  30% {
    transform: translate(3px, 2px) rotate(0deg);
  }

  40% {
    transform: translate(1px, -1px) rotate(1deg);
  }

  50% {
    transform: translate(-1px, 2px) rotate(-1deg);
  }

  60% {
    transform: translate(-3px, 1px) rotate(0deg);
  }

  70% {
    transform: translate(3px, 1px) rotate(-1deg);
  }

  80% {
    transform: translate(-1px, -1px) rotate(1deg);
  }

  90% {
    transform: translate(1px, 2px) rotate(0deg);
  }

  100% {
    transform: translate(1px, -2px) rotate(-1deg);
  }
}

button.hud-item {
  background: #5a6268;
}

/* Rules Popup Specific Styles */
.rules-popup {
  background: var(--card);
  padding: 30px;
  border-radius: 15px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
  text-align: center;
  max-width: 80%;
  font-family: 'Comic Sans MS', cursive, sans-serif;
  color: var(--text);
}

.rules-popup h2 {
  font-size: 2.5rem;
  color: var(--accent);
  margin-bottom: 15px;
}

.rules-popup .rules-content {
  text-align: left;
  margin-bottom: 20px;
  max-height: 60vh;
  /* Limit height for scrollability */
  overflow-y: auto;
  /* Enable scrolling for long rules */
  padding-right: 10px;
  /* Space for scrollbar */
}

.rules-popup .rules-content p,
.rules-popup .rules-content ul {
  border-radius: 15px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
  text-align: center;
  max-width: 80%;
  font-family: 'Comic Sans MS', cursive, sans-serif;
  /* Example fun font */
  color: var(--text);
}

.start-game-popup h2 {
  font-size: 2.5rem;
  color: var(--accent);
  margin-bottom: 15px;
}

.start-game-popup p {
  font-size: 1.2rem;
  margin-bottom: 20px;
}

/* Level Details Popup Styles */
.level-details-popup {
  background: var(--card);
  padding: 30px;
  border-radius: 15px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
  text-align: center;
  max-width: 80%;
  font-family: 'Comic Sans MS', cursive, sans-serif;
  color: var(--text);
}

.level-details-popup h2 {
  font-size: 2.5rem;
  color: var(--accent);
  margin-bottom: 15px;
}

.level-details-popup #level-details-content {
  text-align: left;
  margin-bottom: 20px;
}

.level-details-popup #level-details-content p {
  font-size: 1.1rem;
  line-height: 1.6;
  margin-bottom: 10px;
}

.level-details-popup #level-details-content ul {
  list-style-type: none;
  padding: 0;
  margin-left: 20px;
}

.level-details-popup #level-details-content li {
  margin-bottom: 5px;
}

.level-details-buttons {
  display: flex;
  justify-content: center;
  gap: 20px;
}

.level-failed-popup {
  background: var(--card);
  padding: 30px;
  border-radius: 15px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
  text-align: center;
  max-width: 80%;
  font-family: 'Comic Sans MS', cursive, sans-serif;
  color: var(--text);
}

.bonus-time-popup {
  position: absolute;
  font-size: 1.5rem;
  font-weight: bold;
  color: #28a745;
  /* Green */
  pointer-events: none;
  z-index: 1100;
}

.level-failed-popup h2 {
  font-size: 2.5rem;
  color: #dc3545;
  /* Red for failure */
  margin-bottom: 15px;
}

.level-failed-popup p {
  font-size: 1.2rem;
  margin-bottom: 20px;
}



#timer-display {
  text-align: center;
  font-size: 1.2rem;
  font-weight: bold;
  color: var(--muted);
  margin-top: 5px;
}

@media (max-width:520px) {
  .wrap {
    padding: 8px;
    margin: 12px auto;
  }

  .game-header {
    flex-wrap: wrap;
    justify-content: center;
  }

  .hud,
  .controls {
    gap: 8px;
    width: 100%;
    justify-content: center;
  }

  .hud-item {
    padding: 6px 10px;
    min-width: 70px;
  }

  .hud-item .label {
    font-size: 0.7rem;
  }

  .hud-item .value {
    font-size: 1.5rem;
  }

  #game-board {
    grid-gap: 1px;
  }

  .tile .value {
    bottom: 2px;
    right: 3px;
  }
}

/* Splash Screen Styles */
#splash-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: #000;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 2000;
}

.splash-image {
  max-width: 80%;
  max-height: 60%;
  object-fit: contain;
}

.menu-button {
  padding: 15px 30px;
  font-size: 1.5rem;
  font-weight: bold;
  color: white;
  background-color: #0056b3;
  border: 2px solid white;
  border-radius: 10px;
  cursor: pointer;
  transition: background-color 0.3s;
  opacity: 1;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.5);
  margin-top: 10px;
}

.menu-button:hover {
  background-color: #357ABD;
}

#start-app-button {
  /* Inherits from .menu-button */
}

/* Saga Map Styles */
#saga-map-screen {
  max-width: 900px;
  margin: 0 auto;
  padding: 20px;
  text-align: center;
}

#saga-map-screen h1 {
  font-size: 2.5rem;
  color: var(--accent);
  margin-bottom: 20px;
}

#saga-map-container {
  position: relative;
  width: 100%;
  max-width: 500px;
  /* Max width for the map on larger screens */
  margin: 0 auto;
  /* Center the map container */
  aspect-ratio: 1 / 1.5;
  /* Portrait aspect ratio, adjust as needed */
  background-image: url('../img/crossword_panic_map.png');
  background-size: cover;
  background-position: center;
  border-radius: 15px;
  overflow: hidden;
}

.level-node {
  position: absolute;
  width: 10vw;
  /* Responsive size */
  height: 10vw;
  /* Responsive size */
  max-width: 50px;
  /* Max size for nodes */
  max-height: 50px;
  /* Max size for nodes */
  background-color: var(--card);
  border: 3px solid var(--accent);
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 1.2rem;
  font-weight: bold;
  color: var(--text);
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  transform: translate(-50%, -50%);
}

}

.level-details-popup #level-details-content li {
  margin-bottom: 5px;
}

.level-details-buttons {
  display: flex;
  justify-content: center;
  gap: 20px;
}

.level-failed-popup {
  background: var(--card);
  padding: 30px;
  border-radius: 15px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
  text-align: center;
  max-width: 80%;
  font-family: 'Comic Sans MS', cursive, sans-serif;
  color: var(--text);
}

.bonus-time-popup {
  position: absolute;
  font-size: 1.5rem;
  font-weight: bold;
  color: #28a745;
  /* Green */
  pointer-events: none;
  z-index: 1100;
}

.level-failed-popup h2 {
  font-size: 2.5rem;
  color: #dc3545;
  /* Red for failure */
  margin-bottom: 15px;
}

.level-failed-popup p {
  font-size: 1.2rem;
  margin-bottom: 20px;
}



#timer-display {
  text-align: center;
  font-size: 1.2rem;
  font-weight: bold;
  color: var(--muted);
  margin-top: 5px;
}

@media (max-width:520px) {
  .wrap {
    padding: 8px;
    margin: 12px auto;
  }

  .game-header {
    flex-wrap: wrap;
    justify-content: center;
  }

  .hud,
  .controls {
    gap: 8px;
    width: 100%;
    justify-content: center;
  }

  .hud-item {
    padding: 6px 10px;
    min-width: 70px;
  }

  .hud-item .label {
    font-size: 0.7rem;
  }

  .hud-item .value {
    font-size: 1.5rem;
  }

  #game-board {
    grid-gap: 1px;
  }

  .tile .value {
    bottom: 2px;
    right: 3px;
  }
}

/* Splash Screen Styles */
#splash-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: #000;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 2000;
}

.splash-image {
  max-width: 80%;
  max-height: 60%;
  object-fit: contain;
}

.menu-button {
  padding: 15px 30px;
  font-size: 1.5rem;
  font-weight: bold;
  color: white;
  background-color: #0056b3;
  border: 2px solid white;
  border-radius: 10px;
  cursor: pointer;
  transition: background-color 0.3s;
  opacity: 1;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.5);
  margin-top: 10px;
}

.menu-button:hover {
  background-color: #357ABD;
}

#start-app-button {
  /* Inherits from .menu-button */
}

/* Saga Map Styles */
#saga-map-screen {
  max-width: 900px;
  margin: 0 auto;
  padding: 20px;
  text-align: center;
}

#saga-map-screen h1 {
  font-size: 2.5rem;
  color: var(--accent);
  margin-bottom: 20px;
}

#saga-map-container {
  position: relative;
  width: 100%;
  max-width: 500px;
  /* Max width for the map on larger screens */
  margin: 0 auto;
  /* Center the map container */
  aspect-ratio: 1 / 1.5;
  /* Portrait aspect ratio, adjust as needed */
  background-image: url('../img/crossword_panic_map.png');
  background-size: cover;
  background-position: center;
  border-radius: 15px;
  overflow: hidden;
}

.level-node {
  position: absolute;
  width: 10vw;
  /* Responsive size */
  height: 10vw;
  /* Responsive size */
  max-width: 50px;
  /* Max size for nodes */
  max-height: 50px;
  /* Max size for nodes */
  background-color: var(--card);
  border: 3px solid var(--accent);
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 1.2rem;
  font-weight: bold;
  color: var(--text);
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  transform: translate(-50%, -50%);
}

.level-node:hover {
  transform: translate(-50%, -50%) scale(1.1);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2);
}

.level-node.unlocked {
  background-color: #ffd700;
  /* Gold for unlocked */
  border-color: #ffc107;
}

.level-node.completed {
  background-color: #28a745;
  /* Green for completed */
  border-color: #218838;
  color: white;
}

.level-node.hard {
  border-color: #dc3545;
  /* Red border for hard levels */
  animation: pulse-red 2s infinite;
}

.level-node.easy {
  border-color: #17a2b8;
  /* Cyan border for easy levels */
}

@keyframes pulse-red {
  0% {
    box-shadow: 0 0 0 0 rgba(220, 53, 69, 0.7);
  }

  70% {
    box-shadow: 0 0 0 10px rgba(220, 53, 69, 0);
  }

  100% {
    box-shadow: 0 0 0 0 rgba(220, 53, 69, 0);
  }
}

#map-path {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* Username Popup Styles */
#username-overlay {
  z-index: 2005;
  background-color: rgba(0, 0, 0, 0.85);
}

.username-popup {
  background: var(--card);
  background-color: #ffffff;
  padding: 30px;
  border-radius: 15px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
  text-align: center;
  max-width: 80%;
  font-family: 'Comic Sans MS', cursive, sans-serif;
  color: var(--text);
  min-width: 300px;
  opacity: 1;
}

.username-popup h2 {
  font-size: 2.5rem;
  color: var(--accent);
  margin-bottom: 15px;
}

.username-popup input {
  font-size: 1.2rem;
  padding: 10px;
  border-radius: 5px;
  border: 1px solid var(--border);
  margin-bottom: 15px;
  width: 80%;
}