feat(01-02): welcome screen UI with onboarding flow

- Implement initWelcomeScreen with companion card rendering, layout toggle, start button
- Update index.html with welcome screen structure (companion-grid, layout-toggle, start-btn)
- Add CSS for companion cards, layout buttons, start button with hover/selected/disabled states
- Selecting a companion enables start, clicking start saves progress to IndexedDB and navigates to forest

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-29 11:06:54 +02:00
co-authored by Claude Opus 4.6
parent afae18decc
commit 20a7670ef9
3 changed files with 186 additions and 5 deletions
+15 -1
View File
@@ -12,7 +12,21 @@
/> />
</head> </head>
<body> <body>
<section id="screen-welcome" class="screen screen--active"></section> <section id="screen-welcome" class="screen screen--active">
<div class="welcome">
<h1>Willkommen im Zauberwald!</h1>
<p class="welcome__subtitle">Waehle deine Begleitfigur:</p>
<div class="welcome__companions" id="companion-grid">
<!-- Filled dynamically by screens.ts -->
</div>
<p class="welcome__layout-label">Tastatur-Layout:</p>
<div class="welcome__layout-toggle" id="layout-toggle">
<button class="layout-btn layout-btn--active" data-layout="de">DE</button>
<button class="layout-btn" data-layout="ch">CH</button>
</div>
<button class="welcome__start-btn" id="start-btn" disabled>Los geht's!</button>
</div>
</section>
<section id="screen-forest" class="screen"></section> <section id="screen-forest" class="screen"></section>
<section id="screen-lesson" class="screen"></section> <section id="screen-lesson" class="screen"></section>
<section id="screen-reward" class="screen"></section> <section id="screen-reward" class="screen"></section>
+106
View File
@@ -55,3 +55,109 @@ h3 {
opacity: 1; opacity: 1;
min-height: 100vh; min-height: 100vh;
} }
/* Welcome screen */
.welcome {
display: flex;
flex-direction: column;
align-items: center;
padding: 2rem;
max-width: 600px;
margin: 0 auto;
}
.welcome h1 {
font-family: "Quicksand", sans-serif;
font-size: 2rem;
color: var(--text-dark);
}
.welcome__subtitle,
.welcome__layout-label {
font-size: 1.1rem;
color: var(--text-warm);
margin-bottom: 0.5rem;
}
.welcome__companions {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 1rem;
width: 100%;
}
.companion-card {
background: white;
border: 3px solid transparent;
border-radius: 16px;
padding: 1.5rem;
cursor: pointer;
transition: border-color 0.2s;
text-align: center;
display: flex;
flex-direction: column;
align-items: center;
gap: 0.5rem;
}
.companion-card:hover {
border-color: var(--accent-gold);
}
.companion-card--selected {
border-color: var(--accent-green);
background: var(--bg-forest);
}
.companion-card__emoji {
font-size: 3rem;
}
.companion-card__name {
font-family: "Quicksand", sans-serif;
font-weight: 600;
font-size: 1.2rem;
color: var(--text-dark);
}
.welcome__layout-toggle {
display: flex;
gap: 0.5rem;
margin-top: 0.5rem;
}
.layout-btn {
padding: 0.5rem 1.5rem;
border-radius: 8px;
border: 2px solid var(--text-light);
background: white;
cursor: pointer;
font-family: "Nunito", sans-serif;
font-size: 1rem;
}
.layout-btn--active {
background: var(--accent-green);
color: white;
border-color: var(--accent-green);
}
.welcome__start-btn {
margin-top: 1.5rem;
padding: 1rem 3rem;
border-radius: 12px;
background: var(--accent-green);
color: white;
border: none;
font-family: "Quicksand", sans-serif;
font-weight: 700;
font-size: 1.3rem;
cursor: pointer;
opacity: 1;
transition: opacity 0.2s;
}
.welcome__start-btn:disabled {
opacity: 0.4;
cursor: not-allowed;
}
+65 -4
View File
@@ -1,8 +1,69 @@
import type { ScreenName } from "../types"; import type {
CompanionType,
KeyboardLayout,
ScreenName,
Progress,
} from "../types";
import { companions } from "../companion/characters";
import { saveProgress } from "../storage/db";
export function initWelcomeScreen( export function initWelcomeScreen(
_db: IDBDatabase, db: IDBDatabase,
_navigateTo: (screen: ScreenName) => void, navigateTo: (screen: ScreenName) => void,
): void { ): void {
// Implemented in Task 2 let selectedCompanion: CompanionType | null = null;
let selectedLayout: KeyboardLayout = "de";
const grid = document.getElementById("companion-grid")!;
const startBtn = document.getElementById("start-btn") as HTMLButtonElement;
const layoutToggle = document.getElementById("layout-toggle")!;
// Render companion cards
companions.forEach((c) => {
const card = document.createElement("button");
card.className = "companion-card";
card.dataset.companion = c.type;
card.innerHTML = `
<span class="companion-card__emoji">${c.emoji}</span>
<span class="companion-card__name">${c.name}</span>
`;
card.addEventListener("click", () => {
grid.querySelectorAll(".companion-card").forEach((el) =>
el.classList.remove("companion-card--selected"),
);
card.classList.add("companion-card--selected");
selectedCompanion = c.type;
startBtn.disabled = false;
});
grid.appendChild(card);
});
// Layout toggle
layoutToggle.addEventListener("click", (e) => {
const btn = (e.target as HTMLElement).closest(
".layout-btn",
) as HTMLButtonElement | null;
if (!btn) return;
layoutToggle
.querySelectorAll(".layout-btn")
.forEach((el) => el.classList.remove("layout-btn--active"));
btn.classList.add("layout-btn--active");
selectedLayout = btn.dataset.layout as KeyboardLayout;
});
// Start button
startBtn.addEventListener("click", async () => {
if (!selectedCompanion) return;
const progress: Progress = {
id: 1,
currentLevel: 1,
completedLevels: [],
totalSessions: 0,
sessionDates: [],
selectedCharacter: selectedCompanion,
selectedLayout: selectedLayout,
};
await saveProgress(db, progress);
navigateTo("forest");
});
} }