/* =====================================================================
   Word search — Jeana's layout, made playable
   =====================================================================

   Rebuilt to match the graphic she sent, measured from it:

     - pale blue-white ground with soft circles bleeding off the corners
     - LEFT: orange letter-spaced eyebrow, very large bold grey headline,
       short thick orange rule, three-line standfirst, six white pill chips
       in a 3 x 2 arrangement, small grey sign-off at the foot
     - RIGHT: white card, generous radius and soft shadow, holding a square
       monospaced letter grid
     - found words are capsules over the letters, alternating orange and
       blue, rounded at the ends of the run

   Inline section, not a modal: it reads as part of the page the way her
   graphic reads as one composition.
   ===================================================================== */

.crh-ws {
  position: relative;

  /* FULL BLEED out of the 760px article column.
     The section sits inside .crh-article, which the body section constrains
     to 760px. 100vw with a negative margin of half the difference pushes the
     band back out to the full viewport.

     max-width:100vw is deliberate belt-and-braces: without it, a page that
     has a vertical scrollbar can end up with 100vw wider than the document
     and gain a horizontal scrollbar. Overflow is asserted at four widths in
     the verifier rather than assumed. */
  width: 100vw;
  max-width: 100vw;
  margin-left: calc(50% - 50vw);
  margin-right: calc(50% - 50vw);

  padding: 66px 0;
  border-radius: 0;
  background: linear-gradient(135deg, #f4f8fb 0%, #eef5fa 55%, #f7fafc 100%);
  overflow: hidden;
}

/* The decorative circles in her graphic — one top-left, one bottom-centre. */
.crh-ws__blob {
  position: absolute;
  border-radius: 50%;
  background: #dbe9f4;
  opacity: .65;
  pointer-events: none;
}

.crh-ws__blob--a { width: 300px; height: 300px; top: -150px; left: -110px; }
.crh-ws__blob--b { width: 420px; height: 420px; bottom: -260px; left: 32%; opacity: .45; }

.crh-ws__inner {
  position: relative;
  z-index: 1;

  /* Match the site header's container exactly: 1280px with 12px gutters,
     measured off the live header rather than assumed. The content lines up
     with the nav above it even though the band behind runs full width. */
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 12px;

  display: grid;
  grid-template-columns: minmax(0, 0.92fr) minmax(0, 1fr);
  gap: 56px;
  align-items: center;
}

/* --- left column ---------------------------------------------------- */

.crh-ws__eyebrow {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .17em;
  text-transform: uppercase;
  color: var(--crh-orange);
  margin: 0 0 18px;
}

.crh-ws__title {
  font-size: 46px;
  font-weight: 700;
  line-height: 1.08;
  letter-spacing: -0.01em;
  color: #5a5a5a;
  margin: 0 0 22px;
  text-transform: uppercase;
}

.crh-ws__rule {
  display: block;
  width: 88px;
  height: 6px;
  border-radius: 3px;
  background: var(--crh-orange);
  margin: 0 0 24px;
}

.crh-ws__standfirst {
  font-size: 17px;
  line-height: 1.75;
  color: #5f6b72;
  /* Tightened from 30px. The chips are a continuation of this sentence —
     "similar words" and then the words themselves — so a large gap read as a
     break between two unrelated things. */
  margin: 0 0 18px;
}

/* Her chips: white pills, 3 across, 2 rows. */
.crh-ws__chips {
  list-style: none;
  margin: 0 0 18px;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.crh-ws__chip {
  display: inline-flex;
  align-items: center;
  gap: 0;
  background: #fff;
  border: 1px solid #e3ecf2;
  border-radius: 500px;
  padding: 12px 20px;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: .08em;
  color: #5f6b72;
  box-shadow: 0 1px 3px rgba(99, 99, 99, .07);
  transition: all .2s ease;
}

.crh-ws__chip-tick {
  width: 0;
  height: 14px;
  overflow: hidden;
  color: var(--crh-orange);
  transition: width .2s ease, margin .2s ease;
}

.crh-ws__chip-tick svg { width: 14px; height: 14px; display: block; }

.crh-ws__chip.is-found {
  background: var(--crh-orange-soft);
  border-color: var(--crh-orange);
  color: var(--crh-orange-dark);
}

.crh-ws__chip.is-found .crh-ws__chip-tick { width: 14px; margin-right: 8px; }

/* Struck through, so a found term reads as done at a glance. */
.crh-ws__chip.is-found .crh-ws__chip-text { text-decoration: line-through; opacity: .75; }

.crh-ws__status {
  font-size: 13px;
  font-weight: 600;
  color: var(--crh-grey);
  margin: 0 0 26px;
  display: flex;
  align-items: center;
  /* The gap now only ever falls between the sentence and the button, because
     the sentence is a single span. */
  gap: 12px;
}

/* Keeps "1 of 6 found" on one line with normal word spacing. */
.crh-ws__count { white-space: nowrap; }

.crh-ws__reset {
  background: var(--crh-orange);
  color: #fff;
  border: 0;
  border-radius: 500px;
  padding: 8px 16px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

.crh-ws__reset[hidden] { display: none; }

.crh-ws__signoff {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .12em;
  line-height: 1.85;
  text-transform: uppercase;
  color: #8a949a;
  margin: 0;
}

/* --- right column: the grid card ------------------------------------ */

.crh-ws__card {
  background: #fff;
  border-radius: 22px;
  padding: 26px;
  box-shadow: 0 10px 34px rgba(80, 110, 130, .12);
}

.crh-ws__gridbox { position: relative; }

/* ---------------------------------------------------------------------
   Definition toast
   ---------------------------------------------------------------------
   Sits over the foot of the grid when a word is found, then fades. Inside
   the grid box rather than the page so it reads as feedback from the puzzle,
   and positioned in percentages for the same reason as the drag hint — under
   ScrollSmoother's transform, measured coordinates cannot be trusted here.
   --------------------------------------------------------------------- */

.crh-ws__toast {
  position: absolute;
  left: 4%;
  right: 4%;
  bottom: 4%;
  z-index: 5;
  padding: 14px 18px;
  border-radius: 12px;
  background: rgba(38, 56, 66, .95);
  color: #fff;
  box-shadow: 0 10px 28px rgba(0, 0, 0, .22);
  pointer-events: none;

  /* Hidden by default, and not just transparent: visibility keeps it out of
     the accessibility tree and off the pointer between reveals. */
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px);
  transition: opacity .28s ease, transform .28s ease, visibility 0s linear .28s;
}

.crh-ws__toast.is-visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  transition: opacity .22s ease, transform .22s cubic-bezier(.34, 1.4, .64, 1), visibility 0s;
}

.crh-ws__toast-term {
  display: block;
  margin: 0 0 4px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: .13em;
  text-transform: uppercase;
  color: #ffb27a;
}

.crh-ws__toast-def {
  display: block;
  margin: 0;
  font-size: 13.5px;
  line-height: 1.5;
  color: rgba(255, 255, 255, .93);
}

@media (max-width: 767.98px) {
  .crh-ws__toast { padding: 11px 13px; border-radius: 10px; }
  .crh-ws__toast-term { font-size: 10.5px; }
  .crh-ws__toast-def { font-size: 12px; line-height: 1.45; }
}

@media (prefers-reduced-motion: reduce) {
  .crh-ws__toast { transition: opacity .2s ease, visibility 0s linear .2s; transform: none; }
  .crh-ws__toast.is-visible { transform: none; }
}

.crh-ws__grid {
  display: grid;
  grid-template-columns: repeat(var(--crh-ws-size), minmax(0, 1fr));
  /* No gap: the capsules over found words must run continuously, which they
     cannot do across gutters. Spacing comes from the cells' own aspect. */
  gap: 0;
  /* The drag gesture must not scroll the page on touch. */
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

/* ---------------------------------------------------------------------
   Drag hint
   ---------------------------------------------------------------------
   A word search looks like a picture of a word search, so nothing signals
   that the letters can be dragged. A cursor traces one short horizontal
   run, with a capsule trailing behind it, then rests — repeating on a long
   cycle so it reads as a prompt rather than a distraction.

   Everything is expressed in PERCENTAGES of the grid. This theme runs
   ScrollSmoother, and inside its transform getBoundingClientRect returns
   coordinates that do not correspond to where things paint (cells have
   measured at y = -9,949px on a 1,100px viewport), so anything derived from
   measurement would be positioned wrongly. Percentages are immune.

   JS removes the hint on first pointerdown — once someone has worked it out,
   the prompt is noise.
   --------------------------------------------------------------------- */

.crh-ws__hint-drag {
  position: absolute;
  /* Row 5 of 18, starting at column 4 — over letters, clear of the edges. */
  top: 27.7%;
  left: 22.2%;
  width: 33.3%;   /* six cells */
  height: 5.55%;  /* one cell   */
  pointer-events: none;
  z-index: 3;
}

.crh-ws__hint-trail {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  border-radius: 999px;
  background: rgba(255, 136, 51, .28);
  animation: crh-ws-trail 4.2s ease-in-out infinite;
}

.crh-ws__hint-cursor {
  position: absolute;
  top: 46%;
  left: 0;
  width: 19px;
  height: 19px;
  /* Same grey as the real cursor image on .crh-ws__cell (#59666e). If one
     changes, change both — the whole point is that the animation shows the
     reader the cursor they are about to see. */
  color: #59666e;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .28));
  animation: crh-ws-cursor 4.2s ease-in-out infinite;
}

.crh-ws__hint-cursor svg { width: 100%; height: 100%; display: block; }

@keyframes crh-ws-cursor {
  0%, 8%    { transform: translate(0, 0) scale(1); opacity: 0; }
  12%       { transform: translate(0, 0) scale(1); opacity: 1; }
  18%       { transform: translate(0, 0) scale(.86); opacity: 1; }
  46%       { transform: translate(calc(600% - 19px), 0) scale(.86); opacity: 1; }
  52%       { transform: translate(calc(600% - 19px), 0) scale(1); opacity: 1; }
  64%       { transform: translate(calc(600% - 19px), 0) scale(1); opacity: 0; }
  100%      { transform: translate(0, 0) scale(1); opacity: 0; }
}

@keyframes crh-ws-trail {
  0%, 16%  { width: 0; opacity: 0; }
  20%      { width: 5.5%; opacity: 1; }
  46%      { width: 100%; opacity: 1; }
  60%      { width: 100%; opacity: 1; }
  68%      { width: 100%; opacity: 0; }
  100%     { width: 0; opacity: 0; }
}

/* Gone for good once the reader interacts. */
.crh-ws.is-touched .crh-ws__hint-drag { display: none; }

@media (prefers-reduced-motion: reduce) {
  .crh-ws__hint-trail,
  .crh-ws__hint-cursor { animation: none; }
  .crh-ws__hint-cursor { opacity: .75; }
  .crh-ws__hint-trail { width: 100%; opacity: .5; }
}

.crh-ws__cell {
  position: relative;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Courier New', Courier, monospace;
  font-size: clamp(10px, 1.05vw, 15px);
  font-weight: 700;
  color: #6b7780;

  /* The real cursor matches the one in the hint animation.
     The hint traces a filled arrow across the letters, but the grid was set
     to `cursor: pointer` — the pointing hand — so the moment a reader moved
     onto the grid the cursor changed into something other than what the
     animation had just shown them. This is the SAME arrow path as the hint
     SVG, inlined as a cursor image, with the hotspot at the arrow's tip.
     `grab` is the fallback for any browser that refuses the image: still a
     drag affordance, never the I-beam.

     The SVG is deliberately small (24px) — cursor images above ~32px are
     ignored outright by some browsers. */
  cursor: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'><path d='M5 3l14 8.5-6.2 1.6L9.6 19z' fill='%2359666e' stroke='white' stroke-width='1.4' stroke-linejoin='round'/></svg>") 5 3, grab;

  z-index: 1;
  /* Transform and colour only — both composited, so hovering across a
     324-cell grid stays smooth. */
  transition: transform .16s cubic-bezier(.34, 1.56, .64, 1), color .16s ease;
}

/* While dragging, the arrow closes into a grabbing state so the gesture
   reads as "holding" the run of letters. */
.crh-ws__grid:active .crh-ws__cell,
.crh-ws__cell.is-selecting {
  cursor: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'><path d='M5 3l14 8.5-6.2 1.6L9.6 19z' fill='%23ff8833' stroke='white' stroke-width='1.4' stroke-linejoin='round'/></svg>") 5 3, grabbing;
}

.crh-ws__cell.is-placeholder { cursor: default; }

/* ---------------------------------------------------------------------
   Hover and motion
   ---------------------------------------------------------------------
   A word search looks like a picture of a word search. These make the
   letters feel touchable: each one lifts and warms under the cursor, the
   grid deals itself in on load, and a found word gives a short confirming
   pop. Nothing loops — ambient looping motion next to body copy is a
   distraction, so every animation here is a response to something.

   Hover is behind a fine-pointer query: on touch there is no hover state,
   and applying one leaves a letter stuck looking active after a tap.
   --------------------------------------------------------------------- */

@media (hover: hover) and (pointer: fine) {
  .crh-ws__cell:not(.is-placeholder):hover {
    transform: scale(1.32);
    color: var(--crh-orange);
    z-index: 4;
  }
}

/* The letter under the cursor while dragging. */
.crh-ws__cell.is-selecting {
  transform: scale(1.16);
  color: #2f4451;
}

/* Deal the grid in.
   A short stagger down the rows, so the board assembles rather than simply
   appearing. Runs once on load and once more when a new grid is generated. */
.crh-ws__grid.is-dealing .crh-ws__cell {
  animation: crh-ws-deal .34s cubic-bezier(.2, .9, .3, 1) backwards;
}

@keyframes crh-ws-deal {
  from { opacity: 0; transform: scale(.55); }
  to   { opacity: 1; transform: scale(1); }
}

/* Found: a quick pop, then settle. */
.crh-ws__cell.is-found {
  color: #3f4b52;
  animation: crh-ws-pop .42s cubic-bezier(.34, 1.56, .64, 1) backwards;
}

@keyframes crh-ws-pop {
  0%   { transform: scale(1); }
  38%  { transform: scale(1.3); }
  100% { transform: scale(1); }
}

/* The highlight draws itself along the word rather than flicking on. */
.crh-ws__line--found {
  stroke-dasharray: var(--crh-ws-len, 20);
  stroke-dashoffset: var(--crh-ws-len, 20);
  animation: crh-ws-draw .46s cubic-bezier(.3, .8, .3, 1) forwards;
}

@keyframes crh-ws-draw {
  to { stroke-dashoffset: 0; }
}

/* A chip ticking off is worth a beat of motion — it is the reward. */
.crh-ws__chip.is-found {
  animation: crh-ws-chip .5s cubic-bezier(.34, 1.56, .64, 1);
}

@keyframes crh-ws-chip {
  0%   { transform: scale(1); }
  35%  { transform: scale(1.07); }
  100% { transform: scale(1); }
}

@media (hover: hover) and (pointer: fine) {
  .crh-ws__chip:not(.is-found):hover {
    transform: translateY(-2px);
    border-color: var(--crh-blue-deep, #b8d1dc);
    box-shadow: 0 4px 12px rgba(99, 99, 99, .12);
  }
}

@media (prefers-reduced-motion: reduce) {
  .crh-ws__cell,
  .crh-ws__chip { transition: none; }
  .crh-ws__grid.is-dealing .crh-ws__cell,
  .crh-ws__cell.is-found,
  .crh-ws__chip.is-found { animation: none; }
  .crh-ws__line--found { stroke-dasharray: none; stroke-dashoffset: 0; animation: none; }
  .crh-ws__cell:not(.is-placeholder):hover { transform: none; }
}

/* ---------------------------------------------------------------------
   Selection and found-word highlights
   ---------------------------------------------------------------------
   Drawn as SVG lines over the grid rather than as a background on each
   cell. Per-cell backgrounds are fine for horizontal and vertical runs,
   where neighbouring squares share an edge — but on a DIAGONAL the squares
   only touch at their corners, so a found word rendered as a visible
   staircase of separate blocks. A single line with a round cap is one
   continuous capsule at any angle.
   --------------------------------------------------------------------- */

.crh-ws__lines {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
  overflow: visible;
}

.crh-ws__line {
  /* The viewBox is one unit per cell, so stroke-width is a FRACTION of a
     cell: 0.78 leaves a little air on each side, matching the proportion in
     her graphic. */
  stroke-width: 0.78;
  stroke-linecap: round;
  fill: none;
}

.crh-ws__line--sel { stroke: #cfe4f3; }

.crh-ws__line--found { stroke: #ffd9bd; }
.crh-ws__line--found.tone-blue { stroke: #c9e3f5; }

/* Letters sit above the highlight. */
.crh-ws__cell { z-index: 1; }

.crh-ws__cell.is-wrong::before {
  content: "";
  position: absolute;
  inset: 8%;
  border-radius: 4px;
  background: #f2c9c9;
  z-index: -1;
}

.crh-ws__hint {
  margin: 18px 2px 0;
  font-size: 12.5px;
  color: #9aa6ad;
  text-align: center;
}

/* --- responsive ------------------------------------------------------ */

@media (max-width: 1199.98px) {
  .crh-ws { padding: 52px 0; }
  .crh-ws__inner { gap: 38px; padding: 0 24px; }
  .crh-ws__title { font-size: 38px; }
}

@media (max-width: 991.98px) {
  /* Bootstrap's lg breakpoint is 992px, so this must be 991.98 — a 990px cap
     leaves a live 2px window where columns have stacked but the mobile rules
     have not applied. That off-by-two has shipped a visible bug on this site
     before. */
  .crh-ws__inner { grid-template-columns: minmax(0, 1fr); gap: 32px; }
  .crh-ws__title { font-size: 34px; }
  .crh-ws__blob--b { display: none; }
  /* The card would otherwise stretch the full width of a tablet and the
     letters become absurdly large. */
  .crh-ws__card { max-width: 560px; }
}

@media (max-width: 767.98px) {
  .crh-ws { padding: 34px 0; }
  .crh-ws__inner { padding: 0 18px; }
  .crh-ws__title { font-size: 27px; }
  .crh-ws__standfirst { font-size: 15.5px; margin-bottom: 22px; }
  .crh-ws__rule { width: 66px; height: 5px; margin-bottom: 18px; }
  .crh-ws__chips { gap: 8px; }
  .crh-ws__chip { padding: 10px 14px; font-size: 11px; letter-spacing: .05em; }
  .crh-ws__card { padding: 14px; border-radius: 16px; max-width: none; }
  .crh-ws__cell { font-size: clamp(8px, 2.5vw, 13px); }
  .crh-ws__signoff { font-size: 11.5px; }
  .crh-ws__hint-cursor { width: 16px; height: 16px; }
  @keyframes crh-ws-cursor {
    0%, 8%  { transform: translate(0, 0) scale(1); opacity: 0; }
    12%     { transform: translate(0, 0) scale(1); opacity: 1; }
    18%     { transform: translate(0, 0) scale(.86); opacity: 1; }
    46%     { transform: translate(calc(600% - 16px), 0) scale(.86); opacity: 1; }
    52%     { transform: translate(calc(600% - 16px), 0) scale(1); opacity: 1; }
    64%     { transform: translate(calc(600% - 16px), 0) scale(1); opacity: 0; }
    100%    { transform: translate(0, 0) scale(1); opacity: 0; }
  }
}
