/**
 * bracket.php用スタイル
 * トーナメント表表示のスタイル定義
 */

/* ============================================
   横型トーナメント表（左から右へ）
   ============================================ */

.horizontal-bracket-card {
    padding: 0;
    overflow-x: auto;
}

/* ヘッダー行（すべてのラベルを横一列に配置） */
.bracket-header-row {
    display: flex;
    flex-direction: row;
    align-items: center;
    padding: 1.5rem 1rem 0.5rem 1rem;
    min-width: fit-content;
    gap: 0;
}

.header-cell {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.round-header-cell {
    min-width: 160px;
    width: 180px;
}

.connector-header-cell {
    width: 60px;
}

.champion-header-cell {
    min-width: 160px;
}

/* コンテンツ行 */
.horizontal-bracket-container {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    padding: 0.5rem 1rem 2rem 1rem;
    min-width: fit-content;
    gap: 0;
}

/* ラウンド */
.horizontal-round {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex-shrink: 0;
    min-width: 160px;
    width: 180px;
}

.horizontal-round .horizontal-matches {
    flex: 1;
}

/* 試合エリア */
.horizontal-matches {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    flex: 1;
    gap: 0;
}

.round-label {
    display: inline-block;
    padding: 0.5rem 1.5rem;
    background: #334155;
    border-radius: var(--radius-full);
    font-weight: 600;
    color: #e2e8f0;
    font-size: 0.875rem;
    border: 1px solid #475569;
}

.champion-label {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    color: #ffffff;
    border: none;
    font-weight: 700;
}

.champion-label i {
    margin-right: 0.5rem;
}

.horizontal-match-wrapper {
    display: flex;
    flex-direction: row;
    align-items: center;
    position: relative;
}

/* 試合ボックス */
.horizontal-match {
    position: relative;
    background: var(--bg-card);
    border: 3px solid #64748b;
    border-radius: var(--radius-lg);
    min-width: 160px;
    overflow: hidden;
    transition: all var(--transition-fast);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.horizontal-match:hover {
    transform: scale(1.02);
    box-shadow: var(--shadow-glow);
    border-color: var(--primary);
}

/* チーム行 */
.horizontal-team {
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    gap: 0.5rem;
    transition: all var(--transition-fast);
}

.horizontal-team.winner {
    background: linear-gradient(90deg, rgba(34, 197, 94, 0.4) 0%, rgba(34, 197, 94, 0.1) 100%);
    border-left: 4px solid #22c55e;
}

.horizontal-team.winner .h-team-name {
    color: #22c55e;
    font-weight: 700;
}

.match-divider {
    height: 2px;
    background: #64748b;
}

.h-seed {
    font-size: 0.625rem;
    color: var(--text-secondary);
    padding: 2px 6px;
    background: rgba(100, 116, 139, 0.3);
    border-radius: var(--radius-sm);
    flex-shrink: 0;
    font-weight: 600;
}

.h-team-name {
    flex: 1;
    font-size: 0.875rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 500;
}

.h-team-name .tbd {
    color: var(--text-muted);
    font-style: italic;
}

/* 1回戦TBD非表示用 */
.hidden-match {
    display: none !important;
}

.empty-team .h-team-name {
    /* チーム未設定時はスペースを維持しつつ空表示 */
    min-height: 1em;
}

.h-score {
    font-weight: 700;
    min-width: 28px;
    text-align: center;
    padding: 0.25rem 0.5rem;
    background: rgba(100, 116, 139, 0.3);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    border: 1px solid #64748b;
}

/* ラウンド間の接続 */
.round-connector {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    width: 60px;
    flex-shrink: 0;
}

.connector-group {
    display: flex;
    align-items: center;
}

.connector-merge {
    position: relative;
    width: 60px;
    height: 80px;
}

.merge-line-top,
.merge-line-bottom {
    position: absolute;
    right: 0;
    width: 20px;
    height: 4px;
    background: #cbd5e1;
}

.merge-line-top {
    top: 0;
}

.merge-line-bottom {
    bottom: 0;
}

.merge-line-center {
    position: absolute;
    right: 0;
    top: 0;
    width: 4px;
    height: 100%;
    background: #cbd5e1;
}

/* 右への接続線 */
.connector-right {
    display: flex;
    align-items: center;
    width: 20px;
}

.connector-line-horizontal {
    width: 100%;
    height: 4px;
    background: #cbd5e1;
}

/* 左からの接続線 */
.connector-left {
    display: flex;
    align-items: center;
    width: 20px;
}

.champion-line {
    background: linear-gradient(90deg, #cbd5e1 0%, #f59e0b 100%);
    height: 4px;
}

/* 優勝者ボックス */
.champion-box {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 2rem;
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.3) 0%, rgba(217, 119, 6, 0.2) 100%);
    border: 3px solid #f59e0b;
    border-radius: var(--radius-xl);
    animation: glow 2s ease-in-out infinite;
    box-shadow: 0 4px 15px rgba(245, 158, 11, 0.4);
}

.champion-box i {
    font-size: 1.75rem;
    color: #d97706;
}

.champion-name {
    font-size: 1.25rem;
    font-weight: 700;
    color: #b45309;
}

/* 優勝ラウンド */
.champion-round {
    margin-left: 0;
}

/* ラウンドごとの高さ調整（effective-gapを使用） */
.horizontal-round[data-effective-gap="1"] .horizontal-matches {
    gap: 0.5rem;
}

.horizontal-round[data-effective-gap="2"] .horizontal-matches {
    gap: 2rem;
}

.horizontal-round[data-effective-gap="3"] .horizontal-matches {
    gap: 5rem;
}

.horizontal-round[data-effective-gap="4"] .horizontal-matches {
    gap: 10rem;
}

/* 1→1接続用ストレートコネクタ */
.round-connector-straight {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    width: 60px;
    flex-shrink: 0;
}

/* effective-gapに応じたストレートコネクタのgap */
.round-connector-straight[data-effective-gap="1"] {
    gap: 0.5rem;
}

.round-connector-straight[data-effective-gap="2"] {
    gap: 2rem;
}

.round-connector-straight[data-effective-gap="3"] {
    gap: 5rem;
}

.round-connector-straight[data-effective-gap="4"] {
    gap: 10rem;
}

.connector-group-straight {
    display: flex;
    align-items: center;
    height: auto;
}

.connector-straight-line {
    width: 100%;
    height: 4px;
    background: #cbd5e1;
}

/* レスポンシブ */
@media (max-width: 768px) {
    .bracket-header-row {
        padding: 1rem 0.5rem 0.5rem 0.5rem;
    }

    .round-header-cell {
        min-width: 130px;
        width: 150px;
    }

    .connector-header-cell {
        width: 40px;
    }

    .horizontal-bracket-container {
        padding: 0.5rem 0.5rem 1rem 0.5rem;
    }

    .horizontal-round {
        min-width: 130px;
        width: 150px;
    }

    .horizontal-match {
        min-width: 130px;
    }

    .horizontal-team {
        padding: 0.5rem 0.75rem;
    }

    .h-team-name {
        font-size: 0.75rem;
    }

    .h-score {
        font-size: 0.75rem;
        min-width: 20px;
    }

    .champion-box {
        padding: 0.75rem 1.5rem;
    }

    .champion-name {
        font-size: 1rem;
    }

    .round-connector {
        width: 40px;
    }

    .round-connector-straight {
        width: 40px;
    }

    .connector-merge {
        width: 40px;
        height: 60px;
    }

    .merge-line-top,
    .merge-line-bottom {
        width: 15px;
    }
}

@media (max-width: 480px) {
    .bracket-header-row {
        flex-direction: column;
        gap: 0.5rem;
    }

    .header-cell {
        width: 100%;
    }

    .connector-header-cell {
        display: none;
    }

    .horizontal-bracket-container {
        flex-direction: column;
        align-items: stretch;
    }

    .horizontal-round {
        width: 100%;
    }

    .horizontal-matches {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
    }

    .horizontal-match {
        min-width: 100%;
        max-width: 280px;
    }

    .round-connector {
        display: none;
    }

    .connector-right,
    .connector-left {
        display: none;
    }

    .horizontal-round[data-round] .horizontal-matches {
        gap: 1rem;
    }
}

/* 印刷用 */
@media print {
    .horizontal-bracket-card {
        background: white;
        border: 1px solid #ddd;
    }

    .horizontal-match {
        border: 1px solid #333;
    }

    .connector-line-horizontal,
    .merge-line-top,
    .merge-line-bottom,
    .merge-line-center {
        background: #333;
    }
}

/* アニメーション */
@keyframes glow {
    0%, 100% {
        box-shadow: 0 0 10px rgba(255, 215, 0, 0.3);
    }
    50% {
        box-shadow: 0 0 20px rgba(255, 215, 0, 0.5);
    }
}

/* ============================================
   ライトモード対応
   ============================================ */
[data-theme="light"] .horizontal-match {
    background: #ffffff;
    border: 3px solid #334155;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

[data-theme="light"] .horizontal-match:hover {
    border-color: var(--primary);
    box-shadow: 0 4px 12px rgba(0, 51, 160, 0.25);
}

[data-theme="light"] .horizontal-team.winner {
    background: linear-gradient(90deg, rgba(22, 163, 74, 0.3) 0%, rgba(22, 163, 74, 0.1) 100%);
    border-left: 4px solid #16a34a;
}

[data-theme="light"] .horizontal-team.winner .h-team-name {
    color: #15803d;
    font-weight: 700;
}

[data-theme="light"] .h-team-name {
    color: #1e293b;
    font-weight: 500;
}

[data-theme="light"] .h-score {
    background: #e2e8f0;
    color: #0f172a;
    border: 2px solid #475569;
    font-weight: 700;
}

[data-theme="light"] .h-seed {
    background: #cbd5e1;
    color: #475569;
    font-weight: 600;
}

[data-theme="light"] .match-divider {
    background: #334155;
    height: 2px;
}

[data-theme="light"] .round-label {
    background: #e2e8f0;
    color: #0f172a;
    border: 2px solid #334155;
    font-weight: 600;
}

[data-theme="light"] .champion-label {
    background: linear-gradient(135deg, #ea580c 0%, #c2410c 100%);
    color: #ffffff;
    font-weight: 700;
}

[data-theme="light"] .champion-box {
    background: linear-gradient(135deg, rgba(234, 88, 12, 0.25) 0%, rgba(194, 65, 12, 0.2) 100%);
    border: 3px solid #ea580c;
    box-shadow: 0 4px 15px rgba(234, 88, 12, 0.4);
}

[data-theme="light"] .champion-box i {
    color: #c2410c;
}

[data-theme="light"] .champion-name {
    color: #9a3412;
    font-weight: 700;
}

[data-theme="light"] .connector-line-horizontal,
[data-theme="light"] .merge-line-top,
[data-theme="light"] .merge-line-bottom,
[data-theme="light"] .merge-line-center,
[data-theme="light"] .connector-straight-line {
    background: #000000;
}

[data-theme="light"] .champion-line {
    background: linear-gradient(90deg, #000000 0%, #ea580c 100%);
}

/* ============================================
   スコア編集ボタンと試合情報
   ============================================ */
.match-edit-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 24px;
    height: 24px;
    padding: 0;
    border: none;
    background: rgba(59, 130, 246, 0.8);
    color: #fff;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.7rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    z-index: 10;
    opacity: 0;
}

.horizontal-match:hover .match-edit-btn {
    opacity: 1;
}

.match-edit-btn:hover {
    background: rgba(59, 130, 246, 1);
    transform: scale(1.1);
}

.match-info-row {
    display: flex;
    gap: 0.5rem;
    padding: 0.25rem 0.5rem;
    background: rgba(100, 116, 139, 0.2);
    font-size: 0.65rem;
    color: var(--text-muted);
    flex-wrap: wrap;
}

.match-info-row i {
    margin-right: 2px;
}

.match-datetime,
.match-venue {
    display: flex;
    align-items: center;
    gap: 2px;
}

[data-theme="light"] .match-info-row {
    background: rgba(100, 116, 139, 0.15);
}

/* ============================================
   スコア入力モーダル
   ============================================ */
.score-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: 1rem;
}

.score-modal {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 400px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    animation: modalSlideIn 0.2s ease-out;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.score-modal-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.score-modal-header h3 {
    margin: 0;
    font-size: 1rem;
}

.score-modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.25rem;
    padding: 0;
    line-height: 1;
}

.score-modal-close:hover {
    color: var(--text-primary);
}

.score-modal-body {
    padding: 1.5rem;
}

.score-input-group {
    margin-bottom: 1rem;
}

.score-input-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.score-input-group input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 1rem;
}

.score-teams-row {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
}

.score-team-col {
    flex: 1;
    text-align: center;
}

.score-team-name {
    font-weight: 600;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.score-team-col input[type="number"] {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid var(--border-color);
    border-radius: var(--radius);
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 1.5rem;
    font-weight: 700;
    text-align: center;
}

.score-vs {
    display: flex;
    align-items: flex-end;
    padding-bottom: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
}

.result-type-group {
    margin-bottom: 1rem;
    padding: 1rem;
    background: var(--bg-glass);
    border-radius: var(--radius);
}

.result-type-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.result-type-options {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.result-type-options label {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    cursor: pointer;
    padding: 0.5rem 0.75rem;
    background: var(--bg-input);
    border-radius: var(--radius);
    font-size: 0.8rem;
    border: 1px solid var(--border-color);
    transition: all 0.2s;
}

.result-type-options label:hover {
    border-color: var(--primary);
}

.result-type-options input[type="radio"] {
    margin: 0;
}

.extra-scores-section {
    margin-top: 1rem;
    padding: 1rem;
    background: rgba(59, 130, 246, 0.1);
    border-radius: var(--radius);
    border: 1px dashed var(--primary);
}

.extra-scores-section h4 {
    margin: 0 0 0.75rem 0;
    font-size: 0.875rem;
    color: var(--primary);
}

.score-modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
}

.score-modal-footer .btn {
    min-width: 100px;
}

.score-error-message {
    color: var(--danger);
    font-size: 0.8rem;
    margin-top: 0.5rem;
    display: none;
}

.score-error-message.show {
    display: block;
}

[data-theme="light"] .score-modal {
    background: #ffffff;
}

/* ============================================
   デザイン選択モーダル用スタイル
   ============================================ */
.design-options {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

@media (max-width: 500px) {
    .design-options {
        grid-template-columns: 1fr;
    }
}

.design-option {
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0.75rem;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-lg);
    transition: all 0.2s;
    background: var(--bg-card);
}

.design-option:hover {
    border-color: var(--primary);
    background: var(--bg-glass);
}

.design-option input[type="radio"] {
    display: none;
}

.design-option input[type="radio"]:checked + .design-preview {
    box-shadow: 0 0 0 3px var(--primary);
}

.design-option input[type="radio"]:checked ~ .design-name {
    color: var(--primary);
    font-weight: 700;
}

.design-preview {
    width: 100%;
    height: 80px;
    border-radius: var(--radius);
    padding: 0.5rem;
    margin-bottom: 0.5rem;
    transition: all 0.2s;
}

.preview-header {
    font-size: 0.6rem;
    padding: 0.2rem 0.5rem;
    border-radius: 20px;
    display: inline-block;
    margin-bottom: 0.3rem;
}

.preview-match {
    background: rgba(255,255,255,0.1);
    border-radius: 4px;
    padding: 0.25rem;
}

.preview-team {
    font-size: 0.55rem;
    padding: 0.15rem 0.3rem;
    white-space: nowrap;
}

.preview-team.winner {
    font-weight: 700;
}

.design-name {
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 0.25rem;
}

.design-desc {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-align: center;
}

/* プレビュー - ライト */
.design-preview-light {
    background: #f1f5f9;
}
.design-preview-light .preview-header {
    background: #e2e8f0;
    color: #0f172a;
    border: 1px solid #334155;
}
.design-preview-light .preview-match {
    background: #ffffff;
    border: 2px solid #334155;
}
.design-preview-light .preview-team {
    color: #1e293b;
}
.design-preview-light .preview-team.winner {
    color: #15803d;
    background: linear-gradient(90deg, rgba(22, 163, 74, 0.2) 0%, transparent 100%);
}

/* プレビュー - ダーク */
.design-preview-dark {
    background: #0f172a;
}
.design-preview-dark .preview-header {
    background: #334155;
    color: #e2e8f0;
    border: 1px solid #475569;
}
.design-preview-dark .preview-match {
    background: #1e293b;
    border: 2px solid #64748b;
}
.design-preview-dark .preview-team {
    color: #e2e8f0;
}
.design-preview-dark .preview-team.winner {
    color: #22c55e;
    background: linear-gradient(90deg, rgba(34, 197, 94, 0.3) 0%, transparent 100%);
}

/* プレビュー - ブルー */
.design-preview-blue {
    background: linear-gradient(135deg, #1e3a5f 0%, #0c4a6e 100%);
}
.design-preview-blue .preview-header {
    background: #0ea5e9;
    color: #ffffff;
}
.design-preview-blue .preview-match {
    background: rgba(255,255,255,0.95);
    border: 2px solid #0284c7;
}
.design-preview-blue .preview-team {
    color: #0c4a6e;
}
.design-preview-blue .preview-team.winner {
    color: #0369a1;
    background: linear-gradient(90deg, rgba(14, 165, 233, 0.3) 0%, transparent 100%);
}

/* プレビュー - グリーン */
.design-preview-green {
    background: linear-gradient(135deg, #15803d 0%, #166534 100%);
    background-image:
        linear-gradient(rgba(255,255,255,0.05) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255,255,255,0.05) 1px, transparent 1px),
        linear-gradient(135deg, #15803d 0%, #166534 100%);
    background-size: 8px 8px, 8px 8px, 100% 100%;
}
.design-preview-green .preview-header {
    background: #fbbf24;
    color: #1e293b;
}
.design-preview-green .preview-match {
    background: rgba(255,255,255,0.95);
    border: 2px solid #15803d;
}
.design-preview-green .preview-team {
    color: #166534;
}
.design-preview-green .preview-team.winner {
    color: #b45309;
    background: linear-gradient(90deg, rgba(251, 191, 36, 0.3) 0%, transparent 100%);
}

/* クレジット表示用 */
.bracket-credit {
    display: none;
    text-align: center;
    padding: 0.75rem;
    font-size: 0.75rem;
    border-top: 1px solid var(--border-color);
    margin-top: 1rem;
}

.bracket-credit-inner {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-muted);
}

.bracket-credit-inner i {
    color: var(--primary);
}
