#loginOverlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    visibility: hidden; 
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.3s ease, visibility 0s 0.3s; 
}

#loginOverlay.active {
    visibility: visible;
    opacity: 1;
    transition: opacity 0.3s ease;
}

#loginModal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    width: 90%;
    max-width: 360px;
    background: #0a0a0f; /* Tech dark background */
    border: 1px solid rgba(59, 130, 246, 0.5);
    border-radius: 20px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.5), 0 0 30px rgba(59, 130, 246, 0.3);
    z-index: 1001;
    color: #e5e7eb;
    font-family: 'Noto Sans TC', sans-serif;
    visibility: hidden;
    opacity: 0;
    transition: all 0.3s ease, visibility 0s 0.3s;
}

#loginModal.active {
    visibility: visible;
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
    transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* Modal Shake Animation for Error */
@keyframes modal-shake {
    0%, 100% { transform: translate(-50%, -50%) translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translate(-50%, -50%) translateX(-8px); }
    20%, 40%, 60%, 80% { transform: translate(-50%, -50%) translateX(8px); }
}
#loginModal.shake {
    animation: modal-shake 0.5s ease-in-out;
}


.modal-header {
    padding: 16px 24px;
    border-bottom: 1px solid rgba(59, 130, 246, 0.3);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h4 {
    margin: 0;
    font-size: 1.2rem;
    font-weight: 600;
    color: #fff;
    text-shadow: 0 0 8px rgba(59, 130, 246, 0.7);
}

#closeModalBtn {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.7);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    transition: all 0.2s ease;
}
#closeModalBtn:hover {
    color: #fff;
    transform: rotate(90deg);
}

.modal-body {
    padding: 24px;
}

.modal-tabs {
    display: flex;
    margin-bottom: 20px;
}

.modal-tab {
    flex: 1;
    padding: 10px;
    text-align: center;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    cursor: pointer;
    color: #9ca3af;
    transition: all 0.2s ease;
}
.modal-tab:first-child { border-radius: 8px 0 0 8px; }
.modal-tab:last-child { border-radius: 0 8px 8px 0; border-left: none; }

.modal-tab.active {
    background: rgba(59, 130, 246, 0.2);
    border-color: rgba(59, 130, 246, 0.5);
    color: #fff;
    box-shadow: 0 0 10px rgba(59, 130, 246, 0.3);
}

.modal-tab-content { display: none; }
.modal-tab-content.active { display: block; }

/* 9-Grid Pattern (Visual Placeholder) */
#patternLock {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    max-width: 200px;
    margin: 20px auto;
}
#patternLock .pattern-dot {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(59, 130, 246, 0.5);
    box-shadow: inset 0 0 5px rgba(59, 130, 246, 0.3);
    cursor: not-allowed;
}

/* 4-Digit PIN Pad */
#pinPad {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}
#pinInput {
    width: 200px;
    padding: 12px;
    font-size: 1.5rem;
    text-align: center;
    letter-spacing: 0.5em;
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(59, 130, 246, 0.5);
    color: #fff;
    border-radius: 8px;
    box-shadow: inset 0 2px 10px rgba(0,0,0,0.4);
}
#pinInput::placeholder { color: rgba(255,255,255,0.4); }

#pinSubmitBtn {
    /* Use existing btn-primary styles */
    width: 200px;
    font-weight: 700;
    font-size: 1rem;
    letter-spacing: 1px;
}

#pinErrorMsg {
    color: #ef4444;
    font-size: 0.9rem;
    height: 1.2em;
    text-align: center;
}

/* --- Logged-In State Styles --- */
.login-notice.logged-in {
    background: linear-gradient(135deg, #f0fff4 0%, #e6fcf5 100%);
    color: white;
    border-color: #16a34a;
}
/* Style the button when logged in */
.login-notice.logged-in .login-btn {
    background: #22c55e;
    color: white;
    border-color: #16a34a;
    cursor: not-allowed;
    opacity: 0.8;
}

/* Make subject cards clickable when logged in */
.database-showcase.logged-in .subject-card {
    cursor: pointer;
    transition: all 0.3s ease;
}
.database-showcase.logged-in .subject-card:hover {
    transform: translateY(-5px) scale(1.03);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
}

/* --- Logged-In State Styles (登入成功狀態樣式) --- */

/* 綠色提示視窗 */
.login-notice.logged-in .notice-content {
    background: linear-gradient(135deg, #f0fff4 0%, #e6fcf5 100%); /* 綠色漸層背景 */
    border-color: #22c55e; /* 綠色邊框 */
    box-shadow: 0 8px 30px rgba(34, 197, 94, 0.15); /* 綠色陰影 */
}
.login-notice.logged-in .notice-content i {
    color: #22c55e; /* 圖示變為綠色 */
    text-shadow: 0 0 15px rgba(34, 197, 94, 0.5);
}
.login-notice.logged-in .notice-content h4 {
    color: #166534; /* 標題文字變為深綠色 */
}
.login-notice.logged-in .notice-content p {
    color: #15803d; /* 內文文字變為綠色 */
}

/* --- Pattern Lock Styles (九宮格圖形鎖樣式) --- */
#patternLockContainer {
    position: relative;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 24px; /* 調整點之間的間距 */
    max-width: 240px; /* 調整整體大小 */
    margin: 10px auto 0 auto;
    touch-action: none; /* 禁用觸控時的滾動 */
}

#patternLines {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    pointer-events: none; /* 讓滑鼠事件穿透到下方的點 */
}

/* 已經畫出的固定線條 */
#patternLines line {
    stroke-width: 4px;
    stroke-linecap: round;
    stroke: rgba(59, 130, 246, 0.7);
    transition: stroke 0.2s;
}

/* 成功/失敗時的線條顏色 */
#patternLockContainer.success #patternLines line { stroke: #22c55e; }
#patternLockContainer.error #patternLines line { stroke: #ef4444; }

/* 正在繪製到滑鼠位置的 "暫時" 線條 */
#tempLine {
    stroke-width: 4px;
    stroke-linecap: round;
    stroke: rgba(59, 130, 246, 0.7);
    stroke-dasharray: 4 4; /* 虛線 */
}

/* 九宮格的點 */
.pattern-dot {
    width: 44px; /* 點的大小 */
    height: 44px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid rgba(59, 130, 246, 0.3);
    box-shadow: inset 0 0 5px rgba(59, 130, 246, 0.2);
    cursor: pointer;
    transition: all 0.2s;
    position: relative; /* 用於居中 */
    display: grid;
    place-items: center;
}

/* 點的 "核心" */
.pattern-dot::before {
    content: '';
    width: 14px;
    height: 14px;
    background: rgba(59, 130, 246, 0.5);
    border-radius: 50%;
    transition: all 0.2s;
}

/* 點的狀態：啟用 (active) */
.pattern-dot.active {
    background: rgba(59, 130, 246, 0.2);
    border-color: #3b82f6;
}
.pattern-dot.active::before {
    background: #3b82f6;
    transform: scale(1.2);
    box-shadow: 0 0 10px #3b82f6;
}

/* 點的狀態：成功 (success) */
#patternLockContainer.success .pattern-dot.active {
    background: rgba(34, 197, 94, 0.2);
    border-color: #22c55e;
}
#patternLockContainer.success .pattern-dot.active::before {
    background: #22c55e;
    box-shadow: 0 0 10px #22c55e;
}

/* 點的狀態：失敗 (error) */
#patternLockContainer.error .pattern-dot.active {
    background: rgba(239, 68, 68, 0.2);
    border-color: #ef4444;
}
#patternLockContainer.error .pattern-dot.active::before {
    background: #ef4444;
    box-shadow: 0 0 10px #ef4444;
}