* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: "Clear Sans", "Helvetica Neue", Arial, sans-serif;
  background-color: #121213;
  color: #d7dadc;
  min-height: 100vh;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 8px;
}

header {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  max-width: 500px;
  padding: 20px 0;
  border-bottom: 1px solid #3a3a3c;
}

.visually-hidden {
  position: absolute;
  left: -9999px;
}

header h1 {
  margin: 0 auto;
  font-size: 32px;
  font-weight: 700;
  letter-spacing: 0.05em;
}

#username-modal p {
  padding: 5px 10px;
  margin: 5px 0;
}

#username-modal p span.highlight {
  font-weight: bold;
  color: #d32f2f; /* red accent for important words */
}

#username-modal p span.fun {
  color: #388e3c; /* green for fun stuff */
}

#username-btn {
  position: absolute;
  left: 0;
}

#help-btn {
  position: absolute;
  right: 0;
}

#stats-btn {
  position: absolute;
  right: 40px;
}

/* Prevent double-tap zoom on interactive elements */
button,
.key,
#keyboard {
  touch-action: manipulation;
}

.icon-button {
  background: none;
  border: none;
  color: #d7dadc;
  cursor: pointer;
  padding: 8px;
  font-size: 16px;
  transition: transform 0.2s;
}

.icon-button:focus {
  outline: none;
}
.icon-button:hover {
  transform: scale(1.1);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}
.icon-button:active {
  transform: scale(0.95);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

#game-board {
  display: grid;
  grid-template-rows: repeat(6, 1fr);
  gap: 5px;
  padding: 0;
  transition: box-shadow 0.2s ease-in-out;
}

#game-board:focus {
  outline: none;
}

.tile-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 5px;
}

.tile {
  width: 62px;
  height: 62px;
  border: 2px solid #3a3a3c;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 32px;
  font-weight: bold;
  text-transform: uppercase;
  transition: all 0.2s ease;
}

.tile.filled {
  animation: pop 0.1s ease;
  border-color: #565758;
}

.tile.reveal {
  animation: flip 0.5s ease;
}

.tile.correct {
  background-color: #538d4e;
  border-color: #538d4e;
}

.tile.present {
  background-color: #b59f3b;
  border-color: #b59f3b;
}

.tile.absent {
  background-color: #3a3a3c;
  border-color: #3a3a3c;
}

@keyframes pop {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.1);
  }
}

@keyframes flip {
  0% {
    transform: rotateX(0);
  }
  50% {
    transform: rotateX(90deg);
  }
  100% {
    transform: rotateX(0);
  }
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  10%,
  30%,
  50%,
  70%,
  90% {
    transform: translateX(-5px);
  }
  20%,
  40%,
  60%,
  80% {
    transform: translateX(5px);
  }
}

.shake {
  animation: shake 0.5s ease;
}

#keyboard {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-top: auto;
  padding: 20px 0;
  width: 100%;
  max-width: 500px;
}

.keyboard-row {
  display: flex;
  gap: 6px;
  justify-content: center;
}

.key {
  background-color: #818384;
  border: none;
  border-radius: 4px;
  color: #d7dadc;
  cursor: pointer;
  font-size: 14px;
  font-weight: bold;
  height: 58px;
  padding: 0;
  text-transform: uppercase;
  transition: all 0.2s;
  min-width: 30px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.key:hover {
  background-color: #818384;
  transform: scale(1.05);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}

.key:active {
  transform: scale(0.95);
}

.key.wide {
  min-width: 65px;
  font-size: 12px;
}

.key.correct {
  background-color: #538d4e;
}

.key.present {
  background-color: #b59f3b;
}

.key.absent {
  background-color: #3a3a3c;
}

#message-container {
  position: fixed;
  top: 20%;
  left: 50%;
  transform: translateX(-50%);
  background-color: #121213;
  border: 2px solid #d7dadc;
  border-radius: 8px;
  padding: 16px 24px;
  font-size: 16px;
  font-weight: bold;
  opacity: 0;
  transition: opacity 0.3s;
  z-index: 1000;
}

#message-container.show {
  opacity: 1;
}

#message-container.error {
  background: #8b0000;
  color: #fff;
}

.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.8);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 2000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

.modal.show {
  opacity: 1;
  pointer-events: all;
}

.modal-content {
  background-color: #121213;
  border: 1px solid #3a3a3c;
  border-radius: 8px;
  padding: 24px;
  max-width: 400px;
  width: 90%;
  text-align: center;
}

.modal-content h2 {
  margin-bottom: 16px;
  font-size: 24px;
}

.modal-content p {
  margin-bottom: 8px;
  line-height: 1.4;
}

.modal-content button {
  background-color: #538d4e;
  border: none;
  border-radius: 4px;
  color: white;
  cursor: pointer;
  font-size: 16px;
  font-weight: bold;
  padding: 12px 24px;
  margin-top: 16px;
  transition: transform 0.2s;
}

.modal-content button:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}
.modal-content button:active {
  transform: scale(0.95);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin: 20px 0;
}

.stat-item {
  text-align: center;
}

.stat-number {
  font-size: 32px;
  font-weight: bold;
  display: block;
}

.stat-label {
  font-size: 12px;
  text-transform: uppercase;
  color: #818384;
}
.select-wrapper {
  margin-top: 10px;
  position: relative;
  display: inline-block;
  width: 200px;
}
.select-label {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: #000000;
  pointer-events: none;
  transition: 0.2s ease all;
  background-color: #565758;
  padding: 0 4px;
  font-size: 16px;
}
#language-select {
  width: 100%;
  padding: 8px 35px 8px 10px;
  border: 1px solid #565758;
  border-radius: 5px;
  background-color: #565758;
  color: #000;
  -webkit-text-fill-color: #000;
  font-size: 16px;
  cursor: pointer;

  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}

#language-select:focus {
  outline: none;
  border-color: #565758;
  color: #000;
  -webkit-text-fill-color: #000;
}
.select-wrapper::after {
  content: "▼";
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  color: #000;
  font-size: 0.7em;
}
#language-select:not([value=""]) + .select-label,
#language-select:focus + .select-label {
  top: -8px;
  font-size: 12px;
  color: #d7dadc;
}

#tip-btn {
  background: linear-gradient(135deg, #f7931a, #ffae42);
  border: none;
  color: #fff;
  padding: 12px 20px;
  font-size: 16px;
  border-radius: 4px;
  cursor: pointer;
  display: none;
  transition: transform 0.2s, box-shadow 0.2s;
  animation: tipPulse 2s infinite ease-in-out;
  font-weight: bold;
  box-shadow: 0 0 12px rgba(255, 170, 50, 0.6);
  margin: 5px;
  margin-right: 15px;
}

#tip-btn::hover {
  transform: scale(1.08);
  box-shadow: 0 0 18px rgba(255, 170, 50, 0.9);
}

.leaderboard-row.current-player {
  color: rgba(255, 170, 50, 0.9);
  font-weight: bold;
}

#username-input {
  font-size: 16px;
  margin: 5px;
}

#leaderboard {
  margin-top: 5px;
}

/* Leaderboard container */
.leaderboard {
  width: 100%;
  margin-top: 10px;
  border-top: 1px solid #3a3a3c;
  padding-top: 8px;
  font-size: 14px;
  max-height: 260px;
  overflow-y: auto;
}

/* Header */
.leaderboard h3 {
  text-align: center;
  margin-bottom: 10px;
  font-size: 18px;
  letter-spacing: 0.04em;
}

/* Rows */
.leaderboard-row {
  display: grid;
  grid-template-columns: 32px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 6px 4px;
  border-bottom: 1px solid #2a2a2c;
}

/* Rank number */
.leaderboard-rank {
  color: #818384;
  font-weight: bold;
  text-align: left;
}

/* Username */
.leaderboard-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: left;
}

/* Stats */
.leaderboard-stats {
  color: #818384;
  font-size: 12px;
  text-align: right;
}

.leaderboard-stats::before {
  content: "";
}

/* Highlight current player */
.leaderboard-row.current-player {
  background-color: rgba(255, 170, 50, 0.08);
  border-radius: 4px;
  color: rgba(255, 170, 50, 0.95);
  font-weight: bold;
}

.leaderboard-header {
  display: grid;
  grid-template-columns: 32px 1fr auto;
  gap: 8px;
  padding: 6px 4px;
  margin-bottom: 4px;
  font-size: 12px;
  color: #818384;
  border-bottom: 1px solid #3a3a3c;
}

.leaderboard-number {
  text-align: left;
}

.leaderboard-stats-header {
  text-align: right;
}

.leaderboard-stats {
  text-align: center;
}

#qr-status {
    margin-top: 8px;
}

@keyframes tipPulse {
  0% {
    transform: scale(1);
    box-shadow: 0 0 10px rgba(255, 170, 50, 0.6);
  }
  50% {
    transform: scale(1.1);
    box-shadow: 0 0 20px rgba(255, 170, 50, 1);
  }
  100% {
    transform: scale(1);
    box-shadow: 0 0 10px rgba(255, 170, 50, 0.6);
  }
}

@media (max-width: 500px) {
  header {
    padding: 8px;
  }
  .tile {
    width: 42px;
    height: 42px;
    font-size: 24px;
  }
  #game-board {
    padding-top: 0;
  }
  .key {
    height: 44px;
    min-width: 28px;
    font-size: 12px;
  }
  #keyboard {
    gap: 4px;
    padding-top: 0;
    padding-bottom: 10px;
  }
  .keyboard-row {
    gap: 4px;
  }
  .key.wide {
    min-width: 50px;
    font-size: 10px;
  }
  #help-modal p {
    font-size: 12px;
  }
  #help-modal h2 {
    font-size: 10px;
  }
  #help-modal .tile {
    width: 20px;
    height: 20px;
    font-size: 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}
