.signature-art {
  position: fixed;
  top: 250px;
  right: -230px;
  width: 690px;
  height: 318px;
  background-image: url('/static/images/ui/signature.svg');
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  filter: blur(5px);
  pointer-events: none;
  transform: rotate(-90deg);
}

.main-content {
  margin-top: 110px;
}

.original-section {
  position: relative;
  overflow: visible;
  background-image: url('/static/images/ui/Origical_background_img.png');
  background-repeat: no-repeat;
  background-size: cover;
  background-position: center;
  padding: 20px 0 30px;
}

.original-section::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: -120px;
  bottom: -120px;
  background: linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0) 0%,
    rgba(0, 0, 0, 0.55) 30%,
    rgba(0, 0, 0, 0.8) 75%,
    rgba(0, 0, 0, 0) 87%
  );
  z-index: 0;
  pointer-events: none;
}

.original-section > * {
  position: relative;
  z-index: 1;
}

.ranking-empty {
  grid-column: 1 / -1;
  padding: 40px 20px;
  text-align: center;
  color: #999;
  word-break: keep-all;
}

/* ===== PWA 설치 ===== */
.pwa-install-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  background: transparent;
  border: 1px solid #4a4a4f;
  border-radius: 999px;
  color: #d8d8dc;
  font-size: 12px;
  cursor: pointer;
  margin-right: 4px;
}

.pwa-install-btn svg { display: block; }

/* 설치 프롬프트 준비되면 포인트 색으로 강조 */
.pwa-install-btn.pwa-ready {
  border-color: #FFA178;
  color: #FFA178;
}

.pwa-guide-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 2000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.pwa-guide-overlay.show { opacity: 1; pointer-events: auto; }

.pwa-guide {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%) translateY(105%);
  width: 100%;
  max-width: 37.5rem;
  background: #29292c;
  border: 1px solid #3a3a3e;
  border-bottom: none;
  border-radius: 14px 14px 0 0;
  z-index: 2100;
  transition: transform 0.28s ease;
  padding: 10px 20px calc(24px + env(safe-area-inset-bottom));
  text-align: center;
}

.pwa-guide.show { transform: translateX(-50%) translateY(0); }

.pwa-guide-handle {
  width: 44px;
  height: 4px;
  border-radius: 999px;
  background: #4a4a4f;
  margin: 6px auto 16px;
}

.pwa-guide-title {
  display: block;
  font-size: 17px;
  color: #f2f2f2;
  margin-bottom: 10px;
}

.pwa-guide-body {
  font-size: 14px;
  color: #d8d8dc;
  line-height: 1.7;
  margin: 0 0 18px;
}

.pwa-guide-close {
  width: 100%;
  padding: 13px;
  background: #FFA178;
  color: #1a1a1a;
  border: none;
  border-radius: 6px;
  font-size: 15px;
  cursor: pointer;
}

/* ===== 햄버거 메뉴 ===== */
.nav-menu-btn {
  background: transparent;
  border: none;
  padding: 5px 1px;
  cursor: pointer;
  display: flex;
  align-items: center;
}

.menu-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 1500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.menu-overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.menu-drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  right: max(0px, calc(50% - 18.75rem));
  width: 280px;
  max-width: 82vw;
  background: #29292c;
  border-left: 1px solid #3a3a3e;
  z-index: 1600;
  transform: translateX(105%);
  transition: transform 0.28s ease;
  display: flex;
  flex-direction: column;
  padding: 14px 16px calc(20px + env(safe-area-inset-bottom));
  overflow-y: auto;
}

.menu-drawer.show {
  transform: translateX(0);
}

.menu-drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.menu-drawer-title {
  font-size: 17px;
  color: #f2f2f2;
}

.menu-close-btn {
  background: transparent;
  border: none;
  color: #a8a8ad;
  cursor: pointer;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
}

.menu-close-btn:hover {
  background: #333336;
  color: #f2f2f2;
}

.menu-user {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: #333336;
  border: 1px solid #3a3a3e;
  border-radius: 4px;
  text-decoration: none;
  margin-bottom: 16px;
}

.menu-user-avatar {
  width: 42px;
  height: 42px;
  border-radius: 999px;
  object-fit: cover;
  background: #222;
}

.menu-user-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.menu-user-name {
  color: #f2f2f2;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.menu-user-sub {
  color: #a8a8ad;
  font-size: 12px;
}

.menu-user-coin {
  color: #FFA178;
  font-size: 13px;
  white-space: nowrap;
}

.menu-login-btn {
  display: block;
  text-align: center;
  padding: 13px;
  background: #FFA178;
  color: #1a1a1a;
  border-radius: 4px;
  text-decoration: none;
  font-size: 15px;
  margin-bottom: 16px;
}

.menu-links {
  display: flex;
  flex-direction: column;
  border-top: 1px solid #3a3a3e;
}

.menu-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 14px 4px;
  color: #d8d8dc;
  font-size: 15px;
  text-decoration: none;
  background: transparent;
  border: none;
  border-bottom: 1px solid #3a3a3e;
  cursor: pointer;
}

.menu-item:hover {
  color: #FFA178;
}

.menu-logout {
  margin-top: auto;
  border-bottom: none;
  border-top: 1px solid #3a3a3e;
  color: #e5484d;
}

/* ===== 카테고리 탭 ===== */
.category-page {
  padding: 0 0 90px;
}

/* 카테고리 배너 (사진처럼 칩 버튼을 배너 안에 포함) */
.category-banner {
  position: relative;
  width: 100%;
  color: #ffffff;
  font-size: 34px;
  padding: 10px 20px 18px;
  white-space: nowrap;
  overflow: hidden;
}

.category-banner-rect {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, #B24A4780 0%, #FFA17880 45%, #99614820 100%);
}

.category-banner-rect::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: url("/static/images/ui/Banner_signature_shadow.svg");
  background-repeat: no-repeat;
  background-position: right center;
  background-size: auto 100%;
  pointer-events: none;
}

.category-banner-title {
  position: relative;
  z-index: 1;
}

.category-banner .tr {
  position: relative;
  display: inline-block;
}

.category-banner .rect {
  background: #ffffff;
  width: 100%;
  height: 4px;
  position: absolute;
  left: 0;
  top: 44%;
}

/* 칩 필터: 배너 안, 가로 스크롤 행 */
.category-chip-rows {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 8px;
  margin-top: 16px;
  margin-right: -20px; /* 배너 오른쪽 패딩만큼 상쇄해 화면 끝까지 스크롤되도록 */
  font-size: 0;
}

.category-chip-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.category-chip-row::-webkit-scrollbar {
  display: none;
}

.category-chip {
  flex: 0 0 auto;
  padding: 7px 15px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: 18px;
  color: #ffffff;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}

.category-chip:hover {
  border-color: rgba(255, 255, 255, 0.9);
}

.category-chip.is-active {
  background: #ffffff;
  border-color: #ffffff;
  color: #1a1a1a;
  font-weight: 700;
}

.category-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  margin-bottom: 14px;
}

.category-count {
  font-size: 13px;
  color: #a8a8ad;
}

.category-toolbar-controls {
  display: flex;
  gap: 8px;
}

.category-select {
  appearance: none;
  background: #ececf0 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23555' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E") no-repeat right 9px center;
  border: 1px solid #d5d5da;
  border-radius: 8px;
  color: #222222;
  font-size: 13px;
  padding: 7px 28px 7px 12px;
  cursor: pointer;
}

.category-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px 12px;
  padding: 8px 16px 0;
}

/* 카테고리 카드는 '사진' 기준 (랭킹 카드 스타일 아님):
   정사각형에 가까운 둥근 모서리 이미지 + 그 아래로 제목/소개/태그 */
#category-grid .ranking-card {
  aspect-ratio: auto;
  overflow: visible;
}

#category-grid .ranking-card > img {
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 10px;
  margin-bottom: 8px;
}

#category-grid .ranking-card h3 {
  font-family: 'Pretendard-Regular', sans-serif;
  font-size: 15px;
  color: #f2f2f2;
  padding-bottom: 4px;
}

#category-grid .ranking-card h4 {
  font-size: 12px;
  line-height: 1.4;
  max-height: 2.8em;
}

#category-grid .ranking-card .tags {
  margin-top: 6px;
}

.category-card {
  position: relative;
  background: #2b2b2e;
  border: 1px solid #3a3a3e;
  border-radius: 4px;
  overflow: hidden;
}

.category-card:hover {
  border-color: #4a4a4f;
}

.category-card-link {
  position: absolute;
  inset: 0;
  z-index: 1;
}

.category-card-thumb {
  position: relative;
}

.category-card-thumb img:first-child {
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  display: block;
  background: #333336;
}

.category-card-like {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  background: rgba(0, 0, 0, 0.55);
  border-radius: 4px;
  padding: 5px;
  display: flex;
}

.category-card-like .like-icon {
  width: 18px;
  height: 18px;
  display: block;
}

.category-card-body {
  padding: 10px 12px 12px;
}

.category-card-name {
  margin: 0 0 4px;
  font-size: 14px;
  color: #f2f2f2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.category-card-info {
  margin: 0 0 8px;
  font-size: 12px;
  color: #a8a8ad;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 2.9em;
}

.category-card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 8px;
}

.category-card-tag {
  font-size: 11px;
  color: #77777c;
  white-space: nowrap;
}

.category-empty {
  grid-column: 1 / -1;
  padding: 48px 20px;
  text-align: center;
  color: #77777c;
  font-size: 14px;
}

/* ===== NEW 뱃지 (만든 지 7일 이내 — 서버 popularity.py 가 판정) ===== */
.new-badge {
  position: absolute;
  top: 6px;
  left: 6px;
  z-index: 4;
  background: #FFA178;
  color: #1a1a1a;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  padding: 3px 6px;
  border-radius: 2px;
  letter-spacing: 0.3px;
  pointer-events: none;
}

/* 인기! (최근 24시간 대화가 평소의 2배 이상 — popularity.py): NEW 와 같은 자리·크기, 어두운 바탕 + 강조색 테두리 */
.new-badge.hot-badge {
  background: #1a1a1a;
  color: #FFA178;
  outline: 1px solid #FFA178; outline-offset: -1px;
}

/* 카드의 대화·찜 수 (기준 미만이면 서버가 빼서 안 보임) */
.card-stats {
  display: flex;
  gap: 8px;
  margin: 4px 0 0;
  font-size: 11px;
  line-height: 1.3;
  color: #9a9aa0;
  white-space: nowrap;
  overflow: hidden;
  font-variant-numeric: tabular-nums;
}
.card-stats span + span::before {
  content: '·';
  margin-right: 8px;
  color: #5c5c61;
}
/* ORIGINAL STORY 카드는 글자가 사진 위에 겹치는 형태 → 맨 아래 가운데 */
.ori-character-card .card-stats {
  position: absolute;
  left: 50%;
  bottom: 2.5%;
  transform: translateX(-50%);
  width: 90%;
  justify-content: center;
  z-index: 1;
  margin: 0;
  color: rgba(255, 255, 255, 0.8);
}
.ori-character-card .card-stats span + span::before { color: rgba(255, 255, 255, 0.5); }

/* ===== 카테고리 스켈레톤 (무한 스크롤 로딩) ===== */
.category-sentinel {
  grid-column: 1 / -1;
  height: 1px;
}

.category-skeleton .cs-thumb {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  background: #2b2b2e;
  margin-bottom: 10px;
}

.category-skeleton .cs-line {
  height: 12px;
  border-radius: 4px;
  background: #2b2b2e;
  margin-top: 8px;
}

.category-skeleton .cs-line.short {
  width: 60%;
}

.category-skeleton .cs-thumb,
.category-skeleton .cs-line {
  animation: cs-pulse 1.2s ease-in-out infinite;
}

@keyframes cs-pulse {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 1; }
}

/* ===== 메인 탭 (tab.js) — 숨긴 탭은 hidden 속성, 탭이 켜질 때만 로딩 ===== */
.main-content > .tab-content[hidden] {
  display: none;
}

/* 해시 딥링크(#tab=rank|cat): <head> 스크립트가 첫 페인트 전에 표시 → tab.js 초기화 후 제거 */
html[data-initial-tab] #tab1 {
  display: none;
}

html[data-initial-tab="rank"] #tab2[hidden],
html[data-initial-tab="cat"] #tab3[hidden] {
  display: block;
}

/* 랭킹 탭 스켈레톤 (탭이 켜져 /api/ranking 응답을 기다리는 동안) */
.ranking-skeleton {
  width: 100%;
  aspect-ratio: 139 / 167;
  background: #2b2b2e;
  animation: cs-pulse 1.2s ease-in-out infinite;
}

/* 불러오기 실패 → 다시 시도 (랭킹·카테고리) */
.tab-retry-btn {
  display: block;
  margin: 14px auto 0;
  padding: 9px 20px;
  background: transparent;
  border: 1px solid #4a4a4f;
  border-radius: 999px;
  color: #f2f2f2;
  font-size: 13px;
  cursor: pointer;
}

.tab-retry-btn:hover {
  border-color: #FFA178;
  color: #FFA178;
}

/* 베스트 키워드·뉴 스토리 카드: 카드 높이를 사진 높이로 고정해 두면 이름·설명 아래 '대화·찜' 줄이
   다음 줄 카드에 가려지거나 가로 스크롤 영역 밖으로 잘림 → 카드·줄 높이를 내용에 맞춤 (사진 높이는 그대로) */
.best-character-card,
.new-character-card { height: auto; }
.best-character-grid,
.new-character-grid { height: auto; align-items: start; }
.best-character-card .card-stats,
.new-character-card .card-stats { margin-top: 3px; }

/* 가로 스크롤 줄은 가로로만 (overflow-x: auto 만 두면 세로도 auto 가 되어 위아래로 흔들림) */
.best-character-grid,
.new-character-grid { overflow-y: hidden; overscroll-behavior-x: contain; }

/* 인기! 뱃지: DEEP 뱃지(adult.css .age-badge-19)와 같은 크기·흰 테두리·흰 글자, 색(코랄→피치)과 모양(각진 사각)만 다르게 */
.new-badge.hot-badge {
  top: 6px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  box-sizing: border-box;
  border: 2px solid #ffffff;
  border-radius: 2px;
  outline: none;
  background: linear-gradient(135deg, #ff5a6e, #ffa178);
  color: #ffffff;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.4px;
}

/* 카드 아래 '대화 N' 줄이 늘 붙으므로 베스트 키워드·뉴 스토리 줄 아래 여백을 조금 더 (세로 스크롤·잘림 없이) */
.best-character-grid,
.new-character-grid { padding-bottom: 28px; }
