/**
 * Crossword — layout and board styles.
 *
 * The shared chrome (page header, light play console, level buttons, keycap
 * buttons, result card, form, podium leaderboard, ad labels) comes from the
 * theme's games "arcade" skin (assets/styles/games-arcade.css), which lists
 * .crossword-game alongside the other games and loads after this file. This
 * file owns the page layout (mirrors the other games' base CSS) and the
 * crossword board itself.
 */

.crossword-game-wrap {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1rem 0;
}

.crossword-game {
  --cw-ink: #1f0766;
  --cw-block: #2a0f6e;
  --cw-line: #c9b8f5;
  --cw-word: #efe8ff;
  --cw-active: #fffd90;
  --cw-cross: #dccbff;
  /* Feedback colours match the other games (Guess the Word is the baseline):
     mint = right, slate = wrong, pink corner flag = revealed. */
  --cw-right: #20ffc0;
  --cw-wrong: #5a4a9c;
  --cw-revealed: #651fff;
  --ag-accent: #b898ff;
  font-family: 'Poppins', system-ui, sans-serif;
  color: var(--cw-ink);
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 2rem;
  align-items: start;
}
.crossword-game__main { min-width: 0; }
.crossword-game__main > :last-child { margin-bottom: 3rem; }

.crossword-game__siderail {
  position: sticky;
  top: 16px;
  align-self: start;
  width: 300px;
  min-height: 600px;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}
.crossword-game__video-mrec { display: none; }

@media (max-width: 991.98px) {
  .crossword-game { grid-template-columns: 1fr; }
  .crossword-game__siderail { display: none; }
  .crossword-game__video-mrec {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 250px;
    margin: 1.5rem 0;
  }
}

.crossword-game__intro { margin: 0 0 1.5rem; font-size: 1.02rem; line-height: 1.6; }
.crossword-game__intro > :first-child { margin-top: 0; }
.crossword-game__intro > :last-child { margin-bottom: 0; }

/* ---- Level picker extras (the buttons themselves come from the skin) ---- */
.crossword-game__levels { display: flex; justify-content: center; flex-wrap: wrap; }
.crossword-game__level {
  font: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .1rem;
  cursor: pointer;
}
.crossword-game__level-state {
  margin-top: .25rem;
  padding: .05rem .5rem;
  border-radius: 999px;
  background: #d4fff2;
  color: #1f0766;
  font-size: .72rem;
  font-weight: 700;
}
.crossword-game__level.is-selected .crossword-game__level-state { background: #fff; }

.crossword-game__notice {
  margin: -.5rem 0 1.25rem;
  padding: .75rem 1rem;
  border-radius: 14px;
  background: #fff;
  box-shadow: inset 0 0 0 2px #dccbff, inset 5px 0 0 #651fff;
  font-weight: 600;
  text-align: center;
}
.crossword-game__notice[hidden] { display: none; }

/* ---- Puzzle: clue bar, grid, clue lists ---- */
.crossword-game__puzzle[hidden] { display: none; }
.crossword-game__bar {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 1rem;
  margin: 0 0 .75rem;
  padding: .65rem .9rem;
  border-radius: 14px;
  background: #fff;
  box-shadow: inset 0 0 0 2px #dccbff, 0 6px 14px -10px rgba(31, 7, 102, .5);
}
.crossword-game__current { flex: 1 1 auto; min-width: 0; margin: 0; font-size: 1rem; line-height: 1.35; }
.crossword-game__current strong { color: #651fff; margin-right: .25rem; }
.crossword-game__timer {
  flex: 0 0 auto;
  margin: 0;
  padding: .2rem .7rem;
  border-radius: 999px;
  background: #efe8ff;
  color: #300c8f;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.crossword-game__layout { display: grid; gap: 1.25rem; align-items: start; }
.crossword-game__puzzle.is-size-15 .crossword-game__layout { grid-template-columns: auto minmax(200px, 1fr); }

.crossword-game__grid-scroll {
  max-width: 100%;
  overflow: auto;
  border-radius: 12px;
  -webkit-overflow-scrolling: touch;
}
.crossword-game__puzzle.is-size-25 .crossword-game__grid-scroll,
.crossword-game__puzzle.is-size-40 .crossword-game__grid-scroll { max-height: 78vh; }

.crossword-game__grid {
  --cw-cell: 32px;
  display: grid;
  grid-template-columns: repeat(var(--cw-n, 15), var(--cw-cell));
  grid-auto-rows: var(--cw-cell);
  width: max-content;
  margin: 0 auto;
  border: 2px solid var(--cw-block);
  background: var(--cw-block);
  gap: 1px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
.crossword-game__cell {
  position: relative;
  display: grid;
  place-items: center;
  background: #fff;
  cursor: pointer;
  transition: background-color .12s ease;
}
.crossword-game__cell.is-block { background: var(--cw-block); cursor: default; }
.crossword-game__cell.is-word { background: var(--cw-word); }
.crossword-game__cell.is-active { background: var(--cw-active); box-shadow: inset 0 0 0 2px #651fff; }
.crossword-game__num {
  position: absolute;
  top: 1px;
  left: 2px;
  font-size: max(10px, calc(var(--cw-cell) * .36));
  line-height: 1;
  font-weight: 700;
  color: #2a1f55;
}
.crossword-game__letter {
  font-size: calc(var(--cw-cell) * .52);
  font-weight: 700;
  line-height: 1;
  margin-top: calc(var(--cw-cell) * .2);
  color: var(--cw-ink);
}
.crossword-game__cell.is-right { background: var(--cw-right); }
.crossword-game__cell.is-wrong { background: var(--cw-wrong); }
.crossword-game__cell.is-wrong .crossword-game__letter,
.crossword-game__cell.is-wrong .crossword-game__num { color: #fff; }
/* Revealed squares: purple letter + a corner flag. */
.crossword-game__cell.is-revealed .crossword-game__letter { color: var(--cw-revealed); }
.crossword-game__cell.is-revealed::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  border-style: solid;
  border-width: 0 calc(var(--cw-cell) * .26) calc(var(--cw-cell) * .26) 0;
  border-color: transparent #fc7ed3 transparent transparent;
}
.crossword-game__puzzle.is-solved .crossword-game__cell:not(.is-block) { background: #d4fff2; }

.crossword-game__clues { display: grid; gap: 1rem; min-width: 0; }
.crossword-game__puzzle.is-size-25 .crossword-game__clues,
.crossword-game__puzzle.is-size-40 .crossword-game__clues { grid-template-columns: 1fr 1fr; }
.crossword-game__clue-group {
  min-width: 0;
  padding: .75rem .5rem .5rem .9rem;
  border-radius: 14px;
  background: #fff;
  box-shadow: inset 0 0 0 2px #dccbff;
}
.crossword-game__clue-title {
  margin: 0 0 .4rem;
  font-size: .8rem;
  font-weight: 800;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: #651fff;
}
.crossword-game__clue-list {
  list-style: none;
  margin: 0;
  padding: 0 .4rem 0 0;
  max-height: 340px;
  overflow-y: auto;
}
.crossword-game__puzzle.is-size-15 .crossword-game__clue-list { max-height: 210px; }
.crossword-game__clue {
  display: flex;
  gap: .5rem;
  padding: .3rem .45rem;
  border-radius: 8px;
  font-size: .9rem;
  line-height: 1.35;
  cursor: pointer;
}
.crossword-game__clue:hover { background: #f8f5ff; }
.crossword-game__clue.is-cross { background: #f8f5ff; }
.crossword-game__clue.is-active { background: #efe8ff; box-shadow: inset 3px 0 0 #651fff; }
.crossword-game__clue-num { flex: 0 0 1.8rem; font-weight: 800; color: #651fff; text-align: right; }
.crossword-game__clue-len { color: #5d5280; font-size: .85em; white-space: nowrap; }

/* On-screen keyboard: touch devices only (crossword.js adds .is-touch). */
.crossword-game__keyboard { display: none; margin: 1rem auto 0; max-width: 36rem; }
.crossword-game.is-touch .crossword-game__keyboard { display: block; }
.crossword-game__key-row { display: flex; justify-content: center; gap: .3rem; margin-bottom: .35rem; }
.crossword-game__key {
  font: inherit;
  flex: 1 1 0;
  max-width: 2.9rem;
  min-width: 0;
  padding: .85rem 0;
  border: 0;
  border-radius: 8px;
  background: #fff;
  color: #1f0766;
  font-weight: 700;
  box-shadow: inset 0 0 0 1px #dccbff, 0 3px 0 #dccbff;
  touch-action: manipulation;
}
.crossword-game__key:active { transform: translateY(2px); box-shadow: inset 0 0 0 1px #dccbff, 0 1px 0 #dccbff; }
.crossword-game__key--wide { max-width: 4.2rem; flex: 1.5 1 0; background: #efe8ff; }

/* ---- Controls ---- */
.crossword-game__controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: .75rem;
  flex-wrap: wrap;
  margin: 1.25rem 0 0;
}
.crossword-game__btn { font: inherit; border-radius: 999px; cursor: pointer; border: 2px solid transparent; }
.crossword-game__status { margin: 0; flex: 1 1 100%; text-align: center; min-width: 0; }
.crossword-game__status:empty { display: none; }

/* ---- Result + form (structure; skin supplies the look) ---- */
.crossword-game__score-note { font-size: .85rem; font-weight: 500; }
.crossword-game__form[hidden] { display: none; }
.crossword-game__form-intro { margin: 0 0 .6rem; }
.crossword-game__form-note { margin: 0 0 .8rem; font-size: .78rem; line-height: 1.4; color: #5d5280; }
.crossword-game__form.is-known [data-lb-intro],
.crossword-game__form.is-known [data-lb-note],
.crossword-game__form.is-known [data-lb-fields],
.crossword-game__form.is-known [data-lb-consent] { display: none; }
.crossword-game__known { margin: 0 0 1.25rem; }
.crossword-game__known-name { font-weight: 700; margin: 0 0 .3rem; }
.crossword-game__known .crossword-game__form-note { margin: 0; }
.crossword-game__fields { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; }
.crossword-game__field { display: flex; flex-direction: column; gap: .25rem; font-size: .85rem; }
.crossword-game__field:last-of-type { grid-column: 1 / -1; }
.crossword-game__field input { font: inherit; }
.crossword-game__form button[type="submit"] { margin-top: .9rem; }
.crossword-game__form-feedback { margin: .6rem 0 0; font-size: .9rem; min-height: 1.1em; }
.crossword-game__hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.crossword-game__consent { display: flex; align-items: flex-start; gap: .5rem; margin: .2rem 0 .9rem; font-size: .82rem; line-height: 1.35; cursor: pointer; }
.crossword-game__consent input { flex: 0 0 auto; margin-top: .15rem; }

/* ---- Leaderboard list (structure; skin supplies the look) ---- */
.crossword-game__board { list-style: none; margin: 0; padding: 0; }
.crossword-game__board-row { display: grid; align-items: center; }
.crossword-game__board-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crossword-game__board-score { font-variant-numeric: tabular-nums; }
.crossword-game__board-sep {
  display: flex;
  align-items: center;
  gap: .7rem;
  margin: .4rem 0;
  padding: .3rem 0;
  color: #651fff;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
}
.crossword-game__board-sep::before,
.crossword-game__board-sep::after { content: ''; flex: 1; border-top: 2px dashed #b898ff; }
.crossword-game__board-note { margin: .8rem 0 0; font-size: .8rem; }

@media (max-width: 760px) {
  .crossword-game__puzzle.is-size-15 .crossword-game__layout,
  .crossword-game__puzzle.is-size-25 .crossword-game__clues,
  .crossword-game__puzzle.is-size-40 .crossword-game__clues { grid-template-columns: 1fr; }
  .crossword-game__clue-list,
  .crossword-game__puzzle.is-size-15 .crossword-game__clue-list { max-height: 220px; }
}
/* Touch phones: clue bar → grid → keyboard → clues, so typing sits right
   under the grid instead of below both clue lists. */
@media (max-width: 760px) {
  .crossword-game.is-touch .crossword-game__puzzle:not([hidden]) { display: flex; flex-direction: column; }
  .crossword-game.is-touch .crossword-game__layout { display: contents; }
  .crossword-game.is-touch .crossword-game__bar { order: 0; }
  /* Leave room for the clue bar + keyboard so all three fit on screen. */
  .crossword-game.is-touch .crossword-game__grid-scroll { order: 1; max-height: max(240px, calc(100vh - 340px)); }
  .crossword-game.is-touch .crossword-game__keyboard { order: 2; margin: .75rem auto 1rem; width: 100%; }
  .crossword-game.is-touch .crossword-game__clues { order: 3; }
}
@media (max-width: 560px) {
  .crossword-game__fields { grid-template-columns: 1fr; }
  .crossword-game__field:last-of-type { grid-column: auto; }
  .crossword-game__current { font-size: .92rem; }
}
