/* Game UI (public/js/games/*). Shared by the dev preview and, from F4, the student pages.
   Uses the role variables of base.css; the old WordNerd look: wood, amber, dark board. */

.g-status { margin: 0 0 14px; color: var(--c-accent); font-weight: 600; min-height: 1.5em; }
/* text fields inside games (secret word guess, drowning answer) */
.cw-guess, .dr-input {
  font: inherit; padding: 8px 12px; border-radius: var(--wn-radius-sm);
  border: 1px solid var(--c-wood-line); background: var(--c-field); color: var(--c-field-text);
}
.btn-small { padding: 6px 14px; font-size: .9rem; }
.btn-ghost { background: transparent; }
.btn:disabled { opacity: .45; cursor: default; }

@keyframes g-shake { 0%, 100% { transform: translateX(0); } 20%, 60% { transform: translateX(-7px); } 40%, 80% { transform: translateX(7px); } }
@keyframes g-pop { 0% { transform: scale(1); } 40% { transform: scale(1.06); } 100% { transform: scale(1); } }
.is-wrong { animation: g-shake .35s ease; }
.is-pop { animation: g-pop .35s ease; }

/* ---------- chips and drag and drop (matching, gapfill) ---------- */
.chip-bank {
  display: flex; flex-wrap: wrap; gap: 8px; padding: 12px; min-height: 58px; margin-bottom: 16px;
  border: 2px dashed var(--c-wood-line); border-radius: var(--wn-radius-md); background: rgb(0 0 0 / .15);
}
.chip-bank.is-over { border-color: var(--c-accent); }
.chip {
  display: inline-block; padding: 7px 14px; border-radius: 999px; cursor: grab; user-select: none; touch-action: none;
  background: linear-gradient(#b06a33, #8a4f26); color: var(--wn-amber-500); border: 1px solid var(--wn-wood-line);
  font: 600 1rem var(--wn-font-body); box-shadow: 0 2px 0 var(--wn-wood-700);
  transition: transform .12s ease, box-shadow .12s ease;
}
.chip:hover { transform: translateY(-1px); }
.chip.is-selected { outline: 3px solid var(--c-accent-strong); outline-offset: 2px; }
.chip.is-dragging { opacity: .25; }
.chip[data-locked] { cursor: default; }
.dnd-ghost { transform: rotate(-3deg) scale(1.08); box-shadow: 0 10px 24px rgb(0 0 0 / .45); cursor: grabbing; }
.has-selection [data-drop]:not(.is-done) { outline: 2px dashed rgb(248 184 86 / .45); outline-offset: 2px; }

/* ---------- memory ---------- */
.mem-board {
  --n: 4;
  display: grid; grid-template-columns: repeat(var(--n), 1fr); gap: clamp(5px, 1.4vw, 10px);
  width: min(100%, 620px, calc(100vh - 220px)); margin: 0 auto; perspective: 900px;
}
.mem-card { aspect-ratio: 1; padding: 0; border: 0; background: none; cursor: pointer; font: inherit; }
.mem-inner { position: relative; width: 100%; height: 100%; transform-style: preserve-3d; transition: transform .5s cubic-bezier(.3,.7,.3,1.2); }
.mem-card.is-up .mem-inner { transform: rotateY(180deg); }
.mem-back, .mem-face, .mem-logo {
  position: absolute; inset: 0; border-radius: var(--wn-radius-md); backface-visibility: hidden;
  display: grid; place-items: center; overflow: hidden;
}
.mem-back, .mem-logo {
  background:
    repeating-linear-gradient(90deg, rgb(255 255 255 / .04) 0 3px, transparent 3px 11px),
    linear-gradient(160deg, #b06a33, #7a4420);
  border: 2px solid var(--wn-wood-line); box-shadow: inset 0 0 0 4px rgb(0 0 0 / .12), 0 3px 0 var(--wn-wood-700);
}
/* the logo PNG has wide transparent margins: draw it larger than the card and let the card clip it */
.mem-back img, .mem-logo img { width: 112%; max-width: none; height: auto; filter: drop-shadow(0 2px 2px rgb(0 0 0 / .35)); transform: rotate(-8deg); }
.mem-back::after, .mem-logo::after { content: ''; position: absolute; inset: 7%; border: 2px solid rgb(248 184 86 / .35); border-radius: calc(var(--wn-radius-md) - 4px); }
/* the centre tile of an odd board is not a card: dark, flat, dashed frame, no wood */
.mem-logo { position: relative; aspect-ratio: 1; background: var(--c-bg-deep); border: 2px dashed rgb(248 184 86 / .4); box-shadow: none; }
.mem-logo::after { display: none; }
.mem-logo img { transform: rotate(-8deg) scale(.9); opacity: .8; }
.mem-face {
  transform: rotateY(180deg); padding: 6%; text-align: center; color: var(--c-field-text);
  background: var(--c-field); border: 2px solid var(--wn-amber-500); box-shadow: 0 3px 0 var(--wn-wood-700);
}
.mem-face.mem-term { background: #fff3d6; }
.mem-text {
  display: block; width: 100%; max-height: 100%; overflow: hidden; line-height: 1.15; overflow-wrap: anywhere; hyphens: auto;
  font: 600 clamp(11px, calc(min(620px, 92vw) / var(--n) / 6.5), 19px) var(--wn-font-body);
}
.mem-card.is-matched .mem-face { border-color: var(--c-ok); animation: mem-glow .8s ease; }
.mem-card.is-matched { cursor: default; opacity: .72; transition: opacity .6s .5s; }
@keyframes mem-glow { 0% { box-shadow: 0 0 0 0 rgb(114 217 10 / .9); transform: scale(1); } 50% { transform: scale(1.07); } 100% { box-shadow: 0 0 0 14px rgb(114 217 10 / 0); transform: scale(1); } }

/* ---------- matching ---------- */
.match-list { display: grid; gap: 10px; counter-reset: def; }
.match-card {
  display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; align-items: center;
  padding: 12px 14px; border-radius: var(--wn-radius-md); background: var(--c-field); color: var(--c-field-text);
  border: 2px solid transparent; box-shadow: 0 3px 0 var(--wn-wood-700); transition: border-color .15s, background .2s;
}
.match-num {
  grid-row: span 2; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  background: var(--wn-wood-500); color: var(--wn-amber-500); font-weight: 600;
}
.match-def { font-size: 1rem; }
.match-slot {
  height: 34px; border: 2px dashed #c9a87c; border-radius: 999px; min-width: 120px; justify-self: start; width: min(220px, 100%);
}
.match-card .chip { justify-self: start; }
.match-card.is-over { border-color: var(--c-accent-strong); }
.match-card.is-over .match-slot { background: rgb(248 184 86 / .25); }
.match-card.is-done { background: #e6f7d2; border-color: var(--c-ok); }
.match-card.is-done .match-num { background: var(--c-ok); color: var(--wn-board-900); }
.match-card.is-wrong { border-color: var(--c-error); }

/* ---------- word search ---------- */
.ws-layout { display: flex; flex-wrap: wrap; gap: 18px; align-items: flex-start; }
.ws-board { position: relative; width: min(100%, 560px); user-select: none; -webkit-user-select: none; }
.ws-grid { display: grid; grid-template-columns: repeat(var(--n), 1fr); background: var(--c-field); border-radius: var(--wn-radius-sm); box-shadow: 0 4px 0 var(--wn-wood-700); }
.ws-cell {
  aspect-ratio: 1; display: grid; place-items: center; color: var(--c-field-text); cursor: pointer;
  font: 600 clamp(11px, calc(min(560px, 92vw) / var(--n) * .5), 22px) var(--wn-font-body);
}
.ws-overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.ws-overlay line { opacity: .55; }
.ws-live { stroke: var(--wn-orange-500); opacity: .45 !important; }
.ws-found { animation: ws-draw .3s ease; }
@keyframes ws-draw { from { opacity: 0; } }
.ws-clues { margin: 0; padding-left: 22px; columns: 2 140px; }
.ws-clues li { margin-bottom: 4px; transition: opacity .3s; }
.ws-clues li.is-found { text-decoration: line-through; text-decoration-color: var(--c-accent); opacity: .5; }

/* ---------- crossword ---------- */
.cw-layout { display: flex; flex-wrap: wrap; gap: 22px; align-items: flex-start; }
.cw-grid { --cell: min(36px, calc((100vw - 2 * var(--wn-space) - 70px) / var(--w))); display: grid; gap: 3px; }
.cw-row { display: flex; align-items: center; }
.cw-num { width: 24px; text-align: right; margin-right: 6px; color: var(--c-text-muted); font-size: .85rem; }
.cw-cells { display: flex; gap: 3px; margin-left: calc(var(--offset) * (var(--cell) + 3px)); }
.cw-cell {
  width: var(--cell); height: var(--cell); padding: 0; text-align: center; caret-color: transparent;
  font: 600 calc(var(--cell) * .55) var(--wn-font-body); text-transform: uppercase;
  border-radius: 4px; border: 1px solid var(--wn-wood-line); background: var(--c-field); color: var(--c-field-text);
}
.cw-cell:focus { outline: 3px solid var(--c-accent-strong); outline-offset: 0; background: #fff; }
.cw-cell.is-hidden-col { background: #f7d79b; }
.cw-cell.is-revealed { color: #8a4f26; }
.cw-row.is-solved .cw-cell { background: #dff5c6; border-color: var(--c-ok); }
.cw-row.is-solved .cw-cell.is-hidden-col { background: #b8e986; }
.g-crossword.is-complete .cw-cell.is-hidden-col { background: var(--wn-amber-500); animation: g-pop .5s ease; }
.cw-row.is-shown .cw-cell { color: #9a8a74; background: #efe6d6; }
.cw-secret {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin: 0 0 18px; padding: 12px 14px;
  border-radius: var(--wn-radius-md); background: rgb(0 0 0 / .2); border: 1px solid var(--wn-wood-line);
}
.cw-secret-label { font-family: var(--wn-font-display); color: var(--c-accent); }
.cw-secret-tiles { display: flex; gap: 4px; }
.cw-secret-tile {
  width: 30px; height: 34px; display: grid; place-items: center; border-radius: 4px;
  background: #f7d79b; color: var(--wn-board-900); font: 600 1.05rem var(--wn-font-body);
}
.g-crossword.is-complete .cw-secret-tile { background: var(--wn-amber-500); }
.cw-guess-form { display: flex; gap: 6px; flex: 1 1 220px; }
.cw-guess { flex: 1 1 120px; min-width: 0; text-transform: uppercase; letter-spacing: .1em; }
.cw-clues { margin: 0; padding-left: 22px; max-width: 440px; }
.cw-clues li { margin-bottom: 4px; }

/* ---------- hangman (balloons) ---------- */
.hm-layout { display: grid; grid-template-columns: minmax(180px, 300px) 1fr; gap: 20px; align-items: start; }
@media (max-width: 640px) { .hm-layout { grid-template-columns: 1fr; } .hm-scene { max-width: 240px; margin: 0 auto; } }
.hm-scene { width: 100%; height: auto; overflow: visible; }
.hm-bunch { transition: transform .6s cubic-bezier(.3,.7,.4,1); }
.hm-string { stroke: #d8c7a8; stroke-width: 1.2; }
.hm-balloon { animation: hm-bob 3s ease-in-out infinite; animation-delay: var(--d); transform-box: view-box; }
@keyframes hm-bob { 50% { transform: translateY(-4px) rotate(1.5deg); } }
.hm-balloon.is-popped { animation: hm-pop .35s ease forwards; }
@keyframes hm-pop { 0% { transform: scale(1); opacity: 1; } 45% { transform: scale(1.35); opacity: .9; } 100% { transform: scale(.2); opacity: 0; } }
.hm-bunch.is-falling { animation: hm-fall .9s cubic-bezier(.5,0,.9,.6) forwards; }
@keyframes hm-fall { to { transform: translateY(88px) rotate(14deg); } }
.hm-bunch.is-flying { animation: hm-fly 1.6s ease-in forwards; }
@keyframes hm-fly { to { transform: translateY(-420px); } }
.hm-progress { display: flex; justify-content: center; gap: 8px; margin-top: 8px; }
.hm-dot { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--wn-wood-line); background: transparent; }
.hm-dot.is-won { background: var(--c-ok); border-color: var(--c-ok); }
.hm-dot.is-lost { background: var(--c-error); border-color: var(--c-error); }
.hm-word.is-solved .hm-slot { color: var(--c-ok); border-bottom-color: var(--c-ok); }
.hm-clue { margin: 0 0 8px; color: var(--c-text-muted); }
.hm-clue::before { content: 'Clue: '; color: var(--c-accent); }
.hm-word { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 18px; }
.hm-slot {
  width: 1.6em; height: 1.9em; display: grid; place-items: center; font: 600 1.5rem var(--wn-font-body);
  border-bottom: 3px solid var(--c-accent); color: var(--c-text);
}
.hm-slot.is-fixed { border-bottom-color: transparent; width: .8em; }
.hm-slot.is-reveal { color: #ff8a8a; }
.hm-keys { display: grid; grid-template-columns: repeat(auto-fill, minmax(38px, 1fr)); gap: 5px; max-width: 520px; }
.hm-key {
  aspect-ratio: 1; border-radius: 8px; border: 1px solid var(--wn-wood-line); cursor: pointer;
  background: linear-gradient(#b06a33, #8a4f26); color: var(--wn-amber-500); font: 600 1rem var(--wn-font-body);
  box-shadow: 0 2px 0 var(--wn-wood-700);
}
.hm-key.is-hit { background: var(--c-ok); color: var(--wn-board-900); }
.hm-key.is-miss { background: #5a2a24; color: #c98d85; }
.hm-key:disabled { cursor: default; box-shadow: none; }

/* ---------- gapfill (cloze text) ---------- */
.gf-text {
  line-height: 2.5; font-size: 1.08rem; padding: 18px 20px; margin: 0 0 16px;
  background: var(--c-field); color: var(--c-field-text); border-radius: var(--wn-radius-md); box-shadow: 0 4px 0 var(--wn-wood-700);
}
.gf-gap {
  display: inline-flex; align-items: center; justify-content: center; min-width: 110px; min-height: 38px; vertical-align: middle;
  margin: 0 3px; border: 2px dashed #c9a87c; border-radius: 999px; position: relative;
}
.gf-gap.is-over { border-color: var(--c-accent-strong); background: rgb(248 184 86 / .25); }
.gf-gap:has(.chip) { border-style: solid; border-color: transparent; }
.gf-gap .chip { margin: -2px; }
.gf-gap.is-right .chip { background: var(--c-ok); color: var(--wn-board-900); box-shadow: none; }
.gf-gap.is-wrong .chip { background: #c0392b; color: #fff; text-decoration: line-through; box-shadow: none; }
.gf-gap.is-wrong:not(:has(.chip)) { border-color: #c0392b; }
.gf-fix { position: absolute; left: 50%; top: 100%; transform: translate(-50%, -4px); font-size: .8rem; line-height: 1.2; color: #1d7a1d; font-weight: 600; white-space: nowrap; }
.gf-fix.is-inside { position: static; transform: none; font-size: .95rem; padding: 0 12px; }
.g-gapfill.is-checked .gf-text { line-height: 2.9; }

/* ---------- drowning (telephone box) ---------- */
.dr-layout { display: grid; grid-template-columns: minmax(140px, 220px) 1fr; gap: 24px; align-items: center; }
@media (max-width: 560px) { .dr-layout { grid-template-columns: 120px 1fr; gap: 14px; } }
.dr-box { width: 100%; height: auto; filter: drop-shadow(0 6px 0 rgb(0 0 0 / .3)); }
.dr-level { transition: transform .25s linear; }
.dr-wave { animation: dr-wave 2.4s linear infinite; }
@keyframes dr-wave { to { transform: translateX(-20px); } }
.dr-bubble { fill: rgb(255 255 255 / .55); animation: dr-bubble 3.2s ease-in infinite; animation-delay: var(--d); transform-box: fill-box; }
@keyframes dr-bubble { 0% { transform: translateY(0); opacity: 0; } 15% { opacity: 1; } 100% { transform: translateY(-190px); opacity: 0; } }
.dr-cap { animation: dr-bob 2.4s ease-in-out infinite; }
@keyframes dr-bob { 50% { transform: translateY(2px) rotate(-6deg); } }
.dr-box.is-drain .dr-water { animation: dr-drain .5s ease; }
@keyframes dr-drain { 40% { filter: brightness(1.35); } }
.dr-box.is-full .dr-wave, .dr-box.is-full .dr-cap { animation-play-state: paused; }
.dr-prompt { font: 600 clamp(1.3rem, 4.5vw, 1.9rem) var(--wn-font-body); color: var(--c-accent); margin: 0 0 14px; min-height: 1.3em; }
.dr-prompt.is-new { animation: g-pop .3s ease; }
.dr-form { display: flex; gap: 8px; flex-wrap: wrap; }
.dr-input { flex: 1 1 160px; font-size: 1.15rem; padding: 10px 14px; }
.dr-input.is-wrong { border-color: var(--c-error); }
.dr-actions { display: flex; gap: 8px; }
