/* ============================================================
   まーじゃんふぁいと苦愛 カラーパレット
   ロゴの深緑×金色をベースにした麻雀卓テーマ
   ここの変数を変えると全体の配色が変わる
============================================================ */
:root {
    color-scheme: light;            /* 全ブラウザでライトモードに統一       */
    --mj-bg:              #F7F4EE;  /* ページ背景：温かみのある象牙白      */
    --mj-header-bg:       #1B3A27;  /* テーブルヘッダー背景：麻雀卓の深緑  */
    --mj-header-text:     #fff;      /* ヘッダーテキスト：白                */
    --mj-summary-bg:      #FEF0C7;  /* 集計行背景：薄金                    */
    --mj-btn-primary:     #1C5C38;  /* 期間フィルターボタン：濃緑           */
    --mj-btn-secondary:   #1C5C38;  /* 列順・グラフ・ナビボタン：濃緑（期間ボタンに統一） */
    --mj-btn-active-text: #C9A84C;  /* アクティブボタンのテキスト：金色     */
    --mj-negative:        #C0392B;  /* マイナス値テキスト色                 */
    --mj-link:            #1C5C38;  /* テーブル内リンク色                   */
}

/* ページ背景（viewport全体を象牙白で統一） */
html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    overflow-x: hidden;
}
html {
    background-color: var(--mj-bg);
    background-attachment: fixed;
    height: 100%;
}
body {
    background-color: var(--mj-bg);
}

/* ============================================================
   ボタン配色
   btn-outline-primary  → 期間フィルター
   btn-outline-secondary → 列順・グラフ種別・ナビ
============================================================ */
.btn-outline-primary {
    --bs-btn-color:               var(--mj-btn-primary);
    --bs-btn-border-color:        var(--mj-btn-primary);
    --bs-btn-hover-color:         #fff;
    --bs-btn-hover-bg:            var(--mj-btn-primary);
    --bs-btn-hover-border-color:  var(--mj-btn-primary);
    --bs-btn-active-color:        var(--mj-btn-active-text);
    --bs-btn-active-bg:           var(--mj-btn-primary);
    --bs-btn-active-border-color: var(--mj-btn-primary);
    --bs-btn-disabled-color:      var(--mj-btn-primary);
    --bs-btn-disabled-border-color: var(--mj-btn-primary);
}
.btn-outline-secondary {
    --bs-btn-color:               var(--mj-btn-secondary);
    --bs-btn-border-color:        var(--mj-btn-secondary);
    --bs-btn-hover-color:         #fff;
    --bs-btn-hover-bg:            var(--mj-btn-secondary);
    --bs-btn-hover-border-color:  var(--mj-btn-secondary);
    --bs-btn-active-color:        var(--mj-btn-active-text);
    --bs-btn-active-bg:           var(--mj-btn-secondary);
    --bs-btn-active-border-color: var(--mj-btn-secondary);
    --bs-btn-disabled-color:      var(--mj-btn-secondary);
    --bs-btn-disabled-border-color: var(--mj-btn-secondary);
}

/* リサイズ後にオリジナルtheadがはみ出して見えるのを防ぐ
   表示用クローンは .dt-scroll-head 側にあるので
   .dt-scroll-body 内のオリジナルは常に非表示で問題ない */
.dt-scroll-body thead {
    display: none !important;
}

/* DataTables が生成するスクロールラッパーの上余白をなくす */
.mt-4 {
    margin-top: 0 !important;
}
.dt-scroll-wrapper {
    margin-top: 0 !important;
}

.justify-content-between {
    display: none !important;
}

.mt-2 {
    margin-top: calc(-1 * var(--bs-gutter-y)) !important;
}

/* データ行・集計行のセル上下余白を詰める */
#gameTable td,
#gameTable th,
.dt-scroll-head th {
    padding-top: 0.15rem !important;
    padding-bottom: 0.15rem !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
    font-size: 0.8rem;
}

/* テーブルヘッダー配色（麻雀卓の深緑×金色）＋中央寄せ */
#gameTable thead th,
#analysisTable thead th,
#detailTable thead th,
#eloTable thead th,
.dt-scroll-head th,
.dt-scroll-headInner th,
.dtfc-cloned thead th {
    background-color: var(--mj-header-bg) !important;
    color:            var(--mj-header-text) !important;
/*    border-color:     var(--mj-header-bg) !important;*/
    text-align:       center !important;
}

/* テーブル内のゲーム番号リンク */
#gameTable td a {
    color: var(--mj-link);
}

/* マイナス値 */
.negative {
    color: var(--mj-negative);
}

/* 期間・列順・グラフボタン共通：折り返し時に伸長しない・全ボタン幅統一 */
.period-group > .btn,
.colsort-group > .btn,
.graph-group > .btn {
    flex: 0 0 auto !important;
    min-width: 4.5em;
    padding-left: 0.2rem !important;
    padding-right: 0.2rem !important;
}

/* スマホ横画面時は左右paddingを詰める */
@media (max-width: 900px) and (orientation: landscape) {
    body {
        padding-left: 0.25rem !important;
        padding-right: 0.25rem !important;
    }
}

/* .active クラスがついていないボタンは押されても見た目を変えない */
.btn-outline-primary:not(.active):active,
.btn-outline-secondary:not(.active):active {
    background-color: transparent;
    color: var(--bs-btn-color);
    border-color: var(--bs-btn-border-color);
    box-shadow: none;
}

/* 順位/点数の縦並び・折り返し禁止 */
.player-cell { white-space: nowrap; line-height: 1.6; }

/* プレイヤー列（3列目以降）の幅をCSSで強制統一する
   DataTables の columnDefs だけだと「-」セルが縮んでしまうため */
#gameTable td:nth-child(n+3),
.dt-scroll-head th:nth-child(n+3),
.dt-scroll-headInner th:nth-child(n+3),
.dtfc-cloned td:nth-child(n+3),
.dtfc-cloned th:nth-child(n+3) {
    min-width: 70px;
    width: 70px;
}

/* # 列と開催日列も明示しておく（PC: 0.8rem基準） */
#gameTable td:nth-child(1),
.dt-scroll-head th:nth-child(1),
.dtfc-cloned td:nth-child(1),
.dtfc-cloned th:nth-child(1) {
    min-width: 40px;
    width: 40px;
}
#gameTable td:nth-child(2),
.dt-scroll-head th:nth-child(2),
.dtfc-cloned td:nth-child(2),
.dtfc-cloned th:nth-child(2) {
    min-width: 68px;
    width: 68px;
}
/* スマホ時（0.72rem基準）: フォントサイズと列幅を縮小 */
@media (max-width: 480px) {
    #gameTable td,
    #gameTable th,
    .dt-scroll-head th {
        font-size: 0.72rem !important;
    }
    #gameTable td:nth-child(1),
    .dt-scroll-head th:nth-child(1),
    .dtfc-cloned td:nth-child(1),
    .dtfc-cloned th:nth-child(1) {
        min-width: 36px !important;
        width: 36px !important;
    }
    #gameTable td:nth-child(2),
    .dt-scroll-head th:nth-child(2),
    .dtfc-cloned td:nth-child(2),
    .dtfc-cloned th:nth-child(2) {
        min-width: 62px !important;
        width: 62px !important;
    }
}

/* ヘッダーのプレイヤーリンク */
.player-link { text-decoration: none; }
.player-link:hover { text-decoration: underline; }

/* 開催日リンク（bydate.htmlへ） */
.date-link { color: inherit; text-decoration: none; }
.date-link:hover { text-decoration: underline; }

/* DataTables のページング・検索などの余分UIを非表示 */
.dataTables_filter,
.dataTables_length,
.dataTables_info,
.dataTables_paginate { display: none !important; }

/* グラフ選択行ハイライト（本体 + FixedColumns クローン両方に適用） */
tr.graph-highlight > td,
.dtfc-cloned tr.graph-highlight > td {
    background-color: var(--mj-summary-bg) !important;
}

/* 集計行のスタイル（本体 + FixedColumns クローン両方に適用） */
tr.summary-row > td,
.dtfc-cloned tr.summary-row > td {
    background-color: var(--mj-summary-bg) !important;
    font-weight: bold;
}

/* 集計行の「平均順位 / 合計点数」セルは右寄せ */
tr.summary-row > td.summary-label,
.dtfc-cloned tr.summary-row > td.summary-label {
    text-align: right;
    padding: 0;
    line-height: 1.6;
}

/* DataTables が生成するスクロール領域の高さ調整 */
.dataTables_scrollBody {
    max-height: calc(100vh - 220px) !important;
}

/* 詳細テーブル：マトリクスレイアウト */
#detailTable > :not(:first-child) {
    border-top-color: var(--mj-header-bg) !important;
}
#detailTable {
    table-layout: fixed;
    width:        100%;
}
#detailTable .detail-label-col {
    width: 6.5rem;
}
#detailTable thead th {
    font-size: 0.8rem;
}
#detailTable tbody .detail-label-col {
    background-color: var(--mj-header-bg);
    color:            var(--mj-header-text);
    text-align:       right !important;
    font-size:        0.8rem;
    white-space:      nowrap;
    font-weight:      normal;
    padding-right:    0.6rem !important;
}

/* テーブル背景をページ背景色に統一（タスク1） */
#gameTable,
#analysisTable,
#detailTable,
#eloTable {
    --bs-table-bg: var(--mj-bg);
}

/* 期間/列順/グラフ ラベル幅を統一（タスク10） */
.section-label {
    display: inline-block;
    width: 3em;
    text-align: justify;
    text-align-last: justify;
}

/* ============================================================
   画像グリッド・ライトボックス
============================================================ */

/* グリッドレイアウト */
.img-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 8px;
}

/* 正方形のサムネイル */
.img-grid-item {
    position: relative;
    aspect-ratio: 1;
    cursor: pointer;
    overflow: hidden;
    border-radius: 4px;
}
.img-grid-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* 選択モードのチェックマークバッジ */
.img-grid-item.selected::after {
    content: '✓';
    position: absolute;
    top: 4px;
    right: 4px;
    background: var(--mj-btn-primary);
    color: #fff;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    line-height: 22px;
    text-align: center;
    font-size: 14px;
}

/* ライトボックス */
.lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}
.lightbox.d-none {
    display: none !important;
}
.lightbox img {
    max-width: 95vw;
    max-height: 95vh;
    object-fit: contain;
}
.lightbox-close {
    position: absolute;
    top: 12px;
    right: 16px;
    background: none;
    border: none;
    color: #fff;
    font-size: 2rem;
    line-height: 1;
    cursor: pointer;
    padding: 0;
}

/* 確認ダイアログ */
.confirm-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
}
.confirm-overlay.d-none {
    display: none !important;
}
.confirm-box {
    background: #fff;
    border-radius: 8px;
    padding: 1.5rem;
    max-width: 280px;
    width: 90%;
    text-align: center;
}

/* ============================================================
   管理者用: 対局追加テーブル
============================================================ */
#addTable th,
#addTable td {
    padding: 0.3rem !important;
    vertical-align: middle;
}
#addTable .rank-input {
    display: block;
    width: 54px;
    padding: 0.2rem;
    text-align: center;
    font-size: 0.8rem;
    margin-bottom: 0.25rem;
}
#addTable .points-input {
    display: block;
    width: 68px;
    padding: 0.2rem;
    text-align: center;
    font-size: 0.8rem;
}
#addTable .player-select {
    min-width: 80px;
    font-size: 0.8rem;
}

/* ============================================================
   パスポートカード (player.html)
============================================================ */
.passport-card {
    border: 2px solid var(--mj-header-bg);
    border-radius: 6px;
    overflow: hidden;
    max-width: 580px;
    margin: 0 auto;
    background: #fff;
    box-shadow: 0 2px 12px rgba(0,0,0,0.12);
}
.passport-header {
    background: var(--mj-header-bg);
    color: #fff;
    padding: 0.45rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.passport-header-title {
    font-size: 0.85rem;
    font-weight: bold;
    letter-spacing: 0.08em;
}
.passport-header-sub {
    font-size: 0.65rem;
    letter-spacing: 0.06em;
    opacity: 0.85;
}
.passport-body {
    display: flex;
    gap: 1rem;
    padding: 1rem;
    align-items: flex-start;
}
.passport-photo {
    flex: 0 0 100px;
    width: 100px;
    height: 100px;
    object-fit: cover;
    object-position: center;
    border: 1px solid #ccc;
    display: block;
    background: #e8e8e8;
    align-self: center;
}
.avatar-wrap {
    flex: 0 0 100px;
    position: relative;
    cursor: pointer;
    align-self: center;
}
.avatar-wrap .passport-photo {
    flex: none;
}
.avatar-upload-hint {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.45);
    color: #fff;
    font-size: 0.7rem;
    text-align: center;
    padding: 2px 0;
    opacity: 0;
    transition: opacity 0.2s;
}
.avatar-wrap:hover .avatar-upload-hint {
    opacity: 1;
}
.passport-info {
    flex: 1;
    min-width: 0;
}
.passport-field {
    padding: 0.2rem 0;
    border-bottom: 1px solid #e0d8cc;
}
.passport-field:last-child {
    border-bottom: none;
}
.passport-field-label {
    font-size: 0.58rem;
    color: #999;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    line-height: 1.2;
}
.passport-field-value {
    font-size: 0.88rem;
    font-weight: bold;
    line-height: 1.4;
}
.passport-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.1rem 0.5rem;
}
.passport-stats-3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 0.1rem 0.5rem;
}
.passport-stats-3 > div {
    display: flex;
    flex-direction: column;
}
.passport-stats-3 > div .passport-field-value {
    margin-top: auto;
}
.passport-footer {
    border-top: 2px solid var(--mj-header-bg);
    padding: 0.75rem 1rem;
    background: #fafaf8;
}
.passport-footer-label {
    font-size: 0.58rem;
    color: #999;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    margin-bottom: 0.25rem;
}
/* スマホ：写真と情報を縦並び */
@media (max-width: 380px) {
    .passport-body {
        flex-direction: column;
        align-items: center;
    }
}

/* ============================================================
   ハンバーガーメニュー
============================================================ */
.nav-page-title {
    font-size: 0.95rem;
    font-weight: bold;
    color: #444;
}
.hamburger-btn {
    background: none;
    border: 1px solid var(--mj-btn-secondary);
    border-radius: 4px;
    padding: 0.35rem 0.5rem;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 5px;
    flex-shrink: 0;
}
.hamburger-btn span {
    display: block;
    width: 22px;
    height: 2px;
    background: var(--mj-btn-secondary);
    border-radius: 1px;
}
.hamburger-wrap {
    position: relative;
}
.hamburger-menu {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    min-width: 192px;
    border: 1px solid #ccc;
    border-radius: 6px;
    background: #fff;
    box-shadow: 0 4px 14px rgba(0,0,0,0.12);
    overflow: hidden;
    transform: translateX(110%);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.25s ease, opacity 0.2s ease;
    z-index: 1000;
}
.hamburger-menu.is-open {
    transform: translateX(0);
    opacity: 1;
    pointer-events: auto;
}
.hamburger-menu-item {
    display: block;
    padding: 0.7rem 1.2rem;
    text-decoration: none;
    color: var(--mj-btn-secondary);
    font-size: 0.95rem;
    border-bottom: 1px solid #f0ede8;
}
.hamburger-menu-item:last-child {
    border-bottom: none;
}
.hamburger-menu-item:hover {
    background: var(--mj-bg);
}
.hamburger-menu-item.active {
    background: var(--mj-btn-primary);
    color: var(--mj-btn-active-text);
    font-weight: bold;
}

/* ============================================================
   プレイヤー一覧グリッド (players.html)
============================================================ */
.players-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(480px, 1fr));
    gap: 1.5rem;
}
.passport-card-link {
    text-decoration: none;
    color: inherit;
    display: block;
}
.passport-card-link:hover .passport-card {
    box-shadow: 0 4px 20px rgba(0,0,0,0.18);
    transition: box-shadow 0.15s;
}
@media (max-width: 540px) {
    .players-grid {
        grid-template-columns: 1fr;
    }
}

/* ============================================================
   対戦相手別グラフ (player.html)
============================================================ */
.vs-table {
    --bs-table-bg: var(--mj-bg);
}

.vs-bar-wrap {
    display: flex;
    align-items: center;
    height: 12px;
}
.vs-bar-half {
    flex: 1;
    overflow: hidden;
    display: flex;
}
.vs-bar-left  { justify-content: flex-end; }
.vs-bar-right { justify-content: flex-start; }
.vs-bar-divider {
    width: 1px;
    height: 12px;
    background: #aaa;
    flex-shrink: 0;
}
.vs-bar-fill {
    height: 8px;
    border-radius: 2px;
}

/* ============================================================
   イロレーティングテーブル (elo.html)
============================================================ */
.elo-bar-pos { background-color: var(--mj-btn-primary); }
.elo-bar-neg { background-color: var(--mj-negative); }

#eloTable th,
#eloTable td {
    padding-top:    0.3rem !important;
    padding-bottom: 0.3rem !important;
    font-size: 0.88rem;
}
#eloTable .elo-col-id    { width: 56px; min-width: 56px; }
#eloTable .elo-col-name  { width: 150px; min-width: 120px; text-align: left; white-space: nowrap; }
#eloTable .elo-col-games { width: 54px; min-width: 54px; white-space: nowrap; }
#eloTable .elo-col-val  { width: 60px; min-width: 60px; text-align: right; padding-right: 0.5rem !important; font-variant-numeric: tabular-nums; }
#eloTable .elo-col-bar  { padding-left: 0.4rem !important; padding-right: 0.6rem !important; }
#eloTable .player-link  { color: #222; font-weight: bold; }

/* ============================================================
   ルールページ
============================================================ */
.rules-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    max-width: 780px;
    margin: 0 auto;
}
.rules-card {
    border: 1px solid #c8d8cc;
}
.rules-card-header {
    background-color: var(--mj-header-bg);
    color: var(--mj-header-text);
    font-weight: bold;
    font-size: 0.9rem;
    padding: 0.4rem 0.75rem;
}
.rules-card .list-group-item {
    background-color: transparent;
    font-size: 0.85rem;
    padding: 0.35rem 0.75rem;
    border-color: #e0ece4;
}
/* 特殊ルールカードは2列分の幅に */
.rules-card-wide {
    grid-column: 1 / -1;
}
@media (max-width: 540px) {
    .rules-grid {
        grid-template-columns: 1fr;
    }
    .rules-card-wide {
        grid-column: auto;
    }
}

