/*
 * きばんのはてな オウンドメディア 専用スタイル
 */

/* ==========================================================================
   共通設定
   ========================================================================== */

.kiban-owned-media,
.kiban-archive {
    max-width: 1200px;
    margin: 0 auto;
    padding: 40px 20px;
}

/* ==========================================================================
   Section Container
   ========================================================================== */

.kiban-sections-container {
    margin-top: 60px;
}

.kiban-section {
    margin-bottom: 80px;
    padding-bottom: 60px;
    border-bottom: 2px solid #f0f0f0;
}

.kiban-section:last-child {
    border-bottom: none;
}

/* Section Header */
.section-header {
    margin-bottom: 40px;
    text-align: center;
}

.section-title {
    font-size: 32px;
    font-weight: 700;
    margin-bottom: 12px;
    color: #333;
    position: relative;
    display: inline-block;
    padding-bottom: 12px;
}

.section-title::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 60px;
    height: 3px;
    background: #0066cc;
}

/* セクション別カラー */
.section-kiso .section-title::after { background: #4CAF50; }
.section-sekkei .section-title::after { background: #2196F3; }
.section-hounetsu .section-title::after { background: #FF9800; }
.section-seizou .section-title::after { background: #9C27B0; }
.section-shijou .section-title::after { background: #F44336; }

.section-description {
    font-size: 16px;
    color: #666;
    margin-top: 8px;
}

/* ==========================================================================
   記事カードグリッド
   ========================================================================== */

.kiban-cards-grid,
.kiban-archive-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 30px;
    margin-bottom: 40px;
}

@media (max-width: 768px) {
    .kiban-cards-grid,
    .kiban-archive-grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }
}

/* ==========================================================================
   記事カード
   ========================================================================== */

.kiban-card {
    background: #fff;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.kiban-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

.kiban-card-link {
    text-decoration: none;
    color: inherit;
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* サムネイル */
.kiban-card-thumbnail {
    position: relative;
    width: 100%;
    height: 200px;
    overflow: hidden;
    background: #f5f5f5;
}

.kiban-card-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.kiban-card:hover .kiban-card-thumbnail img {
    transform: scale(1.05);
}

.no-thumbnail {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.no-image-text {
    color: #fff;
    font-size: 18px;
    font-weight: 600;
    opacity: 0.7;
}

<?php
/**
 * Template Part: きばんのはてな記事カード
 * 配置：template-parts/content-kiban-card.php
 */

$thumbnail_url = get_the_post_thumbnail_url( get_the_ID(), 'medium' );

$excerpt = get_the_excerpt();
if ( empty( $excerpt ) ) {
    $excerpt = wp_trim_words( strip_shortcodes( get_the_content() ), 40, '...' );
}

// 難易度（★ / ★★ / ★★★）
$difficulty = (string) get_field( 'difficulty' );
$difficulty_class = '';
$difficulty_label = '';
$difficulty_text = ''; // Schema.org用のテキスト

if ( strpos( $difficulty, '★★★' ) !== false ) {
    $difficulty_class = 'difficulty-advanced';
    $difficulty_label = '★★★';
    $difficulty_text = '上級';
} elseif ( strpos( $difficulty, '★★' ) !== false ) {
    $difficulty_class = 'difficulty-intermediate';
    $difficulty_label = '★★';
    $difficulty_text = '中級';
} elseif ( strpos( $difficulty, '★' ) !== false ) {
    $difficulty_class = 'difficulty-beginner';
    $difficulty_label = '★';
    $difficulty_text = '初級';
}
?>

<a href="<?php the_permalink(); ?>" class="article-card" itemscope itemtype="https://schema.org/Article">
    <div class="card-thumbnail <?php echo empty($thumbnail_url) ? 'no-image' : ''; ?>">
        <?php if ( $thumbnail_url ) : ?>
            <img src="<?php echo esc_url( $thumbnail_url ); ?>" alt="<?php the_title_attribute(); ?>" loading="lazy" itemprop="image">
        <?php endif; ?>
        
        <!-- 難易度バッジをサムネイル内に配置 -->
        <?php if ( $difficulty_label ) : ?>
            <span class="difficulty-badge <?php echo esc_attr( $difficulty_class ); ?>">
                <?php echo esc_html( $difficulty_label ); ?>
            </span>
            <meta itemprop="educationalLevel" content="<?php echo esc_attr( $difficulty_text ); ?>">
        <?php endif; ?>
    </div>

    <div class="card-content">
        <h3 class="card-title" itemprop="headline"><?php the_title(); ?></h3>

        <p class="card-excerpt" itemprop="description"><?php echo esc_html( $excerpt ); ?></p>

        <div class="card-footer">
            <span class="read-more">
                続きを読む
                <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true" focusable="false">
                    <line x1="5" y1="12" x2="19" y2="12"></line>
                    <polyline points="12 5 19 12 12 19"></polyline>
                </svg>
            </span>
        </div>
    </div>
</a>

/* カード本文 */
.kiban-card-content {
    padding: 20px;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}

.kiban-card-title {
    font-size: 18px;
    font-weight: 700;
    line-height: 1.5;
    margin-bottom: 12px;
    color: #333;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.kiban-card-excerpt {
    font-size: 14px;
    line-height: 1.6;
    color: #666;
    margin-bottom: 16px;
    flex-grow: 1;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* メタ情報 */
.kiban-card-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    padding-top: 16px;
    border-top: 1px solid #f0f0f0;
}

.kiban-card-date {
    font-size: 12px;
    color: #999;
}

/* ==========================================================================
   もっと見るボタン
   ========================================================================== */

.section-more-button {
    text-align: center;
    margin-top: 40px;
}

.btn-more {
    display: inline-block;
    padding: 14px 40px;
    background: #fff;
    border: 2px solid #0066cc;
    color: #0066cc;
    text-decoration: none;
    border-radius: 30px;
    font-weight: 600;
    font-size: 16px;
    transition: all 0.3s ease;
}

.btn-more:hover {
    background: #0066cc;
    color: #fff;
}

.btn-more .count {
    font-size: 14px;
    margin-left: 8px;
    opacity: 0.8;
}

/* セクション別ボタンカラー */
.section-kiso .btn-more { border-color: #4CAF50; color: #4CAF50; }
.section-kiso .btn-more:hover { background: #4CAF50; color: #fff; }

.section-sekkei .btn-more { border-color: #2196F3; color: #2196F3; }
.section-sekkei .btn-more:hover { background: #2196F3; color: #fff; }

.section-hounetsu .btn-more { border-color: #FF9800; color: #FF9800; }
.section-hounetsu .btn-more:hover { background: #FF9800; color: #fff; }

.section-seizou .btn-more { border-color: #9C27B0; color: #9C27B0; }
.section-seizou .btn-more:hover { background: #9C27B0; color: #fff; }

.section-shijou .btn-more { border-color: #F44336; color: #F44336; }
.section-shijou .btn-more:hover { background: #F44336; color: #fff; }

/* ==========================================================================
   アーカイブページ
   ========================================================================== */

.kiban-archive .page-header {
    text-align: center;
    margin-bottom: 60px;
    padding-bottom: 30px;
    border-bottom: 2px solid #f0f0f0;
}

.kiban-archive .page-title {
    font-size: 36px;
    font-weight: 700;
    color: #333;
    margin-bottom: 20px;
}

.archive-back-link {
    margin-top: 16px;
}

.archive-back-link a {
    color: #0066cc;
    text-decoration: none;
    font-size: 14px;
    transition: opacity 0.3s;
}

.archive-back-link a:hover {
    opacity: 0.7;
}

/* ページネーション */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    margin-top: 60px;
    padding-top: 40px;
    border-top: 1px solid #f0f0f0;
}

.pagination a,
.pagination span {
    display: inline-block;
    padding: 8px 16px;
    background: #fff;
    border: 1px solid #ddd;
    color: #333;
    text-decoration: none;
    border-radius: 4px;
    transition: all 0.3s ease;
}

.pagination a:hover {
    background: #0066cc;
    color: #fff;
    border-color: #0066cc;
}

.pagination .current {
    background: #0066cc;
    color: #fff;
    border-color: #0066cc;
}

/* 記事なし */
.no-results {
    text-align: center;
    padding: 80px 20px;
    color: #999;
}

.no-results p {
    font-size: 18px;
}

/* ==========================================================================
   レスポンシブ
   ========================================================================== */

@media (max-width: 768px) {
    .section-title {
        font-size: 24px;
    }

    .section-description {
        font-size: 14px;
    }

    .kiban-card-title {
        font-size: 16px;
    }

    .btn-more {
        padding: 12px 30px;
        font-size: 14px;
    }

    .kiban-archive .page-title {
        font-size: 28px;
    }
}