/* 국기 다운로드 도구 전용 스타일
   테마: 시원한 블루 계열 — "세계/지도"를 연상시키는 톤으로 다른 도구들과 구분 */

:root {
  --flag-primary: #2563eb;
  --flag-primary-dark: #1d4ed8;
  --flag-bg: #f7f7f7;
  --flag-card-bg: #ffffff;
  --flag-border: #e2e8f5;
  --flag-text: #1e293b;
  --flag-text-muted: #53575e;
  --flag-radius: 12px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  background: var(--flag-bg);
  color: var(--flag-text);
  line-height: 1.6;
}

/* back-link을 position:fixed로 화면에 띄우면, 스크롤 중인 본문 텍스트가 그 아래를
   지나가는 순간마다 겹쳐 보이는 문제가 있었습니다(실사용 스크린샷으로 발견). 그래서
   버튼만 따로 띄우는 대신, 폭 전체를 덮는 불투명한 배경의 sticky 바(.top-bar) 안에
   버튼을 넣는 방식으로 바꿨습니다 — 그 바 아래로 지나가는 내용은 불투명 배경에
   완전히 가려지므로 어떤 화면 크기에서도 겹쳐 보이지 않습니다. */
.top-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  height: 56px;
  padding: 0 16px;
  background: var(--flag-bg);
}

/* PC처럼 넓은 화면에서는 스크롤을 올렸을 때 상단바 전체가 화면을 가리지 않도록,
   막대(.top-bar) 자체를 폭 전체가 아니라 버튼 크기만큼만 남기고 배경도 지웁니다.
   .back-link 자체가 이미 불투명한 배경(pill 버튼)을 갖고 있어서 겹침 문제 없이
   버튼만 떠 있는 것처럼 보입니다. */
@media (min-width: 768px) {
  .top-bar {
    width: fit-content;
    height: auto;
    padding: 12px 16px 0;
    background: transparent;
  }
}

.back-link {
  display: inline-block;
  padding: 6px 14px;
  background: var(--flag-card-bg);
  border: 1px solid var(--flag-border);
  border-radius: 999px;
  color: var(--flag-text-muted);
  text-decoration: none;
  font-size: 0.9rem;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.08);
}

.back-link:hover {
  color: var(--flag-primary);
}

.page-header {
  text-align: center;
  padding: 10px 16px 16px;
}

.page-header h1 {
  margin: 0 0 8px;
  font-family: "Encode Sans Expanded", -apple-system, BlinkMacSystemFont, sans-serif;
  font-weight: 800;
  font-size: 2.2rem;
  letter-spacing: -0.01em;
  color: var(--flag-primary-dark);
}

.subtitle {
  margin: 0;
  color: var(--flag-text-muted);
  font-size: 1.1rem;
}

.tagline-extra {
  margin: 6px 0 0;
  color: var(--flag-text-muted);
  font-size: 0.9rem;
}

main {
  max-width: 1000px;
  margin: 0 auto;
  padding: 0 16px 48px;
}

.search-section {
  position: sticky;
  top: 56px;
  background: var(--flag-bg);
  padding: 16px 0;
  z-index: 10;
}

.search-input-wrap {
  position: relative;
}

.search-icon {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--flag-text-muted);
  pointer-events: none;
}

#search-input {
  width: 100%;
  padding: 14px 18px 14px 44px;
  font-size: 1.2rem;
  border: 2px solid var(--flag-border);
  border-radius: var(--flag-radius);
  outline: none;
  transition: border-color 0.15s ease;
}

#search-input:focus {
  border-color: var(--flag-primary);
}

.continent-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.continent-tab {
  flex: 0 0 auto;
  padding: 7px 14px;
  font-size: 0.9rem;
  font-weight: 600;
  border: 1px solid var(--flag-border);
  border-radius: 999px;
  background: var(--flag-card-bg);
  color: var(--flag-text-muted);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}

.continent-tab:hover {
  border-color: var(--flag-primary);
  color: var(--flag-primary-dark);
}

.continent-tab.is-active {
  background: var(--flag-primary);
  border-color: var(--flag-primary);
  color: #fff;
}

.result-count {
  margin: 8px 2px 0;
  font-size: 0.9rem;
  color: var(--flag-text-muted);
}

.flag-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  column-gap: 14px;
  row-gap: 22px;
  margin-top: 8px;
}

.recent-section {
  margin-top: 32px;
}

.recent-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.recent-header h2 {
  margin: 0;
  font-size: 1.2rem;
  color: var(--flag-primary-dark);
}

.recent-clear {
  border: none;
  background: none;
  color: var(--flag-text-muted);
  font-size: 0.83rem;
  cursor: pointer;
  text-decoration: underline;
  padding: 0;
}

.recent-clear:hover {
  color: var(--flag-primary-dark);
}

.recent-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

.recent-card {
  flex: 0 0 auto;
  width: 92px;
  background: var(--flag-card-bg);
  border: 1px solid var(--flag-border);
  border-radius: 10px;
  padding: 8px;
  text-align: center;
  cursor: pointer;
}

.recent-card:hover {
  border-color: var(--flag-primary);
}

.recent-card img {
  width: 100%;
  height: 44px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid var(--flag-border);
  display: block;
  margin-bottom: 4px;
}

.recent-card .recent-card-name {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--flag-text);
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.flag-card {
  background: var(--flag-card-bg);
  border: 1px solid var(--flag-border);
  border-radius: var(--flag-radius);
  padding: 12px;
  text-align: center;
  transition: box-shadow 0.12s ease;
}

/* "내가 찾아본 국가"에서 카드를 클릭했을 때, 전체 목록에서 해당 국기 위치로
   스크롤된 뒤 "여기예요!"라는 느낌으로 테두리가 몇 번 깜빡이는 효과입니다. */
@keyframes flag-card-flash {
  0%,
  100% {
    border-color: var(--flag-border);
    box-shadow: none;
  }
  25%,
  75% {
    border-color: var(--flag-primary);
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.35);
  }
  50% {
    border-color: var(--flag-primary);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
  }
}

.flag-card.is-flashing {
  animation: flag-card-flash 0.75s ease-in-out 3;
}

.flag-card img {
  width: 100%;
  height: 80px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--flag-border);
  display: block;
  margin-bottom: 8px;
  background: #f0f0f0;
}

.flag-card .flag-name {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--flag-text);
  display: block;
}

.flag-card .flag-name-en {
  font-size: 0.77rem;
  color: var(--flag-text-muted);
  display: block;
}

.download-btn-row {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.png-size {
  display: block;
  margin-top: 4px;
  font-size: 0.73rem;
  color: var(--flag-text-muted);
}

.flag-card .download-btn {
  flex: 1;
  padding: 6px 0;
  font-size: 0.8rem;
  font-weight: 600;
  border: none;
  border-radius: 6px;
  background: var(--flag-primary);
  color: #fff;
  cursor: pointer;
}

.flag-card .download-btn:hover {
  background: var(--flag-primary-dark);
}

.flag-card .download-btn-svg {
  background: #64748b;
}

.flag-card .download-btn-svg:hover {
  background: #475569;
}

.no-results {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--flag-text-muted);
  padding: 40px 0;
}

.ads-container {
  margin: 40px 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--flag-card-bg);
  border: 1px solid var(--flag-border);
  border-radius: var(--flag-radius);
  color: var(--flag-text-muted);
  font-size: 0.9rem;
}

/* 좌우 여백에 붙어 스크롤을 따라다니는 세로형(스카이스크래퍼) 광고.
   본문(max-width: 1000px)과 겹치지 않을 만큼 화면이 넓을 때만 노출합니다. */
.ads-rail {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  width: 160px;
  margin: 0;
  display: none;
  z-index: 5;
}

.ads-rail-left {
  left: 16px;
}

.ads-rail-right {
  right: 16px;
}

/* 본문(max-width: 1000px) 기준 완전히 안 겹치는 지점은 1352px이지만,
   요청에 따라 중앙 컨텐츠와 최대 10px까지는 겹쳐도 노출되도록 임계값을 낮췄습니다. */
@media (min-width: 1332px) {
  .ads-rail {
    display: flex;
  }
}

.info-section {
  margin-top: 24px;
}

.info-section h2 {
  color: var(--flag-primary-dark);
  font-size: 1.35rem;
  margin-top: 32px;
}

.faq-list .faq-item {
  margin-bottom: 16px;
}

.faq-list dt {
  font-weight: 600;
  margin-bottom: 4px;
}

.faq-list dd {
  margin: 0;
  color: var(--flag-text-muted);
}

.page-footer {
  text-align: center;
  padding: 24px 16px 40px;
  color: var(--flag-text-muted);
  font-size: 0.85rem;
}

.footer-links {
  margin: 8px 0 0;
}

.footer-links a {
  color: var(--flag-text-muted);
  text-decoration: underline;
}

.footer-links a:hover {
  color: var(--flag-primary);
}

@media (max-width: 480px) {
  .flag-grid {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 10px;
  }

  .page-header h1 {
    font-size: 1.7rem;
  }
}

.scroll-top-btn {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 20;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--flag-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(37, 99, 235, 0.3);
  transition: background 0.12s ease, transform 0.12s ease;
}

.scroll-top-btn:hover {
  background: var(--flag-primary-dark);
  transform: translateY(-2px);
}

/* [hidden] 속성과 .scroll-top-btn { display:flex }는 상세도(specificity)가 같아서
   나중에 선언된 쪽이 이겨 hidden이 무시되는 문제가 있었습니다(카테고리 폼에서 이미
   겪은 버그와 동일한 원인). 그래서 [hidden]을 명시적으로 다시 덮어씁니다. */
.scroll-top-btn[hidden] {
  display: none;
}
