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

:root {
    --bg: #1a2e1a;
    --card: #2a4a2a;
    --accent: #c8a96e;
    --gold: #ffd700;
    --text: #e8e0d0;
    --dim: #8a8070;
    --danger: #cc4444;
    --success: #44aa44;
    --slot-bg: #1e3a1e;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
    min-height: 100vh;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* ─── Header ─── */

.game-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    max-width: 500px;
    padding: 12px 16px;
}

.game-title {
    font-size: 20px;
    font-weight: 700;
    color: var(--gold);
}

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

.timer {
    font-size: 14px;
    color: var(--dim);
    font-variant-numeric: tabular-nums;
}

.header-btn {
    background: none;
    border: 1px solid var(--dim);
    color: var(--text);
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.header-btn:hover {
    border-color: var(--gold);
    color: var(--gold);
}

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

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

.diff-1 { background: #2a5a2a; color: #88dd88; }
.diff-2 { background: #5a4a1a; color: #ddcc66; }
.diff-3 { background: #5a1a1a; color: #ee6666; }

/* ─── Board ─── */

.board-container {
    position: relative;
    width: 100%;
    max-width: 500px;
    aspect-ratio: 1;
    margin: 8px auto;
    touch-action: manipulation;
}

.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: var(--card);
    border: 2px solid #3a5a3a;
    border-radius: 8px;
    cursor: pointer;
    user-select: none;
    transition: transform 0.15s, opacity 0.2s, box-shadow 0.15s;
    z-index: var(--z);
}

.tile:hover:not(.blocked) {
    transform: scale(1.08);
    box-shadow: 0 0 12px rgba(200, 169, 110, 0.4);
    border-color: var(--accent);
}

.tile.blocked {
    opacity: 0.45;
    cursor: not-allowed;
    filter: brightness(0.7);
}

.tile.clicked {
    animation: tilePop 0.25s ease-out;
}

@keyframes tilePop {
    0% { transform: scale(1); }
    50% { transform: scale(0.85); }
    100% { transform: scale(0); opacity: 0; }
}

/* ─── Slot ─── */

.slot-area {
    width: 100%;
    max-width: 500px;
    padding: 12px 16px;
}

.slot-bar {
    display: flex;
    gap: 4px;
    background: var(--slot-bg);
    border: 2px solid #3a5a3a;
    border-radius: 12px;
    padding: 6px;
    min-height: 56px;
    align-items: center;
    justify-content: center;
}

.slot-cell {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    background: rgba(255,255,255,0.05);
    border-radius: 8px;
    border: 1px dashed #3a5a3a;
    transition: all 0.2s;
}

.slot-cell.filled {
    background: var(--card);
    border: 1px solid #4a6a4a;
    animation: slotIn 0.2s ease-out;
}

.slot-cell.matched {
    animation: slotMatch 0.3s ease-out;
}

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

@keyframes slotMatch {
    0% { transform: scale(1); }
    50% { transform: scale(1.3); background: var(--gold); }
    100% { transform: scale(0); opacity: 0; }
}

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

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

.power-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 8px 16px;
    background: var(--card);
    border: 1px solid #3a5a3a;
    border-radius: 10px;
    color: var(--text);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
    min-width: 70px;
}

.power-btn .icon { font-size: 20px; }
.power-btn .count { font-size: 10px; color: var(--dim); }

.power-btn:hover:not(:disabled) {
    border-color: var(--accent);
    background: #3a5a3a;
}

.power-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

/* ─── Modals ─── */

.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(4px);
}

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

.modal-box {
    background: var(--card);
    border: 1px solid #4a6a4a;
    border-radius: 16px;
    padding: 28px;
    width: 90%;
    max-width: 380px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.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: var(--bg);
    border: 1px solid #3a5a3a;
    border-radius: 8px;
    color: var(--text);
    font-size: 15px;
    outline: none;
    margin-bottom: 12px;
}

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

.btn-primary {
    width: 100%;
    padding: 10px;
    background: linear-gradient(135deg, #5a8a3a, #3a6a2a);
    border: none;
    border-radius: 10px;
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: 8px;
}

.btn-primary:hover { filter: brightness(1.15); }

.btn-secondary {
    width: 100%;
    padding: 10px;
    background: transparent;
    border: 1px solid #4a6a4a;
    border-radius: 10px;
    color: var(--text);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-secondary:hover { border-color: var(--accent); }

/* ─── Leaderboard ─── */

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

.lb-table th {
    color: var(--dim);
    font-weight: 400;
    padding: 4px 8px;
    border-bottom: 1px solid #3a5a3a;
}

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

.lb-table tr:nth-child(1) td { color: var(--gold); }
.lb-table tr:nth-child(2) td { color: #c0c0c0; }
.lb-table tr:nth-child(3) td { color: #cd7f32; }

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

.lb-tab {
    padding: 4px 16px;
    border-radius: 8px;
    font-size: 13px;
    cursor: pointer;
    border: 1px solid #3a5a3a;
    background: transparent;
    color: var(--dim);
    transition: all 0.2s;
}

.lb-tab.active {
    background: var(--accent);
    color: var(--bg);
    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: inline-block;
    background: var(--bg);
    padding: 8px 16px;
    border-radius: 8px;
    font-family: monospace;
    font-size: 16px;
    color: var(--gold);
    letter-spacing: 2px;
    margin: 8px 0;
    border: 1px dashed var(--accent);
    cursor: pointer;
}

.prize-code:hover::after {
    content: ' 📋';
}

/* ─── Responsive ─── */

@media (max-width: 400px) {
    .game-title { font-size: 17px; }
    .slot-cell { width: 38px; height: 38px; font-size: 20px; }
    .power-btn { padding: 6px 12px; min-width: 60px; }
}
