:root {
    --primary: #94A3B8; /* Modern slate/blueish grey focus */
    --primary-light: #CBD5E1;
    --accent: #3A86FF; /* Vibrant Blue for brand / highlights */
    --accent-hover: #2563EB;
    --bg-dark: #0B0F19; /* Very dark blueish tint */
    --bg-panel: rgba(15, 23, 42, 0.6); /* Glass effect */
    --text-main: #F8FAFC;
    --text-muted: #94A3B8;
    
    --success: #10B981;
    --success-bg: rgba(16, 185, 129, 0.15);
    --error: #EF4444;
    --error-bg: rgba(239, 68, 68, 0.15);
    --warning: #F59E0B;

    --border: rgba(255, 255, 255, 0.1);
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    --transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    height: 100dvh; /* accounts for mobile UI elements */
    overflow: hidden; /* Prevent page bouncing */
    overscroll-behavior: none; /* Disable pull to refresh */
}

body {
    font-family: 'Inter', 'Noto Sans TC', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

/* Dynamic Background Shapes */
.bg-shape {
    position: fixed;
    border-radius: 50%;
    filter: blur(80px);
    z-index: -1;
    animation: float 20s infinite ease-in-out alternate;
}

.shape-1 {
    width: 400px;
    height: 400px;
    background: rgba(58, 134, 255, 0.15);
    top: -100px;
    left: -100px;
}

.shape-2 {
    width: 300px;
    height: 300px;
    background: rgba(16, 185, 129, 0.1);
    bottom: -50px;
    right: -50px;
    animation-delay: -5s;
}

.shape-3 {
    width: 250px;
    height: 250px;
    background: rgba(239, 68, 68, 0.1);
    bottom: 20%;
    left: 20%;
    animation-delay: -10s;
}

@keyframes float {
    0% { transform: translate(0, 0) rotate(0deg); }
    100% { transform: translate(50px, 30px) rotate(10deg); }
}

/* Glass Panel Utility */
.glass-panel {
    background: var(--bg-panel);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border);
    border-radius: 24px;
    box-shadow: var(--glass-shadow);
}

/* App Container */
.app-container {
    width: 100%;
    max-width: 600px;
    height: 100%;
    max-height: 850px;
    padding: 40px;
    position: relative;
    display: flex;
    flex-direction: column;
    overflow-y: auto; /* Internal scrolling for content */
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

/* Views Management */
.view {
    display: none;
    flex-direction: column;
    flex-grow: 1;
    height: 100%;
    animation: fadeIn 0.4s ease-out forwards;
}

.view.active {
    display: flex;
}

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

/* --- Start View --- */
#start-view {
    text-align: center;
    align-items: center;
    justify-content: center;
    flex-grow: 1;
}

.hero-icon {
    font-size: 64px;
    color: var(--accent);
    margin-bottom: 24px;
    animation: bounce 3s infinite ease-in-out;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

h1 {
    font-size: 28px;
    font-weight: 700;
    line-height: 1.4;
    margin-bottom: 12px;
}

h1 .highlight {
    background: linear-gradient(135deg, #3A86FF, #00C2FF);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    color: var(--text-muted);
    font-size: 16px;
    margin-bottom: 40px;
}

.features {
    display: flex;
    gap: 20px;
    margin-bottom: 40px;
    width: 100%;
    justify-content: center;
}

.feature-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    color: var(--primary-light);
    font-size: 14px;
}

.feature-item i {
    font-size: 24px;
    color: var(--accent);
    background: rgba(58, 134, 255, 0.1);
    padding: 12px;
    border-radius: 12px;
}

/* Auth Section */
.auth-section {
    margin-bottom: 30px;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

.password-input {
    width: 100%;
    max-width: 300px;
    padding: 14px 20px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
    font-size: 16px;
    outline: none;
    transition: var(--transition);
    text-align: center;
    letter-spacing: 2px;
    font-family: inherit;
}

.password-input:focus {
    border-color: var(--accent);
    background: rgba(255, 255, 255, 0.1);
    box-shadow: 0 0 0 4px rgba(58, 134, 255, 0.15);
}

.error-msg {
    color: var(--error);
    font-size: 14px;
    margin-top: 8px;
    font-weight: 500;
}

/* Buttons */
.primary-btn {
    background: var(--accent);
    color: white;
    border: none;
    padding: 16px 32px;
    font-size: 18px;
    font-weight: 600;
    border-radius: 16px;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    width: 100%;
    max-width: 300px;
}

.primary-btn:hover {
    background: var(--accent-hover);
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(58, 134, 255, 0.3);
}

.primary-btn:active {
    transform: translateY(0);
}

.primary-btn:disabled {
    cursor: not-allowed;
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.3);
    box-shadow: none;
    transform: none;
}

.secondary-btn {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-main);
    border: none;
    padding: 12px 24px;
    font-size: 16px;
    font-weight: 600;
    border-radius: 16px;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.secondary-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: translateY(-2px);
}

.finish-btn {
    background: var(--success);
}
.finish-btn:hover {
    background: #059669; /* darker success */
    box-shadow: 0 10px 20px rgba(16, 185, 129, 0.3);
}

.pulse-anim {
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(58, 134, 255, 0.4); }
    70% { box-shadow: 0 0 0 15px rgba(58, 134, 255, 0); }
    100% { box-shadow: 0 0 0 0 rgba(58, 134, 255, 0); }
}

/* --- Quiz View --- */
.quiz-header {
    margin-bottom: 30px;
}

.progress-container {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 12px;
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), #00C2FF);
    border-radius: 3px;
    width: 0%;
    transition: width 0.4s ease;
}

.quiz-meta {
    display: flex;
    justify-content: flex-end;
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 500;
}

.question-container {
    margin-bottom: 24px;
    display: flex;
    flex-direction: column;
    flex-grow: 1; /* Takes up remaining available space to push options down */
    justify-content: flex-start; /* Keeps text and image aligned to top */
}

.question-text {
    font-size: 18px;
    line-height: 1.6;
    font-weight: 500;
    margin-bottom: 16px;
    flex-shrink: 0;
}

.question-image {
    width: 100%;
    max-height: 250px;
    object-fit: contain;
    border-radius: 12px;
    margin-bottom: 16px;
    border: 1px solid var(--border);
    background-color: rgba(255, 255, 255, 0.05); /* Added subtle background for transparent images */
    flex-shrink: 0;
}

.options-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
    flex-shrink: 0; /* Prevents options from shrinking */
    margin-bottom: 24px;
}

.option-btn {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    color: var(--text-main);
    padding: 16px 20px;
    border-radius: 12px;
    font-size: 16px;
    text-align: left;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    line-height: 1.4;
}

.option-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.2);
    transform: translateX(4px);
}

.option-btn.selected {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.option-btn.correct {
    background: var(--success-bg);
    border-color: var(--success);
    color: var(--success);
}

.option-btn.wrong {
    background: var(--error-bg);
    border-color: var(--error);
    color: var(--error);
}

.option-btn:disabled {
    cursor: not-allowed;
    opacity: 0.8;
}

.quiz-footer {
    margin-top: auto; /* Push footer to the absolute bottom of .view */
    padding-top: 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.05); /* Adds a nice separator above buttons */
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 52px; /* Prevent layout shift */
    flex-shrink: 0; /* Keeps footer strictly anchored */
}

.quiz-footer .right-actions {
    display: flex;
    gap: 12px;
    margin-left: auto;
}

.quiz-footer .primary-btn {
    width: auto;
    padding: 12px 24px;
}

.hidden {
    display: none !important;
}

/* --- Results View --- */
.results-header {
    text-align: center;
    margin-bottom: 40px;
}

.results-header h2 {
    font-size: 24px;
    margin-bottom: 24px;
    color: var(--primary-light);
}

.score-display {
    position: relative;
    width: 150px;
    height: 150px;
    margin: 0 auto 20px;
}

.score-circle {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.circle-bg {
    fill: none;
    stroke: rgba(255, 255, 255, 0.05);
    stroke-width: 8;
}

.circle-progress {
    fill: none;
    stroke: var(--accent);
    stroke-width: 8;
    stroke-linecap: round;
    stroke-dasharray: 283; /* 2 * pi * 45 */
    stroke-dashoffset: 283;
    transition: stroke-dashoffset 1.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.score-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
}

.score-text span:first-child {
    font-size: 42px;
    font-weight: 700;
    line-height: 1;
}

.score-label {
    font-size: 14px;
    color: var(--text-muted);
    margin-top: 4px;
}

.score-message {
    font-size: 18px;
    font-weight: 500;
}

/* Review Section */
.review-section {
    flex-grow: 1;
    overflow-y: auto;
    margin-bottom: 30px;
    max-height: 300px;
    padding-right: 8px; /* For scrollbar */
}

/* Custom Scrollbar for review section */
.review-section::-webkit-scrollbar {
    width: 6px;
}
.review-section::-webkit-scrollbar-track {
    background: rgba(255,255,255,0.02);
    border-radius: 3px;
}
.review-section::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.1);
    border-radius: 3px;
}

.review-section h3 {
    font-size: 16px;
    color: var(--primary-light);
    margin-bottom: 16px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 8px;
}

.review-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.review-card {
    background: rgba(255, 255, 255, 0.03);
    border-radius: 12px;
    padding: 16px;
    border-left: 4px solid var(--error);
}

.review-card p.q-text {
    font-size: 15px;
    margin-bottom: 12px;
    line-height: 1.5;
}

.review-answer {
    font-size: 14px;
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 6px;
}

.review-answer.correct {
    color: var(--success);
}
.review-answer.wrong {
    color: var(--error);
}

.review-answer i {
    margin-top: 2px;
}

.actions {
    display: flex;
    justify-content: center;
}

/* Responsive */
@media (max-width: 480px) {
    .app-container {
        padding: 24px 20px;
        border-radius: 0; /* Make it completely flush with screen edges */
        border: none;
        max-height: 100%; /* Fill up entire screen */
    }
    
    .features {
        flex-direction: column;
        align-items: center;
        gap: 16px;
    }
    
    .feature-item {
        flex-direction: row;
        width: 100%;
        max-width: 200px;
        justify-content: flex-start;
    }

    .bg-shape {
        display: none; /* Hide decorative background on mobile for performance and cleaner look */
    }
}
