/* ============================================
   RESA Flashcards – Instagram-inspired UI
   Baut auf assets/css/app.css auf (Tokens, Header,
   ig-profile, ig-tabs, Footer) und ergänzt nur die
   Lernkarten-, Quiz- und Memory-Komponenten.
   ============================================ */

:root {
    /* Alias-Tokens für Inline-Styles in generiertem Markup */
    --muted: var(--text-secondary);
    --muted-2: var(--text-tertiary);
    --blue: var(--accent);
    --blue-2: var(--accent-hover);
    --blue-soft: var(--accent-subtle);
    --line: var(--border);
    --line-soft: var(--bg-tertiary);
    --green: #58c322;
    --green-soft: rgba(88, 195, 34, 0.12);
    --red: #ed4956;
    --red-soft: rgba(237, 73, 86, 0.12);
    --amber: #b06000;
    --amber-soft: rgba(251, 188, 4, 0.14);
}

body.fc-page {
    background: var(--bg-primary);
}


/* ==========================================================================
   1. STORY-ROW: Kursteile als Instagram-Stories
   ========================================================================== */

.fc-stories {
    display: flex;
    gap: 1.25rem;
    align-items: flex-start;
    padding: 1rem 1.25rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    scrollbar-width: none;
}

.fc-stories::-webkit-scrollbar {
    display: none;
}

.fc-story {
    flex: 0 0 auto;
    width: 74px;
    text-align: center;
    text-decoration: none;
    color: var(--text-primary);
}

.fc-story__ring {
    display: block;
    width: 66px;
    height: 66px;
    margin: 0 auto 0.4rem;
    border-radius: var(--radius-full);
    padding: 2px;
    background: var(--border);
    transition: transform var(--transition), background var(--transition);
}

.fc-story:hover .fc-story__ring {
    transform: scale(1.04);
}

.fc-story--active .fc-story__ring,
.fc-story:hover .fc-story__ring {
    background: var(--story-gradient);
}

.fc-story__inner {
    width: 100%;
    height: 100%;
    border-radius: var(--radius-full);
    border: 2px solid var(--bg-secondary);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.95rem;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.fc-story--active .fc-story__inner {
    background: var(--bg-secondary);
    box-shadow: inset 0 0 0 1px var(--border);
}

.fc-story__label {
    display: block;
    font-size: 0.7rem;
    line-height: 1.25;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.fc-story--active .fc-story__label {
    color: var(--text-primary);
    font-weight: 600;
}


/* ==========================================================================
   2. TOOLBAR: Suche, Modulfilter, Aktionen
   ========================================================================== */

.fc-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
    padding: 0.85rem 1.25rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
}

.fc-search {
    flex: 1 1 240px;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
    height: 36px;
    padding: 0 0.85rem;
    border-radius: var(--radius-md);
    background: var(--bg-tertiary);
    border: 1px solid transparent;
    transition: background var(--transition), border-color var(--transition);
}

.fc-search:focus-within {
    background: var(--bg-secondary);
    border-color: var(--border);
}

.fc-search svg {
    width: 15px;
    height: 15px;
    flex: 0 0 auto;
    color: var(--text-secondary);
}

.fc-search input {
    flex: 1;
    min-width: 0;
    border: 0;
    outline: 0;
    background: transparent;
    font-family: inherit;
    font-size: 0.875rem;
    color: var(--text-primary);
}

.fc-search input::placeholder {
    color: var(--text-secondary);
}

.fc-select {
    appearance: none;
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-primary);
    background: var(--bg-tertiary);
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    height: 36px;
    padding: 0 2rem 0 0.85rem;
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24'%3E%3Cpath d='M7 10l5 5 5-5z' fill='%238e8e8e'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
}

.fc-select:focus {
    outline: none;
    border-color: var(--border);
    background-color: var(--bg-secondary);
}


/* ==========================================================================
   3. BUTTONS (auf .ig-btn abgestimmt)
   ========================================================================== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 600;
    line-height: 1.2;
    padding: 0.45rem 1rem;
    min-height: 36px;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    cursor: pointer;
    text-decoration: none;
    transition: background var(--transition), color var(--transition), border-color var(--transition), opacity var(--transition);
}

.btn:hover {
    background: #dbdbdb;
    color: var(--text-primary);
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}

.btn-primary:hover {
    background: var(--accent-hover);
    color: #fff;
}

.btn-plain {
    background: transparent;
    border-color: var(--border);
    color: var(--text-primary);
}

.btn-plain:hover {
    background: var(--bg-primary);
}

.btn-ghost {
    background: transparent;
    border-color: transparent;
    color: var(--accent);
    font-weight: 600;
    padding: 0.45rem 0.6rem;
    min-height: 32px;
}

.btn-ghost:hover {
    background: var(--accent-subtle);
    color: var(--accent);
}


/* ==========================================================================
   4. MODULE-CHIPS (ersetzt die frühere Sidebar)
   ========================================================================== */

.fc-modules {
    display: flex;
    gap: 0.4rem;
    align-items: center;
    padding: 0.75rem 1.25rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    scrollbar-width: none;
}

.fc-modules::-webkit-scrollbar {
    display: none;
}

.module-link {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: baseline;
    gap: 0.4rem;
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-primary);
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.4rem 0.9rem;
    cursor: pointer;
    white-space: nowrap;
    transition: background var(--transition), color var(--transition), border-color var(--transition);
}

.module-link:hover {
    background: var(--bg-tertiary);
}

.module-link.active {
    background: var(--text-primary);
    border-color: var(--text-primary);
    color: #fff;
    font-weight: 600;
}

.module-link .module-count {
    font-size: 0.7rem;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

.module-link.active .module-count {
    color: rgba(255, 255, 255, 0.75);
}

.module-link.mastered .module-count {
    color: var(--green);
    font-weight: 700;
}

.module-link.mastered .module-count::after {
    content: " ✓";
}

.module-link.active.mastered .module-count {
    color: #fff;
}


/* ==========================================================================
   5. FORTSCHRITTSBALKEN
   ========================================================================== */

.progress {
    height: 2px;
    background: var(--bg-tertiary);
    overflow: hidden;
}

.progress > i {
    display: block;
    height: 100%;
    width: 0;
    background: var(--story-gradient);
    transition: width 0.3s ease;
}


/* ==========================================================================
   6. LERNKARTEN (Feed-Post-Optik)
   ========================================================================== */

.fc-body {
    padding: 1.25rem;
}

.scene {
    perspective: 1600px;
}

.flip {
    position: relative;
    width: 100%;
    min-height: 320px;
    cursor: pointer;
    transform-style: preserve-3d;
    transition: transform 0.55s cubic-bezier(0.4, 0.2, 0.2, 1);
}

.flip.is-flipped {
    transform: rotateY(180deg);
}

.face {
    position: absolute;
    inset: 0;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 3.25rem 2rem 2.75rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: none;
}

.face .badge {
    position: absolute;
    top: 1rem;
    left: 1.25rem;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-primary);
}

.face .badge::before {
    content: '';
    width: 22px;
    height: 22px;
    border-radius: var(--radius-full);
    background: var(--story-gradient);
    box-shadow: inset 0 0 0 2px var(--bg-secondary);
}

.face .num {
    position: absolute;
    top: 1.2rem;
    right: 1.25rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

.face .label {
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 0.6rem;
}

.front .q {
    font-size: clamp(1.15rem, 2.6vw, 1.5rem);
    font-weight: 600;
    line-height: 1.35;
    color: var(--text-primary);
    letter-spacing: -0.01em;
}

.back {
    transform: rotateY(180deg);
    overflow: hidden;
}

.back::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--story-gradient);
}

.back .a {
    font-size: clamp(0.95rem, 2vw, 1.1rem);
    line-height: 1.55;
    color: var(--text-primary);
}

.hint {
    position: absolute;
    bottom: 1rem;
    left: 0;
    right: 0;
    text-align: center;
    font-size: 0.7rem;
    color: var(--text-tertiary);
}

/* Aktionsleiste unter der Karte – wie die IG-Post-Actions */
.fc-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.85rem 0.25rem 0.4rem;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}

.fc-actions .count {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

.card-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.85rem 0.25rem;
    flex-wrap: wrap;
}

.card-stats {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

#knowBtn {
    color: var(--green);
    border-color: rgba(88, 195, 34, 0.5);
}

#knowBtn:hover {
    background: var(--green-soft);
}

#againBtn {
    color: var(--amber);
    border-color: rgba(176, 96, 0, 0.35);
}

#againBtn:hover {
    background: var(--amber-soft);
}

#hardOnlyBtn.active {
    background: var(--text-primary);
    border-color: var(--text-primary);
    color: #fff;
}

.fc-subactions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    padding: 0 0.25rem 0.25rem;
}


/* ==========================================================================
   7. QUIZ
   ========================================================================== */

.quiz-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    margin-bottom: 1rem;
}

.quiz-card .badge {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.9rem;
}

.quiz-card .badge::before {
    content: '';
    width: 22px;
    height: 22px;
    border-radius: var(--radius-full);
    background: var(--story-gradient);
    box-shadow: inset 0 0 0 2px var(--bg-secondary);
}

.quiz-q {
    font-size: clamp(1.05rem, 2.4vw, 1.3rem);
    font-weight: 600;
    line-height: 1.4;
    letter-spacing: -0.01em;
    margin-bottom: 1.1rem;
}

.opts {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.opt {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    text-align: left;
    font-family: inherit;
    font-size: 0.9rem;
    color: var(--text-primary);
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 0.8rem 0.9rem;
    cursor: pointer;
    transition: background var(--transition), border-color var(--transition);
}

.opt:hover:not(:disabled) {
    background: var(--bg-tertiary);
    border-color: var(--border-hover);
}

.opt:disabled {
    cursor: default;
}

.opt .key {
    flex: 0 0 26px;
    height: 26px;
    border-radius: var(--radius-full);
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
}

.opt.correct {
    border-color: var(--green);
    background: var(--green-soft);
}

.opt.correct .key {
    background: var(--green);
    color: #fff;
}

.opt.wrong {
    border-color: var(--red);
    background: var(--red-soft);
}

.opt.wrong .key {
    background: var(--red);
    color: #fff;
}

.explain {
    display: none;
    margin-top: 1rem;
    padding: 0.9rem 1rem;
    font-size: 0.875rem;
    line-height: 1.55;
    color: var(--text-primary);
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
}

.explain.show {
    display: block;
}

.explain b {
    color: var(--text-primary);
}

.quiz-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.score {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

.score b {
    color: var(--text-primary);
    font-weight: 600;
}


/* ==========================================================================
   8. ERGEBNIS
   ========================================================================== */

.result {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 2.5rem 1.5rem;
    text-align: center;
}

.result .big {
    font-size: clamp(2.25rem, 8vw, 3rem);
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-primary);
    margin: 0.35rem 0;
}

.result p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin: 0.35rem 0 1.5rem;
}

.result-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    flex-wrap: wrap;
}

.hidden {
    display: none !important;
}


/* ==========================================================================
   9. MEMORY-SPIEL
   ========================================================================== */

.fc-statsbar {
    display: flex;
    gap: 0;
    justify-content: space-around;
    padding: 0.85rem 1rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    text-align: center;
}

.fc-statsbar .stat {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    font-size: 0.7rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-secondary);
}

.fc-statsbar .stat b {
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--text-primary);
    text-transform: none;
    font-variant-numeric: tabular-nums;
}

.board {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: var(--grid-gap);
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-top: none;
    padding: 0;
}

.board.cols5 {
    grid-template-columns: repeat(5, minmax(0, 1fr));
}

.mcard {
    position: relative;
    width: 100%;
    aspect-ratio: 1;
    border: 0;
    padding: 0;
    background: transparent;
    cursor: pointer;
    transform-style: preserve-3d;
    transition: transform 0.4s cubic-bezier(0.4, 0.2, 0.2, 1);
}

.mcard.is-up,
.mcard.is-matched {
    transform: rotateY(180deg);
}

.mface {
    position: absolute;
    inset: 0;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 0.5rem;
    border-radius: 0;
}

.mback {
    background: var(--story-gradient);
    color: #fff;
}

.mback span {
    width: 46%;
    aspect-ratio: 1;
    border-radius: var(--radius-full);
    background: rgba(255, 255, 255, 0.18);
    border: 2px solid rgba(255, 255, 255, 0.6);
    display: grid;
    place-items: center;
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.04em;
}

.mfront {
    transform: rotateY(180deg);
    background: var(--bg-secondary);
    box-shadow: inset 0 0 0 1px var(--border);
}

.mfront .sym {
    font-size: clamp(1.5rem, 6vw, 2.25rem);
    line-height: 1;
    margin-bottom: 0.35rem;
}

.mfront .lbl {
    font-size: clamp(0.65rem, 2vw, 0.8rem);
    font-weight: 600;
    line-height: 1.25;
    color: var(--text-primary);
    overflow-wrap: anywhere;
}

.mcard.is-matched .mfront {
    background: var(--green-soft);
    box-shadow: inset 0 0 0 1px var(--green);
}

.mcard.is-matched .mfront::after {
    content: "✓";
    position: absolute;
    top: 0.35rem;
    right: 0.45rem;
    color: var(--green);
    font-size: 0.8rem;
    font-weight: 700;
}

.mcard.is-wrong .mfront {
    background: var(--red-soft);
    box-shadow: inset 0 0 0 1px var(--red);
    animation: fc-shake 0.35s;
}

@keyframes fc-shake {
    0%, 100% { transform: rotateY(180deg) translateX(0); }
    25% { transform: rotateY(180deg) translateX(-5px); }
    75% { transform: rotateY(180deg) translateX(5px); }
}

.mcard:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

.win {
    display: none;
    margin: 1.25rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 2rem 1.5rem;
    text-align: center;
}

.win.show {
    display: block;
}

.win .big {
    font-size: clamp(2rem, 7vw, 2.75rem);
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-primary);
    margin: 0.25rem 0;
}

.win p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin: 0.35rem 0 1.25rem;
}

.win .row {
    display: flex;
    justify-content: center;
    gap: 2rem;
    margin: 1rem 0 1.25rem;
}

.win .row .v {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

.win .row .l {
    font-size: 0.65rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-secondary);
}

.fc-hint {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-align: center;
    padding: 1rem 1.25rem 0;
}


/* ==========================================================================
   10. RESPONSIVE
   ========================================================================== */

@media (max-width: 768px) {
    .fc-stories {
        gap: 0.9rem;
        padding: 0.85rem 1rem;
    }

    .fc-story {
        width: 64px;
    }

    .fc-story__ring {
        width: 58px;
        height: 58px;
    }

    .fc-toolbar,
    .fc-modules {
        padding: 0.75rem 1rem;
    }

    .fc-body {
        padding: 1rem;
    }

    .face {
        padding: 3rem 1.25rem 2.5rem;
    }

    .flip {
        min-height: 360px;
    }

    .quiz-card {
        padding: 1.25rem 1rem;
    }

    .fc-actions,
    .card-actions {
        justify-content: center;
    }

    .fc-actions .count {
        order: -1;
        width: 100%;
        text-align: center;
    }

    .btn {
        flex: 1 1 auto;
    }

    .board.cols5 {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}

@media (max-width: 480px) {
    .fc-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .fc-select,
    .fc-search {
        width: 100%;
    }

    .board,
    .board.cols5 {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}
