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

/* 防止页面加载时的闪烁 */
html {
    /* 确保页面在主题设置完成前不会显示默认样式 */
    visibility: visible;
}

/* 在主题未设置时隐藏内容，避免闪烁 */
html:not([data-theme]) {
    visibility: hidden;
}

/* 页面切换时的平滑过渡 */
body {
    opacity: 1;
    transition: opacity 0.2s ease-in-out;
}

/* 页面加载时的淡入效果 */
body.page-loading {
    opacity: 0;
}

/* 确保所有页面元素在加载完成前保持一致的布局 */
.timer-container {
    min-height: 400px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* 防止Canvas在初始化时闪烁 */
canvas {
    opacity: 1;
    transition: opacity 0.1s ease-in-out;
}

canvas.loading {
    opacity: 0;
}

:root {
    /* 亮色主题 */
    --bg-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --container-bg: rgba(255, 255, 255, 0.95);
    --text-primary: #4a5568;
    --text-secondary: #718096;
    --border-color: #667eea;
    --hourglass-frame: #8b5a3c;
    --shadow: rgba(0, 0, 0, 0.1);
    --btn-hover-shadow: rgba(102, 126, 234, 0.3);
    
    /* 沙漏主题颜色 */
    --hourglass-wood: linear-gradient(135deg, #8b4513 0%, #a0522d 50%, #654321 100%);
    --hourglass-wood-border: #5d2f0f;
    --hourglass-glass-border: #0c1116;
    --hourglass-glass-bg: rgba(78, 78, 69, 0.4);
    --sand-main: linear-gradient(135deg, #f39c12 0%, #e67e22 50%, #d35400 100%);
    --sand-border: #a0522d;
    --sand-top: linear-gradient(180deg, #f4d03f 0%, #f39c12 40%, #e67e22 100%);
    --sand-bottom: linear-gradient(0deg, #d35400 0%, #e67e22 60%, #f39c12 100%);
    --sand-stream: linear-gradient(to bottom, #f39c12, #e67e22);
    --sand-particle: #f39c12; /* Using a brighter color for the splash */
}

[data-theme="dark"] {
    /* 夜间主题 */
    --bg-gradient: linear-gradient(135deg, #1a202c 0%, #2d3748 100%);
    --container-bg: rgba(45, 55, 72, 0.95);
    --text-primary: #e2e8f0;
    --text-secondary: #a0aec0;
    --border-color: #63b3ed;
    --hourglass-frame: #d69e2e;
    --shadow: rgba(0, 0, 0, 0.3);
    --btn-hover-shadow: rgba(99, 179, 237, 0.3);
    
    /* 夜间模式沙漏颜色 */
    --hourglass-wood: linear-gradient(135deg, #b8860b 0%, #daa520 50%, #cd853f 100%);
    --hourglass-wood-border: #8b4513;
    --hourglass-glass-border: #cbd5e0;
    --hourglass-glass-bg: rgba(255,255,255,0.1);
    --sand-main: linear-gradient(135deg, #f39c12 0%, #e67e22 50%, #d35400 100%);
    --sand-border: #b7950b;
    --sand-top: linear-gradient(180deg, #f4d03f 0%, #f39c12 40%, #e67e22 100%);
    --sand-bottom: linear-gradient(0deg, #d35400 0%, #e67e22 60%, #f39c12 100%);
    --sand-stream: linear-gradient(to bottom, #f39c12, #e67e22);
    --sand-particle: #f39c12; /* Using a brighter color for the splash */
}

body {
    font-family: 'Arial', sans-serif;
    background: var(--bg-gradient);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--text-primary);
    /* 移除全局过渡，避免页面切换时的闪烁 */
    transition: background 0.3s ease, color 0.3s ease;
}

.container {
    background: var(--container-bg);
    border-radius: 20px;
    padding: 50px;
    box-shadow: 0 15px 35px var(--shadow);
    max-width: 1350px;
    width: 95%;
    margin: 0 auto;
    /* 只对背景和阴影应用过渡，避免布局变化时的闪烁 */
    transition: background 0.3s ease, box-shadow 0.3s ease;
    display: flex;
    gap: 60px;
    align-items: stretch;
    min-height: 520px;
    justify-content: center;
}

/* Cookie同意弹出框样式 */
.cookie-consent {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--container-bg);
    border-top: 2px solid var(--border-color);
    padding: 20px;
    box-shadow: 0 -5px 20px var(--shadow);
    z-index: 2000;
    transform: translateY(100%);
    transition: transform 0.3s ease;
}

.cookie-consent.show {
    transform: translateY(0);
}

.cookie-content {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
}

.cookie-text h3 {
    color: var(--text-primary);
    margin-bottom: 8px;
    font-size: 1.1em;
}

.cookie-text p {
    color: var(--text-secondary);
    font-size: 0.9em;
    line-height: 1.4;
    margin: 0;
}

.cookie-buttons {
    display: flex;
    gap: 10px;
    flex-shrink: 0;
}

.cookie-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 0.9em;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.cookie-btn.accept {
    background: var(--border-color);
    color: white;
}

.cookie-btn.accept:hover {
    background: #5a67d8;
    transform: translateY(-1px);
}

.cookie-btn.decline {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--text-secondary);
}

.cookie-btn.decline:hover {
    background: var(--text-secondary);
    color: white;
}

/* 响应式设计 */
@media (max-width: 768px) {
    .cookie-content {
        flex-direction: column;
        text-align: center;
        gap: 15px;
    }
    
    .cookie-buttons {
        width: 100%;
        justify-content: center;
    }
    
    .cookie-btn {
        flex: 1;
        max-width: 150px;
    }
}

/* 页面头部导航和主题切换 */
.header {
    position: fixed;
    top: 20px;
    left: 30px;
    right: 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 0;
    z-index: 1000;
}

.page-nav {
    display: flex;
    gap: 10px;
}

.nav-link {
    padding: 8px 16px;
    text-decoration: none;
    color: var(--text-secondary);
    border-radius: 15px;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.3s ease;
}

.nav-link:hover {
    color: var(--border-color);
    background: var(--border-color);
    color: white;
}

.nav-link.active {
    background: var(--border-color);
    color: white;
}

.theme-toggle {
    padding: 8px 12px;
    border: 2px solid var(--border-color);
    background: transparent;
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
}

.theme-toggle:hover {
    background: var(--border-color);
    transform: rotate(15deg) scale(1.1);
}

/* 左侧计时器容器 */
.timer-container {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding-top: 30px;
}

/* 右侧控制面板 */
.control-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 30px 20px;
    position: relative;
    height: 100%;
    justify-content: space-between;
    margin-left: -80px;
}

/* 时间按钮区域 */
.time-buttons-section {
    flex-shrink: 0;
    margin-bottom: 20px;
}

/* 时间选择按钮 */
.time-buttons {
    display: flex;
    justify-content: center;
    gap: 15px;
    flex-wrap: wrap;
}

.time-btn {
    padding: 16px 28px;
    border: 2px solid var(--border-color);
    background: transparent;
    color: var(--border-color);
    border-radius: 25px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 600;
    transition: all 0.3s ease;
    min-width: 105px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.time-btn:hover {
    background: var(--border-color);
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px var(--btn-hover-shadow);
}

.time-btn.active {
    background: var(--border-color);
    color: white;
}

/* 暂停状态下的时间按钮提示 */
.time-buttons.paused-highlight::before {
    content: '💡 You can switch time when paused';
    position: absolute;
    top: -25px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 12px;
    color: var(--text-secondary);
    opacity: 0;
    animation: fadeInOut 3s ease-in-out;
}

.time-buttons.paused-highlight .time-btn {
    animation: pulseGlow 2s ease-in-out infinite;
}

@keyframes fadeInOut {
    0%, 100% { opacity: 0; }
    10%, 90% { opacity: 1; }
}

@keyframes pulseGlow {
    0%, 100% { 
        box-shadow: 0 0 0 0 rgba(102, 126, 234, 0.4);
    }
    50% { 
        box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.2);
    }
}

/* 沙漏容器 */
.hourglass-container {
    display: flex;
    justify-content: center;
}

.hourglass {
    position: relative;
    width: 200px;
    height: 320px;
    display: flex;
    flex-direction: column; /* Changed for easier alignment of chambers */
    align-items: center;
    justify-content: center;
    filter: drop-shadow(0 8px 20px var(--shadow)) drop-shadow(0 4px 8px rgba(0,0,0,0.15));
}

/* 沙漏主体框架 */
.hourglass-frame {
    position: absolute; /* Take frame out of flow */
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    z-index: 2;
}

/* 木质顶盖 */
.hourglass-frame::before {
    content: '';
    position: absolute;
    top: -6px;
    left: 5%;
    right: 5%;
    height: 18px;
    background: var(--hourglass-wood);
    border-radius: 8px;
    z-index: 5;
    border: 2px solid var(--hourglass-wood-border);
    box-shadow: 
        0 2px 4px var(--shadow),
        inset 0 1px 0 rgba(255,255,255,0.2);
}

/* 木质底座 */
.hourglass-frame::after {
    content: '';
    position: absolute;
    bottom: -6px;
    left: 5%;
    right: 5%;
    height: 18px;
    background: var(--hourglass-wood);
    border-radius: 8px;
    z-index: 5;
    border: 2px solid var(--hourglass-wood-border);
    box-shadow: 
        0 2px 4px var(--shadow),
        inset 0 1px 0 rgba(255,255,255,0.2);
}

/* 上半部分容器 */
.top-chamber {
    width: 100%;
    height: 50%; /* Adjusted to 50% */
    position: relative;
    overflow: hidden;
    clip-path: polygon(10% 0, 90% 0, 55% 100%, 45% 100%);
    background: var(--hourglass-glass-bg);
    border: 4px solid var(--hourglass-glass-border);
    border-bottom: none; /* Neck is now handled by the stream container */
    box-shadow: 
        inset 0 2px 4px rgba(0,0,0,0.2),
        inset 2px 0 4px rgba(0,0,0,0.15),
        inset -2px 0 4px rgba(0,0,0,0.15);
}

/* 下半部分容器 */
.bottom-chamber {
    width: 100%;
    height: 50%; /* Adjusted to 50% */
    position: relative;
    overflow: hidden;
    clip-path: polygon(45% 0, 55% 0, 90% 100%, 10% 100%);
    background: var(--hourglass-glass-bg);
    border: 4px solid var(--hourglass-glass-border);
    border-top: none;
    box-shadow: 
        inset 0 -2px 4px rgba(0,0,0,0.2),
        inset 2px 0 4px rgba(0,0,0,0.15),
        inset -2px 0 4px rgba(0,0,0,0.15);
}

/* --- NEW ANIMATION STYLES ---
The following styles replace the old static sand piles.
These elements are animated dynamically by JavaScript.
*/

/* 沙子元素基类 */
#topSand, #bottomSand {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transition: clip-path 0.05s linear; /* Smooths the shape change */
}

/* 顶部沙子 */
#topSand {
    background: var(--sand-top);
    /* Initial state set by JS: polygon(0 0, 100% 0, 100% 100%, 0 100%) */
}

/* 底部沙子 */
#bottomSand {
    background: var(--sand-bottom);
    /* Initial state set by JS: polygon(50% 0, 50% 0, 50% 0, 50% 0) */
}

/* 下落的沙流 */
#fallingStream {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 2px;
    height: 10%; /* Stream height */
    background: var(--sand-stream);
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 10;
}

/* 沙滴涟漪/飞溅效果 */
#sandDropAnimation {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    width: 20px;
    height: 20px;
    background: radial-gradient(circle, var(--sand-particle) 5%, transparent 60%);
    border-radius: 50%;
    opacity: 0;
    z-index: 11;
    top: 100%; /* JS will update this position */
}

/* 状态：计时器运行时 */
.hourglass.running #fallingStream {
    opacity: 1;
}

.hourglass.running #sandDropAnimation {
    animation: sand-drop 0.5s infinite linear;
}

/* 涟漪动画的关键帧 */
@keyframes sand-drop {
    0% {
        opacity: 0;
        transform: translateX(-50%) scale(0.5);
    }
    50% {
        opacity: 0.7;
    }
    100% {
        opacity: 0;
        transform: translateX(-50%) scale(1.5);
    }
}

/* --- END OF NEW ANIMATION STYLES --- */


/* 时间显示 */
.time-display {
    margin: 0;
}

/* 中央时间显示区域 */
.time-display {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 20px 0;
    min-height: 250px;
    position: relative;
}

#timeLeft {
    font-size: 12em;
    font-weight: 800;
    color: var(--text-primary);
    font-family: 'Arial Black', 'Helvetica Neue', Arial, sans-serif;
    text-shadow: 
        0 4px 8px var(--shadow),
        0 2px 4px var(--shadow);
    letter-spacing: 0.02em;
    margin: 0;
    line-height: 0.9;
    position: relative;
    display: block;
    transform: scale(1.1);
}

/* 毫秒显示 */
#milliseconds {
    position: absolute;
    bottom: 0;
    right: -50px;
    font-size: 2.2em;
    font-weight: 600;
    color: var(--text-secondary);
    font-family: 'Arial', 'Helvetica Neue', Arial, sans-serif;
    opacity: 0.8;
    text-shadow: 
        0 2px 4px var(--shadow);
}

/* 控制按钮区域 */
.controls-section {
    flex-shrink: 0;
    margin: 20px 0;
}

/* 控制按钮 */
.controls {
    display: flex;
    justify-content: center;
    gap: 20px;
}

.control-btn {
    padding: 16px 32px;
    border: none;
    border-radius: 25px;
    font-size: 18px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    min-width: 115px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

#startBtn {
    background: #48bb78;
    color: white;
}

#startBtn:hover:not(:disabled) {
    background: #38a169;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(72, 187, 120, 0.3);
}

#pauseBtn {
    background: #ed8936;
    color: white;
}

#pauseBtn:hover:not(:disabled) {
    background: #dd6b20;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(237, 137, 54, 0.3);
}

#resetBtn {
    background: #e53e3e;
    color: white;
}

#resetBtn:hover {
    background: #c53030;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(229, 62, 62, 0.3);
}

.control-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

/* 状态指示区域 */
.status-section {
    flex-shrink: 0;
}

/* 状态指示 */
#status { /* Changed to ID to match JS */
    color: var(--text-secondary);
    font-size: 18px;
    font-weight: 500;
    margin: 0;
    text-align: center;
    opacity: 0.8;
}

/* 完成状态样式 */
.hourglass.completed { /* Tied pulse to hourglass */
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}

/* 底部导航栏样式 */
.footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--container-bg);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--border-color);
    padding: 10px 0;
    z-index: 1000;
    box-shadow: 0 -2px 10px var(--shadow);
    transition: all 0.3s ease;
}

.footer-content {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    font-size: 13px;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

.footer-link {
    color: var(--text-secondary);
    text-decoration: none;
    transition: all 0.3s ease;
    font-weight: 500;
    padding: 6px 10px;
    border-radius: 6px;
    position: relative;
}

.footer-link:hover {
    color: var(--text-primary);
    background: rgba(0, 0, 0, 0.05);
    transform: translateY(-1px);
}

.footer-separator {
    color: var(--text-secondary);
    font-weight: 300;
    user-select: none;
}

/* 响应式设计 */
@media (max-width: 768px) {
    .container {
        flex-direction: column;
        gap: 20px;
        padding: 20px;
        margin: 15px;
        max-width: 600px;
        min-height: auto;
        align-items: center;
        justify-content: flex-start;
    }
    
    .timer-container {
        padding-top: 15px;
    }
    
    .control-panel {
        padding: 20px 15px;
        gap: 15px;
        justify-content: flex-start;
        margin-left: 0;
    }
    
    .time-buttons-section {
        margin-bottom: 15px;
    }
    
    .header {
        position: fixed;
        top: 15px;
        left: 20px;
        right: 20px;
        padding-bottom: 10px;
    }
    
    .time-buttons {
        gap: 8px;
    }
    
    .time-btn {
        padding: 10px 18px;
        font-size: 14px;
        min-width: 80px;
    }
    
    .hourglass {
        width: 160px;
        height: 250px;
    }
    
    #timeLeft {
        font-size: 5em;
        transform: scale(1);
    }
    
    #milliseconds {
        font-size: 1.6em;
        right: -40px;
        bottom: 0;
    }
    
    .time-display {
        margin: 15px 0;
        min-height: 120px;
        flex: 0;
    }
    
    .controls {
        gap: 10px;
    }
    
    .control-btn {
        padding: 12px 20px;
        font-size: 16px;
        min-width: 90px;
    }
    
    .controls-section {
        margin: 15px 0;
    }
    
    #status {
        font-size: 15px;
    }
    
    /* 移动端底部导航栏样式 */
    .footer {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: var(--container-bg);
        backdrop-filter: blur(10px);
        border-top: 1px solid var(--border-color);
        padding: 8px 0;
        z-index: 1000;
    }
    
    .footer-content {
        display: flex;
        justify-content: center;
        align-items: center;
        gap: 12px;
        font-size: 12px;
    }
    
    .footer-link {
        color: var(--text-secondary);
        text-decoration: none;
        transition: color 0.3s ease;
        font-weight: 500;
    }
    
    .footer-link:hover {
        color: var(--text-primary);
    }
    
    .footer-separator {
        color: var(--text-secondary);
        font-weight: 300;
    }
}