* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --bg: #a8d85a;
    --bg-light: #b8e86a;
    --card: #ffffff;
    --accent: #ff9800;
    --gold: #ff6f00;
    --text: #3a5a20;
    --text-light: #5a7a30;
    --dim: #7a9a50;
    --danger: #e04040;
    --success: #4caf50;
    --slot-bg: #6aaa30;
    --btn-blue: #42a5f5;
    --btn-blue-dark: #1e88e5;
    --shadow: rgba(0,0,0,0.1);
    --shadow-md: rgba(0,0,0,0.15);
    --emoji-font: 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji', 'PingFang SC', 'Microsoft YaHei', sans-serif;
}

html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior: none;
    overscroll-behavior-x: none;
}

body {
    background: linear-gradient(180deg, #b8e86a 0%, #8cc63f 50%, #7ab832 100%);
    color: var(--text);
    font-family: 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
    min-height: 100vh;
    min-height: 100dvh;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    -webkit-overflow-scrolling: touch;
}

/* ─── Header ─── */

.game-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    max-width: 500px;
    padding: 10px 16px;
    background: rgba(255,255,255,0.35);
    border-radius: 0 0 16px 16px;
    flex-shrink: 0;
    box-shadow: 0 2px 8px var(--shadow);
}

.game-title {
    font-size: 20px;
    font-weight: 800;
    color: var(--gold);
    text-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.header-right {
    display: flex;
    gap: 10px;
    align-items: center;
}

.timer {
    font-size: 13px;
    color: var(--text-light);
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}

.header-btn {
    background: var(--btn-blue);
    border: none;
    color: #fff;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(66,165,245,0.4);
    transition: transform 0.1s;
}

.header-btn:active {
    transform: scale(0.95);
}

/* ─── Leaderboard Tip ─── */

.lb-tip {
    font-size: 11px;
    color: var(--dim);
    margin-top: 10px;
    padding: 6px 10px;
    background: rgba(0,0,0,0.04);
    border-radius: 8px;
    line-height: 1.6;
}

/* ─── Difficulty badge ─── */

.diff-badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
}

.diff-1 { background: #c8e6c9; color: #2e7d32; }
.diff-2 { background: #dcedc8; color: #558b2f; }
.diff-3 { background: #fff9c4; color: #f57f17; }
.diff-4 { background: #ffe0b2; color: #e65100; }
.diff-5 { background: #ffcdd2; color: #c62828; }
.diff-6 { background: #e1bee7; color: #7b1fa2; }

.free-diff-btn {
    border: none;
    cursor: pointer;
    padding: 4px 12px;
    font-size: 12px;
    font-weight: 700;
    border-radius: 20px;
    transition: transform 0.1s;
}

.free-diff-btn:active {
    transform: scale(0.93);
}

/* ─── Board ─── */

.board-container {
    position: relative;
    width: 100%;
    max-width: 500px;
    flex: 1;
    min-height: 0;
    aspect-ratio: 1;
    margin: 4px auto;
    touch-action: manipulation;
    overflow: hidden;
}

.tile {
    position: absolute;
    width: var(--tile-size);
    height: var(--tile-size);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: calc(var(--tile-size) * 0.55);
    background: #fff;
    border: 2px solid #d0e8a0;
    border-radius: 10px;
    cursor: pointer;
    user-select: none;
    font-family: var(--emoji-font);
    line-height: 1;
    will-change: transform, opacity;
    transition: transform 0.08s ease-out, opacity 0.08s;
    z-index: var(--z);
    box-shadow: 0 2px 4px var(--shadow), 0 1px 0 #c0d890 inset;
}

.tile:active:not(.blocked) {
    transform: scale(0.92);
}

.tile.blocked {
    opacity: 0.4;
    cursor: not-allowed;
    background: #e8ecd8;
    border-color: #c8d8a0;
    box-shadow: none;
}

/* ─── Slot ─── */

.slot-area {
    width: 100%;
    max-width: 500px;
    padding: 6px 16px;
    flex-shrink: 0;
}

.park-bar {
    display: none;
    gap: 4px;
    justify-content: center;
    margin-bottom: 4px;
    min-height: 0;
}

.park-bar.has-tiles {
    display: flex;
}

.park-cell {
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-family: var(--emoji-font);
    line-height: 1;
    background: #fff3e0;
    border: 2px solid #ffb74d;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(255,152,0,0.3);
}

.slot-bar {
    display: flex;
    gap: 4px;
    background: var(--slot-bg);
    border: 3px solid #5a9a28;
    border-radius: 14px;
    padding: 6px;
    min-height: 56px;
    align-items: center;
    justify-content: center;
    box-shadow: 0 3px 8px rgba(0,0,0,0.15), inset 0 2px 4px rgba(0,0,0,0.1);
}

.slot-cell {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-family: var(--emoji-font);
    line-height: 1;
    background: rgba(255,255,255,0.15);
    border-radius: 8px;
    border: 2px dashed rgba(255,255,255,0.3);
}

.slot-cell.filled {
    background: #fff;
    border: 2px solid #d0e8a0;
    box-shadow: 0 1px 3px var(--shadow);
    animation: slotIn 0.15s ease-out;
}

@keyframes slotIn {
    from { transform: translateY(-12px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* ─── Power-up Buttons ─── */

.powerups {
    display: flex;
    gap: 12px;
    padding: 6px 16px 12px;
    width: 100%;
    max-width: 500px;
    justify-content: center;
    flex-shrink: 0;
}

.power-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 8px 16px;
    background: linear-gradient(180deg, #52b5ff, #2196f3);
    border: none;
    border-radius: 12px;
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    min-width: 70px;
    box-shadow: 0 3px 8px rgba(33,150,243,0.35);
    transition: transform 0.1s;
}

.power-btn:active:not(:disabled) {
    transform: scale(0.94);
}

.power-btn .icon { font-size: 20px; }
.power-btn .count { font-size: 10px; color: rgba(255,255,255,0.8); }

.power-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    background: #b0bec5;
    box-shadow: none;
}

/* ─── Modals ─── */

.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.modal-overlay.show { display: flex; }

.modal-box {
    background: #fff;
    border: none;
    border-radius: 20px;
    padding: 28px;
    width: 90%;
    max-width: 380px;
    max-height: 85vh;
    max-height: 85dvh;
    text-align: center;
    box-shadow: 0 16px 48px rgba(0,0,0,0.2);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.modal-box h2 {
    font-size: 22px;
    color: var(--gold);
    margin-bottom: 12px;
}

.modal-box p {
    font-size: 14px;
    color: var(--dim);
    margin-bottom: 16px;
    line-height: 1.6;
}

.modal-input {
    width: 100%;
    padding: 10px 14px;
    background: #f5f8f0;
    border: 2px solid #d0e8a0;
    border-radius: 10px;
    color: var(--text);
    font-size: 15px;
    outline: none;
    margin-bottom: 12px;
}

.modal-input:focus { border-color: var(--accent); }

.btn-primary {
    width: 100%;
    padding: 12px;
    background: linear-gradient(135deg, #66bb6a, #43a047);
    border: none;
    border-radius: 12px;
    color: #fff;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    margin-bottom: 8px;
    box-shadow: 0 3px 8px rgba(67,160,71,0.3);
    transition: transform 0.1s;
}

.btn-primary:active { transform: scale(0.97); }

.btn-secondary {
    width: 100%;
    padding: 10px;
    background: transparent;
    border: 2px solid #c8e6c9;
    border-radius: 12px;
    color: var(--text);
    font-size: 14px;
    cursor: pointer;
    transition: transform 0.1s;
}

.btn-secondary:active { transform: scale(0.97); }

/* ─── Leaderboard ─── */

#lb-content {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    -webkit-overflow-scrolling: touch;
}

.lb-table {
    width: 100%;
    text-align: left;
    font-size: 13px;
    margin: 8px 0;
}

.lb-table th {
    color: var(--dim);
    font-weight: 600;
    padding: 4px 8px;
    border-bottom: 2px solid #e8f5e9;
}

.lb-table td {
    padding: 5px 8px;
}

.lb-table tr.rank-gold td {
    font-weight: 700;
    background: linear-gradient(90deg, #ffb300, #ffd54f, #ffb300);
    background-size: 200% 100%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: shimmer 2.5s ease-in-out infinite;
}

.lb-table tr.rank-silver td {
    font-weight: 700;
    background: linear-gradient(90deg, #90a4ae, #e0e0e0, #90a4ae);
    background-size: 200% 100%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: shimmer 2.5s ease-in-out infinite;
    animation-delay: 0.3s;
}

.lb-table tr.rank-bronze td {
    font-weight: 700;
    background: linear-gradient(90deg, #a1887f, #d7ccc8, #a1887f);
    background-size: 200% 100%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: shimmer 2.5s ease-in-out infinite;
    animation-delay: 0.6s;
}

@keyframes shimmer {
    0% { background-position: -100% 0; }
    50% { background-position: 100% 0; }
    100% { background-position: -100% 0; }
}

.lb-tabs {
    display: flex;
    gap: 6px;
    margin-bottom: 12px;
    justify-content: center;
}

.lb-tab {
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    border: 2px solid #c8e6c9;
    background: transparent;
    color: var(--dim);
    transition: transform 0.1s;
}

.lb-tab:active { transform: scale(0.95); }

.lb-tab.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

/* ─── Result Screen ─── */

.result-icon { font-size: 48px; margin-bottom: 8px; }
.result-stats { font-size: 13px; color: var(--dim); line-height: 1.8; margin-bottom: 12px; }
.result-stats strong { color: var(--gold); }

.prize-code {
    display: block;
    background: #f5f8f0;
    padding: 10px 14px;
    border-radius: 10px;
    font-family: monospace;
    font-size: 13px;
    color: var(--gold);
    letter-spacing: 1px;
    margin: 8px auto;
    border: 2px dashed var(--accent);
    cursor: pointer;
    word-break: break-all;
    max-width: 100%;
    line-height: 1.5;
}

.copy-toast {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0,0,0,0.75);
    color: #fff;
    padding: 12px 24px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 600;
    z-index: 9999;
    pointer-events: none;
    animation: toastFade 1.5s ease forwards;
}

@keyframes toastFade {
    0%, 60% { opacity: 1; }
    100% { opacity: 0; }
}

/* ─── Difficulty Warning Overlay ─── */
.warn-overlay {
    position: fixed; inset: 0; z-index: 10000;
    background: rgba(0,0,0,0.92);
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    opacity: 0; animation: warnFadeIn .4s ease forwards;
}
@keyframes warnFadeIn { to { opacity: 1; } }
.warn-tape {
    width: 120%; height: 38px; position: absolute;
    background: repeating-linear-gradient(
        -45deg, #000 0px, #000 18px, #e5c100 18px, #e5c100 36px
    );
    opacity: .85;
}
.warn-tape.top { top: 18%; transform: rotate(-2deg); }
.warn-tape.bot { bottom: 18%; transform: rotate(2deg); }
.warn-sign {
    position: relative; width: 0; height: 0;
    border-left: 70px solid transparent;
    border-right: 70px solid transparent;
    border-bottom: 122px solid #d32f2f;
    filter: drop-shadow(0 0 40px rgba(211,47,47,.6));
    animation: warnPulse 1.2s ease-in-out infinite alternate;
}
.warn-sign::after {
    content: '!'; position: absolute;
    top: 34px; left: 50%; transform: translateX(-50%);
    font-size: 56px; font-weight: 900; color: #fff;
    text-shadow: 0 2px 6px rgba(0,0,0,.4);
}
@keyframes warnPulse {
    0% { filter: drop-shadow(0 0 20px rgba(211,47,47,.4)); }
    100% { filter: drop-shadow(0 0 50px rgba(211,47,47,.8)); }
}
.warn-text {
    margin-top: 28px; text-align: center; color: #fff;
}
.warn-text .diff-label {
    font-size: 28px; font-weight: 800; letter-spacing: 2px;
    background: linear-gradient(90deg, #ff4444, #ff8800, #ff4444);
    background-size: 200% 100%;
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: warnTextShift 2s linear infinite;
}
@keyframes warnTextShift { to { background-position: 200% 0; } }
.warn-text .sub {
    margin-top: 8px; font-size: 13px; color: #999; letter-spacing: 1px;
}
.warn-dismiss {
    margin-top: 30px; background: transparent; border: 2px solid #d32f2f; color: #d32f2f;
    padding: 10px 32px; border-radius: 8px; font-size: 15px; font-weight: 700;
    cursor: pointer; letter-spacing: 2px; transition: all .2s;
}
.warn-dismiss:hover, .warn-dismiss:active {
    background: #d32f2f; color: #fff;
}

/* ─── Horror Mode (炼狱/地狱) ─── */
.horror-purgatory .board-container {
    filter: saturate(0.7) contrast(1.1);
}
.horror-hell .board-container {
    filter: saturate(0.4) contrast(1.3) sepia(0.15);
}
.horror-hell .board-container::after {
    content: '';
    position: absolute; inset: 0;
    background: radial-gradient(ellipse at center, transparent 50%, rgba(80,0,0,0.25) 100%);
    pointer-events: none; z-index: 100;
}
.creepy-tile {
    font-family: var(--emoji-font);
    font-weight: 800;
    filter: saturate(0.95);
}
.horror-hell .tile {
    text-shadow: 0 0 6px rgba(200,0,0,0.5);
}

.glitch-scanlines {
    display: none;
}
.glitch-scanlines.active {
    opacity: 0;
}
.glitching {
    animation: none !important;
    transform: none !important;
    filter: none !important;
}

/* ─── Power-up needs-earn state ─── */

.power-btn.needs-earn {
    background: linear-gradient(180deg, #78909c, #607d8b);
    box-shadow: 0 3px 8px rgba(96,125,139,0.35);
    position: relative;
}

.power-btn.needs-earn .count {
    background: #ff9800;
    color: #fff;
    border-radius: 10px;
    padding: 0 6px;
    font-size: 10px;
    font-weight: 800;
    min-width: 18px;
    line-height: 16px;
    animation: earnPulse 1.5s ease-in-out infinite;
}

@keyframes earnPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.15); }
}

.power-btn:not(.needs-earn) {
    background: linear-gradient(180deg, #52b5ff, #2196f3);
    box-shadow: 0 3px 8px rgba(33,150,243,0.35);
}

/* ─── Earn Modal ─── */

.earn-box {
    max-width: 340px;
}

.earn-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.earn-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border: 2px solid #e0e0e0;
    border-radius: 14px;
    background: #fafafa;
    cursor: pointer;
    text-align: left;
    transition: all 0.15s;
}

.earn-btn:active {
    transform: scale(0.97);
}

.earn-btn.earn-ad {
    border-color: #ffe0b2;
    background: linear-gradient(135deg, #fff8e1, #fff3e0);
}

.earn-btn.earn-ad:hover {
    border-color: #ffb74d;
    box-shadow: 0 2px 12px rgba(255,152,0,0.15);
}

.earn-btn.earn-share {
    border-color: #c8e6c9;
    background: linear-gradient(135deg, #f1f8e9, #e8f5e9);
}

.earn-btn.earn-share:hover {
    border-color: #66bb6a;
    box-shadow: 0 2px 12px rgba(76,175,80,0.15);
}

.earn-btn .earn-icon {
    font-size: 28px;
    flex-shrink: 0;
}

.earn-btn .earn-label {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
    display: block;
}

.earn-btn .earn-sub {
    font-size: 11px;
    color: var(--dim);
    display: block;
    margin-top: 2px;
}

.earn-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    filter: grayscale(0.6);
}

/* ─── Ad Overlay (fullscreen promo) ─── */

.ad-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 10001;
    background: linear-gradient(135deg, #1a237e 0%, #283593 30%, #3949ab 60%, #1a237e 100%);
    flex-direction: column;
    align-items: center;
    justify-content: center;
    animation: adFadeIn 0.3s ease;
}

.ad-overlay.show {
    display: flex;
}

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

.ad-countdown {
    position: absolute;
    top: 16px;
    right: 16px;
    background: rgba(255,255,255,0.15);
    color: rgba(255,255,255,0.9);
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    border: 2px solid rgba(255,255,255,0.3);
}

.ad-content {
    text-align: center;
    color: #fff;
    padding: 20px;
    max-width: 360px;
}

.ad-logo {
    font-size: 36px;
    font-weight: 900;
    margin-bottom: 8px;
    background: linear-gradient(90deg, #ffd54f, #ffb300, #ffd54f);
    background-size: 200% 100%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: shimmer 3s ease-in-out infinite;
}

.ad-slogan {
    font-size: 16px;
    color: rgba(255,255,255,0.85);
    margin-bottom: 28px;
    font-weight: 500;
}

.ad-features {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 28px;
}

.ad-feat {
    font-size: 15px;
    color: rgba(255,255,255,0.9);
    padding: 10px 18px;
    background: rgba(255,255,255,0.08);
    border-radius: 12px;
    border: 1px solid rgba(255,255,255,0.1);
    font-weight: 500;
}

.ad-cta {
    margin-bottom: 20px;
}

.ad-cta span {
    display: inline-block;
    padding: 12px 28px;
    background: linear-gradient(135deg, #ffd54f, #ffb300);
    color: #1a237e;
    font-size: 16px;
    font-weight: 800;
    border-radius: 30px;
    box-shadow: 0 4px 16px rgba(255,179,0,0.4);
    letter-spacing: 1px;
}

.ad-tip {
    font-size: 12px;
    color: rgba(255,255,255,0.5);
}

.ad-close-btn {
    position: absolute;
    bottom: 40px;
    background: rgba(255,255,255,0.2);
    border: 2px solid rgba(255,255,255,0.4);
    color: #fff;
    padding: 12px 32px;
    border-radius: 30px;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    animation: adBtnFade 0.4s ease;
}

@keyframes adBtnFade {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.ad-close-btn:hover, .ad-close-btn:active {
    background: rgba(255,255,255,0.35);
}

/* ─── Revive Modal ─── */

.revive-box {
    max-width: 340px;
    border: 3px solid #ff9800;
    box-shadow: 0 16px 48px rgba(255,152,0,0.25);
}

.revive-icon {
    font-size: 48px;
    animation: revivePulse 1s ease-in-out infinite;
    margin-bottom: 4px;
}

@keyframes revivePulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.2); }
}

/* ─── Responsive (mobile fullscreen) ─── */

@media (max-width: 768px) {
    body { height: 100vh; height: 100dvh; }
    .game-header {
        max-width: 100%;
        border-radius: 0;
        padding: 8px 12px;
        padding-right: 46px;
    }
    .game-title { font-size: 16px; }
    .timer, .header-btn { font-size: 12px; }
    .board-container { max-width: 100%; margin: 2px auto; }
    .slot-area { max-width: 100%; padding: 4px 10px; }
    .slot-bar { min-height: 44px; padding: 4px; }
    .slot-cell { width: 36px; height: 36px; font-size: 18px; }
    .park-cell { width: 32px; height: 32px; font-size: 17px; }
    .powerups { max-width: 100%; padding: 4px 10px 8px; gap: 8px; }
    .power-btn { padding: 6px 10px; min-width: 56px; font-size: 11px; border-radius: 10px; }
    .power-btn .icon { font-size: 16px; }
    .power-btn .count { font-size: 9px; }
    .ad-logo { font-size: 28px; }
    .ad-slogan { font-size: 14px; margin-bottom: 20px; }
    .ad-feat { font-size: 13px; padding: 8px 14px; }
    .ad-features { gap: 8px; margin-bottom: 20px; }
    .ad-close-btn { bottom: 24px; font-size: 14px; padding: 10px 24px; }
    .earn-btn { padding: 12px 14px; gap: 10px; }
    .earn-btn .earn-icon { font-size: 24px; }
    .earn-btn .earn-label { font-size: 14px; }
    .modal-box { padding: 20px 18px; max-height: 90vh; max-height: 90dvh; }
    .modal-box h2 { font-size: 20px; margin-bottom: 8px; }
    .modal-box p { margin-bottom: 10px; }
    .result-icon { font-size: 40px; margin-bottom: 4px; }
    .result-stats { margin-bottom: 8px; }
    .free-diff-btn { padding: 5px 10px; font-size: 12px; }
}
