* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    user-select: none;
    -webkit-user-select: none;
}

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: radial-gradient(ellipse at top, #1a1f3a 0%, #0a0d1c 100%);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: #e8eaf0;
    touch-action: none;
    overscroll-behavior: none;
    -webkit-overflow-scrolling: touch;
    /* Use dynamic viewport for mobile (avoid URL bar issues) */
    height: 100dvh;
    width: 100vw;
}

#game-container {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 4px;
    padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right))
             max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    max-width: 520px;
    margin: 0 auto;
}

/* ── HUD ── */
#game-header {
    width: 100%;
}

.hud {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 18px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 16px;
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.hud-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.hud-label {
    font-size: 11px;
    color: #9ba3b8;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.hud-value {
    font-size: 22px;
    font-weight: 800;
    color: #ffd966;
    font-variant-numeric: tabular-nums;
}

.reset-btn,
.icon-btn {
    background: rgba(255, 255, 255, 0.08);
    color: #e8eaf0;
    border: 1px solid rgba(255, 255, 255, 0.12);
    width: 42px;
    height: 42px;
    border-radius: 12px;
    font-size: 20px;
    cursor: pointer;
    transition: transform 0.15s, background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.reset-btn:active,
.icon-btn:active {
    transform: scale(0.92);
    background: rgba(255, 255, 255, 0.16);
}

.party-bar-wrapper {
    width: 100%;
    max-width: 480px;
    margin: 0 0 5px 0;
    padding: 7px 9px;
    background: rgba(255, 255, 255, 0.045);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 10px;
}

.party-bar-wrapper.active {
    background: rgba(255, 217, 102, 0.13);
    border-color: rgba(255, 217, 102, 0.4);
}

.party-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 5px;
    color: #e8eaf0;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.4px;
    text-transform: uppercase;
}

#party-time {
    color: #ffd966;
    font-variant-numeric: tabular-nums;
}

.party-bar {
    height: 6px;
    overflow: hidden;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.26);
}

.party-bar-fill {
    height: 100%;
    width: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, #ff6fb1 0%, #ffd966 46%, #6ee887 100%);
    transform: scaleX(0);
    transform-origin: left center;
    transition: transform 0.12s linear;
}

/* Stats row — always visible, updates live as accessories change */
.stats-row {
    width: 100%;
    max-width: 480px;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 5px;
    margin: 6px 0 2px 0;
}

.stat-chip {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
    padding: 4px 4px 5px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.07);
    border-radius: 8px;
}

.stat-chip[data-stat="spawnTime"]    { border-color: rgba(230, 69, 58, 0.35); }
.stat-chip[data-stat="luck"]         { border-color: rgba(62, 192, 90, 0.35); }
.stat-chip[data-stat="startingTier"] { border-color: rgba(58, 139, 220, 0.35); }
.stat-chip[data-stat="capIncome"]    { border-color: rgba(240, 196, 60, 0.35); }

.stat-chip.bumped {
    animation: chipBump 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes chipBump {
    0%   { transform: scale(1); }
    40%  { transform: scale(1.12); background: rgba(255, 217, 102, 0.18); }
    100% { transform: scale(1); }
}

.chip-ic  { font-size: 16px; line-height: 1; }
.chip-lbl { font-size: 9px; color: #8a93aa; text-transform: uppercase; letter-spacing: 0.5px; font-weight: 700; }
.chip-val { font-size: 13px; font-weight: 800; color: #ffd966; font-variant-numeric: tabular-nums; line-height: 1.1; }


/* ── Caps bar (top) ── */
.caps-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    margin-bottom: 6px;
    flex-wrap: nowrap;
    justify-content: space-between;
}

.caps-bar > .caps-badge {
    flex: 1 1 auto;
    min-width: 0;
    justify-content: center;
}

.caps-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: rgba(255, 215, 100, 0.12);
    border: 1px solid rgba(255, 215, 100, 0.3);
    border-radius: 12px;
    font-weight: 800;
    color: #ffd966;
    box-shadow: inset 0 0 12px rgba(255, 200, 50, 0.08);
}

.caps-icon { font-size: 18px; }
.caps-value { font-size: 18px; font-variant-numeric: tabular-nums; }

.stats-mini {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: center;
}

.stat-pill {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 5px 10px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 9px;
    font-size: 12px;
    color: #e8eaf0;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.stat-icon { font-size: 14px; }

/* ── Shelf ── */
#shelf-wrapper {
    width: 100%;
    padding: 4px 0 4px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.shelf {
    position: relative;
    width: 100%;
    max-width: 480px;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    padding: 12px 12px 22px 12px;
    background: rgba(255, 255, 255, 0.04);
    border-radius: 18px;
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.shelf-board {
    position: absolute;
    left: 8px;
    right: 8px;
    bottom: 8px;
    height: 6px;
    background: linear-gradient(180deg, #7d5a3b 0%, #4a2f1a 100%);
    border-radius: 3px;
    box-shadow:
        inset 0 -2px 3px rgba(0, 0, 0, 0.4),
        0 2px 4px rgba(0, 0, 0, 0.3);
}

.shelf-slot {
    position: relative;
    aspect-ratio: 1;
    background: rgba(0, 0, 0, 0.22);
    border-radius: 10px;
    border: 1px dashed rgba(255, 255, 255, 0.07);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: visible;
}

.shelf-slot.red    { border-color: rgba(230, 69, 58, 0.35); background: rgba(120, 28, 34, 0.14); }
.shelf-slot.green  { border-color: rgba(62, 192, 90, 0.35); background: rgba(22, 95, 48, 0.14); }
.shelf-slot.blue   { border-color: rgba(58, 139, 220, 0.35); background: rgba(25, 70, 130, 0.14); }
.shelf-slot.yellow { border-color: rgba(240, 196, 60, 0.35); background: rgba(130, 98, 20, 0.14); }

.shelf-placeholder {
    color: rgba(255, 255, 255, 0.18);
    font-size: clamp(20px, 5vw, 28px);
    font-weight: 900;
    filter: grayscale(1);
}

.accessory {
    width: 88%;
    height: 88%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: clamp(24px, 6vw, 34px);
    filter: drop-shadow(0 3px 5px rgba(0, 0, 0, 0.5));
    animation: accessoryLand 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
    position: relative;
    border-radius: 9px;
}

.accessory.common { background: rgba(160, 168, 184, 0.12); border: 1px solid rgba(160, 168, 184, 0.4); }
.accessory.rare   { background: rgba(93, 158, 255, 0.18); border: 1px solid rgba(93, 158, 255, 0.55); box-shadow: 0 0 12px rgba(93, 158, 255, 0.35); }
.accessory.epic   { background: rgba(200, 122, 255, 0.22); border: 1px solid rgba(200, 122, 255, 0.6); box-shadow: 0 0 16px rgba(200, 122, 255, 0.45); }

.accessory-stat {
    font-size: 9px;
    font-weight: 800;
    margin-top: 2px;
    color: #fff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
    letter-spacing: 0.3px;
    line-height: 1;
}

.accessory.collecting {
    animation: accessoryCollect 0.32s ease-in forwards;
}

.shelf.shake {
    animation: shelfShake 0.3s ease-in-out;
}

@keyframes shelfShake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-6px); }
    75% { transform: translateX(6px); }
}

@keyframes accessoryLand {
    0%   { transform: scale(0) rotate(-20deg); opacity: 0; }
    60%  { transform: scale(1.2) rotate(8deg); opacity: 1; }
    100% { transform: scale(1) rotate(0); opacity: 1; }
}

@keyframes accessoryCollect {
    0%   { transform: scale(1); opacity: 1; }
    100% { transform: scale(0.2) translateY(-30px); opacity: 0; }
}

/* Accessory in-flight (animation from jar to shelf slot) */
.accessory-flying {
    position: fixed;
    z-index: 100;
    pointer-events: none;
    font-size: 32px;
    filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.6));
    transition: left 0.5s cubic-bezier(0.5, 0, 0.5, 1),
                top  0.5s cubic-bezier(0.4, 0, 0.6, 1),
                transform 0.5s ease-out;
}

/* ─── Legacy (arena removed) ─── */
.arena-bg-dead {
    position: absolute;
    inset: 0;
    background:
        radial-gradient(circle at 50% 100%, rgba(60, 130, 220, 0.18) 0%, transparent 60%),
        repeating-linear-gradient(180deg,
            transparent 0px,
            transparent 30px,
            rgba(255, 255, 255, 0.025) 30px,
            rgba(255, 255, 255, 0.025) 31px);
    pointer-events: none;
}

.enemies-layer,
.projectiles-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.base {
    position: absolute;
    left: 50%;
    bottom: 18px;
    transform: translateX(-50%);
    width: 56px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 44px;
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.6));
    z-index: 3;
    transition: transform 0.12s;
}

.base.hit {
    animation: baseShake 0.32s;
}

@keyframes baseShake {
    0%, 100% { transform: translateX(-50%); }
    20% { transform: translateX(-50%) translate(-6px, 2px); }
    40% { transform: translateX(-50%) translate(6px, -2px); }
    60% { transform: translateX(-50%) translate(-4px, 1px); }
    80% { transform: translateX(-50%) translate(4px, -1px); }
}

/* HP bar */
.arena-hp {
    position: absolute;
    left: 12px;
    right: 12px;
    bottom: 6px;
    height: 14px;
    background: rgba(0, 0, 0, 0.55);
    border-radius: 7px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    overflow: hidden;
}

.arena-hp-fill {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, #4adf69 0%, #6ee887 100%);
    transition: width 0.25s ease-out;
}

.arena-hp-fill.low {
    background: linear-gradient(90deg, #df4a4a 0%, #ff6e6e 100%);
}

.arena-hp-text {
    position: absolute;
    inset: 0;
    text-align: center;
    line-height: 14px;
    font-size: 10px;
    font-weight: 800;
    color: #fff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
    letter-spacing: 0.5px;
}

/* Enemy */
.enemy {
    position: absolute;
    width: 34px;
    height: 34px;
    border-radius: 50% 50% 30% 30%;
    background: radial-gradient(circle at 35% 28%, var(--enemy-light), var(--enemy-mid) 50%, var(--enemy-dark));
    box-shadow:
        inset -3px -4px 5px rgba(0, 0, 0, 0.35),
        inset 3px 3px 5px rgba(255, 255, 255, 0.25),
        0 3px 5px rgba(0, 0, 0, 0.5);
    transform-origin: center bottom;
    animation: enemyWobble 0.55s ease-in-out infinite alternate;
    z-index: 2;
    pointer-events: none;
}

.enemy::before, .enemy::after {
    content: '';
    position: absolute;
    top: 36%;
    width: 6px;
    height: 6px;
    background: #fff;
    border-radius: 50%;
    box-shadow: inset 0 0 0 2px #0a0a0a;
}
.enemy::before { left: 25%; }
.enemy::after  { right: 25%; }

.enemy {
    --enemy-light: #b3f5b8;
    --enemy-mid:   #4dd96a;
    --enemy-dark:  #1c7d33;
}

.enemy.tough {
    --enemy-light: #ffbaba;
    --enemy-mid:   #e35454;
    --enemy-dark:  #7a1818;
}

.enemy.elite {
    --enemy-light: #d8b6ff;
    --enemy-mid:   #9249e4;
    --enemy-dark:  #4a1882;
}

.enemy.boss {
    --enemy-light: #ffd070;
    --enemy-mid:   #d94545;
    --enemy-dark:  #6b1a1a;
    width: 64px;
    height: 64px;
    box-shadow:
        inset -5px -6px 8px rgba(0, 0, 0, 0.4),
        inset 5px 5px 7px rgba(255, 255, 255, 0.3),
        0 5px 10px rgba(255, 80, 80, 0.6),
        0 0 24px rgba(255, 120, 50, 0.5);
    animation: bossPulse 1.4s ease-in-out infinite;
    z-index: 4;
}

.enemy.boss::before, .enemy.boss::after {
    top: 38%;
    width: 9px;
    height: 9px;
    box-shadow: inset 0 0 0 3px #0a0a0a;
}
.enemy.boss::before { left: 24%; }
.enemy.boss::after  { right: 24%; }

.boss-crown {
    position: absolute;
    top: -22px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 22px;
    filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.6));
    animation: crownBob 1.4s ease-in-out infinite;
    pointer-events: none;
}

@keyframes bossPulse {
    0%, 100% { transform: scale(1); }
    50%      { transform: scale(1.06); }
}

@keyframes crownBob {
    0%, 100% { transform: translateX(-50%) translateY(0); }
    50%      { transform: translateX(-50%) translateY(-4px); }
}

.enemy-hp-bar.boss {
    top: -12px;
    height: 6px;
    left: -4px;
    right: -4px;
}

.enemy.dying {
    animation: enemyDie 0.32s ease-in forwards;
}

@keyframes enemyWobble {
    0%   { transform: scaleY(1) scaleX(1); }
    100% { transform: scaleY(0.92) scaleX(1.06); }
}

@keyframes enemyDie {
    0%   { transform: scale(1) rotate(0); opacity: 1; }
    100% { transform: scale(0) rotate(90deg); opacity: 0; }
}

.enemy-hp-bar {
    position: absolute;
    top: -8px;
    left: 2px;
    right: 2px;
    height: 4px;
    background: rgba(0, 0, 0, 0.6);
    border-radius: 2px;
    overflow: hidden;
}

.enemy-hp-fill {
    height: 100%;
    background: #ff6464;
    transition: width 0.15s;
}

/* Damage popups */
.dmg-popup {
    position: absolute;
    color: #ffd966;
    font-size: 16px;
    font-weight: 900;
    pointer-events: none;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8);
    animation: dmgFly 0.7s ease-out forwards;
    z-index: 5;
}

.dmg-popup.crit {
    color: #ff7050;
    font-size: 22px;
}

@keyframes dmgFly {
    0%   { transform: translate(-50%, 0) scale(0.5);  opacity: 0; }
    20%  { transform: translate(-50%, -10px) scale(1.1); opacity: 1; }
    100% { transform: translate(-50%, -38px) scale(1);   opacity: 0; }
}

/* Projectile */
.projectile {
    position: absolute;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: radial-gradient(circle at 30% 30%, #fff, var(--proj-color) 70%);
    box-shadow: 0 0 12px var(--proj-color), 0 0 4px #fff;
    z-index: 4;
    pointer-events: none;
}

.projectile.red   { --proj-color: #ff5d4f; }
.projectile.green { --proj-color: #4adf69; }
.projectile.blue  { --proj-color: #4a9fff; }

/* Toast */
.toast {
    position: absolute;
    top: 14px;
    left: 50%;
    transform: translateX(-50%) translateY(-4px);
    padding: 8px 16px;
    background: rgba(20, 28, 50, 0.95);
    color: #fff;
    font-weight: 800;
    font-size: 14px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
    z-index: 10;
    animation: toastIn 0.32s cubic-bezier(0.34, 1.56, 0.64, 1);
    opacity: 1;
    transition: opacity 0.45s, transform 0.45s;
    white-space: nowrap;
    pointer-events: none;
}

.toast.warn { background: rgba(120, 30, 30, 0.96); border-color: #ff7878; }
.toast.win  { background: rgba(30, 80, 50, 0.96); border-color: #6ee887; }
.toast.fail { background: rgba(110, 20, 20, 0.96); border-color: #ff6464; }

.toast.fade {
    opacity: 0;
    transform: translateX(-50%) translateY(-12px);
}

@keyframes toastIn {
    0%   { opacity: 0; transform: translateX(-50%) translateY(-18px) scale(0.85); }
    100% { opacity: 1; transform: translateX(-50%) translateY(-4px) scale(1); }
}

/* ── Board ── */
#board-wrapper {
    flex: 0 0 auto;
    width: 100%;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 0;
    min-height: 0;
}

.board {
    position: relative;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 8px;
    padding: 12px;
    background: rgba(255, 255, 255, 0.04);
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    width: 100%;
    max-width: 480px;
    aspect-ratio: 1;
    touch-action: none;
}

/* ── Cell ── */
.cell {
    position: relative;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1),
                opacity 0.18s;
}

/* Tile silhouette — matches the visible jar outline: narrow rounded
   lid sitting directly on top of a wider body with curved shoulders.
   Positions follow .jar at 92% × 92% centered.
   No overlap → uniform opacity everywhere. */
.cell::before {
    content: '';
    position: absolute;
    top: 4%;
    left: 20.5%;
    right: 20.5%;
    height: 16.5%;
    background: rgba(0, 0, 0, 0.30);
    border-radius: 4px 4px 0 0;
    z-index: 0;
    pointer-events: none;
}

.cell::after {
    content: '';
    position: absolute;
    top: 20.5%;
    left: 7.5%;
    right: 7.5%;
    bottom: 7.5%;
    background: rgba(0, 0, 0, 0.30);
    border-radius: 8px 8px 14px 14px;
    z-index: 0;
    pointer-events: none;
}

/* The jar (when present) must paint above the silhouette */
.cell > .jar { z-index: 1; position: relative; }

.cell.selected {
    background: rgba(255, 217, 102, 0.18);
    box-shadow: 0 0 0 2px #ffd966 inset, 0 0 18px rgba(255, 217, 102, 0.4);
    transform: scale(0.96);
}

.cell.merging {
    animation: mergePulse 0.4s ease-out;
}

.cell.dying {
    animation: dieShrink 0.3s ease-in forwards;
}

.cell.spawning {
    animation: spawnPop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.party-active .cell > .jar {
    animation: jarPartyDance 0.55s ease-in-out infinite alternate;
}

.party-active .cell:nth-child(2n) > .jar {
    animation-delay: -0.18s;
}

.party-active .cell:nth-child(3n) > .jar {
    animation-delay: -0.32s;
}

.cell.drag-source {
    opacity: 0.35;
    transform: scale(0.92);
}

.cell.drag-over-good { transform: scale(1.04); }
.cell.drag-over-good::before { background: rgba(120, 255, 150, 0.45); }
.cell.drag-over-good::after  { background: rgba(120, 255, 150, 0.35); }

.cell.drag-over-bad::before { background: rgba(255, 100, 100, 0.35); }
.cell.drag-over-bad::after  { background: rgba(255, 100, 100, 0.28); }

.spawn-preview {
    position: absolute;
    inset: 0;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    transform: scale(var(--spawn-scale, 0.16));
    transform-origin: center center;
    transition: transform 0.1s linear, opacity 0.1s linear;
    filter: drop-shadow(0 5px 10px rgba(0, 0, 0, 0.32));
    will-change: transform, opacity;
}

.spawn-preview .jar {
    width: 92%;
    height: 92%;
}

.drag-ghost {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 200;
    pointer-events: none;
    filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.5));
    opacity: 0.92;
    will-change: transform;
}

.drag-ghost .jar {
    width: 100%;
    height: 100%;
}

.drag-ghost.pending .jar {
    opacity: var(--pending-drag-opacity, 1);
    transform: scale(var(--pending-drag-scale, 1));
    transform-origin: center center;
}


.spawn-timer {
    position: absolute;
    inset: 8px;
    border-radius: 50%;
    background: conic-gradient(rgba(255, 217, 102, 0.7) 0deg, transparent 0deg);
    pointer-events: none;
    opacity: 0.55;
}

.spawn-timer-center {
    position: absolute;
    inset: 22%;
    border-radius: 50%;
    background: rgba(8, 13, 24, 0.85);
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 800;
    color: #ffd966;
    font-variant-numeric: tabular-nums;
}

.cell.opening .jar-lid {
    animation: lidFly 0.32s ease-out forwards;
}

.cell.opening .jar-body,
.cell.opening .jar-shine,
.cell.opening .jar-number {
    animation: jarFade 0.28s ease-out forwards;
}

@keyframes lidFly {
    0%   { transform: translateY(0) rotate(0); opacity: 1; }
    100% { transform: translateY(-30px) rotate(-30deg); opacity: 0; }
}

@keyframes jarFade {
    0%   { transform: scale(1); opacity: 1; }
    100% { transform: scale(0.4) translateY(8px); opacity: 0; }
}

@keyframes mergePulse {
    0%   { transform: scale(1); }
    50%  { transform: scale(1.18); filter: brightness(1.4); }
    100% { transform: scale(1); }
}

@keyframes dieShrink {
    0%   { transform: scale(1); opacity: 1; }
    100% { transform: scale(0); opacity: 0; }
}

@keyframes spawnPop {
    0%   { transform: scale(0); opacity: 0; }
    60%  { transform: scale(1.1); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}

@keyframes jarPartyDance {
    0%   { transform: translateY(0) rotate(-3deg) scale(1); }
    100% { transform: translateY(-5px) rotate(4deg) scale(1.04); }
}

/* ── Jar Visuals ── */
.jar {
    width: 92%;
    height: 92%;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.jar-body {
    position: absolute;
    inset: 12% 4% 4% 4%;
    border-radius: 8px 8px 14px 14px;
    background: linear-gradient(180deg, var(--jar-light) 0%, var(--jar-mid) 50%, var(--jar-dark) 100%);
    box-shadow:
        inset 0 -6px 8px rgba(0, 0, 0, 0.3),
        inset 4px 0 5px rgba(255, 255, 255, 0.25),
        inset -4px 0 5px rgba(0, 0, 0, 0.2),
        0 3px 6px rgba(0, 0, 0, 0.35);
}

.jar-lid {
    position: absolute;
    top: 0;
    left: 18%;
    right: 18%;
    height: 18%;
    background: linear-gradient(180deg, #6a727f 0%, #3a414e 100%);
    border-radius: 4px 4px 2px 2px;
    box-shadow:
        inset 0 -2px 3px rgba(0, 0, 0, 0.4),
        0 1px 2px rgba(0, 0, 0, 0.3);
}

.jar-shine {
    position: absolute;
    top: 22%;
    left: 14%;
    width: 14%;
    height: 50%;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.55) 0%, rgba(255, 255, 255, 0) 100%);
    border-radius: 50%;
    pointer-events: none;
}

.jar-number {
    position: relative;
    z-index: 2;
    font-size: clamp(16px, 4.5vw, 28px);
    font-weight: 900;
    color: #fff;
    text-shadow:
        0 2px 4px rgba(0, 0, 0, 0.7),
        0 0 8px rgba(0, 0, 0, 0.5);
    margin-top: 14%;
    font-variant-numeric: tabular-nums;
}

.jar-content {
    position: relative;
    z-index: 2;
    margin-top: 18%;
    font-size: clamp(22px, 6vw, 36px);
    filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.5));
    animation: jarContentFloat 2.2s ease-in-out infinite alternate;
}

@keyframes jarContentFloat {
    0%   { transform: translateY(0) rotate(-3deg); }
    100% { transform: translateY(-2px) rotate(3deg); }
}

.jar-infinity-logo {
    --logo-size: 76px;
    position: relative;
    display: grid;
    place-items: center;
    width: var(--logo-size);
    height: calc(var(--logo-size) * 1.08);
    isolation: isolate;
    filter: drop-shadow(0 9px 16px rgba(0, 0, 0, 0.48));
}

.jar-infinity-logo::before {
    content: "";
    position: absolute;
    z-index: 3;
    top: 0;
    left: 21%;
    right: 21%;
    height: 18%;
    border: 1px solid rgba(255, 255, 255, 0.62);
    border-radius: 7px 7px 3px 3px;
    background:
        repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.22) 0 2px, transparent 2px 5px),
        linear-gradient(180deg, #f4f6fb 0%, #a7afbd 44%, #67717f 100%);
    box-shadow:
        inset 0 -4px 5px rgba(0, 0, 0, 0.26),
        0 2px 4px rgba(0, 0, 0, 0.35);
}

.jar-infinity-logo::after {
    content: "";
    position: absolute;
    z-index: 1;
    top: 13%;
    right: 7%;
    bottom: 4%;
    left: 7%;
    border: 2px solid rgba(232, 244, 255, 0.58);
    border-radius: 14px 14px 24px 24px;
    background:
        radial-gradient(circle at 72% 24%, rgba(255, 255, 255, 0.42) 0 10%, transparent 24%),
        linear-gradient(100deg, rgba(255, 255, 255, 0.35) 0 10%, transparent 22%),
        linear-gradient(180deg, rgba(199, 222, 246, 0.32) 0%, rgba(89, 108, 132, 0.38) 100%);
    box-shadow:
        inset 7px 0 9px rgba(255, 255, 255, 0.25),
        inset -8px 0 10px rgba(11, 18, 32, 0.32),
        inset 0 -8px 12px rgba(0, 0, 0, 0.33),
        0 4px 10px rgba(0, 0, 0, 0.35);
}

.jar-logo-mark {
    position: relative;
    z-index: 2;
    margin-top: 19%;
    color: #f7dc72;
    font-size: calc(var(--logo-size) * 0.5);
    font-weight: 900;
    line-height: 1;
    text-shadow:
        0 2px 6px rgba(0, 0, 0, 0.55),
        0 0 14px rgba(255, 217, 102, 0.42);
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.modal.hidden { display: none; }

.modal-bg {
    position: absolute;
    inset: 0;
    background: rgba(5, 8, 18, 0.78);
    backdrop-filter: blur(4px);
}

.modal-panel {
    position: relative;
    max-width: 560px;
    width: 100%;
    max-height: min(88vh, 760px);
    max-height: min(88dvh, 760px);
    background: linear-gradient(180deg, #1a2542 0%, #0e1730 100%);
    border-radius: 18px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.modal-header h2 {
    margin: 0;
    font-size: 18px;
    letter-spacing: 0.4px;
}

.codex-summary {
    padding: 10px 18px;
    font-size: 14px;
    color: #ffd966;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.codex-grid {
    padding: 12px 14px 18px;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-auto-rows: auto;
    gap: 6px;
    overflow-y: auto;
    flex: 1;
    align-content: start;
    min-height: 0;
    -webkit-overflow-scrolling: touch;
}

.codex-col-header {
    text-align: center;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.5px;
    padding: 4px;
    border-radius: 6px;
    text-transform: uppercase;
    color: #fff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}
.codex-col-header.red    { background: rgba(230, 69, 58, 0.4); }
.codex-col-header.green  { background: rgba(62, 192, 90, 0.4); }
.codex-col-header.blue   { background: rgba(58, 139, 220, 0.4); }
.codex-col-header.yellow { background: rgba(240, 196, 60, 0.4); }

.codex-cell {
    min-height: 76px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4px 2px;
    gap: 2px;
    overflow: hidden;
}

.codex-cell.discovered.red    { border-color: rgba(230, 69, 58, 0.55); background: rgba(140, 30, 30, 0.18); }
.codex-cell.discovered.green  { border-color: rgba(62, 192, 90, 0.55); background: rgba(20, 90, 40, 0.18); }
.codex-cell.discovered.blue   { border-color: rgba(58, 139, 220, 0.55); background: rgba(20, 60, 120, 0.18); }
.codex-cell.discovered.yellow { border-color: rgba(240, 196, 60, 0.55); background: rgba(120, 90, 20, 0.18); }

.codex-icon {
    font-size: 24px;
    filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.5));
    line-height: 1;
}

.codex-cell.locked .codex-icon {
    filter: brightness(0) drop-shadow(0 0 4px rgba(255, 255, 255, 0.15));
    opacity: 0.5;
}

.codex-name {
    font-size: 9px;
    font-weight: 700;
    color: #e8eaf0;
    text-align: center;
    line-height: 1.1;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.codex-cell.locked .codex-name {
    color: #4a5168;
}

.codex-stat {
    font-size: 9px;
    color: #ffd966;
    font-weight: 800;
    letter-spacing: 0.2px;
    line-height: 1;
}

.codex-id {
    font-size: 9px;
    color: #6a7188;
    font-weight: 700;
    margin-top: -2px;
}

.store-panel {
    max-width: 460px;
}

.reset-panel {
    max-width: 380px;
}

.reset-body {
    padding: 18px;
    color: #c7cedd;
    font-size: 14px;
    line-height: 1.45;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.reset-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    padding: 12px;
}

.reset-action-btn {
    min-height: 44px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 10px;
    color: #e8eaf0;
    font-weight: 900;
    font-size: 14px;
    cursor: pointer;
}

.reset-action-btn.secondary {
    background: rgba(255, 255, 255, 0.08);
}

.reset-action-btn.danger {
    background: linear-gradient(180deg, #e85a5a 0%, #a62d38 100%);
    border-color: rgba(255, 120, 120, 0.45);
}

.reset-action-btn:active {
    transform: scale(0.97);
}

.store-balance {
    padding: 10px 16px;
    color: #ffd966;
    font-size: 16px;
    font-weight: 900;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    font-variant-numeric: tabular-nums;
}

.store-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px;
    overflow-y: auto;
    min-height: 0;
}

.store-section-title {
    margin: 4px 2px -2px;
    color: #ffd966;
    font-size: 11px;
    font-weight: 900;
    letter-spacing: 0.7px;
    text-transform: uppercase;
}

.store-item {
    width: 100%;
    display: grid;
    grid-template-columns: 40px 1fr auto;
    align-items: center;
    gap: 10px;
    padding: 10px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.09);
    background: rgba(255, 255, 255, 0.055);
    color: #e8eaf0;
    text-align: left;
    cursor: pointer;
}

.store-item:disabled {
    opacity: 0.48;
    cursor: default;
}

.store-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 9px;
    background: rgba(0, 0, 0, 0.22);
    font-size: 22px;
}

.store-copy {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.store-copy b {
    font-size: 13px;
}

.store-copy em {
    color: #9ba3b8;
    font-size: 11px;
    font-style: normal;
    line-height: 1.2;
}

.store-copy small {
    color: #ffd966;
    font-size: 11px;
    font-weight: 800;
}

.store-cost {
    color: #ffd966;
    font-size: 13px;
    font-weight: 900;
    white-space: nowrap;
}

/* Tutorial */
.tutorial-panel {
    max-width: 440px;
}

.tutorial-body {
    padding: 24px 22px 18px;
    text-align: center;
    min-height: 180px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
}

.tut-icon {
    font-size: 54px;
    line-height: 1;
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.5));
    animation: tutIconPop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.tut-icon.is-logo {
    display: grid;
    place-items: center;
    min-height: 86px;
    font-size: 0;
    filter: none;
}

.tutorial-logo {
    --logo-size: 76px;
}

@keyframes tutIconPop {
    0%   { transform: scale(0.3); opacity: 0; }
    100% { transform: scale(1);   opacity: 1; }
}

.tut-text {
    margin: 0;
    font-size: 15px;
    line-height: 1.5;
    color: #d4d8e2;
    max-width: 340px;
}

.tutorial-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 18px 18px;
    gap: 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.tut-btn {
    padding: 10px 16px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #e8eaf0;
    font-size: 14px;
    font-weight: 700;
    border-radius: 10px;
    cursor: pointer;
    min-width: 80px;
    transition: transform 0.15s, background 0.2s;
}

.tut-btn:active {
    transform: scale(0.95);
}

.tut-btn:disabled {
    opacity: 0.4;
    cursor: default;
}

.tut-btn.primary {
    background: linear-gradient(180deg, #4a8bdc 0%, #2964b0 100%);
    border-color: #5a9bee;
    color: #fff;
}

.tut-counter {
    font-size: 12px;
    color: #9ba3b8;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

/* Colors */
.jar.red {
    --jar-light: #ff8a7e;
    --jar-mid:   #e6453a;
    --jar-dark:  #8c1d18;
}
.jar.green {
    --jar-light: #8eed9c;
    --jar-mid:   #3ec05a;
    --jar-dark:  #1b6b2c;
}
.jar.blue {
    --jar-light: #8cc7ff;
    --jar-mid:   #3a8bdc;
    --jar-dark:  #154780;
}
.jar.yellow {
    --jar-light: #fff1a3;
    --jar-mid:   #f0c43c;
    --jar-dark:  #8a6b14;
}
.jar.black {
    --jar-light: #4a4a52;
    --jar-mid:   #232328;
    --jar-dark:  #0a0a0e;
    filter: grayscale(0.6) saturate(0.6);
}
.jar.black .jar-shine { opacity: 0.2; }
.jar.black .jar-lid {
    background: linear-gradient(180deg, #2a2a30 0%, #15151a 100%);
}

/* RGB Boss Jar */
.jar.rgb {
    animation: bossPulse 1.8s ease-in-out infinite;
    filter: drop-shadow(0 0 8px rgba(255, 255, 255, 0.5));
}

.jar.rgb .jar-body {
    background: linear-gradient(135deg,
        #ff5d5d 0%,
        #ffcd5d 16%,
        #5dff5d 33%,
        #5dffff 50%,
        #5d5dff 66%,
        #ce5dff 83%,
        #ff5d5d 100%);
    background-size: 400% 100%;
    animation: rgbShift 2s linear infinite;
    box-shadow:
        inset 0 -6px 8px rgba(0, 0, 0, 0.3),
        inset 4px 0 5px rgba(255, 255, 255, 0.35),
        inset -4px 0 5px rgba(0, 0, 0, 0.2),
        0 3px 6px rgba(0, 0, 0, 0.4);
}

.jar.rgb .jar-lid {
    background: linear-gradient(180deg, #ffd966 0%, #c08400 100%);
    box-shadow:
        inset 0 -2px 3px rgba(0, 0, 0, 0.5),
        0 0 6px rgba(255, 217, 102, 0.6);
}

.jar.rgb .jar-content {
    font-size: clamp(20px, 5.5vw, 32px);
}

@keyframes rgbShift {
    0%   { background-position: 0% 0%; }
    100% { background-position: 100% 0%; }
}

@keyframes bossPulse {
    0%, 100% { transform: scale(1); }
    50%      { transform: scale(1.04); }
}

.cell.boss-tap-pulse {
    animation: bossTapKick 0.18s ease-out;
}

@keyframes bossTapKick {
    0%   { transform: scale(1); }
    40%  { transform: scale(0.92); }
    100% { transform: scale(1); }
}

.cell.boss-burst {
    animation: bossBurst 0.55s ease-out forwards;
}

.cell.shattering {
    animation: shatter 0.5s ease-out forwards;
}

@keyframes shatter {
    0%   { transform: scale(1) rotate(0);     opacity: 1; filter: brightness(1) saturate(1); }
    15%  { transform: scale(1.25) rotate(-8deg);          filter: brightness(1.6) saturate(1.5); }
    30%  { transform: scale(0.85) rotate(12deg); }
    50%  { transform: scale(1.0)  rotate(-18deg); opacity: 0.85; }
    100% { transform: scale(0.15) rotate(180deg); opacity: 0; filter: brightness(0.4) blur(3px); }
}

/* Shard particles fly outward on shatter */
.shard {
    position: fixed;
    width: 10px;
    height: 10px;
    background: linear-gradient(135deg, #6a6a72 0%, #2a2a30 100%);
    border-radius: 1px;
    z-index: 250;
    pointer-events: none;
    box-shadow: 0 0 4px rgba(0, 0, 0, 0.6);
    animation: shardFly 0.6s cubic-bezier(0.3, 0.5, 0.7, 1) forwards;
}

@keyframes shardFly {
    0%   { transform: translate(-50%, -50%) rotate(0deg); opacity: 1; }
    100% { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) rotate(var(--rot)); opacity: 0; }
}

@keyframes bossBurst {
    0%   { transform: scale(1);     box-shadow: 0 0 0 rgba(255, 255, 255, 0); }
    40%  { transform: scale(1.25);  box-shadow: 0 0 30px rgba(255, 255, 255, 0.9), 0 0 60px rgba(255, 217, 102, 0.6); }
    100% { transform: scale(1);     box-shadow: 0 0 0 rgba(255, 255, 255, 0); }
}

@keyframes mergePulseLite {
    0%   { transform: scale(1); }
    50%  { transform: scale(1.16); }
    100% { transform: scale(1); }
}

@keyframes shatterLite {
    0%   { transform: scale(1) rotate(0); opacity: 1; }
    20%  { transform: scale(1.18) rotate(-8deg); }
    55%  { transform: scale(0.92) rotate(14deg); opacity: 0.75; }
    100% { transform: scale(0.12) rotate(180deg); opacity: 0; }
}

@keyframes bossBurstLite {
    0%   { transform: scale(1); }
    40%  { transform: scale(1.22); }
    100% { transform: scale(1); }
}

.jar-tier-label {
    position: absolute;
    top: 3%;
    left: 50%;
    transform: translateX(-50%);
    z-index: 4;
    font-size: clamp(9px, 2.4vw, 11px);
    font-weight: 900;
    color: #fff;
    text-shadow:
        0 1px 1px rgba(0, 0, 0, 0.9),
        0 0 3px rgba(0, 0, 0, 0.7);
    letter-spacing: 0.3px;
    font-variant-numeric: tabular-nums;
    pointer-events: none;
}

.jar.black .jar-tier-label { color: #c8c8d0; }

.jar.jar-locked {
    filter: drop-shadow(0 0 10px rgba(255, 217, 102, 0.38));
}

.jar-lock-badge {
    position: absolute;
    right: 4%;
    bottom: 4%;
    z-index: 5;
    width: 26%;
    height: 22%;
    border-radius: 7px 0 9px 0;
    background:
        linear-gradient(145deg, rgba(255, 240, 150, 0.28), rgba(80, 55, 20, 0.44)),
        rgba(12, 17, 32, 0.42);
    border-left: 1px solid rgba(255, 244, 178, 0.42);
    border-top: 1px solid rgba(255, 244, 178, 0.34);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(9px, 2.8vw, 13px);
    box-shadow:
        inset 1px 1px 2px rgba(255, 255, 255, 0.16),
        inset -2px -2px 3px rgba(0, 0, 0, 0.26);
}

.cell.lock-pulse,
.cell.unlock-pulse {
    animation: lockPulse 0.24s ease-out;
}

@keyframes lockPulse {
    0%   { transform: scale(1); }
    45%  { transform: scale(0.9); filter: brightness(1.35); }
    100% { transform: scale(1); }
}

@media (max-width: 560px) {
    .modal {
        padding: 8px;
        align-items: stretch;
    }

    .modal-panel {
        max-height: calc(100dvh - 16px);
        border-radius: 14px;
    }

    .modal-header {
        padding: 10px 12px;
    }

    .modal-header h2 {
        font-size: 16px;
    }

    .codex-summary {
        padding: 8px 12px;
    }

    .codex-grid {
        padding: 10px;
        gap: 5px;
    }

    .codex-col-header {
        min-height: 34px;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 4px 2px;
        font-size: 10px;
    }

    .codex-cell {
        min-height: 68px;
        padding: 4px 1px;
    }

    .codex-icon {
        font-size: 21px;
    }

    .codex-name,
    .codex-stat {
        font-size: 8px;
    }
}

@media (max-width: 420px) {
    .codex-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 4px;
        padding: 8px;
    }

    .codex-cell {
        min-height: 62px;
        border-radius: 6px;
    }

    .codex-icon {
        font-size: 19px;
    }
}

@media (hover: none), (pointer: coarse) {
    .modal-bg {
        backdrop-filter: none;
    }

    .hud,
    .modal-panel {
        backdrop-filter: none;
    }

    .jar-content {
        animation: none;
        filter: none;
    }

    .party-active .cell > .jar {
        animation: jarPartyDance 0.8s ease-in-out infinite alternate;
    }

    .jar-body,
    .jar-lid,
    .jar.rgb,
    .jar.rgb .jar-body,
    .jar.rgb .jar-lid,
    .jar.jar-locked,
    .spawn-preview,
    .shard,
    .accessory-flying,
    .float-score,
    .modal-panel,
    .codex-icon,
    .accessory-icon,
    .drag-ghost {
        filter: none;
        box-shadow: none;
    }

    .jar.rgb .jar-body {
        animation-duration: 3.5s;
    }

    .cell.merging {
        animation-name: mergePulseLite;
    }

    .cell.shattering {
        animation-name: shatterLite;
    }

    .cell.boss-burst {
        animation-name: bossBurstLite;
    }

    .cell,
    .icon-btn,
    .reset-btn {
        transition-duration: 0.08s;
    }
}

@media (max-width: 420px) {
    .store-item {
        grid-template-columns: 34px 1fr;
    }

    .store-cost {
        grid-column: 2;
    }

    .store-icon {
        width: 34px;
        height: 34px;
        font-size: 19px;
    }
}

/* ── Footer ── */
#game-footer {
    width: 100%;
    text-align: center;
    padding: 10px;
}

.hint {
    margin: 0;
    font-size: 12px;
    color: #7e8599;
    letter-spacing: 0.3px;
}

/* ── Float Score ── */
.float-score {
    position: absolute;
    color: #ffd966;
    font-size: 20px;
    font-weight: 900;
    pointer-events: none;
    text-shadow: 0 2px 6px rgba(0, 0, 0, 0.6);
    animation: floatUp 0.9s ease-out forwards;
    z-index: 10;
}

@keyframes floatUp {
    0%   { transform: translateY(0)    scale(0.6); opacity: 0; }
    20%  { transform: translateY(-10px) scale(1.1); opacity: 1; }
    100% { transform: translateY(-50px) scale(1);   opacity: 0; }
}
