predikt/oracle/web/pages/predictle.tsx

896 lines
30 KiB
TypeScript

import { useEffect, useState, useRef } from 'react'
import { DragDropContext, Droppable, Draggable } from '@hello-pangea/dnd'
import clsx from 'clsx'
import { Page } from 'web/components/layout/page'
import { SEO } from 'web/components/SEO'
import { Col } from 'web/components/layout/col'
import { Row } from 'web/components/layout/row'
import { useAPIGetter } from 'web/hooks/use-api-getter'
import { usePersistentLocalState } from 'web/hooks/use-persistent-local-state'
import { Button } from 'web/components/buttons/button'
import { contractPath } from 'common/contract'
import { referralQuery } from 'common/util/share'
import Link from 'next/link'
import { LoadingIndicator } from 'web/components/widgets/loading-indicator'
import { useUser } from 'web/hooks/use-user'
import { useSaveReferral } from 'web/hooks/use-save-referral'
import { api } from 'web/lib/api/api'
import { track } from 'web/lib/service/analytics'
import {
TbCircleCheck,
TbCircleX,
TbConfetti,
TbMoodConfuzed,
TbClipboard,
} from 'react-icons/tb'
type Market = {
id: string
question: string
slug: string
creatorUsername: string
prob: number
}
type GameState = {
dateString: string
markets: Market[]
correctOrder: Record<string, number>
attempts: { marketId: string; feedback: ('correct' | 'incorrect')[] }[]
completed: boolean
won: boolean
}
type Feedback = 'correct' | 'incorrect'
function getFeedbackEmoji(feedback: Feedback): string {
return feedback === 'correct' ? '✅' : '❌'
}
function FeedbackIcon({ feedback }: { feedback: Feedback }) {
return feedback === 'correct' ? (
<TbCircleCheck
className="h-5 w-5 text-emerald-500"
aria-label="correct"
/>
) : (
<TbCircleX className="h-5 w-5 text-rose-500" aria-label="incorrect" />
)
}
function PredicteGame(props: {
markets: Market[]
correctOrder: Record<string, number>
dateString: string
puzzleNumber: number
}) {
const {
markets: apiMarkets,
correctOrder: apiCorrectOrder,
dateString,
puzzleNumber,
} = props
const user = useUser()
const savedResultRef = useRef(false)
const fetchedServerResultRef = useRef(false)
const [percentileData, setPercentileData] = useState<{
percentile: number
totalUsers: number
} | null>(null)
const [gameState, setGameState, localReady] =
usePersistentLocalState<GameState>(
{
dateString: '',
markets: [],
correctOrder: {},
attempts: [],
completed: false,
won: false,
},
'predictle-game-state'
)
// Track whether we've finished checking server (starts false, set true when done)
const [serverResultLoaded, setServerResultLoaded] = useState(false)
// Fetch server result for logged-in users to check if already completed
useEffect(() => {
// If no user (logged out), mark server check as done
if (user === null) {
setServerResultLoaded(true)
return
}
// If user is undefined (still loading), wait
if (user === undefined) return
// User is logged in - fetch server result
if (fetchedServerResultRef.current || !localReady) return
fetchedServerResultRef.current = true
api('get-predictle-result', { puzzleNumber })
.then((response) => {
if (response.hasResult && response.result) {
// User already completed this puzzle on server - restore full game state
const serverGameState = response.result.gameState
// Reconstruct markets from orderedMarketIds
const orderedMarketsFromServer = serverGameState.orderedMarketIds
.map((id) => apiMarkets.find((m) => m.id === id))
.filter((m): m is Market => m !== undefined)
if (orderedMarketsFromServer.length === apiMarkets.length) {
setGameState({
dateString,
markets: orderedMarketsFromServer,
correctOrder: apiCorrectOrder,
attempts: serverGameState.attempts,
completed: true,
won: response.result.won,
})
setOrderedMarkets(orderedMarketsFromServer)
savedResultRef.current = true // Don't re-save
}
}
setServerResultLoaded(true)
})
.catch((e) => {
console.error('Failed to fetch predictle result:', e)
setServerResultLoaded(true)
})
}, [user, localReady, puzzleNumber, apiMarkets, apiCorrectOrder, dateString])
const ready = localReady && serverResultLoaded
// Use stored markets if they exist for today, otherwise use API markets
const markets =
gameState.dateString === dateString && gameState.markets?.length > 0
? gameState.markets
: apiMarkets
const correctOrder =
gameState.dateString === dateString &&
gameState.correctOrder &&
Object.keys(gameState.correctOrder).length > 0
? gameState.correctOrder
: apiCorrectOrder
// Current order of markets (user-arranged)
const [orderedMarkets, setOrderedMarkets] = useState<Market[]>(markets)
// Initialize or reset game for new day, or migrate old data
useEffect(() => {
if (!ready) return
const isNewDay = gameState.dateString !== dateString
const hasFeedbackButNoMarkets =
gameState.attempts?.length > 0 && !gameState.markets?.length
if (isNewDay || hasFeedbackButNoMarkets) {
// New day or old data format - reset with fresh markets from API
setGameState({
dateString,
markets: apiMarkets,
correctOrder: apiCorrectOrder,
attempts: [],
completed: false,
won: false,
})
setOrderedMarkets(apiMarkets)
fetchedServerResultRef.current = false // Allow re-fetch for new day
}
}, [
ready,
gameState.dateString,
gameState.attempts,
gameState.markets,
dateString,
apiMarkets,
apiCorrectOrder,
])
// Sync markets on load - use stored markets (keep user's order)
useEffect(() => {
if (
ready &&
gameState.dateString === dateString &&
gameState.markets?.length > 0
) {
setOrderedMarkets(gameState.markets)
}
}, [ready, gameState.dateString, dateString, gameState.markets])
// Track analytics when game is completed
const trackedCompletionRef = useRef(false)
useEffect(() => {
// Reset trackedCompletionRef when it's a new day
if (gameState.dateString !== dateString) {
trackedCompletionRef.current = false
}
if (
ready &&
gameState.completed &&
!trackedCompletionRef.current &&
gameState.dateString === dateString
) {
trackedCompletionRef.current = true
const attemptCount = gameState.attempts[0]?.feedback.length || 0
track('predictle completed', {
puzzleNumber,
attempts: attemptCount,
won: gameState.won,
})
}
}, [
ready,
gameState.completed,
gameState.won,
gameState.attempts,
gameState.dateString,
puzzleNumber,
dateString,
])
// Save result to server when game is completed (for logged-in users)
useEffect(() => {
// Reset savedResultRef for new day
if (gameState.dateString !== dateString) {
savedResultRef.current = false
}
if (
ready &&
user &&
gameState.completed &&
!savedResultRef.current &&
gameState.dateString === dateString
) {
savedResultRef.current = true
api('save-predictle-result', {
puzzleNumber,
won: gameState.won,
gameState: {
orderedMarketIds: gameState.markets.map((m) => m.id),
attempts: gameState.attempts,
},
}).catch((e) => {
console.error('Failed to save predictle result:', e)
savedResultRef.current = false // Allow retry on error
})
}
}, [
ready,
user,
gameState.completed,
gameState.won,
gameState.attempts,
gameState.markets,
gameState.dateString,
puzzleNumber,
dateString,
])
// Fetch percentile when user wins
useEffect(() => {
if (!gameState.completed || !gameState.won) {
setPercentileData(null)
return
}
const attemptCount = gameState.attempts[0]?.feedback.length || 0
if (attemptCount === 0) return
api('get-predictle-percentile', {
puzzleNumber,
attempts: attemptCount,
})
.then(setPercentileData)
.catch((e) => {
console.error('Failed to fetch percentile:', e)
})
}, [gameState.completed, gameState.won, gameState.attempts, puzzleNumber])
// Check if a market is locked (correctly guessed)
const isMarketLocked = (marketId: string): boolean => {
const feedback = gameState.attempts.find(
(a) => a.marketId === marketId
)?.feedback
return feedback?.[feedback.length - 1] === 'correct'
}
const handleDragEnd = (result: any) => {
if (!result.destination || gameState.completed) return
const sourceIndex = result.source.index
const destIndex = result.destination.index
// Don't allow dragging locked markets (also handled by isDragDisabled)
const sourceMarket = orderedMarkets[sourceIndex]
if (isMarketLocked(sourceMarket.id)) return
// Get unlocked positions and markets
const unlockedIndices: number[] = []
const unlockedMarkets: Market[] = []
orderedMarkets.forEach((market, idx) => {
if (!isMarketLocked(market.id)) {
unlockedIndices.push(idx)
unlockedMarkets.push(market)
}
})
// Find where source is in the unlocked list
const sourceUnlockedIdx = unlockedIndices.indexOf(sourceIndex)
if (sourceUnlockedIdx === -1) return
// Find the target unlocked index based on destination
// If dropping on a locked position, find nearest unlocked slot
let targetUnlockedIdx: number
if (unlockedIndices.includes(destIndex)) {
targetUnlockedIdx = unlockedIndices.indexOf(destIndex)
} else {
// Find the nearest unlocked index to destIndex
let nearest = 0
let minDist = Math.abs(unlockedIndices[0] - destIndex)
for (let i = 1; i < unlockedIndices.length; i++) {
const dist = Math.abs(unlockedIndices[i] - destIndex)
if (dist < minDist) {
minDist = dist
nearest = i
}
}
targetUnlockedIdx = nearest
}
if (sourceUnlockedIdx === targetUnlockedIdx) return
// Reorder the unlocked markets
const [movedMarket] = unlockedMarkets.splice(sourceUnlockedIdx, 1)
unlockedMarkets.splice(targetUnlockedIdx, 0, movedMarket)
// Rebuild the full array with locked markets in their fixed positions
const newOrder = [...orderedMarkets]
let unlockedIdx = 0
for (let i = 0; i < newOrder.length; i++) {
if (!isMarketLocked(orderedMarkets[i].id)) {
newOrder[i] = unlockedMarkets[unlockedIdx++]
}
}
setOrderedMarkets(newOrder)
}
const handleSubmit = () => {
if (gameState.completed) return
// Calculate feedback for each market
const feedback: { marketId: string; feedback: Feedback[] }[] =
orderedMarkets.map((market, index) => {
const currentPosition = index + 1
const correctPosition = correctOrder[market.id]
// Get previous attempts for this market
const previousFeedback =
gameState.attempts.find((a) => a.marketId === market.id)?.feedback ||
[]
const newFeedback: Feedback =
currentPosition === correctPosition ? 'correct' : 'incorrect'
return {
marketId: market.id,
feedback: [...previousFeedback, newFeedback],
}
})
// Check if all correct
const allCorrect = feedback.every(
(f) => f.feedback[f.feedback.length - 1] === 'correct'
)
// Check attempt count from the new feedback (not the old attempts array length)
const newAttemptCount = feedback[0].feedback.length
setGameState({
dateString,
markets: orderedMarkets, // Save user's current order
correctOrder,
attempts: feedback,
completed: allCorrect || newAttemptCount >= 4,
won: allCorrect,
})
}
const getMarketFeedback = (marketId: string): Feedback[] => {
return (
gameState.attempts.find((a) => a.marketId === marketId)?.feedback || []
)
}
const attemptNumber = gameState.attempts.length
? gameState.attempts[0].feedback.length
: 0
if (!ready) {
return <LoadingIndicator />
}
const correctCount = orderedMarkets.filter((m) => isMarketLocked(m.id)).length
return (
<Col className="w-full max-w-xl gap-6">
{/* Header */}
<Col className="items-center gap-2 text-center">
<img src="/predictle-logo.png" alt="Predictle" className="h-20 w-20" />
<h1 className="inline-block bg-gradient-to-r from-primary-600 via-fuchsia-500 to-pink-500 bg-clip-text text-4xl font-black tracking-tight text-transparent [-webkit-background-clip:text]">
Predictle
</h1>
<p className="max-w-sm text-sm text-slate-600 dark:text-slate-300">
Sort these markets from <span className="font-semibold">highest</span>{' '}
to <span className="font-semibold">lowest</span> probability
</p>
{/* Progress dots */}
{!gameState.completed && (
<Row className="items-center gap-2">
<span className="text-xs font-medium text-slate-500 dark:text-slate-400">
Guesses
</span>
{[1, 2, 3, 4].map((i) => (
<div
key={i}
className={clsx(
'h-3 w-3 rounded-full transition-all',
i <= attemptNumber
? 'bg-gradient-to-br from-primary-500 to-fuchsia-500 shadow-md shadow-primary-200 dark:shadow-primary-500/50'
: 'bg-slate-300 dark:bg-slate-600'
)}
/>
))}
</Row>
)}
{/* Score indicator */}
{attemptNumber > 0 && !gameState.completed && (
<div className="inline-flex items-center gap-1 rounded-full bg-emerald-100 px-4 py-1.5 text-sm font-medium text-emerald-700 dark:bg-emerald-500/20 dark:text-emerald-400 dark:ring-1 dark:ring-emerald-500/30">
<TbCircleCheck className="h-4 w-4" aria-hidden />
{correctCount}/5 correct
</div>
)}
</Col>
{/* Game area */}
<DragDropContext onDragEnd={handleDragEnd}>
<Droppable droppableId="markets">
{(provided, snapshot) => (
<div
{...provided.droppableProps}
ref={provided.innerRef}
className={clsx(
'rounded-2xl border-2 p-3 transition-all duration-200',
snapshot.isDraggingOver
? 'border-fuchsia-300 bg-fuchsia-50 shadow-lg shadow-fuchsia-100 dark:border-fuchsia-500/50 dark:bg-fuchsia-500/10 dark:shadow-fuchsia-500/20'
: 'border-slate-200 bg-slate-50 dark:border-slate-700 dark:bg-slate-800/50'
)}
>
<Col className="gap-2">
<Row className="items-center justify-center gap-1.5 py-1 text-xs font-bold uppercase tracking-widest text-slate-500 dark:text-slate-400">
<svg
className="h-3.5 w-3.5"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
strokeWidth={2.5}
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M5 15l7-7 7 7"
/>
</svg>
<span>Higher probability</span>
</Row>
{orderedMarkets.map((market, index) => (
<Draggable
key={market.id}
draggableId={market.id}
index={index}
isDragDisabled={
gameState.completed || isMarketLocked(market.id)
}
>
{(provided, snapshot) => (
<div
ref={provided.innerRef}
{...provided.draggableProps}
{...provided.dragHandleProps}
>
<MarketCard
market={market}
feedback={getMarketFeedback(market.id)}
isDragging={snapshot.isDragging}
showProb={gameState.completed}
gameOver={gameState.completed}
isLocked={isMarketLocked(market.id)}
/>
</div>
)}
</Draggable>
))}
{provided.placeholder}
<Row className="items-center justify-center gap-1.5 py-1 text-xs font-bold uppercase tracking-widest text-slate-500 dark:text-slate-400">
<svg
className="h-3.5 w-3.5"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
strokeWidth={2.5}
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M19 9l-7 7-7-7"
/>
</svg>
<span>Lower probability</span>
</Row>
</Col>
</div>
)}
</Droppable>
</DragDropContext>
{/* Submit / Results */}
{!gameState.completed ? (
<button
onClick={handleSubmit}
disabled={attemptNumber >= 4}
className={clsx(
'relative w-full overflow-hidden rounded-xl py-4 text-lg font-bold text-white shadow-lg transition-all',
attemptNumber >= 4
? 'cursor-not-allowed bg-ink-400 dark:bg-slate-600'
: 'bg-gradient-to-r from-primary-600 via-fuchsia-500 to-pink-500 shadow-fuchsia-200 hover:scale-[1.02] hover:shadow-xl hover:shadow-fuchsia-200 active:scale-[0.98] dark:shadow-fuchsia-500/30 dark:hover:shadow-fuchsia-500/40'
)}
>
<span className="relative z-10">Submit Guess</span>
</button>
) : (
<Col className="gap-3">
<div
className={clsx(
'rounded-2xl p-6 text-center shadow-lg',
gameState.won
? 'bg-gradient-to-br from-emerald-400 to-teal-500 text-white shadow-emerald-200 dark:from-emerald-600 dark:to-teal-600 dark:shadow-emerald-500/30'
: 'bg-gradient-to-br from-amber-400 to-orange-500 text-white shadow-amber-200 dark:from-amber-600 dark:to-orange-600 dark:shadow-amber-500/30'
)}
>
<div className="mb-2 flex justify-center">
{gameState.won ? (
<TbConfetti className="h-10 w-10" aria-hidden />
) : (
<TbMoodConfuzed className="h-10 w-10" aria-hidden />
)}
</div>
<div className="text-xl font-bold">
{gameState.won
? attemptNumber === 1
? 'Perfect!'
: `You got it in ${attemptNumber} tries!`
: 'Better luck tomorrow!'}
</div>
{gameState.won && (
<div className="mt-1 text-sm opacity-90">
{percentileData && percentileData.totalUsers > 1
? `You did better than ${percentileData.percentile}% of players today!`
: attemptNumber === 1
? 'Aced it on the first try!'
: attemptNumber === 2 || attemptNumber === 3
? 'Great job!'
: 'You made it!'}
</div>
)}
</div>
<ShareButton
attempts={gameState.attempts}
puzzleNumber={puzzleNumber}
markets={orderedMarkets}
username={user?.username}
/>
</Col>
)}
{/* Footer */}
<p
className="text-center text-xs text-slate-400 dark:text-slate-500"
style={{ paddingBottom: 'max(1rem, env(safe-area-inset-bottom))' }}
>
Predictle #{puzzleNumber} • New puzzle daily at midnight PT
</p>
</Col>
)
}
function MarketCard(props: {
market: Market
feedback: Feedback[]
isDragging: boolean
showProb: boolean
gameOver: boolean
isLocked: boolean
}) {
const { market, feedback, isDragging, showProb, gameOver, isLocked } = props
const lastFeedback = feedback[feedback.length - 1]
const isCorrect = lastFeedback === 'correct'
return (
<div
className={clsx(
'group relative rounded-xl border-2 px-4 py-3 transition-all duration-200',
isDragging
? 'scale-105 border-fuchsia-400 bg-fuchsia-50 shadow-xl shadow-fuchsia-200 dark:border-fuchsia-500 dark:bg-fuchsia-500/20 dark:shadow-fuchsia-500/30'
: isCorrect
? 'border-emerald-300 bg-emerald-50 dark:border-emerald-500/50 dark:bg-emerald-500/10'
: 'border-slate-200 bg-white hover:border-slate-300 hover:shadow-md dark:border-slate-600 dark:bg-slate-800 dark:hover:border-slate-500 dark:hover:bg-slate-700/80 dark:hover:shadow-none',
!gameOver && !isLocked && 'cursor-grab active:cursor-grabbing',
isLocked &&
'ring-2 ring-emerald-200 dark:ring-1 dark:ring-emerald-500/50'
)}
>
<Row className="items-center gap-3">
{/* Drag handle indicator */}
{!gameOver && !isLocked && (
<div className="flex flex-col gap-0.5 text-slate-300 transition-colors group-hover:text-slate-400 dark:text-slate-500 dark:group-hover:text-slate-400">
<div className="flex gap-0.5">
<div className="h-1 w-1 rounded-full bg-current" />
<div className="h-1 w-1 rounded-full bg-current" />
</div>
<div className="flex gap-0.5">
<div className="h-1 w-1 rounded-full bg-current" />
<div className="h-1 w-1 rounded-full bg-current" />
</div>
<div className="flex gap-0.5">
<div className="h-1 w-1 rounded-full bg-current" />
<div className="h-1 w-1 rounded-full bg-current" />
</div>
</div>
)}
<Col className="min-w-0 flex-1 gap-1">
{gameOver ? (
<Link
href={contractPath({
creatorUsername: market.creatorUsername,
slug: market.slug,
})}
className={clsx(
'text-sm font-semibold transition-colors',
isCorrect
? 'text-emerald-800 hover:text-emerald-600 dark:text-emerald-300 dark:hover:text-emerald-200'
: 'text-slate-800 hover:text-fuchsia-600 dark:text-slate-200 dark:hover:text-fuchsia-400'
)}
onClick={(e) => e.stopPropagation()}
>
{market.question}
</Link>
) : (
<span className="text-sm font-semibold text-slate-800 dark:text-slate-200">
{market.question}
</span>
)}
{showProb && (
<div className="flex items-center gap-2">
<div className="h-1.5 flex-1 overflow-hidden rounded-full bg-slate-200 dark:bg-slate-700">
<div
className={clsx(
'h-full rounded-full transition-all',
isCorrect
? 'bg-gradient-to-r from-emerald-400 to-teal-400 dark:from-emerald-500 dark:to-teal-500'
: 'bg-gradient-to-r from-primary-400 to-fuchsia-400 dark:from-primary-500 dark:to-fuchsia-500'
)}
style={{ width: `${Math.round(market.prob * 100)}%` }}
/>
</div>
<span
className={clsx(
'whitespace-nowrap text-xs font-bold',
isCorrect
? 'text-emerald-600 dark:text-emerald-400'
: 'text-fuchsia-600 dark:text-fuchsia-400'
)}
>
{Math.round(market.prob * 100)}% chance
</span>
</div>
)}
</Col>
{/* Feedback emojis */}
<Col className="flex-shrink-0 items-end gap-1">
{feedback.length > 0 && (
<Row className="gap-1 text-xl">
{feedback.map((f, i) => (
<FeedbackIcon key={i} feedback={f} />
))}
</Row>
)}
</Col>
</Row>
</div>
)
}
function ShareButton(props: {
attempts: { marketId: string; feedback: Feedback[] }[]
puzzleNumber: number
markets: Market[]
username?: string
}) {
const { attempts, puzzleNumber, markets, username } = props
const [copied, setCopied] = useState(false)
const generateShareText = () => {
// Build feedback lines in the order of markets displayed
const feedbackLines = markets.map((market) => {
const marketAttempt = attempts.find((a) => a.marketId === market.id)
if (!marketAttempt) return ''
return marketAttempt.feedback.map(getFeedbackEmoji).join('')
})
const url = `https://oracle.markets/predictle${
username ? referralQuery(username) : ''
}`
return `Predictle #${puzzleNumber}
${feedbackLines.join('\n')}
Play at ${url}`
}
const handleShare = async () => {
const text = generateShareText()
await navigator.clipboard.writeText(text)
setCopied(true)
setTimeout(() => setCopied(false), 2000)
}
return (
<button
onClick={handleShare}
className={clsx(
'w-full rounded-xl border-2 py-3 font-bold transition-all',
copied
? 'border-emerald-300 bg-emerald-50 text-emerald-600 dark:border-emerald-500/50 dark:bg-emerald-500/20 dark:text-emerald-400'
: 'border-primary-200 bg-primary-50 text-primary-600 hover:border-primary-300 hover:bg-primary-100 dark:border-primary-500/50 dark:bg-primary-500/20 dark:text-primary-400 dark:hover:border-primary-400 dark:hover:bg-primary-500/30'
)}
>
<span className="inline-flex items-center justify-center gap-2">
{copied ? (
<>
<TbCircleCheck className="h-5 w-5" aria-hidden />
Copied to clipboard!
</>
) : (
<>
<TbClipboard className="h-5 w-5" aria-hidden />
Share results
</>
)}
</span>
</button>
)
}
export default function PredictlePage() {
const user = useUser()
useSaveReferral(user)
const { data, loading } = useAPIGetter('get-predictle-markets', {})
// Detect iOS for background positioning workaround
const [isIOS, setIsIOS] = useState(false)
useEffect(() => {
setIsIOS(
/iPad|iPhone|iPod/.test(navigator.userAgent) && !(window as any).MSStream
)
}, [])
// Prevent pull-to-refresh on Android (at body level)
useEffect(() => {
if (typeof document === 'undefined') return
const originalStyle = document.body.style.overscrollBehaviorY
// Only apply on non-iOS to avoid conflicts
if (!isIOS) {
document.body.style.overscrollBehaviorY = 'none'
}
return () => {
// Restore original style on unmount
document.body.style.overscrollBehaviorY = originalStyle
}
}, [isIOS])
// Use absolute positioning on iOS (fixed has rendering bugs), fixed elsewhere
const bgPositionClass = isIOS ? 'absolute' : 'fixed'
return (
<Page trackPageView="predictle" hideFooter className="!bg-transparent">
<SEO
title="Predictle"
description="A daily game where you arrange prediction markets by probability."
url="/predictle"
image="https://oracle.markets/predictle-logo.png"
/>
{/* Wrapper needed for iOS absolute positioning */}
<div
className={clsx(
!isIOS && 'overscroll-y-none',
isIOS && 'relative min-h-screen w-full'
)}
>
{/* Light mode gradient background */}
<div
className={clsx(
'pointer-events-none inset-0 -z-10 bg-gradient-to-br from-primary-100 via-fuchsia-50 to-amber-50 dark:hidden',
bgPositionClass
)}
/>
<div
className={clsx(
'pointer-events-none inset-0 -z-10 bg-[radial-gradient(ellipse_at_top,_var(--tw-gradient-stops))] from-primary-200/30 via-transparent to-transparent dark:hidden',
bgPositionClass
)}
/>
{/* Dark mode gradient background */}
<div
className={clsx(
'pointer-events-none inset-0 -z-10 hidden bg-slate-900 dark:block',
bgPositionClass
)}
/>
<div
className={clsx(
'pointer-events-none inset-0 -z-10 hidden bg-gradient-to-br from-primary-900/30 via-slate-900 to-fuchsia-900/20 dark:block',
bgPositionClass
)}
/>
<div
className={clsx(
'pointer-events-none inset-0 -z-10 hidden bg-[radial-gradient(ellipse_at_top,_var(--tw-gradient-stops))] from-primary-800/20 via-transparent to-transparent dark:block',
bgPositionClass
)}
/>
<Col
className="mx-auto w-full max-w-xl overscroll-y-none px-4 py-8"
style={{ paddingBottom: 'max(2rem, env(safe-area-inset-bottom))' }}
>
{loading || !data ? (
<Col className="items-center gap-4 py-12">
<img
src="/predictle-logo.png"
alt="Predictle"
className="h-20 w-20 animate-pulse"
/>
<LoadingIndicator />
<p className="text-slate-500 dark:text-slate-400">
Loading today's puzzle...
</p>
</Col>
) : (
<PredicteGame
markets={data.markets}
correctOrder={data.correctOrder}
dateString={data.dateString}
puzzleNumber={data.puzzleNumber}
/>
)}
</Col>
</div>
</Page>
)
}