/* 全局样式 */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* 定义安全区域变量默认值 */
:root {
    --safe-area-inset-top: 0px;
    --safe-area-inset-bottom: 0px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: #f5f5f5;
    color: #333;
    line-height: 1.6;
    /* 适配iOS设备 */
    -webkit-text-size-adjust: 100%;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    -webkit-tap-highlight-color: transparent;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

/* 头部样式 */
header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px 0;
    padding-top: calc(20px + var(--safe-area-inset-top)); /* 适配iOS刘海屏 */
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    /* iOS上固定头部时的处理 */
    position: relative;
    z-index: 10;
}

header h1 {
    font-size: 24px;
    font-weight: 600;
}

/* 游戏状态卡片 */
.bg-white {
    background-color: white;
}

.rounded-xl {
    border-radius: 12px;
}

.shadow-md {
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.p-6 {
    padding: 24px;
}

.mb-8 {
    margin-bottom: 32px;
}

/* 玩家卡片 */
#playersContainer {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 20px;
}

.player-card {
    background-color: #f8f9fa;
    border-radius: 8px;
    padding: 16px;
    text-align: center;
    transition: all 0.3s ease;
    border: 1px solid #e9ecef;
}

.player-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 15px rgba(0, 0, 0, 0.1);
}

.player-avatar {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    overflow: hidden;
    margin: 0 auto 12px;
    border: 3px solid #e9ecef;
}

.player-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* 按钮样式 */
button {
    cursor: pointer;
    border: none;
    border-radius: 4px;
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    /* 适配iOS触摸反馈 */
    -webkit-appearance: none;
    appearance: none;
    touch-action: manipulation;
}

#startGameBtn {
    background-color: #28a745;
    color: white;
}

#startGameBtn:hover:not(:disabled) {
    background-color: #218838;
}

#startGameBtn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#newGameBtn {
    background-color: white;
    color: #667eea;
}

#newGameBtn:hover {
    background-color: #f8f9fa;
}

#submitScoreBtn {
    background-color: #667eea;
    color: white;
    padding: 12px 32px;
    font-size: 16px;
    border-radius: 25px;
}

#submitScoreBtn:hover {
    background-color: #5a67d8;
    transform: translateY(-1px);
}

/* 记分区域样式 */
#scoreSection {
    background-color: white;
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    margin-bottom: 32px;
}

#scoreForm > div {
    margin-bottom: 20px;
    padding: 16px;
    background-color: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #e9ecef;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

#scoreForm > div > div:first-child {
    display: flex;
    align-items: center;
}

#scoreForm > div > div:first-child img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    margin-right: 12px;
}

/* 开关按钮样式 */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 60px;
    height: 30px;
    margin-right: 10px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 34px;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 22px;
    width: 22px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked + .toggle-slider {
    background-color: #28a745;
}

input:checked + .toggle-slider:before {
    transform: translateX(30px);
}

/* 输入框样式 */
.score-input {
    width: 80px;
    padding: 8px 12px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 14px;
    text-align: center;
    /* 适配iOS输入框样式 */
    -webkit-appearance: none;
    appearance: none;
    background-clip: padding-box;
}

.score-input:focus {
    border-color: #667eea;
    outline: none;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.2);
}

/* 结果列表样式 */
#resultsList > div {
    margin-bottom: 16px;
    padding: 16px;
    background-color: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #e9ecef;
    border-left: 4px solid #667eea;
}

/* 统计表格样式 */
table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid #e9ecef;
}

th {
    background-color: #f8f9fa;
    font-weight: 600;
    color: #495057;
}

tr:hover {
    background-color: #f8f9fa;
}

/* 动画效果 */
.fade-in {
    animation: fadeIn 0.5s ease-in;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* 红色警告窗口样式 */
.warning-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.warning-container {
    background-color: white;
    border-radius: 8px;
    padding: 24px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    border-left: 4px solid #dc3545;
}

.warning-title {
    color: #dc3545;
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 12px;
}

.warning-message {
    color: #6c757d;
    margin-bottom: 20px;
    line-height: 1.5;
}

.warning-close-btn {
    background-color: #dc3545;
    color: white;
    border: none;
    border-radius: 4px;
    padding: 10px 20px;
    font-size: 14px;
    cursor: pointer;
    width: 100%;
    transition: background-color 0.3s ease;
}

.warning-close-btn:hover {
    background-color: #c82333;
}

/* 响应式设计 */
@media (max-width: 768px) {
    #playersContainer {
        grid-template-columns: repeat(2, 1fr);
    }
    
    #scoreForm > div {
        flex-direction: column;
        align-items: flex-start;
    }
    
    #scoreForm > div > div:last-child {
        margin-top: 12px;
    }
}

@media (max-width: 480px) {
    #playersContainer {
        grid-template-columns: 1fr;
    }
    
    header h1 {
        font-size: 20px;
    }
    
    .p-6 {
        padding: 16px;
    }
    
    /* 移动端底部内容适配iOS安全区域 */
    .ios-safe-bottom {
        padding-bottom: calc(16px + var(--safe-area-inset-bottom));
    }
}

/* iOS PWA模式下的特殊样式 */
@media (display-mode: standalone) {
    body {
        /* 移除iOS Safari默认的滚动条行为 */
        -webkit-overflow-scrolling: touch;
    }
    
    /* 适配横屏模式 */
    @media (orientation: landscape) {
        /* 确保在横屏模式下内容不会被遮挡 */
        header {
            padding-left: 16px;
            padding-right: 16px;
        }
        
        .container {
            padding-left: 16px;
            padding-right: 16px;
        }
    }
}