/*
 * 로또 6/45 - 흰색에서 연두로 번지는 그라데이션 캔버스 위에 반투명 유리 카드.
 *
 * 모양 규칙 (전 페이지 고정):
 *   카드 20px · 내부 블록 14px · 버튼/탭 999px(알약) · 마이크로 칩 6px
 * 강조색은 라임 하나뿐이다. over/under 는 브랜드색이 아니라 증감을 나누는 데이터 축척이다.
 */

:root {
  color-scheme: light;

  --fg: #131c0d;
  --dim: #5a6a51;
  --accent: #3d7a14;        /* 텍스트·선 위 강조. 흰 배경에서 AA 통과 */
  --accent-soft: #7cc142;   /* 채움용. 항상 어두운 글자와 함께 */
  --accent-tint: rgba(124, 193, 66, 0.14);
  --win: var(--accent);     /* 당첨은 별도 색이 아니라 같은 라임이다 */

  --surface: rgba(255, 255, 255, 0.72);
  --surface-solid: #fbfdf7; /* 유리를 못 쓸 때의 대체 */
  --inset: rgba(255, 255, 255, 0.52);
  --line: rgba(25, 45, 10, 0.09);
  --line-strong: rgba(25, 45, 10, 0.16);
  --shadow: 0 1px 2px rgba(40, 62, 20, 0.05), 0 12px 32px -16px rgba(40, 62, 20, 0.18);
  --ring: #1d2b12;          /* 보너스 볼 테두리. 5가지 볼 색 위에서 모두 보인다 */

  --over: #6aa62f;
  --under: #8296a4;

  /* 동행복권 공식 볼 색상 */
  --y: #fbc400; --b: #69c8f2; --r: #ff7272; --g: #9aa3b2; --e: #b0d840;

  --r-card: 20px;
  --r-block: 14px;
  --r-pill: 999px;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --fg: #e9f1e3;
    --dim: #9aab92;
    --accent: #a8e364;
    --accent-soft: #7cc142;
    --accent-tint: rgba(124, 193, 66, 0.16);
    --surface: rgba(255, 255, 255, 0.055);
    --surface-solid: #131a12;
    --inset: rgba(255, 255, 255, 0.04);
    --line: rgba(255, 255, 255, 0.09);
    --line-strong: rgba(255, 255, 255, 0.16);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 16px 40px -20px rgba(0, 0, 0, 0.6);
    --ring: #cfe9a8;
    --over: #9ad459;
    --under: #7d90a0;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--fg);
  font: 15px/1.65 -apple-system, BlinkMacSystemFont, "Pretendard Variable", Pretendard,
        "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  background: var(--surface-solid);
  /* 한글은 단어 중간에서 끊지 않는다. 없으면 '회차번/호에' 처럼 잘린다. */
  word-break: keep-all;
  overflow-wrap: break-word;
}

/* 그라데이션 캔버스. 고정 레이어라 스크롤 중 다시 그리지 않는다.
   inset 을 음수로 둬서 패럴랙스로 밀려도 가장자리가 드러나지 않게 한다. */
body::before {
  content: "";
  position: fixed;
  inset: -18%;
  z-index: -1;
  pointer-events: none;
  will-change: transform;
  background:
    radial-gradient(78% 52% at 86% 4%, rgba(148, 209, 79, 0.30), transparent 62%),
    radial-gradient(64% 44% at 4% 26%, rgba(186, 231, 130, 0.26), transparent 64%),
    radial-gradient(130% 86% at 50% -14%, #e9f7d3 0%, #f4fbe9 34%, #ffffff 70%);
}

@media (prefers-color-scheme: dark) {
  body::before {
    background:
      radial-gradient(78% 52% at 86% 4%, rgba(124, 193, 66, 0.22), transparent 62%),
      radial-gradient(64% 44% at 4% 26%, rgba(90, 150, 50, 0.18), transparent 64%),
      radial-gradient(130% 86% at 50% -14%, #17240f 0%, #101710 38%, #0a0e0a 72%);
  }
}

/* 위에서 천천히 흐르는 블롭 레이어. transform 만 움직이므로 합성만 다시 된다. */
body::after {
  content: "";
  position: fixed;
  inset: -35%;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(34% 27% at 26% 30%, rgba(124, 193, 66, 0.26), transparent 70%),
    radial-gradient(29% 24% at 74% 64%, rgba(168, 227, 100, 0.22), transparent 72%);
}

@media (prefers-color-scheme: dark) {
  body::after {
    background:
      radial-gradient(34% 27% at 26% 30%, rgba(124, 193, 66, 0.14), transparent 70%),
      radial-gradient(29% 24% at 74% 64%, rgba(90, 160, 50, 0.13), transparent 72%);
  }
}

main, .top { max-width: 980px; margin: 0 auto; padding: 0 20px; }
.top { padding-top: 72px; padding-bottom: 4px; }

h1 {
  font-size: clamp(1.9rem, 1.15rem + 2.4vw, 2.75rem);
  line-height: 1.12;
  letter-spacing: -0.032em;
  font-weight: 700;
  margin: 0;
}
.sub { color: var(--dim); margin: 12px 0 0; font-size: .9375rem; }

.card {
  background: var(--surface);
  backdrop-filter: blur(24px) saturate(170%);
  -webkit-backdrop-filter: blur(24px) saturate(170%);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  padding: 24px;
  margin: 16px 0;
  box-shadow: var(--shadow);
  transition: transform .4s cubic-bezier(.16, 1, .3, 1), box-shadow .4s cubic-bezier(.16, 1, .3, 1);
}
@media (hover: hover) and (prefers-reduced-motion: no-preference) {
  .card:hover { transform: translateY(-2px); box-shadow: 0 2px 4px rgba(40,62,20,.06), 0 20px 44px -20px rgba(40,62,20,.26); }
}
.row { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); margin: 16px 0; }
.row .card { margin: 0; }

@media (prefers-reduced-transparency: reduce) {
  .card { background: var(--surface-solid); backdrop-filter: none; -webkit-backdrop-filter: none; }
}

/* 섹션 제목. 작은 대문자 라벨이 아니라 진짜 제목으로 둔다. */
.eyebrow {
  font-size: 1.0625rem;
  font-weight: 650;
  letter-spacing: -0.015em;
  color: var(--fg);
  margin: 0 0 14px;
}
.tag { color: var(--accent); font-weight: 600; }
.note { color: var(--dim); font-size: .8125rem; margin: -8px 0 16px; max-width: 68ch; }

/* 번호 볼 */
.ball {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 50%;
  font-size: .8125rem; font-weight: 700; color: #1b1b1b;
  font-variant-numeric: tabular-nums;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.45), 0 1px 2px rgba(30, 50, 15, 0.14);
}
.ball.y { background: var(--y); } .ball.b { background: var(--b); }
.ball.r { background: var(--r); } .ball.g { background: var(--g); }
.ball.e { background: var(--e); }
.ball.sm { width: 27px; height: 27px; font-size: .75rem; }
.ball.miss { opacity: .26; box-shadow: none; }
.ball.bonus { box-shadow: 0 0 0 2px var(--surface-solid), 0 0 0 4px var(--ring); }

/* 예상번호 세트 */
.sets { display: flex; flex-direction: column; gap: 8px; }
.set {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 12px 14px;
  background: var(--inset);
  border: 1px solid var(--line);
  border-radius: var(--r-block);
  transition: transform .3s cubic-bezier(.16, 1, .3, 1), border-color .3s, background-color .3s;
}
@media (hover: hover) and (prefers-reduced-motion: no-preference) {
  .set:hover { transform: translateY(-2px); border-color: var(--accent-soft); }
}
.set .label { width: 72px; flex: none; color: var(--dim); font-size: .75rem; }
.set .meta { margin-left: auto; color: var(--dim); font-size: .75rem; font-variant-numeric: tabular-nums; }
.set.hit { border-color: var(--accent-soft); background: var(--accent-tint); }
.set .rank { font-weight: 700; color: var(--win); font-size: .8125rem; }

/* 탭과 버튼 */
.tabs { display: flex; gap: 8px; flex-wrap: wrap; margin: 28px 0 0; }
.tabs button, #reroll {
  font: inherit; font-size: .875rem; font-weight: 500; color: var(--fg); cursor: pointer;
  background: var(--surface);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-pill);
  padding: 8px 17px;
  transition: background-color .2s cubic-bezier(.16,1,.3,1), border-color .2s, transform .12s;
}
.tabs button:hover, #reroll:hover { border-color: var(--accent-soft); }
.tabs button:active, #reroll:active { transform: scale(.97); }
.tabs button[aria-selected="true"] {
  background: var(--accent-soft); border-color: var(--accent-soft);
  color: #14200a; font-weight: 650;
}
#reroll { background: var(--accent-soft); border-color: var(--accent-soft); color: #14200a; font-weight: 600; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 4px; }

/* 요약 지표 */
.metrics { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(132px, 1fr)); }
.metric .k { color: var(--dim); font-size: .75rem; }
.metric .v {
  font-size: 1.375rem; font-weight: 600; font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em; margin: 2px 0;
}
.metric .v small { font-size: .8125rem; font-weight: 400; color: var(--dim); }

/* 번호 그리드 */
.grid { display: grid; grid-template-columns: repeat(9, 1fr); gap: 10px 6px; }
@media (max-width: 560px) { .grid { grid-template-columns: repeat(5, 1fr); } }
.cell { text-align: center; }
.cell .n { font-size: .6875rem; color: var(--dim); font-variant-numeric: tabular-nums; margin-top: 4px; }
.cell .track { height: 30px; display: flex; flex-direction: column; justify-content: flex-end; margin-bottom: 5px; }
.cell .fill { border-radius: 3px 3px 0 0; min-height: 2px; }
.cell .fill.over { background: var(--over); }
.cell .fill.under { background: var(--under); }

/* 가로 막대 */
.bars { display: flex; flex-direction: column; gap: 9px; }
.bar { display: grid; grid-template-columns: 64px 1fr 54px; align-items: center; gap: 10px; font-size: .8125rem; }
.bar .t { height: 8px; background: var(--line); border-radius: var(--r-pill); overflow: hidden; }
.bar .f { height: 100%; background: var(--accent-soft); border-radius: var(--r-pill); }
.bar .v { color: var(--dim); text-align: right; font-variant-numeric: tabular-nums; }

/* 순위 목록 */
.rank { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.rank li { display: flex; align-items: center; gap: 10px; font-size: .8125rem; color: var(--dim); font-variant-numeric: tabular-nums; }

/* 채점 배너 */
.scorecard .headline { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.025em; margin: 0 0 4px; }
.scorecard .headline.win { color: var(--win); }
.scorecard .winning { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; margin: 16px 0; }
.scorecard .winning .plus { color: var(--dim); font-size: .8125rem; }

/* 예상번호 기록 */
.hrec { border-top: 1px solid var(--line); padding: 14px 0; }
.hrec:first-child { border-top: 0; padding-top: 0; }
.hrec .h { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: .8125rem; color: var(--dim); margin-bottom: 8px; }
.hrec .h b { color: var(--fg); }
.hrec .line { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; padding: 3px 0; font-size: .75rem; color: var(--dim); }
.hrec .line .label { width: 72px; flex: none; }
.hrec .line .res { margin-left: auto; }
.hrec .line .res.win { color: var(--win); font-weight: 600; }

/* 연관성 쌍 목록 */
.pairs { display: flex; flex-direction: column; gap: 8px; }
.pairs .p { display: flex; align-items: center; gap: 7px; font-size: .75rem; color: var(--dim); font-variant-numeric: tabular-nums; }
.pairs .p .arrow { color: var(--dim); }
.pairs .p .v { margin-left: auto; }
.pairs .p .lift { color: var(--accent); font-weight: 600; }

.reroll { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-top: 18px; }
.sw { display: inline-block; width: 9px; height: 9px; border-radius: 6px; vertical-align: baseline; }
.sw.over { background: var(--over); } .sw.under { background: var(--under); }

footer { color: var(--dim); font-size: .8125rem; margin: 36px 0 72px; }
footer .src { margin-top: 8px; font-size: .75rem; }
.err { color: #b3261e; }
.empty { color: var(--dim); font-size: .875rem; }

/* ── 움직임 ────────────────────────────────────────────────────────────────
   전부 transform 과 opacity 만 건드리고, 스크롤 리스너는 쓰지 않는다.
   prefers-reduced-motion 이면 아래 블록이 통째로 적용되지 않는다. */

@keyframes rise { from { opacity: 0; transform: translateY(26px) scale(.985); } to { opacity: 1; transform: none; } }
@keyframes canvas-pan { from { transform: translate3d(0, 0, 0); } to { transform: translate3d(0, -8%, 0); } }
@keyframes drift {
  from { transform: translate3d(-4%, -2%, 0) rotate(0deg) scale(1); }
  to   { transform: translate3d(5%, 4%, 0) rotate(7deg) scale(1.12); }
}
/* 볼이 하나씩 튀어나온다. 추첨 순서를 흉내내고, '다시 뽑기'의 응답이기도 하다. */
@keyframes ball-in {
  from { opacity: 0; transform: translateY(9px) scale(.55); }
  60%  { transform: translateY(0) scale(1.08); }
  to   { opacity: 1; transform: none; }
}
@keyframes bar-grow { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@keyframes fill-grow { from { transform: scaleY(0); } to { transform: scaleY(1); } }
@keyframes item-in { from { opacity: 0; transform: translateY(9px); } to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: no-preference) {
  /* 배경: 아주 느린 블롭 이동 + 스크롤에 따른 캔버스 패럴랙스 */
  body::after { animation: drift 38s cubic-bezier(.45, 0, .55, 1) infinite alternate; }
  @supports (animation-timeline: scroll()) {
    body::before { animation: canvas-pan linear both; animation-timeline: scroll(root block); }
  }

  /* 섹션은 스크롤에 들어오면서 떠오른다 */
  @supports (animation-timeline: view()) {
    main > section, main > .row, main > nav {
      animation: rise linear both;
      animation-timeline: view();
      animation-range: entry 0% entry 56%;
    }
  }

  /* 요소 단위 등장. 순서(--i)는 app.js 의 stagger() 가 넣는다. */
  /* 행이 먼저 자리를 잡고 그 위로 볼이 떨어진다. 행 없이 볼만 비면 빈 껍데기로 보인다. */
  .sets .set {
    animation: item-in .45s cubic-bezier(.16, 1, .3, 1) backwards;
    animation-delay: calc(var(--i, 0) * 70ms);
  }
  .ball {
    animation: ball-in .5s cubic-bezier(.34, 1.56, .64, 1) backwards;
    animation-delay: calc(var(--i, 0) * 18ms);
  }
  .bar .f {
    transform-origin: left center;
    animation: bar-grow .8s cubic-bezier(.16, 1, .3, 1) backwards;
    animation-delay: calc(var(--i, 0) * 55ms + 60ms);
  }
  .cell .fill {
    transform-origin: bottom center;
    animation: fill-grow .68s cubic-bezier(.16, 1, .3, 1) backwards;
    animation-delay: calc(var(--i, 0) * 13ms);
  }
  .metric, .pairs .p, .rank li {
    animation: item-in .5s cubic-bezier(.16, 1, .3, 1) backwards;
    animation-delay: calc(var(--i, 0) * 42ms);
  }
  .scorecard .headline { animation: item-in .6s cubic-bezier(.16, 1, .3, 1) backwards; }
}

/* 좁은 화면: 세트 한 줄에 볼 6개가 들어가도록 라벨을 윗줄로 뺀다. */
@media (max-width: 560px) {
  .top { padding-top: 48px; }
  .card { padding: 20px 18px; }
  .set { padding: 12px; gap: 6px; }
  .set .label { flex-basis: 100%; width: auto; margin-bottom: 2px; }
  .set .ball { width: 32px; height: 32px; }
  .hrec .line .label { flex-basis: 100%; width: auto; }
}
