* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: linear-gradient(135deg, #cddafd 0%, #e7f0ff 100%);
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 20px;
}
.header {
text-align: center;
margin-bottom: 50px;
animation: fadeInDown 1s ease;
}
.header h1 {
font-size: 3rem;
font-weight: 700;
color: #0d1b2a;
margin-bottom: 10px;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
}
.header p {
font-size: 1.2rem;
color: #415a77;
}
@keyframes fadeInDown {
from {
opacity: 0;
transform: translateY(-30px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.timer-container {
background: white;
border-radius: 30px;
padding: 60px 50px;
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
animation: fadeInUp 1s ease 0.3s backwards;
position: relative;
overflow: hidden;
}
.timer-container::before {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
height: 6px;
background: linear-gradient(90deg, #cddafd 0%, #a1c4fd 50%, #cddafd 100%);
background-size: 200% 100%;
animation: shimmer 3s linear infinite;
}
@keyframes shimmer {
0% {
background-position: 200% 0;
}
100% {
background-position: -200% 0;
}
}
@keyframes fadeInUp {
from {
opacity: 0;
transform: translateY(50px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.timer-title {
text-align: center;
font-size: 1.8rem;
color: #0d1b2a;
margin-bottom: 40px;
font-weight: 700;
}
.countdown {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 25px;
margin-bottom: 40px;
}
.time-unit {
text-align: center;
position: relative;
}
.time-box {
background: linear-gradient(135deg, #cddafd 0%, #b8cff5 100%);
border-radius: 20px;
padding: 30px 20px;
box-shadow: 0 10px 30px rgba(205, 218, 253, 0.4);
position: relative;
overflow: hidden;
transition: all 0.3s ease;
}
.time-box:hover {
transform: translateY(-10px);
box-shadow: 0 15px 40px rgba(205, 218, 253, 0.6);
}
.time-box::before {
content: '';
position: absolute;
top: -50%;
left: -50%;
width: 200%;
height: 200%;
background: linear-gradient(45deg, transparent, rgba(255, 255, 255, 0.3), transparent);
transform: rotate(45deg);
animation: shine 3s infinite;
}
@keyframes shine {
0% {
transform: translateX(-100%) translateY(-100%) rotate(45deg);
}
100% {
transform: translateX(100%) translateY(100%) rotate(45deg);
}
}
.time-value {
font-size: 4rem;
font-weight: 700;
color: #0d1b2a;
line-height: 1;
margin-bottom: 10px;
position: relative;
z-index: 1;
animation: pulse 1s ease-in-out infinite;
}
@keyframes pulse {
0%, 100% {
transform: scale(1);
}
50% {
transform: scale(1.05);
}
}
.time-label {
font-size: 1rem;
color: #415a77;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 2px;
position: relative;
z-index: 1;
}
/* Progress Rings */
.progress-ring {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 90%;
height: 90%;
opacity: 0.3;
}
.progress-ring circle {
fill: none;
stroke: #0d1b2a;
stroke-width: 3;
stroke-dasharray: 283;
stroke-dashoffset: 283;
transform: rotate(-90deg);
transform-origin: center;
animation: progress 1s ease-out forwards;
}
@keyframes progress {
to {
stroke-dashoffset: 0;
}
}
/* Controls */
.controls {
display: flex;
gap: 15px;
justify-content: center;
flex-wrap: wrap;
}
.btn {
padding: 15px 35px;
border: none;
border-radius: 15px;
font-size: 1.1rem;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
text-transform: uppercase;
letter-spacing: 1px;
}
.btn-primary {
background: linear-gradient(135deg, #cddafd 0%, #a1c4fd 100%);
color: #0d1b2a;
box-shadow: 0 6px 20px rgba(205, 218, 253, 0.4);
}
.btn-primary:hover {
transform: translateY(-3px);
box-shadow: 0 10px 30px rgba(205, 218, 253, 0.6);
}
.btn-secondary {
background: #e0e0e0;
color: #555;
}
.btn-secondary:hover {
background: #d0d0d0;
transform: translateY(-3px);
}
.btn:active {
transform: translateY(0);
}
/* Custom Time Input */
.time-setter {
background: rgba(205, 218, 253, 0.2);
border-radius: 20px;
padding: 30px;
margin-bottom: 30px;
animation: fadeInUp 1s ease 0.5s backwards;
}
.time-setter h3 {
text-align: center;
color: #0d1b2a;
margin-bottom: 20px;
font-size: 1.3rem;
}
.input-grid {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 15px;
margin-bottom: 20px;
}
.input-group {
text-align: center;
}
.input-group label {
display: block;
color: #415a77;
font-size: 0.9rem;
font-weight: 600;
margin-bottom: 8px;
text-transform: uppercase;
}
.input-group input {
width: 100%;
padding: 12px;
border: 2px solid #cddafd;
border-radius: 10px;
font-size: 1.2rem;
font-weight: 700;
text-align: center;
color: #0d1b2a;
transition: all 0.3s ease;
}
.input-group input:focus {
outline: none;
border-color: #a1c4fd;
box-shadow: 0 0 0 3px rgba(205, 218, 253, 0.3);
}
/* Expired State */
.expired {
text-align: center;
padding: 40px;
animation: zoomIn 0.5s ease;
}
.expired-icon {
font-size: 5rem;
margin-bottom: 20px;
animation: bounce 1s ease infinite;
}
@keyframes zoomIn {
from {
transform: scale(0);
opacity: 0;
}
to {
transform: scale(1);
opacity: 1;
}
}
@keyframes bounce {
0%, 100% {
transform: translateY(0);
}
50% {
transform: translateY(-20px);
}
}
.expired h2 {
color: #0d1b2a;
font-size: 2.5rem;
margin-bottom: 15px;
}
.expired p {
color: #415a77;
font-size: 1.2rem;
}
@media (max-width: 768px) {
.header h1 {
font-size: 2rem;
}
.timer-container {
padding: 40px 30px;
}
.countdown {
grid-template-columns: repeat(2, 1fr);
gap: 15px;
}
.time-value {
font-size: 3rem;
}
.input-grid {
grid-template-columns: repeat(2, 1fr);
}
.controls {
flex-direction: column;
}
.btn {
width: 100%;
}
}
let countdownInterval;
let isPaused = false;
let endTime;
let remainingTime;
function startTimer() {
const days = parseInt(document.getElementById('inputDays').value) || 0;
const hours = parseInt(document.getElementById('inputHours').value) || 0;
const minutes = parseInt(document.getElementById('inputMinutes').value) || 0;
const seconds = parseInt(document.getElementById('inputSeconds').value) || 0;
const totalSeconds = (days * 86400) + (hours * 3600) + (minutes * 60) + seconds;
if (totalSeconds <= 0) {
alert('Please set a valid time!');
return;
}
if (isPaused && remainingTime) {
endTime = Date.now() + remainingTime;
} else {
endTime = Date.now() + (totalSeconds * 1000);
}
isPaused = false;
document.getElementById('startBtn').style.display = 'none';
document.getElementById('pauseBtn').style.display = 'inline-block';
countdownInterval = setInterval(updateCountdown, 100);
}
function updateCountdown() {
const now = Date.now();
remainingTime = endTime - now;
if (remainingTime <= 0) {
clearInterval(countdownInterval);
showExpired();
return;
}
const days = Math.floor(remainingTime / (1000 * 60 * 60 * 24));
const hours = Math.floor((remainingTime % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
const minutes = Math.floor((remainingTime % (1000 * 60 * 60)) / (1000 * 60));
const seconds = Math.floor((remainingTime % (1000 * 60)) / 1000);
document.getElementById('days').textContent = String(days).padStart(2, '0');
document.getElementById('hours').textContent = String(hours).padStart(2, '0');
document.getElementById('minutes').textContent = String(minutes).padStart(2, '0');
document.getElementById('seconds').textContent = String(seconds).padStart(2, '0');
}
function pauseTimer() {
clearInterval(countdownInterval);
isPaused = true;
document.getElementById('startBtn').style.display = 'inline-block';
document.getElementById('pauseBtn').style.display = 'none';
document.getElementById('startBtn').textContent = '▶ Resume';
}
function resetTimer() {
clearInterval(countdownInterval);
isPaused = false;
remainingTime = null;
document.getElementById('days').textContent = '00';
document.getElementById('hours').textContent = '00';
document.getElementById('minutes').textContent = '00';
document.getElementById('seconds').textContent = '00';
document.getElementById('startBtn').style.display = 'inline-block';
document.getElementById('pauseBtn').style.display = 'none';
document.getElementById('startBtn').textContent = '▶ Start';
document.getElementById('timerStatus').textContent = 'Time Remaining';
const countdown = document.getElementById('countdown');
countdown.innerHTML = `
<div class="time-unit">
<div class="time-box">
<svg class="progress-ring" viewBox="0 0 100 100">
<circle cx="50" cy="50" r="45"></circle>
</svg>
<div class="time-value" id="days">00</div>
<div class="time-label">Days</div>
</div>
</div>
<div class="time-unit">
<div class="time-box">
<svg class="progress-ring" viewBox="0 0 100 100">
<circle cx="50" cy="50" r="45"></circle>
</svg>
<div class="time-value" id="hours">00</div>
<div class="time-label">Hours</div>
</div>
</div>
<div class="time-unit">
<div class="time-box">
<svg class="progress-ring" viewBox="0 0 100 100">
<circle cx="50" cy="50" r="45"></circle>
</svg>
<div class="time-value" id="minutes">00</div>
<div class="time-label">Minutes</div>
</div>
</div>
<div class="time-unit">
<div class="time-box">
<svg class="progress-ring" viewBox="0 0 100 100">
<circle cx="50" cy="50" r="45"></circle>
</svg>
<div class="time-value" id="seconds">00</div>
<div class="time-label">Seconds</div>
</div>
</div>
`;
}
function showExpired() {
document.getElementById('timerStatus').textContent = '⏰ Time\'s Up!';
const countdown = document.getElementById('countdown');
countdown.innerHTML = `
<div class="expired" style="grid-column: 1 / -1;">
<div class="expired-icon">🎉</div>
<h2>Countdown Complete!</h2>
<p>The timer has reached zero</p>
</div>
`;
document.getElementById('startBtn').style.display = 'inline-block';
document.getElementById('pauseBtn').style.display = 'none';
document.getElementById('startBtn').textContent = '▶ Start';
}
No comments yet. Be the first!