/* ========================================
   TWI-RANKING - X動画保存ランキング
   twidouga風 サムネイルグリッドデザイン
   ======================================== */

:root {
    --bg-primary: #c4e1f6;
    --bg-header: #1da1f2;
    --bg-card: #fff;
    --accent: #1da1f2;
    --accent-hover: #0d8de0;
    --text-primary: #14171a;
    --text-secondary: #657786;
    --text-muted: #aab8c2;
    --border: #e1e8ed;
    --radius: 12px;
    --radius-sm: 8px;
}

/* Reset */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; height: auto; }

/* Layout */
.container {
    max-width: 960px;
    margin: 0 auto;
    padding: 0 12px;
}

/* ============ Header ============ */
.site-header {
    background: var(--bg-header);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
}

.logo {
    font-size: 1.2rem;
    font-weight: 800;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 8px;
}

.logo:hover { text-decoration: none; color: #fff; }

.logo-icon {
    width: 28px;
    height: 28px;
    background: rgba(255,255,255,0.2);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

/* Navigation */
.main-nav {
    display: flex;
    gap: 2px;
}

.main-nav a {
    padding: 6px 14px;
    border-radius: 4px;
    color: rgba(255,255,255,0.85);
    font-size: 0.85rem;
    font-weight: 600;
    transition: all 0.2s;
}

.main-nav a:hover,
.main-nav a.active {
    background: rgba(255,255,255,0.2);
    color: #fff;
    text-decoration: none;
}

.main-nav a.active {
    background: rgba(255,255,255,0.3);
}

/* ============ Hero / Search ============ */
.hero {
    text-align: center;
    padding: 32px 0 24px;
}

.hero h1 {
    font-size: 1.6rem;
    font-weight: 800;
    margin-bottom: 6px;
    color: var(--text-primary);
}

.hero p {
    color: var(--text-secondary);
    font-size: 0.95rem;
    margin-bottom: 24px;
}

.search-box {
    max-width: 580px;
    margin: 0 auto;
    display: flex;
    gap: 8px;
}

.search-box input {
    flex: 1;
    padding: 12px 18px;
    border: 2px solid var(--border);
    border-radius: 30px;
    background: #fff;
    color: var(--text-primary);
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.2s;
}

.search-box input:focus {
    border-color: var(--accent);
}

.search-box input::placeholder {
    color: var(--text-muted);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 22px;
    border: none;
    border-radius: 30px;
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-download {
    background: #17bf63;
    color: #fff;
    padding: 10px 20px;
}

.btn-download:hover {
    opacity: 0.9;
}

/* ============ Video Result ============ */
.video-result {
    max-width: 580px;
    margin: 20px auto 0;
    background: var(--bg-card);
    border-radius: var(--radius);
    overflow: hidden;
    display: none;
    box-shadow: 0 2px 12px rgba(0,0,0,0.1);
}

.video-result.show {
    display: block;
    animation: fadeIn 0.3s ease;
}

.video-preview {
    position: relative;
    background: #000;
}

.video-preview video {
    width: 100%;
    max-height: 340px;
    object-fit: contain;
}

.video-info {
    padding: 14px;
}

.video-user {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.video-user img {
    width: 36px;
    height: 36px;
    border-radius: 50%;
}

.video-user-name {
    font-weight: 700;
    font-size: 0.9rem;
}

.video-user-handle {
    color: var(--text-secondary);
    font-size: 0.82rem;
}

.video-text {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-bottom: 10px;
}

.download-buttons {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* ============ Section Title ============ */
.section-title {
    font-size: 1.2rem;
    font-weight: 800;
    margin: 24px 0 12px;
    text-align: center;
    color: var(--text-primary);
}

/* ============ Tabs ============ */
.tabs {
    display: flex;
    gap: 4px;
    justify-content: center;
    margin-bottom: 16px;
}

.tab-btn {
    padding: 8px 18px;
    background: #fff;
    border: 2px solid var(--border);
    border-radius: 20px;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.tab-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.tab-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

/* ============================================
   Thumbnail Grid - twidouga風サムネイル表示
   ============================================ */

.thumb-grid {
    column-count: 3;
    column-gap: 10px;
}

.thumb-card {
    display: block;
    position: relative;
    break-inside: avoid;
    margin-bottom: 10px;
    border-radius: var(--radius);
    overflow: hidden;
    transition: transform 0.15s, box-shadow 0.15s;
}

.thumb-card:hover {
    transform: scale(1.02);
    box-shadow: 0 6px 20px rgba(0,0,0,0.2);
    text-decoration: none;
}

.thumb-card img {
    width: 100%;
    height: auto;
    display: block;
    background: #ddd;
}

/* X(Twitter) アイコンオーバーレイ */
.thumb-card::before {
    content: '';
    position: absolute;
    top: 8px;
    left: 8px;
    width: 28px;
    height: 28px;
    background: var(--accent);
    border-radius: 50%;
    z-index: 2;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    background-size: 16px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

/* 順位バッジ（TOP3のみ表示） */
.thumb-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(0,0,0,0.7);
    color: #fff;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 800;
    z-index: 2;
}

.thumb-badge.gold { background: #ffd700; color: #000; }
.thumb-badge.silver { background: #c0c0c0; color: #000; }
.thumb-badge.bronze { background: #cd7f32; color: #fff; }

/* サムネイルなしの場合 */
.thumb-card .no-thumb {
    width: 100%;
    aspect-ratio: 16 / 9;
    background: linear-gradient(135deg, #e1e8ed, #c4e1f6);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 2rem;
}

/* ============ Loading Spinner ============ */
.spinner {
    display: none;
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 16px auto;
}

.spinner.show { display: block; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ============ Alert ============ */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    margin: 16px 0;
    font-size: 0.9rem;
    display: none;
}

.alert.show { display: block; }

.alert-error {
    background: #ffeaea;
    color: #d32f2f;
    border: 1px solid #f5c6c6;
}

.alert-success {
    background: #e8f5e9;
    color: #2e7d32;
    border: 1px solid #c8e6c9;
}

/* ============ Footer ============ */
.site-footer {
    text-align: center;
    padding: 24px 0;
    margin-top: 32px;
    color: var(--text-muted);
    font-size: 0.8rem;
}

.footer-nav {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px 16px;
    margin-bottom: 12px;
}

.footer-nav a {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.8rem;
}

.footer-nav a:hover {
    color: var(--accent);
    text-decoration: underline;
}

/* ============ Empty State ============ */
.empty-state {
    text-align: center;
    padding: 48px 16px;
    color: var(--text-secondary);
}

.empty-state-icon {
    font-size: 3rem;
    margin-bottom: 12px;
    opacity: 0.5;
}

/* ============ Responsive ============ */
@media (max-width: 768px) {
    .header-inner {
        flex-direction: column;
        gap: 8px;
    }

    .main-nav {
        flex-wrap: wrap;
        justify-content: center;
    }

    .main-nav a {
        padding: 5px 10px;
        font-size: 0.8rem;
    }

    .hero { padding: 24px 0 16px; }
    .hero h1 { font-size: 1.3rem; }

    .search-box {
        flex-direction: column;
    }

    .search-box .btn { width: 100%; }

    .thumb-grid {
        column-count: 2;
        column-gap: 8px;
    }

    .thumb-card {
        margin-bottom: 8px;
        border-radius: var(--radius-sm);
    }

    .thumb-card::before {
        width: 24px;
        height: 24px;
        top: 6px;
        left: 6px;
        background-size: 13px;
    }

    .thumb-badge {
        width: 24px;
        height: 24px;
        top: 6px;
        right: 6px;
        font-size: 0.7rem;
    }

    .section-title {
        font-size: 1rem;
    }
}

@media (max-width: 400px) {
    .container {
        padding: 0 8px;
    }

    .thumb-grid {
        column-gap: 6px;
    }

    .thumb-card {
        margin-bottom: 6px;
    }
}
