Bring games 9-18 in line with GAMES-NEW.md:
- Library sorts easiest first, filters by category and difficulty; difficulty 5
  shows a Nightmare chip, and a no-hint finish earns Nightmare Survivors.
- Time limits end on "Out of time" (no rank); Deep Lab Nereid's countdown is a
  rising water gauge behind the header.
- Evidence Locker search, chapter filter and starred clues (partner sees a count).
- One-shot accusations ask "One shot. Are you both sure?" first.
- Symbol font fallback, tight monospace blocks for grids/keypads/SQL.
- Rank rounds reorder by drag or up/down buttons; reveal highlights #1 and #4.
- Telepathy capped at 30 characters; maze:move accepts forward/left/right/back;
  gate buttons read "Gate (won't open from this side)".
- Overtime solver tables checked against Appendix A; keypad generator re-rolls.
- More content checks (rank items, password fixtures, glyphs/gates on traps) and
  sanitize tests for all ten new games.
- GAMES.md carries the full spoiler guide for 9-18.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-14 08:44:28 +02:00
co-authored by Claude Opus 5.5
parent bbe44e84c4
commit 6669be11e5
35 changed files with 921 additions and 215 deletions
+32 -11
View File
@@ -36,7 +36,13 @@ function Audience({ clue, light }: { clue: ClueView; light: boolean }) {
);
}
function Header({ clue, light, mono }: { clue: ClueView; light: boolean; mono?: boolean }) {
/** Starring a clue: yours to see; your partner only learns how many you starred. */
export interface PinProps {
pinned?: boolean;
onPin?: () => void;
}
function Header({ clue, light, mono, pinned, onPin }: { clue: ClueView; light: boolean; mono?: boolean } & PinProps) {
return (
<div className="mb-3 flex flex-wrap items-start justify-between gap-x-3 gap-y-1.5">
<div className="min-w-0">
@@ -45,7 +51,22 @@ function Header({ clue, light, mono }: { clue: ClueView; light: boolean; mono?:
</div>
<h4 className={`font-semibold leading-snug ${mono ? 'font-mono text-sm' : 'font-sans text-[15px]'}`}>{clue.title}</h4>
</div>
<Audience clue={clue} light={light} />
<div className="flex shrink-0 items-center gap-1.5">
<Audience clue={clue} light={light} />
{onPin && (
<button
type="button"
onClick={onPin}
aria-pressed={pinned}
aria-label={pinned ? `Unstar ${clue.title}` : `Star ${clue.title}`}
className={`-m-1 flex h-9 w-9 items-center justify-center rounded-full font-sans text-lg not-italic transition focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent ${
pinned ? 'text-amber-400' : light ? 'text-stone-500 hover:text-stone-800' : 'text-stone-500 hover:text-stone-200'
}`}
>
{pinned ? '★' : '☆'}
</button>
)}
</div>
</div>
);
}
@@ -98,19 +119,19 @@ export function SignalLamp({ pattern }: { pattern: string }) {
);
}
export function ClueCard({ clue }: { clue: ClueView }) {
export function ClueCard({ clue, ...pin }: { clue: ClueView } & PinProps) {
switch (clue.type) {
case 'note':
return (
<article className="-rotate-[0.6deg] rounded-sm bg-[#f7edc5] p-4 text-stone-900 shadow-lg shadow-black/40">
<Header clue={clue} light />
<Header {...pin} clue={clue} light />
<Markdown className="paper font-hand text-[1.4rem] leading-7">{clue.body}</Markdown>
</article>
);
case 'letter':
return (
<article className="rounded-sm border border-[#d8c9a3] bg-[#f3ead3] bg-[repeating-linear-gradient(0deg,transparent,transparent_27px,rgba(120,90,40,0.07)_28px)] p-5 text-stone-900 shadow-lg shadow-black/40">
<Header clue={clue} light />
<Header {...pin} clue={clue} light />
<Markdown className="paper font-serif text-[1.05rem] leading-7">{clue.body}</Markdown>
</article>
);
@@ -123,7 +144,7 @@ export function ClueCard({ clue }: { clue: ClueView }) {
{clue.type === 'log' ? '▮ Access log' : clue.type === 'report' ? '▮ Official report' : '▮ On file'}
</div>
<div className="p-4">
<Header clue={clue} light mono />
<Header {...pin} clue={clue} light mono />
<Markdown className={`paper text-[15px] leading-6 ${clue.type === 'log' ? 'font-mono text-[13px]' : ''}`}>{clue.body}</Markdown>
</div>
</article>
@@ -135,7 +156,7 @@ export function ClueCard({ clue }: { clue: ClueView }) {
<Markdown className="italic leading-6">{clue.body}</Markdown>
</div>
<div className="mt-3">
<Header clue={clue} light />
<Header {...pin} clue={clue} light />
</div>
</article>
);
@@ -143,21 +164,21 @@ export function ClueCard({ clue }: { clue: ClueView }) {
case 'diagram':
return (
<article className="rounded-md border border-accent/30 bg-black/50 p-4 text-accent">
<Header clue={clue} light={false} mono />
<Header {...pin} clue={clue} light={false} mono />
<Markdown className="font-mono text-[13px] leading-6">{clue.body}</Markdown>
</article>
);
case 'transcript':
return (
<article className="rounded-md border-l-4 border-accent bg-white/[0.06] p-4">
<Header clue={clue} light={false} />
<Header {...pin} clue={clue} light={false} />
<Markdown className="font-serif text-[1.05rem] italic leading-7">{clue.body}</Markdown>
</article>
);
case 'signal':
return (
<article className="rounded-md border border-red-500/30 bg-black/60 p-4">
<Header clue={clue} light={false} mono />
<Header {...pin} clue={clue} light={false} mono />
{clue.signal && <SignalLamp pattern={clue.signal} />}
<Markdown className="text-sm leading-6 text-stone-300">{clue.body}</Markdown>
</article>
@@ -165,7 +186,7 @@ export function ClueCard({ clue }: { clue: ClueView }) {
case 'table':
return (
<article className="rounded-md border border-white/15 bg-white/[0.05] p-4">
<Header clue={clue} light={false} mono />
<Header {...pin} clue={clue} light={false} mono />
<Markdown className="font-mono text-[13px] leading-6">{clue.body}</Markdown>
</article>
);
+14 -2
View File
@@ -3,7 +3,7 @@ import { useNavigate } from 'react-router-dom';
import { formatClock, type GameSummary, type PlayMode } from '@two-keys/shared';
import { getBest, saveSession } from '../lib/session';
import { request } from '../lib/socket';
import { CATEGORY_LABEL, MAX_DIFFICULTY, difficultyKeys, themeVars } from '../lib/theme';
import { CATEGORY_LABEL, DIFFICULTY_LABEL, MAX_DIFFICULTY, difficultyKeys, themeVars } from '../lib/theme';
import { pushToast } from '../lib/toasts';
import { RoleBadge, Sheet } from './ui';
@@ -39,13 +39,25 @@ export function GameCard({ game, className = '' }: { game: GameSummary; classNam
<div className="flex flex-wrap items-center gap-2">
<span className="chip text-accent">{CATEGORY_LABEL[game.category]}</span>
<span className="text-xs text-stone-300">⏱ {game.estimatedMinutes} min</span>
<span className="text-xs" aria-label={`Difficulty ${game.difficulty} of ${MAX_DIFFICULTY}`}>
<span
className="text-xs"
aria-label={`Difficulty ${game.difficulty} of ${MAX_DIFFICULTY}: ${DIFFICULTY_LABEL[game.difficulty]}`}
title={DIFFICULTY_LABEL[game.difficulty]}
>
{difficultyKeys(game.difficulty)}
<span className="opacity-25 grayscale">{difficultyKeys(MAX_DIFFICULTY - game.difficulty)}</span>
</span>
{game.difficulty >= MAX_DIFFICULTY && (
<span className="chip border-red-400/40 text-red-200">☠️ Nightmare</span>
)}
</div>
<h3 className="mt-3 font-display text-2xl font-bold leading-tight">{game.title}</h3>
<p className="mt-2 flex-1 text-sm leading-6 text-stone-300">{game.tagline}</p>
{best?.nightmareSurvivors && (
<div className="mt-3 self-start rounded-full bg-red-500/15 px-2.5 py-1 text-xs font-semibold text-red-200">
☠️ Nightmare Survivors
</div>
)}
<div className="mt-4 flex items-center justify-between gap-2 text-xs text-stone-400">
<span>{best ? `🏆 Best ${formatClock(best.finalSeconds)} · ${best.rank}` : ENGINE_BLURB[game.engine]}</span>
<span className="font-semibold text-accent transition group-hover:translate-x-0.5">Play →</span>
+21
View File
@@ -46,3 +46,24 @@ export function Timer({ timer, receivedAt }: { timer: RoomState['timer']; receiv
</div>
);
}
/** A countdown called a water level is drawn as water rising behind the header, 0% → 100% as time runs out. */
export const isWaterLevel = (timer: RoomState['timer']) => timer.limitSeconds !== null && /water/i.test(timer.limitLabel ?? '');
export function WaterGauge({ timer, receivedAt }: { timer: RoomState['timer']; receivedAt: number }) {
const now = useNow(1000);
if (timer.startedAt === null || timer.limitSeconds === null) return null;
const serverNow = timer.serverNow + (now - receivedAt);
const used = ((timer.finishedAt ?? serverNow) - timer.startedAt) / 1000 + timer.penaltySeconds;
const fill = Math.min(100, Math.max(0, (used / timer.limitSeconds) * 100));
return (
<div className="pointer-events-none absolute inset-0 -z-10 overflow-hidden" aria-hidden>
<div
className="absolute inset-x-0 bottom-0 bg-gradient-to-t from-sky-700/70 to-sky-500/40 transition-[height] duration-1000"
style={{ height: `${fill}%` }}
>
{fill > 0 && fill < 100 && <div className="water-wave absolute inset-x-0 -top-1.5 h-3 motion-reduce:hidden" />}
</div>
</div>
);
}
+9 -4
View File
@@ -179,7 +179,7 @@ function ExplorerCell({ view, send, navigatorName }: { view: ExplorerView; send:
)}
{view.message && <p className="mt-3 text-lg italic text-stone-200">{view.message}</p>}
<p className="mt-3 text-sm text-stone-400">
Open passages: <strong className="text-stone-200">{open.join(', ') || 'none'}</strong>
Open: <strong className="text-stone-200">{open.join(', ') || 'none'}</strong>
</p>
{gated.length > 0 && (
<p className="mt-1 text-sm text-stone-400">
@@ -191,17 +191,22 @@ function ExplorerCell({ view, send, navigatorName }: { view: ExplorerView; send:
<div className="mx-auto grid w-56 grid-cols-3 grid-rows-3 gap-2" role="group" aria-label="Move">
{controls.map((d) => {
const gate = view.gates.includes(d.dir);
const blocked = gate ? " (gate, won't open from this side)" : ' (wall)';
return (
<button
key={d.dir}
className={`btn aspect-square flex-col gap-0 text-2xl ${d.area}`}
disabled={!view.open[d.dir]}
onClick={() => send('maze:move', { dir: d.dir })}
aria-label={`Go ${d.label.toLowerCase()}${view.open[d.dir] ? '' : blocked}`}
aria-label={gate ? `${d.label}: Gate (won't open from this side)` : `Go ${d.label.toLowerCase()}${view.open[d.dir] ? '' : ' (wall)'}`}
title={gate ? "Gate (won't open from this side)" : undefined}
>
{gate ? '⛩' : d.arrow}
{relative && <span className="text-[10px] font-semibold uppercase tracking-wide">{d.label}</span>}
{gate ? (
<span className="text-[10px] font-semibold uppercase leading-tight tracking-wide">Gate</span>
) : (
relative && <span className="text-[10px] font-semibold uppercase tracking-wide">{d.label}</span>
)}
</button>
);
})}
+126 -29
View File
@@ -1,4 +1,4 @@
import { useEffect, useState } from 'react';
import { useEffect, useMemo, useState } from 'react';
import { motion } from 'framer-motion';
import type { AccusationView, ChapterView, ClueView, LockView, Role, RoomState, StoryView } from '@two-keys/shared';
import { otherRole } from '@two-keys/shared';
@@ -14,11 +14,16 @@ interface Props {
send: Send;
}
function Clues({ clues }: { clues: ClueView[] }) {
interface Pins {
pins: string[];
onPin: (clueId: string) => void;
}
function Clues({ clues, pins, onPin }: { clues: ClueView[] } & Pins) {
return (
<div className="space-y-5">
{clues.map((clue) => (
<ClueCard key={clue.id} clue={clue} />
<ClueCard key={clue.id} clue={clue} pinned={pins.includes(clue.id)} onPin={() => onPin(clue.id)} />
))}
</div>
);
@@ -71,11 +76,28 @@ function Accusation({ finale, role, state, send }: { finale: AccusationView; rol
finale.proposal !== null && finale.questions.every((q) => draft[q.id] === finale.proposal!.answers[q.id]);
const partnerName = state.game.roles[otherRole(role)].name;
const mine = finale.proposal?.by === role;
const lastShot = finale.attemptsLeft === 1;
const [confirming, setConfirming] = useState(false);
useEffect(() => setConfirming(false), [proposalKey, finale.agreed]);
let action;
if (matchesProposal && finale.agreed) {
if (matchesProposal && finale.agreed && confirming) {
action = (
<button className="btn-primary w-full" onClick={() => send('finale:submit')}>
<div className="rounded-2xl border border-red-400/50 bg-red-500/10 p-3 text-center" role="alertdialog" aria-label="Confirm accusation">
<p className="font-semibold">One shot. Are you both sure?</p>
<div className="mt-3 flex gap-2">
<button className="btn-primary flex-1" onClick={() => send('finale:submit')}>
Yes, accuse
</button>
<button className="btn flex-1" onClick={() => setConfirming(false)}>
Not yet
</button>
</div>
</div>
);
} else if (matchesProposal && finale.agreed) {
action = (
<button className="btn-primary w-full" onClick={() => (lastShot ? setConfirming(true) : send('finale:submit'))}>
You both agree. Make the accusation ⚖️
</button>
);
@@ -136,7 +158,9 @@ function Accusation({ finale, role, state, send }: { finale: AccusationView; rol
<div className="sticky bottom-0 -mx-4 border-t border-accent/30 bg-bg/95 px-4 pb-[max(0.75rem,env(safe-area-inset-bottom))] pt-3 backdrop-blur">
<p className="mb-2 text-center text-xs text-stone-400" aria-live="polite">
{finale.attemptsLeft} of {finale.maxAttempts} attempts left
{finale.maxAttempts === 1
? 'One attempt only. A wrong accusation ends the game.'
: `${finale.attemptsLeft} of ${finale.maxAttempts} attempts left`}
{finale.proposal && !finale.agreed && ` · ${mine ? 'You' : partnerName} proposed an accusation`}
</p>
{action}
@@ -145,9 +169,70 @@ function Accusation({ finale, role, state, send }: { finale: AccusationView; rol
);
}
function EvidenceLocker({ view, chapters }: { view: StoryView; chapters: ChapterView[] }) {
const textOf = (clue: ClueView) => `${clue.title}\n${clue.body}`.toLowerCase();
/** Search, filter and star your own clues. Everything here is already on this device. */
function EvidenceLocker({
view,
chapters,
finaleClues,
currentChapter,
pins,
onPin,
}: { view: StoryView; chapters: ChapterView[]; finaleClues: ClueView[]; currentChapter: number } & Pins) {
const [query, setQuery] = useState('');
const [only, setOnly] = useState<number | 'all' | 'starred'>('all');
const q = query.trim().toLowerCase();
const filtering = q !== '' || only !== 'all';
const sections = useMemo(() => {
const all = [
...chapters.map((ch, i) => ({ key: ch.id, index: i, title: `Chapter ${i + 1}: ${ch.title}`, chapter: ch, clues: ch.clues })),
...(finaleClues.length > 0 ? [{ key: 'finale', index: chapters.length, title: 'Finale', chapter: null, clues: finaleClues }] : []),
];
return all
.filter((s) => typeof only !== 'number' || s.index === only)
.map((s) => ({
...s,
clues: s.clues.filter((c) => (only !== 'starred' || pins.includes(c.id)) && (q === '' || textOf(c).includes(q))),
}));
}, [chapters, finaleClues, only, q, pins]);
const found = sections.reduce((n, s) => n + s.clues.length, 0);
const chip = (value: typeof only, label: string) => (
<button
key={String(value)}
aria-pressed={only === value}
onClick={() => setOnly(only === value ? 'all' : value)}
className={`min-h-[36px] shrink-0 rounded-full border px-3 py-1 text-sm transition focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent ${
only === value ? 'border-accent bg-accent text-stone-950' : 'border-white/15 bg-white/5 hover:bg-white/10'
}`}
>
{label}
</button>
);
return (
<div className="space-y-6">
<div className="space-y-2">
<input
type="search"
className="field"
placeholder="Search your clues…"
aria-label="Search your clues"
value={query}
onChange={(e) => setQuery(e.target.value)}
/>
<div className="-mx-1 flex gap-2 overflow-x-auto px-1 pb-1" role="group" aria-label="Show">
{chip('all', 'All')}
{chip('starred', `★ Starred (${pins.length})`)}
{chapters.map((_, i) => chip(i, `Ch ${i + 1}`))}
</div>
<p className="text-xs text-stone-400" aria-live="polite">
{filtering ? `${found} clue${found === 1 ? '' : 's'} found · ` : ''}
Your partner has starred {view.partnerPins} of their clue{view.partnerPins === 1 ? '' : 's'}.
</p>
</div>
{view.suspects.length > 0 && (
<section>
<h3 className="mb-2 text-xs font-bold uppercase tracking-widest text-accent">Suspects</h3>
@@ -163,22 +248,25 @@ function EvidenceLocker({ view, chapters }: { view: StoryView; chapters: Chapter
</ul>
</section>
)}
{chapters.length === 0 && view.suspects.length === 0 && (
<p className="text-stone-400">Clues from earlier chapters will collect here.</p>
)}
{chapters.map((ch, i) => (
<details key={ch.id} className="group" open={i === chapters.length - 1}>
<summary className="cursor-pointer list-none rounded-xl bg-white/5 px-3 py-2.5 font-semibold marker:hidden">
<span className="mr-2 inline-block transition group-open:rotate-90" aria-hidden>▸</span>
Chapter {i + 1}: {ch.title}
{ch.lock.keyName && <span className="ml-2 text-sm font-normal text-accent">🔑 {ch.lock.keyName}</span>}
</summary>
<div className="mt-4 space-y-4 px-1">
{ch.lock.successText && <Markdown className="rounded-xl bg-accent/10 p-3 text-sm leading-6">{ch.lock.successText}</Markdown>}
<Clues clues={ch.clues} />
</div>
</details>
))}
{filtering && found === 0 && <p className="text-stone-400">Nothing matches.</p>}
{sections
.filter((s) => !filtering || s.clues.length > 0)
.map((s) => (
// Filtering opens every match; otherwise the latest solved chapter starts open.
<details key={`${s.key}:${filtering}`} className="group" open={filtering || s.index === currentChapter - 1}>
<summary className="cursor-pointer list-none rounded-xl bg-white/5 px-3 py-2.5 font-semibold marker:hidden">
<span className="mr-2 inline-block transition group-open:rotate-90" aria-hidden>▸</span>
{s.title}
{s.chapter?.lock.keyName && <span className="ml-2 text-sm font-normal text-accent">🔑 {s.chapter.lock.keyName}</span>}
</summary>
<div className="mt-4 space-y-4 px-1">
{!filtering && s.chapter?.lock.successText && (
<Markdown className="rounded-xl bg-accent/10 p-3 text-sm leading-6">{s.chapter.lock.successText}</Markdown>
)}
<Clues clues={s.clues} pins={pins} onPin={onPin} />
</div>
</details>
))}
</div>
);
}
@@ -188,8 +276,10 @@ export function StoryGame({ view, state, role, send }: Props) {
const atFinale = view.finale !== null;
const chapter = atFinale ? null : view.chapters[view.currentChapter];
const stageLabel = atFinale ? 'the finale' : `chapter ${view.currentChapter + 1}`;
// Everything already solved: all chapters once the finale opens, earlier ones before that.
const past = atFinale ? view.chapters : view.chapters.slice(0, view.currentChapter);
const pins = view.pins ?? [];
const onPin = (clueId: string) => send('clue:pin', { clueId });
const finaleClues = view.finale?.type === 'escape' ? view.finale.clues : [];
const clueCount = view.chapters.reduce((n, c) => n + c.clues.length, 0) + finaleClues.length;
// Tell the partner what we're looking at.
useEffect(() => {
@@ -208,7 +298,7 @@ export function StoryGame({ view, state, role, send }: Props) {
{atFinale ? 'Finale' : `Chapter ${view.currentChapter + 1} of ${view.totalChapters}`}
</div>
<button className="btn shrink-0 !min-h-[40px] px-3 py-1 text-sm" onClick={() => setLockerOpen(true)}>
🗄️ Evidence{past.length > 0 ? ` (${past.reduce((n, c) => n + c.clues.length, 0)})` : ''}
🗄️ Evidence ({clueCount}){pins.length > 0 ? ` · ★${pins.length}` : ''}
</button>
</div>
<div className="mt-1">
@@ -226,7 +316,7 @@ export function StoryGame({ view, state, role, send }: Props) {
{chapter && (
<>
<Markdown className="text-lg leading-8 text-stone-200">{chapter.narrative}</Markdown>
<Clues clues={chapter.clues} />
<Clues clues={chapter.clues} pins={pins} onPin={onPin} />
{chapter.lock.solved && view.awaitingContinue ? (
<Unlocked
lock={chapter.lock}
@@ -249,13 +339,20 @@ export function StoryGame({ view, state, role, send }: Props) {
{view.finale?.type === 'escape' && (
<>
<Markdown className="text-lg leading-8 text-stone-200">{view.finale.prompt}</Markdown>
<Clues clues={view.finale.clues} />
<Clues clues={view.finale.clues} pins={pins} onPin={onPin} />
<LockPanel key={view.finale.lock.id} lock={view.finale.lock} send={send} />
</>
)}
<Sheet open={lockerOpen} onClose={() => setLockerOpen(false)} title="Evidence Locker">
<EvidenceLocker view={view} chapters={past} />
<EvidenceLocker
view={view}
chapters={view.chapters}
finaleClues={finaleClues}
currentChapter={view.currentChapter}
pins={pins}
onPin={onPin}
/>
</Sheet>
</div>
);
+107 -45
View File
@@ -1,4 +1,4 @@
import { useState, type FormEvent, type ReactNode } from 'react';
import { useRef, useState, type FormEvent, type PointerEvent as ReactPointerEvent, type ReactNode } from 'react';
import { motion } from 'framer-motion';
import type { Role, RoomState, SyncAnswer, SyncView } from '@two-keys/shared';
import { otherRole } from '@two-keys/shared';
@@ -64,7 +64,7 @@ function WordInput({ onSubmit }: { onSubmit: (text: string) => void }) {
className="field text-lg"
value={text}
onChange={(e) => setText(e.target.value)}
maxLength={40}
maxLength={30}
autoComplete="off"
autoCapitalize="none"
spellCheck={false}
@@ -78,46 +78,101 @@ function WordInput({ onSubmit }: { onSubmit: (text: string) => void }) {
);
}
/** Ranking: tap the items in order, most to least. Tap a placed one to take it back out. */
/**
* Ranking: put the items in order, most at the top. Drag the grip (mouse or touch), or use the
* up/down buttons (keyboard and screen readers).
*/
function RankPicker({ items, onSubmit }: { items: string[]; onSubmit: (order: number[]) => void }) {
const [order, setOrder] = useState<number[]>([]);
const toggle = (i: number) => setOrder((o) => (o.includes(i) ? o.filter((x) => x !== i) : [...o, i]));
const [order, setOrder] = useState<number[]>(() => items.map((_, i) => i));
const [dragging, setDragging] = useState<number | null>(null);
const [announce, setAnnounce] = useState('');
const rows = useRef<(HTMLLIElement | null)[]>([]);
const move = (from: number, to: number) => {
if (to < 0 || to >= order.length || from === to) return;
setOrder((o) => {
const next = [...o];
const [item] = next.splice(from, 1);
next.splice(to, 0, item);
return next;
});
setAnnounce(`${items[order[from]]} moved to number ${to + 1}.`);
};
// Pointer dragging: whichever row the pointer is over becomes the dragged item's new place.
const onPointerMove = (e: ReactPointerEvent) => {
if (dragging === null) return;
const from = order.indexOf(dragging);
const to = rows.current.findIndex((row) => {
const r = row?.getBoundingClientRect();
return r !== undefined && e.clientY >= r.top && e.clientY <= r.bottom;
});
if (to >= 0 && to !== from) move(from, to);
};
return (
<div className="space-y-2">
<div className="grid gap-2" role="group" aria-label="Tap in order, most to least">
{items.map((item, i) => {
const place = order.indexOf(i);
return (
<div className="space-y-3">
<p className="text-center text-xs text-stone-400">Most at the top, least at the bottom.</p>
<ol className="grid gap-2 touch-none select-none" onPointerMove={onPointerMove} onPointerUp={() => setDragging(null)} onPointerCancel={() => setDragging(null)}>
{order.map((item, place) => (
<li
key={item}
ref={(el) => (rows.current[place] = el)}
className={`flex min-h-[56px] items-center gap-2 rounded-xl border px-2 py-2 text-lg font-medium transition-colors ${
dragging === item ? 'border-accent bg-accent/25' : 'border-white/15 bg-white/5'
}`}
>
<button
key={i}
onClick={() => toggle(i)}
aria-pressed={place >= 0}
aria-label={place >= 0 ? `${item}, ranked number ${place + 1}. Tap to remove.` : `${item}, not ranked yet`}
className={`flex min-h-[52px] items-center gap-3 rounded-xl border px-4 py-3 text-left text-lg font-medium transition focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent ${
place >= 0 ? 'border-accent bg-accent/25' : 'border-white/15 bg-white/5 hover:bg-white/10'
}`}
type="button"
className="flex h-10 w-8 shrink-0 cursor-grab items-center justify-center rounded-lg text-stone-400 active:cursor-grabbing"
aria-hidden
tabIndex={-1}
onPointerDown={(e) => {
e.preventDefault();
(e.currentTarget.closest('ol') as HTMLElement | null)?.setPointerCapture(e.pointerId);
setDragging(item);
}}
>
<span
className={`flex h-8 w-8 shrink-0 items-center justify-center rounded-full border font-mono text-sm font-bold ${
place >= 0 ? 'border-accent bg-accent text-stone-950' : 'border-white/25 text-stone-500'
}`}
aria-hidden
>
{place >= 0 ? place + 1 : '·'}
</span>
{item}
⠿
</button>
);
})}
</div>
<div className="flex gap-2">
<button className="btn" disabled={order.length === 0} onClick={() => setOrder([])}>
Start over
</button>
<button className="btn-primary flex-1" disabled={order.length !== items.length} onClick={() => onSubmit(order)}>
{order.length === items.length ? 'Lock in this order' : `Tap ${items.length - order.length} more`}
</button>
</div>
<span
className={`flex h-8 w-8 shrink-0 items-center justify-center rounded-full border font-mono text-sm font-bold ${
place === 0 || place === order.length - 1 ? 'border-accent bg-accent text-stone-950' : 'border-white/25 text-stone-400'
}`}
aria-hidden
>
{place + 1}
</span>
<span className="min-w-0 flex-1">{items[item]}</span>
<div className="flex shrink-0 gap-1">
<button
type="button"
className="btn !min-h-[40px] !px-2.5 !py-1"
disabled={place === 0}
onClick={() => move(place, place - 1)}
aria-label={`Move ${items[item]} up, now number ${place + 1}`}
>
▲
</button>
<button
type="button"
className="btn !min-h-[40px] !px-2.5 !py-1"
disabled={place === order.length - 1}
onClick={() => move(place, place + 1)}
aria-label={`Move ${items[item]} down, now number ${place + 1}`}
>
▼
</button>
</div>
</li>
))}
</ol>
<p className="sr-only" aria-live="polite">
{announce}
</p>
<button className="btn-primary w-full" onClick={() => onSubmit(order)}>
Lock in this order
</button>
</div>
);
}
@@ -189,8 +244,8 @@ export function SyncGame({ view, state, role, send }: Props) {
else if (type === 'telepathy') instruction = 'Type ONE word. The same word as your partner, hopefully.';
else if (type === 'rank') {
instruction = view.iAmSubject
? "This one's about you. Tap them in order, most to least. Be honest!"
: `Tap them in the order ${subjectName} would, most to least. The top and the bottom have to match.`;
? "This one's about you. Put them in order, most to least. Be honest!"
: `Put them in the order ${subjectName} would, most to least. The top and the bottom have to match.`;
} else instruction = view.iAmSubject ? "This one's about you. Answer honestly!" : `Guess what ${subjectName} will say.`;
/** An answer as the reveal cards show it. */
@@ -198,12 +253,19 @@ export function SyncGame({ view, state, role, send }: Props) {
if (typeof answer === 'string') return answer;
if (typeof answer === 'number') return q.options[answer];
return (
<ol className="space-y-0.5 text-left text-base">
{answer.map((item, place) => (
<li key={item} className={place === 0 || place === answer.length - 1 ? '' : 'font-normal text-stone-400'}>
{place + 1}. {q.options[item]}
</li>
))}
<ol className="w-full space-y-1 text-left text-sm sm:text-base">
{answer.map((item, place) => {
// #1 and the last place are the ones that score.
const scores = place === 0 || place === answer.length - 1;
return (
<li
key={item}
className={scores ? 'rounded-md bg-accent/20 px-1.5 py-0.5 text-accent' : 'px-1.5 font-normal text-stone-400'}
>
{place + 1}. {q.options[item]}
</li>
);
})}
</ol>
);
};
+21 -3
View File
@@ -101,18 +101,24 @@ body {
.md th:empty {
display: none;
}
/* Stencil grids and box-drawing keypads need tight lines so the boxes join up. */
.md pre {
overflow-x: auto;
font-family: 'JetBrains Mono', monospace;
max-width: 100%;
font-family: 'JetBrains Mono', ui-monospace, 'Noto Sans Symbols 2', monospace;
font-size: 0.9em;
line-height: 1.5;
line-height: 1.15;
white-space: pre;
}
.md pre code.language-sql {
display: block;
line-height: 1.5;
}
.md pre code {
font-size: inherit;
}
.md code {
font-family: 'JetBrains Mono', monospace;
font-family: 'JetBrains Mono', ui-monospace, 'Noto Sans Symbols 2', monospace;
font-size: 0.92em;
}
.md .scroll-x {
@@ -131,6 +137,18 @@ body {
box-shadow: 0 0 28px 10px rgb(255 77 61 / 0.65), inset 0 0 10px rgb(255 220 200 / 0.8);
}
/* ---------- Water gauge (Deep Lab Nereid) ---------- */
.water-wave {
background: radial-gradient(ellipse 12px 6px at 12px 6px, rgb(56 189 248 / 0.55) 98%, transparent) repeat-x;
background-size: 24px 12px;
animation: wave 2.4s linear infinite;
}
@keyframes wave {
to {
background-position-x: 24px;
}
}
@keyframes shake {
20%,
60% {
+7 -1
View File
@@ -36,6 +36,8 @@ export interface BestResult {
rank: string;
hintsUsed: number;
keysEarned: number;
/** Ever finished this (difficulty 5) game with zero hints. Kept once earned. */
nightmareSurvivors?: boolean;
}
export function getBest(gameId: string): BestResult | null {
@@ -53,6 +55,10 @@ export function saveBest(gameId: string, result: BestResult): boolean {
!best ||
result.keysEarned > best.keysEarned ||
(result.keysEarned === best.keysEarned && result.finalSeconds < best.finalSeconds);
if (better) write(`twokeys:best:${gameId}`, JSON.stringify(result));
const nightmareSurvivors = Boolean(result.nightmareSurvivors || best?.nightmareSurvivors);
if (better) write(`twokeys:best:${gameId}`, JSON.stringify({ ...result, nightmareSurvivors }));
else if (nightmareSurvivors && !best?.nightmareSurvivors) {
write(`twokeys:best:${gameId}`, JSON.stringify({ ...best, nightmareSurvivors }));
}
return better;
}
+1
View File
@@ -43,4 +43,5 @@ export const ROLE_BORDER: Record<Role, string> = { A: 'border-roleA/60', B: 'bor
export const ROLE_BG: Record<Role, string> = { A: 'bg-roleA/15', B: 'bg-roleB/15' };
export const MAX_DIFFICULTY = 5;
export const DIFFICULTY_LABEL: Record<number, string> = { 1: 'Easy', 2: 'Medium', 3: 'Hard', 4: 'Expert', 5: 'Nightmare' };
export const difficultyKeys = (n: number) => '🔑'.repeat(Math.max(0, n));
+38 -12
View File
@@ -1,16 +1,37 @@
import { useState } from 'react';
import { useState, type ReactNode } from 'react';
import type { Category } from '@two-keys/shared';
import { GameCard } from '../components/GameCard';
import { SiteShell } from '../components/SiteShell';
import { useGames } from '../lib/hooks';
import { CATEGORY_LABEL } from '../lib/theme';
import { CATEGORY_LABEL, DIFFICULTY_LABEL, MAX_DIFFICULTY } from '../lib/theme';
const FILTERS: (Category | 'all')[] = ['all', 'murder-mystery', 'escape-room', 'co-op'];
const LEVELS = Array.from({ length: MAX_DIFFICULTY }, (_, i) => i + 1);
function Chip({ active, onClick, children }: { active: boolean; onClick: () => void; children: ReactNode }) {
return (
<button
aria-pressed={active}
onClick={onClick}
className={`min-h-[40px] rounded-full border px-4 py-1.5 text-sm font-medium transition focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent ${
active ? 'border-accent bg-accent text-stone-950' : 'border-white/15 bg-white/5 hover:bg-white/10'
}`}
>
{children}
</button>
);
}
export function Library() {
const games = useGames();
const [filter, setFilter] = useState<Category | 'all'>('all');
const shown = (games ?? []).filter((g) => filter === 'all' || g.category === filter);
const [level, setLevel] = useState<number | null>(null);
// Easiest first; ties keep the library's own order.
const shown = (games ?? [])
.filter((g) => (filter === 'all' || g.category === filter) && (level === null || g.difficulty === level))
.map((g, i) => ({ g, i }))
.sort((a, b) => a.g.difficulty - b.g.difficulty || a.i - b.i)
.map(({ g }) => g);
return (
<SiteShell>
@@ -21,16 +42,20 @@ export function Library() {
<div className="mt-5 flex flex-wrap gap-2" role="group" aria-label="Filter by category">
{FILTERS.map((f) => (
<button
key={f}
aria-pressed={filter === f}
onClick={() => setFilter(f)}
className={`min-h-[40px] rounded-full border px-4 py-1.5 text-sm font-medium transition focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent ${
filter === f ? 'border-accent bg-accent text-stone-950' : 'border-white/15 bg-white/5 hover:bg-white/10'
}`}
>
<Chip key={f} active={filter === f} onClick={() => setFilter(f)}>
{f === 'all' ? 'All games' : CATEGORY_LABEL[f]}
</button>
</Chip>
))}
</div>
<div className="mt-2 flex flex-wrap gap-2" role="group" aria-label="Filter by difficulty">
<Chip active={level === null} onClick={() => setLevel(null)}>
Any difficulty
</Chip>
{LEVELS.map((d) => (
<Chip key={d} active={level === d} onClick={() => setLevel(level === d ? null : d)}>
{DIFFICULTY_LABEL[d]}
{d === MAX_DIFFICULTY ? ' ☠️' : ''}
</Chip>
))}
</div>
@@ -43,6 +68,7 @@ export function Library() {
{shown.map((game) => (
<GameCard key={game.id} game={game} />
))}
{shown.length === 0 && <p className="text-stone-400">No games match those filters.</p>}
</div>
)}
</SiteShell>
+3 -2
View File
@@ -5,7 +5,7 @@ import { KeyRing } from '../components/KeyRing';
import { Notepad } from '../components/Notepad';
import { PartnerStatus, PingOverlay } from '../components/PartnerStatus';
import { PassDeviceScreen } from '../components/PassDeviceScreen';
import { Timer } from '../components/Timer';
import { Timer, WaterGauge, isWaterLevel } from '../components/Timer';
import { RoleBadge } from '../components/ui';
import { DefuseGame } from '../engines/DefuseGame';
import { LabyrinthGame } from '../engines/LabyrinthGame';
@@ -45,8 +45,9 @@ export function Play({ state, receivedAt }: { state: RoomState; receivedAt: numb
return (
<div className="mx-auto w-full max-w-2xl px-4" style={{ '--role': ROLE_COLOR[activeRole] } as CSSProperties}>
<header
className={`${view?.engine === 'defuse' ? 'relative' : 'sticky top-0'} z-20 -mx-4 border-b border-white/10 bg-bg/95 px-4 py-2 backdrop-blur`}
className={`${view?.engine === 'defuse' ? 'relative' : 'sticky top-0'} isolate z-20 -mx-4 border-b border-white/10 bg-bg/95 px-4 py-2 backdrop-blur`}
>
{isWaterLevel(state.timer) && <WaterGauge timer={state.timer} receivedAt={receivedAt} />}
<div className="flex items-center justify-between gap-3">
<Link to="/" className="-my-2 shrink-0 py-2 text-lg focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent" aria-label="Two Keys home">
🔑🔑
+9 -2
View File
@@ -38,6 +38,7 @@ export function Results({ state, result }: { state: RoomState; result: GameResul
rank: result.rank,
hintsUsed: result.hintsUsed,
keysEarned: result.keysEarned,
nightmareSurvivors: result.nightmareSurvivors,
}),
);
}, [game.id, result]);
@@ -55,9 +56,15 @@ export function Results({ state, result }: { state: RoomState; result: GameResul
animate={{ scale: 1, rotate: 0, opacity: 1 }}
transition={{ type: 'spring', stiffness: 200, damping: 12 }}
>
{result.success ? (RANK_ICON[result.rank] ?? '🔑') : '🕯️'}
{result.outOfTime ? '⌛' : result.success ? (RANK_ICON[result.rank] ?? '🔑') : '🕯️'}
</motion.div>
<h1 className="mt-3 font-display text-4xl font-bold">{result.rank}</h1>
{/* Out of time gets no rank badge. */}
<h1 className="mt-3 font-display text-4xl font-bold">{result.outOfTime ? 'Out of time' : result.rank}</h1>
{result.nightmareSurvivors && (
<p className="mx-auto mt-3 w-fit rounded-full bg-red-500/15 px-4 py-1.5 font-semibold text-red-200">
☠️ Nightmare Survivors: a difficulty-5 game with zero hints
</p>
)}
{isBest && <p className="mt-1 text-sm font-semibold text-accent">🏆 New personal best</p>}
</header>