/* ============================================
   Goodnight's Sleep — Design System
   ============================================ */

:root {
    /* Color Palette — deep night sky */
    --bg-primary: #07060e;
    --bg-secondary: #0d0b18;
    --bg-card: rgba(18, 15, 35, 0.7);
    --bg-card-hover: rgba(25, 20, 50, 0.8);
    --bg-card-border: rgba(120, 90, 200, 0.12);

    /* Accent colors */
    --accent-primary: #9370db;
    --accent-secondary: #7c5cbf;
    --accent-glow: rgba(147, 112, 219, 0.35);
    --accent-gradient: linear-gradient(135deg, #9370db 0%, #6a4fb8 50%, #5e43a8 100%);

    /* Text */
    --text-primary: #e8e0f0;
    --text-secondary: rgba(200, 190, 220, 0.65);
    --text-muted: rgba(160, 150, 180, 0.4);

    /* Status */
    --active-bg: rgba(147, 112, 219, 0.15);
    --active-border: rgba(147, 112, 219, 0.5);
    --active-glow: 0 0 20px rgba(147, 112, 219, 0.2);

    /* Sizing */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ============================================
   Reset & Base
   ============================================ */

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

html {
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: 'Outfit', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
}

/* ============================================
   Starfield Background
   ============================================ */

.stars-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
}

.stars {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-repeat: repeat;
}

.stars-sm {
    background-image:
        radial-gradient(1px 1px at 50px 80px, rgba(255,255,255,0.4), transparent),
        radial-gradient(1px 1px at 180px 150px, rgba(255,255,255,0.3), transparent),
        radial-gradient(1px 1px at 320px 60px, rgba(255,255,255,0.35), transparent),
        radial-gradient(1px 1px at 450px 200px, rgba(255,255,255,0.25), transparent),
        radial-gradient(1px 1px at 100px 300px, rgba(255,255,255,0.3), transparent),
        radial-gradient(1px 1px at 580px 120px, rgba(255,255,255,0.4), transparent),
        radial-gradient(1px 1px at 700px 280px, rgba(255,255,255,0.2), transparent),
        radial-gradient(1px 1px at 250px 400px, rgba(255,255,255,0.35), transparent);
    background-size: 800px 500px;
    animation: drift 120s linear infinite;
}

.stars-md {
    background-image:
        radial-gradient(1.5px 1.5px at 120px 200px, rgba(200,180,255,0.5), transparent),
        radial-gradient(1.5px 1.5px at 400px 90px, rgba(200,180,255,0.4), transparent),
        radial-gradient(1.5px 1.5px at 550px 350px, rgba(200,180,255,0.35), transparent),
        radial-gradient(1.5px 1.5px at 250px 120px, rgba(200,180,255,0.45), transparent),
        radial-gradient(1.5px 1.5px at 650px 180px, rgba(200,180,255,0.3), transparent);
    background-size: 700px 450px;
    animation: drift 180s linear infinite reverse;
}

.stars-lg {
    background-image:
        radial-gradient(2px 2px at 300px 250px, rgba(147,112,219,0.6), transparent),
        radial-gradient(2px 2px at 600px 100px, rgba(147,112,219,0.5), transparent),
        radial-gradient(2.5px 2.5px at 150px 380px, rgba(147,112,219,0.45), transparent);
    background-size: 900px 500px;
    animation: twinkle 6s ease-in-out infinite alternate, drift 240s linear infinite;
}

@keyframes drift {
    from { transform: translate(0, 0); }
    to { transform: translate(-200px, -100px); }
}

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

/* ============================================
   App Container
   ============================================ */

.app-container {
    position: relative;
    z-index: 1;
    max-width: 640px;
    margin: 0 auto;
    padding: 2rem 1.25rem 4rem;
}

/* ============================================
   Header
   ============================================ */

.app-header {
    text-align: center;
    padding: 2rem 0 2.5rem;
}

.moon-icon {
    margin-bottom: 1rem;
    animation: float 6s ease-in-out infinite;
    filter: drop-shadow(0 0 12px rgba(147, 112, 219, 0.4));
}

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

.app-header h1 {
    font-size: 2.25rem;
    font-weight: 700;
    letter-spacing: -0.5px;
    background: linear-gradient(135deg, #e8e0f0 0%, #c4a8ff 50%, #9370db 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 0.5rem;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1rem;
    font-weight: 300;
    letter-spacing: 0.5px;
}

/* ============================================
   Sections
   ============================================ */

.section {
    margin-bottom: 1.75rem;
}

.section-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
    font-weight: 500;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
    padding-left: 0.25rem;
}

.section-label svg {
    opacity: 0.6;
}

/* ============================================
   Preview Frame
   ============================================ */

.preview-frame {
    width: 100%;
    aspect-ratio: 16 / 9;
    border-radius: var(--radius-lg);
    overflow: hidden;
    position: relative;
    background: #000;
    border: 1px solid var(--bg-card-border);
    box-shadow:
        0 4px 24px rgba(0, 0, 0, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.preview-black {
    position: absolute;
    inset: 0;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity var(--transition-slow);
    z-index: 2;
}

.preview-black.active {
    opacity: 1;
}

.preview-frame video,
.preview-frame img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0;
    transition: opacity var(--transition-slow);
}

.preview-frame video.active,
.preview-frame img.active {
    opacity: 1;
    z-index: 1;
}

/* ============================================
   Background Options
   ============================================ */

.bg-options {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
}

.bg-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.6rem;
    padding: 1rem 0.5rem;
    background: var(--bg-card);
    border: 1px solid var(--bg-card-border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-normal);
    color: var(--text-secondary);
    font-family: 'Outfit', sans-serif;
    font-size: 0.75rem;
    font-weight: 400;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.bg-option:hover {
    background: var(--bg-card-hover);
    border-color: rgba(147, 112, 219, 0.25);
    color: var(--text-primary);
    transform: translateY(-2px);
}

.bg-option.active {
    background: var(--active-bg);
    border-color: var(--active-border);
    color: var(--text-primary);
    box-shadow: var(--active-glow);
}

.bg-option-preview {
    width: 48px;
    height: 32px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.bg-preview-black {
    background: #000;
    border: 1px solid rgba(255,255,255,0.1);
}

.bg-preview-campfire {
    background: linear-gradient(to top, #1a0500, #3d1500, #5c2800);
}

.bg-preview-stars {
    background: linear-gradient(to bottom, #05050f, #0a0a1a, #0f0d20);
}

.bg-preview-aurora {
    background: linear-gradient(135deg, #0a1628, #0d3b3b, #1a3a2a);
}

.bg-preview-nebula {
    background: linear-gradient(135deg, #0d0520, #1a0a3a, #2d1054);
}

.bg-preview-filament {
    background: linear-gradient(135deg, #1a0800, #2a1000, #3d1a08);
}

/* YouTube audio input */
#yt-player-container {
    display: none;
}

.youtube-audio-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: 0.75rem;
    padding: 0.875rem 1rem;
    background: var(--bg-card);
    border: 1px solid var(--bg-card-border);
    border-radius: var(--radius-md);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: var(--text-muted);
    transition: border-color var(--transition-normal), color var(--transition-normal);
}

.youtube-audio-row:focus-within {
    border-color: rgba(147, 112, 219, 0.35);
    color: #ff4444;
}

.youtube-audio-row.active {
    border-color: var(--active-border);
    background: var(--active-bg);
    box-shadow: var(--active-glow);
    color: #ff4444;
}

.youtube-input {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    font-family: 'Outfit', sans-serif;
    font-size: 0.85rem;
    color: var(--text-primary);
    min-width: 0;
}

.youtube-input::placeholder {
    color: var(--text-muted);
}


/* ============================================
   Controls Card (Timer / Sound Duration)
   ============================================ */

.controls-card {
    background: var(--bg-card);
    border: 1px solid var(--bg-card-border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.control-row {
    padding: 0.5rem 0;
}

.control-row + .control-row {
    border-top: 1px solid rgba(120, 90, 200, 0.08);
}

/* Toggle switch */
.toggle-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    width: 100%;
}

.toggle-text {
    font-size: 0.9rem;
    font-weight: 400;
    color: var(--text-primary);
}

.toggle-switch {
    position: relative;
    width: 48px;
    height: 26px;
    flex-shrink: 0;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    inset: 0;
    background: rgba(60, 50, 90, 0.5);
    border-radius: 26px;
    transition: all var(--transition-normal);
    cursor: pointer;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    left: 3px;
    bottom: 3px;
    background: rgba(200, 190, 220, 0.8);
    border-radius: 50%;
    transition: all var(--transition-normal);
}

.toggle-switch input:checked + .toggle-slider {
    background: var(--accent-primary);
    box-shadow: 0 0 12px rgba(147, 112, 219, 0.3);
}

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(22px);
    background: #fff;
}

/* Slider Row */
.slider-row {
    padding-top: 0.75rem;
}

#timer-slider-row,
#duration-slider-row {
    max-height: 0;
    overflow: hidden;
    padding: 0;
    opacity: 0;
    transition: max-height var(--transition-slow), opacity var(--transition-slow), padding var(--transition-slow);
}

#timer-slider-row.visible,
#duration-slider-row.visible {
    max-height: 120px;
    opacity: 1;
    padding: 0.75rem 0 0.5rem;
}

.slider-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
}

.slider-value {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--accent-primary);
    font-variant-numeric: tabular-nums;
}

/* Custom range slider */
.styled-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    background: rgba(60, 50, 90, 0.4);
    border-radius: 3px;
    outline: none;
    cursor: pointer;
    position: relative;
}

.styled-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent-primary);
    cursor: pointer;
    border: 2px solid rgba(255,255,255,0.2);
    box-shadow: 0 0 10px rgba(147, 112, 219, 0.4);
    transition: box-shadow var(--transition-fast), transform var(--transition-fast);
}

.styled-slider::-webkit-slider-thumb:hover {
    box-shadow: 0 0 20px rgba(147, 112, 219, 0.6);
    transform: scale(1.15);
}

.styled-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent-primary);
    cursor: pointer;
    border: 2px solid rgba(255,255,255,0.2);
    box-shadow: 0 0 10px rgba(147, 112, 219, 0.4);
}

.slider-markers {
    display: flex;
    justify-content: space-between;
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 0.4rem;
}

/* ============================================
   Sound Grid
   ============================================ */

.sound-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.75rem;
}

.sound-toggle {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: 1.25rem 0.5rem 1rem;
    background: var(--bg-card);
    border: 1px solid var(--bg-card-border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-normal);
    color: var(--text-secondary);
    font-family: 'Outfit', sans-serif;
    font-size: 0.75rem;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    position: relative;
    overflow: hidden;
}

.sound-toggle::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at 50% 120%, rgba(147, 112, 219, 0.15), transparent 70%);
    opacity: 0;
    transition: opacity var(--transition-normal);
}

.sound-toggle:hover {
    background: var(--bg-card-hover);
    border-color: rgba(147, 112, 219, 0.25);
    color: var(--text-primary);
    transform: translateY(-2px);
}

.sound-toggle.active {
    background: var(--active-bg);
    border-color: var(--active-border);
    color: var(--text-primary);
    box-shadow: var(--active-glow);
}

.sound-toggle.active::before {
    opacity: 1;
}

.sound-icon {
    position: relative;
    z-index: 1;
    opacity: 0.7;
    transition: opacity var(--transition-normal);
}

.sound-toggle.active .sound-icon {
    opacity: 1;
    color: var(--accent-primary);
}

.sound-name {
    position: relative;
    z-index: 1;
    font-weight: 400;
}

.sound-indicator {
    display: flex;
    gap: 3px;
    align-items: flex-end;
    height: 14px;
    position: relative;
    z-index: 1;
    opacity: 0;
    transition: opacity var(--transition-normal);
}

.sound-toggle.active .sound-indicator {
    opacity: 1;
}

.indicator-bar {
    width: 3px;
    background: var(--accent-primary);
    border-radius: 2px;
}

.sound-toggle.active .indicator-bar:nth-child(1) {
    animation: equalizer 0.8s ease-in-out infinite alternate;
    height: 6px;
}

.sound-toggle.active .indicator-bar:nth-child(2) {
    animation: equalizer 0.8s ease-in-out 0.2s infinite alternate;
    height: 10px;
}

.sound-toggle.active .indicator-bar:nth-child(3) {
    animation: equalizer 0.8s ease-in-out 0.4s infinite alternate;
    height: 4px;
}

@keyframes equalizer {
    0% { height: 4px; }
    100% { height: 14px; }
}

/* ============================================
   Start Button
   ============================================ */

.start-section {
    padding-top: 1rem;
}

.start-btn {
    width: 100%;
    padding: 1.25rem 2rem;
    font-family: 'Outfit', sans-serif;
    font-size: 1.2rem;
    font-weight: 600;
    letter-spacing: 0.5px;
    color: #fff;
    background: var(--accent-gradient);
    border: 1px solid rgba(147, 112, 219, 0.4);
    border-radius: var(--radius-xl);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    position: relative;
    overflow: hidden;
    transition: all var(--transition-normal);
    box-shadow:
        0 4px 20px rgba(147, 112, 219, 0.25),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.start-btn:hover {
    transform: translateY(-2px);
    box-shadow:
        0 8px 32px rgba(147, 112, 219, 0.35),
        inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

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

.start-btn-glow {
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 60%);
    animation: pulse-glow 3s ease-in-out infinite;
}

@keyframes pulse-glow {
    0%, 100% { opacity: 0; transform: scale(0.8); }
    50% { opacity: 1; transform: scale(1); }
}

/* ============================================
   Footer
   ============================================ */

.app-footer {
    text-align: center;
    padding: 2rem 0 1rem;
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 300;
}

/* ============================================
   Fullscreen Overlay
   ============================================ */

.fullscreen-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 1.5s ease;
    overflow: hidden;
}

body.fullscreen-active {
    overflow: hidden;
}

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

.fullscreen-overlay.visible {
    opacity: 1;
    pointer-events: all;
}

/* Hide cursor when controls are hidden */
.fullscreen-overlay.cursor-hidden {
    cursor: none;
}

.fullscreen-overlay video,
.fullscreen-overlay img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: none;
}

.fullscreen-overlay video.active,
.fullscreen-overlay img.active {
    display: block;
}

.fullscreen-black {
    position: absolute;
    inset: 0;
    background: #000;
    display: none;
}

.fullscreen-black.active {
    display: block;
}

/* Brightness overlay — sits on top of everything except controls */
.fullscreen-brightness {
    position: absolute;
    inset: 0;
    background: #000;
    opacity: 0;
    z-index: 5;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

/* ── Overlay Controls (auto-hide on idle) ── */
.overlay-controls {
    position: fixed;
    inset: 0;
    z-index: 10000;
    pointer-events: none;
    transition: opacity 0.5s ease;
}

.overlay-controls.hidden {
    opacity: 0;
}

.overlay-controls.visible {
    opacity: 1;
}

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

.exit-btn {
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: rgba(255, 255, 255, 0.6);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-normal);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.exit-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    transform: scale(1.1);
}

/* Overlay slider bar — bottom center */
.overlay-sliders {
    position: absolute;
    bottom: 2.5rem;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    padding: 1rem 1.5rem;
    border-radius: var(--radius-lg);
    border: 1px solid rgba(255, 255, 255, 0.08);
    min-width: 280px;
}

.overlay-slider-group {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: rgba(255, 255, 255, 0.5);
}

.overlay-slider-group svg {
    flex-shrink: 0;
}

.overlay-slider {
    -webkit-appearance: none;
    appearance: none;
    flex: 1;
    height: 4px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}

.overlay-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.85);
    cursor: pointer;
    border: none;
    box-shadow: 0 0 8px rgba(255, 255, 255, 0.3);
}

.overlay-slider::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.85);
    cursor: pointer;
    border: none;
}

.overlay-slider-value {
    font-size: 0.75rem;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.5);
    min-width: 36px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.overlay-timer {
    position: fixed;
    bottom: 8rem;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    padding: 0.5rem 1.5rem;
    border-radius: var(--radius-xl);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.5);
    font-size: 0.85rem;
    font-weight: 400;
    font-variant-numeric: tabular-nums;
    z-index: 10000;
    transition: opacity var(--transition-normal);
}

.overlay-timer.hidden {
    opacity: 0;
}

.overlay-timer.visible {
    opacity: 1;
}

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

@media (max-width: 520px) {
    .app-header h1 {
        font-size: 1.75rem;
    }

    .bg-options,
    .sound-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .app-container {
        padding: 1.5rem 1rem 3rem;
    }

    .start-btn {
        font-size: 1.05rem;
        padding: 1.1rem 1.5rem;
    }
}

@media (max-width: 360px) {
    .app-header h1 {
        font-size: 1.5rem;
    }
}
