updated Version
This commit is contained in:
parent
35d7c2243d
commit
43ebf18ba8
730
CSS/styles.css
730
CSS/styles.css
@ -1,120 +1,281 @@
|
|||||||
*, *::after, *::before{
|
:root {
|
||||||
|
--bg: oklch(97% 0.018 70);
|
||||||
|
--surface: oklch(99% 0.008 70);
|
||||||
|
--fg: oklch(22% 0.02 50);
|
||||||
|
--muted: oklch(50% 0.018 50);
|
||||||
|
--border: oklch(90% 0.014 70);
|
||||||
|
--accent: oklch(64% 0.13 28);
|
||||||
|
--font-display: 'Tiempos Headline', 'Newsreader', 'Iowan Old Style', Georgia, serif;
|
||||||
|
--font-body: 'Söhne', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
|
||||||
|
|
||||||
|
--correct: oklch(59% 0.12 145);
|
||||||
|
--present: oklch(73% 0.12 82);
|
||||||
|
--absent: oklch(47% 0.018 50);
|
||||||
|
--tile: oklch(99% 0.008 70);
|
||||||
|
--key: oklch(91% 0.018 70);
|
||||||
|
--shadow: 0 24px 80px oklch(22% 0.02 50 / 0.12);
|
||||||
|
}
|
||||||
|
|
||||||
|
*,
|
||||||
|
*::before,
|
||||||
|
*::after {
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
html {
|
||||||
|
min-height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
background-color: hsl(0, 67%, 96%);
|
|
||||||
display: flex;
|
|
||||||
text-align: center;
|
|
||||||
flex-direction: column;
|
|
||||||
min-height: 100vh;
|
min-height: 100vh;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 1.5em;
|
background:
|
||||||
font-size: clamp(.5rem, 2.5vmin, 1.5rem);
|
radial-gradient(circle at 12% 0%, oklch(88% 0.065 45 / 0.35), transparent 34rem),
|
||||||
|
var(--bg);
|
||||||
|
color: var(--fg);
|
||||||
|
font-family: var(--font-body);
|
||||||
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.keyboard {
|
body.dark-theme {
|
||||||
display: grid;
|
--bg: oklch(18% 0.018 50);
|
||||||
grid-template-columns: repeat(20, minmax(auto, 1.50em));
|
--surface: oklch(24% 0.018 50);
|
||||||
grid-auto-rows: 4em;
|
--fg: oklch(96% 0.014 70);
|
||||||
gap: .25em;
|
--muted: oklch(76% 0.014 70);
|
||||||
justify-content: center;
|
--border: oklch(33% 0.018 50);
|
||||||
margin-top: 2em; /* ADDED: Fixed spacing from grid */
|
--tile: oklch(26% 0.018 50);
|
||||||
|
--key: oklch(34% 0.018 50);
|
||||||
|
--shadow: 0 24px 80px oklch(8% 0.01 50 / 0.38);
|
||||||
}
|
}
|
||||||
|
|
||||||
.key{
|
button,
|
||||||
font-size: inherit;
|
a {
|
||||||
grid-column: span 2;
|
font: inherit;
|
||||||
border: none;
|
}
|
||||||
padding: 0;
|
|
||||||
|
.app-shell {
|
||||||
|
width: min(1120px, calc(100% - 32px));
|
||||||
|
min-height: 100vh;
|
||||||
|
margin: 0 auto;
|
||||||
|
padding: 24px 0 32px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.topbar,
|
||||||
|
.game-card,
|
||||||
|
.stats-card {
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
background: color-mix(in oklch, var(--surface) 90%, transparent);
|
||||||
|
box-shadow: 0 0 0 1px color-mix(in oklch, var(--surface) 70%, transparent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.topbar {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
align-items: center;
|
||||||
background-color: hsl(
|
justify-content: space-between;
|
||||||
var(--hue, 200),
|
gap: 16px;
|
||||||
var(--saturation, 1%),
|
min-height: 68px;
|
||||||
calc(var(--lightness-offset, 0%) + var(--lightness, 51%))
|
padding: 10px 12px;
|
||||||
);
|
border-radius: 20px;
|
||||||
color: rgb(255, 255, 255);
|
backdrop-filter: blur(18px);
|
||||||
fill: white;
|
}
|
||||||
text-transform: uppercase;
|
|
||||||
border-radius: .25em;
|
.brand,
|
||||||
|
.actions {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand {
|
||||||
|
gap: 12px;
|
||||||
|
color: inherit;
|
||||||
|
text-align: start;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand-mark {
|
||||||
|
display: grid;
|
||||||
|
width: 44px;
|
||||||
|
height: 44px;
|
||||||
|
place-items: center;
|
||||||
|
border-radius: 14px;
|
||||||
|
background: var(--fg);
|
||||||
|
color: var(--surface);
|
||||||
|
font-family: var(--font-display);
|
||||||
|
font-size: 1.35rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand strong {
|
||||||
|
display: block;
|
||||||
|
font-family: var(--font-display);
|
||||||
|
font-size: 1.15rem;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand small,
|
||||||
|
.deck,
|
||||||
|
.status-row,
|
||||||
|
.alert,
|
||||||
|
.definition-alert {
|
||||||
|
color: var(--muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.actions {
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-button,
|
||||||
|
.button {
|
||||||
|
min-width: 44px;
|
||||||
|
min-height: 44px;
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: 14px;
|
||||||
|
background: var(--surface);
|
||||||
|
color: var(--fg);
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
user-select: none;
|
text-decoration: none;
|
||||||
}
|
transition: transform 160ms ease, border-color 160ms ease, background-color 160ms ease;
|
||||||
.key.large{
|
|
||||||
grid-column: span 3;
|
|
||||||
}
|
|
||||||
.key > svg {
|
|
||||||
width: 1.70em;
|
|
||||||
height: 1.70em;
|
|
||||||
}
|
|
||||||
.key:hover, .key:focus{
|
|
||||||
--lightness-offset: 10%;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.key.wrong {
|
.icon-button {
|
||||||
--lightness: 23%;
|
display: inline-grid;
|
||||||
}
|
place-items: center;
|
||||||
.key.wrong-position{
|
font-size: 1.25rem;
|
||||||
--hue: 49;
|
|
||||||
--saturation: 51%;
|
|
||||||
--lightness: 47%;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.key.correct{
|
.icon-button:hover,
|
||||||
--hue: 115;
|
.button:hover {
|
||||||
--saturation: 29%;
|
transform: translateY(-1px);
|
||||||
--lightness: 43%;
|
border-color: color-mix(in oklch, var(--accent), var(--border) 45%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.game-card {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: minmax(280px, 0.9fr) minmax(320px, 1.1fr);
|
||||||
|
gap: clamp(20px, 4vw, 56px);
|
||||||
|
margin-top: 18px;
|
||||||
|
padding: clamp(20px, 4vw, 48px);
|
||||||
|
border-radius: 32px;
|
||||||
|
box-shadow: var(--shadow);
|
||||||
|
}
|
||||||
|
|
||||||
|
.hero-panel {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
text-align: start;
|
||||||
|
}
|
||||||
|
|
||||||
|
.eyebrow {
|
||||||
|
margin: 0 0 12px;
|
||||||
|
color: var(--accent);
|
||||||
|
font-size: 0.75rem;
|
||||||
|
font-weight: 700;
|
||||||
|
letter-spacing: 0.08em;
|
||||||
|
text-transform: uppercase;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1,
|
||||||
|
h2 {
|
||||||
|
margin: 0;
|
||||||
|
font-family: var(--font-display);
|
||||||
|
font-weight: 500;
|
||||||
|
line-height: 1.05;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
max-width: 9ch;
|
||||||
|
font-size: clamp(3rem, 7vw, 5.9rem);
|
||||||
|
}
|
||||||
|
|
||||||
|
h2 {
|
||||||
|
font-size: clamp(2rem, 4vw, 3rem);
|
||||||
|
}
|
||||||
|
|
||||||
|
.deck {
|
||||||
|
max-width: 34rem;
|
||||||
|
margin: 22px 0 0;
|
||||||
|
font-size: clamp(1rem, 1.4vw, 1.2rem);
|
||||||
|
line-height: 1.65;
|
||||||
|
}
|
||||||
|
|
||||||
|
.board-panel {
|
||||||
|
position: relative;
|
||||||
|
display: grid;
|
||||||
|
justify-items: center;
|
||||||
|
gap: 18px;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-row {
|
||||||
|
display: flex;
|
||||||
|
width: min(100%, 430px);
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 12px;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pill {
|
||||||
|
padding: 6px 10px;
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: 999px;
|
||||||
|
color: var(--fg);
|
||||||
|
font-variant-numeric: tabular-nums;
|
||||||
}
|
}
|
||||||
|
|
||||||
.guess-grid {
|
.guess-grid {
|
||||||
display: grid;
|
display: grid;
|
||||||
justify-content: center;
|
grid-template-columns: repeat(5, minmax(44px, 68px));
|
||||||
align-content: center;
|
grid-template-rows: repeat(6, minmax(44px, 68px));
|
||||||
/* flex: 1; */ /* REMOVED: This was causing the large spacing */
|
gap: 8px;
|
||||||
grid-template-columns: repeat(5, 4em);
|
inline-size: min(100%, 372px);
|
||||||
grid-template-rows: repeat(6, 4em);
|
aspect-ratio: 5 / 6;
|
||||||
gap: .25em;
|
|
||||||
margin: 2em auto 5em auto; /* CHANGED: Added top margin and made it centered */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.tile {
|
.tile {
|
||||||
font-size: 2em;
|
display: grid;
|
||||||
color: rgb(158, 155, 155);
|
place-items: center;
|
||||||
border: .05em solid hsl(240, 3%, 14%);
|
border: 1px solid var(--border);
|
||||||
|
border-radius: 14px;
|
||||||
|
background: var(--tile);
|
||||||
|
color: var(--fg);
|
||||||
|
font-size: clamp(1.35rem, 5vw, 2rem);
|
||||||
|
font-weight: 800;
|
||||||
text-transform: uppercase;
|
text-transform: uppercase;
|
||||||
font-weight: bold;
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
user-select: none;
|
user-select: none;
|
||||||
transition: transform 250ms linear;
|
transition: transform 250ms ease, background-color 160ms ease, color 160ms ease, border-color 160ms ease;
|
||||||
transition: transform 250ms linear;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.tile[data-state="active"] {
|
.tile[data-state="active"] {
|
||||||
border-color: hsl(240, 1%, 18%);
|
border-color: color-mix(in oklch, var(--accent), var(--fg) 25%);
|
||||||
|
box-shadow: inset 0 0 0 1px color-mix(in oklch, var(--accent), transparent 60%);
|
||||||
}
|
}
|
||||||
|
|
||||||
.tile[data-state="wrong"] {
|
.tile[data-state="wrong"],
|
||||||
border: none;
|
.key.wrong {
|
||||||
background-color: hsl(240, 12%, 24%);
|
background: var(--absent);
|
||||||
|
border-color: var(--absent);
|
||||||
color: white;
|
color: white;
|
||||||
}
|
}
|
||||||
|
|
||||||
.tile[data-state="wrong-position"] {
|
.tile[data-state="wrong-position"],
|
||||||
border: none;
|
.key.wrong-position {
|
||||||
background-color: hsl(49, 51%, 47%);
|
background: var(--present);
|
||||||
|
border-color: var(--present);
|
||||||
|
color: var(--fg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.tile[data-state="correct"],
|
||||||
|
.key.correct {
|
||||||
|
background: var(--correct);
|
||||||
|
border-color: var(--correct);
|
||||||
color: white;
|
color: white;
|
||||||
}
|
}
|
||||||
|
|
||||||
.tile[data-state="correct"] {
|
.tile.flip {
|
||||||
border: none;
|
transform: rotateX(90deg);
|
||||||
background-color: hsl(115, 31%, 48%);
|
|
||||||
color: white;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.tile.shake {
|
.tile.shake {
|
||||||
animation: shake 250ms ease-in-out;
|
animation: shake 250ms ease-in-out;
|
||||||
}
|
}
|
||||||
@ -123,192 +284,287 @@ body{
|
|||||||
animation: dance 500ms ease-in-out;
|
animation: dance 500ms ease-in-out;
|
||||||
}
|
}
|
||||||
|
|
||||||
.tile.flip {
|
.keyboard {
|
||||||
transform: rotateX(90deg);
|
display: grid;
|
||||||
|
grid-template-columns: repeat(20, minmax(0, 1fr));
|
||||||
|
gap: 6px;
|
||||||
|
width: min(100%, 560px);
|
||||||
|
touch-action: manipulation;
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes shake {
|
.key {
|
||||||
10% {
|
grid-column: span 2;
|
||||||
transform: translateX(-5%);
|
min-height: 48px;
|
||||||
|
padding: 0;
|
||||||
|
border: 1px solid color-mix(in oklch, var(--border), var(--fg) 5%);
|
||||||
|
border-radius: 12px;
|
||||||
|
background: var(--key);
|
||||||
|
color: var(--fg);
|
||||||
|
font-size: clamp(0.8rem, 2vw, 1rem);
|
||||||
|
font-weight: 800;
|
||||||
|
cursor: pointer;
|
||||||
|
user-select: none;
|
||||||
}
|
}
|
||||||
30% {
|
|
||||||
transform: translateX(5%);
|
.key.large {
|
||||||
|
grid-column: span 3;
|
||||||
|
font-size: 0.78rem;
|
||||||
}
|
}
|
||||||
50% {
|
|
||||||
transform: translateX(-7.5%);
|
.key.space {
|
||||||
|
grid-column: span 1;
|
||||||
|
visibility: hidden;
|
||||||
}
|
}
|
||||||
70% {
|
|
||||||
transform: translateX(7.5%);
|
.key svg {
|
||||||
}
|
width: 1.35rem;
|
||||||
90% {
|
height: 1.35rem;
|
||||||
transform: translateX(-5%);
|
fill: currentColor;
|
||||||
}
|
|
||||||
100% {
|
|
||||||
transform: translateX(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@keyframes dance {
|
|
||||||
20% {
|
|
||||||
transform: translateY(-50%);
|
|
||||||
}
|
|
||||||
40% {
|
|
||||||
transform: translateY(5%);
|
|
||||||
}
|
|
||||||
60% {
|
|
||||||
transform: translateY(-25%);
|
|
||||||
}
|
|
||||||
80% {
|
|
||||||
transform: translateY(2.5%);
|
|
||||||
}
|
|
||||||
90% {
|
|
||||||
transform: translateY(-5%);
|
|
||||||
}
|
|
||||||
100% {
|
|
||||||
transform: translateY(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.key:hover,
|
||||||
|
.key:focus-visible {
|
||||||
|
outline: none;
|
||||||
|
transform: translateY(-1px);
|
||||||
|
border-color: var(--accent);
|
||||||
}
|
}
|
||||||
|
|
||||||
.alert-container {
|
.alert-container {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
top: 17vh;
|
inset-block-start: 96px;
|
||||||
left: 50vw;
|
inset-inline: 16px;
|
||||||
transform: translateX(-50%);
|
z-index: 10;
|
||||||
z-index: 1;
|
display: grid;
|
||||||
display: flex;
|
justify-items: center;
|
||||||
flex-direction: column;
|
gap: 8px;
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
.alert{
|
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
background-color: hsl(204, 7%, 85%);
|
|
||||||
padding: .55em;
|
|
||||||
border-radius: .25em;
|
|
||||||
opacity: 1;
|
|
||||||
transition: opacity 500ms ease-in-out;
|
|
||||||
margin-bottom: .5em;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.alert:last-child{
|
.alert {
|
||||||
margin-bottom: 0;
|
max-width: min(440px, calc(100vw - 32px));
|
||||||
|
padding: 12px 16px;
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: 14px;
|
||||||
|
background: var(--surface);
|
||||||
|
box-shadow: var(--shadow);
|
||||||
|
color: var(--fg);
|
||||||
|
line-height: 1.45;
|
||||||
|
opacity: 1;
|
||||||
|
transition: opacity 400ms ease, transform 400ms ease;
|
||||||
}
|
}
|
||||||
|
|
||||||
.alert.hide {
|
.alert.hide {
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
|
transform: translateY(-6px);
|
||||||
}
|
}
|
||||||
|
|
||||||
.img-banner{
|
|
||||||
width: auto ;
|
|
||||||
max-width: 50% ;
|
|
||||||
height: auto ;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
.theme-change{
|
|
||||||
position: absolute;
|
|
||||||
top: 2.5rem;
|
|
||||||
display: flex;
|
|
||||||
color: rgb(202, 181, 181);
|
|
||||||
font-size: 1.2rem;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
.theme-change:hover{
|
|
||||||
color: rgb(150, 141, 141)
|
|
||||||
}
|
|
||||||
|
|
||||||
body.dark-theme{
|
|
||||||
background-color: hsl(0, 0%, 8%);
|
|
||||||
font:white;
|
|
||||||
display: flex;
|
|
||||||
text-align: center;
|
|
||||||
flex-direction: column;
|
|
||||||
min-height: 100vh;
|
|
||||||
margin: 0;
|
|
||||||
padding: 1em;
|
|
||||||
font-size: clamp(.5rem, 2.5vmin, 1.5rem);
|
|
||||||
}
|
|
||||||
|
|
||||||
.share-stats{
|
|
||||||
position: absolute;
|
|
||||||
top: 4.5rem;
|
|
||||||
display: flex;
|
|
||||||
color: rgb(202, 181, 181);
|
|
||||||
font-size: 1.2rem;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
.share-stats:hover{
|
|
||||||
color: rgb(150, 141, 141)
|
|
||||||
}
|
|
||||||
.setting-page{
|
|
||||||
position: absolute;
|
|
||||||
top: 6.5rem;
|
|
||||||
display: flex;
|
|
||||||
color: rgb(202, 181, 181);
|
|
||||||
font-size: 1.2rem;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
.setting-page:hover{
|
|
||||||
color: rgb(150, 141, 141)
|
|
||||||
}
|
|
||||||
/* Definition Alert Styles */
|
|
||||||
.definition-alert {
|
.definition-alert {
|
||||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
pointer-events: auto;
|
||||||
color: white;
|
width: min(440px, calc(100vw - 32px));
|
||||||
padding: 20px;
|
text-align: start;
|
||||||
border-radius: 12px;
|
|
||||||
max-width: 400px;
|
|
||||||
margin: 0 auto 10px;
|
|
||||||
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
|
|
||||||
border: 1px solid rgba(255, 255, 255, 0.2);
|
|
||||||
backdrop-filter: blur(10px);
|
|
||||||
cursor: pointer;
|
|
||||||
transition: all 0.3s ease;
|
|
||||||
text-align: left;
|
|
||||||
line-height: 1.6;
|
|
||||||
font-size: 14px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.definition-alert:hover {
|
|
||||||
transform: translateY(-2px);
|
|
||||||
box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
|
|
||||||
}
|
|
||||||
|
|
||||||
.win-definition {
|
|
||||||
background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
|
|
||||||
border-color: rgba(79, 172, 254, 0.5);
|
|
||||||
}
|
|
||||||
|
|
||||||
.lose-definition {
|
|
||||||
background: linear-gradient(135deg, #fa709a 0%, #fee140 100%);
|
|
||||||
border-color: rgba(250, 112, 154, 0.5);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.definition-alert strong {
|
.definition-alert strong {
|
||||||
font-weight: 700;
|
|
||||||
font-size: 16px;
|
|
||||||
display: block;
|
display: block;
|
||||||
margin-bottom: 8px;
|
margin-bottom: 6px;
|
||||||
|
color: var(--fg);
|
||||||
|
font-family: var(--font-display);
|
||||||
|
font-size: 1.2rem;
|
||||||
|
font-weight: 500;
|
||||||
}
|
}
|
||||||
|
|
||||||
.definition-alert::before {
|
.definition-alert::after {
|
||||||
content: "💡 Click to dismiss";
|
display: block;
|
||||||
position: absolute;
|
margin-top: 10px;
|
||||||
top: 5px;
|
color: var(--muted);
|
||||||
right: 10px;
|
content: "Click to dismiss";
|
||||||
font-size: 10px;
|
font-size: 0.8rem;
|
||||||
opacity: 0.7;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Dark theme adjustments */
|
.stats-modal {
|
||||||
.dark-theme .definition-alert {
|
width: min(520px, calc(100vw - 32px));
|
||||||
border-color: rgba(255, 255, 255, 0.1);
|
padding: 0;
|
||||||
|
border: 0;
|
||||||
|
border-radius: 24px;
|
||||||
|
background: transparent;
|
||||||
|
color: var(--fg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Mobile responsiveness */
|
.stats-modal::backdrop {
|
||||||
@media (max-width: 380px) {
|
background: oklch(18% 0.018 50 / 0.45);
|
||||||
.definition-alert {
|
backdrop-filter: blur(4px);
|
||||||
max-width: 90%;
|
}
|
||||||
font-size: 13px;
|
|
||||||
padding: 15px;
|
.stats-card {
|
||||||
|
padding: 22px;
|
||||||
|
border-radius: 24px;
|
||||||
|
text-align: start;
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal-head,
|
||||||
|
.modal-actions,
|
||||||
|
.stat-item,
|
||||||
|
.guess-bar {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal-head,
|
||||||
|
.modal-actions {
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.close-button {
|
||||||
|
flex: 0 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stats-grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(4, 1fr);
|
||||||
|
gap: 10px;
|
||||||
|
margin: 22px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stat-item {
|
||||||
|
min-height: 82px;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: 16px;
|
||||||
|
background: var(--bg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.stat-item strong {
|
||||||
|
font-family: var(--font-display);
|
||||||
|
font-size: 2rem;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stat-item span {
|
||||||
|
color: var(--muted);
|
||||||
|
font-size: 0.78rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.guess-bars {
|
||||||
|
display: grid;
|
||||||
|
gap: 8px;
|
||||||
|
margin-bottom: 22px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.guess-bar {
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.guess-bar-label {
|
||||||
|
width: 1.5rem;
|
||||||
|
color: var(--muted);
|
||||||
|
font-variant-numeric: tabular-nums;
|
||||||
|
}
|
||||||
|
|
||||||
|
.guess-bar-fill {
|
||||||
|
min-width: 28px;
|
||||||
|
height: 26px;
|
||||||
|
padding-inline-end: 8px;
|
||||||
|
border-radius: 8px;
|
||||||
|
background: color-mix(in oklch, var(--accent), var(--border) 40%);
|
||||||
|
color: white;
|
||||||
|
text-align: end;
|
||||||
|
font-size: 0.8rem;
|
||||||
|
font-weight: 800;
|
||||||
|
line-height: 26px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button {
|
||||||
|
padding: 0 16px;
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button.primary {
|
||||||
|
background: var(--accent);
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button.secondary {
|
||||||
|
background: var(--key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes shake {
|
||||||
|
10%, 90% { transform: translateX(-4%); }
|
||||||
|
30%, 70% { transform: translateX(5%); }
|
||||||
|
50% { transform: translateX(-7%); }
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes dance {
|
||||||
|
20% { transform: translateY(-45%); }
|
||||||
|
40% { transform: translateY(4%); }
|
||||||
|
60% { transform: translateY(-20%); }
|
||||||
|
80% { transform: translateY(2%); }
|
||||||
|
100% { transform: translateY(0); }
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 780px) {
|
||||||
|
.app-shell {
|
||||||
|
width: min(100% - 20px, 600px);
|
||||||
|
padding-top: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.game-card {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
padding: 18px;
|
||||||
|
border-radius: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hero-panel {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1,
|
||||||
|
.deck {
|
||||||
|
margin-inline: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.deck {
|
||||||
|
margin-top: 12px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 460px) {
|
||||||
|
.brand small {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.topbar {
|
||||||
|
padding: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.actions {
|
||||||
|
gap: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-button {
|
||||||
|
min-width: 40px;
|
||||||
|
min-height: 40px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.guess-grid {
|
||||||
|
gap: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tile {
|
||||||
|
border-radius: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.keyboard {
|
||||||
|
gap: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.key {
|
||||||
|
min-height: 44px;
|
||||||
|
border-radius: 9px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stats-grid {
|
||||||
|
grid-template-columns: repeat(2, 1fr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
17
IMPROVEMENTS.md
Normal file
17
IMPROVEMENTS.md
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
# Fancy Wordle Improvements
|
||||||
|
|
||||||
|
Implemented:
|
||||||
|
- Modern responsive game shell while preserving the static HTML/CSS/JS architecture.
|
||||||
|
- Warm-soft visual system with cream surfaces, gentle radii, and restrained accent use.
|
||||||
|
- Generated board and keyboard from data instead of hardcoding repeated markup.
|
||||||
|
- Correct Wordle scoring for repeated letters.
|
||||||
|
- Preserved dark mode, keyboard input, word-list fetches, dictionary validation, win sound, confetti, definition lookup, and the original love-link shortcut.
|
||||||
|
- Added a working stats/share dialog using localStorage.
|
||||||
|
- Improved accessibility with semantic buttons, labels, live alerts, visible focus states, and 44px touch targets.
|
||||||
|
|
||||||
|
Good next features:
|
||||||
|
- Hard mode that forces revealed hints into later guesses.
|
||||||
|
- Daily challenge mode alongside the current unlimited mode.
|
||||||
|
- Reduced-motion preference for flip, dance, and confetti animations.
|
||||||
|
- Offline definition fallback for the target word list.
|
||||||
|
- Importable custom word packs for classroom or party play.
|
||||||
76
fancy-wordle-modern.html
Normal file
76
fancy-wordle-modern.html
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
|
||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<meta name="theme-color" content="#f7efe6">
|
||||||
|
<title>Fancy Wordle</title>
|
||||||
|
<link rel="stylesheet" href="CSS/styles.css">
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/@tsparticles/confetti@3.0.3/tsparticles.confetti.bundle.min.js"></script>
|
||||||
|
<script src="word-data.js?v=4" defer></script>
|
||||||
|
<script src="script.js?v=4" defer></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="app-shell">
|
||||||
|
<header class="topbar" aria-label="Game controls">
|
||||||
|
<a class="brand" href="#" aria-label="Restart Fancy Wordle">
|
||||||
|
<span class="brand-mark">W</span>
|
||||||
|
<span>
|
||||||
|
<strong>Fancy Wordle</strong>
|
||||||
|
<small>Non-stop five-letter play</small>
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<nav class="actions" aria-label="Quick actions">
|
||||||
|
<button class="icon-button" type="button" id="theme-button" aria-label="Toggle dark mode" title="Toggle theme">
|
||||||
|
<span aria-hidden="true">◐</span>
|
||||||
|
</button>
|
||||||
|
<button class="icon-button" type="button" id="Stats-button" aria-label="Open stats and share" title="Stats and share">
|
||||||
|
<span aria-hidden="true">↗</span>
|
||||||
|
</button>
|
||||||
|
<a class="icon-button" href="https://www.youtube.com/watch?v=UkOKCWDJ4iA" target="_blank" rel="noopener noreferrer" aria-label="Open the original love note" title="Original love note">
|
||||||
|
<span aria-hidden="true">♡</span>
|
||||||
|
</a>
|
||||||
|
</nav>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<main class="game-card">
|
||||||
|
<section class="hero-panel" aria-labelledby="game-title">
|
||||||
|
<p class="eyebrow">Daily pace optional</p>
|
||||||
|
<h1 id="game-title">Guess the word in six tries.</h1>
|
||||||
|
<p class="deck">Play as many rounds as you want. Valid words reveal with smooth flips, warm feedback, confetti, sound, and a definition at the end.</p>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section class="board-panel" aria-label="Wordle game board">
|
||||||
|
<div class="status-row">
|
||||||
|
<span id="round-status">Loading word lists…</span>
|
||||||
|
<span class="pill" id="tries-status">0 / 6</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="alert-container" data-alert-container aria-live="polite" aria-atomic="true"></div>
|
||||||
|
<div data-guess-grid class="guess-grid" aria-label="Guess grid"></div>
|
||||||
|
<div data-keyboard class="keyboard" aria-label="Keyboard"></div>
|
||||||
|
</section>
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<dialog class="stats-modal" id="stats-modal" aria-labelledby="stats-title">
|
||||||
|
<form method="dialog" class="stats-card">
|
||||||
|
<div class="modal-head">
|
||||||
|
<div>
|
||||||
|
<p class="eyebrow">Progress</p>
|
||||||
|
<h2 id="stats-title">Game stats</h2>
|
||||||
|
</div>
|
||||||
|
<button class="icon-button close-button" type="submit" aria-label="Close stats">×</button>
|
||||||
|
</div>
|
||||||
|
<div class="stats-grid" id="stats-grid"></div>
|
||||||
|
<div class="guess-bars" id="guess-bars" aria-label="Guess distribution"></div>
|
||||||
|
<menu class="modal-actions">
|
||||||
|
<button type="button" class="button secondary" id="reset-stats">Reset stats</button>
|
||||||
|
<button type="button" class="button primary" id="share-results">Share result</button>
|
||||||
|
</menu>
|
||||||
|
</form>
|
||||||
|
</dialog>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
155
index.html
155
index.html
@ -1,110 +1,75 @@
|
|||||||
<!DOCTYPE html>
|
<!doctype html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/boxicons@latest/css/boxicons.min.css">
|
<meta name="theme-color" content="#f7efe6">
|
||||||
|
<title>Fancy Wordle</title>
|
||||||
<link rel="stylesheet" href="CSS/styles.css">
|
<link rel="stylesheet" href="CSS/styles.css">
|
||||||
<link rel="stylesheet" href="path/to/font-awesome/css/font-awesome.min.css">
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/@tsparticles/confetti@3.0.3/tsparticles.confetti.bundle.min.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/@tsparticles/confetti@3.0.3/tsparticles.confetti.bundle.min.js"></script>
|
||||||
<script src="script.js" defer></script>
|
<script src="word-data.js?v=5" defer></script>
|
||||||
<title>Wordle for Sara</title>
|
<script src="script.js?v=5" defer></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<section class="darkmode section">
|
<div class="app-shell">
|
||||||
<p>
|
<header class="topbar" aria-label="Game controls">
|
||||||
<a href="#"onclick="window.location.reload(true);">
|
<a class="brand" href="#" aria-label="Restart Fancy Wordle">
|
||||||
<img class="img-banner" src="img/wordle.png" alt="wordle">
|
<span class="brand-mark">W</span>
|
||||||
<hr style="width:25%;">
|
<span>
|
||||||
|
<strong>Fancy Wordle</strong>
|
||||||
|
<small>Non-stop five-letter play</small>
|
||||||
|
</span>
|
||||||
</a>
|
</a>
|
||||||
</p>
|
|
||||||
</section>
|
|
||||||
<section class="icons section">
|
|
||||||
<div class="icons__container bd-grid">
|
|
||||||
<i class='bx bx-moon theme-change' title="Theme" id="theme-button"></i>
|
|
||||||
</div>
|
|
||||||
<div class="icons__container bd-grid">
|
|
||||||
<i class='bx bx-share-alt share-stats' title="Stats" id="Stats-button"></i>
|
|
||||||
</div>
|
|
||||||
<div class="icons__container bd-grid">
|
|
||||||
<a href="https://www.youtube.com/watch?v=UkOKCWDJ4iA" target="_blank" rel="noopener noreferrer">
|
|
||||||
<i class='bx bxs-heart setting-page' title="I love You" id="Setting-button"></i>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</section>
|
<nav class="actions" aria-label="Quick actions">
|
||||||
<div class="alert-container" data-alert-container></div>
|
<button class="icon-button" type="button" id="theme-button" aria-label="Toggle dark mode" title="Toggle theme">
|
||||||
<div data-guess-grid class="guess-grid">
|
<span aria-hidden="true">◐</span>
|
||||||
<div class="tile"></div>
|
|
||||||
<div class="tile"></div>
|
|
||||||
<div class="tile"></div>
|
|
||||||
<div class="tile"></div>
|
|
||||||
<div class="tile"></div>
|
|
||||||
<div class="tile"></div>
|
|
||||||
<div class="tile"></div>
|
|
||||||
<div class="tile"></div>
|
|
||||||
<div class="tile"></div>
|
|
||||||
<div class="tile"></div>
|
|
||||||
<div class="tile"></div>
|
|
||||||
<div class="tile"></div>
|
|
||||||
<div class="tile"></div>
|
|
||||||
<div class="tile"></div>
|
|
||||||
<div class="tile"></div>
|
|
||||||
<div class="tile"></div>
|
|
||||||
<div class="tile"></div>
|
|
||||||
<div class="tile"></div>
|
|
||||||
<div class="tile"></div>
|
|
||||||
<div class="tile"></div>
|
|
||||||
<div class="tile"></div>
|
|
||||||
<div class="tile"></div>
|
|
||||||
<div class="tile"></div>
|
|
||||||
<div class="tile"></div>
|
|
||||||
<div class="tile"></div>
|
|
||||||
<div class="tile"></div>
|
|
||||||
<div class="tile"></div>
|
|
||||||
<div class="tile"></div>
|
|
||||||
<div class="tile"></div>
|
|
||||||
<div class="tile"></div>
|
|
||||||
</div>
|
|
||||||
<div data-keyboard class="keyboard">
|
|
||||||
<button class="key" data-key="Q">Q</button>
|
|
||||||
<button class="key" data-key="W">W</button>
|
|
||||||
<button class="key" data-key="E">E</button>
|
|
||||||
<button class="key" data-key="R">R</button>
|
|
||||||
<button class="key" data-key="T">T</button>
|
|
||||||
<button class="key" data-key="Y">Y</button>
|
|
||||||
<button class="key" data-key="U">U</button>
|
|
||||||
<button class="key" data-key="I">I</button>
|
|
||||||
<button class="key" data-key="O">O</button>
|
|
||||||
<button class="key" data-key="P">P</button>
|
|
||||||
<div class="space"></div>
|
|
||||||
<button class="key" data-key="A">A</button>
|
|
||||||
<button class="key" data-key="S">S</button>
|
|
||||||
<button class="key" data-key="D">D</button>
|
|
||||||
<button class="key" data-key="F">F</button>
|
|
||||||
<button class="key" data-key="G">G</button>
|
|
||||||
<button class="key" data-key="H">H</button>
|
|
||||||
<button class="key" data-key="J">J</button>
|
|
||||||
<button class="key" data-key="K">K</button>
|
|
||||||
<button class="key" data-key="L">L</button>
|
|
||||||
<div class="space"></div>
|
|
||||||
<button data-enter class="key large">Enter</button>
|
|
||||||
<button class="key" data-key="Z">Z</button>
|
|
||||||
<button class="key" data-key="X">X</button>
|
|
||||||
<button class="key" data-key="C">C</button>
|
|
||||||
<button class="key" data-key="V">V</button>
|
|
||||||
<button class="key" data-key="B">B</button>
|
|
||||||
<button class="key" data-key="N">N</button>
|
|
||||||
<button class="key" data-key="M">M</button>
|
|
||||||
<button data-delete class="key large">
|
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24">
|
|
||||||
<path fill="var(--color-tone-1)"
|
|
||||||
d="M22 3H7c-.69 0-1.23.35-1.59.88L0 12l5.41 8.11c.36.53.9.89 1.59.89h15c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm0 16H7.07L2.4 12l4.66-7H22v14zm-11.59-2L14 13.41 17.59 17 19 15.59 15.41 12 19 8.41 17.59 7 14 10.59 10.41 7 9 8.41 12.59 12 9 15.59z">
|
|
||||||
</path>
|
|
||||||
</svg>
|
|
||||||
</button>
|
</button>
|
||||||
|
<button class="icon-button" type="button" id="Stats-button" aria-label="Open stats and share" title="Stats and share">
|
||||||
|
<span aria-hidden="true">↗</span>
|
||||||
|
</button>
|
||||||
|
<a class="icon-button" href="https://www.youtube.com/watch?v=UkOKCWDJ4iA" target="_blank" rel="noopener noreferrer" aria-label="Open the original love note" title="Original love note">
|
||||||
|
<span aria-hidden="true">♡</span>
|
||||||
|
</a>
|
||||||
|
</nav>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<main class="game-card">
|
||||||
|
<section class="hero-panel" aria-labelledby="game-title">
|
||||||
|
<p class="eyebrow">Daily pace optional</p>
|
||||||
|
<h1 id="game-title">Guess the word in six tries.</h1>
|
||||||
|
<p class="deck">Play as many rounds as you want. Valid words reveal with smooth flips, warm feedback, confetti, sound, and a definition at the end.</p>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section class="board-panel" aria-label="Wordle game board">
|
||||||
|
<div class="status-row">
|
||||||
|
<span id="round-status">Loading word lists…</span>
|
||||||
|
<span class="pill" id="tries-status">0 / 6</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="alert-container" data-alert-container aria-live="polite" aria-atomic="true"></div>
|
||||||
|
<div data-guess-grid class="guess-grid" aria-label="Guess grid"></div>
|
||||||
|
<div data-keyboard class="keyboard" aria-label="Keyboard"></div>
|
||||||
|
</section>
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<dialog class="stats-modal" id="stats-modal" aria-labelledby="stats-title">
|
||||||
|
<form method="dialog" class="stats-card">
|
||||||
|
<div class="modal-head">
|
||||||
|
<div>
|
||||||
|
<p class="eyebrow">Progress</p>
|
||||||
|
<h2 id="stats-title">Game stats</h2>
|
||||||
|
</div>
|
||||||
|
<button class="icon-button close-button" type="submit" aria-label="Close stats">×</button>
|
||||||
|
</div>
|
||||||
|
<div class="stats-grid" id="stats-grid"></div>
|
||||||
|
<div class="guess-bars" id="guess-bars" aria-label="Guess distribution"></div>
|
||||||
|
<menu class="modal-actions">
|
||||||
|
<button type="button" class="button secondary" id="reset-stats">Reset stats</button>
|
||||||
|
<button type="button" class="button primary" id="share-results">Share result</button>
|
||||||
|
</menu>
|
||||||
|
</form>
|
||||||
|
</dialog>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
840
script.js
840
script.js
@ -1,93 +1,238 @@
|
|||||||
// Global variables
|
|
||||||
let targetWords = []
|
let targetWords = []
|
||||||
let dictionary = []
|
let dictionary = []
|
||||||
|
let dictionarySet = new Set()
|
||||||
let targetWord = ""
|
let targetWord = ""
|
||||||
|
let gameFinished = false
|
||||||
|
let currentGuessIndex = 0
|
||||||
|
let currentTileIndex = 0
|
||||||
|
let lastResult = null
|
||||||
|
let hasInitialized = false
|
||||||
|
let wordListMode = "loading"
|
||||||
|
let isAnimating = false
|
||||||
|
|
||||||
const WORD_LENGTH = 5
|
const WORD_LENGTH = 5
|
||||||
|
const MAX_GUESSES = 6
|
||||||
const FLIP_ANIMATION_DURATION = 500
|
const FLIP_ANIMATION_DURATION = 500
|
||||||
const DANCE_ANIMATION_DURATION = 500
|
const DANCE_ANIMATION_DURATION = 500
|
||||||
|
const STATS_KEY = "fancy-wordle-stats-v2"
|
||||||
|
const KEY_ROWS = ["QWERTYUIOP", "ASDFGHJKL", "ZXCVBNM"]
|
||||||
|
const FALLBACK_TARGET_WORDS = [
|
||||||
|
"about",
|
||||||
|
"after",
|
||||||
|
"apple",
|
||||||
|
"beach",
|
||||||
|
"brain",
|
||||||
|
"chair",
|
||||||
|
"charm",
|
||||||
|
"dream",
|
||||||
|
"field",
|
||||||
|
"flame",
|
||||||
|
"grape",
|
||||||
|
"heart",
|
||||||
|
"house",
|
||||||
|
"light",
|
||||||
|
"magic",
|
||||||
|
"music",
|
||||||
|
"plant",
|
||||||
|
"river",
|
||||||
|
"smile",
|
||||||
|
"stone",
|
||||||
|
"table",
|
||||||
|
"world"
|
||||||
|
]
|
||||||
|
const FALLBACK_EXTRA_DICTIONARY = [
|
||||||
|
"adieu",
|
||||||
|
"audio",
|
||||||
|
"crane",
|
||||||
|
"later",
|
||||||
|
"least",
|
||||||
|
"raise",
|
||||||
|
"roast",
|
||||||
|
"slate",
|
||||||
|
"stare",
|
||||||
|
"tears",
|
||||||
|
"trace"
|
||||||
|
]
|
||||||
|
|
||||||
const keyboard = document.querySelector("[data-keyboard]")
|
const keyboard = document.querySelector("[data-keyboard]")
|
||||||
const alertContainer = document.querySelector("[data-alert-container]")
|
const alertContainer = document.querySelector("[data-alert-container]")
|
||||||
const guessGrid = document.querySelector("[data-guess-grid]")
|
const guessGrid = document.querySelector("[data-guess-grid]")
|
||||||
|
const roundStatus = document.getElementById("round-status")
|
||||||
|
const triesStatus = document.getElementById("tries-status")
|
||||||
|
const themeButton = document.getElementById("theme-button")
|
||||||
|
const statsButton = document.getElementById("Stats-button")
|
||||||
|
const statsModal = document.getElementById("stats-modal")
|
||||||
|
const statsGrid = document.getElementById("stats-grid")
|
||||||
|
const guessBars = document.getElementById("guess-bars")
|
||||||
|
const resetStatsButton = document.getElementById("reset-stats")
|
||||||
|
const shareResultsButton = document.getElementById("share-results")
|
||||||
|
|
||||||
|
if (document.readyState === "loading") {
|
||||||
|
document.addEventListener("DOMContentLoaded", initializeGame, { once: true })
|
||||||
|
} else {
|
||||||
|
initializeGame()
|
||||||
|
}
|
||||||
|
|
||||||
// Initialize the game by loading JSON data
|
|
||||||
async function initializeGame() {
|
async function initializeGame() {
|
||||||
|
if (hasInitialized) return
|
||||||
|
hasInitialized = true
|
||||||
|
|
||||||
|
createBoard()
|
||||||
|
createKeyboard()
|
||||||
|
restoreTheme()
|
||||||
|
bindControls()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Load both JSON files
|
await loadWordLists()
|
||||||
const [targetWordsResponse, dictionaryResponse] = await Promise.all([
|
roundStatus.textContent = wordListMode === "full" ? "Ready" : "Answer list loaded"
|
||||||
fetch('targetWords.json'),
|
} catch (error) {
|
||||||
fetch('dictionary.json')
|
console.error("Failed to initialize game:", error)
|
||||||
])
|
useFallbackWordLists()
|
||||||
|
roundStatus.textContent = "Offline word set"
|
||||||
// Check if responses are ok
|
showAlert("Using a compact offline word set", 3000)
|
||||||
if (!targetWordsResponse.ok) {
|
|
||||||
throw new Error(`Failed to load targetWords.json: ${targetWordsResponse.status}`)
|
|
||||||
}
|
|
||||||
if (!dictionaryResponse.ok) {
|
|
||||||
throw new Error(`Failed to load dictionary.json: ${dictionaryResponse.status}`)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse JSON data
|
|
||||||
targetWords = await targetWordsResponse.json()
|
|
||||||
dictionary = await dictionaryResponse.json()
|
|
||||||
|
|
||||||
// Validate data
|
|
||||||
if (!Array.isArray(targetWords) || targetWords.length === 0) {
|
|
||||||
throw new Error('Target words must be a non-empty array')
|
|
||||||
}
|
|
||||||
if (!Array.isArray(dictionary) || dictionary.length === 0) {
|
|
||||||
throw new Error('Dictionary must be a non-empty array')
|
|
||||||
}
|
|
||||||
|
|
||||||
// Select random target word
|
|
||||||
targetWord = targetWords[Math.floor(Math.random() * targetWords.length)]
|
targetWord = targetWords[Math.floor(Math.random() * targetWords.length)]
|
||||||
|
dictionarySet.add(targetWord)
|
||||||
// Start the game
|
updateTriesStatus()
|
||||||
startInteraction()
|
startInteraction()
|
||||||
|
|
||||||
console.log('Game initialized successfully!')
|
|
||||||
console.log(`Target word selected from ${targetWords.length} possible words`)
|
|
||||||
console.log(`Dictionary loaded with ${dictionary.length} words`)
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Failed to initialize game:', error)
|
|
||||||
showAlert(`Error loading game data: ${error.message}`, 5000)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Alternative initialization with date-based word selection (uncomment if needed)
|
async function loadWordLists() {
|
||||||
/*
|
targetWords = await loadWordList("targetWords")
|
||||||
async function initializeGameWithDate() {
|
|
||||||
|
if (targetWords.length === 0) {
|
||||||
|
throw new Error("targetWords.json is empty or invalid")
|
||||||
|
}
|
||||||
|
|
||||||
|
let dictionaryWords = []
|
||||||
try {
|
try {
|
||||||
const [targetWordsResponse, dictionaryResponse] = await Promise.all([
|
dictionaryWords = await loadWordList("dictionary")
|
||||||
fetch('targetWords.json'),
|
|
||||||
fetch('dictionary.json')
|
|
||||||
])
|
|
||||||
|
|
||||||
if (!targetWordsResponse.ok || !dictionaryResponse.ok) {
|
|
||||||
throw new Error('Failed to load game data files')
|
|
||||||
}
|
|
||||||
|
|
||||||
targetWords = await targetWordsResponse.json()
|
|
||||||
dictionary = await dictionaryResponse.json()
|
|
||||||
|
|
||||||
// Date-based word selection
|
|
||||||
const offsetFromDate = new Date(2022, 0, 1)
|
|
||||||
const msOffset = Date.now() - offsetFromDate
|
|
||||||
const dayOffset = Math.floor(msOffset / 1000 / 60 / 60 / 24)
|
|
||||||
targetWord = targetWords[dayOffset % targetWords.length]
|
|
||||||
|
|
||||||
startInteraction()
|
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to initialize game:', error)
|
console.warn("dictionary.json unavailable; accepting target words only.", error)
|
||||||
showAlert(`Error loading game data: ${error.message}`, 5000)
|
}
|
||||||
|
|
||||||
|
dictionary = normalizeWords([
|
||||||
|
...dictionaryWords,
|
||||||
|
...targetWords
|
||||||
|
])
|
||||||
|
dictionarySet = new Set(dictionary)
|
||||||
|
wordListMode = dictionaryWords.length > 0 ? "full" : "answers-only"
|
||||||
|
|
||||||
|
if (dictionarySet.size === 0) {
|
||||||
|
throw new Error("Accepted word list is empty or invalid")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
async function loadWordList(listName) {
|
||||||
|
const fileName = listName === "targetWords" ? "targetWords.json" : "dictionary.json"
|
||||||
|
|
||||||
|
try {
|
||||||
|
return normalizeWords(await fetchJsonFile(fileName))
|
||||||
|
} catch (error) {
|
||||||
|
const embeddedWords = getEmbeddedWordList(listName)
|
||||||
|
if (embeddedWords.length > 0) {
|
||||||
|
console.info(`${fileName} unavailable; using bundled word data.`, error)
|
||||||
|
return embeddedWords
|
||||||
|
}
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getEmbeddedWordList(listName) {
|
||||||
|
return normalizeWords(window.FANCY_WORDLE_WORD_DATA?.[listName])
|
||||||
|
}
|
||||||
|
|
||||||
|
function useFallbackWordLists() {
|
||||||
|
targetWords = [...FALLBACK_TARGET_WORDS]
|
||||||
|
dictionary = [...new Set([...FALLBACK_TARGET_WORDS, ...FALLBACK_EXTRA_DICTIONARY])]
|
||||||
|
dictionarySet = new Set(dictionary)
|
||||||
|
wordListMode = "fallback"
|
||||||
|
}
|
||||||
|
|
||||||
|
async function fetchJsonFile(fileName) {
|
||||||
|
const response = await fetch(fileName, { cache: "no-store" })
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`${fileName} returned ${response.status}`)
|
||||||
|
}
|
||||||
|
return response.json()
|
||||||
|
}
|
||||||
|
|
||||||
|
function normalizeWords(words) {
|
||||||
|
if (!Array.isArray(words)) return []
|
||||||
|
return words
|
||||||
|
.map(word => String(word).trim().toLowerCase())
|
||||||
|
.filter(word => word.length === WORD_LENGTH)
|
||||||
|
}
|
||||||
|
|
||||||
|
function createBoard() {
|
||||||
|
guessGrid.innerHTML = ""
|
||||||
|
|
||||||
|
for (let index = 0; index < WORD_LENGTH * MAX_GUESSES; index += 1) {
|
||||||
|
const tile = document.createElement("div")
|
||||||
|
tile.className = "tile"
|
||||||
|
tile.setAttribute("role", "img")
|
||||||
|
tile.setAttribute("aria-label", "Empty letter")
|
||||||
|
guessGrid.append(tile)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function createKeyboard() {
|
||||||
|
keyboard.innerHTML = ""
|
||||||
|
|
||||||
|
KEY_ROWS.forEach((row, rowIndex) => {
|
||||||
|
if (rowIndex === 1) keyboard.append(createSpacer())
|
||||||
|
|
||||||
|
if (rowIndex === 2) {
|
||||||
|
keyboard.append(createActionKey("Enter", "Enter", "data-enter"))
|
||||||
|
}
|
||||||
|
|
||||||
|
row.split("").forEach(letter => {
|
||||||
|
const key = document.createElement("button")
|
||||||
|
key.className = "key"
|
||||||
|
key.type = "button"
|
||||||
|
key.dataset.key = letter
|
||||||
|
key.textContent = letter
|
||||||
|
key.setAttribute("aria-label", letter)
|
||||||
|
keyboard.append(key)
|
||||||
|
})
|
||||||
|
|
||||||
|
if (rowIndex === 2) {
|
||||||
|
keyboard.append(createActionKey("⌫", "Delete letter", "data-delete"))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function createSpacer() {
|
||||||
|
const spacer = document.createElement("span")
|
||||||
|
spacer.className = "key space"
|
||||||
|
spacer.setAttribute("aria-hidden", "true")
|
||||||
|
return spacer
|
||||||
|
}
|
||||||
|
|
||||||
|
function createActionKey(label, ariaLabel, attribute) {
|
||||||
|
const key = document.createElement("button")
|
||||||
|
key.className = "key large"
|
||||||
|
key.type = "button"
|
||||||
|
key.textContent = label
|
||||||
|
key.setAttribute(attribute, "")
|
||||||
|
key.setAttribute("aria-label", ariaLabel)
|
||||||
|
return key
|
||||||
|
}
|
||||||
|
|
||||||
|
function bindControls() {
|
||||||
|
themeButton.addEventListener("click", toggleTheme)
|
||||||
|
statsButton.addEventListener("click", openStats)
|
||||||
|
resetStatsButton.addEventListener("click", resetStats)
|
||||||
|
shareResultsButton.addEventListener("click", shareResult)
|
||||||
|
document.querySelector(".brand").addEventListener("click", event => {
|
||||||
|
event.preventDefault()
|
||||||
|
window.location.reload()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
function startInteraction() {
|
function startInteraction() {
|
||||||
|
stopInteraction()
|
||||||
document.addEventListener("click", handleMouseClick)
|
document.addEventListener("click", handleMouseClick)
|
||||||
document.addEventListener("keydown", handleKeyPress)
|
document.addEventListener("keydown", handleKeyPress)
|
||||||
}
|
}
|
||||||
@ -97,360 +242,457 @@ function stopInteraction() {
|
|||||||
document.removeEventListener("keydown", handleKeyPress)
|
document.removeEventListener("keydown", handleKeyPress)
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleMouseClick(e) {
|
function handleMouseClick(event) {
|
||||||
if (e.target.closest("[data-key]")) {
|
const keyButton = event.target.closest("[data-key]")
|
||||||
pressKey(e.target.dataset.key)
|
if (keyButton) {
|
||||||
|
pressKey(keyButton.dataset.key)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e.target.closest("[data-enter]")) {
|
if (event.target.closest("[data-enter]")) {
|
||||||
submitGuess()
|
submitGuess()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e.target.closest("[data-delete]")) {
|
if (event.target.closest("[data-delete]")) {
|
||||||
deleteKey()
|
deleteKey()
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleKeyPress(e) {
|
function handleKeyPress(event) {
|
||||||
if (e.key === "Enter") {
|
if (statsModal.open) return
|
||||||
|
|
||||||
|
if (event.key === "Enter") {
|
||||||
submitGuess()
|
submitGuess()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e.key === "Backspace" || e.key === "Delete") {
|
if (event.key === "Backspace" || event.key === "Delete") {
|
||||||
deleteKey()
|
deleteKey()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e.key.match(/^[a-z]$/)) {
|
if (/^[a-z]$/i.test(event.key)) {
|
||||||
pressKey(e.key)
|
pressKey(event.key)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function pressKey(key) {
|
function pressKey(key) {
|
||||||
const activeTiles = getActiveTiles()
|
if (gameFinished || isAnimating) return
|
||||||
if (activeTiles.length >= WORD_LENGTH) return
|
|
||||||
const nextTile = guessGrid.querySelector(":not([data-letter])")
|
if (currentTileIndex >= WORD_LENGTH) return
|
||||||
nextTile.dataset.letter = key.toLowerCase()
|
|
||||||
nextTile.textContent = key
|
const nextTile = getCurrentRowTiles()[currentTileIndex]
|
||||||
|
if (!nextTile) return
|
||||||
|
|
||||||
|
const letter = key.toLowerCase()
|
||||||
|
nextTile.dataset.letter = letter
|
||||||
|
nextTile.textContent = letter
|
||||||
nextTile.dataset.state = "active"
|
nextTile.dataset.state = "active"
|
||||||
|
nextTile.setAttribute("aria-label", letter)
|
||||||
|
currentTileIndex += 1
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteKey() {
|
function deleteKey() {
|
||||||
const activeTiles = getActiveTiles()
|
if (gameFinished || isAnimating) return
|
||||||
const lastTile = activeTiles[activeTiles.length - 1]
|
|
||||||
if (lastTile == null) return
|
if (currentTileIndex === 0) return
|
||||||
|
|
||||||
|
currentTileIndex -= 1
|
||||||
|
const lastTile = getCurrentRowTiles()[currentTileIndex]
|
||||||
|
if (!lastTile) return
|
||||||
|
|
||||||
lastTile.textContent = ""
|
lastTile.textContent = ""
|
||||||
delete lastTile.dataset.state
|
lastTile.removeAttribute("data-state")
|
||||||
delete lastTile.dataset.letter
|
lastTile.removeAttribute("data-letter")
|
||||||
|
lastTile.setAttribute("aria-label", "Empty letter")
|
||||||
}
|
}
|
||||||
|
|
||||||
function submitGuess() {
|
function submitGuess() {
|
||||||
const activeTiles = [...getActiveTiles()]
|
if (gameFinished || isAnimating) return
|
||||||
|
|
||||||
|
const activeTiles = getCurrentRowTiles().filter(tile => tile.dataset.letter)
|
||||||
if (activeTiles.length !== WORD_LENGTH) {
|
if (activeTiles.length !== WORD_LENGTH) {
|
||||||
showAlert("Not enough letters, Sara")
|
showAlert("Not enough letters")
|
||||||
shakeTiles(activeTiles)
|
shakeTiles(activeTiles)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const guess = activeTiles.reduce((word, tile) => {
|
const guess = activeTiles.map(tile => tile.dataset.letter).join("")
|
||||||
return word + tile.dataset.letter
|
if (!isValidGuess(guess)) {
|
||||||
}, "")
|
showAlert("Not in word list")
|
||||||
|
|
||||||
if (!dictionary.includes(guess)) {
|
|
||||||
showAlert("Not in dictionary")
|
|
||||||
shakeTiles(activeTiles)
|
shakeTiles(activeTiles)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
stopInteraction()
|
stopInteraction()
|
||||||
activeTiles.forEach((...params) => flipTile(...params, guess))
|
isAnimating = true
|
||||||
|
roundStatus.textContent = "Checking guess…"
|
||||||
|
currentGuessIndex += 1
|
||||||
|
updateTriesStatus()
|
||||||
|
|
||||||
|
const states = scoreGuess(guess, targetWord)
|
||||||
|
activeTiles.forEach((tile, index, tiles) => {
|
||||||
|
flipTile(tile, index, tiles, guess, states[index])
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function flipTile(tile, index, array, guess) {
|
function isValidGuess(guess) {
|
||||||
|
if (!/^[a-z]{5}$/.test(guess)) return false
|
||||||
|
return dictionarySet.has(guess)
|
||||||
|
}
|
||||||
|
|
||||||
|
function scoreGuess(guess, answer) {
|
||||||
|
const states = Array(WORD_LENGTH).fill("wrong")
|
||||||
|
const remaining = {}
|
||||||
|
|
||||||
|
for (let index = 0; index < WORD_LENGTH; index += 1) {
|
||||||
|
if (guess[index] === answer[index]) {
|
||||||
|
states[index] = "correct"
|
||||||
|
} else {
|
||||||
|
remaining[answer[index]] = (remaining[answer[index]] || 0) + 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let index = 0; index < WORD_LENGTH; index += 1) {
|
||||||
|
const letter = guess[index]
|
||||||
|
if (states[index] === "correct") continue
|
||||||
|
if (remaining[letter] > 0) {
|
||||||
|
states[index] = "wrong-position"
|
||||||
|
remaining[letter] -= 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return states
|
||||||
|
}
|
||||||
|
|
||||||
|
function flipTile(tile, index, tiles, guess, state) {
|
||||||
const letter = tile.dataset.letter
|
const letter = tile.dataset.letter
|
||||||
const key = keyboard.querySelector(`[data-key="${letter}"i]`)
|
const key = keyboard.querySelector(`[data-key="${letter}"i]`)
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
tile.classList.add("flip")
|
tile.classList.add("flip")
|
||||||
}, (index * FLIP_ANIMATION_DURATION) / 2)
|
|
||||||
|
|
||||||
tile.addEventListener(
|
setTimeout(() => {
|
||||||
"transitionend",
|
|
||||||
() => {
|
|
||||||
tile.classList.remove("flip")
|
tile.classList.remove("flip")
|
||||||
if (targetWord[index] === letter) {
|
tile.textContent = letter
|
||||||
tile.dataset.state = "correct"
|
tile.dataset.state = state
|
||||||
key.classList.add("correct")
|
tile.setAttribute("aria-label", `${letter}, ${readableState(state)}`)
|
||||||
} else if (targetWord.includes(letter)) {
|
updateKeyState(key, state)
|
||||||
tile.dataset.state = "wrong-position"
|
|
||||||
key.classList.add("wrong-position")
|
if (index === tiles.length - 1) {
|
||||||
} else {
|
setTimeout(() => {
|
||||||
tile.dataset.state = "wrong"
|
currentTileIndex = 0
|
||||||
key.classList.add("wrong")
|
isAnimating = false
|
||||||
|
checkWinLose(guess, tiles)
|
||||||
|
}, FLIP_ANIMATION_DURATION / 2)
|
||||||
|
}
|
||||||
|
}, FLIP_ANIMATION_DURATION / 2)
|
||||||
|
}, (index * FLIP_ANIMATION_DURATION) / 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (index === array.length - 1) {
|
function updateKeyState(key, state) {
|
||||||
tile.addEventListener(
|
if (!key) return
|
||||||
"transitionend",
|
|
||||||
() => {
|
const rank = { wrong: 1, "wrong-position": 2, correct: 3 }
|
||||||
startInteraction()
|
const currentState = ["wrong", "wrong-position", "correct"].find(name => key.classList.contains(name))
|
||||||
checkWinLose(guess, array)
|
|
||||||
},
|
if (!currentState || rank[state] > rank[currentState]) {
|
||||||
{ once: true }
|
key.classList.remove("wrong", "wrong-position", "correct")
|
||||||
)
|
key.classList.add(state)
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
{ once: true }
|
|
||||||
)
|
function readableState(state) {
|
||||||
|
if (state === "correct") return "correct"
|
||||||
|
if (state === "wrong-position") return "in the word, wrong spot"
|
||||||
|
return "not in the word"
|
||||||
}
|
}
|
||||||
|
|
||||||
function getActiveTiles() {
|
function getActiveTiles() {
|
||||||
return guessGrid.querySelectorAll('[data-state="active"]')
|
return guessGrid.querySelectorAll('[data-state="active"]')
|
||||||
}
|
}
|
||||||
|
|
||||||
function showAlert(message, duration = 1000) {
|
function getCurrentRowTiles() {
|
||||||
|
const tiles = [...guessGrid.children]
|
||||||
|
const rowStart = currentGuessIndex * WORD_LENGTH
|
||||||
|
return tiles.slice(rowStart, rowStart + WORD_LENGTH)
|
||||||
|
}
|
||||||
|
|
||||||
|
function showAlert(message, duration = 1400) {
|
||||||
const alert = document.createElement("div")
|
const alert = document.createElement("div")
|
||||||
alert.textContent = message
|
alert.textContent = message
|
||||||
alert.classList.add("alert")
|
alert.className = "alert"
|
||||||
alertContainer.prepend(alert)
|
alertContainer.prepend(alert)
|
||||||
|
|
||||||
if (duration == null) return
|
if (duration == null) return
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => dismissAlert(alert), duration)
|
||||||
|
}
|
||||||
|
|
||||||
|
function dismissAlert(alert) {
|
||||||
alert.classList.add("hide")
|
alert.classList.add("hide")
|
||||||
alert.addEventListener("transitionend", () => {
|
alert.addEventListener("transitionend", () => alert.remove(), { once: true })
|
||||||
alert.remove()
|
|
||||||
})
|
|
||||||
}, duration)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function shakeTiles(tiles) {
|
function shakeTiles(tiles) {
|
||||||
tiles.forEach(tile => {
|
tiles.forEach(tile => {
|
||||||
tile.classList.add("shake")
|
tile.classList.add("shake")
|
||||||
tile.addEventListener(
|
tile.addEventListener("animationend", () => tile.classList.remove("shake"), { once: true })
|
||||||
"animationend",
|
|
||||||
() => {
|
|
||||||
tile.classList.remove("shake")
|
|
||||||
},
|
|
||||||
{ once: true }
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
// The CELEBRATION SOUND EFFECT
|
|
||||||
function playCelebrationSound() {
|
|
||||||
const audio = new Audio('Celebration.mp3')
|
|
||||||
audio.volume = 0.5 // Adjust volume as needed
|
|
||||||
audio.play().catch(error => {
|
|
||||||
console.error('Error playing celebration sound:', error)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
// IT'S RIGHT HERE YOU BLIND MOFO"
|
|
||||||
function checkWinLose(guess, tiles) {
|
function checkWinLose(guess, tiles) {
|
||||||
if (guess === targetWord) {
|
if (guess === targetWord) {
|
||||||
|
gameFinished = true
|
||||||
|
lastResult = { won: true, guesses: currentGuessIndex, word: targetWord }
|
||||||
|
saveGameResult(lastResult)
|
||||||
playCelebrationSound()
|
playCelebrationSound()
|
||||||
showAlert("Congratulations, You win!", 5000)
|
showAlert("Congratulations, you win!", 5000)
|
||||||
danceTiles(tiles)
|
danceTiles(tiles)
|
||||||
celebrateWithConfetti()
|
celebrateWithConfetti()
|
||||||
setTimeout(() => {
|
roundStatus.textContent = `Solved in ${currentGuessIndex}`
|
||||||
showWordDefinition(targetWord, true)
|
setTimeout(() => showWordDefinition(targetWord, true), 1800)
|
||||||
},3000)
|
|
||||||
stopInteraction()
|
stopInteraction()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const remainingTiles = guessGrid.querySelectorAll(":not([data-letter])")
|
const remainingTiles = guessGrid.querySelectorAll(":not([data-letter])")
|
||||||
if (remainingTiles.length === 0) {
|
if (remainingTiles.length === 0) {
|
||||||
|
gameFinished = true
|
||||||
|
lastResult = { won: false, guesses: MAX_GUESSES, word: targetWord }
|
||||||
|
saveGameResult(lastResult)
|
||||||
showAlert(targetWord.toUpperCase(), null)
|
showAlert(targetWord.toUpperCase(), null)
|
||||||
|
roundStatus.textContent = "Round complete"
|
||||||
showWordDefinition(targetWord, false)
|
showWordDefinition(targetWord, false)
|
||||||
stopInteraction()
|
stopInteraction()
|
||||||
}
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
roundStatus.textContent = "Keep going"
|
||||||
|
startInteraction()
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateTriesStatus() {
|
||||||
|
triesStatus.textContent = `${currentGuessIndex} / ${MAX_GUESSES}`
|
||||||
|
}
|
||||||
|
|
||||||
|
function playCelebrationSound() {
|
||||||
|
const audio = new Audio("Celebration.mp3")
|
||||||
|
audio.volume = 0.45
|
||||||
|
audio.play().catch(error => {
|
||||||
|
console.info("Celebration sound was blocked or unavailable:", error)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function to fetch and display word definition
|
|
||||||
async function showWordDefinition(word, isWin = true) {
|
async function showWordDefinition(word, isWin = true) {
|
||||||
try {
|
try {
|
||||||
console.log(`Fetching definition for: ${word}`)
|
|
||||||
|
|
||||||
const response = await fetch(`https://api.dictionaryapi.dev/api/v2/entries/en/${word}`)
|
const response = await fetch(`https://api.dictionaryapi.dev/api/v2/entries/en/${word}`)
|
||||||
|
if (!response.ok) throw new Error(`API request failed: ${response.status}`)
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error(`API request failed: ${response.status}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
const data = await response.json()
|
const data = await response.json()
|
||||||
|
|
||||||
// Extract the first definition
|
|
||||||
const firstMeaning = data[0]?.meanings?.[0]
|
const firstMeaning = data[0]?.meanings?.[0]
|
||||||
const definition = firstMeaning?.definitions?.[0]?.definition
|
const definition = firstMeaning?.definitions?.[0]?.definition
|
||||||
const partOfSpeech = firstMeaning?.partOfSpeech
|
const partOfSpeech = firstMeaning?.partOfSpeech
|
||||||
const example = firstMeaning?.definitions?.[0]?.example
|
const example = firstMeaning?.definitions?.[0]?.example
|
||||||
|
|
||||||
if (definition) {
|
if (!definition) throw new Error("No definition found")
|
||||||
// Create definition display
|
|
||||||
let definitionText = `📖 **${word.toUpperCase()}** (${partOfSpeech || 'word'})\n${definition}`
|
|
||||||
|
|
||||||
if (example) {
|
|
||||||
definitionText += `\n\n💡 Example: "${example}"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Show definition in a styled alert
|
|
||||||
showDefinitionAlert(definitionText, isWin)
|
|
||||||
|
|
||||||
} else {
|
|
||||||
throw new Error('No definition found')
|
|
||||||
}
|
|
||||||
|
|
||||||
|
showDefinitionAlert({
|
||||||
|
title: `${word.toUpperCase()} ${partOfSpeech ? `(${partOfSpeech})` : ""}`,
|
||||||
|
body: definition,
|
||||||
|
example,
|
||||||
|
isWin
|
||||||
|
})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error fetching definition:', error)
|
console.info("Definition lookup unavailable:", error)
|
||||||
|
showDefinitionAlert({
|
||||||
// Fallback message
|
title: word.toUpperCase(),
|
||||||
const fallbackMsg = `📖 **${word.toUpperCase()}**\nDefinition not available at the moment.`
|
body: "Definition not available at the moment.",
|
||||||
showDefinitionAlert(fallbackMsg, isWin)
|
isWin
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Special alert function for definitions
|
function showDefinitionAlert({ title, body, example, isWin }) {
|
||||||
function showDefinitionAlert(message, isWin = true) {
|
const alert = document.createElement("button")
|
||||||
const alert = document.createElement("div")
|
alert.type = "button"
|
||||||
alert.innerHTML = message.replace(/\n/g, '<br>').replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>')
|
alert.className = `alert definition-alert ${isWin ? "win-definition" : "lose-definition"}`
|
||||||
alert.classList.add("alert", "definition-alert")
|
alert.innerHTML = `
|
||||||
|
<strong>${escapeHtml(title)}</strong>
|
||||||
if (isWin) {
|
<span>${escapeHtml(body)}</span>
|
||||||
alert.classList.add("win-definition")
|
${example ? `<span><br><br>Example: “${escapeHtml(example)}”</span>` : ""}
|
||||||
} else {
|
`
|
||||||
alert.classList.add("lose-definition")
|
|
||||||
}
|
|
||||||
|
|
||||||
alertContainer.prepend(alert)
|
alertContainer.prepend(alert)
|
||||||
|
alert.addEventListener("click", () => dismissAlert(alert))
|
||||||
// Auto-hide after 8 seconds (longer for reading)
|
setTimeout(() => dismissAlert(alert), 10000)
|
||||||
setTimeout(() => {
|
}
|
||||||
alert.classList.add("hide")
|
|
||||||
alert.addEventListener("transitionend", () => {
|
function escapeHtml(value) {
|
||||||
alert.remove()
|
return String(value)
|
||||||
})
|
.replaceAll("&", "&")
|
||||||
}, 8000)
|
.replaceAll("<", "<")
|
||||||
|
.replaceAll(">", ">")
|
||||||
// Click to dismiss
|
.replaceAll('"', """)
|
||||||
alert.addEventListener('click', () => {
|
.replaceAll("'", "'")
|
||||||
alert.classList.add("hide")
|
|
||||||
alert.addEventListener("transitionend", () => {
|
|
||||||
alert.remove()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Confetti celebration function
|
|
||||||
function celebrateWithConfetti() {
|
function celebrateWithConfetti() {
|
||||||
console.log('Confetti celebration triggered!')
|
if (typeof confetti === "undefined") return
|
||||||
|
|
||||||
// Check if confetti library is loaded
|
const colors = ["#c87949", "#e8c66f", "#7e9f70", "#f7efe6", "#332820"]
|
||||||
if (typeof confetti === 'undefined') {
|
confetti({ particleCount: 90, spread: 70, origin: { y: 0.58 }, colors })
|
||||||
console.error('Confetti library not loaded! Make sure to include the script tag.')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Initial burst from the center
|
|
||||||
confetti({
|
|
||||||
particleCount: 100,
|
|
||||||
spread: 70,
|
|
||||||
origin: { y: 0.6 }
|
|
||||||
})
|
|
||||||
|
|
||||||
// Side cannons effect
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
confetti({
|
confetti({ particleCount: 46, angle: 60, spread: 55, origin: { x: 0 }, colors })
|
||||||
particleCount: 50,
|
confetti({ particleCount: 46, angle: 120, spread: 55, origin: { x: 1 }, colors })
|
||||||
angle: 60,
|
}, 220)
|
||||||
spread: 55,
|
|
||||||
origin: { x: 0 }
|
|
||||||
})
|
|
||||||
confetti({
|
|
||||||
particleCount: 50,
|
|
||||||
angle: 120,
|
|
||||||
spread: 55,
|
|
||||||
origin: { x: 1 }
|
|
||||||
})
|
|
||||||
}, 200)
|
|
||||||
|
|
||||||
// Stars effect
|
|
||||||
setTimeout(() => {
|
|
||||||
confetti({
|
|
||||||
particleCount: 30,
|
|
||||||
spread: 360,
|
|
||||||
startVelocity: 30,
|
|
||||||
decay: 0.9,
|
|
||||||
scalar: 1.2,
|
|
||||||
shapes: ['star'],
|
|
||||||
colors: ['#ff6b6b', '#4ecdc4', '#45b7d1', '#96ceb4', '#ffeaa7']
|
|
||||||
})
|
|
||||||
}, 400)
|
|
||||||
|
|
||||||
// Final cascade
|
|
||||||
setTimeout(() => {
|
|
||||||
confetti({
|
|
||||||
particleCount: 200,
|
|
||||||
spread: 100,
|
|
||||||
origin: { y: 0.4 },
|
|
||||||
colors: ['#ff6b6b', '#4ecdc4', '#45b7d1', '#96ceb4', '#ffeaa7', '#dda0dd']
|
|
||||||
})
|
|
||||||
}, 600)
|
|
||||||
|
|
||||||
console.log('Confetti animation started successfully!')
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error triggering confetti:', error)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function danceTiles(tiles) {
|
function danceTiles(tiles) {
|
||||||
tiles.forEach((tile, index) => {
|
tiles.forEach((tile, index) => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
tile.classList.add("dance")
|
tile.classList.add("dance")
|
||||||
tile.addEventListener(
|
tile.addEventListener("animationend", () => tile.classList.remove("dance"), { once: true })
|
||||||
"animationend",
|
}, (index * DANCE_ANIMATION_DURATION) / WORD_LENGTH)
|
||||||
() => {
|
|
||||||
tile.classList.remove("dance")
|
|
||||||
},
|
|
||||||
{ once: true }
|
|
||||||
)
|
|
||||||
}, (index * DANCE_ANIMATION_DURATION) / 5)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/*==================== DARK LIGHT THEME ====================*/
|
function restoreTheme() {
|
||||||
const themeButton = document.getElementById('theme-button')
|
const selectedTheme = localStorage.getItem("selected-theme")
|
||||||
const darkTheme = 'dark-theme'
|
if (selectedTheme === "dark") {
|
||||||
const iconTheme = 'bx-sun'
|
document.body.classList.add("dark-theme")
|
||||||
|
themeButton.setAttribute("aria-label", "Switch to light mode")
|
||||||
// Previously selected topic (if user selected)
|
}
|
||||||
const selectedTheme = localStorage.getItem('selected-theme')
|
|
||||||
const selectedIcon = localStorage.getItem('selected-icon')
|
|
||||||
|
|
||||||
// We obtain the current theme that the interface has by validating the dark-theme class
|
|
||||||
const getCurrentTheme = () => document.body.classList.contains(darkTheme) ? 'dark' : 'light'
|
|
||||||
const getCurrentIcon = () => themeButton.classList.contains(iconTheme) ? 'bx-moon' : 'bx-sun'
|
|
||||||
|
|
||||||
// We validate if the user previously chose a topic
|
|
||||||
if (selectedTheme) {
|
|
||||||
// If the validation is fulfilled, we ask what the issue was to know if we activated or deactivated the dark
|
|
||||||
document.body.classList[selectedTheme === 'dark' ? 'add' : 'remove'](darkTheme)
|
|
||||||
themeButton.classList[selectedIcon === 'bx-moon' ? 'add' : 'remove'](iconTheme)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Activate / deactivate the theme manually with the button
|
function toggleTheme() {
|
||||||
themeButton.addEventListener('click', () => {
|
document.body.classList.toggle("dark-theme")
|
||||||
// Add or remove the dark / icon theme
|
const theme = document.body.classList.contains("dark-theme") ? "dark" : "light"
|
||||||
document.body.classList.toggle(darkTheme)
|
localStorage.setItem("selected-theme", theme)
|
||||||
themeButton.classList.toggle(iconTheme)
|
themeButton.setAttribute("aria-label", theme === "dark" ? "Switch to light mode" : "Switch to dark mode")
|
||||||
// We save the theme and the current icon that the user chose
|
}
|
||||||
localStorage.setItem('selected-theme', getCurrentTheme())
|
|
||||||
localStorage.setItem('selected-icon', getCurrentIcon())
|
|
||||||
})
|
|
||||||
|
|
||||||
// Initialize the game when the page loads
|
function openStats() {
|
||||||
document.addEventListener('DOMContentLoaded', initializeGame)
|
renderStats()
|
||||||
|
statsModal.showModal()
|
||||||
|
}
|
||||||
|
|
||||||
|
function getStats() {
|
||||||
|
const fallback = {
|
||||||
|
played: 0,
|
||||||
|
wins: 0,
|
||||||
|
currentStreak: 0,
|
||||||
|
maxStreak: 0,
|
||||||
|
distribution: [0, 0, 0, 0, 0, 0]
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return { ...fallback, ...JSON.parse(localStorage.getItem(STATS_KEY)) }
|
||||||
|
} catch {
|
||||||
|
return fallback
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function saveStats(stats) {
|
||||||
|
localStorage.setItem(STATS_KEY, JSON.stringify(stats))
|
||||||
|
}
|
||||||
|
|
||||||
|
function saveGameResult(result) {
|
||||||
|
const stats = getStats()
|
||||||
|
stats.played += 1
|
||||||
|
|
||||||
|
if (result.won) {
|
||||||
|
stats.wins += 1
|
||||||
|
stats.currentStreak += 1
|
||||||
|
stats.maxStreak = Math.max(stats.maxStreak, stats.currentStreak)
|
||||||
|
stats.distribution[result.guesses - 1] += 1
|
||||||
|
} else {
|
||||||
|
stats.currentStreak = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
saveStats(stats)
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderStats() {
|
||||||
|
const stats = getStats()
|
||||||
|
const winRate = stats.played === 0 ? 0 : Math.round((stats.wins / stats.played) * 100)
|
||||||
|
const statItems = [
|
||||||
|
["Played", stats.played],
|
||||||
|
["Win %", winRate],
|
||||||
|
["Streak", stats.currentStreak],
|
||||||
|
["Best", stats.maxStreak]
|
||||||
|
]
|
||||||
|
|
||||||
|
statsGrid.innerHTML = statItems
|
||||||
|
.map(([label, value]) => `<div class="stat-item"><strong>${value}</strong><span>${label}</span></div>`)
|
||||||
|
.join("")
|
||||||
|
|
||||||
|
const maxGuessCount = Math.max(1, ...stats.distribution)
|
||||||
|
guessBars.innerHTML = stats.distribution
|
||||||
|
.map((count, index) => {
|
||||||
|
const width = Math.max(8, Math.round((count / maxGuessCount) * 100))
|
||||||
|
return `
|
||||||
|
<div class="guess-bar">
|
||||||
|
<span class="guess-bar-label">${index + 1}</span>
|
||||||
|
<span class="guess-bar-fill" style="width:${width}%">${count}</span>
|
||||||
|
</div>
|
||||||
|
`
|
||||||
|
})
|
||||||
|
.join("")
|
||||||
|
}
|
||||||
|
|
||||||
|
function resetStats() {
|
||||||
|
localStorage.removeItem(STATS_KEY)
|
||||||
|
renderStats()
|
||||||
|
showAlert("Stats reset")
|
||||||
|
}
|
||||||
|
|
||||||
|
async function shareResult() {
|
||||||
|
const text = buildShareText()
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (navigator.share) {
|
||||||
|
await navigator.share({ text })
|
||||||
|
} else if (navigator.clipboard) {
|
||||||
|
await navigator.clipboard.writeText(text)
|
||||||
|
showAlert("Result copied")
|
||||||
|
} else {
|
||||||
|
showAlert(text, 5000)
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.info("Share cancelled or unavailable:", error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildShareText() {
|
||||||
|
const status = lastResult
|
||||||
|
? `${lastResult.won ? lastResult.guesses : "X"}/${MAX_GUESSES}`
|
||||||
|
: `${currentGuessIndex}/${MAX_GUESSES}`
|
||||||
|
|
||||||
|
return `Fancy Wordle ${status}\n${getResultGrid()}`
|
||||||
|
}
|
||||||
|
|
||||||
|
function getResultGrid() {
|
||||||
|
const submittedTiles = [...guessGrid.querySelectorAll("[data-letter]")]
|
||||||
|
.filter(tile => tile.dataset.state && tile.dataset.state !== "active")
|
||||||
|
|
||||||
|
if (submittedTiles.length === 0) return "No guesses yet."
|
||||||
|
|
||||||
|
return chunk(submittedTiles, WORD_LENGTH)
|
||||||
|
.map(row => row.map(tile => {
|
||||||
|
if (tile.dataset.state === "correct") return "🟩"
|
||||||
|
if (tile.dataset.state === "wrong-position") return "🟨"
|
||||||
|
return "⬛"
|
||||||
|
}).join(""))
|
||||||
|
.join("\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
function chunk(items, size) {
|
||||||
|
const rows = []
|
||||||
|
for (let index = 0; index < items.length; index += size) {
|
||||||
|
rows.push(items.slice(index, index + size))
|
||||||
|
}
|
||||||
|
return rows
|
||||||
|
}
|
||||||
|
|||||||
1
word-data.js
Normal file
1
word-data.js
Normal file
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user