:root {
    /* Default Dark Mode */
    --bg-color: #000;
    --container-bg: rgba(15, 15, 15, 0.85);
    --text-muted: #444;
    --border-color: rgba(255, 255, 255, 0.05);
    
    /* Variables */
    --main-color: #2830cc;
    --glow-blur: 15px;
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --transition-main: all 0.8s var(--ease-out);
    --applied-size: 8rem;
}

/* Light Mode Overrides */
[data-theme="light"] {
    --bg-color: #f0f0f0;
    --container-bg: rgba(255, 255, 255, 0.9);
    --text-muted: #aaa;
    --border-color: rgba(0, 0, 0, 0.1);
}

* { box-sizing: border-box; }

body { 
    position: relative;
    font-family: 'Montserrat', sans-serif; 
    display: flex; 
    justify-content: center; 
    align-items: center; 
    min-height: 100vh; 
    background: var(--bg-color);
    transition: background 0.5s ease;
    margin: 0;
    color: #eee;
    overflow: hidden;
    touch-action: none;
}

#clock-container {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: fit-content;
    max-width: 95vw;
    max-height: 95vh;
    height: auto;
    min-height: fit-content;
    overflow: visible;
    padding: 2rem 4rem;
    background: var(--container-bg);
    border: 1px solid var(--border-color);
    backdrop-filter: blur(15px);
    border-radius: 40px;
    z-index: 1;
    transition: var(--transition-main);
    will-change: opacity, transform;
}

#orbit-ring {
    position: absolute;
    inset: 0; 
    padding: 4px; 
    border-radius: 40px; 
    background: conic-gradient(from var(--angle), transparent 50%, var(--main-color));
    -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    animation: rotateOrbit 3s linear infinite;
    pointer-events: none;
    z-index: 5;
    will-change: transform;
    transition: background 0.5s ease; /* Smooth transition when toggling rainbow off */
}

/* --- RAINBOW ORBIT OVERRIDE --- */
#clock-container.rainbow-orbit #orbit-ring {
    background: conic-gradient(
        from var(--angle), 
        transparent 50%,
        #ff0000,           
        #ffff00,         
        #00ff00,     
        #00ffff,
        #0000ff,
        #8b00ff,           
        transparent 100%
    );
}

@property --angle {
  syntax: '<angle>';
  initial-value: 0deg;
  inherits: false;
}

@keyframes rotateOrbit {
    to { --angle: 360deg; }
}

#time {
    font-weight: 800; 
    color: var(--main-color);
    text-shadow: 0 0 var(--glow-blur) var(--main-color);
    font-size: clamp(2rem, 18vw, var(--applied-size));
    letter-spacing: -3px; 
    z-index: 10;
    cursor: pointer;
    user-select: none;
    transition: var(--transition-main);
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 0.85;
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum";
}

#clock-container.stacked #time { 
    flex-direction: column; 
    font-size: clamp(2rem, 13vw, var(--applied-size)); 
}
#clock-container.stacked .colon { display: none; }

#h, #m { 
    margin: -0.05em 0; 
    display: inline-block;
    min-width: 1.2em;
    text-align: center;
    transition: margin 0.5s var(--ease-out);
}
.colon { opacity: 0.3; transition: opacity 0.5s; font-weight: 300; margin: 0 5px; }

.stacked-sec {
    font-size: 1em; 
    font-weight: 800;
    color: var(--main-color);
    opacity: 0;
    height: 0;
    overflow: hidden;
    transform: translateY(10px);
    transition: all 0.8s var(--ease-out);
    line-height: 0.85;
    display: flex;
    justify-content: center;
    min-width: 1.2em;
    text-align: center;
    margin: -0.05em 0;
}

.hidden-ui .stacked-sec {
    opacity: 1; 
    height: 1em;
    margin-top: -0.05em;
    transform: translateY(0);
    transition-delay: 0.4s; 
}

#clock-container.no-glow #time { text-shadow: none !important; }
#clock-container.no-glow #orbit-ring { opacity: 0.2; }

#fade-controls {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow: hidden;
    max-height: 400px;
    opacity: 1;
    margin-top: 30px;
    transition: var(--transition-main);
}

#fade-controls.hidden-ui { 
    opacity: 0; 
    max-height: 0;
    margin-top: 0;
    pointer-events: none; 
}

.toggle-grid { display: grid; grid-template-columns: 1fr auto 1fr; gap: 12px 20px; align-items: center; width: 100%; max-width: 320px; }
.label-left { text-align: right; color: var(--text-muted); font-size: 0.7rem; font-weight: bold; min-width: 70px; }
.label-right { text-align: left; color: var(--text-muted); font-size: 0.7rem; font-weight: bold; min-width: 70px; }

.controls-divider { width: 100%; max-width: 280px; border-top: 1px solid var(--border-color); padding-top: 25px; margin-top: 20px; display: flex; justify-content: center; }

.size-selector { display: flex; gap: 12px; }
.checkmark {
    display: flex; align-items: center; justify-content: center;
    height: 42px; width: 42px;
    background-color: #0c0c0c;
    border: 1px solid #222;
    border-radius: 50%;
    font-size: 0.8rem; font-weight: bold; color: #555;
    transition: 0.3s;
}

[data-theme="light"] .checkmark { background-color: #ddd; color: #666; border-color: #ccc; }

.size-circle input:checked ~ .checkmark {
    background-color: var(--main-color);
    border-color: #fff;
    color: #fff;
    box-shadow: 0 0 20px var(--main-color);
}
.size-circle { position: relative; cursor: pointer; }
.size-circle input { position: absolute; opacity: 0; }

#clock-settings {
    position: fixed;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    background: #0a0a0a;
    padding: 25px;
    border-radius: 30px;
    border: 1px solid #1a1a1a;
    z-index: 1000;
    width: 280px;
    box-shadow: 0 40px 100px rgba(0,0,0,0.9);
}

[data-theme="light"] #clock-settings {
    background: #fff;
    border-color: #eee;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
}

#settings-header { padding: 10px; cursor: move; color: #333; text-align: center; font-size: 0.6rem; border-bottom: 1px solid #111; margin-bottom: 20px; letter-spacing: 2px;}
[data-theme="light"] #settings-header { color: #aaa; border-bottom-color: #eee; }

.setting-row { display: flex; align-items: center; justify-content: space-between; margin: 15px 0; font-size: 0.85rem; color: #888;}
[data-theme="light"] .setting-row { color: #444; }

#color-picker { 
    appearance: none;
    -webkit-appearance: none;
    border: none; width: 40px; height: 40px; background: transparent; cursor: pointer; padding: 0; outline: none; 
}
#color-picker::-webkit-color-swatch { border: 2px solid #fff; border-radius: 50%; }

#glow-slider { accent-color: var(--main-color); width: 120px; cursor: pointer; }

#close-settings-btn {
    width: 100%;
    background: var(--main-color);
    border: none; color: white;
    padding: 12px; border-radius: 12px;
    margin-top: 15px; font-weight: 800;
    cursor: pointer; font-family: 'Montserrat';
    transition: filter 0.3s;
}

.switch { position: relative; width: 44px; height: 22px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; inset: 0; background-color: #111; transition: .4s; border-radius: 20px; border: 1px solid #222; }
.slider:before { position: absolute; content: ""; height: 16px; width: 16px; left: 2px; bottom: 2px; background: #333; transition: .4s; border-radius: 50%; }
input:checked + .slider { background-color: var(--main-color); border-color: rgba(255,255,255,0.1); }
input:checked + .slider:before { transform: translateX(22px); background: #fff; }