:root {
    --fruit-size: 26px;
}

#app {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 34rem;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    border: 1px solid #eee;
    padding: 0.5rem;
    border-radius: 3px;
}

.night #app{
    border:1px solid #444;
}

/* ================= 头部 ================= */

.headerdiv {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.5rem;
    border-radius: 3px;
    border: 1px solid #eee;
}

.night .headerdiv {
    border:1px solid #444;
}

.headerdiv h2{
    font-size: 0.8rem;
    font-weight: 400;
    white-space: nowrap;
    letter-spacing: .02em;
}

.header-left,
.header-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.header-left {
    justify-self: start;
}

.header-right {
    justify-self: end;
}

.stat-box {
    min-width: 3rem;
    padding: 0.2rem 0.6rem;
    border-radius: 3px;
    line-height: 1.15;
    display: flex;
    flex-direction: column;
    align-items: center;
    border: 1px solid #eee;
}

.night .stat-box{
    border:1px solid #444;
}

.stat-label {
    font-size: 0.5rem;
    font-weight: 400;
    letter-spacing: .08em;
    margin-bottom: 0.25rem;
}

.stat-value {
    font-size: 0.65rem;
    font-weight: 600;
    color: #8E2050;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.night .stat-value{
    color: #bbb;
}

.stat-box.bump {
    animation: stat-bump .55s cubic-bezier(.34, 1.56, .64, 1);
}

@keyframes stat-bump {

    0%,
    100% {
        transform: scale(1);
    }

    35% {
        transform: scale(1.28);
    }
}

.stat-box.low-moves {
    animation: low-pulse .8s ease-in-out infinite;
}

.stat-box.low-moves .stat-value {
    color: #E8336E;
}

@keyframes low-pulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.07);
    }
}

/* ================= 目标进度条 ================= */
.score-panel {
    padding: 0.5rem 0.7rem;
    border-radius: 3px;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    border: 1px solid #eee;
}

.night .score-panel{
    border:1px solid #444;
}

.score-label {

}

.score-num {
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.score-track {
    flex: 1;
    height: 0.5rem;
    border-radius: 999px;
    background: #eee;
    overflow: hidden;
}

.night .score-track{
    background: #444;
}

.night .score-track {

}

.score-fill {
    height: 100%;
    width: 0%;
    border-radius: 999px;
    background: linear-gradient(90deg, #FFD86F, #FC6262);
    transition: width .5s cubic-bezier(.22, 1, .36, 1);
}

/* ================= 棋盘 ================= */
.board-wrap {
    width: 100%;
    aspect-ratio: 1 / 1;
    max-width: 25rem;
    max-height: 80vh;  
    margin: 0.75rem auto;
    display: flex;
    align-items: center;
    justify-content: center;
}

#game-board {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    gap: 0.25rem;
    padding: 0.5rem;
    border-radius: 6px;
    background: #607D8B;
    border: 1px solid #eee;
    touch-action: none;
}

.night #game-board{
    border:1px solid #444;
}

#game-board.flash {
    animation: board-flash .7s ease-out;
    outline: 4px solid rgba(255, 255, 255, .95);
    outline-offset: -4px;
}

@keyframes board-flash {
    0% {
        filter: brightness(1);
    }

    12% {
        filter: brightness(2.2) saturate(1.7);
    }

    25% {
        filter: brightness(1);
    }

    38% {
        filter: brightness(1.8) saturate(1.4);
    }

    50% {
        filter: brightness(1);
    }

    62% {
        filter: brightness(1.5);
    }

    75%,
    100% {
        filter: brightness(1);
    }
}

/* 格子底色统一 */
.cell {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 3px;
    background: rgba(255, 255, 255, .20);
    box-shadow: inset 0 1px 2px rgba(255, 255, 255, .35);
    cursor: pointer;
    touch-action: none;
}

@media (hover: hover) {
    .cell:hover {
        background: rgba(255, 255, 255, .42);
    }
}

/* ================= 水果 ================= */
.fruit {
    position: absolute;
    z-index: 10;
    line-height: 1;
    font-size: var(--fruit-size);
    pointer-events: none;
    /* 命中检测全部交给 .cell，避免手指遮挡 */
    filter: drop-shadow(0 3px 3px rgba(90, 20, 60, .18));
    transition: transform .15s cubic-bezier(.34, 1.56, .64, 1), opacity .15s ease;
    touch-action: none;
}

.fruit.selected {
    z-index: 20;
    filter: drop-shadow(0 0 9px rgba(255, 255, 255, .95)) drop-shadow(0 5px 8px rgba(90, 20, 60, .3));
    animation: wiggle .55s ease-in-out infinite;
}

@keyframes wiggle {

    0%,
    100% {
        transform: scale(1.18) rotate(-5deg);
    }

    50% {
        transform: scale(1.18) rotate(5deg);
    }
}

.fruit.dragging {
    z-index: 40;
    transition: none;
    filter: drop-shadow(0 10px 12px rgba(90, 20, 60, .35));
}

.fruit.match-anim {
    z-index: 15;
    transform: scale(0) rotate(120deg);
    opacity: 0;
    transition: transform .18s cubic-bezier(.45, 0, .7, .2), opacity .16s ease;
}

.fruit.enter {
    animation: fruit-in .34s cubic-bezier(.34, 1.56, .64, 1) backwards;
}

@keyframes fruit-in {
    from {
        transform: scale(0);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* 特殊水果发光：横向金橙光 / 纵向青蓝光 */
.fruit.sp-row,
.fruit.sp-col {
    z-index: 12;
}

.fruit.sp-row::before,
.fruit.sp-col::before {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    width: 140%;
    height: 140%;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    animation: special-pulse 1.1s ease-in-out infinite;
    z-index: -1;
}

.fruit.sp-row::before {
    background: radial-gradient(circle, rgba(255, 232, 150, .95) 0%, rgba(255, 190, 60, .5) 50%, rgba(255, 190, 60, 0) 72%);
}

.fruit.sp-row {
    filter: drop-shadow(0 0 8px rgba(255, 190, 60, .85)) drop-shadow(0 3px 3px rgba(90, 20, 60, .18));
}

.fruit.sp-col::before {
    background: radial-gradient(circle, rgba(170, 240, 255, .95) 0%, rgba(60, 190, 255, .5) 50%, rgba(60, 190, 255, 0) 72%);
}

.fruit.sp-col {
    filter: drop-shadow(0 0 8px rgba(60, 190, 255, .85)) drop-shadow(0 3px 3px rgba(90, 20, 60, .18));
}

@keyframes special-pulse {

    0%,
    100% {
        opacity: .55;
        transform: translate(-50%, -50%) scale(.88);
    }

    50% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1.08);
    }
}

.fruit.rainbow {
    animation: hue-spin 2.4s linear infinite;
}

@keyframes hue-spin {
    from {
        filter: drop-shadow(0 0 8px #FFD700) hue-rotate(0deg);
    }

    to {
        filter: drop-shadow(0 0 8px #FFD700) hue-rotate(360deg);
    }
}

/* ================= 底部按钮 ================= */
.controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    border: 1px solid #eee;
    margin-top: 0.25rem;
    border-radius: 3px;
    padding: 0.5rem;
}

.night .controls{
    border:1px solid #444;
}

.controls button{
    border: 1px solid #eee;
    background-color: #fff;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    height: 1.5rem;
    padding: 0 0.4rem;
    border-radius: 3px;
    font-size: 0.55rem;
    font-weight: 400;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    border-radius: 3px;
}

.night .controls button{
    border: 1px solid #444;
    background-color: #181a1b;
    color: #aaa;
}

.controls button i{
    font-size: 0.6rem;
}

.controls-right {
    display: flex;
    gap: 8px;
}

.btn-disabled {
    opacity: .45;
    pointer-events: none;
}

.badge {
    background: #FFE1EA;
    color: #E8336E;
    font-size: 0.5rem;
    height: 0.7rem;
    padding: 0 0.3rem;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.night .badge{
    background: #444;
    color: #aaa;
}

/* ================= 特效层 ================= */
#fx-layer {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index:999999;
    overflow: hidden;
}

.particle {
    position: fixed;
    border-radius: 50%;
    pointer-events: none;
    z-index:999999;
    animation: particle-burst .6s cubic-bezier(.05, .6, .35, 1) forwards;
}

@keyframes particle-burst {
    0% {
        transform: translate(0, 0) scale(1);
        opacity: 1;
    }

    100% {
        transform: translate(var(--tx, 40px), var(--ty, 0)) scale(.1);
        opacity: 0;
    }
}

.particle.confetti {
    border-radius: 2px;
    animation: confetti-fall 1.6s linear forwards;
}

@keyframes confetti-fall {
    0% {
        transform: translateY(0) rotate(0deg);
        opacity: 1;
    }

    100% {
        transform: translateY(105vh) rotate(var(--rot, 540deg));
        opacity: .7;
    }
}

.points-text {
    position: fixed;
    transform: translate(-50%, -50%);
    font-size: 1.15rem;
    font-weight: 900;
    color: #fff;
    text-shadow: 0 2px 4px rgba(0, 0, 0, .35);
    animation: pts-float .9s ease-out forwards;
    white-space: nowrap;
}

@keyframes pts-float {
    0% {
        opacity: 0;
        transform: translate(-50%, -30%) scale(.6);
    }

    15% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1.1);
    }

    100% {
        opacity: 0;
        transform: translate(-50%, -130%) scale(1);
    }
}

.combo-text {
    position: fixed;
    transform: translate(-50%, -50%);
    font-weight: 900;
    color: #fff;
    white-space: nowrap;
    text-shadow: 0 2px 0 rgba(214, 51, 108, .8), 0 4px 12px rgba(0, 0, 0, .3);
    animation: combo-pop .9s cubic-bezier(.34, 1.56, .64, 1) forwards;
}

@keyframes combo-pop {
    0% {
        transform: translate(-50%, -50%) scale(.3);
        opacity: 0;
    }

    25% {
        transform: translate(-50%, -60%) scale(1.15);
        opacity: 1;
    }

    70% {
        transform: translate(-50%, -80%) scale(1);
        opacity: 1;
    }

    100% {
        transform: translate(-50%, -120%) scale(1);
        opacity: 0;
    }
}

/* 连锁加步提示 */
.reward-text {
    position: fixed;
    transform: translate(-50%, -50%);
    font-weight: 900;
    color: #2FBF71;
    white-space: nowrap;
    text-shadow: 0 0 10px rgba(47, 191, 113, .55), 0 2px 0 rgba(20, 90, 55, .9), 0 4px 12px rgba(0, 0, 0, .25);
    animation: reward-pop 1.1s cubic-bezier(.34, 1.56, .64, 1) forwards;
}

.reward-text span {
    color: #FFD93D;
}

@keyframes reward-pop {
    0% {
        transform: translate(-50%, -50%) scale(.4);
        opacity: 0;
    }

    20% {
        transform: translate(-50%, -60%) scale(1.18);
        opacity: 1;
    }

    75% {
        transform: translate(-50%, -85%) scale(1);
        opacity: 1;
    }

    100% {
        transform: translate(-50%, -125%) scale(1);
        opacity: 0;
    }
}

/* ================= 弹窗 ================= */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 99999;
    background: rgb(0 0 0 / 50%);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    opacity: 0;
    pointer-events: none;
    transition: opacity .3s ease;
}

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

.modal-content {
    background: #fff;
    border-radius: 6px;
    padding: 0.5rem;
    width: 100%;
    max-width: 15rem;
    text-align: center;
    transform: translateY(28px) scale(.94);
    transition: transform .35s cubic-bezier(.34, 1.56, .64, 1);
}

.night .modal-content{
    border:1px solid #444;
    background: #121313;
}

.modal-overlay.active .modal-content {
    transform: translateY(0) scale(1);
}

.modal-icon {
    font-size: 2rem;
    line-height: 1;
    margin-top: 0.5rem;
}

.modal-title {
    margin: 0.6rem 0 0.3rem;
    font-size: 1rem;
    font-weight: 600;
    color: #C2255C;
}

.modal-msg {
    color: #7A6470;
    font-size: 0.65rem;
    line-height: 1.7;
}

.night .modal-msg{
    color: #bbb;
}

.modal-msg b {
    color: #E8336E;
}

.modal-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    margin-top: 1rem;
}

.modal-actions button {
    height: 1.5rem;
    border: 1px solid #607D8B;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #607D8B;
    color: #fff;
    border-radius: 3px;
}

.modal-actions button.btn-soft{
    background-color: #009688;
    border: 1px solid #009688;
}

@media (max-width: 480px) {
    .headerdiv {
        grid-template-columns: 1fr 1fr;
    }
    .headerdiv h2{
        display: none;
    }
}