* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
    background: #1a1a2e;
    color: #fff;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
}

#canvas-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

#canvas-container canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
}

/* ===== 加载界面 ===== */
#loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #1a1a2e, #16213e);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
}

.loading-content {
    text-align: center;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.1);
    border-top-color: #4ECDC4;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 20px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ===== 名字输入 ===== */
#name-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #1a1a2e, #16213e);
    z-index: 90;
    display: flex;
    align-items: center;
    justify-content: center;
}

.name-card {
    background: rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    padding: 40px 30px;
    text-align: center;
    width: 90%;
    max-width: 360px;
}

.name-card h2 {
    font-size: 28px;
    margin-bottom: 8px;
    background: linear-gradient(135deg, #4ECDC4, #45B7D1);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.name-card p {
    color: rgba(255, 255, 255, 0.6);
    margin-bottom: 20px;
    font-size: 14px;
}

.name-card input {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    background: rgba(0, 0, 0, 0.3);
    color: #fff;
    font-size: 16px;
    outline: none;
    transition: border-color 0.3s;
    margin-bottom: 16px;
}

.name-card input:focus {
    border-color: #4ECDC4;
}

.name-card button {
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: 12px;
    background: linear-gradient(135deg, #4ECDC4, #45B7D1);
    color: #fff;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.name-card button:active {
    transform: scale(0.97);
}

/* ===== 玩家列表 ===== */
#player-list {
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 10;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    max-width: calc(100% - 24px);
    pointer-events: none;
}

.player-tag {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    padding: 5px 12px 5px 8px;
    font-size: 13px;
    white-space: nowrap;
    transition: opacity 0.3s;
}

.player-tag .dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.player-tag.me {
    border-color: #4ECDC4;
    box-shadow: 0 0 8px rgba(78, 205, 196, 0.3);
}

.player-tag .pos {
    color: rgba(255, 255, 255, 0.5);
    font-size: 11px;
}

/* ===== 控制栏 ===== */
#control-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    z-index: 10;
    padding: 16px 20px 24px;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.7), transparent);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    flex-wrap: wrap;
}

.dice-display {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 60px;
    height: 60px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.15);
    font-size: 32px;
    font-weight: bold;
    color: #4ECDC4;
    flex-shrink: 0;
}

.dice-display.rolling {
    animation: diceShake 0.1s infinite;
}

@keyframes diceShake {
    0%, 100% { transform: translateX(0) rotate(0); }
    25% { transform: translateX(-2px) rotate(-3deg); }
    75% { transform: translateX(2px) rotate(3deg); }
}

.roll-btn {
    padding: 14px 36px;
    border: none;
    border-radius: 14px;
    background: linear-gradient(135deg, #FF6B6B, #FF8E53);
    color: #fff;
    font-size: 17px;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
    box-shadow: 0 4px 20px rgba(255, 107, 107, 0.4);
    flex-shrink: 0;
}

.roll-btn:active {
    transform: scale(0.95);
}

.roll-btn:disabled {
    background: rgba(255, 255, 255, 0.15);
    box-shadow: none;
    cursor: not-allowed;
    color: rgba(255, 255, 255, 0.4);
}

#position-info {
    font-size: 13px;
    color: rgba(255, 255, 255, 0.6);
    flex-shrink: 0;
}

#position-info span {
    color: #4ECDC4;
    font-weight: 600;
}

/* ===== 消息提示 ===== */
#toast {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 50;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    padding: 16px 28px;
    font-size: 15px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
    text-align: center;
    max-width: 80%;
}

#toast.show {
    opacity: 1;
}

#toast.trap {
    border-color: #FF6B6B;
    color: #FF6B6B;
}

#toast.win {
    border-color: #4ECDC4;
    color: #4ECDC4;
}

/* ===== 胜利弹窗 ===== */
#win-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 80;
    display: flex;
    align-items: center;
    justify-content: center;
}

.win-card {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(15px);
    border: 1px solid rgba(78, 205, 196, 0.3);
    border-radius: 20px;
    padding: 40px 30px;
    text-align: center;
    width: 90%;
    max-width: 340px;
}

.win-card h2 {
    font-size: 26px;
    margin-bottom: 12px;
}

.win-card p {
    color: rgba(255, 255, 255, 0.7);
    margin-bottom: 24px;
    font-size: 15px;
}

.win-actions {
    display: flex;
    gap: 12px;
}

.win-actions button {
    flex: 1;
    width: auto;
    padding: 12px;
    border: none;
    border-radius: 12px;
    background: linear-gradient(135deg, #4ECDC4, #45B7D1);
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
}

.win-actions button#win-close {
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.25);
}

.win-actions button:active {
    transform: scale(0.97);
}

/* ===== 返回按钮 ===== */
.back-btn {
    position: fixed;
    top: 12px;
    right: 12px;
    z-index: 20;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 20px;
    padding: 7px 14px;
    color: #fff;
    font-size: 13px;
    text-decoration: none;
    transition: background 0.2s;
}

.back-btn:active {
    background: rgba(0, 0, 0, 0.7);
}

/* ===== 游戏大厅 ===== */
.lobby-body {
    overflow: auto !important;
    touch-action: auto !important;
}

.lobby-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    z-index: 0;
}

.lobby-bg::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background:
        radial-gradient(circle at 20% 30%, rgba(78, 205, 196, 0.08) 0%, transparent 40%),
        radial-gradient(circle at 80% 70%, rgba(69, 183, 209, 0.08) 0%, transparent 40%);
}

.lobby-container {
    position: relative;
    z-index: 1;
    max-width: 1440px;
    margin: 0 auto;
    padding: 60px 20px 40px;
}

.lobby-header {
    text-align: center;
    margin-bottom: 40px;
}

.lobby-header h1 {
    font-size: 36px;
    background: linear-gradient(135deg, #4ECDC4, #45B7D1);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
}

.lobby-header p {
    color: rgba(255, 255, 255, 0.5);
    font-size: 15px;
}

.lobby-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 20px;
}

.game-card {
    display: flex;
    flex-direction: column;
    background: rgba(255, 255, 255, 0.06);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    padding: 28px 24px;
    text-decoration: none;
    color: #fff;
    transition: transform 0.25s, box-shadow 0.25s, border-color 0.25s;
}

.game-card:hover {
    transform: translateY(-4px);
    border-color: rgba(78, 205, 196, 0.4);
    box-shadow: 0 12px 40px rgba(78, 205, 196, 0.15);
}

.game-card:active {
    transform: translateY(-2px);
}

.game-card-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.game-card-body h2 {
    font-size: 20px;
    margin-bottom: 8px;
    color: #fff;
}

.game-card-body p {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.55);
    line-height: 1.6;
    margin-bottom: 14px;
    flex: 1;
}

.game-tag {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 12px;
    background: rgba(78, 205, 196, 0.15);
    color: #4ECDC4;
    border: 1px solid rgba(78, 205, 196, 0.2);
}

.lobby-footer {
    text-align: center;
    margin-top: 40px;
    color: rgba(255, 255, 255, 0.4);
    font-size: 13px;
}

@media (max-width: 768px) {
    .lobby-header h1 {
        font-size: 28px;
    }

    .lobby-grid {
        grid-template-columns: 1fr;
    }

    .game-card-icon {
        font-size: 40px;
    }
}

/* ===== 通用 ===== */
.hidden {
    display: none !important;
}

/* ===== 手机端适配 ===== */
@media (max-width: 768px) {
    .name-card {
        padding: 30px 20px;
    }

    .name-card h2 {
        font-size: 24px;
    }

    #player-list {
        top: 8px;
        left: 8px;
        gap: 4px;
    }

    .player-tag {
        font-size: 12px;
        padding: 4px 10px 4px 6px;
    }

    #control-bar {
        padding: 12px 16px 20px;
        gap: 14px;
    }

    .dice-display {
        width: 52px;
        height: 52px;
        font-size: 26px;
    }

    .roll-btn {
        padding: 12px 28px;
        font-size: 15px;
    }

    #position-info {
        font-size: 12px;
    }
}

@media (max-width: 400px) {
    #control-bar {
        gap: 10px;
    }

    .dice-display {
        width: 46px;
        height: 46px;
        font-size: 22px;
    }

    .roll-btn {
        padding: 10px 20px;
        font-size: 14px;
    }
}
