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

:root {
    /* One --u = one native game pixel. The canvas is 1920 wide at design size
       and shrinks with the viewport, so HUD chrome sized in --u scales in
       lockstep instead of staying huge on a small browser window. Each use is
       clamped: it never exceeds its original size, and never gets unreadable. */
    --u: calc(min(100vw, 160vh) / 1920);
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #1a1030;
}

body {
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: "Trebuchet MS", "Comic Sans MS", "Chalkboard SE", cursive, sans-serif;
}

canvas#game {
    /* 1920 / 1200 = 1.6 aspect ratio */
    width: min(100vw, calc(100vh * 1.6));
    height: min(100vh, calc(100vw / 1.6));
    display: block;
    touch-action: none;          /* let the canvas own all touch input */
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

/* --------------------------------- HUD --------------------------------- */

#hud {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 10;
    color: #fff;
}

.hud-top {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: clamp(5px, calc(var(--u) * 18), 18px) clamp(7px, calc(var(--u) * 26), 26px);
    gap: clamp(4px, calc(var(--u) * 12), 12px);
}

.hud-group {
    display: flex;
    gap: clamp(4px, calc(var(--u) * 12), 12px);
    align-items: center;
    flex-wrap: wrap;
}

.hud-pill {
    background: rgba(20, 16, 48, 0.55);
    border: clamp(1px, calc(var(--u) * 2), 2px) solid rgba(255, 255, 255, 0.28);
    border-radius: 999px;
    padding: clamp(3px, calc(var(--u) * 10), 10px) clamp(8px, calc(var(--u) * 22), 22px);
    font-size: clamp(11px, calc(var(--u) * 24), 24px);
    font-weight: 700;
    letter-spacing: clamp(0.5px, calc(var(--u) * 2), 2px);
    color: #fff;
    text-shadow: 0 2px 6px rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(4px);
    min-height: clamp(24px, calc(var(--u) * 56), 56px);
    display: flex;
    align-items: center;
    gap: clamp(3px, calc(var(--u) * 8), 8px);
}

#hudLives img {
    width: clamp(14px, calc(var(--u) * 38), 38px);
    height: clamp(14px, calc(var(--u) * 38), 38px);
}

#hudUpgrades:empty {
    display: none;
}

.upBadge {
    position: relative;
    display: inline-flex;
}

.upBadge img {
    width: clamp(15px, calc(var(--u) * 40), 40px);
    height: clamp(15px, calc(var(--u) * 40), 40px);
}

.upBadge b {
    position: absolute;
    right: calc(var(--u) * -8);
    bottom: calc(var(--u) * -6);
    background: #ff8a3c;
    border-radius: 999px;
    font-size: clamp(9px, calc(var(--u) * 15), 15px);
    padding: 1px clamp(4px, calc(var(--u) * 7), 7px);
    border: clamp(1px, calc(var(--u) * 2), 2px) solid #fff;
}

#btnAuto {
    pointer-events: auto;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s, border-color 0.15s;
}

#btnAuto.on {
    background: rgba(63, 158, 87, 0.75);
    border-color: #b6ffc6;
}

#btnEnd {
    background: rgba(158, 63, 63, 0.6);
    border-color: rgba(255, 182, 182, 0.6);
}

#btnEnd:active {
    transform: scale(0.96);
}

#btnAuto:active {
    transform: scale(0.96);
}

/* ------------------------------- overlay ------------------------------- */

#overlay {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(10, 8, 30, 0.55);
    backdrop-filter: blur(6px);
    cursor: pointer;
}

#overlay.hidden {
    display: none;
}

.panel {
    text-align: center;
    color: #fff;
    max-width: 900px;
    padding: 48px 60px;
    background: rgba(26, 18, 54, 0.8);
    border: 3px solid rgba(255, 255, 255, 0.25);
    border-radius: 36px;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.5);
}

.panel h1 {
    font-size: 84px;
    letter-spacing: 10px;
    margin-bottom: 18px;
    background: linear-gradient(180deg, #ffdf6b, #ff8fb2 60%, #c99df5);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    text-shadow: none;
}

.panel p {
    font-size: 26px;
    line-height: 1.5;
    margin-bottom: 16px;
}

.panel .controls {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 22px;
    opacity: 0.9;
}

.panel .controls b {
    color: #ffdf6b;
}

.panel .hint {
    margin-top: 10px;
    font-size: 24px;
    color: #9fe8b6;
    animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.55; }
    50% { opacity: 1; }
}

/* --------------------------- achievement chart --------------------------- */

#ovChart {
    max-width: 560px;
    margin: 6px auto 18px;
}

#ovChart:empty {
    display: none;
}

.ach-title {
    font-size: 20px;
    letter-spacing: 5px;
    color: #cbb8f0;
    margin-bottom: 12px;
}

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

.ach {
    display: grid;
    grid-template-columns: 1fr auto auto;
    align-items: center;
    gap: 16px;
    padding: 10px 20px;
    border-radius: 14px;
    border: 2px solid rgba(255, 255, 255, 0.14);
    background: rgba(255, 255, 255, 0.05);
    opacity: 0.55;
    transition: transform 0.2s;
}

.ach .ach-name {
    text-align: left;
    font-size: 24px;
    font-weight: 700;
    letter-spacing: 1px;
}

.ach .ach-range {
    font-size: 16px;
    opacity: 0.8;
    font-variant-numeric: tabular-nums;
}

.ach .ach-trumpets {
    font-size: 18px;
    min-width: 92px;
    text-align: right;
}

.ach.on {
    opacity: 1;
    border-color: #ffdf6b;
    background: linear-gradient(90deg, rgba(255, 223, 107, 0.22), rgba(255, 143, 178, 0.16));
    box-shadow: 0 0 28px rgba(255, 223, 107, 0.35);
    transform: scale(1.05);
}

.ach.on .ach-name {
    color: #ffdf6b;
}
