/* --- Variable Definitions --- */
:root {
    --font-main: "Roboto Flex", sans-serif;
    
    /* Light Mode Colors */
    --color-primary: #115895;
    --color-link: #198799;
    --color-link-hover: #DC4A0B;
    --color-background: #F4F6F8;
    --color-surface: #FFFFFF;
    --color-text: #212529;
    --color-text-subtle: #6c757d;
    --color-border: #dee2e6;
    --color-button-text: #FFFFFF;
    --color-no: #e74c3c;
    --color-yes: #2ecc71;
}

@media (prefers-color-scheme: dark) {
    :root {
        /* Dark Mode Colors */
        --color-primary: #115895; /* Stays the same as per your spec */
        --color-link: #198799;    /* Stays the same */
        --color-link-hover: #DC4A0B; /* Stays the same */
        --color-background: #111827;
        --color-surface: #1F2937;
        --color-text: #EAEAEA;
        --color-text-subtle: #a0a0a0;
        --color-border: #444444;
        --color-no: #c0392b;
        --color-yes: #27ae60;
    }
}

/* --- General Styles & Resets --- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-main);
    background-color: var(--color-background);
    color: var(--color-text);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* --- Screen Containers --- */
.setup-container, #main-app {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 400px;
    padding: 2rem;
    text-align: center;
}

/* --- Header & Logos --- */
.welcome-logo {
    max-width: 200px;
    margin-bottom: 0.0rem;
}

.app-header {
    margin-bottom: 1rem;
}

.header-logo {
    max-width: 120px;
    height: auto;
}

/* --- Typography --- */
h1 {
    margin-bottom: 2rem;
    font-size: 2.5rem;
    font-weight: 500; 
    color: var(--color-text);
    line-height: 1.2;
    letter-spacing: -0.025em;
}

p {
    margin-bottom: 1.5rem;
    color: var(--color-text-subtle);
    line-height: 1.6;
    max-width: 320px; /* Keeps text from getting too wide on large screens */
}

.tutorial-prompt {
    font-size: 0.9rem;
    color: var(--color-text-subtle);
    margin-top: -1rem; /* Pulls it closer to the text above */
    margin-bottom: 1.5rem;
}

.viajo-link {
    margin-top: 2rem;
    font-size: 0.9rem;
}

/* --- Forms & Buttons --- */
input[type="text"] {
    width: 100%;
    padding: 12px 15px;
    margin-bottom: 1rem;
    border-radius: 8px;
    border: 1px solid var(--color-border);
    background-color: var(--color-surface);
    color: var(--color-text);
    font-family: var(--font-main);
    font-size: 1rem;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input[type="text"]:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(17, 88, 149, 0.2);
}

button {
    border: none;
    border-radius: 8px;
    padding: 10px 20px; /* Reduced padding */
    font-family: var(--font-main);
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease;
}

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

#load-deck-button, #restart-lesson-button {
    width: 100%;
    background-color: var(--color-primary);
    color: var(--color-button-text);
}

.button-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    width: 100%;
    margin-top: 1.5rem;
}

.button-no {
    background-color: #105995;
    color: var(--color-button-text);
    font-weight: 400; /* Set to normal weight */
}

.button-yes {
    background-color: #198799;
    color: var(--color-button-text);
    font-weight: 400; /* Set to normal weight */
}

.link-button, .viajo-link {
    background: none;
    color: var(--color-link);
    text-decoration: none;
    margin-top: 1.5rem;
    font-weight: 400; /* Ensure normal weight */
}

.link-button:hover, .viajo-link:hover {
    color: var(--color-link-hover);
    text-decoration: underline;
}

/* --- Flashcard Styling --- */
.card-container {
    perspective: 1000px;
    width: 100%;
    height: 250px;
    position: relative; /* This is new */
}

.card-container.hiding {
    opacity: 0;
}

/* --- Card Animation States --- */
/* The card waiting to come forward from behind */
.flashcard.is-next {
    transform: translateY(50px) scale(0.85); /* Starts further back */
    opacity: 0; /* Starts completely invisible */
    z-index: 1;
}

/* The active card currently being displayed */
.flashcard.is-active {
    transform: translateY(0) scale(1);
    opacity: 1;
    z-index: 2;
}

/* New: The card that is actively swiping out */
.flashcard.swiping-left {
    transition: transform 0.25s ease-in, opacity 0.25s ease-in;
    transform: translateX(-120%) rotate(-30deg); /* Swipes out to the LEFT */
    opacity: 0;
    z-index: 3; /* Ensure it's on top as it leaves */
}

.flashcard.swiping-right {
    transition: transform 0.25s ease-in, opacity 0.25s ease-in;
    transform: translateX(120%) rotate(30deg); /* Swipes out to the RIGHT */
    opacity: 0;
    z-index: 3; /* Ensure it's on top as it leaves */
}

.flashcard.swiping-down {
    transition: transform 0.25s ease-in, opacity 0.25s ease-in;
    transform: translateY(120%); /* Swipes out DOWN */
    opacity: 0;
    z-index: 3; /* Ensure it's on top as it leaves */
}

.flashcard {
    width: 100%;
    height: 100%;
    position: absolute;
    transform-style: preserve-3d;
    cursor: pointer;
    /* This main transition is for the card coming forward */
    transition: transform 0.3s cubic-bezier(0.25, 1, 0.5, 1), opacity 0.3s ease-out;
}

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

.card-face {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden; /* Safari */
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    border-radius: 12px;
    background-color: var(--color-surface);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    border: 1px solid var(--color-border);
}

.card-face p {
    font-size: 1.5rem;
    color: var(--color-text);
    margin: 0;
    font-weight: 400; /* Sets font weight to normal */
}

.card-back {
    transform: rotateY(180deg);
}

/* --- Recent Decks Styling --- */
#recent-decks-container {
    width: 100%;
    margin-top: 2.5rem;
    text-align: left;
    border-top: 1px solid var(--color-border);
    padding-top: 1.5rem;
}

#recent-decks-container h3 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--color-text);
    margin-bottom: 1rem;
    text-align: center;
}

.recent-decks-list {
    list-style: none; /* Removes the numbers */
    padding: 0;
    text-align: center;
}

.recent-decks-list li {
    margin-bottom: 0.75rem;
}

.recent-decks-list a {
    color: var(--color-link);
    text-decoration: none;
    font-weight: 400;
}

.recent-decks-list a:hover {
    color: var(--color-link-hover);
    text-decoration: underline;
}

.powered-by {
    display: block;
    margin-top: -20px;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

.share-notice {
    font-size: 0.8rem;
    color: var(--color-text-subtle);
    margin-top: 0.0rem;
    margin-bottom: 1rem;
}

/* --- Tutorial Modal Styling --- */
.modal-overlay {
    display: none; /* Hidden by default */
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: var(--color-background) !important;
    justify-content: center;
    align-items: center;
}

.modal-content {
    position: relative;
    background-color: var(--color-surface);
    margin: auto;
    padding: 0;
    border-radius: 12px;
    width: 90%;
    max-width: 600px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    animation: fadeIn 0.3s;
}

@keyframes fadeIn {
    from {transform: scale(0.95); opacity: 0;}
    to {transform: scale(1); opacity: 1;}
}

.modal-slides-container {
    padding: 20px 50px; /* Space for arrows */
    text-align: center;
    background-color: var(--color-background);
}

#tutorial-image {
    max-width: 100%;
    max-height: 70vh;
    border-radius: 8px;
    user-select: none; /* Prevents image dragging */
    -webkit-user-select: none; /* Safari */
}

.modal-close-button {
    color: var(--color-text-subtle);
    position: absolute;
    top: 10px;
    right: 20px;
    font-size: 2rem;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.2s ease;
}

.modal-close-button:hover,
.modal-close-button:focus {
    color: var(--color-text);
    text-decoration: none;
}

.modal-arrow {
    cursor: pointer;
    position: absolute;
    top: 50%;
    width: auto;
    margin-top: -22px;
    padding: 16px;
    color: var(--color-text);
    font-weight: bold;
    font-size: 1.5rem;
    transition: 0.3s ease;
    border-radius: 0 3px 3px 0;
    user-select: none;
    -webkit-user-select: none; /* Safari */
}

.modal-arrow.prev {
    left: 0;
    border-radius: 3px 0 0 3px;
}

.modal-arrow.next {
    right: 0;
    border-radius: 0 3px 3px 0;
}

.modal-arrow:hover {
    background-color: transparent;
    color: var(--color-text);
}

#slide-counter {
    text-align: center;
    padding: 10px 0;
    color: var(--color-text-subtle);
    background-color: var(--color-background);
    font-size: 0.9rem;
}

/* Styles the tutorial button to look like an inline link */
.link-button-inline {
    background: none;
    border: none;
    padding: 0;
    margin: 0;
    font-family: inherit;
    font-size: inherit;
    font-weight: 400;
    color: var(--color-link);
    text-decoration: underline;
    cursor: pointer;
    display: inline; /* Makes it sit nicely in the text */
}

.link-button-inline:hover {
    color: var(--color-link-hover);
}

.link-button-inline:focus-visible {
    outline: none; /* Removes the default oval outline */
    border-radius: 4px; /* Creates a rectangle with slightly rounded corners */
    box-shadow: 0 0 0 2px var(--color-background), 0 0 0 4px var(--color-primary); /* Adds a clean, bigger outline */
}

/* --- Keyboard Shortcut Cues --- */
.key-cue {
    display: none; /* Hidden by default on all devices */
    font-size: 0.8rem;
    color: var(--color-text-subtle);
    margin-top: 6px;
    font-weight: 500;
    text-align: center;
}

#flip-cue {
    margin-bottom: 1rem;
}

/* Show the cues ONLY on devices that support hover (i.e., desktops with a mouse) */
@media (hover: hover) {
    .key-cue {
        display: block;
    }
}

/* --- NEW: Highlight Animation for Sample Link --- */
.is-highlighted {
    animation: flash-border 1.5s 1;
}

@keyframes flash-border {
    0%   {
        border-color: #115895;
        box-shadow: 0 0 0 3px rgba(17, 88, 149, 0.3);
        background-color: #DEE2E6;
    }
    100% {
        border-color: var(--color-border);
        box-shadow: none;
        background-color: var(--color-surface);
    }
}

/* --- Mobile Tutorial Modal (Fullscreen) --- */
@media (max-width: 600px) {

    #tutorial-modal .modal-content {
        width: 100vw;
        height: 100vh;
        border-radius: 0;
        max-width: none;
        padding: 0;
        display: flex;
        flex-direction: column;
    }

    .modal-slides-container {
        height: 100%;
        width: 100%;
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        background-color: var(--color-background);
    }

    #tutorial-image {
        max-width: 100%;
        max-height: 95%;
        object-fit: contain;
    }

    .modal-arrow {
        background-color: rgba(0, 0, 0, 0.4);
        color: white;
        border-radius: 50%;
        width: 44px;
        height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 0;
        top: auto;
        bottom: 20vh;
        margin-top: 0;
        transform: none;
    }

    .modal-arrow:hover {
        background-color: rgba(0, 0, 0, 0.4); /* No background change on hover */
        color: white;
    }

    .modal-arrow.prev {
        left: 50%;
        margin-left: -54px;
        right: auto;
    }

    .modal-arrow.next {
        left: 50%;
        margin-left: 10px;
        right: auto;
    }

    /* Using a more specific selector to force the button to move */
    #tutorial-modal .modal-close-button {
        color: white;
        background-color: rgba(0, 0, 0, 0.4);
        border-radius: 50%;
        width: 32px;
        height: 32px;
        font-size: 1.5rem;
        display: flex;
        align-items: center;
        justify-content: center;
        top: 22vh;
        right: 15px;
    }

    #slide-counter {
        position: absolute;
        bottom: 15vh;
        left: 0;
        right: 0;
        color: var(--color-text-subtle);
        padding: 0;
        background-color: transparent; /* Ensure no background color interferes */
    }
}