:root {
    /* Flashcards specific variables */
    --glass-bg: rgba(255, 255, 255, 0.75);
    --glass-border: rgba(0, 0, 0, 0.08);
    --card-ratio: 1.6;
}

/* Background Blobs - Scoped to the flashcards wrapper */
.flashcards-wrapper {
    position: relative;
    width: 100%;
    max-width: 1100px;
    margin: 0 auto;
    height: auto;
    min-height: 100vh;
    padding: 1.5rem clamp(1.5rem, 4vw, 2.5rem);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
    box-sizing: border-box;
    overflow-x: hidden;
}



.background-blobs {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    overflow: hidden;
    pointer-events: none;
}

.blob {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.15;
    animation: float 10s infinite ease-in-out;
}

.blob-1 {
    width: 400px;
    height: 400px;
    background: var(--accent-color);
    top: -100px;
    left: -100px;
}

.blob-2 {
    width: 300px;
    height: 300px;
    background: var(--accent-hover);
    bottom: -50px;
    right: -50px;
    animation-delay: -2s;
}

.blob-3 {
    width: 200px;
    height: 200px;
    background: var(--accent-light);
    top: 40%;
    left: 60%;
    animation-delay: -5s;
}

@keyframes float {

    0%,
    100% {
        transform: translate(0, 0);
    }

    50% {
        transform: translate(30px, -30px);
    }
}

.app-header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    background: linear-gradient(to right, #333, #555);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 1rem;
    text-align: center;
}

/* Glass Panel Utility */
.glass-panel {
    background: transparent;
    border: none;
    box-shadow: none;
    border-radius: 0;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}

/* Library Section */
.card {
    width: 100%;
    max-width: 800px;
    /* Limit width */
    padding: 2rem;
    transition: transform 0.3s ease;
    margin-bottom: 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

#results-section {
    text-align: center;
    padding: 3rem 2rem;
}

#results-section h2 {
    font-size: 2rem;
    margin-bottom: 2rem;
    color: var(--text-primary);
}

.score-circle {
    width: 150px;
    height: 150px;
    border-radius: 50%;
    border: 4px solid var(--accent-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    font-weight: 700;
    margin: 0 auto 2rem;
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}

.score-circle .total {
    font-size: 1.5rem;
    color: var(--text-secondary);
    font-weight: 500;
    margin-left: 5px;
}

.deck-list {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 2rem;
    max-height: 400px;
    overflow-y: auto;
    padding: 0.5rem;
}

.instruction-panel {
    gap: 1rem;
    padding-top: 1.5rem;
}

.instruction-lede {
    color: var(--text-secondary);
    margin: 0;
}

.instruction-list {
    margin: 0;
    padding-left: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    color: var(--text-primary);
}

.instruction-list strong {
    color: var(--accent-color);
}

.instruction-list em {
    font-style: normal;
    color: inherit;
}

.instruction-footer {
    padding: 1rem 1.25rem;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: var(--text-secondary);
    font-size: 0.95rem;
    line-height: 1.5;
}

.deck-overview {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
}

.deck-overview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    gap: 1.5rem;
    width: 100%;
    max-width: 100%;
    margin: 0 auto 2rem;
}

.deck-title-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    width: 100%;
}

.deck-title-input {
    border: none;
    background: transparent;
    font-size: 2rem;
    font-weight: 600;
    color: var(--text-primary);
    padding: 0;
    margin: 0 0 0.35rem 0;
    width: 100%;
    max-width: none;
}

.deck-title-row {
    display: flex;
    align-items: flex-end;
    gap: 0.75rem;
    flex-wrap: wrap;
    width: 100%;
    margin-bottom: 0.35rem;
}

.deck-title-input-wrapper {
    flex: 1;
}

.deck-title-icon {
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 1.4rem;
    padding: 0.65rem;
    border-radius: 50%;
    transition: color 0.2s ease, background 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.deck-title-icon:hover {
    color: var(--accent-color);
    background: rgba(64, 120, 255, 0.12);
}

.deck-title-actions {
    margin-top: 0.75rem;
    width: 100%;
    position: relative;
    display: flex;
    justify-content: flex-start;
    gap: 0.75rem;
}

.deck-title-actions .btn {
    width: calc(33.333% - 0.5rem);
    flex: 0 0 calc(33.333% - 0.5rem);
    border-radius: 28px;
    min-height: 44px;
    padding: 0.6rem 1.1rem;
    font-size: 0.95rem;
    text-align: center;
}

.deck-title-actions .btn.hidden {
    visibility: hidden;
}

@media (max-width: 640px) {
    .deck-title-actions {
        flex-direction: column;
    }

    .deck-title-actions .btn {
        width: 100%;
        flex: 1 1 100%;
    }

    .deck-title-actions .btn.hidden {
        display: none;
    }
}

.deck-title-subactions {
    display: contents;
}


.deck-title-input:focus {
    outline: none;
    border-bottom: 1px solid var(--accent-color);
}

.deck-title-input::placeholder {
    color: var(--text-secondary);
}

.deck-title-input:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    border-bottom: none;
}

.deck-overview-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 1rem;
    text-align: center;
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
    padding-bottom: 1.5rem;
}

.stat {
    padding: 1rem;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    align-items: center;
}

.stat-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
}

.eyebrow {
    text-transform: uppercase;
    letter-spacing: 0.15em;
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--accent-color);
    color: var(--accent-color);
}

.btn-outline:hover {
    background: rgba(255, 255, 255, 0.08);
}

.study-settings {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 500;
}

.settings-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    animation: modalFadeIn 0.15s ease;
}

.settings-content {
    position: relative;
    width: min(320px, 90vw);
    background: var(--bg-primary);
    border-radius: 20px;
    border: 1px solid var(--glass-border);
    padding: 1.25rem;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
    z-index: 1;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    animation: modalSlideIn 0.15s ease;
}

.settings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.settings-header .icon-btn {
    font-size: 1.4rem;
    width: 2.75rem;
    height: 2.75rem;
    border: 1px solid var(--glass-border);
    background: var(--bg-secondary);
    color: var(--text-primary);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.08);
}

.settings-header .icon-btn:hover {
    background: var(--bg-tertiary);
}

.settings-header h3 {
    margin: 0;
    font-size: 1.4rem;
}

.settings-body {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    font-size: 0.9rem;
}

.settings-group {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    padding: 0;
}

.settings-group p {
    margin: 0.75rem 0 0.5rem 0;
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.settings-group-inline label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.settings-actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    align-items: center;
    margin-top: 2rem;
}

.settings-delete-btn {
    margin-top: 0.25rem;
    margin-bottom: 0;
    font-weight: 500;
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.8rem;
}

.btn-danger-outline {
    background: transparent;
    border: 1px solid rgba(239, 83, 80, 0.5) !important;
    color: var(--danger-color);
}

.btn-danger-outline:hover {
    background: var(--danger-color);
    color: white;
    box-shadow: 0 4px 12px rgba(239, 83, 80, 0.2);
    border-color: var(--danger-color);
}

.settings-action-group {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.settings-action-group .btn {
    padding: 4px 8px;
    font-size: 0.8rem;
    font-weight: 500;
    border-radius: 4px;
}

/* Apply compact styling to ALL buttons in settings */
.settings-content .btn {
    padding: 4px 8px !important;
    font-size: 0.8rem !important;
    font-weight: 500;
    border-radius: 4px;
    width: 180px;
    text-align: center;
}

.utility-action-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: 0;
}

.utility-action-group .btn {
    padding: 4px 8px;
    font-size: 0.8rem;
    text-align: center;
    border-radius: 4px;
    background: var(--bg-secondary);
    border: 1px solid var(--glass-border);
    color: var(--text-primary);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.04);
}

.utility-action-group .btn:hover {
    background: var(--bg-tertiary);
}

.debug-history {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 550;
}

.debug-history .debug-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
}

.debug-panel {
    position: relative;
    width: min(600px, 92vw);
    max-height: min(80vh, 640px);
    background: var(--bg-primary);
    border-radius: 20px;
    border: 1px solid var(--glass-border);
    padding: 1.5rem;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
    z-index: 1;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.debug-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.debug-header .icon-btn {
    width: 2.5rem;
    height: 2.5rem;
    font-size: 1.2rem;
    border: 1px solid var(--glass-border);
    background: var(--bg-secondary);
    color: var(--text-primary);
    box-shadow: none;
}

.debug-body {
    background: var(--bg-secondary);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 1rem;
    font-family: 'Fira Code', 'Source Code Pro', monospace;
    font-size: 0.85rem;
    overflow: auto;
    flex: 1;
    min-height: 220px;
    white-space: pre-wrap;
    word-break: break-word;
}

.debug-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
}

.debug-summary {
    margin: 0;
    color: var(--text-secondary);
    font-size: 0.9rem;
    flex: 1;
}

.debug-empty {
    margin: 0;
    padding: 1rem;
    text-align: center;
    background: var(--bg-secondary);
    border-radius: 12px;
    border: 1px dashed var(--glass-border);
    color: var(--text-secondary);
}

.deck-item {
    background: white;
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 1.2rem;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    transition: all 0.2s;
    cursor: pointer;
}

.deck-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    border-color: var(--accent-color);
}

.deck-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.deck-name {
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--text-primary);
}

.deck-stats {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.deck-progress {
    width: 100%;
    height: 6px;
    background: var(--bg-secondary);
    border-radius: 3px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: var(--accent-color);
    border-radius: 3px;
    transition: width 0.3s ease;
}

.deck-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
    align-items: center;
}

.deck-btn {
    padding: 0.5rem;
    border-radius: 8px;
    border: none;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-play {
    background: var(--accent-color);
    color: white;
    flex: 1;
}

.btn-play:hover {
    background: var(--accent-hover);
}

.btn-restart-icon {
    background: var(--bg-secondary);
    color: var(--text-primary);
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.btn-restart-icon:hover {
    background: var(--bg-hover);
    color: var(--accent-color);
}

.btn-delete {
    background: rgba(239, 83, 80, 0.1);
    color: var(--danger-color);
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.btn-delete:hover {
    background: rgba(239, 83, 80, 0.2);
}

.upload-area {
    border-top: 1px solid var(--glass-border);
    padding-top: 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.empty-state {
    text-align: center;
    color: var(--text-secondary);
    padding: 2rem;
    font-style: italic;
}

/* Editor Section */
#editor-section {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    width: 100%;
    margin-top: 1.5rem;
}

.btn-sm {
    padding: 0.6rem 1.2rem;
    font-size: 0.9rem;
    background: white;
    border: 1px solid var(--glass-border);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.02);
}

.btn-sm:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.05);
    border-color: var(--accent-color);
}

.editor-card-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    max-height: none;
    overflow-y: visible;
    padding: 0;
    margin: 0;
}

.editor-card-row {
    display: flex;
    /* Changed from Grid to Flex to support full-width wrapping panel safely */
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 0.75rem;
    background: white;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    border: 1px solid rgba(226, 232, 240, 0.9);
    cursor: grab;
    transition: transform 0.18s ease, box-shadow 0.2s ease;
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.04);
    position: relative;
    transform-origin: center;
}

.editor-inputs {
    flex: 1;
    /* Ensure inputs take up middle space */
    min-width: 0;
}

.editor-row-actions,
.drag-handle {
    flex-shrink: 0;
    /* Prevent buttons and handle from squishing */
}

.editor-card-row.drop-target::before {
    content: '';
    position: absolute;
    top: -0.5rem;
    left: 0;
    right: 0;
    height: 2px;
    background-color: var(--accent-color);
    pointer-events: none;
    z-index: 10;
}

.editor-card-row.drop-target.drop-target-after::before {
    top: auto;
    bottom: -0.5rem;
}

.editor-card-row.drop-target {
    box-shadow: 0 10px 28px rgba(37, 99, 235, 0.15);
}

.editor-card-row.dragging {
    cursor: grabbing;
    border: 2px dashed var(--accent-color);
}

.editor-card-row.drag-origin-placeholder {
    opacity: 0;
    pointer-events: none;
    margin: 0;
    padding: 0;
    border: none;
    height: 0;
    min-height: 0;
}

.drag-preview {
    position: fixed;
    pointer-events: none;
    background: white;
    border-radius: 8px;
    border: 1px solid rgba(226, 232, 240, 0.9);
    box-shadow: 0 18px 40px rgba(37, 99, 235, 0.25);
    transform-origin: top left;
    z-index: 9999;
}

@keyframes dropDilation {
    0% {
        transform: scale(0.92);
    }

    75% {
        transform: scale(1.03);
    }

    100% {
        transform: scale(1);
    }
}

.drop-dilate {
    animation: dropDilation 0.25s ease-out forwards;
}

.editor-footer {
    display: flex;
    justify-content: center;
    padding-top: 0.75rem;
}

.editor-inputs {
    width: 100%;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 0.65rem;
}

.editor-input {
    width: 100%;
    box-sizing: border-box;
    padding: 0.75rem;
    border: 1px solid rgba(203, 213, 225, 0.9);
    border-radius: 12px;
    font-family: inherit;
    font-size: 0.95rem;
    line-height: 1.5;
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.95);
    resize: none;
    min-height: 120px;
    overflow-y: hidden;
}

.editor-input:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(64, 120, 255, 0.15);
}

.editor-input-wrapper {
    position: relative;
    display: flex;
    flex-direction: column;
}

.editor-input-wrapper .editor-input {
    padding-right: 36px;
}

.pronunciation-btn {
    position: absolute;
    bottom: 8px;
    right: 8px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    opacity: 0.5;
    padding: 4px 6px;
    border-radius: 4px;
    font-size: 0.85em;
    transition: opacity 0.15s, background-color 0.15s, color 0.15s;
}

.pronunciation-btn:hover {
    opacity: 1;
    background: var(--bg-tertiary);
}

.editor-input-wrapper:hover .pronunciation-btn {
    opacity: 0.8;
}


.editor-row-actions {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    align-items: flex-end;
}

.editor-action-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.editor-action-btn:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
    transform: scale(1.1);
}

.editor-action-btn.delete:hover {
    background: rgba(239, 83, 80, 0.1);
    color: var(--danger-color);
}

.drag-handle {
    color: var(--text-secondary);
    cursor: grab;
    display: flex;
    align-items: center;
    align-self: center;
    transition: color 0.2s ease;
}

.editor-card-row.drop-target .drag-handle {
    color: var(--accent-color);
}

.editor-card-row.dragging .drag-handle {
    cursor: grabbing;
}

/* Legacy .settings-group (library template) remains unstyled here to avoid extra backgrounds */

/* Buttons */
.btn {
    padding: 0.8rem 2rem;
    border-radius: 12px;
    border: none;
    font-family: inherit;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-primary {
    background: var(--accent-color);
    color: white;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2);
}

.btn-primary:hover {
    background: var(--accent-hover);
    transform: translateY(-2px);
}

.btn-secondary {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--glass-border);
}

.btn-outline {
    background: transparent;
    border: 1px solid currentColor;
}

.btn-secondary:hover {
    background: var(--bg-hover);
}

.btn-success {
    background: var(--success-color);
    color: white;
    box-shadow: 0 4px 12px rgba(129, 199, 132, 0.3);
}

.btn-danger {
    background: var(--danger-color);
    color: white;
    box-shadow: 0 4px 12px rgba(239, 83, 80, 0.3);
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--text-primary);
}

/* Quiz Section */
#quiz-section {
    width: 100%;
    max-width: 960px;
    padding-inline: clamp(0.75rem, 3vw, 1.5rem);
    box-sizing: border-box;
    margin-inline: auto;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 2rem;
    overflow-x: hidden;
    min-height: 100vh;
}

.quiz-header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--text-secondary);
    font-weight: 600;
    padding: 0;
    position: relative;
    z-index: 1001;
}

.quiz-header #progress-text {
    display: none;
}

.quiz-header #exit-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
    position: relative;
}

/* Settings Menu */
.settings-menu {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 0.5rem;
    background: white;
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 1rem;
    width: 220px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

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

.menu-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.toggle-label {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    width: 100%;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-primary);
    margin-top: 0.2rem;
    gap: 0.75rem;
}

.toggle-label input {
    display: none;
}

.toggle-switch {
    width: 36px;
    height: 20px;
    background: var(--gray-300);
    border-radius: 20px;
    position: relative;
    transition: background 0.3s;
}

.toggle-switch::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    background: white;
    border-radius: 50%;
    transition: transform 0.3s;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.toggle-label input:checked+.toggle-switch {
    background: var(--accent-color);
}

.toggle-label input:checked+.toggle-switch::after {
    transform: translateX(16px);
}

.menu-divider {
    height: 1px;
    background: var(--glass-border);
    margin: 0.2rem 0;
}

.menu-btn {
    background: none;
    border: none;
    text-align: left;
    padding: 0.5rem;
    border-radius: 8px;
    cursor: pointer;
    color: var(--text-primary);
    font-size: 0.9rem;
    transition: background 0.2s;
}

.menu-btn:hover {
    background: var(--bg-secondary);
}

.menu-btn.danger {
    color: var(--danger-color);
}

.menu-btn.danger:hover {
    background: rgba(239, 83, 80, 0.12);
}

.study-stage {
    width: 100%;
    max-width: 960px;
    margin: 0 auto;
    padding: 0 0 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.75rem;
    min-height: 60vh;
    /* Expanded height to prevent scrollbar */
    justify-content: center;
    /* Center content vertically if possible, or start */
}

.flashcard-container {
    perspective: 1000px;
    width: 100%;
    min-height: 200px;
    /* Reduced base height */
    height: 100%;
    /* Fill available */
    flex: 1;
    /* Allow it to grow */
    display: flex;
    flex-direction: column;
}

.flashcard {
    position: relative;
    width: 100%;
    height: 100%;
    /* Fixed Height for stability */
    /* text-align: center;  <-- Removed center align */
    /* transform-style: preserve-3d; <-- Removed 3D style */

    /* Grid trick for dynamic height */
    display: grid;
    grid-template-areas: "stack";
}

.flashcard.flipped .card-front {
    display: none;
}

.flashcard.flipped .card-back {
    display: flex;
}

.card-face {
    /* Position relative to flow in grid */
    grid-area: stack;
    position: relative;
    margin: 0 auto;
    /* Center it */
    box-sizing: border-box;
    /* Include padding/border in width */
    backface-visibility: hidden;
    border-radius: 24px;

    /* Default visibility */
    display: flex;
    flex-direction: column;
}

.card-front,
.card-back {
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 3rem;
    /* 3rem all around */

    width: 100%;
    /* Ensure it fits parent */
    box-sizing: border-box;
    /* Prevent padding overflow */
    border-radius: 24px;
    /* Ensure specific faces have radius */

    /* Increase padding */
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.03);
}

.card-front {
    display: flex;
}

.card-back {
    display: none;
    /* Hidden by default */
}

.card-back {
    background: rgba(37, 99, 235, 0.05);
    border-color: rgba(37, 99, 235, 0.1);
}

.card-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.label {
    text-transform: uppercase;
    letter-spacing: 2px;
    font-size: 0.8rem;
    color: var(--text-secondary);

    /* Alignment with speaker icon & Font Fix */
    position: absolute;
    top: 20px;
    /* Aligns with speaker icon at top:12px + padding */
    left: 0;
    width: 100%;
    text-align: center;
    font-family: 'Inter', sans-serif !important;
    /* Always sans-serif */
}

.flashcard h3 {
    font-size: 1.4rem;
    line-height: 1.4;
    color: var(--text-primary);
}

/* Interaction Area */
.interaction-area {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 80px;
    gap: 1rem;
}

.controls {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    width: 100%;
    align-items: center;
}

.row-btns {
    display: flex;
    gap: 1rem;
    width: 100%;
    justify-content: center;
}

.controls button {
    width: 100%;
    max-width: 300px;
}

/* Input Mode */
#answer-input {
    flex: 1;
    padding: 0.8rem 1.2rem;
    border-radius: 12px;
    border: 1px solid var(--glass-border);
    background: white;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 1rem;
    outline: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.02);
}

#answer-input:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

#answer-input.correct {
    border-color: var(--success-color);
    background-color: rgba(129, 199, 132, 0.1);
    color: var(--success-color);
}

#answer-input.wrong {
    border-color: var(--danger-color);
    background-color: rgba(239, 83, 80, 0.1);
    color: var(--danger-color);
}

.input-container {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    width: 100%;
    max-width: 400px;
}

.input-wrapper {
    display: flex;
    gap: 0.5rem;
    width: 100%;
}

.input-feedback {
    font-size: 0.9rem;
    color: var(--success-color);
    font-weight: 600;
    padding-left: 0.5rem;
    animation: slideDown 0.2s ease-out;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }

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

/* Multiple Choice Mode */
.mc-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    width: 100%;
    margin-top: 0.5rem;
}

@media (max-width: 768px) {
    .mc-container {
        grid-template-columns: 1fr;
    }
}

.mc-btn {
    padding: 1rem;
    border-radius: 12px;
    border: 1px solid var(--glass-border);
    background: white;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    font-size: 1rem;
    text-align: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.02);
}

.mc-btn:hover {
    background: var(--bg-secondary);
    transform: translateY(-2px);
}

.mc-btn.correct {
    background: var(--success-color);
    border-color: var(--success-color);
    color: white;
}

.mc-btn.wrong {
    background: var(--danger-color);
    border-color: var(--danger-color);
    color: white;
    opacity: 0.8;
}

#quiz-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    position: relative;
    /* Context for absolute toasts */
}

/* Results Section */
#results-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
    width: 100%;
    max-width: 800px;
    margin-top: 0;
}

.score-circle {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    border: 4px solid var(--accent-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    font-weight: 700;
    background: rgba(37, 99, 235, 0.05);
    color: var(--text-primary);
}

.total {
    font-size: 1.2rem;
    color: var(--text-secondary);
    margin-left: 5px;
}

.mistakes-container {
    width: 100%;
    background: rgba(239, 83, 80, 0.05);
    border: 1px solid rgba(239, 83, 80, 0.2);
    border-radius: 16px;
    padding: 1.5rem;
}

.mistakes-container h3 {
    color: var(--danger-color);
    margin-bottom: 1rem;
}

.action-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 20px;
    justify-content: center;
}

.action-buttons .btn {
    flex: 1;
    min-width: 120px;
    max-width: 200px;
    white-space: nowrap;
}

.peek-container {
    margin-top: 1rem;
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.peek-list {
    list-style: none;
    padding: 0;
    margin: 0;
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding-bottom: 4rem;
    /* Prevent cut-off */

    /* Hide scrollbar */
    scrollbar-width: none;
    /* Firefox */
    -ms-overflow-style: none;
    /* IE/Edge */
}

.peek-list::-webkit-scrollbar {
    display: none;
    /* Chrome/Safari */
}

#mistakes-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

#mistakes-list li {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem;
    background: white;
    border-radius: 8px;
    border: 1px solid rgba(239, 83, 80, 0.1);
}

.mistake-count {
    color: var(--danger-color);
    font-weight: bold;
}

/* New Deck Button */
#newDeckBtn {
    background-color: var(--btn-dark);
    border: none;
    color: #fff;
    padding: 10px 12px;
    cursor: pointer;
    border-radius: 4px;
    margin-bottom: 10px;
    width: 100%;
    font-size: 1em;
    user-select: none;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

#newDeckBtn:hover {
    background-color: var(--text-primary);
}

/* Peek Drawer */
.peek-drawer {
    position: fixed;
    right: 0;
    top: 0;
    width: 300px;
    height: 100%;
    background: var(--bg-secondary);
    border-left: 1px solid var(--glass-border);
    box-shadow: -5px 0 25px rgba(0, 0, 0, 0.1);
    transform: translateX(100%);
    /* Move completely off-screen */
    transition: transform 0.3s ease;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
}

.peek-drawer.open {
    transform: translateX(0);
}

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

.peek-header button {
    font-size: 2rem;
    padding: 0.2rem 0.6rem;
}

.peek-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.peek-item {
    background: white;
    padding: 1rem;
    border-radius: 12px;
    border: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.peek-item .q {
    font-weight: 600;
    color: var(--text-primary);
}

.peek-item .a {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* Toast (Standalone) */
.toast {
    position: fixed;
    bottom: 10%;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    width: fit-content;
    max-width: 90%;

    z-index: 2000;
    pointer-events: auto;

    padding: 1rem 2rem;
    border-radius: 50px;
    background: rgba(30, 30, 30, 0.9);
    color: white;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(10px);
    font-size: 1.1rem;
    font-weight: 600;
    text-align: center;
    white-space: nowrap;

    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.toast.success {
    background: var(--success-color);
}

.toast.error {
    background: var(--danger-color);
}

.toast.warning {
    background: var(--warning-color);
    color: black;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

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

.hidden {
    display: none !important;
}

.no-animations *,
body.no-animations *,
.flashcards-wrapper.no-animations * {
    animation: none !important;
    transition: none !important;
}

.deck-editor,
#editor-section {
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
}

#library-section {
    width: 100%;
    max-width: 100%;
}

/* Quiz Progress Bar */
.progress-bar-container {
    display: none;
    flex: 1;
    height: 6px;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 3px;
    margin: 0 1rem;
    overflow: hidden;
    max-width: 200px;
}

.progress-bar-fill {
    height: 100%;
    background: var(--accent-color);
    width: 0%;
    transition: width 0.3s ease;
    border-radius: 3px;
}

@media (prefers-color-scheme: dark) {
    .progress-bar-container {
        background: rgba(255, 255, 255, 0.1);
    }
}

/* Audio Button - Positioned relative to card */
.audio-btn {
    position: absolute;
    top: 12px;
    left: 12px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: all 0.2s ease, opacity 0.3s ease;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.6;
}

.audio-btn:hover {
    background-color: var(--bg-hover);
    color: var(--accent-color);
    transform: scale(1.1);
    opacity: 1;
}

input[type="checkbox"] {
    accent-color: var(--accent-color);
    transform: scale(1.5);
    cursor: pointer;
}

.audio-btn.hidden {
    opacity: 0 !important;
    pointer-events: none;
}

/* Stop Scrolling Utility */
body.stop-scrolling {
    overflow: hidden;
}

/* Shake Animation for incorrect input */
@keyframes shake {

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

    25% {
        transform: translateX(-5px);
    }

    75% {
        transform: translateX(5px);
    }
}

.shake {
    animation: shake 0.4s ease-in-out;
}

/* Visual & Accessibility Updates */

/* Settings Menu - Compact Padding */
.settings-menu {
    padding: 8px !important;
    width: 240px !important;
    max-height: 80vh;
    overflow-y: auto;
    gap: 4px !important;
}

.menu-item {
    margin-bottom: 4px !important;
    padding: 4px 6px !important;
    min-height: 32px;
}

.menu-divider {
    margin: 4px 0 !important;
}

/* Flashcard Text - Not Bold */
.card-content,
.card-front,
.card-back,
.flashcard h3,
.flashcard p,
.flashcard div {
    font-weight: 400 !important;
}

/* Font Classes */
.font-sans {
    font-family: 'Inter', system-ui, -apple-system, sans-serif !important;
}

.font-serif {
    font-family: 'Playfair Display', Georgia, serif !important;
}

.font-dyslexic {
    font-family: 'Open-Dyslexic', sans-serif !important;
    line-height: 1.6 !important;
}

/* Font Selector Styling */
.font-selector-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

.font-select {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 0.9rem;
    outline: none;
    cursor: pointer;
}

/* Smart Distractors Panel */
.distractor-panel {
    grid-column: 1 / -1;
    /* Force full width on new row */
    width: 100%;
    box-sizing: border-box;
    background: var(--bg-secondary);
    border: 1px solid rgba(226, 232, 240, 1);
    border-radius: 8px;
    padding: 1rem;
    margin-top: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    /* animation: fadeIn 0.2s ease-out; Remove animation to rule out issues */
}

@media (prefers-color-scheme: dark) {
    .distractor-panel {
        background: rgba(255, 255, 255, 0.03);
        border-color: rgba(255, 255, 255, 0.1);
    }
}

.distractor-panel.hidden {
    display: none !important;
}

.distractor-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5rem;
}

.distractor-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.distractor-tag {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 2px 8px;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    font-size: 0.85rem;
    color: var(--text-primary);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

@media (prefers-color-scheme: dark) {
    .distractor-tag {
        background: rgba(255, 255, 255, 0.05);
        border-color: rgba(255, 255, 255, 0.1);
    }
}

.distractor-tag button {
    border: none;
    background: none;
    color: var(--danger-color);
    cursor: pointer;
    padding: 0;
    font-size: 1rem;
    line-height: 1;
    display: flex;
    align-items: center;
}

.distractor-tag button:hover {
    color: var(--danger-hover);
    /* darker red */
}

.distractor-input-row {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.distractor-input {
    flex: 1;
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.9rem;
}

.distractor-header button.distractor-tab {
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    padding: 0.25rem 0.5rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
}

.distractor-header button.distractor-tab:hover {
    color: var(--text-primary);
}

.distractor-header button.distractor-tab.active {
    color: var(--accent-color);
    border-bottom-color: var(--accent-color);
}

/* Generic Modal Styles (Confirmation, Choice, etc.) */
.modal {
    display: none;
    position: fixed;
    z-index: 2100;
    /* Higher than settings (500) and toasts (2000) */
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    align-items: center;
    justify-content: center;
    animation: modalFadeIn 0.15s ease;
}

/* Flex verify to center content if needed */
.modal[style*="display: block"] {
    display: flex !important;
}

.modal-content {
    background-color: var(--bg-primary);
    margin: auto;
    padding: 1.5rem;
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.5);
    max-width: 500px;
    width: 90%;
    animation: modalPopIn 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

@keyframes modalPopIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes modalFadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }

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

.modal h3 {
    margin: 0;
    font-size: 1.4rem;
    color: var(--text-primary);
}

.modal p {
    margin: 0;
    color: var(--text-secondary);
    line-height: 1.5;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 1rem;
}

/* Ensure buttons in modal match theme */
.modal .btn {
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    border: none;
    font-size: 0.95rem;
}

.modal .btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.modal .btn-secondary:hover {
    background: var(--bg-hover);
}

.modal .btn-primary {
    background: var(--accent-color);
    color: white;
}

.modal .btn-primary:hover {
    background: var(--accent-hover);
}

/* Flashcard Newline Support */
#card-front-text,
#card-back-text {
    white-space: pre-wrap;
}