:root {
    --bg-main: #f8fafc;
    --bg-card: #ffffff;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --border-color: #e2e8f0;
    --border-hover: #cbd5e1;

    /* Blue Gradient Configuration */
    --gradient-primary: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
    --gradient-secondary: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
    --accent-blue: #2563eb;

    /* Spacing & Shadows */
    --shadow-subtle:
        0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
    --shadow-hover:
        0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
    --radius-lg: 20px;
    --radius-md: 12px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: "Plus Jakarta Sans", sans-serif;
    /* Prevents iOS tap highlight flickering */
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-main);
    color: var(--text-primary);
    min-height: 100vh;
    padding: 4rem 2rem; /* Will scale down on mobile */
    display: flex;
    flex-direction: column;
    align-items: center;
}

header,
main {
    width: 100%;
    max-width: 1140px;
}

header {
    margin-bottom: 3.5rem;
}

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.logo {
    font-size: 1.25rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.breadcrumb {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.breadcrumb span {
    cursor: pointer;
    transition: color 0.2s ease;
}

.breadcrumb span:hover {
    color: var(--accent-blue);
}

.breadcrumb-separator {
    margin: 0 0.5rem;
    color: var(--border-hover);
}

h1 {
    font-size: 2.5rem;
    font-weight: 800;
    letter-spacing: -0.04em;
    color: var(--text-primary);
    margin-top: 0.5rem;
}

/* Dashboard Grid Layout */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 2rem;
}

.block-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 2.5rem;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 220px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-subtle);
}

.block-card:hover {
    transform: translateY(-6px);
    border-color: transparent;
    box-shadow: var(--shadow-hover);
}

.card-body h3 {
    font-size: 1.4rem;
    font-weight: 700;
    line-height: 1.3;
    margin-bottom: 0.75rem;
    color: var(--text-primary);
}

.card-body p {
    color: var(--text-secondary);
    font-size: 0.95rem;
    line-height: 1.6;
}

.card-footer-action {
    margin-top: 2rem;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--accent-blue);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Flashcard Engine Components */
.flashcard-view-container {
    display: none;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 620px;
    margin: 1.5rem auto 0 auto;
}

.perspective-wrapper {
    perspective: 1500px;
    width: 100%;
    height: 380px;
    margin-bottom: 2.5rem;
}

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

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

.card-face {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3rem;
    border-radius: 24px;
    text-align: center;
    font-size: 1.35rem;
    font-weight: 600;
    line-height: 1.6;
    box-shadow: var(--shadow-subtle);
    border: 1px solid var(--border-color);
    cursor: pointer;
}

.card-front {
    background: var(--bg-card);
    color: var(--text-primary);
}

.card-front::after {
    content: "Tap card to reveal answer";
    position: absolute;
    bottom: 1.5rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 500;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.card-back {
    transform: rotateY(180deg);
    background: var(--gradient-secondary);
    color: #1e3a8a;
    border: 1px solid #bfdbfe;
}

/* Navigation Systems */
.controls-panel {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    background: var(--bg-card);
    padding: 1.25rem 2rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-subtle);
}

button {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 0.8rem 1.5rem;
    font-size: 0.9rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s ease;
    /* Optimizes responsiveness to mobile touches */
    touch-action: manipulation;
}

button:hover:not(:disabled) {
    background: var(--gradient-primary);
    color: white;
    border-color: transparent;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2);
}

button:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.counter-badge {
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--text-secondary);
    background: var(--bg-main);
    padding: 0.6rem 1.2rem;
    border-radius: 30px;
    border: 1px solid var(--border-color);
}

/* Base Visibility Toggles */
.view-state {
    display: none;
}
.view-state.active {
    display: block;
}
.view-state.active-flex {
    display: flex;
}

/* ==========================================================================
   MOBILE & TABLET RESPONSIVE BREAKPOINTS
   ========================================================================== */

/* Tablet Adjustments (Screens smaller than 768px) */
@media (max-width: 768px) {
    body {
        padding: 2.5rem 1.5rem;
    }

    header {
        margin-bottom: 2.5rem;
    }

    h1 {
        font-size: 2rem;
    }

    .grid {
        grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
        gap: 1.5rem;
    }

    .block-card {
        padding: 2rem;
        min-height: 200px;
    }

    .perspective-wrapper {
        height: 340px;
    }
}

/* Smartphone Adjustments (Screens smaller than 480px) */
@media (max-width: 480px) {
    body {
        padding: 1.5rem 1rem;
    }

    .header-top {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
        margin-bottom: 1rem;
    }

    .breadcrumb {
        font-size: 0.8rem;
    }

    h1 {
        font-size: 1.65rem;
        letter-spacing: -0.02em;
    }

    .grid {
        /* Drop grid constraints completely to stack clean full-width cards */
        grid-template-columns: 1fr;
        gap: 1.25rem;
    }

    .block-card {
        padding: 1.75rem;
        min-height: 180px;
    }

    .card-body h3 {
        font-size: 1.25rem;
    }

    .perspective-wrapper {
        height: 320px; /* Shorter card to ensure controls stay above mobile fold */
        margin-bottom: 1.5rem;
    }

    .card-face {
        padding: 1.75rem;
        font-size: 1.15rem;
    }

    .card-front::after {
        font-size: 0.65rem;
        bottom: 1rem;
    }

    .controls-panel {
        padding: 1rem;
    }

    button {
        padding: 0.75rem 1.25rem;
        font-size: 0.85rem;
    }

    .counter-badge {
        font-size: 0.8rem;
        padding: 0.5rem 0.8rem;
    }
}
