/* ─── Container (wine-red console) ──────────────────────────────────── */
#game-root .jg-wrap {
    position: relative;
    padding: 0.75rem;
    max-width: 640px;
    margin: 0 auto;
    background: linear-gradient(180deg, #2a1010 0%, #5a1818 100%);
    border-radius: var(--jul-radius-lg, 20px);
    user-select: none;
    box-shadow: 0 8px 24px rgba(0,0,0,0.18);
}

/* ─── HUD pills ─────────────────────────────────────────────────────── */
#game-root .jg-header { display: flex; align-items: stretch; gap: 0.4rem; margin-bottom: 0.55rem; }
#game-root .jg-pill {
    flex: 1 1 0; min-width: 0;
    display: flex; align-items: center; gap: 0.45rem;
    padding: 0.32rem 0.65rem;
    background: linear-gradient(180deg, #fff8e1 0%, #fbf0c8 100%);
    border: 1px solid rgba(0,0,0,0.12); border-radius: 12px;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.7), 0 2px 4px rgba(0,0,0,0.18);
}
#game-root .jg-pill-icon { font-size: 1.2rem; line-height: 1; filter: drop-shadow(0 1px 1px rgba(0,0,0,0.15)); }
#game-root .jg-pill-body { display: flex; flex-direction: column; line-height: 1.05; min-width: 0; }
#game-root .jg-lbl { font-size: 0.6rem; letter-spacing: 0.08em; color: #8a5a1a; text-transform: uppercase; font-weight: 700; }
#game-root .jg-val { font-size: 1.2rem; font-weight: 800; color: var(--jul-red-700, #8B0000); font-variant-numeric: tabular-nums; text-shadow: 0 1px 0 rgba(255,255,255,0.5); }
#game-root .jg-audio {
    display: flex; align-items: center; gap: 0.3rem; padding: 0.28rem 0.5rem;
    background: linear-gradient(180deg, #fff8e1 0%, #fbf0c8 100%);
    border: 1px solid rgba(0,0,0,0.12); border-radius: 12px;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.7), 0 2px 4px rgba(0,0,0,0.18);
}
#game-root .jg-mute { background: transparent; border: 0; width: 26px; height: 26px; cursor: pointer; font-size: 0.95rem; padding: 0; }
#game-root .jg-vol { width: 56px; cursor: pointer; accent-color: var(--jul-red-700, #8B0000); }

/* ─── Difficulty chips ──────────────────────────────────────────────── */
#game-root .jg-modes { display: flex; gap: 0.3rem; margin-bottom: 0.6rem; }
#game-root .jg-mode {
    flex: 1 1 0; padding: 0.32rem 0.55rem; font-size: 0.8rem; font-weight: 700;
    color: #fde9a8; background: rgba(0,0,0,0.28);
    border: 1px solid rgba(255, 221, 100, 0.18); border-radius: 999px;
    cursor: pointer; letter-spacing: 0.02em;
    transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease;
}
#game-root .jg-mode:hover:not(.jg-mode--active) { background: rgba(0,0,0,0.42); color: #fff8d0; }
#game-root .jg-mode--active {
    background: linear-gradient(180deg, #fbd24a 0%, #d99b1e 100%);
    color: #4a1a05; border-color: #b8870b;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.6), 0 2px 4px rgba(0,0,0,0.3);
}

/* ─── Playfield (wood table) ────────────────────────────────────────── */
#game-root .jg-playfield {
    position: relative;
    padding: 12px;
    border: 3px solid #ffd66b; border-radius: 14px; overflow: hidden;
    background-image: url('/games/jule-jigsaw/background.jpg');
    background-size: cover; background-position: center;
    box-shadow: 0 0 0 1px rgba(0,0,0,0.4), inset 0 0 16px rgba(0,0,0,0.3);
}
#game-root .jg-board {
    position: relative; width: 100%; aspect-ratio: 600 / 450;
    border-radius: 8px; overflow: hidden;
    background: rgba(20, 10, 6, 0.28);
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.18), inset 0 0 22px rgba(0,0,0,0.4);
}
#game-root .jg-ghost {
    position: absolute; inset: 0; width: 100%; height: 100%;
    object-fit: fill; opacity: 0.16; pointer-events: none;
    transition: opacity 0.25s ease;
}
#game-root .jg-board.jg-no-ghost .jg-ghost { opacity: 0; }
#game-root .jg-board--peek .jg-ghost { opacity: 0.95 !important; }
#game-root .jg-snap {
    position: absolute; z-index: 3; pointer-events: none;
    border: 3px solid #ffe066; border-radius: 6px;
    background: rgba(255, 224, 102, 0.14);
    box-shadow: 0 0 18px rgba(255, 224, 102, 0.85), inset 0 0 14px rgba(255, 224, 102, 0.5);
    animation: jg-snap-pulse 0.7s ease-in-out infinite;
}
#game-root .jg-snap[hidden] { display: none; }
@keyframes jg-snap-pulse { 0%, 100% { opacity: 0.6; } 50% { opacity: 1; } }
#game-root .jg-loading { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #fde9a8; font-weight: 600; font-size: 0.9rem; }

#game-root .jg-piece { display: block; cursor: grab; touch-action: none; filter: drop-shadow(0 2px 3px rgba(0,0,0,0.45)); }
#game-root .jg-piece--placed { position: absolute; cursor: default; pointer-events: none; filter: none; }
#game-root .jg-piece--sel { outline: 3px solid #ffd66b; outline-offset: 2px; border-radius: 4px; transform: scale(1.06); position: relative; z-index: 2; filter: drop-shadow(0 3px 7px rgba(0,0,0,0.6)); }
#game-root .jg-piece--ghost { opacity: 0.3; }
#game-root .jg-piece--nope { animation: jg-nope 0.45s ease; }
@keyframes jg-nope { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-6px); } 40% { transform: translateX(5px); } 60% { transform: translateX(-4px); } 80% { transform: translateX(3px); } }
#game-root .jg-piece--drag { position: fixed; z-index: 1000; pointer-events: none; cursor: grabbing; filter: drop-shadow(0 8px 14px rgba(0,0,0,0.55)); }

#game-root .jg-peek {
    position: absolute; top: 18px; right: 18px; z-index: 4;
    padding: 0.3rem 0.7rem; font-size: 0.78rem; font-weight: 700;
    color: #4a1a05; background: linear-gradient(180deg, #fff8e1, #fbe6a8);
    border: 1px solid #b8870b; border-radius: 999px; cursor: pointer;
    box-shadow: 0 2px 6px rgba(0,0,0,0.35);
}
#game-root .jg-peek:active { transform: translateY(1px); }
#game-root .jg-fs {
    position: absolute; top: 18px; left: 18px; z-index: 4;
    width: 34px; height: 34px; display: flex; align-items: center; justify-content: center;
    background: rgba(0,0,0,0.45); color: #fde9a8;
    border: 1px solid rgba(255, 221, 100, 0.4); border-radius: 9px;
    font-size: 1rem; line-height: 1; cursor: pointer;
    transition: background 0.15s ease, transform 0.08s ease;
}
#game-root .jg-fs:hover { background: rgba(0,0,0,0.68); }
#game-root .jg-fs:active { transform: scale(0.94); }

/* ─── Tray ──────────────────────────────────────────────────────────── */
#game-root .jg-tray {
    display: flex; flex-wrap: wrap; align-content: flex-start; justify-content: center;
    gap: 7px; margin-top: 0.6rem; padding: 0.6rem;
    background: rgba(0,0,0,0.34); border-radius: 12px;
    box-shadow: inset 0 2px 10px rgba(0,0,0,0.55);
    max-height: 42vh; overflow-y: auto;
}
#game-root .jg-tray .jg-piece { cursor: pointer; }
#game-root .jg-tray .jg-piece { filter: drop-shadow(0 2px 3px rgba(0,0,0,0.5)); }

/* ─── Buttons ───────────────────────────────────────────────────────── */
#game-root .jg-actions { display: flex; gap: 0.4rem; justify-content: center; flex-wrap: wrap; margin-top: 0.6rem; }
#game-root .jg-btn {
    display: inline-flex; align-items: center; gap: 0.4rem; padding: 0.55rem 1.2rem;
    font-size: 0.92rem; font-weight: 700; border-radius: 999px; cursor: pointer;
    transition: transform 0.08s ease, background 0.2s ease;
}
#game-root .jg-btn--primary { background: linear-gradient(180deg, #dc2626 0%, #991b1b 100%); color: #fff; border: 1px solid #7f1d1d; box-shadow: 0 3px 8px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.3); }
#game-root .jg-btn--primary:hover { background: linear-gradient(180deg, #ef4444 0%, #b91c1c 100%); transform: translateY(-1px); }
#game-root .jg-btn--primary:active { transform: translateY(1px); }
#game-root .jg-btn--ghost { background: rgba(255, 248, 225, 0.95); color: #4a1a05; border: 1px solid rgba(0,0,0,0.12); box-shadow: inset 0 1px 0 rgba(255,255,255,0.7), 0 2px 4px rgba(0,0,0,0.18); }
#game-root .jg-btn--ghost:hover { background: #fff; transform: translateY(-1px); }
#game-root .jg-btn--ghost:active { transform: translateY(1px); }

/* ─── Win overlay ───────────────────────────────────────────────────── */
#game-root .jg-overlay { position: absolute; inset: 0; z-index: 5; display: flex; align-items: center; justify-content: center; padding: 1rem; background: rgba(20, 10, 10, 0.5); -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px); }
#game-root .jg-overlay[hidden] { display: none; }
#game-root .jg-start {
    position: absolute; inset: 0; z-index: 7;
    display: flex; align-items: center; justify-content: center; padding: 1rem;
    background: rgba(20, 10, 10, 0.55);
    -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
}
#game-root .jg-start[hidden] { display: none; }
#game-root .jg-wrap.jg-prestart .jg-tray,
#game-root .jg-wrap.jg-prestart .jg-actions { display: none; }
#game-root .jg-overlay-card {
    max-width: 320px; width: 100%; text-align: center; padding: 1.3rem 1.2rem;
    background: linear-gradient(180deg, #fff8e1 0%, #fbf0c8 100%);
    border: 1px solid rgba(150, 95, 40, 0.45); border-radius: 16px;
    box-shadow: 0 12px 30px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.7);
    animation: jg-pop 0.3s cubic-bezier(.34,1.56,.64,1);
}
@keyframes jg-pop { 0% { transform: scale(0.85); opacity: 0; } 100% { transform: none; opacity: 1; } }
#game-root .jg-overlay-card h2 { margin: 0 0 0.4rem; color: var(--jul-red-700, #8B0000); font-size: 1.4rem; }
#game-root .jg-overlay-card p { margin: 0 0 0.95rem; color: #4a2a10; font-size: 0.95rem; }
#game-root .jg-rekord { color: #16a34a; }

/* ─── Confetti ──────────────────────────────────────────────────────── */
#game-root .jg-confetti { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 6; }
#game-root .jg-confetti-piece { position: absolute; top: 30%; left: 50%; width: 8px; height: 13px; border-radius: 2px; animation: jg-confetti-fall 1.6s ease-out forwards; }
@keyframes jg-confetti-fall { 0% { transform: translate(0,0) rotate(0); opacity: 1; } 100% { transform: translate(var(--dx), 300px) rotate(var(--rot)); opacity: 0; } }

#game-root .jg-msg { text-align: center; margin-top: 0.5rem; min-height: 1.3em; font-weight: 600; color: #fde9a8; }

/* ─── Fullscreen layout ─────────────────────────────────────────────── */
#game-root .jg-wrap.jg-fs-on {
    width: 100vw; height: 100vh; max-width: none; border-radius: 0;
    padding: 0.7rem; display: flex; flex-direction: column; align-items: center;
    overflow: auto; background: linear-gradient(180deg, #2a1010 0%, #5a1818 100%);
}
#game-root .jg-wrap.jg-fs-on .jg-header,
#game-root .jg-wrap.jg-fs-on .jg-modes,
#game-root .jg-wrap.jg-fs-on .jg-actions { width: 100%; max-width: 680px; flex: 0 0 auto; }
#game-root .jg-wrap.jg-fs-on .jg-playfield {
    width: 100%; max-width: min(94vw, calc((100vh - 380px) * 4 / 3));
    flex: 0 0 auto; margin: 0.3rem 0;
}
#game-root .jg-wrap.jg-fs-on .jg-tray { width: 100%; max-width: 920px; flex: 1 1 auto; min-height: 150px; max-height: none; }

/* ─── Responsive ────────────────────────────────────────────────────── */
@media (min-width: 720px) {
    #game-root .jg-wrap { max-width: 680px; padding: 1rem; }
    #game-root .jg-val { font-size: 1.35rem; }
    #game-root .jg-tray { max-height: 280px; }
}
@media (max-width: 480px) {
    #game-root .jg-wrap { padding: 0.6rem; }
    #game-root .jg-header { flex-wrap: wrap; gap: 0.3rem; }
    #game-root .jg-val { font-size: 1.05rem; }
    #game-root .jg-vol { width: 46px; }
    #game-root .jg-mode { font-size: 0.72rem; padding: 0.3rem 0.4rem; }
    #game-root .jg-peek { top: 14px; right: 14px; font-size: 0.72rem; padding: 0.25rem 0.55rem; }
    #game-root .jg-tray { max-height: 200px; }
}
