/* ═════════ 디자인 토큰 ═════════
   색: 중립 회색 단계(배경 → 면 → 안쪽 면 → 선) + 포인트 색 하나(파랑). 그 외 색은 오류(빨강)만 씁니다.
   모서리: 작은 요소 8 / 버튼·입력·안쪽 카드 12 / 카드·패널·차트 16 (원형은 50%)
   그라데이션·그림자는 쓰지 않고, 시트(모바일 상세)만 그림자를 씁니다. */
:root {
  --bg: #0d1016;
  --surface: #151a23;
  --surface-2: #1b212c;
  --canvas: #0a0d12;
  --line: #262d3a;
  --line-strong: #353e4f;

  --text: #e9edf5;
  --text-2: #aab3c5;
  --muted: #7f899c;

  --accent: #3b82f6;
  --accent-hover: #5b9bff;
  --accent-text: #8ab8ff;
  --on-accent: #fff;
  --danger: #ff7a7a;
  --warn: #f2c14e;      /* 노란색 강조: 이미지 제보 버튼 */
  --gold: #f2c14e;      /* 순위 메달색: 상세 정보의 1·2·3위 숫자에만 사용 */
  --silver: #c9d0dd;
  --bronze: #d28b5a;

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
}
* { box-sizing: border-box; }
html { color-scheme: dark; }
body {
  margin: 0;
  background: radial-gradient(1100px 520px at 50% -240px, rgb(59 130 246 / 0.12), transparent 70%) no-repeat, var(--bg);
  color: var(--text);
  font-family: 'Pretendard Variable', Pretendard, -apple-system, 'Segoe UI', 'Malgun Gothic', sans-serif;
  line-height: 1.6;
  min-height: 100vh;
  word-break: keep-all;          /* 한국어는 글자 중간이 아니라 단어 단위로 줄바꿈 */
  overflow-wrap: break-word;
}
h1, h2, h3, .hint, .note-top { text-wrap: balance; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 20px; }

/* ───── 헤더 ───── */
header.top { display: flex; align-items: center; justify-content: space-between; padding: 18px 0; }
.brand { font-weight: 800; font-size: 20px; letter-spacing: -0.02em; color: var(--text); text-decoration: none; display: flex; align-items: center; gap: 8px; }
.brand .dot { width: 28px; height: 28px; border-radius: var(--r-sm); background: url(/apple-icon-180x180.png) center / cover; flex: none; }
.lang { display: flex; gap: 6px; align-items: center; }
.lang button { background: transparent; border: 1px solid var(--line); color: var(--muted); border-radius: var(--r-sm); padding: 4px 10px; font: inherit; font-size: 13px; cursor: pointer; }
.lang button:hover { color: var(--text); }
.lang button[aria-pressed='true'] { color: var(--text); border-color: var(--accent); }
.lang #logout[hidden] { display: none; }

/* ───── 버튼 ───── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 10px; padding: 12px 20px; font: inherit; font-weight: 700; font-size: 15px; color: var(--on-accent); background: var(--accent); border: 1px solid var(--accent); border-radius: var(--r-md); cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn:disabled { background: var(--surface-2); border-color: var(--line); color: var(--muted); cursor: not-allowed; }
.btn.ghost { background: var(--surface-2); border-color: var(--line); color: var(--text); font-weight: 600; }
.btn.ghost:hover { border-color: var(--line-strong); background: var(--surface-2); }
.btn.big { padding: 20px 28px; font-size: 22px; font-weight: 800; letter-spacing: -0.01em; width: 100%; }
.linkbtn { background: none; border: 0; padding: 0; font: inherit; color: var(--accent-text); text-decoration: none; cursor: pointer; }
#report { color: var(--warn); }
.linkbtn:disabled, #report:disabled { color: var(--muted); cursor: default; }
.linkbtn[hidden] { display: none; }

/* ───── 로그인 전: 히어로 ───── */
.landing-hero { display: grid; grid-template-columns: minmax(0, 6fr) minmax(0, 5fr); gap: 40px; align-items: center; padding: 16px 0 8px; }
/* 데스크톱: 왼쪽에 버블, 오른쪽에 로그인 (읽는 방향). 모바일에서는 아래 미디어쿼리로 로그인이 먼저 */
.landing-hero .hero-chart { order: 1; }
.landing-hero .hero-copy { order: 2; }
.hero-copy h1 { font-size: clamp(30px, 4vw, 46px); line-height: 1.2; margin: 0 0 28px; letter-spacing: -0.03em; }
.cta { max-width: 460px; }
.or { display: flex; align-items: center; gap: 12px; margin: 16px 0 12px; color: var(--muted); font-size: 13px; }
.or::before, .or::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.searchbar { display: flex; }
.searchbar input { flex: 1; min-width: 0; padding: 14px 16px; font: inherit; font-size: 16px; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-right: 0; border-radius: var(--r-md) 0 0 var(--r-md); outline: none; }
.searchbar input::placeholder { color: var(--muted); }
.searchbar input:focus { border-color: var(--accent); }
.searchbar .btn { border-radius: 0 var(--r-md) var(--r-md) 0; padding: 0 22px; }
.hint { color: var(--muted); font-size: 13px; margin: 12px 0 0; }
#msg { min-height: 24px; color: var(--danger); font-size: 14px; margin: 10px 0 0; }
#msg.info { color: var(--muted); }
#msg.ok { color: var(--accent-text); }
.hero-chart { min-width: 0; }

/* ───── 결과 영역 (공통) ───── */
#result { display: none; }
.layout { display: block; }
#stage { position: relative; width: 100%; background: var(--canvas); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; touch-action: pan-y; }
/* 캔버스는 레이아웃 폭에 관여하지 않게 띄워 둡니다. (아이폰 사파리는 고해상도 캔버스의 픽셀 폭만큼 페이지를 넓혀서 오른쪽이 잘렸어요) 높이는 app.js 가 #stage 에 직접 줍니다. */
#stage canvas { position: absolute; left: 0; top: 0; display: block; width: 100%; }
/* 차트 영역(#result)은 스크립트가 켜기 전까지 숨겨져 있어서, 그동안 아래 내용(FAQ)이 위로 붙어 있다가 한꺼번에 밀려 내려갔어요(레이아웃 흔들림).
   그래서 바깥 칸(.hero-chart)에 같은 크기의 자리를 미리 잡아 둡니다. app.js 의 fit() 계산과 같은 값이에요. */
body[data-page='landing'] .hero-chart { min-height: 462px; }
@media (max-width: 699px) { body[data-page='landing'] .hero-chart { min-height: calc((100vw - 34px) * 1.15 + 82px); } }
#tip { position: absolute; pointer-events: none; display: none; background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--r-sm); padding: 8px 12px; font-size: 13px; line-height: 1.45; max-width: 240px; z-index: 2; }
#tip b { display: block; font-size: 14px; }
#tip span { color: var(--muted); }
.note-top { text-align: center; color: var(--muted); font-size: 13px; margin: 0 0 8px; }
.note-top[hidden] { display: none; }
#spread-note { margin: 10px 0 0; } /* 차트 아래에 붙는 안내문은 위쪽 간격을 둡니다 */
.note { color: var(--muted); font-size: 13px; margin: 0; }

/* 로그인 전에는 차트만 보여줍니다 */
body[data-page='landing'] .side { display: none; }
body[data-page='landing'] .note-top { margin-top: 0; }

/* ───── 로그인 후: 차트 + 사이드 패널 ───── */
body[data-page='bubble'] main { padding-top: 4px; }
body[data-page='bubble'] .layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
.side { display: flex; flex-direction: column; gap: 12px; position: sticky; top: 16px; max-height: calc(100vh - 32px); overflow-y: auto; scrollbar-width: thin; }
.who { display: flex; align-items: center; gap: 12px; min-width: 0; }
.who img { width: 48px; height: 48px; border-radius: 50%; flex: none; }
.who h2 { margin: 0; font-size: 18px; line-height: 1.3; overflow-wrap: anywhere; }
.who small { color: var(--muted); font-size: 13px; line-height: 1.4; display: block; }
.side-actions { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.side-actions .btn { padding: 12px 18px; }
.side-actions [hidden] { display: none; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 6px 14px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; min-height: 44px; }
.row + .row { border-top: 1px solid var(--line); }
.lbl { font-size: 14px; color: var(--text-2); }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-md); padding: 3px; gap: 2px; }
.seg button { background: transparent; border: 0; color: var(--muted); font: inherit; font-size: 13px; font-weight: 600; padding: 5px 11px; border-radius: var(--r-sm); cursor: pointer; }
.seg button:hover { color: var(--text); }
.seg button[aria-pressed='true'] { background: var(--accent); color: var(--on-accent); }
.range { display: flex; align-items: center; gap: 8px; }
.range input { width: 150px; accent-color: var(--accent); cursor: pointer; }
.switch { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--text-2); cursor: pointer; user-select: none; position: relative; width: 100%; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track { order: 2; margin-left: auto; width: 36px; height: 21px; border-radius: 11px; background: var(--line-strong); position: relative; transition: background .15s; flex: none; }
.switch .track::after { content: ''; position: absolute; top: 3px; left: 3px; width: 15px; height: 15px; border-radius: 50%; background: var(--on-accent); transition: transform .15s; }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(15px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent-text); outline-offset: 2px; }

/* ───── 게임 상세 ───── */
#detail { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 16px; }
#detail[hidden] { display: none; }
.d-head { display: flex; gap: 12px; align-items: center; }
#d-thumb { width: 56px; height: 56px; border-radius: 50%; flex: none; background: var(--canvas); border: 1px solid var(--line); }
#d-name { margin: 0; flex: 1; min-width: 0; font-size: 17px; line-height: 1.35; text-wrap: balance; overflow-wrap: break-word; }
.d-rank { display: flex; align-items: baseline; gap: 12px; margin-top: 14px; padding: 12px 14px; background: var(--surface-2); border-radius: var(--r-md); }
.d-rank b { font-size: 34px; font-weight: 800; letter-spacing: -0.03em; line-height: 1; color: var(--accent-text); }
.d-rank span { font-size: 13px; color: var(--muted); }
.d-rank[data-tier='1'] b { color: var(--gold); }
.d-rank[data-tier='2'] b { color: var(--silver); }
.d-rank[data-tier='3'] b { color: var(--bronze); }
.d-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.d-stat { background: var(--surface-2); border-radius: var(--r-md); padding: 9px 11px; }
.d-stat b { display: block; font-size: 16px; }
.d-stat span { color: var(--muted); font-size: 12px; }
.d-foot { display: flex; justify-content: space-between; gap: 16px; margin-top: 12px; font-size: 13px; }

/* ───── FAQ / 광고 / 푸터 ───── */
.ad-slot { margin: 18px auto; text-align: center; }
.ad-slot[hidden] { display: none; }
/* 좌우 세로 광고(160×600): 가운데 콘텐츠(최대 1180px) 양옆 빈 공간에 띄웁니다. 화면이 충분히 넓을 때(1540px 이상)만 보입니다. */
.ad-rail { display: none; }
@media (min-width: 1540px) {
  .ad-rail { display: block; position: fixed; top: 96px; width: 160px; z-index: 1; }
  .ad-rail-left { right: calc(50% + 590px + 14px); }
  .ad-rail-right { left: calc(50% + 590px + 14px); }
  .ad-rail .ad-slot { margin: 0; }
}
section.info { margin: 48px 0 0; }
section.info h2 { font-size: 20px; margin: 0 0 12px; }
.faq .faq-list { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: start; }
.faq-item { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: 14px 16px; }
.faq-item h3 { margin: 0; font-size: 15px; font-weight: 600; }
.faq-item p { color: var(--text-2); margin: 6px 0 0; font-size: 14px; }
footer { margin: 56px 0 32px; padding-top: 20px; border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; display: flex; gap: 16px; flex-wrap: wrap; justify-content: space-between; }
footer a { color: var(--muted); }
footer a:hover { color: var(--text); }

/* 소개·개인정보 페이지 */
.page { max-width: 760px; margin: 0 auto; padding: 8px 20px 0; }
.page h1 { font-size: 28px; }
.page h2 { font-size: 18px; margin-top: 28px; }
.page p, .page li { color: var(--text-2); }
.page a { color: var(--accent-text); }

/* ───── 태블릿·모바일 ───── */
@media (max-width: 959px) {
  .faq .faq-list { grid-template-columns: 1fr; }
  .landing-hero { grid-template-columns: minmax(0, 1fr); gap: 24px; }
  .landing-hero .hero-copy { order: 1; }
  .landing-hero .hero-chart { order: 2; }
  .cta { max-width: none; }
  body[data-page='bubble'] .layout { grid-template-columns: minmax(0, 1fr); }
  .side { position: static; max-height: none; overflow: visible; }
  /* 상세 정보는 화면 아래 시트로 띄워 스크롤 없이 바로 보이게 */
  #detail { position: fixed; left: 10px; right: 10px; bottom: 10px; z-index: 30; max-height: 62vh; overflow-y: auto; border-color: var(--line-strong); box-shadow: 0 12px 40px rgb(0 0 0 / 0.6); }
}
@media (max-width: 700px) {
  .wrap { padding: 0 16px; }
  /* 손가락으로 누르기 편하도록 작은 버튼·링크의 높이를 키웁니다 (최소 36px) */
  .lang button { padding: 9px 13px; }
  .seg button { padding: 9px 13px; }
  .linkbtn { padding: 9px 0; }
  footer a { display: inline-block; padding: 10px 2px; }
  footer { gap: 4px 16px; }
}
