/* Index LIVE mode.  Kept local to the index surface; /live.html redirects here. */

.header-search-wrapper.index-search-with-mode {
  /* 검색줄은 헤더 자신의 중앙에 선다 = 사이드바를 뺀 본문 영역의 중앙.
     로그인 모달·구독 안내 카드·표가 모두 이 축을 쓰므로 화면의 세로 중심선이
     하나로 유지된다.
     ⚠ 예전에는 여기서 사이드바 폭의 절반(-105px)을 빼 브라우저 뷰포트 중앙에
     맞췄다. 그러면 검색줄만 다른 축을 쓰게 되어, 나란히 뜨는 모달들과 어긋나
     보인다(대표님 2026-08-16 지적). 보정을 되살리지 말 것. */
  position: absolute;
  z-index: 2;
  left: 50%;
  /* 좌우로 비워둘 폭. 검색줄은 흐름 밖(absolute)이라 flex가 충돌을 막아주지
     못한다. 그래서 옆 그룹이 실제로 차지하는 폭만큼을 직접 예약해야 한다.
     ⚠ 예전 값 160px(=320÷2)은 우측 아이콘 묶음(실측 282px)보다 훨씬 작아,
     좁은 화면에서 검색줄이 언어선택기·프로필 위로 올라탔다(2026-08-20). */
  width: min(780px, calc(100% - var(--header-side-reserve, 306px) * 2));
  max-width: calc(100% - 40px);
  margin: 0;
  transform: translateX(-50%);
  gap: 8px;
}

.header .header-content {
  position: relative;
}

/* 사이드바가 접혀도 축은 그대로 "헤더의 중앙"이다. 헤더 자체가 사이드바 폭만큼
   left를 옮기므로 50%만으로 두 상태 모두 본문 중앙에 맞는다 — 별도 보정이 필요없다.
   ⚠ 여기에 `.cs-sidebar.collapsed ~ .container ... { left: 50% }` 규칙이 있었다.
   값이 기본값과 똑같아 아무 일도 하지 않으면서, 클래스 6개짜리 특이도로 아래
   미디어쿼리의 `left: auto`(클래스 3개)를 이겨버렸다 — 미디어쿼리는 특이도를
   더해주지 않는다. 그 탓에 좁은 화면에서 검색줄이 헤더 밖으로 326px 밀려나 있었다
   (2026-08-20 실측). 되살리지 말 것. */

.index-search-with-mode .index-search-input-group {
  position: relative;
  display: flex;
  flex: 1 1 auto;
  min-width: 0;
  align-items: center;
  gap: 12px;
}

.index-search-with-mode .header-search-input {
  width: auto;
  min-width: 0;
  flex: 1 1 auto;
}

.index-search-with-mode .autocomplete-dropdown {
  left: 0;
  right: 0;
}

/* 폭은 고정이 아니라 "최소 170px, 라벨이 길면 그만큼". 고정폭을 반반 나누면
   영어(Videos & Channels)·일본어(動画・チャンネル)가 제 칸을 넘어 LIVE 위로
   겹친다(2026-09-11 대표님 지적, 실측 26~48px 초과). 한국어는 반쪽에 들어가므로
   예전과 똑같이 170px 반반으로 보인다. 아래 미디어쿼리의 폭도 전부 min-width. */
.index-mode-segment {
  display: inline-flex;
  flex: 0 0 auto;
  min-width: 170px;
  align-items: stretch;
  margin: 0;
  padding: 0;
  border: 1px solid var(--border-color);
  border-radius: 999px;
  background: var(--bg-secondary, var(--card-bg));
}

.index-mode-segment__button {
  display: flex;
  width: 100%;
  min-width: 0;
  min-height: 34px;
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: 0;
  background: transparent;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1.1;
  cursor: pointer;
}

.index-mode-segment__label {
  display: inline-grid;
  /* 남는 폭은 반반, 모자라면 긴 라벨이 제 글자폭을 지킨다 */
  flex: 1 1 0;
  min-width: max-content;
  min-height: 34px;
  place-items: center;
  padding: 6px 8px;
  border-radius: 999px;
  color: var(--text-secondary);
  text-align: center;
  white-space: nowrap;
  pointer-events: none;
}

.index-mode-segment__button:not(.is-live) [data-index-mode-label="trend"],
.index-mode-segment__button.is-live [data-index-mode-label="live"] {
  color: #ffffff;
  background: var(--primary-color);
}

.index-mode-segment__label [aria-hidden="true"] {
  color: currentColor;
  font-size: 0.75em;
  vertical-align: 0.08em;
}

.index-mode-segment__button:focus-visible,
#indexLiveMount button:focus-visible,
#indexLiveMount select:focus-visible,
#indexLiveMount a:focus-visible {
  outline: 3px solid var(--primary-color);
  outline-offset: 2px;
}

#indexLiveMount {
  min-width: 0;
}

#indexLiveMount[hidden] {
  display: none;
}

#indexLiveMount .index-live-mode {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
  padding: 25px;
  border: 1px solid #333333;
  border-radius: 15px;
  background: transparent;
  box-shadow: none;
  color: var(--text-primary);
}

body.dark-theme #indexLiveMount .index-live-mode {
  border-color: #e0e0e0;
  background: transparent;
}

#indexLiveMount .index-live-mode__toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

#indexLiveMount .index-live-mode__field {
  display: flex;
  flex: 1 1 0;
  align-items: center;
  min-width: 0;
  gap: 7px;
  color: var(--text-secondary);
  font-size: 0.82rem;
  font-weight: 700;
}

#indexLiveMount .index-live-mode__field > span {
  flex: 0 0 auto;
  white-space: nowrap;
}

/* 툴바는 국가 · 형태 · 카테고리 · 순위 기준 4칸이다. 형태는 "롱폼 라이브/숏폼 라이브"
   두 항목뿐이라 좁아도 되고, 항목 이름이 가장 긴 카테고리에 여유를 더 준다. */
#indexLiveMount .index-live-mode__field:nth-child(2) { flex-grow: 0.85; }
#indexLiveMount .index-live-mode__field:nth-child(3) { flex-grow: 1.25; }

#indexLiveMount .index-live-mode__field select {
  width: auto;
  flex: 1 1 auto;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--border-color);
  border-radius: 7px;
  background: var(--input-bg, var(--bg-primary));
  color: var(--text-primary);
  font: inherit;
  font-size: 0.9rem;
}

#indexLiveMount .index-live-mode__results,
#indexLiveMount .index-live-mode__grid {
  min-width: 0;
}

#indexLiveMount .index-live-mode__grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
}

#indexLiveMount .index-live-card {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--border-color);
  border-radius: 11px;
  background: var(--card-bg, var(--bg-primary));
}

#indexLiveMount .index-live-card__link {
  display: flex;
  min-width: 0;
  height: 100%;
  flex-direction: column;
  color: inherit;
  text-decoration: none;
}

#indexLiveMount .index-live-card__media {
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: var(--bg-tertiary, rgba(127, 127, 127, 0.12));
}

#indexLiveMount .index-live-card__thumbnail,
#indexLiveMount .index-live-card__thumbnail-placeholder {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#indexLiveMount .index-live-card__thumbnail-placeholder {
  background: linear-gradient(135deg, var(--bg-tertiary, #e5e7eb), var(--bg-secondary, #f3f4f6));
}

#indexLiveMount .index-live-card__status {
  position: absolute;
  right: 8px;
  bottom: 8px;
  max-width: calc(100% - 16px);
  overflow: hidden;
  padding: 4px 7px;
  border-radius: 5px;
  background: rgba(185, 28, 28, 0.94);
  color: #ffffff;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#indexLiveMount .index-live-card__content {
  display: flex;
  min-width: 0;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 4px;
  padding: 9px 10px 10px;
}

#indexLiveMount .index-live-card__title,
#indexLiveMount .index-live-card__channel,
#indexLiveMount .index-live-card__supporting {
  margin: 0;
  overflow: hidden;
  min-width: 0;
}

/* `-webkit-line-clamp: 2`는 "최대 2줄"이지 "항상 2줄"이 아니다. 제목이 1줄인 카드에서는
   아래 요소가 통째로 위로 올라와, 한 행에 늘어선 카드들의 채널명·경과시간·지표 줄이
   전부 제각각 높이에 놓였다(대표님 지적 2026-08-07). 2줄분 높이를 항상 확보한다. */
#indexLiveMount .index-live-card__title {
  display: -webkit-box;
  min-height: calc(2 * 1.28em);
  color: var(--text-primary);
  font-size: 0.88rem;
  line-height: 1.28;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

#indexLiveMount .index-live-card__channel,
#indexLiveMount .index-live-card__supporting {
  color: var(--text-secondary);
  font-size: 0.75rem;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 채널명이 길면 줄바꿈돼 카드마다 높이가 또 달라진다. 한 줄로 고정하고 넘치면 생략. */
#indexLiveMount .index-live-card__channel {
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#indexLiveMount .index-live-card__supporting.is-stale { color: #d97706; font-weight: 700; }

/* `margin-top: auto`가 없으면 지표 줄이 본문 바로 밑에 붙어, 제목 길이에 따라 카드마다
   다른 높이에 놓인다. 카드 바닥에 고정해 한 행의 지표가 일직선으로 정렬되게 한다.
   (`__content`가 이미 flex column + flex:1이라 auto 마진이 남은 공간을 다 먹는다.) */
#indexLiveMount .index-live-card__metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  column-gap: 9px;
  margin: 3px 0 0;
  margin-top: auto;
  padding-top: 7px;
  border-top: 1px solid var(--border-color);
}

#indexLiveMount .index-live-card__metrics div {
  display: flex;
  align-items: baseline;
  align-content: flex-start;
  flex-wrap: wrap;
  gap: 2px 4px;
  min-width: 0;
  max-height: 2.5em;
  overflow: hidden;
}

#indexLiveMount .index-live-card__metrics dt {
  flex: 0 0 auto;
  overflow: hidden;
  color: var(--text-secondary);
  font-size: 0.67rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#indexLiveMount .index-live-card__metrics dd {
  display: inline-flex;
  flex: 0 1 auto;
  flex-wrap: wrap;
  gap: 2px 4px;
  min-width: 0;
  max-height: 2.4em;
  margin: 0;
  overflow: hidden;
  color: var(--text-primary);
  font-size: 0.78rem;
  font-weight: 750;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}

#indexLiveMount .index-live-card__currency { white-space: nowrap; }
#indexLiveMount .index-live-card__currency-more { color: var(--text-secondary); font-size: 0.7rem; font-weight: 750; white-space: nowrap; }
#indexLiveMount .index-live-card__collection-state { color: var(--text-secondary); font-size: 0.76rem; font-weight: 650; white-space: nowrap; }
#indexLiveMount .is-unknown { color: var(--text-secondary); font-weight: 600; }

#indexLiveMount .index-live-card:hover,
#indexLiveMount .index-live-card:focus-within {
  border-color: var(--primary-color);
  box-shadow: 0 4px 14px var(--shadow, rgba(0, 0, 0, 0.1));
}

#indexLiveMount .index-live-mode__state {
  display: grid;
  min-height: 200px;
  place-content: center;
  gap: 12px;
  padding: 24px;
  border: 1px dashed var(--border-color);
  border-radius: 10px;
  color: var(--text-secondary);
  text-align: center;
}

#indexLiveMount .index-live-mode__state p { margin: 0; }

#indexLiveMount .index-live-mode__state button {
  justify-self: center;
  padding: 8px 13px;
  border: 1px solid var(--primary-color);
  border-radius: 7px;
  background: var(--primary-color);
  color: #ffffff;
  font: inherit;
  font-weight: 750;
  cursor: pointer;
}

/* 폭이 줄기 시작하면 우측 묶음을 먼저 얇게 만든다. 검색줄은 가운데 정렬이라
   우측이 1px 넓어질 때마다 검색 입력은 2px씩 좁아진다 — 우측을 줄이는 게 가장
   효율이 좋다. 언어 라벨(한국어/English/日本語)을 접어 국기만 남기면 57px을 번다. */
@media (max-width: 1400px) {
  body { --header-side-reserve: 256px; }
  .lang-selector-btn .lang-name,
  .lang-selector-btn .lang-arrow { display: none; }
  .index-mode-segment { min-width: 148px; }
}

@media (max-width: 1280px) {
  #indexLiveMount .index-live-mode__grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

/* === 두 줄 전환 ===
   [좌측][검색줄][우측]을 한 줄에 다 담지 못하는 폭부터는 검색줄을 아랫줄로 내린다.
   한 줄을 고집하면 검색 입력이 60~70px 까지 눌리고 "영상 검색" 셀렉트가 제 칸을
   넘쳐 "영상·채널" 버튼 위로 올라탄다(실측). 아랫줄로 내리면 폭을 전부 쓴다.
   ⚠ 사이드바가 펼쳐져 있으면 본문이 158px 더 좁으므로 그만큼 일찍 전환한다.

   ⚠ body 여백은 건드리지 않는다. 헤더가 두 줄(111px)이 되어도 본문 첫 카드는
   자기 여백으로 그 아래에서 시작하므로 가려지지 않는다. 예전에 `.container`
   시작점(65px)이 헤더 하단(71px)보다 위라는 이유로 body padding 을 덧댄 적이
   있는데, 그 조건은 **한 줄일 때도 늘 참**이라 잣대 자체가 틀렸다. 덧대면
   오히려 본문이 아래로 밀린다. 되살리지 말 것. */
@media (min-width: 769px) and (max-width: 1200px) {
  /* 헤더가 두 줄이 된 만큼(38px)만 본문을 내린다. 안 내리면 퀵 셀렉션 카드
     윗부분이 헤더에 먹힌다(대표님 2026-08-20 실화면 지적). */
  body:not(:has(.cs-sidebar.collapsed)) .container {
    margin-top: 93px;
  }
  body:not(:has(.cs-sidebar.collapsed)) .header .header-content {
    flex-wrap: wrap;
    height: auto;
    gap: 12px;
    padding-top: 8px;
    padding-bottom: 8px;
  }
  body:not(:has(.cs-sidebar.collapsed)) .header {
    height: auto;
  }
  body:not(:has(.cs-sidebar.collapsed)) .header .header-search-wrapper.index-search-with-mode {
    position: relative;
    left: auto;
    right: auto;
    transform: none;
    order: 3;
    /* ⚠ .header-search-wrapper 에 `flex: 1`(basis 0%)이 걸려 있다. flex 항목의
       주축 크기는 width 가 아니라 flex-basis 가 정하므로, basis 를 100% 로
       바꾸지 않으면 width:100% 는 무시되고 줄바꿈도 일어나지 않는다. */
    flex: 1 1 100%;
    width: 100%;
    max-width: 100%;
    margin-top: 0;
  }
}

@media (min-width: 769px) and (max-width: 1040px) {
  .container {
    margin-top: 93px;
  }
  .header .header-content {
    flex-wrap: wrap;
    height: auto;
    gap: 12px;
    padding-top: 8px;
    padding-bottom: 8px;
  }
  .header {
    height: auto;
  }
  .header .header-search-wrapper.index-search-with-mode {
    position: relative;
    left: auto;
    right: auto;
    transform: none;
    order: 3;
    /* ⚠ .header-search-wrapper 에 `flex: 1`(basis 0%)이 걸려 있다. flex 항목의
       주축 크기는 width 가 아니라 flex-basis 가 정하므로, basis 를 100% 로
       바꾸지 않으면 width:100% 는 무시되고 줄바꿈도 일어나지 않는다. */
    flex: 1 1 100%;
    width: 100%;
    max-width: 100%;
    margin-top: 0;
  }
}

@media (max-width: 1024px) {
  .index-mode-segment { min-width: 148px; }
  .index-mode-segment__button { padding-right: 5px; padding-left: 5px; font-size: 0.74rem; }
  #indexLiveMount .index-live-mode__grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 768px) {
  .header .header-search-wrapper.index-search-with-mode {
    position: relative;
    left: auto;
    width: 100%;
    max-width: 100%;
    margin-top: 8px;
    transform: none;
  }
  .index-search-with-mode .index-search-input-group { gap: 6px; }
  .index-mode-segment { min-width: 126px; }
  .index-mode-segment__button { min-height: 32px; font-size: 0.68rem; }
  #indexLiveMount .index-live-mode { padding: 16px; }
  /* 셀렉트가 4개(국가·형태·카테고리·순위)라 좁은 화면에서는 한 줄에 다 넣으면
     각 칸이 라벨도 못 담을 만큼 눌린다. 2×2로 접는다. */
  #indexLiveMount .index-live-mode__toolbar { flex-wrap: wrap; gap: 6px; }
  #indexLiveMount .index-live-mode__field { flex: 1 1 calc(50% - 3px); gap: 4px; font-size: 0.76rem; }
  #indexLiveMount .index-live-mode__field:nth-child(2),
  #indexLiveMount .index-live-mode__field:nth-child(3) { flex-grow: 1; }
  #indexLiveMount .index-live-mode__field select { padding: 7px 6px; font-size: 0.82rem; }
  #indexLiveMount .index-live-mode__grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* 1000px 이하: '영상 검색' 셀렉트를 확 줄인다.
   좁아지면 한 줄을 [셀렉트][입력창][영상·채널] 셋이 나눠 갖는데, 셀렉트가
   150px 을 차지해 정작 검색 입력이 먼저 눌린다(대표님 2026-08-20 지적).
   글자·여백을 줄여 100px 아래로 내리고, 그만큼을 입력창에 넘긴다.
   ⚠ 480px 이하에서는 아래 블록이 아예 감춘다. */
@media (min-width: 481px) and (max-width: 1000px) {
  .index-search-with-mode .search-type-select {
    /* ⚠ indexstyle.css 에 전역 `select { min-width: 150px }` 가 있다. 글자와
       여백만 줄이면 폭이 1px 도 안 줄어든다(실측 — font 12px 로 바뀌었는데도
       150px 그대로). 이 셀렉트에 한해 그 바닥값을 푼다. */
    min-width: 0;
    padding: 8px 4px 8px 9px;
    font-size: 0.75rem;
    border-radius: 30px;
  }
  .index-search-with-mode .index-search-input-group { gap: 6px; }
}

@media (max-width: 480px) {
  .index-search-with-mode { gap: 5px; padding-right: 4px; padding-left: 4px; }
  .index-search-with-mode .search-type-select { display: none; }
  .index-mode-segment { min-width: 108px; }
  .index-mode-segment__button { padding-right: 3px; padding-left: 3px; font-size: 0.63rem; }
  #indexLiveMount .index-live-mode { padding: 12px; }
  #indexLiveMount .index-live-mode__toolbar { gap: 4px; }
  #indexLiveMount .index-live-mode__field { gap: 3px; font-size: 0.7rem; }
  #indexLiveMount .index-live-mode__field select { padding: 7px 4px; font-size: 0.76rem; }
  #indexLiveMount .index-live-mode__grid { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 340px) {
  #indexLiveMount .index-live-mode__field > span {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }
}

@media (prefers-reduced-motion: reduce) {
  .index-mode-segment__button,
  #indexLiveMount *,
  #indexLiveMount *::before,
  #indexLiveMount *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
