/* ===== Liquid Glass 設計系統：通用框架、玩家狀態、勝率與紀錄卡片 ===== */
:root {
    --glass-fill: linear-gradient(145deg, rgba(255,255,255,0.14), rgba(255,255,255,0.04));
    --glass-fill-soft: linear-gradient(145deg, rgba(255,255,255,0.09), rgba(255,255,255,0.02));
    --glass-border: rgba(255,255,255,0.16);
    --glass-shadow: 0 10px 34px rgba(0,0,0,0.45), inset 0 1px 0 rgba(255,255,255,0.18);
    --text-primary: #F5F5F7;
    --text-secondary: rgba(235,235,245,0.62);
    --text-tertiary: rgba(235,235,245,0.4);
    --accent-blue: #0A84FF;
    --accent-green: #30D158;
    --accent-red: #FF453A;
    --accent-amber: #FF9F0A;
    --accent-gray: #8E8E93;
    --radius-lg: 26px;
    --radius-md: 18px;
    --radius-sm: 12px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang TC", "Segoe UI", sans-serif;
    -webkit-tap-highlight-color: transparent;
}

html, body { height: 100%; }

body {
    background: #06060a;
    color: var(--text-primary);
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    padding: 20px 14px calc(env(safe-area-inset-bottom, 0px) + 160px);
    overflow-x: hidden;
    position: relative;
}

/* 背景動態光斑，營造液態玻璃質感的環境光 */
.ambient-bg {
    position: fixed;
    inset: -10%;
    z-index: -1;
    overflow: hidden;
    pointer-events: none;
}
.ambient-bg span {
    position: absolute;
    border-radius: 50%;
    filter: blur(70px);
    opacity: 0.5;
    animation: drift 18s ease-in-out infinite alternate;
}
.ambient-bg span:nth-child(1) { width: 260px; height: 260px; background: #0A84FF; top: 4%; left: -10%; animation-delay: 0s; }
.ambient-bg span:nth-child(2) { width: 220px; height: 220px; background: #FF375F; top: 52%; right: -12%; animation-delay: -4.5s; }
.ambient-bg span:nth-child(3) { width: 200px; height: 200px; background: #30D158; bottom: -10%; left: 18%; animation-delay: -9s; }
.ambient-bg span:nth-child(4) { width: 180px; height: 180px; background: #FF9F0A; top: 28%; right: 18%; animation-delay: -13.5s; }

@keyframes drift {
    0% { transform: translate(0,0) scale(1); }
    100% { transform: translate(24px, -26px) scale(1.15); }
}

.main-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 390px; /* 針對 iPhone 精準客製最佳化寬度 */
    gap: 14px;
    box-sizing: border-box;
}

.app-title {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 8px;
    margin-bottom: 2px;
}

/* 測試模式提示：用明顯的橘色警示條，避免跟正式資料搞混 */
.test-banner {
    width: 100%;
    background: rgba(255,159,10,0.16);
    border: 1px solid rgba(255,159,10,0.4);
    color: #FFD08A;
    font-size: 0.72rem;
    font-weight: 600;
    line-height: 1.5;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    text-align: center;
}
.test-banner a {
    color: #FFD08A;
    text-decoration: underline;
    font-weight: 700;
    white-space: nowrap;
}
.app-title .title-main {
    font-size: 1.32rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}
.app-title .title-sub {
    font-size: 0.74rem;
    color: var(--text-tertiary);
    font-weight: 500;
}

/* ===== 通用玻璃卡片 ===== */
.glass-card {
    width: 100%;
    background: var(--glass-fill);
    backdrop-filter: blur(28px) saturate(180%);
    -webkit-backdrop-filter: blur(28px) saturate(180%);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--glass-shadow);
    padding: 16px;
}

/* ===== 玩家卡 ===== */
.players-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    padding: 14px 16px;
    transition: box-shadow 0.4s ease, border-color 0.4s ease;
}

/* 每位玩家改為橫向排列：頭像 → 名稱/在線狀態 → 分數，避免直向堆疊佔太多高度 */
.player-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
    flex-wrap: nowrap;
}
.player-chip.side-right {
    flex-direction: row-reverse;
}

.avatar-wrap {
    position: relative;
    flex-shrink: 0;
}
.player-chip .avatar {
    width: 36px; height: 36px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.1rem;
    background: var(--glass-fill-soft);
    border: 1px solid var(--glass-border);
    transition: box-shadow 0.35s ease, filter 0.35s ease;
}

/* 輪到誰下棋，頭像就出現藍色脈動光環 */
.player-chip.is-turn .avatar {
    box-shadow: 0 0 0 2px rgba(10,132,255,0.7), 0 0 16px rgba(10,132,255,0.55);
    animation: turnGlow 1.8s infinite ease-in-out;
}
@keyframes turnGlow {
    0%, 100% { box-shadow: 0 0 0 2px rgba(10,132,255,0.5), 0 0 10px rgba(10,132,255,0.35); }
    50% { box-shadow: 0 0 0 2px rgba(10,132,255,0.85), 0 0 20px rgba(10,132,255,0.65); }
}

/* 獲勝：金色光環＋獎盃徽章浮現；落敗：整體淡出 */
.player-chip.is-winner .avatar {
    box-shadow: 0 0 0 2px #FFD60A, 0 0 18px rgba(255,214,10,0.6);
}
.player-chip.is-winner .trophy-badge {
    opacity: 1;
    transform: scale(1);
}
.player-chip.is-loser {
    opacity: 0.5;
    filter: grayscale(0.4);
}

.trophy-badge {
    position: absolute;
    top: -6px;
    right: -4px;
    font-size: 0.8rem;
    opacity: 0;
    transform: scale(0.4);
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.player-chip.side-right .trophy-badge { right: auto; left: -4px; }

.player-info {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
}
.player-chip.side-right .player-info { align-items: flex-end; }

.p-name-row {
    display: flex;
    align-items: center;
    gap: 4px;
}
.p-name {
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.01em;
}
.stone-icon { font-size: 0.75rem; flex-shrink: 0; }

.player-chip .p-score {
    font-size: 1.35rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.02em;
    flex-shrink: 0;
}

.score-divider {
    font-size: 1rem;
    color: var(--text-tertiary);
    font-weight: 700;
    padding: 0 4px;
    flex-shrink: 0;
    transition: transform 0.3s ease;
}

/* 在線狀態分級：10秒內在線(綠/脈動) / 10-30秒剛剛在線(淡綠) / 其餘皆為離線(灰)並顯示秒/分/小時前 */
/* 用固定寬度＋置中文字，避免「在線」「12 分前」等長短不一的文字讓版面跟著跳動或撐出卡片 */
.presence-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 2px 7px;
    border-radius: 20px;
    font-size: 0.58rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    transition: all 0.3s ease;
    white-space: nowrap;
    max-width: 100%;
    width: fit-content;
    min-width: 44px;
    overflow: hidden;
    text-overflow: ellipsis;
    box-sizing: border-box;
}
.presence-pill .presence-dot {
    width: 6px; height: 6px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}
.presence-pill.online {
    background: rgba(48,209,88,0.16);
    color: var(--accent-green);
}
.presence-pill.online .presence-dot {
    background: var(--accent-green);
    animation: presencePulse 1.8s infinite;
}
.presence-pill.online-soft {
    background: rgba(48,209,88,0.08);
    color: rgba(154, 224, 178, 0.85);
}
.presence-pill.online-soft .presence-dot {
    background: rgba(48,209,88,0.55);
}
.presence-pill.offline {
    background: rgba(142,142,147,0.16);
    color: var(--accent-gray);
}
.presence-pill.offline .presence-dot { background: var(--accent-gray); }

@keyframes presencePulse {
    0% { box-shadow: 0 0 0 0 rgba(48,209,88,0.55); }
    70% { box-shadow: 0 0 0 6px rgba(48,209,88,0); }
    100% { box-shadow: 0 0 0 0 rgba(48,209,88,0); }
}

.game-section {
    width: 100%;
}

/* ===== 卡片區塊標題 ===== */
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}
.section-header .title {
    font-size: 0.92rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}
.section-header .hint {
    font-size: 0.7rem;
    color: var(--text-tertiary);
}


/* 重置按鈕 */
.btn-reset {
    background: var(--glass-fill-soft);
    border: 1px solid var(--glass-border);
    padding: 12px;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    width: 100%;
    margin-top: 14px;
    transition: all 0.2s;
    backdrop-filter: blur(20px);
}
.btn-reset:active {
    transform: scale(0.98);
    background: rgba(255,255,255,0.1);
    color: var(--text-primary);
}

/* ===== 勝率卡片 ===== */
.winrate-numbers {
    display: flex;
    justify-content: space-around;
}
.winrate-stat { text-align: center; }
.winrate-stat .wr-value {
    font-size: 1.7rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.02em;
}
.winrate-stat.me .wr-value { color: #FF6482; }
.winrate-stat.opp .wr-value { color: var(--accent-blue); }
.winrate-stat .wr-label {
    font-size: 0.68rem;
    color: var(--text-tertiary);
    margin-top: 2px;
}

/* ===== 對戰紀錄卡片 ===== */
.history-card {
    margin-bottom: 8px;
}
.history-list { display: flex; flex-direction: column; gap: 8px; }
.history-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.08);
}
.history-row .h-icon { font-size: 1.05rem; }
.history-row .h-info { flex: 1; }
.history-row .h-winner { font-size: 0.8rem; font-weight: 700; }
.history-row .h-meta { font-size: 0.68rem; color: var(--text-tertiary); }
.history-empty {
    text-align: center;
    font-size: 0.78rem;
    color: var(--text-tertiary);
    padding: 10px 0;
}

/* 磨砂玻璃背景特效 (慶祝動畫用) */
#blur-overlay {
    position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(6, 6, 10, 0.55); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
    z-index: 9990; opacity: 0; pointer-events: none; transition: opacity 0.4s ease;
}
#blur-overlay.active { opacity: 1; }

/* 粒子噴發動畫 */
.celebration-particle {
    position: fixed; pointer-events: none; z-index: 9999; font-size: 26px; user-select: none;
    animation: fallAndSpin 2.5s linear forwards;
}
@keyframes fallAndSpin {
    0% { transform: translateY(-50px) rotate(0deg) scale(0); opacity: 0; }
    10% { opacity: 1; transform: translateY(0px) rotate(36deg) scale(1.2); }
    90% { opacity: 1; }
    100% { transform: translateY(100vh) rotate(360deg) scale(0.8); opacity: 0; }
}
