/* =========================================================================
   은퇴네비 (Retire Navi) - 스타일시트
   - 순수 CSS3로 작성한 가벼운 디자인 시스템
   - CSS 커스텀 프로퍼티(변수)로 다크/라이트 테마를 한 번에 전환합니다.
   - 모바일 우선 반응형, 슬라이더 중심 UI에 맞춘 커스텀 range input 스타일
   ========================================================================= */

/* ----- 1. 디자인 토큰 (라이트 모드 기본값) ----- */
:root {
  --bg: #f4f6fb;            /* 페이지 배경 */
  --surface: #ffffff;       /* 카드/패널 표면 */
  --surface-2: #eef1f8;     /* 보조 표면 (트랙 등) */
  --text: #1b2230;          /* 본문 텍스트 */
  --text-muted: #5a6478;    /* 보조 텍스트 */
  --border: #e2e6ef;        /* 경계선 */
  --primary: #2f6df6;       /* 주색상 (경로/주요 곡선) */
  --primary-weak: #dbe6ff;  /* 주색상 약한 버전 */
  --accent: #f59e0b;        /* 강조색 (안전 마진/스트레스) */
  --danger: #ef4444;        /* 경고/최악 시나리오 점선 */
  --success: #16a34a;       /* 성공/완료 인증 */
  --shadow: 0 6px 24px rgba(27, 34, 48, 0.08);
  --radius: 16px;
  --radius-sm: 10px;
}

/* ----- 2. 다크 모드 토큰 (html[data-theme="dark"]) ----- */
[data-theme="dark"] {
  --bg: #0f141f;
  --surface: #182030;
  --surface-2: #222c40;
  --text: #eef2f9;
  --text-muted: #9aa6bd;
  --border: #2a3548;
  --primary: #6ea0ff;
  --primary-weak: #243450;
  --accent: #fbbf24;
  --danger: #f87171;
  --success: #4ade80;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
}

/* ----- 3. 기본 리셋 & 타이포 ----- */
* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Pretendard", system-ui, -apple-system, "Segoe UI", Roboto,
    "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  /* 테마 전환 시 색상이 부드럽게 바뀌도록 */
  transition: background-color 0.25s ease, color 0.25s ease;
}

/* ----- 4. 헤더 ----- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px clamp(16px, 4vw, 40px);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { font-size: 28px; }
.brand-text { display: flex; flex-direction: column; }
.brand-title { font-size: 20px; }
.brand-subtitle { font-size: 12px; color: var(--text-muted); }

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

/* 사용법(설명) 페이지 링크 */
.guide-link {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
}
.guide-link:hover { color: var(--primary); border-color: var(--primary); }

/* 언어 전환 토글 (KO / EN) */
.lang-switch {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
}
.lang-btn {
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease;
}
.lang-btn.is-active {
  background: var(--primary);
  color: #fff;
}

/* 테마 토글 버튼 */
.theme-toggle {
  border: 1px solid var(--border);
  background: var(--surface-2);
  width: 40px;
  height: 40px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ----- 5. 인트로 배너 ----- */
.intro {
  padding: 20px clamp(16px, 4vw, 40px);
  max-width: 1200px;
  margin: 0 auto;
}
.intro-text {
  margin: 0;
  padding: 18px 22px;
  background: linear-gradient(135deg, var(--primary-weak), transparent);
  border-left: 4px solid var(--primary);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 15px;
}

/* ----- 6. 메인 레이아웃 (반응형 2열 그리드) ----- */
.layout {
  max-width: 1200px;
  margin: 0 auto;
  padding: 8px clamp(16px, 4vw, 40px) 40px;
  display: grid;
  grid-template-columns: 1fr;   /* 모바일: 1열 */
  gap: 20px;
}
@media (min-width: 900px) {
  .layout { grid-template-columns: minmax(0, 380px) minmax(0, 1fr); } /* 데스크탑: 2열 */
}

/* ----- 7. 컨트롤 패널 & 슬라이더 ----- */
.control-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 18px 22px;
  margin: 0 0 18px;
}
.control-section legend {
  font-weight: 700;
  font-size: 15px;
  padding: 0 6px;
}
/* 안전 마진 섹션 강조 */
.control-section--accent {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent) inset, var(--shadow);
}
.hint {
  margin: 4px 2px 14px;
  font-size: 13px;
  color: var(--text-muted);
}

/* 슬라이더 한 묶음 */
.slider-field { margin-top: 16px; }
.slider-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 8px;
}
.slider-top label { font-size: 14px; color: var(--text-muted); }
.slider-top output {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* min/max 직접 편집 입력 */
.bounds {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}
.bound {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--text-muted);
  flex: 1;
}
.bound input {
  width: 100%;
  min-width: 0;
  padding: 4px 6px;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
}
.bound input:focus { outline: none; border-color: var(--primary); }

/* 안전 마진 적용 수익률 표시 */
.safety-effective {
  margin: 14px 2px 0;
  font-size: 13px;
  color: var(--text);
  font-weight: 600;
}
.safety-effective #safetyEffective { color: var(--danger); }

/* 커스텀 range input (트랙 + 썸) */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: var(--surface-2);
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--primary);
  border: 3px solid var(--surface);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}
input[type="range"]::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--primary);
  border: 3px solid var(--surface);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}
/* 안전 마진 섹션의 썸은 강조색 */
.control-section--accent input[type="range"]::-webkit-slider-thumb { background: var(--accent); }
.control-section--accent input[type="range"]::-moz-range-thumb { background: var(--accent); }

/* ----- 8. 결과 패널 카드들 ----- */
.metric-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 18px;
}
.metric-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.metric-label { font-size: 13px; color: var(--text-muted); }
.metric-value {
  font-size: 28px;
  font-weight: 800;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
}

.chart-card,
.scenario-card,
.certificate-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 18px;
}
.card-title { margin: 0 0 12px; font-size: 16px; }

.chart-wrap {
  position: relative;
  min-height: 240px;
  display: flex;
  align-items: center;
  justify-content: center;
}
#assetChart { width: 100%; height: 240px; }

.placeholder-note {
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
}

/* 차트 범례 */
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 14px;
  font-size: 12px;
  color: var(--text-muted);
}
.chart-legend .lg { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend .lg i {
  width: 18px;
  height: 0;
  border-top-width: 3px;
  border-top-style: solid;
  display: inline-block;
}
.chart-legend .lg--base i { border-top-color: var(--primary); }
.chart-legend .lg--possible i { border-top-color: var(--success); border-top-style: dashed; }
.chart-legend .lg--stress i { border-top-color: var(--danger); border-top-style: dashed; }
.chart-legend .lg--target i { border-top-color: var(--danger); border-top-style: dotted; }
.chart-legend .lg--retire i { border-top-color: var(--accent); border-top-style: dashed; }

/* 시나리오 저장 폼 */
.scenario-form {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}
.scenario-input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
}
.scenario-input:focus { outline: none; border-color: var(--primary); }

.btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-weight: 600;
  font-size: 14px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
  transition: filter 0.15s ease;
}
.btn:hover { filter: brightness(1.05); }
.btn--primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn--ghost { background: transparent; }
.btn--danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn--sm { padding: 6px 10px; font-size: 13px; }

/* 저장된 시나리오 목록 */
.scenario-list { list-style: none; margin: 0; padding: 0; }
.scenario-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  background: var(--surface-2);
}
.scenario-meta { display: flex; flex-direction: column; min-width: 0; }
.scenario-item .name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.scenario-item .sub { font-size: 12px; color: var(--text-muted); }
.scenario-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* 완료 인증서(주행 완료) 카드 */
.certificate-card {
  text-align: center;
  border: 2px solid var(--success);
  background:
    radial-gradient(120% 80% at 50% 0%, rgba(22, 163, 74, 0.14), transparent 70%),
    var(--surface);
  position: relative;
  overflow: hidden;
}
/* 카드가 나타날 때 부드럽게 떠오르는 등장 애니메이션 */
.certificate-card:not([hidden]) {
  animation: cert-pop 0.5s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
@keyframes cert-pop {
  from { opacity: 0; transform: translateY(12px) scale(0.97); }
  to { opacity: 1; transform: none; }
}

.cert-badge {
  font-size: 44px;
  line-height: 1;
  margin-bottom: 8px;
  /* 결승 깃발이 살짝 흔들리는 연출 */
  animation: cert-wave 1.6s ease-in-out infinite;
  display: inline-block;
}
@keyframes cert-wave {
  0%, 100% { transform: rotate(-6deg); }
  50% { transform: rotate(6deg); }
}

.cert-title {
  margin: 4px 0 6px;
  font-size: 22px;
  color: var(--success);
}
.cert-body { margin: 0 auto 16px; max-width: 420px; color: var(--text); }

.cert-stats {
  display: inline-flex;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: center;
  margin-bottom: 12px;
}
.cert-stat {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 120px;
}
.cert-stat-label { font-size: 12px; color: var(--text-muted); }
.cert-stat-value { font-size: 18px; font-weight: 800; color: var(--success); }
.cert-issued { font-size: 12px; color: var(--text-muted); margin: 4px 0 0; }

/* 인트로 배너 등장 애니메이션 */
.intro-text { animation: intro-fade 0.6s ease both; }
@keyframes intro-fade {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: none; }
}

/* 모션 최소화 선호 사용자는 애니메이션 비활성화 (접근성) */
@media (prefers-reduced-motion: reduce) {
  .certificate-card:not([hidden]),
  .cert-badge,
  .intro-text { animation: none; }
}

/* ----- 9. 푸터 ----- */
.app-footer {
  text-align: center;
  padding: 24px 16px 40px;
  color: var(--text-muted);
  font-size: 12px;
}

/* ----- 10. 접근성: 포커스 표시 ----- */
:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}
