/* ==========================================================================
    CSS: 공통 스타일 (Common Styles)
    ========================================================================== */

/* CSS 변수를 사용하여 테마(라이트/다크 모드)를 관리합니다. */
:root {
    --primary-color: #2563eb; /* 메인 색상 (파랑) */
    --success-color: #10b981; /* 성공 상태 색상 (초록) */
    --warning-color: #f59e0b; /* 경고 상태 색상 (주황) */
    --danger-color: #ef4444;  /* 위험 상태 색상 (빨강) */
    --long-break-color: #8b5cf6; /* 긴 휴식 색상 (보라) */
    
    /* 라이트 모드 색상 */
    --bg-color: #ffffff;
    --bg-secondary: #f8fafc;
    --text-color: #1f2937;
    --text-muted: #6b7280;
    --border-color: #e5e7eb;
    
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    
    /* 타이머 모드에 따라 동적으로 변하는 색상 */
    --current-mode-color: var(--primary-color);
}

/* 다크 모드일 때 적용될 스타일입니다. */
[data-theme="dark"] {
    --bg-color: #111827;
    --bg-secondary: #1f2937;
    --text-color: #f9fafb;
    --text-muted: #b0b8c4; /* 개선: 색상 대비 향상 */
    --border-color: #374151;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.3);
}

/* 기본 스타일: 모든 요소의 마진과 패딩을 제거하고 box-sizing을 설정합니다. */
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-color);
    color: var(--text-color);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.3s ease, color 0.3s ease;
    padding-top: 6rem; /* 헤더 공간 확보 */
    padding-bottom: 4rem; /* 푸터 공간 확보 */
}

/* 일반 버튼 스타일 */
.btn {
    padding: 0.875rem 2rem;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: var(--shadow);
}
.btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-lg);
}
/* 개선: 터치 피드백 강화 */
.btn:active {
    transform: translateY(1px);
    box-shadow: 0 2px 4px -1px rgba(0, 0, 0, 0.2);
}
.btn-primary { background: var(--primary-color); color: white; }
.btn-success { background: var(--success-color); color: white; }
.btn-secondary { background: var(--border-color); color: var(--text-color); }
.btn-danger { background: var(--danger-color); color: white; }

/* 메인 컨테이너 */
.container {
    text-align: center;
    padding: 2rem;
    max-width: 600px;
    width: 100%;
}

/* 제어 버튼 (시작, 초기화 등) */
.controls {
    display: flex;
    gap: 1rem;
    justify-content: center;
    margin: 2rem 0;
    flex-wrap: wrap;
}

/* 모달 공통 스타일 */
.modal {
    display: none; 
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.5); 
    z-index: 1000; 
    align-items: center; justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease; /* 개선: 모달 애니메이션 */
}
.modal.active { 
    display: flex;
    opacity: 1;
}
.modal-content {
    background: var(--bg-color); padding: 2rem; border-radius: 16px;
    max-width: 500px; width: 90%; max-height: 80vh; overflow-y: auto;
    box-shadow: var(--shadow-lg); position: relative;
    transform: scale(0.9);
    transition: transform 0.3s ease; /* 개선: 모달 애니메이션 */
}
.modal.active .modal-content {
    transform: scale(1);
}
.modal-header { font-size: 1.25rem; font-weight: 600; margin-bottom: 1.5rem; }
.modal-close {
    position: absolute; top: 1rem; right: 1rem; background: none; border: none;
    font-size: 1.5rem; cursor: pointer; color: var(--text-color);
}
.modal-footer { margin-top: 1.5rem; text-align: right; display: flex; gap: 0.5rem; justify-content: flex-end; }

/* 모달 안의 폼 스타일 */
.form-group { margin-bottom: 1rem; text-align: left; }
.form-group label { display: block; margin-bottom: 0.5rem; font-weight: 500; }
.form-group input {
    width: 100%; padding: 0.75rem; border: 2px solid var(--border-color);
    border-radius: 8px; background: var(--bg-color); color: var(--text-color);
    font-size: 1rem; font-family: inherit;
}
.form-group input:focus { outline: none; border-color: var(--primary-color); }

/* 설정 패널 공통 스타일 */
.settings-toggle, .help-toggle, .theme-toggle {
    position: absolute;
    top: 2rem;
    background: var(--border-color);
    border: none;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.2rem;
    transition: all 0.2s ease;
    z-index: 10;
}
.settings-toggle { left: 2rem; }
.theme-toggle { right: 2rem; }
.help-toggle { right: 5.5rem; }
.main-nav {
    position: absolute;
    top: 2rem;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 0.5rem;
    align-items: center;
    background-color: var(--border-color);
    padding: 0.5rem;
    border-radius: 99px;
    font-size: 0.9rem;
    z-index: 10;
}
.main-nav a {
    text-decoration: none;
    color: var(--text-color);
    opacity: 0.7;
    font-weight: 500;
    padding: 0.35rem 1rem;
    border-radius: 99px;
    transition: all 0.2s ease;
    min-width: 44px; /* 개선: 터치 영역 확보 */
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.main-nav a.active {
    background-color: var(--bg-color);
    color: var(--primary-color);
    opacity: 1;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.settings-panel {
    position: fixed; top: 0; left: -300px; width: min(300px, 80vw); /* 개선: 반응형 너비 */ height: 100vh;
    background: var(--bg-color); border-right: 1px solid var(--border-color);
    padding: 2rem; transition: left 0.3s ease; z-index: 20;
    box-shadow: var(--shadow-lg); overflow-y: auto;
}
.settings-panel.open { left: 0; }
.settings-overlay {
    position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(0, 0, 0, 0.5); z-index: 15; opacity: 0;
    visibility: hidden; transition: all 0.3s ease;
}
.settings-overlay.open { opacity: 1; visibility: visible; }
.setting-item { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.75rem; }
.toggle-switch {
    position: relative; width: 44px; height: 24px; background: var(--border-color);
    border-radius: 12px; cursor: pointer; transition: background 0.2s ease;
}
.toggle-switch.active { background: var(--primary-color); }
.toggle-switch::after {
    content: ''; position: absolute; top: 2px; left: 2px; width: 20px;
    height: 20px; background: white; border-radius: 50%; transition: transform 0.2s ease;
}
.toggle-switch.active::after { transform: translateX(20px); }

/* 도움말 모달 콘텐츠 스타일 */
.help-section { margin-bottom: 1.5rem; text-align: left; }
.help-section h3 { font-size: 1.1rem; font-weight: 600; margin-bottom: 0.75rem; }
.help-section p { line-height: 1.6; color: var(--text-muted); }
.shortcut-list { list-style: none; padding: 0; }
.shortcut-list li { display: flex; align-items: center; margin-bottom: 0.75rem; }
.shortcut-key {
    background: var(--border-color); border-radius: 6px; padding: 0.25rem 0.6rem;
    margin-right: 1rem; font-family: 'monospace'; font-weight: 500;
    min-width: 80px; text-align: center;
}
.shortcut-desc { color: var(--text-muted); font-size: 0.9rem; }

/* 반응형 디자인 (모바일 화면) */
@media (max-width: 768px) {
    body { padding-top: 5rem; padding-bottom: 4rem; }
    .main-nav { top: 1rem; font-size: 0.8rem; }
    .theme-toggle, .settings-toggle, .help-toggle { top: 1rem; width: 40px; height: 40px; }
    .help-toggle { right: 4.5rem; }
    .theme-toggle { right: 1rem; }
    .settings-toggle { left: 1rem; }
    .btn { padding: 0.75rem 1.5rem; min-width: 80px; }
    .container { padding: 1.5rem; }
}

/* 접근성을 위한 스타일 */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.btn:focus, input:focus, .toggle-switch:focus { outline: 2px solid var(--primary-color); outline-offset: 2px; }


/* ==========================================================================
    CSS: 타이머 전용 스타일 (Timer-specific Styles)
    ========================================================================== */

.timer-display {
    font-size: clamp(4rem, 15vw, 8rem);
    font-weight: 300;
    margin: 1rem 0;
    font-variant-numeric: tabular-nums; /* 숫자 너비 고정 */
    transition: color 0.3s ease; /* 개선: 색상 전환 애니메이션 */
    color: var(--current-mode-color);
}
.timer-display.pulse { animation: pulse 1s ease-in-out; }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.05); } }

.pomodoro-status { min-height: 44px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.5rem; margin-bottom: 1rem; }
#modeDisplay { font-size: 1.5rem; font-weight: 500; color: var(--current-mode-color); transition: color 0.3s ease; }
#pomodoroCounter { font-size: 1rem; opacity: 0.8; }

.progress-bar { width: 100%; height: 4px; background: var(--border-color); border-radius: 2px; margin: 1.5rem 0; overflow: hidden; }
.progress-fill { height: 100%; background: var(--current-mode-color); border-radius: 2px; transition: width 0.1s linear, background-color 0.3s ease; /* 개선: 성능 최적화 */ width: 0%; }

.presets { display: flex; gap: 0.75rem; justify-content: center; margin: 1.5rem 0; flex-wrap: wrap; }
.preset-btn {
    padding: 0.5rem 1rem; border: 1px solid var(--border-color); border-radius: 20px;
    background: var(--bg-color); color: var(--text-color); font-size: 0.875rem; cursor: pointer;
    transition: all 0.2s ease;
}
.preset-btn:hover, .preset-btn.active { border-color: var(--primary-color); background: var(--primary-color); color: white; transform: translateY(-1px); }

.time-inputs { display: flex; gap: 1rem; justify-content: center; align-items: flex-start; margin: 2rem 0; }
.time-input input {
    width: 60px; padding: 0.5rem; border: 2px solid var(--border-color); border-radius: 8px;
    background: var(--bg-color); color: var(--text-color); font-size: 1.125rem; text-align: center;
}
.time-input label { font-size: 0.875rem; font-weight: 500; opacity: 0.7; }

.error-message {
    background: rgba(239, 68, 68, 0.1); color: var(--danger-color); padding: 0.75rem 1rem;
    border-radius: 8px; margin: 1rem 0; font-size: 0.875rem; display: none;
}

/* ==========================================================================
    CSS: 스톱워치 전용 스타일 (Stopwatch-specific Styles)
    ========================================================================== */

.stopwatch-display { font-family: 'Inter', 'monospace'; font-variant-numeric: tabular-nums; color: var(--primary-color); }
.main-time { font-size: clamp(4rem, 15vw, 8rem); font-weight: 300; letter-spacing: -2px; }
.milliseconds { font-size: clamp(1.5rem, 5vw, 2.5rem); font-weight: 400; color: var(--primary-color); opacity: 0.8; }
.milliseconds.hidden { display: none; }

.laps-container { margin-top: 2rem; max-height: 200px; overflow-y: auto; padding-right: 10px; border: 1px solid var(--border-color); border-radius: 8px; }
.laps-list { list-style: none; text-align: left; font-family: 'Inter', 'monospace'; font-variant-numeric: tabular-nums; }
.lap-item { display: flex; justify-content: space-between; align-items: center; padding: 0.75rem 1rem; border-bottom: 1px solid var(--border-color); }
.lap-item:last-child { border-bottom: none; }
.lap-number-display { font-weight: 500; opacity: 0.7; cursor: pointer; flex-grow: 1; margin-right: 1rem; }
.lap-name-input { flex-grow: 1; padding: 0.25rem 0.5rem; border: 1px solid var(--primary-color); border-radius: 4px; background: var(--bg-secondary); font-size: 0.9rem; margin-right: 1rem; }
.lap-time { font-weight: 500; color: var(--primary-color); flex-shrink: 0; }