/* --- Order It --- */
#order-it-player-lives-area {
    display: flex; flex-wrap: wrap; justify-content: center; gap: 15px; padding: 10px;
    background-color: var(--bg-secondary); border-radius: 6px; flex-grow: 1;
}
.order-it-player-life-entry { display: flex; align-items: center; gap: 8px; }
.order-it-player-life-entry.eliminated { opacity: 0.6; }
.order-it-player-life-entry.current-turn .order-it-player-life-name { color: var(--highlight-secondary); font-weight: bold; }
.order-it-player-life-icon { width: 24px; height: 24px; border-radius: 50%; object-fit: cover; }
.order-it-player-life-name { font-size: 0.9em; font-weight: 500; }
.order-it-player-life-hearts { font-size: 1em; color: var(--error-color); letter-spacing: 1px; }

#order-it-scale-container, #order-it-unplaced-container {
    width: 100%; padding: 10px; background-color: var(--bg-secondary); border-radius: 6px;
    min-height: 200px; display: flex; flex-direction: column; /* Increased min-height for stability */
}
#order-it-scale-container { position: relative; }
.order-it-direction-indicator {
    position: absolute; width: 30px; top: 5px; bottom: 5px; z-index: 200;
    box-sizing: border-box; border-radius: 4px; background-color: var(--bg-tertiary);
    color: var(--highlight-secondary); display: flex; justify-content: center; align-items: center;
    font-size: 1.5em; font-weight: bold; user-select: none;
    transition: all 0.2s ease;
    border: 1px solid transparent;
}
.order-it-direction-indicator.clickable {
    cursor: pointer;
    background-color: rgba(var(--bg-tertiary-rgb), 0.8);
    border-color: var(--highlight-secondary);
    color: #fff;
    box-shadow: 0 0 10px rgba(var(--highlight-secondary-rgb), 0.3);
}
.order-it-direction-indicator.clickable:hover {
    background-color: var(--highlight-secondary);
    color: var(--bg-primary);
    transform: scaleX(1.1);
}
.order-it-direction-indicator.disabled {
    opacity: 0.3;
    cursor: not-allowed;
    pointer-events: none;
}
#order-it-direction-indicator-left { left: 5px; }
#order-it-direction-indicator-right { right: 5px; }

#order-it-unplaced-container h5 { margin-bottom: 10px; text-align: center; color: var(--text-secondary); }
#order-it-unplaced-items-area {
    display: flex; flex-wrap: nowrap; gap: var(--order-it-grid-gap); padding: 10px;
    border: 1px dashed var(--border-color); border-radius: 4px; flex-grow: 1; min-height: 0;
    min-height: calc(var(--dynamic-item-size, 100px) + 20px); justify-content: safe center; align-items: safe center;
    overflow-x: scroll; overflow-y: hidden;
    scrollbar-width: thin !important;
    scrollbar-color: transparent transparent !important;
    transition: scrollbar-color 0.2s ease !important;
}
#order-it-scale-area {
    display: flex; gap: var(--order-it-grid-gap); min-height: calc(var(--dynamic-item-size, 100px) + 20px);
    justify-content: safe center; align-items: safe center; position: relative; border: 1px dashed var(--border-color);
    border-radius: 4px; flex-grow: 1; min-height: 0;
    overflow-x: scroll; overflow-y: hidden;
    margin-left: 35px; margin-right: 35px;
    padding: 10px;
    scrollbar-width: thin !important;
    scrollbar-color: transparent transparent !important;
    transition: scrollbar-color 0.2s ease !important;
}
#order-it-scale-area:hover,
#order-it-scale-container:hover #order-it-scale-area,
#order-it-unplaced-items-area:hover,
#order-it-unplaced-container:hover #order-it-unplaced-items-area {
    scrollbar-color: var(--border-color) transparent !important;
}
#order-it-scale-area::-webkit-scrollbar,
#order-it-unplaced-items-area::-webkit-scrollbar {
    width: 6px !important;
    height: 6px !important;
}
#order-it-scale-area::-webkit-scrollbar-track,
#order-it-unplaced-items-area::-webkit-scrollbar-track {
    background: transparent !important;
}
#order-it-scale-area::-webkit-scrollbar-thumb,
#order-it-unplaced-items-area::-webkit-scrollbar-thumb {
    background: transparent !important;
    border: none !important;
    border-radius: 3px !important;
}
#order-it-scale-area:hover::-webkit-scrollbar-thumb,
#order-it-scale-container:hover #order-it-scale-area::-webkit-scrollbar-thumb,
#order-it-unplaced-items-area:hover::-webkit-scrollbar-thumb,
#order-it-unplaced-container:hover #order-it-unplaced-items-area::-webkit-scrollbar-thumb {
    background: var(--border-color) !important;
}
#order-it-scale-area::-webkit-scrollbar-thumb:hover,
#order-it-unplaced-items-area::-webkit-scrollbar-thumb:hover {
    background: var(--highlight-primary) !important;
}
.order-it-slot-container {
    flex: 0 0 var(--dynamic-item-size, 100px);
    width: var(--dynamic-item-size, 100px);
    height: var(--dynamic-item-size, 100px);
    position: relative;
    box-sizing: border-box;
}
.order-it-slot-container .order-it-item {
    width: 100% !important;
    height: 100% !important;
}

.order-it-scale-slot {
    border: 2px dashed var(--border-color); border-radius: 4px; display: flex; justify-content: safe center;
    align-items: safe center; font-size: 2em; font-weight: bold; color: var(--text-secondary); flex-shrink: 0; user-select: none;
}
.order-it-scale-slot.fading-out { animation: fadeOut 0.5s ease forwards; }

@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
.order-it-scale-slot.drop-hover { background-color: color-mix(in srgb, rgb(var(--highlight-primary-rgb)) 15%, var(--bg-secondary)); }

.order-it-item {
    width: var(--dynamic-item-size, 100px); height: var(--dynamic-item-size, 100px); background-color: var(--bg-tertiary); border: 1px solid var(--border-color);
    border-radius: 4px; display: flex; flex-direction: column; justify-content: flex-end; cursor: grab;
    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, opacity 0.2s ease, border-color 0.2s ease;
    flex-shrink: 0;
}
.order-it-item.dragging { opacity: 0.5 !important; cursor: grabbing !important; transform: scale(1.05); }
.order-it-item.pending-confirmation { border-color: var(--warning-color); border-style: dashed; }
.order-it-item.preview-placement { border-color: var(--highlight-secondary); border-style: dotted !important; opacity: 0.6; }
.order-it-item.order-it-item-awaiting-reveal { border-color: var(--highlight-primary); }

.order-it-item-img-placeholder {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-size: cover;
    background-position: center; z-index: 1; background-color: var(--bg-primary);
}
.order-it-item-info {
    position: relative; z-index: 2; background: rgba(var(--bg-tertiary-rgb), 0.90);
    padding: var(--item-padding-scale, 5px); width: 100%; text-align: center; display: flex; flex-direction: column;
    justify-content: center; align-items: center; gap: 2px; min-height: auto;
    font-size: calc(var(--item-font-scale, 1) * 1em);
}
.order-it-item-name {
    font-size: 0.7em; 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;
}
.order-it-item-name.overflows { padding-right: 18px; }
.order-it-item-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;
}
.order-it-item-value { font-size: 0.6em; line-height: 1.1; color: var(--highlight-secondary); }

/* Missing classes restored */
.order-it-item-shaking {
    animation: orderItShake 0.82s cubic-bezier(.36, .07, .19, .97) both infinite;
    transform: translate3d(0, 0, 0);
}
.order-it-item-glowing {
    border-color: var(--highlight-primary) !important;
    animation: orderItGlow 1.5s ease-in-out infinite alternate;
}
.order-it-item-flash-correct {
    --feedback-flash-bg-color: rgba(46, 204, 113, 0.4);
    --feedback-flash-border-color: var(--success-color);
    animation: orderItFlashFeedback 3s ease-out forwards;
}
.order-it-item-flash-incorrect {
    --feedback-flash-bg-color: rgba(231, 76, 60, 0.4);
    --feedback-flash-border-color: var(--error-color);
    animation: orderItFlashFeedback 3s ease-out forwards;
}

@keyframes orderItFlashFeedback {
    0% { background-color: var(--feedback-flash-bg-color); border-color: var(--feedback-flash-border-color); box-shadow: 0 0 15px var(--feedback-flash-border-color); }
    10% { background-color: var(--feedback-flash-bg-color); border-color: var(--feedback-flash-border-color); box-shadow: 0 0 25px var(--feedback-flash-border-color); }
    100% { background-color: transparent; border-color: transparent; box-shadow: none; }
}

@keyframes orderItShake { 
    10%, 90% { transform: translate3d(-1px, 0, 0); } 
    20%, 80% { transform: translate3d(2px, 0, 0); } 
    30%, 50%, 70% { transform: translate3d(-3px, 0, 0); } 
    40%, 60% { transform: translate3d(3px, 0, 0); } 
}

@keyframes orderItGlow { 
    from { box-shadow: 0 0 5px 2px rgba(var(--highlight-primary-rgb), 0.4); } 
    to { box-shadow: 0 0 15px 5px rgba(var(--highlight-primary-rgb), 0.7); } 
}

@keyframes orderItTimerPulse { 
    0% { transform: scale(1); opacity: 1; } 
    50% { transform: scale(1.1); opacity: 0.8; } 
    100% { transform: scale(1); opacity: 1; } 
}

.order-it-container-flash-correct {
    animation: orderItContainerFlashCorrect 3s ease-out forwards;
}
.order-it-container-flash-incorrect {
    animation: orderItContainerFlashIncorrect 3s ease-out forwards;
}

@keyframes orderItContainerFlashCorrect {
    0% { box-shadow: inset 0 0 0px rgba(46, 204, 113, 0); }
    10% { box-shadow: inset 0 0 60px rgba(46, 204, 113, 0.8); }
    100% { box-shadow: inset 0 0 0px rgba(46, 204, 113, 0); }
}
@keyframes orderItContainerFlashIncorrect {
    0% { box-shadow: inset 0 0 0px rgba(231, 76, 60, 0); }
    10% { box-shadow: inset 0 0 60px rgba(231, 76, 60, 0.8); }
    100% { box-shadow: inset 0 0 0px rgba(231, 76, 60, 0); }
}

#order-it-turn-timer {
    display: inline-block; font-size: 1.4em; color: white; margin-left: 12px;
    vertical-align: middle; text-shadow: 0 1px 2px rgba(0,0,0,0.5);
    font-variant-numeric: tabular-nums; min-width: 2ch;
}
#order-it-turn-timer.critical { color: var(--error-color); animation: orderItTimerPulse 1s infinite; }
#order-it-controls-area { display: flex; justify-content: center; align-items: center; flex-wrap: wrap; gap: 15px; margin-top: auto; padding-top: 15px; }
.order-it-host-controls-wrapper { display: flex; gap: 15px; justify-content: center; align-items: center; flex-wrap: wrap; }
.order-it-header-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    gap: 15px;
}

@media (hover: hover) {
    .order-it-item-info.can-expand:hover .order-it-item-name {
        white-space: normal; word-wrap: break-word; overflow: visible; padding-right: 0 !important;
    }
    .order-it-item-info.can-expand:hover .order-it-item-name::after { display: none; }
}
.order-it-item-info.can-expand.expanded .order-it-item-name {
    white-space: normal; word-wrap: break-word; overflow: visible; padding-right: 0 !important;
}
.order-it-item-info.can-expand.expanded .order-it-item-name::after { display: none; }

@media (max-width: 600px) {
    #order-it-game-view .game-view-main { flex-direction: row; align-items: stretch; gap: 10px; overflow-y: hidden; }
    #order-it-scale-container { flex: 1; display: flex; flex-direction: column; align-items: stretch; overflow: hidden; position: relative; padding: 10px; }
    .order-it-direction-indicator { width: auto; left: 5px; right: 5px; height: 30px; }
    #order-it-direction-indicator-left { top: auto; bottom: 5px; }
    #order-it-direction-indicator-right { bottom: auto; top: 5px; }

    #order-it-unplaced-container { flex: 1; max-height: none; display: flex; flex-direction: column; overflow: hidden; }
    #order-it-scale-area { flex-direction: column-reverse; flex-grow: 1; min-height: 0; justify-content: flex-start; align-items: center; padding: 10px; margin-top: 35px; margin-bottom: 35px; margin-left: 0; margin-right: 0; overflow-y: scroll; overflow-x: hidden; }
    #order-it-unplaced-items-area { flex-direction: column; align-items: center; justify-content: center; flex-grow: 1; padding: 5px; border: 1px dashed var(--border-color); flex-wrap: nowrap; overflow-y: scroll; overflow-x: hidden; }

    .order-it-slot-container {
        flex: 0 0 var(--dynamic-item-size, 100px);
        width: var(--dynamic-item-size, 100px);
        height: var(--dynamic-item-size, 100px);
        position: relative;
    }
}

body.is-spectator #order-it-confirm-button {
    display: none !important;
}

/* Keep the scroll containers interactive; spectators cannot manipulate items. */
body.is-spectator #order-it-scale-area .order-it-item,
body.is-spectator #order-it-unplaced-items-area .order-it-item {
    pointer-events: auto !important;
}

body.is-spectator .order-it-direction-indicator {
    display: none !important;
}

.order-it-duck-success-anim {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 120%;
    height: 120%;
    max-width: 150px;
    max-height: 150px;
    object-fit: contain;
    z-index: 10;
    pointer-events: none;
    transform-origin: center;
    animation: orderItDuckAnim 1.5s ease-in-out forwards;
}

@keyframes orderItDuckAnim {
    0% {
        transform: translate(-50%, -50%) scale(0) rotate(0deg);
        opacity: 0;
    }
    15% {
        transform: translate(-50%, -50%) scale(1.3) rotate(var(--tilt-angle, 0deg));
        opacity: 1;
    }
    30% {
        transform: translate(-50%, -50%) scale(1.0) rotate(var(--tilt-angle, 0deg));
        opacity: 1;
    }
    70% {
        transform: translate(-50%, -50%) scale(1.0) rotate(var(--tilt-angle, 0deg));
        opacity: 1;
    }
    100% {
        transform: translate(-50%, -50%) scale(0) rotate(0deg);
        opacity: 0;
    }
}

