*, *::before, *::after { box-sizing: border-box; }
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  touch-action: pan-x pan-y; /* 핀치 줌 차단 (iOS Safari 보강) */
  /* 가로 스크롤 안전장치 — 어떤 자식이 viewport 폭을 넘겨도 본문이 좌우로 밀리지
     않도록. 의도된 가로 스크롤 영역(.data-table-wrap 등)은 자체적으로
     overflow-x: auto 를 가지고 있어 영향받지 않는다. */
  overflow-x: hidden;
}
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--color-text);
  background: var(--color-surface);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

/* iOS Safari 자동 확대 방지 — input/select/textarea 폰트 사이즈가 16px 미만이면
   포커스 시 확대(zoom) 후 사용자가 손으로 축소해야 한다. 모바일에서만 16px 강제.
   체크박스/라디오/range/file/color 같이 텍스트 입력이 아닌 컨트롤은 영향 X. */
@media (max-width: 768px) {
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]):not([type="color"]),
  select,
  textarea {
    font-size: 16px;
  }
}

/* 모든 미디어/iframe 이 부모 폭을 넘어 가로 스크롤을 만들지 않도록. */
iframe { max-width: 100%; }
img, svg, video { max-width: 100%; height: auto; display: block; }
/* 썸네일 공통: 정해진 영역을 벗어나지 않고, 큰 이미지는 가운데 기준 crop. */
.inv-thumb,
.item-detail-thumb,
.box-inv-card .thumb,
.gift-card-thumb,
.ship-order-thumb,
.prize-thumb,
.box-stats-emoji,
.gift-thumb-mini,
.gift-confirm-thumb,
.pur-thumb,
.ship-item-thumb,
.draw-card .thumb,
.hof-thumb {
  overflow: hidden;
}
.inv-thumb img,
.item-detail-thumb img,
.box-inv-card .thumb img,
.gift-card-thumb img,
.ship-order-thumb img,
.prize-thumb img,
.box-stats-emoji img,
.gift-thumb-mini img,
.gift-confirm-thumb img,
.pur-thumb img,
.ship-item-thumb img,
.draw-card .thumb img,
.hof-thumb .hof-img,
.event-emoji img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
}
a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button {
  font: inherit;
  cursor: pointer;
  border: none;
  background: none;
  padding: 0;
  color: inherit;
}
button:focus-visible, a:focus-visible, input:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}
input, textarea, select {
  font: inherit;
  color: inherit;
}

h1, h2, h3, h4, h5, h6 { margin: 0; font-weight: var(--weight-bold); line-height: var(--leading-tight); }
p { margin: 0; }
ul, ol { margin: 0; padding: 0; list-style: none; }

/* 유틸 */
.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;
}
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-md);
  font-weight: var(--weight-medium);
  font-size: var(--text-base);
  transition: background .15s ease, color .15s ease, transform .05s ease;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-hover); }
.btn-secondary { background: var(--color-primary-soft); color: var(--color-primary); }
.btn-ghost { color: var(--color-text-sub); }
.btn-ghost:hover { background: var(--color-surface); }
.btn-block { width: 100%; }

/* 배지 */
.badge {
  display: inline-flex; align-items: center; gap: var(--space-1);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  background: var(--color-primary-soft);
  color: var(--color-primary);
}
.badge-accent { background: #FFECEC; color: var(--color-accent); }

/* 카드 공통 */
.card {
  background: var(--color-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

/* 스켈레톤 */
.skeleton {
  background: linear-gradient(90deg, #ECEEF5 25%, #F5F6FA 37%, #ECEEF5 63%);
  background-size: 400% 100%;
  animation: skel 1.4s ease infinite;
  border-radius: var(--radius-sm);
}
@keyframes skel {
  0% { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}

/* 스피너 / 로딩 오버레이 (공통 — ui.js showSpinner/hideSpinner) */
.spinner {
  display: inline-block;
  width: 20px; height: 20px;
  border: 2px solid rgba(124, 58, 237,.2);
  border-top-color: var(--color-point, #7C3AED);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex: none;
}
.spinner.sm { width: 14px; height: 14px; border-width: 2px; }
.spinner.lg { width: 32px; height: 32px; border-width: 3px; }
@keyframes spin {
  to { transform: rotate(360deg); }
}

.spinner-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 15, 30, 0.38);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9998;
  animation: overlay-fade 0.18s ease-out;
}
.spinner-overlay .spinner-box {
  background: #fff;
  padding: 18px 24px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: 0 12px 32px rgba(0,0,0,.22);
  min-width: 160px;
  max-width: 80vw;
}
.spinner-overlay .spinner-msg {
  color: #222;
  font-size: 14px;
  font-weight: 500;
}
@keyframes overlay-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* 버튼 로딩 상태 — lockButton 이 추가하는 클래스.
   텍스트 옆 스피너, 포인터/클릭 차단, 반투명. */
.btn-loading {
  pointer-events: none;
  position: relative;
  opacity: 0.75;
}
.btn-loading .spinner {
  width: 14px; height: 14px; border-width: 2px;
  border-color: rgba(255,255,255,.35);
  border-top-color: #fff;
  vertical-align: -2px;
  margin-right: 6px;
}
.btn-secondary.btn-loading .spinner,
.btn.btn-loading .spinner {
  border-color: rgba(124, 58, 237,.25);
  border-top-color: var(--color-point, #7C3AED);
}
