* {
  box-sizing: border-box;
}

:root {
  --sky: #dff3ff;
  --mint: #def8e8;
  --sun: #fff1bf;
  --orange: #ffb35c;
  --blue: #3d95c4;
  --green: #49b870;
  --pink: #ff7fa4;
  --ink: #24323b;
  --muted: #5d717c;
  --card: #ffffff;
  --cell-size: clamp(32px, 3.2vw, 46px);
}

html {
  min-height: 100%;
  overflow-y: auto;
}

body {
  min-height: 100vh;
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--ink);
  background: linear-gradient(135deg, var(--sky), var(--sun) 48%, var(--mint));
  overflow-x: hidden;
  overflow-y: auto;
}

button,
input {
  font: inherit;
}

button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  padding: 0.68rem 0.9rem;
  color: #21303a;
  background: #f4f8fb;
  box-shadow: 0 4px 0 #c6d6df;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

button:hover {
  transform: translateY(-1px);
  background: #ffffff;
}

button:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #c6d6df;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.65;
  transform: none;
}

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

.app-shell {
  width: min(98vw, 1500px);
  margin: 0 auto;
  padding: clamp(0.35rem, 1.2vw, 0.85rem);
}

.game-card {
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
  border-radius: 8px;
  padding: clamp(0.55rem, 1.25vw, 1rem);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 18px 40px rgba(45, 90, 112, 0.18);
}

.game-header {
  text-align: center;
  margin-bottom: 0.55rem;
}

.theme-label {
  display: inline-block;
  max-width: 100%;
  margin: 0 0 0.28rem;
  border-radius: 999px;
  padding: 0.28rem 0.65rem;
  color: #2f6d4c;
  background: #e3f8d7;
  font-size: 0.9rem;
  font-weight: 800;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.game-header h1 {
  margin: 0;
  color: #1d6f9c;
  font-size: clamp(1.6rem, 4vw, 2.65rem);
  line-height: 1;
  letter-spacing: 0;
}

.game-header p:last-child {
  max-width: 680px;
  margin: 0.35rem auto 0;
  color: var(--muted);
  font-size: clamp(0.88rem, 1.65vw, 1rem);
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.level-title {
  margin: 0.4rem 0 0;
  color: #2f6d4c;
  font-size: clamp(0.98rem, 2vw, 1.18rem);
  letter-spacing: 0;
}

.score-board {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.45rem;
  align-items: stretch;
  margin: 0 auto 0.6rem;
  border: 2px solid #e5f0f6;
  border-radius: 8px;
  padding: 0.48rem;
  background: #fbfdff;
}

.score-item {
  border-radius: 8px;
  padding: 0.45rem;
  background: #edf8ff;
  text-align: center;
}

.score-label {
  display: block;
  margin-bottom: 0.15rem;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 700;
}

.score-item strong {
  color: #1975a8;
  font-size: clamp(1rem, 3vw, 1.35rem);
}

.message-text {
  grid-column: 1 / -1;
  margin: 0;
  border-radius: 8px;
  padding: 0.52rem;
  color: #6b4a11;
  background: #fff3cd;
  font-weight: 800;
  text-align: center;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.game-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.85rem;
  align-items: start;
  min-width: 0;
}

.hidden {
  display: none !important;
}

.final-result {
  display: grid;
  gap: 0.85rem;
  justify-items: center;
  margin: 0 auto 1rem;
  border: 2px solid #cfeee0;
  border-radius: 8px;
  padding: clamp(1rem, 4vw, 1.4rem);
  background: #f0fff5;
  text-align: center;
}

.final-result h2 {
  margin: 0;
  color: #21834c;
  font-size: clamp(1.7rem, 6vw, 2.35rem);
}

.final-result p {
  max-width: 620px;
  margin: 0;
  color: #36535f;
  line-height: 1.5;
}

.final-result strong {
  color: #176d98;
  font-size: clamp(1.2rem, 4vw, 1.55rem);
}

.board-area,
.clue-area {
  min-width: 0;
  border: 2px solid #e5f0f6;
  border-radius: 8px;
  padding: 0.65rem;
  background: #ffffff;
}

.board-area {
  display: grid;
  gap: 0.5rem;
  align-content: start;
}

.section-title h2,
.clue-group h2 {
  margin: 0 0 0.45rem;
  color: #246b8e;
  font-size: 1.05rem;
  letter-spacing: 0;
}

.grid-scroller {
  width: 100%;
  min-width: 0;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  padding: 0.05rem 0.05rem 0.2rem;
}

.crossword-grid {
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--cell-size));
  grid-auto-rows: var(--cell-size);
  gap: 1px;
  width: max-content;
  margin: 0 auto;
  padding: 1px;
  border: 2px solid #111820;
  border-radius: 6px;
  background: #111820;
  overflow: hidden;
}

.cell {
  position: relative;
  width: var(--cell-size);
  aspect-ratio: 1;
  border-radius: 0;
}

.cell.blocked {
  background: #111820;
}

.cell.playable {
  background: #ffffff;
  box-shadow: inset 0 0 0 1px #111820;
}

.cell.playable.in-word:not(.correct):not(.wrong) {
  background: #e5f6ff;
}

.cell.playable.active {
  background: #bfe9ff;
  box-shadow: inset 0 0 0 2px #1785bd;
}

.cell.playable.correct {
  background: #dff7d9;
}

.cell.playable.wrong {
  background: #ffdce7;
}

.cell.playable.hint {
  box-shadow: inset 0 0 0 3px #ffd166;
}

.cell-number {
  position: absolute;
  top: 2px;
  left: 4px;
  z-index: 1;
  color: #2f6f8a;
  font-size: clamp(0.52rem, 1.8vw, 0.72rem);
  font-weight: 900;
  line-height: 1;
  pointer-events: none;
}

.cell input {
  width: 100%;
  height: 100%;
  border: 0;
  border-radius: 0;
  padding: 0.38rem 0.05rem 0.05rem;
  color: #20323d;
  background: transparent;
  text-align: center;
  text-transform: uppercase;
  font-size: clamp(1rem, 2.7vw, 1.45rem);
  font-weight: 900;
}

.cell input:focus {
  outline: 0;
}

.clue-area {
  display: grid;
  gap: 0.62rem;
}

.clue-list {
  display: grid;
  gap: 0.36rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.clue-button {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.6rem;
  align-items: center;
  width: 100%;
  min-height: 36px;
  padding: 0.45rem 0.58rem;
  background: #f6fbff;
  box-shadow: none;
  text-align: left;
  font-weight: 700;
}

.clue-button:hover,
.clue-button.active {
  background: #e9f7ff;
}

.clue-button.clue-correct {
  background: #e5f8df;
  color: #245c37;
}

.clue-button.clue-wrong {
  background: #ffe3eb;
  color: #77314a;
}

.clue-number {
  display: inline-grid;
  place-items: center;
  width: 1.55rem;
  height: 1.55rem;
  border-radius: 50%;
  color: #ffffff;
  background: var(--orange);
  font-size: 0.78rem;
  font-weight: 900;
}

.button-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.45rem;
  margin-top: 0;
}

.primary-button {
  color: #ffffff;
  background: var(--green);
  box-shadow: 0 4px 0 #2d8d50;
}

.primary-button:hover {
  background: #55c87c;
}

#hintButton {
  background: #ffe2a8;
  box-shadow: 0 4px 0 #d99d37;
}

#playAgainButton {
  background: #dff2ff;
  box-shadow: 0 4px 0 #8cc0dc;
}

.next-button {
  color: #ffffff;
  background: #2c8ed6;
  box-shadow: 0 4px 0 #176da8;
}

.next-button:hover {
  background: #379de8;
}

.virtual-keyboard {
  display: grid;
  gap: 0.45rem;
  margin-top: 0;
  border: 2px solid #e5f0f6;
  border-radius: 8px;
  padding: 0.55rem;
  background: #ffffff;
}

.letter-keyboard {
  display: grid;
  grid-template-columns: repeat(13, minmax(0, 1fr));
  gap: 0.36rem;
}

.key-button {
  min-height: 34px;
  padding: 0.28rem 0.16rem;
  color: #17405a;
  background: #e8f6ff;
  box-shadow: 0 3px 0 #9ecce5;
  font-size: clamp(0.9rem, 2vw, 1.05rem);
}

.key-button:hover {
  background: #f5fbff;
}

.keyboard-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.45rem;
}

.keyboard-command {
  min-height: 38px;
  background: #fff0c9;
  box-shadow: 0 3px 0 #ddb563;
}

@media (min-width: 900px) {
  .game-layout {
    grid-template-columns: minmax(620px, 1.65fr) minmax(320px, 0.78fr);
  }

  .clue-area {
    max-height: calc(100vh - 205px);
    overflow-y: auto;
  }

  .button-row {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .score-board {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (min-width: 1180px) {
  .board-area {
    grid-template-columns: max-content minmax(220px, 1fr);
    grid-template-areas:
      "title title"
      "grid actions"
      "grid keyboard";
    column-gap: 0.8rem;
    align-items: start;
  }

  .section-title {
    grid-area: title;
  }

  .grid-scroller {
    grid-area: grid;
  }

  .button-row {
    grid-area: actions;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .virtual-keyboard {
    grid-area: keyboard;
    align-self: start;
  }

  .letter-keyboard {
    grid-template-columns: repeat(7, minmax(0, 1fr));
  }
}

@media (max-height: 720px) and (min-width: 900px) {
  :root {
    --cell-size: clamp(28px, 2.65vw, 38px);
  }

  .app-shell {
    padding-block: 0.3rem;
  }

  .game-header {
    margin-bottom: 0.4rem;
  }

  .game-header h1 {
    font-size: clamp(1.5rem, 3.5vw, 2.25rem);
  }

  .game-header p:last-child {
    margin-top: 0.25rem;
    line-height: 1.25;
  }

  .level-title {
    margin-top: 0.3rem;
  }

  .score-board {
    margin-bottom: 0.45rem;
  }

  .clue-area {
    max-height: calc(100vh - 175px);
  }
}

@media (max-width: 520px) {
  :root {
    --cell-size: clamp(26px, 6.4vw, 30px);
  }

  .app-shell {
    padding: 0.45rem;
  }

  .game-card,
  .board-area,
  .clue-area {
    padding: 0.65rem;
  }

  .score-board,
  .button-row {
    grid-template-columns: 1fr;
  }

  .crossword-grid {
    width: 100%;
    gap: 1px;
    grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
    grid-auto-rows: auto;
    padding: 1px;
  }

  .cell {
    width: 100%;
  }

  .cell input {
    padding: 0.3rem 0 0.05rem;
    font-size: clamp(0.72rem, 3.4vw, 1rem);
  }

  .cell-number {
    top: 1px;
    left: 2px;
    font-size: clamp(0.45rem, 1.8vw, 0.58rem);
  }

  .message-text {
    font-size: 0.9rem;
  }

  .letter-keyboard {
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 0.32rem;
  }

  .key-button {
    min-height: 34px;
    padding: 0.28rem 0.1rem;
  }

  .keyboard-actions {
    grid-template-columns: 1fr;
  }

  button {
    width: 100%;
  }
}
