html {
  overflow-x: hidden;
  box-sizing: border-box;
  scrollbar-width: none;
}

*, *::before, *::after {
  box-sizing: inherit;
}

body {
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 0;
  padding: 20px;
  background: linear-gradient(135deg, #0d2818 0%, #1a3d2e 50%, #0a1f14 100%);
  background-attachment: fixed;
  min-height: 100vh;
  color: #e0e6ed;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
  -ms-overflow-style: none;
  padding-bottom: 30vh;
}

::-webkit-scrollbar {
  display: none;
  width: 0;
  height: 0;
}

@keyframes modalFadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
@keyframes modalSlideIn {
  from {
    transform: translateY(-50px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}
@keyframes shimmer {
  0% {
    transform: translateX(-50%) translateY(-150%);
  }
  100% {
    transform: translateX(50%) translateY(150%);
  }
}
@keyframes flip {
  0% {
    transform: rotateY(0deg);
  }
  50% {
    transform: rotateY(90deg);
  }
  100% {
    transform: rotateY(0deg);
  }
}
.cell {
  transform-style: preserve-3d;
  perspective: 1000px;
  backface-visibility: hidden;
  transition: background-color 0.1s ease;
}
.cell.flipping {
  animation: flip 0.6s ease;
}

.cell.flipping {
  transition: none;
}
.cell.flipping.correct, .cell.flipping.present, .cell.flipping.absent {
  transition: none;
}

.header {
  text-align: center;
  margin-bottom: 30px;
  padding-top: 8px;
}

.subtitle {
  color: #b0bec5;
  margin: 5px 0 0 0;
  font-size: 1.1em;
}

.title-tiles {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  margin-bottom: 15px;
  flex-wrap: wrap;
}

.title-tile {
  width: 60px;
  height: 60px;
  background: linear-gradient(135deg, #f5f5dc 0%, #e6ddc4 100%);
  border: 2px solid #8b7355;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  position: relative;
  box-shadow: inset 0 2px 4px rgba(255, 255, 255, 0.6), inset 0 -2px 4px rgba(0, 0, 0, 0.1), 0 0 0 1px rgba(139, 115, 85, 0.6), 0 4px 0 rgba(105, 87, 64, 0.8), 0 6px 12px rgba(0, 0, 0, 0.3);
  transform: rotate(-2deg);
  transition: transform 0.3s ease;
  color: #2c1810;
}
.title-tile:nth-child(even) {
  transform: rotate(1deg);
}
.title-tile:nth-child(3n) {
  transform: rotate(-1deg);
}
.title-tile:hover {
  transform: rotate(0deg) scale(1.05);
}
.title-tile .letter {
  font-size: 32px;
  font-weight: bold;
  line-height: 1;
  margin-bottom: 2px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}
.title-tile .score {
  font-size: 12px;
  font-weight: bold;
  position: absolute;
  bottom: 4px;
  right: 6px;
  color: #2c1810;
}

.container {
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  min-width: 500px;
  max-width: 500px;
  border-radius: 16px;
  margin-block: 0px;
}

.game-container {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: center;
}

.game-info {
  text-align: center;
  padding: 15px;
  word-break: keep-all;
}
.game-info h3 {
  margin: 0;
  color: #ffffff;
  font-size: 1.2em;
}
.game-info p {
  margin: 5px 0 0 0;
  color: #b0bec5;
}
.game-info #timer-info {
  font-weight: bold;
  color: #b0bec5;
}
.game-info #timer-info.running {
  color: #4ade80;
}

.grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 20px;
  border-radius: 16px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.4);
  justify-content: center;
}

.row {
  display: grid;
  gap: 8px;
  justify-content: center;
  position: relative;
}
.row.cols-4 {
  grid-template-columns: repeat(4, 1fr);
}
.row.cols-5 {
  grid-template-columns: repeat(5, 1fr);
}
.row.cols-6 {
  grid-template-columns: repeat(6, 1fr);
}
.row.cols-7 {
  grid-template-columns: repeat(7, 1fr);
}

.row-container {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 15px;
  margin-bottom: 10px;
}

.row-score {
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #e0e6ed;
  height: 50px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: bold;
  min-width: 50px;
  text-align: center;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}
.row-score.submitted {
  background: rgba(102, 126, 234, 0.2);
  border-color: rgba(102, 126, 234, 0.4);
  color: #667eea;
}
.row-score:not(:empty) {
  background: rgba(16, 185, 129, 0.1);
  border-color: rgba(16, 185, 129, 0.3);
  color: #10b981;
}

#puzzle-controls {
  margin-top: 16px;
  display: flex;
  justify-content: center;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

#total-score {
  display: none;
  display: none;
  color: #10b981;
  font-weight: bold;
}

@media (max-width: 480px) {
  .random-puzzle-button {
    font-size: 0.8em;
    padding: 4px 12px;
  }
}
.cell {
  width: 50px;
  height: 50px;
  border: 2px dashed #4a5568;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: bold;
  text-transform: uppercase;
  background: rgba(255, 255, 255, 0.05);
  color: #e0e6ed;
  border-radius: 8px;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  position: relative;
  /* Prevent the user from highlighting the game tiles */
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}
.cell .letter {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
}
.cell .score {
  position: absolute;
  bottom: 4px;
  right: 3px;
  font-size: 10px;
  font-weight: normal;
  color: #a0aec0;
  line-height: 1;
}
.cell.filled {
  border: 2px solid #718096;
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
  box-shadow: inset 0 2px 4px rgba(255, 255, 255, 0.3), inset 0 -1px 2px rgba(0, 0, 0, 0.2), 0 0 0 1px rgba(113, 128, 150, 0.5), 0 4px 0 rgba(90, 103, 116, 0.8), 0 6px 8px rgba(0, 0, 0, 0.3);
  border-radius: 6px;
}
.cell.filled .score {
  color: rgba(255, 255, 255, 0.7);
}
.cell.correct {
  background: linear-gradient(135deg, #48bb78 0%, #38a169 100%);
  border: 2px solid #38a169;
  color: white;
  box-shadow: inset 0 2px 4px rgba(255, 255, 255, 0.4), inset 0 -1px 2px rgba(0, 0, 0, 0.3), 0 0 0 1px rgba(56, 161, 105, 0.6), 0 4px 0 rgba(20, 80, 50, 0.95), 0 6px 16px rgba(0, 0, 0, 0.5);
  border-radius: 8px;
}
.cell.correct .score {
  color: rgba(255, 255, 255, 0.7);
}
.cell.present {
  background: linear-gradient(135deg, #ed8936 0%, #dd6b20 100%);
  border: 2px solid #dd6b20;
  color: white;
  box-shadow: inset 0 2px 4px rgba(255, 255, 255, 0.4), inset 0 -1px 2px rgba(0, 0, 0, 0.3), 0 0 0 1px rgba(221, 107, 32, 0.6), 0 4px 0 rgba(120, 55, 15, 0.95), 0 6px 16px rgba(0, 0, 0, 0.5);
  border-radius: 8px;
}
.cell.present .score {
  color: rgba(255, 255, 255, 0.7);
}
.cell.absent {
  background: linear-gradient(135deg, #f5f5dc 0%, #e6ddc4 100%);
  border: 2px solid #8b7355;
  color: #2c1810;
  box-shadow: inset 0 2px 4px rgba(255, 255, 255, 0.4), inset 0 -1px 2px rgba(0, 0, 0, 0.3), 0 0 0 1px rgba(139, 115, 85, 0.6), 0 4px 0 rgba(105, 87, 64, 0.8), 0 6px 16px rgba(0, 0, 0, 0.5);
  border-radius: 8px;
  box-shadow: inset 0 2px 4px rgba(255, 255, 255, 0.6), inset 0 -2px 4px rgba(0, 0, 0, 0.1), 0 0 0 1px rgba(139, 115, 85, 0.6), 0 4px 0 rgba(105, 87, 64, 0.8), 0 6px 12px rgba(0, 0, 0, 0.3);
}
.cell.absent .score {
  color: #2c1810;
}
.cell.bonus {
  background: linear-gradient(135deg, #ffd700 0%, #ffb300 100%);
  border: 2px solid #cc8f00;
  color: #654321;
  box-shadow: inset 0 2px 4px rgba(255, 255, 255, 0.4), inset 0 -1px 2px rgba(0, 0, 0, 0.3), 0 0 0 1px rgba(204, 143, 0, 0.6), 0 4px 0 rgba(100, 70, 0, 0.95), 0 6px 16px rgba(0, 0, 0, 0.5);
  border-radius: 8px;
  border-radius: 6px;
  position: relative;
  overflow: hidden;
}
.cell.bonus::before {
  content: "";
  position: absolute;
  top: -200%;
  left: -200%;
  width: 500%;
  height: 500%;
  background: linear-gradient(-20deg, transparent 45%, transparent 49%, rgba(255, 255, 255, 0.4) 49.5%, rgba(255, 255, 255, 0.6) 50%, rgba(255, 255, 255, 0.4) 50.5%, transparent 51%, transparent 55%);
  opacity: 0;
  pointer-events: none;
  animation: none;
}
.cell.bonus.animating-shimmer::before {
  animation: shimmer 3s linear forwards;
  opacity: 1;
}
.cell.bonus .score {
  color: rgba(101, 67, 33, 0.9);
  font-weight: bold;
}
.cell.jitter-1 {
  transform: scale(1.05) rotate(0.5deg) translate(0.5px, -0.3px) !important;
}
.cell.jitter-2 {
  transform: scale(1.05) rotate(-0.7deg) translate(-0.4px, 0.6px) !important;
}
.cell.jitter-3 {
  transform: scale(1.05) rotate(0.3deg) translate(0.2px, 0.4px) !important;
}
.cell.jitter-4 {
  transform: scale(1.05) rotate(-0.4deg) translate(-0.6px, -0.2px) !important;
}
.cell.jitter-5 {
  transform: scale(1.05) rotate(0.6deg) translate(0.3px, 0.5px) !important;
}
.cell.jitter-6 {
  transform: scale(1.05) rotate(-0.2deg) translate(-0.3px, 0.2px) !important;
}
.cell.jitter-7 {
  transform: scale(1.05) rotate(0.8deg) translate(0.4px, -0.5px) !important;
}
.cell.jitter-8 {
  transform: scale(1.05) rotate(-0.5deg) translate(-0.2px, 0.3px) !important;
}
.cell.revealing {
  animation: revealTile 0.6s ease-out forwards;
  transform-origin: center;
  z-index: 10;
}
.cell.bonus-tile {
  background: linear-gradient(135deg, #ffd700 0%, #ffed4e 25%, #ffd700 50%, #ffb347 75%, #ffd700 100%);
  border: 2px solid #b8860b;
  color: #8b4513;
  box-shadow: inset 0 2px 4px rgba(255, 255, 255, 0.6), inset 0 -1px 2px rgba(0, 0, 0, 0.2), 0 0 0 1px rgba(184, 134, 11, 0.8), 0 4px 0 rgba(139, 69, 19, 0.8), 0 6px 12px rgba(0, 0, 0, 0.4);
  animation: bonusReveal 0.8s ease-out forwards;
  transform-origin: center;
}
.cell.bonus-tile .letter {
  font-size: 24px;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
}
.cell.bonus-tile .score {
  color: #8b4513;
  font-weight: bold;
  font-size: 14px;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 2px;
  padding: 1px 2px;
}
.cell.bonus-tile::before {
  content: "";
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent 0%, rgba(255, 255, 255, 0.4) 50%, transparent 100%);
  animation: goldShimmer 2s ease-in-out infinite;
}

@keyframes bonusReveal {
  0% {
    transform: scale(0) rotateY(0deg);
    opacity: 0;
  }
  50% {
    transform: scale(1.1) rotateY(90deg);
    opacity: 0.8;
  }
  100% {
    transform: scale(1) rotateY(0deg);
    opacity: 1;
  }
}
@keyframes goldShimmer {
  0% {
    left: -100%;
  }
  100% {
    left: 100%;
  }
}
.keyboard {
  position: fixed;
  height: 30%;
  padding: 16px;
  z-index: 100;
  bottom: 0;
  width: 100%;
  background: rgba(13, 40, 24, 0.6);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  justify-content: center;
}

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

.key {
  padding: 12px 8px;
  font-size: 14px;
  font-weight: bold;
  border: 2px solid #4a5568;
  background: rgba(255, 255, 255, 0.05);
  color: #e0e6ed;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  min-width: 40px;
  height: 50px;
  text-align: center;
  text-transform: uppercase;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.key:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: #667eea;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}
.key:active {
  transform: translateY(0);
}
.key.correct {
  background: linear-gradient(135deg, #48bb78 0%, #38a169 100%);
  border-color: #38a169;
  color: white;
}
.key.present {
  background: linear-gradient(135deg, #ed8936 0%, #dd6b20 100%);
  border-color: #dd6b20;
  color: white;
}
.key.absent {
  background: linear-gradient(135deg, #4a5568 0%, #2d3748 100%);
  border-color: #2d3748;
  color: #a0aec0;
}
.key.wide {
  min-width: 80px;
}

.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: modalFadeIn 0.3s ease;
}

.modal-content {
  background: rgba(26, 26, 46, 0.95);
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: 20px;
  padding: 0;
  max-width: 500px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(15px);
  animation: modalSlideIn 0.3s ease;
}

.modal-header {
  padding: 24px 24px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-header h2 {
  margin: 0;
  color: #ffffff;
  font-size: 1.8em;
  font-weight: bold;
}

.modal-close {
  background: none;
  border: none;
  color: #a0aec0;
  font-size: 28px;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.2s ease;
}
.modal-close:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
}

.modal-body {
  padding: 24px;
  padding-bottom: 8px;
  color: #e0e6ed;
  text-align: center;
}
.modal-body p {
  margin: 12px 0;
  font-size: 1.1em;
  line-height: 1.4;
}

#modalScore {
  font-weight: bold;
  font-size: 1.3em;
  color: #48bb78;
  margin: 16px 0;
}

.share-grid {
  margin: 16px 0 8px;
  font-family: monospace;
  font-size: 1.2em;
  line-height: 1.3;
  background: rgba(0, 0, 0, 0.2);
  padding: 12px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  white-space: pre-wrap;
}
.share-grid .emoji-row {
  display: flex;
  justify-content: center;
  gap: 2px;
  margin-bottom: 4px;
  font-size: 20px;
}

.modal-buttons {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-block: 12px;
}

.modal-footer {
  padding: 8px 24px 20px;
  display: flex;
  gap: 8px;
  justify-content: center;
}

.score-win {
  background: rgba(72, 187, 120, 0.2) !important;
  border: 1px solid rgba(72, 187, 120, 0.4) !important;
  border-radius: 12px !important;
  padding: 16px 24px !important;
  color: #48bb78 !important;
  backdrop-filter: blur(10px) !important;
  font-size: 1.2em !important;
  text-align: center !important;
}

.score-lose {
  background: rgba(245, 101, 101, 0.2) !important;
  border: 1px solid rgba(245, 101, 101, 0.4) !important;
  border-radius: 12px !important;
  padding: 16px 24px !important;
  color: #f56565 !important;
  backdrop-filter: blur(10px) !important;
  font-size: 1.2em !important;
  text-align: center !important;
}

.instructions {
  padding: 24px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.3);
}
.instructions h3 {
  color: #ffffff;
  margin-top: 15px;
  margin-bottom: 16px;
  font-size: 1.3em;
}
.instructions h3:first-of-type {
  margin-top: 0px;
}
.instructions ul {
  margin: 12px 0;
  padding-left: 20px;
}
.instructions li {
  margin-bottom: 8px;
  line-height: 1.4;
}
.instructions p {
  margin: 16px 0 8px 0;
  line-height: 1.4;
}
.instructions .color-coding {
  display: flex;
  flex-direction: column;
}
.instructions .cell {
  height: 15px;
  width: 15px;
  display: inline-block;
  margin-inline: 5px;
}

@media (max-width: 768px) {
  .title-tiles {
    gap: 4px;
  }
  .title-tile {
    width: 50px;
    height: 50px;
  }
  .title-tile .letter {
    font-size: 26px;
  }
  .title-tile .score {
    font-size: 8px;
    bottom: 3px;
    right: 4px;
  }
  .container {
    min-width: 400px;
    max-width: 400px;
  }
  .cell {
    width: 40px;
    height: 40px;
    font-size: 18px;
  }
  .row {
    gap: 6px;
  }
  .row-score {
    font-size: 12px;
    padding: 3px 6px;
    min-width: 40px;
    min-height: 40px;
    width: 40px;
    height: 40px;
  }
}
@media (max-width: 600px) {
  .key {
    padding: 8px 4px;
    font-size: 11px;
    min-width: 36px;
  }
  .key.wide {
    min-width: 52px;
  }
}
@media (max-width: 480px) {
  .title-tile {
    width: 40px;
    height: 40px;
  }
  .container {
    min-width: 350px;
    max-width: 350px;
  }
  .cell {
    width: 35px;
    height: 35px;
    font-size: 16px;
  }
  .cell .score {
    font-size: 8px;
    bottom: 1px;
    right: 2px;
  }
  .row {
    gap: 4px;
  }
  .row-score {
    font-size: 10px;
    padding: 2px 4px;
    min-width: 30px;
    min-width: 35px;
    min-height: 35px;
    width: 35px;
    height: 35px;
  }
  .keyboard-row {
    gap: 3px;
  }
  .key {
    padding: 8px 4px;
    font-size: 11px;
    min-width: 32px;
  }
  .key.wide {
    min-width: 52px;
  }
  .modal-content {
    width: 95%;
    margin: 8px;
  }
  .modal-header {
    padding: 20px 20px 12px;
  }
  .modal-header h2 {
    font-size: 1.5em;
  }
  .modal-body {
    padding: 20px;
  }
  .modal-footer {
    padding: 12px 20px 20px;
    flex-direction: column;
  }
}
.btn {
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  font-size: 0.9em;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 8px;
}
.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}
.btn:active {
  transform: translateY(2px);
  box-shadow: none;
}
.btn-primary {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: 2px solid #667eea;
}
.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}
.btn-primary:active {
  transform: translateY(2px);
  box-shadow: none;
}
.btn-secondary {
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #e0e6ed;
}
.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.2);
}
.btn-success {
  background: linear-gradient(135deg, #6effa6 0%, #4ea24b 100%);
  color: white;
  border: 2px solid #6effa6;
}
.btn-success:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(91, 240, 77, 0.493);
}
.btn-success:active {
  transform: translateY(2px);
  box-shadow: none;
}

input {
  border-radius: 8px;
  padding-inline: 12px;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.text-btn {
  display: flex;
  gap: 0px;
}
.text-btn input {
  border-radius: 0px;
  border-top-left-radius: 8px;
  border-bottom-left-radius: 8px;
}
.text-btn .btn {
  border-radius: 0px;
  border-top-right-radius: 8px;
  border-bottom-right-radius: 8px;
}
