freezmo/components/activities/Matching.tsx
Martin Dvorak 52cce42cde Frosted ice glass restyle
Rebuilds the look around the spec: an ice scene, one shared glass
recipe, icy accents and glass on every large surface. Visual only —
layout, behaviour, copy and functionality are untouched.

Background
- .ice-scene: fixed, z-index -1, pointer-events none. Navy base
  (#070b16 to #0c1426) in dark, pale (#f4f9ff to #e6f1fb) in light,
  four drifting glacier blobs (#38bdf8/#60a5fa/#818cf8, 30-60s
  transform-only loops), five glossy ice orbs (40-220px radial
  gradients with a highlight at 30% 25% and a blue shadow) placed so the
  glass blurs them, and an SVG feTurbulence grain at 4-5%.
- prefers-reduced-motion stops the drift; phones get two blobs and two
  orbs fewer.

Glass
- One shared recipe (.glass-panel, .card, .sidebar-surface,
  .study-chrome, .tabbar, .glass, .gate-card): rgba(255,255,255,.06)
  dark / .55 light, blur(24px) saturate(140%) (16px on phones), a bright
  1px rim, an inset top highlight and a blue-tinted outer shadow.
- Nested glass (chips, inputs, secondary buttons) is more opaque and
  never adds a second blur layer. @supports fallback for no
  backdrop-filter. Radii: 24-28px cards/sheets, 14px inputs/buttons,
  pills for chips. Cards hover brighter + cyan rim + 2px lift, 180ms.

Colour and type
- Accent is glacier cyan (#38bdf8) to ice blue (#0ea5e9); progress bars
  and selected states use the gradient; the active sidebar item is a
  frosted highlight with a cyan rim.
- Primary CTA: icy gradient — white to #bfe3ff with ink text in dark,
  deep blue in light (biased so the label sits on the darker half and
  keeps 5.6:1).
- Leftover slate/black greys replaced with navy-tinted frost tokens.
- Headings are semibold with tighter tracking.

Screens
- Dashboard: the sidebar is one tall inset rounded glass panel; deck
  cards are glass.
- Gate: one centred glass card over the scene, orbs visible behind it.
- Sheets/modals: glass over the dimmed, lightly blurred backdrop.
- Study view: question card more opaque (.glass-solid); top bar and
  pager are slim glass pills.

Perf: measured on a phone viewport with 4x CPU throttling. The animated
blobs' filter: blur() was the whole cost (150ms vs 33ms per frame), so
they are soft radial gradients with no filter now; idle 60fps, ~17ms
median while scrolling.

Tests updated for the new tokens: contrast 18/18 AA, deck chrome 15/15,
key gate 49/49, install sheet 64/64, deck fixes 15/15, retry 14/14,
zoom 6/6, final ux 12/12, security 8/8, pwa 16/16.
2026-10-08 10:11:55 +00:00

151 lines
5.6 KiB
TypeScript

"use client";
import { useMemo, useState } from "react";
import type { Activity } from "@/lib/schemas";
import { cn, shuffle } from "@/lib/utils";
import {
ActivityHeader,
FeedbackPanel,
Hint,
PromptCard,
type ActivityComponentProps,
} from "./shared";
type MatchingActivity = Extract<Activity, { type: "matching" }>;
export function Matching({ activity, onAnswered, onNext, isLast }: ActivityComponentProps<MatchingActivity>) {
const terms = useMemo(
() => shuffle(activity.pairs.map((pair, index) => ({ index, text: pair.term }))),
[activity],
);
const definitions = useMemo(
() => shuffle(activity.pairs.map((pair, index) => ({ index, text: pair.definition }))),
[activity],
);
const [selectedTerm, setSelectedTerm] = useState<number | null>(null);
const [matched, setMatched] = useState<number[]>([]);
const [misses, setMisses] = useState(0);
const [flash, setFlash] = useState<{ term: number; definition: number } | null>(null);
const [done, setDone] = useState(false);
const total = activity.pairs.length;
const complete = matched.length === total;
const onDefinitionTap = (definitionIndex: number) => {
if (done || selectedTerm === null || matched.includes(definitionIndex)) return;
if (selectedTerm === definitionIndex) {
const next = [...matched, definitionIndex];
setMatched(next);
setSelectedTerm(null);
if (next.length === total) {
const correct = misses === 0;
setDone(true);
onAnswered(correct);
}
} else {
setMisses((value) => value + 1);
setFlash({ term: selectedTerm, definition: definitionIndex });
window.setTimeout(() => setFlash(null), 500);
setSelectedTerm(null);
}
};
return (
<>
<ActivityHeader
type="matching"
topic={activity.topic}
extra={
<span className="rounded-full bg-[var(--surface-strong)] px-3 py-1 text-xs font-bold text-frost-600 dark:text-frost-200">
{matched.length}/{total} matched
</span>
}
/>
<PromptCard className="py-4">
<p className="text-lg font-bold text-frost-950 dark:text-frost-50">{activity.instruction}</p>
<Hint>
{done
? "All matched!"
: selectedTerm === null
? "Tap a term on the left, then its match on the right."
: "Now tap the matching definition →"}
</Hint>
</PromptCard>
<div className="grid grid-cols-2 gap-2.5">
<div className="flex flex-col gap-2.5">
{terms.map((term) => {
const isMatched = matched.includes(term.index);
const isSelected = selectedTerm === term.index;
const isFlashing = flash?.term === term.index;
return (
<button
key={`term-${term.index}`}
type="button"
disabled={isMatched || done}
onClick={() => setSelectedTerm(isSelected ? null : term.index)}
className={cn(
"min-h-16 rounded-2xl border px-3 py-2 text-left text-sm font-semibold backdrop-blur-xl transition-all",
isMatched
? "border-emerald-200/80 bg-emerald-50/85 text-emerald-800 dark:border-emerald-400/40 dark:bg-emerald-400/15 dark:text-emerald-100"
: isSelected
? "border-accent-400 bg-accent-50/80 text-frost-900 dark:bg-accent-500/20 dark:text-white"
: "border-white/60 bg-white/55 text-frost-950 hover:bg-white/80 dark:border-white/12 dark:bg-white/[0.07] dark:text-frost-50",
isFlashing && "animate-wiggle border-rose-400 bg-rose-50 dark:bg-rose-400/15",
)}
>
<span className="mr-1">{isMatched ? "✓" : "•"}</span>
{term.text}
</button>
);
})}
</div>
<div className="flex flex-col gap-2.5">
{definitions.map((definition) => {
const isMatched = matched.includes(definition.index);
const isFlashing = flash?.definition === definition.index;
return (
<button
key={`def-${definition.index}`}
type="button"
disabled={isMatched || done || selectedTerm === null}
onClick={() => onDefinitionTap(definition.index)}
className={cn(
"min-h-16 rounded-2xl border-2 px-3 py-2 text-left text-sm transition-all",
isMatched
? "border-emerald-200/80 bg-emerald-50/85 text-emerald-800 dark:border-emerald-400/40 dark:bg-emerald-400/15 dark:text-emerald-100"
: "border-white/60 bg-white/55 text-frost-700 hover:bg-white/80 disabled:opacity-60 dark:border-white/12 dark:bg-white/[0.07] dark:text-frost-200",
isFlashing && "animate-wiggle border-rose-400 bg-rose-50 dark:bg-rose-400/15",
)}
>
{definition.text}
</button>
);
})}
</div>
</div>
{complete ? (
<FeedbackPanel
correct={misses === 0}
explanation={activity.explanation}
xp={activity.xp}
isLast={isLast}
onNext={onNext}
headline={misses === 0 ? "Perfect match!" : "Matched — with a few slips"}
detail={
<span>
{misses === 0
? "You matched everything first try."
: `You made ${misses} wrong ${misses === 1 ? "attempt" : "attempts"}.`}
</span>
}
/>
) : null}
</>
);
}