@font-face {
    font-family: 'BlurLight';
    src: url(../fonts/blurlight.ttf);
}

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

html, body {
    background: #0d0d0d;
    color: #c0c0c0;
    font-family: 'BlurLight', monospace;
}

body {
    padding: env(safe-area-inset-top) 20px env(safe-area-inset-bottom);
    overflow-y: auto;
}

.page {
    max-width: 420px;
    margin: 0 auto;
    padding: 40px 0 64px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

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

.top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    animation: fadeUp 0.4s ease both;
}

.back {
    font-size: 12px;
    color: #c0c0c0;
    text-decoration: none;
    opacity: 0.3;
    letter-spacing: 2px;
    transition: opacity 0.2s;
}
.back:hover { opacity: 0.8; }

.scores {
    display: flex;
    align-items: center;
    gap: 16px;
}

.score-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    min-width: 48px;
}

.score-label {
    font-size: 10px;
    opacity: 0.35;
    letter-spacing: 2px;
}

.score-val {
    font-size: 20px;
    letter-spacing: 1px;
}

.new-btn {
    background: transparent;
    border: 1px solid rgba(200,200,200,0.25);
    color: #c0c0c0;
    font-family: 'BlurLight', monospace;
    font-size: 12px;
    letter-spacing: 2px;
    padding: 5px 12px;
    cursor: pointer;
    transition: border-color 0.2s, opacity 0.2s;
    opacity: 0.55;
}
.new-btn:hover { border-color: rgba(200,200,200,0.7); opacity: 1; }

.board-wrap {
    position: relative;
    animation: fadeUp 0.5s ease 0.05s both;
}

.board {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    background: rgba(200,200,200,0.07);
    padding: 8px;
    border-radius: 4px;
    touch-action: none;
    user-select: none;
}

.cell {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 3px;
    background: rgba(200,200,200,0.06);
    font-size: clamp(18px, 5vw, 28px);
    letter-spacing: 0;
    font-weight: normal;
    transition: background 0.1s;
}

.cell[data-val="2"]    { background: rgba(200,200,200,0.10); color: #c0c0c0; }
.cell[data-val="4"]    { background: rgba(200,200,200,0.18); color: #c0c0c0; }
.cell[data-val="8"]    { background: rgba(200,200,200,0.28); color: #e0e0e0; }
.cell[data-val="16"]   { background: rgba(200,200,200,0.38); color: #e8e8e8; }
.cell[data-val="32"]   { background: rgba(200,200,200,0.50); color: #fff; }
.cell[data-val="64"]   { background: rgba(200,200,200,0.62); color: #111; }
.cell[data-val="128"]  { background: rgba(200,200,200,0.74); color: #111; font-size: clamp(14px, 4vw, 22px); }
.cell[data-val="256"]  { background: rgba(200,200,200,0.84); color: #0d0d0d; font-size: clamp(14px, 4vw, 22px); }
.cell[data-val="512"]  { background: rgba(220,220,220,0.92); color: #0d0d0d; font-size: clamp(14px, 4vw, 22px); }
.cell[data-val="1024"] { background: rgba(240,240,240,0.96); color: #0d0d0d; font-size: clamp(12px, 3.5vw, 18px); }
.cell[data-val="2048"] { background: rgba(220,180,50,0.92);  color: #0d0d0d; font-size: clamp(12px, 3.5vw, 18px); }

@keyframes pop {
    0%   { transform: scale(0); }
    60%  { transform: scale(1.1); }
    100% { transform: scale(1); }
}
.cell.new { animation: pop 0.15s ease both; }

/* overlay */
.overlay {
    position: absolute;
    inset: 0;
    background: rgba(13,13,13,0.92);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    animation: fadeUp 0.3s ease both;
}

.overlay-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    padding: 24px;
    width: 100%;
}

.over-title {
    font-size: 22px;
    letter-spacing: 3px;
    opacity: 0.9;
}

.over-score {
    font-size: 32px;
    letter-spacing: 2px;
}

.over-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
    max-width: 220px;
}

.nick-input {
    background: transparent;
    border: none;
    border-bottom: 1px solid rgba(200,200,200,0.3);
    color: #c0c0c0;
    font-family: 'BlurLight', monospace;
    font-size: 16px;
    letter-spacing: 2px;
    padding: 6px 0;
    outline: none;
    text-align: center;
    transition: border-color 0.2s;
}
.nick-input:focus { border-color: rgba(200,200,200,0.7); }
.nick-input::placeholder { opacity: 0.3; }

.over-btn {
    background: transparent;
    border: 1px solid rgba(200,200,200,0.3);
    color: #c0c0c0;
    font-family: 'BlurLight', monospace;
    font-size: 13px;
    letter-spacing: 2px;
    padding: 7px 0;
    width: 100%;
    max-width: 220px;
    cursor: pointer;
    transition: border-color 0.2s, opacity 0.2s;
    opacity: 0.7;
}
.over-btn:hover { border-color: rgba(200,200,200,0.8); opacity: 1; }
.over-btn.secondary { opacity: 0.35; margin-top: 4px; }
.over-btn.secondary:hover { opacity: 0.7; }

.over-saved {
    font-size: 13px;
    opacity: 0.5;
    letter-spacing: 2px;
}

.hint {
    font-size: 11px;
    opacity: 0.2;
    letter-spacing: 2px;
    text-align: center;
    animation: fadeUp 0.5s ease 0.1s both;
}

.plays-count {
    font-size: 11px;
    opacity: 0.22;
    letter-spacing: 2px;
    text-align: center;
    animation: fadeUp 0.5s ease 0.12s both;
}

/* leaderboard */
.leaderboard {
    display: flex;
    flex-direction: column;
    gap: 14px;
    animation: fadeUp 0.5s ease 0.15s both;
}

.lb-title {
    font-size: 13px;
    opacity: 0.35;
    letter-spacing: 3px;
}

.lb-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.lb-loading, .lb-empty {
    font-size: 13px;
    opacity: 0.25;
    letter-spacing: 1px;
}

.lb-item {
    display: flex;
    align-items: baseline;
    gap: 10px;
    font-size: 15px;
    letter-spacing: 0.5px;
    animation: fadeUp 0.3s ease both;
}

.lb-rank {
    font-size: 11px;
    opacity: 0.25;
    letter-spacing: 1px;
    width: 20px;
    flex-shrink: 0;
}

.lb-nick {
    flex: 1;
    opacity: 0.8;
}

.lb-score {
    font-size: 14px;
    opacity: 0.55;
    letter-spacing: 1px;
}
