#stay-in-budget-game-view {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    position: relative;
}

/* Budget display flows naturally as a single block of text */
#sib-budget-display {
    display: block;
    text-align: left;
    line-height: 1.4;
    padding: 0;
    margin: 0;
    width: 100%;
}

#sib-budget-display h3 {
    display: inline;
    margin: 0 8px 0 0;
    padding: 0;
    font-size: 1.1em;
    color: var(--text-primary);
}

#sib-budget-value {
    display: inline;
    font-weight: bold;
    font-size: 1.5em;
    color: var(--success-color);
}

#sib-round-name {
    display: inline;
    margin-left: 8px;
    font-weight: 500;
    font-size: 1.1em;
    color: var(--text-secondary);
    word-wrap: break-word;
}

/* Timer styles strictly enforcing dimensions */
#sib-timer-container { 
    position: relative; 
    width: 60px; 
    height: 60px; 
    min-width: 60px;
    min-height: 60px;
    flex-shrink: 0;
    display: block !important; 
}
#sib-timer-svg { 
    transform: rotate(-90deg); 
    width: 100%;
    height: 100%;
    display: block;
}
#sib-timer-text {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.5em; font-weight: bold; color: var(--text-primary);
}

#sib-budget-intro-overlay {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    z-index: 50; display: none;
    justify-content: center; align-items: center;
    border-radius: 10px;
}

#sib-budget-intro-overlay::before {
    content: "";
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: transparent; 
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    border-radius: 10px;
    opacity: 0;
    transition: opacity 0.5s ease;
    z-index: -1;
}

#sib-budget-intro-overlay.bg-active::before {
    opacity: 1;
}

.intro-content-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    gap: 15px;
    position: relative;
    z-index: 1;
}

#sib-intro-label {
    margin: 0;
    text-align: center;
    opacity: 0;
    transition: opacity 0.4s ease;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

#sib-intro-label.visible {
    opacity: 1;
}

.sib-intro-title {
    font-size: 1.5em;
    font-weight: bold;
    color: #ffff;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

.sib-intro-subtitle {
    font-size: 1.2em;
    color: var(--highlight-primary);
    font-weight: bold;
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

/* Slot Machine Styles */
.slot-container {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 2px;
    padding: 20px;
    border-radius: 12px;
    will-change: transform;
    max-width: 90vw;
}

.digit-box {
    position: relative;
    width: 0.65em; 
    height: 1.1em; 
    font-size: 5.5rem;
    font-weight: 900;
    color: var(--success-color);
    overflow-y: hidden; 
    overflow-x: visible;
    display: flex;
    justify-content: center;
    -webkit-mask-image: linear-gradient(to bottom, transparent 0%, black 15%, black 85%, transparent 100%);
    mask-image: linear-gradient(to bottom, transparent 0%, black 15%, black 85%, transparent 100%);
    scrollbar-width: none;
}

.digit-box::-webkit-scrollbar {
    display: none;
}

.digit-box .digit {
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

.digit-box.symbol-box {
    width: auto; 
    min-width: 0.4em;
    margin: 0 10px; 
    overflow: visible; 
    -webkit-mask-image: none; 
    mask-image: none;
    justify-content: flex-start; 
}

.digit-box.symbol-box .digit {
    position: relative; 
    justify-content: flex-start;
}

.digit {
    position: absolute;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    white-space: nowrap; 
    will-change: transform, opacity;
}

/* Directional transitions (rolling up or down like an odometer) */
.slot-enter-up { transform: translateY(100%); opacity: 0; }
.slot-enter-down { transform: translateY(-100%); opacity: 0; }
.slot-enter-active { transform: translateY(0) !important; opacity: 1 !important; }
.slot-exit-up { transform: translateY(-100%) !important; opacity: 0 !important; }
.slot-exit-down { transform: translateY(100%) !important; opacity: 0 !important; }

.slot-container.pop { transform: scale(1.3) !important; transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275); }

@keyframes flyToCorner {
    0% { transform: scale(1.3) translate(0, 0); opacity: 1; }
    100% { transform: scale(0.3) translate(-80vw, -80vh); opacity: 0; }
}
.slot-container.fly-to-destination {
    transition: transform 0.5s cubic-bezier(0.45, 0, 0.55, 1), opacity 0.4s ease-in;
    transform: translate(var(--fly-x), var(--fly-y)) scale(var(--fly-scale)) !important;
    opacity: 0;
    pointer-events: none;
}

@keyframes popHeader {
    0% { transform: scale(1); }
    50% { transform: scale(1.5); color: #fff; }
    100% { transform: scale(1); }
}
.pop-header { animation: popHeader 0.3s ease-out; display: inline-block; }

/* Grid Layout */
.sib-grid {
    display: grid;
    /* Forces max of 6 cards by calculating the min-width dynamically based on container width */
    grid-template-columns: repeat(auto-fill, minmax(max(110px, calc((100% - 72px) / 7)), 1fr));
    grid-auto-rows: max-content; 
    gap: 12px; 
    width: 100%; 
    flex: 1 1 0px; 
    padding: 10px; 
    align-content: start;
    overflow-y: auto; 
    min-height: 0; 
    scrollbar-width: thin;
    scrollbar-color: var(--highlight-primary) var(--bg-tertiary);
}

.sib-grid::-webkit-scrollbar { width: 10px; height: 10px; }
.sib-grid::-webkit-scrollbar-track { background: var(--bg-tertiary); border-radius: 8px; }
.sib-grid::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, var(--highlight-primary), var(--highlight-secondary));
    border-radius: 8px; border: 2px solid rgba(0, 0, 0, 0.25);
}
.sib-grid::-webkit-scrollbar-thumb:hover { filter: brightness(1.1); }

@keyframes sibSlideIn {
    from { opacity: 0; transform: translateY(10px) scale(0.95); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.sib-card {
    width: 100%;
    height: auto;
    min-height: auto;
    aspect-ratio: 1 / 1; 
    background-color: var(--bg-primary); 
    border: 1px solid var(--border-color);
    border-radius: 4px; display: flex; flex-direction: column; justify-content: flex-end; 
    cursor: pointer; box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.2); 
    user-select: none; position: relative; overflow: hidden;
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
    opacity: 0;
    animation: sibSlideIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.sib-card:hover { transform: translateY(-4px); box-shadow: 0 8px 16px rgba(0,0,0,0.4); }
.sib-card.selected { border-color: var(--success-color); border-width: 3px; transform: scale(0.96); }

.sib-card-checkmark {
    position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
    background: var(--success-color); color: white;
    width: 40px; height: 40px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.5em; font-weight: bold;
    opacity: 0; transition: opacity 0.2s; z-index: 10;
    box-shadow: 0 0 15px rgba(0,0,0,0.5);
}
.sib-card.selected .sib-card-checkmark { opacity: 1; }

.sib-card-img {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-size: cover;
    background-position: center; z-index: 1; background-color: var(--bg-primary);
    transition: opacity 0.8s ease; 
}
.sib-card.selected .sib-card-img { opacity: 0.5; }

.sib-card-info {
    position: relative; z-index: 2; background: rgba(var(--bg-tertiary-rgb), 0.90);
    padding: 5px; width: 100%; text-align: center; display: flex; flex-direction: column;
    justify-content: center; align-items: center; gap: 2px; min-height: auto;
    transition: opacity 0.8s ease;
}
.sib-card-name {
    font-size: 0.85em; line-height: 1.2; font-weight: bold; color: #fff;
    display: block; width: 100%; white-space: nowrap; overflow: hidden;
    text-overflow: ellipsis; position: relative; padding-right: 0;
}
.sib-card-name.overflows { padding-right: 18px; }
.sib-card-name.overflows::after {
    content: '🔍'; position: absolute; right: 0; top: 50%; transform: translateY(-50%);
    font-size: 0.7em; opacity: 0.7; filter: grayscale(1); pointer-events: none;
}

@media (hover: hover) {
    .sib-card-info.can-expand:hover .sib-card-name {
        white-space: normal; word-wrap: break-word; overflow: visible; padding-right: 0 !important;
    }
    .sib-card-info.can-expand:hover .sib-card-name::after { display: none; }
}
.sib-card-info.can-expand.expanded .sib-card-name {
    white-space: normal; word-wrap: break-word; overflow: visible; padding-right: 0 !important;
}
.sib-card-info.can-expand.expanded .sib-card-name::after { display: none; }

.sib-card-info-btn {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--bg-secondary);
    color: var(--highlight-primary);
    border: 2px solid var(--highlight-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 14px;
    cursor: pointer;
    z-index: 10;
    box-shadow: 0 2px 5px rgba(0,0,0,0.4);
    transition: opacity 0.8s ease, transform 0.2s, background-color 0.2s, color 0.2s;
    font-family: serif;
    font-style: italic;
}
.sib-card-info-btn:hover {
    transform: scale(1.1);
    background: var(--highlight-primary);
    color: white;
}

#sib-grid-container.images-hidden .sib-card-img,
#sib-grid-container.images-hidden .sib-card-info,
#sib-grid-container.images-hidden .sib-card-info-btn {
    opacity: 0 !important;
    transition: none !important; 
}

#stay-in-budget-game-view .game-view-main {
    overflow: hidden !important; 
    justify-content: flex-start; 
    align-items: stretch;
}

#sib-reveal-container {
    flex: 1 1 0px; 
    min-height: 0; 
    max-height: 100%;
    width: 100%;
    overflow: hidden;
}

#sib-reveal-container .sib-player-col {
    min-height: 0;
    max-height: 100%;
    overflow: hidden;
}

#sib-reveal-container .mtp-col-cards {
    flex: 1 1 100%;
    overflow-y: auto;
    min-height: 0;
    scrollbar-width: thin;
    scrollbar-color: var(--highlight-primary) var(--bg-tertiary);
}

#sib-reveal-container .mtp-col-cards::-webkit-scrollbar { 
    width: 10px; 
    height: 10px; 
}
#sib-reveal-container .mtp-col-cards::-webkit-scrollbar-track { 
    background: var(--bg-tertiary); 
    border-radius: 8px; 
}
#sib-reveal-container .mtp-col-cards::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, var(--highlight-primary), var(--highlight-secondary));
    border-radius: 8px; 
    border: 2px solid rgba(0, 0, 0, 0.25);
}
#sib-reveal-container .mtp-col-cards::-webkit-scrollbar-thumb:hover { 
    filter: brightness(1.1); 
}

.sib-col-total { font-size: 1.5em; font-weight: bold; color: var(--success-color); }
.sib-col-total.over-budget { color: var(--error-color); text-decoration: line-through; animation: orderItShake 0.5s; }
.sib-player-col.winner-col { border-color: #FFD700; box-shadow: 0 0 20px rgba(255, 215, 0, 0.4); }

.sib-item-hover-preview {
    position: fixed;
    pointer-events: none;
    z-index: 10000;
    display: none;
    flex-direction: column;
    width: 160px;
    background: var(--bg-secondary);
    border: 2px solid var(--highlight-primary);
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.6);
    overflow: hidden;
    animation: sibPreviewFade 0.15s ease-out forwards;
}

@keyframes sibPreviewFade {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.sib-item-hover-preview img {
    width: 100%;
    height: 160px;
    object-fit: cover;
    background: var(--bg-primary);
    display: block;
}

.sib-item-hover-preview .preview-name {
    padding: 8px;
    text-align: center;
    font-size: 0.9em;
    line-height: 1.2;
    font-weight: bold;
    color: #fff;
    background: rgba(var(--bg-tertiary-rgb), 0.95);
}

/* ----------------------------------------------------
   Mobile Overrides for Stay in Budget
   ---------------------------------------------------- */
@media (max-width: 768px) {
    #stay-in-budget-game-view .game-view-caption {
        padding: 40px 0 0 0 !important;
        margin-bottom: 10px;
        text-align: center;
    }

    #sib-budget-display {
        text-align: center;
    }

    .digit-box {
        font-size: min(13vw, 3.5rem);
    }
    
    .sib-card-name {
        font-size: 0.8rem;
    }
    
    .sib-card-info.can-expand:active .sib-card-name,
    .sib-card-info.can-expand:focus .sib-card-name {
        white-space: normal; 
        word-wrap: break-word; 
        overflow: visible; 
        padding-right: 0 !important;
    }
    
    .sib-card-info.can-expand:active .sib-card-name::after,
    .sib-card-info.can-expand:focus .sib-card-name::after {
        display: none;
    }

    #stay-in-budget-game-view {
        height: auto !important;
        min-height: max-content !important;
        flex-shrink: 0 !important;
    }

    #stay-in-budget-game-view .game-view-main {
        overflow: visible !important;
        height: auto !important;
        min-height: max-content !important;
        flex-shrink: 0 !important;
    }

    .sib-grid {
        height: auto !important;
        min-height: max-content !important;
        flex-shrink: 0 !important;
        overflow: visible !important;
        grid-template-columns: repeat(auto-fill, minmax(min(110px, calc((100% - 24px) / 3)), 1fr));
    }

    #sib-reveal-container {
        display: flex;
        flex-direction: row;
        justify-content: center;
        flex-wrap: wrap;
        gap: 20px;
        height: auto !important;
        min-height: max-content !important;
        max-height: none !important;
        overflow: visible !important;
        flex-shrink: 0 !important;
    }

    #sib-reveal-container .sib-player-col {
        width: 250px;
        max-width: 100%;
        height: 500px; 
        max-height: none;
        overflow: hidden;
        margin-bottom: 0;
        background: var(--bg-secondary);
        border-radius: 8px;
    }

    #sib-reveal-container .mtp-col-cards {
        flex: 1 1 auto;
        overflow-y: auto;
    }
}