/**
 * Tournament Show Page Styles
 * Extracted from show.php for better maintainability
 */

/* ============================================
   対戦結果マトリックス表のスタイル
   ============================================ */
.matrix-table {
    border-collapse: collapse;
    font-size: 0.75rem;
    width: 100%;
    margin-top: 1rem;
}
.matrix-table th,
.matrix-table td {
    border: 1px solid var(--border-color);
    padding: 0.35rem;
    text-align: center;
    min-width: 40px;
}
.matrix-table th {
    background: var(--bg-glass);
    font-weight: 600;
}
.matrix-table .team-header {
    text-align: left;
    min-width: 80px;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.matrix-table .diagonal {
    background: var(--bg-glass);
    color: var(--text-muted);
}
.matrix-table .result-win {
    background: rgba(34, 197, 94, 0.15);
    color: var(--success);
    font-weight: 600;
}
.matrix-table .result-lose {
    background: rgba(239, 68, 68, 0.15);
    color: var(--danger);
}
.matrix-table .result-draw {
    background: rgba(234, 179, 8, 0.15);
    color: #fbbf24;
}
.matrix-table .result-pending {
    color: var(--text-muted);
}
.matrix-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.matrix-section {
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}
.matrix-section h4 {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

/* ============================================
   カテゴリカードのスタイル
   ============================================ */
.category-card-link {
    text-decoration: none;
    color: inherit;
    display: block;
}

.category-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1.25rem;
    background: var(--bg-glass);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    transition: all var(--transition-fast);
}

.category-card:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-glow);
}

.category-card-icon {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    border-radius: var(--radius);
    color: white;
    font-size: 1.25rem;
    flex-shrink: 0;
}

.category-card-content {
    flex: 1;
    min-width: 0;
}

.category-card-title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.category-card-meta {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.category-card-arrow {
    color: var(--text-muted);
    transition: all var(--transition-fast);
}

.category-card:hover .category-card-arrow {
    color: var(--primary);
    transform: translateX(4px);
}

/* ============================================
   リーグブロック縦配置レイアウト
   ============================================ */

.league-blocks-vertical {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.league-block-section {
    background: var(--bg-glass);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    border: 1px solid var(--border-color);
}

.block-header {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 1.25rem;
    padding-bottom: 0.75rem;
    border-bottom: 2px solid var(--primary);
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.block-edit-btn-wrapper {
    flex-shrink: 0;
}

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
}

.btn-outline:hover {
    background: var(--hover-bg);
    border-color: var(--primary);
    color: var(--primary);
}

.block-content-row {
    display: flex;
    flex-direction: row;
    gap: 2rem;
    align-items: flex-start;
}

.match-results-section {
    flex: 1;
    min-width: 300px;
    max-width: 450px;
}

.standings-section {
    flex: 1;
    min-width: 400px;
}

.section-subtitle {
    font-size: 0.9rem;
    margin-bottom: 0.75rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.section-subtitle i {
    margin-right: 0.5rem;
}

.rank-confirmed-badge {
    margin-top: 0.75rem;
    padding: 0.5rem;
    background: rgba(34, 197, 94, 0.1);
    border-radius: var(--radius-sm);
    text-align: center;
}

.rank-confirmed-badge span {
    color: var(--success);
    font-size: 0.875rem;
}

/* レスポンシブ: タブレット以下で縦配置 */
@media (max-width: 900px) {
    .block-content-row {
        flex-direction: column;
    }

    .match-results-section,
    .standings-section {
        min-width: 100%;
        max-width: 100%;
    }
}

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

.horizontal-bracket-container {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    padding: 2rem 1rem;
    overflow-x: auto;
    gap: 0;
    position: relative;
}

/* ラウンド */
.horizontal-round {
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.horizontal-round-header {
    text-align: center;
    margin-bottom: 1rem;
    flex-shrink: 0;
}

.round-label {
    display: inline-block;
    padding: 0.5rem 1.5rem;
    background: var(--bg-glass);
    border-radius: var(--radius-full);
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.champion-label {
    background: linear-gradient(135deg, #ffd700 0%, #ffaa00 100%);
    color: #000;
}

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

/* 試合エリア - Flexboxで均等配置 */
.horizontal-matches {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    flex: 1;
    min-height: 400px;
}

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

/* 試合ボックス */
.horizontal-match {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    min-width: 160px;
    overflow: hidden;
    transition: all var(--transition-fast);
}

.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.2) 0%, transparent 100%);
    border-left: 3px solid var(--success);
}

.horizontal-team.winner .h-team-name {
    color: var(--success);
    font-weight: 600;
}

.match-divider {
    height: 1px;
    background: var(--border-color);
}

.h-seed {
    font-size: 0.625rem;
    color: var(--text-muted);
    padding: 2px 5px;
    background: var(--bg-glass);
    border-radius: var(--radius-sm);
    flex-shrink: 0;
}

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

.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: 24px;
    text-align: center;
    padding: 0.25rem 0.5rem;
    background: var(--bg-glass);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
}

/* ラウンド間の接続 - SVG方式 */
.round-connector {
    min-width: 60px;
    flex-shrink: 0;
}

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

/* SVGコネクタを配置するためのコンテナ */
.connector-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.connector-svg line {
    stroke: var(--border-color);
    stroke-width: 2;
}

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

.connector-line-horizontal {
    width: 100%;
    height: 2px;
    background: var(--border-color);
}

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

.champion-line {
    background: linear-gradient(90deg, var(--border-color) 0%, #ffd700 100%);
}

/* 優勝者ボックス */
.champion-box {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 2rem;
    background: linear-gradient(135deg, rgba(255, 215, 0, 0.2) 0%, rgba(255, 170, 0, 0.1) 100%);
    border: 2px solid #ffd700;
    border-radius: var(--radius-xl);
    animation: glow 2s ease-in-out infinite;
}

.champion-box i {
    font-size: 1.5rem;
    color: #ffd700;
}

.champion-name {
    font-size: 1.25rem;
    font-weight: 700;
    background: linear-gradient(135deg, #ffd700 0%, #ffaa00 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* 画像ダウンロード時のオーバーライド */
.champion-name.download-override {
    background: none !important;
    -webkit-background-clip: unset !important;
    -webkit-text-fill-color: inherit !important;
    background-clip: unset !important;
}

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

/* 各ラウンドの高さを統一 */
.horizontal-round .horizontal-matches {
    min-height: 500px;
}

/* ============================================
   対戦結果リスト
   ============================================ */

.match-results-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.match-result-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    padding: 0.75rem;
    background: var(--bg-glass);
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
}

.match-result-row:hover {
    background: rgba(255, 255, 255, 0.08);
}

.match-result-row.completed {
    border-left: 3px solid var(--primary);
}

.match-meta {
    width: 100%;
    display: flex;
    gap: 0.75rem;
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    flex-wrap: wrap;
}

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

.match-meta .match-datetime,
.match-meta .match-venue {
    display: flex;
    align-items: center;
}

.match-team {
    flex: 1;
    font-size: 0.875rem;
}

.match-team.home {
    text-align: right;
    padding-right: 0.75rem;
}

.match-team.away {
    text-align: left;
    padding-left: 0.75rem;
}

.match-team.winner {
    color: var(--success);
    font-weight: 600;
}

.match-score {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 80px;
    justify-content: center;
}

.match-score .score {
    font-weight: 700;
    font-size: 1rem;
    min-width: 24px;
    text-align: center;
}

.match-score .score-separator {
    color: var(--text-muted);
}

.match-score .vs {
    color: var(--text-muted);
    font-size: 0.75rem;
}

/* ============================================
   3位決定戦 セクション
   ============================================ */
.third-place-section {
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 2px dashed var(--border-color);
}

.third-place-header {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.third-place-header i {
    color: #cd7f32; /* ブロンズ色 */
}

.third-place-match {
    display: flex;
    justify-content: center;
}

.third-place-match .horizontal-match {
    min-width: 280px;
    max-width: 350px;
}

/* ============================================
   デザイン選択時のハイライト
   ============================================ */
.design-option:hover {
    border-color: var(--primary) !important;
    background: var(--bg-glass) !important;
}
.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);
}
.league-design-option input[type="radio"]:checked + .design-preview {
    box-shadow: 0 0 0 3px var(--primary);
}
.league-design-option input[type="radio"]:checked ~ .design-name {
    color: var(--primary);
}

/* ============================================
   スコア編集ボタン
   ============================================ */
.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,
.match-result-row:hover .match-edit-btn {
    opacity: 1;
}

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

/* ============================================
   スコア入力モーダル
   ============================================ */
.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: #1e293b;
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 400px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    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;
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.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;
}

/* ============================================
   Animations
   ============================================ */
@keyframes glow {
    0%, 100% { box-shadow: 0 0 20px rgba(255, 215, 0, 0.3); }
    50% { box-shadow: 0 0 30px rgba(255, 215, 0, 0.5); }
}

/* ============================================
   Responsive - Tablet
   ============================================ */
@media (max-width: 768px) {
    .horizontal-bracket-container {
        padding: 1rem 0.5rem;
    }

    .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;
    }

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

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

    .match-team {
        font-size: 0.75rem;
    }

    .match-score .score {
        font-size: 0.875rem;
    }
}

/* ============================================
   Responsive - Mobile
   ============================================ */
@media (max-width: 500px) {
    .design-options {
        grid-template-columns: 1fr !important;
    }
}

@media (max-width: 480px) {
    .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;
    }
}
