:root {
    --bg-1: #ffe7ee;
    --bg-2: #fff4e0;
    --bg-3: #e8f5ff;
    --card: #ffffff;
    --card-shadow: 0 12px 28px rgba(255, 169, 182, 0.28), 0 2px 6px rgba(0, 0, 0, 0.04);
    --text: #5c4a3d;
    --text-soft: #9a8478;
    --accent: #ff8aa3;
    --accent-dark: #ff6b8a;
    --mint: #7fe5b7;
    --mint-dark: #5dc8a0;
    --yellow: #ffd571;
    --board: #fff8dc;
    --board-line: #fbe9b8;
    --radius-lg: 28px;
    --radius-md: 18px;
    --radius-sm: 12px;
    --font: 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', system-ui, -apple-system, sans-serif;
}

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

html, body {
    margin: 0;
    padding: 0;
    min-height: 100%;
}

body {
    font-family: var(--font);
    color: var(--text);
    background:
        radial-gradient(circle at 15% 20%, var(--bg-3) 0%, transparent 45%),
        radial-gradient(circle at 85% 80%, var(--bg-2) 0%, transparent 45%),
        linear-gradient(135deg, var(--bg-1) 0%, #fff 100%);
    background-attachment: fixed;
    overflow-x: hidden;
    position: relative;
    user-select: none;
    -webkit-user-select: none;
}

/* 飘云装饰 */
.cloud {
    position: fixed;
    background: rgba(255, 255, 255, 0.7);
    border-radius: 50%;
    filter: blur(2px);
    pointer-events: none;
    z-index: 0;
}

.cloud::before,
.cloud::after {
    content: '';
    position: absolute;
    background: inherit;
    border-radius: 50%;
}

.cloud-1 {
    width: 120px;
    height: 40px;
    top: 8%;
    left: 5%;
    animation: float 18s ease-in-out infinite;
}

.cloud-1::before { width: 60px; height: 60px; top: -30px; left: 15px; }
.cloud-1::after { width: 50px; height: 50px; top: -25px; right: 20px; }

.cloud-2 {
    width: 90px;
    height: 30px;
    top: 18%;
    right: 8%;
    animation: float 22s ease-in-out infinite reverse;
}

.cloud-2::before { width: 45px; height: 45px; top: -22px; left: 12px; }
.cloud-2::after { width: 40px; height: 40px; top: -18px; right: 12px; }

.cloud-3 {
    width: 100px;
    height: 35px;
    bottom: 15%;
    left: 10%;
    animation: float 26s ease-in-out infinite;
}

.cloud-3::before { width: 50px; height: 50px; top: -25px; left: 15px; }
.cloud-3::after { width: 42px; height: 42px; top: -20px; right: 15px; }

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-16px); }
}

/* 主容器 */
.game-wrap {
    position: relative;
    z-index: 1;
    max-width: 480px;
    margin: 0 auto;
    padding: 28px 18px 24px;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 18px;
}

/* 顶部栏 */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    background: var(--card);
    padding: 10px 18px;
    border-radius: 999px;
    box-shadow: var(--card-shadow);
    font-weight: 700;
    font-size: 18px;
    color: var(--accent-dark);
}

.brand-emoji {
    font-size: 22px;
    transform: translateY(-1px);
}

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

.score-card {
    background: var(--card);
    border-radius: var(--radius-md);
    box-shadow: var(--card-shadow);
    padding: 8px 16px;
    min-width: 74px;
    text-align: center;
}

.score-card.best {
    background: linear-gradient(135deg, #fff5cc 0%, #ffe9a8 100%);
}

.score-label {
    font-size: 11px;
    color: var(--text-soft);
    letter-spacing: 0.05em;
}

.score-value {
    font-size: 22px;
    font-weight: 800;
    color: var(--text);
    line-height: 1.1;
    margin-top: 2px;
    font-feature-settings: 'tnum';
}

/* 棋盘 */
.board-wrap {
    position: relative;
    background: var(--card);
    border-radius: var(--radius-lg);
    padding: 14px;
    box-shadow: var(--card-shadow);
    aspect-ratio: 1 / 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

#board {
    width: 100%;
    height: 100%;
    border-radius: var(--radius-md);
    background:
        radial-gradient(circle at 30% 30%, #fffceb 0%, var(--board) 60%, #fbedc4 100%);
    display: block;
    touch-action: none;
}

/* 遮罩 */
.overlay {
    position: absolute;
    inset: 14px;
    border-radius: var(--radius-md);
    background: rgba(255, 244, 224, 0.78);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 18px;
    transition: opacity 0.25s ease;
}

.overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.overlay-card {
    background: var(--card);
    border-radius: var(--radius-lg);
    padding: 24px 28px;
    text-align: center;
    box-shadow: 0 18px 40px rgba(255, 169, 182, 0.32);
    max-width: 90%;
    animation: pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes pop {
    0% { transform: scale(0.7); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

.overlay-emoji {
    font-size: 52px;
    line-height: 1;
    margin-bottom: 8px;
    animation: wiggle 1.4s ease-in-out infinite;
}

@keyframes wiggle {
    0%, 100% { transform: rotate(-6deg); }
    50% { transform: rotate(6deg); }
}

.overlay-title {
    margin: 6px 0 8px;
    font-size: 22px;
    color: var(--accent-dark);
    font-weight: 800;
}

.overlay-text {
    margin: 0 0 16px;
    color: var(--text-soft);
    font-size: 14px;
    line-height: 1.55;
}

.overlay-hint {
    margin: 12px 0 0;
    color: var(--text-soft);
    font-size: 12px;
}

/* 按钮 */
.btn {
    border: none;
    cursor: pointer;
    font-family: inherit;
    font-weight: 700;
    transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.btn:active {
    transform: scale(0.94);
}

.btn.primary {
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
    color: white;
    padding: 12px 36px;
    border-radius: 999px;
    font-size: 16px;
    box-shadow: 0 6px 16px rgba(255, 107, 138, 0.4);
}

.btn.primary:hover {
    box-shadow: 0 8px 20px rgba(255, 107, 138, 0.5);
}

.btn.ghost {
    background: white;
    color: var(--accent-dark);
    padding: 12px 28px;
    border-radius: 999px;
    font-size: 15px;
    box-shadow: inset 0 0 0 2px rgba(255, 138, 163, 0.4);
}

.btn.ghost:hover {
    background: rgba(255, 138, 163, 0.08);
}

.overlay-actions {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    margin: 0 0 4px;
}

/* 难度选择 */
.difficulty-row {
    margin: 0 0 14px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.difficulty-row.hidden {
    display: none;
}

.difficulty-label {
    font-size: 12px;
    color: var(--text-soft);
    letter-spacing: 0.06em;
}

.diff-pills {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
}

.diff-pill {
    border: none;
    background: rgba(255, 244, 224, 0.65);
    color: var(--text);
    padding: 7px 13px;
    border-radius: 999px;
    font-size: 13px;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.12s ease, background 0.2s, box-shadow 0.2s;
    -webkit-tap-highlight-color: transparent;
    box-shadow: inset 0 0 0 1.5px rgba(255, 184, 197, 0.35);
}

.diff-pill:hover {
    background: white;
}

.diff-pill.active {
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
    color: white;
    box-shadow: 0 4px 10px rgba(255, 107, 138, 0.4);
}

.diff-pill:active {
    transform: scale(0.94);
}

.hidden {
    display: none !important;
}

/* 分享弹层 */
.share-modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

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

.share-modal-mask {
    position: absolute;
    inset: 0;
    background: rgba(40, 24, 36, 0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    animation: fade 0.2s ease;
}

@keyframes fade {
    from { opacity: 0; }
    to { opacity: 1; }
}

.share-modal-panel {
    position: relative;
    background: white;
    border-radius: var(--radius-lg);
    padding: 22px 22px 18px;
    max-width: 360px;
    width: 100%;
    max-height: 92vh;
    overflow-y: auto;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.25);
    animation: pop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.share-close {
    position: absolute;
    top: 10px;
    right: 12px;
    background: transparent;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    font-size: 16px;
    color: var(--text-soft);
    cursor: pointer;
    transition: background 0.15s;
}

.share-close:hover {
    background: rgba(0, 0, 0, 0.05);
}

.share-modal-title {
    margin: 0 0 14px;
    font-size: 18px;
    text-align: center;
    color: var(--accent-dark);
}

.share-image-wrap {
    position: relative;
    border-radius: var(--radius-md);
    overflow: hidden;
    background: linear-gradient(135deg, #fff5ed, #ffeaf1);
    min-height: 360px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 20px rgba(255, 169, 182, 0.18);
}

.share-image {
    display: block;
    width: 100%;
    height: auto;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: default;
}

.share-image-loading {
    position: absolute;
    color: var(--text-soft);
    font-size: 13px;
}

.share-image-wrap.ready .share-image-loading {
    display: none;
}

.share-hint {
    margin: 12px 0 14px;
    text-align: center;
    color: var(--text-soft);
    font-size: 12.5px;
    line-height: 1.5;
}

.hint-desktop { display: inline; }
.hint-mobile { display: none; }

@media (hover: none) and (pointer: coarse) {
    .hint-desktop { display: none; }
    .hint-mobile { display: inline; }
}

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

.share-actions .btn {
    padding: 11px 22px;
    font-size: 14px;
}

.share-toast {
    text-align: center;
    margin-top: 10px;
    min-height: 18px;
    font-size: 12px;
    color: var(--mint-dark);
    opacity: 0;
    transition: opacity 0.2s;
}

.share-toast.visible {
    opacity: 1;
}

/* 方向键 */
.controls {
    text-align: center;
}

.control-hint {
    font-size: 12px;
    color: var(--text-soft);
    margin-bottom: 12px;
}

.dpad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    max-width: 220px;
    margin: 0 auto;
}

.dpad-btn {
    background: var(--card);
    border: none;
    border-radius: var(--radius-md);
    color: var(--accent-dark);
    font-size: 18px;
    font-weight: 700;
    aspect-ratio: 1 / 1;
    box-shadow: var(--card-shadow);
    cursor: pointer;
    transition: transform 0.1s, background 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.dpad-btn:active {
    transform: scale(0.9);
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
    color: white;
}

.dpad-btn.up { grid-column: 2; grid-row: 1; }
.dpad-btn.left { grid-column: 1; grid-row: 2; }
.dpad-btn.pause { grid-column: 2; grid-row: 2; background: linear-gradient(135deg, var(--yellow) 0%, #ffb84d 100%); color: white; font-size: 14px; letter-spacing: 2px; }
.dpad-btn.right { grid-column: 3; grid-row: 2; }
.dpad-btn.down { grid-column: 2; grid-row: 3; }

.foot {
    text-align: center;
    font-size: 12px;
    color: var(--text-soft);
    padding: 4px 0 12px;
}

/* 小屏适配 */
@media (max-width: 420px) {
    .game-wrap { padding: 18px 14px; gap: 14px; }
    .brand { font-size: 15px; padding: 8px 14px; }
    .brand-emoji { font-size: 18px; }
    .score-card { min-width: 64px; padding: 6px 12px; }
    .score-value { font-size: 19px; }
    .overlay-title { font-size: 18px; }
    .overlay-card { padding: 20px 22px; }
    .overlay-emoji { font-size: 44px; }
    .dpad { max-width: 200px; }
}

/* 短屏适配 (横屏手机) */
@media (max-height: 640px) and (orientation: landscape) {
    .game-wrap {
        max-width: 700px;
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
    }
    .topbar { flex-basis: 100%; }
    .board-wrap { flex: 0 0 50%; max-width: 50%; }
    .controls { flex: 1; }
    .foot { flex-basis: 100%; }
}
