:root {
    --header-height: 60px;
    --col-header-height: 40px;
    --row-height: 50px;
    --judge-row-height: 140px;
    --revival-row-height: 25px;
    --spacer-height: 10px;
    --col-width: 200px;
    --header-bg: #222;
    --accent-color: #f1c40f;
    --border-color: #ddd;
}

body {
    font-family: "Helvetica Neue", Arial, "Hiragino Kaku Gothic ProN", "Hiragino Sans", Meiryo, sans-serif;
    margin: 0;
    padding: 0;
    background-color: #f4f4f4;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* --- ヘッダー関連 --- */
.page-header {
    background-color: var(--header-bg);
    color: #fff;
    height: var(--header-height);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    z-index: 100;
    flex-shrink: 0;
}

/* タイトル左側のエリア（メニューとタイトルを横並びにする） */
.header-left {
    display: flex;
    align-items: center;
}

h1 { margin: 0; font-size: 18px; font-weight: bold; color: var(--accent-color); }

.header-center { flex-grow: 1; display: flex; justify-content: center; }
.search-container { position: relative; width: 300px; }
#search-input {
    width: 100%; padding: 8px 10px; border-radius: 4px; border: none; font-size: 14px;
    background-color: #fff;
}

.header-right { display: flex; align-items: center; }
.legend { display: flex; gap: 15px; font-size: 11px; color: #ccc; }
.legend-item { display: flex; align-items: center; }
.dot { width: 12px; height: 12px; border-radius: 2px; margin-right: 6px; border: 1px solid #ccc; }
.winner-example { background-color: #FFB6C1; }
.normal-dot { background-color: #fff; }
.revival-dot { background-color: #f0f0f0; }

/* --- ハンバーガーメニュー (M-1仕様: 黒×金) --- */
.menu-container {
    display: flex;
    align-items: center;
    margin-right: 15px; /* タイトルとの間隔 */
}

.hamburger-btn {
    position: relative;
    z-index: 2000;
    width: 40px;
    height: 40px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 8px; /* 2本線の間隔 */
}

/* 2本線のスタイリッシュなデザイン */
.hamburger-btn span {
    display: block;
    width: 30px;
    height: 2px;
    background: linear-gradient(90deg, #ffd700, #ff8c00); /* ゴールドグラデーション */
    transition: all 0.4s ease;
}

.hamburger-btn:hover span {
    box-shadow: 0 0 8px rgba(255, 215, 0, 0.6);
}

/* メニュー展開時のボタン変化（×になる） */
.hamburger-btn.open span:nth-child(1) { transform: translateY(5px) rotate(45deg); }
.hamburger-btn.open span:nth-child(2) { transform: translateY(-5px) rotate(-45deg); }

/* メニュー本体（フェードイン・黒背景） */
.nav-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    background-color: rgba(20, 20, 20, 0.96); /* ほぼ不透明な黒 */
    z-index: 1999;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.nav-overlay.open {
    opacity: 1;
    visibility: visible;
}

.nav-list {
    list-style: none;
    padding: 0;
    text-align: center;
}

.nav-list li {
    margin: 25px 0;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.4s ease, transform 0.4s ease;
}

/* メニューが開いたときに時間差で項目を表示 */
.nav-overlay.open .nav-list li { opacity: 1; transform: translateY(0); }
.nav-overlay.open .nav-list li:nth-child(1) { transition-delay: 0.1s; }
.nav-overlay.open .nav-list li:nth-child(2) { transition-delay: 0.2s; }
.nav-overlay.open .nav-list li:nth-child(3) { transition-delay: 0.3s; }
.nav-overlay.open .nav-list li:nth-child(4) { transition-delay: 0.4s; }
.nav-overlay.open .nav-list li:nth-child(5) { transition-delay: 0.5s; }

.nav-list li a {
    text-decoration: none;
    color: #fff;
    font-size: 24px;
    font-family: 'Times New Roman', serif; /* M-1らしい明朝体系フォント */
    letter-spacing: 2px;
    display: block;
    transition: color 0.2s, text-shadow 0.2s;
}

.nav-list li a:hover {
    color: #ffd700;
    text-shadow: 0 0 15px rgba(255, 215, 0, 0.6);
}

.nav-list li a span {
    display: block;
    font-size: 12px;
    color: #888;
    margin-top: 5px;
    font-family: "Helvetica Neue", Arial, sans-serif;
    letter-spacing: 0;
}

.nav-divider {
    width: 40px;
    height: 1px;
    background-color: #444;
    margin: 20px auto;
}

/* --- マトリックスレイアウト --- */
.matrix-wrapper {
    flex-grow: 1;
    overflow: hidden;
    position: relative;
    display: flex;
    background-color: #fff;
}

.matrix-container {
    display: flex;
    width: 100%;
    height: 100%;
}

/* 左側固定：行ヘッダー全体 */
.row-headers {
    width: 110px;
    flex-shrink: 0;
    background-color: #fff;
    border-right: 2px solid #999;
    z-index: 20;
    box-shadow: 2px 0 5px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    height: 100%;
}

.row-header-static {
    height: var(--col-header-height);
    background-color: #e0e0e0;
    color: #333;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 12px;
    border-bottom: 2px solid #999;
    flex-shrink: 0;
    z-index: 25;
}

.row-header-mask {
    flex-grow: 1;
    flex-basis: 0;
    min-height: 0;
    overflow: hidden;
    position: relative;
    background-color: #fff;
}

#row-header-scroll-content { width: 100%; }

.row-header-item {
    display: flex;
    align-items: center;
    justify-content: center;
    border-bottom: 1px solid var(--border-color);
    font-size: 11px;
    font-weight: bold;
    color: #555;
    background-color: #fcfcfc;
    box-sizing: border-box;
    width: 100%;
}

.row-header-item.rank-row { height: var(--row-height); }
.row-header-item.judge-row { height: var(--judge-row-height); background-color: #444; color: var(--accent-color); }
.row-header-item.revival-row { 
    height: var(--revival-row-height); 
    background-color: #e8e8e8; 
    color: #333; 
    font-size: 10px; 
}
.spacer-row { height: var(--spacer-height); background-color: #ddd; border: none; }

/* 右側：スクロールエリア */
.matrix-scroll-area {
    flex-grow: 1;
    overflow: auto;
    position: relative;
    background-color: #f9f9f9;
}

.column-headers {
    display: flex;
    height: var(--col-header-height);
    position: sticky;
    top: 0;
    z-index: 10;
    background-color: #e0e0e0;
    width: max-content;
    border-bottom: 2px solid #999;
}

.column-header-item {
    width: var(--col-width);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-right: 1px solid #ccc;
    font-size: 12px;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.2s;
    background-color: #e0e0e0;
}
.column-header-item:hover { background-color: #d0d0d0; color: #000; }
.col-year { font-size: 14px; }
.col-edition { font-size: 10px; color: #666; }

.matrix-grid { display: flex; width: max-content; }
.grid-column { width: var(--col-width); border-right: 1px solid var(--border-color); flex-shrink: 0; }

.grid-cell {
    border-bottom: 1px solid var(--border-color);
    padding: 2px;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
}

.grid-cell.rank-cell { height: var(--row-height); }
.grid-cell.judge-row-cell { height: var(--judge-row-height); background-color: #f5f5f5; padding-top: 5px; align-items: flex-start; }
.grid-cell.revival-cell { height: var(--revival-row-height); background-color: #fcfcfc; padding: 0; }
.grid-cell.spacer-cell { height: var(--spacer-height); background-color: #f4f4f4; border-bottom: none; }
.grid-cell.no-border { border-bottom: none; background-color: transparent; }

.duo-panel {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-radius: 2px;
    cursor: pointer;
    font-size: 12px;
    font-weight: bold;
    text-align: center;
    background-color: #fff;
    border: 1px solid #e0e0e0;
    transition: all 0.1s;
    position: relative;
    overflow: hidden;
    color: #333;
}
.duo-panel.text-sm { font-size: 11px; }
.duo-panel.text-xs { font-size: 10px; }

.duo-panel:hover { transform: scale(1.05); box-shadow: 0 4px 8px rgba(0,0,0,0.2); z-index: 50; border-color: #999; }

.revival-cell .duo-panel {
    font-size: 10px;
    flex-direction: row;
    justify-content: space-between;
    padding: 0 5px;
    border: none;
    background: transparent;
}
.revival-cell .duo-panel span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.revival-cell .duo-score { display: none; }

.duo-score { font-size: 10px; font-weight: normal; margin-top: 1px; opacity: 0.7; }

.judge-tags {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    justify-content: center;
    gap: 1px;
    height: 100%;
    width: 100%;
    padding: 0 2px;
    box-sizing: border-box;
}
.judge-tag {
    writing-mode: vertical-rl;
    text-orientation: upright;
    font-size: 10px;
    background-color: #fff;
    border: 1px solid #ccc;
    padding: 4px 0;
    border-radius: 2px;
    cursor: pointer;
    color: #444;
    white-space: nowrap;
    height: 90%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    min-width: 0;
}
.judge-tag:hover { background-color: #333; color: #fff; border-color: #333; }

.dimmed { opacity: 0.1; pointer-events: none; filter: grayscale(100%); }

/* --- サイドバー --- */
/* Z-Indexを上げ、オーバーレイよりも手前に表示するよう修正 */
#details-sidebar {
    position: fixed; 
    top: 0; 
    right: -800px; 
    width: 800px; 
    height: 100%;
    background-color: #fff; 
    box-shadow: -5px 0 15px rgba(0,0,0,0.3);
    z-index: 2100; /* Ranking Modal(1000) > Global Overlay(2000) > Sidebar(2100) */
    transition: right 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex; 
    flex-direction: column;
}
#details-sidebar.open { right: 0; }

/* ヘッダーレイアウト修正：戻るボタン対応 */
.sidebar-header { 
    padding: 15px 20px; 
    background: #333; 
    color: #fff; 
    display: flex; 
    align-items: center; 
    flex-shrink: 0; 
    gap: 15px; /* 要素間の間隔 */
}

/* 戻るボタンのスタイル */
#sidebar-back-btn {
    background: none;
    border: 1px solid rgba(255,255,255,0.3);
    color: inherit;
    font-size: 14px;
    cursor: pointer;
    padding: 4px 10px;
    border-radius: 4px;
    display: none; /* JSで制御 */
    align-items: center;
    line-height: 1;
}
#sidebar-back-btn:hover {
    background-color: rgba(255,255,255,0.1);
}

/* タイトルを伸ばして閉じるボタンを右端へ */
#sidebar-title { 
    font-size: 18px; 
    margin: 0; 
    flex-grow: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#close-sidebar-btn { 
    background: none; 
    border: none; 
    color: inherit; 
    font-size: 28px; 
    cursor: pointer; 
    padding: 0;
    line-height: 1;
}

.sidebar-content { flex-grow: 1; overflow-y: auto; padding: 20px; font-size: 13px; line-height: 1.5; }

.duo-summary {
    background-color: #f8f9fa;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 15px;
    margin-bottom: 20px;
    display: flex;
    gap: 20px;
    align-items: center;
    font-size: 14px;
}
.summary-item strong { font-size: 18px; color: #d32f2f; margin-left: 5px; }

.history-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.history-table th, .history-table td { border: 1px solid #ccc; padding: 8px; vertical-align: middle; }
.history-table th { background-color: #e0e0e0; font-weight: bold; text-align: center; color: #333; white-space: nowrap; }
.history-table td.year-cell { text-align: center; font-weight: bold; background-color: #f9f9f9; width: 60px; }
.history-table td.result-cell { text-align: center; white-space: nowrap; width: 100px; }
.history-table td.detail-cell { text-align: left; font-size: 12px; }

/* 決勝進出（4位〜10位） */
.row-final { border-left: 5px solid #666; background-color: #fff; }
.row-final .result-cell { 
    font-weight: bold; 
    background-color: #f2f2f2; 
    color: #1976d2;
}

/* 準決勝・準々決勝など（予選） */
.row-revival { 
    background-color: #f4f8fb; 
    color: #333; 
}
.row-revival .result-cell { 
    font-weight: bold; 
    color: #333;
}

.row-winner { background-color: #fffbe0; border-left: 5px solid #FFD700; }
.row-winner .result-cell { 
    font-weight: bold; 
    color: #d4af37;
}
.row-rank-2 { border-left: 5px solid #A9A9A9; }
.row-rank-2 .result-cell { 
    font-weight: bold; 
    background-color: #dcdcdc;
    color: #757575;
}
.row-rank-3 { border-left: 5px solid #CD7F32; }
.row-rank-3 .result-cell { 
    font-weight: bold; 
    background-color: #fff0e0; 
    color: #cd7f32;
}

.row-qualifier { color: #777; background-color: #fff; font-size: 12px; }
.row-qualifier .result-cell { font-size: 11px; }

.mini-score-table {
    width: 100%; border-collapse: collapse; font-size: 11px; margin-top: 5px; background-color: #fff;
    table-layout: fixed;
}
.mini-score-table th, .mini-score-table td { padding: 4px 2px; text-align: center; border: 1px solid #ddd; width: 45px; overflow: hidden; white-space: nowrap; }
.mini-score-table th { background-color: #f0f0f0; }

.vote-badge { display: inline-block; padding: 2px 6px; background-color: #eee; border-radius: 4px; font-size: 11px; border: 1px solid #ccc; margin-top: 4px; }

.sidebar-controls {
    padding: 10px 0; margin-bottom: 10px; border-bottom: 1px solid #eee; display: flex; align-items: center; gap: 10px;
}
.sidebar-controls label { font-size: 12px; font-weight: bold; color: #555; }
.sort-btn {
    padding: 4px 10px; font-size: 12px; border: 1px solid #ccc; background: #fff; border-radius: 4px; cursor: pointer; transition: all 0.2s;
}
.sort-btn.active { background-color: #333; color: #fff; border-color: #333; }

.judge-matrix-table {
    border-collapse: collapse;
    font-size: 11px;
    margin-top: 10px;
    table-layout: fixed;
}
.judge-matrix-table thead th {
    position: sticky; top: 0; z-index: 10; background-color: #f5f5f5; height: 30px;
}
.judge-matrix-table tbody th.rank-header,
.judge-matrix-table thead th.rank-label-col {
    position: sticky; left: 0; z-index: 11; background-color: #f5f5f5; border-right: 2px solid #bbb; width: 60px; text-align: center;
}
.judge-matrix-table thead th.rank-label-col { z-index: 12; }

.judge-matrix-table th, .judge-matrix-table td {
    border: 1px solid #ddd; padding: 4px; text-align: center; vertical-align: middle; width: 100px; min-width: 100px; height: 50px;
}

.judge-cell-content { display: flex; flex-direction: column; justify-content: center; align-items: center; height: 100%; line-height: 1.2; }
.judge-duo-name { font-weight: bold; font-size: 10px; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 90px; }
.judge-duo-name.text-sm { font-size: 9px; }
.judge-score { font-size: 13px; font-weight: bold; }

.final-vote-marker { display: inline-block; margin-top: 2px; padding: 1px 4px; background-color: #ff9800; color: #fff; font-size: 9px; border-radius: 2px; line-height: 1; }
.score-high { color: #d32f2f; font-weight: bold; background-color: rgba(211, 47, 47, 0.03); }
.score-low { color: #1976d2; background-color: rgba(25, 118, 210, 0.03); }

/* オーバーレイ：ランキングモーダルより上位にするため z-index を 2000 に変更 */
#global-overlay {
    position: fixed; 
    inset: 0; 
    background: rgba(0,0,0,0.6);
    display: none; 
    z-index: 2000;
}
#global-overlay.open { display: block; }

/* ツールチップ：サイドバーより上位にするため z-index を 3000 に変更 */
#custom-tooltip {
    position: absolute; display: none; background: rgba(0,0,0,0.9); color: #fff;
    padding: 8px 12px; border-radius: 4px; font-size: 12px; z-index: 3000;
    pointer-events: none; white-space: pre-line; line-height: 1.4;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

.detail-table {
    width: 100%; border-collapse: collapse; margin-bottom: 20px; font-size: 13px; border: 1px solid #ddd; background-color: #fff;
}
.detail-table th {
    background-color: #f5f5f5; color: #333; font-weight: bold; padding: 10px 6px; text-align: center; border: 1px solid #ddd; white-space: nowrap; position: sticky; top: 0; z-index: 10; box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.detail-table td { padding: 8px 6px; text-align: center; border: 1px solid #ddd; vertical-align: middle; color: #333; }
.detail-table td:nth-child(2) { text-align: left; font-weight: bold; min-width: 130px; font-size: 13px; }
.detail-table td:nth-child(1) { font-weight: bold; color: #666; width: 40px; background-color: #fafafa; }
.detail-table td:nth-child(3) { font-weight: bold; background-color: #fcfcfc; }
.detail-table tr:first-child td { background-color: #fffde7; border-bottom: 1px solid #e6ce00; }
.detail-table tr:first-child td:nth-child(1) { background-color: #FFD700; color: #000; border: 1px solid #d4af37; }

/* --- ランキング・分析モーダル --- */
.header-btn {
    margin-right: 20px;
    padding: 6px 12px;
    background-color: #444;
    color: #fff;
    border: 1px solid #666;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    font-weight: bold;
    transition: background 0.2s;
}
.header-btn:hover { background-color: #666; }

/* ランキングモーダル：z-index 1000 */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.8);
    z-index: 1000; display: none; justify-content: center; align-items: center;
}
.modal-overlay.open { display: flex; }

.modal-container {
    width: 90%; height: 90%; background: #f4f4f4; border-radius: 8px;
    display: flex; flex-direction: column; overflow: hidden;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
}

.modal-header {
    background: #333; color: #fff; padding: 15px 20px;
    display: flex; justify-content: space-between; align-items: center;
}
.modal-header h2 { margin: 0; font-size: 18px; color: #f1c40f; }
.close-modal-btn { background: none; border: none; color: #fff; font-size: 28px; cursor: pointer; }

/* タブナビゲーション */
.modal-tabs {
    display: flex; background: #ddd; border-bottom: 1px solid #ccc;
}
.tab-btn {
    flex: 1; padding: 12px; border: none; background: #ddd; cursor: pointer;
    font-weight: bold; color: #666; font-size: 14px; transition: 0.2s;
}
.tab-btn:hover { background: #ccc; }
.tab-btn.active { background: #fff; color: #333; border-top: 3px solid #f1c40f; }

.modal-body {
    flex-grow: 1; overflow-y: auto; padding: 20px; background: #fff;
}
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ランキンググリッド */
.ranking-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 20px;
}

.ranking-card {
    background: #fff; border: 1px solid #ddd; border-radius: 4px; overflow: hidden;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}
.ranking-card-header {
    background: #333; color: #fff; padding: 10px; font-weight: bold; font-size: 13px; text-align: center;
}

.ranking-table {
    width: 100%; border-collapse: collapse; font-size: 12px;
}
.ranking-table th, .ranking-table td {
    padding: 6px 8px; border-bottom: 1px solid #eee; text-align: left;
}
.ranking-table th { background: #f9f9f9; font-weight: bold; color: #555; }
.ranking-table tr:nth-child(even) { background: #fcfcfc; }
.ranking-table tr:hover { background: #f0f0f0; }

.rank-num { width: 30px; text-align: center; font-weight: bold; color: #888; }
.rank-1 { color: #d4af37; font-size: 14px; } /* 金 */
.rank-2 { color: #a9a9a9; font-size: 13px; } /* 銀 */
.rank-3 { color: #cd7f32; font-size: 13px; } /* 銅 */

.rank-val { text-align: right; font-weight: bold; color: #333; }
.sub-val { font-size: 10px; color: #999; margin-left: 4px; }

.chart-grid {
    display: grid;
    grid-template-columns: 1fr 1fr; /* 2列 */
    gap: 20px;
    padding-bottom: 20px;
}
.chart-card {
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 15px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    height: 350px; /* 固定高さ */
    display: flex;
    flex-direction: column;
}
.chart-card h3 {
    margin: 0 0 10px 0;
    font-size: 14px;
    color: #333;
    text-align: center;
}
.chart-card canvas {
    flex-grow: 1;
}
/* スマホ等は1列に */
@media (max-width: 800px) {
    .chart-grid { grid-template-columns: 1fr; }
}