*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --green: #7a9eb5;
    --green-lt: #edf2f6;
    --blue: #5b7e96;
    --blue-lt: #e8eff4;
    --red: #b07a7a;
    --red-lt: #f5eded;
    --gray-50: #f5f7f9;
    --gray-100: #eaeff3;
    --gray-300: #c8d4dc;
    --gray-500: #8fa5b5;
    --gray-700: #5c7285;
    --gray-900: #2c3e4a;
    --radius: 8px;
    --shadow: 0 2px 12px rgba(91, 126, 150, .13);
}

body {
    font-family: 'Noto Sans TC', 'PingFang TC', 'Microsoft JhengHei', sans-serif;
    background: var(--gray-50);
    color: var(--gray-900);
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 24px 16px 48px;
}

/* 標題樣式 */
header {
    width: 100%;
    max-width: 640px;
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
    justify-content: center;
}

header h1 {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--gray-900);
    line-height: 1.3;
}

header p {
    font-size: .8rem;
    color: var(--gray-500);
    margin-top: 2px;
}

/* 題目樣式 */
.card {
    background: #fff;
    border-radius: 12px;
    box-shadow: var(--shadow);
    padding: 28px 24px;
    width: 100%;
    max-width: 640px;

    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

/* 身分驗證頁面 */
#loadingArea {
    text-align: center;
    padding: 48px 0;
    color: var(--gray-500);
    font-size: 1rem;
}

.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--gray-300);
    border-top-color: var(--green);
    border-radius: 50%;
    animation: spin .8s linear infinite;
    margin: 0 auto 14px;
}

@keyframes spin {
    to {
    transform: rotate(360deg);
    }
}

/* Google登入按鈕 */
#loginArea {
    display: none;
    text-align: center;
    padding: 32px 0 16px;
}

#loginArea .login-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 6px;
}

#loginArea .login-sub {
    font-size: .85rem;
    color: var(--gray-500);
    margin-bottom: 24px;
}

#g_id_signin {
    display: inline-block;
}

/* 外部登入頁面 */
#teacherAuthArea {
    display: none;
    border: 2px dashed var(--blue);
    border-radius: var(--radius);
    padding: 20px;
    margin-top: 16px;
    background: var(--blue-lt);
}

#teacherAuthArea h3 {
    color: var(--blue);
    font-size: 1rem;
    margin-bottom: 8px;
}

#teacherAuthArea p {
    font-size: .85rem;
    color: var(--gray-700);
    margin-bottom: 16px;
}

/* 表單頁面 */
#formArea {
    display: none;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-weight: 600;
    font-size: .9rem;
    color: var(--gray-700);
    margin-bottom: 6px;
}

.form-group .hint {
    font-size: .78rem;
    color: var(--gray-500);
    margin-bottom: 5px;
}

input[type="text"],
input[type="password"],
input[type="date"],
select,
textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1.5px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: .95rem;
    font-family: inherit;
    color: var(--gray-900);
    background: #fff;
    transition: border-color .2s;
    appearance: auto;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--green);
    box-shadow: 0 0 0 3px rgba(26, 127, 75, .15);
}

input[readonly],
input[disabled] {
    background: var(--gray-100);
    color: var(--gray-700);
    cursor: not-allowed;
    border-color: var(--gray-300);
}

textarea {
    height: 88px;
    resize: vertical;
}

/* 點名表 */
#studentList {
    border: 1.5px solid var(--gray-300);
    border-radius: var(--radius);
    max-height: 380px;
    overflow-y: auto;
    background: #fff;
}

.student-item {
    display: flex;
    align-items: center;
    padding: 11px 14px;
    border-bottom: 1px dashed var(--gray-300);
    font-size: .95rem;
    cursor: pointer;
    transition: background .2s, color .2s;
    background: var(--red-lt);
    color: var(--red);
}

.student-item:last-child {
    border-bottom: none;
}

.student-item.present {
    background: var(--green-lt);
    color: var(--green);
}

.student-item input[type="checkbox"] {
    width: 18px;
    height: 18px;
    margin-right: 12px;
    accent-color: var(--green);
    cursor: pointer;
    flex-shrink: 0;
}

.student-item label {
    cursor: pointer;
    flex: 1;
}

/* 點擊簽名 */
#sigOpenBtn {
    background: var(--gray-100);
    border: 1.5px solid var(--gray-300);
    color: var(--gray-700);
    border-radius: var(--radius);
    padding: 10px;
    font-size: .95rem;
    font-weight: 600;
    width: 100%;
    cursor: pointer;
    transition: background .2s;
}

#sigOpenBtn:hover {
    background: var(--gray-300);
}

#sigStatus {
    display: none;
    color: var(--green);
    font-weight: 600;
    font-size: .9rem;
    text-align: center;
    margin-top: 10px;
}

/* 簽名面板 */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .55);
    z-index: 999;
    justify-content: center;
    align-items: center;
    padding: 16px;
}

.modal-overlay.open {
    display: flex;
}

.modal-content {
    background: #fff;
    border-radius: 14px;
    padding: 24px 20px 20px;
    width: 100%;
    max-width: 520px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, .18);
}

.modal-content h3 {
    font-size: 1.05rem;
    text-align: center;
    margin-bottom: 14px;
    color: var(--gray-900);
}

#sigCanvas {
    width: 100%;
    height: 260px;
    border: 1.5px solid var(--gray-300);
    border-radius: var(--radius);
    background: #fff;
    cursor: crosshair;
    touch-action: none;
    display: block;
}

.btn-group {
    display: flex;
    gap: 10px;
    margin-top: 14px;
}

.btn-group button {
    flex: 1;
}

/* 按鈕 */
.btn {
    display: block;
    width: 100%;
    padding: 13px;
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: opacity .2s, transform .1s;
    font-family: inherit;
}

.btn:active {
    transform: scale(.98);
}

.btn:disabled {
    opacity: .55;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--blue);
    color: #fff;
}

.btn-green {
    background: var(--green);
    color: #fff;
}

.btn-red {
    background: var(--red);
    color: #fff;
}

.btn-gray {
    background: var(--gray-500);
    color: #fff;
}

.btn-submit {
    background: var(--blue);
    color: #fff;
    margin-top: 6px;
    font-size: 1.05rem;
}

/* 分隔線 */
.divider {
    border: none;
    border-top: 1px solid var(--gray-300);
    margin: 20px 0;
}

/* 開發人員 */
footer {
    margin-top: 24px;
    font-size: .78rem;
    color: var(--gray-500);
    text-align: center;
}

/* 記錄列表 */
.record-item {
    padding: 12px 14px;
    border-radius: var(--radius);
    border: 1.5px solid var(--gray-100);
    background: var(--gray-50);
    margin-bottom: 8px;
    font-size: .93rem;
    color: var(--gray-900);
    cursor: pointer;
    transition: background .15s, border-color .15s;
    display: flex;
    align-items: center;
    gap: 8px;
}

.record-item::before {
    content: '';
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    background-image: url('https://raw.githubusercontent.com/ckclubrollcall/-/main/images/%E5%96%AE%E7%AD%86%E7%B4%80%E9%8C%84.png?raw=true');
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
}

.record-item:hover {
    background: var(--blue-lt);
    border-color: var(--blue);
}

#recordDetailArea {
    font-size: .93rem;
}

/* 主選單滿版與彈性佈局（最終隱藏安全版） */
#menuArea {
    display: none; /* 預設徹底隱藏，避免閃爍 */
    flex: 1;       /* 顯示時自動撐滿 card 剩餘的高度 */
    width: 100%;
    flex-direction: column;
}

/* 主選單左右按鈕外層容器 */
.menu-btn-row {
    display: flex;
    flex-direction: column;
    gap: 16px; 
    flex: 1;       /* 讓外層容器自動吞下所有剩餘的彈性空間 */
    margin-top: 0; 
}

/* 開始點名按鈕（綠色系淡化虛線框） */
.btn-menu-green {
    background: rgba(128, 161, 144, 0.08); 
    color: #4e6659;                        
    border: 2px dashed #80a190;             
    box-shadow: none;
    flex: 1;                               /* 兩個按鈕平分高度 */
    padding: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border-radius: 12px;
    line-height: 1.4;
    cursor: pointer;
    font-family: inherit;
    transition: background-color 0.2s, transform 0.1s;
}

/* 查詢紀錄按鈕（藍色系淡化虛線框） */
.btn-menu-blue {
    background: rgba(123, 139, 172, 0.08); 
    color: #4b5873;                        
    border: 2px dashed #7b8bac;             
    box-shadow: none;
    flex: 1;                               /* 兩個按鈕平分高度 */
    padding: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border-radius: 12px;
    line-height: 1.4;
    cursor: pointer;
    font-family: inherit;
    transition: background-color 0.2s, transform 0.1s;
}

/* 滑鼠懸停與點擊效果 */
.btn-menu-green:hover { background: rgba(128, 161, 144, 0.15); }
.btn-menu-blue:hover { background: rgba(123, 139, 172, 0.15); }

.btn-menu-green:active, .btn-menu-blue:active {
    transform: scale(0.99); 
}

/* 當非幹部登入隱藏點名按鈕時，讓查詢紀錄單獨撐滿 100% 高度 */
.btn-menu-green[style*="none"] + .btn-menu-blue {
    height: 100%;
}

/* 按鈕標題字體 */
.menu-btn-title {
    font-size: 1.3rem;
    font-weight: 700;
    line-height: 1;
}

/* 按鈕備註字體 */
.menu-btn-desc {
    font-size: 0.85rem;
    color: var(--gray-700);
    font-weight: 400;
}

/* 點名詳細資訊卡 */
.detail-card {
    background: #fff;
    border-radius: var(--radius);
    border: 1.5px solid var(--gray-100);
    overflow: hidden;
    margin-bottom: 4px;
}

.detail-row {
    display: flex;
    padding: 10px 14px;
    border-bottom: 1px solid var(--gray-100);
    font-size: .92rem;
    gap: 10px;
    align-items: flex-start;
}

.detail-row:last-child { border-bottom: none; }

.detail-label {
    color: var(--gray-500);
    font-size: .82rem;
    font-weight: 600;
    min-width: 72px;
    padding-top: 1px;
    flex-shrink: 0;
}

.detail-row-absent {
    flex-direction: column;
    gap: 6px;
}

.absent-box {
    white-space: pre-wrap;
    background: #fff;
    border: 1.5px dashed var(--gray-300);
    border-radius: var(--radius);
    padding: 10px 12px;
    font-size: .9rem;
    color: var(--gray-700);
    line-height: 1.7;
}

.char-counter {
    font-size: .75rem;
    color: var(--gray-500);
    text-align: right;
    margin-top: 3px;
}

.char-counter.warn {
    color: var(--red);
    font-weight: 600;
}

/* 送出中遮罩層 */
.submit-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(44, 62, 74, .45);
    backdrop-filter: blur(1px);
    z-index: 950;
    justify-content: center;
    align-items: center;
    padding: 16px;
}

.submit-overlay.open {
    display: flex;
}

.submit-overlay-box {
    background: rgba(255, 255, 255, .96);
    border-radius: 14px;
    padding: 28px 32px;
    text-align: center;
    box-shadow: 0 8px 32px rgba(0, 0, 0, .25);
    max-width: 320px;
}

.submit-overlay-box .spinner {
    margin: 0 auto 14px;
}

.submit-overlay-box p {
    font-size: .95rem;
    font-weight: 600;
    color: var(--gray-900);
    line-height: 1.5;
}

/* 自訂對話框樣式 */
#customDialog .modal-content {
    max-width: 400px;
    text-align: center;
    border: 1px solid var(--gray-300);
    box-shadow: 0 10px 25px rgba(44, 62, 74, 0.15);
    animation: modalReveal 0.22s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes modalReveal {
    from {
        opacity: 0;
        transform: scale(0.93);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}