/* Tournament Tool Styles (Unified with League UI & Bracket Fixed) */

.setup-card, .bracket-card {
    margin-bottom: 2rem;
    animation: fadeIn 0.4s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* --- DashBoard / Root List Style (League-like UI) --- */
.root-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1.5rem;
    margin-top: 1.5rem;
}

.tournament-card {
    padding: 1.25rem;
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    transition: all 0.2s;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    box-shadow: var(--shadow-sm);
    border-left: 4px solid var(--primary);
}

.tournament-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
    border-color: var(--primary);
}

.card-header {
    font-size: 0.8rem;
    color: var(--text-muted);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-title {
    font-weight: bold;
    font-size: 1.1rem;
    margin: 0;
    color: var(--text-main);
}

.card-summary {
    font-size: 0.85rem;
    color: var(--text-muted);
    background: var(--bg-muted);
    padding: 0.6rem;
    border-radius: var(--radius-sm);
    border: 1px dashed var(--border-color);
}

.card-footer {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

/* Status Badges */
.status-badge {
    padding: 0.15rem 0.6rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
}
.status-setup { background: #f1f5f9; color: #64748b; }
.status-active { background: #dcfce7; color: #15803d; }
.status-finished { background: #e0f2fe; color: #0369a1; }


/* --- Bracket System Style (Detailed View) --- */
.bracket-card {
    width: 100%;
    overflow-x: auto; /* Ensure horizontal scroll for large brackets */
    padding: 1.5rem;
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
}

.bracket-container {
    display: flex;
    min-width: max-content; /* Prevent squashing */
    padding-bottom: 2rem;
    align-items: center; /* Center champion vertically with final match */
}

.bracket {
    display: flex;
    flex-direction: row;
    gap: 0;
    flex-shrink: 0;
}

.round {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    width: 220px;
    margin-right: 40px;
    flex-shrink: 0;
}

.match {
    display: flex;
    flex-direction: column;
    justify-content: center;
    position: relative;
    margin: 15px 0;
    min-height: 100px; /* Ensure enough height for connections */
}

/* Connectors */
.match::after {
    content: '';
    position: absolute;
    right: -20px;
    top: 50%;
    width: 20px;
    height: 2px;
    background-color: var(--border-color);
}

.match::before {
    content: '';
    position: absolute;
    right: -20px;
    top: 50%;
    bottom: -50%;
    width: 2px;
    background-color: var(--border-color);
}

.match:nth-child(even)::before {
    top: -50%;
    bottom: 50%;
}

/* Hide lines for last round and special cases */
.round:last-child .match::after,
.final-round .match::after,
.champion-match::after,
.seed-match::before,
.final-round .match::before,
.champion-match::before {
    display: none !important;
}

.match-team {
    padding: 0.6rem;
    background-color: var(--bg-color);
    border: 1px solid var(--border-color);
    font-size: 0.95rem;
    font-weight: 500;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    margin: 1px 0;
    position: relative;
    z-index: 2;
}

.match-team.winner {
    background-color: var(--primary);
    color: white;
    border-color: var(--primary);
    font-weight: bold;
}

.match-team:hover:not(.winner):not(.empty) {
    background-color: var(--bg-muted);
    border-color: var(--primary);
}

.match-team.empty {
    background-color: var(--bg-muted);
    color: var(--text-muted);
    font-style: italic;
    cursor: default;
}

/* --- Match List for Scoring (Below Bracket) --- */
#tournament-matches-panel {
    animation: fadeIn 0.4s ease-out;
}

.round-section {
    margin-bottom: 2rem;
}

.round-header {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--bg-muted);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.matches-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1.25rem;
}

.match-card {
    padding: 1rem;
    background-color: var(--bg-muted);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    transition: all 0.2s;
    position: relative;
}

.match-card:hover {
    box-shadow: var(--shadow-sm);
    border-color: var(--primary);
    background-color: var(--card-bg);
}

.match-card-header {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
    display: flex;
    justify-content: space-between;
}

.match-card-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.match-card-team {
    width: 140px; /* Fixed width to ensure visibility */
    flex-shrink: 0;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.match-card-team.winner-name {
    color: var(--primary);
}

.match-card-score {
    width: 60px;
    text-align: center;
    padding: 0.4rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background-color: var(--card-bg);
    font-weight: 700;
    color: var(--text-main);
}

.match-card-memo-preview {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px dashed var(--border-color);
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    line-clamp: 3; /* Added for standard compatibility */
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.match-card-score:focus {
    border-color: var(--primary);
    outline: none;
}

.match-card-memo-btn {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.9rem;
    opacity: 0.5;
    transition: opacity 0.2s;
}

.match-card-memo-btn:hover {
    opacity: 1;
}

.match-card-memo-btn.has-memo {
    opacity: 1;
    color: var(--primary);
}

/* Champion View */
#tournament-bracket-champion {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: 20px;
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: none; /* Changed: Default hidden */
    align-items: center;
    justify-content: center;
    z-index: 2000;
    backdrop-filter: blur(2px);
}

.modal:not(.hidden) {
    display: flex; /* Display only when not hidden */
}

.modal-content {
    width: 90%;
    max-width: 450px;
    padding: 1.5rem;
    animation: slideInModal 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

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

/* Print Styles */
@media print {
    #header-area, .bracket-controls, app-header, app-footer, .btn-outline, .btn-primary, .card-footer, .match-card-memo-btn, #tournament-matches-panel { display: none !important; }
    .bracket-card { border: none; box-shadow: none; padding: 0; width: 100%; border-radius: 0; }
    body { background: white; }
    .bracket-container { min-width: auto; }
}