/* 03-stats.css — 統計のページ
 *
 * style.css を分けたもの。元は1本の7,600行だった。
 * ⚠️ 読み込む順番を変えないこと。番号の順に重ねることで、
 *    分ける前とまったく同じ見た目になる。あとの番号が勝つ。
 * ⚠️ 新しい指定をここの先頭に足さないこと。
 *    打ち消し合っている指定があるので、置き場所で結果が変わる。
 */
/* ==============================
   Stats Page Styles
   ============================== */

/* --- Stats TOC (Table of Contents) --- */
.stats-toc {
    display: flex;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 30px;
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--bg-color);
    padding: 12px 0;
    border-bottom: 1px solid var(--border-color);
}

.stats-toc-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 20px;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    text-decoration: none;
    font-size: 0.8rem;
    font-weight: 700;
    transition: all 0.2s;
    white-space: nowrap;
}

.stats-toc-item:hover {
    border-color: var(--main-accent);
    color: var(--main-accent);
    background: rgba(0, 229, 255, 0.08);
}

.stats-toc-item svg {
    opacity: 0.7;
    flex-shrink: 0;
}

.stats-toc-item:hover svg {
    opacity: 1;
}

#dashboard-section,
#overlap-section,
#calendar-section,
#artist-ranking-section {
    scroll-margin-top: 60px;
}

@media (max-width: 768px) {
    .stats-toc {
        gap: 6px;
        padding: 10px 0;
    }

    .stats-toc-item {
        padding: 6px 12px;
        font-size: 0.7rem;
    }

    .stats-toc-item svg {
        width: 14px;
        height: 14px;
    }

    #dashboard-section,
    #overlap-section,
    #calendar-section,
    #artist-ranking-section {
        scroll-margin-top: 50px;
    }

    .ranking-bar-track {
        display: none;
    }
}

.stats-subtitle {
    font-family: 'Montserrat', 'Noto Sans JP', sans-serif;
    font-weight: 700;
    font-size: 1.1rem;
    margin-bottom: 15px;
    color: var(--main-accent);
}

.stats-controls {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.stats-select {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 8px 12px;
    color: var(--text-color);
    font-size: 0.9rem;
    outline: none;
    cursor: pointer;
    min-width: 150px;
}

.stats-select:focus {
    border-color: var(--main-accent);
}

/* --- Member Bar Chart (Feature 14) --- */
.member-bar-chart {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.stat-bar-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.stat-member-name {
    width: 100px;
    font-weight: 700;
    font-size: 0.85rem;
    text-decoration: none;
    white-space: nowrap;
    flex-shrink: 0;
    transition: opacity 0.2s;
}

.stat-member-name:hover {
    opacity: 0.7;
}

.stat-bar-track {
    flex: 1;
    height: 20px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 4px;
    overflow: hidden;
}

[data-theme="light"] .stat-bar-track {
    background: rgba(0, 0, 0, 0.06);
}

.stat-bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.8s ease;
    opacity: 0.85;
}

.stat-bar-count {
    width: 40px;
    text-align: right;
    font-weight: 700;
    font-size: 0.9rem;
    flex-shrink: 0;
}

/* --- Monthly Activity Chart --- */
.monthly-chart-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.monthly-chart-container {
    display: flex;
    align-items: flex-end;
    gap: 2px;
    min-height: 180px;
    padding-top: 10px;
    min-width: max-content;
}

.monthly-bar {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 32px;
    flex-shrink: 0;
}

.bar-fill-wrapper {
    width: 100%;
    height: 120px;
    display: flex;
    align-items: flex-end;
}

.bar-fill {
    width: 100%;
    border-radius: 3px 3px 0 0;
    transition: height 0.5s ease;
    min-height: 1px;
}

.bar-count {
    font-size: 0.65rem;
    margin-top: 2px;
    opacity: 0.7;
    height: 14px;
}

.bar-label {
    font-size: 0.6rem;
    opacity: 0.5;
    white-space: pre-line;
    text-align: center;
    line-height: 1.2;
    height: 28px;
}

/* --- Member Stats Grid (Cards) --- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-top: 20px;
}

.member-stat-card {
    text-decoration: none;
    color: var(--text-color);
    text-align: center;
    padding: 20px 16px;
    border-top: 3px solid var(--card-accent);
    cursor: pointer;
    transition: transform 0.3s, border-color 0.3s;
}

.member-stat-card:hover {
    transform: translateY(-3px);
    border-color: var(--card-accent);
}

.member-stat-name {
    font-weight: 700;
    font-size: 0.95rem;
    margin-bottom: 8px;
}

.member-stat-total {
    font-family: 'Montserrat', sans-serif;
    font-size: 2rem;
    font-weight: 900;
    line-height: 1;
    margin-bottom: 8px;
}

.member-stat-unit {
    font-size: 0.7rem;
    font-weight: 400;
    margin-left: 4px;
    opacity: 0.6;
}

.member-stat-artists {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-bottom: 8px;
    min-height: 48px;
}

.top-artist-item {
    font-size: 0.75rem;
    opacity: 0.7;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.member-stat-date {
    font-size: 0.7rem;
    opacity: 0.5;
}

/* --- Overlap Map (Feature 9) --- */
.overlap-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(280px, 100%), 1fr));
    gap: 12px;
    overflow: hidden;
}

.overlap-card {
    padding: 16px;
    cursor: pointer;
    transition: all 0.3s;
    overflow: hidden;
    max-width: 100%;
    box-sizing: border-box;
}

.overlap-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.overlap-title {
    font-weight: 700;
    font-size: 0.95rem;
}

.overlap-member-count {
    font-size: 0.8rem;
    color: var(--main-accent);
    font-weight: 700;
}

.overlap-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 4px;
}

.member-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 700;
    color: #000;
    white-space: nowrap;
}

.member-badge.small {
    padding: 1px 6px;
    font-size: 0.65rem;
}

.overlap-versions {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.overlap-card.expanded .overlap-versions {
    max-height: 500px;
}

.overlap-version {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
    border-top: 1px solid var(--border-color);
    font-size: 0.8rem;
    flex-wrap: wrap;
}

.overlap-date {
    opacity: 0.6;
    font-size: 0.75rem;
    flex-shrink: 0;
}

.overlap-singer-full {
    opacity: 0.5;
    font-size: 0.7rem;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.overlap-play-link {
    color: var(--main-accent);
    text-decoration: none;
    font-weight: 700;
    font-size: 0.75rem;
    flex-shrink: 0;
}

.overlap-play-link:hover {
    text-decoration: underline;
}

/* --- Heatmap Calendar (Feature 12) --- */
.heatmap-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 10px;
}

.heatmap-outer {
    display: flex;
    gap: 4px;
    min-width: max-content;
}

.heatmap-day-labels {
    display: grid;
    grid-template-rows: repeat(7, 13px);
    gap: 2px;
    font-size: 0.6rem;
    opacity: 0.5;
    text-align: right;
    padding-right: 4px;
}

.heatmap-day-labels span {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    height: 13px;
}

.heatmap-month-labels {
    position: relative;
    height: 16px;
    font-size: 0.65rem;
    opacity: 0.5;
    margin-bottom: 2px;
    margin-left: 28px;
    min-width: max-content;
}

.heatmap-month-labels span {
    white-space: nowrap;
    position: absolute;
}

.heatmap-container {
    display: grid;
    grid-template-rows: repeat(7, 13px);
    grid-auto-flow: column;
    grid-auto-columns: 13px;
    gap: 2px;
}

.heatmap-cell {
    width: 13px;
    height: 13px;
    border-radius: 2px;
    cursor: pointer;
    transition: outline 0.1s;
}

.heatmap-cell:hover {
    outline: 2px solid var(--text-color);
    outline-offset: -1px;
}

.heatmap-cell.level-out {
    background: transparent;
    cursor: default;
}

.heatmap-cell.level-out:hover {
    outline: none;
}

.heatmap-cell.level-0 {
    background: rgba(255, 255, 255, 0.06);
}

.heatmap-cell.level-1 {
    background: rgba(0, 229, 255, 0.2);
}

.heatmap-cell.level-2 {
    background: rgba(0, 229, 255, 0.4);
}

.heatmap-cell.level-3 {
    background: rgba(0, 229, 255, 0.65);
}

.heatmap-cell.level-4 {
    background: rgba(0, 229, 255, 0.9);
}

[data-theme="light"] .heatmap-cell.level-0 {
    background: rgba(0, 0, 0, 0.06);
}

[data-theme="light"] .heatmap-cell.level-1 {
    background: rgba(0, 118, 163, 0.2);
}

[data-theme="light"] .heatmap-cell.level-2 {
    background: rgba(0, 118, 163, 0.4);
}

[data-theme="light"] .heatmap-cell.level-3 {
    background: rgba(0, 118, 163, 0.65);
}

[data-theme="light"] .heatmap-cell.level-4 {
    background: rgba(0, 118, 163, 0.9);
}

.heatmap-legend {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    font-size: 0.7rem;
    opacity: 0.6;
    margin-top: 8px;
}

.heatmap-legend .heatmap-cell {
    width: 13px;
    height: 13px;
    cursor: default;
}

.heatmap-legend .heatmap-cell:hover {
    outline: none;
}

/* --- Stats Hub Cards --- */
.stats-hub-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 10px;
    max-width: 900px;
    margin: 0 auto;
}

/* PC5列では不要 */
.stats-hub-grid .stats-hub-card:last-child {
    grid-column: auto;
}

.stats-hub-card {
    text-decoration: none;
    color: var(--text-color);
    text-align: center;
    padding: 16px 10px;
    cursor: pointer;
    transition: transform 0.3s, border-color 0.3s;
    border-top: 2px solid var(--main-accent);
}

.stats-hub-card:hover {
    transform: translateY(-3px);
}

.stats-hub-icon {
    margin-bottom: 6px;
    color: var(--main-accent);
}

.stats-hub-icon svg {
    width: 24px;
    height: 24px;
}

.stats-hub-title {
    font-family: 'Montserrat', 'Noto Sans JP', sans-serif;
    font-weight: 700;
    font-size: 0.8rem;
    margin-bottom: 4px;
}

.stats-hub-desc {
    font-size: 0.7rem;
    opacity: 0.6;
    line-height: 1.4;
}

@media (max-width: 768px) {
    .stats-hub-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }

    /* モバイル: 5番目のカードを1カラム幅で中央に */
    .stats-hub-grid .stats-hub-card:last-child {
        grid-column: 1 / 2;
        max-width: none;
        justify-self: stretch;
    }

    .stats-hub-card {
        padding: 12px 8px;
    }
}

/* --- Monthly Calendar Grid --- */
/* カレンダーナビゲーション */
.cal-nav {
    display: flex;
    align-items: center;
    gap: 12px;
}

.cal-nav-btn {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    width: 36px;
    height: 36px;
    border-radius: 8px;
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, border-color 0.2s;
}

.cal-nav-btn:hover {
    background: var(--main-accent);
    color: #000;
    border-color: var(--main-accent);
}

.cal-nav-label {
    font-family: 'Montserrat', 'Noto Sans JP', sans-serif;
    font-weight: 700;
    font-size: 1rem;
    min-width: 120px;
    text-align: center;
}

.calendar-single-month {
    max-width: 500px;
    margin: 20px auto 0;
}

.calendar-single-month .cal-month-card {
    padding: 20px;
}

.calendar-single-month .cal-day {
    min-height: 44px;
}

.calendar-single-month .cal-day-num {
    font-size: 0.85rem;
}

.calendar-single-month .cal-day-count {
    font-size: 0.65rem;
}

.calendar-monthly-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-top: 20px;
}

.cal-month-card {
    padding: 16px;
}

.cal-month-card:hover {
    transform: none;
}

.cal-month-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.cal-month-name {
    font-family: 'Montserrat', 'Noto Sans JP', sans-serif;
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--main-accent);
}

.cal-month-total {
    font-size: 0.75rem;
    font-weight: 700;
    opacity: 0.6;
}

.cal-day-labels {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    text-align: center;
    font-size: 0.6rem;
    opacity: 0.4;
    margin-bottom: 4px;
    font-weight: 700;
}

.cal-days-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
}

.cal-day {
    aspect-ratio: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    cursor: pointer;
    position: relative;
    transition: outline 0.1s;
    min-height: 32px;
}

.cal-day.empty {
    cursor: default;
}

.cal-day:not(.empty):hover {
    outline: 2px solid var(--main-accent);
    outline-offset: -1px;
}

.cal-day-num {
    font-size: 0.7rem;
    font-weight: 600;
    line-height: 1;
}

.cal-day-count {
    font-size: 0.55rem;
    font-weight: 700;
    color: var(--main-accent);
    line-height: 1;
    margin-top: 1px;
}

.cal-day.level-0 {
    background: rgba(255, 255, 255, 0.03);
}

.cal-day.level-1 {
    background: rgba(0, 229, 255, 0.12);
}

.cal-day.level-2 {
    background: rgba(0, 229, 255, 0.25);
}

.cal-day.level-3 {
    background: rgba(0, 229, 255, 0.4);
}

.cal-day.level-4 {
    background: rgba(0, 229, 255, 0.6);
}

[data-theme="light"] .cal-day.level-0 {
    background: rgba(0, 0, 0, 0.03);
}

[data-theme="light"] .cal-day.level-1 {
    background: rgba(0, 118, 163, 0.1);
}

[data-theme="light"] .cal-day.level-2 {
    background: rgba(0, 118, 163, 0.2);
}

[data-theme="light"] .cal-day.level-3 {
    background: rgba(0, 118, 163, 0.35);
}

[data-theme="light"] .cal-day.level-4 {
    background: rgba(0, 118, 163, 0.5);
}

@media (max-width: 1024px) {
    .calendar-monthly-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .calendar-monthly-grid {
        grid-template-columns: 1fr;
    }

    .cal-month-card {
        padding: 12px;
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
        background: rgba(26, 28, 35, 0.95) !important;
        box-shadow: none !important;
    }

    [data-theme="light"] .cal-month-card {
        background: rgba(255, 255, 255, 0.95) !important;
    }
}

/* --- Overlap Member Link --- */
.overlap-member-link {
    text-decoration: none;
    color: #000;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.2s;
}

.overlap-member-link:hover {
    opacity: 0.8;
    transform: scale(1.05);
}

.calendar-song-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-color);
    flex-wrap: wrap;
}

.calendar-song-item:last-child {
    border-bottom: none;
}

.calendar-song-meta {
    font-size: 0.8rem;
    opacity: 0.6;
}

.calendar-stream-group {
    border-bottom: 1px solid var(--border-color);
    padding: 8px 0;
}

.calendar-stream-group:last-child {
    border-bottom: none;
}

.calendar-stream-header {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 4px;
}

.calendar-stream-songs {
    padding-left: 16px;
    border-left: 2px solid var(--main-accent);
    margin-left: 4px;
}

.calendar-stream-song-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 3px 0;
    flex-wrap: wrap;
}

.calendar-stream-song-name {
    font-size: 0.85rem;
}

/* --- Artist Ranking (Feature 13) --- */
.ranking-container {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.ranking-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 0;
}

.ranking-position {
    width: 28px;
    text-align: right;
    font-family: 'Montserrat', sans-serif;
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--main-accent);
    flex-shrink: 0;
}

.ranking-name {
    width: 150px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-color);
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex-shrink: 0;
}

.ranking-name:hover {
    color: var(--main-accent);
}

.ranking-info {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.ranking-info .ranking-name {
    width: 100%;
    display: block;
    white-space: normal;
}

.ranking-artist-sub {
    display: block;
    font-size: 0.7rem;
    opacity: 0.5;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 1px;
}

.ranking-song-info {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.ranking-song-info .ranking-name {
    width: auto;
    flex-shrink: 0;
}

.ranking-song-info .ranking-artist-sub {
    flex: 1;
    min-width: 0;
}

.ranking-singers {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    margin-top: 4px;
}

.ranking-singers .member-badge {
    font-size: 0.6rem;
    padding: 1px 5px;
    border-radius: 3px;
}

.song-ranking-item {
    padding: 8px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.song-ranking-main {
    display: flex;
    align-items: center;
    gap: 10px;
}

.song-ranking-main .ranking-name {
    width: 160px;
    flex-shrink: 0;
}

.song-ranking-detail {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: 38px;
    margin-top: 4px;
    flex-wrap: wrap;
}

.song-ranking-detail .ranking-artist-sub {
    margin-top: 0;
    flex-shrink: 0;
}

[data-theme="light"] .song-ranking-item {
    border-bottom-color: rgba(0, 0, 0, 0.08);
}

.ranking-bar-track {
    flex: 1;
    height: 6px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 3px;
    overflow: hidden;
}

[data-theme="light"] .ranking-bar-track {
    background: rgba(0, 0, 0, 0.06);
}

.ranking-bar-fill {
    height: 100%;
    background: var(--main-accent);
    border-radius: 3px;
    opacity: 0.35;
    transition: width 0.5s ease;
}

[data-theme="light"] .ranking-bar-fill {
    opacity: 0.7;
    background: #00838f;
}

.ranking-count {
    width: 45px;
    text-align: right;
    font-size: 0.8rem;
    font-weight: 700;
    flex-shrink: 0;
    opacity: 0.8;
    margin-left: auto;
}

/* --- Collaboration Ranking --- */
.collab-ranking-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.collab-ranking-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    flex-wrap: wrap;
}

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

.collab-x {
    font-size: 0.8rem;
    opacity: 0.5;
}

@media (max-width: 768px) {
    .collab-pair {
        min-width: 0;
    }

    .collab-pair .member-badge {
        font-size: 0.6rem;
        padding: 2px 6px;
    }

    .collab-ranking-item .ranking-count {
        flex-shrink: 0;
        margin-left: auto;
    }
}

/* --- Stats Responsive --- */
@media (max-width: 1024px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .overlap-grid {
        grid-template-columns: 1fr;
    }

    .overlap-card.cyber-card {
        padding: 12px;
    }

    .overlap-badges .member-badge {
        font-size: 0.6rem;
        padding: 2px 6px;
    }

    .stat-member-name {
        width: 80px;
        font-size: 0.75rem;
    }

    .ranking-name {
        width: auto;
        flex-shrink: 1;
        white-space: normal;
        font-size: 0.8rem;
    }

    .ranking-song-info {
        flex-direction: column;
        gap: 0;
    }

    .ranking-song-info .ranking-name {
        white-space: normal;
        word-break: break-all;
    }

    .monthly-bar {
        width: 24px;
    }

    .heatmap-container {
        grid-auto-columns: 11px;
        grid-template-rows: repeat(7, 11px);
    }

    .heatmap-cell {
        width: 11px;
        height: 11px;
    }

    .heatmap-month-labels {
        grid-auto-columns: 11px;
    }

    .heatmap-day-labels {
        grid-template-rows: repeat(7, 11px);
    }

    .heatmap-day-labels span {
        height: 11px;
        font-size: 0.5rem;
    }

    .member-stat-card {
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
        background: rgba(26, 28, 35, 0.95) !important;
        box-shadow: none !important;
    }

    [data-theme="light"] .member-stat-card {
        background: rgba(255, 255, 255, 0.95) !important;
    }
}
