/* ---------- Game pages (loaded only on game pages) ---------- */
.ghead { display: flex; gap: 16px; align-items: center; margin: 4px 0 14px; }
.ghead__img { width: 120px; height: 72px; border-radius: 12px; object-fit: cover; flex: none; box-shadow: var(--shadow); }
.ghead h1 { margin: 0 0 2px; font-size: clamp(1.5rem, 4vw, 2rem); }
.ghead p { margin: 0; color: var(--muted); font-size: 0.95rem; }
@media (max-width: 480px) { .ghead__img { width: 84px; height: 50px; } .ghead p { display: none; } }

.game { padding: 14px; max-width: 620px; margin: 0 auto 28px; user-select: none; -webkit-user-select: none; }
.btn--game { background: var(--game); color: var(--game-ink); box-shadow: none; }
.btn--game:hover { background: var(--game); filter: brightness(1.06); }
.btn--big { font-size: 1.1rem; padding: 14px 32px; }

.gbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 14px; }
.gtabs { display: inline-flex; background: var(--surface-2); border-radius: 999px; padding: 4px; }
.gtabs button {
  font: inherit; font-weight: 700; font-size: 0.9rem; border: 0; background: none; color: var(--text);
  padding: 7px 14px; border-radius: 999px; cursor: pointer;
}
.gtabs button[aria-selected="true"] { background: var(--game); color: var(--game-ink); }
.gtabs small { opacity: 0.75; font-weight: 600; }
.gbar__tools { display: flex; gap: 4px; }
.gbar__tools .icon-btn { font-weight: 800; font-size: 1.05rem; text-decoration: none; color: var(--text); border: 1px solid var(--border); }

.gboard { display: flex; flex-direction: column; align-items: center; gap: 14px; min-height: 360px; }
.gloading, .gstatus { color: var(--muted); text-align: center; margin: 40px 0; }
.gdone { display: flex; justify-content: center; }

/* Keyboard */
.kbd { width: 100%; max-width: 520px; display: flex; flex-direction: column; gap: 6px; }
.kbd__row { display: flex; gap: 5px; justify-content: center; }
.kbd__key {
  flex: 1 1 0; min-width: 0; height: 52px; border: 0; border-radius: 8px; cursor: pointer;
  background: var(--surface-2); color: var(--text); font: inherit; font-weight: 800; font-size: 1rem;
  text-transform: uppercase; touch-action: manipulation; padding: 0;
}
.kbd__key--wide { flex: 1.6 1 0; font-size: 0.75rem; }
.kbd__key:active { transform: translateY(1px); }
.kbd__key[data-state="correct"] { background: var(--good); color: #fff; }
.kbd__key[data-state="present"] { background: var(--warn); color: #1b1433; }
.kbd__key[data-state="absent"] { background: #8b8698; color: #fff; opacity: 0.55; }
.kbd__key:disabled { cursor: default; }

/* Toasts */
.toasts { position: fixed; top: 84px; left: 0; right: 0; z-index: 60; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; }
.toast {
  background: var(--text); color: var(--bg); font-weight: 700; padding: 9px 16px; border-radius: 10px;
  box-shadow: var(--shadow-lift); animation: toast-in 0.18s ease-out;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } }

/* Result / stats dialog */
.gdialog {
  border: 0; border-radius: 20px; padding: 0; width: min(420px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgb(0 0 0 / 0.35);
}
.gdialog::backdrop { background: rgb(20 15 40 / 0.55); }
.gdialog__head { display: flex; justify-content: space-between; align-items: center; padding: 16px 16px 0 22px; }
.gdialog__head h2 { margin: 0; font-size: 1.35rem; }
.gdialog > div:last-child { padding: 8px 22px 22px; }
.gstats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; text-align: center; margin: 14px 0; }
.gstats strong { display: block; font-size: 1.6rem; line-height: 1.1; }
.gstats span { font-size: 0.72rem; color: var(--muted); }
.gresult__answer { font-size: 1.05rem; }
.gresult__actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.gresult__next { text-align: center; color: var(--muted); font-size: 0.9rem; margin-bottom: 0; }
.gresult__next strong { color: var(--text); font-variant-numeric: tabular-nums; }

.shake { animation: shake 0.35s; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

/* ---------- Word Guess ---------- */
.wg-grid { display: grid; gap: 6px; }
.wg-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.wg-cell {
  width: clamp(48px, 14vw, 60px); aspect-ratio: 1; display: grid; place-items: center;
  border: 2px solid var(--border); border-radius: 8px; font-size: 1.7rem; font-weight: 900; text-transform: uppercase;
  background: var(--surface); transition: background-color 0.25s, border-color 0.25s, color 0.25s;
}
.wg-cell[data-filled="1"] { border-color: var(--muted); }
.wg-cell[data-state="correct"] { background: var(--good); border-color: var(--good); color: #fff; }
.wg-cell[data-state="present"] { background: var(--warn); border-color: var(--warn); color: #1b1433; }
.wg-cell[data-state="absent"] { background: #8b8698; border-color: #8b8698; color: #fff; }

/* ---------- Hangman ---------- */
.hm-cat { margin: 0; color: var(--muted); }
.hm-art { width: min(240px, 60vw); height: auto; stroke: var(--text); stroke-width: 5; stroke-linecap: round; fill: none; }
.hm-body > * { opacity: 0; transition: opacity 0.25s; stroke: var(--game); }
.hm-body > .is-on { opacity: 1; }
.hm-word { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.hm-slot {
  width: clamp(28px, 8vw, 40px); height: 46px; border-bottom: 4px solid var(--text); display: grid; place-items: end center;
  font-size: 1.7rem; font-weight: 900; text-transform: uppercase; padding-bottom: 2px;
}
.hm-slot.is-open { border-color: var(--game); }
.hm-lives { margin: 0; font-weight: 700; }

/* ---------- Word Hive ---------- */
.hv-progress {
  display: flex; align-items: center; gap: 14px; width: 100%; max-width: 460px;
  background: none; border: 0; padding: 4px 0; cursor: pointer; font: inherit; color: var(--text);
}
.hv-rank { font-weight: 900; font-size: 1rem; min-width: 92px; text-align: left; }
.hv-track { position: relative; flex: 1; height: 28px; display: flex; align-items: center; justify-content: space-between; }
.hv-track::before { content: ""; position: absolute; left: 6px; right: 6px; height: 3px; background: var(--border); border-radius: 2px; }
.hv-fill {
  position: absolute; left: 6px; height: 3px; border-radius: 2px; background: var(--game);
  width: calc((100% - 12px) * var(--fill, 0)); transition: width 0.4s ease;
}
.hv-dot {
  position: relative; z-index: 1; width: 12px; height: 12px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--border); display: grid; place-items: center;
  font-size: 0.72rem; font-weight: 900; transition: all 0.25s ease;
}
.hv-dot.is-reached { background: var(--game); border-color: var(--game); }
.hv-dot.is-current {
  width: 30px; height: 30px; margin: 0 -9px; color: var(--game-ink);
  box-shadow: 0 0 0 4px var(--game-soft);
}
.hv-dot:last-child { border-radius: 4px; transform: rotate(45deg); }
.hv-dot:last-child.is-current { transform: none; border-radius: 50%; }
.hv-ranks { list-style: none; padding: 0; margin: 0; }
.hv-ranks li { display: flex; justify-content: space-between; padding: 8px 4px; border-bottom: 1px solid var(--border); color: var(--muted); }
.hv-ranks li.is-reached { color: var(--text); font-weight: 700; }
.hv-ranks li.is-reached span::before { content: "✓ "; color: var(--good); }

.hv-input {
  min-height: 52px; font-size: clamp(1.7rem, 7vw, 2.2rem); font-weight: 900; text-transform: uppercase;
  letter-spacing: 0.06em; display: flex; align-items: center; justify-content: center;
}
.hv-input .is-center { color: var(--game); -webkit-text-stroke: 1px #b45309; }
.hv-input .is-bad { color: var(--muted); opacity: 0.5; }
.hv-caret { width: 3px; height: 38px; background: var(--game); border-radius: 2px; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.hv-hive { width: min(290px, 76vw); height: auto; overflow: visible; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.hv-cell { cursor: pointer; outline: none; }
.hv-cell__in { transition: transform 0.12s ease; transform-box: fill-box; transform-origin: center; }
.hv-cell polygon {
  fill: var(--surface); stroke: var(--border); stroke-width: 2; stroke-linejoin: round;
  filter: drop-shadow(0 3px 0 rgb(27 20 51 / 0.12));
  transition: fill 0.15s;
}
.hv-cell text { font-size: 38px; font-weight: 900; fill: var(--text); pointer-events: none; font-family: var(--font); }
@media (hover: hover) { .hv-cell:hover polygon { fill: var(--surface-2); } }
.hv-cell:focus-visible polygon { stroke: var(--focus); stroke-width: 4; }
.hv-cell--center polygon { fill: var(--game); stroke: var(--game); }
.hv-cell--center:hover polygon { fill: var(--game); }
.hv-cell--center text { fill: var(--game-ink); }
.hv-cell.is-pressed .hv-cell__in { animation: hv-press 0.18s ease; }
@keyframes hv-press { 50% { transform: scale(0.9); } }
.hv-cell.is-shuffling text { animation: hv-fade 0.3s ease; }
@keyframes hv-fade { from { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .hv-cell.is-pressed .hv-cell__in, .hv-cell.is-shuffling text { animation: none; } }

.hv-controls, .sc-controls, .ld-tools { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.hv-controls .btn { min-width: 96px; }
.hv-shuffle { font-size: 1.3rem; min-width: 52px !important; padding-inline: 0; border-radius: 50%; aspect-ratio: 1; }
.hv-found { width: 100%; max-width: 480px; background: var(--surface-2); border-radius: 12px; padding: 10px 14px; }
.hv-found summary { cursor: pointer; font-weight: 700; }
.hv-found ul { list-style: none; padding: 0; margin: 8px 0 0; columns: 3 110px; font-weight: 600; text-transform: capitalize; }
.hv-found li { padding: 2px 0; break-inside: avoid; }
.hv-found .is-missed { color: var(--muted); opacity: 0.7; }
.hv-found .is-pangram { color: #b45309; font-weight: 900; }
.hv-reveal { font-size: 0.85rem; }

/* ---------- Word Scramble ---------- */
.sc-start { text-align: center; max-width: 360px; margin: 40px auto; }
.sc-head { display: flex; justify-content: space-between; width: 100%; max-width: 420px; font-weight: 800; font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.sc-head.is-low .sc-time { color: #dc2626; }
.sc-answer, .sc-tiles { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.sc-answer span {
  width: clamp(36px, 10vw, 48px); height: 52px; border-bottom: 4px solid var(--game); display: grid; place-items: center;
  font-size: 1.7rem; font-weight: 900; text-transform: uppercase;
}
.sc-answer span.is-hint { color: var(--muted); }
.sc-tile {
  width: clamp(40px, 11vw, 54px); height: 54px; border: 0; border-radius: 10px; cursor: pointer;
  background: var(--game); color: var(--game-ink); font: inherit; font-size: 1.6rem; font-weight: 900; text-transform: uppercase;
  box-shadow: 0 3px 0 rgb(0 0 0 / 0.2); touch-action: manipulation;
}
.sc-tile:disabled { opacity: 0.2; box-shadow: none; cursor: default; }
.sc-solved { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; max-width: 480px; }
.sc-solved li { background: var(--game-soft); padding: 4px 10px; border-radius: 99px; font-weight: 700; text-transform: uppercase; }

/* ---------- Word Search ---------- */
.ws-head { display: flex; justify-content: space-between; width: 100%; font-weight: 600; gap: 8px; flex-wrap: wrap; }
.ws-time { font-variant-numeric: tabular-nums; font-weight: 800; }
.ws-grid {
  display: grid; grid-template-columns: repeat(var(--n), 1fr); width: min(100%, 480px); aspect-ratio: 1;
  background: var(--surface); border: 2px solid var(--border); border-radius: 12px; padding: 4px; touch-action: none;
}
.ws-cell {
  display: grid; place-items: center; font-weight: 800; text-transform: uppercase; font-size: clamp(0.95rem, 4vw, 1.25rem);
  border-radius: 50%; cursor: pointer;
}
.ws-cell.is-found { background: var(--game-soft); color: var(--text); border-radius: 6px; }
.ws-cell.is-found[data-hue="1"] { background: rgb(22 163 74 / 0.2); }
.ws-cell.is-found[data-hue="2"] { background: rgb(225 29 116 / 0.18); }
.ws-cell.is-found[data-hue="3"] { background: rgb(255 183 3 / 0.3); }
.ws-cell.is-found[data-hue="4"] { background: rgb(124 58 237 / 0.2); }
.ws-cell.is-found[data-hue="5"] { background: rgb(249 115 22 / 0.22); }
.ws-cell.is-sel { background: var(--game); color: var(--game-ink); border-radius: 6px; }
.ws-list { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 6px 14px; justify-content: center; max-width: 480px; }
.ws-list li { font-weight: 700; text-transform: uppercase; }
.ws-list .is-found { text-decoration: line-through; color: var(--muted); }

/* ---------- Word Ladder ---------- */
.ld-info { text-align: center; margin: 0; max-width: 420px; }
.ld-steps { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; align-items: center; }
.ld-row { display: flex; gap: 6px; }
.ld-row span {
  width: 46px; height: 46px; display: grid; place-items: center; border-radius: 8px; border: 2px solid var(--border);
  font-size: 1.5rem; font-weight: 900; text-transform: uppercase; background: var(--surface);
}
.ld-row span.is-changed { background: var(--game-soft); border-color: var(--game); }
.ld-row.is-start span { background: var(--surface-2); }
.ld-row.is-target span { background: var(--game); color: var(--game-ink); border-color: var(--game); }
.ld-row.is-goal { margin-top: 10px; position: relative; }
.ld-row.is-goal::before { content: "⋮"; position: absolute; top: -18px; left: 50%; transform: translateX(-50%); color: var(--muted); }
.ld-row.is-input span { border-style: dashed; border-color: var(--muted); }

/* ---------- Copy + more games ---------- */
.game-copy { margin: 0 auto 24px; max-width: 46em; }
.game-copy h2 { font-size: 1.3rem; }
.games--small { grid-template-columns: repeat(auto-fill, minmax(min(100%, 160px), 1fr)); gap: 12px; }
.games--small .card { padding-bottom: 12px; }
.games--small .card h3 { font-size: 1rem; }

/* ---------- Phones: fit the whole game above the bottom ad ----------
   On phones the board, keyboard and controls must sit fully on screen with a
   clear, non-interactive gap above the fixed ad (AdSense asks for space
   between ads and game controls to avoid accidental clicks). Sizes scale
   with the visible height (dvh) so short phones still fit. */
@media (max-width: 560px) {
  main:has(> .wrap > .game) { padding-top: 10px; }
  .ghead { margin: 0 0 8px; gap: 10px; }
  .ghead__img { width: 56px; height: 34px; border-radius: 8px; }
  .ghead h1 { font-size: 1.3rem; }
  .game { padding: 10px; margin-bottom: 28px; }
  .gbar { margin-bottom: 8px; }
  .gtabs button { padding: 6px 12px; }
  .gboard { gap: 10px; min-height: 0; }
  .wg-grid, .wg-row { gap: 5px; }
  .wg-cell { width: clamp(34px, min(14vw, calc((100dvh - var(--anchor-h) - 380px) / 6.5)), 60px); font-size: 1.4rem; }
  .kbd { gap: 5px; }
  .kbd__key { height: clamp(38px, 5.8dvh, 52px); }
  .hm-art { width: auto; height: clamp(90px, calc(100dvh - var(--anchor-h) - 520px), 200px); }
  .hm-slot { height: 40px; }
  .hv-input { min-height: 40px; }
  .ld-info { font-size: 0.92rem; }
  .ld-steps { gap: 4px; }
  .ld-row span { width: 40px; height: 40px; font-size: 1.3rem; }
  .hv-hive { width: min(290px, 76vw, calc(100dvh - var(--anchor-h) - 385px)); }
}
