/* Base styles for the body and overall layout */
body {
    font-family: 'Arial', sans-serif;
    margin: 0;
    padding: 0;
    background-color: #121212; /* Dark background for app feel */
    color: white;
    text-align: center;
    overflow-x: hidden; /* Prevent horizontal scrolling */
    -webkit-tap-highlight-color: transparent; /* Remove tap highlight on mobile */
    overscroll-behavior: contain; /* Prevent pull-to-refresh on mobile */
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(18, 18, 18, 0.9);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    color: #e63946;
    font-size: 1.2em;
    transition: opacity 0.5s ease-out;
}

.loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.spinner {
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top: 4px solid #e63946;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin-bottom: 15px;
}

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

/* Header styling */
header {
    background-color: #1a1a1a;
    padding: 10px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.5); /* Subtle shadow */
    position: relative; /* For z-index to work against video */
    z-index: 20; /* Ensure header is above everything but loading overlay */
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 10px;
}

.logo-text {
    font-size: 24px;
    font-weight: bold;
    color: #e63946; /* Distinctive red for logo text */
}

/* Main container for the app content */
.container {
    max-width: 100%;
    margin: 0 auto;
    padding: 0;
    position: relative;
}

/* Video display area */
#video-container {
    position: relative;
    width: 100%;
    max-width: 800px; /* Max width for larger screens */
    margin: 0 auto;
    background-color: black;
    overflow: hidden;
    border-radius: 8px; /* Rounded corners for the video frame */
    aspect-ratio: 16 / 9; /* Maintain 16:9 aspect ratio */
}

#video {
    width: 100%;
    height: 100%; /* Make video fill container */
    object-fit: cover; /* Cover the container without distortion */
    display: block;
    background-color: black; /* Ensure black background when no stream */
}

/* Overlay for timestamp and other info */
#overlay {
    position: absolute;
    top: 10px;
    left: 10px;
    color: white;
    background-color: rgba(0, 0, 0, 0.5); /* Semi-transparent background */
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 14px;
    font-family: monospace; /* Monospace font for a techy look */
    pointer-events: none; /* Allows clicks to pass through to video */
    z-index: 5; /* Ensures it's above the video */
}

/* Control buttons container */
#controls {
    position: absolute;
    top: 10px;
    right: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 10; /* Ensures controls are clickable */
    transition: opacity 0.3s; /* Smooth fade for dimming */
}

#controls.recording-dim { /* Class to dim controls during recording */
    opacity: 0.3;
}

#controls.recording-dim:hover { /* Full opacity on hover when dimmed */
    opacity: 1;
}

/* Button styling */
button {
    background-color: #e63946; /* Red primary button color */
    color: white;
    border: none;
    padding: 10px 15px;
    border-radius: 4px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s; /* Smooth transitions for hover/active states */
    min-width: 100px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.3);
    -webkit-appearance: none; /* Remove default button styles for better consistency */
    -moz-appearance: none;
    appearance: none;
}

button:hover:not(:disabled) {
    background-color: #f0505a; /* Lighter red on hover */
}

button:disabled {
    background-color: #555; /* Grey when disabled */
    cursor: not-allowed;
    opacity: 0.7;
}

button.recording-active {
    background-color: #f44336;
    box-shadow: 0 0 10px #f44336;
    animation: pulse 1.5s infinite; /* Pulsing effect for active record button */
}

@keyframes pulse {
    0% { box-shadow: 0 0 10px #f44336; }
    50% { box-shadow: 0 0 20px #f44336; }
    100% { box-shadow: 0 0 10px #f44336; }
}

/* Recordings section styling */
#recordings-section {
    margin-top: 20px;
    padding: 10px;
}

#recordings-section h2 {
    margin-bottom: 15px;
    color: #e63946; /* Red heading for recordings */
}

#recordings {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); /* Adjusted minmax for better small screen fit */
    gap: 15px;
    padding: 0 10px; /* Add some padding for the grid */
    justify-content: center; /* Center grid items */
}

.recording-item { /* Individual recording card */
    background-color: #1a1a1a;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 5px rgba(0,0,0,0.3);
    display: flex;
    flex-direction: column;
}

.recording-item video {
    width: 100%;
    height: auto; /* Ensure video scales correctly */
    display: block;
    background-color: black;
}

.recording-info {
    padding: 10px;
    font-size: 14px;
    text-align: left;
    flex-grow: 1; /* Allows info section to expand */
}

.recording-actions {
    display: flex;
    justify-content: space-between;
    padding: 10px;
    background-color: #222;
    gap: 10px; /* Space between action buttons */
}

.recording-actions button {
    padding: 8px 12px;
    font-size: 13px;
    min-width: auto;
    flex-grow: 1; /* Makes buttons fill available space */
}

.recording-actions button.download {
    background-color: #4CAF50; /* Green for download */
}
.recording-actions button.download:hover:not(:disabled) {
    background-color: #45a049;
}

.recording-actions button.delete {
    background-color: #f44336; /* Red for delete */
}
.recording-actions button.delete:hover:not(:disabled) {
    background-color: #d32f2f;
}

/* Footer styling */
footer {
    margin-top: 30px;
    padding: 20px;
    background-color: #1a1a1a;
    font-size: 12px;
    color: #777;
}

/* Recording status indicator (REC) */
.status {
    position: absolute;
    top: 10px;
    right: 140px; /* Positioned relative to controls */
    background-color: rgba(255, 0, 0, 0.7);
    color: white;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 12px;
    display: none; /* Hidden by default */
    z-index: 5;
    animation: blink 1s infinite; /* Blinking effect */
}

@keyframes blink {
    0% { opacity: 1; }
    50% { opacity: 0.5; }
    100% { opacity: 1; }
}

/* Message box for user feedback */
#message-box {
    background-color: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 10px;
    margin: 10px auto;
    border-radius: 5px;
    max-width: 500px;
    display: none; /* Hidden by default */
    font-size: 14px;
    word-wrap: break-word; /* Ensure long messages break correctly */
}

/* Platform specific instructions */
.platform-instructions {
    background-color: #1a1a1a;
    border-left: 4px solid #e63946;
    padding: 15px;
    margin: 20px auto;
    max-width: 600px;
    text-align: left;
    display: none; /* Hidden by default, shown based on platform */
}

/* Fallback message for unsupported browsers */
#fallback-message {
    display: none; /* Hidden by default */
    background-color: #333;
    padding: 15px;
    border-radius: 5px;
    margin: 15px auto;
    max-width: 600px;
}

/* Responsive adjustments for smaller screens */
@media (max-width: 600px) {
    button {
        padding: 8px 10px; /* Slightly smaller padding */
        min-width: 60px; /* Smaller min-width */
        font-size: 13px; /* Smaller font size */
    }
    
    #controls {
        flex-direction: column;
        right: 5px;
        top: 5px;
        gap: 5px;
    }

    .status {
        right: 5px; /* Adjust position for smaller screens */
        top: auto;
        bottom: 5px; /* Position at the bottom right on small screens */
    }

    #recordings {
        grid-template-columns: 1fr; /* Single column layout for recordings */
        padding: 0 5px; /* Reduce padding for smaller screens */
    }

    .recording-actions button {
        padding: 6px 10px;
        font-size: 12px;
    }

    #overlay {
        font-size: 12px;
        padding: 3px 8px;
    }
}