/* Unit Review (Modern Design) */
.doc-container {
    position: fixed;
    inset: 0;
    background-color: var(--md-sys-color-surface);
    z-index: 2000;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.doc-header {
    padding: 16px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--md-sys-color-surface-container);
    z-index: 100;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.doc-header.header-hidden {
    transform: translateY(-100%);
}

.doc-page {
    flex: 1;
    padding: 24px;
    padding-top: 80px;
    /* Offset for absolute header */
    overflow-y: auto;
    scroll-behavior: smooth;
}

#docContent {
    max-width: 900px;
    margin: 0 auto;
    display: grid;
    gap: 24px;
    padding-bottom: 80px;
}

.doc-entry {
    background: #FFFFFF;
    border-radius: 24px;
    padding: 24px;
    border: 1px solid var(--md-sys-color-surface-container);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    position: relative;
}

.doc-entry:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.06);
}

.doc-entry img {
    max-width: 100%;
    width: auto;
    display: block;
    margin: 0 auto;
    max-height: 480px;
    object-fit: contain;
    border-radius: 16px;
    margin-bottom: 20px;
    background: var(--md-sys-color-surface-container);
}

.doc-img-container {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 16px;
    overflow: hidden;
    margin-bottom: 16px;
}

.doc-text h4 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--md-sys-color-on-surface);
    margin-bottom: 8px;
    font-family: 'Outfit', sans-serif;
}

.doc-stats-line {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    padding: 6px 12px;
    background: rgba(var(--md-sys-color-primary-rgb), 0.08);
    border: 1px solid rgba(var(--md-sys-color-primary-rgb), 0.12);
    border-radius: 100px;
    width: fit-content;
    font-size: 0.85rem;
    color: var(--md-sys-color-primary);
    font-weight: 500;
}

.doc-stats-item {
    display: flex;
    align-items: center;
    gap: 4px;
}

.doc-stats-item.starred {
    color: #EAB308;
    background: rgba(234, 179, 8, 0.1);
    padding: 2px 8px;
    border-radius: 100px;
    margin-left: -4px;
}

.doc-explanation summary::-webkit-details-marker {
    display: none;
}





@font-face {
    font-family: 'ChongxiSealSubset';
    src: url('../../public/assets/fonts/chongxi_seal.woff?v=2') format('woff');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Roboto', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

html,
body {
    width: 100%;
    height: 100%;
    overflow: hidden;

    /* Material 3 Light Mode Tokens */
    --md-sys-color-primary: #6D8A96;
    --md-sys-color-primary-rgb: 109, 138, 150;
    --md-sys-color-on-primary: #FFFFFF;
    --md-sys-color-primary-container: #E7EEF1;
    --md-sys-color-on-primary-container: #051F26;
    --md-sys-color-secondary: #5A7580;
    --md-sys-color-on-secondary: #FFFFFF;
    --md-sys-color-surface: #F8F9FA;
    --md-sys-color-on-surface: #1F1F1F;
    --md-sys-color-surface-container: #F1F4F5;
    --md-sys-color-outline: #70797C;
    --md-sys-color-outline-rgb: 112, 121, 124;
    --md-sys-color-error: #BA1A1A;

    /* Legacy Variable Mappings (Mapping new to old for compatibility) */
    --bg-primary: var(--md-sys-color-surface);
    --bg-secondary: #FFFFFF;
    --text-primary: var(--md-sys-color-on-surface);
    --text-secondary: #5F6368;
    --text-muted: #70757A;
    --heading-color: #202124;
    --border-primary: #DADCE0;
    --border-secondary: #BDC1C6;
    --accent-blue: var(--md-sys-color-primary);
    --accent-blue-hover: #5A7580;
    --accent-green: #35854b;
    --accent-orange: #FBBC04;
    --accent-red: #BA1A1A;
    --shadow-color: rgba(0, 0, 0, 0.1);
    --focus-ring: rgba(109, 138, 150, 0.25);
    --modal-bg: #FFFFFF;
    --card-answer-bg: rgba(248, 249, 250, 0.95);

    background-color: var(--bg-primary);
    color: var(--text-primary);
    transition: background-color 0.3s cubic-bezier(0.2, 0, 0, 1), color 0.3s cubic-bezier(0.2, 0, 0, 1);
}



.flashcard-title,
.start-title {
    font-family: "ChongxiSealSubset", "ChongxiSeal", serif;
    color: var(--md-sys-color-primary);
    font-weight: normal;
    letter-spacing: 6px;
    text-align: center;
    padding-bottom: 5px;
    transition: color 0.4s ease;
}

.start-title {
    font-size: 3.5rem;
    margin-bottom: 8px;
    position: relative;
    overflow: hidden;
    display: inline-block;
    line-height: 1.2;
    color: #202124;
}

.start-title::before {
    content: '';
    position: absolute;
    top: 0;
    left: -30%;
    width: 15%;
    height: 100%;
    background: linear-gradient(to right, transparent, rgba(255, 255, 255, 0.4), transparent);
    transform: skewX(-20deg);
    animation: shine 8s infinite;
    filter: blur(4px);
}



.start-subtitle {
    color: var(--text-secondary);
    font-family: 'Outfit', sans-serif;
    font-size: 0.9rem;
    font-weight: 600;
    letter-spacing: 0.25em;
    margin-bottom: 0;
    text-transform: uppercase;
    opacity: 0.8;
}

.hero-section {
    background: radial-gradient(circle at top, rgba(var(--md-sys-color-primary-rgb, 109, 138, 150), 0.05) 0%, transparent 70%);
    border-bottom: 1px solid rgba(var(--md-sys-color-outline-rgb, 112, 121, 124), 0.05);
}



.card {
    background: var(--bg-secondary);
    border-radius: 20px;
    border: 1px solid var(--border-primary);
    box-shadow: 0 1px 3px var(--shadow-color);
    transition: all 0.25s cubic-bezier(0.2, 0, 0, 1);
    cursor: pointer;
    position: relative;
    overflow: hidden;
    padding: 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 12px;
    opacity: 0;
    animation: fadeIn 0.6s ease forwards;
}

@media (hover: hover) {
    .card:hover {
        box-shadow: 0 12px 24px var(--shadow-color);
        border-color: var(--md-sys-color-primary);
        background-color: var(--md-sys-color-primary-container);
    }
}

.card h3 {
    color: var(--heading-color);
    font-family: 'Outfit', sans-serif;
    font-weight: 600;
    font-size: 1.25rem;
}

.card .icon-container {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--md-sys-color-primary-container) !important;
    color: var(--md-sys-color-primary) !important;
    margin-bottom: 4px;
}

.card.disabled {
    opacity: 0.5;
    pointer-events: none;
    cursor: not-allowed;
}

.card.disabled h3 {
    color: var(--text-muted);
}

.card.disabled .mt-auto>div {
    background-color: var(--border-secondary) !important;
    color: var(--text-muted) !important;
    text-align: center;
    font-weight: 600;
}

.tab-content {
    opacity: 1;
}

.fade-in {
    animation: fadeIn 0.6s ease-in-out forwards;
    opacity: 0;
}

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

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

.flashcard-title {
    font-size: 1.8rem;
    margin-bottom: 15px;
}

.start-screen {
    width: 100%;
    height: calc(100% - 64px);
    display: flex;
    flex-direction: column;
    padding: 20px;
    opacity: 0;
    animation: fadeIn 0.8s ease-out forwards;
    position: relative;
    overflow-y: auto;
}

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

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

@keyframes pulse {
    0% {
        box-shadow: 0 0 10px var(--accent-blue);
    }

    50% {
        box-shadow: 0 0 20px var(--accent-blue-hover);
    }

    100% {
        box-shadow: 0 0 10px var(--accent-blue);
    }
}

@keyframes shine {
    0% {
        left: -50%;
    }

    100% {
        left: 150%;
    }
}

.start-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
    align-items: flex-start;
    margin-bottom: 20px;
    position: relative;
}

.start-button {
    padding: 12px 28px;
    font-size: 1rem;
    font-family: 'Outfit', sans-serif;
    font-weight: 600;
    background-color: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
    border: none;
    border-radius: 100px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.2, 0, 0, 1);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

@media (hover: hover) {
    .start-button:hover {
        box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
        filter: brightness(1.08);
    }
}

.start-button:active {
    box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
    opacity: 0.8;
}

#modalStartQuizBtn:not(:disabled) {
    background-color: var(--accent-blue);
    box-shadow: 0 2px 8px rgba(121, 168, 143, 0.25);
}

@media (hover: hover) {
    #modalStartQuizBtn:not(:disabled):hover {
        background-color: var(--accent-blue-hover);
        box-shadow: 0 8px 20px rgba(121, 168, 143, 0.35);
    }
}

#modalStartQuizBtn:not(:disabled):active {
    box-shadow: 0 2px 4px rgba(121, 168, 143, 0.2);
    opacity: 0.8;
}

#modalOpenDocBtn:not(:disabled) {
    border-width: 1.5px !important;
}

@media (hover: hover) {
    #modalOpenDocBtn:not(:disabled):hover {
        background-color: rgba(109, 138, 150, 0.12) !important;
        color: var(--accent-blue) !important;
        box-shadow: 0 6px 16px rgba(109, 138, 150, 0.15);
        border-color: var(--accent-blue) !important;
    }
}

#modalOpenDocBtn:not(:disabled):active {
    box-shadow: 0 2px 4px rgba(109, 138, 150, 0.1);
    opacity: 0.8;
}

/* Resume button: border-only style */
#resumeButton {
    background: transparent;
    color: var(--text-primary);
    border: 1px solid var(--border-primary);
    box-shadow: none;
    animation: none;
}

@media (hover: hover) {
    #resumeButton:hover {
        background: var(--bg-secondary);
    }
}



/* Resume progress bar */
.resume-progress {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-top: 8px;
}

.resume-progress-bar {
    width: 220px;
    height: 8px;
    background: var(--border-secondary);
    border-radius: 999px;
    overflow: hidden;
}

.resume-progress-fill {
    height: 100%;
    width: 0;
    background: var(--accent-blue);
    transition: width 0.3s ease;
}

.resume-progress-text {
    font-size: 0.9rem;
    color: var(--text-primary);
}

#signInBtn {
    background-color: #ffffff !important;
    color: #000000 !important;
    border: 1px solid #d3d3d3 !important;
    box-shadow: none !important;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 8px 16px;
    font-size: 14px;
    border-radius: 20px;
    z-index: 10;
    transition: transform 0.2s ease;
}

@media (hover: hover) {
    #signInBtn:hover {
        transform: scale(1.05);
    }
}

/* Dark mode styles for sign in button */


@media (hover: hover) {}

#greeting {
    background-color: transparent;
    color: #333333;
    font-size: 14px;
    border-radius: 20px;
    z-index: 10;
}

/* Dark mode styles for greeting */


.edit-nickname-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    margin-left: 6px;
    border: 1px solid var(--border-secondary);
    background: var(--bg-secondary);
    color: var(--text-primary);
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    line-height: 1;
}

@media (hover: hover) {
    .edit-nickname-btn:hover {
        background: var(--bg-primary);
    }
}

/* 暱稱編輯樣式 */
#nicknameInput {
    padding: 15px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 16px;
    background-color: #ffffff;
    color: #333333;
    transition: border-color 0.3s, box-shadow 0.3s;
    width: 100%;
    box-sizing: border-box;
}

#nicknameInput:focus {
    outline: none;
    border-color: var(--accent-green);
    box-shadow: 0 0 0 2px rgba(121, 168, 143, 0.25);
}

#nicknameInput::placeholder {
    color: #999;
}

#saveNicknameBtn {
    padding: 12px 24px;
    background-color: var(--accent-green);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.3s, transform 0.2s, box-shadow 0.3s;
    min-width: 80px;
}

@media (hover: hover) {
    #saveNicknameBtn:hover {
        background-color: #6B9B7F;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    }
}

#saveNicknameBtn:active {
    transform: translateY(0);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

#saveNicknameBtn:disabled {
    background-color: #ccc;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* 暗色模式下的暱稱編輯樣式 */








/* 登入模態框樣式 */
.login-modal {
    display: none;
    position: fixed;
    z-index: 10000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.4);
    justify-content: center;
    align-items: center;
}

.login-modal-content {
    background-color: #ffffff;
    margin: 20px;
    padding: 30px;
    border: none;
    border-radius: 15px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    position: relative;
}

.login-modal h2 {
    text-align: center;
    margin-bottom: 30px;
    color: #333333;
    font-size: 24px;
    font-weight: 600;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.login-form input {
    padding: 15px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 16px;
    background-color: #ffffff;
    color: #333333;
    transition: border-color 0.3s;
}

.login-form input:focus {
    outline: none;
    border-color: var(--accent-green);
    box-shadow: 0 0 0 2px rgba(121, 168, 143, 0.25);
}

.login-form button {
    padding: 15px;
    background-color: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 4px var(--shadow-color);
}

@media (hover: hover) {
    .login-form button:hover {
        filter: brightness(1.05);
        box-shadow: 0 6px 12px var(--shadow-color);
    }
}

.login-form button:disabled {
    background-color: #ccc;
    cursor: not-allowed;
}

/* 登入方式分隔線 */
.or-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text-secondary, #777);
    font-size: 14px;
}

.or-divider::before,
.or-divider::after {
    content: "";
    flex: 1 1 auto;
    height: 1px;
    background: var(--border-color, #e0e0e0);
}

.login-toggle {
    text-align: center;
    margin-top: 20px;
    color: #666666;
}

.login-toggle a {
    color: var(--accent-green);
    text-decoration: none;
    cursor: pointer;
}

@media (hover: hover) {
    .login-toggle a:hover {
        text-decoration: underline;
    }
}

.forgot-password-link {
    color: #e74c3c !important;
    margin-left: 15px;
}

@media (hover: hover) {
    .forgot-password-link:hover {
        color: #c0392b !important;
        text-decoration: underline;
    }
}

.close-modal {
    position: absolute;
    right: 15px;
    top: 15px;
    font-size: 28px;
    font-weight: bold;
    color: #999999;
    cursor: pointer;
}

@media (hover: hover) {
    .close-modal:hover {
        color: #333333;
    }
}

/* Dark mode styles for login modal */
body.dark-mode .login-modal-content {
    background-color: var(--modal-bg);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
}

body.dark-mode .login-modal h2 {
    color: var(--text-primary);
}

body.dark-mode .login-form input {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--border-primary);
}

body.dark-mode .login-form input:focus {
    border-color: var(--accent-green);
    box-shadow: 0 0 0 2px rgba(135, 199, 168, 0.25);
}

body.dark-mode .login-form input::placeholder {
    color: var(--text-muted);
}

body.dark-mode .login-form button:disabled {
    background-color: var(--border-primary);
    color: var(--text-muted);
}

body.dark-mode .login-toggle {
    color: var(--text-secondary);
}

body.dark-mode .close-modal {
    color: var(--text-secondary);
}

@media (hover: hover) {
    body.dark-mode .close-modal:hover {
        color: var(--text-primary);
    }
}

.dropdown-menu {
    position: relative;
    display: inline-block;
}

.dropdown-toggle {
    position: relative;
    padding-right: 45px;
}

.dropdown-toggle::after {
    content: '▲';
    font-size: 0.7em;
    position: absolute;
    right: 18px;
    top: 50%;
    transform: translateY(-50%);
    transition: transform 0.3s ease;
}

.dropdown-menu.active .dropdown-toggle::after {
    transform: translateY(-50%) rotate(180deg);
}

@media (hover: hover) and (pointer: fine) {
    .dropdown-menu:hover .dropdown-toggle::after {
        transform: translateY(-50%) rotate(180deg);
    }
}

.dropdown-content {
    display: none;
    position: absolute;
    background-color: var(--bg-secondary);
    min-width: 240px;
    max-height: 520px;
    box-shadow: 0 10px 25px var(--shadow-color);
    z-index: 10;
    border-radius: 8px;
    padding: 8px;
    bottom: -100%;
    left: 50%;
    margin-bottom: 8px;
    transform-origin: bottom center;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: #00000030 var(--bg-secondary);
}

.dropdown-content::-webkit-scrollbar {
    width: 8px;
}

.dropdown-content::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

.dropdown-content::-webkit-scrollbar-thumb {
    background-color: var(--accent-blue);
    border-radius: 4px;
    border: 2px solid var(--bg-secondary);
}

@media (hover: hover) {
    .dropdown-content::-webkit-scrollbar-thumb:hover {
        background-color: var(--accent-blue-hover);
    }
}


.dropdown-menu.active .dropdown-content {
    display: block;
    opacity: 0;
    animation: elegantDropdownAppear 0.4s cubic-bezier(0.23, 1, 0.32, 1) forwards;
}

@media (hover: hover) and (pointer: fine) {
    .dropdown-menu:hover .dropdown-content {
        display: block;
        opacity: 0;
        animation: elegantDropdownAppear 0.4s cubic-bezier(0.23, 1, 0.32, 1) forwards;
    }
}

@keyframes elegantDropdownAppear {
    0% {
        opacity: 0;
        transform: translateX(-50%) translateY(-10px) scaleY(0.85);
    }

    100% {
        opacity: 1;
        transform: translateX(-50%) translateY(0) scaleY(1);
    }
}

.dropdown-item {
    width: 100%;
    padding: 10px 15px;
    text-decoration: none;
    display: block;
    background-color: transparent;
    border: none;
    color: var(--text-primary);
    text-align: left;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: 6px;
    transition: background-color 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.dropdown-item:not(:last-child) {
    margin-bottom: 4px;
}

@media (hover: hover) {
    .dropdown-item:hover {
        background-color: var(--accent-blue-hover);
        color: var(--bg-secondary);
        transform: none;
    }
}

.modal-errata-number {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 4px;
    margin-bottom: 0;
    font-weight: 400;
    opacity: 0.6;
    transition: color 0.4s ease, opacity 0.4s ease;
}

.doc-text .errata-number {
    font-size: 0.75rem;
    color: var(--md-sys-color-outline);
    background: var(--md-sys-color-surface-container);
    padding: 4px 10px;
    border-radius: 8px;
    opacity: 0.9;
    font-family: 'Outfit', sans-serif;
    font-weight: 600;
    margin-top: 16px;
    display: inline-block;
    border: 1px solid rgba(var(--md-sys-color-outline-rgb), 0.1);
}


.footer {
    position: absolute;
    bottom: 15px;
    width: 100%;
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-muted);
    transition: color 0.4s ease;
}

.footer a {
    color: var(--text-secondary);
    text-decoration: none;
    transition: color 0.3s ease;
}

@media (hover: hover) {
    .footer a:hover {
        color: var(--accent-blue-hover);
        text-decoration: none;
    }
}

/* Material Design App Bar (Sticky Top Bar) */
.md-app-bar {
    position: sticky;
    top: 0;
    width: 100%;
    height: 64px;
    background-color: rgba(var(--md-sys-color-surface-rgb, 248, 249, 250), 0.85);

    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    transition: all 0.3s ease;
}

body.dark-mode .md-app-bar {
    --md-sys-color-surface-rgb: 28, 28, 28;
    background-color: rgba(var(--md-sys-color-surface-rgb), 0.85);
}

.app-bar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    font-family: "ChongxiSealSubset", "ChongxiSeal", serif;
    color: #44545b;
    text-decoration: none;
    letter-spacing: 2px;
}

.app-bar-brand span {
    font-family: "ChongxiSealSubset", "ChongxiSeal", serif;
    font-weight: normal;
    font-size: 25px;
}

.app-bar-logo {
    height: 32px;
    width: auto;
}

.app-bar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Account System */
.account-container {
    position: relative;
    display: flex;
    align-items: center;
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background-color: var(--md-sys-color-primary);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.1rem;
    cursor: pointer;
    transition: transform 0.2s cubic-bezier(0.2, 0, 0, 1), box-shadow 0.2s ease;
    user-select: none;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.user-avatar:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.profile-menu {
    position: absolute;
    top: calc(100% + 12px);
    right: 0;
    width: 240px;
    background-color: var(--md-sys-color-surface);
    border-radius: 20px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    border: 1px solid var(--border-primary);
    display: none;
    flex-direction: column;
    overflow: hidden;
    z-index: 1001;
    padding: 8px;
    transform-origin: top right;
    animation: menuIn 0.2s cubic-bezier(0.2, 0, 0, 1) forwards;
}

@keyframes menuIn {
    from {
        transform: scale(0.95);
        opacity: 0;
    }

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

.profile-menu.active {
    display: flex;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: var(--text-primary);
    cursor: pointer;
    transition: background-color 0.2s ease;
    border-radius: 12px;
    font-size: 0.95rem;
    font-weight: 500;
}

.menu-item:hover {
    background-color: var(--md-sys-color-surface-container);
}

.menu-item i {
    width: 18px;
    height: 18px;
    opacity: 0.8;
}

.menu-divider {
    height: 1px;
    background-color: var(--border-primary);
    margin: 8px 0;
}

.user-info-section {
    padding: 12px 16px 8px;
    margin-bottom: 4px;
}

.user-display-name {
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-primary);
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-email {
    font-size: 0.8rem;
    color: var(--text-secondary);
    display: block;
}

.day-night-toggle {
    position: relative;
    top: 0;
    left: 0;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--border-primary);
    background-color: var(--md-sys-color-surface-container);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    box-shadow: none;
    transition: all 0.2s cubic-bezier(0.2, 0, 0, 1);
    color: var(--accent-blue);
}

.day-night-toggle:hover {
    transform: scale(1.05);
}

.star-top {
    position: relative;
    top: 0;
    left: 0;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid var(--border-primary);
    background-color: var(--md-sys-color-surface-container);
    color: #F59E0B;
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 10;
    box-shadow: none;
    transition: all 0.2s cubic-bezier(0.2, 0, 0, 1);
}

@media (hover: hover) {
    .star-top:hover {
        transform: scale(1.05);
    }
}

body.dark-mode .star-top {
    background-color: var(--bg-primary);
    color: #FBBF24;
    /* brighter yellow for dark mode */
    border: 1px solid var(--border-secondary);
}

.toggle-icon {
    width: 30px;
    height: 30px;
    overflow: visible;
    transition: transform 0.8s cubic-bezier(0.4, 0, 0.2, 1);
}

.toggle-icon .icon-shape {
    fill: var(--toggle-icon-color);
    transition: fill 0.4s ease;
}

.toggle-icon .sun-ray {
    stroke: var(--toggle-icon-color);
    stroke-width: 4;
    stroke-linecap: round;
    transition: stroke 0.4s ease, opacity 0.5s ease;
}

.toggle-icon .moon-mask {
    fill: var(--toggle-moon-mask);
    transition: fill 0.4s ease;
}

.toggle-icon.rotate {
    transform: rotate(180deg);
}

.toggle-icon .sun-rays {
    opacity: 1;
    transition: opacity 0.5s 0.1s ease;
}

.toggle-icon .moon-group {
    opacity: 1;
    transition: opacity 0.5s 0.1s ease;
}

.toggle-icon.night .sun-rays {
    opacity: 0;
}

.toggle-icon.day .moon-group {
    opacity: 0;
}

.flashcard-container {
    width: 100%;
    height: 100%;
    display: none;
    flex-direction: column;
    background-color: var(--bg-primary);
    padding: 16px;
    position: relative;
    margin: 0 auto;
    opacity: 0;
    animation: fadeIn 0.6s 0.2s ease-out forwards;
    transition: background-color 0.4s ease;
}

.progress {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
    gap: 16px;
    padding: 0;
    background-color: transparent;
    width: 100%;
}

.progress-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 4px 12px;
    background-color: var(--md-sys-color-surface-container);
    border-radius: 8px;
    border: 1px solid var(--border-primary);
    font-family: 'Outfit', sans-serif;
    font-weight: 600;
    transition: all 0.3s cubic-bezier(0.2, 0, 0, 1);
    min-width: 60px;
}

.progress-item:hover {
    background-color: var(--bg-secondary);
}

.progress-item span:first-child,
#wrong,
#correct {
    font-size: 1rem;
    line-height: 1;
}

#wrong {
    color: var(--accent-red);
}

#correct {
    color: var(--accent-green);
}

.progress-item span:last-child {
    font-size: 0.6rem;
    opacity: 0.6;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-secondary);
    line-height: 1;
}

.card-content {
    position: relative;
    flex-grow: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    margin-bottom: 10px;
    border-radius: 24px;
    background-color: var(--md-sys-color-surface-container);
    box-shadow: 0 2px 8px var(--shadow-color);
    border: 1px solid var(--border-primary);
    transition: all 0.3s cubic-bezier(0.2, 0, 0, 1);
}

.loading-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(var(--bg-secondary-rgb, 255, 255, 255), 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2;
    border-radius: 10px;
    transition: background-color 0.4s ease, opacity 0.3s ease-out;
}

body.dark-mode .loading-screen {
    --bg-secondary-rgb: 42, 42, 42;
}

.spinner {
    border: 4px solid var(--border-primary);
    border-top: 4px solid var(--accent-blue);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1.2s cubic-bezier(0.5, 0, 0.5, 1) infinite;
    transition: border-color 0.4s ease;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

.card-content img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    transition: opacity 0.5s ease-in-out;
    opacity: 0;
    border-radius: 10px;
}

.card-content img.loaded {
    opacity: 1;
}

.star-toggle {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 2;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 999px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 20px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s ease, background-color 0.2s ease, color 0.2s ease;
}

@media (hover: hover) {
    .star-toggle:hover {
        transform: scale(1.05);
        background-color: rgba(0, 0, 0, 0.08);
    }
}

.star-toggle.active {
    color: #F59E0B;
    background: transparent;
}

.your-answer-label {
    font-size: 0.75rem;
    font-family: 'Outfit', sans-serif;
    font-weight: 600;
    color: var(--md-sys-color-primary);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    padding-left: 4px;
}

.answer-input-container {
    margin-bottom: 10px;
}

.answer-input {
    width: 100%;
    padding: 12px 16px;
    font-size: 1.1rem;
    text-align: center;
    border: 1px solid var(--border-primary);
    background-color: var(--md-sys-color-surface-container-low);
    color: var(--text-primary);
    outline: none;
    transition: all 0.2s cubic-bezier(0.2, 0, 0, 1);
    border-radius: 24px;
}

.answer-input::placeholder {
    color: var(--text-muted);
    opacity: 0.7;
}

.answer-input:focus {
    border-color: var(--border-primary);
    box-shadow: 0 0 0 2px var(--md-sys-color-primary-container);
}

.bottom-buttons {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    transition: visibility 0s linear 0.3s, opacity 0.3s ease;
}

.dont-know-button,
.answer-button {
    padding: 10px 24px;
    font-size: 1rem;
    font-family: 'Outfit', sans-serif;
    font-weight: 600;
    border: none;
    border-radius: 100px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.2, 0, 0, 1);
}

.dont-know-button {
    background-color: transparent;
    color: var(--md-sys-color-primary);
    border: 1px solid var(--md-sys-color-outline);
}

@media (hover: hover) {
    .dont-know-button:hover {
        background-color: var(--md-sys-color-primary-container);
        border-color: var(--md-sys-color-primary);
    }
}

.answer-button {
    background-color: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.comment-toggle-btn {
    padding: 10px 20px;
    font-size: 0.9rem;
    font-family: 'Outfit', sans-serif;
    font-weight: 600;
    background-color: rgba(var(--md-sys-color-primary-rgb), 0.08);
    color: var(--md-sys-color-primary);
    border: none;
    border-radius: 100px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.2, 0, 0, 1);
    display: flex;
    align-items: center;
    gap: 6px;
}

@media (hover: hover) {
    .comment-toggle-btn:hover {
        color: var(--md-sys-color-on-primary-container);
        background-color: rgba(var(--md-sys-color-primary-rgb), 0.15);
    }
}

/* Comment Drawer */
.comment-drawer {
    position: absolute;
    bottom: 25px;
    left: 25px;
    right: 25px;
    height: auto;
    max-height: 80%;
    background-color: var(--card-answer-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-radius: 28px;
    border: 1px solid var(--border-primary);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
    z-index: 100;
    transform: translateY(calc(100% + 25px));
    transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.comment-drawer.active {
    transform: translateY(0);
}

.comment-header {
    padding: 16px 24px;
    border-bottom: 1px solid var(--md-sys-color-surface-container);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.comment-list {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.comment-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.comment-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
}

.comment-author {
    font-weight: 700;
    color: var(--md-sys-color-on-surface);
}

.comment-time {
    color: var(--text-muted);
}

.comment-text {
    background: var(--md-sys-color-surface-container);
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 0.95rem;
    line-height: 1.5;
    color: var(--md-sys-color-on-surface);
    width: fit-content;
    max-width: 90%;
}

.comment-input-area {
    padding: 16px 20px;
    border-top: 1px solid rgba(var(--md-sys-color-outline-rgb), 0.1);
    display: flex;
    gap: 12px;
    background: transparent;
}

.comment-input {
    flex: 1;
    padding: 12px 20px;
    border: 1px solid var(--md-sys-color-outline);
    border-radius: 100px;
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.2s;
}

.comment-input:focus {
    border-color: var(--md-sys-color-primary);
}

.comment-send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--md-sys-color-primary);
    color: white;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s;
}

.comment-send-btn:active {
    transform: scale(0.9);
}


body.dark-mode .comment-drawer,
body.dark-mode .comment-input-area {
    background-color: rgba(30, 32, 34, 0.85);
}

body.dark-mode .comment-text {
    background: #2d2f31;
    color: #e2e2e6;
}

@media (hover: hover) {
    .answer-button:hover {
        box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
        filter: brightness(1.05);
    }
}

/* Resume Progress Stylings */
.restart-progress-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    font-size: 0.85rem;
    font-family: 'Outfit', sans-serif;
    font-weight: 500;
    color: var(--text-secondary);
    background-color: transparent;
    border: 1px solid var(--border-primary);
    border-radius: 100px;
    cursor: pointer;
    transition: all 0.2s ease;
    margin: 0 auto;
}

.restart-progress-btn:hover {
    background-color: var(--md-sys-color-surface-container-high);
    color: var(--md-sys-color-error);
    border-color: var(--md-sys-color-error);
}

.restart-progress-btn i {
    width: 14px;
    height: 14px;
}

.dont-know-button:active,
.answer-button:active {
    transform: scale(0.98);
    box-shadow: 0 1px 3px var(--shadow-color);
}

/* Footer Styles */
.site-footer {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.85rem;
    letter-spacing: 0.02em;
    width: 100%;
    flex-shrink: 0;
}

.site-footer p {
    margin: 0;
    opacity: 0.6;
}

.card-answer {
    display: none;
    position: absolute;
    bottom: 16px;
    left: 16px;
    right: 16px;
    background-color: var(--card-answer-bg);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    padding: 16px;
    border-radius: 24px;
    border: none;
    font-size: 1rem;
    z-index: 3;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 12px;
    box-shadow: 0 5px 20px var(--shadow-color);
    opacity: 0;
    transform: translateY(10px);
    animation: fadeSlideIn 0.4s ease-out forwards;
    color: var(--text-primary);
    text-align: center;
    transition: background-color 0.4s ease, color 0.4s ease, box-shadow 0.4s ease;
}

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

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

#showAnswer {
    font-weight: 600;
}

.error-number {
    position: absolute;
    bottom: 8px;
    left: 11px;
    font-size: 0.5rem;
    color: var(--text-muted);
    opacity: 0.2;
    pointer-events: none;
    font-weight: 400;
    transition: color 0.4s ease, opacity 0.4s ease;
}

#showExplanation {
    color: var(--text-secondary);
    line-height: 1.5;
    margin-top: 5px;
    overflow-y: auto;
    overflow: visible;
    transition: color 0.4s ease;
}

#showExplanation strong {
    font-weight: 600;
    color: var(--text-primary);
    transition: color 0.4s ease;
}

#showExplanation .contribute-link {
    color: var(--accent-blue);
    cursor: pointer;
    text-decoration: underline;
    font-weight: 500;
    margin-left: 5px;
    transition: color 0.3s ease;
}

@media (hover: hover) {
    #showExplanation .contribute-link:hover {
        color: var(--accent-blue-hover);
    }
}

.contribution-area {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border-primary);
    display: flex;
    transition: border-color 0.4s ease;
}

.contribution-area input {
    flex: 1;
    padding: 8px 12px;
    font-size: 1rem;
    border: 1px solid var(--border-secondary);
    border-radius: 6px;
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    outline: none;
    resize: vertical;
    margin-right: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05) inset;
    transition: background-color 0.4s ease, color 0.4s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

.contribution-area input:focus {
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px var(--focus-ring), 0 1px 3px rgba(0, 0, 0, 0.05) inset;
}

.contribution-area button {
    padding: 8px 18px;
    font-size: 1rem;
    font-weight: 500;
    background-color: var(--accent-blue);
    color: var(--bg-secondary);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.3s ease, color 0.3s ease, transform 0.2s ease;
    float: right;
}

@media (hover: hover) {
    .contribution-area button:hover {
        background-color: var(--accent-blue-hover);
    }
}

.contribution-area button:active {
    transform: scale(0.97);
}

.contribution-area button.loading {
    position: relative;
    color: transparent !important;
    pointer-events: none;
}

.contribution-area button.loading::after {
    content: '';
    display: block;
    position: absolute;
    top: 50%;
    left: 50%;
    width: 16px;
    height: 16px;
    margin-top: -8px;
    margin-left: -8px;
    border: 2px solid rgba(var(--bg-secondary-rgb, 255, 255, 255), 0.4);
    border-top-color: var(--bg-secondary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    transition: border-color 0.4s ease;
}

body.dark-mode .contribution-area button.loading::after {
    --bg-secondary-rgb: 42, 42, 42;
    border-top-color: var(--bg-secondary);
}

.next-button {
    display: block;
    padding: 10px 22px;
    font-size: 1rem;
    font-weight: 500;
    background-color: transparent;
    color: var(--accent-blue);
    border: 1px solid var(--accent-blue);
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.3s ease;
    align-self: center;
}

@media (hover: hover) {
    .next-button:hover {
        background-color: var(--accent-blue);
        color: var(--bg-secondary);
        border-color: var(--accent-blue);
        box-shadow: 0 4px 12px rgba(var(--accent-blue-rgb, 109, 138, 150), 0.2);
    }

    body.dark-mode .next-button:hover {
        --accent-blue-rgb: 122, 160, 178;
    }
}

.next-button:active {
    opacity: 0.8;
    box-shadow: none;
}

.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    justify-content: center;
    align-items: center;
    opacity: 0;
    animation: fadeInModal 0.4s ease forwards;
    transition: background-color 0.4s ease;
}

@keyframes fadeInModal {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.modal-content {
    width: 90%;
    max-width: 560px;
    max-height: 85vh;
    overflow-y: auto;
    background-color: var(--md-sys-color-surface);
    padding: 32px;
    border-radius: 28px;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.15);
    position: relative;
    transform: scale(0.95);
    animation: m3DialogIn 0.3s cubic-bezier(0.2, 0, 0, 1) forwards;
    border: 1px solid var(--border-primary);
}

@keyframes m3DialogIn {
    from {
        transform: scale(0.9) translateY(20px);
        opacity: 0;
    }

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

.nav-button {
    all: unset;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    cursor: pointer;
    pointer-events: auto;
    color: var(--text-primary);
    font-size: 2rem;
    line-height: 1;
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    opacity: 0.6;
    transition: opacity 0.3s ease, transform 0.3s ease, color 0.3s ease;
}

.nav-left {
    left: -80px;
}

.nav-right {
    right: -80px;
}

@keyframes scaleUpModal {
    from {
        transform: scale(0.95);
        opacity: 0;
    }

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

.close {
    position: absolute;
    top: 13px;
    right: 20px;
    font-size: 2rem;
    font-weight: 300;
    color: var(--text-secondary);
    cursor: pointer;
    line-height: 1;
    transition: color 0.3s ease, transform 0.3s ease;
}

@media (hover: hover) {
    .close:hover {
        color: var(--accent-blue-hover);
    }
}

.modal-content h2 {
    font-size: 1.5rem;
    margin-bottom: 20px;
    color: var(--heading-color);
    font-weight: 600;
    border-bottom: 1px solid var(--border-primary);
    padding-bottom: 10px;
    transition: color 0.4s ease, border-color 0.4s ease;
}

.modal-content p {
    font-size: 1rem;
    line-height: 1.7;
    margin-bottom: 15px;
    color: var(--text-primary);
    transition: color 0.4s ease;
}

.modal-content li {
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border-primary);
    list-style-type: decimal;
    transition: border-color 0.4s ease;
}

.modal-content li:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.modal-content li p {
    margin-bottom: 8px;
}

.modal-content li p strong {
    color: var(--text-primary);
}

.modal-content li em {
    color: var(--text-secondary);
}

.modal-content img {
    height: auto;
    margin-bottom: 12px;
    border-radius: 6px;
    border: 1px solid var(--border-primary);
    display: block;
    box-shadow: 0 2px 5px var(--shadow-color);
    background-color: var(--bg-secondary);
    transition: border-color 0.4s ease, box-shadow 0.4s ease, background-color 0.4s ease;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

.answer-input-container[style*="hidden"],
.bottom-buttons[style*="hidden"],
.your-answer-label[style*="hidden"] {
    opacity: 0;
    visibility: hidden;
    transition: visibility 0s linear 0.3s, opacity 0.3s ease;
}

.player-input {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    width: 100%;
    max-width: 400px;
    margin: 0 auto;
    margin-bottom: 24px;
}

.player-input input {
    width: 100%;
    padding: 10px 16px;
    font-size: 1rem;
    border: 1px solid var(--border-secondary);
    border-radius: 8px;
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    transition: border-color .3s ease, box-shadow .3s ease;
}

.player-input input:focus {
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px var(--focus-ring);
    outline: none;
}

.leaderboard {
    width: 100%;
    background-color: var(--md-sys-color-surface-container);
    border: 1px solid var(--border-primary);
    border-radius: 20px;
    padding: 0;
    max-height: 520px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 4px 12px var(--shadow-color);
    transition: max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@media (max-width: 1023px) {
    .leaderboard {
        max-height: 64px;
        /* Only header height */
        border-radius: 16px;
    }

    .leaderboard.is-expanded {
        max-height: 500px;
    }
}

.leaderboard-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-primary);
    background-color: var(--md-sys-color-surface-container);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    user-select: none;
}

.leaderboard h3 {
    margin: 0;
    font-size: 1.1rem;
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
    color: var(--md-sys-color-primary);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.leaderboard-toggle-icon {
    display: none;
    transition: transform 0.3s ease;
    color: var(--md-sys-color-primary);
}

@media (max-width: 1023px) {
    .leaderboard-toggle-icon {
        display: block;
    }
}

.leaderboard.is-expanded .leaderboard-toggle-icon {
    transform: rotate(180deg);
}

.leaderboard ol {
    margin: 0;
    list-style: none;
    overflow-y: auto;
    flex-grow: 1;
    scrollbar-width: thin;
}

.leaderboard li {
    display: flex;
    align-items: center;
    padding: 12px 24px;
    transition: background-color 0.2s ease;
    font-family: 'Roboto', sans-serif;
    border-bottom: 1px solid rgba(var(--md-sys-color-outline-rgb, 112, 121, 124), 0.1);
}

.leaderboard li:last-child {
    border-bottom: none;
}

@media (hover: hover) {
    .leaderboard li:hover {
        background-color: var(--md-sys-color-primary-container);
        opacity: 0.9;
    }
}

.leaderboard-rank {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-primary);
    border-radius: 50%;
    font-weight: 700;
    font-size: 0.85rem;
    margin-right: 16px;
    flex-shrink: 0;
}

.leaderboard-name {
    flex: 1;
    font-weight: 500;
    color: var(--text-primary);
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.leaderboard-score {
    font-weight: 700;
    color: var(--md-sys-color-secondary);
    font-size: 1rem;
    margin-left: 12px;
}



.leaderboard li.current-user .leaderboard-rank {
    background-color: var(--md-sys-color-primary);
    color: #fff;
}

.alert-modal {
    display: none;
    background-color: var(--modal-bg);
    color: var(--text-primary);
    padding: 20px;
    border-radius: 8px;
    max-width: 90%;
    width: 400px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    position: absolute;
    top: 20px;
    left: 50%;
    translate: -50%;
    padding-right: 40px;
    z-index: 300000;
}

.nav-button {
    background-color: transparent;
    width: auto;
    height: auto;
    color: var(--text-primary);
    font-size: 2rem;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    cursor: pointer;
    pointer-events: auto;
    transition: opacity 0.3s ease, transform 0.3s ease;
    z-index: 3010;
    border: none;
    outline: none;
    opacity: 0.6;
    appearance: none;
    padding: 0;
}

.nav-left {
    left: -80px;
}

.nav-right {
    right: -80px;
}

.nav-button::before {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 0;
    height: 0;
    background: var(--accent-blue);
    border-radius: 50%;
    opacity: 0;
    transition: width 0.3s ease, height 0.3s ease, opacity 0.3s ease, filter 0.3s ease;
    pointer-events: none;
}

@media (hover: hover) {
    .nav-button:hover {
        color: var(--accent-blue);
    }

    .nav-button:hover::before {
        width: 80px;
        height: 80px;
        opacity: 0.4;
        filter: blur(10px);
    }
}


@media screen and (max-width: 768px) {
    .start-title {
        font-size: 2.2rem;
        letter-spacing: 4px;
    }

    .progress {
        gap: 0;
    }

    .dropdown-menu.active .dropdown-content {
        display: block;
        opacity: 1;
        visibility: visible;
        transform: translateX(-50%) translateY(0) scaleY(1);
        animation: elegantDropdownAppear 0.4s cubic-bezier(0.23, 1, 0.32, 1) forwards;
    }


    .progress-number-green {
        margin-left: 0;
    }

    .progress-number-orange {
        margin-right: 0;
    }
}

/* 手機模式下取消所有 hover 效果，以防止「粘性」hover，但保留 .active 等選中狀態 */
@media (hover: none) {
    * {
        -webkit-tap-highlight-color: transparent;
    }

    /* 取消 Tailwind 的 hover 效果 (針對 transform) */
    [class*="hover:"]:hover,
    .group:hover [class*="group-hover:"] {
        transform: none !important;
        transition: none !important;
    }

    /* 針對單元選擇按鈕 (unit selection buttons) 的 hover 進行取消，但保留選中狀態 */
    /* 只有在沒有選中樣式類別時才重製邊框 */
    .hover\:border-\[var\(--accent-blue\)\]:hover:not(.border-\[var\(--accent-blue\)\]) {
        border-color: var(--border-primary) !important;
    }

    /* 針對主畫面題庫卡片的 group-hover 特別取消顏色變化，回到初始變數 */
    .group:hover .group-hover\:bg-\[var\(--accent-blue\)\],
    .group:hover .group-hover\:bg-white {
        background-color: var(--bg-primary) !important;
    }

    .group:hover .group-hover\:border-\[var\(--accent-blue\)\],
    .group:hover .group-hover\:border-white {
        border-color: var(--border-secondary) !important;
    }

    .group:hover .group-hover\:text-white,
    .group:hover .group-hover\:text-\[var\(--accent-blue\)\],
    .group:hover .group-hover\:text-gray-500 {
        color: var(--text-secondary) !important;
    }

    .group:hover .group-hover\:opacity-100 {
        opacity: 0 !important;
    }

    /* 讓按鈕在點擊時有明顯的反饋 */
    .tab-btn:active,
    .card:active,
    .start-button:active,
    .answer-button:active,
    #unitModalList button:active {
        opacity: 0.7;
    }
}

/* Rank Update Animations */
@keyframes rankTickUp {
    0% {
        transform: translateY(0);
        opacity: 1;
    }

    50% {
        transform: translateY(20px);
        opacity: 0;
    }

    51% {
        transform: translateY(-20px);
        opacity: 0;
    }

    100% {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes rankTickDown {
    0% {
        transform: translateY(0);
        opacity: 1;
    }

    50% {
        transform: translateY(-20px);
        opacity: 0;
    }

    51% {
        transform: translateY(20px);
        opacity: 0;
    }

    100% {
        transform: translateY(0);
        opacity: 1;
    }
}

.rank-up-text {
    color: #35854b !important;
    animation: rankTickUp 0.6s cubic-bezier(0.2, 0, 0, 1) forwards;
}

.rank-down-text {
    color: #BA1A1A !important;
    animation: rankTickDown 0.6s cubic-bezier(0.2, 0, 0, 1) forwards;
}

#rank-display {
    display: inline-block;
    transition: color 0.4s ease;
}