responsive design update

This commit is contained in:
mehmet 2026-11-22 16:56:23 +03:00
parent 134b17aa2e
commit aa04134600
4 changed files with 60 additions and 46 deletions

1
.gitignore vendored
View File

@ -23,6 +23,7 @@ web/out/
# production # production
web/build web/build
deploy/
# debug # debug
npm-debug.log* npm-debug.log*

View File

@ -57,21 +57,20 @@ export default function NumberPad({ digitNumber, onSubmit, disabled = false, bus
}); });
return ( return (
<div className="flex flex-col items-center gap-6 w-full"> <div className="flex flex-col items-center gap-4 sm:gap-6 w-full">
<div className="w-full overflow-x-auto"> {/* Boxes shrink to fit the screen width, so up to 10 digits fit on a phone without scrolling */}
<div className="flex gap-2 sm:gap-3 justify-center min-w-max px-1"> <div className="flex gap-1.5 sm:gap-3 justify-center w-full max-w-xl">
{digits.map((d, i) => ( {digits.map((d, i) => (
<div <div
key={i} key={i}
className="w-9 h-12 sm:w-12 sm:h-16 flex items-center justify-center text-xl sm:text-3xl font-bold bg-neutral-800 rounded-lg border border-neutral-700" className="flex-1 min-w-0 max-w-12 sm:max-w-14 h-12 sm:h-16 flex items-center justify-center text-xl sm:text-3xl font-bold bg-neutral-800 rounded-lg border border-neutral-700"
> >
{d} {d}
</div> </div>
))} ))}
</div>
</div> </div>
<div className="grid grid-cols-3 gap-3 w-56"> <div className="grid grid-cols-3 gap-2 sm:gap-3 w-full max-w-64">
{KEYPAD.map((n) => { {KEYPAD.map((n) => {
const off = used.has(String(n)) || locked; const off = used.has(String(n)) || locked;
return ( return (

View File

@ -49,22 +49,24 @@ export default function MultiplayerLobby() {
}; };
return ( return (
<main className="h-screen w-full flex flex-col"> <main className="h-dvh w-full flex flex-col">
<header className="p-3 sm:p-4 text-center text-2xl sm:text-3xl font-bold bg-neutral-800 shadow-lg relative"> {/* 3-column grid keeps the title centred without the Home link overlapping it on narrow screens */}
<Link href="/" className="absolute left-3 top-1/2 -translate-y-1/2 text-sm font-normal text-blue-400 hover:text-blue-200"> <header className="p-3 sm:p-4 bg-neutral-800 shadow-lg grid grid-cols-[1fr_auto_1fr] items-center gap-2">
<Link href="/" className="justify-self-start text-sm text-blue-400 hover:text-blue-200">
← Home ← Home
</Link> </Link>
Multiplayer <h1 className="text-xl sm:text-3xl font-bold">Multiplayer</h1>
<span />
</header> </header>
<section className="flex-grow w-full max-w-3xl mx-auto p-4 sm:p-6 flex flex-col gap-4 overflow-y-auto"> <section className="flex-grow w-full max-w-3xl mx-auto p-3 sm:p-6 flex flex-col gap-3 sm:gap-4 overflow-y-auto">
<div className="flex items-center justify-between gap-4"> <div className="flex items-center justify-between gap-3">
<h2 className="text-xl font-semibold">Games</h2> <h2 className="text-lg sm:text-xl font-semibold">Games</h2>
<button <button
onClick={() => setShowCreate(true)} onClick={() => setShowCreate(true)}
className="px-4 py-2 rounded-lg bg-purple-600 hover:bg-purple-700 transition font-semibold" className="px-3 sm:px-4 py-2 rounded-lg bg-purple-600 hover:bg-purple-700 transition font-semibold text-sm sm:text-base"
> >
+ Create New Game + <span className="hidden sm:inline">Create </span>New Game
</button> </button>
</div> </div>
@ -80,24 +82,24 @@ export default function MultiplayerLobby() {
{games?.map((g) => ( {games?.map((g) => (
<li <li
key={g.id} key={g.id}
className={`flex items-center gap-3 p-3 sm:p-4 rounded-lg bg-neutral-800 border border-neutral-700 ${ className={`flex items-center gap-2 sm:gap-3 p-3 sm:p-4 rounded-lg bg-neutral-800 border border-neutral-700 ${
g.status === 'CLOSED' ? 'opacity-60' : '' g.status === 'CLOSED' ? 'opacity-60' : ''
}`} }`}
> >
<div className="flex-grow min-w-0"> <div className="flex-grow min-w-0">
<p className="font-semibold truncate">{g.name}</p> <p className="font-semibold truncate">{g.name}</p>
<p className="text-sm opacity-70"> <p className="text-xs sm:text-sm opacity-70">
{GAME_TYPES[g.type]?.label} · {g.digits} digits · {g.players}/2 players {GAME_TYPES[g.type]?.label} · {g.digits} digits · {g.players}/2 players
</p> </p>
</div> </div>
<span className={`text-xs px-2 py-1 rounded-full border ${STATUS_STYLE[g.status]}`}> <span className={`shrink-0 text-xs px-2 py-1 rounded-full border ${STATUS_STYLE[g.status]}`}>
{g.status.toLowerCase()} {g.status.toLowerCase()}
</span> </span>
{g.status === 'WAITING' && ( {g.status === 'WAITING' && (
<button <button
onClick={() => handleJoin(g.id)} onClick={() => handleJoin(g.id)}
disabled={joining !== null} disabled={joining !== null}
className="px-4 py-2 rounded bg-emerald-600 hover:bg-emerald-700 disabled:opacity-40 text-sm font-semibold" className="shrink-0 px-3 sm:px-4 py-2 rounded bg-emerald-600 hover:bg-emerald-700 disabled:opacity-40 text-sm font-semibold"
> >
{joining === g.id ? '...' : 'Join'} {joining === g.id ? '...' : 'Join'}
</button> </button>
@ -141,7 +143,7 @@ function CreateGameModal({ onClose, onCreated }) {
<form <form
onSubmit={handleSubmit} onSubmit={handleSubmit}
onClick={(e) => e.stopPropagation()} onClick={(e) => e.stopPropagation()}
className="bg-neutral-800 rounded-xl p-4 sm:p-6 w-full max-w-md flex flex-col gap-4" className="bg-neutral-800 rounded-xl p-4 sm:p-6 w-full max-w-md max-h-[90dvh] overflow-y-auto flex flex-col gap-4"
> >
<h2 className="text-xl font-semibold text-center">Create New Game</h2> <h2 className="text-xl font-semibold text-center">Create New Game</h2>

View File

@ -140,31 +140,39 @@ export default function MultiplayerPlayPage() {
const elapsed = state.stage === 'PLAYING' ? state.elapsedMs + (Date.now() - receivedAt) : state.elapsedMs; const elapsed = state.stage === 'PLAYING' ? state.elapsedMs + (Date.now() - receivedAt) : state.elapsedMs;
return ( return (
<main className="h-screen w-full flex flex-col"> <main className="h-dvh w-full flex flex-col">
<header className="p-3 sm:p-4 bg-neutral-800 shadow-lg flex items-center gap-3"> <header className="p-2 sm:p-4 bg-neutral-800 shadow-lg flex items-center gap-2 sm:gap-3">
<button onClick={handleLeave} className="px-3 py-2 bg-rose-700 hover:bg-rose-800 rounded text-sm shrink-0"> <button
{finished ? '← Lobby' : 'Leave Game'} onClick={handleLeave}
className="px-2 sm:px-3 py-2 bg-rose-700 hover:bg-rose-800 rounded text-xs sm:text-sm shrink-0"
>
{finished ? '← Lobby' : 'Leave'}
</button> </button>
<div className="flex-grow text-center min-w-0"> <div className="flex-grow text-center min-w-0">
<h1 className="text-xl sm:text-2xl font-bold truncate">{state.name}</h1> <h1 className="text-lg sm:text-2xl font-bold truncate">{state.name}</h1>
<p className="text-xs sm:text-sm opacity-70"> <p className="text-xs sm:text-sm opacity-70 truncate">
{type?.label} · {state.digits} digits {type?.label} · {state.digits} digits
</p> </p>
</div> </div>
<div className="shrink-0 flex flex-col items-end gap-1 text-sm"> <div className="shrink-0 flex flex-col items-end gap-1 text-xs sm:text-sm">
{(state.stage === 'PLAYING' || finished) && state.elapsedMs > 0 && ( {(state.stage === 'PLAYING' || finished) && state.elapsedMs > 0 && (
<span className="bg-neutral-900 px-3 py-1 rounded-full border border-neutral-700 font-mono"> <span className="bg-neutral-900 px-2 sm:px-3 py-0.5 sm:py-1 rounded-full border border-neutral-700 font-mono">
⏱ {formatTime(elapsed)} ⏱ {formatTime(elapsed)}
</span> </span>
)} )}
{roundBased && state.stage === 'PLAYING' && ( {roundBased && state.stage === 'PLAYING' && (
<span className="bg-neutral-900 px-3 py-1 rounded-full border border-neutral-700">Round {state.round}</span> <span className="bg-neutral-900 px-2 sm:px-3 py-0.5 sm:py-1 rounded-full border border-neutral-700">
Round {state.round}
</span>
)} )}
</div> </div>
</header> </header>
<section className="flex-grow flex flex-col md:flex-row min-h-0"> {/* Mobile: one scrolling column (game, then history). Desktop: side by side, each scrolls on its own. */}
<div className="flex-1 flex flex-col items-center justify-center p-6 gap-6 overflow-y-auto"> <section className="flex-grow flex flex-col md:flex-row min-h-0 overflow-y-auto md:overflow-hidden">
<div className="md:flex-1 flex flex-col items-center p-4 sm:p-6 gap-4 sm:gap-6 md:overflow-y-auto">
{/* my-auto centres the content when there is room without clipping its top when there isn't */}
<div className="my-auto w-full flex flex-col items-center gap-4 sm:gap-6">
{state.stage === 'WAITING' && <WaitingPanel state={state} />} {state.stage === 'WAITING' && <WaitingPanel state={state} />}
{state.stage === 'SETUP' && ( {state.stage === 'SETUP' && (
<SetupPanel state={state} busy={busy} onSubmit={handleSecret} /> <SetupPanel state={state} busy={busy} onSubmit={handleSecret} />
@ -174,16 +182,17 @@ export default function MultiplayerPlayPage() {
)} )}
{finished && <ResultPanel state={state} onBack={handleLeave} />} {finished && <ResultPanel state={state} onBack={handleLeave} />}
{actionError && <p className="text-rose-400 text-sm">{actionError}</p>} {actionError && <p className="text-rose-400 text-sm">{actionError}</p>}
</div>
</div> </div>
{(state.stage === 'PLAYING' || finished) && ( {(state.stage === 'PLAYING' || finished) && (
<aside className="md:w-[28rem] grid grid-cols-2 gap-4 p-4 sm:p-6 border-t md:border-t-0 md:border-l border-neutral-800 overflow-y-auto max-h-[35vh] md:max-h-none"> <aside className="md:w-[28rem] shrink-0 grid grid-cols-2 content-start gap-3 sm:gap-4 p-3 sm:p-6 border-t md:border-t-0 md:border-l border-neutral-800 md:overflow-y-auto">
<History title="Your guesses" history={state.you.history} /> <History title="Your guesses" history={state.you.history} />
{roundBased || finished ? ( {roundBased || finished ? (
<History title="Rival's guesses" history={state.rival?.history || []} /> <History title="Rival's guesses" history={state.rival?.history || []} />
) : ( ) : (
<div> <div>
<h3 className="text-lg font-semibold mb-3">Rival</h3> <h3 className="text-base sm:text-lg font-semibold mb-2 sm:mb-3">Rival</h3>
<p className="text-sm opacity-70 mb-2">Rival guesses are hidden in Time Challenge.</p> <p className="text-sm opacity-70 mb-2">Rival guesses are hidden in Time Challenge.</p>
<p>Attempts: {state.rival?.attempts ?? 0}</p> <p>Attempts: {state.rival?.attempts ?? 0}</p>
<p className={state.rival?.found ? 'text-emerald-400' : 'opacity-70'}> <p className={state.rival?.found ? 'text-emerald-400' : 'opacity-70'}>
@ -199,7 +208,7 @@ export default function MultiplayerPlayPage() {
} }
function CenterMessage({ children }) { function CenterMessage({ children }) {
return <main className="h-screen w-full flex flex-col items-center justify-center gap-4 p-6 text-center">{children}</main>; return <main className="h-dvh w-full flex flex-col items-center justify-center gap-4 p-6 text-center">{children}</main>;
} }
function WaitingPanel({ state }) { function WaitingPanel({ state }) {
@ -220,7 +229,7 @@ function SetupPanel({ state, busy, onSubmit }) {
return ( return (
<> <>
<div className="text-center"> <div className="text-center">
<p className="text-xl font-semibold">Choose a {state.digits}-digit number for your rival</p> <p className="text-lg sm:text-xl font-semibold">Choose a {state.digits}-digit number for your rival</p>
<p className="text-sm opacity-70">Each digit can be used only once.</p> <p className="text-sm opacity-70">Each digit can be used only once.</p>
</div> </div>
<NumberPad <NumberPad
@ -265,7 +274,7 @@ function PlayingPanel({ state, busy, onSubmit }) {
return ( return (
<> <>
<p className="text-center text-lg">{status}</p> <p className="text-center text-base sm:text-lg">{status}</p>
{!(state.type === 'TIME_CHALLENGE' && you.found) && ( {!(state.type === 'TIME_CHALLENGE' && you.found) && (
<NumberPad digitNumber={state.digits} onSubmit={onSubmit} busy={busy} disabled={!state.canGuess} /> <NumberPad digitNumber={state.digits} onSubmit={onSubmit} busy={busy} disabled={!state.canGuess} />
)} )}
@ -315,7 +324,7 @@ function ResultPanel({ state, onBack }) {
<tbody> <tbody>
{rows.map(([label, render]) => ( {rows.map(([label, render]) => (
<tr key={label} className="border-b border-neutral-800"> <tr key={label} className="border-b border-neutral-800">
<td className="py-2 text-left opacity-70">{label}</td> <td className="py-2 pr-2 text-left opacity-70 text-sm sm:text-base">{label}</td>
<td>{render(you)}</td> <td>{render(you)}</td>
<td>{render(rival)}</td> <td>{render(rival)}</td>
</tr> </tr>
@ -337,10 +346,13 @@ function History({ title, history }) {
const items = [...history].reverse(); const items = [...history].reverse();
return ( return (
<div className="min-w-0"> <div className="min-w-0">
<h3 className="text-lg font-semibold mb-3">{title}</h3> <h3 className="text-base sm:text-lg font-semibold mb-2 sm:mb-3">{title}</h3>
{items.length === 0 && <p className="opacity-60 text-sm">No guesses yet.</p>} {items.length === 0 && <p className="opacity-60 text-sm">No guesses yet.</p>}
{items.map((h) => ( {items.map((h) => (
<div key={h.turn} className="py-2 px-3 mb-2 bg-neutral-800 rounded border border-neutral-700 font-mono text-sm sm:text-base"> <div
key={h.turn}
className="py-1.5 sm:py-2 px-2 sm:px-3 mb-2 bg-neutral-800 rounded border border-neutral-700 font-mono text-xs sm:text-base break-all"
>
<span className="opacity-50 mr-2">{h.turn}.</span> <span className="opacity-50 mr-2">{h.turn}.</span>
{h.guess} {h.guess}
{h.positive === null ? ( {h.positive === null ? (