/* ============================================================
   SPIEL — Design-System für die legasthenie.me Lernspiele
   Konzept „Lesefenster“ (Mario, 03.11.2026): blau-weiß gerahmt,
   helles Design, Schrift Lexend, große Abstände, keine Verläufe.
   Vorlage: h15.drcag.com/SPIELREDESIGN/k5.html
   Mobile-first, Touch >= 48px. Alle Klassen unter .spiel-app
   gescoped — keine Kollision mit styles.css.
   ============================================================ */

/* ---------- Design-Tokens (Single Source of Truth) ----------
   Alle Spiele und die Canvas-Share-Karte (spiel-core.js, getComputedStyle)
   lesen diese Tokens. Namen unverändert gegenüber dem Schulheft-Look. */
.spiel-app, :root {
    --sp-paper: #ffffff;      /* Fläche im Fenster */
    --sp-grid: #dbe7f5;       /* nur noch Share-Karte */
    --sp-card: #ffffff;
    --sp-ink: #16324f;        /* Text */
    --sp-ink-soft: #5b6f86;
    --sp-accent: #1d64c2;     /* Rahmen-/Aktionsblau */
    --sp-accent-deep: #154b92;
    --sp-accent-soft: #e8f1fb;/* helle Blautönung */
    --sp-line: #bcd3ee;       /* feine blaue Linie */
    --sp-good: #1f9d63;
    --sp-good-soft: #e2f5ea;
    --sp-bad: #d9534f;
    --sp-bad-soft: #fde8e7;
    --sp-sun: #f0b400;
    --sp-radius: 14px;
    --sp-radius-lg: 22px;
    --sp-shadow: 0 0 0 2px var(--sp-line);   /* statt Schatten: feine Rahmenlinie */
    --sp-font: 'Lexend', 'Atkinson Hyperlegible', system-ui, sans-serif;
}

/* Semantische Aliasse (bestehende Spiele referenzieren --spiel-*) */
:root {
    --spiel-paper: var(--sp-paper);
    --spiel-grid-line: var(--sp-grid);
    --spiel-ink: var(--sp-ink);
    --spiel-ink-soft: var(--sp-ink-soft);
    --spiel-blue: var(--sp-accent);
    --spiel-blue-deep: var(--sp-accent-deep);
    --spiel-green: var(--sp-good);
    --spiel-green-deep: #17784b;
    --spiel-coral: var(--sp-bad);
    --spiel-coral-deep: #b53f3b;
    --spiel-sun: var(--sp-sun);
    --spiel-card: var(--sp-card);
    --spiel-shadow: var(--sp-shadow);
    --spiel-shadow-press: 0 0 0 2px var(--sp-line);
    --spiel-radius: var(--sp-radius-lg);
    --spiel-radius-sm: var(--sp-radius);
    --spiel-hue: var(--sp-accent);        /* ein Blau für alle Spiele */
    --spiel-hue-deep: var(--sp-accent-deep);
    --spiel-font: var(--sp-font);
    --spiel-touch: 56px;
    --spiel-safe-top: env(safe-area-inset-top, 0px);
    --spiel-safe-bottom: env(safe-area-inset-bottom, 0px);
}

.spiel-app *,
.spiel-app *::before,
.spiel-app *::after { margin: 0; padding: 0; box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body.spiel-body {
    font-family: var(--sp-font);
    font-size: 19px;
    line-height: 1.6;
    letter-spacing: 0.01em;
    color: var(--spiel-ink);
    min-height: 100vh;
    min-height: 100dvh;
    background: #ffffff;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    overscroll-behavior-y: none;
    margin: 0;
}

:where(.spiel-app) button { font-family: inherit; border: none; background: none; color: inherit; cursor: pointer; -webkit-user-select: none; user-select: none; }
.spiel-app img { max-width: 100%; }
:where(.spiel-app) a { color: var(--spiel-hue); }
.spiel-app [hidden] { display: none !important; }

/* ---------- Fenster (App-Rahmen) ---------- */
.spiel-app {
    max-width: 720px;
    margin: 0 auto;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    padding: calc(26px + var(--spiel-safe-top)) 20px calc(26px + var(--spiel-safe-bottom));
}
.spiel-frame {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    background: var(--spiel-paper);
    border: 4px solid var(--spiel-hue);
    border-radius: 30px;
    box-shadow: 0 0 0 12px var(--sp-accent-soft);
    padding: 0 26px 28px;
    overflow: hidden;
}

/* ---------- Kopfband ---------- */
.spiel-topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 64px;
    margin: 0 -26px 14px;
    padding: 10px 18px;
    background: var(--spiel-hue);
    color: #fff;
}
.spiel-icon-btn {
    width: 46px;
    height: 46px;
    flex: 0 0 46px;
    border-radius: var(--spiel-radius-sm);
    border: 2px solid rgba(255,255,255,.55);
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    line-height: 1;
    color: #fff;
    text-decoration: none;
    transition: transform 0.15s ease, background 0.15s ease;
}
.spiel-icon-btn:hover { background: rgba(255,255,255,.14); }
.spiel-icon-btn:active { transform: scale(0.92); }
.spiel-topbar-title {
    font-size: 1.05em;
    font-weight: 700;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.spiel-topbar-meta {
    margin-left: auto;
    font-size: 0.8em;
    color: rgba(255,255,255,.9);
    white-space: nowrap;
}
.spiel-topbar-meta + .spiel-icon-btn { margin-left: 0; }
.spiel-topbar > .spiel-icon-btn:last-child { margin-left: auto; }
.spiel-topbar-meta ~ .spiel-icon-btn:last-child { margin-left: 0; }

/* ---------- Fortschritts-Kästchen ---------- */
.spiel-progress {
    display: flex;
    gap: 6px;
    flex: 1;
    min-width: 0;
    justify-content: center;
    flex-wrap: nowrap;
}
.spiel-pbox {
    width: 20px;
    height: 20px;
    border-radius: 5px;
    border: 2px solid rgba(255,255,255,.6);
    background: transparent;
    transition: all 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.spiel-pbox.done-right { background: #fff; border-color: #fff; transform: scale(1.06); }
.spiel-pbox.current { border-color: #fff; box-shadow: 0 0 0 3px rgba(255,255,255,.35); }

/* ---------- Screens ---------- */
.spiel-screen { display: none; flex-direction: column; flex: 1; animation: spiel-screen-in 0.3s ease; }
.spiel-screen.active { display: flex; }
@keyframes spiel-screen-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ---------- Start-Screen ---------- */
.spiel-hero {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 22px;
    padding: 14px 0 10px;
}
.spiel-badge {
    width: 112px;
    height: 112px;
    border-radius: var(--spiel-radius);
    background: #fff;
    border: 3px solid var(--spiel-hue);
    color: var(--spiel-hue);
    font-size: 52px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}
.spiel-badge img { width: 78%; height: 78%; object-fit: contain; display: block; }
.spiel-hero h1 { font-size: 1.9em; line-height: 1.25; font-weight: 700; letter-spacing: 0; }
.spiel-hero .spiel-howto {
    font-size: 1em;
    line-height: 1.6;
    color: var(--spiel-ink);
    max-width: 480px;
}

/* ---------- Setup-Auswahl ---------- */
.spiel-setup {
    display: flex;
    flex-direction: column;
    gap: 20px;
    width: 100%;
    max-width: 480px;
}
.spiel-setup-group { display: flex; flex-direction: column; gap: 8px; }
.spiel-setup-label { font-size: 0.95em; font-weight: 700; color: var(--spiel-ink); text-align: center; }
.spiel-setup-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.spiel-setup-row.cols-2 { grid-template-columns: repeat(2, 1fr); }
.spiel-setup-row.cols-3 { grid-template-columns: repeat(3, 1fr); }
.spiel-setup-row.cols-5 { grid-template-columns: repeat(5, 1fr); }
.spiel-setup-row .spiel-set-btn {
    min-height: 64px;
    border-radius: var(--spiel-radius-sm);
    background: #fff;
    border: 3px solid var(--sp-line);
    font-weight: 700;
    font-size: 1em;
    color: var(--spiel-ink);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 6px 8px;
    transition: border-color 0.15s ease, transform 0.1s ease, color 0.15s ease, background 0.15s ease;
}
.spiel-setup-row .spiel-set-btn .spiel-set-ico { font-size: 1.25em; line-height: 1.1; }
.spiel-setup-row .spiel-set-btn.selected { border-color: var(--spiel-hue); background: var(--spiel-hue); color: #fff; }
.spiel-setup-row .spiel-set-btn:active { transform: scale(0.96); }

.spiel-setup-best {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    border: 2px solid var(--sp-line);
    border-radius: 999px;
    padding: 7px 18px;
    align-self: center;
    font-size: 0.9em;
}
.spiel-setup-best[hidden] { display: none; }
.spiel-setup-best-lbl { font-weight: 700; color: var(--spiel-ink-soft); }
.spiel-setup-best-val { display: inline-flex; align-items: center; gap: 8px; }
.spiel-setup-best-stars { color: var(--spiel-sun); letter-spacing: 1px; }
.spiel-setup-best-time { font-weight: 700; color: var(--spiel-ink); }

/* ---------- Buttons ---------- */
.spiel-btn-primary {
    min-height: 66px;
    padding: 16px 56px;
    border-radius: 999px;
    background: var(--spiel-hue);
    color: #fff;
    font-size: 1.25em;
    font-weight: 700;
    border: 3px solid var(--spiel-hue);
    transition: transform 0.1s ease, background 0.15s ease;
}
.spiel-btn-primary:hover { background: var(--spiel-hue-deep); border-color: var(--spiel-hue-deep); }
.spiel-btn-primary:active { transform: translateY(2px); }
.spiel-btn-secondary {
    min-height: 54px;
    padding: 12px 28px;
    border-radius: 999px;
    background: #fff;
    color: var(--spiel-hue);
    font-size: 1em;
    font-weight: 700;
    border: 3px solid var(--spiel-hue);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: transform 0.1s ease, background 0.15s ease;
}
.spiel-btn-secondary:active { transform: translateY(2px); background: var(--sp-accent-soft); }
.spiel-btn-ghost {
    min-height: 48px;
    padding: 10px 20px;
    border-radius: 999px;
    background: transparent;
    color: var(--spiel-ink-soft);
    font-size: 0.95em;
    font-weight: 700;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}
.spiel-btn-ghost:hover { color: var(--spiel-hue); }
.spiel-btn-ghost:active { opacity: 0.6; }

/* ---------- Aufgaben-Kopf im Spiel ---------- */
.spiel-quest {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 10px 0 6px;
}
.spiel-quest-text {
    font-size: clamp(20px, 5vw, 25px);
    font-weight: 700;
    color: var(--spiel-ink);
    line-height: 1.3;
}
.spiel-target {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.5em;
    height: 1.5em;
    padding: 0 0.2em;
    margin: 0 0.1em;
    vertical-align: -0.3em;
    background: var(--spiel-hue);
    color: #fff;
    font-weight: 700;
    border-radius: 8px;
}
.spiel-quest-meta {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    font-weight: 700;
    font-size: 0.9em;
    color: var(--spiel-ink-soft);
}
.spiel-remaining {
    border: 2px solid var(--sp-line);
    background: #fff;
    border-radius: 999px;
    padding: 3px 14px;
    color: var(--spiel-hue);
    font-variant-numeric: tabular-nums;
}
.spiel-time { font-variant-numeric: tabular-nums; }

/* ---------- Spielfeld ---------- */
.spiel-field-wrap {
    flex: 1;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 10px 0 6px;
}
.spiel-field {
    display: grid;
    grid-template-columns: repeat(var(--spiel-cols, 6), 1fr);
    gap: 10px;
    width: 100%;
    max-width: 560px;
    margin: 0 auto;
}
.spiel-cell {
    position: relative;
    aspect-ratio: 1;
    min-width: 44px;
    min-height: 44px;
    border-radius: var(--spiel-radius-sm);
    background: #fff;
    border: 3px solid var(--sp-line);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(22px, 7vw, 40px);
    font-weight: 700;
    line-height: 1;
    color: var(--spiel-ink);
    transition: transform 0.1s ease, background 0.2s ease, border-color 0.15s ease;
    overflow: hidden;
}
.spiel-cell:active { transform: translateY(2px); }
.spiel-cell .spiel-glyph { position: relative; z-index: 1; pointer-events: none; }

/* wachsende Durchstreich-Linie */
.spiel-strike {
    position: absolute;
    left: 8%;
    top: 50%;
    width: 84%;
    height: 4px;
    border-radius: 4px;
    background: var(--spiel-green-deep);
    transform-origin: left center;
    transform: translateY(-50%) rotate(-16deg) scaleX(0);
    transition: transform 0.28s cubic-bezier(0.34, 1.4, 0.64, 1);
    z-index: 2;
    pointer-events: none;
}
.spiel-cell.struck { background: var(--sp-good-soft); border-color: var(--spiel-green); cursor: default; }
.spiel-cell.struck .spiel-glyph { color: var(--spiel-green-deep); }
.spiel-cell.struck .spiel-strike { transform: translateY(-50%) rotate(-16deg) scaleX(1); }
.spiel-cell.wrong { background: var(--sp-bad-soft); border-color: var(--spiel-coral); animation: spiel-shake 0.4s ease; }
.spiel-cell.wrong .spiel-glyph { color: var(--spiel-coral); }

@keyframes spiel-shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-6px); }
    75% { transform: translateX(6px); }
}

/* ---------- Feedback-Sheet (oben, unterhalb des Kopfbands) ---------- */
.spiel-feedback {
    position: fixed;
    left: 50%;
    top: calc(96px + var(--spiel-safe-top));
    transform: translate(-50%, calc(-100% - 120px));
    visibility: hidden;
    opacity: 0;
    width: min(92vw, 480px);
    border-radius: var(--spiel-radius-sm);
    padding: 14px 22px;
    background: #fff;
    border: 3px solid;
    font-family: var(--sp-font);
    font-size: 18px;
    font-weight: 700;
    line-height: 1.4;
    text-align: center;
    box-shadow: 0 12px 30px rgba(22,50,79,.18);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.2s ease, visibility 0s linear 0.3s;
    z-index: 500;
    pointer-events: none;
}
.spiel-feedback.show { transform: translate(-50%, 0); visibility: visible; opacity: 1; transition-delay: 0s; }
.spiel-feedback.good { border-color: var(--spiel-green); color: var(--spiel-green-deep); }
.spiel-feedback.bad { border-color: var(--spiel-coral); color: var(--spiel-coral-deep); }

/* ---------- Toast ---------- */
.spiel-toast {
    position: fixed;
    left: 50%;
    bottom: calc(24px + var(--spiel-safe-bottom));
    transform: translate(-50%, 160%);
    background: var(--spiel-ink);
    color: #fff;
    font-family: var(--sp-font);
    font-weight: 700;
    font-size: 16px;
    padding: 12px 22px;
    border-radius: 999px;
    max-width: 90vw;
    text-align: center;
    z-index: 600;
    pointer-events: none;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.spiel-toast.show { transform: translate(-50%, 0); }

/* ---------- Ergebnis-Screen ---------- */
.spiel-result-hero {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    padding: 20px 0 10px;
}
.spiel-result-emoji { font-size: 60px; line-height: 1; }
.spiel-result-hero h2 { font-size: 1.6em; font-weight: 700; }
.spiel-stars { display: flex; gap: 8px; font-size: 46px; line-height: 1; }
.spiel-stars .spiel-star { color: var(--sp-line); transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1); }
.spiel-stars .spiel-star.on { color: var(--spiel-sun); animation: spiel-pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1); }

.spiel-result-card {
    background: #fff;
    border: 3px solid var(--spiel-hue);
    border-radius: var(--spiel-radius);
    padding: 22px 34px;
    display: flex;
    gap: 30px;
    justify-content: center;
}
.spiel-result-card .spiel-stat { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.spiel-result-card .spiel-stat .spiel-val { font-size: 2.1em; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--spiel-hue); line-height: 1.1; }
.spiel-result-card .spiel-stat .spiel-lbl { font-size: 0.8em; font-weight: 700; color: var(--spiel-ink-soft); }

.spiel-record {
    display: none;
    border: 2px solid var(--spiel-sun);
    background: #fff8e1;
    color: #7a5200;
    font-weight: 700;
    font-size: 0.9em;
    border-radius: 999px;
    padding: 6px 20px;
    animation: spiel-pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.spiel-record.on { display: block; }

.spiel-result-actions {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    margin-top: 8px;
}

@keyframes spiel-pop {
    0% { transform: scale(0.4); opacity: 0; }
    80% { transform: scale(1.12); }
    100% { transform: scale(1); opacity: 1; }
}

/* ---------- Konfetti ---------- */
#spiel-confetti {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 400;
}

/* ---------- Footer ---------- */
.spiel-footer {
    margin-top: auto;
    text-align: center;
    padding-top: 22px;
}
.spiel-footer p, .spiel-footer a {
    font-size: 0.85em;
    color: var(--spiel-ink-soft);
    font-weight: 400;
}
.spiel-footer a { color: var(--spiel-hue); text-decoration: underline; text-underline-offset: 3px; }

/* ---------- Utility ---------- */
.spiel-hidden { display: none !important; }

/* ---------- Handy ---------- */
@media (max-width: 600px) {
    body.spiel-body { font-size: 18px; }
    .spiel-app { padding: calc(16px + var(--spiel-safe-top)) 12px calc(18px + var(--spiel-safe-bottom)); }
    .spiel-frame { padding: 0 14px 20px; border-radius: 24px; box-shadow: 0 0 0 8px var(--sp-accent-soft); }
    .spiel-topbar { margin: 0 -14px 12px; padding: 8px 12px; min-height: 60px; gap: 8px; }
    .spiel-topbar-meta { display: none; }
    .spiel-hero h1 { font-size: 1.6em; }
    .spiel-btn-primary { padding: 14px 44px; width: 100%; max-width: 420px; }
    .spiel-result-card { gap: 20px; padding: 18px 20px; }
}

@media (prefers-reduced-motion: reduce) {
    .spiel-app *, .spiel-app *::before, .spiel-app *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
