:root {
    --primary: #3b82f6;
    --primary-light: #60a5fa;
    --primary-dark: #1e40af;
    --accent: #8b5cf6;
    --bg: #f8fafc;
    --card-bg: #ffffff;
    --text: #0f172a;
    --text-secondary: #64748b;
    --card-shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 4px 6px rgba(0, 0, 0, 0.04);
    --border-color: #e2e8f0;
}

html {
    height: 100%;
    overflow-x: hidden;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg);
    /* Moved background to pseudo-element or fixed container to prevent jumps */
    color: var(--text);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    min-height: 100%;
    margin: 0;
    padding: 20px;
    box-sizing: border-box;
    overflow-x: hidden;
    position: relative;
}

/* Fixed background container */
body::before {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-image: url('background.png');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    z-index: -1;
    /* Ensure it stays behind everything */
}

h1 {
    margin-top: 20px;
    margin-bottom: 32px;
    font-size: 2rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.5px;
}

/* Progress Bar */
.progress {
    margin-bottom: 28px;
    font-size: 0.9rem;
    color: var(--text);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 12px;

    /* Improve readability over background image */
    background: rgba(255, 255, 255, 0.4);
    padding: 12px 16px;
    border-radius: 16px;
    box-shadow: 0 6px 18px rgba(12, 14, 20, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    max-width: 100%;
}

@media (max-width: 480px) {
    .progress {
        padding: 2px 8px;
        gap: 4px;
        flex-direction: row;
        justify-content: center;
        width: auto;
        margin-bottom: 8px;
        border-radius: 20px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    }

    .progress__controls {
        gap: 0;
    }

    .progress__controls button {
        padding: 4px;
        font-size: 0.9rem;
        min-width: 28px;
        background: transparent;
        border: none;
        box-shadow: none;
    }

    .progress__info {
        gap: 2px;
        font-size: 0.8rem;
    }

    .progress__info select {
        max-width: 85px;
        font-size: 0.75rem;
        border: none !important;
    }

    .progress__info input {
        width: 32px !important;
        font-size: 0.8rem;
        padding: 0 !important;
        border: none !important;
        background: transparent !important;
    }

    .progress__info span:first-of-type {
        display: none;
    }
}

/* The Flashcard Scene */
.scene {
    width: 100%;
    max-width: 550px;
    height: 380px;
    perspective: 1000px;
    cursor: pointer;
}

/* Controls moved to the progress bar for compact layout */
.progress__controls {
    display: inline-flex;
    gap: 4px;
    /* reduced from 8px */
    align-items: center;
    margin-right: 8px;
    /* reduced from 12px */
    padding: 2px 4px;
    /* reduced from 4px 8px */
    border-radius: 10px;
}

.progress__controls button {
    background: rgba(255, 255, 255, 0.4);
    padding: 4px 8px;
    /* reduced from 6px 10px */
    min-width: 32px;
    /* reduced from 38px */
    border-radius: 6px;
    font-size: 0.95rem;
}

/* The Card Object */
.card {
    width: 100%;
    height: 100%;
    position: relative;
    transition: transform 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    transform-style: preserve-3d;
    border-radius: 16px;
    box-shadow: var(--card-shadow);
}

/* Flip Action */
.card.is-flipped {
    transform: rotateY(180deg);
}

/* Card Faces */
.card__face {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    text-align: center;
    padding: 40px 40px 96px;
    /* leave space at bottom for controls */
    box-sizing: border-box;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    font-size: 1.1rem;
    line-height: 1.6;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* Vertically center content when it's short, but allow scrolling from top when long */
.card__face::before,
.card__face::after {
    content: '';
    margin: auto;
}

/* Custom scrollbar for better visibility on long answers */
.card__face::-webkit-scrollbar {
    width: 6px;
}

.card__face::-webkit-scrollbar-track {
    background: transparent;
}

.card__face::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 3px;
}

.card__face--back::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
}

.card__face--front {
    border: 2px solid rgba(59, 130, 246, 0.9);
    color: var(--primary);
    font-weight: 600;
    background-color: rgba(255, 255, 255, 0.85);
    background-image: linear-gradient(135deg, rgba(59, 130, 246, 0.03) 0%, rgba(139, 92, 246, 0.03) 100%);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

.card__face--back {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.9) 0%, rgba(30, 64, 175, 0.9) 100%);
    color: white;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    transform: rotateY(180deg);
}

/* Navigation Buttons */
.controls {
    margin-top: 40px;
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: center;
}

/* Small spacing to keep the progress bar neat */
/* .progress select,
.progress input,
.progress span,
.progress .progress__controls {
    vertical-align: middle;
} */

/* Controls placed as direct children of the .card so they move with the card and stay on top */
.card>.controls {
    position: absolute;
    /* overlay on the card so they remain visible */
    left: 50%;
    transform: translateX(-50%);
    bottom: 18px;
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
    z-index: 60;
    /* ensure buttons sit on top of faces */
    width: calc(100% - 48px);
    pointer-events: auto;
}

/* Visibility toggles: by default show front controls; when flipped hide all controls */
.card>.controls.controls--back {
    display: none;
}

.card.is-flipped>.controls.controls--front {
    display: none;
}

.card.is-flipped>.controls.controls--back {
    display: none;
}

/* Ensure all controls are hidden when the card is flipped */
.card.is-flipped>.controls {
    display: none !important;
    pointer-events: none !important;
}

/* Prominent flip button inside the card */
.card .flipBtn {
    background-color: var(--primary);
    color: white;
    border-color: var(--primary);
    padding: 8px 18px;
    border-radius: 8px;
    font-weight: 700;
}

/* Back face variant so the button looks good on dark background */
.card__face--back .flipBtn {
    background-color: rgba(255, 255, 255, 0.12);
    color: white;
    border-color: rgba(255, 255, 255, 0.2);
}

.card .controls button:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
}

/* Slightly smaller buttons inside cards for better fit */
.card .controls button {
    padding: 8px 12px;
    min-width: 72px;
}

@media (max-width: 480px) {
    .card .controls button {
        padding: 8px 10px;
        font-size: 0.9rem;
        min-width: 60px;
    }
}

button {
    padding: 10px 24px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background-color: white;
    color: var(--text);
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 500;
    transition: all 0.2s ease;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

button:hover {
    background-color: var(--primary);
    color: white;
    border-color: var(--primary);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
    transform: translateY(-1px);
}

button:active {
    transform: scale(0.96);
}

/* Swipe Animations */
@keyframes slideOutLeft {
    to {
        transform: translateX(-150%) rotateY(0deg);
        opacity: 0;
    }
}

@keyframes slideOutLeftFlipped {
    to {
        transform: translateX(-150%) rotateY(180deg);
        opacity: 0;
    }
}

@keyframes slideOutRight {
    to {
        transform: translateX(150%) rotateY(0deg);
        opacity: 0;
    }
}

@keyframes slideOutRightFlipped {
    to {
        transform: translateX(150%) rotateY(180deg);
        opacity: 0;
    }
}

@keyframes slideInLeft {
    from {
        transform: translateX(-150%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideInRight {
    from {
        transform: translateX(150%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.card.slide-out-left {
    animation: slideOutLeft 0.3s forwards ease-in;
}

.card.slide-out-left-flipped {
    animation: slideOutLeftFlipped 0.3s forwards ease-in;
}

.card.slide-out-right {
    animation: slideOutRight 0.3s forwards ease-in;
}

.card.slide-out-right-flipped {
    animation: slideOutRightFlipped 0.3s forwards ease-in;
}

.card.slide-in-left {
    animation: slideInLeft 0.3s forwards ease-out;
}

.card.slide-in-right {
    animation: slideInRight 0.3s forwards ease-out;
}

/* Mobile Adjustments */
@media (max-width: 480px) {
    body {
        padding: 8px;
    }

    h1 {
        font-size: 1.25rem;
        margin-top: 2px;
        margin-bottom: 8px;
    }

    .scene {
        height: 520px;
        max-height: 75vh;
    }

    .card__face {
        padding: 16px 12px 60px;
        font-size: 0.9rem;
    }

    .controls {
        gap: 8px;
        width: 100%;
    }

    button {
        padding: 10px 14px;
        font-size: 0.9rem;
    }
}

/* Simple password gate overlay */
.gate {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.gate__panel {
    background: var(--card-bg);
    color: var(--text);
    padding: 32px;
    border-radius: 16px;
    width: 380px;
    max-width: calc(100% - 40px);
    box-shadow: 0 20px 25px rgba(0, 0, 0, 0.15);
    text-align: center;
}

.gate__panel h2 {
    margin: 0 0 16px;
    font-size: 1.3rem;
    font-weight: 700;
}

.gate__panel input {
    width: 100%;
    padding: 12px;
    margin-bottom: 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    background: var(--bg);
    color: var(--text);
    box-sizing: border-box;
    transition: border-color 0.2s;
}

.gate__panel input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.gate__actions {
    display: flex;
    justify-content: center;
    gap: 8px;
}

.gate__msg {
    color: #dc2626;
    min-height: 1.2em;
    margin-bottom: 12px;
    font-size: 0.9rem;
    font-weight: 500;
}

.gate__hint {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 12px;
}

body.locked {
    overflow: hidden;
}

/* Shake hint */
@keyframes shake {
    0% {
        transform: translateX(0);
    }

    20% {
        transform: translateX(-6px);
    }

    40% {
        transform: translateX(6px);
    }

    60% {
        transform: translateX(-4px);
    }

    80% {
        transform: translateX(4px);
    }

    100% {
        transform: translateX(0);
    }
}

.shake {
    animation: shake 0.3s ease;
}

/* Input styling for progress */
input[type="number"] {
    padding: 6px 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: inherit;
    color: var(--text);
    background: var(--bg);
    width: 50px;
    text-align: center;
    transition: border-color 0.2s;
}

input[type="number"]:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
}
