/**
 * Eduplayify Game Template Styles: image_puzzle (لغز الصورة)
 * - حاوية مستقلة بنطاق كلاسات ipz-* لمنع أي تعارض
 * - فرض اتجاه LTR على لوحة القص فقط لتطابق إحداثيات Canvas مع الحفاظ على RTL للنصوص
 */

.ipz-wrap {
    width: 100%;
    min-width: 0;
    max-width: 1040px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    font-family: inherit;
    box-sizing: border-box;
}

.ipz-topbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    padding: 10px 14px;
}

.ipz-header-box {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1 1 260px;
    min-width: 0;
}

.ipz-header-text {
    margin: 0;
    font-size: 1.02rem;
    font-weight: 800;
    color: #0f172a;
    line-height: 1.4;
}

.ipz-tools {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}

.ipz-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 700;
    background: #eef2ff;
    color: #4338ca;
    border: 1px solid #c7d2fe;
}

.ipz-pill.is-warn {
    background: #fef3c7;
    color: #92400e;
    border-color: #fde68a;
}

.ipz-btn {
    border: 1px solid #cbd5e1;
    background: #ffffff;
    color: #1e293b;
    border-radius: 10px;
    padding: 6px 11px;
    font-size: 0.82rem;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-family: inherit;
    transition: transform 0.12s ease, border-color 0.15s ease, background 0.15s ease;
}

.ipz-btn:hover:not(:disabled) {
    border-color: #4f46e5;
    transform: translateY(-1px);
}

.ipz-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.ipz-btn.is-active {
    background: #eef2ff;
    color: #4338ca;
    border-color: #6366f1;
}

.ipz-btn.is-primary {
    background: #4f46e5;
    color: #ffffff;
    border-color: #4f46e5;
}

.ipz-btn.is-success {
    background: #10b981;
    color: #ffffff;
    border-color: #10b981;
}

.ipz-stage {
    display: grid;
    grid-template-columns: minmax(0, 1.35fr) minmax(280px, 0.95fr);
    gap: 14px;
    align-items: start;
    width: 100%;
    min-width: 0;
}

.ipz-frame-card,
.ipz-tray-card {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 16px;
    padding: 12px;
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.05);
    min-width: 0;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.ipz-progress-wrap {
    width: 100%;
    height: 7px;
    background: #f1f5f9;
    border-radius: 999px;
    overflow: hidden;
    margin-bottom: 10px;
}

.ipz-progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #4f46e5, #10b981);
    border-radius: 999px;
    transition: width 0.25s ease;
}

.ipz-frame-outer {
    background: #dde6f4;
    border: 3px solid #cbd5e1;
    border-radius: 14px;
    padding: 10px;
    box-shadow: inset 0 4px 12px rgba(15, 23, 42, 0.08);
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.ipz-board-wrap {
    position: relative;
    width: 100%;
    aspect-ratio: 4 / 3;
    margin: 0 auto;
    direction: ltr;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
}

.ipz-board-bg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    border-radius: 8px;
    pointer-events: none;
}

.ipz-slots-grid {
    position: absolute;
    inset: 0;
    display: grid;
    direction: ltr;
    z-index: 2;
}

.ipz-slot {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s ease, box-shadow 0.15s ease;
}

.ipz-slot.is-over {
    background: rgba(79, 70, 229, 0.18);
    box-shadow: inset 0 0 0 2px #4f46e5;
    border-radius: 6px;
}

.ipz-slot.is-wrong {
    background: rgba(239, 68, 68, 0.18);
    box-shadow: inset 0 0 0 2px #ef4444;
    animation: ipzShake 0.35s ease;
}

.ipz-slot.is-correct-check {
    box-shadow: inset 0 0 0 3px #10b981;
}

.ipz-slot.is-wrong-check {
    box-shadow: inset 0 0 0 3px #ef4444;
}

.ipz-slot.is-hint-pulse {
    animation: ipzPulse 0.9s ease-in-out 2;
}

.ipz-slot-prompt {
    position: relative;
    z-index: 3;
    background: rgba(255, 255, 255, 0.94);
    color: #0f172a;
    border: 1px solid rgba(15, 23, 42, 0.16);
    border-radius: 8px;
    padding: 3px 7px;
    font-size: 0.72rem;
    font-weight: 800;
    text-align: center;
    max-width: 90%;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
    pointer-events: none;
    line-height: 1.25;
}

.ipz-placed-canvas,
.ipz-placed-bg-tile {
    position: absolute;
    pointer-events: none;
    z-index: 4;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.18));
}

.ipz-placed-bg-tile {
    inset: 0;
    border-radius: 6px;
    border: 1.5px solid rgba(255, 255, 255, 0.75);
    box-sizing: border-box;
}

.ipz-placed-canvas.is-pop,
.ipz-placed-bg-tile.is-pop {
    animation: ipzPop 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}

.ipz-slot-badge {
    position: absolute;
    top: 4px;
    inset-inline-end: 4px;
    z-index: 6;
    background: rgba(15, 23, 42, 0.68);
    color: #ffffff;
    border-radius: 6px;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 1px 5px;
    pointer-events: none;
}

html[dir="rtl"] .ipz-slot-prompt,
html[dir="rtl"] .ipz-slot-badge {
    direction: rtl;
}

/* Tray */
.ipz-tray-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 4px;
}

.ipz-tray-title {
    font-size: 0.92rem;
    font-weight: 800;
    color: #0f172a;
}

.ipz-tray-hint {
    margin: 0 0 8px;
    font-size: 0.78rem;
    color: #64748b;
}

.ipz-tray {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    align-items: center;
    align-content: flex-start;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
    min-height: 190px;
    max-height: 440px;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 10px 8px;
    background: #f1f5f9;
    border: 2px dashed #cbd5e1;
    border-radius: 12px;
}

.ipz-tray-piece {
    position: relative;
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.72);
    border: 2px solid transparent;
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    transition: transform 0.14s ease, border-color 0.14s ease, box-shadow 0.14s ease, opacity 0.16s ease;
}

.ipz-tray-piece:hover {
    transform: translateY(-2px) scale(1.03);
    box-shadow: 0 6px 14px rgba(15, 23, 42, 0.12);
}

.ipz-tray-piece.is-selected {
    border-color: #4f46e5;
    background: rgba(79, 70, 229, 0.12);
    box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.18);
    transform: scale(1.05);
}

.ipz-tray-piece.is-dragging-origin {
    opacity: 0.25;
    transform: scale(0.92);
}

.ipz-tray-piece canvas,
.ipz-tray-tile {
    display: block;
    filter: drop-shadow(0 3px 6px rgba(15, 23, 42, 0.2));
    transition: transform 0.18s ease;
    pointer-events: none;
}

.ipz-tray-tile {
    border-radius: 6px;
    border: 1.5px solid rgba(255, 255, 255, 0.85);
}

.ipz-rotate-btn {
    position: absolute;
    top: -7px;
    inset-inline-end: -7px;
    width: 24px;
    height: 24px;
    border-radius: 999px;
    border: 1px solid #cbd5e1;
    background: #ffffff;
    color: #4f46e5;
    font-size: 13px;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.16);
    z-index: 3;
}

.ipz-rotate-btn:hover {
    background: #4f46e5;
    color: #ffffff;
}

.ipz-piece-clue {
    margin-top: 4px;
    font-size: 0.68rem;
    font-weight: 700;
    color: #1e293b;
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    padding: 1px 6px;
    max-width: 110px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    pointer-events: none;
}

.ipz-tray-empty {
    text-align: center;
    color: #059669;
    font-weight: 800;
    font-size: 0.92rem;
    padding: 18px;
}

.ipz-concept-card {
    margin-top: 10px;
    padding: 10px 12px;
    border-radius: 12px;
    background: rgba(79, 70, 229, 0.08);
    border: 1px solid rgba(79, 70, 229, 0.22);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.ipz-concept-title {
    font-weight: 800;
    font-size: 0.88rem;
    color: #4338ca;
}

.ipz-concept-fact {
    font-size: 0.82rem;
    color: #1e293b;
}

.ipz-quiz-box {
    background: #f8fafc;
    border: 1.5px solid #c7d2fe;
    border-radius: 14px;
    padding: 14px;
    margin-top: 4px;
}

.ipz-quiz-q {
    font-weight: 800;
    font-size: 0.95rem;
    color: #0f172a;
    margin-bottom: 10px;
}

.ipz-quiz-opts {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 8px;
}

.ipz-quiz-opt {
    border: 1.5px solid #cbd5e1;
    background: #ffffff;
    color: #0f172a;
    border-radius: 10px;
    padding: 9px 12px;
    font-size: 0.86rem;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
    text-align: start;
}

.ipz-quiz-opt:hover:not(:disabled) {
    border-color: #4f46e5;
}

.ipz-quiz-opt.is-right {
    background: #dcfce7;
    border-color: #10b981;
    color: #065f46;
}

.ipz-quiz-opt.is-wrong {
    background: #fee2e2;
    border-color: #ef4444;
    color: #991b1b;
}

.ipz-drag-ghost {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 99999;
    pointer-events: none;
    will-change: transform;
    filter: drop-shadow(0 14px 24px rgba(15, 23, 42, 0.34));
}

.ipz-frame-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 10px;
}

@media (max-width: 860px) {
    .ipz-stage {
        grid-template-columns: minmax(0, 1fr);
    }
    .ipz-tray {
        min-height: 130px;
    }
}

@media (max-width: 768px) {
    .ipz-wrap {
        gap: 8px;
    }
    .ipz-topbar {
        padding: 8px 10px;
        gap: 6px;
        border-radius: 12px;
    }
    .ipz-header-box {
        flex: 1 1 100%;
        gap: 6px;
    }
    .ipz-header-text {
        font-size: 0.9rem;
        line-height: 1.35;
    }
    .ipz-tools {
        width: 100%;
        gap: 5px;
    }
    .ipz-pill {
        padding: 3px 8px;
        font-size: 0.74rem;
    }
    .ipz-btn {
        padding: 5px 9px;
        font-size: 0.76rem;
        border-radius: 8px;
    }
    .ipz-stage {
        gap: 8px;
    }
    .ipz-frame-card,
    .ipz-tray-card {
        padding: 8px;
        border-radius: 12px;
    }
    .ipz-progress-wrap {
        height: 5px;
        margin-bottom: 6px;
    }
    .ipz-frame-outer {
        padding: 6px;
        border-width: 2px;
        border-radius: 10px;
    }
    .ipz-tray-head {
        margin-bottom: 3px;
    }
    .ipz-tray-title {
        font-size: 0.85rem;
    }
    .ipz-tray-hint {
        font-size: 0.72rem;
        margin: 0 0 6px;
        line-height: 1.35;
    }
    .ipz-tray {
        flex-wrap: nowrap;
        justify-content: flex-start;
        align-items: center;
        align-content: center;
        min-height: 98px;
        max-height: none;
        padding: 10px;
        scroll-padding-inline: 10px;
        gap: 8px;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x proximity;
        overscroll-behavior-x: contain;
        touch-action: pan-x;
        scrollbar-width: thin;
        scrollbar-color: #94a3b8 #e2e8f0;
    }
    .ipz-tray::-webkit-scrollbar {
        height: 5px;
    }
    .ipz-tray::-webkit-scrollbar-track {
        background: #e2e8f0;
        border-radius: 999px;
    }
    .ipz-tray::-webkit-scrollbar-thumb {
        background: #94a3b8;
        border-radius: 999px;
    }
    .ipz-tray-piece {
        flex: 0 0 auto;
        padding: 5px;
        border-radius: 8px;
        scroll-snap-align: start;
        touch-action: pan-x;
    }
    .ipz-rotate-btn {
        top: 2px;
        inset-inline-end: 2px;
        width: 30px;
        height: 30px;
        font-size: 15px;
    }
}

@media (max-width: 480px) {
    .ipz-wrap {
        gap: 6px;
    }
    .ipz-topbar {
        padding: 6px 8px;
    }
    .ipz-header-text {
        font-size: 0.85rem;
    }
    .ipz-frame-card,
    .ipz-tray-card {
        padding: 7px;
    }
    .ipz-frame-outer {
        padding: 5px;
    }
    .ipz-tray {
        min-height: 92px;
        padding: 8px 6px;
        gap: 6px;
    }
}

@media (hover: none) and (pointer: coarse) and (orientation: landscape) and (max-height: 520px) {
    .ipz-wrap {
        gap: 6px;
    }
    .ipz-topbar {
        padding: 5px 10px;
        gap: 6px;
    }
    .ipz-header-text {
        font-size: 0.85rem;
    }
    .ipz-stage {
        grid-template-columns: minmax(0, 1.3fr) minmax(190px, 0.9fr);
        gap: 10px;
        align-items: start;
    }
    .ipz-frame-card,
    .ipz-tray-card {
        padding: 7px;
    }
    .ipz-frame-outer {
        padding: 5px;
    }
    .ipz-tray-hint {
        display: none;
    }
    .ipz-tray {
        flex-wrap: wrap;
        justify-content: center;
        align-content: flex-start;
        min-height: 150px;
        max-height: 62vh;
        overflow-y: auto;
        overflow-x: hidden;
        scroll-snap-type: none;
        touch-action: pan-y;
    }
    .ipz-tray-piece {
        touch-action: pan-y;
    }
    .ipz-rotate-btn {
        top: -4px;
        inset-inline-end: -4px;
        width: 28px;
        height: 28px;
    }
}

@keyframes ipzPop {
    0% { transform: scale(0.84); opacity: 0.7; }
    65% { transform: scale(1.04); opacity: 1; }
    100% { transform: scale(1); }
}

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

@keyframes ipzPulse {
    0%, 100% { box-shadow: inset 0 0 0 2px transparent; }
    50% { box-shadow: inset 0 0 0 4px #f59e0b; background: rgba(245, 158, 11, 0.18); }
}

