* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    /* 颜色系统 */
    --bg: #f8f9fa;
    --surface: #ffffff;
    --text-primary: #1a1a2e;
    --text-secondary: #6c757d;
    --text-tertiary: #adb5bd;
    --accent: #ff6b6b;
    --accent-light: #ff8787;
    --accent-bg: #fff5f5;
    --success: #51cf66;
    --warning: #ffd43b;
    --danger: #ff6b6b;
    --ring-bg: #e9ecef;
    --ring-track: #dee2e6;
    --border: #e9ecef;
    
    /* 间距 */
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;
    
    /* 圆角 */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --radius-full: 9999px;
    
    /* 阴影 */
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.1);
    
    /* 安全区域 */
    --safe-top: env(safe-area-inset-top, 20px);
    --safe-bottom: env(safe-area-inset-bottom, 20px);
}

html, body {
    height: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
    background: var(--bg);
    color: var(--text-primary);
    overflow: hidden;
    position: fixed;
    width: 100%;
    user-select: none;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ===== 页面容器 ===== */
.page-container {
    display: flex;
    width: 200%;
    height: 100dvh;
    transition: transform 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    will-change: transform;
}

.page-container.swiping {
    transition: none;
}

.page {
    width: 50%;
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    padding: var(--safe-top) var(--spacing-md) calc(60px + var(--safe-bottom));
    -webkit-overflow-scrolling: touch;
}

.page::-webkit-scrollbar { display: none; }
.page { scrollbar-width: none; }

/* ===== 顶部栏 ===== */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-md) 0;
    margin-bottom: var(--spacing-md);
}

.header-left, .header-right {
    width: 44px;
    display: flex;
}

.header-right { justify-content: flex-end; }

.header-center {
    flex: 1;
    text-align: center;
}

.header-center h1 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.5px;
}

.date-display, .date-range {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.icon-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    border-radius: var(--radius-full);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.icon-btn:active {
    background: var(--bg);
    transform: scale(0.95);
}

/* ===== 主要内容区 ===== */
.main-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-lg);
    padding: 0 var(--spacing-sm);
}

/* ===== 圆环容器 ===== */
.ring-container {
    width: 100%;
    display: flex;
    justify-content: center;
    padding: var(--spacing-md) 0;
}

.ring-wrapper {
    position: relative;
    width: 240px;
    height: 240px;
}

.ring-svg {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
    filter: drop-shadow(0 4px 12px rgba(0,0,0,0.1));
}

.ring-bg {
    fill: none;
    stroke: var(--ring-bg);
    stroke-width: 12;
}

.ring-progress {
    fill: none;
    stroke: var(--accent);
    stroke-width: 12;
    stroke-linecap: round;
    stroke-dasharray: 722.57;
    stroke-dashoffset: 722.57;
    transition: stroke-dashoffset 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.ring-center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-xs);
}

.ring-count {
    font-size: 64px;
    font-weight: 200;
    color: var(--text-primary);
    line-height: 1;
    font-variant-numeric: tabular-nums;
    transition: transform 0.15s ease;
}

.ring-count.bump { 
    transform: scale(1.05);
}

.ring-unit {
    font-size: 16px;
    color: var(--text-secondary);
    font-weight: 400;
}

/* ===== 记录按钮 ===== */
.record-section {
    width: 100%;
    display: flex;
    justify-content: center;
    padding: var(--spacing-md) 0;
}

.record-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    width: 100%;
    max-width: 280px;
    padding: var(--spacing-md) var(--spacing-xl);
    background: var(--accent);
    border: none;
    border-radius: var(--radius-xl);
    font-size: 16px;
    font-weight: 500;
    color: white;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(255, 107, 107, 0.3);
    transition: all 0.2s ease;
}

.record-btn:active {
    transform: scale(0.98);
    box-shadow: 0 2px 8px rgba(255, 107, 107, 0.2);
}

.btn-icon {
    display: flex;
    align-items: center;
}

/* ===== 底部统计 ===== */
.stats-container {
    width: 100%;
    padding: var(--spacing-md) 0;
}

.stats-card {
    display: flex;
    align-items: center;
    justify-content: space-around;
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: var(--spacing-lg);
    box-shadow: var(--shadow-md);
    margin-bottom: var(--spacing-md);
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-xs);
}

.stat-value {
    font-size: 28px;
    font-weight: 600;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

.stat-label {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
}

.stat-divider {
    width: 1px;
    height: 40px;
    background: var(--border);
}

.stats-note {
    text-align: center;
    font-size: 13px;
    color: var(--text-secondary);
    padding: 0 var(--spacing-md);
}

/* ===== 滑动提示 ===== */
.swipe-hint {
    position: absolute;
    bottom: calc(20px + var(--safe-bottom));
    left: 0;
    right: 0;
    text-align: center;
    color: var(--text-tertiary);
    font-size: 12px;
    padding: var(--spacing-sm) 0;
}

/* ===== 页面指示器 ===== */
.page-indicator {
    position: fixed;
    bottom: calc(10px + var(--safe-bottom));
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: var(--spacing-sm);
    z-index: 10;
}

.dot {
    width: 6px;
    height: 6px;
    border-radius: var(--radius-full);
    background: var(--text-tertiary);
    transition: all 0.3s ease;
}

.dot.active {
    background: var(--text-primary);
    width: 20px;
    border-radius: 3px;
}

/* ===== 趋势页 ===== */
.tab-bar {
    display: flex;
    background: var(--bg);
    border-radius: var(--radius-md);
    padding: 3px;
    margin-bottom: var(--spacing-lg);
    border: 1px solid var(--border);
}

.tab {
    flex: 1;
    padding: var(--spacing-sm) 0;
    border: none;
    background: transparent;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.25s ease;
}

.tab.active {
    background: var(--surface);
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
}

/* ===== 图表容器 ===== */
.chart-container {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: var(--spacing-md);
    box-shadow: var(--shadow-md);
    margin-bottom: var(--spacing-lg);
}

#trendChart {
    width: 100%;
    height: 220px;
}

/* ===== 趋势统计卡片 ===== */
.trend-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-lg);
}

.trend-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: var(--spacing-md);
    box-shadow: var(--shadow-md);
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.card-header {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.card-icon {
    font-size: 16px;
}

.card-title {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
}

.card-value {
    font-size: 32px;
    font-weight: 600;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

.card-unit {
    font-size: 12px;
    color: var(--text-tertiary);
}

/* ===== 趋势提示 ===== */
.trend-note {
    text-align: center;
    font-size: 14px;
    color: var(--text-secondary);
    padding: var(--spacing-md);
    background: var(--accent-bg);
    border-radius: var(--radius-md);
    margin-bottom: var(--spacing-md);
}

/* ===== 弹窗 ===== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.4);
    z-index: 100;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

.modal-overlay.show {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background: var(--surface);
    width: 100%;
    max-width: 500px;
    max-height: 80vh;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    padding: var(--spacing-lg);
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.modal-overlay.show .modal-content {
    transform: translateY(0);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-lg);
}

.modal-header h3 {
    font-size: 18px;
    font-weight: 600;
}

.modal-close {
    width: 32px;
    height: 32px;
    border: none;
    background: var(--bg);
    border-radius: var(--radius-full);
    font-size: 16px;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.modal-close:active {
    background: var(--border);
    transform: scale(0.95);
}

.modal-body {
    overflow-y: auto;
    max-height: 60vh;
}

.modal-body::-webkit-scrollbar { display: none; }

.history-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-md) 0;
    border-bottom: 1px solid var(--border);
    font-size: 15px;
}

.history-item:last-child { border-bottom: none; }

.history-item .h-time {
    color: var(--text-primary);
    font-weight: 500;
    font-variant-numeric: tabular-nums;
}

.history-item .h-count {
    color: var(--text-secondary);
    font-size: 14px;
}

.history-item .h-del {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: var(--text-tertiary);
    font-size: 16px;
    cursor: pointer;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.history-item .h-del:active { 
    background: var(--accent-bg); 
    color: var(--danger); 
}

.history-empty {
    text-align: center;
    color: var(--text-tertiary);
    padding: var(--spacing-xl) 0;
    font-size: 14px;
}

/* ===== 设置 ===== */
.settings-body { 
    padding: var(--spacing-sm) 0; 
}

.setting-group {
    margin-bottom: var(--spacing-lg);
}

.setting-group h4 {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: var(--spacing-md);
    padding-left: var(--spacing-xs);
}

.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-md);
    background: var(--bg);
    border-radius: var(--radius-md);
}

.setting-info {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
}

.setting-title {
    font-size: 15px;
    color: var(--text-primary);
    font-weight: 500;
}

.setting-desc {
    font-size: 12px;
    color: var(--text-secondary);
}

.setting-control {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
}

.setting-btn {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    border: 1.5px solid var(--border);
    background: var(--surface);
    font-size: 18px;
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.setting-btn:active { 
    background: var(--bg); 
    transform: scale(0.95);
}

.setting-val {
    font-size: 18px;
    font-weight: 600;
    min-width: 32px;
    text-align: center;
    color: var(--text-primary);
}

.setting-action {
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--accent);
    border: none;
    border-radius: var(--radius-full);
    font-size: 14px;
    font-weight: 500;
    color: white;
    cursor: pointer;
    transition: all 0.2s ease;
}

.setting-action:active {
    transform: scale(0.95);
    opacity: 0.9;
}

/* ===== Toast ===== */
.toast {
    position: fixed;
    top: calc(60px + var(--safe-top));
    left: 50%;
    transform: translateX(-50%) translateY(-20px);
    background: var(--text-primary);
    color: white;
    padding: var(--spacing-sm) var(--spacing-lg);
    border-radius: var(--radius-full);
    font-size: 13px;
    font-weight: 500;
    opacity: 0;
    transition: all 0.3s ease;
    pointer-events: none;
    z-index: 200;
    white-space: nowrap;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ===== 响应式调整 ===== */
@media (max-width: 320px) {
    .ring-wrapper {
        width: 200px;
        height: 200px;
    }
    
    .ring-count {
        font-size: 48px;
    }
    
    .stats-card {
        padding: var(--spacing-md);
    }
    
    .stat-value {
        font-size: 24px;
    }
}

@media (min-width: 768px) {
    .page {
        padding: var(--spacing-xl) var(--spacing-xl) calc(80px + var(--safe-bottom));
    }
    
    .main-content {
        max-width: 400px;
        margin: 0 auto;
    }
    
    .trend-stats {
        grid-template-columns: repeat(4, 1fr);
    }
}