/* =========================================================================
   Lotto Maker — 디자인 시스템
   토큰 → 프리미티브 → 컴포넌트 순서. 색은 전부 :root 의 커스텀 프로퍼티로만
   씁니다. 다크 모드는 토큰만 다시 정의하고 컴포넌트 규칙은 건드리지 않습니다.
   ========================================================================= */

/* ---------- 1. 토큰 (라이트가 기준) ---------- */

:root {
  color-scheme: light;

  --bg: #f6f7fb;
  --bg-tint-a: #dbe4ff;
  --bg-tint-b: #ffe3ec;
  --surface: #ffffff;
  --surface-2: #f1f3f9;
  --surface-sunken: #eceff7;
  --border: #e2e6f0;
  --border-strong: #cdd4e4;

  --text: #14161d;
  --text-dim: #5b6379;
  --text-faint: #8b93a7;

  --accent: #4c5cf5;
  --accent-hover: #3d4ce8;
  --accent-fg: #ffffff;
  --accent-soft: #e8ebff;
  --accent-ring: rgba(76, 92, 245, 0.35);

  --good: #129a6b;
  --warn: #c2760a;
  --danger: #d2384a;

  /* 로또 공 — 실제 한국 로또 번호 구간 색 */
  --ball-y: #fbc400;
  --ball-b: #3ba7e0;
  --ball-r: #f0525f;
  --ball-g: #7b8496;
  --ball-v: #86c231;
  --ball-fg: #ffffff;
  --ball-shade: rgba(0, 0, 0, 0.22);

  --shadow-sm: 0 1px 2px rgba(20, 22, 29, 0.06), 0 1px 3px rgba(20, 22, 29, 0.05);
  --shadow-md: 0 4px 10px rgba(20, 22, 29, 0.07), 0 12px 28px rgba(20, 22, 29, 0.07);
  --shadow-lg: 0 8px 20px rgba(20, 22, 29, 0.09), 0 28px 60px rgba(20, 22, 29, 0.11);

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 18px;
  --r-xl: 26px;
  --r-pill: 999px;

  --gap: clamp(0.75rem, 0.4rem + 1.2vw, 1.25rem);
  --pad-card: clamp(1.1rem, 0.7rem + 1.6vw, 1.9rem);
  --page-max: 1080px;

  --font: 'Pretendard Variable', Pretendard, -apple-system, BlinkMacSystemFont,
    'Apple SD Gothic Neo', 'Segoe UI', 'Malgun Gothic', Roboto, 'Helvetica Neue',
    system-ui, sans-serif;
  --font-num: ui-rounded, 'SF Pro Rounded', 'Segoe UI Variable Display', var(--font);

  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
  --dur: 220ms;
}

/* 시스템이 다크일 때. [data-theme='light'] 로 명시 선택하면 적용하지 않습니다. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;

    --bg: #0c0e14;
    --bg-tint-a: #1b2450;
    --bg-tint-b: #3a1c35;
    --surface: #151822;
    --surface-2: #1c2030;
    --surface-sunken: #10131c;
    --border: #262b3a;
    --border-strong: #363d52;

    --text: #eef0f7;
    --text-dim: #a3abc2;
    --text-faint: #6f7891;

    --accent: #8b98ff;
    --accent-hover: #a1acff;
    --accent-fg: #10121a;
    --accent-soft: #1e2444;
    --accent-ring: rgba(139, 152, 255, 0.4);

    --good: #35c496;
    --warn: #e0a63c;
    --danger: #ff7080;

    --ball-y: #e0ad00;
    --ball-b: #2f8fc4;
    --ball-r: #d64653;
    --ball-g: #69728a;
    --ball-v: #6ea828;
    --ball-shade: rgba(0, 0, 0, 0.4);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.5);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.45), 0 14px 32px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 24px rgba(0, 0, 0, 0.5), 0 32px 70px rgba(0, 0, 0, 0.55);
  }
}

:root[data-theme='dark'] {
  color-scheme: dark;

  --bg: #0c0e14;
  --bg-tint-a: #1b2450;
  --bg-tint-b: #3a1c35;
  --surface: #151822;
  --surface-2: #1c2030;
  --surface-sunken: #10131c;
  --border: #262b3a;
  --border-strong: #363d52;

  --text: #eef0f7;
  --text-dim: #a3abc2;
  --text-faint: #6f7891;

  --accent: #8b98ff;
  --accent-hover: #a1acff;
  --accent-fg: #10121a;
  --accent-soft: #1e2444;
  --accent-ring: rgba(139, 152, 255, 0.4);

  --good: #35c496;
  --warn: #e0a63c;
  --danger: #ff7080;

  --ball-y: #e0ad00;
  --ball-b: #2f8fc4;
  --ball-r: #d64653;
  --ball-g: #69728a;
  --ball-v: #6ea828;
  --ball-shade: rgba(0, 0, 0, 0.4);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.5);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.45), 0 14px 32px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 24px rgba(0, 0, 0, 0.5), 0 32px 70px rgba(0, 0, 0, 0.55);
}

/* ---------- 2. 리셋 ---------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font);
  font-size: clamp(0.95rem, 0.9rem + 0.2vw, 1.0625rem);
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;

  /* 안전망일 뿐입니다. 가로 넘침은 원인 쪽에서 고쳐야 합니다 — 여기서 숨기면
     잘린 내용으로 스크롤할 방법까지 같이 사라집니다. */
  overflow-x: clip;
}

/* 은은한 배경 광원. 고정이라 스크롤 성능에 영향을 주지 않습니다. */
body::before {
  content: '';
  position: fixed;
  inset: -20% -10% auto -10%;
  height: 70vh;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(45% 55% at 20% 0%, var(--bg-tint-a) 0%, transparent 70%),
    radial-gradient(40% 50% at 85% 10%, var(--bg-tint-b) 0%, transparent 70%);
  opacity: 0.55;
  filter: blur(10px);
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.25;
  letter-spacing: -0.02em;
  font-weight: 700;
  text-wrap: balance;
}

p {
  margin: 0;
}

a {
  color: inherit;
  text-decoration: none;
}

ul,
ol {
  margin: 0;
  padding: 0;
  list-style: none;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  cursor: pointer;
}

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

:where(a, button, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

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

/* ---------- 3. 레이아웃 프리미티브 ---------- */

.wrap {
  width: min(100% - 2rem, var(--page-max));
  margin-inline: auto;
}

.skip {
  position: absolute;
  inset-inline-start: 0.5rem;
  top: -100%;
  z-index: 100;
  padding: 0.6rem 1rem;
  border-radius: var(--r-md);
  background: var(--accent);
  color: var(--accent-fg);
  font-weight: 600;
  transition: top var(--dur) var(--ease);
}

.skip:focus {
  top: 0.5rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
}

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

/* ---------- 4. 헤더 ---------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--bg); /* color-mix 미지원 브라우저용 폴백 */
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
}

.site-header__row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: 60px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  font-size: 1.0625rem;
  margin-inline-end: auto;
}

.brand__mark {
  width: 30px;
  height: 30px;
  flex: none;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: var(--r-md);
  color: var(--text-dim);
  border: 1px solid transparent;
  transition:
    background var(--dur) var(--ease),
    color var(--dur) var(--ease),
    border-color var(--dur) var(--ease);
}

.icon-btn:hover {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}

.icon-btn svg {
  width: 19px;
  height: 19px;
}

/* ---------- 언어 메뉴 ---------- */

.langmenu {
  position: relative;
}

/* <details> 기본 삼각형 제거 */
.langmenu > summary {
  list-style: none;
  cursor: pointer;
}

.langmenu > summary::-webkit-details-marker {
  display: none;
}

.lang-btn {
  width: auto;
  gap: 0.35rem;
  padding-inline: 0.6rem;
  font-size: 0.8125rem;
  font-weight: 650;
  display: inline-flex;
  align-items: center;
}

.lang-btn svg {
  width: 17px;
  height: 17px;
  flex: none;
}

/* 좁은 화면에서는 지구본만 남깁니다 — 언어 이름이 헤더를 밀어냅니다. */
@media (max-width: 480px) {
  .lang-btn__name {
    display: none;
  }
  .lang-btn {
    padding-inline: 0;
    width: 38px;
    justify-content: center;
  }
}

.langmenu[open] > summary {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}

.langmenu__list {
  position: absolute;
  z-index: 50;
  top: calc(100% + 0.4rem);
  inset-inline-end: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(8.5rem, 1fr));
  gap: 0.1rem;
  padding: 0.35rem;
  max-height: min(70vh, 28rem);
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
}

@media (max-width: 420px) {
  .langmenu__list {
    grid-template-columns: 1fr;
    /* 화면 밖으로 나가지 않게 뷰포트 안에 가둡니다 */
    max-width: calc(100vw - 2rem);
  }
}

.langmenu__list a {
  padding: 0.5rem 0.7rem;
  border-radius: var(--r-sm);
  font-size: 0.875rem;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}

.langmenu__list a:hover {
  background: var(--surface-2);
  color: var(--text);
}

.langmenu__list a[aria-current='true'] {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
}

/* ---------- 5. 선택 컨트롤 (구버전 48항목 드롭다운의 대체) ---------- */

/*
 * 라벨과 컨트롤을 2열 그리드로 놓습니다.
 *
 * 첫 열이 auto 라서 두 라벨 중 넓은 쪽에 맞춰 자동으로 잡힙니다. 고정폭(4.5rem)일
 * 때는 태국어("จำนวนตัวเลข")·힌디어("संख्याओं की गिनती")처럼 긴 라벨이 두 줄로
 * 접혔는데, 언어가 17개면 모두를 만족하는 고정값이 존재하지 않습니다.
 *
 * 둘째 열의 minmax(0, 1fr) 이 핵심입니다. 그냥 1fr 이면 그리드 아이템의 기본
 * min-width:auto 때문에 내용 너비 아래로 못 줄어들고, .seg 의 overflow-x 가
 * 작동하지 못해 문서 전체가 옆으로 밀립니다.
 */
.picker {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 0.55rem 0.8rem;
  padding-block: 0.85rem 1rem;
}

.picker__label {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-faint);
  white-space: nowrap;
}

/*
 * 작은 라벨들에 준 letter-spacing 은 라틴 문자에서만 좋습니다.
 * 아랍 문자는 글자가 서로 이어져야 하는데 자간을 벌리면 연결이 끊어지고,
 * 데바나가리·태국 문자도 자음·모음 결합이 어긋나 보입니다.
 */
:root[lang='ar'] :is(.picker__label, .hero__eyebrow, .stat__title, .related h2),
:root[lang='hi'] :is(.picker__label, .hero__eyebrow, .stat__title, .related h2),
:root[lang='th'] :is(.picker__label, .hero__eyebrow, .stat__title, .related h2) {
  letter-spacing: normal;
}

/* 좁은 화면에서는 라벨을 위로 올려 컨트롤에 가로폭을 다 줍니다. */
@media (max-width: 560px) {
  .picker {
    grid-template-columns: minmax(0, 1fr);
    gap: 0.3rem;
  }

  /* 두 번째 묶음 앞에 숨 쉴 틈 */
  .picker__label:nth-of-type(2) {
    margin-top: 0.5rem;
  }
}

/*
 * 가로 스크롤 알림.
 *
 * 좁은 화면에서 칸이 잘리면 잘린 항목이 살짝 보이긴 하지만, 그것만으로는
 * "옆에 더 있다"가 읽히지 않습니다(6개까지만 있는 줄 알았다는 제보). 넘칠 때만
 * 가장자리에 화살표를 띄우고, 누르면 실제로 넘어갑니다.
 * 표시 여부는 app.js 가 has-prev / has-next 클래스로 켜고 끕니다.
 */
.seg-wrap {
  position: relative;
  min-width: 0;
}

.seg-more {
  position: absolute;
  inset-block: 1px;
  inline-size: 2.25rem;
  display: none;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: var(--r-pill);
  color: var(--text);
  cursor: pointer;
}

.seg-more svg {
  width: 18px;
  height: 18px;
  /* 화살표는 "읽는 방향의 끝"을 가리켜야 합니다 — RTL 에서는 뒤집습니다. */
  transform: scaleX(var(--chev, 1));
}

.seg-wrap.has-prev .seg-more--start,
.seg-wrap.has-next .seg-more--end {
  display: grid;
}

.seg-more--start {
  inset-inline-start: 1px;
  justify-content: start;
  padding-inline-start: 0.15rem;
  --chev: -1;
  background: linear-gradient(to left, transparent, var(--surface-sunken) 45%);
}

.seg-more--end {
  inset-inline-end: 1px;
  justify-content: end;
  padding-inline-end: 0.15rem;
  background: linear-gradient(to right, transparent, var(--surface-sunken) 45%);
}

[dir='rtl'] .seg-more--start {
  --chev: 1;
  background: linear-gradient(to right, transparent, var(--surface-sunken) 45%);
}

[dir='rtl'] .seg-more--end {
  --chev: -1;
  background: linear-gradient(to left, transparent, var(--surface-sunken) 45%);
}

.seg-more:hover {
  color: var(--accent);
}

.seg-more:active svg {
  transform: scaleX(var(--chev, 1)) scale(0.85);
}

.seg {
  display: flex;
  gap: 0.25rem;
  padding: 0.25rem;
  border-radius: var(--r-pill);
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
  scroll-snap-type: x proximity;

  /* 플렉스 아이템의 기본 min-width 는 auto 라서, 이게 없으면 내용 너비 아래로
     줄어들지 않습니다. 그러면 위의 overflow-x 가 영영 작동하지 못하고
     좁은 화면에서 문서 전체를 옆으로 밀어냅니다(번호 개수 8칸 = 약 430px). */
  flex: 1;
  min-width: 0;
}

.seg::-webkit-scrollbar {
  display: none;
}

.seg__item {
  flex: 1 0 auto;
  scroll-snap-align: center;
  padding: 0.42rem 0.85rem;
  border-radius: var(--r-pill);
  font-size: 0.875rem;
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
  color: var(--text-dim);
  transition:
    background var(--dur) var(--ease),
    color var(--dur) var(--ease),
    box-shadow var(--dur) var(--ease);
}

.seg__item:hover {
  color: var(--text);
  background: var(--surface);
}

.seg__item[aria-current='page'] {
  background: var(--accent);
  color: var(--accent-fg);
  box-shadow: var(--shadow-sm);
}

/* ---------- 6. 히어로 (최근 추첨) ---------- */

.hero {
  position: relative;
  overflow: hidden;
  padding: var(--pad-card);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  background: var(--surface);
  border: 1px solid var(--border);
}

.hero::after {
  content: '';
  position: absolute;
  inset-inline: 0;
  top: 0;
  height: 3px;
  background: linear-gradient(
    90deg,
    var(--ball-y),
    var(--ball-b),
    var(--ball-r),
    var(--ball-g),
    var(--ball-v)
  );
}

.hero__top {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem 0.75rem;
  margin-bottom: 0.35rem;
}

.hero__eyebrow {
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
}

.hero h1 {
  font-size: clamp(1.35rem, 1.05rem + 1.5vw, 2rem);
  width: 100%;
}

.hero__lede {
  margin-top: 0.5rem;
  max-width: 62ch;
  color: var(--text-dim);
  font-size: 0.9375rem;
}

.hero__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 1rem;
  margin-top: 0.5rem;
  font-size: 0.875rem;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

.hero__meta button {
  color: var(--accent);
  font-size: inherit;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* 공 배치 */
.balls {
  display: flex;
  flex-wrap: wrap;
  gap: clamp(0.4rem, 0.2rem + 0.8vw, 0.7rem);
  margin: clamp(1rem, 0.6rem + 1.4vw, 1.6rem) 0 0.25rem;
}

.ball {
  --size: clamp(2.75rem, 2rem + 3.2vw, 3.9rem);
  position: relative;
  display: grid;
  place-items: center;
  width: var(--size);
  height: var(--size);
  border-radius: 50%;
  font-family: var(--font-num);
  font-size: calc(var(--size) * 0.4);
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--ball-fg);
  background: var(--tone);
  box-shadow:
    inset 0 calc(var(--size) * -0.12) calc(var(--size) * 0.16) var(--ball-shade),
    inset 0 calc(var(--size) * 0.06) calc(var(--size) * 0.1) rgba(255, 255, 255, 0.35),
    var(--shadow-sm);
  animation: ball-in 420ms var(--ease) backwards;
  animation-delay: calc(var(--i, 0) * 45ms);
}

/* 광택 하이라이트 */
.ball::before {
  content: '';
  position: absolute;
  top: 12%;
  left: 18%;
  width: 34%;
  height: 26%;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.5);
  filter: blur(2px);
}

@keyframes ball-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.8);
  }
}

.ball--y { --tone: var(--ball-y); }
.ball--b { --tone: var(--ball-b); }
.ball--r { --tone: var(--ball-r); }
.ball--g { --tone: var(--ball-g); }
.ball--v { --tone: var(--ball-v); }

.ball--sm {
  --size: clamp(2rem, 1.7rem + 1.1vw, 2.4rem);
  animation: none;
}

.ball--xs {
  --size: 1.75rem;
  animation: none;
  font-size: 0.75rem;
}

/* 카운트다운 + 액션 */
.hero__bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  margin-top: clamp(1rem, 0.7rem + 1vw, 1.5rem);
  padding-top: clamp(0.9rem, 0.7rem + 0.8vw, 1.2rem);
  border-top: 1px solid var(--border);
}

.countdown {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin-inline-end: auto;
  font-size: 0.875rem;
  color: var(--text-dim);
}

.countdown__time {
  font-family: var(--font-num);
  font-size: 1.05rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  letter-spacing: 0.01em;
}

.countdown__ring {
  width: 26px;
  height: 26px;
  flex: none;
  transform: rotate(-90deg);
}

.countdown__ring circle {
  fill: none;
  stroke-width: 3;
  stroke-linecap: round;
}

.countdown__ring .track {
  stroke: var(--border-strong);
}

.countdown__ring .fill {
  stroke: var(--accent);
  transition: stroke-dashoffset 1s linear;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.95rem;
  border-radius: var(--r-pill);
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 0.875rem;
  font-weight: 650;
  color: var(--text);
  transition:
    background var(--dur) var(--ease),
    border-color var(--dur) var(--ease),
    transform 120ms var(--ease);
}

.btn svg {
  width: 15px;
  height: 15px;
}

.btn:hover {
  border-color: var(--border-strong);
  background: var(--surface);
}

.btn:active {
  transform: scale(0.96);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn--primary {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-fg);
}

.btn--primary:hover {
  background: var(--accent-hover);
}

.btn--ok {
  color: var(--good);
  border-color: var(--good);
}

/* ---------- 7. 탭 ---------- */

.tabs {
  display: flex;
  gap: 0.35rem;
  margin: clamp(1.5rem, 1rem + 2vw, 2.5rem) 0 1rem;
  border-bottom: 1px solid var(--border);
}

.tab {
  position: relative;
  padding: 0.6rem 0.2rem;
  margin-inline-end: 1.2rem;
  font-weight: 650;
  color: var(--text-faint);
  transition: color var(--dur) var(--ease);
}

.tab:hover {
  color: var(--text);
}

.tab[aria-selected='true'] {
  color: var(--text);
}

.tab[aria-selected='true']::after {
  content: '';
  position: absolute;
  inset-inline: 0;
  bottom: -1px;
  height: 2px;
  border-radius: 2px;
  background: var(--accent);
}

.tab__count {
  margin-inline-start: 0.35rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

[hidden] {
  display: none !important;
}

/* ---------- 8. 이력 ---------- */

.history {
  display: grid;
  gap: 0.5rem;
  content-visibility: auto;
  contain-intrinsic-size: auto 640px;
}

.draw {
  display: grid;
  grid-template-columns: 2.25rem 1fr auto;
  align-items: center;
  gap: 0.35rem 0.9rem;
  padding: 0.75rem 0.9rem;
  border-radius: var(--r-md);
  background: var(--surface);
  border: 1px solid var(--border);
  transition: border-color var(--dur) var(--ease);
}

.draw:hover {
  border-color: var(--border-strong);
}

.draw--latest {
  border-color: var(--accent);
  background: var(--accent-soft);
  background: color-mix(in srgb, var(--accent-soft) 60%, var(--surface));
}

.draw__no {
  font-family: var(--font-num);
  font-size: 0.8125rem;
  font-weight: 700;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

.draw__balls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.draw__side {
  display: grid;
  justify-items: end;
  gap: 0.1rem;
  font-size: 0.75rem;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.draw__time {
  color: var(--text-dim);
  font-size: 0.8125rem;
}

.chip {
  display: inline-block;
  padding: 0.05rem 0.45rem;
  border-radius: var(--r-pill);
  background: var(--accent);
  color: var(--accent-fg);
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

@media (max-width: 560px) {
  .draw {
    grid-template-columns: 2rem 1fr;
  }
  .draw__side {
    grid-column: 2;
    justify-items: start;
  }
}

/* ---------- 9. 통계 ---------- */

.stats {
  display: grid;
  gap: var(--gap);
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr));
}

.stat {
  padding: 1.1rem 1.15rem;
  border-radius: var(--r-lg);
  background: var(--surface);
  border: 1px solid var(--border);
}

.stat--wide {
  grid-column: 1 / -1;
}

.stat__title {
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 0.85rem;
}

.stat__big {
  font-family: var(--font-num);
  font-size: 1.75rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.stat__sub {
  font-size: 0.8125rem;
  color: var(--text-dim);
  margin-top: 0.2rem;
}

/* 출현 빈도 막대 */
.freq {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(28px, 1fr));
  gap: 0.3rem;
  align-items: end;
}

.freq__col {
  display: grid;
  gap: 0.25rem;
  justify-items: center;
}

.freq__bar {
  width: 100%;
  min-height: 3px;
  height: calc(3px + var(--h) * 46px);
  border-radius: 3px;
  background: var(--tone);
  opacity: calc(0.28 + var(--h) * 0.72);
  transition: height var(--dur) var(--ease);
}

.freq__n {
  font-family: var(--font-num);
  font-size: 0.625rem;
  font-weight: 600;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

/* 홀짝 막대 */
.split {
  display: flex;
  height: 10px;
  border-radius: var(--r-pill);
  overflow: hidden;
  background: var(--surface-sunken);
  margin-bottom: 0.6rem;
}

.split__odd {
  background: var(--accent);
}

.split__even {
  background: var(--ball-v);
}

.split-legend {
  display: flex;
  gap: 1rem;
  font-size: 0.8125rem;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

.split-legend span::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-inline-end: 0.4rem;
  background: var(--dot);
}

.ball-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

/* ---------- 10. 상태 (로딩 / 오류 / 빈 값) ---------- */

.skeleton {
  border-radius: var(--r-md);
  background: linear-gradient(
    100deg,
    var(--surface-2) 30%,
    var(--surface-sunken) 50%,
    var(--surface-2) 70%
  );
  background-size: 220% 100%;
  animation: shimmer 1.4s var(--ease) infinite;
}

@keyframes shimmer {
  to {
    background-position: -120% 0;
  }
}

.skeleton--ball {
  width: clamp(2.75rem, 2rem + 3.2vw, 3.9rem);
  aspect-ratio: 1;
  border-radius: 50%;
}

.skeleton--row {
  height: 62px;
}

.notice {
  display: grid;
  justify-items: center;
  gap: 0.6rem;
  padding: 2.5rem 1.25rem;
  text-align: center;
  border-radius: var(--r-lg);
  border: 1px dashed var(--border-strong);
  color: var(--text-dim);
}

.notice h3 {
  font-size: 1.05rem;
  color: var(--text);
}

.banner {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.9rem;
  margin-bottom: 0.75rem;
  border-radius: var(--r-md);
  background: var(--surface-2);
  background: color-mix(in srgb, var(--warn) 14%, var(--surface));
  border: 1px solid var(--warn);
  border-color: color-mix(in srgb, var(--warn) 35%, transparent);
  font-size: 0.8125rem;
  color: var(--text);
}

/* 화면 낭독기 전용 알림 영역 */
.live {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}

/* ---------- 11. 관련 링크 ---------- */

.related {
  margin-top: clamp(2rem, 1.5rem + 2vw, 3rem);
}

.related h2 {
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 0.75rem;
}

.related__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.5rem;
}

.related__link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.6rem 0.85rem;
  border-radius: var(--r-md);
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 0.875rem;
  font-weight: 600;
  transition:
    border-color var(--dur) var(--ease),
    transform var(--dur) var(--ease);
}

.related__link:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.related__link span {
  color: var(--text-faint);
  font-weight: 500;
  font-size: 0.8125rem;
}

/* ---------- 12. 광고 슬롯 ---------- */

/* 광고 단위를 직접 넣을 경우 자리를 미리 잡아 레이아웃이 밀리지 않게 합니다. */
.ad-slot {
  display: block;
  margin: clamp(1.5rem, 1rem + 2vw, 2.5rem) 0;
  min-height: 100px;
  text-align: center;
  overflow: hidden;
}

/* 자동 광고는 이 컨테이너 안이 아니라 문서 곳곳에 스스로 끼어듭니다.
   그래서 비어 있는 슬롯은 접어야 합니다 — 안 그러면 히어로와 이력 사이에
   아무것도 없는 200px 짜리 구멍이 영구히 남습니다. */
.ad-slot:empty {
  min-height: 0;
  margin: 0;
}

/* ---------- 13. 푸터 ---------- */

.site-footer {
  margin-top: clamp(3rem, 2rem + 4vw, 5rem);
  padding-block: 2rem 2.5rem;
  border-top: 1px solid var(--border);
  background: var(--surface-sunken);
  font-size: 0.8125rem;
  color: var(--text-dim);
}

.site-footer nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.25rem;
  margin-bottom: 1.1rem;
  font-weight: 600;
  color: var(--text);
}

.site-footer nav a:hover {
  color: var(--accent);
}

.site-footer__legal {
  display: grid;
  gap: 0.35rem;
  max-width: 60ch;
}

.site-footer__biz {
  color: var(--text-faint);
  font-size: 0.75rem;
  line-height: 1.7;
}

/* ---------- 14. 본문 페이지 (약관 · 소개 등) ---------- */

.prose {
  max-width: 72ch;
  margin-block: clamp(1.5rem, 1rem + 2vw, 2.5rem);
}

.prose h1 {
  font-size: clamp(1.6rem, 1.2rem + 2vw, 2.25rem);
  margin-bottom: 0.75rem;
}

.prose h2 {
  font-size: 1.15rem;
  margin-top: 2rem;
  margin-bottom: 0.5rem;
}

.prose h3 {
  font-size: 1rem;
  margin-top: 1.35rem;
  margin-bottom: 0.35rem;
}

.prose p,
.prose li {
  color: var(--text-dim);
  margin-bottom: 0.6rem;
}

.prose ul {
  list-style: disc;
  padding-inline-start: 1.25rem;
  margin-bottom: 1rem;
}

.prose a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.prose .lede {
  font-size: 1.0625rem;
  color: var(--text);
}

.prose table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1.25rem;
  font-size: 0.875rem;
}

.prose th,
.prose td {
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  text-align: start;
  vertical-align: top;
}

.prose th {
  background: var(--surface-2);
  font-weight: 700;
  white-space: nowrap;
}

/* 폼 */
.field {
  display: grid;
  gap: 0.35rem;
  margin-bottom: 1rem;
}

.field label {
  font-size: 0.8125rem;
  font-weight: 700;
}

.field input,
.field textarea {
  font: inherit;
  width: 100%;
  padding: 0.65rem 0.8rem;
  border-radius: var(--r-md);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  transition:
    border-color var(--dur) var(--ease),
    box-shadow var(--dur) var(--ease);
}

.field input:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.field textarea {
  resize: vertical;
  min-height: 9rem;
}

.form-status {
  margin-top: 0.9rem;
  font-size: 0.875rem;
  font-weight: 600;
  min-height: 1.4em;
}

.form-status[data-kind='ok'] {
  color: var(--good);
}

.form-status[data-kind='error'] {
  color: var(--danger);
}

/* ---------- 15. RTL (아랍어) ---------- */

/*
 * 레이아웃은 대부분 논리 속성(margin-inline, inset-inline, text-align: start)으로
 * 짜여 있어 dir="rtl" 만으로 뒤집힙니다. 아래는 그렇게 되지 않는 것들입니다.
 */

/* 공 안의 숫자는 항상 왼→오 입니다. 아랍어 문맥에서 "12" 가 뒤집히면 안 됩니다. */
[dir='rtl'] .ball,
[dir='rtl'] .countdown__time,
[dir='rtl'] .draw__no,
[dir='rtl'] .freq__n,
[dir='rtl'] .stat__big {
  direction: ltr;
  unicode-bidi: isolate;
}

/* 공의 광택은 왼쪽 위 광원 — 방향과 무관하게 그대로 둡니다. */
[dir='rtl'] .ball::before {
  left: auto;
  right: 18%;
}

/* 카운트다운 링은 12시 방향에서 시작해야 합니다(회전은 뒤집지 않습니다). */
[dir='rtl'] .countdown__ring {
  transform: rotate(-90deg) scaleX(-1);
}

/* ---------- 16. 페이지 전환 (소프트 내비게이션) ---------- */

@media (prefers-reduced-motion: no-preference) {
  .swapping #view {
    opacity: 0.45;
    transition: opacity 120ms var(--ease);
  }
}

/* ---------- 17. 번호 맞추기 게임 ---------- */

.game {
  margin-top: clamp(1rem, 0.6rem + 1.4vw, 1.6rem);
  padding: clamp(0.9rem, 0.6rem + 1.2vw, 1.4rem);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.game__title {
  font-size: 1rem;
  margin: 0 0 0.35rem;
}

.game__lede {
  margin: 0 0 0.7rem;
  color: var(--text-dim);
  font-size: 0.9rem;
}

.game__bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.8rem;
}

/* 번호 선택판 — 공과 같은 구간 색을 테두리로 씁니다 */
.gpick {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 0.35rem;
}

@media (max-width: 560px) {
  .gpick {
    grid-template-columns: repeat(6, 1fr);
  }
}

.gpick__n {
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 2px solid var(--tone);
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--font-num);
  font-size: 0.9rem;
  font-weight: 700;
  transition:
    background var(--dur) var(--ease),
    color var(--dur) var(--ease),
    transform 120ms var(--ease);
}

.gpick__n:hover {
  transform: scale(1.08);
}

.gpick__n.is-on {
  background: var(--tone);
  color: var(--ball-fg);
  box-shadow: inset 0 -0.4em 0.5em var(--ball-shade);
}

/* 내 번호 줄 */
.game__mine {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.game__label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-dim);
}

.game__result {
  margin: 0.7rem 0 0;
  font-weight: 700;
}

.game__result--jackpot {
  color: var(--accent);
  font-size: 1.1rem;
}

.game__sub {
  margin: 0.15rem 0 0;
  font-size: 0.82rem;
  color: var(--text-dim);
}

/* 적중한 공 — 번호를 가리지 않도록 테두리·빛으로만 강조합니다 */
.ball--hit {
  box-shadow:
    0 0 0 3px var(--surface),
    0 0 0 5.5px var(--accent),
    0 0 14px 2px var(--accent),
    inset 0 calc(var(--size) * -0.12) calc(var(--size) * 0.16) var(--ball-shade);
}

@media (prefers-reduced-motion: no-preference) {
  .ball--hit {
    animation:
      ball-in 420ms var(--ease) backwards,
      hit-pulse 1.2s var(--ease) infinite alternate;
    animation-delay: calc(var(--i, 0) * 45ms), 0s;
  }

  @keyframes hit-pulse {
    from {
      box-shadow:
        0 0 0 3px var(--surface),
        0 0 0 5.5px var(--accent),
        0 0 8px 1px var(--accent),
        inset 0 calc(var(--size) * -0.12) calc(var(--size) * 0.16) var(--ball-shade);
    }
    to {
      box-shadow:
        0 0 0 3px var(--surface),
        0 0 0 5.5px var(--accent),
        0 0 18px 4px var(--accent),
        inset 0 calc(var(--size) * -0.12) calc(var(--size) * 0.16) var(--ball-shade);
    }
  }
}

/* 회차별 적중 배지 */
.chip--game {
  background: var(--surface-sunken);
  color: var(--text);
  border: 1px solid var(--border);
  font-family: var(--font-num);
}

/* ---------- 18. SNS 공유 폴백 패널 (데스크톱) ---------- */

.sharebox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(0, 0, 0, 0.55);
}

.sharebox__card {
  width: min(420px, 100%);
  max-height: 90vh;
  overflow: auto;
  display: grid;
  gap: 0.75rem;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.sharebox__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.sharebox__img {
  width: 100%;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
}

.sharebox__row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.sharebox__note {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-dim);
}

/* ---------- 19. 누적 성적표 ---------- */

.score {
  margin-top: 0.9rem;
  padding-top: 0.8rem;
  border-top: 1px dashed var(--border);
}

.score__sum {
  margin: 0.25rem 0 0.5rem;
  font-size: 0.82rem;
  color: var(--text-dim);
}

.score__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.score__chip {
  padding: 0.15rem 0.55rem;
  border-radius: var(--r-pill);
  border: 1px solid var(--border);
  background: var(--surface-sunken);
  font-family: var(--font-num);
  font-size: 0.78rem;
  font-weight: 700;
}

.score__chip--jackpot {
  border-color: var(--ball-y);
  background: var(--ball-y);
  color: #10121a;
}

.score__line {
  margin: 0.5rem 0 0;
  font-size: 0.82rem;
  font-weight: 700;
}

/* ---------- 20. 모바일 주소 안내 바 (하루 1회) ---------- */

.urlbar {
  position: fixed;
  inset-inline: 0.75rem;
  bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px));
  z-index: 900;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
}

@media (prefers-reduced-motion: no-preference) {
  .urlbar {
    animation: urlbar-in 360ms var(--ease) backwards;
  }

  @keyframes urlbar-in {
    from {
      transform: translateY(120%);
      opacity: 0;
    }
  }
}

.urlbar__body {
  flex: 1;
  min-width: 0;
}

.urlbar__text {
  margin: 0 0 0.15rem;
  font-size: 0.78rem;
  color: var(--text-dim);
}

.urlbar__host {
  display: block;
  font-family: var(--font-num);
  font-size: 0.85rem;
  overflow-wrap: anywhere;
}

.urlbar__close {
  padding: 0.35rem 0.55rem;
  flex-shrink: 0;
}

/* 성적표 접기/펼치기 — 기본은 접힌 상태 */
.score__head {
  cursor: pointer;
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-dim);
}

.score__head::-webkit-details-marker {
  display: none;
}

.score__head::before {
  content: '▸';
  transition: transform var(--dur) var(--ease);
}

.score[open] .score__head::before {
  transform: rotate(90deg);
}

[dir='rtl'] .score__head::before {
  content: '◂';
}

.score__head:hover {
  color: var(--text);
}

/* 성적표 — 최근 결과 목록 (점이 채워진 만큼 맞춘 것) */
.score__subhead {
  display: block;
  margin-top: 0.55rem;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.score__rows {
  display: grid;
  gap: 0.3rem;
  margin-top: 0.35rem;
}

.score__row {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.3rem 0.55rem;
  border-radius: var(--r-sm);
  background: var(--surface-sunken);
  font-size: 0.8rem;
}

.score__row--jackpot {
  background: var(--ball-y);
  color: #10121a;
  font-weight: 700;
}

.score__time {
  font-family: var(--font-num);
  color: var(--text-faint);
  flex-shrink: 0;
}

.score__row--jackpot .score__time {
  color: inherit;
}

.score__dots {
  display: inline-flex;
  gap: 0.2rem;
  flex-shrink: 0;
}

.score__dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  border: 1.5px solid var(--text-faint);
}

.score__dot.is-hit {
  background: var(--accent);
  border-color: var(--accent);
}

.score__row--jackpot .score__dot.is-hit {
  background: #10121a;
  border-color: #10121a;
}

.score__hitText {
  color: var(--text-dim);
}

.score__row--jackpot .score__hitText {
  color: inherit;
}
