:root {
  color-scheme: dark;
  --bg: #0b0d10;
  --panel: #12151a;
  --panel-2: #1a1f26;
  --panel-3: #222933;
  --text: #f7f8fa;
  --muted: #8e99a7;
  --line: #2b333e;
  --accent: #ff4f45;
  --accent-2: #37d6a0;
  --info: #55b8ff;
  --focus: #ffd166;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.38);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
}

body.pseudo-fullscreen {
  overflow: hidden;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  gap: 1px;
  min-height: 100%;
  padding: 0;
  background: var(--line);
}

.viewer,
.explorer {
  min-width: 0;
  background: var(--panel);
}

.viewer {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 22px 24px;
}

.home-discovery {
  display: none;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
  min-height: 0;
  overflow: auto;
  padding: 4px 4px 20px 0;
  scrollbar-gutter: stable;
}

body.home-mode .home-discovery {
  display: grid;
}

.player-panel {
  display: contents;
}

body.home-mode .viewer > .stage,
body.home-mode .viewer > .player-panel {
  display: none;
}

.home-section-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.home-section-head h2 {
  margin: 0;
  font-size: 1.22rem;
  letter-spacing: 0;
}

.home-count {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 0.8rem;
}

.home-head-tools {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* 列数と国の設定。セクションの並び替えとは独立で、常に一覧の先頭に留まる。
   .home-discovery がスクローラなので sticky で上部へ貼り付く。 */
.home-toolbar {
  position: sticky;
  top: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
  padding: 8px 0 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

/* ===== 並び替え可能なトップページのセクション ===== */
.home-section {
  display: grid;
  gap: 0;
}

.home-section-title {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

/* 掴む場所を限定する: グリッドは横スクロールするので、見出しの
   ハンドルだけをドラッグ対象にしないとスクロールと競合する。 */
.home-drag-handle {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--muted);
  /* タッチでのドラッグを成立させるため、ブラウザ既定のスクロールを止める。 */
  touch-action: none;
  cursor: grab;
}

.home-drag-handle svg {
  width: 20px;
  height: 20px;
}

.home-drag-handle:hover {
  border-color: #566273;
  color: var(--text);
}

.home-drag-handle:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.home-section.dragging {
  position: relative;
  z-index: 5;
  opacity: 0.92;
  cursor: grabbing;
}

.home-section.dragging .home-drag-handle {
  cursor: grabbing;
  border-color: rgba(85, 184, 255, 0.56);
  background: #232b34;
  color: var(--text);
}

/* 挿入先の目印。ドラッグ中だけ出す。 */
.home-section.drop-before {
  box-shadow: inset 0 3px 0 0 var(--accent);
}

.home-section.drop-after {
  box-shadow: inset 0 -3px 0 0 var(--accent);
}

body.home-reordering {
  user-select: none;
}

.home-recommend-head {
  margin-top: 12px;
  align-items: center;
}

.home-grid {
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(3, auto);
  grid-auto-columns: clamp(184px, 21vw, 236px);
  gap: 10px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 2px 2px 10px;
  scroll-snap-type: x proximity;
  overscroll-behavior-x: contain;
}

.home-grid::-webkit-scrollbar {
  height: 8px;
}

.home-grid::-webkit-scrollbar-thumb {
  border-radius: 4px;
  background: #2e3843;
}

.home-grid::-webkit-scrollbar-track {
  background: transparent;
}

.home-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #101419;
  padding: 0;
  overflow: hidden;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  content-visibility: auto;
  contain-intrinsic-size: 210px;
  scroll-snap-align: start;
  transition: border-color 140ms ease, background 140ms ease, transform 140ms ease;
}

.home-card:hover {
  border-color: #566273;
  background: #171c22;
  transform: translateY(-2px);
}

.home-card:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.home-card.selected {
  border-color: var(--accent);
  box-shadow: inset 3px 0 0 var(--accent);
}

.home-thumb {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: #050608;
}

.home-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.home-live-badge {
  position: absolute;
  left: 8px;
  bottom: 8px;
  border-radius: 3px;
  background: var(--accent);
  color: #fff;
  padding: 3px 6px;
  font-size: 0.7rem;
  font-weight: 800;
}

.home-meta {
  display: grid;
  /* チャンネル名と統計は別行。行間はタイトルとの間より狭くして1つの塊に見せる。 */
  gap: 3px;
  padding: 10px 11px 12px;
  align-content: start;
}

.home-meta strong {
  display: -webkit-box;
  min-width: 0;
  margin-bottom: 3px;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-height: 1.35;
}

.home-meta > span {
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.8rem;
  line-height: 1.3;
}

/* 統計(再生数・視聴者数・日付)はチャンネル名に押し出されないよう独立させる。
   さらに項目ごとの要素に分けて、幅が足りないときは項目単位で折り返す
   — 省略記号で切ると数字や日付が読めなくなるため。 */
.home-meta-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 1px 9px;
  overflow: visible;
  white-space: normal;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.home-meta-stats > span {
  white-space: nowrap;
}

.home-loading {
  grid-row: 1 / -1;
  grid-column: span 2;
  min-height: 120px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 5px;
  color: var(--muted);
  padding: 0 16px;
  text-align: center;
  font-size: 0.86rem;
}

.home-loading.more {
  grid-column: span 1;
}

.home-loading.error {
  border-color: rgba(255, 79, 69, 0.46);
  color: #ffaaa5;
}

.viewer.pseudo-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: block;
  width: 100vw;
  height: 100vh;
  border: 0;
  padding: 0;
  background: #050608;
}

.viewer.pseudo-fullscreen:not(.controls-visible) {
  cursor: none;
}

.viewer.pseudo-fullscreen .topbar {
  display: none;
}

/* 映像はビューポート全面。コントロール類は下部グラデーションのオーバーレイで、
   タップ表示 → 3秒無操作でフェードアウトする。 */
.viewer.pseudo-fullscreen .stage {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 0;
  aspect-ratio: auto;
  border: 0;
  box-shadow: none;
}

.viewer.pseudo-fullscreen .player-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 30px 20px 14px;
  background: linear-gradient(to top, rgba(3, 4, 6, 0.94) 0%, rgba(3, 4, 6, 0.6) 62%, rgba(3, 4, 6, 0) 100%);
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 220ms ease, transform 220ms ease;
}

.viewer.pseudo-fullscreen.controls-visible .player-panel {
  opacity: 1;
  pointer-events: auto;
  transform: none;
}

.viewer.pseudo-fullscreen .controls {
  border: 0;
  background: transparent;
  padding: 0;
}

.viewer.pseudo-fullscreen .meter-row span {
  background: rgba(21, 26, 32, 0.72);
}

.explorer {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 22px 20px;
  overflow: hidden;
}

.topbar,
.result-head,
.meter-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand-lockup,
.explorer-head {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-lockup {
  min-width: 0;
}

.title-stack {
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  padding: 0;
  border: 1px solid rgba(255, 79, 69, 0.72);
  background: #251718;
  color: #ff8a83;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: border-color 140ms ease, background 140ms ease, color 140ms ease;
}

.brand-mark:hover {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.explorer-head {
  justify-content: space-between;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.explorer-head h2 {
  margin: 0;
  font-size: 1.25rem;
  letter-spacing: 0;
}

.live-dot {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: #a9f2d9;
  font-size: 0.72rem;
  font-weight: 700;
}

.live-dot::before {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent-2);
  box-shadow: 0 0 0 4px rgba(55, 214, 160, 0.12);
  content: "";
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
}

h1 {
  margin: 0;
  max-width: 58ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 1.5rem;
  letter-spacing: 0;
}

.status-pill,
.meter-row span,
.result-head span {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  background: #151a20;
  color: var(--muted);
  padding: 7px 10px;
  border-radius: 4px;
  font-size: 0.82rem;
}

.pager {
  display: grid;
  grid-template-columns: 1fr 54px 1fr;
  align-items: center;
  gap: 8px;
}

.live-button {
  min-height: 34px;
  border: 1px solid rgba(255, 79, 69, 0.62);
  border-radius: 4px;
  background: #251718;
  color: #ff8a83;
  padding: 0 11px;
  font-size: 0.76rem;
  font-weight: 800;
}

.live-button.active {
  background: var(--accent);
  color: #fff;
}

.pager button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--text);
}

.pager button:disabled {
  cursor: default;
  opacity: 0.45;
}

.pager span {
  color: var(--muted);
  text-align: center;
  font-size: 0.84rem;
}

/* エラー・警告時のみ表示する */
.status-pill {
  display: none;
}

.status-pill.warn {
  display: block;
  color: #ffe4a0;
  border-color: rgba(242, 201, 76, 0.55);
}

.stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  min-height: 260px;
  overflow: hidden;
  background: #030405;
  border: 1px solid #303844;
  box-shadow: var(--shadow);
}

.stage iframe,
.stage canvas,
.empty-state {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.stage iframe,
.stage canvas {
  display: none;
  border: 0;
}

.stage canvas {
  object-fit: contain;
  background: #000;
}

.stage.standard iframe,
.stage.lowLatency #streamCanvas,
.stage.frameStream #frameCanvas {
  display: block;
}

.stage.lowLatency.buffering #streamCanvas {
  visibility: hidden;
}

.stage.frameStream.frameGpu #frameCanvas {
  display: none;
}

.stage.frameStream.frameGpu #frameGpuCanvas {
  display: block;
}

.empty-state {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 10px;
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

.empty-index {
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 800;
}

.empty-state strong {
  color: var(--text);
  font-size: 1.15rem;
}

.stage.standard .empty-state,
.stage.lowLatency .empty-state,
.stage.frameStream .empty-state {
  display: none;
}

.seekbar {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) 52px;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 0.82rem;
}

.seekbar input {
  width: 100%;
  min-height: 28px;
  padding: 0;
  accent-color: var(--accent);
}

.seekbar span:last-child {
  text-align: right;
}

.controls {
  display: flex;
  align-items: center;
  /* 操作系は右寄せ。設定パネルは flex: 1 0 100% で1行を占めるため影響しない。
     560px 以下では下の @media で 1fr の4列グリッドになり、ここは効かない。 */
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  background: #0f1216;
}

.icon-button,
.search-row button {
  display: inline-grid;
  place-items: center;
  min-width: 50px;
  height: 42px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 700;
}

.icon-button.primary {
  background: var(--accent);
  border-color: var(--accent);
}

.icon-button.active {
  border-color: rgba(85, 184, 255, 0.56);
  background: #232b34;
}

/* 歯車で開閉する再生設定(再生モード / 画質 / FPS / 形式 / 描画)。
   .controls の最終要素として全幅で折り返し、閉じているときは占有しない。 */
.settings-panel {
  flex: 1 0 100%;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(128px, 1fr));
  gap: 10px;
  margin-top: 4px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: rgba(21, 26, 32, 0.72);
}

.settings-panel[hidden] {
  display: none;
}

#settingsButton .btn-icon {
  transition: transform 160ms ease;
}

#settingsButton.active .btn-icon {
  transform: rotate(60deg);
}

.icon-button:hover,
.search-row button:hover,
.pager button:hover:not(:disabled) {
  border-color: #566273;
  background: var(--panel-3);
}

.icon-button:focus-visible,
.search-row button:focus-visible,
.dropdown-toggle:focus-visible,
.dropdown-option:focus-visible,
.brand-mark:focus-visible,
input:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.select-wrap,
.volume-wrap,
.search,
.quick-url {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--muted);
  font-size: 0.82rem;
}

input {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #111318;
  color: var(--text);
  padding: 0 11px;
}

.dropdown {
  position: relative;
  min-width: 112px;
}

.dropdown-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 9px;
  width: 100%;
  min-height: 42px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 700;
}

.dropdown-toggle:hover {
  border-color: #566273;
  background: var(--panel-3);
}

.dropdown.open .dropdown-toggle {
  border-color: rgba(85, 184, 255, 0.56);
  background: #232b34;
}

.dropdown-current {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
}

.dropdown-caret {
  flex: 0 0 auto;
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid currentColor;
  opacity: 0.7;
  transition: transform 140ms ease;
}

.dropdown.open .dropdown-caret {
  transform: rotate(180deg);
}

.dropdown-menu[hidden] {
  display: none;
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 90;
  display: grid;
  gap: 2px;
  min-width: 100%;
  width: max-content;
  max-width: 260px;
  max-height: 288px;
  overflow: auto;
  padding: 6px;
  border: 1px solid #39424e;
  border-radius: 6px;
  background: #171c23;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.5);
}

.dropdown-menu.up {
  top: auto;
  bottom: calc(100% + 6px);
}

.dropdown-option {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: var(--text);
  font-size: 0.82rem;
  text-align: left;
  white-space: nowrap;
}

.dropdown-option:hover:not(:disabled) {
  border-color: #566273;
  background: var(--panel-3);
}

.dropdown-option.active {
  border-color: rgba(85, 184, 255, 0.56);
  background: #232b34;
}

.dropdown-option.active::after {
  content: "✓";
  margin-left: auto;
  padding-left: 10px;
  color: var(--info);
  font-weight: 800;
}

.dropdown-option:disabled {
  cursor: default;
  opacity: 0.42;
}

.dropdown.compact {
  min-width: 96px;
}

.dropdown.compact .dropdown-toggle {
  min-height: 34px;
  padding: 0 9px;
  font-size: 0.78rem;
}

.flag {
  display: inline-flex;
  flex: 0 0 auto;
  width: 21px;
  height: 14px;
  border-radius: 2px;
  overflow: hidden;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.16);
}

.flag svg {
  display: block;
  width: 100%;
  height: 100%;
}

.volume-wrap {
  min-width: 150px;
}

.volume-wrap input {
  padding: 0;
}

.meter-row {
  justify-content: flex-start;
  flex-wrap: wrap;
}

.search-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 42px;
  gap: 8px;
}

.search-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.notice {
  display: grid;
  gap: 5px;
  border-left: 3px solid var(--focus);
  background: #1c1a13;
  padding: 10px 12px;
  color: var(--muted);
  font-size: 0.84rem;
}

.notice strong {
  color: var(--text);
}

.results {
  display: grid;
  gap: 10px;
  overflow: auto;
  padding: 2px 4px;
  scrollbar-gutter: stable;
}

.result {
  position: relative;
  display: grid;
  grid-template-columns: 116px minmax(0, 1fr);
  gap: 10px;
  min-height: 76px;
  border: 1px solid var(--line);
  background: #15191f;
  border-radius: 4px;
  padding: 8px;
  text-align: left;
  color: var(--text);
  cursor: pointer;
  content-visibility: auto;
  contain-intrinsic-size: 100px;
}

.result:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.result:hover {
  border-color: rgba(255, 79, 69, 0.82);
  background: #1b1f25;
  transform: translateX(2px);
}

.result.selected {
  border-color: var(--accent);
  background: #1b1f25;
  transform: none;
  box-shadow: inset 3px 0 0 var(--accent);
}

.result {
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
}

.thumb {
  position: relative;
  overflow: hidden;
  aspect-ratio: 16 / 9;
  border-radius: 5px;
  background: #08090b;
}

.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.duration {
  position: absolute;
  right: 5px;
  bottom: 5px;
  padding: 2px 5px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.78);
  font-size: 0.72rem;
}

.meta {
  min-width: 0;
}

.duration.live {
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}

.meta {
  padding-right: 26px;
}

.meta strong,
.meta span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
}

.meta strong {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  line-height: 1.28;
}

.meta span {
  margin-top: 4px;
  color: var(--muted);
  white-space: nowrap;
  font-size: 0.8rem;
}

.meta .meta-stats {
  color: #aeb9c6;
}

.fav-button {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 1px solid rgba(255, 209, 102, 0.35);
  border-radius: 4px;
  background: rgba(10, 12, 15, 0.72);
  color: #cbd4de;
  font-size: 0.9rem;
  line-height: 1;
  cursor: pointer;
  transition: color 140ms ease, border-color 140ms ease, background 140ms ease;
}

.fav-button:hover {
  border-color: var(--focus);
  color: var(--focus);
}

.fav-button.active {
  border-color: var(--focus);
  background: rgba(255, 209, 102, 0.16);
  color: var(--focus);
}

.result .fav-button {
  position: absolute;
  top: 7px;
  right: 7px;
}

.home-thumb .fav-button {
  position: absolute;
  top: 6px;
  right: 6px;
}

.title-fav {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  font-size: 1.05rem;
  align-self: center;
}

@media (max-width: 980px) {
  .shell {
    grid-template-columns: 1fr;
    gap: 1px;
    padding: 0;
  }

  .explorer {
    max-height: none;
  }

  h1 {
    white-space: normal;
  }

  .stage {
    min-height: auto;
  }
}

@media (max-width: 560px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  /* 狭幅でも flex のまま。固定列のグリッドにするとボタン数(最初から再生は
     VODのみ表示)で末尾に空きセルが出て、右端に来るべき再生ボタンがずれる。
     音量を1行占有させ、残りのボタンを均等に伸ばして行を埋める。 */
  .controls > .volume-wrap {
    flex: 1 0 100%;
  }

  .controls > .icon-button {
    flex: 1 1 42px;
    min-width: 42px;
  }

  .controls > .settings-panel {
    grid-template-columns: repeat(auto-fit, minmax(112px, 1fr));
  }

  .search-options .select-wrap {
    grid-column: span 2;
  }

  .result {
    grid-template-columns: 96px minmax(0, 1fr);
  }

  .home-grid {
    grid-auto-columns: 74vw;
  }
}

/* ===== 読み込みオーバーレイ(buffering 中に表示、前動画の残像も覆う) ===== */
.stage-loading {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 24px;
  text-align: center;
  background:
    radial-gradient(560px 300px at 18% 0%, rgba(255, 79, 69, 0.16), transparent 62%),
    radial-gradient(520px 320px at 85% 100%, rgba(85, 184, 255, 0.1), transparent 60%),
    #05070a;
}

.stage.buffering .stage-loading {
  display: flex;
}

.loader-visual {
  position: relative;
  width: 92px;
  height: 92px;
}

.loader-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: conic-gradient(from 0deg, transparent 0 40deg, var(--accent) 150deg, #ff9a5b 210deg, transparent 320deg);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 7px), #000 calc(100% - 6px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 7px), #000 calc(100% - 6px));
  animation: loaderSpin 1.1s linear infinite;
}

.loader-core {
  position: absolute;
  inset: 14px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  background: rgba(18, 21, 26, 0.92);
  color: var(--accent);
  font-weight: 800;
  font-size: 0.88rem;
  letter-spacing: 0.08em;
  animation: loaderPulse 2.2s ease-in-out infinite;
}

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

@keyframes loaderPulse {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

.loader-copy {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 78%;
}

/* CM 待ち中はローディングを「読み込み」ではなく「CM」として見せる */
body.ad-break .loader-eyebrow::after {
  content: " — CM";
}

body.ad-break .loader-ring {
  background: conic-gradient(from 0deg, transparent 0 40deg, var(--info) 150deg, #8fd0ff 210deg, transparent 320deg);
}

body.ad-break .loader-core {
  color: var(--info);
}

body.ad-break .loader-bar span {
  background: linear-gradient(90deg, var(--info), #8fd0ff);
}

.loader-eyebrow {
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.34em;
  background: linear-gradient(90deg, #59626d 0%, #f7f8fa 50%, #59626d 100%);
  background-size: 200% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: loaderShimmer 1.8s linear infinite;
}

@keyframes loaderShimmer {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

#loadingTitle {
  font-size: 1.02rem;
  color: var(--text);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.loader-status {
  color: var(--muted);
  font-size: 0.8rem;
  min-height: 1.1em;
}

.loader-bar {
  width: min(320px, 70%);
  height: 3px;
  border-radius: 2px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.08);
}

.loader-bar span {
  display: block;
  height: 100%;
  width: 38%;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--accent), #ff9a5b);
  animation: loaderSlide 1.25s cubic-bezier(0.45, 0.05, 0.55, 0.95) infinite;
}

@keyframes loaderSlide {
  0% { transform: translateX(-110%); }
  100% { transform: translateX(290%); }
}

/* ===== 再生ページのチャンネル行 ===== */
.channel-row {
  margin: 2px 0 10px;
}

.channel-link {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  max-width: 100%;
  padding: 6px 14px 6px 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  text-align: left;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.15s ease;
}

.channel-link:hover {
  border-color: var(--accent);
  background: var(--panel-3);
  transform: translateY(-1px);
}

.channel-avatar {
  width: 34px;
  height: 34px;
  flex: none;
  border-radius: 50%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #2b333e, #1a1f26);
  color: var(--muted);
  font-weight: 800;
  font-size: 0.95rem;
}

.channel-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.channel-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.channel-name {
  font-weight: 700;
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.channel-sub {
  color: var(--muted);
  font-size: 0.74rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ===== チャンネル動画の展開ストリップ(プレイヤー下・横スクロール) ===== */
.channel-videos {
  margin: -4px 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 4px 12px 2px;
  animation: channelVideosOpen 0.18s ease;
}

@keyframes channelVideosOpen {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.channel-videos-inner {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.channel-strip {
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: auto;
  grid-auto-columns: clamp(168px, 19vw, 220px);
  gap: 10px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 2px 2px 12px;
  scroll-snap-type: x proximity;
  overscroll-behavior-x: contain;
}

.channel-strip::-webkit-scrollbar {
  height: 8px;
}

.channel-strip::-webkit-scrollbar-thumb {
  border-radius: 4px;
  background: #2e3843;
}

.channel-strip::-webkit-scrollbar-track {
  background: transparent;
}

.channel-strip .home-card {
  scroll-snap-align: start;
}

.channel-section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 14px 2px 8px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.18em;
}

.channel-section-title::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

/* ===== トップページの表示列数ピッカー ===== */
.cols-picker {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
}

.cols-label {
  color: var(--muted);
  font-size: 0.68rem;
  padding: 0 4px 0 6px;
}

.cols-picker button {
  width: 26px;
  height: 24px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
}

.cols-picker button:hover {
  color: var(--text);
}

.cols-picker button.active {
  background: var(--accent);
  color: #fff;
}

.home-grid {
  grid-template-rows: repeat(var(--home-rows, 3), auto);
}


/* ===== コントロールのアイコンボタン(記号文字を使わず質感のあるSVGで表現) ===== */
.icon-button {
  background-image: linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0) 62%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.09), 0 1px 2px rgba(0, 0, 0, 0.45);
  transition: transform 0.12s ease, border-color 0.15s ease, background-color 0.15s ease;
}

.icon-button:active {
  transform: translateY(1px);
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.5);
}

.icon-button.primary {
  background-image: linear-gradient(180deg, rgba(255, 255, 255, 0.24), rgba(255, 255, 255, 0) 70%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3), 0 2px 7px rgba(255, 79, 69, 0.32);
}

.btn-glyph {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
}

.btn-icon {
  display: block;
  width: 22px;
  height: 22px;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.55));
}

.icon-button.primary .btn-icon {
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.3));
}

/* チャンネル行の開閉シェブロン(車載 Chromium で化ける「▴」の置き換え) */
.channel-chevron {
  width: 18px;
  height: 18px;
  flex: none;
  margin-left: 2px;
  color: var(--muted);
  transition: transform 0.18s ease, color 0.15s ease;
}

.channel-link:hover .channel-chevron {
  color: var(--text);
}

.channel-link[aria-expanded="true"] .channel-chevron {
  transform: rotate(180deg);
  color: var(--accent);
}

/* チャンネル行はコントロールの下に置く */
.channel-row {
  margin: 10px 0 0;
}

.channel-videos {
  margin: 8px 0 0;
}
