:root {
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-alt: #273549;
    --text: #e2e8f0;
    --text-muted: #94a3b8;
    --accent: #22c55e;
    --accent-dark: #16a34a;
    --accent-contrast: #052e13;
    --danger: #ef4444;
    --border: #334155;
    --radius: 10px;
}

/* F-20: weitere Themes, aktiviert über data-theme auf <body> */
[data-theme="paper"] {
    --bg: #e8e4d9;
    --surface: #fdfcf0;
    --surface-alt: #fffef5;
    --text: #2c3e50;
    --text-muted: #6b7280;
    --accent: #34495e;
    --accent-dark: #1abc9c;
    --accent-contrast: #ffffff;
    --danger: #c0392b;
    --border: #dcdde1;
}

body[data-theme="paper"] {
    font-family: "Georgia", "Times New Roman", serif;
}

[data-theme="cyberpunk"] {
    --bg: #0b0e14;
    --surface: #0f121a;
    --surface-alt: #1a1f29;
    --text: #00ff9f;
    --text-muted: #4b6b5e;
    --accent: #ff003c;
    --accent-dark: #ff0055;
    --accent-contrast: #0b0e14;
    --danger: #ff0055;
    --border: #323232;
}

body[data-theme="cyberpunk"] {
    font-family: "Courier New", Courier, monospace;
    text-shadow: 0 0 5px rgba(0, 255, 159, 0.4);
}

/* Easter-Egg-Theme: viele Pikachus fliegen im Hintergrund umher, siehe
   PikachuBackground-Komponente. */
[data-theme="pikachu"] {
    --bg: #fff8dc;
    --surface: #fffdf5;
    --surface-alt: #fff1b8;
    --text: #2b2b2b;
    --text-muted: #7a6a2a;
    --accent: #f6d02f;
    --accent-dark: #e0b400;
    --accent-contrast: #2b2b2b;
    --danger: #e8544c;
    --border: #f0dd8c;
}

/* Easter-Egg-Theme: Zeichen regnen wie in Matrix von oben nach unten, siehe
   MatrixBackground-Komponente. */
[data-theme="matrix"] {
    --bg: #000000;
    --surface: #060a06;
    --surface-alt: #0c140c;
    --text: #d0ffd0;
    --text-muted: #4caf50;
    --accent: #00ff41;
    --accent-dark: #00cc34;
    --accent-contrast: #001a00;
    --danger: #ff4d4d;
    --border: #1f3a1f;
}

body[data-theme="matrix"] {
    font-family: "Courier New", Courier, monospace;
}

body[data-theme="matrix"] .card {
    border: 1px solid var(--border);
}

/* Easter-Egg-Theme: bunte Loot-Llamas fliegen im Hintergrund umher, siehe
   FortniteBackground-Komponente. */
[data-theme="fortnite"] {
    --bg: #1a1a2e;
    --surface: #22223b;
    --surface-alt: #2b2d5c;
    --text: #f1f1f1;
    --text-muted: #a9a9c9;
    --accent: #8b5cf6;
    --accent-dark: #6d28d9;
    --accent-contrast: #ffffff;
    --danger: #ef4444;
    --border: #3d3d6b;
}

/* Easter-Egg-Theme: Burger und Pommes fliegen im Hintergrund umher, siehe
   BurgerBackground-Komponente. */
[data-theme="burger"] {
    --bg: #fff4e0;
    --surface: #fff8ec;
    --surface-alt: #ffe9b8;
    --text: #3a2415;
    --text-muted: #8a6a4a;
    --accent: #e63946;
    --accent-dark: #c1121f;
    --accent-contrast: #ffffff;
    --danger: #c1121f;
    --border: #f0c987;
}

/* Billard-Theme: angelehnt an eine Kneipen-Billardecke (dunkelrote Wand,
   warmes Messing-Tunnelgewölbe, grüner Filz) – Billardkugeln rollen im
   Hintergrund, siehe BillardBackground-Komponente. */
[data-theme="billard"] {
    --bg: #4a1015;
    --surface: #3a2a1e;
    --surface-alt: #4a3625;
    --text: #f5e6c8;
    --text-muted: #c9a876;
    --accent: #2f7a4d;
    --accent-dark: #1f5a35;
    --accent-contrast: #ffffff;
    --danger: #c1272d;
    --border: #8a6a3a;
}

/* Herzen-Theme: rosa/rote Herzen schweben im Hintergrund nach oben, siehe
   HeartsBackground-Komponente. */
[data-theme="hearts"] {
    --bg: #fff0f5;
    --surface: #ffffff;
    --surface-alt: #ffe0ea;
    --text: #4a1228;
    --text-muted: #9c4566;
    --accent: #e91e63;
    --accent-dark: #c2185b;
    --accent-contrast: #ffffff;
    --danger: #b71c1c;
    --border: #f8bbd0;
}

.theme-switcher {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.icon {
    width: 1.1em;
    height: 1.1em;
    vertical-align: -0.18em;
    flex: 0 0 auto;
}

.nav-btn,
.save-btn,
.delete-btn,
.review-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

* {
    box-sizing: border-box;
}

html {
    /* iOS Safari ignoriert seit iOS 10 user-scalable=no/maximum-scale im
       viewport-meta-Tag (bewusste Accessibility-Entscheidung von WebKit) –
       Pinch-Zoom lässt sich dort nur noch per touch-action abschalten.
       "pan-y" erlaubt vertikales Scrollen, verbietet aber Pinch-Zoom UND
       Doppeltipp-Zoom (alles, was hier nicht explizit erlaubt ist). */
    touch-action: pan-y;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    /* F-25: soll sich wie eine native App anfühlen – kein grauer
       Tap-Highlight-Flash, kein horizontales Wackeln bei versehentlich zu
       breitem Inhalt. */
    overflow-x: hidden;
    touch-action: pan-y;
    -webkit-tap-highlight-color: transparent;
    -webkit-text-size-adjust: 100%;
}

.container {
    max-width: 640px;
    margin: 0 auto;
    padding: 1rem;
}

/* Desktopansicht (opt-in per DesktopViewToggle, siehe layout_toggle.rs):
   `min-width` zusaetzlich zum `data-layout`-Attribut, damit eine gespeicherte
   Praeferenz auf einem schmaleren Fenster/Geraet nicht trotzdem wirkt. */
@media (min-width: 1024px) {
    body[data-layout="desktop"] .container {
        max-width: 1100px;
    }

    body[data-layout="desktop"] .nav-tabs {
        justify-content: center;
    }

    body[data-layout="desktop"] .deck-list,
    body[data-layout="desktop"] .card-list {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
        gap: 0.75rem;
    }
}

.header-flex {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

h1 {
    font-size: 1.4rem;
    margin: 0;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1rem;
}

.flex {
    display: flex;
}

.flex-col {
    display: flex;
    flex-direction: column;
}

.gap-2 {
    gap: 0.5rem;
}

.items-center {
    align-items: center;
}

.mb-1 {
    margin-bottom: 1rem;
}

input {
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    padding: 0.6rem 0.8rem;
    font-size: 1rem;
    width: 100%;
}

button {
    border: none;
    border-radius: var(--radius);
    padding: 0.6rem 1rem;
    font-size: 1rem;
    cursor: pointer;
}

.save-btn {
    background: var(--accent);
    color: var(--accent-contrast);
    font-weight: 600;
}

.save-btn:hover {
    background: var(--accent-dark);
}

.save-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.nav-btn {
    background: var(--surface-alt);
    color: var(--text);
}

.nav-btn.active {
    background: var(--accent);
    color: var(--accent-contrast);
    font-weight: 600;
}

.nav-tabs {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.logout-btn,
.delete-btn {
    background: transparent;
    color: var(--danger);
    border: 1px solid var(--danger);
}

.hint-text {
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* Reserviert Platz für später ein-/ausgeblendete Elemente, statt sie aus dem
   Fluss zu nehmen (F-28) – verhindert Layout-Sprünge z. B. beim Aufdecken
   von Karteikarten. */
.invisible {
    visibility: hidden;
}

.error-msg {
    color: var(--danger);
    font-size: 0.9rem;
}

.status-msg.success {
    color: var(--accent);
    font-size: 0.9rem;
}

.auth-switch {
    font-size: 0.9rem;
    color: var(--text-muted);
}

.auth-switch a {
    color: var(--accent);
}

.welcome {
    text-align: center;
    padding: 2rem 0;
}

.deck-form,
.card-form {
    margin-bottom: 1rem;
}

.deck-list,
.card-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.deck-row,
.card-row {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    background: var(--surface-alt);
    border-radius: var(--radius);
    padding: 0.6rem 0.8rem;
}

.deck-row-main {
    /* Echtes <button> statt <div on:click> (B-1): iOS Safari liefert Klicks
       auf per JS gebundene Handler an nicht-nativ-interaktiven Elementen
       (div/span) unzuverlässig, gerade in verschachtelten Flex-Layouts.
       Native Buttons erhalten Taps garantiert – Firefox Mobile und macOS
       Safari sind hier toleranter, weshalb der Bug dort nicht auffiel. */
    display: block;
    flex: 1 1 auto;
    min-width: 0;
    text-align: left;
    background: none;
    color: inherit;
    font: inherit;
    padding: 0;
    border-radius: 0;
    cursor: pointer;
    touch-action: manipulation;
}

.deck-row-main strong,
.deck-row-main .hint-text {
    overflow-wrap: break-word;
}

.preset-list {
    margin-bottom: 1.5rem;
}

.preset-list h3 {
    font-size: 0.95rem;
    margin-bottom: 0.5rem;
}

.preset-row {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    background: var(--surface-alt);
    border-radius: var(--radius);
    padding: 0.6rem 0.8rem;
    margin-bottom: 0.5rem;
}

/* Ohne min-width: 0 behält der Text-Block in Safari seine implizite
   Flex-Item-Mindestbreite (= min-content). Sobald Name + Vokabelzahl beim
   Umbruch zu breit werden, verschiebt WebKit die Treffer-/Klickfläche des
   "Übernehmen"-Buttons sichtbar an eine andere Stelle als seinen optischen
   Platz (Safari-Flexbug bei flex-wrap + justify-content: space-between) –
   Taps auf den Button liefen dadurch ins Leere. flex-shrink: 0 auf dem
   Button verhindert zusätzlich, dass er selbst gestaucht wird. */
.preset-row-main {
    flex: 1 1 auto;
    min-width: 0;
}

.preset-row-action {
    flex-shrink: 0;
}

.preset-row > div {
    min-width: 0;
    overflow-wrap: break-word;
}

.study-view {
    text-align: center;
}

.study-done {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 0;
}

.box-indicator {
    display: flex;
    justify-content: center;
    gap: 0.4rem;
    margin: 0.25rem 0 0.5rem;
}

.box-dot {
    width: 0.6rem;
    height: 0.6rem;
    border-radius: 50%;
    background: var(--surface-alt);
    border: 1px solid var(--border);
}

.box-dot.filled {
    background: var(--accent);
    border-color: var(--accent);
}

.box-progress {
    display: flex;
    justify-content: center;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.box-progress-item {
    font-size: 0.85rem;
    padding: 0.2rem 0.6rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface-alt);
}

.box-progress-item.box2 {
    border-color: var(--accent);
    color: var(--accent);
}

.flashcard {
    /* Echtes <button> statt <div on:click> (Safari-Klick-Bug, siehe
       .deck-row-main) – hier zusätzlich Reset von Breite/Font/Farbe, da der
       globale button-Reset sonst Text zentriert/verkleinert darstellt. */
    width: 100%;
    text-align: inherit;
    font: inherit;
    color: inherit;
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2.5rem 1rem;
    margin: 1rem 0;
    cursor: pointer;
    min-height: 120px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 0.5rem;
}

.flashcard-front {
    font-size: 1.6rem;
    font-weight: 600;
    margin: 0;
}

.flashcard-back {
    font-size: 1.3rem;
    color: var(--accent);
    margin: 0;
}

.study-actions {
    justify-content: center;
}

.review-btn {
    flex: 1;
    max-width: 200px;
    font-weight: 600;
}

.review-btn.correct {
    background: var(--accent);
    color: var(--accent-contrast);
}

.review-btn.wrong {
    background: var(--danger);
    color: #fff;
}

/* Mobile: größere Tap-Targets, gestapelte Formulare */
@media (max-width: 480px) {
    .container {
        padding: 0.75rem;
    }

    h1 {
        font-size: 1.2rem;
    }

    .card-form,
    .deck-form .flex {
        flex-direction: column;
    }

    .flashcard {
        padding: 2rem 0.75rem;
        min-height: 160px;
    }

    .flashcard-front {
        font-size: 1.4rem;
    }

    button {
        padding: 0.75rem 1rem;
    }

    /* F-25: Deck-/Karten-/Preset-Zeilen auf schmalen Bildschirmen stapeln
       statt nebeneinander zu quetschen, damit Aktions-Buttons nicht aus dem
       sichtbaren Bereich rutschen. */
    .deck-row,
    .card-row,
    .preset-row {
        flex-direction: column;
        align-items: stretch;
    }

    .deck-row-main {
        width: 100%;
    }
}

.app-footer {
    margin-top: 2rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.app-footer a {
    color: var(--accent);
}

.impressum-view h3 {
    font-size: 0.95rem;
    margin-bottom: 0.2rem;
}

.impressum-view p {
    margin-top: 0;
    margin-bottom: 1rem;
    color: var(--text-muted);
}

.secondary-btn {
    background: var(--surface-alt);
    color: var(--text);
    border: 1px solid var(--border);
}

/* Pikachu-Theme: Hintergrundlayer bleibt immer im DOM (kein Re-Mount beim
   Theme-Wechsel), wird aber nur bei aktivem Theme sichtbar/animiert. */
.pikachu-background {
    display: none;
    position: fixed;
    inset: 0;
    overflow: hidden;
    /* -1 statt 0: ein positioniertes Element (auch mit z-index: 0) malt sonst
       immer über statischem Inhalt, egal in welcher DOM-Reihenfolge – Header/
       Nav-Tabs (kein .card-Wrapper) verschwanden dadurch komplett. */
    z-index: -1;
    pointer-events: none;
}

.pikachu-background.active {
    display: block;
}

.pikachu-fly {
    position: absolute;
    left: -15%;
    animation-name: pikachu-fly;
    animation-timing-function: linear;
    animation-iteration-count: infinite;
}

.pikachu-icon {
    width: 100%;
    height: auto;
    display: block;
    filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.15));
    animation: pikachu-bob 1.6s ease-in-out infinite;
}

@keyframes pikachu-fly {
    from {
        transform: translateX(0);
    }
    to {
        transform: translateX(130vw);
    }
}

@keyframes pikachu-bob {
    0%,
    100% {
        transform: translateY(0) rotate(-4deg);
    }
    50% {
        transform: translateY(-14px) rotate(4deg);
    }
}

@media (prefers-reduced-motion: reduce) {
    .pikachu-fly,
    .pikachu-icon {
        animation: none;
    }
}

/* Matrix-Theme: Spalten aus Zeichen regnen von oben nach unten, siehe
   MatrixBackground-Komponente. */
.matrix-background {
    display: none;
    position: fixed;
    inset: 0;
    overflow: hidden;
    z-index: -1;
    pointer-events: none;
    background: #000000;
}

.matrix-background.active {
    display: block;
}

.matrix-column {
    position: absolute;
    top: -50%;
    display: flex;
    flex-direction: column;
    font-family: "Courier New", Courier, monospace;
    font-size: 1.1rem;
    line-height: 1.3;
    color: #00ff41;
    text-shadow: 0 0 8px rgba(0, 255, 65, 0.8);
    animation-name: matrix-fall;
    animation-timing-function: linear;
    animation-iteration-count: infinite;
}

.matrix-column span:last-child {
    color: #d0ffd0;
    text-shadow: 0 0 12px rgba(255, 255, 255, 0.9);
}

@keyframes matrix-fall {
    from {
        transform: translateY(0);
    }
    to {
        transform: translateY(150vh);
    }
}

@media (prefers-reduced-motion: reduce) {
    .matrix-column {
        animation: none;
    }
}

/* Fortnite-Theme: Loot-Llamas fliegen quer über den Hintergrund, siehe
   FortniteBackground-Komponente – gleiches Muster wie beim Pikachu-Theme. */
.fortnite-background {
    display: none;
    position: fixed;
    inset: 0;
    overflow: hidden;
    z-index: -1;
    pointer-events: none;
}

.fortnite-background.active {
    display: block;
}

.fortnite-fly {
    position: absolute;
    left: -15%;
    animation-name: fortnite-fly;
    animation-timing-function: linear;
    animation-iteration-count: infinite;
}

.fortnite-icon {
    width: 100%;
    height: auto;
    display: block;
    filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.25));
    animation: fortnite-bob 1.8s ease-in-out infinite;
}

@keyframes fortnite-fly {
    from {
        transform: translateX(0);
    }
    to {
        transform: translateX(130vw);
    }
}

@keyframes fortnite-bob {
    0%,
    100% {
        transform: translateY(0) rotate(-3deg);
    }
    50% {
        transform: translateY(-12px) rotate(3deg);
    }
}

@media (prefers-reduced-motion: reduce) {
    .fortnite-fly,
    .fortnite-icon {
        animation: none;
    }
}

/* Burger-Theme: Burger und Pommes fliegen quer über den Hintergrund, siehe
   BurgerBackground-Komponente – gleiches Muster wie beim Pikachu-Theme. */
.burger-background {
    display: none;
    position: fixed;
    inset: 0;
    overflow: hidden;
    z-index: -1;
    pointer-events: none;
}

.burger-background.active {
    display: block;
}

.burger-fly {
    position: absolute;
    left: -15%;
    animation-name: burger-fly;
    animation-timing-function: linear;
    animation-iteration-count: infinite;
}

.burger-icon,
.fries-icon {
    width: 100%;
    height: auto;
    display: block;
    filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.2));
    animation: burger-spin 2.2s linear infinite;
}

@keyframes burger-fly {
    from {
        transform: translateX(0);
    }
    to {
        transform: translateX(130vw);
    }
}

@keyframes burger-spin {
    0%,
    100% {
        transform: translateY(0) rotate(-6deg);
    }
    50% {
        transform: translateY(-14px) rotate(6deg);
    }
}

@media (prefers-reduced-motion: reduce) {
    .burger-fly,
    .burger-icon,
    .fries-icon {
        animation: none;
    }
}

/* Billard-Theme: Kugeln rollen (mit Eigenrotation) quer über den
   Hintergrund, siehe BillardBackground-Komponente. */
.billard-background {
    display: none;
    position: fixed;
    inset: 0;
    overflow: hidden;
    z-index: -1;
    pointer-events: none;
}

.billard-background.active {
    display: block;
}

.billard-roll {
    position: absolute;
    left: -15%;
    animation-name: billard-roll;
    animation-timing-function: linear;
    animation-iteration-count: infinite;
}

.billard-icon {
    width: 100%;
    height: auto;
    display: block;
    filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.3));
    animation: billard-spin 1.4s linear infinite;
}

@keyframes billard-roll {
    from {
        transform: translateX(0);
    }
    to {
        transform: translateX(130vw);
    }
}

@keyframes billard-spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

@media (prefers-reduced-motion: reduce) {
    .billard-roll,
    .billard-icon {
        animation: none;
    }
}

/* Herzen-Theme: Layer bleibt immer im DOM, nur bei aktivem Theme sichtbar. */
.hearts-background {
    display: none;
    position: fixed;
    inset: 0;
    overflow: hidden;
    z-index: -1;
    pointer-events: none;
}

.hearts-background.active {
    display: block;
}

.hearts-float {
    position: absolute;
    bottom: -15%;
    animation-name: hearts-float;
    animation-timing-function: linear;
    animation-iteration-count: infinite;
}

.hearts-icon {
    width: 100%;
    height: auto;
    display: block;
    filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.15));
    animation: hearts-beat 1.2s ease-in-out infinite;
}

@keyframes hearts-float {
    from {
        transform: translateY(0);
    }
    to {
        transform: translateY(-125vh);
    }
}

@keyframes hearts-beat {
    0%,
    100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.18);
    }
}

@media (prefers-reduced-motion: reduce) {
    .hearts-float,
    .hearts-icon {
        animation: none;
    }
}
