/* ===== شكل صحنك — صفحة التشكيل بملء الشاشة (assets/css/plate-page.css) =====
 *
 * الفلسفة البصرية: الكاميرا ثابتة تماماً فوق الصحن (زاوية 90° في السكون، بلا ميل)،
 * والعمق يأتي من ثلاثية الأبعاد نفسها لا من زاوية الكاميرا:
 *   1) الطبقات تنزاح بمقدار يتناسب مع عمقها (translateZ داخل perspective)
 *   2) ظل التماس يزحف عكس المؤشر فيبدو الصحن مرفوعاً فوق الطاولة
 *   3) بريق ضوئي يتبع المؤشر + شريط ضوء يمرّ ببطء فوق السطح
 *   4) دخان خفيف يتصاعد فوق الرز، وقطع تهبط بحركة موزّعة
 *
 * المتغيّرات: --px/--py تحدّدهما assets/js/plate-page.js، و--gx/--gy/--sh-x/--sh-y
 * تحدّدها assets/js/plate.js (حزمة الميل الحيّ).
 */

/* --------------------------------------------------------------- الصفحة */
.pl-page {
    position: relative;
    padding: 14px clamp(10px, 2.5vw, 26px) 46px;
    background:
        radial-gradient(1200px 520px at 88% -10%, rgba(255, 176, 82, 0.10), transparent 60%),
        radial-gradient(900px 460px at 6% 4%, rgba(26, 26, 78, 0.07), transparent 62%);
    min-height: calc(100vh - 168px);
}

/* --------------------------------------------------------------- الترويسة */
.pl-head {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
    margin-bottom: 14px;
}
.pl-back {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--primary);
    text-decoration: none;
    background: #fff;
    border: 1px solid var(--border, #e6e6ec);
    border-radius: 50px;
    padding: 8px 14px;
    transition: all 0.18s;
}
.pl-back:hover { border-color: var(--accent); color: var(--accent); }
.pl-back svg { transform: scaleX(-1); }
.pl-head-text { flex: 1 1 240px; min-width: 0; }
.pl-head-text h1 {
    margin: 0;
    font-size: clamp(1.05rem, 2.3vw, 1.45rem);
    font-weight: 800;
    color: var(--primary);
    line-height: 1.3;
}
.pl-head-text p { margin: 2px 0 0; font-size: 0.78rem; color: var(--text-muted, #8a8a97); }
.pl-clear {
    background: transparent;
    border: 1px solid var(--border, #e6e6ec);
    color: var(--text-muted, #8a8a97);
    border-radius: 50px;
    padding: 8px 14px;
    font-family: 'Tajawal', sans-serif;
    font-size: 0.78rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.18s;
}
.pl-clear:hover { border-color: #d9534f; color: #d9534f; background: #fff5f5; }
.pl-off {
    background: #fff;
    border: 1px dashed var(--border, #e6e6ec);
    border-radius: 14px;
    padding: 40px 20px;
    text-align: center;
    color: var(--text-muted, #8a8a97);
    font-size: 0.9rem;
    font-weight: 700;
}

/* -------------------------------------------------------------- التخطيط */
.pl-grid {
    display: grid;
    /* RTL: العمود 1 يميناً — اللوحة 386px ثابتة عن يمين، والمسرح يأخذ الباقي */
    grid-template-columns: minmax(330px, 386px) minmax(0, 1fr);
    gap: clamp(14px, 2.4vw, 30px);
    align-items: start;
}
.pl-stage-wrap { grid-column: 2; grid-row: 1; }   /* RTL: العمود 1 يمين — اللوحة تبدأ من اليمين */
.pl-panel { grid-column: 1; grid-row: 1; }

/* --------------------------------------------------------------- اللوحة */
.pl-panel {
    position: sticky;
    top: 12px;
    background: #fff;
    border: 1px solid var(--border, #e6e6ec);
    border-radius: 18px;
    padding: 12px 14px 14px;
    box-shadow: 0 14px 34px rgba(20, 20, 60, 0.07);
    max-height: calc(100vh - 40px);
    overflow-y: auto;
}
.pl-panel::-webkit-scrollbar { width: 6px; }
.pl-panel::-webkit-scrollbar-thumb { background: #dcdce4; border-radius: 3px; }
.pl-panel .plate-chips { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.pl-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 18px;
    padding: 12px 12px;
    border: 1px solid var(--border, #ececf1);
    border-radius: 14px;
    background: linear-gradient(180deg, #fbfbfd, #f4f4f8);
}
.pl-foot .plate-add-btn { flex: 1 1 auto; min-width: 150px; }

/* ------------------------------------------------- المسرح: تصوير علوي 90° */
.pl-stage-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}
.pl-stage {
    position: relative;
    width: min(72vh, 52vw, 620px);
    aspect-ratio: 1 / 1;
    perspective: 1400px;
    perspective-origin: 50% 50%;
    --px: 0px;
    --py: 0px;
    touch-action: pan-y;
    animation: plStageIn 0.55s cubic-bezier(0.2, 0.8, 0.3, 1) both;
    outline: none;
}
@keyframes plStageIn {
    from { opacity: 0; transform: translateY(16px) scale(0.975); }
    to { opacity: 1; transform: none; }
}

/* الطاولة: سطح دافئ مع تظليل دائري يُبرز الصحن الأبيض */
.pl-stage::before {
    content: "";
    position: absolute;
    inset: -5%;
    border-radius: 50%;
    background:
        radial-gradient(circle at 50% 32%, #fffdf8 0%, #f1ece3 52%, #ddd6c9 88%, #cfc7b8 100%);
    box-shadow: inset 0 0 70px rgba(120, 104, 78, 0.22);
}

/* ظل التماس: يزحف عكس المؤشر والاتجاه — مصدر العمق الأول */
.pl-shadow {
    position: absolute;
    inset: 3%;
    z-index: 0;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(0, 0, 0, 0.40) 0%, rgba(0, 0, 0, 0.20) 56%, transparent 72%);
    filter: blur(16px);
    transform: translate(calc(var(--px, 0px) * -1.6 + var(--sh-x, 0px)), calc(var(--py, 0px) * -1.6 + var(--sh-y, 16px)));
    transition: transform 0.22s cubic-bezier(0.2, 0.85, 0.3, 1);
}

/* الصحن الحقيقي: صورة سيراميك علوية بحواف شفافة (يجهّزها tools/make_photos.py) */
.pl-plate {
    position: absolute;
    inset: 0;
    z-index: 1;
    background: url('../img/plate/base.webp') center / contain no-repeat;
    transform: translate(calc(var(--px, 0px) * -0.5), calc(var(--py, 0px) * -0.5));
    transition: transform 0.22s cubic-bezier(0.2, 0.85, 0.3, 1);
}

/* مستقبل الطبقات: كل قرص أرز وكل قطعة بعمقها الحقيقي (translateZ) */
.pl-heap {
    position: absolute;
    inset: 0;
    z-index: 3;
    transform-style: preserve-3d;
    pointer-events: none;
}

/* دخان خفيف فوق الرز الساخن — يظهر فقط بعد وضع الأرز */
.pl-steam {
    position: absolute;
    left: 50%;
    top: 6%;
    width: 58%;
    height: 54%;
    transform: translateX(-50%);
    z-index: 6;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.6s ease;
}
.pl-stage.has-rice .pl-steam { opacity: 1; }
.pl-steam i {
    position: absolute;
    bottom: 0;
    width: 36%;
    height: 100%;
    background: radial-gradient(ellipse at 50% 78%, rgba(255, 255, 255, 0.6), rgba(255, 255, 255, 0) 72%);
    filter: blur(13px);
    opacity: 0;
    animation: plSteam 6s ease-in-out infinite;
}
.pl-steam i:nth-child(1) { left: 6%; animation-delay: 0s; }
.pl-steam i:nth-child(2) { left: 34%; animation-delay: 2s; }
.pl-steam i:nth-child(3) { left: 62%; animation-delay: 4s; }
@keyframes plSteam {
    0% { opacity: 0; transform: translateY(16%) scaleX(0.7); }
    35% { opacity: 0.5; }
    100% { opacity: 0; transform: translateY(-72%) scaleX(1.3); }
}

/* --------------------------------------------------------- حركة الطبقات */
/* القطع تهبط من الأعلى وتستقرّ بارتداد خفيف؛ الرز يتمدّد كأنه ينتشر في الوعاء */
.pl-stage .plate-layer-media { animation: plDrop 0.5s cubic-bezier(0.16, 0.86, 0.3, 1.26) both; }
.pl-stage .plate-layer.is-base .plate-layer-media { animation: plRice 0.62s cubic-bezier(0.2, 0.8, 0.25, 1) both; }
@keyframes plDrop {
    0% { opacity: 0; transform: translateY(-58px) scale(0.5) rotate(-16deg); }
    55% { opacity: 1; }
    78% { transform: translateY(5px) scale(1.04) rotate(3deg); }
    100% { opacity: 1; transform: translateY(0) scale(1) rotate(0deg); }
}
@keyframes plRice {
    0% { opacity: 0; transform: scale(1.1); }
    55% { opacity: 1; }
    100% { opacity: 1; transform: scale(1); }
}
/* ظل القطع يتغيّر قليلاً مع ارتفاعها الحقيقي فوق الرز */
.pl-stage .plate-layer.is-base { filter: drop-shadow(0 6px 8px rgba(0, 0, 0, 0.24)); }
.pl-stage .plate-layer.is-top { filter: drop-shadow(0 9px 9px rgba(0, 0, 0, 0.40)); }

/* --------------------------------------------------------- الشاشات الصغيرة */
@media (max-width: 991px) {
    .pl-grid { grid-template-columns: 1fr; }
    .pl-stage-wrap,
    .pl-panel { grid-column: auto; grid-row: auto; }
    .pl-stage { width: min(93vw, 460px); }
    .pl-panel { position: static; max-height: none; }
}
@media (max-width: 575px) {
    .pl-page { padding-bottom: 34px; }
    .pl-head-text p { display: none; }
    .pl-stage { width: min(95vw, 400px); }
}
@media (prefers-reduced-motion: reduce) {
    .pl-steam i { animation: none; }
}
