/* Word Search: a painted place behind a white board, big dark letters, and fat
   coloured bars round the words found.

   As in Word Wheel, the game inside the shell does not follow the site themes:
   what is behind it can be any colour, so each piece carries its own ground,
   dark glass or white. --ws-hue, the buttons' colour, is set by main.js for
   each scene. The dialogs are left to the theme. */

.word-search-page { margin: 0; }

.word-search-page .ws-shell {
  --ws-hue: 142;
  --ws-tile: hsl(var(--ws-hue) 62% 38%);
  --ws-tile-light: hsl(var(--ws-hue) 66% 52%);
  --ws-tile-dark: hsl(var(--ws-hue) 70% 24%);
  --ws-glass: rgba(10, 16, 34, 0.55);
  --ws-white: rgba(255, 255, 255, 0.92);
  --ws-ink: #241824;
  --ws-font: "Trebuchet MS", "Segoe UI", Roboto, sans-serif;

  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px 14px;
  background: var(--ground);
}


/* ---------------------------------------------------------------- the scene */

.ws-scene {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  background: #2f7233;
}

.ws-scene > div {
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 700ms ease;
}

.ws-scene > div.is-on { opacity: 1; }

.word-search-page .ws-shell > .ws-readout,
.word-search-page .ws-shell > .ws-main {
  position: relative;
  z-index: 1;
}


/* ------------------------------------------------------------- the numbers */

.word-search-page .ws-shell > .ws-readout {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  align-self: center;
  gap: 6px 20px;
  max-width: 100%;
  padding: 6px 20px;
  border-radius: 999px;
  background: var(--ws-glass);
  color: rgba(255, 255, 255, 0.84);
  box-sizing: border-box;
}

.ws-readout .ar-readout__item {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
}

.word-search-page .ws-readout b,
.word-search-page .ws-readout__tag {
  color: #fff;
  font-variant-numeric: tabular-nums;
}

.word-search-page .ws-readout__tag { font-weight: 700; }

.ws-purse > span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.word-search-page .ws-purse b { color: #ffd45e; }

.ws-purse i {
  display: inline-block;
  width: 1em;
  height: 1em;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff6c8 0 16%, #ffc83d 52%, #b87700 100%);
  box-shadow: 0 0 0 1px #8a5800, 0 1px 3px rgba(0, 0, 0, 0.4);
}


/* ------------------------------------------------------------------- layout */

.ws-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
}

/* The board and the list side by side. */
.ws-play {
  flex: 1;
  display: flex;
  justify-content: center;
  gap: 16px;
  min-width: 0;
  min-height: 0;
}

.ws-field {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  min-height: 0;
}

/* The box the board is fitted into: its own size is what the card is measured
   against, so the board is as big as the room allows, whatever the room. */
.ws-boardbox {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  min-height: 0;
  container-type: size;
}

.ws-card {
  width: min(100cqw, 100cqh);
  height: min(100cqw, 100cqh);
  padding: min(1.6cqmin, 14px);
  box-sizing: border-box;
  border-radius: min(3.5cqmin, 28px);
  background: var(--ws-white);
  box-shadow: 0 14px 40px rgba(4, 8, 20, 0.35);
}


/* ----------------------------------------------------- the letters in hand */

.ws-entry {
  display: flex;
  justify-content: center;
  min-height: 2.6rem;
}

.ws-staged {
  min-width: 4rem;
  max-width: 100%;
  padding: 0 1.2rem;
  border-radius: 999px;
  background: linear-gradient(180deg, var(--ws-tile-light), var(--ws-tile-dark));
  color: #fff;
  font: 800 1.6rem/2.6rem var(--ws-font);
  letter-spacing: 0.14em;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  box-shadow: 0 3px 10px rgba(4, 8, 20, 0.4);
  box-sizing: border-box;
}

.ws-staged:empty { visibility: hidden; }


/* ---------------------------------------------------------------- the board */

.ws-board {
  display: block;
  width: 100%;
  height: 100%;
  /* A drag across the board is a word, never a scroll or a selection. */
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  cursor: pointer;
}

.ws-board:focus-visible {
  outline: 3px solid var(--ws-tile);
  outline-offset: 4px;
  border-radius: 8px;
}

.ws-letter {
  fill: var(--ws-ink);
  font: 800 58px var(--ws-font);
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
  transform-box: fill-box;
  transform-origin: center;
  animation: ws-arrive 360ms cubic-bezier(0.3, 1.6, 0.5, 1) backwards;
}

/* The biggest boards give more of each square to its letter. */
.ws-board[data-size="15"] .ws-letter { font-size: 64px; }
.ws-board[data-size="18"] .ws-letter { font-size: 70px; }

.ws-letter.is-marked { fill: #fff; }

.ws-letter.is-pop { animation: ws-pop 420ms ease; }

@keyframes ws-arrive { from { transform: scale(0); } }

@keyframes ws-pop {
  45% { transform: scale(1.45); }
}

.ws-bar {
  fill: none;
  opacity: 0.82;
  pointer-events: none;
}

.ws-bar.is-fresh { animation: ws-bar-in 420ms ease; }

@keyframes ws-bar-in {
  from { opacity: 0; stroke-width: 130px; }
}

.ws-bar--live {
  stroke: var(--ws-tile);
  opacity: 0.88;
}

.ws-bar--wrong {
  stroke: #d23b3b;
  animation: ws-wrong 600ms ease forwards;
}

@keyframes ws-wrong {
  0%   { transform: translateX(0); }
  20%  { transform: translateX(-14px); }
  40%  { transform: translateX(12px); }
  60%  { transform: translateX(-8px); opacity: 0.7; }
  100% { transform: translateX(0); opacity: 0; }
}

.ws-hint {
  fill: none;
  stroke: #d98200;
  stroke-linecap: round;
  pointer-events: none;
  animation: ws-hint 1.1s ease-in-out infinite;
}

circle.ws-hint { stroke-width: 9; }

line.ws-hint {
  /* A pale band with its first and last letter plain to see. */
  stroke: #ffd45e;
  opacity: 0.65;
  stroke-dasharray: 30 95;
}

@keyframes ws-hint {
  50% { opacity: 0.3; }
}

.ws-cursor {
  fill: none;
  stroke: var(--ws-tile-dark);
  stroke-width: 7;
  pointer-events: none;
}

/* The bow a finished board takes. */
.ws-card.is-solved { animation: ws-bow 700ms ease; }

@keyframes ws-bow {
  35% { transform: scale(1.04) rotate(-1deg); }
  70% { transform: scale(0.99) rotate(0.6deg); }
}


/* ----------------------------------------------------------------- the list */

.ws-list {
  flex: 0 1 clamp(12rem, 26vw, 24rem);
  align-self: center;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 100%;
  min-height: 0;
  margin-right: auto;
  padding: 12px 14px;
  border-radius: 20px;
  background: var(--ws-white);
  color: var(--ws-ink);
  box-shadow: 0 14px 40px rgba(4, 8, 20, 0.3);
  box-sizing: border-box;
}

.ws-list h2 {
  flex: none;
  margin: 0;
  padding: 8px 10px;
  border-radius: 12px;
  background: linear-gradient(180deg, var(--ws-tile-light), var(--ws-tile-dark));
  color: #fff;
  font: 800 1.35rem var(--ws-font);
  text-align: center;
}

.ws-list ul {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr));
  gap: 4px 6px;
  min-height: 0;
  margin: 0;
  padding: 2px;
  list-style: none;
  overflow-y: auto;
}

.ws-list:has(ul.is-long) { flex-basis: clamp(15.5rem, 30vw, 26rem); }

.ws-list ul.is-long { grid-template-columns: repeat(auto-fill, minmax(6.2rem, 1fr)); }

.word-search-page .ws-list li button {
  width: 100%;
  min-height: 2rem;
  padding: 3px 6px;
  border: 2px solid transparent;
  border-radius: 999px;
  background: none;
  color: var(--ws-ink);
  font: 800 1.08rem var(--ws-font);
  letter-spacing: 0.03em;
  cursor: pointer;
}

.word-search-page .ws-list ul.is-long li button { padding-inline: 2px; font-size: 0.9rem; }

.word-search-page .ws-list li button:hover { background: rgba(20, 32, 58, 0.08); }

.word-search-page .ws-list li button.is-picked { border-color: #d98200; background: #fff1c4; }

.word-search-page .ws-list li button.is-found {
  background: var(--ws-mark);
  text-decoration: line-through;
  text-decoration-thickness: 2px;
  cursor: default;
  animation: ws-pop 460ms ease 520ms backwards;
}

.ws-status {
  flex: none;
  min-height: 1.3em;
  margin: 0;
  color: #5a4a5a;
  font-size: 0.92rem;
  text-align: center;
  text-wrap: balance;
}


/* The photographer's signature, when a photograph is behind. */
.ws-credit {
  position: absolute;
  right: 6px;
  bottom: 2px;
  margin: 0;
  padding: 0 12px;
  border-radius: 999px;
  background: rgba(10, 16, 34, 0.34);
  color: rgba(255, 255, 255, 0.97);
  font-family: "Dancing Script", "Segoe Script", cursive;
  font-size: clamp(1.1rem, 2vw, 1.7rem);
  line-height: 1.4;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.7);
  pointer-events: none;
}


/* ---------------------------------------------------------------- the dock */

.word-search-page .ws-shell .hh-dock button {
  flex: 0 0 5.2rem;
  border: 2px solid rgba(255, 255, 255, 0.7);
  border-radius: 18px;
  background: linear-gradient(180deg, var(--ws-tile-light), var(--ws-tile-dark));
  color: #fff;
  box-shadow: 0 4px 10px rgba(4, 8, 20, 0.45);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

.word-search-page .ws-shell .hh-dock button:hover:not(:disabled) { filter: brightness(1.15); }


/* ----------------------------------------------- the screens over the scene */

.word-search-page .ws-shell:has(.ar-screen:not([hidden])) .ws-play { visibility: hidden; }

.word-search-page .ws-shell .ar-screen {
  background: transparent;
  backdrop-filter: none;
}

.word-search-page .ws-shell .ar-screen.is-page .ar-screen__panel {
  height: auto;
  max-height: 100%;
  margin-block: auto;
  padding: 0 14px;
  border-radius: 18px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  box-shadow: 0 14px 40px rgba(4, 8, 20, 0.45);
}

.word-search-page .ws-shell .ar-screen:not(.is-page) .ar-screen__panel {
  border: 3px solid #ffc83d;
  border-radius: 22px;
  background: color-mix(in srgb, var(--surface) 95%, transparent);
  box-shadow: 0 0 0 6px rgba(255, 200, 61, 0.28), 0 18px 50px rgba(4, 8, 20, 0.55);
}

.word-search-page .ws-shell .ar-tally__score b { font-size: 2.4rem; }
.word-search-page .ws-shell .ar-tally__stars .ar-star { width: 28px; height: 28px; }
.word-search-page .ws-shell .ar-tally__coins b { font-size: 1.6rem; }

.word-search-page .ws-shell .ar-tally__actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.word-search-page .ws-shell .ar-tally__actions .ar-primary {
  grid-column: 1 / -1;
  font-size: 1.1rem;
}

/* The subjects: as many across as fit. */
.ws-themes {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(8.5rem, 1fr));
  gap: 8px;
  width: 100%;
  padding-bottom: 14px;
}

.word-search-page .ws-themes button {
  min-height: 3rem;
  padding: 6px 10px;
  border: 1px solid var(--rule-strong);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.word-search-page .ws-themes button:hover { border-color: var(--accent); background: var(--accent-soft); }
.word-search-page .ws-themes button:first-child { border-style: dashed; }
.word-search-page .ws-themes button[aria-current] { border: 3px solid var(--accent); }


/* ---------------------------------------------------------------- the show */

.ws-splash,
.ws-fx {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.ws-splash { z-index: 5; }
.ws-splash[hidden] { display: none; }

.ws-fx {
  z-index: 6;
  overflow: hidden;
}

.ws-fx > span {
  position: absolute;
  left: 0;
  top: 0;
}

.ws-fly {
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  color: var(--ws-ink);
  font: 800 1.3rem/1 var(--ws-font);
  box-shadow: 0 3px 8px rgba(4, 8, 20, 0.35);
}

/* The pieces thrown by games/wordWheel/fx.js, which names them. */
.ws-fx > .ww-spark {
  width: 12px;
  height: 12px;
  margin: -6px 0 0 -6px;
  background: #fff3a8;
  filter: drop-shadow(0 0 4px #ffb300);
  clip-path: polygon(50% 0, 61% 39%, 100% 50%, 61% 61%,
                     50% 100%, 39% 61%, 0 50%, 39% 39%);
}

.ws-fx > .ww-praise {
  white-space: nowrap;
  font: 900 3rem var(--ws-font);
  color: #fff;
  -webkit-text-stroke: 7px #14203a;
  paint-order: stroke fill;
}


/* ---------------------------------------------------------------- dialogs */

.ws-dialog {
  width: min(32rem, calc(100vw - 32px));
  padding: 0 18px 18px;
  border: 1px solid var(--rule-strong);
  border-radius: 12px;
  background: var(--raised, var(--surface));
  color: var(--ink);
}

.ws-dialog::backdrop { background: var(--backdrop, rgba(0, 0, 0, 0.55)); }

.ws-dialog__head {
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  padding: 14px 0 10px;
  background: inherit;
  border-bottom: 1px solid var(--rule);
}

.ws-dialog__head h2 { flex: 1; margin: 0; font-size: 1.25rem; }

.ws-dialog__head button {
  min-width: 2.4rem;
  min-height: 2.4rem;
  border: 1px solid var(--rule-strong);
  border-radius: 8px;
  background: var(--button-bg, var(--surface));
  color: inherit;
  font-size: 1.2rem;
  cursor: pointer;
}

.ws-dialog__note { margin: 14px 0 0; color: var(--ink-muted); }

.ws-dialog__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 18px;
}

.ws-dialog__actions button {
  flex: 1 1 8rem;
  min-height: 2.8rem;
  padding: 0 0.9rem;
  border: 1px solid var(--rule-strong);
  border-radius: 8px;
  background: var(--button-bg, var(--surface));
  color: var(--button-ink, var(--ink));
  font: inherit;
  cursor: pointer;
}

.ws-dialog__actions button:hover { background: var(--accent-soft); }

.ws-dialog__actions .ws-primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 700;
}

.ws-dialog__actions .ws-primary:hover { background: var(--accent); filter: brightness(1.12); }

.ws-rules { margin: 4px 0 0; }

.ws-rules h3 {
  margin: 16px 0 4px;
  color: var(--accent);
  font-family: var(--font-display);
  font-size: 1rem;
}

.ws-rules p { margin: 0 0 6px; line-height: 1.5; }
.ws-rules ul { margin: 0 0 6px; padding-left: 1.2rem; }
.ws-rules li { margin: 0 0 4px; line-height: 1.45; }

#stats-body h3 { margin: 18px 0 0; font-size: 1.05rem; }

.word-search-page .stats-list {
  display: grid;
  grid-template-columns: 1fr auto;
  margin: 12px 0 0;
}

.word-search-page .stats-list dt,
.word-search-page .stats-list dd {
  margin: 0;
  padding: 7px 0;
  border-bottom: 1px solid var(--rule);
}

.word-search-page .stats-list dt { color: var(--ink-muted); }

.word-search-page .stats-list dd {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: right;
}


/* A short window: closer lines, so the list is all in view. */
@media (max-height: 46rem) {
  .ws-list ul { gap: 2px 6px; }

  .word-search-page .ws-list li button {
    min-height: 1.6rem;
    padding-block: 0;
    font-size: 0.98rem;
  }

  .ws-list h2 { padding-block: 4px; font-size: 1.15rem; }
}


/* ------------------------------------------------- upright: the list under */

@media (orientation: portrait), (max-width: 40rem) and (min-height: 501px) {
  .ws-play { flex-direction: column; gap: 8px; }

  .ws-boardbox { justify-content: center; }

  .ws-list,
  .ws-list:has(ul.is-long) {
    flex: 0 0 auto;
    align-self: stretch;
    max-height: 34%;
    margin: 0;
    padding: 8px 10px;
    gap: 4px;
  }

  .ws-list h2 { padding: 3px 8px; font-size: 1.05rem; }

  .ws-list ul,
  .ws-list ul.is-long {
    grid-template-columns: repeat(auto-fill, minmax(6.6rem, 1fr));
    gap: 1px 4px;
  }

  .word-search-page .ws-list li button,
  .word-search-page .ws-list ul.is-long li button {
    min-height: 1.7rem;
    padding: 1px 2px;
    font-size: 0.86rem;
  }
}


/* ---------------------------------------------------------------- phones */

@media (pointer: coarse) and (max-width: 720px), (pointer: coarse) and (max-height: 500px) {
  .word-search-page .ws-shell { gap: 4px; padding: 4px 6px 6px; }

  .word-search-page .ws-shell > .ws-readout {
    align-self: stretch;
    padding: 4px 8px;
    border-radius: 14px;
  }

  /* The code is in Menu. */
  .ws-readout__tag { display: none; }

  .ws-card { padding: 4px; border-radius: 12px; }

  .ws-entry { min-height: 2rem; }
  .ws-staged { font-size: 1.2rem; line-height: 2rem; }

  .ws-status { font-size: 0.8rem; }

  .ws-fx > .ww-praise { font-size: 2.2rem; }

  .word-search-page .ws-shell .hh-dock button { flex: 0 1 5.2rem; }
}

/* A phone on its side: every line of height goes to the board. */
@media (pointer: coarse) and (max-height: 500px) {
  .ws-status { display: none; }

  /* The buttons stand down the right-hand side. */
  .word-search-page .ws-main { flex-direction: row; }

  .word-search-page .ws-shell .hh-dock {
    flex-direction: column;
    justify-content: center;
  }

  .word-search-page .ws-shell .hh-dock button {
    flex: 0 0 auto;
    width: 4.4rem;
  }

  .ws-list,
  .ws-list:has(ul.is-long) { flex-basis: 34vw; padding: 6px 8px; }

  .ws-list h2 { padding: 2px 8px; font-size: 0.95rem; }

  .ws-list ul,
  .ws-list ul.is-long { grid-template-columns: repeat(auto-fill, minmax(6.4rem, 1fr)); }

  .word-search-page .ws-list li button,
  .word-search-page .ws-list ul.is-long li button { min-height: 1.6rem; font-size: 0.82rem; }
}


@media (prefers-reduced-motion: reduce) {
  .ws-scene > div { transition: none; }

  .ws-letter,
  .ws-letter.is-pop,
  .ws-bar.is-fresh,
  .ws-hint,
  .ws-card.is-solved,
  .word-search-page .ws-list li button.is-found { animation: none; }
}
