/* ─────────────────────────────────────────────────────────────
   Swiss Modernism 2.0 — 디자인 토큰 단일 출처

   규칙: 색·간격·서체·모션 값은 이 파일에서만 정의한다.
         페이지 스타일에는 리터럴 값을 두지 않고 토큰을 참조한다.
         값을 바꾸려면 설계 문서를 먼저 갱신한다.

   원칙: 격자는 구조다 · 타이포가 위계를 전달한다 · 여백은 능동적이다
         액센트는 하나다 · 모든 색 조합은 대비 검증을 통과한다
   ───────────────────────────────────────────────────────────── */

/* ══ 1. 토큰 — 라이트 ══ */
:root {
  /* 색 */
  --color-bg: #FFFFFF;
  --color-surface: #F5F5F5;
  --color-text: #111111;          /* 순수 흑 금지 */
  --color-text-muted: #666666;
  --color-border: #D4D4D4;
  --color-border-strong: #949494;

  /* 액센트 — 유일. 라이트에서는 텍스트 색으로 쓰지 않는다(대비 미달) */
  --accent: #C08050;
  --accent-hover: #C58A5E;        /* 밝아진다. 어두워지면 라벨 대비가 떨어진다 */
  --accent-on: #111111;           /* 액센트 면 위의 글자색. 흰색 금지 */
  --accent-rgb: 192, 128, 80;     /* rgba(var(--accent-rgb), α) 형태의 반투명 글로우용 */

  /* 서체 */
  --font-body: 'Pretendard', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, monospace;

  /* 타이포 스케일 */
  --text-display: clamp(2.5rem, 5vw, 4rem);
  --text-h1: 2.25rem;
  --text-h2: 1.5rem;
  --text-h3: 1.125rem;
  --text-body: 1rem;
  --text-sm: 0.875rem;
  --text-label: 0.75rem;

  /* 행간 */
  --leading-none: 1;        /* 버튼 등 단일 행 */
  --leading-tight: 1.2;     /* 큰 제목 */
  --leading-snug: 1.4;      /* 소제목·레이블 */
  --leading-base: 1.5;      /* 조밀한 본문 */
  --leading-normal: 1.6;    /* 본문 기본 */
  --leading-relaxed: 1.75;  /* 긴 글(약관·정책) */

  /* 굵기 — 600(semibold)은 설계서에 기록된 추가 단계다 */
  --weight-normal: 400;
  --weight-medium: 500;
  --weight-semibold: 600;
  --weight-bold: 700;

  /* 스페이싱 — 8px 배수. 숫자가 배수를 뜻한다 */
  --space-half: 0.25rem;   /*  4px */
  --space-1: 0.5rem;       /*  8px */
  --space-2: 1rem;         /* 16px */
  --space-3: 1.5rem;       /* 24px */
  --space-4: 2rem;         /* 32px */
  --space-6: 3rem;         /* 48px */
  --space-8: 4rem;         /* 64px */
  --space-12: 6rem;        /* 96px */
  --space-section: clamp(4rem, 8vw, 8rem);

  /* 그리드 */
  --grid-columns: 12;
  --grid-gap: 1rem;
  --container-max: 1280px;   /* 구조 영역 */
  --reading-max: 800px;      /* 읽기 영역 — 행 길이가 가독성을 좌우한다 */

  /* 형태 */
  --radius-sm: 4px;
  --radius: 8px;
  --radius-pill: 999px;      /* 칩·필터 한정 */
  --shadow-card: 0 2px 12px rgba(0, 0, 0, 0.06);
  --shadow-lift: 0 4px 16px rgba(0, 0, 0, 0.10);

  /* 차트 — 범주형 데이터 전용(단일 액센트 규칙의 기록된 예외).
     채도 ≤80%, 배경 대비 ≥6:1 을 만족하도록 조율했다. */
  --chart-1: #185FA5;
  --chart-2: #0F6E56;
  --chart-3: #804E10;
  --chart-4: #993C1D;
  --chart-5: #534AB7;
  --chart-6: #5F5E5A;

  /* 모션 — transform·opacity만 애니메이션한다 */
  --dur-fast: 200ms;
  --dur-base: 300ms;
  --dur-enter: 420ms;
  --ease-out: cubic-bezier(0, 0, 0.2, 1);
  --stagger: 80ms;
}

/* ══ 2. 다크 오버라이드 — 색과 그림자만 ══ */
@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #111111;
    --color-surface: #1C1C1C;
    --color-text: #F5F5F5;
    --color-text-muted: #A0A0A0;
    --color-border: #333333;
    --color-border-strong: #555555;

    --accent: #D9A273;          /* 다크에서는 텍스트 색으로 써도 된다 */
    --accent-hover: #E8B98C;
    --accent-on: #111111;
    --accent-rgb: 217, 162, 115;

    --chart-1: #85B7EB;
    --chart-2: #5DCAA5;
    --chart-3: #EFC480;
    --chart-4: #F0997B;
    --chart-5: #AFA9EC;
    --chart-6: #B4B2A9;

    /* 검정 위에서는 그림자가 보이지 않는다. 테두리가 대신한다 */
    --shadow-card: none;
    --shadow-lift: none;
  }
}

/* ══ 3. 리셋 · 기본 요소 ══ */
*,
*::before,
*::after { margin: 0; padding: 0; box-sizing: border-box; }

html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font-body);
  font-size: var(--text-body);
  line-height: 1.6;
  letter-spacing: -0.01em;
  background: var(--color-bg);
  color: var(--color-text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6 { font-weight: 700; letter-spacing: -0.02em; }
h1 { font-size: var(--text-h1); line-height: 1.2; }
h2 { font-size: var(--text-h2); line-height: 1.3; }
h3 { font-size: var(--text-h3); line-height: 1.4; }

/* 링크는 색이 아니라 밑줄로 구분한다 */
a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 0.2em;
  text-decoration-thickness: 1px;
  transition: opacity var(--dur-fast) var(--ease-out);
}
a:hover { opacity: 0.7; }

img, svg, video { max-width: 100%; height: auto; display: block; }

code, pre, kbd, samp { font-family: var(--font-mono); font-size: 0.9em; }
pre {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-2);
  overflow-x: auto;
}

hr { border: 0; border-top: 1px solid var(--color-border); margin: var(--space-4) 0; }

::selection { background: var(--accent); color: var(--accent-on); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ══ 4. 타이포 유틸 ══ */
.t-display { font-size: var(--text-display); font-weight: 700; line-height: 1.1; letter-spacing: -0.02em; }
.t-h1      { font-size: var(--text-h1);   font-weight: 700; line-height: 1.2; }
.t-h2      { font-size: var(--text-h2);   font-weight: 700; line-height: 1.3; }
.t-h3      { font-size: var(--text-h3);   font-weight: 700; line-height: 1.4; }
.t-body    { font-size: var(--text-body); font-weight: 400; line-height: 1.6; }
.t-sm      { font-size: var(--text-sm);   font-weight: 400; line-height: 1.5; }
.t-label   { font-size: var(--text-label);font-weight: 500; line-height: 1.4; }
.t-muted   { color: var(--color-text-muted); }
.t-mono    { font-family: var(--font-mono); }

/* ══ 5. 레이아웃 ══ */
.container {
  max-width: var(--container-max);
  margin-inline: auto;
  padding-inline: var(--space-2);
}

.container-reading {
  max-width: var(--reading-max);
  margin-inline: auto;
  padding-inline: var(--space-2);
}

.grid-12 {
  display: grid;
  grid-template-columns: repeat(var(--grid-columns), 1fr);
  gap: var(--grid-gap);
}

.section { padding-block: var(--space-section); }

/* 768px 미만에서 모든 그리드는 단일 칼럼으로 붕괴한다 */
@media (max-width: 768px) {
  .grid-12 { grid-template-columns: 1fr; }
  .grid-12 > * { grid-column: auto !important; }
}

/* ══ 6. 컴포넌트 ══ */

/* 버튼 — background-color는 전이하지 않는다(transform·opacity 전용 규칙) */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  padding: 12px 24px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: var(--text-body);
  font-weight: 500;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
  background: var(--accent);
  color: var(--accent-on);
  transition: transform var(--dur-fast) var(--ease-out);
}
.btn:hover { background: var(--accent-hover); transform: translateY(-1px); box-shadow: var(--shadow-lift); opacity: 1; }
.btn:active { transform: translateY(0); box-shadow: none; }
.btn[disabled],
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; box-shadow: none; }
.btn[disabled]:hover,
.btn:disabled:hover { background: var(--accent); transform: none; box-shadow: none; }

.btn-secondary {
  background: transparent;
  color: var(--color-text);
  border-color: var(--color-border-strong);
}
.btn-secondary:hover { background: var(--color-surface); }
.btn-secondary[disabled]:hover,
.btn-secondary:disabled:hover { background: transparent; }

.btn-ghost {
  background: transparent;
  color: var(--color-text-muted);
  border-color: transparent;
}
.btn-ghost:hover { background: var(--color-surface); color: var(--color-text); }
.btn-ghost[disabled]:hover,
.btn-ghost:disabled:hover { background: transparent; }

/* 카드 */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-3);
  box-shadow: var(--shadow-card);
}

/* 입력 — 레이블은 항상 입력 위에 둔다 */
.field { display: flex; flex-direction: column; gap: var(--space-half); }
.field > label {
  font-size: var(--text-label);
  font-weight: 500;
  color: var(--color-text-muted);
}
.field input,
.field textarea,
.field select,
.input {
  font-family: inherit;
  font-size: var(--text-body);
  padding: 12px;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius);
  background: var(--color-bg);
  color: var(--color-text);
  width: 100%;
}
.field input::placeholder,
.field textarea::placeholder,
.input::placeholder { color: var(--color-text-muted); }

/* 오류는 색이 아니라 테두리 굵기와 텍스트로 알린다 */
.field[data-invalid] input,
.field[data-invalid] textarea,
.field[data-invalid] select {
  border-width: 2px;
  border-color: var(--color-text);
}
.field-error { font-size: var(--text-sm); color: var(--color-text); font-weight: 500; }

/* 칩 */
.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-half);
  padding: var(--space-half) var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
  background: var(--color-surface);
  font-size: var(--text-sm);
  text-decoration: none;
  cursor: pointer;
  transition: transform var(--dur-fast) var(--ease-out);
}
.chip:hover { transform: translateY(-1px); opacity: 1; }
.chip[aria-pressed="true"],
.chip.is-active { background: var(--accent); color: var(--accent-on); border-color: var(--accent); }

/* 뱃지 */
.badge {
  display: inline-block;
  padding: 2px var(--space-1);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  font-size: var(--text-label);
  font-weight: 500;
}

/* 콜아웃 — 색이 아니라 아이콘과 좌측 선으로 종류를 구분한다 */
.callout {
  background: var(--color-surface);
  border-left: 3px solid var(--color-border-strong);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: var(--space-2);
  margin-block: var(--space-2);
}
.callout-title {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--text-label);
  font-weight: 500;
  margin-bottom: var(--space-half);
}
.callout-warn   { border-left-color: var(--color-text); }
.callout-danger { border-left-color: var(--color-text); border-left-width: 4px; }
.callout-tip    { border-left-color: var(--color-border); }
.callout-summary{ border-left-color: var(--accent); }

/* 아이콘 — currentColor를 쓰므로 다크 대응이 자동이다 */
.icon {
  display: inline-block;
  width: 20px;
  height: 20px;
  stroke: currentColor;
  stroke-width: 1.5;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: -0.125em;
  flex-shrink: 0;
}
.icon-sm { width: 16px; height: 16px; }
.icon-lg { width: 24px; height: 24px; }

/* 접근성 — 시각적으로 숨기되 스크린리더에는 남긴다 */
.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;
}

/* ══ 7. 모션 ══ */
@keyframes enter {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

.enter { animation: enter var(--dur-enter) var(--ease-out) both; }

/* 리스트 순차 진입 — 지연 누적이 체감되므로 10개까지만 */
.stagger > *  { animation: enter var(--dur-enter) var(--ease-out) both; }
.stagger > *:nth-child(1)  { animation-delay: calc(var(--stagger) * 0); }
.stagger > *:nth-child(2)  { animation-delay: calc(var(--stagger) * 1); }
.stagger > *:nth-child(3)  { animation-delay: calc(var(--stagger) * 2); }
.stagger > *:nth-child(4)  { animation-delay: calc(var(--stagger) * 3); }
.stagger > *:nth-child(5)  { animation-delay: calc(var(--stagger) * 4); }
.stagger > *:nth-child(6)  { animation-delay: calc(var(--stagger) * 5); }
.stagger > *:nth-child(7)  { animation-delay: calc(var(--stagger) * 6); }
.stagger > *:nth-child(8)  { animation-delay: calc(var(--stagger) * 7); }
.stagger > *:nth-child(9)  { animation-delay: calc(var(--stagger) * 8); }
.stagger > *:nth-child(10) { animation-delay: calc(var(--stagger) * 9); }
.stagger > *:nth-child(n+11) { animation-delay: calc(var(--stagger) * 9); }

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
