/* ===========================
   1. CSS Variables (토큰)
   =========================== */
:root {
  /* 폰트 */
  --font-sans: 'Pretendard Variable', 'Pretendard', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  /* 색상 — 러닝 테마 */
  --color-primary:      #F97316;
  --color-primary-light: #FED7AA;
  --color-bg:           #FAFAFA;
  --color-surface:      #FFFFFF;
  --color-border:       #E5E7EB;
  --color-text:         #111827;
  --color-text-muted:   #6B7280;

  /* 심박수 존 색상 */
  --zone1-color: #60A5FA;   /* 회복 */
  --zone2-color: #34D399;   /* 지방연소·지구력 */
  --zone3-color: #FBBF24;   /* 유산소 강화 */
  --zone4-color: #F97316;   /* 역치·젖산 */
  --zone5-color: #EF4444;   /* 최대 출력 */

  /* 간격 */
  --space-xs:  4px;
  --space-sm:  8px;
  --space-md:  16px;
  --space-lg:  24px;
  --space-xl:  32px;

  /* 타이포그래피 */
  --font-size-sm:   13px;
  --font-size-base: 16px;
  --font-size-lg:   20px;
  --font-size-xl:   28px;

  /* 그림자 */
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08), 0 2px 4px rgba(0,0,0,0.06);

  /* 반경 */
  --radius-sm:  6px;
  --radius-md:  12px;
  --radius-lg:  20px;

  /* 탭 */
  --tab-height: 52px;
  --header-height: 48px;
}

/* 다크모드 */
@media (prefers-color-scheme: dark) {
  :root {
    --color-bg:      #111827;
    --color-surface: #1F2937;
    --color-border:  #374151;
    --color-text:    #F9FAFB;
    --color-text-muted: #9CA3AF;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.25);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.35);
  }
}

/* ===========================
   2. Reset & Base
   =========================== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: var(--font-size-base);
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100dvh;
  padding-bottom: calc(var(--tab-height) + env(safe-area-inset-bottom));
}

/* ===========================
   3. 레이아웃 — 헤더
   =========================== */
.app-header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-md);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
  position: sticky;
  top: 0;
  z-index: 10;
}

.lang-toggle {
  display: flex;
  align-items: center;
  gap: 2px;
}

.lang-btn {
  font-size: 11px;
  font-family: inherit;
  font-weight: 500;
  padding: 3px 8px;
  border: none;
  border-radius: calc(var(--radius-sm) - 2px);
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  line-height: 1.4;
}

.lang-btn--active {
  background: var(--color-primary);
  color: #fff;
}

.lang-btn:not(.lang-btn--active):hover {
  color: var(--color-text);
}

.app-title {
  font-size: var(--font-size-lg);
  font-weight: 700;
}

/* ===========================
   4. 탭 네비게이션
   =========================== */
.tab-nav {
  display: flex;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--tab-height);
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom);
}

.tab-label {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  cursor: pointer;
  min-height: 44px;
  transition: color 0.15s ease;
  border: none;
  background: none;
  font-family: inherit;
}

.tab-label.active {
  color: var(--color-primary);
  border-bottom: 2px solid var(--color-primary);
}

.tab-label:hover:not(.active) {
  color: var(--color-text);
}

/* ===========================
   5. 콘텐츠 영역
   =========================== */
.tab-content {
  max-width: 640px;
  margin: 0 auto;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
  animation: fadeIn 0.18s ease;
}

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

.section {
  padding: var(--space-md);
  margin-bottom: var(--space-sm);
}

/* ===========================
   6. 공통 컴포넌트 토큰
   =========================== */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s ease;
}

@media (hover: hover) {
  .card:hover {
    box-shadow: var(--shadow-md);
  }
}

/* ===========================
   7. 반응형 — 데스크톱
   =========================== */
@media (min-width: 640px) {
  .tab-nav {
    position: sticky;
    top: var(--header-height);
    bottom: auto;
    border-top: none;
    border-bottom: 1px solid var(--color-border);
  }

  body {
    padding-bottom: 0;
  }

  .tab-label.active {
    border-bottom: 3px solid var(--color-primary);
    border: none;
  }
}

/* ===========================
   8. Footer
   =========================== */
.app-footer {
  padding: var(--space-md);
  border-top: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-xs);
  width: 100%;
  box-sizing: border-box;
}

.app-footer__inner {
  display: contents;
}

.app-footer__copyright {
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
  margin: 0;
}

.app-footer__links {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
}

.app-footer__link {
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  font-family: inherit;
  text-decoration: none;
}

.app-footer__link:hover {
  color: var(--color-primary);
  text-decoration: underline;
}

.app-footer__divider {
  font-size: var(--font-size-xs);
  color: var(--color-border);
}

/* ===========================
   9. 정책 모달
   =========================== */
.policy-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.policy-modal[hidden] {
  display: none;
}

.policy-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
}

.policy-modal__box {
  position: relative;
  background: var(--color-surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  width: 100%;
  max-width: 640px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-md);
}

.policy-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.policy-modal__title {
  font-size: var(--font-size-md);
  font-weight: 600;
  margin: 0;
  color: var(--color-text);
}

.policy-modal__close {
  background: none;
  border: none;
  font-size: 18px;
  color: var(--color-text-muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  font-family: inherit;
}

.policy-modal__close:hover {
  background: var(--color-border);
  color: var(--color-text);
}

.policy-modal__body {
  overflow-y: auto;
  padding: var(--space-md);
  font-size: var(--font-size-sm);
  color: var(--color-text);
  line-height: 1.7;
}

.policy-modal__body h3 {
  font-size: var(--font-size-sm);
  font-weight: 600;
  margin: var(--space-md) 0 var(--space-xs);
  color: var(--color-text);
}

.policy-modal__body h3:first-child {
  margin-top: 0;
}

.policy-modal__body p {
  margin: 0 0 var(--space-xs);
  color: var(--color-text-muted);
}

@media (min-width: 640px) {
  .policy-modal {
    align-items: center;
  }

  .policy-modal__box {
    border-radius: var(--radius-lg);
    max-height: 70vh;
  }
}
