:root {
    --bg: #0f172a;
    --card-bg: #1e293b;
    --card-inner: #0b1120;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --border: #334155;

    --primary: #ef4444;
    --superchat: #ec4899;
    --pos: #22c55e;
    --neutral: #64748b;
    --neg: #f97316;
    --danger: #ef4444;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    background: var(--bg);
    color: var(--text);
    padding: 20px 16px;
    min-height: 100vh;
}

.container {
    max-width: 1100px;
    margin: 0 auto;
}

/* ヘッダー */
.app-brand {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
    padding: 0 4px;
}

.brand-logo {
    font-size: 19px;
    font-weight: 800;
    background: linear-gradient(135deg, #ff6b6b, #ff8e53);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.brand-tag {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 600;
}

/* カード共通 */
.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.3);
    margin-bottom: 20px;
}

/* 検索フォーム */
.input-row {
    display: flex;
    gap: 10px;
}

input[type="text"] {
    flex: 1;
    padding: 13px 16px;
    background: var(--card-inner);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    color: #fff;
    outline: none;
    transition: all 0.2s ease;
}

input[type="text"]:focus {
    border-color: #ff6b6b;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2);
}

button.btn-search {
    padding: 13px 24px;
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s ease;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

button.btn-search:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(239, 68, 68, 0.4);
}

button.btn-search:disabled {
    background: #475569;
    box-shadow: none;
    cursor: not-allowed;
    transform: none;
}

/* 初期表示イラスト */
.welcome-card {
    text-align: center;
    padding: 30px 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.welcome-img-wrapper {
    max-width: 540px;
    width: 100%;
    margin-bottom: 16px;
    border-radius: 12px;
    overflow: hidden;
}

.welcome-img {
    width: 100%;
    height: auto;
    display: block;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

.welcome-text h2 {
    font-size: 18px;
    margin-bottom: 8px;
    color: #ff8e53;
}

.welcome-text p {
    font-size: 13px;
    color: var(--text-muted);
    max-width: 600px;
    line-height: 1.6;
}

/* プログレスバー */
.progress-wrapper {
    display: none;
    margin-top: 16px;
}

.progress-info {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.progress-bar-bg {
    width: 100%;
    height: 10px;
    background: var(--card-inner);
    border-radius: 5px;
    overflow: hidden;
    border: 1px solid var(--border);
}

.progress-bar-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #ff8e53, #ef4444, #ff8e53);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite linear;
    border-radius: 5px;
    transition: width 0.4s ease;
}

@keyframes shimmer {
    0% {
        background-position: 200% 0;
    }

    100% {
        background-position: -200% 0;
    }
}

/* 統計カード */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 10px;
    margin-bottom: 20px;
}

.stat-box {
    background: var(--card-inner);
    padding: 12px 8px;
    border-radius: 8px;
    text-align: center;
    border: 1px solid var(--border);
}

.stat-title {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 3px;
}

.stat-val {
    font-size: 17px;
    font-weight: 800;
}

/* 📈 タイムライン（線グラフ） */
.timeline-container {
    background: var(--card-inner);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px 20px;
    margin-bottom: 20px;
}

.timeline-header-text {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.timeline-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-muted);
}

.interactive-hint {
    font-size: 11px;
    color: #38bdf8;
    font-weight: 600;
}

.timeline-chart-wrapper {
    width: 100%;
    height: 170px;
    position: relative;
    cursor: pointer;
    /* クリックできることを明示 */
}

/* グラフ & ワードクラウド */
.visual-grid {
    display: grid;
    grid-template-columns: 1fr 1.3fr;
    gap: 16px;
    margin-bottom: 20px;
}

.visual-box {
    background: var(--card-inner);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.visual-title-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    margin-bottom: 10px;
}

.visual-title {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-muted);
}

.chart-wrapper {
    width: 100%;
    max-width: 260px;
    height: 210px;
}

.wordcloud-wrapper {
    width: 100%;
    height: 210px;
    position: relative;
    cursor: pointer;
    /* クリックできることを明示 */
}

#wordCloudCanvas {
    width: 100% !important;
    height: 100% !important;
}

/* タブ ＆ 検索ボタン */
.tabs-header-wrapper {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
    gap: 8px;
    width: 100%;
}

.tabs {
    display: flex;
    gap: 6px;
    flex: 1;
    min-width: 0;
}

.tab-btn {
    flex: 1 1 0px;
    min-width: 0;
    padding: 9px 4px;
    border: 1px solid var(--border);
    background: var(--card-inner);
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 6px;
    font-weight: 700;
    font-size: 12px;
    transition: all 0.2s ease;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: center;
}

.tab-btn:hover {
    color: #fff;
    background: #1e293b;
}

.tab-btn.active {
    color: #fff;
    background: #334155;
    border-color: #64748b;
}

.tab-btn.tab-superchat.active {
    background: #831843;
    border-color: var(--superchat);
    color: #fbcfe8;
}

.tab-btn.tab-pos.active {
    background: #14532d;
    border-color: var(--pos);
    color: #bbf7d0;
}

.tab-btn.tab-neutral.active {
    background: #334155;
    border-color: var(--neutral);
    color: #e2e8f0;
}

.tab-btn.tab-neg.active {
    background: #7c2d12;
    border-color: var(--neg);
    color: #fed7aa;
}

.tab-btn.tab-danger.active {
    background: #7f1d1d;
    border-color: var(--danger);
    color: #fecaca;
}

.btn-open-search {
    flex-shrink: 0;
    padding: 9px 16px;
    background: #1e293b;
    border: 1px solid #38bdf8;
    color: #38bdf8;
    border-radius: 6px;
    font-weight: 700;
    font-size: 12px;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s ease;
}

.btn-open-search:hover {
    background: #0284c7;
    color: white;
    box-shadow: 0 0 10px rgba(56, 189, 248, 0.4);
}

/* 絞り込みバナー */
.search-status-banner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(56, 189, 248, 0.15);
    border: 1px solid #38bdf8;
    padding: 9px 16px;
    border-radius: 8px;
    margin-bottom: 12px;
    font-size: 13px;
    color: #e0f2fe;
}

.btn-clear-search {
    background: #0284c7;
    color: white;
    border: none;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
    transition: 0.2s;
}

.btn-clear-search:hover {
    background: #0369a1;
}

/* 検索モーダル */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    animation: fadeIn 0.2s ease;
}

.modal-content {
    background: #1e293b;
    border: 1px solid #475569;
    border-radius: 12px;
    width: 90%;
    max-width: 520px;
    padding: 24px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.modal-header h3 {
    font-size: 16px;
    color: #38bdf8;
}

.btn-close-modal {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 18px;
    cursor: pointer;
}

.btn-close-modal:hover {
    color: white;
}

.modal-desc {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 16px;
}

.modal-input-row {
    display: flex;
    gap: 8px;
}

.modal-input-row input {
    flex: 1;
    padding: 12px 14px;
    background: var(--card-inner);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    color: white;
    outline: none;
}

.modal-input-row input:focus {
    border-color: #38bdf8;
}

.btn-execute-search {
    padding: 12px 20px;
    background: #0284c7;
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
}

.btn-execute-search:hover {
    background: #0369a1;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* テーブル */
.table-wrapper {
    max-height: 520px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--card-inner);
    position: relative;
}

table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 13px;
}

th,
td {
    border-bottom: 1px solid #1e293b;
    border-right: 1px solid #1e293b;
    padding: 11px 14px;
}

th:last-child,
td:last-child {
    border-right: none;
}

th {
    background: #1e293b !important;
    color: var(--text-muted);
    font-weight: 700;
    position: sticky;
    top: 0;
    z-index: 10;
    text-align: center;
    border-top: none;
    box-shadow: 0 1px 0 var(--border);
}

tr:hover td {
    background: #162032;
}

/* バッジ */
.badge {
    display: inline-block;
    min-width: 84px;
    text-align: center;
    padding: 4px 8px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
}

.badge-superchat {
    background: rgba(236, 72, 153, 0.15);
    color: #f472b6;
    border: 1px solid rgba(236, 72, 153, 0.3);
}

.badge-pos {
    background: rgba(34, 197, 94, 0.15);
    color: #4ade80;
    border: 1px solid rgba(34, 197, 94, 0.3);
}

.badge-neutral {
    background: rgba(100, 116, 139, 0.15);
    color: #94a3b8;
    border: 1px solid rgba(100, 116, 139, 0.3);
}

.badge-neg {
    background: rgba(249, 115, 22, 0.15);
    color: #fb923c;
    border: 1px solid rgba(249, 115, 22, 0.3);
}

.badge-danger {
    background: rgba(239, 68, 68, 0.2);
    color: #f87171;
    border: 1px solid rgba(239, 68, 68, 0.4);
}

.col-center {
    text-align: center;
}

.col-text {
    text-align: left;
    word-break: break-word;
    color: #e2e8f0;
}

.author-link {
    color: #38bdf8;
    text-decoration: none;
    font-weight: 600;
}

.author-link:hover {
    text-decoration: underline;
}

.superchat-badge {
    display: inline-block;
    background: #831843;
    color: #fbcfe8;
    font-weight: 700;
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 4px;
    margin-top: 4px;
}

/* SEOセクション & フッター */
.seo-section {
    margin-top: 30px;
    border-top: 1px solid var(--border);
    padding-top: 24px;
}

.seo-section h3 {
    font-size: 15px;
    color: #ff8e53;
    margin-bottom: 14px;
    text-align: center;
}

.seo-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
}

.seo-card {
    background: var(--card-inner);
    padding: 14px;
    border-radius: 8px;
    border: 1px solid var(--border);
    font-size: 12px;
}

.seo-card h4 {
    color: #f1f5f9;
    margin-bottom: 6px;
    font-size: 13px;
}

.seo-card p {
    color: var(--text-muted);
    line-height: 1.5;
}

footer {
    text-align: center;
    margin-top: 24px;
    font-size: 11px;
    color: var(--text-muted);
}

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #0f172a;
}

::-webkit-scrollbar-thumb {
    background: #334155;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #475569;
}

/* レスポンシブ */
@media (max-width: 860px) {
    .visual-grid {
        grid-template-columns: 1fr;
    }

    .stats-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .seo-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 640px) {
    body {
        padding: 14px 10px;
    }

    .card {
        padding: 16px 12px;
    }

    .input-row {
        flex-direction: column;
    }

    button.btn-search {
        width: 100%;
    }

    .stats-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 6px;
    }

    .stat-box {
        padding: 8px 4px;
    }

    .stat-title {
        font-size: 10px;
    }

    .stat-val {
        font-size: 15px;
    }

    .tabs-header-wrapper {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .tabs {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 6px;
    }

    .tab-btn {
        padding: 8px 4px;
        font-size: 11px;
        border-radius: 6px;
        text-align: center;
    }

    .btn-open-search {
        width: 100%;
        text-align: center;
        padding: 10px;
    }

    thead {
        display: none;
    }

    table,
    tbody,
    tr {
        display: block;
        width: 100%;
    }

    tr {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        padding: 12px 10px;
        border-bottom: 1px solid var(--border);
        gap: 6px 10px;
    }

    td {
        border: none !important;
        padding: 0 !important;
    }

    td:nth-child(1) {
        order: 1;
        width: auto;
    }

    .badge {
        min-width: auto;
        padding: 3px 8px;
        font-size: 10px;
    }

    td:nth-child(2) {
        order: 2;
        width: auto;
        font-size: 11px;
        color: var(--text-muted);
    }

    td:nth-child(3) {
        order: 3;
        width: auto;
        flex: 1;
        text-align: left !important;
        font-size: 12px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .superchat-badge {
        margin-top: 0;
        margin-left: 6px;
        font-size: 10px;
        padding: 1px 4px;
    }

    td:nth-child(4) {
        order: 4;
        width: 100%;
        margin-top: 4px;
        font-size: 13px;
        line-height: 1.5;
        color: #f1f5f9;
    }
}