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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    touch-action: manipulation;
    flex-wrap: wrap;
    gap: 20px;
    align-content: center; /* Ensures content is centered vertically if wrapping happens with extra height */
}

.container {
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    padding: 40px;
    max-width: 500px;
    width: 100%;
    text-align: center;
}

h1 {
    color: #333;
    font-size: 2.5em;
    margin-bottom: 10px;
    font-weight: 700;
}

.instruction {
    color: #666;
    font-size: 1.1em;
    margin-bottom: 30px;
}

.stats {
    display: flex;
    justify-content: space-around;
    margin-bottom: 40px;
    gap: 20px;
}

.stat-box {
    flex: 1;
    background: #f5f5f5;
    padding: 20px;
    border-radius: 15px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.stat-box .label {
    font-size: 0.9em;
    color: #999;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.stat-box .value {
    font-size: 2.5em;
    font-weight: 700;
    color: #667eea;
}

.stat-box .unit {
    font-size: 0.9em;
    color: #999;
}

.tap-button {
    width: 100%;
    padding: 20px;
    font-size: 1.3em;
    font-weight: 600;
    color: white;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 15px;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-bottom: 20px;
    box-shadow: 0 10px 25px rgba(102, 126, 234, 0.4);
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
}

.tap-button:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 15px 35px rgba(102, 126, 234, 0.6);
}

.tap-button:active:not(:disabled) {
    transform: translateY(0);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.tap-button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.result-container {
    background: #f0f7ff;
    padding: 30px;
    border-radius: 15px;
    border: 2px solid #667eea;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.result-container.hidden {
    display: none;
    opacity: 0;
}

.result-container h2 {
    color: #667eea;
    font-size: 2em;
    margin-bottom: 20px;
}

.result-text {
    font-size: 1.3em;
    color: #333;
    margin-bottom: 15px;
    font-weight: 600;
}

.result-text span {
    color: #667eea;
    font-size: 1.4em;
    font-weight: 700;
}

.result-rate {
    font-size: 1.1em;
    color: #666;
    margin-bottom: 25px;
}

.result-rate span {
    color: #764ba2;
    font-weight: 700;
}

.restart-button {
    padding: 12px 30px;
    font-size: 1.1em;
    font-weight: 600;
    color: white;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.3);
}

.restart-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(102, 126, 234, 0.5);
}

.restart-button:active {
    transform: translateY(0);
}

/* 圖表容器 */
.chart-container {
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    padding: 40px;
    max-width: 500px;
    width: 100%;
    margin: 20px auto;
    text-align: center;
}

.chart-container h2 {
    color: #333;
    font-size: 1.8em;
    margin-bottom: 25px;
    font-weight: 700;
}

.chart-wrapper {
    position: relative;
    height: 300px;
    margin-bottom: 30px;
}

.history-stats {
    display: flex;
    justify-content: space-around;
    gap: 15px;
    margin-bottom: 25px;
}

.history-stat {
    flex: 1;
    background: #f5f5f5;
    padding: 15px;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.history-label {
    font-size: 0.85em;
    color: #999;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.history-value {
    font-size: 1.8em;
    font-weight: 700;
    color: #667eea;
}

.clear-button {
    padding: 10px 20px;
    font-size: 0.95em;
    font-weight: 600;
    color: #999;
    background: #f5f5f5;
    border: 1px solid #ddd;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.clear-button:hover:not(.hidden) {
    color: #e74c3c;
    border-color: #e74c3c;
    background: #ffe6e6;
}

.clear-button.hidden {
    display: none;
}

/* 響應式設計 */
@media (max-width: 600px) {
    .container {
        padding: 30px 20px;
        margin-bottom: 20px; /* Add space between stacked items */
    }

    /* Remove default margin on chart container since we use gap/margin-bottom now */
    .chart-container {
        margin: 0;
    }

    h1 {
        font-size: 2em;
    }

    .stat-box .value {
        font-size: 2em;
    }

    .tap-button {
        padding: 15px;
        font-size: 1.1em;
    }

    .chart-container {
        padding: 25px 15px;
    }

    .chart-container h2 {
        font-size: 1.5em;
    }

    .history-stats {
        flex-direction: column;
        gap: 10px;
    }

    .chart-wrapper {
        height: 250px;
    }
}
