/* ========= 웹폰트 ========= */
@font-face {
  font-family: 'GangwonEduSaeeum_OTFMediumA';
  src: url('https://fastly.jsdelivr.net/gh/projectnoonnu/noonfonts_2201-2@1.0/GangwonEduSaeeum_OTFMediumA.woff') format('woff');
  font-weight: normal;
  font-style: normal;
}

/* ========= 기본 리셋 & 테마 ========= */
* { box-sizing: border-box; margin: 0; padding: 0; }
:root{
  --bg: #f7f7fb;
  --card: #fff;
  --ink: #111;
  --muted: #666;
  --line: #e9ecf2;
  --ring: #dfe4ee;
  --accent: #111;
  --accent-soft: #f0f1f6;
  --chip: #eef1f7;
  --chip-ink: #334;
  --success: #12b886;
  --down: #e03131;
  --new: #2b8a3e;
  --warn: #f08c00;
  --radius: 14px;
  --shadow: 0 10px 24px rgba(0,0,0,.08);
  --rank-row-h: 48px;  /* 한 줄 높이 */
  --rank-gap: 10px;    /* 그리드 gap */
}

html, body{
  background: white;
  color: var(--ink);
  font-family: 'GangwonEduSaeeum_OTFMediumA', Arial, sans-serif;
  display: flex; flex-direction: column; align-items: center;
  overflow-x: hidden; min-height: 100vh;
}

/* ========= 상단 내비 ========= */
nav {
  position: fixed; top: 0; left: 0; width: 100%;
  background-color: #f4f4f4;
  padding: 10px 0; z-index: 1000;
}
nav ul{ list-style: none; display: flex; justify-content: flex-end; padding: 0 20px; }
nav ul li{ display: inline; }
nav ul li a{
  color: rgb(62,62,62); text-decoration: none; padding: 8px 12px; font-size: 14px;
  font-family: 'GangwonEduSaeeum_OTFMediumA', Arial, sans-serif;
}
nav ul li a:hover{ background: #555; color: #fff; }

/* ========= 광고 ========= */
.ad-container, .footer-ad-container{
  width: 100%; min-height: 90px; display: flex; justify-content: center; align-items: center;
}
.ad-container{ margin-top: 60px; margin-bottom: 20px; }
.footer-ad-container{ margin-top: 30px; }

/* 광고 컨테이너가 flex 교차축(center) 영향 안 받도록 폭 강제 */
.ad-container,
.footer-ad-container{
  align-self: stretch;   /* 부모 align-items:center 무시하고 가로 꽉 */
  width: 100vw;          /* 뷰포트 기준 가로 전체 */
  max-width: 100%;       /* 스크롤 튀는 것 방지 */
  min-width: 320px;      /* 모바일에서 0 또는 너무 작은 폭 방지 */
}

/* ========= 앱 ========= */
#app{
  width: 360px; height: 550px; position: relative;
  background: var(--card); border-radius: 12px; box-shadow: var(--shadow); overflow: hidden;
}

/* ========= 스크린 ========= */
.screen{ width: 100%; height: 100%; position: absolute; inset: 0; display: none; }
.screen.active{
  display: flex !important; flex-direction: column; justify-content: center; align-items: center;
}
#select-screen.screen.active,
#result-screen.screen.active{ justify-content: flex-start; align-items: stretch; }
.container{ width: 100%; height: 100%; padding: 16px; }

/* ========= 접근성 ========= */
.sr-only{
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* 스텝퍼: 기본은 숨김, 2~4단계에서만 표시 */
.stepper{
  display: none;
  list-style: none;
  position: absolute; left: 0; right: 0; bottom: 8px;
  justify-content: center; gap: 8px; padding: 0 12px; z-index: 5;
}
#app.show-stepper .stepper{
  display: flex;
}
.stepper li{
  font-size: 12px; color: var(--muted);
  background: var(--accent-soft); border: 1px solid var(--line);
  padding: 6px 10px; border-radius: 999px;
}
.stepper li.active{ color: #fff; background: var(--ink); border-color: var(--ink); }

/* ========= 버튼 ========= */
.btn{ border: 0; cursor: pointer; user-select: none; border-radius: 12px; padding: 12px 16px; font-size: 16px; }
.btn.primary{
  background: linear-gradient(135deg, #ff5fa0 0%, #ff86b8 45%, #ffd1e1 100%);
  color: #fff; font-weight: 700; box-shadow: 0 10px 24px rgba(255,95,160,.35), inset 0 -2px 0 rgba(0,0,0,.08);
}
.btn.tiny{ padding: 8px 10px; font-size: 12px; border-radius: 10px; }
.btn.kakao{
  color: #3c1e1e; font-weight: 800;
  background: linear-gradient(135deg,#F7E600 0%, #ffe66a 100%); box-shadow: 0 6px 14px rgba(247,230,0,.35);
}
.btn.link{
  background: #fff; border: 1px solid var(--line); color: var(--ink); font-weight: 700;
}
.btn.restart{
  color: #fff; font-weight: 800;
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 45%, #a78bfa 100%);
  box-shadow: 0 8px 18px rgba(99,102,241,.35);
}

/* ========= 시작 화면 ========= */
#start-screen{ position: relative; }
.background-img{ position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; z-index: 0; }
#start-screen::after{ content:""; position:absolute; inset:0; background: linear-gradient(to top, rgba(0,0,0,.35), rgba(0,0,0,0) 45%); z-index: 1; }
.start-cta{
  position: absolute; left: 50%; bottom: 48px; transform: translateX(-50%);
  z-index: 2; width: 88%; display: flex; flex-direction: column; gap: 10px; align-items: center; justify-content: center;
}
.help-text{ color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.35); font-size: 13px; }

/* ========= 선택 화면 ========= */
#select-screen .container{ display: flex; flex-direction: column; gap: 12px; padding-bottom: 56px; } /* ⬅ 스텝퍼 공간 */
.container.narrow{ padding: 20px; }
#select-title{ font-size: 20px; margin-bottom: 8px; }
.field-row{ display: flex; flex-direction: column; gap: 6px; margin: 10px 0; }
label{ font-size: 14px; color: var(--muted); }
select{
  width: 100%; height: 46px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px;
  background: #fff; color: var(--ink); font-size: 16px; outline: none; transition: box-shadow .15s ease, border-color .15s ease;
}
select:focus{ border-color: var(--ink); box-shadow: 0 0 0 3px var(--ring); }
.actions{ display: flex; gap: 8px; margin-top: 6px; }

/* ========= 카드/그리드 ========= */
.card{
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 12px;
}
.card + .card{ margin-top: 12px; }
.card-header{ display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.card-header h3{ font-size: 16px; }
.card-actions{ display: flex; gap: 6px; }

.rank-grid{
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--rank-gap);

  /* ⬇️ Top10(=5행)까지만 보이도록 높이 제한 + 스크롤 */
  grid-auto-rows: var(--rank-row-h);
  max-height: calc(5 * var(--rank-row-h) + 4 * var(--rank-gap));
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.rank-item{
  display: flex; align-items: center; gap: 8px;
  background: var(--chip); color: var(--chip-ink);
  border-radius: 12px; padding: 8px 10px; border: 1px solid var(--line);
  min-height: var(--rank-row-h);   /* 행 높이 보장 */
  align-items: center;              /* 세로 중앙 정렬 보장 */
}
.rank-item.top5{
  background: linear-gradient(135deg, #fff 0%, #fff 50%, #fff 70%), radial-gradient(120px 80px at 0% 0%, #ffe6f3 0%, rgba(255,255,255,0) 70%);
  border-color: #f7cbe4;
}
.rank-num{
  min-width: 28px; height: 28px; line-height: 28px;
  display: inline-flex; align-items: center; justify-content: center;
  background: #fff; border: 1px solid var(--line);
  border-radius: 999px; font-weight: 700; font-size: 13px;
}
.rank-name{ font-size: 15px; }

/* 변화(리치 요소) */
.rank-delta{
  margin-left: auto; font-size: 12px; padding: 2px 6px; border-radius: 999px; border: 1px solid var(--line);
  background: #fff;
}
.rank-delta.up{ color: var(--success); border-color: #c9f3e6; background: #eafaf4; }
.rank-delta.down{ color: var(--down); border-color: #ffd6db; background: #fff1f3; }
.rank-delta.same{ color: var(--muted); background: #f5f6f8; }
.rank-delta.new{ color: var(--new); border-color: #d6f2dc; background: #eefaf0; font-weight: 800; }

/* ========= 로딩 ========= */
.loading-wrap{ display: flex; flex-direction: column; align-items: center; gap: 10px; }
.spinner{ width: 36px; height: 36px; border-radius: 999px; border: 3px solid var(--line); border-top-color: var(--ink); animation: spin 1s linear infinite; }
@keyframes spin{ to { transform: rotate(360deg); } }
.loading-text{ font-size: 16px; }
.loading-sub{ font-size: 13px; color: var(--muted); }

/* ========= 결과 ========= */
#result-screen .container.result{
  display: flex; flex-direction: column; gap: 10px;
  height: 100%; min-height: 0; padding: 12px 12px 64px; /* ⬅ 하단 여유(스텝퍼/액션) */
  overflow-y: auto; -webkit-overflow-scrolling: touch;
}
.result-header h2{ font-size: 20px; }
.result-header .subtitle{ color: var(--muted); margin-top: 4px; }

.actions-row{
  display: none; gap: 8px; justify-content: space-between; margin-top: 8px;
  position: sticky; bottom: 0; padding-top: 8px;
  background: linear-gradient(to top, #fff 70%, rgba(255,255,255,0.9) 100%, transparent);
}
.actions-row .btn{ flex: 1; }

/* ▼ 하단 액션 버튼 사이즈만 축소 */
.actions-row .btn {
  font-size: 14px;      /* 기존 16px → 14px */
  padding: 10px 12px;   /* 살짝 줄인 여백 */
  min-height: 44px;     /* 터치 접근성은 유지 */
  border-radius: 10px;
}

/* 옵션: 화면이 아주 작을 때 더 작게 */
@media (max-width: 380px) {
  .actions-row .btn {
    font-size: 13px;
    padding: 9px 10px;
  }
}

/* 이모지+텍스트 정렬 더 깔끔하게 하고 싶다면 */
.actions-row .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px; /* 이모지와 텍스트 사이 여백 */
}

/* 스크롤바(웹킷) */
#result-screen .container.result::-webkit-scrollbar{ width: 8px; height: 8px; }
#result-screen .container.result::-webkit-scrollbar-thumb{ background: #d6dbe6; border-radius: 999px; }
#result-screen .container.result::-webkit-scrollbar-track{ background: #f3f5f9; border-radius: 999px; }
