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

:root {
    --primary: #16213e;
    --secondary: #0f3460;
    --accent: #e94560;
    --success: #00d9a3;
    --text: #ffffff;
    --text-muted: #a0a0a0;
    --bg: #1a1a2e;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
    height: 100vh;
    touch-action: manipulation;
}

/* Screen Management */
.screen {
    display: none;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
}

.screen.active {
    display: flex;
}

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: var(--primary);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

header h1 {
    font-size: 1.5rem;
    font-weight: 600;
}

.end-session-btn,
.history-btn {
    padding: 1.5rem 2rem;
    border: none;
    border-radius: 12px;
    font-size: 1.2rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    min-height: 70px;
}

.end-session-btn {
    background: var(--accent);
    color: var(--text);
}

.end-session-btn:active {
    transform: scale(0.95);
    background: #d63850;
}

.history-btn {
    background: var(--secondary);
    color: var(--text);
}

.history-btn:active {
    transform: scale(0.95);
}

.back-btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    background: var(--secondary);
    color: var(--text);
}

.back-btn:active {
    transform: scale(0.95);
}

/* History Header */
.history-header {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 1rem;
    align-items: center;
}

.history-actions {
    display: flex;
    gap: 0.5rem;
}

.export-btn,
.clear-btn {
    padding: 0.75rem 1rem;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.export-btn {
    background: var(--success);
    color: var(--primary);
}

.export-btn:active {
    transform: scale(0.95);
    background: #00c090;
}

.clear-btn {
    background: var(--accent);
    color: var(--text);
}

.clear-btn:active {
    transform: scale(0.95);
    background: #d63850;
}

/* Counter Container */
.counter-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1rem 2rem;
    gap: 1rem;
    min-height: 0;
}

.counter-display {
    text-align: center;
}

.counter-number {
    font-size: 6rem;
    font-weight: 700;
    color: var(--success);
    line-height: 1;
    text-shadow: 0 0 20px rgba(0, 217, 163, 0.3);
}

.counter-label {
    font-size: 1.5rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
}

/* Count Button */
.count-button {
    width: 100%;
    flex: 1;
    min-height: 0;
    border-radius: 20px;
    border: none;
    background: linear-gradient(135deg, var(--accent) 0%, #ff6b9d 100%);
    color: var(--text);
    font-size: 2rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.1s;
    box-shadow: 0 10px 30px rgba(233, 69, 96, 0.4);
    position: relative;
    overflow: hidden;
}

.count-button:active {
    transform: scale(0.95);
    box-shadow: 0 5px 15px rgba(233, 69, 96, 0.6);
}

.count-button::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: translate(-50%, -50%);
    transition: width 0.3s, height 0.3s;
}

.count-button:active::before {
    width: 200%;
    height: 200%;
}

.tap-instruction {
    position: relative;
    z-index: 1;
}

/* Timer Display */
.timer-display {
    font-size: 2.5rem;
    font-weight: 600;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

/* Stats Display */
.stats-display {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.5rem;
    padding: 0.75rem 1rem 5rem;
    width: 100%;
}

.stat-item {
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.stat-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--success);
    line-height: 1;
}

@media (max-width: 400px) {
    .stat-label {
        font-size: 0.65rem;
    }

    .stat-value {
        font-size: 1.2rem;
    }
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.2s;
}

.modal.active {
    display: flex;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: var(--primary);
    border-radius: 20px;
    padding: 2rem;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    animation: slideUp 0.3s;
}

@keyframes slideUp {
    from {
        transform: translateY(50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-content h2 {
    text-align: center;
    margin-bottom: 1.5rem;
    font-size: 1.8rem;
}

.confirm-message {
    text-align: center;
    color: var(--text-muted);
    margin-bottom: 2rem;
    line-height: 1.5;
}

.session-summary {
    text-align: center;
    margin-bottom: 2rem;
}

.summary-count {
    font-size: 4rem;
    font-weight: 700;
    color: var(--success);
}

.summary-label {
    color: var(--text-muted);
    font-size: 1.2rem;
}

.summary-duration {
    color: var(--text-muted);
    font-size: 1.5rem;
    margin-top: 0.5rem;
    font-variant-numeric: tabular-nums;
}

.edit-section {
    margin-bottom: 2rem;
}

.edit-section label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-muted);
}

.edit-input {
    width: 100%;
    padding: 1rem;
    border: 2px solid var(--secondary);
    border-radius: 10px;
    background: var(--bg);
    color: var(--text);
    font-size: 1.5rem;
    text-align: center;
}

.modal-actions {
    display: flex;
    gap: 1rem;
}

.btn {
    flex: 1;
    padding: 1rem;
    border: none;
    border-radius: 10px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-accept {
    background: var(--success);
    color: var(--primary);
}

.btn-accept:active {
    transform: scale(0.95);
    background: #00c090;
}

.btn-discard {
    background: var(--secondary);
    color: var(--text);
}

.btn-discard:active {
    transform: scale(0.95);
}

/* History Screen */
.history-container {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

/* Month Navigation */
.month-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
    padding: 0.75rem 0;
}

.month-nav-btn {
    background: var(--secondary);
    color: var(--text);
    border: none;
    border-radius: 8px;
    padding: 0.5rem 1rem;
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.2s;
}

.month-nav-btn:active {
    transform: scale(0.95);
}

.month-nav-btn:disabled {
    opacity: 0.3;
    pointer-events: none;
}

.month-label {
    font-size: 1.2rem;
    font-weight: 600;
    min-width: 10rem;
    text-align: center;
}

/* Month Summary */
.month-summary {
    display: flex;
    justify-content: space-around;
    padding: 0.5rem 1rem;
    margin-bottom: 0.5rem;
}

/* Chart */
.chart-container {
    background: var(--primary);
    border-radius: 12px;
    padding: 1rem;
    margin-bottom: 1rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.chart {
    display: flex;
    align-items: flex-end;
    justify-content: space-around;
    height: 200px;
    gap: 1px;
    padding: 0.5rem 0;
    border-bottom: 2px solid var(--secondary);
}

.chart-bar-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    height: 100%;
    min-width: 0;
}

.chart-bar {
    width: 100%;
    background: linear-gradient(to top, var(--accent), var(--success));
    border-radius: 3px 3px 0 0;
    transition: all 0.3s ease;
    position: relative;
    min-height: 2px;
}

.chart-bar-empty {
    background: var(--secondary);
    min-height: 1px;
}

.chart-value {
    font-size: 0.55rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0.15rem;
}

.chart-label {
    font-size: 0.5rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
    text-align: center;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.history-item {
    background: var(--primary);
    border-radius: 12px;
    padding: 1.25rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.history-item-left {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.history-count {
    font-size: 2rem;
    font-weight: 700;
    color: var(--success);
}

.history-date {
    font-size: 0.9rem;
    color: var(--text-muted);
}

.history-time {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.history-duration {
    font-size: 1.1rem;
    color: var(--accent);
    font-weight: 600;
    margin-top: 0.25rem;
    font-variant-numeric: tabular-nums;
}

.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--text-muted);
}

.empty-state p {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.empty-subtitle {
    font-size: 1rem !important;
}

/* Responsive adjustments */
@media (max-width: 400px) {
    .counter-number {
        font-size: 4rem;
    }
}
