/* ===========================================
 * Responsive - レスポンシブ対応
 * タブレット・スマホでのレイアウト調整
 * 重複削除・最新版のみ統合
 * =========================================== */

/* ===========================================
 * タブレット対応（1024px以下）
 * =========================================== */
@media (max-width: 1024px) {
  /* サイドバーをモーダル風に */
  .sidebar {
    position: fixed;
    top: 0;
    left: -100%;
    width: 320px;
    max-width: 85vw;
    height: 100vh;
    background: white;
    z-index: 999;
    overflow-y: auto;
    transition: left 0.3s ease-in-out;
    box-shadow: 2px 0 12px rgba(0, 0, 0, 0.15);
  }
  
  .sidebar.active {
    left: 0;
  }
  
  .sidebar-mobile-header {
    display: flex;
  }
  
  .main-container {
    flex-direction: column;
  }
  
  .sidebar-section {
    margin-bottom: 12px;
  }
  
  .category-list {
    max-height: none;
  }
  
  .header-nav {
    display: none;
  }
}

/* ===========================================
 * スマホ対応（768px以下）
 * =========================================== */
@media (max-width: 768px) {
  /* ヘッダー調整 */
  .site-header {
    position: sticky;
    top: 0;
    z-index: 1001;
  }
  
  .header-top {
    padding: 6px 12px;
  }
  
  .site-logo a {
    font-size: 18px;
  }
  
  /* ヘッダー中央寄せ（スマホ） */
  .site-header .header-inner {
    padding: 0.3rem 0.5rem;
  }
  
  .site-header .page-title {
    font-size: 0.85rem;
    padding-right: 50px;
  }
  
  /* ページタイトル内の要素調整 */
  .page-title .title-number {
    font-size: 1.05em;
  }
  
  .page-title .title-type {
    font-size: 0.9em;
    margin: 0 0.3rem;
  }
  
  .page-title .title-period {
    font-size: 0.85em;
  }
  
  /* TOPページのヘッダー調整（スマホ） */
  body.page-top .header-inner {
    padding: 5px 5px;
    position: relative;
    justify-content: center;
  }
  
  body.page-top .header-spacer {
    display: none;
  }
  
  body.page-top .header-logo img {
    max-width: 75%;
    width: 75%;
  }
  
  body.page-top .hamburger-btn {
    position: absolute;
    top: 15px;
    right: 5px;
  }
  
  body.page-top .top-hero-logo {
    display: none;
  }
  
  /* メインコンテナ */
  .main-container {
    padding: 8px;
    gap: 8px;
  }
  
  /* サイドバー - スマホでは全画面モーダル */
  .sidebar {
    width: 100%;
    max-width: 100vw;
    z-index: 1002; /* ヘッダー（z-index: 1001）よりも上に表示 */
  }
  
  /* サイドバーオーバーレイもヘッダーより上 */
  #sidebarOverlay,
  .sidebar-overlay {
    z-index: 1001 !important;
  }
  
  /* カテゴリリストの高さ制限 */
  .sidebar-category-section .category-list {
    max-height: 200px;
  }
  
  .sidebar-pagination-section {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid #ddd;
  }
  
  .mobile-pagination {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
  }
  
  /* ランキングヘッダー */
  .ranking-header {
    padding: 10px 12px;
    flex-direction: column;
    align-items: flex-start;
  }
  
  .ranking-header h1 {
    font-size: 16px;
  }
  
  /* 検索セクション */
  .search-section {
    padding: 10px 12px;
  }
  
  .search-input {
    min-width: 150px;
  }
  
  /* 年代ナビ */
  .year-row a, 
  .year-row span {
    padding: 4px 8px;
    font-size: 12px;
  }
  
  .num-popup-content {
    min-width: 280px;
    left: -50px;
  }
  
  /* ページネーション - 非表示 */
  .pagination {
    display: none;
  }
  
  /* ランキング上部ナビ調整 */
  .ranking-top-nav {
    gap: 0.5rem;
    padding: 0.5rem;
    margin-bottom: 0.5rem;
  }
  
  /* メタデータのスペーシング削減 */
  .ranking-meta {
    margin: 0.5rem 0 !important;
    padding: 0.5rem !important;
    font-size: 0.8rem !important;
  }
  
  .ranking-meta summary {
    font-size: 0.8rem !important;
  }
  
  .ranking-formula-text {
    margin-top: 0.5rem !important;
    font-size: 0.75rem !important;
  }
  
  .ranking-formula-text p {
    margin: 0.25rem 0 !important;
  }
  
  .ranking-main-thumb img {
    width: 96px;
    height: 54px;
    object-fit: cover;
  }
  
  .nav-btn {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    min-width: 60px;
  }
  
  /* ランキングアイテム - スマホレイアウト */
  .rank-item {
    display: grid;
    grid-template-areas:
      "thumb title title"
      "thumb meta-date meta-uploader"
      "category button rank";
    grid-template-columns: 120px auto 1fr;
    grid-template-rows: auto auto auto;
    gap: 0.2rem;
    padding: 0.3rem;
    background: white;
    border-radius: 8px;
    margin-bottom: 0.3rem;
  }
  
  /* サムネイル - 左側、2行分 */
  .rank-item .rank-thumb {
    grid-area: thumb;
    width: 120px;
    height: 68px;
    flex-shrink: 0;
  }
  
  .rank-item .rank-thumb a {
    display: block;
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #000;
    border-radius: 4px;
  }
  
  .rank-item .rank-thumb a img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
  }
  
  .rank-item .rank-thumb .thumb-placeholder {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f0f0f0;
    color: #999;
    font-size: 0.65rem;
  }
  
  .rank-item .rank-thumb .thumb-duration {
    position: absolute;
    bottom: 2px;
    right: 2px;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 2px 4px;
    border-radius: 2px;
    font-size: 0.6rem;
    z-index: 2;
  }
  
  /* タイトル - サムネの右、2行まで */
  .rank-item .rank-title {
    grid-area: title;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.4;
    margin: 0;
  }
  
  .rank-item .rank-title a {
    font-size: 0.875rem;
    font-weight: 600;
    color: #007bff;
    text-decoration: none;
    display: inline;
  }
  
  .rank-item .rank-title .external-icon {
    font-size: 0.75rem;
    margin-left: 2px;
    color: #007bff;
  }
  
  /* 投稿日 - タイトルの下左 */
  .rank-item .rank-meta-date {
    grid-area: meta-date;
    font-size: 0.7rem;
    color: #666;
    display: flex;
    align-items: center;
  }
  
  /* 投稿者 - 投稿日の右 */
  .rank-item .rank-meta-uploader {
    grid-area: meta-uploader;
    display: flex;
    align-items: center;
    gap: 0.3rem;
    justify-content: flex-end;
  }
  
  .rank-item .rank-meta-uploader .uploader-icon-placeholder {
    width: 15px;
    height: 15px;
    border-radius: 50%;
    background: #f0f0f0;
    flex-shrink: 0;
  }
  
  .rank-item .rank-meta-uploader .uploader-name {
    font-size: 0.7rem;
    color: #333;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 120px;
  }
  
  /* カテゴリ - サムネの下左 */
  .rank-item .rank-category-row {
    grid-area: category;
    display: flex;
    align-items: center;
  }
  
  .rank-item .rank-category-row .category-name {
    font-size: 0.875rem;
    color: #007bff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-decoration: none;
    cursor: pointer;
  }
  
  .rank-item .rank-category-row .category-name:hover {
    text-decoration: underline;
  }
  
  /* 順位 - サムネの下右 */
  .rank-item .rank-badge-row {
    grid-area: rank;
    display: flex;
    align-items: center;
    justify-content: flex-end;
  }
  
  .rank-item .rank-badge-row .rank-badge {
    font-size: 0.875rem;
    font-weight: 600;
    color: #000;
    white-space: nowrap;
  }
  
  /* PC版用の要素を非表示 */
  .rank-item .rank-left,
  .rank-item .rank-right,
  .rank-item .rank-title-pc {
    display: none;
  }
  
  /* メイン情報エリア */
  .rank-item .rank-main {
    display: contents; /* グリッドの子要素を親グリッドに直接配置 */
  }
  
  /* 旧投稿者情報 - 非表示 */
  .rank-item .rank-mobile-info {
    display: none;
  }
  
  /* タイトル - 下段に配置 */
  .rank-item .rank-title {
    grid-area: title;
    margin: 0;
  }
  
  .rank-item .rank-title a {
    font-size: 0.9rem;
    font-weight: bold;
    color: #007bff;
    text-decoration: none;
    line-height: 1.4;
    display: inline;
  }
  
  /* PC用投稿者エリア - スマホでは非表示 */
  .rank-item .rank-right {
    display: none;
  }
  
  /* 統計情報 */
  .rank-item .rank-stats {
    clear: both;
    margin-top: 0.4rem;
  }
  
  /* スマホ版では前回順位・総合ポイントを非表示（詳細内のみ表示） */
  .rank-item .rank-stats .stat-left {
    display: none;
  }
  
  /* スマホ版では統計情報も非表示（詳細内のみ表示） */
  .rank-item .rank-stats .stats-grid {
    display: none;
  }
  
  /* スマホ版では年代選択を非表示 */
  .year-selector {
    display: none !important;
  }
  
  /* スマホ用：詳細折り畳みボタン */
  .mobile-details-toggle {
    grid-area: button;
    display: flex !important;
    align-items: center;
    justify-content: center;
    gap: 0.2rem;
    width: auto !important;
    max-width: none !important;
    min-width: auto !important;
    box-sizing: border-box !important;
    padding: 0.2rem 0.4rem;
    margin: 0;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.2s;
    font-size: 0.65rem;
    color: #495057;
    white-space: nowrap;
  }
  
  .mobile-details-toggle:hover {
    background: #e9ecef;
  }
  
  .mobile-details-toggle .toggle-icon {
    transition: transform 0.3s;
    font-size: 0.7rem;
  }
  
  .rank-item.is-open .mobile-details-toggle .toggle-icon {
    transform: rotate(180deg);
  }
  
  /* スマホ用：詳細 */
  .rank-item-details {
    grid-column: 1 / -1; /* グリッドの全幅に配置 */
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    margin: 0;
    padding: 0.5rem;
    background: #f8f9fa;
    border-radius: 6px;
    font-size: 0.75rem;
  }
  
  .rank-item-details .detail-row {
    display: flex;
    justify-content: space-between;
    padding: 0.25rem 0;
    border-bottom: 1px solid #e9ecef;
  }
  
  .rank-item-details .detail-row:last-child {
    border-bottom: none;
  }
  
  /* 詳細ボタン（スマホ版） */
  .rank-item-details .detail-action {
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid #e9ecef;
    text-align: center;
  }
  
  .rank-item-details .mobile-detail-btn-link {
    display: block;
    text-decoration: none;
  }
  
  .rank-item-details .detail-btn {
    display: block;
    width: 100%;
    padding: 0.5rem;
    font-size: 0.85rem;
  }
  
  /* PC版の詳細ボタンをスマホでは非表示 */
  .rank-right .detail-btn-link {
    display: none;
  }
  
  .rank-item-details .detail-label {
    color: #6c757d;
    font-weight: 500;
  }
  
  .rank-item-details .detail-value {
    color: #212529;
    text-align: right;
  }
  
  .rank-item-details .prev-rank-mobile.up {
    color: #28a745;
    font-weight: 600;
  }
  
  .rank-item-details .prev-rank-mobile.down {
    color: #dc3545;
    font-weight: 600;
  }
  
  .rank-item-details .prev-rank-mobile.new {
    color: #ff3333;
    font-weight: 600;
  }
  
  /* ページトップボタン */
  .page-top-btn {
    position: fixed;
    bottom: 80px;
    right: 20px;
    width: 50px;
    height: 50px;
    background: rgba(0, 123, 255, 0.9);
    color: #fff;
    border: none;
    border-radius: 50%;
    font-size: 1.5rem;
    cursor: pointer;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s, background 0.2s;
    z-index: 99;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  }
  
  .page-top-btn.visible {
    opacity: 1;
    pointer-events: auto;
  }
  
  .page-top-btn:hover {
    background: rgba(0, 123, 255, 1);
  }
  
  /* ページ設定ボタン（スマホ専用） */
  .mobile-filter-btn {
    display: flex !important;
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 50px;
    padding: 12px 20px;
    font-size: 14px;
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
    cursor: pointer;
    align-items: center;
    gap: 8px;
    transition: all 0.3s;
  }
  
  .mobile-filter-btn:hover {
    background: #5568d3;
    box-shadow: 0 6px 16px rgba(102, 126, 234, 0.5);
  }
  
  .mobile-filter-btn:active {
    transform: scale(0.95);
  }
  
  /* TOPページ調整 */
  .top-page-title h1 {
    font-size: 24px;
  }
  
  .top-twitter-and-selector {
    flex-direction: column;
  }
  
  .ranking-cards {
    grid-template-columns: 1fr;
  }
  
  .card-content {
    padding: 15px;
  }
}

/* ===========================================
 * 極小画面対応（480px以下）
 * =========================================== */
@media (max-width: 480px) {
  .main-container {
    padding: 8px;
  }
  
  .rank-item {
    padding: 6px;
    grid-template-columns: 120px auto 1fr;
  }
  
  .rank-item .rank-number {
    font-size: 1.1rem;
  }
  
  .rank-item .rank-thumb {
    width: 120px;
    height: 68px;
  }
  
  .rank-item .rank-title a {
    font-size: 0.8rem;
  }
  
  .site-logo a {
    font-size: 16px;
  }
}

/* ===========================================
 * PC専用スタイル（769px以上）
 * =========================================== */
@media (min-width: 769px) {
  /* ランキングアイテムのレイアウトをPC用に戻す */
  .rank-item {
    display: flex !important;
    flex-direction: row !important;
    align-items: flex-start !important;
    padding: 12px 16px !important;
    gap: 12px !important;
  }
  
  /* 順位エリアをPC用に戻す */
  .rank-item .rank-left {
    display: block !important;
    width: 70px !important;
    text-align: center !important;
    margin-bottom: 0 !important;
    padding-bottom: 0 !important;
    border-bottom: none !important;
  }
  
  .rank-item .rank-left .category-name-pc {
    display: block !important;
    font-size: 11px !important;
    color: var(--text-muted) !important;
    margin-top: 2px !important;
  }
  
  .rank-item .rank-left .category-rank-pc {
    display: block !important;
    font-size: 11px !important;
    color: var(--text-muted) !important;
    margin-top: 1px !important;
  }
  
  /* スマホ用投稿者情報を非表示 */
  .rank-mobile-info {
    display: none !important;
  }
  
  /* スマホ版の新要素を非表示 */
  .rank-item .rank-title,
  .rank-item .rank-meta-date,
  .rank-item .rank-meta-uploader,
  .rank-item .rank-category-row,
  .rank-item .rank-badge-row,
  .rank-item .mobile-details-toggle {
    display: none !important;
  }
  
  /* PC版のタイトルを表示 */
  .rank-item .rank-title-pc {
    display: block !important;
  }
  
  /* PC用サムネイルを表示（スマホのfloat設定を解除） */
  .rank-item .rank-thumb {
    display: block !important;
    float: none !important;
    width: 130px !important;
    height: auto !important;
    margin-right: 0 !important;
    margin-bottom: 0 !important;
  }
  
  .rank-item .rank-thumb a {
    display: block !important;
    position: relative !important;
    width: auto !important;
    height: auto !important;
    background: transparent !important;
  }
  
  .rank-item .rank-thumb a img {
    position: static !important;
    width: 130px !important;
    height: 73px !important;
  }
  
  .rank-item .rank-thumb .thumb-placeholder {
    position: static !important;
    width: 130px !important;
    height: 73px !important;
  }
  
  /* メイン情報エリアをPC用に戻す */
  .rank-item .rank-main {
    flex: 1 !important;
    min-width: 0 !important;
    overflow: visible !important;
  }
  
  /* 統計情報をPC用に戻す */
  .rank-item .rank-stats {
    display: flex !important;
    align-items: flex-start !important;
    gap: 16px !important;
    flex-wrap: wrap !important;
    clear: none !important;
    margin-top: 0 !important;
  }
  
  /* PC用投稿者エリアを表示 */
  .rank-item .rank-right {
    display: block !important;
    width: 140px !important;
    text-align: right !important;
  }
  
  .rank-item .rank-right .uploader-info {
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
    justify-content: flex-end !important;
  }
  
  .rank-item .rank-right .uploader-name {
    display: block !important;
    font-size: 12px !important;
    color: var(--text-color) !important;
    max-width: 90px !important;
  }
  
  .rank-item .rank-right .upload-date {
    display: block !important;
    font-size: 11px !important;
    color: var(--text-muted) !important;
  }
  
  /* PC版では詳細ボタンを非表示 */
  .mobile-details-toggle {
    display: none !important;
  }
  
  .rank-item-details {
    display: none !important;
  }
  
  /* PC版ではスマホ版の詳細ボタンを非表示 */
  .rank-item-details .mobile-detail-btn-link {
    display: none !important;
  }
  
  /* PC版では右側の詳細ボタンを表示 */
  .rank-right .detail-btn-link {
    display: block !important;
  }
  
  /* PC版ではサイドバーの表示設定とページ移動を非表示 */
  .sidebar-view-mode-section,
  .sidebar-pagination-section {
    display: none !important;
  }
  
  /* サイドバーを通常表示 */
  .sidebar-mobile-header {
    display: none;
  }
  
  /* フィルターボタンを非表示 */
  .mobile-filter-btn {
    display: none;
  }
}