/* Skip link for accessibility */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--accent, #eb6f63);
    color: #fff;
    padding: 8px 16px;
    z-index: 10000;
    transition: top 0.2s;
    font-size: 14px;
    border-radius: 0 0 4px 0;
}
.skip-link:focus {
    top: 0;
}

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

/* Touch Optimization */
button, a, input, [role="button"], [role="link"] {
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

input[type="text"], textarea {
  -webkit-user-select: text;
  user-select: text;
}

:root {
  --primary: #e74c3c;
  --primary-dark: #c0392b;
  --bg-dark: #0f0f23;
  --bg-secondary: #1a1a2e;
  --bg-tertiary: #2d2d44;
  --text-light: #ffffff;
  --text-secondary: #b0b0b0;
  --success: #00b894;
  --warning: #f39c12;
  --danger: #e74c3c;
  --shadow: rgba(0, 0, 0, 0.3);
  --radius: 16px;
}

/* App Loader */
.app-loader {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--bg-dark, #0f0f23);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.3s;
}
.app-loader.hidden {
    opacity: 0;
    pointer-events: none;
}
.loader-spinner {
    width: 40px; height: 40px;
    border: 3px solid rgba(255,255,255,0.1);
    border-top-color: #e74c3c;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background: linear-gradient(135deg, var(--bg-dark) 0%, var(--bg-secondary) 100%);
  color: var(--text-light);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-touch-callout: none;
}

/* 헤더 */
header {
  padding: 20px;
  background: rgba(15, 15, 35, 0.95);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.header-content {
  flex: 1;
}

.app-title {
  font-size: 24px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--primary), #ff6b5b);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 4px;
}

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

.header-controls {
  display: flex;
  gap: 12px;
  align-items: center;
}

/* 언어 선택기 */
.language-selector {
  position: relative;
  z-index: 100;
}

#lang-toggle {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(231, 76, 60, 0.2);
  border: 1px solid rgba(231, 76, 60, 0.3);
  color: var(--primary);
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
}

#lang-toggle:hover {
  background: rgba(231, 76, 60, 0.3);
  transform: scale(1.05);
}

.lang-menu {
  position: absolute;
  top: 50px;
  right: 0;
  background: var(--bg-secondary);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  max-height: 400px;
  overflow-y: auto;
  backdrop-filter: blur(10px);
  box-shadow: 0 10px 40px var(--shadow);
}

.lang-menu.hidden {
  display: none;
}

.lang-option {
  padding: 12px 16px;
  background: none;
  border: none;
  color: var(--text-light);
  cursor: pointer;
  font-size: 14px;
  white-space: nowrap;
  transition: all 0.2s ease;
  text-align: left;
}

.lang-option:hover {
  background: rgba(231, 76, 60, 0.1);
  color: var(--primary);
}

.lang-option.active {
  background: rgba(231, 76, 60, 0.2);
  color: var(--primary);
  font-weight: 600;
}

/* 메인 컨테이너 */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 20px;
  overflow-y: auto;
}

/* 타이머 섹션 */
.timer-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 30px;
  width: 100%;
  max-width: 400px;
}

.timer-info {
  text-align: center;
}

.timer-label {
  font-size: 16px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 8px;
  font-weight: 600;
}

/* 원형 타이머 */
.timer-display {
  position: relative;
  width: 280px;
  height: 280px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

.timer-circle {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: conic-gradient(
    var(--primary) 0deg,
    var(--primary) calc(var(--progress, 0) * 360deg),
    rgba(255, 255, 255, 0.1) calc(var(--progress, 0) * 360deg),
    rgba(255, 255, 255, 0.1) 360deg
  );
  padding: 8px;
}

.timer-circle::after {
  content: '';
  position: absolute;
  inset: 8px;
  border-radius: 50%;
  background: var(--bg-secondary);
}

.timer-content {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.timer-time {
  font-size: 64px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--primary);
}

.timer-period {
  font-size: 14px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* 타이머 통계 */
.timer-stats {
  display: flex;
  justify-content: space-around;
  width: 100%;
  padding: 20px;
  background: rgba(29, 29, 46, 0.8);
  border-radius: var(--radius);
  border: 1px solid rgba(255, 255, 255, 0.1);
  gap: 12px;
}

.stat-item {
  text-align: center;
  flex: 1;
}

.stat-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--primary);
}

.stat-label {
  font-size: 11px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 4px;
}

/* 컨트롤 버튼 */
.controls {
  display: flex;
  gap: 12px;
  width: 100%;
  justify-content: center;
}

.btn {
  padding: 14px 28px;
  border: none;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  flex: 1;
  box-shadow: 0 4px 15px rgba(231, 76, 60, 0.3);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(231, 76, 60, 0.4);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-light);
  border: 1px solid rgba(255, 255, 255, 0.2);
  flex: 1;
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.3);
}

.btn-icon {
  width: 44px;
  padding: 0;
  background: rgba(231, 76, 60, 0.2);
  color: var(--primary);
  border: 1px solid rgba(231, 76, 60, 0.3);
  font-size: 20px;
}

.btn-icon:hover {
  background: rgba(231, 76, 60, 0.3);
}

/* 모달 */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 200;
  animation: fadeIn 0.3s ease;
}

.modal.active {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 200;
}

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

@keyframes slideUp {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

.modal-content {
  background: var(--bg-secondary);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 24px;
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  animation: slideUp 0.3s ease;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.modal-title {
  font-size: 20px;
  font-weight: 700;
}

.modal-close {
  width: 44px;
  height: 44px;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  border-radius: 50%;
  color: var(--text-light);
  font-size: 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.modal-close:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* 폼 요소 */
.form-group {
  margin-bottom: 20px;
}

.form-label {
  display: block;
  margin-bottom: 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-light);
}

.form-input,
.form-select {
  width: 100%;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  color: var(--text-light);
  font-size: 16px;
  transition: all 0.2s ease;
}

.form-input:focus,
.form-select:focus {
  outline: none;
  border-color: var(--primary);
  background: rgba(255, 255, 255, 0.08);
  box-shadow: 0 0 0 3px rgba(231, 76, 60, 0.1);
}

.form-input::placeholder {
  color: var(--text-secondary);
}

/* 체크박스 */
.checkbox-wrapper {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  cursor: pointer;
}

.checkbox-input {
  width: 20px;
  height: 20px;
  cursor: pointer;
  accent-color: var(--primary);
}

.checkbox-label {
  flex: 1;
  cursor: pointer;
  font-size: 14px;
}

/* 통계 섹션 */
.stats-section {
  margin-bottom: 24px;
}

.stats-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--primary);
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 20px;
}

.stat-card {
  background: rgba(255, 255, 255, 0.05);
  padding: 16px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  text-align: center;
}

.stat-card-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 4px;
}

.stat-card-label {
  font-size: 12px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* 주간 차트 (CSS 바) */
.chart-container {
  background: rgba(255, 255, 255, 0.05);
  padding: 16px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  margin-bottom: 20px;
}

.chart-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text-light);
}

.chart-bars {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  height: 120px;
}

.chart-bar {
  flex: 1;
  background: linear-gradient(180deg, var(--primary), var(--primary-dark));
  border-radius: 4px 4px 0 0;
  position: relative;
  min-height: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.chart-bar:hover {
  opacity: 0.8;
}

.chart-bar::after {
  content: attr(data-value);
  position: absolute;
  top: -24px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
}

.chart-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 12px;
  font-size: 11px;
  color: var(--text-secondary);
}

/* 목표 설정 */
.goal-section {
  background: rgba(231, 76, 60, 0.1);
  border: 1px solid rgba(231, 76, 60, 0.2);
  padding: 16px;
  border-radius: var(--radius);
  margin-bottom: 20px;
}

.goal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.goal-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--primary);
}

.goal-progress {
  width: 100%;
  height: 8px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 8px;
}

.goal-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #ff6b5b);
  border-radius: 4px;
  transition: width 0.3s ease;
}

.goal-text {
  font-size: 12px;
  color: var(--text-secondary);
  text-align: center;
}

/* 프리미엄 섹션 */
.premium-section {
  background: linear-gradient(135deg, rgba(231, 76, 60, 0.15) 0%, rgba(243, 156, 18, 0.1) 100%);
  border: 1px solid rgba(231, 76, 60, 0.2);
  padding: 16px;
  border-radius: var(--radius);
  text-align: center;
  margin-bottom: 20px;
}

.premium-badge {
  display: inline-block;
  background: linear-gradient(135deg, var(--primary), #ff6b5b);
  color: white;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.premium-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 8px;
}

.premium-description {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 16px;
  line-height: 1.5;
}

.btn-premium {
  width: 100%;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  padding: 14px;
  border: none;
  border-radius: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  min-height: 44px;
}

.btn-premium:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(231, 76, 60, 0.4);
}

/* 분석 결과 */
.analysis-results {
  display: none;
  gap: 16px;
  margin-bottom: 20px;
}

.analysis-results.active {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.analysis-item {
  background: rgba(255, 255, 255, 0.05);
  padding: 16px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  text-align: center;
}

.analysis-label {
  font-size: 12px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.analysis-score {
  font-size: 32px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--primary), #ff6b5b);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 8px;
}

.analysis-bar {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  overflow: hidden;
}

.analysis-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #ff6b5b);
  border-radius: 3px;
}

/* 포커스 모드 */
.focus-mode .header-content,
.focus-mode .header-controls,
.focus-mode .timer-stats,
.focus-mode .controls {
  display: none;
}

.focus-mode main {
  padding: 0;
}

.focus-mode .timer-display {
  width: 100%;
  max-width: 100%;
  height: 100%;
}

/* 반응형 */
@media (max-width: 600px) {
  .timer-display {
    width: 240px;
    height: 240px;
  }

  .timer-time {
    font-size: 48px;
  }

  .timer-stats {
    flex-wrap: wrap;
  }

  .modal-content {
    border-radius: 20px;
    margin: 20px;
    max-height: none;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  header {
    padding: 16px;
  }

  .app-title {
    font-size: 20px;
  }

  .app-subtitle {
    font-size: 11px;
  }

  .controls {
    flex-wrap: wrap;
  }

  .btn {
    padding: 12px 20px;
    font-size: 13px;
  }

  main {
    padding: 16px;
    gap: 20px;
  }

  .timer-container {
    gap: 24px;
  }
}

@media (max-width: 360px) {
  .timer-display {
    width: 200px;
    height: 200px;
  }

  .timer-time {
    font-size: 40px;
  }

  .timer-stats {
    padding: 16px 12px;
  }

  .stat-value {
    font-size: 20px;
  }
}

/* 마이크로인터랙션 */
@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.7;
  }
}

@keyframes slideInLeft {
  from {
    opacity: 0;
    transform: translateX(-20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

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

.btn {
  animation: slideInUp 0.3s ease;
}

/* 리플 효과 */
.btn::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%);
  pointer-events: none;
}

.btn:active::before {
  animation: ripple 0.6s ease-out;
}

@keyframes ripple {
  0% {
    width: 0;
    height: 0;
  }
  100% {
    width: 300px;
    height: 300px;
  }
}

/* 다크 모드 (이미 기본값) */
@media (prefers-color-scheme: dark) {
  body {
    background: linear-gradient(135deg, var(--bg-dark) 0%, var(--bg-secondary) 100%);
  }
}

/* 라이트 모드 지원 (옵션) */
body.light-mode,
[data-theme="light"] {
  --bg-dark: #f5f5fa;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f0f0f0;
  --text-light: #1a1a2e;
  --text-secondary: #5a5a70;
  --shadow: rgba(0, 0, 0, 0.1);
}

[data-theme="light"] body {
  background: linear-gradient(135deg, #f5f5fa 0%, #ffffff 100%);
}

body.light-mode header,
[data-theme="light"] header {
  background: rgba(255, 255, 255, 0.95);
  border-bottom-color: rgba(0, 0, 0, 0.1);
}

body.light-mode .form-input,
body.light-mode .form-select,
[data-theme="light"] .form-input,
[data-theme="light"] .form-select {
  background: rgba(0, 0, 0, 0.05);
  border-color: rgba(0, 0, 0, 0.1);
  color: var(--text-light);
}

body.light-mode .modal-content,
[data-theme="light"] .modal-content {
  background: var(--bg-secondary);
  border-color: rgba(0, 0, 0, 0.1);
}

[data-theme="light"] .timer-stats {
  background: rgba(255, 255, 255, 0.8);
  border-color: rgba(0, 0, 0, 0.1);
}

[data-theme="light"] .stat-card {
  background: rgba(255, 255, 255, 0.8);
  border-color: rgba(0, 0, 0, 0.1);
}

[data-theme="light"] .chart-container {
  background: rgba(255, 255, 255, 0.8);
  border-color: rgba(0, 0, 0, 0.1);
}

[data-theme="light"] .goal-section {
  background: rgba(231, 76, 60, 0.05);
  border-color: rgba(231, 76, 60, 0.15);
}

[data-theme="light"] .premium-section {
  background: linear-gradient(135deg, rgba(231, 76, 60, 0.1) 0%, rgba(243, 156, 18, 0.05) 100%);
  border-color: rgba(231, 76, 60, 0.15);
}

[data-theme="light"] .analysis-item {
  background: rgba(255, 255, 255, 0.8);
  border-color: rgba(0, 0, 0, 0.1);
}

[data-theme="light"] .lang-menu {
  background: var(--bg-secondary);
  border-color: rgba(0, 0, 0, 0.1);
}

[data-theme="light"] .lang-option:hover {
  background: rgba(231, 76, 60, 0.1);
}

[data-theme="light"] .lang-option.active {
  background: rgba(231, 76, 60, 0.15);
}

/* Theme Toggle Button */
.theme-toggle {
  position: fixed;
  top: 12px;
  right: 56px;
  z-index: 1000;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  font-size: 18px;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

[data-theme="light"] .theme-toggle {
  background: rgba(26, 26, 46, 0.1);
  border-color: rgba(26, 26, 46, 0.15);
}

.theme-toggle:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: scale(1.05);
}

[data-theme="light"] .theme-toggle:hover {
  background: rgba(26, 26, 46, 0.15);
}

.theme-toggle:active {
  transform: scale(0.95);
}

/* 호환성 */
@supports (backdrop-filter: blur(10px)) {
  header, .modal-content {
    backdrop-filter: blur(10px);
  }
}

@supports not (backdrop-filter: blur(10px)) {
  header, .modal-content {
    background: rgba(15, 15, 35, 0.98);
  }
}

/* 접근성 */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* 포커스 표시 */
button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* 인쇄 스타일 */
@media print {
  header, .controls, .modal {
    display: none;
  }

  body {
    background: white;
    color: black;
  }
}

/* Selection Color */
::selection {
    background: #e74c3c;
    color: white;
}

::-moz-selection {
    background: #e74c3c;
    color: white;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 10px;
}

::-webkit-scrollbar-track {
    background: var(--bg-dark, var(--bg-primary, var(--background, #0f0f23)));
}

::-webkit-scrollbar-thumb {
    background: #e74c3c;
    border-radius: 5px;
    border: 2px solid var(--bg-dark, var(--bg-primary, var(--background, #0f0f23)));
}

::-webkit-scrollbar-thumb:hover {
    background: #eb6f63;
    opacity: 0.8;
}

/* Accessibility: reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
