/* ============================================
   Ghost Battle — 幽靈對戰（與過往紀錄競速）
   Palette: ghost = 琥珀金（最佳紀錄）, me = 主題藍 #365A92
   ============================================ */
:root {
    --gb-ghost: #f0a72e;
    --gb-ghost-deep: #b97a14;
    --gb-ghost-soft: rgba(240, 167, 46, 0.12);
    --gb-ghost-border: rgba(240, 167, 46, 0.45);
    /* "me" follows the active theme accent; ghost (gold) stays its own identity */
    --gb-me: var(--theme-accent, #365A92);
    --gb-me-light: var(--theme-accent, #5D84C1);
    --gb-me-soft: rgba(54, 90, 146, 0.14);
    --gb-wrong: #ef5350;
    --gb-ahead-bg: rgba(34, 197, 94, 0.15);
    --gb-ahead-fg: #16a34a;
    --gb-behind-bg: rgba(239, 83, 80, 0.12);
    --gb-behind-fg: #d43c39;
    --gb-surface: #fff;
    --gb-surface-alt: #f6f8fa;
    --gb-text: #444;
    --gb-text-sub: #999;
    --gb-divider: rgba(240, 167, 46, 0.25);
    --gb-shadow: rgba(0, 0, 0, 0.18);
}

body.fcj-dark {
    --gb-surface: #232834;
    --gb-surface-alt: #1c2029;
    --gb-text: #dde2ea;
    --gb-text-sub: #8b93a2;
    --gb-shadow: rgba(0, 0, 0, 0.5);
}

/* 幽靈目前位置標記（逐字）：金色虛線框 + 漂浮幽靈徽章（與使用者 current 指示並存） */
.char.ghost-current {
    position: relative;
    outline: 2px dashed var(--gb-ghost);
    outline-offset: -1px;
    border-radius: 4px;
    background-color: var(--gb-ghost-soft);
}

.char.ghost-current::after {
    content: "👻";
    position: absolute;
    top: -13px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 12px;
    line-height: 1;
    z-index: 5;
    pointer-events: none;
    animation: ghost-bob-badge 1.2s ease-in-out infinite;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.35));
}

/* 線上對戰：對手是真人，徽章改用閃電（與統計列／圖表的 ⚡ 一致），非幽靈 */
#app.online-battle-active .char.ghost-current::after {
    content: "⚡";
}

/* 徽章需保留水平置中位移 */
@keyframes ghost-bob-badge {
    0%, 100% { transform: translateX(-50%) translateY(0); }
    50% { transform: translateX(-50%) translateY(-3px); }
}

@keyframes ghost-bob {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-3px); }
}

/* 對戰中的「我」目前字元：實心主題藍 + 光暈，與琥珀色幽靈標記明確區分。
   僅限英文模式：倉頡／速成的字元堆疊（拆碼＋字）對 .char.current 的背景／定位
   敏感，套用此標記會造成換行位移，故只在 #article.english 啟用。空白字排除。 */
#app.ghost-battle-active #article.english .char.current:not(.space) {
    position: relative;
    z-index: 6;
    background: var(--gb-me) !important;
    border-radius: 5px;
    box-shadow: 0 0 0 2px rgba(93, 132, 193, 0.95), 0 0 14px rgba(93, 132, 193, 0.85);
    animation: ghost-my-char-pulse 1.1s ease-in-out infinite;
}

#app.ghost-battle-active #article.english .char.current:not(.space) .text,
#app.ghost-battle-active #article.english .char.current:not(.space) .code,
#app.ghost-battle-active #article.english .char.current:not(.space) {
    color: #fff !important;
}

@keyframes ghost-my-char-pulse {
    0%, 100% { box-shadow: 0 0 0 2px rgba(93, 132, 193, 0.95), 0 0 14px rgba(93, 132, 193, 0.85); }
    50% { box-shadow: 0 0 0 2px rgba(93, 132, 193, 0.95), 0 0 22px rgba(93, 132, 193, 1); }
}

/* 幽靈軌跡：只標示幽靈打錯的字（紅色底條），打對不留痕跡 */
.char.ghost-trail-wrong {
    box-shadow: inset 0 -3px 0 rgba(239, 83, 80, 0.70);
    border-radius: 2px;
}

/* 統計列幽靈狀態 */
.ghost-battle-stat {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.ghost-battle-stat-icon {
    color: var(--gb-ghost);
    font-size: 14px;
    margin-right: 2px;
    animation: ghost-bob 1.2s ease-in-out infinite;
}

.ghost-battle-stat-wpm {
    color: var(--gb-ghost-deep) !important;
}

.ghost-battle-stat-status {
    font-size: 12px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
    background-color: var(--gb-ghost-soft);
    color: var(--gb-ghost-deep);
    white-space: nowrap;
}

.ghost-battle-stat-status.ghost-battle-ahead {
    background-color: var(--gb-ahead-bg);
    color: var(--gb-ahead-fg);
}

.ghost-battle-stat-status.ghost-battle-behind {
    background-color: var(--gb-behind-bg);
    color: var(--gb-behind-fg);
}

/* ============================================
   即時對戰統計面板
   ============================================ */
#ghost-battle-panel {
    position: fixed;
    right: 16px;
    top: 76px;
    width: 232px;
    background: var(--gb-surface);
    border: 1px solid var(--gb-ghost-border);
    border-radius: 10px;
    box-shadow: 0 4px 16px var(--gb-shadow);
    z-index: 60;
    font-size: 13px;
    overflow: hidden;
    user-select: none;
}

#ghost-battle-panel.collapsed {
    width: auto;
    min-width: 150px;
}

.ghost-battle-panel-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: linear-gradient(135deg, rgba(240, 167, 46, 0.16), rgba(240, 167, 46, 0.05));
    cursor: pointer;
}

.ghost-battle-panel-title {
    font-weight: 700;
    color: var(--gb-ghost-deep);
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.ghost-battle-panel-status {
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
    background-color: var(--gb-ghost-soft);
    color: var(--gb-ghost-deep);
    white-space: nowrap;
    margin-left: auto;
}

.ghost-battle-panel-status.ghost-battle-ahead {
    background-color: var(--gb-ahead-bg);
    color: var(--gb-ahead-fg);
}

.ghost-battle-panel-status.ghost-battle-behind {
    background-color: var(--gb-behind-bg);
    color: var(--gb-behind-fg);
}

.ghost-battle-panel-chevron {
    color: var(--gb-ghost);
    font-size: 14px;
}

.ghost-battle-panel-body {
    padding: 8px 12px 10px;
}

.ghost-battle-panel-row {
    display: grid;
    grid-template-columns: 1fr 56px 56px;
    align-items: center;
    padding: 3px 0;
}

.ghost-battle-panel-head-row {
    font-size: 11px;
    color: var(--gb-text-sub);
    border-bottom: 1px solid var(--gb-divider);
    padding-bottom: 4px;
    margin-bottom: 2px;
}

.ghost-battle-panel-label {
    color: var(--gb-text-sub);
}

.ghost-battle-panel-me,
.ghost-battle-panel-ghost {
    text-align: right;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.ghost-battle-panel-me {
    color: var(--gb-me);
}

.ghost-battle-panel-ghost {
    color: var(--gb-ghost-deep);
}

.ghost-battle-panel-leading {
    position: relative;
}

.ghost-battle-panel-leading::after {
    content: "▲";
    font-size: 9px;
    margin-left: 3px;
    color: var(--gb-ahead-fg);
}

.ghost-battle-panel-progress {
    margin-top: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.ghost-battle-panel-progress-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.ghost-battle-panel-progress-label {
    width: 22px;
    font-size: 11px;
    color: var(--gb-text-sub);
    text-align: center;
}

.ghost-battle-panel-progress-track {
    flex: 1;
    height: 8px;
    border-radius: 4px;
    background: rgba(125, 125, 125, 0.15);
    overflow: hidden;
}

.ghost-battle-panel-progress-bar {
    height: 100%;
    border-radius: 4px;
    transition: width 0.15s linear;
}

.ghost-battle-panel-progress-bar-me {
    background: linear-gradient(90deg, var(--gb-me), var(--gb-me-light));
}

.ghost-battle-panel-progress-bar-ghost {
    background: var(--gb-ghost);
}

/* 對戰進行中：改為頁首下方的水平統計列 */
#ghost-battle-panel.ghost-live-horizontal {
    top: 88px;
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    width: auto;
    max-width: 96vw;
    border-radius: 12px;
}

/* 統計列為 fixed 定位，文章需讓出高度避免被遮住。
   （空間在 armed 階段就保留，開打時不會位移） */
#app.ghost-battle-active #article-container-wrapper {
    margin-top: 64px;
}

/* 倉頡／速成且字詞提示開啟時，第一行上方的字詞圖卡（絕對定位、
   高出字行約 106px）需要更多空間才不會被統計列蓋住 */
#app.ghost-battle-active.word-tooltips-active:has(#article.cangjie) #article-container-wrapper {
    margin-top: 110px;
}

#ghost-battle-panel.ghost-live-horizontal .ghost-battle-panel-header {
    display: none;
}

#ghost-battle-panel.ghost-live-horizontal .ghost-battle-panel-body {
    padding: 10px 22px;
}

.ghost-live-strip {
    display: flex;
    align-items: center;
    gap: 22px;
    white-space: nowrap;
}

.ghost-live-strip-icon {
    color: var(--gb-ghost);
    font-size: 21px;
    animation: ghost-bob 1.2s ease-in-out infinite;
}

.ghost-live-strip .ghost-battle-panel-status {
    font-size: 13.5px;
    padding: 4px 12px;
    border-radius: 12px;
}

.ghost-live-group {
    display: inline-flex;
    align-items: baseline;
    gap: 5px;
}

.ghost-live-label {
    font-size: 13px;
    color: var(--gb-text-sub);
}

.ghost-live-me {
    color: var(--gb-me);
    font-size: 19px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.ghost-live-ghost {
    color: var(--gb-ghost-deep);
    font-size: 19px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.ghost-live-sep {
    color: var(--gb-text-sub);
    font-size: 13px;
}

.ghost-live-leading::after {
    content: "▲";
    font-size: 9px;
    margin-left: 2px;
    color: var(--gb-ahead-fg);
    vertical-align: 2px;
}

.ghost-live-progress {
    display: inline-flex;
    flex-direction: column;
    gap: 4px;
    min-width: 150px;
}

.ghost-live-progress-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.ghost-live-progress-row i {
    font-style: normal;
    font-size: 12px;
    color: var(--gb-text-sub);
    width: 18px;
    text-align: center;
    line-height: 1;
}

.ghost-live-progress-track {
    flex: 1;
    height: 8px;
    border-radius: 4px;
    background: rgba(125, 125, 125, 0.18);
    overflow: hidden;
    display: block;
}

/* 一鍵重來 */
.ghost-live-reset {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 1px solid var(--gb-me-light);
    background: var(--gb-me-soft);
    color: var(--gb-me);
    font-size: 14px;
    font-weight: 700;
    border-radius: 10px;
    padding: 7px 14px;
    cursor: pointer;
    transition: background-color 0.12s ease, transform 0.12s ease;
}

.ghost-live-reset:hover {
    background: var(--gb-me-light);
    color: #fff;
    transform: translateY(-1px);
}

.ghost-live-reset i {
    font-size: 13px;
}

.ghost-live-progress-track .ghost-battle-panel-progress-bar {
    display: block;
}

/* 窄螢幕：水平列允許換行 */
@media (max-width: 900px) {
    .ghost-live-strip {
        flex-wrap: wrap;
        justify-content: center;
        gap: 8px 14px;
    }
}

/* 賽前對手摘要（面板小卡） */
.ghost-battle-opponent-chip {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 2px 0;
}

.ghost-battle-opponent-summary {
    display: flex;
    align-items: baseline;
    gap: 4px;
    font-weight: 600;
    color: var(--gb-text);
}

.ghost-battle-select-wpm {
    color: var(--gb-ghost-deep);
    font-size: 15px;
    font-variant-numeric: tabular-nums;
}

.ghost-battle-select-unit {
    font-size: 11px;
    color: var(--gb-text-sub);
}

.ghost-battle-select-best {
    font-size: 10px;
    font-weight: 700;
    color: var(--gb-ghost-deep);
    background: rgba(240, 167, 46, 0.18);
    border-radius: 8px;
    padding: 1px 6px;
    white-space: nowrap;
}

.ghost-battle-opponent-none {
    font-size: 12px;
    color: var(--gb-text-sub);
    font-weight: 500;
}

.ghost-battle-opponent-change {
    border: 1px solid var(--gb-ghost-border);
    background: var(--gb-surface);
    color: var(--gb-ghost-deep);
    font-size: 12px;
    font-weight: 600;
    border-radius: 8px;
    padding: 3px 10px;
    cursor: pointer;
    white-space: nowrap;
}

.ghost-battle-opponent-change:hover {
    background: var(--gb-ghost-soft);
}

/* ============================================
   賽前選擇對手對話框（置中）
   ============================================ */
#ghost-battle-select-overlay {
    position: fixed;
    inset: 0;
    /* No backdrop-filter: blur on this fixed overlay triggers a Chrome
       compositing bug that paints the entire dialog nearly transparent. */
    background: rgba(15, 25, 40, 0.55);
    z-index: 5000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

#ghost-battle-select-dialog {
    position: relative;
    width: 420px;
    max-width: 94vw;
    max-height: 84vh;
    display: flex;
    flex-direction: column;
    background: var(--gb-surface);
    border-radius: 16px;
    box-shadow: 0 20px 60px var(--gb-shadow);
    overflow: hidden;
}

.ghost-battle-dialog-close {
    position: absolute;
    top: 10px;
    right: 12px;
    width: 30px;
    height: 30px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.25);
    color: #fff;
    font-size: 15px;
    cursor: pointer;
    z-index: 2;
}

.ghost-battle-dialog-close:hover {
    background: rgba(255, 255, 255, 0.40);
}

.ghost-battle-dialog-header {
    background: var(--gb-me);
    color: #fff;
    text-align: center;
    padding: 20px 20px 16px;
}

.ghost-battle-dialog-icon {
    font-size: 34px;
    line-height: 1;
    margin-bottom: 6px;
    color: #ffd98a;
    animation: ghost-bob 1.2s ease-in-out infinite;
}

.ghost-battle-dialog-title {
    font-size: 20px;
    font-weight: 800;
    letter-spacing: 2px;
}

.ghost-battle-dialog-subtitle {
    margin-top: 4px;
    font-size: 12px;
    opacity: 0.85;
}

.ghost-battle-dialog-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px 4px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.ghost-battle-dialog-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border: 1.5px solid rgba(240, 167, 46, 0.22);
    border-radius: 12px;
    cursor: pointer;
    background: var(--gb-surface);
    transition: border-color 0.12s ease, background-color 0.12s ease, transform 0.12s ease, box-shadow 0.12s ease;
}

.ghost-battle-dialog-row:hover {
    background: var(--gb-ghost-soft);
    transform: translateY(-1px);
    box-shadow: 0 3px 10px var(--gb-shadow);
}

.ghost-battle-dialog-row.selected {
    background: var(--gb-ghost-soft);
    border-color: var(--gb-ghost);
    box-shadow: 0 0 0 1px var(--gb-ghost) inset;
    animation: gb-row-select 0.28s ease;
}

@keyframes gb-row-select {
    0% { transform: scale(1); }
    45% { transform: scale(1.015); }
    100% { transform: scale(1); }
}

.ghost-battle-dialog-rank {
    flex: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(240, 167, 46, 0.14);
    color: var(--gb-ghost-deep);
    font-size: 13px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ghost-battle-dialog-rank-best {
    background: rgba(240, 167, 46, 0.28);
    font-size: 16px;
}

.ghost-battle-dialog-info {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
    flex: 1;
}

.ghost-battle-dialog-main {
    display: flex;
    align-items: baseline;
    gap: 5px;
}

.ghost-battle-dialog-wpm {
    color: var(--gb-ghost-deep);
    font-size: 21px;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    line-height: 1.1;
}

.ghost-battle-dialog-unit {
    font-size: 11px;
    color: var(--gb-text-sub);
}

.ghost-battle-dialog-best-tag {
    font-size: 10px;
    font-weight: 700;
    color: var(--gb-ghost-deep);
    background: rgba(240, 167, 46, 0.20);
    border: 1px solid rgba(240, 167, 46, 0.40);
    border-radius: 8px;
    padding: 1px 7px;
    margin-left: 4px;
    white-space: nowrap;
}

.ghost-battle-dialog-stats {
    display: flex;
    align-items: center;
    gap: 12px;
    white-space: nowrap;
}

.ghost-battle-dialog-stat {
    display: inline-flex;
    align-items: baseline;
    gap: 4px;
}

.ghost-battle-dialog-stat-label {
    font-size: 10.5px;
    color: var(--gb-text-sub);
}

.ghost-battle-dialog-stat-value {
    font-size: 13px;
    font-weight: 700;
    color: var(--gb-text);
    font-variant-numeric: tabular-nums;
}

.ghost-battle-dialog-when {
    flex: none;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 1px;
    padding: 4px 10px;
    border-radius: 8px;
    background: rgba(125, 125, 125, 0.08);
}

.ghost-battle-dialog-when-date {
    font-size: 12px;
    font-weight: 700;
    color: var(--gb-text);
    white-space: nowrap;
}

.ghost-battle-dialog-when-time {
    font-size: 11px;
    color: var(--gb-text-sub);
    font-variant-numeric: tabular-nums;
}

.ghost-battle-dialog-check {
    flex: none;
    color: var(--gb-ghost);
    font-size: 18px;
}

.ghost-battle-dialog-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 16px 4px;
}

.ghost-battle-dialog-skip {
    border: 1.5px solid rgba(125, 125, 125, 0.30);
    background: transparent;
    color: var(--gb-text-sub);
    font-size: 13px;
    cursor: pointer;
    padding: 8px 16px;
    border-radius: 10px;
}

.ghost-battle-dialog-skip:hover,
.ghost-battle-dialog-skip.selected {
    color: var(--gb-text);
    background: rgba(125, 125, 125, 0.12);
}

.ghost-battle-dialog-confirm {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    border: none;
    background: var(--gb-me);
    color: #fff;
    font-size: 15px;
    font-weight: 700;
    border-radius: 10px;
    padding: 9px 22px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.ghost-battle-dialog-confirm:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.32);
}

.ghost-battle-dialog-hint {
    text-align: center;
    font-size: 11px;
    color: var(--gb-text-sub);
    padding: 6px 0 4px;
}

.ghost-battle-dialog-reset {
    align-self: center;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    border: none;
    background: transparent;
    color: rgba(239, 83, 80, 0.75);
    font-size: 11.5px;
    cursor: pointer;
    padding: 4px 10px 12px;
    border-radius: 8px;
}

.ghost-battle-dialog-reset:hover {
    color: #ef5350;
    text-decoration: underline;
}

/* 確認對話框（SweetAlert）需高於選擇對手彈窗 */
body .swal2-container {
    z-index: 6000;
}

/* ============================================
   成績畫面：幽靈對戰結果橫幅（動畫，疊於深藍成績底上）
   ============================================ */
.result-ghost-banner {
    position: relative;
    display: flex;
    align-items: center;
    gap: 14px;
    margin: 4px 0 12px;
    padding: 14px 18px;
    border-radius: 14px;
    overflow: hidden;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
}

.result-ghost-banner-win {
    background: linear-gradient(135deg, rgba(240, 167, 46, 0.28), rgba(34, 197, 94, 0.18));
    border: 1.5px solid rgba(240, 167, 46, 0.65);
    animation: ghost-banner-pop 0.55s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.result-ghost-banner-lose {
    background: linear-gradient(135deg, rgba(93, 132, 193, 0.28), rgba(54, 90, 146, 0.18));
    border: 1.5px solid rgba(93, 132, 193, 0.55);
    animation: ghost-banner-shake 0.6s ease both;
}

.result-ghost-banner-draw {
    background: linear-gradient(135deg, rgba(148, 163, 184, 0.26), rgba(100, 116, 139, 0.16));
    border: 1.5px solid rgba(148, 163, 184, 0.55);
    animation: ghost-banner-pop 0.55s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes ghost-banner-pop {
    0% { transform: scale(0.6); opacity: 0; }
    60% { transform: scale(1.06); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}

@keyframes ghost-banner-shake {
    0% { transform: translateX(0) scale(0.92); opacity: 0; }
    30% { transform: translateX(-7px) scale(1); opacity: 1; }
    50% { transform: translateX(6px); }
    70% { transform: translateX(-4px); }
    85% { transform: translateX(2px); }
    100% { transform: translateX(0); }
}

.result-ghost-banner-icon {
    flex: none;
    width: 46px;
    height: 46px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
}

.result-ghost-banner-win .result-ghost-banner-icon {
    background: rgba(240, 167, 46, 0.30);
    color: #ffd98a;
    animation: ghost-trophy-swing 1.6s ease-in-out 0.4s infinite;
}

.result-ghost-banner-lose .result-ghost-banner-icon {
    background: rgba(93, 132, 193, 0.30);
    color: #cfe0ff;
    animation: ghost-bob 1.2s ease-in-out infinite;
}

.result-ghost-banner-draw .result-ghost-banner-icon {
    background: rgba(148, 163, 184, 0.30);
    color: #e2e8f0;
    animation: ghost-bob 1.2s ease-in-out infinite;
}

@keyframes ghost-trophy-swing {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(-10deg); }
    75% { transform: rotate(10deg); }
}

.result-ghost-banner-text {
    min-width: 0;
}

.result-ghost-banner-title {
    font-size: 20px;
    font-weight: 800;
    letter-spacing: 1px;
}

.result-ghost-banner-win .result-ghost-banner-title {
    color: #ffd98a;
}

.result-ghost-banner-lose .result-ghost-banner-title {
    color: #cfe0ff;
}

.result-ghost-banner-draw .result-ghost-banner-title {
    color: #e2e8f0;
}

.result-ghost-banner-subtitle {
    font-size: 12.5px;
    color: rgba(255, 255, 255, 0.75);
    margin-top: 2px;
}

.result-ghost-banner-compare {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}

.result-ghost-banner-chip {
    display: inline-flex;
    align-items: baseline;
    gap: 5px;
    padding: 6px 12px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
}

.result-ghost-banner-chip b {
    font-size: 19px;
    font-variant-numeric: tabular-nums;
}

.result-ghost-banner-chip-me {
    background: rgba(93, 132, 193, 0.30);
    color: #d8e6ff;
}

.result-ghost-banner-chip-ghost {
    background: rgba(240, 167, 46, 0.26);
    color: #ffd98a;
}

.result-ghost-banner-win .result-ghost-banner-chip-me {
    animation: ghost-chip-pulse 1.4s ease-in-out 0.6s 3;
}

@keyframes ghost-chip-pulse {
    0%, 100% { transform: scale(1); box-shadow: none; }
    50% { transform: scale(1.08); box-shadow: 0 0 14px rgba(93, 132, 193, 0.65); }
}

.result-ghost-banner-vs {
    font-size: 11px;
    font-weight: 800;
    color: rgba(255, 255, 255, 0.55);
    letter-spacing: 1px;
}

.result-ghost-banner-unit {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.55);
}

/* 勝利彩帶 */
.result-ghost-banner-confetti {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.confetti-piece {
    position: absolute;
    top: -12px;
    width: 7px;
    height: 12px;
    border-radius: 2px;
    opacity: 0;
    animation: confetti-fall 2.2s ease-in both;
}

@keyframes confetti-fall {
    0% { opacity: 1; transform: translateY(-10px) rotateZ(0deg) rotateY(0deg); }
    100% { opacity: 0.15; transform: translateY(130px) rotateZ(340deg) rotateY(540deg); }
}

.confetti-piece:nth-child(6n + 1) { background: #f0a72e; }
.confetti-piece:nth-child(6n + 2) { background: #22c55e; }
.confetti-piece:nth-child(6n + 3) { background: #5D84C1; }
.confetti-piece:nth-child(6n + 4) { background: #2af0c2; }
.confetti-piece:nth-child(6n + 5) { background: #ffd98a; }
.confetti-piece:nth-child(6n + 6) { background: #ef5350; }

.confetti-piece:nth-child(1)  { left: 4%;  animation-delay: 0.10s; }
.confetti-piece:nth-child(2)  { left: 10%; animation-delay: 0.45s; }
.confetti-piece:nth-child(3)  { left: 16%; animation-delay: 0.25s; }
.confetti-piece:nth-child(4)  { left: 22%; animation-delay: 0.60s; }
.confetti-piece:nth-child(5)  { left: 28%; animation-delay: 0.15s; }
.confetti-piece:nth-child(6)  { left: 34%; animation-delay: 0.50s; }
.confetti-piece:nth-child(7)  { left: 40%; animation-delay: 0.30s; }
.confetti-piece:nth-child(8)  { left: 46%; animation-delay: 0.70s; }
.confetti-piece:nth-child(9)  { left: 52%; animation-delay: 0.20s; }
.confetti-piece:nth-child(10) { left: 58%; animation-delay: 0.55s; }
.confetti-piece:nth-child(11) { left: 64%; animation-delay: 0.35s; }
.confetti-piece:nth-child(12) { left: 70%; animation-delay: 0.65s; }
.confetti-piece:nth-child(13) { left: 76%; animation-delay: 0.12s; }
.confetti-piece:nth-child(14) { left: 82%; animation-delay: 0.48s; }
.confetti-piece:nth-child(15) { left: 88%; animation-delay: 0.28s; }
.confetti-piece:nth-child(16) { left: 94%; animation-delay: 0.58s; }
.confetti-piece:nth-child(17) { left: 7%;  animation-delay: 0.80s; }
.confetti-piece:nth-child(18) { left: 91%; animation-delay: 0.85s; }

/* 窄螢幕：比較區塊換行置中 */
@media (max-width: 720px) {
    .result-ghost-banner {
        flex-wrap: wrap;
        justify-content: center;
        text-align: center;
    }
    .result-ghost-banner-compare {
        margin-left: 0;
        width: 100%;
        justify-content: center;
    }
}

/* ============================================
   3-2-1-GO 紅綠燈倒數
   ============================================ */
#ghost-countdown-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 25, 40, 0.45);
    z-index: 5100;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ghost-countdown-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 18px;
}

/* 橫向賽車式燈箱 */
.ghost-countdown-light {
    display: flex;
    gap: 18px;
    padding: 14px 22px;
    background: #1a1d24;
    border: 2px solid #343a46;
    border-radius: 16px;
    box-shadow: 0 10px 36px rgba(0, 0, 0, 0.5);
}

.ghost-countdown-lamp {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: #2b303b;
    border: 2px solid #3c424f;
    transition: background-color 0.1s ease, box-shadow 0.1s ease;
}

.ghost-countdown-lamp.lit-red {
    background: #ef5350;
    border-color: #ff8a80;
    box-shadow: 0 0 22px rgba(239, 83, 80, 0.9);
}

.ghost-countdown-lamp.lit-green {
    background: #2bef6b;
    border-color: #8affb0;
    box-shadow: 0 0 26px rgba(43, 239, 107, 0.95);
}

/* 倒數數字：每步不同 animation-name 以重新觸發彈跳 */
.ghost-countdown-number {
    font-size: 84px;
    font-weight: 900;
    line-height: 1;
    color: #fff;
    text-shadow: 0 4px 18px rgba(0, 0, 0, 0.55);
    font-family: 'Roboto Mono', monospace;
    letter-spacing: 2px;
}

.ghost-countdown-number-3 { color: #ff8a80; animation: gc-pop-3 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both; }
.ghost-countdown-number-2 { color: #ff8a80; animation: gc-pop-2 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both; }
.ghost-countdown-number-1 { color: #ff8a80; animation: gc-pop-1 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both; }
.ghost-countdown-number-go { color: #69ff9c; animation: gc-pop-go 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) both; }

@keyframes gc-pop-3 { 0% { transform: scale(2.2); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
@keyframes gc-pop-2 { 0% { transform: scale(2.2); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
@keyframes gc-pop-1 { 0% { transform: scale(2.2); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
@keyframes gc-pop-go {
    0% { transform: scale(0.4); opacity: 0; }
    60% { transform: scale(1.35); opacity: 1; }
    100% { transform: scale(1.15); opacity: 1; }
}

/* GO 時整體輕微閃光 */
.ghost-countdown-step-go .ghost-countdown-light {
    animation: gc-go-flash 0.5s ease-out both;
}

@keyframes gc-go-flash {
    0% { box-shadow: 0 10px 36px rgba(0, 0, 0, 0.5); }
    40% { box-shadow: 0 0 60px rgba(43, 239, 107, 0.65); }
    100% { box-shadow: 0 10px 36px rgba(0, 0, 0, 0.5); }
}

/* ============================================
   幽靈對戰大廳（/ghost-battle）
   ============================================ */
.ghost-lobby {
    max-width: 860px;
    margin: 0 auto;
    padding: 8px 20px 60px;
    font-family: 'Microsoft YaHei', 'PingFang SC', sans-serif;
}

.ghost-lobby-header {
    text-align: center;
    margin: 18px 0 26px;
}

.ghost-lobby-title {
    font-size: 30px;
    font-weight: 800;
    color: var(--gb-me);
    letter-spacing: 2px;
}

.ghost-lobby-title i {
    color: var(--gb-ghost);
    margin-right: 8px;
}

.ghost-lobby-subtitle {
    margin-top: 6px;
    font-size: 14px;
    color: var(--gb-text-sub);
}

.ghost-lobby-loading {
    text-align: center;
    color: var(--gb-text-sub);
    padding: 40px 0;
    font-size: 15px;
}

/* 空狀態 */
.ghost-lobby-empty {
    max-width: 460px;
    margin: 30px auto;
    background: var(--gb-surface);
    border: 1.5px solid rgba(240, 167, 46, 0.35);
    border-radius: 16px;
    padding: 36px 28px;
    text-align: center;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.08);
}

.ghost-lobby-empty-icon {
    font-size: 56px;
    line-height: 1;
    margin-bottom: 12px;
    animation: ghost-bob 1.2s ease-in-out infinite;
    display: inline-block;
}

.ghost-lobby-empty-title {
    font-size: 20px;
    font-weight: 800;
    color: var(--gb-text);
}

.ghost-lobby-empty-text {
    margin-top: 10px;
    font-size: 14px;
    line-height: 1.7;
    color: var(--gb-text-sub);
}

.ghost-lobby-empty-btn {
    margin-top: 20px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: none;
    background: var(--gb-me);
    color: #fff;
    font-size: 15px;
    font-weight: 700;
    border-radius: 10px;
    padding: 11px 26px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.ghost-lobby-empty-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.26);
}

/* 練習分組卡 */
.ghost-lobby-groups {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.ghost-lobby-group {
    background: var(--gb-surface);
    border: 1.5px solid rgba(240, 167, 46, 0.30);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.07);
}

.ghost-lobby-group-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 18px;
    background: linear-gradient(135deg, rgba(54, 90, 146, 0.08), rgba(240, 167, 46, 0.08));
    border-bottom: 1px solid rgba(240, 167, 46, 0.20);
}

.ghost-lobby-group-ime {
    flex: none;
    font-size: 13px;
    font-weight: 800;
    color: #fff;
    background: var(--gb-me);
    border-radius: 8px;
    padding: 4px 12px;
    letter-spacing: 1px;
}

.ghost-lobby-group-article {
    font-size: 14px;
    font-weight: 600;
    color: var(--gb-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ghost-lobby-records {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px 16px 14px;
}

.ghost-lobby-record {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border: 1.5px solid rgba(240, 167, 46, 0.22);
    border-radius: 12px;
    background: var(--gb-surface);
    transition: border-color 0.12s ease, background-color 0.12s ease, transform 0.12s ease, box-shadow 0.12s ease;
}

.ghost-lobby-record:hover {
    background: var(--gb-ghost-soft);
    transform: translateY(-1px);
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.10);
}

.ghost-lobby-start-btn {
    flex: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: none;
    background: var(--gb-me);
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    border-radius: 9px;
    padding: 8px 16px;
    cursor: pointer;
    white-space: nowrap;
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.ghost-lobby-start-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(54, 90, 146, 0.40);
}

@media (max-width: 640px) {
    .ghost-lobby-record {
        flex-wrap: wrap;
    }
    .ghost-lobby-start-btn {
        width: 100%;
        justify-content: center;
    }
}

/* ── 大廳：最佳紀錄 hero + 其他紀錄精簡卡片（設計 3 + 卡片網格）── */
.ghost-lobby-body {
    padding: 14px 16px 16px;
}

.ghost-hero {
    display: flex;
    align-items: center;
    gap: 14px;
    background: var(--gb-ghost-soft);
    border: 1.5px solid var(--gb-ghost-border);
    border-radius: 14px;
    padding: 14px 16px;
}

.ghost-hero-icon {
    flex: none;
    font-size: 32px;
    color: var(--gb-ghost);
}

.ghost-hero-info {
    flex: 1;
    min-width: 0;
}

.ghost-hero-label {
    font-size: 12px;
    color: var(--gb-text-sub);
}

.ghost-hero-main {
    display: flex;
    align-items: baseline;
    gap: 6px;
    flex-wrap: wrap;
}

.ghost-hero-wpm {
    font-family: 'Roboto Mono', monospace;
    font-size: 30px;
    font-weight: 800;
    line-height: 1.1;
    color: var(--gb-ghost-deep);
}

.ghost-hero-meta {
    font-size: 12px;
    color: var(--gb-text-sub);
}

.ghost-hero-cta {
    margin-top: 1px;
    font-size: 12px;
    font-weight: 700;
    color: var(--gb-ghost-deep);
}

body.fcj-dark .ghost-hero-wpm,
body.fcj-dark .ghost-hero-cta {
    color: #f0c372;
}

.ghost-hero-btn {
    flex: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: none;
    background: var(--gb-ghost);
    color: #3a2503;
    font-size: 13.5px;
    font-weight: 700;
    border-radius: 10px;
    padding: 10px 16px;
    cursor: pointer;
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.ghost-hero-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(240, 167, 46, 0.40);
}

.ghost-lobby-others {
    margin-top: 14px;
}

.ghost-lobby-others-label {
    margin: 0 2px 8px;
    font-size: 12px;
    color: var(--gb-text-sub);
}

.ghost-lobby-card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 8px;
}

.ghost-mini-card {
    background: var(--gb-surface);
    border: 1px solid rgba(240, 167, 46, 0.22);
    border-radius: 10px;
    padding: 10px 11px;
    transition: border-color 0.12s ease, transform 0.12s ease, box-shadow 0.12s ease;
}

.ghost-mini-card:hover {
    border-color: var(--gb-ghost);
    transform: translateY(-1px);
    box-shadow: 0 3px 10px var(--gb-shadow);
}

.ghost-mini-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 5px;
}

.ghost-mini-rank {
    font-family: 'Roboto Mono', monospace;
    font-size: 11px;
    font-weight: 700;
    color: var(--gb-text-sub);
    background: var(--gb-ghost-soft);
    border-radius: 5px;
    padding: 1px 6px;
}

.ghost-mini-when {
    font-size: 11px;
    color: var(--gb-text-sub);
}

.ghost-mini-main {
    display: flex;
    align-items: baseline;
    gap: 3px;
}

.ghost-mini-wpm {
    font-family: 'Roboto Mono', monospace;
    font-size: 20px;
    font-weight: 700;
    color: var(--gb-me);
}

.ghost-mini-unit {
    font-size: 11px;
    color: var(--gb-text-sub);
}

.ghost-mini-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin: 6px 0 8px;
}

.ghost-mini-chip {
    font-size: 11px;
    color: var(--gb-text-sub);
    background: var(--gb-surface-alt);
    border-radius: 5px;
    padding: 1px 6px;
}

.ghost-mini-btn {
    width: 100%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    border: 1px solid var(--gb-me);
    background: transparent;
    color: var(--gb-me);
    font-size: 12px;
    font-weight: 700;
    border-radius: 8px;
    padding: 6px;
    cursor: pointer;
    transition: background-color 0.12s ease, color 0.12s ease;
}

.ghost-mini-btn:hover {
    background: var(--gb-me);
    color: #fff;
}

/* 成績頁幽靈按鈕 */
.result-btn-ghost {
    border-color: rgba(240, 167, 46, 0.75);
    background: rgba(240, 167, 46, 0.18);
    color: #ffd98a;
}

.result-btn-ghost:hover {
    background: var(--gb-ghost);
    border-color: #ffd98a;
    color: #3a2503;
}

/* 尊重「減少動態」系統設定：關閉慶祝 / 抖動 / 倒數彈跳等動畫 */
@media (prefers-reduced-motion: reduce) {
    .result-ghost-banner,
    .result-ghost-banner-win .result-ghost-banner-icon,
    .result-ghost-banner-lose .result-ghost-banner-icon,
    .result-ghost-banner-draw .result-ghost-banner-icon,
    .result-ghost-banner-win .result-ghost-banner-chip-me,
    .confetti-piece,
    .ghost-countdown-number,
    .ghost-countdown-step-go .ghost-countdown-light,
    .ghost-lobby-empty-icon,
    .ghost-battle-dialog-row.selected,
    .char.ghost-current::after {
        animation: none !important;
    }
}

/* Ghost's value shown under each result stat card (ghost battle comparison). */
.result-stat-ghost {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    margin-top: 6px;
    padding: 3px 12px;
    border-radius: 999px;
    background: #2f2413;
    border: 1px solid rgba(246, 178, 58, 0.32);
    color: #f6b23a;
    font-size: 12.5px;
    font-weight: 700;
    line-height: 1.25;
    white-space: nowrap;
}

.result-stat-ghost i {
    font-size: 11px;
    opacity: 1;
    color: #f6b23a;
}
