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

/* Elegant Dark Maturaball Theme */
:root {
    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
    --secondary-color: #6b7280;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --light-color: #ffffff;
    --dark-color: #111827;
    --darker-color: #0f172a;
    --border-color: rgba(255,255,255,0.1);
    --card-bg: #1f2937;
    --card-border: rgba(255,255,255,0.05);
    --shadow: 0 10px 25px rgba(0,0,0,0.3);
    --glow: 0 0 20px rgba(59,130,246,0.3);
    --border-radius: 16px;
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, Roboto, 'Helvetica Neue', Arial, sans-serif;

    /* Elegant Gradients */
    --elegant-gradient: linear-gradient(135deg,
        var(--primary-color) 0%,
        #6366f1 50%,
        #8b5cf6 100%
    );
    --card-gradient: linear-gradient(145deg,
        var(--card-bg) 0%,
        #374151 100%
    );

    /* Professional Dark Background */
    --bg-gradient: radial-gradient(ellipse at center, var(--dark-color) 0%, var(--darker-color) 100%);
    --subtle-pattern:
        radial-gradient(1px 1px at 25px 25px, rgba(255,255,255,0.02), transparent),
        radial-gradient(1px 1px at 75px 75px, rgba(255,255,255,0.01), transparent);
}

/* Elegant Dark Professional Theme */
body {
    font-family: var(--font-family);
    background:
        var(--subtle-pattern),
        var(--bg-gradient);
    background-size: 50px 50px, cover;
    background-attachment: fixed;
    min-height: 100vh;
    color: var(--light-color);
    line-height: 1.6;
    position: relative;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Professional subtle accent */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--elegant-gradient);
    z-index: 1000;
    opacity: 0.8;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Professional Header */
.mario-kart-header {
    background: linear-gradient(135deg,
        rgba(255,255,255,0.08) 0%,
        rgba(255,255,255,0.04) 100%);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 32px 28px;
    margin: 8px 0 24px 0;
    box-shadow: var(--shadow);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 24px;
    position: relative;
    overflow: hidden;
}

.mario-kart-header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: var(--elegant-gradient);
    opacity: 0.3;
}

.htl-branding {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--secondary-color);
    opacity: 0.7;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.main-title {
    flex: 1;
    text-align: center;
}

.professional-logo {
    margin-bottom: 20px;
}

.logo-text {
    font-size: 2.8rem;
    font-weight: 700;
    background: var(--elegant-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: 1px;
    margin-bottom: 8px;
    line-height: 1.2;
}

.subtitle {
    font-size: 1.1rem;
    color: var(--secondary-color);
    font-weight: 400;
    opacity: 0.9;
    letter-spacing: 0.5px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 15px;
}

.camera-icon {
    font-size: 2.5rem;
    animation: bounce 2s infinite;
}

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

.header h1 {
    font-size: 2rem;
    color: var(--primary-color);
    font-weight: 700;
}

.session-info {
    text-align: right;
}

.session-name {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--dark-color);
}

.photo-count {
    color: var(--secondary-color);
    font-size: 0.9rem;
    margin-top: 5px;
}

/* Main Content */
.main {
    flex: 1;
    background: linear-gradient(135deg,
        rgba(255,255,255,0.1) 0%,
        rgba(255,255,255,0.05) 100%);
    backdrop-filter: blur(15px);
    border: 2px solid rgba(255,255,255,0.2);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Controls */
.controls {
    padding: 25px;
    background: var(--light-color);
    border-bottom: 1px solid var(--border-color);
    text-align: center;
}

.download-info {
    margin-bottom: 20px;
}

.download-info p {
    color: var(--secondary-color);
    font-size: 1.1rem;
}

.control-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
    flex-wrap: wrap;
}

/* Buttons */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: var(--border-radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    white-space: nowrap;
}

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

.btn.primary {
    background: linear-gradient(45deg, var(--primary-color), var(--warning-color));
    color: white;
    box-shadow: 0 6px 20px rgba(255, 107, 107, 0.4);
    border: 2px solid rgba(255,255,255,0.3);
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 1px;
    position: relative;
    overflow: hidden;
}

.btn.primary::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.4), transparent);
    transition: left 0.5s;
}

.btn.primary:hover:not(:disabled) {
    background: linear-gradient(45deg, var(--primary-hover), var(--warning-color));
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 8px 30px rgba(255, 107, 107, 0.6);
    animation: power-up 0.3s ease;
}

.btn.primary:hover:not(:disabled)::before {
    left: 100%;
}

@keyframes power-up {
    0% { filter: brightness(1); }
    50% { filter: brightness(1.3); }
    100% { filter: brightness(1.1); }
}

.btn.secondary {
    background: var(--light-color);
    color: var(--dark-color);
    border: 2px solid var(--border-color);
}

.btn.secondary:hover:not(:disabled) {
    background: var(--border-color);
    transform: translateY(-1px);
}

.btn.large {
    padding: 15px 30px;
    font-size: 1.2rem;
}

.btn-icon {
    font-size: 1.2rem;
}

/* Photos Grid */
.photos-grid {
    flex: 1;
    padding: 25px;
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 20px;
    min-height: 400px;
    justify-content: center;
}

.photo-item {
    position: relative;
    border-radius: var(--border-radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: all 0.3s;
    background: linear-gradient(135deg,
        rgba(255,255,255,0.2) 0%,
        rgba(255,255,255,0.1) 100%);
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255,255,255,0.3);
    display: flex;
    flex-direction: column;
    height: fit-content;
    transform-style: preserve-3d;
}

.photo-item:hover {
    transform: translateY(-12px) rotateY(5deg);
    box-shadow: 0 15px 40px rgba(255,107,107,0.3);
    border-color: var(--rainbow-gradient);
    animation: kart-boost 0.3s ease;
}

@keyframes kart-boost {
    0% { transform: translateY(-12px) rotateY(5deg) scale(1); }
    50% { transform: translateY(-12px) rotateY(5deg) scale(1.02); }
    100% { transform: translateY(-12px) rotateY(5deg) scale(1); }
}

.photo-item.selected {
    border: 3px solid;
    border-image: var(--rainbow-gradient) 1;
    transform: translateY(-8px) scale(1.03);
    animation: selection-glow 2s ease-in-out infinite alternate;
}

@keyframes selection-glow {
    from { box-shadow: 0 8px 30px rgba(255,107,107,0.4); }
    to { box-shadow: 0 8px 30px rgba(76,236,196,0.6); }
}

.photo-item.selected::after {
    content: '⭐';
    position: absolute;
    top: 15px;
    right: 15px;
    background: linear-gradient(45deg, var(--primary-color), var(--warning-color));
    color: white;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 1.5rem;
    z-index: 2;
    box-shadow: var(--shadow), var(--glow);
    animation: star-spin 2s linear infinite;
    border: 2px solid rgba(255,255,255,0.5);
}

@keyframes star-spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

@keyframes checkmark {
    from {
        transform: scale(0);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

.photo-image {
    width: 100%;
    height: auto;
    aspect-ratio: 3/2;
    object-fit: cover;
    display: block;
    transition: transform 0.3s;
    flex-shrink: 0;
}

.photo-item:hover .photo-image {
    transform: scale(1.05);
}

.photo-info {
    padding: 10px 15px;
    background: white;
}

.photo-filename {
    display: none; /* Hide photo filenames in download portal */
}

.photo-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.photo-actions .btn {
    flex: 1;
    font-size: 0.85rem;
    padding: 10px 8px;
    min-height: 44px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.photo-actions .btn-icon {
    font-size: 1.2rem;
    line-height: 1;
}

.photo-actions .btn-text {
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1;
}

/* Photo action buttons now styled via .photo-actions .btn */

/* Fixed Download Button */
.fixed-download {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
    from {
        transform: translateX(-50%) translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateX(-50%) translateY(0);
        opacity: 1;
    }
}

/* Loading State */
.loading-state {
    text-align: center;
    padding: 80px 20px;
    background: white;
    border-radius: var(--border-radius);
    margin: 20px 0;
    box-shadow: var(--shadow);
}

.loading-spinner {
    width: 60px;
    height: 60px;
    border: 6px solid var(--light-color);
    border-top: 6px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 30px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-state h2 {
    color: var(--dark-color);
    margin-bottom: 10px;
    font-size: 1.8rem;
}

.loading-state p {
    color: var(--secondary-color);
    font-size: 1.1rem;
}

/* Error State */
.error-state {
    text-align: center;
    padding: 80px 20px;
    background: white;
    border-radius: var(--border-radius);
    margin: 20px 0;
    box-shadow: var(--shadow);
}

.error-icon {
    font-size: 4rem;
    margin-bottom: 20px;
    opacity: 0.7;
}

.error-state h2 {
    color: var(--danger-color);
    margin-bottom: 15px;
    font-size: 1.8rem;
}

.error-state p {
    color: var(--secondary-color);
    margin-bottom: 30px;
    font-size: 1.1rem;
}

.retry-btn {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: var(--border-radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}

.retry-btn:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
}

/* Landing Page */
.landing-page {
    flex: 1;
    background: white;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    padding: 40px;
    text-align: center;
}

.hero {
    margin-bottom: 50px;
}

.hero-icon {
    font-size: 5rem;
    margin-bottom: 20px;
    animation: bounce 2s infinite;
}

.hero h1 {
    font-size: 2.5rem;
    color: var(--primary-color);
    margin-bottom: 15px;
    font-weight: 700;
}

.hero p {
    font-size: 1.2rem;
    color: var(--secondary-color);
}

.features {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 30px;
    margin-bottom: 50px;
}

.feature {
    padding: 30px 20px;
    border-radius: var(--border-radius);
    background: var(--light-color);
    transition: transform 0.3s;
}

.feature:hover {
    transform: translateY(-5px);
}

.feature-icon {
    font-size: 2.5rem;
    margin-bottom: 15px;
}

.feature h3 {
    color: var(--dark-color);
    margin-bottom: 10px;
    font-size: 1.3rem;
}

.feature p {
    color: var(--secondary-color);
}

.instructions {
    margin-bottom: 40px;
}

.instructions h2 {
    color: var(--dark-color);
    margin-bottom: 20px;
    font-size: 2rem;
}

.instructions ol {
    text-align: left;
    max-width: 500px;
    margin: 0 auto;
    font-size: 1.1rem;
}

.instructions li {
    margin-bottom: 10px;
    padding: 10px;
    background: var(--light-color);
    border-radius: 8px;
}

.cta {
    margin-bottom: 20px;
}

.cta p {
    font-size: 1.2rem;
    color: var(--dark-color);
    margin-bottom: 20px;
    font-weight: 600;
}

.qr-placeholder {
    background: var(--light-color);
    border: 2px dashed var(--border-color);
    border-radius: var(--border-radius);
    padding: 40px 20px;
    color: var(--secondary-color);
}

.qr-icon {
    font-size: 3rem;
    margin-bottom: 10px;
}

/* Professional Footer */
.professional-footer {
    text-align: center;
    padding: 32px 24px;
    margin-top: 40px;
    background: linear-gradient(135deg,
        rgba(255,255,255,0.05) 0%,
        rgba(255,255,255,0.02) 100%);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
}

.footer-content {
    max-width: 600px;
    margin: 0 auto;
}

.footer-main {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--light-color);
    margin-bottom: 8px;
    background: var(--elegant-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.footer-sub {
    font-size: 0.95rem;
    color: var(--secondary-color);
    opacity: 0.8;
    font-weight: 400;
    line-height: 1.4;
    margin: 0;
}

.finish-line {
    font-size: 1.5rem;
    margin: 10px 0;
    animation: flag-wave 2s ease-in-out infinite;
}

.mario-kart-footer p {
    margin: 8px 0;
    text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.mario-kart-footer p:first-of-type {
    background: var(--rainbow-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-size: 1.1rem;
}

.mario-kart-footer p:last-of-type {
    color: var(--warning-color);
    font-style: italic;
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 2000;
}

.toast {
    background: var(--dark-color);
    color: white;
    padding: 15px 20px;
    border-radius: var(--border-radius);
    margin-bottom: 10px;
    box-shadow: var(--shadow);
    max-width: 300px;
    animation: slideInToast 0.3s ease-out;
}

.toast.success {
    background: var(--success-color);
}

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

.toast.warning {
    background: var(--warning-color);
    color: var(--dark-color);
}

@keyframes slideInToast {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Responsive Design */
/* Enhanced Mobile Responsiveness */
@media (max-width: 768px) {
    .container {
        padding: 15px;
    }

    /* Mobile Header Optimization */
    .mario-kart-header {
        flex-direction: column;
        padding: 20px 15px;
        gap: 15px;
    }

    .htl-branding {
        writing-mode: horizontal-tb;
        text-orientation: unset;
        font-size: 0.8rem;
        order: 3;
    }

    .main-title {
        order: 1;
    }

    .logo-text {
        font-size: 2rem;
    }

    .subtitle {
        font-size: 1rem;
    }

    /* Mobile Controls */
    .controls {
        flex-direction: column;
        gap: 20px;
        padding: 20px 15px;
        text-align: center;
    }

    .control-buttons {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }

    .btn {
        width: 100%;
        padding: 16px 20px;
        font-size: 1.1rem;
        min-height: 56px; /* Touch-friendly size */
        border-radius: 15px;
    }

    /* Mobile Photo Grid */
    .photos-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
        gap: 12px;
        padding: 15px;
    }

    .photo-item {
        border-radius: 15px;
        box-shadow:
            0 8px 20px rgba(0,0,0,0.15),
            0 3px 8px rgba(0,0,0,0.1);
    }

    .photo-item:hover {
        transform: translateY(-4px) scale(1.02);
    }

    .photo-image {
        border-radius: 15px 15px 0 0;
    }

    .photo-info {
        padding: 8px 12px;
    }

    /* Mobile Fixed Download Button */
    .fixed-download {
        left: 15px;
        right: 15px;
        bottom: 15px;
        transform: translateX(0);
    }

    .fixed-download .btn {
        width: 100%;
        font-size: 1.2rem;
        padding: 18px 20px;
        border-radius: 15px;
        box-shadow:
            0 8px 25px rgba(0,0,0,0.3),
            inset 0 1px 0 rgba(255,255,255,0.4);
    }

    /* Mobile Footer */
    .professional-footer {
        padding: 20px 15px;
        font-size: 0.9rem;
    }

    .footer-content p {
        margin: 8px 0;
    }

    .features {
        grid-template-columns: 1fr;
        gap: 20px;
    }

    .hero h1 {
        font-size: 2rem;
    }

    .hero-icon {
        font-size: 4rem;
    }

    .landing-page {
        padding: 30px 20px;
    }
}

/* Ultra Mobile Optimization */
@media (max-width: 480px) {
    .container {
        padding: 10px;
    }

    .logo-text {
        font-size: 1.8rem;
        letter-spacing: 1px;
    }

    .subtitle {
        font-size: 0.9rem;
    }

    /* Ultra-mobile photo grid */
    .photos-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 8px;
        padding: 10px;
    }

    .photo-item {
        border-radius: 12px;
        min-height: 140px;
    }

    .photo-image {
        height: 120px;
        border-radius: 12px 12px 0 0;
    }

    .photo-info {
        padding: 6px 10px;
    }

    /* Touch-optimized buttons */
    .btn {
        padding: 18px 16px;
        font-size: 1rem;
        min-height: 60px;
        border-radius: 12px;
    }

    .fixed-download {
        left: 10px;
        right: 10px;
        bottom: 10px;
    }

    .fixed-download .btn {
        font-size: 1.1rem;
        padding: 20px 16px;
        min-height: 64px;
    }

    .mario-kart-header {
        padding: 15px 10px;
    }

    .controls {
        padding: 15px 10px;
    }

    .photo-actions {
        flex-direction: row;
        gap: 6px;
    }

    .photo-actions .btn {
        min-height: 48px;
        font-size: 0.8rem;
        padding: 8px 6px;
    }

    .photo-actions .btn-icon {
        font-size: 1.1rem;
    }

    .photo-actions .btn-text {
        font-size: 0.7rem;
    }
}

/* Mobile Gallery Save Improvements */
@media (max-width: 768px) {
    /* Make gallery button more prominent on mobile */
    .save-gallery-btn {
        background: linear-gradient(135deg, #10b981 0%, #059669 100%);
        border: none;
        color: white;
        font-weight: 600;
        box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
    }

    .save-gallery-btn:hover,
    .save-gallery-btn:active {
        background: linear-gradient(135deg, #059669 0%, #047857 100%);
        transform: translateY(-1px);
        box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
    }

    /* Larger touch targets for mobile */
    .photo-actions .btn {
        min-height: 50px;
        font-size: 0.9rem;
        padding: 12px 10px;
        border-radius: 12px;
        transition: all 0.2s ease;
    }

    .photo-actions .btn:active {
        transform: scale(0.98);
    }

    /* Better visual feedback for mobile users */
    .btn.secondary {
        background: linear-gradient(135deg, #6b7280 0%, #4b5563 100%);
        color: white;
        border: none;
    }

    .btn.secondary:hover,
    .btn.secondary:active {
        background: linear-gradient(135deg, #4b5563 0%, #374151 100%);
    }
}

/* Full screen image overlay styles (for iOS) */
.image-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.95);
    z-index: 10000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    box-sizing: border-box;
    backdrop-filter: blur(10px);
}

.image-overlay img {
    max-width: 100%;
    max-height: 70vh;
    object-fit: contain;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.image-overlay .instructions {
    color: white;
    text-align: center;
    margin-top: 20px;
    font-size: 16px;
    line-height: 1.6;
    background: rgba(255, 255, 255, 0.1);
    padding: 20px;
    border-radius: 12px;
    backdrop-filter: blur(10px);
    max-width: 320px;
}

.image-overlay .instructions strong {
    color: #10b981;
    font-size: 18px;
    display: block;
    margin-bottom: 10px;
}

/* Toast notification improvements for mobile */
@media (max-width: 768px) {
    .toast {
        font-size: 14px;
        padding: 12px 16px;
        border-radius: 12px;
        margin-bottom: 8px;
        max-width: calc(100vw - 40px);
        backdrop-filter: blur(10px);
    }

    .toast.info {
        background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
        color: white;
        border: none;
    }

    .toast.success {
        background: linear-gradient(135deg, #10b981 0%, #059669 100%);
        color: white;
        border: none;
    }

    .toast.error {
        background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
        color: white;
        border: none;
    }
}