:root {
    --primary-color: #4a90e2;
    --primary-hover: #357abd;
    --secondary-color: #6c757d;
    --background-color: #f4f7f6;
    --card-bg: #ffffff;
    --card-back-bg: #f8f9fa;
    --text-color: #333333;
    --shadow-sm: 0 2px 4px rgba(0,0,0,0.1);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.1);
    --radius-md: 12px;
    --radius-lg: 20px;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    margin: 0;
    display: flex;
    justify-content: center;
    min-height: 100vh;
    color: var(--text-color);
}

.container {
    width: 100%;
    max-width: 900px;
    padding: 40px 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

header {
    width: 100%;
    margin-bottom: 40px;
    text-align: center;
    background: rgba(255, 255, 255, 0.8);
    padding: 20px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    backdrop-filter: blur(10px);
}

h1 {
    margin: 0 0 15px 0;
    color: var(--primary-color);
    font-weight: 700;
    font-size: 2.5rem;
    letter-spacing: -0.5px;
}

.controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
}

label {
    font-weight: 600;
    color: var(--secondary-color);
}

select {
    padding: 10px 16px;
    font-size: 16px;
    border-radius: 8px;
    border: 2px solid #e1e4e8;
    background-color: white;
    cursor: pointer;
    transition: border-color 0.2s;
    outline: none;
}

select:focus {
    border-color: var(--primary-color);
}

select:hover {
    border-color: #cbd3da;
}

main {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.flashcard {
    background-color: transparent;
    width: 100%;
    max-width: 700px;
    min-height: 450px;
    height: auto;
    perspective: 1000px;
    cursor: pointer;
    margin-bottom: 30px;
}

.card-inner {
    position: relative;
    width: 100%;
    min-height: 450px;
    text-align: center;
    transition: transform 0.6s cubic-bezier(0.4, 0.0, 0.2, 1);
    transform-style: preserve-3d;
    box-shadow: var(--shadow-lg);
    border-radius: var(--radius-lg);
    background-color: var(--card-bg);
    display: grid;
    grid-template-areas: "card";
}

.flashcard:hover .card-inner {
    box-shadow: 0 15px 25px rgba(0,0,0,0.15);
}

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

.card-face {
    grid-area: card;
    width: 100%;
    height: 100%;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: var(--radius-lg);
    padding: 40px;
    box-sizing: border-box;
    overflow-y: visible;
}

.card-face::-webkit-scrollbar {
    width: 6px;
}

.card-face::-webkit-scrollbar-thumb {
    background-color: #d1d5db;
    border-radius: 3px;
}

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

/* Subtle pattern for the back to distinguish it */
.card-back {
    background-color: var(--card-back-bg);
    color: var(--text-color);
    transform: rotateY(180deg);
    border: 1px solid rgba(0,0,0,0.05);
    background-image: radial-gradient(#e1e4e8 1px, transparent 1px);
    background-size: 20px 20px;
}

.content {
    font-size: 1.5rem;
    line-height: 1.6;
    text-align: center; /* Center text by default */
    width: 100%;
    max-width: 100%;
}

/* Ensure aligned text for code blocks or lists */
.content pre, .content ul, .content ol {
    text-align: left;
    display: inline-block; /* Helps with centering the block itself while keeping content left-aligned */
    width: auto;           /* Do not force full width, allow centering */
    max-width: 100%;       /* Prevent overflow */
    box-sizing: border-box;
}

.content ul, .content ol {
    padding-left: 1.5em;   /* Ensure bullets have space inside the block */
}

.content h1, .content h2, .content h3 {
    margin-top: 0;
}

.content img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
}

/* Code block styling */
pre {
    background-color: #2d3436;
    color: #dfe6e9;
    padding: 15px;
    border-radius: 8px;
    overflow-x: auto;
    font-size: 0.9rem;
}

code {
    font-family: 'Consolas', 'Monaco', monospace;
    background-color: rgba(0,0,0,0.05);
    padding: 2px 4px;
    border-radius: 4px;
}

pre code {
    background-color: transparent;
    padding: 0;
}

/* Table Styles */
.content table {
    border-collapse: collapse;
    width: auto;
    max-width: 100%;
    margin: 15px auto;
    border: 1px solid #dbdbdb;
}

.content th, .content td {
    border: 1px solid #dbdbdb;
    padding: 8px 15px;
    text-align: left;
}

.content th {
    background-color: #f1f3f5;
    font-weight: 600;
}

.navigation {
    display: flex;
    align-items: center;
    gap: 30px;
    background: white;
    padding: 15px 30px;
    border-radius: 50px;
    box-shadow: var(--shadow-md);
}

button {
    padding: 12px 25px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 25px;
    transition: all 0.2s;
    box-shadow: 0 2px 5px rgba(74, 144, 226, 0.3);
}

button:hover {
    background-color: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(74, 144, 226, 0.4);
}

button:active {
    transform: translateY(0);
}

button:disabled {
    background-color: #e0e0e0;
    color: #a0a0a0;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

#counter {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--secondary-color);
    min-width: 60px;
    text-align: center;
}

.instruction {
    margin-top: 20px;
    color: var(--secondary-color);
    font-size: 0.95rem;
    opacity: 0.7;
    display: flex;
    align-items: center;
    gap: 5px;
}

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

.flashcard {
    animation: fadeIn 0.5s ease-out;
}
