/*
  손나루 디자인 시스템 v1 — 토큰 초안 (2026-11-15)
  상태: 설계 초안. 아직 어떤 HTML에도 연결하지 않았다. 운영 화면에 영향 없음.
  설계 문서: docs/design_system/SONNARU_DESIGN_SYSTEM_V1.md
  미리보기: docs/design_system/components-preview.html

  규칙
  - 화면 코드는 의미 토큰(--sn-*)만 쓴다. 원시 값(--sn-raw-*)은 이 파일 안에서만 쓴다.
  - 접두사 --sn- 를 써서 기존 tokens.css·refresh.css 변수(--ink, --green 등)와 부딪히지 않게 했다.
  - 토스 TDS·카카오·당근 SEED·KRDS의 값/자산을 복사하지 않았다. 구조(의미 이름, 4px 격자, 글자 계단)만 참고했다.
  - 글자 크기는 rem(16px 루트 기준)이다. 현재 styles.css 는 루트를 20px!important 로 두므로 그대로 연결하면
    모든 rem 토큰이 1.25배가 된다. 연결 방식은 설계 문서 f장 0단계(안 A/B, 1단계 권장은 안 B)를 따른다.
  - 대비(WCAG 2.x 비율, 2026-11-15 스크립트 재계산값. 실제 기기 측정 아님):
    라이트: 본문 #17191C/바탕 16.3:1, 보조 #434B58/흰 8.8:1(가라앉은 면 7.7:1), 힌트 #5F6775/흰 5.7:1(가라앉은 면 5.0:1),
            흰 글자/주색 #2F5BEA 5.5:1, 흰 글자/주색 눌림 #1E43BF 8.0:1, 조작 테두리 #7A8392/흰 3.8:1,
            위험 #C42B2B/흰 5.6:1, 확인 표식 #B86E00/옅은 호박 3.7:1(테두리용).
    다크:   본문 #EEF1F5/#121418 16.3:1, 보조 10.0:1, 힌트 #9AA3B0/면 6.6:1, 링크 #9DB7FF/면 8.5:1,
            흰 글자/주색 #3D67F0 4.8:1, 흰 글자/주색 눌림 #2F5BEA 5.5:1(고침: 예전 #5A7FF5 는 3.6:1로 미달),
            흰 글자/건수 빨강 #C42B2B 5.6:1(고침: 예전 #E05252 위 흰 글자는 3.8:1로 미달).
*/

:root {
  color-scheme: light dark;

  /* ---------- 1. 원시 값 (이 파일 안에서만) ---------- */
  --sn-raw-blue-50: #eaf0fe;
  --sn-raw-blue-500: #2f5bea;   /* 2026-11-11 대표 승인 주 행동색(현재 refresh.css 와 같음) */
  --sn-raw-blue-600: #2448c4;
  --sn-raw-blue-700: #1e43bf;
  --sn-raw-gray-0: #ffffff;
  --sn-raw-gray-50: #f5f6f8;
  --sn-raw-gray-100: #eef0f3;
  --sn-raw-gray-200: #e3e6eb;
  --sn-raw-gray-500: #7a8392;
  --sn-raw-gray-600: #5f6775;
  --sn-raw-gray-700: #434b58;
  --sn-raw-gray-800: #2b3038;
  --sn-raw-gray-900: #17191c;

  /* ---------- 2. 색 — 의미 토큰 (라이트) ---------- */
  /* 바탕과 면 */
  --sn-color-bg: var(--sn-raw-gray-50);
  --sn-color-surface: var(--sn-raw-gray-0);
  --sn-color-surface-sunk: var(--sn-raw-gray-100);     /* 미리 채운 칸, 접힌 영역 */
  --sn-color-overlay: rgb(23 25 28 / 48%);

  /* 글자 */
  --sn-color-text-strong: var(--sn-raw-gray-900);      /* 제목, 핵심 숫자 */
  --sn-color-text: var(--sn-raw-gray-800);             /* 본문 */
  --sn-color-text-sub: var(--sn-raw-gray-700);         /* 보조 설명 */
  --sn-color-text-hint: var(--sn-raw-gray-600);        /* 도움말, 내부 번호(4.5:1 이상 유지) */
  --sn-color-text-on-primary: #ffffff;

  /* 선 */
  --sn-color-line: var(--sn-raw-gray-200);             /* 카드 경계 */
  --sn-color-line-control: var(--sn-raw-gray-500);     /* 입력칸 테두리(3:1 이상) */

  /* 주 행동 — 한 화면에 하나 */
  --sn-color-primary: var(--sn-raw-blue-500);
  --sn-color-primary-hover: var(--sn-raw-blue-700);
  --sn-color-primary-weak: var(--sn-raw-blue-50);      /* 보조 버튼 바탕, 입력 강조 바탕 */
  --sn-color-primary-text: var(--sn-raw-blue-600);     /* 링크, 텍스트 버튼, 현재 단계 글자 */

  /* 의미색: 글자(-text)와 바탕(-weak)을 짝으로. 항상 아이콘/낱말과 함께 쓴다 */
  --sn-color-info-text: #1d5394;
  --sn-color-info-weak: #e8f1fb;
  --sn-color-check-text: #7a4a00;   /* '확인 필요'(노랑 계열, 카카오 노랑과 다른 옅은 호박색) */
  --sn-color-check-weak: #fff4dc;
  --sn-color-check-mark: #b86e00;   /* 테두리·아이콘 표식(3:1 이상) */
  --sn-color-danger: #c42b2b;       /* 위험 버튼 바탕, 오류 테두리 */
  --sn-color-danger-text: #a82424;
  --sn-color-danger-weak: #fdecec;
  --sn-color-danger-solid: #c42b2b; /* 흰 글자를 올리는 채운 빨강(건수 원). 라이트·다크 같은 값, 흰 글자 5.6:1 */
  --sn-color-text-on-danger: #ffffff;
  --sn-color-success-text: #0b6e4d;
  --sn-color-success-weak: #e7f6ef;
  --sn-color-ai-text: #5b33b8;      /* 'AI가 만든 것' 표시 전용 */
  --sn-color-ai-weak: #f1ecfd;

  /* 초점(입력 강조) */
  --sn-focus-ring-width: 2px;
  --sn-focus-ring-color: var(--sn-color-primary);
  --sn-focus-ring: 0 0 0 var(--sn-focus-ring-width) var(--sn-focus-ring-color);
  --sn-focus-outline: 3px solid var(--sn-raw-gray-900); /* 키보드 초점(버튼·링크) */

  /* ---------- 3. 글꼴 ---------- */
  /* 이미 자체 호스팅 중인 Pretendard Variable(SIL OFL 1.1)을 그대로 쓴다. 외부 CDN 없음(CSP 'self'). */
  --sn-font-body: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
  --sn-font-heading: var(--sn-font-body);
  --sn-font-number: var(--sn-font-body);          /* 숫자는 같은 글꼴 + tabular-nums */
  --sn-font-number-feature: "tnum" 1;
  --sn-font-mono: ui-monospace, "SFMono-Regular", Consolas, "D2Coding", monospace; /* 연결 문구 복사 칸 */
  --sn-font-emoji: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif; /* OS 기본 이모지 */

  /* 글자 크기 7단계 (16px 루트 기준 px 표기). 본문은 17px. 15px 미만은 배지·법적 유의사항에만 */
  --sn-text-display: 1.875rem;   /* 30px 핵심 숫자(금액) */
  --sn-text-title-1: 1.625rem;   /* 26px 화면 제목 */
  --sn-text-title-2: 1.375rem;   /* 22px 지금 할 일 제목, 카드 제목 */
  --sn-text-title-3: 1.25rem;    /* 20px 단락 제목 */
  --sn-text-body: 1.0625rem;     /* 17px 본문, 버튼, 입력 */
  --sn-text-sub: 0.9375rem;      /* 15px 보조, 도움말 */
  --sn-text-caption: 0.8125rem;  /* 13px 배지, 내부 번호, 하단 유의사항(굵기 500 이상) */

  --sn-leading-display: 1.25;
  --sn-leading-title: 1.35;
  --sn-leading-body: 1.55;       /* 지금 1.6~1.9 → 1.55 로 줄여 화면 길이 단축 */
  --sn-leading-tight: 1.3;

  --sn-weight-regular: 400;
  --sn-weight-medium: 500;
  --sn-weight-semibold: 600;
  --sn-weight-bold: 700;         /* 굵기는 이 4개만 */

  --sn-measure: 36em;            /* 본문 한 줄 최대 길이 */

  /* ---------- 4. 간격 (4px 격자) ---------- */
  --sn-space-1: 0.25rem;  /* 4 */
  --sn-space-2: 0.5rem;   /* 8 */
  --sn-space-3: 0.75rem;  /* 12 */
  --sn-space-4: 1rem;     /* 16 */
  --sn-space-5: 1.25rem;  /* 20 */
  --sn-space-6: 1.5rem;   /* 24 */
  --sn-space-8: 2rem;     /* 32 */
  --sn-space-10: 2.5rem;  /* 40 */
  --sn-space-12: 3rem;    /* 48 */
  --sn-gutter: 16px;                 /* 화면 좌우 여백(휴대폰) */
  --sn-gutter-wide: clamp(16px, 4vw, 40px);
  --sn-between-text: var(--sn-space-2);
  --sn-between-blocks: var(--sn-space-6);
  --sn-container: 45rem;             /* 업무 화면 본문 폭 720px */

  /* ---------- 5. 크기 ---------- */
  --sn-control-h-lg: 3.5rem;   /* 56px 하단 주 버튼 */
  --sn-control-h-md: 3.25rem;  /* 52px 기본 버튼, 입력칸 */
  --sn-control-h-sm: 2.5rem;   /* 40px 작은 버튼(표 안 등). 터치 영역은 44px 유지 */
  --sn-target-min: 44px;
  --sn-icon-sm: 20px;
  --sn-icon-md: 24px;
  --sn-icon-lg: 40px;          /* 상태 카드·빈 상태 아이콘/이모지 */

  /* ---------- 6. 라운드 ---------- */
  --sn-radius-sm: 8px;    /* 배지, 작은 칩 */
  --sn-radius-md: 12px;   /* 버튼, 입력 */
  --sn-radius-lg: 16px;   /* 카드 */
  --sn-radius-xl: 24px;   /* 바텀시트 윗모서리 */
  --sn-radius-full: 999px;

  /* ---------- 7. 그림자 (2단계만. 경계는 항상 1px 선으로도 그린다) ---------- */
  --sn-shadow-card: 0 1px 2px rgb(23 25 28 / 4%);
  --sn-shadow-float: 0 12px 32px rgb(23 25 28 / 14%);  /* 시트, 토스트 */

  /* ---------- 8. 움직임 ---------- */
  --sn-duration-fast: 120ms;   /* 누름, 색 바뀜 */
  --sn-duration-base: 200ms;   /* 펼치기, 시트 */
  --sn-duration-slow: 320ms;   /* 화면 전환 */
  --sn-ease-standard: cubic-bezier(0.2, 0, 0, 1);
  --sn-ease-exit: cubic-bezier(0.3, 0, 1, 1);
  --sn-toast-time: 4s;

  /* ---------- 9. 층 ---------- */
  --sn-z-sticky: 10;
  --sn-z-sheet: 100;
  --sn-z-toast: 200;
}

/* ---------- 다크: 시스템이 어둡고 사용자가 '밝게'를 고르지 않았을 때 ---------- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --sn-color-bg: #121418;
    --sn-color-surface: #1b1e24;
    --sn-color-surface-sunk: #252a32;
    --sn-color-overlay: rgb(0 0 0 / 60%);
    --sn-color-text-strong: #eef1f5;
    --sn-color-text: #dfe3ea;
    --sn-color-text-sub: #c3c9d3;
    --sn-color-text-hint: #9aa3b0;
    --sn-color-line: #3a414c;
    --sn-color-line-control: #8c95a3;
    --sn-color-primary: #3d67f0;
    --sn-color-primary-hover: #2f5bea; /* 흰 글자 5.5:1. 밝게 하면 흰 글자 대비가 떨어진다 */
    --sn-color-primary-weak: #1e2a4a;
    --sn-color-primary-text: #9db7ff;
    --sn-color-info-text: #a9ccf5;
    --sn-color-info-weak: #172a40;
    --sn-color-check-text: #ffd38a;
    --sn-color-check-weak: #33270f;
    --sn-color-check-mark: #e0a440;
    --sn-color-danger: #e05252;
    --sn-color-danger-text: #ff9b9b;
    --sn-color-danger-weak: #3a1b1b;
    --sn-color-success-text: #8fe0bd;
    --sn-color-success-weak: #173528;
    --sn-color-ai-text: #cdb8ff;
    --sn-color-ai-weak: #2a2045;
    --sn-focus-ring-color: #9db7ff;
    --sn-focus-outline: 3px solid #c4d4ff;
    --sn-shadow-card: none;
    --sn-shadow-float: 0 12px 32px rgb(0 0 0 / 45%);
  }
}

/* ---------- 다크: theme.js 가 html[data-theme=dark] 를 붙였을 때(같은 값) ---------- */
:root[data-theme="dark"] {
  --sn-color-bg: #121418;
  --sn-color-surface: #1b1e24;
  --sn-color-surface-sunk: #252a32;
  --sn-color-overlay: rgb(0 0 0 / 60%);
  --sn-color-text-strong: #eef1f5;
  --sn-color-text: #dfe3ea;
  --sn-color-text-sub: #c3c9d3;
  --sn-color-text-hint: #9aa3b0;
  --sn-color-line: #3a414c;
  --sn-color-line-control: #8c95a3;
  --sn-color-primary: #3d67f0;
  --sn-color-primary-hover: #2f5bea;
  --sn-color-primary-weak: #1e2a4a;
  --sn-color-primary-text: #9db7ff;
  --sn-color-info-text: #a9ccf5;
  --sn-color-info-weak: #172a40;
  --sn-color-check-text: #ffd38a;
  --sn-color-check-weak: #33270f;
  --sn-color-check-mark: #e0a440;
  --sn-color-danger: #e05252;
  --sn-color-danger-text: #ff9b9b;
  --sn-color-danger-weak: #3a1b1b;
  --sn-color-success-text: #8fe0bd;
  --sn-color-success-weak: #173528;
  --sn-color-ai-text: #cdb8ff;
  --sn-color-ai-weak: #2a2045;
  --sn-focus-ring-color: #9db7ff;
  --sn-focus-outline: 3px solid #c4d4ff;
  --sn-shadow-card: none;
  --sn-shadow-float: 0 12px 32px rgb(0 0 0 / 45%);
}

/* ---------- 큰 글씨: 글자·컨트롤 크기만 키운다(간격·라운드는 그대로) ---------- */
/* 연결 단계에서 reading-preference.js 가 data-text-size 를 붙이도록 바꾼다. 브라우저 글자 크기 설정은 rem 으로 자동 반영 */
:root[data-text-size="large"] {
  --sn-text-display: 2.25rem;    /* 36 */
  --sn-text-title-1: 1.875rem;   /* 30 */
  --sn-text-title-2: 1.625rem;   /* 26 */
  --sn-text-title-3: 1.4375rem;  /* 23 */
  --sn-text-body: 1.25rem;       /* 20 */
  --sn-text-sub: 1.125rem;       /* 18 */
  --sn-text-caption: 1rem;       /* 16 */
  --sn-control-h-lg: 4rem;
  --sn-control-h-md: 3.75rem;
  --sn-control-h-sm: 3rem;
  --sn-icon-md: 28px;
  --sn-leading-body: 1.5;
}
:root[data-text-size="xlarge"] {
  --sn-text-display: 2.625rem;   /* 42 */
  --sn-text-title-1: 2.125rem;   /* 34 */
  --sn-text-title-2: 1.875rem;   /* 30 */
  --sn-text-title-3: 1.625rem;   /* 26 */
  --sn-text-body: 1.5rem;        /* 24 */
  --sn-text-sub: 1.3125rem;      /* 21 */
  --sn-text-caption: 1.125rem;   /* 18 */
  --sn-control-h-lg: 4.5rem;
  --sn-control-h-md: 4.25rem;
  --sn-control-h-sm: 3.5rem;
  --sn-icon-md: 32px;
  --sn-leading-body: 1.45;
}

/* ---------- 움직임 줄이기 ---------- */
@media (prefers-reduced-motion: reduce) {
  :root {
    --sn-duration-fast: 0ms;
    --sn-duration-base: 0ms;
    --sn-duration-slow: 0ms;
  }
}
