/* ==================== RESET & BASE ==================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --accent: #FF4136;
  --accent-light: #FF6B63;
  --accent-bg: #FFF0EF;
  --bg: #F3F4F6;
  --surface: #FFFFFF;
  --surface2: #F9FAFB;
  --border: #E5E7EB;
  --text: #111827;
  --text2: #4B5563;
  --text3: #9CA3AF;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 6px 28px rgba(0, 0, 0, 0.1);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --nav-h: 60px;
  --header-h: 56px;
  --transition: 0.18s ease;
  --font: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

[data-theme="dark"] {
  --bg: #0D0E12;
  --surface: #181920;
  --surface2: #20222B;
  --border: #2C2F3B;
  --text: #F3F4F6;
  --text2: #A1A7B3;
  --text3: #6B7280;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 6px 28px rgba(0, 0, 0, 0.5);
  --accent-bg: rgba(255, 65, 54, 0.14);
}

html, body { height: 100%; overflow: hidden; }
body {
  font-family: var(--font);
  font-size: 15px;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }
img { max-width: 100%; display: block; }

/* ==================== APP LAYOUT ==================== */
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 780px;
  margin: 0 auto;
  position: relative;
  background: var(--surface);
  box-shadow: var(--shadow-md);
}

/* ==================== HEADER ==================== */
#header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: var(--header-h);
}

.header-content h1 {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--text);
}

.header-actions { display: flex; gap: 8px; align-items: center; }

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  background: var(--bg);
  color: var(--text2);
  transition: all var(--transition);
}

.icon-btn:active, .icon-btn:hover {
  background: var(--border);
  transform: scale(0.95);
}

#refresh-btn { font-size: 20px; font-weight: 600; }
#refresh-btn.spinning { animation: spin 0.75s linear infinite; }

/* ==================== FILTER CHIPS ==================== */
.filter-row {
  display: flex;
  gap: 8px;
  padding: 6px 16px 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.filter-row::-webkit-scrollbar { display: none; }

.filter-chip {
  flex-shrink: 0;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  background: var(--bg);
  color: var(--text2);
  border: 1.5px solid transparent;
  transition: all var(--transition);
  white-space: nowrap;
}

.filter-chip.active {
  background: var(--accent-bg);
  color: var(--accent);
  border-color: var(--accent);
}

.filter-chip:active { transform: scale(0.96); }

/* ==================== MAIN / PAGES ==================== */
#main {
  flex: 1;
  position: relative;
  overflow: hidden;
}

.page {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: none;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px);
}

.page.active { display: block; }

/* ==================== BOTTOM NAV ==================== */
#bottom-nav {
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 100;
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 8px 0 6px;
  color: var(--text3);
  transition: all var(--transition);
  position: relative;
}

.nav-item.active { color: var(--accent); }
.nav-item.active::after {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 28px;
  height: 2.5px;
  background: var(--accent);
  border-radius: 0 0 2px 2px;
}

.nav-icon { font-size: 21px; line-height: 1; }
.nav-label { font-size: 11px; font-weight: 700; }
.nav-item:active { transform: scale(0.92); }

/* ==================== SECTION HEADERS ==================== */
.section-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 18px 16px 10px;
}

.section-header h2 {
  font-size: 17px;
  font-weight: 800;
  flex: 1;
  letter-spacing: -0.3px;
}

.section-icon { width: 18px; height: 18px; font-size: 17px; line-height: 1; }
.section-time { font-size: 12px; color: var(--text3); flex-shrink: 0; }

/* ==================== GOOGLE TRENDS LIST ==================== */
.trends-list { padding: 0 16px; }

.trend-item {
  background: var(--surface);
  border-radius: var(--radius);
  margin-bottom: 8px;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all var(--transition);
  overflow: hidden;
}

.trend-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
}

.trend-item:hover {
  border-color: var(--accent-light);
}

.trend-item.expanded {
  border-color: var(--accent);
}

.trend-rank {
  min-width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 800;
  flex-shrink: 0;
}

.trend-rank.top1 { background: #FFD700; color: #7B5800; }
.trend-rank.top2 { background: #D1D5DB; color: #374151; }
.trend-rank.top3 { background: #E69A5B; color: #5E2E06; }
.trend-rank.other { background: var(--bg); color: var(--text2); font-size: 12px; }

.trend-info { flex: 1; min-width: 0; }
.trend-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.trend-traffic {
  font-size: 12px;
  color: var(--text3);
  margin-top: 1px;
}

.trend-thumb {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--bg);
}

.trend-arrow {
  font-size: 14px;
  color: var(--text3);
  transition: transform var(--transition);
  flex-shrink: 0;
}
.trend-item.expanded .trend-arrow { transform: rotate(180deg); color: var(--accent); }

.trend-news {
  display: none;
  padding: 0 14px 12px;
  border-top: 1px solid var(--border);
  background: var(--surface2);
  gap: 8px;
  flex-direction: column;
}
.trend-item.expanded .trend-news { display: flex; padding-top: 10px; }

.trend-news-item {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: background var(--transition);
}
.trend-news-item:hover { background: var(--bg); }

.trend-news-img {
  width: 54px;
  height: 54px;
  border-radius: 6px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--border);
}

.trend-news-content { flex: 1; min-width: 0; }
.trend-news-title {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  color: var(--text);
}
.trend-news-source {
  font-size: 11px;
  color: var(--text3);
  margin-top: 4px;
}

.trend-search-link {
  display: block;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  padding: 6px;
  border-radius: var(--radius-sm);
  background: var(--accent-bg);
}

/* ==================== TRENDAYS ISSUES ==================== */
.issues-list { padding: 0 16px 8px; }

.issue-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 10px;
  overflow: hidden;
  transition: border-color var(--transition);
}

.issue-card-header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px;
  cursor: pointer;
}

.issue-rank-badge {
  min-width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 800;
  flex-shrink: 0;
}

.issue-main { flex: 1; min-width: 0; }

.issue-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.issue-keyword {
  font-size: 16px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.3px;
}

.issue-stat {
  font-size: 12px;
  color: var(--text3);
  margin-top: 2px;
}
.issue-stat .surge-badge {
  color: var(--accent);
  font-weight: 700;
}

.issue-summary {
  font-size: 13px;
  color: var(--text2);
  line-height: 1.55;
  margin-top: 8px;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.issue-card.expanded .issue-summary {
  -webkit-line-clamp: unset;
}

.issue-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.community-chip {
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  background: var(--bg);
  color: var(--text2);
  border: 1px solid var(--border);
  transition: all var(--transition);
}

.community-chip:hover,
.community-chip.active {
  background: var(--accent-bg);
  color: var(--accent);
  border-color: var(--accent);
}

.issue-toggle-btn {
  font-size: 16px;
  color: var(--text3);
  padding: 4px;
  transition: transform var(--transition);
  flex-shrink: 0;
  margin-top: 2px;
}
.issue-card.expanded .issue-toggle-btn { transform: rotate(180deg); color: var(--accent); }

.heatmap-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

.heatmap {
  flex: 1;
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 22px;
}

.heatmap-bar {
  flex: 1;
  border-radius: 2px 2px 0 0;
  min-height: 2px;
  background: var(--accent);
  opacity: 0.25;
}
.heatmap-bar.peak { opacity: 1; }

.heatmap-peak-label {
  font-size: 11px;
  color: var(--text3);
  flex-shrink: 0;
}

/* Issue posts list */
.issue-posts {
  display: none;
  border-top: 1px solid var(--border);
  background: var(--surface2);
}
.issue-card.expanded .issue-posts { display: block; }

.issue-posts-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--text3);
  padding: 9px 14px 6px;
}

.issue-ext-link {
  color: var(--accent);
  font-size: 11px;
}

.issue-post-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  border-top: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--transition);
}
.issue-post-item:hover { background: var(--bg); }
.issue-post-item.highlighted {
  background: var(--accent-bg);
}

.site-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 20px;
  background: var(--surface);
  color: var(--accent);
  border: 1px solid var(--border);
  flex-shrink: 0;
  white-space: nowrap;
}

.issue-post-title {
  font-size: 13px;
  color: var(--text);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.issue-post-meta {
  font-size: 11px;
  color: var(--text3);
  flex-shrink: 0;
}

/* ==================== FEED LIST ==================== */
.notice-banner {
  margin: 10px 16px 4px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  background: var(--accent-bg);
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.4;
}

.feed-list { padding: 0; }

.feed-card {
  display: flex;
  gap: 12px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--transition);
}
.feed-card:hover, .feed-card:active { background: var(--surface2); }

.feed-thumbnail {
  width: 72px;
  height: 72px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  flex-shrink: 0;
  background: var(--bg);
}

.feed-no-thumb {
  width: 72px;
  height: 72px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
}

.feed-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.feed-source-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}

.feed-source-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 20px;
  color: white;
  flex-shrink: 0;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge-daum { background: #F97316; }
.badge-dcinside { background: #3B82F6; }
.badge-instiz { background: #10B981; }
.badge-ruliweb { background: #2563EB; }
.badge-clien { background: #0D9488; }
.badge-theqoo { background: #9333EA; }
.badge-default { background: #6B7280; }

.feed-category {
  font-size: 11px;
  color: var(--text3);
  background: var(--bg);
  padding: 2px 6px;
  border-radius: 10px;
  flex-shrink: 0;
}

.feed-title {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.4;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.feed-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 6px;
  font-size: 12px;
  color: var(--text3);
  align-items: center;
}

.feed-meta-item { display: flex; align-items: center; gap: 3px; }

.feed-end {
  text-align: center;
  padding: 20px 16px;
  font-size: 12px;
  color: var(--text3);
}

/* ==================== POPULAR PAGE (WAGLENET) ==================== */
.wagle-header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px 8px;
  font-size: 12px;
  color: var(--text3);
}

.wagle-header-bar strong {
  color: var(--text);
  font-size: 14px;
}

.wagle-list {
  padding: 0 12px;
}

.wagle-item {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 13px 10px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--transition);
}
.wagle-item:hover, .wagle-item:active {
  background: var(--surface2);
}

.wagle-rank {
  min-width: 26px;
  height: 26px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 800;
  flex-shrink: 0;
  margin-top: 1px;
  background: var(--bg);
  color: var(--text2);
}

.wagle-rank.top {
  background: #F59E0B;
  color: #111827;
}

.wagle-body {
  flex: 1;
  min-width: 0;
}

.wagle-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.wagle-title-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex: 1;
}

.wagle-new-badge {
  flex-shrink: 0;
  font-size: 10px;
  font-weight: 800;
  padding: 1px 6px;
  border-radius: 5px;
  background: rgba(16, 185, 129, 0.14);
  color: #10B981;
  border: 1px solid rgba(16, 185, 129, 0.35);
}

.wagle-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.wagle-detail-btn {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 6px;
  background: var(--bg);
  color: var(--text2);
  border: 1px solid var(--border);
  transition: all var(--transition);
}
.wagle-detail-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.wagle-meta-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 7px;
  font-size: 12px;
}

.wagle-views {
  color: #D97706;
  font-weight: 700;
}
[data-theme="dark"] .wagle-views {
  color: #FBBF24;
}

.wagle-comments {
  color: var(--text2);
  font-weight: 600;
}

.wagle-tags {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.wagle-comm-chip {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 6px;
  background: var(--bg);
  color: var(--text2);
  border: 1px solid var(--border);
}

.wagle-score-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(245, 158, 11, 0.14);
  color: #D97706;
  border: 1px solid rgba(245, 158, 11, 0.28);
}
[data-theme="dark"] .wagle-score-badge {
  color: #FCD34D;
}

/* ==================== STATES ==================== */
.loading-state, .empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  gap: 14px;
  color: var(--text3);
  font-size: 14px;
  text-align: center;
  min-height: 320px;
}

.empty-icon { font-size: 44px; line-height: 1; }

.primary-btn {
  padding: 10px 18px;
  border-radius: 22px;
  background: var(--accent);
  color: white;
  font-size: 14px;
  font-weight: 700;
  box-shadow: var(--shadow);
  transition: transform var(--transition), opacity var(--transition);
}
.primary-btn:hover { opacity: 0.92; }
.primary-btn:active { transform: scale(0.96); }

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

.load-more {
  display: flex;
  justify-content: center;
  padding: 20px;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ==================== SCROLL STYLING ==================== */
.page::-webkit-scrollbar { width: 5px; }
.page::-webkit-scrollbar-track { background: transparent; }
.page::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
