<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Subject Card</title>
    <style>
        :root {
            --bg-color: #f7f8fa;
            --card-bg: #ffffff;
            --primary-color: #FB8C00;
            /* 更现代的暖橙色 */
            --secondary-color: #FFF3E0;
            /* 浅橙色背景 */
            --text-main: #1a1a1a;
            --text-sub: #8590a6;
            --text-light: #999;
            --border-color: #eaeaea;
            --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
            --card-shadow: 0 12px 40px rgba(0, 0, 0, 0.08);
            --img-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
        }

        body {
            margin: 0;
            padding: 40px;
            font-family: var(--font-family);
            background-color: transparent;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            box-sizing: border-box;
        }

        #card {
            width: 800px;
            display: flex;
            background-color: var(--card-bg);
            border-radius: 20px;
            box-shadow: var(--card-shadow);
            overflow: hidden;
            padding: 24px;
            box-sizing: border-box;
            gap: 28px;
            border: 1px solid rgba(0, 0, 0, 0.02);
            position: relative;
        }

        /* 装饰性背景圆 */
        #card::before {
            content: "";
            position: absolute;
            top: -50px;
            right: -50px;
            width: 150px;
            height: 150px;
            background: linear-gradient(135deg, var(--secondary-color) 0%, rgba(255, 255, 255, 0) 70%);
            border-radius: 50%;
            z-index: 0;
            opacity: 0.6;
        }

        /* 右上角更新日角标 */
        .weekday-badge {
            position: absolute;
            top: 0;
            right: 0;
            z-index: 10;
            /* 上边和右边直角，左下角圆角 */
            border-radius: 0 20px 0 16px;
            background: linear-gradient(135deg, #FF9800 0%, #F57C00 100%);
            padding: 8px 18px 10px 16px;
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 1px;
            box-shadow: -2px 2px 8px rgba(245, 124, 0, 0.3);
        }

        .weekday-badge::after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 0;
            width: 8px;
            height: 8px;
            background: linear-gradient(135deg, transparent 50%, rgba(230, 81, 0, 0.15) 50%);
        }

        .weekday-kanji {
            font-size: 22px;
            font-weight: 900;
            color: #fff;
            line-height: 1;
            text-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
        }

        .weekday-sub {
            font-size: 9px;
            font-weight: 600;
            color: rgba(255, 255, 255, 0.85);
            letter-spacing: 1px;
        }

        /* 左侧图片容器 */
        .cover-container {
            flex-shrink: 0;
            width: 210px;
            display: flex;
            flex-direction: column;
            gap: 12px;
            align-self: stretch;
            /* 充满高度 */
        }

        .cover-wrapper {
            border-radius: 12px;
            overflow: hidden;
            box-shadow: var(--img-shadow);
            background-color: #f0f0f0;
            position: relative;
            z-index: 1;
            font-size: 0;
            /* 消除图片底部间隙 */
        }

        .cover-image {
            width: 100%;
            height: auto;
            display: block;
            object-fit: cover;
            min-height: 297px;
            transition: transform 0.3s ease;
        }

        /* 剧集进度（左侧） */
        .episode-container {
            background: #fff;
            border-radius: 12px;
            padding: 10px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.04);
        }

        .episode-label {
            font-size: 10px;
            font-weight: 700;
            color: var(--text-light);
            margin-bottom: 8px;
            letter-spacing: 0.5px;
            display: flex;
            align-items: center;
            justify-content: space-between;
        }

        .episode-progress-text {
            font-size: 10px;
            font-weight: 600;
            color: var(--primary-color);
        }

        .episode-grid {
            display: flex;
            flex-wrap: wrap;
            gap: 4px;
        }

        .ep-cell {
            width: 28px;
            height: 28px;
            border-radius: 6px;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 11px;
            font-weight: 700;
        }

        /* 已播出：橙色醒目背景 + 白色数字 */
        .ep-aired {
            background: linear-gradient(135deg, #FF9800, #FB8C00);
            color: #fff;
            box-shadow: 0 2px 6px rgba(251, 140, 0, 0.35);
            text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
        }

        /* 未播出：灰色背景 + 深灰数字 */
        .ep-unaired {
            background-color: #e8e8e8;
            color: #666;
        }

        /* 评分直方图 */
        .chart-container {
            background: #fff;
            border-radius: 12px;
            padding: 12px 8px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.04);
            margin-top: auto;
            /* 推到底部 */
            display: flex;
            flex-direction: column;
            gap: 4px;
        }

        .chart-title {
            font-size: 10px;
            color: var(--text-light);
            font-weight: 700;
            letter-spacing: 0.5px;
            margin-bottom: 4px;
            text-align: center;
        }

        .chart-bars {
            display: flex;
            align-items: flex-end;
            justify-content: space-between;
            height: 45px;
            gap: 2px;
            padding-bottom: 2px;
            border-bottom: 1px solid #eee;
        }

        .bar-wrapper {
            flex: 1;
            display: flex;
            flex-direction: column;
            align-items: center;
            height: 100%;
            justify-content: flex-end;
            position: relative;
        }

        .bar {
            width: 80%;
            background-color: #ffe0b2;
            border-radius: 2px 2px 0 0;
            min-height: 2px;
            /* 确保0分也能看到一点点底 */
            transition: height 0.3s;
        }

        /* 高分段颜色加深 */
        .bar-wrapper:nth-child(n+8) .bar {
            background-color: var(--primary-color);
            opacity: 0.9;
        }

        /* 底部坐标轴 */
        .chart-labels {
            display: flex;
            justify-content: space-between;
            margin-top: 2px;
            padding: 0 2px;
        }

        .chart-label {
            font-size: 9px;
            color: #ccc;
            font-family: monospace;
            width: 12px;
            /* 固定宽度以便对齐 */
            text-align: center;
        }

        /* 右侧内容区域 */
        .content {
            flex-grow: 1;
            display: flex;
            flex-direction: column;
            gap: 16px;
            justify-content: flex-start;
            position: relative;
            z-index: 1;
        }

        /* 标题部分 */
        .header {
            display: flex;
            flex-direction: column;
            gap: 4px;
        }

        .title {
            font-size: 28px;
            font-weight: 800;
            color: var(--text-main);
            line-height: 1.3;
            margin: 0;
            letter-spacing: -0.5px;
        }

        .subtitle {
            font-size: 14px;
            color: var(--text-sub);
            margin: 0;
            font-weight: 500;
        }

        /* 评分行 */
        .meta-row {
            display: flex;
            align-items: center;
            gap: 16px;
            margin-top: 4px;
        }

        .score-badge {
            display: flex;
            align-items: baseline;
            gap: 4px;
            color: var(--primary-color);
        }

        .star-icon {
            font-size: 24px;
            line-height: 1;
            filter: drop-shadow(0 2px 4px rgba(251, 140, 0, 0.3));
        }

        .score-val {
            font-size: 36px;
            font-weight: 800;
            line-height: 1;
            letter-spacing: -1px;
        }

        .score-label {
            font-size: 13px;
            color: var(--text-light);
            font-weight: 500;
            transform: translateY(-2px);
        }

        .rank-badge {
            background-color: var(--secondary-color);
            color: #E65100;
            padding: 4px 10px;
            border-radius: 8px;
            font-size: 13px;
            font-weight: 700;
            letter-spacing: 0.5px;
            display: flex;
            align-items: center;
        }

        .rating-count {
            font-size: 13px;
            color: var(--text-sub);
            margin-left: auto;
            background: #f5f5f5;
            padding: 4px 10px;
            border-radius: 20px;
        }

        /* Tags */
        .tags-container {
            display: flex;
            flex-wrap: wrap;
            gap: 8px;
        }

        .tag {
            background-color: #fff;
            border: 1px solid #e0e0e0;
            color: var(--text-sub);
            padding: 4px 12px;
            border-radius: 6px;
            font-size: 12px;
            font-weight: 500;
            transition: all 0.2s;
        }

        /* 简介 */
        .summary-container {
            margin-top: 8px;
            padding-top: 20px;
            border-top: 1px dashed var(--border-color);
            flex-grow: 1;
        }

        .summary-label {
            font-size: 14px;
            font-weight: 700;
            color: var(--text-main);
            margin-bottom: 8px;
            text-transform: uppercase;
            letter-spacing: 1px;
            opacity: 0.8;
        }

        .summary-text {
            font-size: 15px;
            color: #4a4a4a;
            line-height: 1.8;
            margin: 0;
            text-align: justify;
            /* 限制显示行数，防止过长 */
            display: -webkit-box;
            -webkit-line-clamp: 7;
            -webkit-box-orient: vertical;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        /* 底部信息 */
        .footer {
            margin-top: auto;
            display: flex;
            gap: 24px;
            font-size: 13px;
            color: var(--text-light);
            padding-top: 16px;
            align-items: center;
        }

        .info-item {
            display: flex;
            align-items: center;
            gap: 6px;
            background: #f9f9f9;
            padding: 4px 10px;
            border-radius: 6px;
        }

        .info-icon {
            opacity: 0.7;
        }

        .id-badge {
            margin-left: auto;
            font-family: monospace;
            opacity: 0.5;
            font-size: 12px;
        }

        /* 空状态占位 */
        .no-data {
            color: #ccc;
            font-style: italic;
            font-size: 14px;
        }
    </style>
</head>

<body>
    <div id="card">
        <!-- 右上角更新日角标 -->
        {% if air_weekday %}
        <div class="weekday-badge">
            <span class="weekday-kanji">{{ air_weekday }}</span>
            <span class="weekday-sub">曜日</span>
        </div>
        {% endif %}

        <!-- 左侧封面 -->
        <div class="cover-container">
            <div class="cover-wrapper">
                {% if image_url %}
                <img class="cover-image" src="{{ image_url }}" alt="Cover" referrerpolicy="no-referrer"
                    onerror="this.style.display='none'">
                {% endif %}
            </div>

            <!-- 剧集进度 -->
            {% if episode_list %}
            <div class="episode-container">
                <div class="episode-label">
                    放送进度
                    {% set aired_count = episode_list | selectattr('aired') | list | length %}
                    <span class="episode-progress-text">{{ aired_count }} / {{ episode_list | length }}</span>
                </div>
                <div class="episode-grid">
                    {% for ep_item in episode_list %}
                    <div class="ep-cell {{ 'ep-aired' if ep_item.aired else 'ep-unaired' }}">
                        {{ ep_item.ep }}
                    </div>
                    {% endfor %}
                </div>
            </div>
            {% endif %}

            <!-- 评分分布 -->
            {% if rating and rating.count %}
            <div class="chart-container">
                <div class="chart-title">评分分布</div>
                <div class="chart-bars">
                    {% set max_count = rating.count.values() | max if rating.count else 1 %}

                    {% for i in range(1, 11) %}
                    {% set count = rating.count[i|string] or 0 %}
                    {% set height_percent = (count / max_count * 100) if max_count > 0 else 0 %}
                    {% set final_height = height_percent if height_percent > 1 else 1 %}
                    <div class="bar-wrapper" title="{{ i }}分: {{ count }}人">
                        <div class="bar" style="height: {{ final_height }}%;"></div>
                    </div>
                    {% endfor %}
                </div>
                <div class="chart-labels">
                    <span class="chart-label">1</span>
                    <span class="chart-label"></span>
                    <span class="chart-label"></span>
                    <span class="chart-label"></span>
                    <span class="chart-label">5</span>
                    <span class="chart-label"></span>
                    <span class="chart-label"></span>
                    <span class="chart-label"></span>
                    <span class="chart-label"></span>
                    <span class="chart-label">10</span>
                </div>
            </div>
            {% endif %}
        </div>

        <!-- 右侧信息 -->
        <div class="content">
            <!-- 标题 -->
            <div class="header">
                <h1 class="title">{{ name_cn or name }}</h1>
                {% if name_cn and name != name_cn %}
                <p class="subtitle">{{ name }}</p>
                {% endif %}
            </div>

            <!-- 评分与排名 -->
            {% if rating %}
            <div class="meta-row">
                <div class="score-badge">
                    <span class="star-icon">★</span>
                    <span class="score-val">{{ rating.score }}</span>
                </div>
                {% set display_rank = rating.rank or rank %}
                {% if display_rank %}
                <div class="rank-badge">
                    #{{ display_rank }}
                </div>
                {% endif %}
                <div class="rating-count">
                    {{ rating.total }} 人评分
                </div>
                {% if collection and collection.doing %}
                <div class="rating-count" style="margin-left: 8px;">
                    {{ collection.doing }} 人在看
                </div>
                {% endif %}
            </div>
            {% else %}
            <div class="meta-row">
                <span class="no-data">暂无评分</span>
            </div>
            {% endif %}

            <!-- 标签 -->
            {% if tags %}
            <div class="tags-container">
                {% for tag in tags[:8] %}
                <span class="tag">{{ tag.name }}</span>
                {% endfor %}
            </div>
            {% endif %}

            <!-- 简介 -->
            <div class="summary-container">
                <div class="summary-label">简介</div>
                <p class="summary-text">
                    {{ summary if summary else '暂无简介' }}
                </p>
            </div>

            <!-- 底部额外信息 -->
            <div class="footer">
                {% if date %}
                <div class="info-item">
                    <span class="info-icon">📅</span>
                    <span>{{ date }}</span>
                </div>
                {% endif %}
                {% if platform %}
                <div class="info-item">
                    <span class="info-icon">📺</span>
                    <span>{{ platform }}</span>
                </div>
                {% endif %}
                {% if id %}
                <div class="id-badge">
                    ID: {{ id }}
                </div>
                {% endif %}
            </div>
        </div>
    </div>
</body>

</html>