:root {
    --bg: #1a1a2e;
    --card: #16213e;
    --accent: #e94560;
    --cat: #f59e0b;
    --dog: #6366f1;
    --text: #f1f5f9;
    --text-dim: #94a3b8;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background: var(--bg);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
}

.game-container {
    position: relative;
    width: 100%;
    max-width: 500px;
    height: 100vh;
    max-height: 850px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 10px;
}

/* ===== Overlay (Mode/Side Selection) ===== */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(26, 26, 46, 0.92);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-radius: 16px;
    z-index: 30;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.35s ease;
}

.overlay.active {
    opacity: 1;
    pointer-events: all;
}

.overlay-content {
    text-align: center;
    padding: 24px;
    max-width: 320px;
}

.overlay-logo {
    font-size: 3.5rem;
    margin-bottom: 8px;
    animation: popIn 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.overlay-title {
    font-size: 1.5rem;
    font-weight: 900;
    color: var(--text);
    margin-bottom: 4px;
    background: linear-gradient(135deg, var(--cat), var(--dog));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.overlay-desc {
    font-size: 0.85rem;
    color: var(--text-dim);
    margin-bottom: 20px;
    letter-spacing: 0.5px;
}

.mode-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.mode-btn {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px 20px;
    background: var(--card);
    border: 2px solid rgba(255, 255, 255, 0.08);
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.25s ease;
    text-align: left;
    width: 100%;
}

.mode-btn:hover {
    border-color: var(--accent);
    background: rgba(233, 69, 96, 0.1);
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(233, 69, 96, 0.15);
}

.mode-btn:active {
    transform: translateY(0);
}

.mode-icon {
    font-size: 2rem;
    flex-shrink: 0;
}

.mode-label {
    display: block;
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: 0.5px;
}

.mode-sub {
    display: block;
    font-size: 0.75rem;
    color: var(--text-dim);
    margin-top: 2px;
}

.back-btn {
    margin-top: 16px;
    padding: 10px 24px;
    font-size: 0.85rem;
    font-weight: 600;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-dim);
    transition: all 0.2s ease;
}

.back-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    color: var(--text);
}

/* ===== Mode Badge ===== */
.mode-badge {
    position: absolute;
    top: 10px;
    right: 14px;
    z-index: 15;
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 4px 12px;
    background: rgba(22, 33, 62, 0.8);
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: var(--text-dim);
    pointer-events: none;
}

/* ===== Header ===== */
.game-header {
    width: 100%;
    padding: 0 4px;
    margin-bottom: 10px;
    margin-top: 4px;
    z-index: 10;
}

.player-info {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.player-card {
    background: var(--card);
    border-radius: 16px;
    padding: 10px 18px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    min-width: 90px;
    transition: all 0.3s ease;
    border: 2px solid transparent;
}

.player-card.active-cat {
    border-color: var(--cat);
    box-shadow: 0 0 20px rgba(245, 158, 11, 0.25);
}

.player-card.active-dog {
    border-color: var(--dog);
    box-shadow: 0 0 20px rgba(99, 102, 241, 0.25);
}

.player-icon {
    font-size: 1.5rem;
}

.player-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-dim);
    font-weight: 600;
}

.player-score {
    font-size: 1.3rem;
    font-weight: 800;
    background: linear-gradient(135deg, #e94560, #f59e0b);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* ===== Turn Indicator ===== */
.turn-indicator {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 8px 16px;
    background: var(--card);
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.turn-icon {
    font-size: 1.8rem;
    animation: bounce 1s ease-in-out infinite;
}

.turn-icon.thinking {
    animation: think 0.6s ease-in-out infinite alternate;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}

@keyframes think {
    0% { transform: scale(1) rotate(0deg); }
    25% { transform: scale(1.1) rotate(-5deg); }
    75% { transform: scale(1.1) rotate(5deg); }
    100% { transform: scale(1) rotate(0deg); }
}

.turn-text {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text);
    white-space: nowrap;
}

/* ===== Canvas ===== */
.board-wrapper {
    position: relative;
    width: 100%;
    display: flex;
    justify-content: center;
}

canvas {
    display: block;
    border-radius: 16px;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(233, 69, 96, 0.15);
    width: 100%;
    height: auto;
    aspect-ratio: 1;
    background: #f5e6c8;
    touch-action: none;
}

/* ===== Footer ===== */
.game-footer {
    width: 100%;
    display: flex;
    justify-content: center;
    margin-top: 10px;
    z-index: 10;
}

.restart-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 32px;
    font-size: 0.95rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    background: linear-gradient(135deg, var(--cat), var(--dog));
    color: white;
    transition: all 0.3s ease;
    box-shadow: 0 6px 24px rgba(233, 69, 96, 0.25);
    text-transform: uppercase;
}

.restart-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 32px rgba(233, 69, 96, 0.35);
}

.restart-btn:active {
    transform: translateY(0);
    box-shadow: 0 4px 16px rgba(233, 69, 96, 0.25);
}

/* ===== Game Over Overlay ===== */
.game-over-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: rgba(26, 26, 46, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-radius: 16px;
    z-index: 20;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
}

.game-over-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.game-over-icon {
    font-size: 4rem;
    margin-bottom: 4px;
    animation: popIn 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes popIn {
    0% { transform: scale(0); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

.game-over-title {
    font-size: 2.2rem;
    font-weight: 900;
    text-align: center;
    background: linear-gradient(135deg, var(--cat), var(--dog), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.game-over-detail {
    font-size: 1rem;
    color: var(--text-dim);
    letter-spacing: 1px;
    margin-bottom: 8px;
}

.play-again-btn {
    padding: 14px 48px;
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: 1px;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    background: linear-gradient(135deg, var(--cat), var(--dog));
    color: white;
    transition: all 0.3s ease;
    box-shadow: 0 8px 30px rgba(233, 69, 96, 0.3);
    text-transform: uppercase;
}

.play-again-btn:hover {
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 12px 40px rgba(233, 69, 96, 0.4);
}

/* ===== 竖屏手机适配 ===== */
@media (max-width: 420px) and (orientation: portrait) {
    .game-container {
        padding: 6px;
        max-height: 100vh;
    }
    .player-card {
        padding: 6px 10px;
        min-width: 65px;
    }
    .player-icon {
        font-size: 1.1rem;
    }
    .player-label {
        font-size: 0.55rem;
    }
    .player-score {
        font-size: 1rem;
    }
    .turn-indicator {
        padding: 5px 8px;
    }
    .turn-icon {
        font-size: 1.3rem;
    }
    .turn-text {
        font-size: 0.55rem;
    }
    .game-over-title {
        font-size: 1.6rem;
    }
    .game-over-icon {
        font-size: 3rem;
    }
    .restart-btn, .play-again-btn {
        padding: 8px 20px;
        font-size: 0.8rem;
    }
    .overlay-title {
        font-size: 1.1rem;
    }
    .overlay-desc {
        font-size: 0.75rem;
    }
    .mode-btn {
        padding: 10px 14px;
    }
    .mode-icon {
        font-size: 1.4rem;
    }
    .mode-label {
        font-size: 0.9rem;
    }
    .game-footer {
        margin-top: 6px;
    }
    canvas {
        border-radius: 12px;
    }
}

/* ===== 横屏手机适配 ===== */
@media (max-width: 900px) and (orientation: landscape) {
    .game-container {
        max-width: 100%;
        max-height: 100vh;
        flex-direction: row;
        flex-wrap: wrap;
        padding: 4px 8px;
        gap: 4px;
        justify-content: center;
        align-content: center;
    }
    .game-header {
        width: 100%;
        margin-bottom: 4px;
        margin-top: 0;
        flex-shrink: 0;
    }
    .player-card {
        padding: 4px 10px;
        min-width: 70px;
    }
    .player-icon {
        font-size: 1.1rem;
    }
    .player-label {
        font-size: 0.55rem;
    }
    .player-score {
        font-size: 1rem;
    }
    .turn-indicator {
        padding: 4px 10px;
        flex-direction: row;
        gap: 4px;
    }
    .turn-icon {
        font-size: 1.2rem;
    }
    .turn-text {
        font-size: 0.55rem;
    }
    .board-wrapper {
        flex: 1;
        min-height: 0;
        max-height: 78vh;
        display: flex;
        justify-content: center;
        align-items: center;
    }
    canvas {
        max-height: 100%;
        width: auto;
        height: auto;
    }
    .game-footer {
        width: auto;
        margin-top: 0;
        flex-shrink: 0;
        margin-left: auto;
    }
    .restart-btn {
        padding: 8px 16px;
        font-size: 0.8rem;
    }
    .game-over-title {
        font-size: 1.5rem;
    }
    .game-over-icon {
        font-size: 2.5rem;
    }
    .play-again-btn {
        padding: 10px 28px;
        font-size: 0.85rem;
    }
    .mode-badge {
        top: 4px;
        right: 8px;
        font-size: 0.55rem;
        padding: 2px 8px;
    }
    .overlay-content {
        padding: 16px;
        max-width: 280px;
    }
    .overlay-title {
        font-size: 1.1rem;
    }
    .overlay-desc {
        font-size: 0.75rem;
        margin-bottom: 12px;
    }
    .mode-btn {
        padding: 10px 14px;
        gap: 10px;
    }
    .mode-icon {
        font-size: 1.4rem;
    }
    .mode-label {
        font-size: 0.9rem;
    }
}
