/* Lingo2 - Grid Styles (Mobile-First) */

/* Grid Container */
.grid-container {
  display: flex;
  justify-content: center;
  margin: 2em 0;
}

.grid {
  border-collapse: separate;
  border-spacing: 1vw;
  background-color: transparent;
}

/* Grid Cells */
.grid-cell {
  width: 9vw;
  height: 9vw;
  text-align: center;
  vertical-align: middle;
  font-size: 6vw;
  font-weight: bold;
  border: 1px solid #c6e9ff;
  border-radius: 4px;
  box-shadow: 5px 5px 10px rgba(0, 0, 0, 0.25);
  text-shadow: 2px 2px 5px rgba(0, 0, 0, 0.6);
  transition: var(--transition);
}

/* Empty cells (not yet filled) */
.grid-cell.empty {
  background: linear-gradient(to bottom, #11A7FF, #0065CF);
  border-color: #c6e9ff;
}

/* Color codes - Letter states */

/* R - Rouge: Correct letter, correct position */
.grid-cell.R {
  background: linear-gradient(to bottom, #f78972, #95351e);
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.3),
              inset 0 5px 0 rgba(255, 255, 255, 0.2),
              5px 5px 10px rgba(0, 0, 0, 0.25);
  border-color: #d64932;
  color: white;
}

/* B - Blanc/Jaune: Correct letter, wrong position */
.grid-cell.B {
  background: radial-gradient(circle, #f9f97f, #ffd400);
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.2),
              inset 0 5px 0 rgba(255, 255, 255, 0.3),
              5px 5px 10px rgba(0, 0, 0, 0.25);
  border-color: #e6c200;
  color: #2d2d2d;
  text-shadow: 1px 1px 2px rgba(255, 255, 255, 0.5);
}

/* N - Noir/Absent: Letter not in word */
.grid-cell.N {
  background: linear-gradient(to bottom, #11A7FF, #0065CF);
  border-color: #5bb8ff;
  color: white;
}

/* L - Lost (word displayed when game is lost) */
.grid-cell.L {
  background: #2d2d2d;
  border-color: #444;
  color: #999;
}

/* Known letter - Pre-filled letters on next row */
.grid-cell.known-letter {
  opacity: 0.7;
  transform: scale(0.95);
}

.next-row {
  position: relative;
}

/* Animations */

/* Victory animation - shimmer effect on winning row */
@keyframes victory_cell_animation {
  0% {
    background-position: -500% center;
  }
  100% {
    background-position: 500% center;
  }
}

.victory-row .grid-cell.R,
.animate-victory .grid-cell.R {
  background: linear-gradient(
    90deg,
    #95351e 0%,
    #f78972 25%,
    #ffffff 50%,
    #f78972 75%,
    #95351e 100%
  );
  background-size: 200% 100%;
  animation: victory_cell_animation 0.8s linear infinite;
}

/* Grid rotation animation (when changing) */
@keyframes changing_grid_animation {
  0% {
    transform: rotateY(0deg);
  }
  100% {
    transform: rotateY(-90deg);
  }
}

@keyframes grid_created_animation {
  0% {
    transform: rotateY(-90deg);
    opacity: 0;
  }
  100% {
    transform: rotateY(0deg);
    opacity: 1;
  }
}

.grid.changing {
  animation: changing_grid_animation 0.25s ease-out;
}

.grid.created {
  animation: grid_created_animation 0.25s ease-out;
}

/* Current row highlight */
.grid-row.current-row .grid-cell.empty {
  border-color: var(--lingo_yellow);
  box-shadow: 0 0 10px rgba(255, 228, 78, 0.5),
              5px 5px 10px rgba(0, 0, 0, 0.25);
}

/* Letter animation when entered */
@keyframes letter_appear {
  0% {
    transform: scale(0.5);
    opacity: 0;
  }
  50% {
    transform: scale(1.2);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.grid-cell.new-letter {
  animation: letter_appear 0.2s ease-out;
}

/* Row reveal animation */
@keyframes row_reveal {
  0% {
    transform: scaleY(0);
    opacity: 0;
  }
  100% {
    transform: scaleY(1);
    opacity: 1;
  }
}

.grid-row.reveal {
  animation: row_reveal 0.3s ease-out;
}

/* Game Container Styles */
.game-container {
  max-width: 800px;
  margin: 0 auto;
}

.game-header {
  text-align: center;
  margin-bottom: 1.5em;
}

.game-info {
  font-size: 1em;
  opacity: 0.9;
}

/* Input Container */
.input-container {
  max-width: 600px;
  margin: 1em auto 0.5em;
  padding: 0 1em;
  text-align: center;
}

.word-form {
  display: flex;
  gap: 0.5em;
  margin-bottom: 0.5em;
  align-items: stretch;
}

.word-input {
  flex: 1;
  font-size: 1.5em;
  text-align: center;
  text-transform: uppercase;
  padding: 0.5em 0.3em;
  border: 2px solid var(--lingo_blue);
  border-radius: 8px;
  background-color: #ffffff20;
  color: white;
  font-family: 'Gotham', monospace;
  letter-spacing: 0.1em;
  min-width: 0; /* Allow shrinking on mobile */
  /* iOS/iPad specific fixes for input visibility */
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  opacity: 1 !important;
  visibility: visible !important;
  display: block !important;
  box-sizing: border-box;
}

.word-input::placeholder {
  font-size: 0.85em;
  letter-spacing: 0.05em;
  color: rgba(255, 255, 255, 0.5);
}

.word-input:focus {
  outline: none;
  border-color: var(--lingo_yellow);
  box-shadow: 0 0 15px rgba(255, 228, 78, 0.5);
}

.btn-submit {
  font-size: 1.3em;
  padding: 0.5em 1em;
  white-space: nowrap;
  flex-shrink: 0;
}

.input-hint {
  font-size: 0.75em;
  opacity: 0.8;
  margin: 0.3em 0;
  line-height: 1.3;
}

.input-error {
  color: #ff6b6b;
  font-size: 0.9em;
  font-weight: bold;
  min-height: 1.5em;
  margin: 0.3em 0;
}

/* Result Pages (Victory/Defeat) */
.result-container {
  max-width: 700px;
  margin: 0 auto;
}

.result-header {
  margin-bottom: 2em;
}

.result-title {
  font-size: 3em;
  margin-bottom: 0.3em;
}

.victory-title {
  color: var(--lingo_yellow);
  text-shadow: 0 0 20px rgba(255, 228, 78, 0.8);
}

.defeat-title {
  color: #ff6b6b;
}

.result-subtitle {
  font-size: 1.3em;
  opacity: 0.9;
}

.result-actions {
  display: flex;
  flex-direction: column;
  gap: 1em;
  align-items: center;
  margin-top: 2em;
}

/* Responsive - Desktop */
@media (min-width: 1024px) {
  .grid-cell {
    width: 8vw;
    height: 8vw;
    font-size: 5vw;
  }

  .grid {
    border-spacing: 0.8vw;
  }

  .word-input {
    font-size: 2.5em;
  }

  .result-actions {
    flex-direction: row;
    justify-content: center;
  }
}

/* Score Box */
.score-box {
  background-color: #ffffff10;
  padding: 1.5em;
  border-radius: 12px;
  margin: 2em 0;
}

.score-total {
  font-size: 3em;
  font-weight: bold;
  color: var(--lingo_yellow);
  margin: 0.3em 0;
}

.score-details {
  font-size: 0.9em;
  opacity: 0.8;
}

.score-details p {
  margin: 0.2em 0;
}

/* Level Unlock */
.level-unlock {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 1.5em;
  border-radius: 12px;
  margin: 2em 0;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
}

.unlock-message {
  display: inline-block;
  font-size: 1.5em;
  font-weight: bold;
  margin: 0;
  padding: 1em 2em;
  background: linear-gradient(135deg, var(--lingo_yellow) 0%, #ffd400 100%);
  color: var(--lingo_dark);
  text-decoration: none;
  border-radius: 10px;
  transition: transform 0.2s, box-shadow 0.2s;
  cursor: pointer;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
}

.unlock-message:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.3);
}

/* Word Reveal (Defeat) */
.word-reveal {
  margin: 2em 0;
}

.revealed-word {
  font-size: 3em;
  color: var(--lingo_red);
  font-weight: bold;
  letter-spacing: 0.1em;
  text-shadow: 0 0 20px rgba(165, 42, 46, 0.8);
}

/* Lives Box */
.lives-box {
  background-color: #ffffff10;
  padding: 1.5em;
  border-radius: 12px;
  margin: 2em 0;
}

.lives-message {
  font-size: 1.3em;
  margin: 0;
}

/* ========================================
   RESPONSIVE - MOBILE OPTIMIZATIONS
   ======================================== */

/* Mobile devices (phones in portrait) */
@media (max-width: 480px) {
  /* Compact game header */
  .game-header {
    margin: 0.5em 0;
  }

  .game-header h2 {
    font-size: 1.5em;
    margin: 0.3em 0;
  }

  .game-info {
    font-size: 0.85em;
  }

  /* Compact timer */
  .timer-container {
    margin: 0.5em 0;
  }

  .timer-circle {
    width: 60px;
    height: 60px;
  }

  .timer-text {
    font-size: 1.2em;
  }

  /* Compact input form */
  .input-container {
    margin: 0.5em auto;
    padding: 0 0.5em;
  }

  .word-form {
    gap: 0.3em;
  }

  .word-input {
    font-size: 1.2em;
    padding: 0.4em 0.2em;
    letter-spacing: 0.05em;
  }

  .word-input::placeholder {
    font-size: 0.8em;
  }

  .btn-submit {
    font-size: 1.1em;
    padding: 0.4em 0.7em;
  }

  .input-hint {
    font-size: 0.7em;
    margin: 0.2em 0;
  }

  .input-error {
    font-size: 0.8em;
    min-height: 1.2em;
  }

  /* Compact grid */
  .grid-container {
    margin: 0.5em 0;
  }

  .grid {
    border-spacing: 0.5vw;
  }

  .grid-cell {
    width: 10vw;
    height: 10vw;
    font-size: 5vw;
  }
}

/* Very small devices (smaller phones) */
@media (max-width: 360px) {
  .game-header h2 {
    font-size: 1.3em;
  }

  .word-input {
    font-size: 1em;
  }

  .btn-submit {
    font-size: 1em;
    padding: 0.4em 0.5em;
  }

  .input-hint {
    font-size: 0.65em;
  }

  .grid-cell {
    width: 11vw;
    height: 11vw;
    font-size: 5.5vw;
  }
}

/* Tablets and larger phones in landscape */
@media (min-width: 481px) and (max-width: 768px) {
  .word-input {
    font-size: 1.8em;
  }

  .btn-submit {
    font-size: 1.5em;
  }
}

/* Desktop and tablet (iPad) optimizations - Apply from 768px */
/* Use fixed pixel sizes like in debug_ipad for consistent rendering */
@media (min-width: 768px) {
  /* Input field - same as debug_ipad */
  .word-input {
    font-size: 2em !important;
    padding: 0.5em !important;
    text-align: center;
    background: rgba(255, 255, 255, 0.3) !important;
    border: 3px solid var(--lingo_blue) !important;
    border-radius: 8px;
    color: white;
    height: auto;
    line-height: normal;
  }

  .btn-submit {
    font-size: 1.7em;
    padding: 0.5em 1em;
  }

  /* Grid structure - same as debug_ipad */
  .grid {
    display: table;
    border-collapse: separate;
    border-spacing: 6px;
    margin: 0 auto;
  }

  .grid-row {
    display: table-row;
  }

  /* Grid cells - fixed sizes like debug_ipad */
  .grid-cell {
    display: table-cell !important;
    width: 55px !important;
    height: 55px !important;
    text-align: center !important;
    vertical-align: middle !important;
    font-size: 36px !important;
    line-height: 55px !important;
    font-weight: bold;
    border-radius: 6px;
    padding: 0 !important;
  }

  /* Adjust for different word lengths */
  /* 5 letters - larger cells */
  .grid-row .grid-cell:first-child:nth-last-child(5),
  .grid-row .grid-cell:first-child:nth-last-child(5) ~ .grid-cell {
    width: 65px !important;
    height: 65px !important;
    font-size: 42px !important;
    line-height: 65px !important;
  }

  /* 6 letters */
  .grid-row .grid-cell:first-child:nth-last-child(6),
  .grid-row .grid-cell:first-child:nth-last-child(6) ~ .grid-cell {
    width: 60px !important;
    height: 60px !important;
    font-size: 38px !important;
    line-height: 60px !important;
  }

  /* 7 letters */
  .grid-row .grid-cell:first-child:nth-last-child(7),
  .grid-row .grid-cell:first-child:nth-last-child(7) ~ .grid-cell {
    width: 55px !important;
    height: 55px !important;
    font-size: 36px !important;
    line-height: 55px !important;
  }

  /* 8 letters */
  .grid-row .grid-cell:first-child:nth-last-child(8),
  .grid-row .grid-cell:first-child:nth-last-child(8) ~ .grid-cell {
    width: 50px !important;
    height: 50px !important;
    font-size: 32px !important;
    line-height: 50px !important;
  }

  /* 9 letters */
  .grid-row .grid-cell:first-child:nth-last-child(9),
  .grid-row .grid-cell:first-child:nth-last-child(9) ~ .grid-cell {
    width: 48px !important;
    height: 48px !important;
    font-size: 30px !important;
    line-height: 48px !important;
  }

  /* 10 letters */
  .grid-row .grid-cell:first-child:nth-last-child(10),
  .grid-row .grid-cell:first-child:nth-last-child(10) ~ .grid-cell {
    width: 45px !important;
    height: 45px !important;
    font-size: 28px !important;
    line-height: 45px !important;
  }
}
