:root {
    --primary-blue: #007bff;
    --dark-blue: #0056b3;
    --bg-color: #f0f4f8;
    --card-white: #ffffff;
    --green-success: #28a745;
    --red-error: #dc3545;
    --text-dark: #333;
}

body {
    font-family: 'Segoe UI', system-ui, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-dark);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    margin: 0;
    padding: 20px;
    box-sizing: border-box;
}

.screen {
    width: 100%;
    max-width: 900px;
    display: flex;
    flex-direction: column;
    align-items: center;
    animation: fadeIn 0.4s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.category-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    width: 100%;
}

.category-btn {
    padding: 40px 20px;
    font-size: 1.2rem;
    font-weight: bold;
    background: white;
    border: 3px solid var(--primary-blue);
    color: var(--primary-blue);
    border-radius: 15px;
    cursor: pointer;
    transition: 0.3s;
}

.category-btn:hover {
    background: var(--primary-blue);
    color: white;
    transform: translateY(-3px);
}

/* FLASHCARD LOGIK */
.flashcard-container {
    perspective: 1000px;
    width: 100%;
    max-width: 700px; /* Bredare för att rymma långa formler */
    height: 400px;
    cursor: pointer;
    margin: 20px 0;
}

.flashcard {
    position: relative;
    width: 100%;
    height: 100%;
    transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    transform-style: preserve-3d;
}

.flashcard.flipped { transform: rotateY(180deg); }

.card-face {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 45px 30px;
    box-sizing: border-box;
    border-radius: 20px;
    background: white;
    border: 4px solid var(--primary-blue);
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    overflow-y: auto; /* Gör lång text scrollbar inuti kortet */
}

.card-back { transform: rotateY(180deg); background-color: #fcfdfe; }

.math-content {
    width: 100%;
    word-wrap: break-word;
    line-height: 1.6;
}

.label {
    position: absolute; top: 15px; left: 20px;
    font-size: 0.7rem; font-weight: bold; color: var(--primary-blue);
    text-transform: uppercase; letter-spacing: 1px;
}

/* KONTROLLER */
.controls {
    background: white; padding: 10px 25px; border-radius: 50px;
    margin-bottom: 20px; display: flex; gap: 20px; flex-wrap: wrap;
    align-items: center; box-shadow: 0 4px 10px rgba(0,0,0,0.05);
}

.btn-home { position: absolute; top: 20px; left: 20px; padding: 8px 15px; border-radius: 20px; border: 1px solid #ccc; cursor: pointer; }

.feedback-btns { display: flex; gap: 15px; margin-top: 10px; }
.btn { padding: 12px 25px; border: none; border-radius: 10px; color: white; font-weight: bold; cursor: pointer; min-width: 140px; }
.btn-right { background: var(--green-success); }
.btn-wrong { background: var(--red-error); }

/* PLUS-KNAPP & MODAL */
.add-set-btn { position: fixed; bottom: 30px; right: 30px; width: 60px; height: 60px; border-radius: 50%; background: var(--green-success); color: white; font-size: 30px; border: none; cursor: pointer; z-index: 99; }
.modal { display: none; position: fixed; z-index: 200; left: 0; top: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); backdrop-filter: blur(4px); }
.modal-content { background: white; margin: 5% auto; padding: 30px; border-radius: 20px; width: 90%; max-width: 500px; }
textarea { width: 100%; padding: 10px; border-radius: 10px; border: 1px solid #ddd; margin: 10px 0; font-family: inherit; }

/* TOGGLE SWITCH */
.switch { position: relative; width: 40px; height: 22px; display: inline-block; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background: #ccc; transition: .4s; border-radius: 20px; }
.slider:before { position: absolute; content: ""; height: 16px; width: 16px; left: 3px; bottom: 3px; background: white; transition: .4s; border-radius: 50%; }
input:checked + .slider { background: var(--primary-blue); }
input:checked + .slider:before { transform: translateX(18px); }

@media (max-width: 600px) {
    .flashcard-container { height: 350px; }
    .btn-home { position: static; margin-bottom: 10px; }
}