/* Word Search. Scoped to .ws. */
.ws { --line: #1c2b4a; --panel: #0b1328; --text: #dfe9ff; --muted: #8aa3c4; --accent: #55d6ff; --warm: #ffd166;
  position: relative; max-width: 1000px; margin: 0 auto; padding: 8px 4px 14px; color: var(--text);
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.ws [hidden] { display: none !important; }
.ws button, .ws select { font-family: inherit; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
.ws :focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ws-sr { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ---------- top bar ---------- */
.ws-top { display: flex; align-items: center; gap: 8px 10px; flex-wrap: wrap; margin: 0 0 12px; }
.ws-seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); }
.ws-segbtn { border: 0; background: transparent; color: var(--muted); font-weight: 650; font-size: 13.5px; padding: 0 14px; min-height: 36px; border-radius: 999px; cursor: pointer; transition: background-color .2s, color .2s; }
@media (hover: hover) { .ws-segbtn:hover:not(.is-on) { color: #fff; } }
.ws-segbtn.is-on { background: #e8edf2; color: #0b1328; }
.ws-diffs .ws-segbtn.is-on { background: var(--accent); color: #031520; }
.ws-ibtn { flex: none; width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; border: 1px solid #2a3b5f; background: transparent; color: #c9d7ef; cursor: pointer; transition: background-color .2s, color .2s; }
@media (hover: hover) { .ws-ibtn:hover { border-color: #5b7099; color: #fff; } }
.ws-ibtn svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; }

/* ---------- layout ---------- */
.ws-main { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 18px; align-items: start; }
.ws-boardwrap { min-width: 0; }
.ws-board { position: relative; width: 100%; max-width: min(640px, max(340px, calc(100vh - 236px))); margin: 0 auto; padding: 8px; border-radius: 18px; background: linear-gradient(180deg, #0d1730, #0a1226); border: 1px solid var(--line); box-shadow: 0 10px 30px rgba(0,0,0,0.35), inset 0 1px 0 rgba(255,255,255,0.04); }
.ws-grid { --n: 11; --cs: 40px; position: relative; width: 100%; aspect-ratio: 1; touch-action: none; cursor: pointer; border-radius: 12px; outline: none; }
.ws .ws-grid:focus-visible { outline: none; box-shadow: 0 0 0 2px rgba(85,214,255,0.7); }
.ws-cells { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(var(--n), minmax(0, 1fr)); grid-template-rows: repeat(var(--n), minmax(0, 1fr)); z-index: 2; pointer-events: none; }
.ws-cell { display: grid; place-items: center; min-width: 0; min-height: 0; font-weight: 750; font-size: calc(var(--cs) * 0.54); line-height: 1; color: #d3e1f7; letter-spacing: 0; border-radius: 50%; transition: color .15s, transform .15s cubic-bezier(.2,.8,.2,1); font-variant-numeric: tabular-nums; }
.ws-cell.got { color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,0.45); }
.ws-cell.on { color: #fff; transform: scale(1.12); }
.ws-cell.hint { box-shadow: 0 0 0 2.5px var(--warm), 0 0 14px rgba(255,209,102,0.55); color: var(--warm); animation: ws-hint 1.6s ease-in-out infinite; }
.ws-cell.hint.got { color: #fff; }
.ws-cell.hintpop { animation: ws-hintpop .5s cubic-bezier(.2,.9,.3,1.3), ws-hint 1.6s ease-in-out .5s infinite; }
.ws.kbd .ws-grid:focus .ws-cell.cur { box-shadow: inset 0 0 0 2.5px var(--accent); background: rgba(85,214,255,0.12); }
.ws-cell.wave { animation: ws-wave .42s cubic-bezier(.2,.8,.2,1) both; }
.ws-cells.deal .ws-cell { animation: ws-deal .45s cubic-bezier(.2,.8,.2,1) both; }

.ws-caps { position: absolute; inset: 0; z-index: 1; pointer-events: none; }
.ws-cap { position: absolute; border-radius: 999px; background: color-mix(in srgb, var(--c) 40%, transparent); box-shadow: inset 0 0 0 2px var(--c), 0 0 10px color-mix(in srgb, var(--c) 30%, transparent); }
.ws-cap.pop { animation: ws-pop .38s cubic-bezier(.2,.9,.3,1.25) both; }
.ws-cap.shine { animation: ws-shine .8s ease both; }
.ws-livecap { --c: #e8edf2; background: rgba(232,237,242,0.2); box-shadow: inset 0 0 0 2px rgba(232,237,242,0.85); z-index: 3; }
.ws-livecap.pending { animation: ws-pulse 1.1s ease-in-out infinite; }
.ws-miss { --c: #ff6b81; background: rgba(255,107,129,0.22); box-shadow: inset 0 0 0 2px rgba(255,107,129,0.8); animation: ws-miss .46s ease both; }
.ws-fx { position: absolute; inset: 0; z-index: 4; pointer-events: none; overflow: visible; }
.ws-fx i { position: absolute; left: 50%; top: 45%; width: 9px; height: 9px; border-radius: 2px; }
.ws-toast { position: absolute; left: 50%; top: -10px; z-index: 6; transform: translate(-50%, -8px); padding: 7px 16px; border-radius: 999px; background: #f4f7fb; color: #0b1328; font-weight: 800; font-size: 14px; letter-spacing: 0.04em; white-space: nowrap; pointer-events: none; opacity: 0; box-shadow: 0 8px 24px rgba(0,0,0,0.45), inset 0 -3px 0 var(--c, #55d6ff); }
.ws-toast.show { animation: ws-toast 1.3s ease forwards; }

/* ---------- side panel ---------- */
.ws-side { display: flex; flex-direction: column; gap: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 14px; min-width: 0; }
.ws-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.ws-titles { min-width: 0; }
.ws-theme { font-size: 20px; font-weight: 800; color: #fff; letter-spacing: -0.01em; line-height: 1.2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ws-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ws-sub b { color: #c9d7ef; font-weight: 700; }
.ws-code { font-variant-numeric: tabular-nums; letter-spacing: 0.02em; }
.ws-clock { flex: none; font-size: 18px; font-weight: 750; font-variant-numeric: tabular-nums; color: var(--muted); padding: 4px 10px; border-radius: 10px; background: #060b18; border: 1px solid var(--line); }
.ws-clock.on { color: #fff; }
.ws.is-done .ws-clock { color: #5ee6a8; border-color: rgba(94,230,168,0.4); }
.ws-progress { height: 5px; border-radius: 3px; background: #16223d; overflow: hidden; }
.ws-progress i { display: block; height: 100%; width: 0; border-radius: 3px; background: linear-gradient(90deg, #55d6ff, #5ee6a8); transition: width .45s cubic-bezier(.2,.8,.2,1); }
.ws-words { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; align-content: start; }
.ws-w { position: relative; display: flex; align-items: center; gap: 7px; min-width: 0; min-height: 26px; font-size: 14px; font-weight: 700; letter-spacing: 0.05em; color: #e6eefc; white-space: nowrap; }
.ws-w::before { content: ''; flex: none; width: 7px; height: 7px; border-radius: 50%; background: #2a3b5f; transition: background-color .3s, transform .3s; }
.ws-w > span:first-of-type { position: relative; overflow: hidden; text-overflow: clip; }
.ws-w > span:first-of-type::after { content: ''; position: absolute; left: -1px; right: -1px; top: 50%; height: 2.5px; margin-top: -1px; border-radius: 2px; background: var(--c); transform: scaleX(0); transform-origin: left; transition: transform .35s cubic-bezier(.2,.8,.2,1); }
.ws-w.found { color: #6f84a6; cursor: pointer; }
.ws-w.found::before { background: var(--c); }
.ws-w.found > span:first-of-type::after { transform: scaleX(1); }
.ws-w.just { animation: ws-just .5s cubic-bezier(.2,.9,.3,1.3); }
.ws-w.just > span:first-of-type::after { animation: ws-strike .45s .08s cubic-bezier(.2,.8,.2,1) both; }
.ws-tools { display: flex; flex-wrap: wrap; gap: 8px; margin-top: auto; }
.ws-themepick { flex: 1 1 100%; display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); font-weight: 600; }
.ws-themepick select { flex: 1 1 auto; min-width: 0; min-height: 40px; background: #060b18; color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 0 10px; font-size: 14px; cursor: pointer; }
.ws-btn { flex: 1 1 0; display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 14px; border-radius: 999px; border: 1px solid #2a3b5f; background: transparent; color: var(--text); font-weight: 700; font-size: 14px; cursor: pointer; white-space: nowrap; transition: background-color .15s, border-color .15s, transform .12s, opacity .15s; }
@media (hover: hover) { .ws-btn:hover:not(:disabled) { border-color: #5b7099; background: rgba(255,255,255,0.03); } }
.ws-btn:active:not(:disabled) { transform: scale(0.97); }
.ws-btn:disabled { opacity: 0.4; cursor: default; }
.ws-btn svg { width: 17px; height: 17px; fill: none; stroke: var(--warm); stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.ws-btn-primary { background: var(--warm); color: #1a1200; border-color: var(--warm); }
@media (hover: hover) { .ws-btn-primary:hover:not(:disabled) { background: #ffe08a; border-color: #ffe08a; } }
.ws.is-done #ws-new { animation: ws-nudge 1.8s ease-in-out 1.2s 2; }

/* ---------- sheets ---------- */
.ws-scrim { position: fixed; inset: 0; z-index: 1100; display: flex; align-items: center; justify-content: center; padding: 20px; background: rgba(2,4,10,0.62); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); animation: ws-fade .2s ease; }
.ws-scrim.out { animation: ws-fade .17s ease reverse forwards; }
.ws-sheet { position: relative; width: 100%; max-width: 420px; max-height: min(88vh, 720px); overflow: auto; overscroll-behavior: contain; background: #0d1630; border: 1px solid #22345a; border-radius: 20px; padding: 24px 22px 20px; box-shadow: 0 30px 80px rgba(0,0,0,0.6); color: var(--text); text-align: center; animation: ws-sheet .28s cubic-bezier(.2,.8,.2,1); }
.ws-scrim.out .ws-sheet { animation: ws-sheet .17s ease reverse forwards; }
.ws-sheet:focus { outline: none; }
.ws-x { position: absolute; top: 12px; right: 12px; width: 36px; height: 36px; border-radius: 50%; border: 0; background: rgba(255,255,255,0.08); color: #c9d7ef; font-size: 21px; line-height: 1; cursor: pointer; }
@media (hover: hover) { .ws-x:hover { background: rgba(255,255,255,0.14); color: #fff; } }
.ws-sheet-title { margin: 0 0 4px; font-size: 23px; font-weight: 800; color: #fff; letter-spacing: -0.01em; }
.ws-subline { margin: 0; color: var(--muted); font-size: 14px; }
.ws-res-badge { width: 58px; height: 58px; margin: 0 auto 12px; border-radius: 50%; display: grid; place-items: center; background: radial-gradient(circle at 35% 30%, #8ff0c6, #2ec27e); box-shadow: 0 8px 24px rgba(46,194,126,0.35); animation: ws-badge .5s cubic-bezier(.2,.9,.3,1.35) both; }
.ws-res-badge svg { width: 30px; height: 30px; fill: none; stroke: #02190d; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 24; animation: ws-tick .45s .2s ease both; }
.ws-time { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 16px 0 4px; flex-wrap: wrap; }
.ws-time b { font-size: 40px; font-weight: 800; color: #fff; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.ws-pill { padding: 4px 10px; border-radius: 999px; background: var(--warm); color: #1a1200; font-size: 12.5px; font-weight: 800; animation: ws-badge .5s .35s cubic-bezier(.2,.9,.3,1.35) both; }
.ws-best { color: var(--muted); font-size: 13.5px; font-weight: 600; }
.ws-statrow { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0 0; }
.ws-statrow-4 { grid-template-columns: repeat(4, 1fr); }
.ws-statrow div { display: flex; flex-direction: column; gap: 2px; padding: 10px 4px; border-radius: 12px; background: #0a1226; border: 1px solid var(--line); }
.ws-statrow b { font-size: 21px; font-weight: 800; color: #fff; font-variant-numeric: tabular-nums; }
.ws-statrow span { font-size: 11.5px; color: var(--muted); }
.ws-next { margin: 14px 0 0; color: var(--muted); font-size: 13px; }
.ws-next b { color: #fff; font-variant-numeric: tabular-nums; }
.ws-table { width: 100%; margin: 16px 0 0; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.ws-table th, .ws-table td { padding: 9px 6px; border-bottom: 1px solid var(--line); text-align: right; }
.ws-table th:first-child { text-align: left; }
.ws-table thead th { font-size: 11.5px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; }
.ws-table tbody th { color: #fff; font-weight: 700; }
.ws-sheet-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.ws-sheet-actions .ws-btn-primary { flex-basis: 100%; }

/* ---------- animation ---------- */
@keyframes ws-pop { from { scale: 0.7; opacity: 0; } 60% { scale: 1.06; opacity: 1; } }
@keyframes ws-shine { 40% { filter: brightness(1.6) saturate(1.2); scale: 1.06; } }
@keyframes ws-pulse { 50% { box-shadow: inset 0 0 0 2px rgba(232,237,242,0.85), 0 0 0 5px rgba(232,237,242,0.18); } }
@keyframes ws-miss { 0% { opacity: 1; } 20% { translate: -4px 0; } 40% { translate: 4px 0; } 60% { translate: -3px 0; opacity: 0.9; } 100% { translate: 0 0; opacity: 0; } }
@keyframes ws-wave { 45% { transform: scale(1.32) translateY(-6%); color: #fff; } }
@keyframes ws-deal { from { opacity: 0; transform: scale(0.6); } }
@keyframes ws-hint { 50% { box-shadow: 0 0 0 4px rgba(255,209,102,0.5), 0 0 20px rgba(255,209,102,0.6); } }
@keyframes ws-hintpop { from { transform: scale(1.8); } }
@keyframes ws-toast { 0% { opacity: 0; transform: translate(-50%, -8px) scale(0.9); } 14%, 78% { opacity: 1; transform: translate(-50%, 0) scale(1); } 100% { opacity: 0; transform: translate(-50%, -4px); } }
@keyframes ws-just { 35% { transform: translateX(4px) scale(1.06); } }
@keyframes ws-strike { from { transform: scaleX(0); } }
@keyframes ws-nudge { 0%, 70%, 100% { transform: none; } 80% { transform: scale(1.04); } 90% { transform: scale(0.99); } }
@keyframes ws-fade { from { opacity: 0; } }
@keyframes ws-sheet { from { opacity: 0; transform: translateY(16px) scale(0.98); } }
@keyframes ws-up { from { transform: translateY(100%); } }
@keyframes ws-badge { from { transform: scale(0.4); opacity: 0; } }
@keyframes ws-tick { from { stroke-dashoffset: 24; } to { stroke-dashoffset: 0; } }
@media (prefers-reduced-motion: reduce) { .ws *, .ws-scrim, .ws-sheet { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; } }

/* ---------- phones and narrow screens ---------- */
@media (max-width: 760px) {
  .ws-board { max-width: 640px; }
  .ws-main { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .ws-board { padding: 6px; border-radius: 16px; }
  .ws-side { padding: 12px; gap: 10px; }
  .ws-words { grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 2px 10px; }
  .ws-w { font-size: 13.5px; min-height: 24px; }
}
@media (max-width: 420px) {
  .ws { padding-top: 4px; }
  .ws-top { gap: 6px; margin-bottom: 8px; }
  .ws-segbtn { padding: 0 11px; font-size: 13px; }
  .ws-board { padding: 4px; }
  .ws-theme { font-size: 18px; }
  .ws-words { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 2px 8px; }
  .ws-w { font-size: 12.5px; letter-spacing: 0.03em; gap: 5px; }
  .ws-w::before { width: 6px; height: 6px; }
  .ws-scrim { align-items: flex-end; padding: 0; }
  .ws-sheet { max-width: none; border-radius: 22px 22px 0 0; padding-bottom: calc(18px + env(safe-area-inset-bottom, 0px)); animation-name: ws-up; border-bottom: 0; }
  .ws-scrim.out .ws-sheet { animation-name: ws-up; }
}

/* ---------- full screen (.ws-fit is set by game.js inside the site's immersive stage) ---------- */
.ws.ws-fit { max-width: none; height: 100%; margin: 0; padding: 6px; display: flex; flex-direction: column; overflow: hidden; }
.ws-fit .ws-board { width: fit-content; max-width: none; margin: 0 auto; }
.ws-fit .ws-grid { width: var(--ws-bs); }
/* portrait: controls, grid and word list stacked and centred together */
.ws.ws-port { justify-content: center; }
.ws-port .ws-top { flex: none; justify-content: center; margin-bottom: 8px; }
.ws-port .ws-main { flex: none; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.ws-port .ws-side { width: 100%; max-width: 720px; margin: 0 auto; }
.ws-port .ws-words { grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); }
@media (max-width: 420px) { .ws-port .ws-words { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
/* landscape: grid on the left, everything else in a column beside it */
.ws.ws-land { display: grid; grid-template-columns: auto var(--ws-pw, 300px); grid-template-rows: auto minmax(0, 1fr); gap: 8px 16px; justify-content: center; align-content: center; }
.ws-land .ws-main { display: contents; }
.ws-land .ws-boardwrap { grid-column: 1; grid-row: 1 / -1; display: flex; align-items: center; }
.ws-land .ws-top { grid-column: 2; grid-row: 1; margin: 0; }
.ws-land .ws-side { grid-column: 2; grid-row: 2; min-height: 0; overflow: hidden; padding: 12px; gap: 9px; align-self: stretch; }
.ws-land .ws-words { min-height: 0; overflow: auto; overscroll-behavior: contain; grid-template-columns: repeat(auto-fill, minmax(108px, 1fr)); }
@media (max-height: 520px) {
  .ws-land .ws-top { gap: 6px; flex-wrap: nowrap; }
  .ws-sheet { padding: 16px 18px 14px; max-height: 94vh; }
  .ws-res-badge { display: none; }
  .ws-time { margin: 8px 0 0; } .ws-time b { font-size: 30px; }
  .ws-statrow { margin-top: 10px; } .ws-statrow div { padding: 6px 4px; } .ws-statrow b { font-size: 17px; }
  .ws-next { margin-top: 8px; }
  .ws-sheet-actions { margin-top: 12px; } .ws-sheet-actions .ws-btn-primary { flex-basis: 0; }
  .ws-table th, .ws-table td { padding: 6px; }
  .ws-land .ws-segbtn { min-height: 34px; padding: 0 10px; font-size: 13px; }
  .ws-land .ws-ibtn { width: 40px; height: 40px; }
  .ws-land .ws-side { padding: 10px; gap: 7px; }
  .ws-land .ws-theme { font-size: 17px; }
  .ws-land .ws-clock { font-size: 15px; padding: 3px 8px; }
  .ws-land .ws-w { font-size: 12.5px; min-height: 21px; }
  .ws-land .ws-btn { min-height: 40px; }
  .ws-land .ws-themepick select { min-height: 38px; }
}
/* touch: every control is at least 40px */
@media (pointer: coarse) {
  .ws .ws-segbtn, .ws-land .ws-segbtn { min-height: 40px; }
  .ws .ws-x { width: 40px; height: 40px; top: 10px; right: 10px; }
}
