* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    position: fixed;
    touch-action: none;
    margin: 0;
    padding: 0;
    /* 支持安全区域 */
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Microsoft YaHei', 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
    min-height: 100vh;
    min-height: -webkit-fill-available; /* iOS Safari */
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    -webkit-overflow-scrolling: touch;
}

.container {
    text-align: center;
    color: white;
    padding: 0;
    width: 100%;
    height: 100%;
    max-height: 100vh;
    max-height: -webkit-fill-available; /* iOS Safari */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    box-sizing: border-box;
    position: relative;
}

.game-area {
    position: relative;
    width: 100%;
    height: 100%;
    max-width: 100vw;
    max-height: 100vh;
    margin: 0;
    background: linear-gradient(to bottom, #0a0a0a 0%, #1a1a1a 100%);
    border-radius: 0;
    box-shadow: none;
    overflow: hidden;
    touch-action: none;
    box-sizing: border-box;
}

/* 平板和桌面端 */
@media (min-width: 769px) {
    .game-area {
        width: 800px;
        max-width: 800px;
        height: 600px;
        max-height: 600px;
        border-radius: 12px;
        box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
    }
}

/* 火苗样式 */
.flame {
    position: absolute;
    top: 8%;
    left: 5%;
    width: 50px;
    height: 60px;
    cursor: grab;
    z-index: 10;
    transition: transform 0.1s;
    touch-action: none;
}

.flame:active {
    cursor: grabbing;
    transform: scale(1.1);
}

.flame.touching {
    transform: scale(1.15);
    opacity: 0.9;
}

/* 移动端火苗尺寸调整 */
@media (max-width: 360px) {
    .flame {
        width: 40px;
        height: 50px;
        top: 6%;
        left: 4%;
    }
}

@media (min-width: 361px) and (max-width: 480px) {
    .flame {
        width: 45px;
        height: 55px;
        top: 7%;
        left: 4%;
    }
}

@media (min-width: 769px) {
    .flame {
        top: 50px;
        left: 20px;
    }
}

.flame-inner {
    width: 100%;
    height: 100%;
    background: radial-gradient(ellipse at center, #ff6b00 0%, #ff8c00 30%, #ff4500 60%, #ff0000 100%);
    border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
    box-shadow: 
        0 0 20px #ff6b00,
        0 0 40px #ff4500,
        inset 0 0 20px #ffaa00;
    animation: flicker 0.3s infinite alternate;
    position: relative;
}

.flame-inner::before {
    content: '';
    position: absolute;
    top: -10px;
    left: 50%;
    transform: translateX(-50%);
    width: 20px;
    height: 20px;
    background: radial-gradient(circle, #ffff00 0%, #ffaa00 50%, transparent 100%);
    border-radius: 50%;
    animation: flicker 0.2s infinite alternate;
}

@keyframes flicker {
    0% {
        transform: scale(1) translateX(0);
        opacity: 1;
    }
    100% {
        transform: scale(1.1) translateX(2px);
        opacity: 0.9;
    }
}

/* 爆竹容器 */
.firecracker-container {
    position: absolute;
    bottom: 12%;
    left: 50%;
    transform: translateX(-50%);
    z-index: 5;
}

@media (max-width: 360px) {
    .firecracker-container {
        bottom: 8%;
    }
}

@media (min-width: 361px) and (max-width: 480px) {
    .firecracker-container {
        bottom: 10%;
    }
}

@media (orientation: landscape) and (max-height: 500px) {
    .firecracker-container {
        bottom: 5%;
    }
}

@media (min-width: 769px) {
    .firecracker-container {
        bottom: 15%;
    }
}

/* 引信 */
.fuse {
    width: 6px;
    height: 90px;
    background: linear-gradient(to bottom, #8b4513 0%, #654321 50%, #3d2817 100%);
    margin: 0 auto;
    position: relative;
    border-radius: 3px;
    box-shadow: 
        0 0 10px rgba(0, 0, 0, 0.7), 
        inset 0 0 4px rgba(0, 0, 0, 0.4),
        0 2px 4px rgba(0, 0, 0, 0.5);
    z-index: 15;
    margin-bottom: 8px;
    border: 1px solid rgba(139, 69, 19, 0.5);
}

@media (max-width: 360px) {
    .fuse {
        width: 4px;
        height: 70px;
        margin-bottom: 5px;
    }
}

@media (min-width: 361px) and (max-width: 480px) {
    .fuse {
        width: 5px;
        height: 80px;
        margin-bottom: 6px;
    }
}

@media (orientation: landscape) and (max-height: 500px) {
    .fuse {
        height: 60px;
        margin-bottom: 4px;
    }
}

.fuse::after {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 6px;
    height: 6px;
    background: #ff6b00;
    border-radius: 50%;
    opacity: 0;
    transition: opacity 0.3s;
}

.fuse.burning::after {
    opacity: 1;
    animation: burn 0.5s infinite;
    box-shadow: 0 0 10px #ff4500;
}

.fuse.burning {
    background: linear-gradient(to bottom, #ff4500 0%, #ff6b00 30%, #8b4513 50%, #654321 100%);
    animation: burnDown 1.5s linear forwards;
}

@keyframes burn {
    0%, 100% {
        transform: translateX(-50%) scale(1);
    }
    50% {
        transform: translateX(-50%) scale(1.2);
    }
}

@keyframes burnDown {
    0% {
        background: linear-gradient(to bottom, #ff4500 0%, #ff6b00 30%, #8b4513 50%, #654321 100%);
    }
    100% {
        background: linear-gradient(to bottom, #ff4500 0%, #ff6b00 50%, #ff4500 80%, #ff6b00 100%);
    }
}

/* 爆竹串 */
.firecracker-string {
    position: relative;
    width: 200px;
    min-height: 600px;
    margin: 0 auto;
}

@media (max-width: 360px) {
    .firecracker-string {
        width: 130px;
        min-height: 450px;
    }
}

@media (min-width: 361px) and (max-width: 480px) {
    .firecracker-string {
        width: 150px;
        min-height: 500px;
    }
}

@media (orientation: landscape) and (max-height: 500px) {
    .firecracker-string {
        min-height: 350px;
    }
}

@media (min-width: 769px) {
    .firecracker-string {
        width: 250px;
        min-height: 700px;
    }
}

/* 单个爆竹节 */
.firecracker-segment {
    width: 35px;
    height: 25px;
    position: absolute;
    transition: opacity 0.1s, transform 0.1s;
    transform-origin: center center;
}

@media (max-width: 480px) {
    .firecracker-segment {
        width: 30px;
        height: 22px;
    }
}

@media (min-width: 769px) {
    .firecracker-segment {
        width: 40px;
        height: 28px;
    }
}

.firecracker-segment-body {
    width: 100%;
    height: 100%;
    background: linear-gradient(to right, #dc143c 0%, #b22222 50%, #dc143c 100%);
    border-radius: 4px;
    position: relative;
    box-shadow: 
        inset 0 0 10px rgba(0, 0, 0, 0.3),
        0 2px 8px rgba(0, 0, 0, 0.5);
    border: 1.5px solid #8b0000;
}

.firecracker-segment-pattern {
    width: 100%;
    height: 100%;
    background-image: 
        repeating-linear-gradient(0deg, transparent, transparent 8px, #ffd700 8px, #ffd700 9px),
        repeating-linear-gradient(90deg, transparent, transparent 6px, rgba(255, 255, 255, 0.1) 6px, rgba(255, 255, 255, 0.1) 7px);
    border-radius: 3px;
}

/* 连接线 - 使用伪元素创建弯曲的连接 */
.firecracker-segment::before {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 50%;
    transform: translateX(-50%);
    width: 3px;
    height: 2px;
    background: #654321;
    z-index: -1;
}

/* 爆炸状态 */
.firecracker-segment.exploded {
    opacity: 0 !important;
    transform: scale(0);
    transition: all 0.1s;
    pointer-events: none;
}

.firecracker-segment.exploding {
    animation: segmentShake 0.05s infinite;
}

/* 确保重置后爆竹节正常显示 */
.firecracker-segment:not(.exploded) {
    opacity: 1 !important;
    transform: none;
    pointer-events: auto;
}

@keyframes segmentShake {
    0%, 100% {
        transform: translateX(0) scale(1);
    }
    25% {
        transform: translateX(-2px) scale(1.05);
    }
    75% {
        transform: translateX(2px) scale(1.05);
    }
}

/* 爆炸画布 */
#explosionCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 20;
}

/* 拖拽提示 */
.flame.dragging {
    opacity: 0.8;
    transform: scale(1.2);
    z-index: 15;
}

/* 重置按钮样式优化 */
button {
    padding: 10px 20px;
    font-size: 0.85em;
    background: rgba(255, 255, 255, 0.25);
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.8);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
    touch-action: manipulation;
    -webkit-tap-highlight-color: rgba(255, 255, 255, 0.3);
    min-height: 44px; /* 移动端最小触摸区域 */
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(5px);
}

button:active {
    background: rgba(255, 255, 255, 0.4);
    transform: scale(0.95);
}

button:hover {
    background: rgba(255, 255, 255, 0.35);
}

@media (max-width: 360px) {
    button {
        padding: 8px 16px;
        font-size: 0.75em;
        min-height: 40px;
        top: 8px;
        right: 8px;
    }
}

@media (min-width: 361px) and (max-width: 480px) {
    button {
        padding: 10px 18px;
        font-size: 0.8em;
        min-height: 42px;
    }
}

@media (orientation: landscape) and (max-height: 500px) {
    button {
        padding: 6px 14px;
        font-size: 0.7em;
        min-height: 36px;
        top: 6px;
        right: 6px;
    }
}

@media (min-width: 769px) {
    button {
        padding: 12px 24px;
        font-size: 0.9em;
    }
}