:root {
    --cream: #fff2d6;
    --cream2: #ffe2ac;
    --brick: #a6412a;
    --brick-dark: #7c2c1a;
    --brick-light: #c85a3a;
    --ink: #4a2712;
    --accent: #ffb238;
    --accent2: #ff7a3c;
    --good: #3ddc84;
    --danger: #ff4d4d;
    --panel: #fff6e4;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}
html,
body {
    margin: 0;
    padding: 0;
    height: 100%;
    overscroll-behavior: none;
    font-family: 'Fredoka One', 'Baloo 2', 'Comic Sans MS', 'Segoe UI', system-ui, sans-serif;
    color: var(--ink);
    overflow-x: hidden;
    -webkit-user-select: none;
    user-select: none;
}

#gameWrap {
    position: fixed;
    inset: 0;

    display: flex;
    align-items: center;
    justify-content: center;

    background-image: url('./bg.png');
    background-size: cover;
    background-position: center center;
    background-repeat: no-repeat;

    /* Optional dark overlay */
    background-color: #5a3018;
}

#gameCanvas {
    display: block;
    touch-action: none;
    box-shadow: 0 0 0 6px #2c1608, 0 20px 60px rgba(0, 0, 0, .6);
    border-radius: 10px;
}

/* ---------- overlays ---------- */
.overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 20;
    opacity: 1;
    transition: opacity .35s ease, visibility .35s ease;
    pointer-events: auto;
}

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

.card {
    background: linear-gradient(180deg, var(--panel), var(--cream2));
    border: 5px solid var(--brick);
    border-radius: 26px;
    box-shadow: 0 12px 0 var(--brick-dark), 0 20px 40px rgba(0, 0, 0, .45), inset 0 2px 0 rgba(255, 255, 255, .6);
    padding: 26px 24px 22px;
    width: min(88vw, 380px);
    max-height: 88vh;
    overflow-y: auto;
    text-align: center;
    color: var(--ink);
    position: relative;
    animation: popIn .45s cubic-bezier(.2, 1.4, .4, 1);
}

@keyframes popIn {
    0% {
        transform: scale(.6) translateY(20px);
        opacity: 0;
    }

    100% {
        transform: scale(1) translateY(0);
        opacity: 1;
    }
}

h1.title {
    font-size: clamp(30px, 8vw, 42px);
    margin: 0 0 4px;
    color: var(--accent2);
    -webkit-text-stroke: 3px var(--ink);
    text-shadow: 0 5px 0 var(--brick-dark);
    letter-spacing: 1px;
    transform: rotate(-2deg);
    width: 95%;
}

.subtitle {
    font-size: 14px;
    color: var(--brick-dark);
    margin-bottom: 10px;
    font-weight: bold;
    opacity: .85;
}

.blockIcon {
    width: 196px;
    height: 196px;
    margin: 6px auto 10px;
    animation: floaty 1.6s ease-in-out infinite;border-radius: 30px;
}

@keyframes floaty {

    0%,
    100% {
        transform: translateY(0) rotate(-3deg);
    }

    50% {
        transform: translateY(-10px) rotate(3deg);
    }
}

.btn {
    display: block;
    width: 100%;
    margin: 10px auto 0;
    padding: 14px 10px;
    font-family: inherit;
    font-size: 19px;
    font-weight: bold;
    color: #fff;
    background: linear-gradient(180deg, var(--accent), var(--accent2));
    border: none;
    border-radius: 30px;
    cursor: pointer;
    box-shadow: 0 6px 0 #b8501f, inset 0 2px 0 rgba(255, 255, 255, .5);
    text-shadow: 0 2px 2px rgba(0, 0, 0, .25);
    transition: transform .08s ease, box-shadow .08s ease;
    letter-spacing: .5px;
    margin-top: 15px;
}

.btn:active {
    transform: translateY(5px);
    box-shadow: 0 1px 0 #b8501f;
}

.btn.secondary {
    background: linear-gradient(180deg, #fff, #ffe6b8);
    color: var(--brick-dark);
    box-shadow: 0 6px 0 #c99a55, inset 0 2px 0 rgba(255, 255, 255, .8);
    text-shadow: none;
}

.btn.secondary:active {
    box-shadow: 0 1px 0 #c99a55;
}

.btn.small {
    padding: 10px;
    font-size: 15px;
}

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

.row2 .btn {
    margin-top: 10px;
}

.scoreLine {
    display: flex;
    justify-content: center;
    gap: 22px;
    margin: 8px 0 4px;
    font-size: 15px;
    font-weight: bold;
    color: var(--brick-dark);
}

.scoreLine b {
    display: block;
    font-size: 26px;
    color: var(--accent2);
    -webkit-text-stroke: 1.4px var(--ink);
}

.iconTopRight {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, .7);
    border: 3px solid var(--brick);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 18px;
    color: var(--brick-dark);
}

.htpList {
    text-align: left;
    font-size: 14.5px;
    line-height: 1.55;
    color: var(--ink);
    margin: 10px 0 4px;
}

.htpList div {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 10px;
}

.htpList .emo {
    font-size: 22px;
    width: 30px;
    text-align: center;
    flex-shrink: 0;
}

/* ---------- HUD ---------- */
#hud {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 10;
}

#scoreDisplay {
    position: absolute;
    top: 14px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 44px;
    font-weight: bold;
    color: #fff;
    -webkit-text-stroke: 3px var(--ink);
    text-shadow: 0 4px 0 var(--brick-dark);
}

#livesDisplay {
    position: absolute;
    top: 62px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 5px;
}

#livesDisplay .heart {
    font-size: 20px;
    filter: drop-shadow(0 2px 0 var(--brick-dark));
    transition: transform .25s ease, opacity .25s ease;
}

#livesDisplay .heart.lost {
    opacity: .28;
    transform: scale(.8);
    filter: grayscale(1);
}

#bestBadge {
    position: absolute;
    top: 20px;
    right: 16px;
    pointer-events: auto;
    cursor: pointer;
    background: rgba(255, 255, 255, .85);
    border: 3px solid var(--brick);
    border-radius: 12px;
    padding: 5px 10px;
    font-size: 16px;
    font-weight: bold;
    color: var(--brick-dark);
}

#pauseBtn {
    position: absolute;
    top: 16px;
    left: 16px;
    pointer-events: auto;
    cursor: pointer;

    width: 46px;
    height: 46px;
    border-radius: 20%;

    padding-left: 7px;
    padding-top: 5px;

    /* Glass effect */
    background: linear-gradient(145deg,
            rgba(255, 255, 255, 0.95),
            rgba(255, 255, 255, 0.72));

    border: 3px solid var(--brick);

    display: flex;
    align-items: center;
    justify-content: center;

    font-size: 19px;
    font-weight: 700;
    color: var(--brick-dark);

    /* 3D depth */
    box-shadow:
        0 4px 0 var(--brick-dark),
        0 8px 18px rgba(0, 0, 0, 0.22),
        inset 0 2px 4px rgba(255, 255, 255, 0.9);

    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);

    transition:
        transform 0.18s ease,
        box-shadow 0.18s ease,
        background 0.18s ease;
}

/* Hover */
#pauseBtn:hover {
    transform: translateY(-2px) scale(1.06);

    background: linear-gradient(145deg,
            #ffffff,
            #f5e8df);

    box-shadow:
        0 6px 0 var(--brick-dark),
        0 12px 24px rgba(0, 0, 0, 0.25),
        inset 0 2px 5px rgba(255, 255, 255, 1);
}

/* Click */
#pauseBtn:active {
    transform: translateY(3px) scale(0.96);

    box-shadow:
        0 2px 0 var(--brick-dark),
        0 5px 12px rgba(0, 0, 0, 0.2),
        inset 0 2px 4px rgba(0, 0, 0, 0.08);
}

/* Keyboard focus */
#pauseBtn:focus-visible {
    outline: 3px solid rgba(255, 255, 255, 0.9);
    outline-offset: 3px;
}

#comboPop {
    position: absolute;
    left: 50%;
    top: 40%;
    transform: translate(-50%, -50%);
    font-size: 22px;
    font-weight: bold;
    color: var(--good);
    -webkit-text-stroke: 2px var(--ink);
    opacity: 0;
    pointer-events: none;
}

#preload {
    position: absolute;
    inset: 0;
    z-index: 30;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: linear-gradient(180deg, #ffcf7a, #ff9a4d);
}

#preload .blockIcon {
    width: 110px;
    height: 110px;
}

#barTrack {
    width: 200px;
    height: 16px;
    border-radius: 10px;
    background: rgba(0, 0, 0, .25);
    border: 3px solid var(--ink);
    overflow: hidden;
    margin-top: 14px;
}

#barFill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--accent), var(--accent2));
    transition: width .15s ease;
}

#preloadText {
    margin-top: 10px;
    color: var(--ink);
    font-weight: bold;
    font-size: 14px;
    letter-spacing: 1px;
}

.muteToggle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 12px;
    font-size: 13px;
    color: var(--brick-dark);
    font-weight: bold;
    cursor: pointer;
}

.muteToggle .dot {
    width: 34px;
    height: 20px;
    border-radius: 20px;
    background: #ccb188;
    position: relative;
    transition: .2s;
    border: 2px solid var(--brick-dark);
}

.muteToggle .dot::after {
    content: '';
    position: absolute;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #fff;
    top: 1px;
    left: 1px;
    transition: .2s;
}

.muteToggle.on .dot {
    background: var(--good);
}

.muteToggle.on .dot::after {
    left: 16px;
}

#brandTag {
    position: absolute;
    bottom: 6px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 10px;
    letter-spacing: 2px;
    color: rgba(255, 255, 255, .5);
    z-index: 5;
    pointer-events: none;
}