/* 
 * TeeTimeVN - 移动端优化样式
 * 触屏交互 + 手势支持
 */

/* ========== 移动端全局 ========== */
@media (max-width: 768px) {
    html {
        /* 防止 iOS Safari 橡皮筋效果 */
        overscroll-behavior: none;
    }

    body {
        /* 禁用文字选择提高触控体验 */
        -webkit-touch-callout: none;
    }

    /* 禁用长按菜单 */
    img,
    a {
        -webkit-touch-callout: none;
    }
}

/* ========== 触屏优化按钮 ========== */
.touch-btn {
    min-width: 48px;
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

/* 大号触控按钮 - 用于记分 */
.touch-btn-xl {
    width: 80px;
    height: 80px;
    font-size: 2rem;
    font-weight: 700;
    background: var(--color-bg-elevated);
    border: 2px solid rgba(212, 175, 55, 0.3);
    border-radius: var(--radius-lg);
    color: var(--color-text-primary);
    transition: all var(--transition-fast);
}

.touch-btn-xl:active {
    transform: scale(0.95);
    background: var(--color-primary);
    border-color: var(--color-accent);
}

/* ========== 滑动容器 ========== */
.swipe-container {
    overflow: hidden;
    touch-action: pan-y pinch-zoom;
}

.swipe-wrapper {
    display: flex;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform;
}

.swipe-slide {
    flex-shrink: 0;
    width: 100%;
}

/* 滑动指示器 */
.swipe-indicators {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    padding: 1rem 0;
}

.swipe-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--color-text-muted);
    transition: all var(--transition-fast);
}

.swipe-indicator.active {
    width: 24px;
    border-radius: 4px;
    background: var(--color-accent);
}

/* ========== 球员切换卡片 ========== */
.player-switcher {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.25rem;
    padding: 0.5rem 0;
}

/* 确保一排最多4个玩家 */
.player-switcher .player-card {
    flex: 0 0 23%;
    max-width: 23%;
    min-width: 50px;
    box-sizing: border-box;
}

/* 紧凑型玩家卡片（无头像） */
.player-card-compact {
    flex: 0 0 23%;
    max-width: 23%;
    min-width: 55px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.15rem;
    padding: 0.4rem 0.2rem;
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
    cursor: pointer;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid transparent;
}

.player-card-compact:active,
.player-card-compact.active {
    background: rgba(212, 175, 55, 0.15);
    border-color: var(--color-accent);
}

.player-card-compact .player-name {
    font-size: 0.7rem;
    color: var(--color-text-secondary);
    white-space: nowrap;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: center;
}

.player-card-compact.active .player-name {
    color: var(--color-accent);
    font-weight: 600;
}

.player-card-compact .player-score {
    font-size: 0.85rem;
    font-weight: 700;
}

.player-switcher::-webkit-scrollbar {
    display: none;
}

.player-card {
    flex-shrink: 0;
    scroll-snap-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.375rem;
    padding: 0.5rem;
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
    cursor: pointer;
}

.player-card:active,
.player-card.active {
    background: rgba(212, 175, 55, 0.15);
}

.player-card.active .avatar {
    border-color: var(--color-accent);
    box-shadow: 0 0 12px rgba(212, 175, 55, 0.4);
}

.player-card .player-name {
    font-size: 0.75rem;
    color: var(--color-text-secondary);
    white-space: nowrap;
    max-width: 60px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.player-card.active .player-name {
    color: var(--color-accent);
    font-weight: 600;
}

/* ========== 记分组件 ========== */
.scoring-panel {
    background: var(--color-bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid rgba(212, 175, 55, 0.15);
    padding: 1.5rem;
}

.scoring-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}

.hole-info {
    text-align: center;
}

.hole-number {
    font-family: var(--font-display);
    font-size: 3rem;
    font-weight: 700;
    line-height: 1;
    background: var(--gradient-gold);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.hole-par {
    font-size: 0.875rem;
    color: var(--color-text-muted);
    margin-top: 0.25rem;
}

.hole-index {
    font-size: 0.75rem;
    color: var(--color-text-muted);
}

/* 步进器 */
.stepper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.stepper-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.stepper-controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

.stepper-btn {
    width: 56px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-bg-elevated);
    border: 2px solid rgba(212, 175, 55, 0.2);
    border-radius: var(--radius-md);
    color: var(--color-accent);
    font-size: 1.5rem;
    font-weight: 700;
    cursor: pointer;
    transition: all var(--transition-fast);
    -webkit-tap-highlight-color: transparent;
}

.stepper-btn:active {
    background: var(--color-primary);
    transform: scale(0.95);
}

.stepper-value {
    font-family: var(--font-display);
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--color-text-primary);
    min-width: 56px;
    text-align: center;
    line-height: 1;
    padding: 0.5rem 0;
}

/* 总杆显示 */
.total-strokes {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-width: 100px;
}

.total-value {
    font-family: var(--font-display);
    font-size: 4rem;
    font-weight: 700;
    line-height: 1;
    color: var(--color-text-primary);
}

.total-label {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    margin-top: 0.25rem;
}

/* 相对标准杆标签 */
.relative-par-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.25rem 0.75rem;
    border-radius: var(--radius-full);
    font-size: 0.875rem;
    font-weight: 600;
    margin-top: 0.5rem;
}

.relative-par-badge.eagle {
    background: rgba(234, 179, 8, 0.2);
    color: var(--color-eagle);
}

.relative-par-badge.birdie {
    background: rgba(34, 197, 94, 0.2);
    color: var(--color-birdie);
}

.relative-par-badge.par {
    background: rgba(255, 255, 255, 0.1);
    color: var(--color-text-secondary);
}

.relative-par-badge.bogey {
    background: rgba(249, 115, 22, 0.2);
    color: var(--color-bogey);
}

.relative-par-badge.double-bogey {
    background: rgba(239, 68, 68, 0.2);
    color: var(--color-double-bogey);
}

/* ========== 横屏记分卡 ========== */
@media (orientation: landscape) {
    .scoring-landscape {
        display: flex;
        gap: 1rem;
        padding: 0.5rem;
    }

    .scoring-landscape .hole-info {
        flex-shrink: 0;
        width: 120px;
    }

    .scoring-landscape .scoring-inputs {
        flex: 1;
        display: flex;
        justify-content: space-around;
    }
}

/* ========== 记分卡表格 ========== */
.scorecard-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
    background: var(--color-bg-card);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.scorecard-table th,
.scorecard-table td {
    padding: 0.5rem 0.375rem;
    text-align: center;
    border: 1px solid rgba(212, 175, 55, 0.1);
}

.scorecard-table th {
    background: var(--color-bg-elevated);
    font-weight: 600;
    color: var(--color-text-secondary);
    font-size: 0.75rem;
}

.scorecard-table .hole-row th {
    background: var(--color-primary);
    color: white;
}

.scorecard-table .par-row td {
    background: rgba(26, 95, 59, 0.3);
    font-weight: 500;
}

.scorecard-table .player-row td {
    font-weight: 600;
}

.scorecard-table .player-name {
    text-align: left;
    padding-left: 0.75rem;
    white-space: nowrap;
    max-width: 80px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.scorecard-table .total-col {
    background: rgba(212, 175, 55, 0.1);
    font-weight: 700;
}

/* 成绩高亮 - 表格内使用边框圆圈 */
.scorecard-table .score-birdie {
    position: relative;
}

.scorecard-table .score-birdie::after {
    content: '';
    position: absolute;
    inset: 4px;
    border: 2px solid var(--color-birdie);
    border-radius: 50%;
}

.scorecard-table .score-eagle {
    position: relative;
}

.scorecard-table .score-eagle::after {
    content: '';
    position: absolute;
    inset: 2px;
    border: 3px double var(--color-eagle);
    border-radius: 50%;
}

.scorecard-table .score-bogey {
    position: relative;
}

.scorecard-table .score-bogey::after {
    content: '';
    position: absolute;
    inset: 4px;
    border: 2px solid var(--color-bogey);
}

.scorecard-table .score-double-bogey {
    position: relative;
}

.scorecard-table .score-double-bogey::after {
    content: '';
    position: absolute;
    inset: 2px;
    border: 3px double var(--color-double-bogey);
}

/* 成绩高亮 - 玩家卡片内只使用颜色 */
.player-score.score-eagle {
    color: #fbbf24;
}

.player-score.score-birdie {
    color: #22c55e;
}

.player-score.score-par {
    color: var(--color-text-primary);
}

.player-score.score-bogey {
    color: #f97316;
}

.player-score.score-double {
    color: #ef4444;
}

/* ========== 球道图背景 ========== */
.hole-background {
    position: absolute;
    inset: 0;
    opacity: 0.1;
    background-size: cover;
    background-position: center;
    pointer-events: none;
    z-index: 0;
}

/* ========== 导航手势区域 ========== */
.nav-gesture-left,
.nav-gesture-right {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    width: 60px;
    height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.nav-gesture-left {
    left: 0;
}

.nav-gesture-right {
    right: 0;
}

.nav-gesture-left:active,
.nav-gesture-right:active {
    opacity: 1;
}

.nav-gesture-icon {
    width: 40px;
    height: 40px;
    background: rgba(212, 175, 55, 0.3);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-accent);
    font-size: 1.25rem;
}

/* ========== 震动反馈视觉提示 ========== */
.haptic-feedback {
    animation: hapticPulse 0.15s ease;
}

@keyframes hapticPulse {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(0.95);
        box-shadow: 0 0 20px rgba(212, 175, 55, 0.5);
    }

    100% {
        transform: scale(1);
    }
}

/* ========== 二维码显示 ========== */
.qr-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 2rem;
    background: white;
    border-radius: var(--radius-lg);
    margin: 1rem 0;
}

.qr-code {
    width: 200px;
    height: 200px;
}

.qr-code-text {
    margin-top: 1rem;
    font-family: var(--font-display);
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: 0.2em;
    color: var(--color-primary);
}

/* ========== 等待房间 ========== */
.lobby-players {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    margin: 1.5rem 0;
}

.lobby-player-slot {
    aspect-ratio: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    background: var(--color-bg-card);
    border: 2px dashed rgba(212, 175, 55, 0.2);
    border-radius: var(--radius-lg);
    transition: all var(--transition-normal);
}

.lobby-player-slot.filled {
    border-style: solid;
    border-color: rgba(212, 175, 55, 0.4);
    background: var(--color-bg-elevated);
}

.lobby-player-slot.host {
    border-color: var(--color-accent);
    box-shadow: var(--shadow-glow);
}

.lobby-player-slot .avatar {
    width: 64px;
    height: 64px;
    font-size: 1.5rem;
}

.lobby-player-slot .waiting-icon {
    font-size: 2rem;
    color: var(--color-text-muted);
}

/* ========== 安全区域适配 ========== */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .bottom-fixed {
        padding-bottom: calc(1rem + env(safe-area-inset-bottom));
    }
}

/* ========== 暗黑模式增强（如系统为亮色时） ========== */
@media (prefers-color-scheme: light) {
    /* 保持深色主题，不跟随系统 */
}

/* ========== 高刷新率优化 ========== */
@media (prefers-reduced-motion: no-preference) {
    .smooth-scroll {
        scroll-behavior: smooth;
    }
}

/* ========== 大屏幕横屏适配 ========== */
@media (min-width: 768px) and (orientation: landscape) {
    .container {
        max-width: 960px;
    }

    .scoring-panel {
        padding: 2rem 3rem;
    }

    .scorecard-table {
        font-size: 1rem;
    }

    .scorecard-table th,
    .scorecard-table td {
        padding: 0.75rem 0.5rem;
    }
}