body {
  background: #1a2332;
  margin: 0;
  padding: 0;
}

#wrapper {
  max-width: 1600px;
  margin: 0 auto;
  padding: .5rem 1.5rem;
  padding-top: calc(45px + .5rem);
  font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Arial, sans-serif;
  background: #1a2332;
  height: calc(100vh - 45px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#game-header {
  text-align: center;
  margin-bottom: .5rem;
  flex-shrink: 0;

  & h1 {
    font-size: 1.6rem;
    color: #e8f0ff;
    margin: 0 0 .4rem;
    font-weight: 700;
    text-shadow: 0 2px 4px #0000004d;
  }

  & #controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    margin-bottom: .3rem;

    & label {
      font-size: 1rem;
      color: #c8d6e8;
      font-weight: 500;
    }

    & select {
      padding: .5rem 1rem;
      font-size: 1rem;
      border: 2px solid #4a6fa5;
      border-radius: 4px;
      background: #2d3e50;
      color: #e8f0ff;
      cursor: pointer;
      font-weight: 500;

      &:focus {
        outline: none;
        border-color: #6b8fc9;
        box-shadow: 0 0 0 3px #4a6fa54d;
      }

      & option {
        background: #2d3e50;
        color: #e8f0ff;
      }
    }

    & button {
      padding: .5rem 1.5rem;
      font-size: 1rem;
      font-weight: 600;
      color: #fff;
      background: #4a6fa5;
      border: none;
      border-radius: 4px;
      cursor: pointer;
      transition: background .2s;

      &:hover {
        background: #5a7fb5;
      }

      &:active {
        background: #3a5f95;
      }

      &:focus {
        outline: none;
        box-shadow: 0 0 0 3px #4a6fa566;
      }

      &:disabled {
        background: #3a4a5c;
        color: #6a7a8c;
        cursor: not-allowed;
        opacity: .6;
      }
    }

    & #hint-button {
      background: #ff9800;

      &:hover:not(:disabled) {
        background: #f57c00;
      }

      &:active:not(:disabled) {
        background: #e65100;
      }
    }
  }

  & #score-display {
    font-size: 1rem;
    color: #c8d6e8;
    font-weight: 500;

    & #found-count {
      font-weight: 700;
      color: #e8f0ff;
    }
  }
}

#feedback-message {
  position: fixed;
  top: 100px;
  left: 50%;
  transform: translateX(-50%)translateY(-20px);
  padding: .75rem 1.5rem;
  background: #2d3e50;
  border: 2px solid #4a6fa5;
  border-radius: 6px;
  color: #e8f0ff;
  font-size: 1rem;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s, transform .3s;
  z-index: 999;
  box-shadow: 0 4px 12px #0006;

  &.show {
    opacity: 1;
    transform: translateX(-50%)translateY(0);
  }

  &.error {
    background: #c62828;
    border-color: #d32f2f;
    color: #fff;
  }

  &.success {
    background: #2e7d32;
    border-color: #4caf50;
    color: #fff;
  }
}

#game-container {
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: flex-start;
  gap: 2rem;
  max-width: 100%;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

#grid-container {
  display: grid;
  grid-template-columns: repeat(15, 1fr);
  grid-template-rows: repeat(15, 1fr);
  gap: 3px;
  background: #0d1520;
  border: 3px solid #2d3e50;
  padding: 3px;
  width: 100%;
  max-width: 650px;
  min-width: 550px;
  aspect-ratio: 1;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  flex-shrink: 0;

  & .grid-cell {
    background: #e8f0ff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: 700;
    color: #1a2332;
    cursor: pointer;
    transition: background .15s, color .15s;
    font-family: Courier New, monospace;

    &:hover {
      background: #d0e0f5;
    }

    &.selected {
      background: #ffeb3b;
      color: #1a2332;
    }

    &.found {
      background: #4caf50;
      color: #fff;
    }

    &.hint {
      background: #ff9800;
      color: #fff;
      animation: .5s ease-in-out 2 pulse;
    }
  }
}

@keyframes pulse {
  0%, 100% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.1);
  }
}

#word-bank {
  width: 100%;
  max-width: 320px;
  min-width: 280px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;

  & h3 {
    font-size: 1.1rem;
    color: #e8f0ff;
    margin: 0 0 .4rem;
    font-weight: 600;
    text-align: center;
    flex-shrink: 0;
  }

  & #word-list {
    display: flex;
    flex-direction: column;
    gap: .3rem;
    overflow-y: auto;
    padding-right: .25rem;

    &::-webkit-scrollbar {
      width: 6px;
    }

    &::-webkit-scrollbar-track {
      background: #1a2332;
      border-radius: 3px;
    }

    &::-webkit-scrollbar-thumb {
      background: #4a6fa5;
      border-radius: 3px;

      &:hover {
        background: #5a7fb5;
      }
    }

    & .word-item {
      padding: .4rem .75rem;
      background: #2d3e50;
      border: 2px solid #4a6fa5;
      border-radius: 4px;
      font-size: .9rem;
      font-weight: 600;
      color: #e8f0ff;
      text-align: left;
      transition: all .2s;
      line-height: 1.1;
      flex-shrink: 0;

      &.found {
        background: #4caf50;
        color: #fff;
        text-decoration: line-through;
        border-color: #4caf50;
      }
    }
  }
}

#game-complete {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #000000d9;
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: .3s ease-out fadeIn;
  overflow: hidden;

  &.visible {
    display: flex;
    overflow: hidden;
  }

  & #complete-content {
    background: linear-gradient(135deg, #2d3e50 0%, #1a2332 100%);
    border: 3px solid #4a6fa5;
    border-radius: 12px;
    padding: 3rem 2.5rem;
    text-align: center;
    max-width: 500px;
    box-shadow: 0 8px 32px #0009;
    animation: .4s ease-out slideUp;
  }

  & h2 {
    font-size: 2.5rem;
    color: gold;
    margin: 0 0 1rem;
    font-weight: 700;
    text-shadow: 0 2px 8px #ffd70066;
    animation: .6s ease-out celebrate;
  }

  & p {
    font-size: 1.3rem;
    color: #e8f0ff;
    margin: 0 0 2rem;
    line-height: 1.4;
  }

  & #game-stats {
    background: #0000004d;
    border-radius: 8px;
    padding: 1.5rem;
    margin: 0 0 2rem;
    display: flex;
    flex-direction: column;
    gap: .75rem;

    & .stat-item {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: .5rem 0;
      border-bottom: 1px solid #4a6fa54d;

      &:last-child {
        border-bottom: none;
      }

      & .stat-label {
        font-size: 1rem;
        color: #c8d6e8;
        font-weight: 500;
      }

      & .stat-value {
        font-size: 1.1rem;
        color: gold;
        font-weight: 700;
      }
    }
  }

  & button {
    padding: 1rem 2rem;
    font-size: 1.2rem;
    font-weight: 700;
    color: #fff;
    background: linear-gradient(135deg, #4caf50 0%, #2e7d32 100%);
    border: 2px solid #66bb6a;
    border-radius: 8px;
    cursor: pointer;
    transition: all .3s;
    box-shadow: 0 4px 12px #4caf5066;
    text-transform: uppercase;
    letter-spacing: .5px;

    &:hover {
      background: linear-gradient(135deg, #66bb6a 0%, #4caf50 100%);
      transform: translateY(-2px);
      box-shadow: 0 6px 16px #4caf5099;
    }

    &:active {
      transform: translateY(0);
      box-shadow: 0 2px 8px #4caf5066;
    }

    &:focus {
      outline: none;
      box-shadow: 0 0 0 3px #4caf5080;
    }
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes slideUp {
  from {
    transform: translateY(30px);
    opacity: 0;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes celebrate {
  0% {
    transform: scale(.8);
    opacity: 0;
  }

  50% {
    transform: scale(1.1);
  }

  100% {
    transform: scale(1);
    opacity: 1;
  }
}

@media (width <= 1200px) {
  #wrapper {
    height: auto;
    min-height: calc(100vh - 45px);
  }

  #game-container {
    flex-direction: column;
    align-items: center;
    overflow: visible;
  }

  #grid-container {
    max-width: 500px;
    min-width: auto;

    & .grid-cell {
      font-size: 1.3rem;
    }
  }

  #word-bank {
    max-width: 500px;

    & #word-list {
      display: grid;
      grid-template-columns: repeat(3, 1fr);
      overflow-y: visible;
    }
  }
}

@media (width <= 600px) {
  #wrapper {
    padding: 1rem;
    padding-top: calc(40px + 1rem);
    height: auto;
    min-height: calc(100vh - 40px);
  }

  #game-header {
    & h1 {
      font-size: 2rem;
    }

    & #controls {
      flex-direction: column;
      gap: .75rem;

      & label {
        font-size: .9rem;
      }

      & select, & button {
        font-size: .9rem;
        padding: .5rem 1rem;
      }
    }

    & #score-display {
      font-size: 1rem;
    }
  }

  #grid-container {
    max-width: 100%;
    min-width: auto;
    gap: 1px;
    padding: 1px;

    & .grid-cell {
      font-size: 1.1rem;
    }
  }

  #word-bank {
    max-width: 100%;
    min-width: auto;

    & h3 {
      font-size: 1.25rem;
    }

    & #word-list {
      display: grid;
      grid-template-columns: repeat(2, 1fr);

      & .word-item {
        font-size: .9rem;
        padding: .6rem;
      }
    }
  }

  #feedback-message {
    top: 80px;
    font-size: .9rem;
    padding: .6rem 1.2rem;
  }

  #game-complete {
    & #complete-content {
      padding: 2rem 1.5rem;
      max-width: 90%;
    }

    & h2 {
      font-size: 2rem;
    }

    & p {
      font-size: 1.1rem;
    }

    & #game-stats {
      padding: 1rem;

      & .stat-item {
        & .stat-label {
          font-size: .9rem;
        }

        & .stat-value {
          font-size: 1rem;
        }
      }
    }

    & button {
      font-size: 1rem;
      padding: .75rem 1.5rem;
    }
  }
}

.grid-cell:focus-visible {
  outline: 3px solid #000;
  outline-offset: -3px;
  z-index: 1;
}

select:focus-visible, button:focus-visible {
  outline: 3px solid #000;
  outline-offset: 2px;
}

.grid-cell {
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
