/* ===== 全局 ===== */
* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
    background: linear-gradient(135deg, #f6e7c1 0%, #cbe2b9 50%, #a8d5ba 100%);
    min-height: 100vh;
    color: #3d4a3d;
    user-select: none;
    -webkit-user-select: none;
    overflow-x: hidden;
}

.app {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* ===== 视图容器 ===== */
.view { min-height: 100vh; }
.view.hidden { display: none; }
.view-gallery,
.view-theme,
.view-game {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* ===== 通用页面头部 ===== */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(8px);
    border-radius: 16px;
    padding: 14px 20px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    margin-bottom: 24px;
}

.page-title {
    font-size: 22px;
    color: #4a6741;
    letter-spacing: 2px;
    margin: 0;
}

.page-header-spacer { width: 92px; }

.back-btn {
    border: none;
    background: rgba(255, 255, 255, 0.85);
    color: #4a6741;
    border-radius: 10px;
    padding: 8px 16px;
    font-size: 14px;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(74, 103, 65, 0.15);
    transition: transform 0.15s, box-shadow 0.15s;
    min-width: 92px;
}
.back-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(74, 103, 65, 0.25);
}
.back-btn:active { transform: translateY(0); }

.btn-small {
    padding: 6px 12px;
    font-size: 13px;
}

/* ===== 顶部（游戏页） ===== */
.app-header {
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(8px);
    border-radius: 16px;
    padding: 14px 20px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    margin-bottom: 24px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 16px;
}

.level-info {
    flex: 1 1 auto;
    min-width: 200px;
    display: inline-flex;
    align-items: baseline;
    gap: 8px;
    color: #4a6741;
    font-size: 16px;
    letter-spacing: 1px;
}
.level-info-theme { font-weight: 700; }
.level-info-sep { color: #b8cdb0; }
.level-info-level { font-weight: 600; }
.level-info-mode { color: #8a9a7a; font-size: 13px; margin-left: 4px; }

.app-header h1 {
    font-size: 26px;
    color: #4a6741;
    margin-bottom: 14px;
    text-align: center;
    letter-spacing: 2px;
}

.controls {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    justify-content: center;
    align-items: center;
}

.ctrl-item {
    font-size: 15px;
    color: #4a6741;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.ctrl-item select {
    padding: 6px 10px;
    border-radius: 8px;
    border: 1px solid #b8cdb0;
    background: #fff;
    font-size: 14px;
    cursor: pointer;
    outline: none;
}

.btn {
    padding: 8px 18px;
    border: none;
    border-radius: 10px;
    background: linear-gradient(135deg, #88b378, #6d9961);
    color: #fff;
    font-size: 14px;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(109, 153, 97, 0.4);
    transition: transform 0.15s, box-shadow 0.15s;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(109, 153, 97, 0.5);
}

.btn:active { transform: translateY(0); }

.btn-secondary {
    background: linear-gradient(135deg, #d4a574, #b8895a);
    box-shadow: 0 2px 8px rgba(184, 137, 90, 0.4);
}

.info {
    background: #fff;
    padding: 6px 14px;
    border-radius: 10px;
    font-weight: 600;
    color: #6d9961;
}

/* ===== 游戏区 ===== */
.game-area {
    display: flex;
    gap: 24px;
    flex-wrap: wrap;
    justify-content: center;
    align-items: flex-start;
}

.board-wrapper {
    background: rgba(255, 255, 255, 0.5);
    border-radius: 16px;
    padding: 12px;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.1);
}

.board {
    position: relative;
    background: #d6c5a3;
    border: 3px solid #8a7548;
    border-radius: 8px;
    overflow: hidden;
}

/* 单个图块 */
.tile {
    position: absolute;
    background-repeat: no-repeat;
    box-sizing: border-box;
    border: 1px solid rgba(0, 0, 0, 0.08);
    cursor: grab;
    transition: transform 0.12s, box-shadow 0.12s;
}

.tile:hover {
    z-index: 2;
}

.tile.dragging-source {
    opacity: 0.25;
}

.tile.hover-target {
    box-shadow: inset 0 0 0 3px #d9534f, 0 0 12px rgba(217, 83, 79, 0.7);
    z-index: 3;
}

/* ghost 拖拽元素 */
.ghost {
    position: fixed;
    pointer-events: none;
    z-index: 10000;
    transform: scale(0.94);
    box-shadow: 0 0 0 3px #f0c040, 0 8px 24px rgba(0, 0, 0, 0.35);
    border-radius: 4px;
    overflow: hidden;
}

.ghost > div {
    position: absolute;
    background-repeat: no-repeat;
}

/* ===== 预览侧栏 ===== */
.preview {
    width: 240px;
    background: rgba(255, 255, 255, 0.7);
    border-radius: 16px;
    padding: 16px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

.preview h3 {
    color: #4a6741;
    font-size: 16px;
    margin-bottom: 10px;
    text-align: center;
}

.toggle-preview {
    display: block;
    width: 100%;
    margin-bottom: 12px;
}

.preview-img-wrap.hidden {
    display: none;
}

.preview-img-wrap {
    width: 100%;
    border-radius: 8px;
    overflow: hidden;
    border: 2px solid #b8cdb0;
    background: #f0e8d8;
    aspect-ratio: 1 / 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.preview-img-wrap img {
    max-width: 100%;
    max-height: 100%;
    display: block;
}

.tip {
    margin-top: 12px;
    font-size: 12px;
    color: #6d7a6d;
    line-height: 1.5;
}

/* ===== 胜利弹窗 ===== */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    animation: fadeIn 0.25s;
}

.modal.hidden { display: none; }

.modal-content {
    background: #fff;
    padding: 40px 60px;
    border-radius: 20px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: pop 0.3s;
}

.timer-info {
    min-width: 72px;
    font-variant-numeric: tabular-nums;
    letter-spacing: 1px;
}


.modal-content h2 {
    color: #4a6741;
    margin-bottom: 18px;
    font-size: 26px;
}

.win-stats {
    display: flex;
    gap: 28px;
    justify-content: center;
    margin-bottom: 24px;
}

.win-stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    background: #f6f0e6;
    border-radius: 12px;
    padding: 12px 24px;
    min-width: 90px;
}

.win-stat-label {
    font-size: 13px;
    color: #8a9a7a;
    letter-spacing: 1px;
}

.win-stat-value {
    font-size: 28px;
    font-weight: 700;
    color: #4a6741;
    font-variant-numeric: tabular-nums;
}

#finalTime { color: #d9534f; }
.combo-value { color: #f5a623; }

.modal-actions {
    display: flex;
    gap: 14px;
    justify-content: center;
    flex-wrap: wrap;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes pop {
    0% { transform: scale(0.7); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

/* ===== 胜利动画层 ===== */
.win-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.78);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 9998;
    cursor: pointer;
    animation: fadeIn 0.3s;
}

.win-overlay.hidden { display: none; }

.win-img {
    height: 50vh;
    max-width: 90vw;
    object-fit: contain;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6), 0 0 0 4px rgba(255, 255, 255, 0.15);
    transform: scale(0);
    opacity: 0;
    animation: winZoomIn 1.1s cubic-bezier(0.18, 0.89, 0.32, 1.28) forwards;
}

@keyframes winZoomIn {
    0%   { transform: scale(0);    opacity: 0; }
    30%  { opacity: 1; }
    100% { transform: scale(1);    opacity: 1; }
}

.win-hint {
    margin-top: 24px;
    color: #fff;
    font-size: 16px;
    letter-spacing: 2px;
    opacity: 0.85;
    animation: hintBlink 1.6s ease-in-out infinite;
}

.win-hint.hidden { display: none; }

@keyframes hintBlink {
    0%, 100% { opacity: 0.4; }
    50%      { opacity: 1; }
}

/* ===== 连击飘字 ===== */
.combo-popup {
    position: fixed;
    top: 45%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.3);
    z-index: 200;
    pointer-events: none;
    font-weight: 900;
    font-size: 42px;
    letter-spacing: 4px;
    text-align: center;
    white-space: nowrap;
    opacity: 0;
    animation: comboFloat 1.3s cubic-bezier(0.22, 1, 0.36, 1) forwards;
    text-shadow:
        0 0 8px rgba(0,0,0,0.3),
        0 2px 4px rgba(0,0,0,0.2);
    -webkit-text-stroke: 1.5px rgba(0,0,0,0.15);
}

.combo-badge {
    display: block;
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 2px;
    margin-top: 4px;
    opacity: 0.85;
    -webkit-text-stroke: 0;
}

/* 颜色级别 */
.combo-level-2 { color: #4ecdc4; text-shadow: 0 0 12px rgba(78,205,196,0.5), 0 2px 4px rgba(0,0,0,0.2); }
.combo-level-3 { color: #f5a623; font-size: 48px; text-shadow: 0 0 16px rgba(245,166,35,0.5), 0 2px 4px rgba(0,0,0,0.2); }
.combo-level-4 { color: #ff6b35; font-size: 52px; text-shadow: 0 0 20px rgba(255,107,53,0.5), 0 2px 4px rgba(0,0,0,0.2); }
.combo-level-5 { color: #e63946; font-size: 56px; text-shadow: 0 0 24px rgba(230,57,70,0.6), 0 2px 4px rgba(0,0,0,0.2); }
.combo-level-6 {
    font-size: 60px;
    background: linear-gradient(135deg, #f5a623, #e63946, #a855f7, #4ecdc4);
    background-size: 300% 300%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: comboFloat 1.3s cubic-bezier(0.22, 1, 0.36, 1) forwards,
               rainbowShift 1s ease infinite;
    filter: drop-shadow(0 0 12px rgba(168,85,247,0.5));
}

@keyframes comboFloat {
    0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.3); }
    15%  { opacity: 1; transform: translate(-50%, -55%) scale(1.25); }
    30%  { opacity: 1; transform: translate(-50%, -55%) scale(1); }
    70%  { opacity: 1; transform: translate(-50%, -60%) scale(1); }
    100% { opacity: 0; transform: translate(-50%, -90%) scale(0.9); }
}

@keyframes rainbowShift {
    0%   { background-position: 0% 50%; }
    50%  { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

/* ===== 响应式 ===== */
@media (max-width: 900px) {
    .game-area { flex-direction: column; align-items: center; }
    .preview { width: 100%; max-width: 360px; }
    .home-title { font-size: 44px; }
    .home-actions { flex-direction: column; gap: 16px; }
    .big-btn { min-width: 240px; }
    .theme-grid { grid-template-columns: 1fr; }
    .level-grid { grid-template-columns: repeat(2, 1fr); }
    .level-info { font-size: 14px; min-width: 0; }
}

/* ===== 首页 ===== */
.view-home {
    position: relative;
    min-height: 100vh;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.home-bg {
    position: absolute;
    inset: 0;
    background-size: cover;
    background-position: center;
    filter: blur(10px) brightness(0.7) saturate(1.1);
    transform: scale(1.1);
    z-index: 0;
}
.home-bg::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg,
        rgba(246, 231, 193, 0.45) 0%,
        rgba(168, 213, 186, 0.55) 100%);
}

.home-content {
    position: relative;
    z-index: 1;
    text-align: center;
    padding: 40px 20px;
    max-width: 720px;
    width: 100%;
}

.home-title {
    font-size: 56px;
    color: #fff;
    letter-spacing: 6px;
    text-shadow:
        0 2px 10px rgba(0, 0, 0, 0.35),
        0 0 30px rgba(255, 255, 255, 0.25);
    margin-bottom: 14px;
    animation: titleFadeIn 0.9s ease-out;
}

.home-subtitle {
    color: rgba(255, 255, 255, 0.92);
    font-size: 16px;
    letter-spacing: 4px;
    margin-bottom: 50px;
    text-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    animation: titleFadeIn 1.2s ease-out;
}

@keyframes titleFadeIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

.home-actions {
    display: flex;
    gap: 28px;
    justify-content: center;
    flex-wrap: wrap;
}

.big-btn {
    position: relative;
    border: none;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(8px);
    color: #4a6741;
    padding: 22px 36px;
    min-width: 220px;
    cursor: pointer;
    box-shadow:
        0 8px 28px rgba(0, 0, 0, 0.18),
        inset 0 0 0 1px rgba(255, 255, 255, 0.6);
    transition: transform 0.2s, box-shadow 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    font-family: inherit;
}
.big-btn:hover {
    transform: translateY(-3px);
    box-shadow:
        0 12px 36px rgba(0, 0, 0, 0.22),
        inset 0 0 0 1px rgba(255, 255, 255, 0.7);
}
.big-btn:active { transform: translateY(-1px); }

.big-btn-icon {
    font-size: 30px;
    line-height: 1;
    margin-bottom: 2px;
}
.big-btn-text {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: 4px;
}
.big-btn-sub {
    font-size: 12px;
    color: #8a9a7a;
    letter-spacing: 1px;
    max-width: 240px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.big-btn-primary {
    background: linear-gradient(135deg, #88b378, #6d9961);
    color: #fff;
    box-shadow:
        0 8px 28px rgba(74, 103, 65, 0.45),
        inset 0 0 0 1px rgba(255, 255, 255, 0.3);
}
.big-btn-primary .big-btn-sub { color: rgba(255, 255, 255, 0.85); }
.big-btn-primary:hover {
    box-shadow:
        0 12px 36px rgba(74, 103, 65, 0.55),
        inset 0 0 0 1px rgba(255, 255, 255, 0.4);
}

/* ===== 画廊页主题卡片 ===== */
.theme-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 24px;
}

.theme-card {
    position: relative;
    background: rgba(255, 255, 255, 0.75);
    backdrop-filter: blur(8px);
    border-radius: 20px;
    padding: 24px;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.1);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 22px;
    transition: transform 0.2s, box-shadow 0.2s;
    overflow: hidden;
}
.theme-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 36px rgba(0, 0, 0, 0.18);
}

.theme-card.locked {
    cursor: not-allowed;
    filter: grayscale(0.85);
    opacity: 0.7;
}
.theme-card.locked:hover {
    transform: none;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.1);
}

/* 全满星金光边框 */
.theme-card.crown {
    box-shadow:
        0 6px 24px rgba(0, 0, 0, 0.1),
        0 0 0 2px #f5c518,
        0 0 30px rgba(245, 197, 24, 0.5);
    animation: crownGlow 2.4s ease-in-out infinite;
}
@keyframes crownGlow {
    0%, 100% {
        box-shadow:
            0 6px 24px rgba(0, 0, 0, 0.1),
            0 0 0 2px #f5c518,
            0 0 24px rgba(245, 197, 24, 0.45);
    }
    50% {
        box-shadow:
            0 6px 24px rgba(0, 0, 0, 0.1),
            0 0 0 2px #ffd966,
            0 0 40px rgba(245, 197, 24, 0.7);
    }
}

/* 圆形进度环 */
.theme-ring {
    width: 110px;
    height: 110px;
    border-radius: 50%;
    padding: 6px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.5);
    transition: transform 0.4s;
}
.theme-card:hover .theme-ring { transform: rotate(3deg) scale(1.04); }

.theme-cover {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background-size: cover;
    background-position: center;
    border: 3px solid #fff;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
}

.theme-info { flex: 1; min-width: 0; }
.theme-name {
    font-size: 22px;
    font-weight: 700;
    color: #4a6741;
    letter-spacing: 2px;
    margin-bottom: 8px;
}
.theme-card.crown .theme-name { color: #b8860b; }

.theme-progress {
    font-size: 14px;
    color: #6d7a6d;
    letter-spacing: 1px;
}

/* ===== 主题详情页关卡格子 ===== */
.level-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 18px;
}

.level-card {
    position: relative;
    aspect-ratio: 1 / 1.25;
    border-radius: 16px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.7);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}
.level-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.18);
}
.level-card.locked { cursor: not-allowed; }
.level-card.locked:hover {
    transform: none;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}

.level-thumb {
    position: absolute;
    inset: 0 0 38% 0;
    background-size: cover;
    background-position: center;
}
.level-card.locked .level-thumb { filter: grayscale(1) blur(3px) brightness(0.85); }
.level-card.challenge .level-thumb { filter: brightness(0.65); }

.level-mode-tag {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    font-size: 11px;
    letter-spacing: 1px;
    padding: 3px 8px;
    border-radius: 8px;
    z-index: 2;
}

.level-mask {
    position: absolute;
    inset: 0 0 38% 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
    pointer-events: none;
}
.lock-icon {
    font-size: 36px;
    filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.5));
}
.challenge-tag {
    color: #fff;
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 3px;
    text-shadow: 0 2px 6px rgba(0, 0, 0, 0.6);
    padding: 6px 14px;
    border-radius: 10px;
    background: rgba(245, 166, 35, 0.85);
    box-shadow: 0 4px 12px rgba(245, 166, 35, 0.5);
}

.level-caption {
    position: absolute;
    left: 0; right: 0; bottom: 0;
    height: 38%;
    background: rgba(255, 255, 255, 0.92);
    padding: 8px 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    text-align: center;
}
.level-name {
    font-size: 13px;
    color: #4a6741;
    font-weight: 600;
    letter-spacing: 1px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    width: 100%;
}
.level-meta {
    font-size: 11px;
    color: #8a9a7a;
    letter-spacing: 1px;
    font-variant-numeric: tabular-nums;
}

.level-stars {
    display: inline-flex;
    gap: 2px;
    font-size: 14px;
}
.star.on { filter: drop-shadow(0 0 3px rgba(245, 197, 24, 0.7)); }
.star.off { filter: grayscale(1); opacity: 0.35; }

/* ===== 胜利弹窗三星 ===== */
.win-stars {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin: 6px 0 18px;
    height: 64px;
}
.win-star {
    font-size: 56px;
    line-height: 1;
    display: inline-block;
    transform: scale(1);
    opacity: 0.35;
    filter: grayscale(1);
    transition: filter 0.2s;
}
/* 已获得的星星：初始隐藏，等 pop 弹出 */
.win-star.on {
    transform: scale(0);
    opacity: 0;
    filter: none;
}
.win-star.on.pop {
    animation: starPop 0.55s cubic-bezier(0.18, 0.89, 0.32, 1.28) forwards;
    filter:
        drop-shadow(0 0 8px rgba(245, 197, 24, 0.9))
        drop-shadow(0 0 18px rgba(255, 217, 102, 0.6));
}
@keyframes starPop {
    0%   { transform: scale(0) rotate(-30deg); opacity: 0; }
    60%  { transform: scale(1.35) rotate(8deg); opacity: 1; }
    100% { transform: scale(1) rotate(0); opacity: 1; }
}

.score-value { color: #f5a623; }

/* ===== 金色拖尾 SVG ===== */
.merge-trail {
    position: absolute;
    pointer-events: none;
    z-index: 4;
}
