/* ===== شكل صحنك — ورقة أنماط مستقلة (assets/css/plate.css) =====
 *
 * كل ما يخصّ منصّة تركيب الصحن: الزر العائم، النافذة، المسرح ثلاثي الأبعاد،
 * الطبقات، والبطاقات. الصور كلها من assets/img/plate (يولّدها tools/make_food.py).
 *
 * الميل: --tilt-x / --tilt-y يحدّدهما assets/js/plate.js من حركة المؤشر/اللمس،
 * وتعتمد الطبقات على translateZ داخل perspective فتنشأ أعماق حقيقية بلا مكتبات.
 */

/* ------------------------------------------------------------- الزر العائم */
.plate-fab {
    position: fixed;
    bottom: 90px;
    right: 16px;
    z-index: 1050;
    display: flex;
    align-items: center;
    gap: 7px;
    background: var(--primary);
    color: #fff;
    border: 2px solid var(--accent);
    border-radius: 50px;
    padding: 10px 16px;
    font-family: 'Tajawal', sans-serif;
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
    box-shadow: 0 6px 18px rgba(26, 26, 78, 0.35);
    transition: transform 0.2s, background 0.2s;
}
.plate-fab:hover { transform: translateY(-2px); background: #232363; }
.plate-fab svg { color: var(--accent); flex-shrink: 0; }
@media (min-width: 992px) { .plate-fab { bottom: 28px; } }

/* --------------------------------------------------------------- النافذة */
.plate-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 15, 35, 0.6);
    backdrop-filter: blur(3px);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s;
}
.plate-overlay.open { opacity: 1; visibility: visible; }
.plate-modal {
    background: #fff;
    border-radius: 16px;
    width: 100%;
    max-width: 520px;
    max-height: 92vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: translateY(24px);
    transition: transform 0.25s;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}
.plate-overlay.open .plate-modal { transform: translateY(0); }
.plate-modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    background: var(--primary);
    color: #fff;
}
.plate-modal-head h3 { margin: 0; font-size: 1.05rem; font-weight: 700; }
.plate-close {
    background: rgba(255, 255, 255, 0.12);
    border: none;
    color: #fff;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}
.plate-close:hover { background: var(--accent); }
.plate-modal-body { padding: 16px; overflow-y: auto; }
.plate-stage-wrap { display: flex; justify-content: center; }

/* ------------------------------------------------- المسرح: تصوير علوي 3D */
.plate-stage {
    position: relative;
    width: min(92vw, 420px);
    aspect-ratio: 1 / 1;
    margin: 6px auto;
    overflow: hidden;
    perspective: 1200px;
    perspective-origin: 50% 34%;
    --tilt-x: 4deg;      /* السكون: علوٍ شبه مباشر كما في الفيديو */
    --tilt-y: 0deg;
    --sh-x: 0px;
    --sh-y: 14px;
    touch-action: pan-y;
}
.plate-base {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: #b7bcc2 url('../img/plate/base.webp') center / cover no-repeat;
    box-shadow:
        var(--sh-x, 0px) var(--sh-y, 14px) 34px rgba(0, 0, 0, 0.34),
        0 3px 8px rgba(0, 0, 0, 0.18);
    transform: rotateX(var(--tilt-x)) rotateY(var(--tilt-y)) scale(1.02);
    transition: transform 0.22s cubic-bezier(.2, .85, .3, 1), box-shadow 0.22s ease-out;
    z-index: 1;
}
/* مستوى واحد لكل المكوّنات: يدور بنفس زاوية الصحن فتبدو كلها على سطحه */
.plate-heap {
    position: absolute;
    inset: 0;
    transform: rotateX(var(--tilt-x)) rotateY(var(--tilt-y));
    transform-style: preserve-3d;
    transition: transform 0.22s cubic-bezier(.2, .85, .3, 1);
    z-index: 3;
    pointer-events: none;
}
.plate-empty-hint {
    position: absolute;
    inset: 0;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    font-size: 0.82rem;
    font-weight: 700;
    color: #fff;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.75);
    background: rgba(0, 0, 0, 0.28);
    border-radius: 50%;
    padding: 30px;
    margin: 0;
    pointer-events: none;
}

/* ---------------------------------------------------------- طبقات الصحن */
.plate-layer {
    position: absolute;
    z-index: 3;
    transform: translate(-50%, -50%);
    pointer-events: none;
    opacity: 0;
    animation: plateLayerIn 0.3s forwards;
    display: block;
}
/* قاعدة الطبق: قرص الأرز الذي يملأ الوعاء حتى الحافة (بلا قصّ — الصورة قرص أصلاً) */
.plate-layer.is-base {
    z-index: 1;
    filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.22));
}
/* القطع الموضوعة فوق الأرز: مرفوعة بعمق حقيقي وظل أسفلها */
.plate-layer.is-top {
    z-index: 2;
    filter: drop-shadow(0 5px 6px rgba(0, 0, 0, 0.36));
}
.plate-layer-media {
    display: block;
    width: 100%;
    height: auto;
    transform: scale(0.7) translateY(-12px);
    animation: platePop 0.36s cubic-bezier(.2, .9, .25, 1.25) forwards;
}
.plate-layer-qty {
    position: absolute;
    top: -4px;
    inset-inline-end: -4px;
    min-width: 22px;
    height: 22px;
    padding: 0 5px;
    border-radius: 11px;
    background: var(--primary);
    color: #fff;
    font-size: 0.72rem;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}
@keyframes plateLayerIn {
    to { opacity: 1; }
}
@keyframes platePop {
    from { transform: scale(0.7) translateY(-12px); }
    to { transform: scale(1) translateY(0); }
}

/* --------------------------------------------------------------- البطاقات */
.plate-chips { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 8px; margin-top: 16px; }
.plate-chips-sep {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 20px;
    color: var(--primary);
    font-size: 0.8rem;
    font-weight: 800;
}
.plate-chips-sep::before,
.plate-chips-sep::after {
    content: "";
    flex: 1;
    height: 1px;
    background: #e4e4ea;
}
.plate-chips-sep span { flex-shrink: 0; }
.plate-chip {
    display: grid;
    grid-template-columns: 40px minmax(0, 1fr) auto;
    grid-template-rows: auto auto auto;
    align-items: center;
    column-gap: 6px;
    row-gap: 2px;
    padding: 8px;
    border: 1.5px solid var(--border, #e2e2e8);
    border-radius: 10px;
    background: #fff;
    transition: all 0.15s;
    margin: 0;
    cursor: pointer;
    user-select: none;
}
.plate-chip:hover { border-color: var(--accent); background: #fff8f2; }
.plate-chip.is-active { border-color: var(--accent); background: #fff3e8; box-shadow: 0 0 0 1px var(--accent); }
/* الإضافات مقفلة إلى أن يُضاف الأرز إلى الصحن */
.plate-chip.is-locked { opacity: 0.45; filter: grayscale(0.4); cursor: not-allowed; }
.plate-chip.is-locked:hover { border-color: var(--border, #e2e2e8); background: #fff; }
.plate-chip.is-locked .plate-stepper { pointer-events: none; }
.plate-chip.shake { animation: plateShake 0.36s ease; }
@keyframes plateShake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    50% { transform: translateX(5px); }
    75% { transform: translateX(-3px); }
}
.plate-chip-img { grid-column: 1; grid-row: 1 / 4; width: 40px; height: 40px; object-fit: contain; background: #f4f4f7; border-radius: 50%; flex-shrink: 0; padding: 3px; }
.plate-chip-img-ph { display: flex; align-items: center; justify-content: center; font-weight: 800; color: var(--accent); font-size: 0.85rem; }
.plate-chip-name { grid-column: 2 / 4; grid-row: 1; font-size: 0.78rem; font-weight: 700; color: var(--primary); white-space: normal; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; line-height: 1.25; align-self: center; }
/* السعر سطرٌ وحده (صفّ 2) والزرّان سطرٌ آخر (صفّ 3): فلا يغطّي أحدهما الآخر
   مهما ضاقت الرقاقة، ويبقى المبلغ مقروءاً تحت الاسم. */
.plate-chip-price { grid-column: 2 / 4; grid-row: 2; font-size: 0.66rem; color: var(--accent); font-weight: 800; white-space: nowrap; align-self: center; min-width: 0; }
.plate-stepper { grid-column: 2 / 4; grid-row: 3; display: flex; align-items: center; gap: 4px; flex-shrink: 0; justify-self: start; }
.plate-stepper .stepper-val { min-width: 12px; text-align: center; font-weight: 800; font-size: 0.72rem; color: var(--primary); }
.plate-stepper .stepper-btn { width: 20px; height: 20px; border-radius: 6px; border: 1px solid var(--border, #e2e2e8); background: #fff; color: var(--primary); font-weight: 800; font-size: 0.75rem; line-height: 1; cursor: pointer; padding: 0; }
.plate-stepper .stepper-btn:hover { border-color: var(--accent); color: var(--accent); }
.plate-stepper .stepper-plus { background: var(--accent); border-color: var(--accent); color: #fff; }
.plate-stepper .stepper-plus:hover { background: var(--accent-hover); color: #fff; }

/* ------------------------------------------------------------- الشريط السفلي */
.plate-modal-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
    padding: 12px 16px;
    border-top: 1px solid #eee;
    background: #fafafa;
}
.plate-total-wrap { display: flex; flex-direction: column; }
.plate-total-label { font-size: 0.7rem; color: #888; }
.plate-total { font-size: 1rem; font-weight: 800; color: var(--primary); }
.plate-add-btn {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: 11px 18px;
    font-family: 'Tajawal', sans-serif;
    font-weight: 700;
    font-size: 0.88rem;
    cursor: pointer;
    transition: background 0.2s;
}
.plate-add-btn:hover { background: var(--accent-hover); }
