:root {
  --ws-bg: linear-gradient(180deg, #f5f8ff 0%, #e6edf8 100%);
  --ws-panel: rgba(255, 255, 255, 0.92);
  --ws-panel-strong: #ffffff;
  --ws-border: #a4b8d7;
  --ws-text: #152b4f;
  --ws-muted: #3f5f8f;
  --ws-accent: #183963;
  --ws-accent-text: #ffffff;
  --ws-found: #2f9e44;
  --ws-select: #ffd43b;
  --ws-shadow: 0 20px 50px rgba(18, 45, 91, 0.14);
}

:root[data-theme="dark"] {
  --ws-bg: linear-gradient(180deg, #061221 0%, #0c1d33 100%);
  --ws-panel: rgba(10, 27, 49, 0.94);
  --ws-panel-strong: #0a1b31;
  --ws-border: #2f517b;
  --ws-text: #eef5ff;
  --ws-muted: #b6cae7;
  --ws-accent: #2c5d97;
  --ws-accent-text: #eef5ff;
  --ws-found: #51cf66;
  --ws-select: #f08c00;
  --ws-shadow: 0 24px 56px rgba(0, 0, 0, 0.38);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--ws-bg);
  color: var(--ws-text);
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

.wordsearch-page {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 56px;
}

.wordsearch-header {
  margin-bottom: 28px;
}

.wordsearch-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.wordsearch-link,
.difficulty-button,
#playAgainButton {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--ws-border);
  background: var(--ws-panel);
  color: var(--ws-text);
  text-decoration: none;
  font-weight: 700;
  box-shadow: var(--ws-shadow);
  cursor: pointer;
  transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease, filter 0.16s ease;
}

.wordsearch-link {
  min-height: 42px;
  padding: 0 16px;
}

.wordsearch-link:hover,
.wordsearch-link:focus-visible,
.difficulty-button:hover,
.difficulty-button:focus-visible,
#playAgainButton:hover,
#playAgainButton:focus-visible {
  transform: translateY(-2px);
  box-shadow: 0 22px 40px rgba(18, 45, 91, 0.2);
  border-color: var(--ws-accent);
  outline: none;
}

.wordsearch-start,
.wordsearch-game {
  background: var(--ws-panel);
  border: 1px solid var(--ws-border);
  box-shadow: var(--ws-shadow);
  padding: 28px;
}

.wordsearch-start {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 420px);
  gap: 26px;
  align-items: center;
}

.wordsearch-start h1,
.game-top h1 {
  margin: 0 0 8px;
  font-size: clamp(2rem, 4vw, 3rem);
  line-height: 1;
}

.wordsearch-start p,
.game-stats {
  margin: 0;
  color: var(--ws-muted);
  font-size: 1.05rem;
  line-height: 1.45;
}

.difficulty-buttons {
  display: grid;
  gap: 10px;
}

.difficulty-button {
  width: 100%;
  min-height: 48px;
  padding: 0 16px;
  background: var(--ws-accent);
  color: var(--ws-accent-text);
  box-shadow: none;
}

.game-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 20px;
}

.timer {
  min-width: 120px;
  border: 1px solid var(--ws-border);
  background: var(--ws-panel-strong);
  color: var(--ws-text);
  padding: 10px 14px;
  text-align: center;
}

.timer span {
  display: block;
  color: var(--ws-muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

.timer strong {
  display: block;
  font-size: 1.6rem;
  line-height: 1.1;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  gap: 18px;
  align-items: start;
}

.board-wrap {
  overflow: auto;
  padding: 4px;
}

.word-grid {
  --grid-size: 12;
  display: grid;
  grid-template-columns: repeat(var(--grid-size), minmax(28px, 1fr));
  width: min(100%, 760px);
  aspect-ratio: 1;
  touch-action: none;
  user-select: none;
  border: 1px solid var(--ws-border);
  background: var(--ws-panel-strong);
}

.cell {
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  border: 1px solid rgba(164, 184, 215, 0.42);
  background: transparent;
  color: var(--ws-text);
  font-size: clamp(0.8rem, 2vw, 1.18rem);
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
}

.cell.selected {
  background: var(--ws-select);
  color: #111;
}

.cell.found {
  background: rgba(47, 158, 68, 0.2);
  color: var(--ws-found);
}

.cell.selected.found {
  background: var(--ws-select);
  color: #111;
}

.word-list-panel {
  border: 1px solid var(--ws-border);
  background: var(--ws-panel-strong);
  padding: 16px;
}

.word-list-panel h2 {
  margin: 0 0 12px;
  font-size: 1.25rem;
}

.word-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.word-list li {
  border-bottom: 1px solid rgba(164, 184, 215, 0.42);
  padding-bottom: 7px;
  color: var(--ws-text);
  font-weight: 700;
  overflow-wrap: anywhere;
}

.word-list li.found {
  color: var(--ws-found);
  text-decoration: line-through;
}

.complete-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(0, 0, 0, 0.52);
}

.complete-dialog {
  width: min(420px, 100%);
  border: 1px solid var(--ws-border);
  background: var(--ws-panel-strong);
  color: var(--ws-text);
  box-shadow: var(--ws-shadow);
  padding: 24px;
  text-align: center;
}

.complete-dialog h2 {
  margin: 0 0 8px;
  font-size: 2rem;
}

.complete-dialog p {
  margin: 0 0 18px;
  color: var(--ws-muted);
}

#playAgainButton {
  min-height: 42px;
  padding: 0 18px;
  background: var(--ws-accent);
  color: var(--ws-accent-text);
  box-shadow: none;
}

@media (max-width: 900px) {
  .wordsearch-start,
  .game-layout {
    grid-template-columns: 1fr;
  }

  .word-grid {
    width: min(100%, 680px);
  }

  .word-list {
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  }
}

@media (max-width: 700px) {
  .wordsearch-page {
    width: min(100% - 18px, 1180px);
    padding-top: 16px;
    padding-bottom: 42px;
  }

  .wordsearch-nav {
    justify-content: center;
  }

  .wordsearch-start,
  .wordsearch-game {
    padding: 18px;
  }

  .game-top {
    display: grid;
  }

  .timer {
    width: 100%;
  }

  .word-grid {
    min-width: min(560px, 100vw - 44px);
  }
}
