/* ============================================
   2048 · 经典暖色版
   配色：米黄底色 + 暖橙渐变数字方块
============================================ */

:root {
    --bg: #faf8ef;
    --bg-soft: #f7f1dc;
    --board-bg: #bbada0;
    --cell-bg: #cdc1b4;
    --text-dark: #776e65;
    --text-light: #f9f6f2;
    --shadow-soft: 0 6px 20px rgba(0, 0, 0, 0.08);
    --shadow-card: 0 10px 30px rgba(118, 100, 88, 0.18);
    --accent: #edc22e;
    --accent-deep: #d4a017;

    /* 棋盘网格几何（百分比基于 .tiles 容器） */
    --cell-size: 22.375%;
    --cell-step: 25.875%;

    /* 方块颜色 */
    --tile-2: linear-gradient(160deg, #f3eada 0%, #ece0c8 100%);
    --tile-4: linear-gradient(160deg, #efdbb2 0%, #ead2a1 100%);
    --tile-8: linear-gradient(155deg, #f5b97c 0%, #f0a361 100%);
    --tile-16: linear-gradient(155deg, #f59563 0%, #ee7e44 100%);
    --tile-32: linear-gradient(155deg, #f47957 0%, #ed5d37 100%);
    --tile-64: linear-gradient(155deg, #f15c3b 0%, #d63d1a 100%);
    --tile-128: linear-gradient(155deg, #f6d57d 0%, #f0c042 100%);
    --tile-256: linear-gradient(155deg, #f7d365 0%, #efb524 100%);
    --tile-512: linear-gradient(155deg, #f6c845 0%, #ecaa1a 100%);
    --tile-1024: linear-gradient(155deg, #f3bc34 0%, #d99711 100%);
    --tile-2048: linear-gradient(155deg, #edc22e 0%, #c8830d 100%);
    --tile-huge: linear-gradient(155deg, #3c3a32 0%, #1b1a16 100%);

    --font-tile: clamp(1.7rem, 7.5vmin, 3.4rem);
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html,
body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    background-image:
        radial-gradient(circle at 18% -10%, rgba(237, 194, 46, 0.18), transparent 45%),
        radial-gradient(circle at 110% 110%, rgba(245, 149, 99, 0.18), transparent 45%);
    color: var(--text-dark);
    font-family: "Inter", "Helvetica Neue", "PingFang SC", "Microsoft YaHei", -apple-system,
        BlinkMacSystemFont, sans-serif;
    min-height: 100vh;
    overflow-x: hidden;
}

body {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: clamp(12px, 3vh, 32px) 14px env(safe-area-inset-bottom, 14px);
}

.bg-glow {
    position: fixed;
    width: 380px;
    height: 380px;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.45;
    pointer-events: none;
    z-index: 0;
}

.bg-glow-1 {
    background: #f5b97c;
    top: -120px;
    left: -100px;
}

.bg-glow-2 {
    background: #edc22e;
    bottom: -140px;
    right: -120px;
}

.game-wrap {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 460px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* ============================================
   顶部品牌 + 分数
============================================ */

.topbar {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 12px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-logo {
    width: 64px;
    height: 64px;
    border-radius: 12px;
    background: linear-gradient(155deg, #edc22e 0%, #c8830d 100%);
    color: #fff;
    font-weight: 800;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-card);
    letter-spacing: 0.5px;
}

.brand-title {
    font-size: 22px;
    font-weight: 800;
    color: #5d4f43;
    letter-spacing: 1px;
}

.brand-desc {
    font-size: 12px;
    color: #998270;
    margin-top: 4px;
}

.scores {
    display: flex;
    gap: 8px;
}

.score-card {
    position: relative;
    min-width: 80px;
    background: linear-gradient(160deg, #b6a99c 0%, #998b7e 100%);
    color: #fff;
    border-radius: 10px;
    padding: 8px 14px 10px;
    text-align: center;
    box-shadow: var(--shadow-soft);
}

.score-card.best {
    background: linear-gradient(160deg, #edc22e 0%, #c8830d 100%);
}

.score-label {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 1px;
    opacity: 0.85;
    text-transform: uppercase;
}

.score-value {
    font-size: 22px;
    font-weight: 800;
    margin-top: 2px;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
}

.score-add {
    position: absolute;
    left: 0;
    right: 0;
    top: 4px;
    color: rgba(255, 255, 255, 0.95);
    font-size: 18px;
    font-weight: 800;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
    pointer-events: none;
    opacity: 0;
}

.score-add.show {
    animation: score-fly 0.9s ease-out forwards;
}

@keyframes score-fly {
    0% {
        opacity: 0;
        transform: translateY(0);
    }
    20% {
        opacity: 1;
    }
    100% {
        opacity: 0;
        transform: translateY(-32px);
    }
}

/* ============================================
   工具栏
============================================ */

.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: rgba(255, 255, 255, 0.6);
    border: 1px solid rgba(187, 173, 160, 0.25);
    border-radius: 12px;
    padding: 10px 14px;
    box-shadow: var(--shadow-soft);
    backdrop-filter: blur(6px);
}

.hint {
    font-size: 12px;
    line-height: 1.5;
    color: #7a6b5e;
    flex: 1;
}

.hint-strong {
    display: inline-block;
    background: #edc22e;
    color: #fff;
    font-weight: 700;
    padding: 1px 8px;
    border-radius: 6px;
    margin-right: 6px;
    font-size: 11px;
    letter-spacing: 1px;
}

.hint-text b {
    color: #c8830d;
}

.btn {
    border: none;
    cursor: pointer;
    font-family: inherit;
    font-weight: 700;
    border-radius: 10px;
    padding: 10px 16px;
    transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    user-select: none;
    white-space: nowrap;
}

.btn.primary {
    background: linear-gradient(155deg, #edc22e 0%, #c8830d 100%);
    color: #fff;
    box-shadow: 0 6px 16px rgba(200, 131, 13, 0.35);
}

.btn.primary:hover {
    transform: translateY(-1px);
    filter: brightness(1.05);
}

.btn.primary:active {
    transform: translateY(1px);
    filter: brightness(0.97);
}

.btn.ghost {
    background: rgba(255, 255, 255, 0.85);
    color: #7a6b5e;
    border: 1.5px solid #d6c8b8;
}

.btn.ghost:hover {
    border-color: #edc22e;
    color: #c8830d;
}

.btn.share {
    background: linear-gradient(155deg, #f59563 0%, #ee7e44 100%);
    color: #fff;
    box-shadow: 0 6px 16px rgba(238, 126, 68, 0.35);
}

.btn.share:hover {
    transform: translateY(-1px);
    filter: brightness(1.05);
}

.btn.share:active {
    transform: translateY(1px);
    filter: brightness(0.97);
}

.btn-icon {
    font-size: 16px;
    display: inline-block;
    transform: translateY(-1px);
}

/* ============================================
   棋盘
============================================ */

.board-wrap {
    position: relative;
}

.board {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
    background: var(--board-bg);
    border-radius: 16px;
    padding: 2.5%;
    box-shadow: var(--shadow-card);
    touch-action: none;
    user-select: none;
    overflow: hidden;
}

.grid {
    position: absolute;
    inset: 2.5%;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 3.5%;
}

.cell {
    background: var(--cell-bg);
    border-radius: 8px;
}

.tiles {
    position: absolute;
    inset: 2.5%;
    pointer-events: none;
}

/* ============================================
   方块
============================================ */

.tile {
    position: absolute;
    width: var(--cell-size);
    height: var(--cell-size);
    top: calc(var(--r, 0) * var(--cell-step));
    left: calc(var(--c, 0) * var(--cell-step));
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: var(--font-tile);
    color: var(--text-dark);
    background: var(--tile-2);
    transition: top 0.16s cubic-bezier(0.4, 0, 0.2, 1),
        left 0.16s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: top, left, transform;
    box-shadow: 0 2px 6px rgba(118, 100, 88, 0.18),
        inset 0 1px 0 rgba(255, 255, 255, 0.35);
    font-variant-numeric: tabular-nums;
    line-height: 1;
}

.tile.spawn {
    animation: tile-spawn 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes tile-spawn {
    0% {
        opacity: 0;
        transform: scale(0);
    }
    60% {
        opacity: 1;
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

.tile.merged {
    animation: tile-merge 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
    z-index: 2;
}

@keyframes tile-merge {
    0% {
        transform: scale(0.92);
    }
    50% {
        transform: scale(1.15);
    }
    100% {
        transform: scale(1);
    }
}

/* 数值样式 */
.tile.v-2 {
    background: var(--tile-2);
    color: var(--text-dark);
}
.tile.v-4 {
    background: var(--tile-4);
    color: var(--text-dark);
}
.tile.v-8 {
    background: var(--tile-8);
    color: var(--text-light);
}
.tile.v-16 {
    background: var(--tile-16);
    color: var(--text-light);
}
.tile.v-32 {
    background: var(--tile-32);
    color: var(--text-light);
}
.tile.v-64 {
    background: var(--tile-64);
    color: var(--text-light);
    box-shadow: 0 2px 6px rgba(118, 100, 88, 0.22),
        0 0 12px rgba(241, 92, 59, 0.35),
        inset 0 1px 0 rgba(255, 255, 255, 0.35);
}
.tile.v-128 {
    background: var(--tile-128);
    color: var(--text-light);
    font-size: calc(var(--font-tile) * 0.92);
    box-shadow: 0 2px 6px rgba(118, 100, 88, 0.22),
        0 0 14px rgba(240, 192, 66, 0.45),
        inset 0 1px 0 rgba(255, 255, 255, 0.4);
}
.tile.v-256 {
    background: var(--tile-256);
    color: var(--text-light);
    font-size: calc(var(--font-tile) * 0.92);
    box-shadow: 0 2px 6px rgba(118, 100, 88, 0.22),
        0 0 16px rgba(239, 181, 36, 0.5),
        inset 0 1px 0 rgba(255, 255, 255, 0.4);
}
.tile.v-512 {
    background: var(--tile-512);
    color: var(--text-light);
    font-size: calc(var(--font-tile) * 0.92);
    box-shadow: 0 2px 6px rgba(118, 100, 88, 0.22),
        0 0 18px rgba(236, 170, 26, 0.55),
        inset 0 1px 0 rgba(255, 255, 255, 0.4);
}
.tile.v-1024 {
    background: var(--tile-1024);
    color: var(--text-light);
    font-size: calc(var(--font-tile) * 0.78);
    box-shadow: 0 2px 6px rgba(118, 100, 88, 0.22),
        0 0 20px rgba(217, 151, 17, 0.6),
        inset 0 1px 0 rgba(255, 255, 255, 0.4);
}
.tile.v-2048 {
    background: var(--tile-2048);
    color: var(--text-light);
    font-size: calc(var(--font-tile) * 0.78);
    box-shadow: 0 2px 6px rgba(118, 100, 88, 0.22),
        0 0 26px rgba(237, 194, 46, 0.75),
        inset 0 1px 0 rgba(255, 255, 255, 0.45);
}
.tile.v-huge {
    background: var(--tile-huge);
    color: #f9f6f2;
    font-size: calc(var(--font-tile) * 0.7);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35),
        0 0 26px rgba(60, 58, 50, 0.7),
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

/* ============================================
   覆盖层
============================================ */

.overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(238, 228, 218, 0.78);
    border-radius: 16px;
    backdrop-filter: blur(2px);
    z-index: 10;
    animation: overlay-in 0.3s ease-out both;
}

.overlay.hidden {
    display: none;
}

@keyframes overlay-in {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.overlay-card {
    text-align: center;
    padding: 24px 28px;
    max-width: 84%;
}

.overlay-emoji {
    font-size: 50px;
    line-height: 1;
    margin-bottom: 10px;
    filter: drop-shadow(0 4px 10px rgba(118, 100, 88, 0.25));
    animation: bounce-in 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes bounce-in {
    0% {
        transform: scale(0) rotate(-20deg);
    }
    70% {
        transform: scale(1.1) rotate(8deg);
    }
    100% {
        transform: scale(1) rotate(0deg);
    }
}

.overlay-title {
    font-size: 28px;
    font-weight: 800;
    color: #5d4f43;
    margin: 0 0 8px;
}

.overlay-text {
    font-size: 14px;
    color: #8a7a6b;
    margin: 0 0 18px;
    line-height: 1.5;
}

.overlay-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

/* ============================================
   底部
============================================ */

.foot {
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #998270;
    font-size: 12px;
    padding: 4px 2px 10px;
    flex-wrap: wrap;
    gap: 8px;
}

.keys {
    display: flex;
    align-items: center;
    gap: 4px;
}

.key {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    background: #fff;
    border: 1px solid #d6c8b8;
    border-bottom-width: 2px;
    border-radius: 5px;
    font-size: 12px;
    color: #7a6b5e;
    font-weight: 700;
}

.keys-tip {
    margin-left: 6px;
    color: #998270;
}

/* ============================================
   响应式
============================================ */

@media (max-width: 380px) {
    .brand-logo {
        width: 54px;
        height: 54px;
        font-size: 15px;
    }

    .brand-title {
        font-size: 18px;
    }

    .brand-desc {
        font-size: 11px;
    }

    .score-card {
        min-width: 66px;
        padding: 6px 10px 8px;
    }

    .score-value {
        font-size: 18px;
    }

    .toolbar {
        padding: 8px 10px;
    }

    .hint {
        font-size: 11px;
    }

    .btn {
        padding: 8px 12px;
        font-size: 13px;
    }

    .keys-tip {
        display: none;
    }
}

@media (max-width: 480px) {
    body {
        padding: 8px 10px env(safe-area-inset-bottom, 10px);
    }
}

/* ============================================
   分享弹层
============================================ */

.share-mask {
    position: fixed;
    inset: 0;
    background: rgba(50, 40, 30, 0.55);
    backdrop-filter: blur(6px);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: overlay-in 0.25s ease-out both;
}

.share-mask.hidden {
    display: none;
}

.share-modal {
    position: relative;
    width: 100%;
    max-width: 420px;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
    background: linear-gradient(180deg, #ffffff 0%, #faf4e6 100%);
    border-radius: 18px;
    padding: 22px 22px 18px;
    box-shadow: 0 25px 60px rgba(60, 40, 20, 0.35),
        inset 0 1px 0 rgba(255, 255, 255, 0.6);
    animation: share-in 0.32s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes share-in {
    0% {
        opacity: 0;
        transform: translateY(20px) scale(0.94);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.share-close {
    position: absolute;
    top: 12px;
    right: 14px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: rgba(187, 173, 160, 0.18);
    color: #7a6b5e;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s ease, color 0.15s ease;
}

.share-close:hover {
    background: rgba(237, 194, 46, 0.25);
    color: #c8830d;
}

.share-modal-title {
    margin: 0 36px 4px 0;
    font-size: 20px;
    font-weight: 800;
    color: #5d4f43;
}

.share-modal-sub {
    margin: 0 0 14px;
    font-size: 12.5px;
    line-height: 1.55;
    color: #998270;
}

.share-canvas-wrap {
    background: #f0e6d2;
    border-radius: 14px;
    padding: 6px;
    box-shadow: inset 0 1px 4px rgba(0, 0, 0, 0.08);
    margin-bottom: 14px;
}

.share-canvas-wrap canvas {
    display: block;
    width: 100%;
    height: auto;
    border-radius: 10px;
    background: #faf8ef;
}

.share-actions {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.share-actions .btn {
    flex: 1;
    justify-content: center;
    padding: 11px 8px;
    font-size: 13.5px;
}

.share-link {
    background: rgba(237, 194, 46, 0.12);
    border: 1px solid rgba(237, 194, 46, 0.28);
    border-radius: 10px;
    padding: 8px 12px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.share-link-label {
    font-size: 11px;
    font-weight: 700;
    color: #c8830d;
    letter-spacing: 1px;
    text-transform: uppercase;
}

.share-link-url {
    font-size: 12.5px;
    color: #5d4f43;
    word-break: break-all;
    font-family: "SF Mono", "Menlo", "Consolas", monospace;
}

.share-toast {
    position: fixed;
    bottom: 38px;
    left: 50%;
    transform: translateX(-50%) translateY(10px);
    background: rgba(40, 30, 20, 0.92);
    color: #fff8e6;
    padding: 10px 18px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 600;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 200;
    max-width: 86%;
    text-align: center;
    word-break: break-all;
}

.share-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

@media (max-width: 380px) {
    .share-modal {
        padding: 18px 16px 14px;
    }
    .share-modal-title {
        font-size: 18px;
    }
    .share-actions {
        flex-wrap: wrap;
    }
    .share-actions .btn {
        font-size: 13px;
        padding: 10px 6px;
    }
}
