/* Global Resets and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    line-height: 1.6;
    background-color: #f4f7f6; /* Softer background */
    color: #333;
    padding: 20px;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
}

.app-container {
    background: #ffffff;
    padding: 30px 40px;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 77, 153, 0.1); /* Softer shadow */
    width: 100%;
    max-width: 650px; /* Optimal width for single card display */
    margin: 20px auto;
    display: flex;
    flex-direction: column;
}

/* Header Styling */
header {
    border-bottom: 1px solid #e0e6ed;
    padding-bottom: 25px;
    margin-bottom: 25px;
    text-align: center;
}
header h1 {
    color: #1a5f99; /* Professional blue */
    font-size: 2em;
    font-weight: 600;
    margin-bottom: 20px;
}
.app-controls { display: flex; flex-direction: column; gap: 15px; }
.initial-load-button {
    background-color: #007bff; border-color: #007bff; font-size: 1.1em;
    width: 100%; padding: 12px; color: white; border-radius: 6px; cursor: pointer; transition: background-color 0.2s;
}
.initial-load-button:hover { background-color: #0056b3; }
.initial-load-button:disabled { background-color: #adb5bd; cursor: not-allowed; }

.session-controls {
    padding: 15px;
    background-color: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #e9ecef;
}
.session-controls-row {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
}
.topic-selector-group { display: flex; align-items: center; gap: 8px; flex: 2; min-width: 250px;}
.shuffle-control-group { display: flex; align-items: center; gap: 8px; flex: 1; justify-content: flex-end; }

.topic-selector-group label, .shuffle-control-group label { 
    font-weight: 500; color: #495057; margin-right: 5px; white-space: nowrap; cursor: pointer;
}
#topic-selector, #shuffle-toggle {
    padding: 10px 12px; border: 1px solid #ced4da; border-radius: 6px;
    font-size: 1em; color: #495057; background-color: #fff;
}
#topic-selector { flex-grow: 1; }
#shuffle-toggle { transform: scale(1.2); cursor: pointer; accent-color: #007bff; }
#topic-selector:focus { border-color: #3498db; box-shadow: 0 0 0 0.2rem rgba(52, 152, 219, 0.25); outline: none; }


/* Main Flashcard Area */
#flashcard-area {
    margin-top: 25px;
    flex-grow: 1; 
    display: flex;
    flex-direction: column;
    justify-content: center; 
    align-items: center;
}

.flashcard-viewer {
    width: 100%;
    max-width: 480px; 
    height: 280px;    
    perspective: 1200px; /* Enhanced 3D effect */
    margin-bottom: 25px; 
}

.flashcard {
    width: 100%; height: 100%;
    position: relative;
    cursor: pointer;
    user-select: none;
}
.flashcard:focus {
    outline: none;
}

.flashcard:focus-visible { /* Style for keyboard-only focus, modern browsers */
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.45); /* Subtle blue glow, similar to Bootstrap focus */
    border-radius: 12px; /* Ensure shadow follows card curve if flashcard itself has radius */
}

.flashcard-inner {
    width: 100%; height: 100%;
    text-align: center;
    transition: transform 0.6s cubic-bezier(0.4, 0.0, 0.2, 1); /* Smoother transition */
    transform-style: preserve-3d;
    border-radius: 15px; /* Slightly more pronounced curve, adjust as you like (e.g., 8px, 10px, 15px) */
    /* Layered shadow for a softer, more "embossed" or lifted effect */
    box-shadow: 
        0 2px 4px rgba(0, 0, 0, 0.07), /* Closer, subtle shadow */
        0 5px 15px rgba(0, 0, 0, 0.1); /* More diffuse, larger shadow for depth */
}

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

.flashcard-front,
.flashcard-back {
    position: absolute;
    width: 100%;
    height: 100%;
    -webkit-backface-visibility: hidden; /* Safari */
    backface-visibility: hidden;
    display: flex;
    flex-direction: column; 
    align-items: center;
    justify-content: center;
    padding: 25px;
    border-radius: 15px; /* Match the inner card's radius */
    /* border: 1px solid #e0e6ed; */ /* Slightly softer border color */
    overflow-y: auto; 
    font-size: 1.2em; 
}

.flashcard-front::before, .flashcard-back::before {
    position: absolute;
    top: 15px;
    left: 15px;
    font-size: 0.7em;
    font-weight: bold;
    color: #007bff;
    text-transform: uppercase;
}
.flashcard-front::before { content: 'Question'; }
.flashcard-back::before { content: 'Answer'; }


.flashcard-front {
    background: linear-gradient(135deg, #ffffff 0%, #f8fcff 100%);
    color: #2c3e50;
}
#flashcard-question-text { font-weight: 500; line-height: 1.4; }

.flashcard-back {
    /* Slightly different background for back */
    /* background: linear-gradient(135deg, #f0f4f8 0%, #e6edf5 100%); */
    /* Slightly different background for back */
    color: #34495e;
    transform: rotateY(180deg); 
}
#flashcard-answer-text { line-height: 1.5; }

#flashcard-empty-message { font-size: 1.1em; color: #6c757d; }

/* Navigation Footer Styling */
footer#navigation-controls { 
    display: flex; justify-content: space-between; align-items: center; 
    margin-top: auto; 
    padding-top: 25px; border-top: 1px solid #e0e6ed; width: 100%;
}
#flashcard-counter { font-size: 0.95em; color: #495057; font-weight: 500; }

button { 
    padding: 10px 18px; font-size: 1em; font-weight: 500; color: #fff;
    background-color: #007bff; border: none; border-radius: 6px;
    cursor: pointer; transition: background-color 0.2s, transform 0.1s;
}
button:hover:not(:disabled) { background-color: #0056b3; transform: translateY(-1px); }
button:active:not(:disabled) { transform: translateY(0px); }
button:disabled { background-color: #adb5bd; cursor: not-allowed; opacity: 0.7; }

/* Loading and Error Message Styling */
#loading-indicator { font-size: 1.2em; color: #495057; padding: 30px 0; text-align: center; }
.status-message { padding: 10px 15px; margin-top: 15px; border-radius: 6px; text-align: center; font-weight: 500; }
.error-message { color: #842029; background-color: #f8d7da; border: 1px solid #f5c2c7; }
#error-message:empty { display:none; }

/* Responsive Adjustments */
@media (max-width: 600px) {
    .app-container { padding: 20px 15px; }
    header h1 { font-size: 1.6em; }
    .flashcard-viewer { height: 280px; max-width: 100%; } /* More responsive height */
    .flashcard-front, .flashcard-back { font-size: 1.1em; padding: 15px; }
    .flashcard-front::before, .flashcard-back::before { font-size: 0.65em; top: 10px; left: 10px; }
    
    .session-controls-row { flex-direction: column; align-items: stretch; gap: 15px; }
    .topic-selector-group, .shuffle-control-group { width: 100%; justify-content: flex-start; }
    .topic-selector-group label, .shuffle-control-group label { text-align: left; }
    #topic-selector { width: 100%; }

    footer#navigation-controls { flex-wrap: wrap; justify-content: center; gap: 10px; }
    #flashcard-counter { width: 100%; text-align: center; order: -1; margin-bottom: 10px; }
    #prev-flashcard, #next-flashcard { flex-grow: 1; }
}