/* ========================================
   Word Search – Styles
   Mobile-first · dark by default · matches the AK Games look
======================================== */

:root {
  --bg: #0f0f1a;
  --card: #1a1a2e;
  --surface: #26264a;
  --surface-2: #20203c;
  --accent: #7c5cff;
  --accent-2: #ff6b9d;
  --text: #eeeef5;
  --muted: #9a9cb8;
  --correct: #4ecca3;
  --wrong: #e94560;
  --gold: #f9c74f;
  --backdrop: rgba(0, 0, 0, 0.7);
  --radius: 14px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  --line-opacity: 0.5;
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #f4f1ea;
  --card: #ffffff;
  --surface: #e8e4f3;
  --surface-2: #f3f0fb;
  --accent: #6a45f0;
  --accent-2: #d63a78;
  --text: #1f2233;
  --muted: #5d6275;
  --correct: #1f9e76;
  --wrong: #d63a55;
  --gold: #b7791f;
  --backdrop: rgba(20, 20, 40, 0.5);
  --shadow: 0 6px 24px rgba(40, 40, 80, 0.12);
  --line-opacity: 0.42;
  color-scheme: light;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.5;
}

a { color: inherit; }
button, select { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
[hidden] { display: none !important; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

.skip-link {
  position: absolute; left: 12px; top: -60px; z-index: 300;
  background: var(--accent); color: #fff; padding: 10px 14px; border-radius: 8px; font-weight: 700;
}
.skip-link:focus { top: 12px; }

/* ---------- Header ---------- */
/* Not sticky: a pinned header would cover the top row of the grid when the page is scrolled */
.site-header {
  position: relative; z-index: 50; width: 100%;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid color-mix(in srgb, var(--muted) 22%, transparent);
  padding-top: env(safe-area-inset-top);
}
.site-header-inner {
  max-width: 960px; margin: 0 auto; padding: 8px 12px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; min-width: 0; }
.brand img { border-radius: 8px; flex-shrink: 0; }
.brand-name { font-size: 1.3rem; font-weight: 800; letter-spacing: 0.3px; white-space: nowrap; }
.header-actions { display: flex; gap: 4px; flex-shrink: 0; }
.icon-btn {
  width: 42px; height: 42px; border: none; border-radius: 50%;
  background: var(--surface); font-size: 1.05rem; cursor: pointer;
}

/* ---------- Card ---------- */
.container {
  width: calc(100% - 24px); max-width: 960px; margin: 14px 12px 0;
  background: var(--card); border-radius: var(--radius); padding: 16px;
  box-shadow: var(--shadow);
}

.mode-tabs {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px;
  background: var(--surface); border-radius: 12px; margin-bottom: 12px;
}
.tab {
  border: none; background: transparent; min-height: 44px; border-radius: 9px;
  font-weight: 600; cursor: pointer; color: var(--muted);
}
.tab.active { background: var(--card); color: var(--text); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15); }
.badge { margin-left: 4px; color: var(--correct); font-weight: 800; }

.options { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.options select {
  width: 100%; min-height: 44px; padding: 8px 10px; border-radius: 10px;
  border: 1px solid transparent; background: var(--surface); cursor: pointer;
}

.strip { display: grid; grid-template-columns: repeat(4, 1fr); text-align: center; margin-bottom: 10px; }
.strip > div { display: flex; flex-direction: column; }
.strip-label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); }
.strip-value { font-size: 1.05rem; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- Play layout ---------- */
.play-layout { display: grid; gap: 14px; }

.round-info { text-align: center; font-size: 0.85rem; color: var(--muted); margin-bottom: 6px; }

.board {
  --n: 10;
  position: relative;
  width: min(100%, 560px);
  aspect-ratio: 1;
  margin: 0 auto;
  border-radius: 12px;
  background: var(--surface-2);
  container-type: inline-size;
  touch-action: none;             /* drags select letters instead of scrolling */
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}
.board:focus-visible { outline-offset: 4px; }

.lines, .grid { position: absolute; inset: 0; width: 100%; height: 100%; }
.lines { overflow: visible; }

.grid { display: grid; grid-template-columns: repeat(var(--n), 1fr); grid-template-rows: repeat(var(--n), 1fr); }

.cell {
  display: grid; place-items: center;
  font-weight: 800;
  font-size: calc(100cqw / var(--n) * 0.5);
  line-height: 1;
  border-radius: 50%;
  position: relative;
  transition: color 0.15s ease, transform 0.15s ease;
}

.cell.in-word { color: var(--text); }
.cell.anchor { background: color-mix(in srgb, var(--gold) 45%, transparent); }
.cell.cursor { box-shadow: inset 0 0 0 3px var(--gold); }
.cell.hint { animation: hint-pulse 0.9s ease-in-out 5; }
@keyframes hint-pulse {
  0%, 100% { box-shadow: inset 0 0 0 0 transparent; transform: scale(1); }
  50% { box-shadow: inset 0 0 0 4px var(--gold); transform: scale(1.18); }
}
.cell.celebrate { animation: cell-hop 0.5s ease both; }
@keyframes cell-hop {
  0% { transform: translateY(0) scale(1); }
  40% { transform: translateY(-24%) scale(1.25); color: var(--gold); }
  100% { transform: translateY(0) scale(1); }
}

/* Highlight capsules (SVG, units = cells) */
.lines line { stroke-linecap: round; stroke-width: 0.78; }
.lines .found { stroke-opacity: var(--line-opacity); }
.lines .found.new { animation: line-in 0.35s ease-out; }
@keyframes line-in { from { stroke-width: 0.2; stroke-opacity: 0.9; } }
.lines .active { stroke: var(--gold); stroke-opacity: 0.55; }
.lines .active.bad { stroke: var(--wrong); animation: shake 0.3s ease; }
@keyframes shake { 25% { transform: translateX(-0.15px); } 75% { transform: translateX(0.15px); } }

.message { text-align: center; min-height: 24px; margin-top: 8px; color: var(--muted); font-size: 0.95rem; }
.message.good { color: var(--correct); font-weight: 700; }
.message.bad { color: var(--wrong); }

/* ---------- Word list ---------- */
.side-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 6px; }
.side-head h2 { font-size: 1rem; }
.progress-text { color: var(--muted); font-weight: 700; font-variant-numeric: tabular-nums; }
.progress-bar { height: 6px; border-radius: 3px; background: var(--surface); overflow: hidden; margin-bottom: 10px; }
.progress-bar span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width 0.3s ease; }

.word-list { list-style: none; display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.word-list li {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 10px; border-radius: 999px; background: var(--surface);
  font-weight: 700; font-size: 0.9rem; letter-spacing: 0.5px;
}
.word-list .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); opacity: 0.4; }
.word-list li.found { color: var(--muted); text-decoration: line-through; text-decoration-thickness: 2px; }
.word-list li.found .dot { opacity: 1; }
.word-list li.just-found { animation: pop 0.4s ease; }
@keyframes pop { 50% { transform: scale(1.15); } }

.controls { display: flex; gap: 8px; }
.controls > * { flex: 1; }

.btn, .btn-secondary {
  border: none; font-weight: 700; border-radius: 10px; cursor: pointer; min-height: 44px;
  transition: transform 0.12s ease, filter 0.15s ease;
}
.btn { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; padding: 12px 26px; font-size: 1.05rem; }
.btn:hover { filter: brightness(1.1); }
.btn-secondary { background: var(--surface); padding: 10px 14px; font-size: 0.9rem; }
.btn-secondary:disabled { opacity: 0.45; cursor: default; }
.btn:active, .btn-secondary:active:not(:disabled) { transform: scale(0.97); }
.link-btn {
  background: none; border: none; color: var(--muted); text-decoration: underline;
  text-underline-offset: 3px; cursor: pointer; padding: 10px 2px; font-size: inherit;
}

/* ---------- Footer ---------- */
.site-footer {
  width: 100%; max-width: 960px; margin-top: auto;
  padding: 24px 12px calc(20px + env(safe-area-inset-bottom));
  text-align: center; color: var(--muted); font-size: 0.85rem;
}
.footer-links { display: flex; justify-content: center; flex-wrap: wrap; gap: 4px 18px; margin-bottom: 6px; }
.footer-links a { color: var(--muted); text-underline-offset: 3px; padding: 10px 2px; }
.footer-links a:hover, .link-btn:hover { color: var(--text); }
.footer-links > :not([hidden]) ~ :not([hidden])::before {
  content: "|"; display: inline-block; margin-right: 18px;
  color: color-mix(in srgb, var(--muted) 50%, transparent); text-decoration: none;
}
.footer-meta { font-size: 0.78rem; }

/* ---------- Modals ---------- */
.modal {
  position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center;
  padding: 20px; background: var(--backdrop); animation: fade 0.2s ease;
}
.modal.hidden { display: none; }
@keyframes fade { from { opacity: 0; } }
.modal-content {
  position: relative; width: 100%; max-width: 380px; max-height: calc(100vh - 40px); overflow-y: auto;
  background: var(--card); padding: 30px 24px 24px; border-radius: var(--radius);
  text-align: center; box-shadow: var(--shadow); animation: rise 0.25s ease;
}
@keyframes rise { from { transform: translateY(16px); opacity: 0; } }
.modal-close {
  position: absolute; top: 6px; right: 6px; width: 44px; height: 44px; border: none; background: none;
  font-size: 1.1rem; color: var(--muted); cursor: pointer; border-radius: 50%;
}
.modal-content h2 { font-size: 1.6rem; margin-bottom: 6px; }
.result-time { font-size: 2.6rem; font-weight: 900; font-variant-numeric: tabular-nums; color: var(--gold); line-height: 1.2; }
.result-best { color: var(--correct); font-weight: 800; margin-bottom: 4px; }
.modal-detail { color: var(--muted); margin-bottom: 4px; }
.modal-stats { color: var(--muted); font-size: 0.85rem; margin-bottom: 18px; }
.modal-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

.stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 12px; }
.stats-grid div { background: var(--surface); border-radius: 10px; padding: 10px 8px; }
.stats-grid dd { font-size: 1.35rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.stats-grid dt { font-size: 0.78rem; color: var(--muted); }

.help-content { text-align: left; }
.help-content h2 { text-align: center; }
.help-content h3 { font-size: 1rem; margin: 14px 0 6px; }
.help-content ul { padding-left: 20px; display: grid; gap: 6px; }
.help-content .modal-detail { margin-top: 14px; }

.confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 200; display: none; }
.confetti.active { display: block; }

/* ---------- Wider screens: board + word list side by side ---------- */
@media (min-width: 760px) {
  .play-layout { grid-template-columns: minmax(0, 1fr) 250px; align-items: start; }
  .board { width: min(100%, 560px, calc(100vh - 250px)); min-width: 300px; }
  .word-list { flex-direction: column; flex-wrap: nowrap; }
  .word-list.many { display: grid; grid-template-columns: 1fr 1fr; }
  .word-list.many li { font-size: 0.78rem; padding: 4px 8px; }
  .controls { flex-direction: column; }
  .play-layout:has(.word-list.many) { grid-template-columns: minmax(0, 1fr) 300px; }
}

/* Phones: five header buttons leave no room for the title – keep it for screen readers */
@media (max-width: 440px) {
  .brand-name { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .icon-btn { width: 40px; height: 40px; }
}

@media (max-width: 380px) {
  .container { width: calc(100% - 16px); margin: 10px 8px 0; padding: 12px 10px; }
  .icon-btn { width: 38px; height: 38px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- Levels: level chip + tier colours ---------- */
.level-options { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.level-chip { display: flex; align-items: center; gap: 10px; }
.level-number { font-size: 1.15rem; font-weight: 900; }
.tier-pill {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  font-size: 0.75rem; font-weight: 800; letter-spacing: 0.3px; color: #10101c;
}
.tier-starter { background: #90be6d; }
.tier-easy { background: #4cc9f0; }
.tier-medium { background: #f9c74f; }
.tier-hard { background: #f8961e; }
.tier-expert { background: #ff6b9d; }

/* ---------- Age picker (first launch + settings) ---------- */
.age-hero { font-size: 2.6rem; line-height: 1; margin-bottom: 6px; }
.age-options { display: grid; gap: 8px; margin-top: 14px; }
.age-btn {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px;
  width: 100%; min-height: 56px; padding: 10px 14px; text-align: left;
  border: 2px solid transparent; border-radius: 12px; background: var(--surface); cursor: pointer;
  transition: border-color 0.15s ease, transform 0.12s ease;
}
.age-btn:hover { border-color: var(--accent); }
.age-btn:active { transform: scale(0.98); }
.age-btn[aria-pressed="true"] { border-color: var(--gold); }
.age-icon { font-size: 1.5rem; }
.age-label { font-weight: 800; font-size: 1.05rem; }
.age-tier { font-size: 0.78rem; color: var(--muted); }
.age-options.compact .age-btn { min-height: 46px; padding: 6px 12px; }

.settings-content { text-align: left; }
.settings-content h2 { text-align: center; }
.settings-content h3 { font-size: 1rem; margin: 16px 0 4px; }
.switch-row { display: flex; align-items: center; gap: 10px; cursor: pointer; padding: 6px 0; }
.switch-row input { width: 20px; height: 20px; accent-color: var(--accent); }

/* ---------- Level map ---------- */
.map-content { max-width: 480px; }
.map-body { text-align: left; display: grid; gap: 16px; margin-top: 10px; }
.map-band h3 { font-size: 0.9rem; margin-bottom: 8px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.map-range { color: var(--muted); font-weight: 600; font-size: 0.8rem; }
.map-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.map-level {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 52px; border: 2px solid transparent; border-radius: 10px;
  background: var(--surface); cursor: pointer; font-weight: 800;
}
.map-level:hover:not(:disabled) { border-color: var(--accent); }
.map-level.current { border-color: var(--gold); }
.map-level:disabled { opacity: 0.4; cursor: default; }
.map-n { font-size: 1rem; line-height: 1.1; }
.map-stars { font-size: 0.6rem; line-height: 1.2; min-height: 0.8rem; letter-spacing: -1px; }

/* ---------- Result stars ---------- */
.result-stars { font-size: 2.2rem; letter-spacing: 4px; margin: 2px 0 2px; }

/* ---------- Kid mode (under 10): bigger letters, chunkier highlights ---------- */
body.kid .cell { font-size: calc(100cqw / var(--n) * 0.6); }
body.kid .lines line { stroke-width: 0.86; }
body.kid .word-list li { font-size: 1rem; padding: 6px 12px; }
