/* ─── Design tokens ─────────────────────────────────────────────── */
:root {
    --ts-primary:     #6366f1;
    --ts-accent:      #a78bfa;
    --ts-gold:        #fbbf24;
    --ts-perfect:     #34d399;
    --ts-bg:          #080c14;
    --ts-card:        #111827;
    --ts-card-border: rgba(255,255,255,0.08);
    --ts-text:        #eef3ff;
    --ts-muted:       #6b7fa3;
    --ts-shadow:      rgba(0,0,0,0.6);
}

/* ─── Reset ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

body, html {
    margin: 0;
    padding: 0;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    background: var(--ts-bg);
    font-family: 'Outfit', sans-serif;
    color: var(--ts-text);
}

#gameUI {
    position: relative;
    width: 100%;
    height: 100%;
}

#canvasContainer {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

/* ─── HUD ───────────────────────────────────────────────────────── */
.hud-header {
    position: absolute;
    top: 72px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 0;
    z-index: 10;
    pointer-events: none;
    background: rgba(8, 12, 20, 0.6);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border: 1px solid var(--ts-card-border);
    border-radius: 20px;
    padding: 10px 20px;
}

.hud-score {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0 18px;
}

.hud-score + .hud-score {
    border-left: 1px solid rgba(255,255,255,0.07);
}

.hud-score--center {
    padding: 0 24px;
}

.hud-label {
    font-size: 0.62rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--ts-muted);
    margin-bottom: 2px;
}

.hud-value {
    font-size: 1.6rem;
    font-weight: 800;
    color: #fff;
    line-height: 1;
    transition: transform 0.1s;
}

.hud-value--main {
    font-size: 2.1rem;
    text-shadow: 0 0 24px rgba(99,102,241,0.6);
}

.hud-level {
    color: var(--ts-accent);
    text-shadow: 0 0 16px rgba(167,139,250,0.5);
}

@keyframes scorePop {
    0%   { transform: scale(1); }
    40%  { transform: scale(1.4); }
    100% { transform: scale(1); }
}

.score-pop { animation: scorePop 0.22s ease-out forwards; }

/* ─── Combo display ─────────────────────────────────────────────── */
.combo-display {
    position: absolute;
    top: 148px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    pointer-events: none;
    background: linear-gradient(135deg, rgba(99,102,241,0.18), rgba(167,139,250,0.18));
    border: 1px solid rgba(167,139,250,0.3);
    border-radius: 40px;
    padding: 4px 18px;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: var(--ts-accent);
}

.combo-display.hidden { display: none; }

/* ─── Floating text ─────────────────────────────────────────────── */
@keyframes floatUp {
    0%   { opacity: 1;   transform: translateX(-50%) translateY(0)    scale(1);    }
    20%  { opacity: 1;   transform: translateX(-50%) translateY(-10px) scale(1.12); }
    100% { opacity: 0;   transform: translateX(-50%) translateY(-70px) scale(0.88); }
}

.floating-text {
    position: absolute;
    left: 50%;
    top: 40%;
    transform: translateX(-50%);
    pointer-events: none;
    font-weight: 800;
    font-size: 1.4rem;
    letter-spacing: 2px;
    text-transform: uppercase;
    animation: floatUp 1.1s ease-out forwards;
    z-index: 20;
    white-space: nowrap;
    text-shadow: 0 2px 12px rgba(0,0,0,0.7);
}

.floating-text--perfect {
    color: var(--ts-perfect);
    font-size: 1.8rem;
    text-shadow: 0 0 24px rgba(52,211,153,0.7), 0 2px 10px rgba(0,0,0,0.6);
}

.floating-text--combo {
    color: var(--ts-gold);
    font-size: 1.2rem;
    text-shadow: 0 0 18px rgba(251,191,36,0.6), 0 2px 8px rgba(0,0,0,0.5);
}

/* ─── Modal overlay ─────────────────────────────────────────────── */
@keyframes overlayFadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-overlay {
    position: absolute;
    inset: 0;
    z-index: 100;
    background: rgba(5, 8, 16, 0.88);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: overlayFadeIn 0.3s ease;
}

.modal-overlay.hidden { display: none !important; }

/* ─── Modal card ─────────────────────────────────────────────────── */
@keyframes cardSlideIn {
    from { opacity: 0; transform: translateY(28px) scale(0.93); }
    to   { opacity: 1; transform: translateY(0)    scale(1); }
}

.modal-card {
    background: var(--ts-card);
    padding: 36px 30px 28px;
    border-radius: 28px;
    width: 90%;
    max-width: 380px;
    text-align: center;
    border: 1px solid var(--ts-card-border);
    box-shadow: 0 28px 64px rgba(0,0,0,0.8), 0 0 0 1px rgba(255,255,255,0.025);
    animation: cardSlideIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-icon {
    font-size: 2.8rem;
    margin-bottom: 8px;
    line-height: 1;
}

.modal-card h2 {
    margin: 0 0 6px;
    font-size: 2rem;
    font-weight: 800;
    background: linear-gradient(135deg, #fff 20%, var(--ts-accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.modal-subtitle {
    color: var(--ts-muted);
    margin: 0 0 22px;
    font-size: 0.88rem;
}

/* ─── Input ─────────────────────────────────────────────────────── */
.input-group {
    margin: 0 0 20px;
    text-align: left;
}

.input-group label {
    display: block;
    margin-bottom: 8px;
    color: var(--ts-muted);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.input-group input {
    width: 100%;
    padding: 13px 16px;
    background: rgba(255,255,255,0.035);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 14px;
    color: #fff;
    font-size: 1rem;
    outline: none;
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.input-group input:focus {
    border-color: var(--ts-primary);
    box-shadow: 0 0 0 3px rgba(99,102,241,0.2);
}

.input-group input::placeholder { color: #2d3e54; }

/* ─── Buttons ───────────────────────────────────────────────────── */
.btn-primary {
    width: 100%;
    padding: 15px;
    background: linear-gradient(135deg, var(--ts-primary), var(--ts-accent));
    border: none;
    border-radius: 16px;
    color: #fff;
    font-weight: 700;
    font-size: 1.05rem;
    cursor: pointer;
    font-family: inherit;
    box-shadow: 0 8px 24px rgba(99,102,241,0.4);
    transition: transform 0.15s, box-shadow 0.15s;
    letter-spacing: 0.5px;
}

.btn-primary:hover  { transform: translateY(-2px); box-shadow: 0 14px 32px rgba(99,102,241,0.5); }
.btn-primary:active { transform: scale(0.97); box-shadow: 0 4px 14px rgba(99,102,241,0.35); }

.btn-secondary {
    width: 100%;
    padding: 13px;
    background: transparent;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 16px;
    color: var(--ts-muted);
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.btn-secondary:hover  { background: rgba(255,255,255,0.06); border-color: rgba(255,255,255,0.2); color: #fff; }
.btn-secondary:active { transform: scale(0.97); }

/* ─── Game-over stats ───────────────────────────────────────────── */
.final-score {
    font-size: 4.5rem;
    font-weight: 800;
    margin: 6px 0 4px;
    color: #fff;
    line-height: 1;
    text-shadow: 0 0 32px rgba(99,102,241,0.5);
}

@keyframes newBestPulse {
    0%, 100% { opacity: 1;   transform: scale(1); }
    50%       { opacity: 0.8; transform: scale(1.08); }
}

.new-best {
    color: var(--ts-gold);
    font-size: 0.9rem;
    font-weight: 700;
    margin: 0 0 12px;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    animation: newBestPulse 1.1s ease-in-out infinite;
}

.new-best.hidden { display: none; }

.game-stats {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin: 14px 0 20px;
}

.stat-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.07);
    border-radius: 14px;
    padding: 10px 6px;
}

.stat-label {
    font-size: 0.58rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--ts-muted);
    margin-bottom: 4px;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 800;
    color: #fff;
}

.modal-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* ─── Space-key hint ─────────────────────────────────────────────── */
.hint-text {
    margin: 14px 0 0;
    font-size: 0.72rem;
    color: #2d3e54;
}

kbd {
    display: inline-block;
    padding: 1px 7px;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 5px;
    font-family: inherit;
    font-size: 0.68rem;
    color: var(--ts-muted);
}

/* ─── Bottom ad ─────────────────────────────────────────────────── */
.game-bottom-ad {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 15;
    display: flex;
    justify-content: center;
    align-items: flex-end;
    padding: 8px;
    min-height: 60px;
    max-height: 100px;
    pointer-events: none;
    background: linear-gradient(to top, rgba(0,0,0,0.7) 0%, transparent 100%);
    box-sizing: border-box;
    overflow: hidden;
}

.game-bottom-ad ins,
.game-bottom-ad .game-ad-slot {
    pointer-events: auto;
    width: min(100%, 728px);
    max-width: 728px;
    max-height: 90px;
    overflow: hidden;
}

/* ─── Responsive ────────────────────────────────────────────────── */
@media (max-width: 600px) {
    .hud-header    { top: 58px; padding: 8px 12px; border-radius: 16px; }
    .hud-score     { padding: 0 10px; }
    .hud-value     { font-size: 1.3rem; }
    .hud-value--main { font-size: 1.65rem; }
    .combo-display { top: 122px; font-size: 0.66rem; }
    .modal-card    { padding: 26px 18px 22px; }
    .final-score   { font-size: 3.2rem; }
    .floating-text { font-size: 1.15rem; }
    .floating-text--perfect { font-size: 1.45rem; }
}