:root {
    --bg: #0a0a0a;
    --surface: #141414;
    --surface2: #1e1e1e;
    --border: rgba(212,175,55,0.25);
    --border-active: rgba(212,175,55,0.6);
    --gold: #d4af37;
    --gold-light: #fde047;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --danger: #ef4444;
    --success: #22c55e;
    --radius: 8px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: 'Noto Sans JP', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}
.navbar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 14px 32px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}
.navbar h1 {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--gold-light);
    letter-spacing: 0.15em;
}
.navbar-tabs {
    display: flex;
    gap: 4px;
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 4px;
    margin-left: auto;
}
.navbar-tab {
    padding: 7px 24px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}
.navbar-tab:hover { color: var(--text); }
.navbar-tab.active {
    background: var(--gold);
    color: #1a1200;
}
.btn-obs {
    position: relative;
    padding: 7px 18px;
    border: 1px solid var(--border-active);
    border-radius: 6px;
    background: rgba(212,175,55,0.12);
    color: var(--gold-light);
    font-family: inherit;
    font-size: 0.88rem;
    font-weight: 700;
    cursor: pointer;
    letter-spacing: 0.1em;
    transition: background 0.2s, border-color 0.2s;
    white-space: nowrap;
}
.btn-obs:hover { background: rgba(212,175,55,0.22); }
.obs-popup {
    position: absolute;
    top: calc(100% + 10px);
    right: 32px;
    background: var(--surface2);
    border: 1px solid var(--border-active);
    border-radius: 8px;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    z-index: 200;
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
    white-space: nowrap;
}
.obs-url {
    font-size: 0.85rem;
    color: var(--text);
    font-family: monospace;
    letter-spacing: 0.02em;
}
.btn-obs-copy {
    padding: 5px 14px;
    border: 1px solid var(--border-active);
    border-radius: 6px;
    background: var(--gold);
    color: #1a1200;
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 700;
    cursor: pointer;
    transition: opacity 0.2s;
}
.btn-obs-copy:hover { opacity: 0.85; }
.page { display: none; }
.page.active { display: block; }
.container {
    max-width: 1800px;
    margin: 0 auto;
    padding: 32px 24px 80px;
    display: flex;
    flex-direction: column;
    gap: 40px;
}
.section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px 32px;
}
.section > h2 {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--gold);
    letter-spacing: 0.15em;
    margin-bottom: 24px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}
.settings-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}
@media (max-width: 800px) {
    .settings-grid { grid-template-columns: 1fr; }
}
.settings-card {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 24px;
}
.settings-card h3 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 6px;
}
.settings-desc {
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-bottom: 18px;
}
.form-group {
    margin-bottom: 14px;
}
.form-group label {
    display: block;
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-bottom: 5px;
}
.form-group input,
.form-group select {
    width: 100%;
    background: #0d0d0d;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    padding: 8px 12px;
    font-size: 0.9rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
}
.form-group input:focus,
.form-group select:focus { border-color: var(--gold); }
.form-group input::placeholder { color: #3a3a3a; }
.btn-row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 6px;
}
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 18px;
    border: none;
    border-radius: 6px;
    font-size: 0.88rem;
    font-family: inherit;
    font-weight: 700;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.1s;
    white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary {
    background: var(--gold);
    color: #1a1200;
}
.btn-primary:hover:not(:disabled) { opacity: 0.85; }
.btn-secondary {
    background: var(--surface2);
    color: var(--text-muted);
    border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) { border-color: var(--gold); color: var(--text); }
.btn-danger {
    background: rgba(239,68,68,0.15);
    color: var(--danger);
    border: 1px solid rgba(239,68,68,0.3);
}
.btn-danger:hover:not(:disabled) { background: rgba(239,68,68,0.25); }
.btn-icon {
    background: var(--surface2);
    color: var(--text-muted);
    border: 1px solid var(--border);
    padding: 8px 12px;
    font-size: 1.1rem;
}
.btn-icon:hover { color: var(--gold-light); border-color: var(--border-active); }
.status-msg {
    margin-top: 12px;
    font-size: 0.85rem;
    padding: 8px 12px;
    border-radius: 6px;
}
.status-msg.success { background: rgba(34,197,94,0.12); color: var(--success); }
.status-msg.error   { background: rgba(239,68,68,0.12); color: var(--danger);  }
.status-msg.loading { color: var(--text-muted); }
.tournament-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}
.tournament-row label {
    font-size: 0.9rem;
    color: var(--text-muted);
    white-space: nowrap;
}
.tournament-row select {
    background: #0d0d0d;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    padding: 8px 12px;
    font-size: 0.9rem;
    font-family: inherit;
    outline: none;
    min-width: 260px;
    transition: border-color 0.2s;
}
.tournament-row select:focus { border-color: var(--gold); }
.tab-bar {
    display: flex;
    gap: 4px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 4px;
    margin-bottom: 20px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.tab-bar::-webkit-scrollbar { display: none; }
.tab-btn {
    padding: 8px 22px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    white-space: nowrap;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active {
    background: var(--gold);
    color: #1a1200;
}
.sort-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 20px;
    font-size: 0.85rem;
    color: var(--text-muted);
    flex-wrap: wrap;
}
.sort-btn {
    padding: 5px 14px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: transparent;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.82rem;
    cursor: pointer;
    transition: all 0.2s;
}
.sort-btn.active {
    border-color: var(--gold);
    color: var(--gold-light);
    background: rgba(212,175,55,0.1);
}
.sort-sep { color: var(--border); margin: 0 4px; }
#category-filter-wrap { display: none; }
#category-filter-wrap.visible { display: inline-flex; align-items: center; gap: 6px; }
#category-filter {
    background: #0d0d0d;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    padding: 4px 8px;
    font-size: 0.82rem;
    font-family: inherit;
    outline: none;
}
.tab-content { display: none; }
.tab-content.active { display: block; }
.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 14px;
}
.d-card {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 8px;
    transition: border-color 0.2s, transform 0.15s;
    position: relative;
}
.d-card:hover {
    border-color: var(--border-active);
    transform: translateY(-2px);
}
.d-card-rank {
    position: absolute;
    top: 8px;
    right: 8px;
    font-size: 0.75rem;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 4px;
    background: rgba(30,30,30,0.9);
    color: #e2e8f0;
}
.d-card.rank-1 .d-card-rank { background: rgba(212,175,55,0.9); color: #1a1200; }
.d-card.rank-2 .d-card-rank { background: rgba(180,190,210,0.9); color: #1a1a1a; }
.d-card.rank-3 .d-card-rank { background: rgba(160,82,20,0.9);   color: #fff4e8; }
.d-card-img {
    width: 80px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.d-card-img img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}
.d-card.stage-card .d-card-img {
    width: 120px;
    height: 68px;
}
.d-card.stage-card .d-card-img img {
    object-fit: cover;
    width: 100%;
    height: 100%;
    border-radius: 4px;
}
.d-card.rule-card .d-card-img {
    width: 100px;
    height: 80px;
}
.d-card-name {
    font-size: 0.82rem;
    color: var(--text);
    word-break: break-all;
    line-height: 1.3;
}
.d-card-bar {
    width: 100%;
    height: 3px;
    background: rgba(255,255,255,0.08);
    border-radius: 2px;
}
.d-card-bar-fill {
    height: 100%;
    background: var(--gold);
    border-radius: 2px;
    width: 0%;
    transition: width 0.8s ease-out;
}
.d-card-count {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--gold-light);
}
.d-card-category {
    font-size: 0.7rem;
    color: var(--text-muted);
    background: rgba(255,255,255,0.05);
    padding: 1px 6px;
    border-radius: 10px;
}
.teams-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 20px;
    align-items: start;
}
.team-sort-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin-bottom: 16px;
    font-size: 0.82rem;
    color: var(--text-muted);
}
.team-card {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.team-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 14px 18px;
    cursor: pointer;
    user-select: none;
    transition: background 0.15s;
}
.team-card-header:hover {
    background: rgba(255,255,255,0.04);
}
.team-card-header h3 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--gold-light);
    margin: 0;
    flex: 1 1 0;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.team-scores {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}
.team-score-pill {
    font-size: 0.72rem;
    padding: 3px 8px;
    border-radius: 20px;
    white-space: nowrap;
    line-height: 1.4;
}
.team-score-pill strong {
    font-size: 0.88rem;
    font-weight: 700;
    margin-left: 3px;
}
.team-score-pill.diversity {
    background: rgba(56, 189, 248, 0.15);
    color: #7dd3fc;
    border: 1px solid rgba(56, 189, 248, 0.3);
}
.team-score-pill.rarity {
    background: rgba(192, 132, 252, 0.15);
    color: #d8b4fe;
    border: 1px solid rgba(192, 132, 252, 0.3);
}
.team-score-pill.untrusted {
    opacity: 0.45;
    filter: grayscale(0.5);
}
.team-score-untrustworthy {
    font-size: 0.65rem;
    padding: 2px 6px;
    border-radius: 20px;
    background: rgba(148, 163, 184, 0.12);
    color: var(--text-muted);
    border: 1px solid rgba(148, 163, 184, 0.25);
    white-space: nowrap;
}
.team-card-chevron {
    font-size: 0.7rem;
    color: var(--text-muted);
    transition: transform 0.2s;
    flex-shrink: 0;
}
.team-card.expanded .team-card-chevron {
    transform: rotate(180deg);
}
.team-card-body {
    display: none;
    padding: 4px 18px 16px;
    border-top: 1px solid var(--border);
}
.team-card.expanded .team-card-body {
    display: block;
}
.team-stat-section {
    margin-bottom: 14px;
}
.team-stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 8px;
    letter-spacing: 0.08em;
}
.team-stat-icons {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
}
.team-stat-icon-item {
    position: relative;
    flex-shrink: 0;
}
.team-stat-icon-item img {
    width: 48px;
    height: 48px;
    object-fit: contain;
    display: block;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.6));
}
.team-stat-icon-item img.stage-thumb {
    width: 72px;
    height: 40px;
    object-fit: cover;
    border-radius: 4px;
}
.team-stat-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: var(--gold);
    color: #1a1200;
    font-size: 0.65rem;
    font-weight: 700;
    min-width: 16px;
    height: 16px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 3px;
    line-height: 1;
}
.team-stat-empty {
    font-size: 0.8rem;
    color: var(--text-muted);
}
.charts-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}
.chart-card {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    min-width: 0;
}
.chart-card-wide {
    /* PCでは2カラムレイアウトの中の通常サイズ（全幅にしない） */
}
.chart-card-half canvas {
    max-height: 220px;
}
#chart-categories-diff {
    max-height: 300px !important;
}
.chart-card-wide canvas {
    max-height: 220px;
}
.heatmap-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.heatmap-wrap canvas {
    max-height: 220px !important;
    min-width: 400px;
}
.chart-card h3 {
    font-size: 0.85rem;
    color: var(--text-muted);
    letter-spacing: 0.08em;
}
.chart-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
    gap: 8px;
}
.chart-toggle {
    display: flex;
    gap: 2px;
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 2px;
    flex-shrink: 0;
}
.chart-toggle-btn {
    padding: 3px 10px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    white-space: nowrap;
}
.chart-toggle-btn.active {
    background: var(--gold);
    color: #1a1200;
}
.empty-state {
    text-align: center;
    padding: 60px 0;
    color: var(--text-muted);
    font-size: 0.95rem;
}
.hidden { display: none !important; }
.overview-row {
    display: flex;
    gap: 16px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}
.overview-pill {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px 20px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.overview-pill-label {
    font-size: 0.75rem;
    color: var(--text-muted);
}
.overview-pill-value {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--gold-light);
}
.stability-unit {
    font-size: 0.75rem;
    font-weight: 400;
    color: var(--text-muted);
}
.overview-pill-divider {
    width: 1px;
    align-self: stretch;
    background: var(--border);
    margin: 0 4px;
}
.overview-pill-stability {
    border-color: rgba(255,255,255,0.1);
}
@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,0.15);
    border-top-color: var(--gold);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    vertical-align: middle;
}
@media (max-width: 768px) {
    .navbar {
        flex-wrap: wrap;
        gap: 8px;
        padding: 10px 16px;
    }
    .navbar h1 {
        font-size: 1.05rem;
        flex: 1;
    }
    .navbar-tabs {
        order: 3;
        width: 100%;
        justify-content: center;
        margin-left: 0;
    }
    .navbar-tab { padding: 6px 18px; }
    .btn-obs { display: none; }
    .obs-popup { display: none !important; }
}
@media (max-width: 640px) {
    .container { padding: 16px 12px 60px; gap: 24px; }
    .section { padding: 16px 14px; }
    .section > h2 { font-size: 1rem; margin-bottom: 16px; }
}
@media (max-width: 480px) {
    .overview-row { gap: 8px; }
    .overview-pill { padding: 8px 14px; }
    .overview-pill-value { font-size: 1.1rem; }
}
@media (max-width: 640px) {
    .tournament-row { gap: 8px; }
    .tournament-row select { min-width: 0; flex: 1; }
}
@media (max-width: 480px) {
    .sort-controls { font-size: 0.8rem; gap: 6px; }
    .sort-btn { padding: 4px 10px; }
}
@media (max-width: 480px) {
    .cards-grid {
        grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
        gap: 10px;
    }
    .d-card { padding: 10px 8px; }
    .d-card-count { font-size: 1rem; }
}
@media (max-width: 560px) {
    .teams-grid { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
    .charts-grid { grid-template-columns: 1fr; }
    .chart-card-half canvas { max-height: 260px; }
}
@media (max-width: 640px) {
    .charts-grid { gap: 14px; }
    .chart-card { padding: 12px; }
    .chart-card-wide canvas { max-height: 240px; }
}
@media (max-width: 480px) {
    .settings-card { padding: 16px 14px; }
}

/* 拡大ボタン */
.btn-chart-expand {
    padding: 3px 7px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.9rem;
    cursor: pointer;
    transition: color 0.2s, border-color 0.2s;
    flex-shrink: 0;
    line-height: 1;
}
.btn-chart-expand:hover { color: var(--gold-light); border-color: var(--border-active); }

/* チャートモーダル */
.chart-modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.85);
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
}
.chart-modal.hidden { display: none; }
.chart-modal-inner {
    background: var(--surface);
    border: 1px solid var(--border-active);
    border-radius: 12px;
    width: 90vw;
    max-width: 1200px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.chart-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.chart-modal-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--gold-light);
    letter-spacing: 0.08em;
}
.chart-modal-close {
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.9rem;
    cursor: pointer;
    transition: color 0.2s, border-color 0.2s;
}
.chart-modal-close:hover { color: var(--danger); border-color: var(--danger); }
.chart-modal-body {
    flex: 1;
    padding: 20px;
    overflow: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 0;
}
.chart-modal-body canvas {
    max-width: 100%;
    max-height: 70dvh;
}

/* スマホ縦向き時: モーダルを90度回転して横向き表示 */
@media (max-width: 768px) and (orientation: portrait) {
    .chart-modal-inner {
        position: fixed;
        top: 50%;
        left: 50%;
        width: 100dvh;
        max-width: 100dvh;
        height: 100dvw;
        max-height: 100dvw;
        transform: translate(-50%, -50%) rotate(90deg);
        border-radius: 0;
        border: none;
    }
    .chart-modal-body canvas {
        max-height: calc(100dvw - 56px);
    }
}
