/* ============================================================
   WeekPics — Global Stylesheet
   ============================================================ */

/* ---- Reset & Base ---- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --color-primary: #4f46e5;
    --color-primary-hover: #4338ca;
    --color-primary-light: #eef2ff;
    --color-success: #16a34a;
    --color-success-bg: #f0fdf4;
    --color-error: #dc2626;
    --color-error-bg: #fef2f2;
    --color-warning: #f59e0b;
    --color-bg: #f8fafc;
    --color-surface: #ffffff;
    --color-text: #1e293b;
    --color-text-secondary: #64748b;
    --color-border: #e2e8f0;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 25px rgba(0,0,0,0.1);
    --transition: 0.2s ease;
}

html {
    font-size: 16px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial,
        "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.6;
    min-height: 100vh;
}

a {
    color: var(--color-primary);
    text-decoration: none;
}

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
}

.btn-primary {
    background: var(--color-primary);
    color: white;
}
.btn-primary:hover { background: var(--color-primary-hover); }
.btn-primary:disabled {
    background: #a5b4fc;
    cursor: not-allowed;
}

.btn-outline {
    background: transparent;
    color: var(--color-primary);
    border: 1.5px solid var(--color-border);
}
.btn-outline:hover {
    background: var(--color-primary-light);
    border-color: var(--color-primary);
}

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

/* ---- Header ---- */
.main-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-small {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--color-primary);
}

/* ============================================================
   Welcome (Auth) Page
   ============================================================ */
.welcome-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.welcome-container {
    width: 100%;
    max-width: 520px;
    padding: 24px;
}

.welcome-header {
    text-align: center;
    margin-bottom: 32px;
}

.brand {
    font-size: 2.8rem;
    font-weight: 800;
    color: white;
    letter-spacing: -1px;
    text-shadow: 0 2px 10px rgba(0,0,0,0.2);
}

.brand-subtitle {
    color: rgba(255,255,255,0.85);
    font-size: 1.05rem;
    margin-top: 4px;
}

.auth-card {
    background: var(--color-surface);
    border-radius: var(--radius);
    padding: 32px 28px;
    box-shadow: var(--shadow-lg);
}

.auth-card h2 {
    text-align: center;
    font-size: 1.3rem;
    margin-bottom: 8px;
}

.auth-desc {
    text-align: center;
    color: var(--color-text-secondary);
    font-size: 0.9rem;
    margin-bottom: 24px;
}

.quiz-loading {
    text-align: center;
    color: var(--color-text-secondary);
    padding: 24px 0;
}

/* Quiz questions */
.quiz-question {
    margin-bottom: 20px;
    padding: 16px;
    background: var(--color-bg);
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
}

.quiz-question .q-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}

.quiz-question .q-subject {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 4px;
    background: var(--color-primary-light);
    color: var(--color-primary);
}

.quiz-question .q-text {
    font-weight: 500;
    font-size: 0.95rem;
}

.quiz-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.quiz-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
    font-size: 0.9rem;
}

.quiz-option:hover {
    border-color: var(--color-primary);
    background: var(--color-primary-light);
}

.quiz-option.selected {
    border-color: var(--color-primary);
    background: var(--color-primary-light);
    font-weight: 500;
}

.quiz-option input[type="radio"] {
    accent-color: var(--color-primary);
    width: 16px;
    height: 16px;
}

.result-message {
    margin-top: 20px;
    padding: 14px;
    border-radius: var(--radius-sm);
    text-align: center;
    font-weight: 500;
}

.result-message.success {
    background: var(--color-success-bg);
    color: var(--color-success);
    border: 1px solid #bbf7d0;
}

.result-message.error {
    background: var(--color-error-bg);
    color: var(--color-error);
    border: 1px solid #fecaca;
}

.result-message .retry-hint {
    font-size: 0.85rem;
    margin-top: 6px;
    font-weight: 400;
}

.welcome-footer {
    text-align: center;
    margin-top: 20px;
    color: rgba(255,255,255,0.7);
    font-size: 0.85rem;
}

/* ============================================================
   Upload Section
   ============================================================ */
.upload-section {
    max-width: 800px;
    margin: 24px auto;
    padding: 0 16px;
}

.upload-area {
    border: 2px dashed var(--color-border);
    border-radius: var(--radius);
    padding: 40px 24px;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition);
    background: var(--color-surface);
}

.upload-area:hover,
.upload-area.drag-over {
    border-color: var(--color-primary);
    background: var(--color-primary-light);
}

.upload-icon {
    font-size: 2.5rem;
    margin-bottom: 12px;
}

.upload-hint {
    color: var(--color-text-secondary);
    font-size: 0.8rem;
    margin-top: 8px;
}

/* Progress bar */
.progress-container {
    margin-top: 16px;
    background: var(--color-surface);
    border-radius: var(--radius-sm);
    padding: 16px;
    box-shadow: var(--shadow);
}

.progress-bar {
    height: 8px;
    background: var(--color-border);
    border-radius: 4px;
    overflow: hidden;
}

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

.progress-text {
    text-align: center;
    margin-top: 8px;
    font-size: 0.85rem;
    color: var(--color-text-secondary);
}

/* Upload result */
.upload-result {
    margin-top: 16px;
    padding: 16px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
}

.upload-result.has-failures {
    background: var(--color-warning);
    color: #78350f;
}

.upload-result.all-success {
    background: var(--color-success-bg);
    color: var(--color-success);
    border: 1px solid #bbf7d0;
}

/* ============================================================
   Week Info
   ============================================================ */
.week-info {
    max-width: 1200px;
    margin: 24px auto 0;
    padding: 20px 24px;
    text-align: center;
}

.week-info h2 {
    font-size: 1.4rem;
    color: var(--color-text);
}

.week-info p {
    color: var(--color-text-secondary);
    margin-top: 4px;
}

/* ============================================================
   Gallery
   ============================================================ */
.gallery {
    max-width: 1200px;
    margin: 20px auto;
    padding: 0 16px 40px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 16px;
}

.gallery-empty {
    grid-column: 1 / -1;
    text-align: center;
    padding: 60px 20px;
    color: var(--color-text-secondary);
}

.gallery-empty p:first-child {
    font-size: 1.1rem;
    margin-bottom: 8px;
}

.gallery-item {
    position: relative;
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    background: var(--color-surface);
    box-shadow: var(--shadow);
    transition: transform var(--transition), box-shadow var(--transition);
    aspect-ratio: 1;
}

.gallery-item:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
}

.gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.gallery-item .item-info {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 8px 12px;
    background: linear-gradient(transparent, rgba(0,0,0,0.6));
    color: white;
    font-size: 0.78rem;
    opacity: 0;
    transition: opacity var(--transition);
}

.gallery-item:hover .item-info {
    opacity: 1;
}

/* ============================================================
   Modal
   ============================================================ */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.open {
    display: flex;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
}

.modal-content {
    position: relative;
    max-width: 90vw;
    max-height: 90vh;
    z-index: 1;
}

.modal-content img {
    max-width: 90vw;
    max-height: 85vh;
    object-fit: contain;
    border-radius: var(--radius-sm);
}

.modal-close {
    position: absolute;
    top: -40px;
    right: 0;
    background: none;
    border: none;
    color: white;
    font-size: 2rem;
    cursor: pointer;
    line-height: 1;
    padding: 4px 8px;
}

/* ============================================================
   History Page
   ============================================================ */
.history-main {
    max-width: 800px;
    margin: 0 auto;
    padding: 32px 16px;
}

.history-main h2 {
    text-align: center;
    margin-bottom: 4px;
}

.history-subtitle {
    text-align: center;
    color: var(--color-text-secondary);
    margin-bottom: 24px;
    font-size: 0.9rem;
}

.history-loading {
    text-align: center;
    color: var(--color-text-secondary);
    padding: 40px 0;
}

.history-empty {
    text-align: center;
    color: var(--color-text-secondary);
    padding: 40px 0;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.history-item-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 24px;
    background: var(--color-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    transition: all var(--transition);
    border: 1.5px solid transparent;
    gap: 16px;
    flex-wrap: wrap;
}

.history-item-row:hover {
    border-color: var(--color-primary);
    box-shadow: var(--shadow-lg);
}

.hi-left {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.hi-left .hi-week {
    font-weight: 600;
    font-size: 1.05rem;
}

.hi-stats {
    display: flex;
    align-items: center;
    gap: 14px;
    color: var(--color-text-secondary);
    font-size: 0.85rem;
}

.hi-links {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.82rem;
}

/* ============================================================
   Video Page
   ============================================================ */
.video-page {
    background: #000;
    color: #fff;
    overflow: hidden;
    height: 100vh;
    height: 100dvh;
}

.video-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    background: rgba(0, 0, 0, 0.85);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10;
    backdrop-filter: blur(8px);
}

.video-header .btn-outline {
    color: #fff;
    border-color: rgba(255, 255, 255, 0.3);
    font-size: 0.85rem;
    padding: 6px 14px;
}

.video-header .btn-outline:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.6);
}

.video-indicator {
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.7);
    font-variant-numeric: tabular-nums;
}

.video-weekbar {
    position: fixed;
    top: 52px;
    left: 0;
    right: 0;
    text-align: center;
    padding: 6px;
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.6);
    z-index: 9;
    background: linear-gradient(rgba(0,0,0,0.6), transparent);
}

/* Full-screen swipe container */
.video-container {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    transition: transform 0.35s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    will-change: transform;
}

.video-slide {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000;
}

.video-slide video {
    max-width: 100%;
    max-height: 100vh;
    max-height: 100dvh;
    width: auto;
    height: auto;
    object-fit: contain;
    display: block;
}

.video-empty {
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: rgba(255, 255, 255, 0.5);
    font-size: 1.1rem;
    gap: 12px;
}

.video-empty p:first-child {
    font-size: 3rem;
}

/* ============================================================
   Hidden utility
   ============================================================ */
.hidden {
    display: none !important;
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 640px) {
    .gallery {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
        gap: 10px;
    }
    .brand { font-size: 2.2rem; }
    .auth-card { padding: 24px 18px; }
    .upload-area { padding: 28px 16px; }
    .main-header { padding: 12px 16px; }
}
