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

/* Root Variables */
:root {
    --base-size: 300px; /* Initial conservative size */
    --text-size: calc(var(--base-size) / 17);
    --transition-duration: 0.5s;
    
    /* Circle height-based positioning calculations */
    --circle-height: var(--base-size);
    --translate-position-1: calc(var(--circle-height) * 0.5);    /* Bottom: Line touches top */
    --translate-position-2: calc(var(--circle-height) * 0.25);   /* Lower: 1/4 intersection */
    --translate-position-3: 0px;                                 /* Middle: Center intersection */
    --translate-position-4: calc(var(--circle-height) * -0.25);  /* Upper: 3/4 intersection */
    --translate-position-5: calc(var(--circle-height) * -0.5);   /* Top: Line touches bottom */
}

/* Dark Background */
body {
    background-color: #000;
    color: #fff;
    font-family: Arial, sans-serif;
    overflow: hidden;
}

/* Main Container */
.container {
    position: relative;
    width: 100vw;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

/* Horizon Line */
.horizon-line {
    position: absolute;
    top: 46%;
    left: 0;
    width: 100%;
    height: 1px;
    background-color: #fff;
    transform: translateY(-50%);
    z-index: 1;
}

/* Sun Container */
.sun-container {
    position: absolute;
    left: 50%;
    top: 46%;
    width: var(--circle-height);
    height: var(--circle-height);
    transform: translate(-50%, calc(-50% + var(--circle-offset, 0px)));
    z-index: 2;
    transition: transform var(--transition-duration) cubic-bezier(0.4, 0, 0.2, 1),
                width var(--transition-duration) cubic-bezier(0.4, 0, 0.2, 1),
                height var(--transition-duration) cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform, width, height;
    transform-origin: center;
}

/* Sun Circle */
.sun {
    width: 100%;
    height: 100%;
    background-color: #000;
    border: 2px solid #fff;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: width var(--transition-duration), height var(--transition-duration);
    transform-style: preserve-3d;
    backface-visibility: hidden;
}

/* Sun Content */
.sun-content {
    text-align: center;
    font-size: max(calc(var(--text-size)), 12px); /* Prevent text from becoming too small */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    max-height: 90%;
    width: 90%;
    overflow: auto;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    padding: 2% 0;
}

/* Individual Sun Events */
.sun-event {
    margin: 1px 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    user-select: none;
    -webkit-user-select: none;
    line-height: 1.2;
}

/* New class for closest time event - bold styling */
.current-time-closest {
    font-weight: 900 !important;
    letter-spacing: -0.02em;
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.997);
}

/* Loading and Error Indicators */
#loading-indicator,
#error-container {
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 20px;
    border-radius: 10px;
    text-align: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
    max-width: 280px;
    word-wrap: break-word;
    z-index: 1000;
}

/* Responsive Text Scaling */
@media (max-width: 600px) {
    :root {
        --text-size: calc(var(--base-size) / 20);
    }
    
    .sun-event {
        margin: 1px 0;
        font-size: 0.95em;
    }
    
    .current-time-closest {
        letter-spacing: -0.01em; /* Adjusted for smaller screens */
    }
}

@media (min-width: 601px) and (max-width: 1024px) {
    :root {
        --text-size: calc(var(--base-size) / 17);
    }
}

@media (min-width: 1025px) and (max-width: 1440px) {
    :root {
        --text-size: calc(var(--base-size) / 18);
    }
}

@media (min-width: 1441px) and (max-width: 1920px) {
    :root {
        --text-size: calc(var(--base-size) / 20);
    }
}

/* For very large screens */
@media (min-width: 1921px) {
    :root {
        --text-size: calc(var(--base-size) / 22);
    }
}

/* Additional height-based breakpoint for tall screens */
@media (min-height: 1080px) {
    :root {
        --text-size: calc(var(--base-size) / 20);
    }
}

/* Small screen optimizations */
@media (max-height: 400px), (max-width: 400px) {
    .sun-event {
        font-size: 0.9em;
        margin: 0;
    }
    
    .current-time-closest {
        letter-spacing: 0; /* Remove letter spacing adjustment for very small screens */
    }
}

/* High-DPI Screen Optimizations */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .sun {
        border-width: 1px;
    }
}

/* Print Styles */
@media print {
    body {
        background-color: white;
        color: black;
    }
    
    .sun {
        border: 1px solid black;
        print-color-adjust: exact;
        -webkit-print-color-adjust: exact;
    }
    
    .horizon-line {
        background-color: black;
    }
    
    .current-time-closest {
        font-weight: 900 !important;
        print-color-adjust: exact;
        -webkit-print-color-adjust: exact;
    }
}

/* Landscape orientation handling */
@media (orientation: landscape) {
    .sun-container {
        transform-origin: center center;
    }
}

/* Portrait orientation handling */
@media (orientation: portrait) {
    .sun-container {
        transform-origin: center center;
    }
}

/* Reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
    .sun-container {
        transition-duration: 0.1s;
    }
}

/* Scrollbar Styling */
.sun-content::-webkit-scrollbar {
    width: 0;
    height: 0;
}

.sun-content {
    scrollbar-width: none;
    -ms-overflow-style: none;
}