/* ランキングコンテナ */
.ranking-container {
    margin-top: 3rem;
}

.ranking-title1 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--primary);
    text-align: center;
    margin-bottom: 2rem;
    position: relative;
    text-decoration: underline;
}


.ranking-title2 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--primary);
    text-align: center;
    margin-bottom: 2rem;
    position: relative;
}

.ranking-title2::after {
    content: "";
    display: block;
    width: 400px;
    height: 4px;
    background: linear-gradient(to right, var(--primary), transparent);
    margin: 0.5rem auto 0;
}

.ranking-list {
    display: grid;
    grid-template-columns: 1fr;
    gap: 2rem;
}

.annotation {
    margin-top: 56px;
}

/* ランキングアイテム */
.ranking-item {
    display: flex;
    flex-direction: column;
    background-color: white;
    border-radius: 0.75rem;
    overflow: hidden;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    opacity: 0;
    transform: translateY(20px);
}

.ranking-item.show {
    opacity: 1;
    transform: translateY(0);
}

.ranking-item:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 15px rgba(0, 0, 0, 0.1);
}

/* トップ3のスタイル */
.ranking-item.top-1 {
    border: 2px solid #ffd700;
    background-color: #fffde7;
}

.ranking-item.top-2 {
    border: 2px solid #c0c0c0;
    background-color: #f5f5f5;
}

.ranking-item.top-3 {
    border: 2px solid #d6a16c;
    background-color: #fff8e1;
}

.ranking-item-image {
    position: relative;
    height: 200px;
    overflow: hidden;
}

.ranking-item-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.5s ease;
}

.ranking-item:hover .ranking-item-image img {
    transform: scale(1.05);
}

.rank-icon {
    position: absolute;
    top: 10px;
    left: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    color: white;
    font-weight: bold;
    font-size: 1.25rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.rank-icon.rank-1 {
    background-color: #ffd700;
}

.rank-icon.rank-2 {
    background-color: #c0c0c0;
}

.rank-icon.rank-3 {
    background-color: #cd7f32;
}

.crown-icon {
    position: absolute;
    top: 5px;
    width: 20px;
    height: 20px;
}

.rank-icon span {
    margin-top: 10px;
}

.rank-number {
    position: absolute;
    top: 10px;
    left: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: var(--primary);
    color: white;
    font-weight: bold;
    font-size: 1.25rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.ranking-item-content {
    padding: 1.5rem;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}

.ranking-item-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1rem;
}

.ranking-item-name {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--foreground);
    flex-grow: 1;
    margin-right: 1rem;
}

.ranking-item-trend {
    display: flex;
    align-items: center;
}

.trend-icon {
    width: 24px;
    height: 24px;
}

.trend-up {
    color: #3e7ce0;
}

.trend-down {
    color: #f44336;
}

.trend-same {
    color: #34bf18;
}

.trend-same {
    transform: scale(0.9);
    /* 少し小さくして他のアイコンとバランスを取る */
}

.ranking-item-details {
    display: flex;
    justify-content: space-between;
    margin-top: auto;
}

.ranking-item-price {
    font-weight: 700;
    color: var(--primary);
}

.ranking-item-prefecture {
    color: var(--muted-foreground);
}

/* ランキングtab */

/* ベーススタイル（PC/スマホ共通） */
.ranking-tabs {
    display: flex;
    justify-content: center;
    margin-top: 2rem;
    border-bottom: 2px solid #e2e8f0;

    /* ★修正1: 横幅が親要素を超えないように明記 */
    width: 100%;
    box-sizing: border-box;
}

.ranking-tab {
    /* PCの基本スタイル */
    padding: 0.75rem 1.5rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    background: none;
    position: relative;
    transition: color 0.3s, background-color 0.3s;
    margin: 0 0.5rem;
    border-radius: 0.5rem 0.5rem 0 0;

    /* 重要: 文字の折り返しを防ぐ */
    white-space: nowrap;
}

/* PC/スマホ共通のActiveスタイル */
.ranking-tab.active {
    color: var(--primary);
    background-color: rgba(0, 0, 0, 0.05);
}

.ranking-tab.active::after {
    content: "";
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 100%;
    height: 3px;
    background-color: var(--primary);
}

/* ▼▼ スマホ用レスポンシブ (768px以下) ▼▼ */
@media (max-width: 768px) {

    /* 新しく作った外側の枠 */
    .tabs-wrapper {
        position: relative;
        /* グラデーションの基準点 */
        width: 100%;
        overflow: hidden;
        /* 枠からはみ出た部分を隠す */
    }

    /* 右側のフェード（ぼかし）を作る */
    .tabs-wrapper::after {
        content: "";
        position: absolute;
        top: 0;
        right: 0;
        height: 100%;
        width: 40px;
        /* グラデーションの幅 */

        /* 透明 → 白 へのグラデーション */
        background: linear-gradient(to right, rgba(255, 255, 255, 0), #ffffff);

        pointer-events: none;
        /* 下にあるボタンをクリックできるようにする */
        z-index: 10;
    }

    .ranking-tabs {
        /* 以前のコードのまま */
        display: flex;
        justify-content: flex-start;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        width: 100%;
        scrollbar-width: none;
        padding-bottom: 0;

        /* フェードの下に文字が隠れるように、右余白を多めにとる */
        padding-right: 40px;
    }

    .ranking-tabs::-webkit-scrollbar {
        display: none;
    }

    .ranking-tab {
        padding: 0.75rem 1rem;
        margin: 0;

        /* ★修正4: flex-shrink: 0 ではなく flexプロパティで完全に固定 */
        /* これにより意図しない伸縮や、親要素への干渉を防ぎます */
        flex: 0 0 auto;

        font-size: 0.9rem;
    }

    /* ★修正5: 最後のタブだけ右側に余白を作る */
    /* これがないと、一番右までスクロールした時に文字が画面端に張り付いて見にくくなる */
    .ranking-tab:last-child {
        margin-right: 1rem;
    }

    /* スマホでactive時の下線の位置調整 */
    .ranking-tab.active::after {
        /* PCの -2px だとはみ出す場合があるので、スマホでは 0 にして枠内に収める */
        bottom: 0;
    }
}

/* 非表示クラス */
.hidden {
    display: none !important;
}

/* レスポンシブデザイン */
@media (min-width: 640px) {
    .ranking-item {
        flex-direction: row;
    }

    .ranking-item-image {
        width: 200px;
        height: auto;
    }

    .ranking-item-content {
        width: calc(100% - 200px);
    }
}

@media (min-width: 768px) {
    .ranking-list {
        grid-template-columns: repeat(2, 1fr);
    }

    .ranking-item {
        flex-direction: column;
    }

    .ranking-item-image {
        width: 100%;
        height: 200px;
    }

    .ranking-item-content {
        width: 100%;
    }

    .ranking-item.top-1,
    .ranking-item.top-2,
    .ranking-item.top-3 {
        grid-column: span 1;
    }
}

@media (min-width: 1024px) {
    .ranking-list {
        grid-template-columns: repeat(3, 1fr);
    }

    .ranking-item.top-1 {
        grid-column: span 3;
        flex-direction: row;
    }

    .ranking-item.top-1 .ranking-item-image {
        width: 40%;
        height: 250px;
    }

    .ranking-item.top-1 .ranking-item-content {
        width: 60%;
    }

    .ranking-item.top-2,
    .ranking-item.top-3 {
        grid-column: span 1;
    }
}