/* =========================================================
   디자인 값 — 색, 글꼴, 모서리, 여백, 효과 속도는 여기서만 바꾸면 돼요
   ========================================================= */
:root {
  /* ── 색상 ── */
  --color-page: #F4F1EC;          /* 페이지 전체 바탕 (위 영역 뒤) */
  --color-surface: #FFFFFF;       /* 아래 영역, 주문 창 바탕 */
  --color-preview: #FFFFFF;       /* 미리보기 칸 바탕 = 선택된 탭 바탕 (같아야 이어져 보임) */
  --color-tab: #E8E3DB;           /* 선택 안 된 탭, 제품군 버튼 줄 바탕 */
  --color-text: #1F1D1A;          /* 기본 글자 */
  --color-text-soft: #625C54;     /* 보조 글자 (설명, 라벨). 흰 바탕·탭 바탕 모두 대비 기준(4.5:1) 이상 */
  --color-text-faint: #7A736A;    /* 흐린 글자 (가격, 요약 항목명). 흰 바탕 대비 4.5:1 이상 → 야외 햇빛에서도 읽힘 */
  --color-line: #E7E2DA;          /* 구분선, 입력칸 테두리 */
  --color-accent: #1F1D1A;        /* 선택 테두리, 체크, 주문 버튼 */
  --color-accent-text: #FFFFFF;   /* 주문 버튼 글자 */
  --color-focus: #2F6FED;         /* 키보드로 이동할 때 보이는 테두리 */
  --color-danger: #C2410C;        /* 오류 안내, 품절 (흰 바탕 대비 4.5:1 이상) */
  --color-success: #2F9E44;       /* 완료 표시 */
  --color-skeleton: #ECE7DF;      /* 불러오는 중 회색 블록 */
  --color-backdrop: rgba(24, 22, 19, .42); /* 주문 창 뒤 어두운 막 */

  /* ── 글꼴 ── */
  --font-sans: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, system-ui, "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif;
  --font-size-xs: 12px;           /* 선택지 가격, 작은 안내 (야외에서 읽히도록 12px 이상) */
  --font-size-sm: 13px;           /* 탭 이름, 선택지 이름, 요약 */
  --font-size-md: 15px;           /* 본문, 버튼 */
  --font-size-lg: 17px;           /* 주문 창 제목 */
  --font-size-xl: 22px;           /* 총 금액 */
  --font-size-input: 16px;        /* 입력칸 (16px 미만이면 아이폰이 화면을 확대함) */

  /* ── 모서리 둥글기 ── */
  --radius-lg: 22px;              /* 미리보기 칸(왼쪽), 아래 영역, 주문 창 */
  --radius-preview-tab-side: 12px; /* 미리보기 칸의 탭 쪽(오른쪽) 모서리 */
  --radius-md: 14px;              /* 선택지 색 견본, 입력칸 */
  --radius-sm: 10px;              /* 탭 */
  --radius-pill: 999px;           /* 버튼 */

  /* ── 여백과 크기 ── */
  --gutter: 16px;                 /* 화면 좌우 여백 */
  --gap: 12px;                    /* 덩어리 사이 간격 */
  --max-width: 480px;             /* 데스크톱에서 최대 폭 */
  /* 미리보기 크기: 평소엔 화면 폭에 맞추고, 화면이 낮으면 나머지(제품군 버튼·선택지·요약·금액)가 한 화면에 들어오도록 줄임
     svh = 브라우저 툴바가 펼쳐진 상태의 화면 높이 → 스크롤로 툴바가 접혔다 펴져도 크기가 출렁이지 않음 */
  --layout-rest: 352px;          /* 미리보기를 뺀 나머지 영역의 높이 (값이 크면 미리보기가 작아짐). .claude/layout-check.js 로 잰 값 */
  --preview-min-size: 200px;      /* 화면이 아주 낮아도 미리보기는 이 크기 이상 */
  --preview-max: max(var(--preview-min-size), calc(100svh - var(--layout-rest)));
  --tab-width: 54px;              /* 오른쪽 탭 폭 */
  --tab-pop: 8px;                 /* 선택된 탭이 왼쪽으로 나와 미리보기 칸에 붙는 거리 (= 선택 안 된 탭과 미리보기 칸 사이 틈) */
  --tab-gap: 5px;                 /* 탭 사이 간격 */
  --tab-max-height: 64px;         /* 탭 높이 (탭이 적을 때). 탭이 많아지면 미리보기 높이를 꽉 채우도록 자동으로 나눔 */
  --tab-min-height: 28px;         /* 탭 최소 높이. 탭이 많으면 여기까지 줄어 한눈에 보이고, 그래도 넘칠 때만 세로 스크롤 */
  --tab-fillet: 8px;              /* 선택된 탭과 미리보기 칸이 만나는 위·아래 오목한 이음매 크기 */
  --choice-width: 72px;           /* 선택지 한 칸 폭 */
  --choice-size: 52px;            /* 선택지 색 견본 크기 */
  --option-body-height: 132px;    /* 선택지 영역 높이 (탭마다 높이가 달라 화면이 출렁이지 않게 고정) */

  /* ── 그림자 ── */
  --shadow-preview: none;         /* 미리보기 칸 그림자. 선택된 탭과 한 몸처럼 이어져야 해서 없음 (넣으면 탭과 만나는 곳에서 끊겨 보임) */
  --shadow-panel: 0 -1px 0 rgba(31, 29, 26, .04), 0 -8px 32px rgba(31, 29, 26, .06);
  --shadow-raised: 0 1px 3px rgba(31, 29, 26, .12);
  --shadow-sheet: 0 -12px 48px rgba(31, 29, 26, .2);

  /* ── 효과 (속도와 강도) ── */
  --ease-out: cubic-bezier(.22, 1, .36, 1);       /* 빠르게 시작해 부드럽게 멈춤 */
  --ease-spring: cubic-bezier(.34, 1.56, .64, 1); /* 살짝 튕기며 멈춤 (체크 표시) */
  --ease-in: cubic-bezier(.4, 0, 1, 1);           /* 천천히 시작해 빠르게 사라짐 (퇴장) */
  --dur-press: 90ms;              /* 누를 때 눌리는 속도 */
  --dur-select: 180ms;            /* 선택 테두리·체크가 나타나는 속도 */
  --dur-tab: 240ms;               /* 탭 튀어나옴, 색 전환 */
  --dur-panel: 220ms;             /* 탭 바꿀 때 선택지 등장 */
  --dur-layer: 200ms;             /* 미리보기 레이어 교체 */
  --dur-group: 280ms;             /* 제품군 전환: 새 제품 등장, 버튼 표시 이동 */
  --dur-group-out: 130ms;         /* 제품군 전환: 이전 제품이 사라지는 시간 (다 사라진 뒤 새 제품 등장 → 겹쳐 보이지 않음) */
  --dur-price: 360ms;             /* 총 금액 숫자 굴러가기 + 강조 */
  --dur-sheet: 320ms;             /* 주문 창 열고 닫기 */
  --press-scale: .94;             /* 눌렀을 때 줄어드는 정도 (1이면 효과 없음) */
  --panel-shift: 10px;            /* 선택지 등장 시 미끄러지는 거리 */
  --price-bump-scale: 1.08;       /* 총 금액 강조 시 커지는 정도 */
}

/* 세로가 긴 폰에서는 선택지를 조금 크게 */
@media (min-height: 760px) {
  :root {
    --choice-width: 78px;
    --choice-size: 58px;
    --option-body-height: 144px;
    --layout-rest: 358px;
  }
}

/* 기기에서 '동작 줄이기'를 켰으면 효과를 끔 */
@media (prefers-reduced-motion: reduce) {
  :root {
    --dur-press: 0ms;
    --dur-select: 0ms;
    --dur-tab: 0ms;
    --dur-panel: 0ms;
    --dur-layer: 0ms;
    --dur-group: 0ms;
    --dur-group-out: 0ms;
    --dur-price: 0ms;
    --dur-sheet: 0ms;
    --press-scale: 1;
    --panel-shift: 0px;
    --price-bump-scale: 1;
  }
}


/* =========================================================
   기본
   ========================================================= */
*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  color-scheme: only light;                   /* 브라우저가 강제로 다크 모드(색 반전)를 걸지 않게 → 제품 색이 그대로 보임 */
  overscroll-behavior-y: contain;             /* 화면 위에서 당겨도 새로고침되지 않음 */
  background: var(--color-page);
}
html.is-locked, html.is-locked body { overflow: hidden; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font-sans);
  font-size: var(--font-size-md);
  line-height: 1.45;
  color: var(--color-text);
  background: var(--color-page);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
button, a, input, textarea, label, .app { touch-action: manipulation; }
img { -webkit-user-drag: none; user-select: none; }
[hidden] { display: none !important; }

/* 길게 눌러도 '이미지 저장' 메뉴나 글자 선택이 뜨지 않게 (조작하는 부분만. 입력칸·주문 내용은 그대로 선택 가능) */
.preview, .tab, .choice, .group-btn, .btn, .total, .summary, .option-head, .text-tools {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}
button img { pointer-events: none; }

:focus { outline: none; }
:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.app {
  display: flex;
  flex-direction: column;
  max-width: var(--max-width);
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding-top: env(safe-area-inset-top);
  overflow-x: clip;                           /* 어떤 요소도 화면을 가로로 밀어내지 못하게 */
}


/* =========================================================
   위 영역: 미리보기
   ========================================================= */
.stage {
  padding: var(--gutter) var(--gutter) var(--gap);
  padding-left: max(var(--gutter), env(safe-area-inset-left));
  padding-right: max(var(--gutter), env(safe-area-inset-right));
}

.stage-row {
  display: flex;
  width: 100%;
  max-width: calc(var(--preview-max) + var(--tab-width) + var(--tab-pop));
  margin: 0 auto;
}

.preview {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius-lg) var(--radius-preview-tab-side) var(--radius-preview-tab-side) var(--radius-lg);
  transition: border-radius var(--dur-tab) var(--ease-out);   /* 맨 위·아래 탭이 붙을 때 그쪽 모서리가 각지게 */
  background: var(--color-preview);
  box-shadow: var(--shadow-preview);
  overflow: hidden;
  isolation: isolate;
}

.preview-canvas {
  position: absolute;
  inset: 0;
  container-type: inline-size; /* 문구 글자 크기를 미리보기 폭 기준(cqw)으로 맞추기 위함 */
}

/* 제품군 하나의 레이어 묶음. 제품군을 바꾸면 이전 묶음이 먼저 사라지고(is-leaving), 그다음 새 묶음이 나타남 */
.stack {
  position: absolute;
  inset: 0;
  animation: stack-in var(--dur-group) var(--ease-out) backwards;
}
.stack.is-after-leave { animation-delay: var(--dur-group-out); }
.stack.is-leaving { animation: stack-out var(--dur-group-out) var(--ease-in) forwards; }

.layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.layer-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  animation: fade-in var(--dur-layer) var(--ease-out) backwards;
}
.layer-img.is-instant { animation: none; }
.layer-img.is-leaving { animation: fade-out var(--dur-layer) var(--ease-out) both; }

/* text 옵션 글자 */
.layer-text span {
  position: absolute;
  left: calc(var(--x, 50) * 1%);
  top: calc(var(--y, 50) * 1%);
  transform: translate(-50%, -50%);
  font-size: calc(var(--size, 6) * 1cqw);
  font-weight: var(--weight, 700);
  color: var(--color, var(--color-text));
  line-height: 1;
  letter-spacing: -0.01em;
  white-space: pre;
}

/* 바탕 이미지가 없을 때 대체 표시 */
.stack.is-base-missing::before {
  content: attr(data-missing-text);
  position: absolute;
  inset: 14%;
  display: grid;
  place-items: center;
  border: 2px dashed var(--color-line);
  border-radius: var(--radius-md);
  color: var(--color-text-faint);
  font-size: var(--font-size-sm);
}

/* 불러오는 중 표시 (아주 빨리 끝나면 보이지 않도록 살짝 늦게 등장) */
.preview-skeleton {
  position: absolute;
  inset: 14%;
  border-radius: 50%;
  background: var(--color-skeleton);
  animation: skeleton-in 200ms 250ms both, pulse 1.4s 450ms ease-in-out infinite;
  transition: opacity var(--dur-group) var(--ease-out);
}
.preview.has-stack .preview-skeleton { opacity: 0; animation: none; }


/* =========================================================
   위 영역: 오른쪽 책갈피 탭
   구조: [미리보기 칸][틈 --tab-pop][탭 --tab-width]  (탭 버튼 자체는 틈까지 포함한 전체 폭)
   - 선택 안 된 탭: 미리보기 칸에서 --tab-pop 떨어진, 오른쪽이 둥근 책갈피
   - 선택된 탭: 오른쪽 끝은 다른 탭과 같은 자리에 둔 채 왼쪽으로만 늘어나 미리보기 칸에 붙음
     → 다른 탭보다 넓어져서 '선택됨'이 분명하고, 같은 색 + 오목한 이음매로 미리보기와 한 몸처럼 보임
   - 배치 방식은 JS가 탭 개수와 미리보기 높이를 보고 고름 (data-mode)
     top    : 탭이 적을 때. 최대 높이로 미리보기 맨 위에 딱 붙여 시작
     fill   : 탭이 많을 때. 미리보기 높이를 위아래 끝까지 꽉 채움
     scroll : 최소 높이로도 넘칠 때만. 둥근 모서리를 피한 레일 안에서 세로 스크롤
   - 이음매 규칙: 이음매는 항상 미리보기의 '곧은 가장자리'와 만남
     맨 위(아래)에 딱 붙은 탭은 이음매 대신 미리보기 그쪽 모서리를 각지게 바꿔 이어 붙임 (data-edge)
     JS가 top 모드를 고를 때 아래쪽에 (모서리 + 이음매) 높이 이상의 여유가 남는지 확인함
   ========================================================= */
.tabs {
  position: relative;
  z-index: 1;
  flex: 0 0 calc(var(--tab-width) + var(--tab-pop) + 2px);
  margin-left: -2px;                          /* 선택된 탭이 미리보기 가장자리를 2px 덮어 이음새 없앰 */
  display: flex;
  flex-direction: column;
  gap: var(--tab-gap);
  contain: size;                              /* 탭 수와 상관없이 높이는 미리보기 칸에 맞춤 */
  overflow: hidden;                           /* 가로로 밀리거나 잘리지 않음 */
  overflow: clip;                             /* + 코드나 포커스 이동으로도 스크롤되지 않음 (지원 안 하는 브라우저는 위 hidden) */
  touch-action: pan-y;                        /* 탭 위에서 가로로 쓸어도 아무것도 움직이지 않음 */
}
.tabs[data-mode="fill"] .tab { flex: 1 1 0; }
.tabs[data-mode="scroll"] {
  margin-block: var(--radius-preview-tab-side);
  padding-block: var(--tab-fillet);
  overflow: hidden auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
  -webkit-mask-image: linear-gradient(to bottom, transparent, #000 var(--tab-fillet), #000 calc(100% - var(--tab-fillet)), transparent);
  mask-image: linear-gradient(to bottom, transparent, #000 var(--tab-fillet), #000 calc(100% - var(--tab-fillet)), transparent);
}
.tabs[data-mode="scroll"] .tab { flex: 0 0 var(--tab-min-height); }
.tabs::-webkit-scrollbar { display: none; }

.tab {
  position: relative;
  flex: 0 0 var(--tab-max-height);
  min-height: var(--tab-min-height);
  width: 100%;
  padding: 4px 4px 4px calc(var(--tab-pop) + 6px);   /* 글자는 선택 안 된 탭의 보이는 부분 가운데에 */
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-soft);
  font-size: var(--font-size-sm);
  font-weight: 500;
  line-height: 1.15;
  text-align: center;
  transition: color var(--dur-tab) var(--ease-out);
  animation: tab-in var(--dur-tab) var(--ease-out) backwards;
  animation-delay: calc(var(--i, 0) * 30ms);
  container-type: size;                       /* 탭 높이에 따라 안쪽 글자 배치를 바꾸기 위함 (아래 @container) */
}
.tab:active { color: var(--color-text); }

/* 탭 사이 틈까지 누를 수 있게 하는 보이지 않는 누름 영역 */
.tab-hit {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(var(--tab-gap) / -2);
  bottom: calc(var(--tab-gap) / -2);
}

/* 탭이 낮아지면 (탭이 많거나 글씨를 크게 설정한 폰) 이름은 한 줄로, 점은 숨김 */
@container (max-height: 40px) {
  .tab-label { -webkit-line-clamp: 1; }
  .tab-dot { display: none; }
}
/* 그래도 이름이 탭을 넘치면 (글씨를 크게 설정한 폰 등) JS가 단계적으로 붙임:
   점 숨김 → 글자 조금 줄임 → 더 줄임(두 줄까지) → 한 줄 말줄임(최후) */
.tab.fit-1 .tab-dot { display: none; }
.tab.fit-2 .tab-label { font-size: .86em; }
.tab.fit-3 .tab-label { font-size: .74em; }
.tab.fit-4 .tab-label { -webkit-line-clamp: 1; }
.tab.is-active { color: var(--color-text); font-weight: 600; }

/* 탭의 배경: 선택 안 됨 = 틈 오른쪽만 보임 / 선택됨 = 왼쪽 끝(미리보기)까지 펼쳐짐 */
.tab-bg {
  position: absolute;
  inset: 0;
  background: var(--color-tab);
  clip-path: inset(0 0 0 calc(var(--tab-pop) + 2px) round 0 var(--radius-sm) var(--radius-sm) 0);
  transition:
    clip-path var(--dur-tab) var(--ease-out),
    background-color var(--dur-tab) var(--ease-out);
}
.tab.is-active .tab-bg {
  background: var(--color-preview);
  clip-path: inset(0 0 0 0 round 0 var(--radius-sm) var(--radius-sm) 0);
}

/* 이름 + 점. 선택되면 넓어진 탭의 가운데로 살짝 이동 */
.tab-inner {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 0;
  max-width: 100%;
  max-height: 100%;
  overflow: hidden;
  transition: translate var(--dur-tab) var(--ease-out);
}
.tab.is-active .tab-inner { translate: calc((var(--tab-pop) + 2px) / -2) 0; }

/* 선택된 탭과 미리보기 칸이 만나는 위·아래의 오목한 이음매 */
.tab::before,
.tab::after {
  content: "";
  position: absolute;
  left: 0;
  width: var(--tab-fillet);
  height: var(--tab-fillet);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-tab) var(--ease-out);
}
.tab::before {
  bottom: 100%;
  background: radial-gradient(circle at 100% 0, transparent calc(var(--tab-fillet) - .5px), var(--color-preview) var(--tab-fillet));
}
.tab::after {
  top: 100%;
  background: radial-gradient(circle at 100% 100%, transparent calc(var(--tab-fillet) - .5px), var(--color-preview) var(--tab-fillet));
}
.tab.is-active::before,
.tab.is-active::after { opacity: 1; }
/* 미리보기 맨 위·맨 아래에 딱 붙은 탭은 그쪽 이음매 대신 미리보기 모서리를 각지게 해서 이음 */
.tabs:not([data-mode="scroll"]) .tab:first-child::before,
.tabs[data-mode="fill"] .tab:last-child::after { display: none; }
.stage-row[data-edge~="top"] .preview { border-top-right-radius: 0; }
.stage-row[data-edge~="bottom"] .preview { border-bottom-right-radius: 0; }

.tab-label {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* 탭 아래 작은 점: 현재 고른 색(또는 문구 입력 여부) */
.tab-dot {
  flex: 0 0 auto;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--dot, transparent);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .08);
  opacity: 0;
  scale: .4;
  transition: opacity var(--dur-select) var(--ease-out), scale var(--dur-select) var(--ease-spring), background-color var(--dur-select) var(--ease-out);
}
.tab.has-dot .tab-dot { opacity: 1; scale: 1; }

.tab-skeleton {
  flex: 0 0 var(--tab-max-height);
  width: var(--tab-width);
  margin-left: calc(var(--tab-pop) + 2px);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: var(--color-skeleton);
  animation: skeleton-in 200ms 250ms both;
}


/* =========================================================
   위 영역: 제품군 버튼 (선택 표시가 미끄러져 이동)
   ========================================================= */
.groups-wrap {
  display: flex;
  margin-top: var(--gap);
  padding-right: calc(var(--tab-width) + var(--tab-pop));   /* 탭 열만큼 비워 미리보기 칸 기준 가운데에 오도록 */
  overflow-x: auto;
  scrollbar-width: none;
}
.groups-wrap::-webkit-scrollbar { display: none; }

.groups {
  --n: 1;
  --i: 0;
  position: relative;
  display: inline-grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;                     /* 모든 버튼 폭을 같게 → 표시가 일정하게 이동 */
  flex: 0 0 auto;
  margin-inline: auto;                        /* 가운데 정렬. 넘칠 때는 왼쪽부터 시작해 앞부분이 잘리지 않고 스크롤됨 */
  padding: 3px;
  border-radius: var(--radius-pill);
  background: var(--color-tab);
}

.groups-indicator {
  position: absolute;
  top: 3px;
  bottom: 3px;
  left: 3px;
  width: calc((100% - 6px) / var(--n));
  border-radius: var(--radius-pill);
  background: var(--color-surface);
  box-shadow: var(--shadow-raised);
  transform: translateX(calc(var(--i) * 100%));
  transition: transform var(--dur-group) var(--ease-out);
}
.groups:not(.is-ready) .groups-indicator { opacity: 0; }

.group-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 14px;
  border-radius: var(--radius-pill);
  color: var(--color-text-soft);
  font-size: var(--font-size-sm);
  font-weight: 600;
  white-space: nowrap;
  transition: color var(--dur-group) var(--ease-out), transform var(--dur-press) var(--ease-out);
}
.group-btn:active { transform: scale(var(--press-scale)); }
.group-btn.is-selected { color: var(--color-text); }
/* 보이는 높이는 34px, 누르는 범위는 위아래로 넓혀 44px */
.group-btn::after { content: ""; position: absolute; inset: -5px 0; }

.group-icon {
  width: 16px;
  height: 16px;
  opacity: .55;
  transition: opacity var(--dur-group) var(--ease-out);
}
.group-btn.is-selected .group-icon { opacity: 1; }


/* =========================================================
   아래 영역
   ========================================================= */
.panel {
  flex: 1 0 auto;
  display: flex;
  flex-direction: column;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  background: var(--color-surface);
  box-shadow: var(--shadow-panel);
}

.option-panel {
  position: relative;
  min-height: var(--option-body-height);
  overflow: hidden;
}

/* 탭을 바꿀 때마다 새로 그려지며 등장 (아래 탭으로 가면 아래에서, 위 탭으로 가면 위에서) */
.option-body {
  min-height: var(--option-body-height);
  padding-top: 14px;
  animation: panel-in-down var(--dur-panel) var(--ease-out) backwards;
}
.option-body[data-dir="up"] { animation-name: panel-in-up; }
.option-body[data-dir="none"] { animation-name: fade-in; }

.option-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 0 var(--gutter);
  margin-bottom: 6px;
}
.option-name { margin: 0; font-size: var(--font-size-md); font-weight: 700; }
.option-desc { margin: 0; color: var(--color-text-soft); font-size: var(--font-size-sm); }
.option-empty { margin: 0; padding: 24px var(--gutter); color: var(--color-text-faint); text-align: center; }

.option-skeleton {
  display: flex;
  gap: 10px;
  padding: 44px var(--gutter) 0;
}
.option-skeleton span {
  width: var(--choice-size);
  height: var(--choice-size);
  margin: 0 calc((var(--choice-width) - var(--choice-size)) / 2);
  border-radius: var(--radius-md);
  background: var(--color-skeleton);
  animation: skeleton-in 200ms 250ms both;
}


/* ── 선택지 (가로 스크롤) ── */
.choices-wrap { position: relative; }

/* 스크롤할 내용이 더 있으면 가장자리를 흐리게 */
.choices-wrap::before,
.choices-wrap::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  z-index: 1;
  width: 28px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 160ms linear;
}
.choices-wrap::before { left: 0; background: linear-gradient(to right, var(--color-surface), transparent); }
.choices-wrap::after { right: 0; background: linear-gradient(to left, var(--color-surface), transparent); }
.choices-wrap.has-more-left::before,
.choices-wrap.has-more-right::after { opacity: 1; }

.choices {
  display: flex;
  gap: 4px;
  padding: 6px var(--gutter) 8px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scroll-snap-type: x proximity;
  scroll-padding: 0 var(--gutter);
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.choices::-webkit-scrollbar { display: none; }

.choice {
  flex: 0 0 auto;
  min-width: var(--choice-width);             /* 평소엔 이 폭. 글씨를 크게 설정하면 가격이 들어갈 만큼 넓어짐 */
  max-width: calc(var(--choice-width) * 1.6);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 4px 2px 2px;
  border-radius: var(--radius-md);
  scroll-snap-align: start;
  transition: transform var(--dur-press) var(--ease-out);
}
.choice:active { transform: scale(var(--press-scale)); }
.choice:focus-visible { outline-offset: -2px; }

.choice-swatch {
  position: relative;
  width: var(--choice-size);
  height: var(--choice-size);
  border-radius: var(--radius-md);
  background: var(--swatch, var(--color-skeleton));
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .07);
}
.choice-swatch img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: inherit;
}

/* 선택 테두리 */
.choice-swatch::after {
  content: "";
  position: absolute;
  inset: -4px;
  border: 2px solid var(--color-accent);
  border-radius: calc(var(--radius-md) + 4px);
  opacity: 0;
  scale: .92;
  transition: opacity var(--dur-select) var(--ease-out), scale var(--dur-select) var(--ease-out);
}
.choice.is-selected .choice-swatch::after { opacity: 1; scale: 1; }

/* 선택 체크 */
.choice-check {
  position: absolute;
  top: -7px;
  right: -7px;
  z-index: 1;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--color-accent);
  box-shadow: 0 0 0 2px var(--color-surface);
  opacity: 0;
  scale: .3;
  transition: opacity var(--dur-select) var(--ease-out), scale var(--dur-select) var(--ease-spring);
}
.choice-check::before {
  content: "";
  position: absolute;
  left: 7px;
  top: 4px;
  width: 5px;
  height: 9px;
  border: solid var(--color-accent-text);
  border-width: 0 2px 2px 0;
  rotate: 45deg;
}
.choice.is-selected .choice-check { opacity: 1; scale: 1; }

.choice-initial {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  color: var(--color-text-soft);
  font-size: var(--font-size-md);
  font-weight: 700;
}

.choice-name {
  max-width: 100%;
  padding: 0 2px;
  font-size: var(--font-size-sm);
  font-weight: 500;
  line-height: 1.2;
  color: var(--color-text-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color var(--dur-select) var(--ease-out);
}
.choice.is-selected .choice-name { color: var(--color-text); font-weight: 600; }

.choice-price {
  min-height: 1.2em;
  margin-top: -4px;
  font-size: var(--font-size-xs);
  line-height: 1.2;
  color: var(--color-text-faint);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;                        /* "+1,000원"이 숫자 중간에서 줄바꿈되지 않게 */
}

/* 품절 */
.choice.is-soldout { cursor: not-allowed; }
.choice.is-soldout:active { transform: none; }
.choice.is-soldout .choice-swatch { opacity: .35; }
.choice.is-soldout .choice-swatch::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 8%;
  bottom: 8%;
  width: 2px;
  background: var(--color-text-soft);
  rotate: 45deg;
}
.choice.is-soldout .choice-name { color: var(--color-text-faint); }
.choice.is-soldout .choice-price { color: var(--color-danger); font-weight: 600; }


/* ── 글자 입력 (text 옵션) ── */
.text-field {
  position: relative;
  margin: 6px var(--gutter) 0;
}
.text-input {
  width: 100%;
  height: 52px;
  padding: 0 92px 0 16px;
  border: 1.5px solid var(--color-line);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  font-size: var(--font-size-input);
  transition: border-color var(--dur-select) var(--ease-out);
}
.text-input::placeholder { color: var(--color-text-faint); }
.text-input:focus { border-color: var(--color-accent); }

.text-tools {
  position: absolute;
  top: 0;
  right: 6px;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 2px;
}
.text-counter {
  color: var(--color-text-faint);
  font-size: var(--font-size-xs);
  font-variant-numeric: tabular-nums;
}
.text-counter.is-full { color: var(--color-danger); font-weight: 600; }

.text-clear {
  position: relative;
  width: 44px;                                /* 누르는 범위 44px, 보이는 동그라미는 안쪽 18px */
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  opacity: 0;
  scale: .6;
  pointer-events: none;
  transition: opacity var(--dur-select) var(--ease-out), scale var(--dur-select) var(--ease-out);
}
.text-clear::before {
  content: "";
  position: absolute;
  inset: 13px;
  border-radius: 50%;
  background: var(--color-tab);
}
.text-clear::after {
  content: "×";
  position: relative;
  color: var(--color-text-soft);
  font-size: 16px;
  line-height: 1;
}
.text-field.has-value .text-clear { opacity: 1; scale: 1; pointer-events: auto; }

.text-hint {
  margin: 8px var(--gutter) 0;
  color: var(--color-text-soft);
  font-size: var(--font-size-xs);
}

/* 문구 입력 중, 키보드 때문에 미리보기가 가려지면 보이는 화면 위쪽에 뜨는 작은 미리보기 */
.mini-preview {
  position: fixed;
  top: calc(var(--mini-top, 0px) + 10px);
  right: 10px;
  z-index: 8;
  width: min(38vw, 168px);
  aspect-ratio: 1 / 1;
  border-radius: var(--radius-md);
  background: var(--color-preview);
  box-shadow: 0 8px 28px rgba(31, 29, 26, .18), 0 0 0 1px rgba(31, 29, 26, .06);
  overflow: hidden;
  container-type: inline-size;                /* 안쪽 문구 글자 크기를 작은 미리보기 폭에 맞춤 */
  pointer-events: none;
  opacity: 0;
  transform: translateY(-8px) scale(.96);
  transition: opacity var(--dur-select) var(--ease-out), transform var(--dur-select) var(--ease-out);
}
.mini-preview.is-visible { opacity: 1; transform: none; }
.mini-preview * { animation: none !important; }


/* ── 현재 선택 요약 ── */
.summary {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin: auto 0 0;                           /* 남는 공간은 선택지와 요약 사이로 → 요약은 금액 바로 위 */
  padding: 12px var(--gutter) 12px;
  list-style: none;
  font-size: var(--font-size-sm);
  line-height: 1.4;
}
.summary li { display: inline-flex; gap: 5px; }
.summary-key { color: var(--color-text-faint); }
.summary-val { color: var(--color-text-soft); font-weight: 500; }
.summary-val.is-missing { color: var(--color-danger); }


/* ── 총 금액 + 주문하기 (항상 화면 아래에 붙어 있음) ── */
.checkout {
  position: sticky;
  bottom: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px var(--gutter) calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--color-line);
  background: var(--color-surface);
}

.total { display: flex; flex-direction: column; flex: 0 0 auto; }   /* 금액은 줄어들지 않음 (글씨가 커지면 버튼이 양보) */
.total-label { color: var(--color-text-soft); font-size: var(--font-size-xs); }
.total-amount {
  display: inline-block;
  font-size: var(--font-size-xl);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;          /* 숫자 폭을 같게 해서 굴러갈 때 흔들리지 않음 */
  transform-origin: left center;
  white-space: nowrap;
}
.total-amount[data-bump="a"] { animation: bump-a var(--dur-price) var(--ease-out); }
.total-amount[data-bump="b"] { animation: bump-b var(--dur-price) var(--ease-out); }

.order-btn { flex: 1 1 auto; min-width: 0; max-width: 240px; margin-left: auto; padding: 0 16px; }


/* =========================================================
   버튼
   ========================================================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 52px;
  padding: 0 22px;
  border-radius: var(--radius-pill);
  font-size: var(--font-size-md);
  font-weight: 700;
  white-space: nowrap;
  transition: transform var(--dur-press) var(--ease-out), opacity var(--dur-select) var(--ease-out), background-color var(--dur-select) var(--ease-out);
}
.btn:active:not(:disabled) { transform: scale(var(--press-scale)); }
.btn:disabled { cursor: default; }
.btn-primary { background: var(--color-accent); color: var(--color-accent-text); }
.btn-primary:disabled { opacity: .35; }
.btn-ghost { background: var(--color-tab); color: var(--color-text); }
.btn-block { width: 100%; }


/* =========================================================
   주문 창
   ========================================================= */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: var(--color-backdrop);
  opacity: 0;
  transition: opacity var(--dur-sheet) var(--ease-out);
}
.sheet.is-open .sheet-backdrop { opacity: 1; }

.sheet-panel {
  position: relative;
  width: 100%;
  max-width: var(--max-width);
  max-height: calc(var(--vvh, 100dvh) - 24px);
  margin-bottom: var(--kb, 0px);              /* 아이폰 키보드가 올라오면 그만큼 위로 */
  padding: 8px 20px calc(20px + env(safe-area-inset-bottom));
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  background: var(--color-surface);
  box-shadow: var(--shadow-sheet);
  overflow-y: auto;
  overscroll-behavior: contain;
  transform: translateY(100%);
  transition: transform var(--dur-sheet) var(--ease-out);
}
.sheet.is-open .sheet-panel { transform: translateY(0); }

.sheet-grabber {
  width: 36px;
  height: 4px;
  margin: 0 auto 12px;
  border-radius: 2px;
  background: var(--color-line);
}

.sheet-view-success { display: none; }
.sheet-panel[data-view="success"] .sheet-view-form { display: none; }
.sheet-panel[data-view="success"] .sheet-view-success { display: block; animation: pop-in var(--dur-sheet) var(--ease-out) backwards; }

.sheet-title { margin: 0 0 12px; font-size: var(--font-size-lg); font-weight: 700; }

.sheet-order {
  margin-bottom: 18px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: var(--color-page);
  font-size: var(--font-size-sm);
}
.sheet-order-head { display: flex; justify-content: space-between; gap: 12px; font-weight: 700; }
.sheet-order-head span:last-child { font-variant-numeric: tabular-nums; }
.sheet-order-lines { margin: 6px 0 0; color: var(--color-text-soft); }

.fields { margin: 0; padding: 0; border: 0; min-width: 0; }
.fields:disabled { opacity: .6; }

.field { display: block; margin-bottom: 12px; }
.field-label { display: block; margin-bottom: 6px; color: var(--color-text-soft); font-size: var(--font-size-sm); font-weight: 600; }
.field-label em { font-style: normal; font-weight: 400; color: var(--color-text-faint); }
.field-input {
  display: block;
  width: 100%;
  height: 48px;
  padding: 0 14px;
  border: 1.5px solid var(--color-line);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  font-size: var(--font-size-input);
  transition: border-color var(--dur-select) var(--ease-out);
}
.field-input:focus { border-color: var(--color-accent); }
.field-input.is-invalid { border-color: var(--color-danger); }
.field-textarea { height: auto; min-height: 72px; padding: 12px 14px; resize: none; line-height: 1.4; }
.field-error { display: block; min-height: 0; margin-top: 4px; color: var(--color-danger); font-size: var(--font-size-xs); }
.field-error:empty { display: none; }

.hp { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }

.privacy {
  margin: 4px 0 10px;
  color: var(--color-text-soft);
  font-size: var(--font-size-xs);
  line-height: 1.5;
}

.consent {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  font-size: var(--font-size-sm);
  cursor: pointer;
}
.consent input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.consent-box {
  position: relative;
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  border: 1.5px solid var(--color-line);
  border-radius: 7px;
  transition: background-color var(--dur-select) var(--ease-out), border-color var(--dur-select) var(--ease-out);
}
.consent-box::after {
  content: "";
  position: absolute;
  left: 6.5px;
  top: 2.5px;
  width: 5px;
  height: 10px;
  border: solid var(--color-accent-text);
  border-width: 0 2px 2px 0;
  rotate: 45deg;
  opacity: 0;
  scale: .5;
  transition: opacity var(--dur-select) var(--ease-out), scale var(--dur-select) var(--ease-spring);
}
.consent input:checked + .consent-box { background: var(--color-accent); border-color: var(--color-accent); }
.consent input:checked + .consent-box::after { opacity: 1; scale: 1; }
.consent input:focus-visible + .consent-box { outline: 2px solid var(--color-focus); outline-offset: 2px; }
.consent.is-invalid .consent-box { border-color: var(--color-danger); }

.form-message {
  min-height: 0;
  margin: 10px 0 0;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--color-page);
  color: var(--color-text-soft);
  font-size: var(--font-size-sm);
}
.form-message:empty { display: none; }
.form-message.is-error { background: #FDF0EA; color: var(--color-danger); }

.sheet-actions { display: flex; gap: 10px; margin-top: 16px; }
.sheet-actions .btn-ghost { flex: 0 0 auto; }
.sheet-actions .submit-btn { flex: 1 1 auto; }

.spinner {
  display: none;
  width: 18px;
  height: 18px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
.is-sending .spinner { display: inline-block; }

/* 완료 화면 */
.sheet-view-success { text-align: center; padding-top: 8px; }
.success-mark {
  position: relative;
  width: 56px;
  height: 56px;
  margin: 4px auto 14px;
  border-radius: 50%;
  background: var(--color-success);
}
.success-mark::after {
  content: "";
  position: absolute;
  left: 20px;
  top: 13px;
  width: 12px;
  height: 22px;
  border: solid #fff;
  border-width: 0 3px 3px 0;
  rotate: 45deg;
}
.success-title { margin-bottom: 14px; }
.success-label { margin: 0; color: var(--color-text-soft); font-size: var(--font-size-sm); }
.success-number {
  margin: 2px 0 16px;
  font-size: 44px;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.sheet-view-success .sheet-order { text-align: left; }
.success-message { margin: 0 0 6px; font-weight: 600; }
.success-demo { margin: 0 0 12px; color: var(--color-danger); font-size: var(--font-size-xs); }
.sheet-view-success .btn-block { margin-top: 12px; }


/* =========================================================
   오류 / 기타
   ========================================================= */
.app-error {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 24px;
  background: var(--color-page);
  text-align: center;
}
.app-error-title { margin: 0; font-size: var(--font-size-lg); font-weight: 700; }
.app-error-detail { margin: 0 0 12px; color: var(--color-text-soft); font-size: var(--font-size-sm); white-space: pre-line; }

/* 로컬에서만 보이는 products.json 경고 알림 */
.dev-toast {
  position: fixed;
  left: 12px;
  top: calc(12px + env(safe-area-inset-top));
  z-index: 20;
  max-width: calc(100% - 24px);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: #3B2A00;
  color: #FFE8A3;
  font-size: var(--font-size-xs);
  box-shadow: var(--shadow-raised);
  animation: fade-in 200ms both;
}

.noscript { padding: 24px; text-align: center; }


/* =========================================================
   데스크톱: 가운데 정렬된 폰 크기 화면
   ========================================================= */
@media (min-width: 560px) and (min-height: 601px) {
  body { padding: 24px 0; }
  .app { min-height: calc(100dvh - 48px); }
  .panel { border-radius: var(--radius-lg); }
  .checkout { border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
  .sheet { align-items: center; }
  .sheet-panel { border-radius: var(--radius-lg); max-width: 420px; margin-bottom: 0; }
}


/* =========================================================
   가로로 넓고 낮은 화면 (휴대폰을 가로로 돌렸을 때, 낮고 넓은 브라우저 창)
   미리보기는 왼쪽에 화면 높이만큼 크게, 선택지·요약·금액·주문은 오른쪽에
   ========================================================= */
@media (orientation: landscape) and (max-height: 600px) {
  :root {
    /* 화면 높이 - 위아래 여백 - 제품군 버튼 줄(46px) - 홈 바 등 안전 영역 */
    --preview-max: calc(100svh - 2 * var(--gap) - 46px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  }
  .app {
    flex-direction: row;
    max-width: 1000px;
    height: 100dvh;
    min-height: 0;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
  }
  .stage {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: var(--gap) var(--gutter) calc(var(--gap) + env(safe-area-inset-bottom));
  }
  .stage-row {
    width: calc(var(--preview-max) + var(--tab-width) + var(--tab-pop));
    max-width: none;
  }
  .panel {
    flex: 1 1 auto;
    min-width: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    border-radius: 0;
    box-shadow: -8px 0 32px rgba(31, 29, 26, .06);
  }
}


/* =========================================================
   효과 정의 (속도는 맨 위 --dur-* 변수로 조절)
   ========================================================= */
@keyframes fade-in { from { opacity: 0; } }
@keyframes fade-out { to { opacity: 0; } }
@keyframes stack-in { from { opacity: 0; transform: scale(.97); } }
@keyframes stack-out { to { opacity: 0; transform: scale(.98); } }
@keyframes panel-in-down { from { opacity: 0; transform: translateY(var(--panel-shift)); } }
@keyframes panel-in-up { from { opacity: 0; transform: translateY(calc(var(--panel-shift) * -1)); } }
@keyframes tab-in { from { opacity: 0; transform: translateX(14px); } }
@keyframes pop-in { from { opacity: 0; transform: scale(.96); } }
@keyframes bump-a { 40% { transform: scale(var(--price-bump-scale)); } }
@keyframes bump-b { 40% { transform: scale(var(--price-bump-scale)); } }
@keyframes skeleton-in { from { opacity: 0; } }
@keyframes pulse { 50% { opacity: .55; } }
@keyframes spin { to { transform: rotate(360deg); } }

/* 동작 줄이기: 등장 효과를 아예 끔
   (길이 0ms 애니메이션은 일부 브라우저에서 첫 프레임에 멈춰 보일 수 있어서 none 으로 끔) */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; }
  .spinner { animation: spin 1.6s linear infinite !important; }   /* 전송 중 표시는 기능이라 유지 */
}
