/**
 * Blauschbook Styles
 * Party guestbook with psychedelic image transformations
 * Inherits base styling from base.html template
 */

/* =============================================================================
   Base Styles - Extend from base template
   ============================================================================= */

/* =============================================================================
   Camera / Capture View
   ============================================================================= */

.capture-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.video-container {
    position: relative;
    width: 100%;
    max-width: 600px;
    /* Dynamic aspect ratio from camera, fallback to 4/3 */
    aspect-ratio: var(--camera-aspect-ratio, 1.3333);
    background: #000;
    border-radius: 1rem;
    overflow: hidden;
    border: 1px solid var(--glass-border);
    box-shadow: var(--glow);
}

.video-container video {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* Portrait orientation - allow full width */
@media (orientation: portrait) {
    .video-container {
        max-width: 100%;
    }
}

.preview-container {
    display: none;
    position: relative;
    width: 100%;
    max-width: 600px;
}

.preview-container.active {
    display: block;
}

.preview-container img {
    width: 100%;
    border-radius: 1rem;
}

.capture-controls {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    justify-content: center;
}

/* Camera switch button */
.btn-switch {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    border: 2px solid var(--glass-border);
    color: var(--text);
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-switch:hover {
    border-color: var(--primary);
    color: var(--primary);
    box-shadow: var(--glow);
}

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

/* Capture button - special styling for camera shutter */
.btn-capture {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: linear-gradient(145deg, rgba(0, 255, 204, 0.3), rgba(0, 204, 153, 0.2));
    border: 4px solid var(--primary);
    box-shadow: 0 0 30px rgba(0, 255, 204, 0.4);
    color: var(--primary);
    cursor: pointer;
    transition: var(--transition);
}

.btn-capture:hover {
    transform: scale(1.1);
    box-shadow: 0 0 50px rgba(0, 255, 204, 0.6);
}

.upload-fallback {
    margin-top: 1rem;
    text-align: center;
}

.upload-fallback input[type="file"] {
    display: none;
}

.upload-fallback label {
    color: var(--text-dim);
    cursor: pointer;
    text-decoration: underline;
}

.upload-fallback label:hover {
    color: var(--primary);
}

/* Greeting Input */
.greeting-form {
    width: 100%;
    max-width: 600px;
    margin-top: 1rem;
}

.greeting-input {
    width: 100%;
    padding: 1rem;
    font-size: 1rem;
    font-family: 'Rajdhani', sans-serif;
    border: 1px solid var(--glass-border);
    border-radius: 0.5rem;
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    color: var(--text);
    resize: vertical;
    min-height: 100px;
    transition: var(--transition);
}

.greeting-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: var(--glow);
}

.char-count {
    text-align: right;
    color: var(--text-dim);
    font-size: 0.875rem;
    margin-top: 0.25rem;
}

/* =============================================================================
   Processing Animation - Crosshair + Comet
   ============================================================================= */

.processing-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 60vh;
    text-align: center;
    padding: 2rem;
}

.animation-wrapper {
    position: relative;
    width: 200px;
    height: 200px;
    margin: 2rem 0;
}

/* Crosshair - pulses and cycles colors */
.crosshair {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 60px;
    height: 60px;
}

.crosshair::before,
.crosshair::after {
    content: '';
    position: absolute;
    background: currentColor;
    animation: crosshair-pulse 2s ease-in-out infinite, crosshair-color 8s linear infinite;
}

.crosshair::before {
    top: 50%;
    left: 0;
    width: 100%;
    height: 4px;
    transform: translateY(-50%);
}

.crosshair::after {
    left: 50%;
    top: 0;
    width: 4px;
    height: 100%;
    transform: translateX(-50%);
}

@keyframes crosshair-pulse {

    0%,
    100% {
        opacity: 1;
        transform: scale(1);
    }

    50% {
        opacity: 0.6;
        transform: scale(1.2);
    }
}

@keyframes crosshair-color {
    0% {
        color: #499deb;
    }

    25% {
        color: #612ca1;
    }

    50% {
        color: #00ffcc;
    }

    75% {
        color: #ff8800;
    }

    100% {
        color: #499deb;
    }
}

/* Comet - rotates opposite direction around crosshair */
.comet-orbit {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    animation: orbit-reverse 3s linear infinite;
}

.comet {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 20px;
    height: 20px;
}

.comet-head {
    width: 20px;
    height: 20px;
    background: radial-gradient(circle, #fff 0%, #feca57 50%, #ff6b6b 100%);
    border-radius: 50%;
    box-shadow:
        0 0 20px #feca57,
        0 0 40px #ff6b6b,
        0 0 60px #ff6b6b;
    animation: comet-glow 1s ease-in-out infinite alternate;
}

.comet-tail {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 60px;
    height: 4px;
    background: linear-gradient(90deg, rgba(254, 202, 87, 0.8) 0%, rgba(255, 107, 107, 0) 100%);
    transform-origin: left center;
    transform: translateY(-50%) rotate(90deg);
    border-radius: 2px;
}

@keyframes orbit-reverse {
    from {
        transform: rotate(360deg);
    }

    to {
        transform: rotate(0deg);
    }
}

@keyframes comet-glow {
    from {
        box-shadow:
            0 0 20px #feca57,
            0 0 40px #ff6b6b,
            0 0 60px #ff6b6b;
    }

    to {
        box-shadow:
            0 0 30px #feca57,
            0 0 60px #ff6b6b,
            0 0 90px #ff6b6b;
    }
}

/* Additional orbiting particles */
.particle-orbit {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.particle-orbit:nth-child(2) {
    animation: orbit-reverse 4s linear infinite;
}

.particle-orbit:nth-child(3) {
    animation: orbit-reverse 5s linear infinite reverse;
}

.particle {
    position: absolute;
    width: 8px;
    height: 8px;
    background: radial-gradient(circle, #fff 0%, #48dbfb 100%);
    border-radius: 50%;
    box-shadow: 0 0 10px #48dbfb;
}

.particle-orbit:nth-child(2) .particle {
    top: 20%;
    left: 50%;
    transform: translateX(-50%);
}

.particle-orbit:nth-child(3) .particle {
    top: 80%;
    left: 50%;
    transform: translateX(-50%);
    background: radial-gradient(circle, #fff 0%, #ff9ff3 100%);
    box-shadow: 0 0 10px #ff9ff3;
}

.processing-text {
    font-size: 1.25rem;
    font-family: 'Orbitron', sans-serif;
    color: var(--primary);
    text-shadow: var(--glow);
    animation: text-pulse 2s ease-in-out infinite;
}

@keyframes text-pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

.processing-status {
    margin-top: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-dim);
}

/* =============================================================================
   Gallery
   ============================================================================= */

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
    padding: 1rem 0;
}

.gallery-card {
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    border-radius: 1rem;
    overflow: hidden;
    transition: var(--transition);
}

.gallery-card:hover {
    transform: translateY(-4px);
    border-color: var(--primary);
    box-shadow: var(--glow-strong);
}

.gallery-card-image {
    position: relative;
    aspect-ratio: 1;
    overflow: hidden;
    cursor: pointer;
}

.gallery-card-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s;
}

.gallery-card:hover .gallery-card-image img {
    transform: scale(1.05);
}

.gallery-card-content {
    padding: 1rem;
}

.gallery-card-content .greeting {
    font-size: 0.95rem;
    line-height: 1.5;
    margin-bottom: 0.5rem;
    color: var(--text);
}

.gallery-card-content time {
    font-size: 0.75rem;
    color: var(--text-dim);
}

/* Gallery Modal */
.gallery-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
}

.gallery-modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
}

.modal-content {
    position: relative;
    background: var(--bg-overlay);
    backdrop-filter: blur(20px);
    border: 1px solid var(--primary);
    border-radius: 1rem;
    padding: 2rem;
    max-width: 90vw;
    max-height: 90vh;
    overflow: auto;
    z-index: 1;
    box-shadow: var(--glow-strong);
}

.modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 40px;
    height: 40px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 50%;
    color: var(--primary);
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.modal-close:hover {
    background: var(--primary);
    color: var(--bg);
    box-shadow: var(--glow);
}

.modal-images {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
}

/* Single image modal layout */
.modal-image-single {
    text-align: center;
    margin-bottom: 1.5rem;
}

.modal-image-single img {
    max-width: 100%;
    max-height: 60vh;
    border-radius: 0.5rem;
    border: 1px solid var(--glass-border);
    cursor: zoom-in;
}

/* Zoom overlay - appended to body for true fullscreen */
.zoom-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.95);
    z-index: 9999;
    overflow: auto;
    cursor: grab;
    /* Ensure overlay captures all events */
    isolation: isolate;
}

.zoom-overlay.dragging {
    cursor: grabbing;
    user-select: none;
}

.zoom-overlay img {
    display: block;
    max-width: none;
    max-height: none;
    min-height: 100vh;
    min-width: 100vw;
    width: auto;
    height: auto;
    object-fit: contain;
    cursor: inherit;
    /* Background behind image to capture events in scrolled areas */
    background: rgba(0, 0, 0, 0.95);
}

.modal-controls {
    text-align: center;
    margin-bottom: 1.5rem;
}

.modal-controls .btn {
    min-width: 180px;
}

.modal-greeting {
    text-align: center;
    padding-top: 1rem;
    border-top: 1px solid var(--glass-border);
}

.modal-greeting p {
    font-size: 1.1rem;
    line-height: 1.6;
    color: var(--text);
    margin-bottom: 0.5rem;
}

.modal-greeting time {
    font-size: 0.85rem;
    color: var(--text-dim);
}

@media (max-width: 768px) {
    .modal-images {
        grid-template-columns: 1fr;
    }

    .modal-image-single img {
        max-height: 50vh;
    }

    .modal-content {
        padding: 0.75rem;
        border-radius: 0.5rem;
    }

    .modal-close {
        top: 0.5rem;
        right: 0.5rem;
        width: 32px;
        height: 32px;
        font-size: 1.25rem;
    }

    .modal-image-single {
        margin-bottom: 0.75rem;
    }

    .modal-controls {
        margin-bottom: 0.75rem;
    }

    .modal-greeting {
        padding-top: 0.75rem;
    }
}

.modal-image-container {
    text-align: center;
}

.modal-image-container h3 {
    margin-bottom: 1rem;
    color: var(--text-dim);
    font-family: 'Highup', 'Orbitron', sans-serif;
}

.modal-image-container img {
    max-width: 100%;
    max-height: 60vh;
    border-radius: 0.5rem;
}

/* Submit Gate */
.submit-gate {
    text-align: center;
    padding: 3rem 1rem;
}

.submit-gate h2 {
    font-size: 1.5rem;
    margin-bottom: 1rem;
    color: var(--text);
    font-family: 'Highup', 'Orbitron', sans-serif;
}

.submit-gate p {
    color: var(--text-dim);
    margin-bottom: 2rem;
}

/* Empty State */
.gallery-empty {
    text-align: center;
    padding: 3rem;
    color: var(--text-dim);
}

/* Loading indicator */
.gallery-loading {
    text-align: center;
    padding: 2rem;
    color: var(--text-dim);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--glass-border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
    box-shadow: var(--glow);
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* =============================================================================
   Capture Page - Immersive Camera Experience
   ============================================================================= */

/* Reset container styles for capture page */
.blauschbook-container:has(.capture-page) {
    max-width: none;
    padding: 0;
    margin: 0;
}

.blauschbook-container:has(.capture-page)>main {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 100vh;
    min-height: 100dvh;
}

.capture-page {
    flex: 1;
    display: flex;
    flex-direction: column;
    width: 100%;
}

.capture-page .capture-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    width: 100%;
}

.capture-page #camera-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    width: 100%;
}

/* Camera wrapper - contains video and overlays */
.capture-page .camera-wrapper {
    position: relative;
    width: 100%;
    background: #000;
    /* Use native camera aspect ratio, fallback to 4:3 */
    aspect-ratio: var(--camera-aspect-ratio, 1.3333);
}

/* Video container - immersive */
.capture-page .video-container {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    max-width: none;
    border: none;
    border-radius: 0;
    box-shadow: none;
    background: #000;
    overflow: hidden;
}

.capture-page .video-container video {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 0;
    transform: scaleX(-1);
}

/* Overlay controls - top corners */
.capture-overlay-controls {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 1rem;
    padding-top: max(1rem, env(safe-area-inset-top));
    z-index: 20;
    pointer-events: none;
}

.capture-overlay-controls>* {
    pointer-events: auto;
}

.capture-overlay-right {
    display: flex;
    gap: 0.5rem;
}

.btn-overlay {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    text-decoration: none;
    padding: 0;
    box-sizing: border-box;
}

.btn-overlay input[type="file"] {
    display: none;
}

.btn-overlay:hover {
    background: rgba(0, 0, 0, 0.7);
    border-color: rgba(255, 255, 255, 0.5);
}

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

.btn-overlay svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

/* Shutter button - bottom center, floating */
.capture-shutter {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    padding: 1.5rem;
    padding-bottom: max(1.5rem, env(safe-area-inset-bottom));
    z-index: 20;
}

.capture-page .btn-capture {
    width: 72px;
    height: 72px;
    min-width: 72px;
    min-height: 72px;
    border-radius: 50%;
    background: transparent;
    border: 4px solid white;
    cursor: pointer;
    position: relative;
    transition: transform 0.15s ease;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    color: transparent;
    padding: 0;
    box-sizing: border-box;
}

/* Inner circle using pseudo-element */
.capture-page .btn-capture::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: white;
    transition: background 0.15s ease;
}

.capture-page .btn-capture:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

.capture-page .btn-capture:active {
    transform: scale(0.95);
}

.capture-page .btn-capture:active::after {
    background: rgba(255, 255, 255, 0.7);
}

/* Camera unavailable icon */
.camera-unavailable-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: rgba(255, 255, 255, 0.6);
}

.camera-unavailable-icon svg {
    stroke: rgba(255, 255, 255, 0.4);
    margin-bottom: 1rem;
}

.camera-unavailable-icon p {
    font-size: 1rem;
    margin: 0;
}

/* Upload button styled as shutter */
.btn-upload-shutter {
    display: flex !important;
    align-items: center;
    justify-content: center;
    background: transparent !important;
}

.btn-upload-shutter::after {
    display: none !important;
}

.btn-upload-shutter svg {
    stroke: white;
}

/* Upload hint - subtle above shutter */
.upload-hint {
    position: absolute;
    bottom: 110px;
    bottom: calc(110px + env(safe-area-inset-bottom));
    left: 0;
    right: 0;
    text-align: center;
    z-index: 20;
}

.upload-hint input[type="file"] {
    display: none;
}

.upload-hint label {
    color: rgba(255, 255, 255, 0.6);
    font-size: 0.85rem;
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 2px;
    transition: color 0.2s ease;
}

.upload-hint label:hover {
    color: rgba(255, 255, 255, 0.9);
}

/* Preview state */
.capture-page .preview-container {
    max-width: none;
    background: #000;
}

.capture-page .preview-container.active {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1rem;
}

.capture-page .preview-container img {
    max-width: 100%;
    max-height: 50vh;
    border-radius: 0.5rem;
    object-fit: contain;
}

/* Greeting section after capture */
.capture-page #greeting-section {
    padding: 1rem;
    max-width: 600px;
    margin: 0 auto;
    width: 100%;
}

/* Desktop: add some chrome back */
@media (min-width: 768px) {
    .capture-page {
        padding: 1rem;
        background: var(--bg);
    }

    .capture-page .camera-wrapper {
        max-width: 700px;
        margin: 0 auto;
        border-radius: 1rem;
        overflow: hidden;
    }

    .capture-page .video-container {
        border-radius: 1rem;
    }

    .capture-page .video-container video {
        /* Use contain to show full camera view without cropping */
        object-fit: contain;
    }

    .capture-page #greeting-section {
        padding: 2rem;
    }

    .capture-page .preview-container.active {
        padding: 2rem;
    }
}

/* =============================================================================
   Responsive
   ============================================================================= */

@media (max-width: 640px) {
    .blauschbook-title {
        font-size: 1.75rem;
    }

    .video-container {
        border-radius: 0.5rem;
    }

    .btn-capture {
        width: 70px;
        height: 70px;
    }

    .btn-switch {
        width: 44px;
        height: 44px;
    }

    .animation-wrapper {
        width: 160px;
        height: 160px;
    }

    .gallery-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
}
