/* --- 1. DESIGN SYSTEM (Deep Midnight V3) --- */
:root {
    --bg-dark: #020204;
    --bg-gradient: radial-gradient(circle at 50% -20%, #1a1f35 0%, #020204 60%);
    --glass-bg: rgba(255, 255, 255, 0.03);
    --glass-border: rgba(255, 255, 255, 0.08);
    --glass-highlight: rgba(255, 255, 255, 0.1);

    --text-main: #F0F2F5;
    --text-muted: #8F9BA8;

    --accent-primary: #8E9EAB;
    --accent-glow: rgba(142, 158, 171, 0.4);

    --radius-lg: 24px;
    --radius-md: 16px;
    --font-family: 'Outfit', sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-font-smoothing: antialiased;
}

body {
    background: var(--bg-dark);
    background-image: var(--bg-gradient);
    background-attachment: fixed;
    color: var(--text-main);
    font-family: var(--font-family);
    min-height: 100vh;
    overflow-x: hidden;
    transition: opacity 1.5s ease;
}

/* Ambient Background Animation */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at 80% 80%, rgba(30, 41, 59, 0.2) 0%, transparent 50%);
    pointer-events: none;
    z-index: -1;
    animation: pulseBg 20s infinite alternate ease-in-out;
}

@keyframes pulseBg {
    0% {
        opacity: 0.5;
        transform: scale(1);
    }

    100% {
        opacity: 0.8;
        transform: scale(1.1);
    }
}

/* Layout */
.wrapper {
    max-width: 1100px;
    margin: 0 auto;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 4rem;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 0;
    position: relative;
    z-index: 50;
    /* Higher Z for dropdown */
}

/* Brand & Logo */
.brand {
    display: flex;
    align-items: center;
}

.logo-link {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none !important;
    border: none !important;
    color: var(--text-main);
}

.logo-img {
    height: 48px;
    width: auto;
    filter: drop-shadow(0 0 10px rgba(142, 158, 171, 0.2));
}

.brand-text {
    display: flex;
    flex-direction: column;
}

.brand h1 {
    font-size: 1.6rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    line-height: 1.1;
    background: linear-gradient(to right, #fff, #ccc);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin: 0;
}

.brand span {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 300;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    margin-top: 2px;
}

/* --- GLASSMORPHISM UTILS --- */
.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
}

/* --- CUSTOM DROPDOWN (TIMER) --- */
.custom-select-wrapper {
    position: relative;
    user-select: none;
    width: 140px;
}

.custom-select {
    position: relative;
    display: flex;
    flex-direction: column;
}

.custom-select__trigger {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    font-size: 0.9rem;
    font-weight: 400;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s;
}

.custom-select__trigger:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-main);
}

.advanced-controls {
    margin-bottom: 4rem;
    /* Added spacing */
    display: flex;
    justify-content: center;
    gap: 16px;
    flex-wrap: wrap;
}

.custom-select__trigger span {
    margin-right: 8px;
}

.arrow {
    position: relative;
    height: 8px;
    width: 8px;
}

.arrow::before,
.arrow::after {
    content: '';
    position: absolute;
    bottom: 0px;
    width: 0.1rem;
    height: 100%;
    transition: all 0.3s;
}

.arrow::before {
    left: -2px;
    transform: rotate(45deg);
    background-color: var(--text-muted);
}

.arrow::after {
    left: 2px;
    transform: rotate(-45deg);
    background-color: var(--text-muted);
}

.open .arrow::before {
    transform: rotate(-45deg);
}

.open .arrow::after {
    transform: rotate(45deg);
}

.custom-options {
    position: absolute;
    display: block;
    top: 120%;
    left: 0;
    right: 0;
    background: #111;
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.5);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    z-index: 100;
    transform: translateY(-10px);
    transition: all 0.3s;
    overflow: hidden;
}

.custom-select.open .custom-options {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0);
}

.custom-option {
    position: relative;
    display: block;
    padding: 10px 16px;
    font-size: 0.9rem;
    font-weight: 300;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
    border-bottom: 1px solid rgba(255, 255, 255, 0.02);
}

.custom-option:last-of-type {
    border-bottom: none;
}

.custom-option:hover,
.custom-option.selected {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-main);
}


/* --- QUICK SCAPES (PRESETS) --- */
.presets-container {
    overflow-x: auto;
    white-space: nowrap;
    padding: 10px 4px 15px 4px;
    /* Added top/side padding to prevent hover clipping */
    scrollbar-width: none;
}

.presets-container::-webkit-scrollbar {
    display: none;
}

.preset-scroll {
    display: flex;
    gap: 12px;
}

.preset-chip {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    color: var(--text-muted);
    padding: 10px 20px;
    border-radius: 50px;
    cursor: pointer;
    font-family: var(--font-family);
    font-size: 0.9rem;
    font-weight: 400;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

.preset-chip:hover {
    background: var(--glass-highlight);
    color: var(--text-main);
    border-color: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
}

.preset-chip.active {
    background: var(--text-main);
    color: var(--bg-dark);
    font-weight: 500;
    box-shadow: 0 0 15px rgba(255, 255, 255, 0.2);
}

/* --- SOUND MIXER --- */
.mixer-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 24px;
}

.sound-card {
    position: relative;
    padding: 24px;
    text-align: center;
    border-radius: var(--radius-md);
    transition: transform 0.3s ease, background 0.3s;
    cursor: pointer;
    overflow: hidden;
}

.sound-card::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    padding: 1px;
    background: linear-gradient(to bottom, rgba(255, 255, 255, 0.1), transparent);
    -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    opacity: 0.5;
    pointer-events: none;
}

.sound-card.active {
    background: rgba(255, 255, 255, 0.07);
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.3);
}

.sound-card:active {
    transform: scale(0.98);
}

.icon {
    width: 42px;
    height: 42px;
    margin-bottom: 1rem;
    fill: var(--text-muted);
    transition: fill 0.4s ease, filter 0.4s ease;
}

.sound-card.active .icon {
    fill: var(--text-main);
    filter: drop-shadow(0 0 8px var(--accent-glow));
}

.sound-name {
    display: block;
    margin-bottom: 12px;
    font-size: 0.95rem;
    color: var(--text-main);
}

/* Custom Slider */
input[type=range] {
    width: 100%;
    -webkit-appearance: none;
    background: transparent;
}

input[type=range]::-webkit-slider-runnable-track {
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
}

input[type=range]::-webkit-slider-thumb {
    height: 12px;
    width: 12px;
    border-radius: 50%;
    background: var(--text-main);
    -webkit-appearance: none;
    margin-top: -4px;
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
    transition: transform 0.1s;
}

input[type=range]:hover::-webkit-slider-thumb {
    transform: scale(1.3);
}

/* --- BREATHING GUIDE --- */
.breathing-section {
    padding: 4rem 2rem;
    margin-top: 4rem;
    /* Added spacing */
    text-align: center;
    position: relative;
    overflow: hidden;
}

.circle-container {
    width: 240px;
    height: 240px;
    margin: 0 auto;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}

.breath-ring {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.05);
    /* Outer static ring */
}

.breath-indicator {
    width: 120px;
    height: 120px;
    background: radial-gradient(circle, rgba(142, 158, 171, 0.2) 0%, rgba(142, 158, 171, 0) 70%);
    border-radius: 50%;
    box-shadow: 0 0 50px rgba(142, 158, 171, 0.1);
    transform: scale(1);
    display: flex;
    align-items: center;
    justify-content: center;
}

.breath-label {
    position: absolute;
    font-size: 1.1rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    font-weight: 300;
    color: var(--text-muted);
    transition: color 0.5s;
}

/* Animations */
.anim-inhale {
    animation: inhale 4s ease-in-out forwards;
}

.anim-hold {
    animation: hold 7s linear forwards;
}

.anim-exhale {
    animation: exhale 8s ease-in-out forwards;
}

@keyframes inhale {
    0% {
        transform: scale(1);
        background: rgba(142, 158, 171, 0.2);
    }

    100% {
        transform: scale(2.2);
        background: rgba(142, 158, 171, 0.4);
    }
}

@keyframes hold {
    0% {
        transform: scale(2.2);
        background: rgba(142, 158, 171, 0.4);
    }

    100% {
        transform: scale(2.2);
        opacity: 0.8;
    }
}

@keyframes exhale {
    0% {
        transform: scale(2.2);
        background: rgba(142, 158, 171, 0.4);
    }

    100% {
        transform: scale(1);
        background: rgba(142, 158, 171, 0.2);
    }
}

.btn-modern {
    margin-top: 2rem;
    background: transparent;
    color: var(--text-main);
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 12px 32px;
    border-radius: 50px;
    font-family: inherit;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.3s;
    letter-spacing: 0.05em;
}

.btn-modern:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: #fff;
}

/* Active State for Modern Buttons (Binaural/Nap) */
/* Unified Active State (Orange Gradient) for ALL Control Buttons */
.btn-modern.active,
#btnPowerNap.active {
    background: linear-gradient(45deg, #FF9800, #F44336) !important;
    color: white !important;
    border: none !important;
    box-shadow: 0 0 25px rgba(255, 152, 0, 0.5) !important;
    font-weight: 700 !important;
    transform: scale(1.05);
}

/* Install Button (Glass CTA) */
.btn-glass {

    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: var(--text-main);
    padding: 8px 20px;
    border-radius: 50px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-glass:hover {
    background: rgba(255, 255, 255, 0.2);
    box-shadow: 0 0 15px rgba(255, 255, 255, 0.1);
    transform: translateY(-1px);
}

/* --- CONTENT & FOOTER --- */
article {
    color: var(--text-muted);
    line-height: 1.8;
    font-weight: 300;
    border-top: 1px solid var(--glass-border);
    padding-top: 3rem;
}

article h2 {
    color: var(--text-main);
    margin-top: 2.5rem;
    font-weight: 500;
}

strong {
    color: var(--text-main);
    font-weight: 500;
}

footer {
    text-align: center;
    padding: 3rem 0 1rem;
    color: #444;
    font-size: 0.8rem;
    border-top: 1px solid rgba(255, 255, 255, 0.03);
    margin-top: 3rem;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.footer-links a {
    color: var(--text-muted);
    text-decoration: none;
    margin: 0 10px;
    transition: color 0.3s;
}

.footer-links a:hover {
    color: var(--text-main);
}

/* --- TOOLBAR & MODES --- */
.toolbar {
    display: flex;
    gap: 1.5rem;
    align-items: center;
}

#timerDisplay {
    font-variant-numeric: tabular-nums;
    color: var(--text-main);
    display: none;
}

#timerDisplay.active {
    display: block;
}

/* Blackout Mode */
/* Blackout Mode */
body.blackout section,
body.blackout header,
body.blackout article,
body.blackout footer,
body.blackout .ads-slot,
body.blackout .ads-slot span,
body.blackout .ads-container {
    opacity: 0.03;
    pointer-events: none;
    filter: blur(4px);
    transition: all 1.5s ease;
}

/* Exception for the Dim button itself to allow waking up */
body.blackout #btnDim,
body.blackout .digital-clock {
    opacity: 1;
    /* Button visible but dim? Or just rely on pointer events? User wants clear 'Dim' meaning */
    pointer-events: auto;
    filter: none;
}

body.blackout #btnDim {
    opacity: 0.5;
    /* Increased visibility */
    border-color: rgba(255, 255, 255, 0.4);
    box-shadow: 0 0 15px rgba(255, 255, 255, 0.1);
}

body.blackout #btnDim:hover {
    opacity: 1;
    box-shadow: 0 0 20px rgba(255, 255, 255, 0.3);
}

button#btnDim.dim-active {
    background: rgba(255, 255, 255, 0.2);
    border-color: #fff;
}

.digital-clock {
    position: fixed;
    top: 50%;
    width: 100%;
    text-align: center;
    transform: translateY(-50%);
    font-size: 8rem;
    font-weight: 200;
    opacity: 0;
    pointer-events: none;
    transition: opacity 1s;
}

body.blackout .digital-clock {
    opacity: 0.4;
}

/* Mobile */
@media (max-width: 768px) {
    .wrapper {
        padding: 1.5rem;
        gap: 3rem;
    }

    header {
        flex-direction: column;
        gap: 1.5rem;
        align-items: center;
    }

    .toolbar {
        width: 100%;
        justify-content: center;
        gap: 1rem;
    }

    .digital-clock {
        font-size: 4rem;
    }
}