* { box-sizing: border-box; font-family: -apple-system, BlinkMacSystemFont, "Microsoft JhengHei", sans-serif; }
html, body { height: 100%; margin: 0; padding: 0; background-color: #f0f2f5; -webkit-tap-highlight-color: transparent; overscroll-behavior-y: none; }

.login-body { display: flex; justify-content: center; align-items: center; min-height: 100vh; padding: env(safe-area-inset-top) 20px env(safe-area-inset-bottom) 20px; }
.container { background: white; padding: 30px; border-radius: 16px; box-shadow: 0 4px 24px rgba(0,0,0,0.06); width: 100%; max-width: 400px; text-align: center; }
h1 { color: #1a1a1a; margin-bottom: 20px; font-weight: 700; }
input[type="text"], input[type="password"] { width: 100%; padding: 14px; margin: 10px 0; border: 1px solid #e0e0e0; border-radius: 10px; font-size: 16px; transition: border 0.2s; }
input[type="text"]:focus, input[type="password"]:focus { border-color: #4CAF50; outline: none; }
button { width: 100%; padding: 14px; background-color: #4CAF50; color: white; border: none; border-radius: 10px; font-size: 16px; font-weight: bold; cursor: pointer; margin-top: 15px; transition: 0.2s; }
button:hover { background-color: #45a049; }
.checkbox-group { text-align: left; margin: 15px 0; font-size: 15px; color: #555; }
.switch-text { margin-top: 20px; font-size: 14px; color: #666; }
.switch-text a { color: #007BFF; text-decoration: none; font-weight: bold; }

/* 🚀 頂部導覽列：動態增加 padding-top，加強避開 iOS 動態島 */
.navbar { background-color: #ffffff; padding: max(20px, env(safe-area-inset-top)) 20px 15px 20px; display: flex; justify-content: space-between; align-items: center; box-shadow: 0 1px 8px rgba(0,0,0,0.05); position: sticky; top: 0; z-index: 100; }
.navbar h1 { margin: 0; color: #333; font-size: 22px; }
.logout-btn { background-color: #fdeaea; color: #d32f2f; padding: 8px 16px; border-radius: 20px; font-size: 14px; font-weight: bold; margin: 0; width: auto; }

.main-container { padding: 20px 15px 120px 15px; max-width: 1000px; margin: 0 auto; }
.page-header { margin-bottom: 15px; display: flex; justify-content: space-between; align-items: center; }
#current-view-title { margin: 0; font-size: 20px; color: #333; font-weight: 700; }

/* 🚀 新增：返回按鈕樣式 */
.back-btn { background-color: #f0f0f0; color: #333; padding: 8px 14px; border-radius: 20px; font-size: 14px; border: none; font-weight: bold; margin: 0; width: auto; box-shadow: 0 2px 5px rgba(0,0,0,0.05); }

.upload-section { background: white; padding: 20px; border-radius: 16px; box-shadow: 0 2px 12px rgba(0,0,0,0.04); margin-bottom: 25px; text-align: center; }
.upload-btn { background-color: #ebf5ff; color: #007BFF; padding: 14px 24px; border-radius: 12px; font-size: 16px; display: inline-block; width: auto; margin: 0; font-weight: bold; }
.upload-confirm-btn { background-color: #ff9800; color: white; padding: 14px 30px; border-radius: 12px; font-size: 16px; display: inline-block; width: auto; margin-top: 10px; }
.preview-container { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 15px; }
.preview-item { position: relative; }
.preview-img { width: 70px; height: 70px; object-fit: cover; border-radius: 10px; border: 1px solid #ddd; }
.preview-item p { margin: 4px 0 0 0; font-size: 11px; color: #666; max-width: 70px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.progress-container { margin-top: 20px; text-align: center; }
.progress-bar-bg { background-color: #e0e0e0; border-radius: 10px; height: 12px; width: 100%; overflow: hidden; margin-top: 5px; }
.progress-bar-fill { background-color: #4CAF50; height: 100%; width: 0%; transition: width 0.3s ease; }

.bottom-nav { position: fixed; bottom: 0; left: 0; width: 100%; background: #ffffff; display: flex; justify-content: space-around; padding: 10px 0; padding-bottom: calc(10px + env(safe-area-inset-bottom)); box-shadow: 0 -2px 15px rgba(0,0,0,0.06); z-index: 1000; }
.nav-item { display: flex; flex-direction: column; align-items: center; color: #888; font-size: 12px; cursor: pointer; flex: 1; transition: 0.2s; }
.nav-icon { font-size: 24px; margin-bottom: 4px; filter: grayscale(100%); opacity: 0.6; }
.nav-item.active { color: #4CAF50; font-weight: bold; }
.nav-item.active .nav-icon { filter: grayscale(0%); opacity: 1; transform: translateY(-2px); }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 15px; }
.empty-state { grid-column: 1/-1; text-align: center; color: #888; padding: 40px 0; font-size: 16px; }

.media-card { background: white; border-radius: 14px; overflow: hidden; box-shadow: 0 2px 10px rgba(0,0,0,0.05); display: flex; flex-direction: column; position: relative; transition: transform 0.2s; touch-action: pan-y; }
.media-preview { width: 100%; aspect-ratio: 1/1; position: relative; background: #f9f9f9; cursor: pointer; }
.media-preview img, .media-preview video { width: 100%; height: 100%; object-fit: cover; }
.play-btn { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); font-size: 40px; color: rgba(255,255,255,0.8); pointer-events: none; text-shadow: 0 0 10px rgba(0,0,0,0.5); }
.media-details { padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.uploader-name { margin: 0; font-size: 13px; color: #555; font-weight: 500; }
.media-controls { display: flex; justify-content: space-between; gap: 5px; }

.ctrl-btn { flex: 1; background: transparent; border: 1px solid #ddd; padding: 6px 0; border-radius: 6px; font-size: 12px; cursor: pointer; color: #555; font-weight: bold; margin: 0; }
.ctrl-span { flex: 1; text-align: center; font-size: 12px; font-weight: bold; padding: 6px 0; }
.ctrl-btn:hover { background: #f5f5f5; }

.album-card, .album-create-card { background: white; border-radius: 16px; padding: 25px 10px; text-align: center; box-shadow: 0 2px 10px rgba(0,0,0,0.05); cursor: pointer; transition: 0.2s; display: flex; flex-direction: column; justify-content: center; }
.album-create-card { border: 2px dashed #bbb; background: transparent; box-shadow: none; }
.album-create-card:active, .album-card:active { transform: scale(0.96); }
.album-icon { font-size: 48px; margin-bottom: 10px; }
.album-title { margin: 0; font-size: 16px; font-weight: bold; color: #333; margin-bottom: 5px; }

body.select-mode-active .media-card { touch-action: none; user-select: none; }
.media-card.selected { border: 3px solid #4CAF50; transform: scale(0.95); }
.check-icon { display: none; position: absolute; top: 10px; right: 10px; font-size: 24px; background: white; border-radius: 50%; width: 28px; height: 28px; line-height: 28px; text-align: center; box-shadow: 0 2px 5px rgba(0,0,0,0.2); z-index: 10; pointer-events: none; }
.media-card.selected .check-icon { display: block; color: #4CAF50; }

.batch-action-bar { display: none; position: fixed; bottom: calc(70px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); width: 95%; max-width: 500px; background: rgba(33,33,33,0.95); color: white; padding: 12px 15px; border-radius: 30px; align-items: center; justify-content: space-between; box-shadow: 0 4px 15px rgba(0,0,0,0.2); z-index: 1000; backdrop-filter: blur(5px); }
.batch-action-bar button { margin: 0; padding: 8px 12px; border-radius: 20px; font-size: 13px; width: auto; border: none; cursor: pointer; }
.btn-confirm { background: #4CAF50; color: white; }
.btn-cancel { background: #ccc; color: #333; }

/* 🚀 燈箱樣式升級：支援縮放、滑動與控制項 */
.lightbox { display: none; position: fixed; z-index: 10000; left: 0; top: 0; width: 100%; height: 100%; background-color: rgba(0,0,0,0.95); align-items: center; justify-content: center; flex-direction: column; overflow: hidden; padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom) 0; touch-action: none;}
.lightbox-zoom-container { display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; transform-origin: center center; }
.lightbox img, .lightbox video { max-width: 95vw; max-height: 85vh; border-radius: 12px; pointer-events: none; }
.close-lightbox { position: absolute; top: calc(20px + env(safe-area-inset-top)); right: 20px; color: white; font-size: 40px; cursor: pointer; z-index: 10001; text-shadow: 0 2px 5px rgba(0,0,0,0.5); }
.lightbox-nav { position: absolute; top: 50%; transform: translateY(-50%); color: rgba(255,255,255,0.7); font-size: 40px; cursor: pointer; padding: 20px; user-select: none; z-index: 10001; font-weight: bold; }
.lightbox-nav:hover { color: white; }
.lightbox-prev { left: 10px; }
.lightbox-next { right: 10px; }
.lightbox-counter { position: absolute; top: calc(30px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); color: white; font-size: 14px; font-weight: bold; background: rgba(0,0,0,0.5); padding: 5px 15px; border-radius: 20px; z-index: 10001; letter-spacing: 1px; }

.custom-modal-overlay { display: none; position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background: rgba(0, 0, 0, 0.6); z-index: 10005; align-items: center; justify-content: center; backdrop-filter: blur(3px); }
.custom-modal-box { background: white; padding: 25px; border-radius: 20px; width: 85%; max-width: 350px; text-align: center; box-shadow: 0 10px 40px rgba(0,0,0,0.2); animation: modalFadeIn 0.3s ease; }
@keyframes modalFadeIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }
.custom-modal-msg { font-size: 17px; margin-bottom: 20px; color: #333; font-weight: bold; white-space: pre-wrap; line-height: 1.4; }
.custom-modal-input { width: 100%; padding: 12px; margin-bottom: 20px; border: 1px solid #ddd; border-radius: 10px; font-size: 16px; }

.custom-modal-btns { display: flex; gap: 15px; margin-top: 15px; justify-content: center; }
.custom-modal-btn { flex: 0 1 45%; padding: 12px; border-radius: 12px; border: none; font-size: 16px; font-weight: bold; margin: 0; }

body.elder-mode { font-size: 120%; }
body.elder-mode .nav-item span { font-size: 16px; font-weight: bold; }
body.elder-mode .upload-btn, body.elder-mode .upload-confirm-btn { font-size: 20px; padding: 18px; }

@media screen and (max-width: 768px) {
    .gallery { grid-template-columns: repeat(auto-fill, minmax(45%, 1fr)); gap: 10px; }
    .upload-section { padding: 15px; margin-bottom: 15px; }
    .ctrl-btn { font-size: 11px; padding: 4px 0; }
    .media-details { padding: 8px; gap: 6px; }
    .custom-modal-box { padding: 20px; }
    .lightbox-nav { font-size: 30px; padding: 10px; }
}
@media screen and (min-width: 769px) {
    .bottom-nav { position: sticky; top: 65px; bottom: auto; background: transparent; box-shadow: none; justify-content: flex-start; gap: 20px; padding: 10px 20px; margin-bottom: 20px; border-bottom: 1px solid #e0e0e0; z-index: 99;}
    .nav-item { flex: none; flex-direction: row; gap: 10px; font-size: 16px; background: white; padding: 10px 20px; border-radius: 30px; box-shadow: 0 2px 5px rgba(0,0,0,0.05); }
    .nav-icon { margin-bottom: 0; font-size: 20px; }
    .main-container { padding-bottom: 20px; }
}