/* ── 기본 ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --navy:     #1a3a5c;
  --blue:     #2980b9;
  --blue-l:   #3498db;
  --gold:     #f39c12;
  --bg:       #f5f6fa;
  --card:     #ffffff;
  --text:     #333;
  --sub:      #999;
  --border:   #ddd;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  font-family: 'Noto Sans KR', 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  padding-bottom: calc(24px + var(--safe-bot));
}

/* ══════════════════════════════════════════════════════
   스크롤 고정 영역 (헤더 + 검색 + 필터 전체 묶음)
══════════════════════════════════════════════════════ */
.sticky-controls {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg);
  box-shadow: 0 2px 10px rgba(0,0,0,0.08);
}

/* ── 헤더 ──────────────────────────────────────────────── */
header {
  background: var(--card);
  padding: calc(10px + var(--safe-top)) 16px 10px;
  border-bottom: 1px solid #eef0f4;
}
.header-content {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 700px;
  margin: 0 auto;
}
.header-icon {
  width: 30px; height: 30px;
  border-radius: 6px;
  object-fit: contain;
  flex-shrink: 0;
}
.header-title {
  font-family: 'Playfair Display', 'Georgia', serif;
  font-size: 1.05em;
  font-weight: 700;
  background: linear-gradient(135deg, #1a3a5c 0%, #2980b9 60%, #1a3a5c 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.install-btn {
  flex-shrink: 0;
  background: var(--navy);
  color: #fff;
  border: none;
  border-radius: 14px;
  padding: 4px 10px;
  font-size: 0.72em;
  font-family: inherit;
  cursor: pointer;
}

/* ── 검색 + 필터 래퍼 ────────────────────────────────── */
.control-wrap {
  background: var(--card);
  padding: 10px 16px;
  max-width: 100%;
}

/* ── 검색 폼 ────────────────────────────────────────────── */
.search-form {
  display: flex;
  gap: 8px;
  max-width: 700px;
  margin: 0 auto 8px;
}
.search-form input {
  flex: 1;
  height: 40px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  font-size: 0.88em;
  font-family: inherit;
  background: var(--bg);
  transition: border-color 0.2s;
  min-width: 0;
}
.search-form input:focus {
  outline: none;
  border-color: var(--blue-l);
  background: #fff;
}
.search-form button {
  flex-shrink: 0;
  height: 40px;
  background: var(--blue-l);
  color: #fff;
  border: none;
  padding: 0 14px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 0.84em;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s;
}
.search-form button:active { background: var(--blue); }
.search-form button:disabled { background: #a0c4e0; cursor: not-allowed; }

/* ── 필터 바 ─────────────────────────────────────────────
   JS 가 inline style="display:none / display:flex" 를 주입하므로
   내부 레이아웃은 .filter-row 에서 처리
─────────────────────────────────────────────────────── */
.filter-bar {
  max-width: 700px;
  margin: 0 auto;
  /* JS 가 flex 주입해도 내부는 .filter-row 가 담당 */
  align-items: stretch;
}

/* 한 줄: [중요도 라벨] [버튼들 스크롤] [N건] */
.filter-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.filter-label {
  flex-shrink: 0;
  font-size: 0.75em;
  font-weight: 700;
  color: #888;
  white-space: nowrap;       /* ★ 줄바꿈 금지 → 세로 깨짐 방지 */
  line-height: 1;
}

/* 별점 버튼 가로 스크롤 영역 */
.filter-scroll {
  flex: 1;
  display: flex;
  gap: 5px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  /* 양쪽 페이드 효과로 스크롤 암시 */
  -webkit-mask-image: linear-gradient(to right, transparent 0, #000 8px, #000 calc(100% - 8px), transparent 100%);
  mask-image: linear-gradient(to right, transparent 0, #000 8px, #000 calc(100% - 8px), transparent 100%);
}
.filter-scroll::-webkit-scrollbar { display: none; }

/* 필터 버튼 — 시각적으로 작게, 터치는 여유있게 */
.filter-btn {
  flex-shrink: 0;
  height: 30px;
  padding: 0 10px;
  border: 1.5px solid var(--border);
  border-radius: 15px;
  background: var(--card);
  color: #555;
  font-size: 0.78em;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  /* 터치 즉시 반응 (300ms 지연 제거) */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.1s;
}
.filter-btn.active {
  background: var(--gold);
  border-color: var(--gold);
  color: #fff;
  font-weight: 700;
}
.filter-btn:active {
  transform: scale(0.93);
  opacity: 0.8;
}

/* 건수 */
.filter-count {
  flex-shrink: 0;
  font-size: 0.75em;
  color: var(--blue);
  font-weight: 700;
  white-space: nowrap;
}

/* ── 진행 바 ─────────────────────────────────────────────── */
.progress-wrap {
  max-width: 700px;
  margin: 12px auto 0;
  padding: 0 16px;
}
.progress-inner {
  display: flex;
  align-items: center;
  gap: 10px;
}
#progress-container {
  flex: 1;
  background: #e8ecf0;
  height: 8px;
  border-radius: 12px;
  overflow: hidden;
}
#progress-bar {
  height: 100%;
  width: 0%;
  border-radius: 12px;
  background: linear-gradient(90deg,
    #e74c3c, #e67e22, #f1c40f, #2ecc71, #3498db, #9b59b6, #e74c3c);
  background-size: 400% 100%;
  animation: rainbowFlow 4s linear infinite;
  transition: width 0.8s cubic-bezier(0.25, 0.8, 0.25, 1);
}
@keyframes rainbowFlow {
  0%   { background-position: 0% 0; }
  100% { background-position: 400% 0; }
}
#progress-pct {
  font-size: 0.75em;
  font-weight: 700;
  white-space: nowrap;
  min-width: 30px;
  background: linear-gradient(90deg,#e74c3c,#e67e22,#f1c40f,#2ecc71,#3498db,#9b59b6,#e74c3c);
  background-size: 400% 100%;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: rainbowFlow 4s linear infinite;
}

/* ── 뉴스 목록 ───────────────────────────────────────────── */
#news-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  max-width: 700px;
  margin: 14px auto 0;
  padding: 0 16px;
}
.news-item {
  background: var(--card);
  padding: 14px;
  border-radius: 10px;
  box-shadow: 0 1px 6px rgba(0,0,0,0.07);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.35s ease, transform 0.35s ease;
  -webkit-tap-highlight-color: transparent;
}
.news-item.show  { opacity: 1; transform: translateY(0); }
.news-item:active { background: #f8fafc; }
.news-item a {
  text-decoration: none;
  color: #1a0dab;
  font-size: 0.92em;
  display: block;
  margin-bottom: 6px;
  line-height: 1.5;
}
.news-score {
  font-size: 0.88em;
  margin-bottom: 4px;
  letter-spacing: 1px;
  color: var(--gold);
}
.news-meta  { font-size: 0.75em; color: var(--sub); margin-top: 2px; }
.no-result  { text-align: center; color: #aaa; margin-top: 60px; font-size: 0.95em; }

/* ── 페이지네이션 ─────────────────────────────────────────
   5열 grid: [맨앞] [이전] [1/N] [다음] [맨뒤]
   모바일 터치 최적화
─────────────────────────────────────────────────────── */
#pagination {
  max-width: 700px;
  margin: 20px auto 48px;
  padding: 0 16px;
  display: grid;
  grid-template-columns: 1fr 1fr auto 1fr 1fr;
  align-items: center;
  gap: 6px;
}
#pagination button {
  width: 100%;
  min-height: 44px;
  padding: 4px 4px;
  background: var(--blue-l);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-weight: 700;
  font-size: 0.78em;
  font-family: inherit;
  line-height: 1.2;
  word-break: keep-all;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  transition: background 0.15s, transform 0.1s;
}
#pagination button:active:not(:disabled) {
  background: var(--blue);
  transform: scale(0.95);
}
#pagination button:disabled {
  background: #dce6ef;
  color: #aaa;
  cursor: not-allowed;
}
#pagination span {
  font-weight: 700;
  font-size: 0.82em;
  color: #555;
  text-align: center;
  white-space: nowrap;
}

/* ── 빈 상태 ───────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 60px 32px;
}
.empty-icon  { font-size: 3em; margin-bottom: 16px; }
.empty-title { font-size: 1em; font-weight: 700; margin-bottom: 8px; }
.empty-desc  { font-size: 0.85em; color: var(--sub); line-height: 1.7; }

/* ── 토스트 ────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: calc(24px + var(--safe-bot));
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: #1a2332;
  color: #fff;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 0.85em;
  white-space: nowrap;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  transition: transform 0.3s ease;
  z-index: 9999;
  pointer-events: none;
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* ── 서버 오류 오버레이 ──────────────────────────────────── */
#reconnect-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 99999;
}

/* ── 반응형 (태블릿+) ──────────────────────────────────── */
@media (min-width: 600px) {
  #news-list { grid-template-columns: repeat(2, 1fr); }
  .header-title { font-size: 1.3em; }
  .search-form button { padding: 0 20px; font-size: 0.92em; }

  #pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
  }
  #pagination button {
    width: auto;
    min-width: 72px;
    font-size: 0.85em;
    padding: 0 14px;
  }
}
@media (min-width: 960px) {
  #news-list     { grid-template-columns: repeat(2, 1fr); max-width: 1000px; }
  .control-wrap  { max-width: 100%; }
  .search-form   { max-width: 1000px; }
  .filter-bar    { max-width: 1000px; }
  #pagination    { max-width: 1000px; }
  .progress-wrap { max-width: 1000px; }
}

/* ══════════════════════════════════════════════════════
   PWA 설치 배너
══════════════════════════════════════════════════════ */
#pwa-banner {
  position: fixed;
  bottom: calc(20px + var(--safe-bot));
  left: 50%;
  transform: translateX(-50%) translateY(140px);
  width: calc(100% - 32px);
  max-width: 460px;
  background: linear-gradient(135deg, #1a3a5c 0%, #1e4a78 100%);
  border-radius: 18px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.35);
  z-index: 9990;
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  overflow: hidden;
}
#pwa-banner.show {
  transform: translateX(-50%) translateY(0);
}

/* iOS 화살표 */
.pwa-arrow {
  text-align: center;
  color: var(--gold);
  font-size: 1.4em;
  padding-bottom: 10px;
  animation: bounce 1.2s ease infinite;
}
@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(5px); }
}

.pwa-inner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
}
.pwa-icon {
  width: 52px;
  height: 52px;
  border-radius: 13px;
  flex-shrink: 0;
  box-shadow: 0 3px 12px rgba(0,0,0,0.3);
}
.pwa-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.pwa-text strong {
  color: #fff;
  font-size: 0.92em;
  font-weight: 700;
}
.pwa-text span {
  color: rgba(255,255,255,0.7);
  font-size: 0.75em;
  line-height: 1.5;
}
.pwa-text b {
  color: var(--gold);
  font-weight: 700;
}
.pwa-ok {
  flex-shrink: 0;
  background: var(--gold);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 9px 16px;
  font-size: 0.86em;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.15s, transform 0.1s;
}
.pwa-ok:active { opacity: 0.8; transform: scale(0.96); }
.pwa-x {
  flex-shrink: 0;
  background: rgba(255,255,255,0.12);
  color: rgba(255,255,255,0.75);
  border: none;
  border-radius: 50%;
  width: 30px;
  height: 30px;
  font-size: 0.82em;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s;
}
.pwa-x:active { background: rgba(255,255,255,0.25); }
