# Responsive Foundation Profile

`responsive.config`는 typography, spacing, radius foundation의 responsive 출력 방식을 정하는 SCSS compile-time profile이다. 아무것도 지정하지 않으면 글자, 컴포넌트 간격, 모서리 곡률은 모든 viewport에서 고정하고, 화면 간격만 `769px`에서 한 번 전환한다. 모든 그룹에 공통 mode를 주거나 token 그룹별로 mode를 따로 지정할 수 있다. 소비자는 token 값을 다시 작성하지 않고 mode와 공통 stop 또는 foundation별 stop range를 선택한다.

`@orioncactuscorp/ui/foundations.css`와 `@orioncactuscorp/ui/styles.css` 같은 prebuilt CSS는 이 기본 구성으로 빌드되어 있다. profile을 바꾸려면 SCSS source foundation을 직접 import해서 consumer build에서 컴파일해야 한다.

## 빠른 선택

원하는 동작의 설정 한 줄을 `scss/index.scss`의 `with()`에 넣는다. 표에 없는 조합만 [Config](#config) 이하를 읽는다. 값은 px이고 viewport 폭 `375 / 1024 / 1440` 순이다.

| 원하는 동작                                         | 설정                                       | `body1`      | `display1`     | `item-padding-small` | `section-padding-viewport-x` | `radius-large` |
| --------------------------------------------------- | ------------------------------------------ | ------------ | -------------- | -------------------- | ---------------------------- | -------------- |
| 글자·컴포넌트 고정, 화면 여백만 한 번 전환 (기본값) | 없음                                       | 16 / 16 / 16 | 48 / 48 / 48   | 16 / 16 / 16         | 16 / 32 / 32                 | 12 / 12 / 12   |
| 전부 연속으로 변함                                  | `$oc-responsive-mode: fluid`               | 17 / 17 / 18 | 48 / 51.2 / 64 | 16 / 20 / 21.6       | 18.8 / 42.7 / 48             | 12 / 16 / 22.5 |
| 글자만 연속으로 변함                                | `$oc-responsive-typo-mode: fluid`          | 17 / 17 / 18 | 48 / 51.2 / 64 | 16 / 16 / 16         | 16 / 32 / 32                 | 12 / 12 / 12   |
| 화면 여백만 연속으로 변함                           | `$oc-responsive-space-section-mode: fluid` | 16 / 16 / 16 | 48 / 48 / 48   | 16 / 16 / 16         | 18.8 / 42.7 / 48             | 12 / 12 / 12   |
| stop마다 계단식 전환                                | `$oc-responsive-mode: stepped`             | 16 / 17 / 18 | 48 / 48 / 64   | 16 / 16 / 20         | 16 / 32 / 32                 | 12 / 12 / 12   |
| 전부 고정 (화면 여백 전환도 없음)                   | `$oc-responsive-mode: static`              | 16 / 16 / 16 | 48 / 48 / 48   | 16 / 16 / 16         | 16 / 16 / 16                 | 12 / 12 / 12   |

```scss
// styles/foundations.scss
@use '@orioncactuscorp/ui/scss/index.scss' with (
  $oc-responsive-mode: fluid
);
```

적용 조건:

- Sass compile이 필요하다. 이 파일을 앱 root에서 `foundations.css` 대신 import한다.
- `scss/index.scss`는 reset까지 출력한다. `foundations.css`, `reset.css`를 함께 import하지 않는다.
- `scss/index.scss`는 token을 prebuilt `foundations.css`와 같은 `@layer oc-tokens`에, reset을 `@layer oc-reset`에 출력한다. token override 작성 기준은 prebuilt를 쓸 때와 같다.
- `styles.css`는 기본 구성 foundation을 내장하므로 profile을 바꿀 수 없다. 번들러의 컴포넌트 CSS 자동 로드와 위 SCSS 파일로 전환한다.
- 모든 설정은 entry의 `with()` 한 곳에 모은다([Configure Through `scss/index.scss`](#configure-through-scssindexscss)).

### Stop과 전환 지점

| stop    | `min` | `sm`  | `md`  | `lg`   | `xl`   | `hg`   |
| ------- | ----- | ----- | ----- | ------ | ------ | ------ |
| 기준 폭 | base  | 480px | 768px | 1280px | 1600px | 1920px |

- `stepped`: stop 값은 기준 폭보다 1px 넓은 곳부터 적용된다. `md` 값은 `769px`부터, `lg` 값은 `1281px`부터다. radius는 `md`와 `xl` 값만 가지므로 `1601px`부터 `xl` 값이 된다(`radius-large` 12px → 24px).
- `fluid`: 본문 계열 글자(`body1`~`caption2`)는 `375px`에서 `md` 값에 도달해 `768px`까지 유지한다(`body1` 17px). `375px`보다 좁으면 `sm` 값(`body1` 16px)까지 줄어든다.
- `fluid` 값은 `clamp(작은 stop 값, 큰 stop 값 / 기준 폭 × 100vw, 큰 stop 값)` 형태다. 폭에 비례해 커지다가 큰 stop 값에서 멈추므로 두 stop 사이를 직선으로 잇지 않는다. 예를 들어 `body1`은 `1024px`에서도 17px이고 `1280px`에서 18px이 된다.
- `fluid` radius는 `clamp(md 값, md 값 / 768 × 100vw, xl 값)` 형태다. `768px`부터 커지기 시작해 `xl` 값에서 멈춘다. `radius-large`는 `1024px`에서 16px, `1440px`에서 22.5px, `1536px` 이상에서 24px이다.
- `static`: `$oc-responsive-static-stop`으로 고정할 stop을 고른다. 생략하면 기본 stop 범위에서 글자는 `sm`, 컴포넌트 간격은 `md`, 화면 여백은 `min` 값, radius는 `md` 값이 된다.

## Config

```scss
@use '@orioncactuscorp/ui/scss/foundations/responsive.config' with (
  $oc-responsive-mode: null,
  $oc-responsive-stops: (
    min,
    sm,
    md,
    lg,
    xl,
    hg,
  ),
  $oc-responsive-typo-stops: null,
  $oc-responsive-space-stops: null,
  $oc-responsive-radius-stops: null,
  $oc-responsive-space-profile: null,
  $oc-responsive-static-stop: null,
  $oc-responsive-typo-mode: null,
  $oc-responsive-space-item-mode: null,
  $oc-responsive-space-section-mode: null,
  $oc-responsive-radius-mode: null
);
```

### `$oc-responsive-mode`

모든 token 그룹에 공통으로 적용할 mode다. 기본값 `null`은 각 그룹이 자기 기본값을 쓴다는 뜻이다.

- `fluid`: stop 사이를 `oc-fluid()`로 보간한다.
- `stepped`: `clamp()` 없이 stop 값이 breakpoint에서 계단식으로 바뀐다.
- `static`: 선택한 stop 하나를 전체 viewport에 고정한다.

### 그룹별 mode

아래 네 변수는 token 그룹 하나의 mode만 바꾼다. 값은 `$oc-responsive-mode`와 같은 `fluid`, `stepped`, `static`이다.

| 변수                                | 대상 token                                             | 값                             |
| ----------------------------------- | ------------------------------------------------------ | ------------------------------ |
| `$oc-responsive-typo-mode`          | `--oc-typo-size-*`, `--oc-typo-height-*`               | `fluid` / `stepped` / `static` |
| `$oc-responsive-space-item-mode`    | `--oc-space-item-*`                                    | `fluid` / `stepped` / `static` |
| `$oc-responsive-space-section-mode` | `--oc-space-section-*`                                 | `fluid` / `stepped` / `static` |
| `$oc-responsive-radius-mode`        | `--oc-atomic-radius-*` (`micro`, `max`, `factor` 제외) | `fluid` / `stepped` / `static` |

- 각 그룹의 mode는 아래 순서로 정한다.
  1. 그룹 mode를 지정하면 그 값을 쓴다.
  2. 아니면 `$oc-responsive-mode`를 지정했을 때 그 값을 쓴다.
  3. 둘 다 없으면 그룹 기본값을 쓴다. `typo`, `space-item`, `radius`는 `static`, `space-section`은 `stepped`다.
- 그룹이 `static`이면 고정할 stop은 기존 규칙을 그대로 따른다. `$oc-responsive-static-stop`이 있으면 그 stop을, 없으면 해당 foundation의 active stops 첫 번째 stop을 쓴다. 두 space 그룹은 같은 `$oc-responsive-space-stops`를 사용한다.
- 고정할 stop에 값이 없으면 typo, space와 같은 규칙으로 더 작은 stop 중 가장 가까운 값을, 없으면 더 큰 stop 중 가장 가까운 값을 쓴다.
- radius token은 `md`(Mobile)와 `xl`(Desktop) 값을 갖는다. 예를 들어 `radius-large`는 `md` 12px / `xl` 24px, `radius-medium`은 12px / 16px, `radius-small`은 10px / 12px이다. 그래서 `static`에서 고정할 stop이 `min`, `sm`, `md`, `lg`이면 `md` 값, `xl`, `hg`이면 `xl` 값이 된다. `stepped`는 `1601px`부터 `xl` 값이 된다. 모든 mode에서 값은 `oc-radius()`를 거쳐 `--oc-atomic-radius-factor` 배율을 받는다.
- 다른 값을 지정하면 변수 이름을 포함한 오류로 compile이 중단된다.
- `$oc-responsive-space-profile`은 `stepped`인 space 그룹에만 적용된다. 기본 구성에서는 `space-section` 그룹이 `stepped`이므로 그 그룹에 적용된다. profile을 지정했는데 `stepped`인 space 그룹이 없으면 compile 오류가 발생한다.

### 화면 간격 그룹의 기본 stop

`space-section` 그룹이 기본값으로 동작할 때는 stop을 `(min, md)`로 제한해 `769px`에서 한 번만 전환한다. 기본값으로 동작한다는 것은 `$oc-responsive-mode`, `$oc-responsive-space-section-mode`, `$oc-responsive-space-stops`를 모두 지정하지 않은 상태다.

셋 중 하나라도 지정하면 이 제한은 적용되지 않는다. `space-section` 그룹은 `$oc-responsive-space-stops`, 없으면 `$oc-responsive-stops`의 전체 범위를 쓴다. 예를 들어 `$oc-responsive-space-section-mode: fluid`만 지정하면 화면 여백은 `xl` 값(가로 48px)까지 보간된다. `$oc-responsive-stops`만 지정한 경우에는 제한이 그대로 적용된다.

### `$oc-responsive-stops`

활성화할 기본 design stop 목록이다.

- `fluid`: active range로 사용한다. range 밖은 가까운 active stop 값으로 고정된다.
- `stepped`: 첫 stop은 base 값으로 출력하고, 이후 stop은 `respond-to(min, stop)` 기준 media에서 출력한다.
- `static`: foundation별 stops가 없을 때 fallback active range로 사용한다.

`sm`, `md`는 design stop 이름이다. 단일 `respond-to(sm/md)` mixin은 max-width 편의 API지만, `stepped` profile의 stop 전환은 `respond-to(min, stop)` 기준이다. 예를 들어 `md` 값은 `min-width: 769px`부터 적용된다.

### `$oc-responsive-typo-stops`

`typo` size/height token에만 적용할 design stop 목록이다. `null`이면 `$oc-responsive-stops`를 사용한다.

### `$oc-responsive-space-stops`

`space` token에만 적용할 design stop 목록이다. `null`이면 `$oc-responsive-stops`를 사용한다. 단, `space-section` 그룹이 기본값으로 동작하면 `(min, md)`를 쓴다([화면 간격 그룹의 기본 stop](#화면-간격-그룹의-기본-stop)).

### `$oc-responsive-radius-stops`

`--oc-atomic-radius-*` token에만 적용할 design stop 목록이다. `null`이면 `$oc-responsive-stops`를 사용한다. 예를 들어 `(md, xl)`로 지정하면 `stepped`에서 base `md` 값, `1601px+` `xl` 값만 출력한다.

### `$oc-atomic-radius-overrides`

radius token의 stop 값을 바꾸는 map이다. `atomic` module의 변수이며 `$oc-space-overrides`와 같은 형태로 token → stop → px 숫자를 지정한다. 기본값과 병합되고 `null`을 지정한 stop은 정의되지 않은 것으로 취급한다. `fluid`는 `md` 값에서 `xl` 값까지 보간하므로 다른 stop에 지정한 값은 `stepped`와 `static`에만 쓰인다.

```scss
@use '@orioncactuscorp/ui/scss/index.scss' with (
  $oc-atomic-radius-overrides: (
    large: (
      xl: 20,
    ),
  )
);
```

### `$oc-responsive-space-profile`

`space` token의 stepped 출력 방식을 바꾸는 profile이다. `null`이면 `stepped` mode에서 active stops를 순서대로 출력한다. 그룹별 mode를 쓰면 `stepped`인 space 그룹에만 적용된다.

현재 지원하는 profile type:

- `stepped-points`: named point별 target stop을 출력한다. `points.base`는 base `:root` 값이고, `min-md` 같은 point는 `respond-to(min, md)` 기준 media로 출력한다.

`max-active-defined` target은 `$oc-responsive-space-stops` 안에서 해당 token에 실제 값이 있는 마지막 stop을 사용한다. `$oc-space-overrides`에서 stop 값을 `null`로 지정하면 그 stop은 정의되지 않은 것으로 취급한다.

### `$oc-responsive-static-stop`

`static` mode에서 전체 foundation에 공통으로 사용할 stop이다. 생략하면 각 foundation의 active stops 첫 번째 stop을 사용한다. foundation별 stops가 없으면 `$oc-responsive-stops`의 첫 번째 stop을 사용한다.

## Examples

### Default

별도 설정 없이 `typo`와 `space`를 import하면 기본 구성이 적용된다.

```scss
@use '@orioncactuscorp/ui/scss/foundations/typo';
@use '@orioncactuscorp/ui/scss/foundations/space';
```

출력 형태:

```css
:root {
  --oc-typo-size-body1: 1rem;
  --oc-space-section-padding-viewport-x: 1rem;
  --oc-space-item-padding-small: 1rem;
}

@media screen and (min-width: 769px) {
  :root {
    --oc-space-section-padding-viewport-x: 2rem;
  }
}
```

`typo`는 typography token의 첫 값인 `sm` 값(`body1` 16px, `display1` 48px)으로 고정된다. item 간격은 `md` 값으로 고정된다(`item-padding-small` 16px). section 그룹은 `min` 값을 base로 쓰고 `769px+`에서 `md` 값으로 바뀐다. `section-padding-viewport-x`는 16px에서 32px로, `section-padding-viewport-y`는 16px에서 24px로 전환된다. `section-gap-*`은 `min` 값이 없어 base에서도 `md` 값을 쓰므로 전환 전후가 같다(`section-gap-section` 48px). `atomic`을 함께 import하면 radius는 `md` 값으로 고정된다(`radius-large` 12px).

기본 구성을 변수로 모두 적으면 아래와 같고, 출력은 설정이 없을 때와 같다.

```scss
@use '@orioncactuscorp/ui/scss/foundations/responsive.config' with (
  $oc-responsive-typo-mode: static,
  $oc-responsive-space-item-mode: static,
  $oc-responsive-space-section-mode: stepped,
  $oc-responsive-space-stops: (
    min,
    md,
  )
);

@use '@orioncactuscorp/ui/scss/foundations/typo';
@use '@orioncactuscorp/ui/scss/foundations/space';
```

### Fluid

모든 그룹을 `fluid`로 출력한다. typography와 spacing이 viewport 폭에 따라 연속으로 바뀐다. 예를 들어 1440px에서 `body1`은 18px, 화면 여백 가로는 48px이다.

```scss
@use '@orioncactuscorp/ui/scss/foundations/responsive.config' with (
  $oc-responsive-mode: fluid
);

@use '@orioncactuscorp/ui/scss/foundations/typo';
@use '@orioncactuscorp/ui/scss/foundations/space';
```

### Stepped, sm~md Only

`sm` 값을 base로 쓰고, `md` 값은 `769px`부터 적용한다. `lg` 이상 stop은 출력하지 않으므로 `md` 값이 이후 viewport에서도 유지된다.

```scss
@use '@orioncactuscorp/ui/scss/foundations/responsive.config' with (
  $oc-responsive-mode: stepped,
  $oc-responsive-stops: (
    sm,
    md,
  )
);

@use '@orioncactuscorp/ui/scss/foundations/typo';
@use '@orioncactuscorp/ui/scss/foundations/space';
```

출력 형태:

```css
:root {
  --oc-typo-size-body1: 1rem;
}

@media screen and (min-width: 769px) {
  :root {
    --oc-typo-size-body1: 1.0625rem;
  }
}
```

### Separate Typo and Space Stops

mode는 `typo`와 `space`가 공유하되 active stop range만 다르게 지정할 수 있다. 아래 예시는 `typo`를 `sm` 값에 고정하고, `space`는 `sm` 값을 base로 쓰다가 `md` 이상에서 `md` 값으로 전환한다.

```scss
@use '@orioncactuscorp/ui/scss/foundations/responsive.config' with (
  $oc-responsive-mode: stepped,
  $oc-responsive-typo-stops: (
    sm,
  ),
  $oc-responsive-space-stops: (
    sm,
    md,
  )
);

@use '@orioncactuscorp/ui/scss/foundations/typo';
@use '@orioncactuscorp/ui/scss/foundations/space';
```

`$oc-responsive-typo-stops` 또는 `$oc-responsive-space-stops`를 생략하면 기존처럼 `$oc-responsive-stops`를 fallback으로 사용한다. `static` mode에서 `$oc-responsive-static-stop`을 생략한 경우에도 각 foundation의 첫 active stop을 고정값으로 사용한다.

### Two-Mode Figma Viewport

Figma `Viewport` collection이 `Mobile(md)`와 `Desktop(min, md)`처럼 두 mode만 갖고, `Desktop(min, md)`가 token별 desktop target 값을 가리킬 때는 `space`에 `stepped-points` profile을 사용한다.

```scss
@use '@orioncactuscorp/ui/scss/foundations/responsive.config' with (
  $oc-responsive-mode: stepped,
  $oc-responsive-typo-stops: (
    sm,
  ),
  $oc-responsive-space-stops: (
    md,
    lg,
    xl,
  ),
  $oc-responsive-space-profile: (
    type: stepped-points,
    points: (
      base: md,
      min-md: max-active-defined,
    ),
  )
);

@use '@orioncactuscorp/ui/scss/foundations/space' with (
  $oc-space-overrides: (
    section-padding-viewport-x: (
      md: 20,
      xl: 32,
    ),
    section-padding-viewport-y: (
      md: 16,
      xl: 24,
    ),
    item-gap-small: (
      xl: null,
    ),
  )
);
```

이 profile은 `space`의 base 값을 각 token의 `md`로 출력하고, `769px+`부터 `$oc-responsive-space-stops` 안의 마지막 정의값으로 전환한다. 예를 들어 `item-padding-xsmall`은 `md -> xl`, `item-gap-tiny`는 `md -> lg`, `item-gap-small`은 `xl: null` 때문에 `md -> lg`로 출력된다.

### Static md

전체 viewport에서 `md` 값을 사용한다. 한 stop만 쓸 때 `fluid`나 `stepped`도 결과적으로 static처럼 출력되지만, 고정 의도를 드러내려면 `static` mode를 권장한다.

```scss
@use '@orioncactuscorp/ui/scss/foundations/responsive.config' with (
  $oc-responsive-mode: static,
  $oc-responsive-static-stop: md
);

@use '@orioncactuscorp/ui/scss/foundations/typo';
@use '@orioncactuscorp/ui/scss/foundations/space';
```

출력 형태:

```css
:root {
  --oc-typo-size-body1: 1.0625rem;
  --oc-space-section-padding-viewport-x: 2rem;
}
```

### Fixed Type and Item Spacing, Fluid Layout

타이포와 item 간격은 기본값대로 고정하고, section 간격만 fluid로 바꾼다.

```scss
@use '@orioncactuscorp/ui/scss/foundations/responsive.config' with (
  $oc-responsive-space-section-mode: fluid
);

@use '@orioncactuscorp/ui/scss/foundations/typo';
@use '@orioncactuscorp/ui/scss/foundations/space';
```

`--oc-space-section-*` 출력은 `$oc-responsive-mode: fluid`와 같다. section mode를 직접 지정했으므로 기본 `(min, md)` 제한이 빠지고 전체 stop 범위를 보간한다.

[Default](#default)의 변수를 모두 적은 설정에서 `$oc-responsive-space-section-mode`만 `fluid`로 바꾸면 결과가 다르다. `$oc-responsive-space-stops: (min, md)`가 남아 section 그룹이 `min`~`md` 사이만 보간하고 `md` 이후에는 값이 고정되므로, stops 지정도 함께 뺀다.

### Configure Through `scss/index.scss`

`@orioncactuscorp/ui/scss/index.scss`는 `responsive.config`와 `color.config`를 함께 forward한다. foundation을 하나씩 나열하지 않고 entry 하나에 `with()`로 설정을 넘길 수 있다. `typo`, `space`의 override 변수도 같은 `with()`에 넣는다.

```scss
@use '@orioncactuscorp/ui/scss/index.scss' with (
  $oc-responsive-mode: fluid,
  $oc-color-system-preference: false,
  $oc-typo-font-family: (
    'Pretendard Variable',
    var(--oc-typo-font-family-system),
  ),
  $oc-typo-size-overrides: (
    display1: (
      sm: 56,
    ),
  ),
  $oc-space-overrides: (
    item-gap-small: (
      md: 10,
    ),
  )
);
```

entry를 한 번 load한 뒤에는 `typo`, `space`, `responsive.config`를 따로 `with()`로 설정할 수 없다. Sass는 이미 load된 module의 재설정을 허용하지 않으므로 "This module was already loaded, so it can't be configured using "with"." 오류가 발생한다. 모든 설정은 entry의 `with()` 한 곳에 모은다.

## Full Foundation Rebuild

`foundations.css`를 profile 적용 버전으로 대체할 때는 [Configure Through `scss/index.scss`](#configure-through-scssindexscss)처럼 `scss/index.scss` 하나를 `with()`로 설정해 import한다. 이 entry는 prebuilt와 같은 파일과 순서로 token을 `@layer oc-tokens`에 출력하고 reset을 `@layer oc-reset`에 출력하므로, 대체한 뒤에도 cascade 우선순위가 바뀌지 않는다.

```scss
// styles/foundations.scss
@use '@orioncactuscorp/ui/scss/index.scss' with (
  $oc-responsive-mode: static,
  $oc-responsive-static-stop: md
);
```

```tsx
import './styles/foundations.scss';
```

### Foundation module 직접 import

`scss/foundations/typo`, `space` 같은 module을 하나씩 `@use`하면 그 module의 token만 layer 밖에 출력한다. prebuilt `foundations/*.css`와 같은 부분 출력이다. layer 밖 선언은 `@layer oc-tokens`보다 우선하므로, 이 방식은 prebuilt foundation 위에 일부 token만 덧씌울 때 쓴다.

```scss
// prebuilt foundations.css 위에 typo와 space만 fluid로 덧씌운다
@use '@orioncactuscorp/ui/scss/foundations/responsive.config' with (
  $oc-responsive-mode: fluid
);
@use '@orioncactuscorp/ui/scss/foundations/typo';
@use '@orioncactuscorp/ui/scss/foundations/space';
```

- 덧씌운 token은 layer 밖에 있으므로 consumer override와 specificity·로드 순서로 겨룬다.
- 한 compile에서 `scss/index.scss`와 foundation module을 함께 `@use`하지 않는다. 같은 token이 `@layer oc-tokens` 안과 layer 밖에 두 번 출력되어, layer 밖 출력이 다시 consumer override와 specificity·로드 순서로 겨룬다.

## Scope

- responsive profile은 현재 `typo` size/height, `space`, `atomic` radius token을 제어한다.
- Typography letter spacing과 weight는 고정 token map을 유지한다.
- radius 중 `--oc-atomic-radius-micro`, `--oc-atomic-radius-max`, `--oc-atomic-radius-factor`는 mode와 관계없이 고정값이다. `$oc-responsive-space-profile`은 radius에 적용되지 않는다.
- CSS variable runtime override와 SCSS compile-time profile은 서로 다른 customization 경로다.
