/* ═══════════════════════════════════════════════════════════════ */
/* 🧩 像素离散·拼图冒险 — 全新游戏风格 UI v5.1                     */
/* ═══════════════════════════════════════════════════════════════ */

:root {
    --bg: #0c0e1a;
    --bg-card: #161929;
    --bg-surface: #1c2035;
    --border: rgba(255,255,255,0.06);
    --border-hover: rgba(255,255,255,0.15);
    --text: #e8eaf0;
    --text-sub: #8b91a8;
    --text-muted: #4a4f6a;
    --gold: #fbbf24;
    --gold-dim: rgba(251,191,36,0.12);
    --pink: #f472b6;
    --purple: #8b5cf6;
    --green: #10b981;
    --red: #ef4444;
    --blue: #60a5fa;
    --cyan: #22d3ee;
    --radius: 14px;
    --shadow: 0 8px 32px rgba(0,0,0,0.5);
    --glow-gold: 0 0 20px rgba(251,191,36,0.3);
    --glow-purple: 0 0 20px rgba(139,92,246,0.3);
    --glow-cyan: 0 0 20px rgba(34,211,238,0.3);
}

/* ═══ 亮色主题 ═══ */
[data-theme="light"] {
    --bg: #f0f4ff;
    --bg-card: rgba(255,255,255,0.85);
    --bg-surface: rgba(240,245,255,0.9);
    --border: rgba(180,200,240,0.3);
    --border-hover: rgba(100,140,220,0.4);
    --text: #1a1a2e;
    --text-sub: #5a6a7e;
    --text-muted: #94a3b8;
    --gold-dim: rgba(245,158,11,0.08);
    --shadow: 0 4px 20px rgba(100,140,220,0.12);
    --glow-gold: 0 0 15px rgba(245,158,11,0.2);
    --glow-purple: 0 0 15px rgba(139,92,246,0.15);
    --glow-cyan: 0 0 15px rgba(34,211,238,0.15);
}
[data-theme="light"] body { background: linear-gradient(135deg, #e8eeff 0%, #f4f0ff 35%, #eef6ff 65%, #f0f4ff 100%); background-attachment: fixed; }

/* ═══ 亮色主题组件覆盖 ═══ */
[data-theme="light"] .rpg-node-img-wrap { filter: drop-shadow(0 4px 12px rgba(100,140,220,0.2)); }
[data-theme="light"] .rpg-node.locked .rpg-node-img { filter: brightness(0.6) saturate(0.4); }
[data-theme="light"] .mask-text { color: rgba(30,41,59,0.8); text-shadow: 0 1px 4px rgba(255,255,255,0.8); }
[data-theme="light"] .mask-hint { color: rgba(30,41,59,0.5); text-shadow: 0 1px 3px rgba(255,255,255,0.6); }
[data-theme="light"] .region-header { background: rgba(255,255,255,0.88); backdrop-filter: blur(12px); border-bottom-color: rgba(180,200,240,0.3); }
[data-theme="light"] .region-story { color: #5a6a7e; background: rgba(240,245,255,0.8); border-color: rgba(180,200,240,0.25); }
[data-theme="light"] .stage-card { background: rgba(255,255,255,0.85); border-color: rgba(180,200,240,0.3); }
[data-theme="light"] .stage-card:hover:not(.locked) { border-color: var(--gold); }
[data-theme="light"] .stage-info { background: linear-gradient(to top, rgba(255,255,255,0.95) 60%, transparent); }
[data-theme="light"] .stage-number { color: #94a3b8; }
[data-theme="light"] .stage-name { color: #1e293b; }
[data-theme="light"] .game-topbar { background: rgba(255,255,255,0.88); backdrop-filter: blur(12px); border-bottom-color: rgba(180,200,240,0.3); }
[data-theme="light"] .back-btn { color: #5a6a7e; }
[data-theme="light"] .back-btn:hover { color: #1e293b; background: rgba(100,140,220,0.08); }
[data-theme="light"] .game-diff-badge { background: rgba(245,158,11,0.1); color: #92400e; }
[data-theme="light"] .tool-btn { background: rgba(240,245,255,0.8); border-color: rgba(180,200,240,0.3); color: #5a6a7e; }
[data-theme="light"] .game-stats-bar { background: rgba(255,255,255,0.88); border-bottom-color: rgba(180,200,240,0.3); }
[data-theme="light"] .puzzle-board { background: rgba(240,245,255,0.9); border-color: rgba(180,200,240,0.3); box-shadow: 0 12px 40px rgba(100,140,220,0.12); }
[data-theme="light"] .puzzle-slot { background: rgba(100,140,220,0.04); border-color: rgba(180,200,240,0.2); }
[data-theme="light"] .puzzle-slot.drag-over { box-shadow: inset 0 0 16px rgba(245,158,11,0.2), 0 0 12px rgba(245,158,11,0.15); }
[data-theme="light"] .modal-overlay { background: rgba(100,120,180,0.4); backdrop-filter: blur(12px); }
[data-theme="light"] .win-modal { background: rgba(255,255,255,0.95); border-color: rgba(180,200,240,0.3); }
[data-theme="light"] .shop-modal { background: rgba(255,255,255,0.95); border-color: rgba(180,200,240,0.3); }
[data-theme="light"] .shop-item { background: rgba(240,245,255,0.8); border-color: rgba(180,200,240,0.25); }
[data-theme="light"] .btn-ghost { background: rgba(240,245,255,0.8); border-color: rgba(180,200,240,0.3); color: #5a6a7e; }
[data-theme="light"] .preview-overlay { background: rgba(100,120,180,0.6); }
[data-theme="light"] .site-footer { color: #94a3b8; border-top-color: rgba(180,200,240,0.3); }
[data-theme="light"] .site-footer a { color: #5a6a7e; }
[data-theme="light"] .btn-shop { background: rgba(255,255,255,0.85); border-color: rgba(180,200,240,0.3); color: #5a6a7e; }

/* ═══ 基础 ═══ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    margin: 0;
    overflow-x: hidden;
}
a { color: var(--text-sub); text-decoration: none; transition: color 0.15s; }
a:hover { color: var(--text); }

.view { display: none; min-height: 100vh; flex-direction: column; }
.view.active { display: flex; }

#mapView {
    position: relative;
    background: transparent;
}
#mapView::before {
    content: '';
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(12,14,26,0.65);
    z-index: 0; pointer-events: none;
}
#mapView > * { position: relative; z-index: 1; }
[data-theme="light"] #mapView { background: transparent; }
[data-theme="light"] #mapView::before { background: rgba(240,244,255,0.7); }


/* ═══════════════════════════════════════ */
/* 🗺️ RPG 世界地图                         */
/* ═══════════════════════════════════════ */
.region-path {
    position: relative;
    width: 100%; margin: 0 auto;
    aspect-ratio: 9/16;
    min-height: 700px;
    padding: 0 10%;
}

/* SVG 路径线 */
.map-svg-path {
    position: absolute; top: 0; left: 10%; right: 10%;
    width: 80%; height: 100%;
    z-index: 1; pointer-events: none;
}
.map-path-line {
    fill: none; stroke: rgba(255,255,255,0.08);
    stroke-width: 0.6; stroke-linecap: round;
}
.map-path-line.unlocked {
    stroke: rgba(16,185,129,0.35); stroke-width: 0.6;
}
.map-path-dash {
    fill: none; stroke: rgba(251,191,36,0.5);
    stroke-width: 0.3; stroke-linecap: round;
    stroke-dasharray: 1.5 2;
    animation: dashFlow 12s linear infinite;
}
@keyframes dashFlow {
    to { stroke-dashoffset: -40; }
}
[data-theme="light"] .map-path-line { stroke: rgba(180,200,240,0.2); }
[data-theme="light"] .map-path-line.unlocked { stroke: rgba(16,185,129,0.25); }
[data-theme="light"] .map-path-dash { stroke: rgba(245,158,11,0.4); }

/* RPG 节点 */
.rpg-node {
    position: absolute; z-index: 2;
    transform: translate(-50%, -50%);
    cursor: pointer; transition: transform 0.3s, filter 0.3s;
    display: flex; flex-direction: column; align-items: center;
    gap: 2px; width: 400px;
}
.rpg-node:hover:not(.locked) {
    transform: translate(-50%, -50%) scale(1.08);
    z-index: 10;
}
.rpg-node.locked { cursor: not-allowed; }
.rpg-node.locked .rpg-node-img { filter: brightness(0.35) saturate(0.3); }
.rpg-node.current .rpg-node-img-wrap { animation: nodeFloat 3s ease-in-out infinite; }
.rpg-node.region-newly-unlocked .rpg-node-img-wrap {
    animation: regionUnlockPop 1.2s cubic-bezier(.2,1.35,.35,1) both, nodeFloat 3s ease-in-out 1.2s infinite;
    box-shadow: 0 0 0 3px rgba(251,191,36,.45), 0 0 34px rgba(251,191,36,.65);
}
.rpg-node.region-newly-unlocked .rpg-node-img-wrap::before {
    content: '';
    position: absolute;
    inset: -14px;
    border-radius: inherit;
    border: 2px solid rgba(251,191,36,.55);
    animation: unlockRing 1.2s ease-out both;
    pointer-events: none;
}

@keyframes regionUnlockPop {
    0% { transform: scale(.72) translateY(18px); opacity: .35; }
    45% { transform: scale(1.08) translateY(-8px); opacity: 1; }
    70% { transform: scale(.98) translateY(0); }
    100% { transform: scale(1) translateY(0); }
}
@keyframes unlockRing {
    0% { transform: scale(.72); opacity: 0; }
    35% { opacity: 1; }
    100% { transform: scale(1.18); opacity: 0; }
}
.rpg-node.current .rpg-node-img-wrap::after {
    content: '';
    position: absolute; inset: -6px;
    border-radius: 50%; border: 2px solid rgba(34,211,238,0.3);
    animation: ringPulse 2s ease-in-out infinite;
    pointer-events: none;
}
@keyframes nodeFloat {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-6px); }
}
@keyframes ringPulse {
    0%, 100% { opacity: 0.3; transform: scale(1); }
    50% { opacity: 0.8; transform: scale(1.05); }
}

/* 节点图片 */
.rpg-node-img-wrap {
    position: relative; width: 360px; height: 360px;
    display: flex; align-items: center; justify-content: center;
    filter: drop-shadow(0 4px 12px rgba(0,0,0,0.4));
}
.rpg-node-img {
    width: 100%; height: 100%; object-fit: contain;
    transition: filter 0.3s;
}
.rpg-node:hover:not(.locked) .rpg-node-img { filter: brightness(1.1); }

/* 未解锁遮罩 */
.rpg-node-mask {
    position: absolute; inset: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 6px; pointer-events: none;
}
.mask-text {
    font-size: 1rem; font-weight: 700; color: rgba(255,255,255,0.85);
    letter-spacing: 2px;
    text-shadow: 0 2px 8px rgba(0,0,0,0.8), 0 0 20px rgba(0,0,0,0.5);
}
.mask-hint {
    font-size: 0.7rem; color: rgba(255,255,255,0.5);
    font-weight: 400; letter-spacing: 0.5px;
    text-shadow: 0 1px 4px rgba(0,0,0,0.8);
}

/* 节点文字（居中叠放在图片上） */
.rpg-node-label {
    position: absolute; inset: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 2px; pointer-events: none;
    text-shadow: 0 2px 8px rgba(0,0,0,0.8), 0 0 20px rgba(0,0,0,0.5);
}
.rpg-node-name {
    font-size: 0.88rem; font-weight: 700; color: #fff;
    letter-spacing: 0.5px;
}
.rpg-node.locked .rpg-node-name { color: rgba(255,255,255,0.4); }
.rpg-node-stars { font-size: 0.68rem; color: var(--gold); font-weight: 600; }
[data-theme="light"] .rpg-node-label {
    text-shadow: 0 1px 4px rgba(255,255,255,0.8), 0 0 8px rgba(255,255,255,0.5);
}
[data-theme="light"] .rpg-node-name { color: #1e293b; }
[data-theme="light"] .rpg-node.locked .rpg-node-name { color: rgba(30,41,59,0.4); }

/* 连接线（旧的，隐藏） */
.path-line { display: none; }

/* 道具商店入口 */
.shop-entry { text-align: center; padding: 10px 20px 30px; }
.btn-shop {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: 12px; padding: 10px 24px; font-size: 0.9rem;
    color: var(--text-sub); cursor: pointer; transition: all 0.2s; font-weight: 600;
}
.btn-shop:hover { border-color: var(--gold); color: var(--gold); }


/* ═══════════════════════════════════════ */
/* 📍 区域关卡选择                          */
/* ═══════════════════════════════════════ */
#regionView {
    --region-bg: none;
    position: relative;
}
#regionView::before {
    content: '';
    position: fixed; inset: 0;
    background: var(--region-bg) center / cover no-repeat;
    z-index: 0; pointer-events: none; opacity: 0.15; filter: blur(4px);
}
#regionView::after {
    content: '';
    position: fixed; inset: 0;
    background: linear-gradient(to bottom, var(--bg) 0%, transparent 30%, transparent 70%, var(--bg) 100%);
    z-index: 0; pointer-events: none;
}
#regionView > * { position: relative; z-index: 1; }
[data-theme="light"] #regionView::before { opacity: 0.2; }

.region-header {
    position: sticky; top: 0; z-index: 100;
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 16px; background: rgba(12,14,26,0.92);
    backdrop-filter: blur(16px); border-bottom: 1px solid var(--border);
}
.region-title-wrap { display: flex; align-items: center; gap: 8px; }
.region-icon { font-size: 1.3rem; }
.region-name { font-size: 1.1rem; font-weight: 700; }
.region-progress-mini { font-size: 0.8rem; color: var(--text-muted); }
.region-story {
    text-align: center; padding: 16px 20px; margin: 0 auto;
    max-width: 500px; font-size: 0.85rem; color: var(--text-sub);
    line-height: 1.6; font-style: italic;
    background: var(--bg-surface); border-bottom: 1px solid var(--border);
}

.stage-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px; max-width: 600px; margin: 20px auto 40px; padding: 0 16px; width: 100%;
}
.stage-card {
    position: relative; border-radius: var(--radius); overflow: hidden;
    border: 2px solid var(--border); background: var(--bg-card);
    cursor: pointer; transition: all 0.25s; aspect-ratio: 3/4;
}
.stage-card:hover:not(.locked) {
    transform: translateY(-4px); border-color: var(--gold); box-shadow: var(--glow-gold);
}
.stage-card.locked { opacity: 0.72; cursor: not-allowed; }
.stage-card.locked .stage-cover { filter: blur(3px) grayscale(0.55) brightness(0.62); }
.stage-card.unplayed .stage-cover { filter: blur(2px) saturate(0.85) brightness(0.92); }
.stage-card.unplayed:hover .stage-cover { filter: blur(1px) saturate(0.95) brightness(1); }
.stage-card.cleared { border-color: rgba(16,185,129,0.4); }
.stage-card.cleared .stage-cover { filter: none; }
.stage-card.current { border-color: var(--cyan); box-shadow: var(--glow-cyan); }
.stage-card.newly-unlocked {
    animation: unlockBounce 0.9s cubic-bezier(.2,1.35,.35,1) both;
    box-shadow: 0 0 0 2px rgba(251,191,36,.45), 0 0 26px rgba(251,191,36,.55);
}
.stage-card.previewing {
    animation: previewPulse 0.5s ease-out both;
}

@keyframes unlockBounce {
    0% { transform: scale(.86) translateY(12px); opacity: .45; }
    45% { transform: scale(1.08) translateY(-6px); opacity: 1; }
    70% { transform: scale(.98) translateY(0); }
    100% { transform: scale(1) translateY(0); }
}

@keyframes previewPulse {
    0% { transform: scale(1); }
    45% { transform: scale(1.04); box-shadow: 0 0 24px rgba(251,191,36,.55); }
    100% { transform: scale(1); }
}

.stage-cover {
    position: absolute; inset: 0; background-size: cover; background-position: center;
    transition: transform 0.3s;
}
.stage-card:hover:not(.locked) .stage-cover { transform: scale(1.05); }

.stage-info {
    position: absolute; bottom: 0; left: 0; right: 0;
    background: linear-gradient(to top, rgba(0,0,0,0.88) 60%, transparent);
    padding: 28px 10px 10px; text-align: center;
}
.stage-number { font-size: 0.7rem; color: var(--text-muted); font-weight: 700; text-transform: uppercase; letter-spacing: 1px; }
.stage-name { font-size: 0.82rem; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin: 2px 0; }
.stage-stars { font-size: 0.85rem; letter-spacing: 2px; }
.stage-stars .star-on { color: var(--gold); }
.stage-stars .star-off { color: var(--text-muted); opacity: 0.3; }
.stage-best { font-size: 0.62rem; color: var(--text-muted); margin-top: 2px; }
.stage-diff-tag {
    position: absolute; top: 8px; right: 8px; font-size: 0.65rem;
    padding: 2px 8px; border-radius: 6px; font-weight: 700;
    background: rgba(0,0,0,0.6); color: var(--gold); backdrop-filter: blur(4px);
}
.stage-lock {
    position: absolute; inset: 0; display: flex; align-items: center;
    justify-content: center; font-size: 2.2rem; z-index: 2;
    background: rgba(0,0,0,0.3);
}


/* ═══════════════════════════════════════ */
/* 🎮 游戏视图                              */
/* ═══════════════════════════════════════ */
.game-topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 16px; background: var(--bg-card);
    border-bottom: 1px solid var(--border);
}
.back-btn {
    background: none; border: none; color: var(--text-sub); cursor: pointer;
    font-size: 0.88rem; padding: 6px 12px; border-radius: 8px; transition: all 0.15s;
}
.back-btn:hover { color: var(--text); background: var(--bg-surface); }
.game-stage-info { display: flex; align-items: center; gap: 8px; }
.game-stage-info span:first-child { font-weight: 700; font-size: 0.95rem; }
.game-diff-badge {
    padding: 3px 10px; border-radius: 6px; font-size: 0.72rem; font-weight: 700;
    background: var(--gold-dim); color: var(--gold);
}

.game-tools { display: flex; gap: 6px; }
.tool-btn {
    display: flex; align-items: center; gap: 3px;
    background: var(--bg-surface); border: 1px solid var(--border);
    border-radius: 8px; padding: 5px 10px; cursor: pointer;
    font-size: 0.9rem; color: var(--text-sub); transition: all 0.15s;
}
.tool-btn:hover { border-color: var(--gold); color: var(--gold); }
.tool-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.tool-icon { width: 22px; height: 22px; object-fit: contain; }
.tool-count { font-size: 0.72rem; font-weight: 700; color: var(--gold); }

.game-stats-bar {
    display: flex; justify-content: center; gap: 28px; padding: 10px 16px;
    background: var(--bg-card); border-bottom: 1px solid var(--border);
}
.stat-item { display: flex; align-items: center; gap: 6px; font-size: 0.9rem; }
.stat-icon { font-size: 0.95rem; }
.stat-item span:last-child { font-weight: 700; color: var(--gold); min-width: 44px; }
.stat-limit { font-weight: 400 !important; color: var(--text-muted) !important; font-size: 0.78rem; min-width: auto !important; margin-left: 2px; }
#timer.time-warn { color: #f59e0b !important; }
#timer.time-over { color: #ef4444 !important; animation: timerPulse 1s infinite; }
@keyframes timerPulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }

/* 棋盘 */
.puzzle-board-wrap {
    display: flex; flex-direction: column; align-items: center;
    padding: 16px 16px 20px; flex: 1; justify-content: center;
}
.puzzle-board {
    display: grid; gap: 3px; background: var(--bg-surface); padding: 6px;
    border-radius: 14px; border: 2px solid rgba(255,255,255,0.08);
    width: min(85vw, 400px); aspect-ratio: 9/16; max-width: 100%;
    box-shadow: 0 12px 40px rgba(0,0,0,0.5);
}
.puzzle-slot {
    width: 100%; height: 100%; border-radius: 4px;
    background: rgba(255,255,255,0.03); border: 1px solid rgba(255,255,255,0.08);
    display: flex; align-items: center; justify-content: center;
    transition: all 0.2s; background-repeat: no-repeat; position: relative; overflow: hidden;
    cursor: grab;
}
.puzzle-slot.filled { border: 1px solid rgba(99,102,241,0.3); background-color: transparent; }
.puzzle-slot.dragging-source {
    opacity: 0.35; transform: scale(0.95);
    border-color: var(--gold) !important;
}
.puzzle-slot.drag-over {
    border-color: var(--gold) !important;
    box-shadow: inset 0 0 16px rgba(251,191,36,0.25), 0 0 12px rgba(251,191,36,0.15);
    transform: scale(1.04); z-index: 2;
}
.puzzle-slot.just-swapped {
    animation: swapPop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.puzzle-slot:active { cursor: grabbing; }
@keyframes swapPop {
    0% { transform: scale(0.85); opacity: 0.6; }
    60% { transform: scale(1.06); }
    100% { transform: scale(1); opacity: 1; }
}
.puzzle-slot.auto-placed { animation: autoGlow 0.6s ease; }
@keyframes autoGlow {
    0% { box-shadow: 0 0 0 rgba(34,211,238,0); transform: scale(1); }
    50% { box-shadow: 0 0 20px rgba(34,211,238,0.6); transform: scale(1.05); }
    100% { box-shadow: 0 0 0 rgba(34,211,238,0); transform: scale(1); }
}
.auto-trail-burst {
    position: fixed;
    width: 90px; height: 90px;
    transform: translate(-50%, -50%);
    pointer-events: none;
    z-index: 9998;
}
.auto-trail-burst span {
    position: absolute;
    left: 50%; top: 50%;
    color: #22d3ee;
    font-size: 1.2rem;
    text-shadow: 0 0 12px rgba(34,211,238,.9);
    animation: autoTrailPop .85s ease-out forwards;
}
.auto-trail-burst span:nth-child(2) { color: #fbbf24; animation-delay: .08s; }
.auto-trail-burst span:nth-child(3) { color: #a78bfa; animation-delay: .16s; }
@keyframes autoTrailPop {
    0% { transform: translate(-50%, -50%) scale(0); opacity: 0; }
    35% { transform: translate(-50%, -50%) scale(1.25); opacity: 1; }
    100% { transform: translate(calc(-50% + 28px), calc(-50% - 42px)) scale(.3); opacity: 0; }
}
.time-added {
    animation: timeAddedPulse .7s ease-out;
}
@keyframes timeAddedPulse {
    0% { transform: scale(1); color: inherit; }
    45% { transform: scale(1.25); color: #34d399; text-shadow: 0 0 14px rgba(52,211,153,.85); }
    100% { transform: scale(1); }
}
.time-bonus-float {
    position: fixed;
    transform: translate(-50%, -100%);
    color: #34d399;
    font-weight: 900;
    font-size: 1.1rem;
    text-shadow: 0 0 12px rgba(52,211,153,.85), 0 2px 4px rgba(0,0,0,.45);
    pointer-events: none;
    z-index: 9999;
    animation: timeBonusFloat .9s ease-out forwards;
}
@keyframes timeBonusFloat {
    0% { transform: translate(-50%, -40%) scale(.75); opacity: 0; }
    25% { opacity: 1; }
    100% { transform: translate(-50%, -160%) scale(1.05); opacity: 0; }
}

/* 预览遮罩 */
.preview-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.92);
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    z-index: 9999; cursor: zoom-out; padding: 20px; gap: 12px;
}
.preview-overlay img {
    max-width: 88vw; max-height: 78vh; border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.8);
}
.preview-overlay.preview-scan-active::after {
    content: '';
    position: absolute;
    left: 8%; right: 8%; top: 18%; height: 3px;
    background: linear-gradient(90deg, transparent, rgba(251,191,36,.95), transparent);
    box-shadow: 0 0 18px rgba(251,191,36,.8);
    animation: previewScan 1.1s ease-in-out infinite;
}
@keyframes previewScan {
    0% { transform: translateY(0); opacity: 0; }
    18% { opacity: 1; }
    100% { transform: translateY(56vh); opacity: 0; }
}
.preview-timer {
    font-size: 2rem; font-weight: 800; color: var(--gold);
    text-shadow: 0 0 20px rgba(251,191,36,0.5);
}
.preview-hint { font-size: 0.75rem; color: var(--text-muted); }


/* ═══════════════════════════════════════ */
/* 🎉 通关弹窗 + 商店                       */
/* ═══════════════════════════════════════ */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.8);
    display: none; align-items: center; justify-content: center;
    z-index: 9998; padding: 20px; backdrop-filter: blur(8px);
}
.modal-overlay.active { display: flex; }

.win-modal {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: 20px; padding: 28px 24px; width: 100%; max-width: 380px;
    text-align: center; box-shadow: var(--shadow);
    animation: modalPop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes modalPop {
    from { opacity: 0; transform: scale(0.85) translateY(20px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}
.win-stars { font-size: 2.6rem; margin-bottom: 6px; letter-spacing: 6px; }
.win-title { font-size: 1.3rem; margin-bottom: 14px; color: var(--gold); }
.win-stats { display: flex; justify-content: center; gap: 32px; margin-bottom: 12px; }
.win-stat { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.win-stat-label { font-size: 0.72rem; color: var(--text-muted); }
.win-stat-val { font-size: 1.2rem; font-weight: 800; color: var(--text); }
.win-reward { font-size: 0.82rem; color: var(--green); min-height: 1.2em; }
.win-star-criteria {
    margin: -2px 0 8px;
    font-size: 0.76rem;
    color: var(--text-muted);
    background: rgba(251,191,36,.08);
    border: 1px solid rgba(251,191,36,.16);
    border-radius: 999px;
    padding: 4px 10px;
    display: inline-flex;
}
.win-rewards { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-bottom: 8px; }
.reward-tag {
    display: inline-flex; align-items: center; gap: 6px;
    font-size: 0.78rem; padding: 4px 10px; border-radius: 20px;
    background: var(--gold-dim); color: var(--gold); font-weight: 600;
}
.reward-icon {
    width: 22px;
    height: 22px;
    object-fit: contain;
    filter: drop-shadow(0 0 6px rgba(251,191,36,.35));
}
.reward-item {
    animation: rewardPop .45s cubic-bezier(.2,1.35,.35,1) both;
}
@keyframes rewardPop {
    0% { transform: scale(.72); opacity: 0; }
    70% { transform: scale(1.08); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}
.win-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }

.btn-game {
    padding: 11px 20px; border: none; border-radius: 12px;
    font-size: 0.9rem; font-weight: 700; cursor: pointer; transition: all 0.2s;
}
.btn-gold {
    background: linear-gradient(135deg, var(--gold), #f59e0b);
    color: #000; box-shadow: 0 4px 16px rgba(251,191,36,0.3);
}
.btn-gold:hover { transform: translateY(-2px); box-shadow: 0 6px 24px rgba(251,191,36,0.45); }
.btn-ghost {
    background: var(--bg-surface); color: var(--text-sub); border: 1px solid var(--border);
}
.btn-ghost:hover { border-color: var(--border-hover); color: var(--text); }

/* ─── 道具商店 ─── */
.shop-modal {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: 20px; padding: 24px; width: 100%; max-width: 420px;
    box-shadow: var(--shadow);
    animation: modalPop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.shop-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.shop-header h2 { font-size: 1.15rem; }
.close-btn {
    background: none; border: none; color: var(--text-muted);
    font-size: 1.6rem; cursor: pointer; padding: 0 4px; line-height: 1;
}
.close-btn:hover { color: var(--text); }

.shop-items { display: flex; flex-direction: column; gap: 10px; }
.shop-item {
    display: flex; align-items: center; gap: 14px;
    background: var(--bg-surface); border: 1px solid var(--border);
    border-radius: 14px; padding: 14px;
}
.shop-item-icon { width: 42px; height: 42px; object-fit: contain; flex-shrink: 0; }
.shop-item-info { flex: 1; min-width: 0; }
.shop-item-name { font-size: 0.9rem; font-weight: 700; margin-bottom: 2px; }
.shop-item-desc { font-size: 0.75rem; color: var(--text-sub); line-height: 1.4; }
.shop-item-action { display: flex; flex-direction: column; align-items: center; gap: 6px; flex-shrink: 0; }
.shop-price { font-size: 0.72rem; color: var(--gold); font-weight: 600; }
.btn-buy {
    padding: 6px 16px; font-size: 0.78rem; border-radius: 8px;
    background: var(--gold); color: #000; border: none; cursor: pointer;
    font-weight: 700; transition: all 0.15s;
}
.btn-buy:hover { transform: scale(1.05); box-shadow: 0 2px 10px rgba(251,191,36,0.3); }
.shop-footer { margin-top: 16px; text-align: center; font-size: 0.82rem; color: var(--text-sub); }
.shop-footer strong { color: var(--gold); }

/* ═══ 剧情对话 ═══ */
.dialogue-overlay {
    position: fixed; inset: 0; z-index: 9999;
    background: rgba(0,0,0,0.7); backdrop-filter: blur(6px);
    display: none; align-items: flex-end; justify-content: center;
    padding: 20px 16px 40px; cursor: pointer;
}
.dialogue-overlay.active { display: flex; }
.dialogue-box {
    width: 100%; max-width: 560px;
    background: linear-gradient(180deg, rgba(22,25,41,0.95), rgba(12,14,26,0.98));
    border: 1px solid rgba(251,191,36,0.2);
    border-radius: 16px; padding: 20px 24px 16px;
    box-shadow: 0 -4px 30px rgba(0,0,0,0.5), 0 0 20px rgba(251,191,36,0.08);
    animation: dialogueSlideUp 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes dialogueSlideUp {
    from { opacity: 0; transform: translateY(30px); }
    to { opacity: 1; transform: translateY(0); }
}
.dialogue-header {
    display: flex; align-items: center; gap: 8px; margin-bottom: 12px;
}
.dialogue-icon { font-size: 1.3rem; }
.dialogue-name {
    font-size: 0.9rem; font-weight: 700; color: var(--gold);
    padding: 2px 12px; background: rgba(251,191,36,0.1);
    border-radius: 6px; border: 1px solid rgba(251,191,36,0.2);
}
.dialogue-text {
    font-size: 0.92rem; line-height: 1.7; color: var(--text);
    min-height: 3em;
}
.dialogue-hint {
    text-align: right; font-size: 0.7rem; color: var(--text-muted);
    margin-top: 10px; animation: hintBlink 1.5s ease-in-out infinite;
}
@keyframes hintBlink {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 1; }
}

/* 剧情对话亮色主题 */
[data-theme="light"] .dialogue-box {
    background: linear-gradient(180deg, rgba(255,255,255,0.96), rgba(245,248,255,0.98));
    border-color: rgba(245,158,11,0.25);
    box-shadow: 0 -4px 30px rgba(100,140,220,0.15), 0 0 20px rgba(245,158,11,0.06);
}
[data-theme="light"] .dialogue-name {
    background: rgba(245,158,11,0.08); border-color: rgba(245,158,11,0.2); color: #92400e;
}
[data-theme="light"] .dialogue-text { color: #1e293b; }

/* ═══ 页脚 ═══ */
.site-footer {
    text-align: center; padding: 20px; color: var(--text-muted);
    font-size: 0.78rem; border-top: 1px solid var(--border); margin-top: auto;
}
.site-footer a { color: var(--text-sub); }

/* ═══ Toast ═══ */
.toast {
    position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%);
    background: var(--bg-card); border: 1px solid var(--border);
    padding: 10px 24px; border-radius: 12px; font-size: 0.85rem;
    color: var(--text); z-index: 10000; opacity: 0; pointer-events: none;
    transition: opacity 0.3s, transform 0.3s;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.toast.show { opacity: 1; pointer-events: auto; }

/* ═══ 响应式 ═══ */
@media (max-width: 480px) {
    .region-path { min-height: 600px; }
    .rpg-node { width: 300px; }
    .rpg-node-img-wrap { width: 260px; height: 260px; }
    .rpg-node-name { font-size: 0.82rem; }
    .rpg-node-stars { font-size: 0.65rem; }
    .mask-text { font-size: 0.82rem; letter-spacing: 1px; }
    .mask-hint { font-size: 0.62rem; }
}
@media (max-width: 640px) {
    .shop-entry { display: block; }
    .stage-grid { grid-template-columns: repeat(auto-fill, minmax(115px, 1fr)); gap: 10px; padding: 0 12px; }
    .game-stats-bar { gap: 16px; }
    .win-modal { padding: 22px 18px; }
    .shop-modal { padding: 18px; }
}
@media (min-width: 641px) {
    .shop-entry { display: none; }
}
@media (min-width: 768px) {
    .region-path { aspect-ratio: 4/3; min-height: 750px; }
    .rpg-node { width: 440px; }
    .rpg-node-img-wrap { width: 400px; height: 400px; }
    .rpg-node-name { font-size: 1.05rem; }
}
@media (min-width: 1024px) {
    .region-path { aspect-ratio: 16/10; min-height: 700px; }
    .rpg-node { width: 500px; }
    .rpg-node-img-wrap { width: 440px; height: 440px; }
    .rpg-node-name { font-size: 1.1rem; }
}

/* ═══ 滚动条 ═══ */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.15); }


/* ═══════════════════════════════════════
   🕊️ 登录 / 注册弹窗（puzzle-login-modal）
   挂在 .modal-overlay#puzzleLoginModal 内部
   ═══════════════════════════════════════ */
.puzzle-login-modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 24px;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow);
    animation: modalPop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.puzzle-login-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 6px;
}
.puzzle-login-header h2 {
    font-size: 1.15rem;
    margin: 0;
}
.puzzle-login-tip {
    font-size: 0.78rem;
    color: var(--text-sub);
    margin: 0 0 16px;
    line-height: 1.5;
}

/* 登录方式分隔线（上方 Google，下方邮箱） */
.puzzle-auth-divider {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 6px 0 14px;
    color: var(--text-muted);
    font-size: 0.72rem;
}
.puzzle-auth-divider::before,
.puzzle-auth-divider::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--border);
}
.puzzle-auth-divider span { flex-shrink: 0; }
.puzzle-auth-field {
    margin-bottom: 12px;
    text-align: left;
}
.puzzle-auth-field label {
    display: block;
    font-size: 0.78rem;
    color: var(--text-sub);
    margin-bottom: 5px;
}
.puzzle-auth-field input {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text);
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
    box-sizing: border-box;
}
.puzzle-auth-field input:focus {
    border-color: var(--gold);
    box-shadow: 0 0 0 3px rgba(251,191,36,0.15);
}
.puzzle-auth-msg {
    display: none;
    font-size: 0.78rem;
    margin: 4px 0 8px;
    padding: 8px 10px;
    border-radius: 8px;
    line-height: 1.4;
}
.puzzle-auth-error {
    color: #ef4444;
    background: rgba(239,68,68,0.1);
}
.puzzle-auth-success {
    color: var(--green);
    background: rgba(16,185,129,0.1);
}
.puzzle-login-foot {
    margin-top: 14px;
    font-size: 0.7rem;
    color: var(--text-muted);
    text-align: center;
    line-height: 1.6;
}
.puzzle-login-foot a {
    color: var(--gold);
    text-decoration: none;
}
.puzzle-login-foot a:hover { text-decoration: underline; }

/* 浅色模式适配 */
[data-theme="light"] .puzzle-login-modal {
    background: rgba(255,255,255,0.97);
    border-color: rgba(180,200,240,0.4);
}
[data-theme="light"] .puzzle-auth-field input {
    background: rgba(245,248,255,0.9);
    border-color: rgba(180,200,240,0.5);
    color: #1e293b;
}
[data-theme="light"] .puzzle-auth-field input:focus {
    border-color: #f59e0b;
    box-shadow: 0 0 0 3px rgba(245,158,11,0.18);
}

/* 移动端 */
@media (max-width: 480px) {
    .puzzle-login-modal { padding: 20px; max-width: 92vw; }
    .puzzle-login-header h2 { font-size: 1.05rem; }
}


/* ═══════════════════════════════════════
   👤 已登录头像胶囊（仿主站 .user-avatar-wrap）
   #puzzleLoginBtn 已登录时由 JS 加 .user-avatar-wrap 类，
   未登录时保持 .puzzle-login-btn 蓝色按钮样式（在 navbar.css 里）
   ═══════════════════════════════════════ */
.user-avatar-wrap {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 2px 12px 2px 2px;
    border-radius: 20px;
    transition: all 0.2s ease;
    background: rgba(31, 41, 55, 0.4);
    border: 1px solid transparent;
    /* 覆盖 navbar.css 里 button 默认 padding/font-size */
    font-family: inherit;
    color: inherit;
    line-height: 1;
    border: 1px solid transparent;
    /* 让 <button> 元素也能套这套样式 */
    -webkit-appearance: none;
    appearance: none;
    max-width: 200px;
}
.user-avatar-wrap:hover {
    background: rgba(251, 191, 36, 0.1);
    border-color: rgba(251, 191, 36, 0.3);
    transform: translateY(-1px);
}

/* 首字母 / 图片头像（28×28） */
.user-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
    font-size: 0.85rem;
    letter-spacing: 0.5px;
    flex-shrink: 0;
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    box-shadow: 0 0 0 2px rgba(255,255,255,0.05);
    text-transform: uppercase;
    user-select: none;
    overflow: hidden;
}
/* 头像 8 色：按 uid 哈希稳定选色（同主站算法） */
.user-avatar.avatar-0 { background: linear-gradient(135deg, #6366f1, #8b5cf6); }
.user-avatar.avatar-1 { background: linear-gradient(135deg, #ec4899, #f43f5e); }
.user-avatar.avatar-2 { background: linear-gradient(135deg, #10b981, #14b8a6); }
.user-avatar.avatar-3 { background: linear-gradient(135deg, #f59e0b, #ef4444); }
.user-avatar.avatar-4 { background: linear-gradient(135deg, #3b82f6, #06b6d4); }
.user-avatar.avatar-5 { background: linear-gradient(135deg, #a855f7, #d946ef); }
.user-avatar.avatar-6 { background: linear-gradient(135deg, #f97316, #fbbf24); }
.user-avatar.avatar-7 { background: linear-gradient(135deg, #14b8a6, #22d3ee); }

/* 自定义图片头像 */
.user-avatar.avatar-img { background: #374151 !important; padding: 0; }
.user-avatar.avatar-img img {
    width: 100%; height: 100%; object-fit: cover; display: block;
}

/* 昵称椭圆里的紧凑昵称 */
.user-avatar-wrap .avatar-nickname {
    font-size: 0.82rem;
    color: #e5e7eb;
    max-width: 110px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding-right: 2px;
    font-weight: 600;
}

/* 浅色模式 */
[data-theme="light"] .user-avatar-wrap {
    background: rgba(100,140,220,0.06);
}
[data-theme="light"] .user-avatar-wrap:hover {
    background: rgba(100,140,220,0.12);
    border-color: rgba(100,140,220,0.25);
}
[data-theme="light"] .user-avatar { box-shadow: 0 0 0 2px rgba(100,140,220,0.15); }
[data-theme="light"] .user-avatar.avatar-img { background: #e2e8f0 !important; }
[data-theme="light"] .user-avatar-wrap .avatar-nickname { color: #1e293b; }

/* 移动端：缩小昵称最大宽度避免挤爆 HUD */
@media (max-width: 640px) {
    .user-avatar-wrap { padding: 2px 8px 2px 2px; gap: 6px; max-width: 130px; }
    .user-avatar { width: 24px; height: 24px; font-size: 0.78rem; }
    .user-avatar-wrap .avatar-nickname { font-size: 0.74rem; max-width: 64px; }
}
@media (max-width: 360px) {
    .user-avatar-wrap .avatar-nickname { display: none; }
    .user-avatar-wrap { padding: 2px; }
}

/* ═══════════════════════════════════════
   ✨ 游戏反馈：胜利烟花 / 星星果冻 / 拼合闪光
   ═══════════════════════════════════════ */

#winModal {
    overflow: hidden;
}

.win-firework-layer,
.win-confetti-layer {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
}
.win-firework-layer { opacity: 0.95; }
.win-confetti-layer {
    overflow: hidden;
    opacity: 0.9;
}

#winModal .win-modal {
    position: relative;
    z-index: 1;
    animation: winModalPop 0.42s cubic-bezier(0.22, 1.25, 0.36, 1) both;
}

@keyframes winModalPop {
    0% { transform: translateY(18px) scale(0.92); opacity: 0; }
    62% { transform: translateY(-3px) scale(1.025); opacity: 1; }
    100% { transform: translateY(0) scale(1); opacity: 1; }
}

.win-star {
    display: inline-block;
    opacity: 0;
    transform: scale(0) rotate(-25deg);
    animation: starJelly 0.72s cubic-bezier(0.2, 1.35, 0.35, 1) var(--delay, 0s) both;
}
.win-star.earned {
    filter: drop-shadow(0 0 10px rgba(251, 191, 36, .85));
}
.win-star.empty {
    opacity: 0.55;
    filter: grayscale(0.25);
}

@keyframes starJelly {
    0% { opacity: 0; transform: scale(0) rotate(-25deg); }
    38% { opacity: 1; transform: scale(1.42, 0.72) rotate(10deg); }
    56% { transform: scale(0.82, 1.22) rotate(-6deg); }
    74% { transform: scale(1.12, 0.92) rotate(3deg); }
    100% { opacity: 1; transform: scale(1) rotate(0deg); }
}

.css-firework-container {
    position: absolute;
    width: 0;
    height: 0;
    pointer-events: none;
    transform: scale(var(--scale, 1));
}

.firework-particle {
    position: absolute;
    left: 0;
    top: 0;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    animation: fireworkBurst 1.2s ease-out var(--delay, 0s) forwards;
}

@keyframes fireworkBurst {
    0% { transform: translate(0, 0) scale(1); opacity: 0; }
    10% { opacity: 1; }
    72% { opacity: 1; }
    100% { transform: translate(var(--tx), var(--ty)) scale(0); opacity: 0; }
}

.confetti-piece {
    position: absolute;
    top: -12px;
    width: 8px;
    height: 14px;
    opacity: 0;
    animation: confettiFall var(--duration, 5s) linear var(--delay, 0s) infinite;
}

@keyframes confettiFall {
    0% { transform: translate3d(0, -10vh, 0) rotate(0deg); opacity: 0; }
    8% { opacity: 1; }
    100% { transform: translate3d(var(--drift), 112vh, 0) rotate(var(--rot)); opacity: 0; }
}

/* 拼合成功的本地 HTML/CSS 闪光，不接 Spine，位置随碎片动态计算 */
.css-spark {
    position: fixed;
    width: 98px;
    height: 98px;
    pointer-events: none;
    z-index: 9999;
    transform: translate(-50%, -50%);
}
.css-spark span {
    position: absolute;
    left: 50%;
    top: 50%;
    font-size: 2rem;
    transform: translate(-50%, -50%) scale(0);
    animation: sparkPop 0.76s ease-out forwards;
    text-shadow: 0 0 12px rgba(251,191,36,.9), 0 0 22px rgba(244,114,182,.45);
}
.css-spark span:nth-child(2) { left: 25%; top: 35%; font-size: 1.15rem; animation-delay: .06s; }
.css-spark span:nth-child(3) { left: 72%; top: 70%; font-size: 1.1rem; animation-delay: .12s; }
.css-spark span:nth-child(4) { left: 70%; top: 25%; font-size: .9rem; animation-delay: .18s; }

@keyframes sparkPop {
    0% { transform: translate(-50%, -50%) scale(0) rotate(0deg); opacity: 0; }
    32% { transform: translate(-50%, -50%) scale(1.35) rotate(14deg); opacity: 1; }
    100% { transform: translate(-50%, -50%) scale(.45) rotate(34deg); opacity: 0; }
}

.puzzle-slot.piece-correct {
    animation: correctGlow 0.52s ease-out;
}

@keyframes correctGlow {
    0% { box-shadow: 0 0 0 0 rgba(251, 191, 36, 0.8); transform: scale(1); }
    42% { box-shadow: 0 0 20px 5px rgba(251, 191, 36, 0.55); transform: scale(1.035); }
    100% { box-shadow: none; transform: scale(1); }
}

.combo-indicator {
    position: fixed;
    top: 18%;
    left: 50%;
    transform: translateX(-50%);
    font-size: 1.35rem;
    font-weight: 800;
    color: #fbbf24;
    text-shadow: 0 0 10px rgba(251,191,36,.85), 0 2px 4px rgba(0,0,0,.5);
    pointer-events: none;
    z-index: 9998;
    animation: comboFade 0.85s ease-out forwards;
}

@keyframes comboFade {
    0% { opacity: 0; transform: translateX(-50%) translateY(10px) scale(.8); }
    28% { opacity: 1; transform: translateX(-50%) translateY(0) scale(1.12); }
    100% { opacity: 0; transform: translateX(-50%) translateY(-22px) scale(1); }
}

@media (max-width: 480px) {
    .firework-particle {
        width: 6px;
        height: 6px;
    }
    .combo-indicator { top: 16%; font-size: 1.15rem; }
}
