/* 追加與修正至 style.css */
body {
    background-color: #0b0b10; color: #e2e8f0;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    display: flex; flex-direction: column; justify-content: center; align-items: center;
    min-height: 100vh; margin: 0; padding-top: 50px; box-sizing: border-box;
}

/* 頂部導覽列 */
.global-nav {
    position: fixed; top: 0; left: 0; width: 100%; height: 50px;
    background: #131322; border-bottom: 1px solid #22223b;
    display: flex; justify-content: space-between; align-items: center;
    padding: 0 20px; box-sizing: border-box; z-index: 10;
}
.nav-btn { background: #27273a; padding: 6px 12px; font-size: 0.8rem; border: 1px solid #3f3f56;}
.rule-toggle-btn { background: #1e1b4b; border-color: #4338ca; }

/* 等待匹配看板 */
.queue-board { margin-top: 20px; background: #07070c; padding: 12px; border-radius: 8px; border: 1px solid #22223b; text-align: left; }
.queue-board h3 { margin: 0 0 10px 0; font-size: 0.85rem; color: #94a3b8; }
.queue-list { display: flex; flex-direction: column; gap: 6px; }
.queue-item {
    background: #181825; padding: 8px 12px; border-radius: 6px; border: 1px solid #2563eb;
    display: flex; justify-content: space-between; align-items: center; font-size: 0.8rem; cursor: pointer; transition: 0.2s;
}
.queue-item:hover { background: #1e293b; }
.queue-item::after { content: "點擊迎戰 ⚔️"; color: #3b82f6; font-weight: bold; font-size: 0.75rem; }
.queue-empty { font-size: 0.8rem; color: #4b5563; text-align: center; padding: 5px 0; }

/* 投降按鈕 */
.info-bar { display: flex; justify-content: space-between; align-items: center; }
.surrender-btn { background: #991b1b; padding: 4px 10px; font-size: 0.75rem; border: 1px solid #f43f5e; border-radius: 4px;}

/* 規則說明彈窗 */
.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(7, 7, 12, 0.85); backdrop-filter: blur(4px);
    display: flex; justify-content: center; align-items: center; z-index: 100;
}
.modal-content {
    background: #131322; border: 1px solid #4338ca; padding: 25px; border-radius: 16px;
    max-width: 400px; width: 90%; text-align: left; box-shadow: 0 0 30px rgba(99,102,241,0.3);
}
.modal-content h2 { margin-top: 0; font-size: 1.2rem; color: #818cf8; border-bottom: 1px solid #22223b; padding-bottom: 10px; }
.modal-body { font-size: 0.8rem; color: #94a3b8; line-height: 1.6; }
.modal-body code { background: #07070c; padding: 2px 4px; border-radius: 4px; color: #f43f5e; }
.modal-body ul { padding-left: 15px; margin: 5px 0; }
.close-modal-btn { background: #4f46e5; width: 100%; margin-top: 15px; }

/* 其餘已有樣式與前版相同... */
.game-container { text-align: center; max-width: 460px; width: 100%; padding: 12px; }
.panel { background: #131322; padding: 25px; border-radius: 16px; border: 1px solid #22223b; }
button { padding: 12px; border: none; border-radius: 8px; cursor: pointer; font-size: 0.9rem; font-weight: 700; color: #ffffff; transition: all 0.2s ease; letter-spacing: 0.5px; }
button:hover { filter: brightness(1.2); transform: translateY(-1px); }
button:disabled { background: #2d2d3d !important; color: #64748b; cursor: not-allowed; transform: none; }
.primary-btn { background: #2563eb; width: 100%; margin-bottom: 12px; box-shadow: 0 4px 12px rgba(37,99,235,0.2); }
.secondary-btn { background: #059669; width: 100%; margin-bottom: 12px; box-shadow: 0 4px 12px rgba(5,150,105,0.2); }
.join-room { display: flex; gap: 8px; }
.join-room input { flex: 1; padding: 12px; border-radius: 8px; border: 1px solid #22223b; background: #080811; color: white; text-align: center; font-size: 1.1rem; font-family: monospace; }
.join-room button { background: #ca8a04; }
.status-msg { color: #eab308; font-size: 0.85rem; margin-top: 10px; }
.board { display: grid; grid-template-columns: repeat(9, 1fr); grid-template-rows: repeat(9, 1fr); gap: 4px; background-color: #1a1a2e; padding: 8px; border-radius: 16px; aspect-ratio: 1/1; margin-bottom: 15px; box-shadow: 0 20px 40px -15px rgba(0,0,0,0.7); }
.cell { background-color: #07070c; border-radius: 6px; display: flex; justify-content: center; align-items: center; transition: background-color 0.2s; }
.piece-container {
    width: 82%;
    height: 82%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
    user-select: none;
}
.piece-svg {
    width: 100%;
    height: 100%;
    filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.5));
    transition: transform 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.piece-container:hover .piece-svg {
    transform: scale(1.1);
}
.piece-label {
    position: absolute;
    bottom: -3px;
    font-size: 0.55rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    padding: 1px 4px;
    border-radius: 4px;
    background: rgba(7, 7, 12, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.15);
    pointer-events: none;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}
.label-p1 {
    color: #93c5fd;
    border-color: rgba(59, 130, 246, 0.5);
}
.label-p2 {
    color: #fca5a5;
    border-color: rgba(239, 68, 68, 0.5);
}
.highlight-inner { background-color: #17172b; border: 1px dashed #6366f1; cursor: pointer; animation: glowPulse 1.2s infinite ease-in-out; }
.control-panel { background: #131322; padding: 15px; border-radius: 16px; border: 1px solid #22223b; }
.status { font-weight: 700; margin-bottom: 12px; color: #10b981; font-size: 0.9rem; }
.action-buttons { display: flex; flex-direction: column; gap: 8px; }
.inner-select-group { display: flex; gap: 8px; }
.inner-select-group button { flex: 1; }
.btn-inner { background: #312e81; border: 1px solid #4338ca; }
.btn-charge { background: #7f1d1d; border: 1px solid #991b1b; font-size: 0.95rem; }
.move-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.move-grid button { background: #1c1c2e; padding: 11px 0; border: 1px solid #2d2d44; color: #94a3b8; }
.move-grid button:hover { background: #222239; color: #ffffff; }
.battle-log { margin-top: 12px; font-size: 0.8rem; color: #94a3b8; background: #07070c; padding: 12px; border-radius: 8px; min-height: 45px; text-align: left; line-height: 1.5; border: 1px solid #22223b; white-space: pre-line; }

/* lobby divider */
.lobby-divider {
    border: 0;
    height: 1px;
    background: #22223b;
    margin: 20px 0;
}

/* timer styles */
.timer-container {
    margin-bottom: 15px;
    background: #131322;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid #22223b;
}
.timer-bar-wrapper {
    height: 8px;
    background-color: #07070c;
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 5px;
}
.timer-bar {
    height: 100%;
    width: 100%;
    background-color: #10b981;
    transition: width 0.1s linear, background-color 0.3s ease;
}
.timer-text {
    font-size: 0.8rem;
    color: #94a3b8;
    text-align: center;
    font-family: monospace;
}

/* active games board */
.active-games-board {
    margin-top: 20px;
    background: #07070c;
    padding: 12px;
    border-radius: 8px;
    border: 1px solid #22223b;
    text-align: left;
}
.active-games-board h3 {
    margin: 0 0 10px 0;
    font-size: 0.85rem;
    color: #94a3b8;
}
.active-games-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.active-game-item {
    background: #181825;
    padding: 8px 12px;
    border-radius: 6px;
    border: 1px solid #4338ca;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8rem;
}
.active-games-empty {
    font-size: 0.8rem;
    color: #4b5563;
    text-align: center;
    padding: 5px 0;
}
.spectate-btn {
    background: #4f46e5;
    padding: 4px 8px;
    font-size: 0.75rem;
    border-radius: 4px;
    border: none;
    font-weight: normal;
}
.spectate-btn:hover {
    background: #6366f1;
}

/* history board */
.history-board {
    margin-top: 20px;
    background: #07070c;
    padding: 12px;
    border-radius: 8px;
    border: 1px solid #22223b;
    text-align: left;
}
.history-board h3 {
    margin: 0 0 10px 0;
    font-size: 0.85rem;
    color: #94a3b8;
}
.history-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 250px;
    overflow-y: auto;
}
.history-item {
    background: #131322;
    padding: 10px;
    border-radius: 6px;
    border: 1px solid #22223b;
    cursor: pointer;
    transition: 0.2s;
}
.history-item:hover {
    background: #1c1c2e;
    border-color: #3f3f56;
}
.history-main-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}
.history-time {
    font-size: 0.7rem;
    color: #64748b;
}
.history-players {
    font-size: 0.8rem;
    color: #e2e8f0;
}
.history-summary {
    font-size: 0.75rem;
    color: #94a3b8;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.history-empty {
    font-size: 0.8rem;
    color: #4b5563;
    text-align: center;
    padding: 5px 0;
}

/* leaderboard board */
.leaderboard-board {
    margin-top: 20px;
    background: #07070c;
    padding: 12px;
    border-radius: 8px;
    border: 1px solid #22223b;
    text-align: left;
}
.leaderboard-board h3 {
    margin: 0 0 10px 0;
    font-size: 0.85rem;
    color: #fbbf24;
    text-shadow: 0 0 8px rgba(251, 191, 36, 0.3);
}
.leaderboard-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 300px;
    overflow-y: auto;
}
.leaderboard-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #111122;
    padding: 8px 12px;
    border-radius: 6px;
    border: 1px solid #22223b;
    transition: 0.2s;
}
.leaderboard-item:hover {
    border-color: #3b82f6;
    background: #15152a;
}
.leaderboard-left {
    display: flex;
    align-items: center;
    gap: 10px;
}
.leaderboard-rank {
    font-weight: bold;
    width: 24px;
    text-align: center;
    font-size: 0.9rem;
}
.rank-1 { color: #fbbf24; text-shadow: 0 0 8px rgba(251, 191, 36, 0.4); }
.rank-2 { color: #cbd5e1; }
.rank-3 { color: #d97706; }
.leaderboard-name {
    font-weight: 500;
    color: #f8fafc;
    font-size: 0.8rem;
}
.leaderboard-right {
    display: flex;
    align-items: center;
    gap: 15px;
}
.leaderboard-mmr {
    color: #60a5fa;
    font-weight: 600;
    font-size: 0.85rem;
}
.leaderboard-stats {
    font-size: 0.75rem;
    color: #64748b;
}
.leaderboard-empty {
    font-size: 0.8rem;
    color: #4b5563;
    text-align: center;
    padding: 10px 0;
}

/* badges */
.badge {
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: bold;
}
.badge-win {
    background-color: rgba(16, 185, 129, 0.2);
    color: #10b981;
    border: 1px solid #10b981;
}
.badge-lose {
    background-color: rgba(239, 68, 68, 0.2);
    color: #ef4444;
    border: 1px solid #ef4444;
}
.badge-draw {
    background-color: rgba(148, 163, 184, 0.2);
    color: #94a3b8;
    border: 1px solid #94a3b8;
}
.badge-neutral {
    background-color: rgba(99, 102, 241, 0.2);
    color: #818cf8;
    border: 1px solid #818cf8;
}

/* history modal details */
.history-modal-content {
    max-width: 500px;
}
.history-detail-title p {
    margin: 5px 0;
    font-size: 0.85rem;
    color: #e2e8f0;
}
.history-detail-logs {
    max-height: 300px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding-right: 5px;
}
.history-log-block {
    background: #07070c;
    padding: 10px;
    border-radius: 6px;
    border: 1px solid #22223b;
    font-size: 0.8rem;
    color: #94a3b8;
    white-space: pre-line;
    line-height: 1.5;
}

/* action tip styles */
.action-tip {
    font-size: 0.8rem;
    color: #94a3b8;
    background: #07070c;
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid #22223b;
    text-align: left;
    line-height: 1.6;
    margin-top: 8px;
}

/* piece selection and highlights */
.clickable-piece {
    cursor: pointer;
    transition: background-color 0.2s;
}
.clickable-piece:hover {
    background-color: #131325 !important;
}
.selected-piece {
    background-color: #1e1b4b !important;
    border: 1px solid #4338ca !important;
    box-shadow: 0 0 10px rgba(99, 102, 241, 0.4);
}
.highlight-move {
    background-color: #064e3b;
    border: 1px dashed #10b981;
    cursor: pointer;
    animation: glowPulseGreen 1.2s infinite ease-in-out;
}

/* keyframes */
@keyframes glowPulse {
    0% { box-shadow: inset 0 0 5px rgba(99, 102, 241, 0.3); }
    50% { box-shadow: inset 0 0 15px rgba(99, 102, 241, 0.7); }
    100% { box-shadow: inset 0 0 5px rgba(99, 102, 241, 0.3); }
}
@keyframes glowPulseGreen {
    0% { box-shadow: inset 0 0 5px rgba(16, 185, 129, 0.3); }
    50% { box-shadow: inset 0 0 15px rgba(16, 185, 129, 0.7); }
    100% { box-shadow: inset 0 0 5px rgba(16, 185, 129, 0.3); }
}

/* ==========================================
   Supabase OAuth 登入面板與戰績樣式
   ========================================== */

.auth-panel {
    background: rgba(13, 13, 23, 0.95);
    border: 1px solid #1e1b4b;
    border-radius: 12px;
    padding: 15px 20px;
    margin-bottom: 20px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5), inset 0 0 10px rgba(99, 102, 241, 0.15);
    transition: all 0.3s ease;
}

.auth-tip {
    font-size: 0.85rem;
    color: #94a3b8;
    margin-top: 0;
    margin-bottom: 12px;
    text-align: center;
}

.oauth-buttons {
    display: flex;
    justify-content: center;
    gap: 15px;
}

.oauth-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    font-size: 0.9rem;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.25s ease;
    border: 1px solid transparent;
    color: #ffffff;
    background: transparent;
}

.oauth-icon {
    width: 18px;
    height: 18px;
}

.google-btn {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.15);
}

.google-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: #ffffff;
    box-shadow: 0 0 15px rgba(255, 255, 255, 0.3);
}

.discord-btn {
    background: rgba(88, 101, 242, 0.15);
    border: 1px solid rgba(88, 101, 242, 0.4);
}

.discord-btn:hover {
    background: #5865F2;
    border-color: #5865F2;
    box-shadow: 0 0 15px rgba(88, 101, 242, 0.6);
}

/* 已登入會員資訊區 */
.user-profile {
    display: flex;
    align-items: center;
    gap: 16px;
}

.user-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid #818cf8;
    box-shadow: 0 0 10px rgba(129, 140, 248, 0.6);
}

.user-details {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
    text-align: left;
}

.user-name {
    font-size: 1.05rem;
    font-weight: bold;
    color: #f8fafc;
    text-shadow: 0 0 5px rgba(255, 255, 255, 0.3);
}

.user-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.stat-tag {
    font-size: 0.75rem;
    padding: 3px 8px;
    border-radius: 6px;
    border: 1px solid transparent;
}

.mmr-tag {
    background: rgba(167, 139, 250, 0.15);
    color: #c084fc;
    border-color: rgba(167, 139, 250, 0.3);
    box-shadow: 0 0 5px rgba(167, 139, 250, 0.2);
}

.win-tag {
    background: rgba(16, 185, 129, 0.15);
    color: #34d399;
    border-color: rgba(16, 185, 129, 0.3);
}

.lose-tag {
    background: rgba(239, 68, 68, 0.15);
    color: #f87171;
    border-color: rgba(239, 68, 68, 0.3);
}

.rate-tag {
    background: rgba(99, 102, 241, 0.15);
    color: #818cf8;
    border-color: rgba(99, 102, 241, 0.3);
}

.logout-btn {
    padding: 6px 12px;
    font-size: 0.8rem;
    border-radius: 6px;
    background: rgba(239, 68, 68, 0.1);
    color: #f87171;
    border: 1px solid rgba(239, 68, 68, 0.3);
    cursor: pointer;
    transition: all 0.2s;
}

.logout-btn:hover {
    background: #ef4444;
    color: #ffffff;
    box-shadow: 0 0 10px rgba(239, 68, 68, 0.5);
}

/* ==========================================
   電競排位對決列樣式 (match-vs-bar)
   ========================================== */

.match-vs-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(8, 8, 16, 0.9);
    border: 1px solid #1e1b4b;
    border-radius: 10px;
    padding: 10px 20px;
    margin-bottom: 15px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
}

.vs-player {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 42%;
}

.p1-vs-side {
    justify-content: flex-start;
    color: #3b82f6;
    text-shadow: 0 0 8px rgba(59, 130, 246, 0.5);
    font-weight: bold;
}

.p2-vs-side {
    justify-content: flex-end;
    color: #ef4444;
    text-shadow: 0 0 8px rgba(239, 68, 68, 0.5);
    font-weight: bold;
}

.vs-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1.5px solid currentColor;
    box-shadow: 0 0 6px currentColor;
}

.vs-mmr-badge {
    font-size: 0.75rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #94a3b8;
    padding: 2px 6px;
    border-radius: 4px;
}

.vs-divider {
    font-size: 1.2rem;
    font-weight: 900;
    font-style: italic;
    color: #a78bfa;
    text-shadow: 0 0 12px #a78bfa;
    width: 16%;
    text-align: center;
}

/* ==========================================
   對局結算彈窗樣式 (game-over-modal)
   ========================================== */

.game-over-content {
    max-width: 420px;
    border: 2px solid #1e1b4b;
    box-shadow: 0 0 30px rgba(99, 102, 241, 0.4);
    animation: modalPop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    text-align: center;
}

@keyframes modalPop {
    from { transform: scale(0.8); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.victory-title {
    color: #10b981;
    font-size: 2.4rem;
    font-weight: 900;
    letter-spacing: 3px;
    text-shadow: 0 0 15px rgba(16, 185, 129, 0.7);
    margin-bottom: 15px;
    font-style: italic;
}

.defeat-title {
    color: #ef4444;
    font-size: 2.4rem;
    font-weight: 900;
    letter-spacing: 3px;
    text-shadow: 0 0 15px rgba(239, 68, 68, 0.7);
    margin-bottom: 15px;
    font-style: italic;
}

.draw-title {
    color: #94a3b8;
    font-size: 2.4rem;
    font-weight: 900;
    letter-spacing: 3px;
    text-shadow: 0 0 15px rgba(148, 163, 184, 0.7);
    margin-bottom: 15px;
    font-style: italic;
}

.game-over-stats-box {
    background: rgba(8, 8, 16, 0.85);
    border: 1px solid #22223b;
    border-radius: 8px;
    padding: 15px;
    margin: 15px 0 20px 0;
    font-size: 0.95rem;
    color: #e2e8f0;
    line-height: 1.8;
    text-align: left;
}

.game-over-reason {
    color: #94a3b8;
    font-size: 0.85rem;
    margin-bottom: 15px;
    font-style: italic;
}

.mmr-change-up {
    color: #10b981;
    font-weight: bold;
    text-shadow: 0 0 5px rgba(16, 185, 129, 0.3);
}

.mmr-change-down {
    color: #ef4444;
    font-weight: bold;
    text-shadow: 0 0 5px rgba(239, 68, 68, 0.3);
}

/* ==========================================
   規則說明彈窗樣式優化 (rules-modal)
   ========================================== */

.rules-modal-content {
    max-width: 600px !important;
    width: 90% !important;
    max-height: 80vh !important; /* 限制最高為螢幕高度的 80% */
    display: flex !important;
    flex-direction: column !important;
}

.rules-modal-content .modal-body {
    overflow-y: auto !important; /* 內容過長時在內部產生垂直滾動 */
    flex-grow: 1 !important;
    padding-right: 10px !important;
}

.rules-section {
    margin-bottom: 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
    padding-bottom: 15px;
}

.rules-section:last-child {
    border-bottom: none;
    padding-bottom: 0;
    margin-bottom: 0;
}

.rules-section h3 {
    margin-top: 0;
    margin-bottom: 10px;
    font-size: 1rem;
    color: #a78bfa;
    text-shadow: 0 0 5px rgba(167, 139, 250, 0.3);
}

.rules-section ul, .rules-section ol {
    margin: 5px 0;
    padding-left: 20px;
}

.rules-section li {
    margin-bottom: 8px;
    font-size: 0.85rem;
    color: #94a3b8;
}

.rules-section p {
    font-size: 0.85rem;
    color: #cbd5e1;
    margin: 5px 0;
}