.swiss-component {
    font-family: Arial, "Microsoft JhengHei", sans-serif;
    margin: 14px 0 24px;
}

.swiss-title { margin: 0 0 6px; }
.swiss-meta { margin: 0 0 12px; color: #64748b; font-size: 13px; }
.swiss-subsection { margin: 12px 0 16px; }
.swiss-subhead { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.swiss-subhead h3,
.table-heading { margin: 0; color: #334155; font-size: 18px; }

.swiss-btn {
    display: inline-block;
    padding: 5px 10px;
    border: 1px solid #9fb8c8;
    border-radius: 7px;
    background: #fff;
    color: #245c78;
    font-weight: 700;
    text-decoration: none;
}
.swiss-btn:hover { background: #f2f8fb; }

.swiss-scroll { width: 100%; overflow-x: auto; }

.swiss-rank,
.swiss-cross,
.swiss-mini,
.game-list {
    border: 1px solid #d7e0e7;
    border-collapse: separate;
    border-spacing: 0;
    border-radius: 10px;
    overflow: hidden;
    background: #fff;
    box-shadow: 0 2px 10px rgba(31, 41, 55, .06);
    font-size: 14px;
    white-space: nowrap;
}

.swiss-rank th,
.swiss-cross th,
.swiss-mini th,
.game-list th {
    padding: 8px 10px;
    border-right: 1px solid #d7e0e7;
    border-bottom: 1px solid #cad7e0;
    background: #eaf3f8;
    color: #334155;
    font-weight: 700;
    text-align: center;
}

.swiss-rank td,
.swiss-cross td,
.swiss-mini td,
.game-list td {
    padding: 8px 10px;
    border-right: 1px solid #e3e9ee;
    border-bottom: 1px solid #e3e9ee;
    background: #fff;
    color: #263238;
    text-align: center;
}

.swiss-rank th:last-child,
.swiss-rank td:last-child,
.swiss-cross th:last-child,
.swiss-cross td:last-child,
.swiss-mini th:last-child,
.swiss-mini td:last-child,
.game-list th:last-child,
.game-list td:last-child { border-right: 0; }

.swiss-rank tbody tr:last-child td,
.swiss-cross tbody tr:last-child td,
.swiss-mini tbody tr:last-child td,
.game-list tbody tr:last-child td { border-bottom: 0; }

/* 戰績表不做整列 hover；交叉表完全不套用整列 hover，避免覆蓋固定斜線與儲存格語意底色。 */
.swiss-rank tbody tr:hover {
    background: transparent;
    box-shadow: none;
    filter: none;
}
.swiss-rank tbody tr:hover > td {
    background: #fff;
    box-shadow: none;
    filter: none;
}

.swiss-rank .name,
.swiss-cross .name,
.swiss-mini .text-left { text-align: left; }
.swiss-rank .rating,
.swiss-cross .rating,
.game-list .rating { font-weight: 700; }

.swiss-component .score-win { color: #287a3b; font-weight: 700; }
.swiss-component .score-draw { color: #8a6d00; font-weight: 700; }
.swiss-component .score-loss { color: #b3261e; font-weight: 700; }

.swiss-rank td.score-win,
.swiss-cross td.score-win,
.game-list td.score-win,
.swiss-rank tbody tr:hover > td.score-win { background: #e7f7d5; }

.swiss-rank td.score-draw,
.swiss-cross td.score-draw,
.game-list td.score-draw,
.swiss-rank tbody tr:hover > td.score-draw { background: #fff4c7; }

.swiss-rank td.score-loss,
.swiss-cross td.score-loss,
.game-list td.score-loss,
.swiss-rank tbody tr:hover > td.score-loss { background: #fbe4e4; }

.swiss-rank .total,
.swiss-cross .total,
.swiss-rank tbody tr:hover > td.total {
    background: #e6f0ff;
    color: #1565c0;
    font-size: 16px;
    font-weight: 800;
}

.swiss-rank .round-head,
.swiss-rank .total-head,
.swiss-cross .total-head { color: #1565c0; }
.swiss-rank .opponent { color: #111; font-weight: 600; }
.swiss-rank .opponent.opening { color: #c62828; }
.swiss-rank .place,
.swiss-cross .place { font-weight: 800; }

.swiss-component a {
    color: #2563a6;
    font-weight: 600;
    text-decoration: none;
}
.swiss-component a:hover {
    background: transparent;
    text-decoration: underline;
}

.cross-player {
    max-width: 110px;
    overflow: hidden;
    text-overflow: ellipsis;
}
/* 自己對自己的格子永遠顯示斜線，不再依賴 hover 背景。 */
.swiss-cross td.cross-self {
    position: relative;
    min-width: 44px;
    background: #f3f4f6;
}
.swiss-cross td.cross-self::after {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: linear-gradient(to top right, transparent 48%, #b7bec7 49%, #b7bec7 51%, transparent 52%);
}
.cross-result {
    position: relative;
    min-width: 44px;
    cursor: pointer;
}
.cross-result.pair-focus {
    z-index: 1;
    outline: 2px solid #f59e0b;
    outline-offset: -2px;
}
/* 交叉表對局 hover 時，自己的姓名與對手姓名一起以橘框標示。 */
.swiss-cross td.name.pair-name-focus {
    position: relative;
    z-index: 1;
    outline: 2px solid #f59e0b;
    outline-offset: -2px;
}
.opening-score { color: #c62828; font-weight: 800; }
.reply-score { color: #111; font-weight: 700; }
.cross-sep { margin: 0 2px; color: #94a3b8; }

.game-result {
    color: #2563a6;
    font-size: 16px;
    font-weight: 800;
}
.game-result a {
    color: inherit;
    font-size: inherit;
    font-weight: inherit;
}

.swiss-empty { padding: 8px 0; color: #64748b; font-size: 13px; }
.inline-delete { display: inline; }
.link-danger {
    padding: 0;
    border: 0;
    background: none;
    color: #b42318;
    cursor: pointer;
    font: inherit;
    text-decoration: underline;
}

.help-head {
    position: relative;
    cursor: help;
    text-decoration-line: underline;
    text-decoration-style: dotted;
    text-decoration-thickness: 1px;
    text-decoration-color: #78909c;
    text-underline-offset: 4px;
}
.help-mark { display: none; }
.swiss-tooltip {
    position: fixed;
    z-index: 99999;
    max-width: 430px;
    padding: 9px 11px;
    border-radius: 8px;
    background: #263238;
    color: #fff;
    box-shadow: 0 4px 18px rgba(0, 0, 0, .22);
    font-size: 13px;
    line-height: 1.5;
    pointer-events: none;
    white-space: pre-line;
}

.swiss-form {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin: 14px 0;
}
.swiss-form input,
.swiss-form select,
.swiss-edit input,
.swiss-edit select {
    padding: 7px 9px;
    border: 1px solid #bdcbd5;
    border-radius: 6px;
    background: #fff;
}
.swiss-form button,
.swiss-edit button {
    padding: 7px 12px;
    border: 1px solid #9fb8c8;
    border-radius: 7px;
    background: #fff;
    cursor: pointer;
}
.swiss-edit { max-width: 1000px; }
.swiss-edit table { width: 100%; border-collapse: collapse; }
.swiss-edit th,
.swiss-edit td { padding: 7px; border-bottom: 1px solid #e5e7eb; text-align: left; }
.swiss-edit .actions { display: flex; gap: 8px; margin-top: 14px; }
.swiss-edit .primary { background: #245c78; color: #fff; }
.den-score { color: #1565c0; font-weight: 800; }

/* 輪次分數與對手欄採固定緊湊寬度。 */
.swiss-rank th.round-head,
.swiss-rank th.opponent-head,
.swiss-rank td.round-score,
.swiss-rank td.opponent {
    box-sizing: border-box;
    width: 46px;
    min-width: 46px;
    max-width: 46px;
    padding-right: 5px;
    padding-left: 5px;
}
.swiss-rank td.round-score {
    color: #1565c0;
    font-size: 16px;
    font-weight: 800;
}
.swiss-rank td.opponent { font-size: 14px; }
.swiss-game-cell,
.swiss-summary-cell { cursor: pointer; }

/* 一般輔分來源仍以橘框標示。 */
.swiss-rank td.swiss-focus {
    position: relative;
    z-index: 2;
    outline: 2px solid #f59e0b;
    outline-offset: -2px;
}
.swiss-rank td.round-score.swiss-focus {
    outline: 0;
    border-right-color: transparent;
    box-shadow:
        inset 2px 0 #f59e0b,
        inset 0 2px #f59e0b,
        inset 0 -2px #f59e0b;
}
.swiss-rank td.opponent.swiss-focus {
    outline: 0;
    box-shadow:
        inset -2px 0 #f59e0b,
        inset 0 2px #f59e0b,
        inset 0 -2px #f59e0b;
}

/*
 * 對局互動：
 * - 滑鼠所在棋手：姓名＋「分數／對手」為綠框。
 * - 對手：姓名＋對應「分數／對手」為橘框。
 * - 點一下固定後，滑鼠所在棋手的綠框改為藍框；對手仍保留橘框。
 */
.swiss-rank td.swiss-game-primary { --swiss-game-frame: #16a34a; }
.swiss-rank td.swiss-game-primary.swiss-game-primary-pinned { --swiss-game-frame: #2563eb; }
.swiss-rank td.swiss-game-opponent { --swiss-game-frame: #f59e0b; }

.swiss-rank td.swiss-game-primary,
.swiss-rank td.swiss-game-opponent {
    position: relative;
    z-index: 3;
    outline: 0;
}
.swiss-rank td.name.swiss-game-primary,
.swiss-rank td.name.swiss-game-opponent {
    box-shadow: inset 0 0 0 2px var(--swiss-game-frame);
}
.swiss-rank td.round-score.swiss-game-primary,
.swiss-rank td.round-score.swiss-game-opponent {
    border-right-color: transparent;
    box-shadow:
        inset 2px 0 var(--swiss-game-frame),
        inset 0 2px var(--swiss-game-frame),
        inset 0 -2px var(--swiss-game-frame);
}
.swiss-rank td.opponent.swiss-game-primary,
.swiss-rank td.opponent.swiss-game-opponent {
    box-shadow:
        inset -2px 0 var(--swiss-game-frame),
        inset 0 2px var(--swiss-game-frame),
        inset 0 -2px var(--swiss-game-frame);
}

/* 可點擊總分／輔分／升段分：懸停時來源分數與本列姓名為綠框，固定時改為藍框。 */
.swiss-rank td.swiss-summary-anchor {
    position: relative;
    z-index: 3;
    outline: 2px solid #16a34a;
    outline-offset: -2px;
}
.swiss-rank td.swiss-summary-anchor.swiss-summary-pinned {
    outline-color: #2563eb;
}

/* 輔分互動視覺化。 */
.swiss-rank td.swiss-hover-source,
.swiss-rank tbody tr:hover > td.swiss-hover-source { background: #e7f7d5; }
.swiss-rank td.swiss-hover-result.score-win,
.swiss-rank tbody tr:hover > td.swiss-hover-result.score-win { background: #e7f7d5; }
.swiss-rank td.swiss-hover-result.score-draw,
.swiss-rank tbody tr:hover > td.swiss-hover-result.score-draw { background: #fff4c7; }
.swiss-rank td.swiss-hover-result.score-loss,
.swiss-rank tbody tr:hover > td.swiss-hover-result.score-loss { background: #fbe4e4; }

@media (max-width: 768px) {
    .swiss-rank,
    .swiss-cross,
    .swiss-mini,
    .game-list { font-size: 13px; }

    .swiss-rank th,
    .swiss-rank td,
    .swiss-cross th,
    .swiss-cross td,
    .swiss-mini th,
    .swiss-mini td,
    .game-list th,
    .game-list td { padding: 7px 8px; }

    .help-head { cursor: pointer; }
}
