/**
 * 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;
}

/* Easy (10×10) and Medium (15×15): grid and clues side by side when the
   puzzle area is wide enough (a container query, so it follows the space the
   game actually has, not the window), the grid taking whatever width the clue
   column leaves. Narrower, and always for Hard (20×20), the clues stack under
   the grid so its squares stay a comfortable size. */
.crossword-game__puzzle { container-type: inline-size; }
.crossword-game__layout { display: grid; gap: 1.25rem; align-items: start; }
@container (min-width: 700px) {
  .crossword-game__puzzle:is(.is-size-10, .is-size-15) .crossword-game__layout { grid-template-columns: minmax(0, 1fr) minmax(220px, 280px); }
  /* Side by side, the two clue lists share the grid's height. */
  .crossword-game__puzzle:is(.is-size-10, .is-size-15) .crossword-game__clue-list { max-height: 210px; }
}

/* The grid is sized by crossword.js to fit this box exactly, so it never
   scrolls. Square corners: rounding here would clip the corner squares. */
.crossword-game__grid-scroll {
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}
/* Puzzles saved before the sizes changed (25×25, 40×40) may still scroll. */
.crossword-game__puzzle:is(.is-size-25, .is-size-40) .crossword-game__grid-scroll {
  overflow: auto;
  max-height: 78vh;
  -webkit-overflow-scrolling: touch;
}

/* Grid lines are each square's own right and bottom border (plus the outer
   frame), not gaps between squares: borders snap to whole screen pixels, so
   no line disappears at fractional zoom or device scaling. */
.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-top: 2px solid var(--cw-block);
  border-left: 2px solid var(--cw-block);
  background: var(--cw-block);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
.crossword-game__cell {
  position: relative;
  box-sizing: border-box;
  display: grid;
  place-items: center;
  border-right: 1px solid var(--cw-block);
  border-bottom: 1px solid var(--cw-block);
  background: #fff;
  cursor: pointer;
  transition: background-color .12s ease;
}
/* The last column and row carry the 2px outer frame. */
.crossword-game__cell.is-col-last { border-right-width: 2px; }
.crossword-game__cell.is-row-last { border-bottom-width: 2px; }
.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: clamp(7px, calc(var(--cw-cell) * .36), 16px);
  line-height: 1;
  font-weight: 700;
  color: #2a1f55;
}
.crossword-game__letter {
  font-size: max(11px, calc(var(--cw-cell) * .52)); /* stays readable on small (phone) squares */
  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__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;
}
/* Stacked under the grid, the across and down lists sit side by side. */
.crossword-game__clues { grid-template-columns: 1fr 1fr; }
@container (min-width: 700px) {
  .crossword-game__puzzle:is(.is-size-10, .is-size-15) .crossword-game__clues { grid-template-columns: 1fr; }
}
.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__clues { grid-template-columns: 1fr; }
  .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; }
}

/* ===== Reveal word countdown =============================================
   Daily puzzles allow a limited number of word reveals (the plugin keeps the
   count). The button carries a "N left" badge; the "one left" modal is the
   shared games dialog (.games-dialog in games-arcade.css). */
.crossword-game__reveal-word {
  display: inline-flex;
  align-items: center;
  gap: .55rem;
}
.crossword-game__reveal-count {
  display: inline-block;
  min-width: 4.4em;
  padding: .15em .6em;
  border-radius: 999px;
  background: var(--ga-lilac-100, #efe8ff);
  color: var(--ga-purple-900, #1f0766);
  font-size: .8em;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1.5;
  text-align: center;
}
.crossword-game__reveal-count[hidden] { display: none; }
.crossword-game__reveal-word.is-last .crossword-game__reveal-count {
  background: var(--ga-coral, #ff7a7a);
  color: var(--ga-purple-900, #1f0766);
}
.crossword-game__reveal-word:disabled .crossword-game__reveal-count {
  background: transparent;
  box-shadow: inset 0 0 0 1px currentColor;
}

/* Newspaper look: paper pill, solid ink for the last one. */
html[data-games-look="newspaper"] .crossword-game__reveal-count { background: #eeeae2; color: #34312c; }
html[data-games-look="newspaper"] .crossword-game__reveal-word.is-last .crossword-game__reveal-count {
  background: var(--np-ink, #34312c);
  color: #fff;
}
