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

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #0f0a1e;
    font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
}

#gameContainer {
    position: relative;
    width: 100vw;
    height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: radial-gradient(ellipse at center, #1a1040 0%, #0f0a1e 70%, #050310 100%);
    gap: 10px;
    padding: 10px;
}

#gameCanvas {
    display: block;
    background: #1a1230;
    border: 2px solid rgba(255, 180, 80, 0.3);
    border-radius: 10px;
    box-shadow:
        0 0 40px rgba(255, 180, 80, 0.15),
        inset 0 0 24px rgba(0, 0, 0, 0.5);
    touch-action: none;
    max-width: 100%;
    max-height: 100%;
}

/* HUD */
#hud {
    width: 100%;
    max-width: 520px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.hud-row {
    display: flex;
    justify-content: space-between;
    gap: 6px;
}
.hud-item {
    flex: 1;
    text-align: center;
    color: #e0c080;
    font-size: 13px;
    letter-spacing: 1px;
    padding: 7px 4px;
    background: rgba(255, 180, 80, 0.08);
    border: 1px solid rgba(255, 180, 80, 0.22);
    border-radius: 8px;
}
.hud-item span {
    color: #ffcc66;
    font-weight: bold;
    font-size: 15px;
    margin-left: 2px;
}
.hud-buttons {
    display: flex;
    gap: 6px;
    justify-content: center;
    flex-wrap: wrap;
}
.hud-btn {
    padding: 6px 14px;
    font-size: 13px;
    color: #f5e5c0;
    background: rgba(255, 180, 80, 0.12);
    border: 1px solid rgba(255, 180, 80, 0.3);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s;
}
.hud-btn:hover {
    background: rgba(255, 180, 80, 0.25);
    transform: translateY(-1px);
}
.hud-btn:active { transform: translateY(0); }

/* 覆盖层 */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: rgba(10, 5, 25, 0.9);
    backdrop-filter: blur(6px);
    color: #fff;
    z-index: 10;
    text-align: center;
    padding: 20px;
    overflow-y: auto;
}

.title {
    font-size: 48px;
    margin-bottom: 10px;
    background: linear-gradient(90deg, #ffcc66, #ff8a5c, #ff5e8c);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: 8px;
    animation: glow 2.2s ease-in-out infinite alternate;
}
.title.small {
    font-size: 34px;
    letter-spacing: 4px;
}
@keyframes glow {
    from { filter: brightness(1); }
    to   { filter: brightness(1.35); }
}

.trophy {
    font-size: 60px;
    margin-bottom: 8px;
    animation: bounce 0.8s ease infinite alternate;
}
@keyframes bounce {
    from { transform: translateY(0); }
    to   { transform: translateY(-10px); }
}

.subtitle {
    font-size: 15px;
    color: #a08060;
    margin-bottom: 20px;
}

.rules {
    max-width: 420px;
    background: rgba(255, 180, 80, 0.06);
    border: 1px solid rgba(255, 180, 80, 0.18);
    border-radius: 10px;
    padding: 12px 18px;
    margin-bottom: 16px;
    line-height: 1.8;
    color: #d8c090;
    font-size: 14px;
}
.rule-title {
    color: #ffcc66;
    font-weight: bold;
    margin-bottom: 4px;
    letter-spacing: 2px;
}

.instructions {
    margin: 4px 0 18px;
    color: #b09870;
    font-size: 13px;
    line-height: 2;
}
.key {
    display: inline-block;
    padding: 2px 10px;
    margin: 0 3px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 180, 80, 0.3);
    border-radius: 6px;
    font-family: monospace;
    color: #ffcc66;
    font-size: 12px;
}

/* 关卡选择 */
.level-select {
    margin-bottom: 20px;
    max-width: 480px;
    width: 100%;
}
.option-label {
    color: #c0a070;
    font-size: 13px;
    letter-spacing: 2px;
    margin-bottom: 10px;
}
.level-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 6px;
    max-width: 360px;
    margin: 0 auto;
}
.level-cell {
    aspect-ratio: 1 / 1;
    font-size: 13px;
    color: #e0c080;
    background: rgba(255, 180, 80, 0.08);
    border: 1px solid rgba(255, 180, 80, 0.22);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    position: relative;
}
.level-cell:hover {
    background: rgba(255, 180, 80, 0.22);
    transform: translateY(-1px);
}
.level-cell.cleared {
    background: linear-gradient(135deg, rgba(120, 200, 120, 0.3), rgba(80, 160, 80, 0.2));
    border-color: rgba(120, 220, 120, 0.5);
    color: #aaffaa;
}
.level-cell.cleared::after {
    content: '✓';
    position: absolute;
    top: 2px;
    right: 4px;
    font-size: 10px;
    color: #88ff88;
}
.level-cell.selected {
    background: linear-gradient(135deg, #ffcc66, #ff8a5c);
    border-color: #ffcc66;
    color: #20100a;
    font-weight: bold;
    box-shadow: 0 0 14px rgba(255, 180, 80, 0.5);
}

.btn {
    padding: 12px 40px;
    font-size: 17px;
    color: #20100a;
    background: linear-gradient(135deg, #ffcc66 0%, #ff8a5c 100%);
    border: none;
    border-radius: 30px;
    cursor: pointer;
    letter-spacing: 3px;
    font-weight: bold;
    box-shadow: 0 4px 22px rgba(255, 140, 80, 0.45);
    transition: transform 0.15s, box-shadow 0.15s;
    margin: 5px;
}
.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 28px rgba(255, 140, 80, 0.65);
}
.btn:active { transform: translateY(0); }
.btn-secondary {
    background: linear-gradient(135deg, #888, #555);
    color: #fff;
    box-shadow: 0 4px 20px rgba(120, 120, 120, 0.3);
}

.final-stats {
    font-size: 17px;
    line-height: 2;
    margin-bottom: 18px;
    color: #e0c8a0;
}
.final-stats span {
    color: #ffcc66;
    font-weight: bold;
}

/* 方向键 (移动端) */
#dpad {
    position: relative;
    width: 180px;
    height: 180px;
    margin-top: 4px;
    flex-shrink: 0;
}
.dpad-btn {
    position: absolute;
    width: 60px;
    height: 60px;
    font-size: 22px;
    color: #ffcc66;
    background: rgba(255, 180, 80, 0.12);
    border: 1px solid rgba(255, 180, 80, 0.3);
    border-radius: 12px;
    cursor: pointer;
}
.dpad-btn:active {
    background: rgba(255, 180, 80, 0.4);
}
.dpad-btn.up    { top: 0; left: 60px; }
.dpad-btn.down  { bottom: 0; left: 60px; }
.dpad-btn.left  { top: 60px; left: 0; }
.dpad-btn.right { top: 60px; right: 0; }

.hidden { display: none !important; }

/* 桌面端隐藏方向键 */
@media (hover: hover) and (pointer: fine) {
    #dpad { display: none !important; }
}

@media (max-width: 600px) {
    .title { font-size: 34px; letter-spacing: 5px; }
    .title.small { font-size: 26px; }
    .level-grid { grid-template-columns: repeat(6, 1fr); }
    .hud-item { font-size: 12px; padding: 6px 2px; }
    .hud-btn { padding: 5px 10px; font-size: 12px; }
    .rules { font-size: 13px; padding: 10px 14px; }
}
