:root {
    --primary-color: #82c91e;
    --primary-dark: #6eb015;
    --bg-color: #121212;
    --bg-panel: #1e1e1e;
    --text-color: #f1f5f9;
    --text-muted: #94a3b8;
    --error-color: #e74c3c;
    --border-color: #333333;
}

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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.hidden {
    display: none !important;
}

/* HEADER */
.app-header {
    background-color: var(--bg-panel);
    padding: 20px 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    border-bottom: 1px solid var(--border-color);
}

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

.nav-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 1rem;
    transition: color 0.3s;
}

.nav-btn:hover {
    color: var(--text-color);
}

.back-link {
    left: 20px;
}

.home-link {
    right: 20px;
    font-size: 1.3rem;
}

/* MAIN CONTAINER */
.delay-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 1000px;
    /* Limit width on very large screens */
    margin: 0 auto;
    padding: 20px;
    gap: 20px;
}

/* VIDEO AREA */
.video-wrapper {
    flex: 1;
    background-color: #000;
    border-radius: 12px;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    border: 1px solid var(--border-color);
    min-height: 300px;
}

#playback-canvas {
    width: 100%;
    height: 100%;
    object-fit: contain;
    /* Like background-size: contain */
}

/* OVERLAYS */
.overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 20px;
    z-index: 10;
}

.overlay-hint {
    color: var(--text-muted);
    margin-top: 15px;
    font-size: 0.95rem;
}

.error-icon {
    font-size: 3rem;
    color: var(--error-color);
    margin-bottom: 15px;
}

#error-title {
    color: var(--error-color);
    margin-bottom: 10px;
}

.loading-icon {
    font-size: 3rem;
    color: var(--primary-color);
    margin-bottom: 15px;
}

/* LIVE INDICATOR */
.live-indicator {
    position: absolute;
    top: 15px;
    right: 15px;
    background: rgba(0, 0, 0, 0.6);
    padding: 6px 12px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    font-weight: 700;
    color: white;
    z-index: 5;
    backdrop-filter: blur(4px);
}

.red-dot {
    width: 10px;
    height: 10px;
    background-color: var(--error-color);
    border-radius: 50%;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        transform: scale(0.95);
        opacity: 0.5;
    }

    50% {
        transform: scale(1.1);
        opacity: 1;
    }

    100% {
        transform: scale(0.95);
        opacity: 0.5;
    }
}

/* CONTROLS */
.controls-wrapper {
    background-color: var(--bg-panel);
    border-radius: 12px;
    padding: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 40px;
    flex-wrap: wrap;
    border: 1px solid var(--border-color);
}

.control-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

.control-label {
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 600;
}

.delay-setter {
    display: flex;
    align-items: center;
    gap: 20px;
}

.delay-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100px;
}

#delay-value {
    font-size: 3rem;
    font-weight: 800;
    line-height: 1;
    color: var(--primary-color);
}

.delay-unit {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
}

/* BUTTONS */
.btn {
    border: none;
    font-family: inherit;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-weight: 600;
    touch-action: manipulation;
}

.btn i,
.btn-icon i,
.btn-icon-text i,
.btn-ctrl i,
.btn-icon-close i {
    pointer-events: none;
}

.btn-large {
    padding: 18px 36px;
    font-size: 1.2rem;
    border-radius: 12px;
}

.btn-primary {
    background-color: var(--error-color);
    /* Red for Recording/Starting */
    color: white;
}

.btn-primary:hover {
    background-color: #c0392b;
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(231, 76, 60, 0.4);
}

.btn-secondary {
    background-color: transparent;
    color: var(--text-color);
    border: 2px solid var(--text-muted);
    padding: 10px 20px;
}

.btn-secondary:hover {
    border-color: var(--text-color);
    background-color: rgba(255, 255, 255, 0.05);
}

.btn-ctrl {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background-color: var(--bg-color);
    color: var(--text-color);
    font-size: 1.5rem;
    border: 2px solid var(--border-color);
    touch-action: manipulation;
}

@media (hover: hover) {
    .btn-ctrl:hover {
        background-color: #2a2a2a;
        border-color: var(--text-muted);
    }
}

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

/* IN-VIDEO CONTROLS */
.in-video-controls {
    position: absolute;
    bottom: 15px;
    right: 15px;
    display: flex;
    gap: 15px;
    z-index: 20;
}

.btn-icon {
    background: rgba(0, 0, 0, 0.6);
    color: white;
    border: none;
    width: 45px;
    height: 45px;
    border-radius: 50%;
    font-size: 1.2rem;
    cursor: pointer;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
}

@media (hover: hover) {
    .btn-icon:hover {
        background: rgba(0, 0, 0, 0.9);
        transform: scale(1.1);
    }
}

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

.in-video-controls-left {
    position: absolute;
    bottom: 15px;
    left: 15px;
    z-index: 20;
}

.btn-icon-text {
    background: rgba(0, 0, 0, 0.6);
    color: white;
    border: none;
    width: auto;
    height: 45px;
    padding: 0 20px;
    border-radius: 22.5px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    white-space: nowrap;
    touch-action: manipulation;
}

@media (hover: hover) {
    .btn-icon-text:hover {
        background: rgba(231, 76, 60, 0.9);
        /* Red hover for stop */
        transform: scale(1.05);
    }
}

.btn-icon-text:active {
    transform: scale(0.95);
}

/* SETTINGS MODAL */
.settings-modal {
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(10px);
    z-index: 30;
}

.settings-content {
    background-color: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    width: 90%;
    max-width: 400px;
    padding: 25px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8);
    text-align: left;
}

.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 15px;
    margin-bottom: 5px;
}

.settings-header h2 {
    font-size: 1.2rem;
    color: var(--text-color);
}

.btn-icon-close {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
}

.btn-icon-close:hover {
    color: var(--error-color);
}

.settings-row {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.settings-row label {
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.form-select {
    width: 100%;
    padding: 12px;
    background-color: var(--bg-color);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    border-radius: 8px;
    font-size: 1rem;
    outline: none;
}

.form-select:focus {
    border-color: var(--primary-color);
}

.settings-hint {
    font-size: 0.8rem;
    color: var(--text-muted);
    line-height: 1.4;
}

.modal-setter {
    justify-content: space-between;
    background: var(--bg-color);
    padding: 10px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.btn-small {
    width: 40px;
    height: 40px;
    font-size: 1rem;
}

.modal-value-display {
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--primary-color);
}

/* Responsive */
@media (max-width: 600px) {
    .app-header h1 {
        font-size: 1.2rem;
    }

    .nav-btn span {
        display: none;
    }

    .btn-ctrl {
        width: 50px;
        height: 50px;
        font-size: 1.2rem;
    }

    #delay-value {
        font-size: 2.5rem;
    }
}

/* iOS Safari Fullscreen Fallback */
.fullscreen-fallback {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    max-width: none !important;
    max-height: none !important;
    z-index: 99999 !important;
    background: black !important;
    margin: 0 !important;
    padding: 0 !important;
    border-radius: 0 !important;
}

body.fullscreen-active {
    overflow: hidden !important;
}