/* Animated liquid background */
body {
    transition: color 0.3s ease-out;
    margin: 0;
    padding: 2vmin;
    min-height: 100vh;
    min-height: 100dvh; /* Dynamic viewport height for mobile */
    box-sizing: border-box;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 50%, #f093fb 100%);
    background-size: 400% 400%;
    animation: gradient-shift 15s ease infinite;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: auto;
}

/* Mobile: less padding to maximize screen space */
@media (max-width: 768px) {
    body {
        padding: 1.5vmin;
    }
}

@media (max-width: 480px) {
    body {
        padding: 1vmin;
        align-items: flex-start;
        padding-top: max(1vmin, env(safe-area-inset-top));
    }
}

/* Landscape: wider layout, less vertical padding */
@media (orientation: landscape) {
    body {
        padding: 1vh 2vw;
        align-items: center;
        overflow: auto;
    }
}

/* Wavy cloud layers for glass to obscure */
body::before,
body::after {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    z-index: 0;
    pointer-events: none;
    mask-image: radial-gradient(ellipse 100% 100% at center, black 40%, transparent 100%);
    -webkit-mask-image: radial-gradient(ellipse 100% 100% at center, black 40%, transparent 100%);
}

/* Mobile: reduce cloud visibility for better content clarity */
@media (max-width: 480px) {
    body::before,
    body::after {
        opacity: 0.6;
    }
}

body::before {
    background: 
        radial-gradient(ellipse 1400px 200px at 20% 30%, rgba(255, 255, 255, 0.58) 0%, rgba(255, 255, 255, 0.27) 40%, transparent 70%),
        radial-gradient(ellipse 1200px 180px at 80% 20%, rgba(255, 255, 255, 0.53) 0%, rgba(255, 255, 255, 0.22) 40%, transparent 70%),
        radial-gradient(ellipse 1600px 220px at 40% 70%, rgba(255, 255, 255, 0.62) 0%, rgba(255, 255, 255, 0.32) 40%, transparent 70%);
    animation: clouds-drift-1 30s ease-in-out infinite;
    filter: blur(22px);
}

body::after {
    background: 
        radial-gradient(ellipse 1500px 190px at 60% 40%, rgba(255, 255, 255, 0.56) 0%, rgba(255, 255, 255, 0.25) 40%, transparent 70%),
        radial-gradient(ellipse 1300px 210px at 30% 80%, rgba(255, 255, 255, 0.6) 0%, rgba(255, 255, 255, 0.3) 40%, transparent 70%),
        radial-gradient(ellipse 1800px 240px at 90% 70%, rgba(255, 255, 255, 0.5) 0%, rgba(255, 255, 255, 0.21) 40%, transparent 70%);
    animation: clouds-drift-2 40s ease-in-out infinite reverse;
    filter: blur(26px);
}

@media (max-width: 768px) {
    body {
        animation: none;
        background-size: 100% 100%;
    }

    body::before,
    body::after {
        animation: none;
        filter: blur(18px);
        mask-image: none;
        -webkit-mask-image: none;
    }
}

@keyframes clouds-drift-1 {
    0%, 100% {
        transform: translate(0, 0) rotate(0deg);
    }
    33% {
        transform: translate(-2%, 1%) rotate(0.5deg);
    }
    66% {
        transform: translate(1%, -2%) rotate(-0.3deg);
    }
}

@keyframes clouds-drift-2 {
    0%, 100% {
        transform: translate(0, 0) rotate(0deg);
    }
    50% {
        transform: translate(1.5%, 1.5%) rotate(-0.8deg);
    }
}

/* Animated gradient background */
@keyframes gradient-shift {
    0% {
        background-position: 0% 50%;
    }
    50% {
        background-position: 100% 50%;
    }
    100% {
        background-position: 0% 50%;
    }
}

/* Floating liquid glass card */
#background {
    max-width: min(1200px, 95vw);
    width: 90%;
    min-height: min(600px, 75vh);
    padding: clamp(16px, 3vmin, 40px);
    background: rgba(255, 255, 255, 0.12);
    backdrop-filter: blur(20px) saturate(160%);
    -webkit-backdrop-filter: blur(20px) saturate(160%);
    border-radius: clamp(12px, 2vmin, 24px);
    border: 1px solid rgba(255, 255, 255, 0.25);
    box-shadow: 
        0 8px 32px 0 rgba(31, 38, 135, 0.37),
        inset 0 0 12px rgba(255, 255, 255, 0.08);
    position: relative;
    z-index: 1;
    overflow: hidden;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    justify-content: space-evenly;
}

/* Mottled glass texture overlay */
#background::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: 
        repeating-linear-gradient(
            45deg,
            transparent,
            transparent 2px,
            rgba(255, 255, 255, 0.03) 2px,
            rgba(255, 255, 255, 0.03) 4px
        ),
        repeating-linear-gradient(
            -45deg,
            transparent,
            transparent 2px,
            rgba(255, 255, 255, 0.02) 2px,
            rgba(255, 255, 255, 0.02) 4px
        );
    opacity: 0.5;
    pointer-events: none;
    z-index: 1;
}

/* Ensure content appears above texture */
#background > * {
    position: relative;
    z-index: 2;
}

/* Mobile-specific adjustments for iPhone */
@media (max-width: 768px) {
    #background {
        width: 96%;
        min-height: min(550px, 70vh);
        padding: clamp(12px, 2.5vmin, 20px);
        max-width: 100%;
        backdrop-filter: blur(14px) saturate(140%);
        -webkit-backdrop-filter: blur(14px) saturate(140%);
    }
}

@media (max-width: 480px) {
    #background {
        width: 98%;
        min-height: min(500px, 65vh);
        padding: clamp(10px, 2vmin, 16px);
    }
}

/* Landscape: wider, more compact */
@media (orientation: landscape) {
    #background {
        width: 98%;
        max-width: 95vw;
        padding: clamp(6px, 1vh, 12px) clamp(12px, 2vw, 24px);
        display: flex;
        flex-direction: column;
        justify-content: center;
    }
}

/* Main title spans full width */
.mainTitle {
    width: 100%;
    text-align: left;
    font-size: clamp(1.25rem, 2.5vw, 2.5rem); /* Responsive font size */
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-weight: 500;
    letter-spacing: -0.02em;
}

.mainTitle h3 {
    font-weight: 600;
    margin: 0;
    padding: 0;
}

/* Mobile portrait: larger title */
@media (max-width: 480px) and (orientation: portrait) {
    .mainTitle {
        font-size: clamp(1.5rem, 6vw, 2rem);
        text-align: center;
    }
}

/* Rounds display spans full width */
.roundsDisplay {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: clamp(1.25rem, 5vw, 2.5rem);
    margin-bottom: clamp(1rem, 2vh, 1.5rem);
    padding-bottom: clamp(0.5rem, 1vh, 1rem);
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    gap: clamp(2rem, 10vw, 6rem);
}

/* Mobile portrait: larger rounds display */
@media (max-width: 480px) and (orientation: portrait) {
    .roundsDisplay {
        font-size: clamp(1.5rem, 6vw, 2rem);
        justify-content: space-around;
        margin-bottom: clamp(1.5rem, 3vh, 2rem);
        padding-bottom: clamp(0.75rem, 1.5vh, 1.5rem);
        border-bottom: 1px solid rgba(255, 255, 255, 0.25);
        gap: clamp(3rem, 15vw, 8rem);
    }
}

/* Timer display adjusts with viewport */
.timerDisplay {
    width: 100%;
    font-size: clamp(3rem, 25vw, 12rem); /* Responsive font size */
    text-align: center;
    font-variant-numeric: tabular-nums; /* Fixed-width digits prevent layout shift */
    margin-top: clamp(0.5rem, 1vh, 1rem);
    margin-bottom: clamp(0.5rem, 1vh, 1rem);
    white-space: nowrap; /* Prevent wrapping */
    overflow: visible; /* Allow overflow rather than wrap */
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: nowrap;
}

/* Mobile portrait: larger timer to fill vertical space */
@media (max-width: 480px) and (orientation: portrait) {
    .timerDisplay {
        font-size: clamp(3rem, 22vw, 7rem);
        letter-spacing: -0.03em; /* Tighter spacing on mobile */
        margin-top: clamp(1rem, 2vh, 1.5rem);
        margin-bottom: clamp(1rem, 2vh, 1.5rem);
    }
}

/* Landscape: use more horizontal space */
@media (orientation: landscape) {
    .timerDisplay {
        font-size: clamp(5rem, 24vh, 16rem);
        letter-spacing: -0.02em;
        margin-top: clamp(0.5rem, 1vh, 1rem);
        margin-bottom: clamp(0.5rem, 1vh, 1rem);
    }
    
    .mainTitle {
        font-size: clamp(1.25rem, 3vh, 2rem);
        text-align: center;
    }
    
    .roundsDisplay {
        font-size: clamp(1.25rem, 3vh, 2rem);
        margin-bottom: clamp(0.5rem, 1.5vh, 1rem);
    }
}

/* Individual digit styling */
.digit {
    display: inline-block;
}

/* Separator styling (colon and period) */
.separator {
    display: inline-block;
    opacity: 0.8;
}

/* Continuous subtle pulse animation for tenths digit */
.digit-tenths {
    will-change: transform, opacity;
    animation: tenths-pulse 0.25s ease-in-out infinite;
}

@keyframes tenths-pulse {
    0%, 100% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.02);
        opacity: 0.95;
    }
}

/* Smooth color transitions for blink states */
body {
    transition: color 0.3s ease-out;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    margin: 0;
    padding: 20px;
    min-height: 100vh;
    box-sizing: border-box;
}

/* Add a subtle glow effect to the timer display */
.timerDisplay {
    text-shadow: 0 0 20px rgba(255, 255, 255, 0.3),
                 0 0 40px rgba(255, 255, 255, 0.2);
}

@media (max-width: 768px) {
    .timerDisplay {
        text-shadow: 0 0 14px rgba(255, 255, 255, 0.25);
    }
}

/* Pulse the entire timer display slightly - only when idle */
@keyframes timer-breathe {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.01);
    }
}

.timerDisplay.timer-idle {
    animation: timer-breathe 4s ease-in-out infinite;
}

/* Button container uses Flexbox */
#buttonDisplay {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
}

/* Buttons adjust based on container width */
#buttonDisplay button {
    flex: 0 0 auto; /* Don't grow, size to content */
    margin: 0.5%;
    min-width: auto;   /* Let content determine width */
    max-width: none;  /* No max restriction */
    font-size: clamp(0.875rem, 1.5vw, 1.5rem); /* Responsive font size */
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-weight: 400;
    letter-spacing: -0.01em;
    color: #283f8a;
    text-shadow: 0 1px 1px rgba(255, 255, 255, 0.35);
    
    /* Enhanced liquid glass effect for buttons */
    background: linear-gradient(
        135deg,
        rgba(140, 200, 255, 0.28) 0%,
        rgba(90, 125, 235, 0.28) 45%,
        rgba(70, 45, 160, 0.3) 100%
    );
    backdrop-filter: blur(12px) saturate(160%);
    -webkit-backdrop-filter: blur(12px) saturate(160%);
    border: 1px solid rgba(130, 175, 255, 0.35);
    border-radius: 12px;
    padding: 10px 16px;
    box-shadow: 
        0 8px 24px 0 rgba(36, 54, 140, 0.25);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1),
        box-shadow 0.3s cubic-bezier(0.4, 0, 0.2, 1),
        background 0.3s cubic-bezier(0.4, 0, 0.2, 1),
        border-color 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

/* Mottled glass texture for buttons */
#buttonDisplay button::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: 
        radial-gradient(circle at 20% 30%, rgba(255, 255, 255, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 80% 70%, rgba(255, 255, 255, 0.08) 0%, transparent 50%),
        repeating-linear-gradient(
            60deg,
            transparent,
            transparent 3px,
            rgba(255, 255, 255, 0.02) 3px,
            rgba(255, 255, 255, 0.02) 6px
        );
    opacity: 0.6;
    pointer-events: none;
}

/* Mobile: smaller buttons that fit better */
@media (max-width: 480px) {
    #buttonDisplay button {
        flex: 0 1 auto;
        min-width: 65px;
        max-width: none;
        font-size: clamp(0.7rem, 3vw, 0.95rem);
        padding: 7px 11px;
        margin: 2px;
        white-space: nowrap;
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
    }
}

/* Landscape: compact buttons in a single row */
@media (orientation: landscape) {
    #buttonDisplay {
        gap: 6px;
        margin-top: 0.5rem;
        flex-wrap: nowrap;
    }
    
    #buttonDisplay button {
        flex: 0 1 auto;
        min-width: auto;
        font-size: clamp(0.7rem, 1.8vw, 0.9rem);
        padding: 5px 11px;
        margin: 0;
        white-space: nowrap;
    }
}

#buttonDisplay button:hover {
    background: linear-gradient(
        135deg,
        rgba(150, 210, 255, 0.35) 0%,
        rgba(100, 135, 245, 0.35) 45%,
        rgba(80, 55, 175, 0.38) 100%
    );
    transform: translateY(-2px);
    box-shadow: 
        0 12px 32px 0 rgba(36, 54, 140, 0.3);
    border-color: rgba(160, 200, 255, 0.55);
}

#buttonDisplay button:active {
    transform: translateY(0);
    background: linear-gradient(
        135deg,
        rgba(120, 180, 245, 0.25) 0%,
        rgba(85, 115, 220, 0.25) 45%,
        rgba(65, 40, 150, 0.28) 100%
    );
    box-shadow: 
        0 4px 12px 0 rgba(36, 54, 140, 0.2);
}
